nrwl / nx

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

Dependent targets receive the original arguments and break #10653

Closed dstoyanoff closed 2 years ago

dstoyanoff commented 2 years ago

Current Behavior

I have a repo with yarn workspaces and nx. When executing test for a certain project, I need to build all its dependent projects. For that, I have configured the following in my nx.json:

    "test": [
      {
        "target": "build",
        "projects": "dependencies"
      }
    ]

Then I run nx test ui -u to execute jest with updating snapshots. When this happens, nx forwards the -u argument to my build command, which fails because that's not a recognized parameter.

Expected Behavior

The build should not receive the arguments or at least there should be a way to specify which arguments to get forwarded (perhaps in the dependency definition).

Steps to Reproduce

Failure Logs

hooks project is a dependency of ui, so this is what gets executed eventually

> nx run hooks:build --coverage
yarn run v1.22.18
$ rollup -c && tsc-alias --coverage=true
src/index.ts → dist/index.cjs.js, dist/index.js...
created dist/index.cjs.js, dist/index.js in 7.3s
error: unknown option '--coverage=true'
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Environment

$ nx report

>  NX  Report complete - copy this into the issue template

  Node : 16.13.1
  OS   : darwin x64
  yarn : 1.22.17

  nx : 13.3.0
  @nrwl/angular : 13.3.0
  @nrwl/cli : 13.3.0
  @nrwl/cypress : 13.3.0
  @nrwl/devkit : 13.3.0
  @nrwl/eslint-plugin-nx : 13.3.0
  @nrwl/express : undefined
  @nrwl/jest : 13.3.0
  @nrwl/linter : 13.3.0
  @nrwl/nest : undefined
  @nrwl/next : undefined
  @nrwl/node : 13.3.0
  @nrwl/nx-cloud : undefined
  @nrwl/react : undefined
  @nrwl/react-native : undefined
  @nrwl/schematics : undefined
  @nrwl/tao : 13.3.0
  @nrwl/web : undefined
  @nrwl/workspace : 13.3.0
  @nrwl/storybook : 13.3.0
  @nrwl/gatsby : undefined
  typescript : 4.4.4
  rxjs : 7.4.0
  ---------------------------------------
  Community plugins:
     @angular/animations: 13.0.3
     @angular/cdk: 13.0.3
     @angular/common: 13.0.3
     @angular/compiler: 13.0.3
     @angular/core: 13.0.3
     @angular/forms: 13.0.3
     @angular/localize: 13.0.3
     @angular/material: 13.0.3
     @angular/platform-browser: 13.0.3
     @angular/platform-browser-dynamic: 13.0.3
     @angular/router: 13.0.3
     @angular/service-worker: 13.0.3
     @ngrx/component: 13.0.2
     @ngrx/component-store: 13.0.2
     @ngrx/effects: 13.0.2
     @ngrx/entity: 13.0.2
     @ngrx/router-store: 13.0.2
     @ngrx/store: 13.0.2
     @angular-devkit/build-angular: 13.0.4
     @angular/cli: 13.0.4
     @angular/compiler-cli: 13.0.3
     @angular/language-service: 13.0.3
     @ngrx/schematics: 13.0.2
     @ngrx/store-devtools: 13.0.2
     @nrwl/nx-plugin: 13.3.0
     ng-mocks: 12.5.0
FrozenPandaz commented 2 years ago

Could you please provide a repo please?

Are test and build package.json scripts or using the nx:run-commands executor?

We have logic in place that will not propogate arguments to different executors for this exact reason. However, I could see an issue when you're using the same executor (nx:run-commands) but for 2 different reasons. :eyes:

But please provide a repro for us so we can reproduce this easily. :pray:

dstoyanoff commented 2 years ago

Hello, Unfortunately the repo is private and will be quite time consuming to replicate. In this case, it's a yarn workspace with separate package.json's per project, so in this case, I am targeting existing npm scripts.

Im the example above, nx run hooks:build --coverage would call the build target on the hooks project, passing --coverage additionally. This would in-fact trigger a build on self and hooks's dependent projects, passing --coverage

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

dstoyanoff commented 2 years ago

Not stale.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

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.