fix(core): run-commands should fail when a command in serial fails (#4477)

This commit is contained in:
Jason Jean 2021-01-11 12:19:41 -05:00 committed by GitHub
parent 19c5f53ebf
commit 82f801b0db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 6 deletions

View File

@ -58,4 +58,25 @@ describe('Run Commands', () => {
expect(result).toContain('print: y');
done();
}, 120000);
it('should fail when a process exits non-zero', () => {
newProject();
const myapp = uniq('myapp1');
runCLI(`generate @nrwl/web:app ${myapp}`);
const config = readJson(workspaceConfigName());
config.projects[myapp].targets.error = {
executor: '@nrwl/workspace:run-commands',
options: {
command: `exit 1`,
},
};
updateFile(workspaceConfigName(), JSON.stringify(config));
try {
runCLI('error');
fail('Should error if process errors');
} catch (e) {}
});
});

View File

@ -177,7 +177,7 @@ describe('Command Runner Builder', () => {
});
});
it('should stop execution when a command fails', async () => {
it('should stop execution and fail when a command fails', async () => {
const f = fileSync().name;
try {
@ -185,6 +185,7 @@ describe('Command Runner Builder', () => {
commands: [`echo 1 >> ${f} && exit 1`, `echo 2 >> ${f}`],
parallel: false,
});
fail('should fail when a command fails');
} catch (e) {}
expect(readFile(f)).toEqual('1');
});

View File

@ -152,9 +152,9 @@ function normalizeOptions(
}
async function runSerially(options: NormalizedRunCommandsBuilderOptions) {
options.commands.forEach((c) => {
for (const c of options.commands) {
createSyncProcess(c.command, options.color, options.cwd);
});
}
return true;
}

View File

@ -158,9 +158,16 @@ function normalizeOptions(
}
async function runSerially(options: NormalizedRunCommandsBuilderOptions) {
options.commands.forEach((c) => {
createSyncProcess(c.command, options.color, options.cwd);
});
for (const c of options.commands) {
try {
createSyncProcess(c.command, options.color, options.cwd);
} catch (e) {
process.stderr.write(
`Warning: @nrwl/run-commands command "${c.command}" exited with non-zero status code`
);
return false;
}
}
return true;
}