From 398c8d3af8ed6b7aa33e5c27b0cdfc700fd92800 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Wed, 12 Aug 2020 00:48:20 -0700 Subject: [PATCH 1/3] Add a unit test that shows rushx does not pass its args --- apps/rush-lib/src/cli/test/Cli.test.ts | 18 ++++++++++++++++++ .../src/cli/test/repo/rushx-project/build.js | 2 ++ .../cli/test/repo/rushx-project/package.json | 7 +++++++ apps/rush-lib/src/startx.ts | 6 ++++++ 4 files changed, 33 insertions(+) create mode 100644 apps/rush-lib/src/cli/test/repo/rushx-project/build.js create mode 100644 apps/rush-lib/src/cli/test/repo/rushx-project/package.json create mode 100644 apps/rush-lib/src/startx.ts diff --git a/apps/rush-lib/src/cli/test/Cli.test.ts b/apps/rush-lib/src/cli/test/Cli.test.ts index 7215d9257a..f4a31e60a7 100644 --- a/apps/rush-lib/src/cli/test/Cli.test.ts +++ b/apps/rush-lib/src/cli/test/Cli.test.ts @@ -19,4 +19,22 @@ describe('CLI', () => { }); }).not.toThrow(); }); + + it('rushx should pass args to scripts', () => { + // Invoke "rushx" + const startPath: string = path.resolve(path.join(__dirname, '../../../lib/startx.js')); + + // Run "rushx show-args 1 2 -x" in the "repo/rushx-project" folder + const output: string = Utilities.executeCommandAndCaptureOutput( + 'node', + [startPath, 'show-args', '1', '2', '-x'], + path.join(__dirname, 'repo', 'rushx-project') + ); + const lastLine: string = + output + .split(/\s*\n\s*/) + .filter((x) => x) + .pop() || ''; + expect(lastLine).toEqual('build.js: ARGS=[]'); + }); }); diff --git a/apps/rush-lib/src/cli/test/repo/rushx-project/build.js b/apps/rush-lib/src/cli/test/repo/rushx-project/build.js new file mode 100644 index 0000000000..fd3033bfe2 --- /dev/null +++ b/apps/rush-lib/src/cli/test/repo/rushx-project/build.js @@ -0,0 +1,2 @@ +// slice(2) trims away "node.exe" and "build.js" from the array +console.log('build.js: ARGS=' + JSON.stringify(process.argv.slice(2))); diff --git a/apps/rush-lib/src/cli/test/repo/rushx-project/package.json b/apps/rush-lib/src/cli/test/repo/rushx-project/package.json new file mode 100644 index 0000000000..94d30df2ce --- /dev/null +++ b/apps/rush-lib/src/cli/test/repo/rushx-project/package.json @@ -0,0 +1,7 @@ +{ + "name": "rushx-project", + "version": "0.0.0", + "scripts": { + "show-args": "node ./build.js" + } +} diff --git a/apps/rush-lib/src/startx.ts b/apps/rush-lib/src/startx.ts new file mode 100644 index 0000000000..56b39590b0 --- /dev/null +++ b/apps/rush-lib/src/startx.ts @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. +// See LICENSE in the project root for license information. + +import { Rush } from './api/Rush'; + +Rush.launchRushX(Rush.version, { isManaged: false }); From 7f8ec76d62f81174a47aba88e5aa1c505509b2e7 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Wed, 12 Aug 2020 00:58:13 -0700 Subject: [PATCH 2/3] Fix issue where rushx args were not passed to the shell script --- apps/rush-lib/src/cli/RushXCommandLine.ts | 10 ++++++++-- apps/rush-lib/src/cli/test/Cli.test.ts | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/apps/rush-lib/src/cli/RushXCommandLine.ts b/apps/rush-lib/src/cli/RushXCommandLine.ts index 9b1b2502a4..754c7cc8d8 100644 --- a/apps/rush-lib/src/cli/RushXCommandLine.ts +++ b/apps/rush-lib/src/cli/RushXCommandLine.ts @@ -102,11 +102,17 @@ export class RushXCommandLine { return; } - console.log('Executing: ' + JSON.stringify(scriptBody) + os.EOL); + const remainingArgs: string[] = args.slice(1); + let commandWithArgs: string = scriptBody; + if (remainingArgs.length > 0) { + commandWithArgs += ' ' + remainingArgs.join(' '); + } + + console.log('Executing: ' + JSON.stringify(commandWithArgs) + os.EOL); const packageFolder: string = path.dirname(packageJsonFilePath); - const exitCode: number = Utilities.executeLifecycleCommand(scriptBody, { + const exitCode: number = Utilities.executeLifecycleCommand(commandWithArgs, { rushConfiguration, workingDirectory: packageFolder, // If there is a rush.json then use its .npmrc from the temp folder. diff --git a/apps/rush-lib/src/cli/test/Cli.test.ts b/apps/rush-lib/src/cli/test/Cli.test.ts index f4a31e60a7..35e215164f 100644 --- a/apps/rush-lib/src/cli/test/Cli.test.ts +++ b/apps/rush-lib/src/cli/test/Cli.test.ts @@ -35,6 +35,6 @@ describe('CLI', () => { .split(/\s*\n\s*/) .filter((x) => x) .pop() || ''; - expect(lastLine).toEqual('build.js: ARGS=[]'); + expect(lastLine).toEqual('build.js: ARGS=["1","2","-x"]'); }); }); From 3bf7cd6af0449e661b4cfbd0b9051693d0079d94 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Wed, 12 Aug 2020 00:59:04 -0700 Subject: [PATCH 3/3] rush change --- .../rush/octogonz-better-rushx_2020-08-12-07-58.json | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 common/changes/@microsoft/rush/octogonz-better-rushx_2020-08-12-07-58.json diff --git a/common/changes/@microsoft/rush/octogonz-better-rushx_2020-08-12-07-58.json b/common/changes/@microsoft/rush/octogonz-better-rushx_2020-08-12-07-58.json new file mode 100644 index 0000000000..87f1bcf574 --- /dev/null +++ b/common/changes/@microsoft/rush/octogonz-better-rushx_2020-08-12-07-58.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Fix an issue where \"rushx\" did not pass additional command-line arguments to the package.json script (GitHub #1232)", + "type": "none" + } + ], + "packageName": "@microsoft/rush", + "email": "4673363+octogonz@users.noreply.github.com" +} \ No newline at end of file