Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[rush] Fix an issue where "rushx" did not pass additional parameters to the shell script #2096

Merged
merged 3 commits into from
Aug 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions apps/rush-lib/src/cli/RushXCommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
18 changes: 18 additions & 0 deletions apps/rush-lib/src/cli/test/Cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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=["1","2","-x"]');
});
});
2 changes: 2 additions & 0 deletions apps/rush-lib/src/cli/test/repo/rushx-project/build.js
Original file line number Diff line number Diff line change
@@ -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)));
7 changes: 7 additions & 0 deletions apps/rush-lib/src/cli/test/repo/rushx-project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "rushx-project",
"version": "0.0.0",
"scripts": {
"show-args": "node ./build.js"
}
}
6 changes: 6 additions & 0 deletions apps/rush-lib/src/startx.ts
Original file line number Diff line number Diff line change
@@ -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 });
Original file line number Diff line number Diff line change
@@ -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"
}