Skip to content

Commit 5de3151

Browse files
committed
GlobalScriptAction.ts now invokes the script and correctly returns its exit code
1 parent 9a91c64 commit 5de3151

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

apps/rush-lib/src/cli/RushCommandLineParser.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,10 @@ export class RushCommandLineParser extends CommandLineParser {
229229
// performs nontrivial work that can throw an exception. Either the Rush class would need
230230
// to handle reporting for those exceptions, or else _populateActions() should be moved
231231
// to a RushCommandLineParser lifecycle stage that can handle it.
232-
process.exit(1);
232+
if (process.exitCode > 0) {
233+
process.exit(process.exitCode);
234+
} else {
235+
process.exit(1);
236+
}
233237
}
234238
}

apps/rush-lib/src/cli/scriptActions/GlobalScriptAction.ts

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
22
// See LICENSE in the project root for license information.
33

4+
import * as colors from 'colors';
45
import * as fsx from 'fs-extra';
56
import * as os from 'os';
67

78
import { BaseScriptAction, IBaseScriptActionOptions } from './BaseScriptAction';
9+
import { Utilities } from '../../utilities/Utilities';
10+
import { AlreadyReportedError } from '../../../lib/utilities/AlreadyReportedError';
811

912
/**
1013
* Constructor parameters for GlobalScriptAction.
@@ -34,19 +37,40 @@ export class GlobalScriptAction extends BaseScriptAction {
3437
}
3538

3639
public run(): Promise<void> {
37-
if (!fsx.existsSync(this.rushConfiguration.rushLinkJsonFilename)) {
38-
throw new Error(`File not found: ${this.rushConfiguration.rushLinkJsonFilename}` +
39-
`${os.EOL}Did you run "rush link"?`);
40-
}
40+
return Promise.resolve().then(() => {
41+
if (!fsx.existsSync(this.rushConfiguration.rushLinkJsonFilename)) {
42+
throw new Error(`File not found: ${this.rushConfiguration.rushLinkJsonFilename}` +
43+
`${os.EOL}Did you run "rush link"?`);
44+
}
4145

42-
// Collect all custom parameter values
43-
const customParameterValues: string[] = [];
46+
// Collect all custom parameter values
47+
const customParameterValues: string[] = [];
4448

45-
for (const customParameter of this.customParameters) {
46-
customParameter.appendToArgList(customParameterValues);
47-
}
49+
for (const customParameter of this.customParameters) {
50+
customParameter.appendToArgList(customParameterValues);
51+
}
4852

49-
return Promise.resolve();
53+
let shellCommand: string = this._scriptPath;
54+
if (customParameterValues.length > 0) {
55+
shellCommand += ' ' + customParameterValues.join(' ');
56+
}
57+
58+
const exitCode: number = Utilities.executeLifecycleCommand(shellCommand,
59+
{
60+
workingDirectory: this.rushConfiguration.rushJsonFolder,
61+
initCwd: this.rushConfiguration.commonTempFolder,
62+
handleOutput: false
63+
}
64+
);
65+
66+
if (exitCode > 0) {
67+
console.log(os.EOL + colors.red(`The script failed with exit code ${exitCode}`));
68+
}
69+
70+
process.exitCode = exitCode;
71+
72+
throw new AlreadyReportedError();
73+
});
5074
}
5175

5276
protected onDefineParameters(): void {

apps/rush-lib/src/cli/test/repo/common/config/rush/command-line.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"commandKind": "global",
1313
"summary": "Deploys the build",
1414
"description": "Uploads all the built assets to the CDN",
15-
"scriptPath": "common/scripts/deploy.js"
15+
"scriptPath": "node common/scripts/deploy.js"
1616
}
1717
],
1818

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
console.log('Executing common/scripts/deploy.js');
2+
console.log('ARGV: ' + JSON.stringify(process.argv));
3+
console.log('CWD: ' + process.cwd());
4+
console.log('NPM_INITCWD: ' + process.env['INIT_CWD']);
5+
6+
process.exit(123)

0 commit comments

Comments
 (0)