GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: run all tasks when --continue-on-error=true · lint-staged/lint-staged@33d4502

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • .changeset
    • cool-sites-taste.md
  • lib
    • getSpawnedTask.js
    • getSpawnedTasks.js
    • runAll.js
  • package-lock.json
  • test/unit
    • runAll.spec.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎.changeset/cool-sites-taste.md‎

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'lint-staged': patch
3+
---
4+
5+
Fix problems with `--continue-on-error` option, where tasks might have still been killed (`SIGINT`) when one of them failed.
Collapse file

‎lib/getSpawnedTask.js‎

Copy file name to clipboardExpand all lines: lib/getSpawnedTask.js
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ export const makeErr = (command, error, ctx) => {
129129
* @param {Object} options
130130
* @param {boolean} [options.color]
131131
* @param {string} options.command — Linter task
132+
* @param {string} [options.continueOnError]
132133
* @param {string} [options.cwd]
133134
* @param {String} options.topLevelDir - Current git repo top-level path
134135
* @param {Boolean} options.isFn - Whether the linter task is a function
@@ -139,6 +140,7 @@ export const makeErr = (command, error, ctx) => {
139140
export const getSpawnedTask = ({
140141
color,
141142
command,
143+
continueOnError = false,
142144
cwd = process.cwd(),
143145
files,
144146
topLevelDir,
@@ -165,15 +167,19 @@ export const getSpawnedTask = ({
165167

166168
try {
167169
const subprocess = spawn(cmd, isFn ? args : args.concat(files), spawnOptions)
168-
quitInterruptCheck = interruptExecutionOnError(ctx, subprocess)
170+
if (!continueOnError) {
171+
quitInterruptCheck = interruptExecutionOnError(ctx, subprocess)
172+
}
169173
const result = await subprocess
170174
if (verbose) {
171175
handleOutput(command, result, ctx)
172176
}
173177
} catch (error) {
174178
throw makeErr(command, error, ctx)
175179
} finally {
176-
await quitInterruptCheck()
180+
if (quitInterruptCheck) {
181+
await quitInterruptCheck()
182+
}
177183
}
178184
}
179185
}
Collapse file

‎lib/getSpawnedTasks.js‎

Copy file name to clipboardExpand all lines: lib/getSpawnedTasks.js
+11-1Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,21 @@ const debugLog = createDebug('lint-staged:getSpawnedTasks')
1010
* @param {object} options
1111
* @param {boolean} [options.color]
1212
* @param {Array<string|Function>|string|Function} options.commands
13+
* @param {string} options.continueOnError
1314
* @param {string} options.cwd
1415
* @param {import('./getStagedFiles.js').StagedFile[]} options.files
1516
* @param {string} options.topLevelDir
1617
* @param {Boolean} verbose
1718
*/
18-
export const getSpawnedTasks = async ({ color, commands, cwd, files, topLevelDir, verbose }) => {
19+
export const getSpawnedTasks = async ({
20+
color,
21+
commands,
22+
continueOnError,
23+
cwd,
24+
files,
25+
topLevelDir,
26+
verbose,
27+
}) => {
1928
debugLog('Creating Listr tasks for commands %o', commands)
2029
const cmdTasks = []
2130

@@ -48,6 +57,7 @@ export const getSpawnedTasks = async ({ color, commands, cwd, files, topLevelDir
4857
const task = getSpawnedTask({
4958
color,
5059
command,
60+
continueOnError,
5161
cwd,
5262
files: filepaths,
5363
topLevelDir,
Collapse file

‎lib/runAll.js‎

Copy file name to clipboardExpand all lines: lib/runAll.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ export const runAll = async (
224224
: getSpawnedTasks({
225225
color,
226226
commands: task.commands,
227+
continueOnError,
227228
cwd: groupCwd,
228229
files: task.fileList,
229230
topLevelDir,
Collapse file

‎package-lock.json‎

Copy file name to clipboardExpand all lines: package-lock.json
-11Lines changed: 0 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Collapse file

‎test/unit/runAll.spec.js‎

Copy file name to clipboardExpand all lines: test/unit/runAll.spec.js
+42-3Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,19 @@ describe('runAll', () => {
452452
})
453453

454454
it('should reject after running all tasks when continueOnError is true', async ({ expect }) => {
455-
getStagedFiles.mockImplementationOnce(async () => [{ filepath: 'foo.js', status: 'A' }])
455+
getStagedFiles.mockImplementationOnce(async () => [
456+
{
457+
filepath: 'foo.js',
458+
status: 'A',
459+
},
460+
{ filepath: 'bar.py', status: 'A' },
461+
])
462+
456463
searchConfigs.mockImplementationOnce(async () => ({
457-
'': { '*.js': 'echo "failing command"' },
464+
'': {
465+
'*.js': ['echo "success js command 1"', 'echo "success js command 2"'],
466+
'*.py': 'echo "failing py command"',
467+
},
458468
}))
459469

460470
// Mock first spawn call (git operations) to succeed
@@ -465,7 +475,15 @@ describe('runAll', () => {
465475
})
466476
)
467477

468-
// Mock second spawn call (the actual task) to fail
478+
// Mock second spawn call (`echo "success js command 1"`) to succeed
479+
spawn.mockImplementationOnce(() =>
480+
mockNanoSpawnReturnValue({
481+
output: 'Success',
482+
nodeChildProcess: { pid: 0 },
483+
})
484+
)
485+
486+
// Mock second spawn call (`echo "failing py command"`) to fail
469487
spawn.mockImplementationOnce(() =>
470488
mockNanoSpawnReturnValue(
471489
Object.assign(new SubprocessError(), {
@@ -475,11 +493,32 @@ describe('runAll', () => {
475493
)
476494
)
477495

496+
// Mock first spawn call ('success js command 2') to succeed
497+
spawn.mockImplementationOnce(() =>
498+
mockNanoSpawnReturnValue(
499+
{
500+
output: 'Success',
501+
nodeChildProcess: { pid: 0 },
502+
},
503+
1000
504+
)
505+
)
506+
478507
mockGitWorkflow.runTasks.mockImplementationOnce(async (ctx, task, { listrTasks }) => {
479508
return task.newListr(listrTasks)
480509
})
481510

482511
// With continueOnError: true, should still reject but after running all tasks
483512
await expect(runAll({ continueOnError: true })).rejects.toThrow('lint-staged failed')
513+
514+
expect(console.printHistory()).toMatch(
515+
/"data":"COMPLETED".*"title":"echo \\"success js command 1\\"/
516+
)
517+
expect(console.printHistory()).toMatch(
518+
/"data":{"error":"echo \\"failing py command\\" \[FAILED\]"}/
519+
)
520+
expect(console.printHistory()).toMatch(
521+
/"data":"COMPLETED".*"title":"echo \\"success js command 2\\"/
522+
)
484523
})
485524
})

0 commit comments

Comments
0 (0)
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.