Skip to content

Commit

Permalink
Add pre-commit hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
julienmalard committed Jan 27, 2025
1 parent 690850b commit 71d9f0d
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .nano-staged.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {resolve, sep} from 'path';

export default {
'*.{js,mjs,cjs,ts,mts,cts,vue}': 'eslint --cache --fix',

/**
* Run typechecking if any type-sensitive files or project dependencies was changed
* @param {string[]} filenames
* @return {string[]}
*/
'{package-lock.json,packages/**/{*.ts,*.vue,tsconfig.json}}': ({filenames}) => {
// if dependencies was changed run type checking for all packages
if (filenames.some(f => f.endsWith('package-lock.json'))) {
return ['pnpm run typecheck --if-present'];
}

// else run type checking for staged packages
const fileNameToPackageName = filename =>
filename.replace(resolve(process.cwd(), 'packages') + sep, '').split(sep)[0];
return [...new Set(filenames.map(fileNameToPackageName))].map(
p => `pnpm run typecheck:${p} --if-present`,
);
},
};

0 comments on commit 71d9f0d

Please sign in to comment.