Skip to content

Commit 5a1105a

Browse files
leosvelperezFrozenPandaz
authored andcommitted
fix(misc): allow run-commands to accept readyWhen for a single command (#6496)
1 parent cc02bba commit 5a1105a

File tree

6 files changed

+9
-48
lines changed

6 files changed

+9
-48
lines changed

docs/angular/api-workspace/executors/run-commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,4 @@ Run commands in parallel
222222

223223
Type: `string`
224224

225-
String to appear in `stdout` or `stderr` that indicates that the task is done. This option can only be used when multiple commands are run and `parallel` is set to `true`. If not specified, the task is done when all the child processes complete.
225+
String to appear in `stdout` or `stderr` that indicates that the task is done. When running multiple commands, this option can only be used when `parallel` is set to `true`. If not specified, the task is done when all the child processes complete.

docs/node/api-workspace/executors/run-commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,4 @@ Run commands in parallel
223223

224224
Type: `string`
225225

226-
String to appear in `stdout` or `stderr` that indicates that the task is done. This option can only be used when multiple commands are run and `parallel` is set to `true`. If not specified, the task is done when all the child processes complete.
226+
String to appear in `stdout` or `stderr` that indicates that the task is done. When running multiple commands, this option can only be used when `parallel` is set to `true`. If not specified, the task is done when all the child processes complete.

docs/react/api-workspace/executors/run-commands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,4 +223,4 @@ Run commands in parallel
223223

224224
Type: `string`
225225

226-
String to appear in `stdout` or `stderr` that indicates that the task is done. This option can only be used when multiple commands are run and `parallel` is set to `true`. If not specified, the task is done when all the child processes complete.
226+
String to appear in `stdout` or `stderr` that indicates that the task is done. When running multiple commands, this option can only be used when `parallel` is set to `true`. If not specified, the task is done when all the child processes complete.

packages/workspace/src/executors/run-commands/run-commands.impl.spec.ts

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -194,36 +194,6 @@ describe('Command Runner Builder', () => {
194194
});
195195

196196
describe('readyWhen', () => {
197-
it('should warn when command is specified instead of commands', async () => {
198-
jest.spyOn(process.stderr, 'write');
199-
await runCommands(
200-
{
201-
command: `echo 'Hello World'`,
202-
readyWhen: 'READY',
203-
},
204-
context
205-
);
206-
207-
expect(process.stderr.write).toHaveBeenCalledWith(
208-
'Warning: "readyWhen" has no effect when a single command is run. The task will be done when the command process is completed. Ignoring.'
209-
);
210-
});
211-
212-
it('should warn when a single command is specified', async () => {
213-
jest.spyOn(process.stderr, 'write');
214-
await runCommands(
215-
{
216-
commands: [`echo 'Hello World'`],
217-
readyWhen: 'READY',
218-
},
219-
context
220-
);
221-
222-
expect(process.stderr.write).toHaveBeenCalledWith(
223-
'Warning: "readyWhen" has no effect when a single command is run. The task will be done when the command process is completed. Ignoring.'
224-
);
225-
});
226-
227197
it('should error when parallel = false', async () => {
228198
try {
229199
await runCommands(
@@ -237,7 +207,7 @@ describe('Command Runner Builder', () => {
237207
fail('should throw');
238208
} catch (e) {
239209
expect(e.message).toEqual(
240-
`ERROR: Bad builder config for @nrwl/run-commands - "readyWhen" can only be used when parallel=true.`
210+
`ERROR: Bad executor config for @nrwl/run-commands - "readyWhen" can only be used when "parallel=true".`
241211
);
242212
}
243213
});

packages/workspace/src/executors/run-commands/run-commands.impl.ts

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,9 @@ export default async function (
7171
const normalized = normalizeOptions(options);
7272

7373
if (options.readyWhen && !options.parallel) {
74-
if (options.command || options.commands?.length === 1) {
75-
process.stderr.write(
76-
'Warning: "readyWhen" has no effect when a single command is run. The task will be done when the command process is completed. Ignoring.'
77-
);
78-
} else {
79-
throw new Error(
80-
'ERROR: Bad builder config for @nrwl/run-commands - "readyWhen" can only be used when parallel=true.'
81-
);
82-
}
74+
throw new Error(
75+
'ERROR: Bad executor config for @nrwl/run-commands - "readyWhen" can only be used when "parallel=true".'
76+
);
8377
}
8478

8579
try {
@@ -146,14 +140,11 @@ function normalizeOptions(
146140

147141
if (options.command) {
148142
options.commands = [{ command: options.command }];
149-
options.parallel = false;
143+
options.parallel = !!options.readyWhen;
150144
} else {
151145
options.commands = options.commands.map((c) =>
152146
typeof c === 'string' ? { command: c } : c
153147
);
154-
if (options.commands.length === 1) {
155-
options.parallel = false;
156-
}
157148
}
158149
(options as NormalizedRunCommandsBuilderOptions).commands.forEach((c) => {
159150
c.command = transformCommand(

packages/workspace/src/executors/run-commands/schema.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
},
4747
"readyWhen": {
4848
"type": "string",
49-
"description": "String to appear in `stdout` or `stderr` that indicates that the task is done. This option can only be used when multiple commands are run and `parallel` is set to `true`. If not specified, the task is done when all the child processes complete."
49+
"description": "String to appear in `stdout` or `stderr` that indicates that the task is done. When running multiple commands, this option can only be used when `parallel` is set to `true`. If not specified, the task is done when all the child processes complete."
5050
},
5151
"args": {
5252
"type": "string",

0 commit comments

Comments
 (0)