nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
22.7k stars 2.27k forks source link

[run-commands-executor]: Difference when running `command` and `commands` #9149

Closed YonatanKra closed 2 years ago

YonatanKra commented 2 years ago

Current Behavior

When running the command like this:

options: {
  command: "./scripts/run.script.sh {args.task}"
}

It works fine.

Trying to run it like this:

options: {
  commands: ["./scripts/run.script.sh {args.task}"]
}

Results in an error.

Expected Behavior

I'd expect the two commands to run the same way.

Steps to Reproduce

  1. git clone https://github.com/Vonage/vivid-3.git
  2. git checkout nx-run-commands-bug
  3. npm i
  4. Run npx nx run components:e2e and see it fails
  5. Edit libs/components/project.json and change e2e: {options: { commands: []} } to the command syntax (e.g. e2e: { options: { command: "" } }).
  6. Run npx nx run components:e2e and see it succeeds in running the e2e tests

Failure Logs

Environment

 >  NX   Report complete - copy this into the issue template

   Node : 16.13.0
   OS   : darwin x64
   npm  : 8.1.0

   nx : 13.8.2
   @nrwl/angular : undefined
   @nrwl/cli : 13.8.2
   @nrwl/cypress : 13.8.2
   @nrwl/detox : 13.4.1
   @nrwl/devkit : 13.8.2
   @nrwl/eslint-plugin-nx : 13.8.2
   @nrwl/express : undefined
   @nrwl/jest : 13.8.2
   @nrwl/js : 13.8.2
   @nrwl/linter : 13.8.2
   @nrwl/nest : undefined
   @nrwl/next : undefined
   @nrwl/node : 13.8.2
   @nrwl/nx-cloud : undefined
   @nrwl/react : 13.4.1
   @nrwl/react-native : 13.4.1
   @nrwl/schematics : undefined
   @nrwl/storybook : 13.4.1
   @nrwl/tao : 13.8.2
   @nrwl/web : 13.8.2
   @nrwl/workspace : 13.8.2
   typescript : 4.4.4
   rxjs : 6.6.7
   ---------------------------------------
   Community plugins:
         nx-stylelint: 13.1.0
AgentEnder commented 2 years ago

@YonatanKra cloning your repo I noticed the error message "the input device is not a TTY" when using "commands" instead of "command".

This is because "commands" defaults to parallel execution, so the stdio options cannot be inherited. If you add "parallel": false to the options object, your e2e target should work with "commands"

Am I good to close this, or do you have some further question / request?

YonatanKra commented 2 years ago

Thanks @AgentEnder . What if I need to run several commands in parallel (which is the main purpose for moving to the commands syntax). What's the cause for the difference?

AgentEnder commented 2 years ago

Check out the difference in implementation of the 2 functions referenced here: https://github.com/nrwl/nx/blob/master/packages/workspace/src/executors/run-commands/run-commands.impl.ts#L81

The gist is that processes ran in parallel cannot inherit stdin, and the docker run script you are invoking is throwing if it cannot process stdin.

YonatanKra commented 2 years ago

Amazing! Thanks a lot!

github-actions[bot] commented 1 year ago

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.