Skip to content

Commit

Permalink
chore(git-hooks): setup Husky
Browse files Browse the repository at this point in the history
Add pre-commit hook
  • Loading branch information
nelson6e65 committed Oct 15, 2023
1 parent 29b3e18 commit 1915f05
Show file tree
Hide file tree
Showing 11 changed files with 945 additions and 42 deletions.
24 changes: 14 additions & 10 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const path = require('node:path');
// const path = require('node:path');

/**
* @type {import('eslint').Linter.RulesRecord}
Expand Down Expand Up @@ -166,15 +166,19 @@ module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'import', 'unicorn'],
parserOptions: {
tsconfigRootDir: path.dirname('./'),
project: [
//
'./tsconfig.base.json',
'./tsconfig.internal.json',
'./tsconfig.test.json',
'./tsconfig.main.json',
// './examples/**/tsconfig.json',
],
EXPERIMENTAL_useProjectService: true,
// project: true,
// tsconfigRootDir: path.dirname('./'),
// project: 'tsconfig.json',
// project: [
// //
// './tsconfig.base.json',
// './tsconfig.configs.json',
// './tsconfig.internal.json',
// './tsconfig.test.json',
// './tsconfig.main.json',
// // './examples/**/tsconfig.json',
// ],
},
rules: {
...defaultRules,
Expand Down
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
# shellcheck source=/dev/null
. "$(dirname -- "$0")/_/husky.sh"

npx lint-staged
19 changes: 19 additions & 0 deletions .lintstagedrc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const eslintCmd = 'eslint --fix';
const prettierCmd = 'prettier --ignore-unknown --write';

// FIXME: tsc for specific files.
// TODO: Run tsc in the entire project (-p tsconfig.x.json) instead of per-file
// https://github.com/lint-staged/lint-staged?tab=readme-ov-file#example-wrap-filenames-in-single-quotes-and-run-once-per-file
// const tscCmd = 'tsc --noEmit';

export default {
// Javascript sources
'*.{js,cjs,mjs}': [eslintCmd, prettierCmd],

// Typescript sources
'*.{ts,cts,mts}': [eslintCmd, prettierCmd],

// Other files
'*!(.{js,cjs,mjs,ts,cts,mts})': [prettierCmd],
'.prettierrc.json': () => 'npm run lint:prettier-config',
};
8 changes: 4 additions & 4 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import path from 'node:path';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';

import { defineBuildConfig } from 'unbuild';

const ROOT_DIR = path.dirname(fileURLToPath(import.meta.url));
const ROOT_DIR = dirname(fileURLToPath(import.meta.url));

// const entries: BuildEntry[] = [
// //
Expand All @@ -24,7 +24,7 @@ export default defineBuildConfig([
// entries, // Let it autodetect entries from package.json
rollup: {
dts: {
tsconfig: path.resolve(ROOT_DIR, './tsconfig.base.json'),
tsconfig: resolve(ROOT_DIR, './tsconfig.base.json'),
},
inlineDependencies: true,
output: {
Expand All @@ -35,7 +35,7 @@ export default defineBuildConfig([
},
declaration: 'compatible',
alias: {
'~': path.resolve(ROOT_DIR, './src'),
'~': resolve(ROOT_DIR, './src'),
},
},
]);
2 changes: 1 addition & 1 deletion internal/build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fileURLToPath } from 'node:url';

import { defineBuildConfig } from 'unbuild';

import { CommentBuilder, EMPTY_NEW_LINE } from './utils/comment-builder';
import { CommentBuilder, EMPTY_NEW_LINE } from './utils/comment-builder.js';

// TODO: Move to a separated workspace

Expand Down
Loading

0 comments on commit 1915f05

Please sign in to comment.