-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Run-Commands: Arguments are incorrectly appended when using multiple commands #3335
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
Comments
Looks like this is the current expected (undocumented) behavior as shown by the following source code:
it('should add all args to the command if no interpolation in the command', async () => {
const exec = spyOn(require('child_process'), 'execSync').and.callThrough();
const scheduleRun = await architect.scheduleBuilder(
'@nrwl/workspace:run-commands',
{
command: `echo`,
a: 123,
b: 456,
}
);
//wait a tick for the serial runner to schedule the first task
await Promise.resolve();
const run = await scheduleRun;
const result = await run.result;
expect(exec).toHaveBeenCalledWith(`echo --a=123 --b=456`, {
stdio: [0, 1, 2],
cwd: undefined,
env: process.env,
});
});
function transformCommand(command: string, args: { [key: string]: string }) {
if (command.indexOf('{args.') > -1) {
const regex = /{args\.([^}]+)}/g;
return command.replace(regex, (_, group: string) => args[group]);
} else if (Object.keys(args).length > 0) {
const stringifiedArgs = Object.keys(args)
.map((a) => `--${a}=${args[a]}`)
.join(' ');
return `${command} ${stringifiedArgs}`;
} else {
return command;
}
} This looks to have been added as the default behavior after commands began supporting an array of strings as well as an array of objects. Example: // OLD docs:
"create-script": {
"builder": "@nrwl/workspace:run-commands",
"options": {
"commands": [
{
"command": "mkdir -p scripts"
},
{
"command": "touch scripts/{args.name}.sh"
},
{
"command": "chmod +x scripts/{args.name}.sh"
}
],
"cwd": "apps/frontend",
"parallel": false
}
}
// NEW docs:
"create-script": {
"builder": "@nrwl/workspace:run-commands",
"options": {
"commands": [
"mkdir -p scripts",
"touch scripts/{args.name}.sh",
"chmod +x scripts/{args.name}.sh"
],
"cwd": "apps/frontend",
"parallel": false
}
} It still doesn't make any sense to me though why you would want to force the arguments into a command if it doesn't explicitly use interpolation. Users should be expected to use interpolation since the documentation explicitly states to use interpolation (i.e. Forcing arguments regardless of the use of interpolated values breaks lots of commands. Happy to submit a PR if my logic is correct 👌 . |
There are two separate scenarios run-commands is used for:
I see the following options:
I think when using command (singular), forwarding by default is what you want.
There is not reason not to forward. You are wrapping another tool here. For multiple commands, not forwarding is probably more reasonable--cause args won't align. Maybe we can introduce forwardAllArgs option, default it to false when using "commands" (plural). What do you think? |
@vsavkin thanks for your response. I would also agree that it's not reasonable to forward when using And just to be clear, this wouldn't affect interpolation correct? Meaning |
Sorry for the late reply. Yup. It won't affect interpolation. It will only affect default forwarding. @germanp173 would you like to send a PR making the change? I can help you out. If not, I'll make the change myself. |
@vsavkin no worries and I got you ... I should be able to send a PR early next week 👍 |
Thank you! |
…to true ddress PR feedback by adding support of the forwardAllArgs option at a per command level and default to true ISSUES CLOSED: nrwl#3335
drop top level forwardAllArgs and only support this flag when using within a command object of the commands array ISSUES CLOSED: nrwl#3335
I would love to see this backported to 9.x. As far as I can tell it's not supported in 9.7.0:
|
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
When attempting to run multiple commands with arguments as shown in the docs, there are two scenarios:
{args.some_arg}
--name=testing
, the commandmkdir scripts
would actually runmkdir scripts --name=testing
Expected Behavior
Commands that do not use arguments should not have raw arguments appended to them as it can cause them to fail.
Steps to Reproduce
nrwl/nx-examples#109
Failure Logs
Reference repro PR.
Environment
@nrwl/angular : Not Found
@nrwl/cli : 9.5.1
@nrwl/cypress : 9.5.1
@nrwl/eslint-plugin-nx : 9.5.1
@nrwl/express : Not Found
@nrwl/jest : 9.5.1
@nrwl/linter : 9.5.1
@nrwl/nest : 9.5.1
@nrwl/next : 9.5.1
@nrwl/node : 9.5.1
@nrwl/react : 9.5.1
@nrwl/schematics : Not Found
@nrwl/tao : 9.5.1
@nrwl/web : 9.5.1
@nrwl/workspace : 9.5.1
typescript : 3.8.3
The text was updated successfully, but these errors were encountered: