My first thought was also that this must not be a problem with lint-staged, but I'm not sure what else to tie it back to. It may be an issue with husky as well
"lint-staged": {
"**/*.js": ["eslint --fix","git add"],
"**/*.scss": ["prettier --write","git add"]
},
with one scss file staged, the prettier task hangs and takes about 27 seconds to complete, but running node_modules/.bin/prettier **/*.scss --write on the entire project (abt 300 files) takes 11 seconds.
After digging into the debug logs I see:
for the js/eslint task:
lint-staged:find-bin Resolving binary for commandgit add+1s
for the scss/prettier task:
lint-staged:find-bin Resolving binary for commandgit add+24s
(18 seconds trying a newer version of node)
Weird!
I tried switching the order of the tasks and the slowdown resolving git occurred on the second task (now eslint --fix)
lint-staged:bin Running `[email protected]` +0ms
lint-staged Loading config using `cosmiconfig` +0ms
lint-staged Successfully loaded config from `###/front-end/package.json`:
lint-staged { '**/*.js': [ 'eslint --fix', 'git add' ],
lint-staged '**/*.scss': [ 'prettier --write', 'git add' ] } +7ms
lint-staged:cfg Normalizing config +0ms
lint-staged:cfg Validating config +5ms
Running lint-staged with the following config:
{
linters: {
'**/*.js': [
'eslint --fix',
'git add'
],
'**/*.scss': [
'prettier --write',
'git add'
]
},
concurrent: true,
chunkSize: 9007199254740991,
globOptions: {
matchBase: true,
dot: true
},
subTaskConcurrency: 1,
renderer: 'verbose'
}
lint-staged Loaded scripts from package.json:
lint-staged { dev: 'npm start',
lint-staged build: 'npm rebuild node-sass && node ./_build/build.js',
lint-staged 'watch-aem': 'node_modules/.bin/aemsync -w \'../gwl-view\'',
lint-staged packages: 'sh ./packages/importPackages',
lint-staged clean: 'rm -rf ./cl/build/* ./ll/build/* ./atm/build/* ./quadrus/build/* ./idea/build/* ./edl/build/* ./glc/build/* ./rfp/build/*',
lint-staged precommit: 'lint-staged',
lint-staged prettier: 'prettier --write \'./**/*.{scss,js}\'' } +16ms
lint-staged:run Running all linter scripts +0ms
lint-staged:run Resolved git directory to be `/Users/l392044/Documents/websites/aem/` +1ms
lint-staged:run Loaded list of staged files in git:
lint-staged:run [ 'gwl/ds-src/shared/scripts/services/trax.js',
lint-staged:run 'gwl/ds-src/shared/styles/_base.scss' ] +66ms
lint-staged:gen-tasks Generating linter tasks +0ms
lint-staged:cfg Normalizing config +76ms
lint-staged:gen-tasks Generated task:
lint-staged:gen-tasks { pattern: '**/*.js',
lint-staged:gen-tasks commands: [ 'eslint --fix', 'git add' ],
lint-staged:gen-tasks fileList: [ '###/front-end/shared/scripts/services/trax.js' ] } +4ms
lint-staged:gen-tasks Generated task:
lint-staged:gen-tasks { pattern: '**/*.scss',
lint-staged:gen-tasks commands: [ 'prettier --write', 'git add' ],
lint-staged:gen-tasks fileList: [ '###/front-end/shared/styles/_base.scss' ] } +0ms
Running tasks for **/*.js [started]
Running tasks for **/*.scss [started]
lint-staged:run-script Running script with commands [ 'eslint --fix', 'git add' ] +0ms
lint-staged:cfg Normalizing config +9ms
lint-staged:run-script Running script with commands [ 'prettier --write', 'git add' ] +2ms
lint-staged:cfg Normalizing config +2ms
eslint --fix [started]
prettier --write [started]
lint-staged:find-bin Resolving binary for command `eslint --fix` +0ms
lint-staged:find-bin Binary for `eslint --fix` resolved to `###/front-end/node_modules/.bin/eslint` +4ms
lint-staged:find-bin Resolving binary for command `prettier --write` +0ms
lint-staged:find-bin `prettier` resolved to npm script - `prettier --write './**/*.{scss,js}'` +0ms
lint-staged:run-script bin: ###/front-end/node_modules/.bin/eslint +7ms
lint-staged:run-script args: [ '--fix',
lint-staged:run-script '###/front-end/shared/scripts/services/trax.js' ] +0ms
lint-staged:run-script opts: {} +0ms
lint-staged:run-script bin: npm +8ms
lint-staged:run-script args: [ 'run',
lint-staged:run-script 'prettier',
lint-staged:run-script '--',
lint-staged:run-script '--write',
lint-staged:run-script '###/front-end/shared/styles/_base.scss' ] +0ms
lint-staged:run-script opts: {} +0ms
eslint --fix [completed]
git add [started]
lint-staged:find-bin Resolving binary for command `git add` +1s
lint-staged:find-bin Binary for `git add` resolved to `/usr/local/bin/git` +2ms
lint-staged:run-script bin: /usr/local/bin/git +997ms
lint-staged:run-script args: [ 'add',
lint-staged:run-script '###/front-end/shared/scripts/services/trax.js' ] +0ms
lint-staged:run-script opts: { cwd: '/Users/l392044/Documents/websites/aem/' } +1ms
git add [completed]
Running tasks for **/*.js [completed]
prettier --write [completed]
git add [started]
lint-staged:find-bin Resolving binary for command `git add` +24s
lint-staged:find-bin Binary for `git add` resolved to `/usr/local/bin/git` +1ms
lint-staged:run-script bin: /usr/local/bin/git +24s
lint-staged:run-script args: [ 'add',
lint-staged:run-script '###/front-end/shared/styles/_base.scss' ] +0ms
lint-staged:run-script opts: { cwd: '/Users/l392044/Documents/websites/aem/' } +1ms
git add [completed]
Running tasks for **/*.scss [completed]
lint-staged linters were executed successfully! +26s
lint-staged: 6.0.0From the logs, I can see that you have a script named prettier.
lint-staged Loaded scripts from package.json:
lint-staged { dev: 'npm start',
lint-staged build: 'npm rebuild node-sass && node ./_build/build.js',
lint-staged 'watch-aem': 'node_modules/.bin/aemsync -w \'../gwl-view\'',
lint-staged packages: 'sh ./packages/importPackages',
lint-staged clean: 'rm -rf ./cl/build/* ./ll/build/* ./atm/build/* ./quadrus/build/* ./idea/build/* ./edl/build/* ./glc/build/* ./rfp/build/*',
lint-staged precommit: 'lint-staged',
lint-staged prettier: 'prettier --write \'./**/*.{scss,js}\'' } +16ms 馃 Here's the problem
This takes priority over prettier, the binary, which would be installed to node_modules/.bin/prettier. The debug logs also call this out - lint-staged:find-bin prettier resolved to npm script - prettier --write './**/*.{scss,js}'. This means that prettier will run on your entire project instead of the modified files which would be passed to it by lint-staged. Simply change the name for the prettier script to something like format.
The line lint-staged:find-bin Resolving binary for command git add +24s is slightly misleading. It doesn't mean that resolving git add took 24 secs. Instead it is the time between the last line logged from that module which would be Binary for git add resolved to /usr/local/bin/git. This is just how debug works, can't do much about it.
I am closing this issue but if you are still facing performance issues after doing the suggested changes, we can reopen it.
ah thanks.. that makes sense!
Related to #376
Most helpful comment
From the logs, I can see that you have a script named
prettier.This takes priority over
prettier, the binary, which would be installed tonode_modules/.bin/prettier. The debug logs also call this out -lint-staged:find-bin prettier resolved to npm script - prettier --write './**/*.{scss,js}'. This means thatprettierwill run on your entire project instead of the modified files which would be passed to it bylint-staged. Simply change the name for the prettier script to something likeformat.The line
lint-staged:find-bin Resolving binary for command git add +24sis slightly misleading. It doesn't mean that resolvinggit addtook 24 secs. Instead it is the time between the last line logged from that module which would beBinary for git add resolved to /usr/local/bin/git. This is just howdebugworks, can't do much about it.I am closing this issue but if you are still facing performance issues after doing the suggested changes, we can reopen it.