New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: run task command on files deep copy #1217
Conversation
919cc48
to
9006d3d
Compare
So you're saying something can mutate the list of files? Do you have a reproduction case? I'm wondering how this is possible. Also let's create an issue for this first and reference the PR. |
Also before we can merge it we would need a test for this. |
Yeah, I faced this issue running Here is an example: const divideArray = (arr, size) => {
return new Array(Math.ceil(arr.length / size))
.fill()
.map((_) => arr.splice(0, size))
}
const splitCommand = (filenames, commandFormat) => {
const splitFilenames = divideArray(filenames, 5)
return splitFilenames.map((files) => `${commandFormat} ${files.join(' ')}`)
}
module.exports = {
'*.js': (filenames) => [
"pnpm prettier --write '*.js'",
...splitCommand(filenames, 'pnpm run --silent eslint --fix'),
],
} This basically outputs the same command applied to a subset of the filenames. If there are 10 changed files, the You can see that the Not sure to have the time to add a test this week. |
Deep copying the array indeed solves the issue: const divideArray = (arr, size) => {
const arrCopy = [...arr]
return new Array(Math.ceil(arrCopy.length / size))
.fill()
.map((_) => arrCopy.splice(0, size))
} But it would be definitely better if the library handled that case internally. |
9006d3d
to
565169c
Compare
Ping @louneskmt I rebased this PR and added a changeset file! |
565169c
to
7aca556
Compare
7aca556
to
d2e6f8b
Compare
Thanks for the unit test and the merge! |
Thanks @louneskmt for your contribution! |
This prevents the task command to change the files array by inadvertence. It happened to me and I took a long moment to diagnose the issue.