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

Updating package.json in any capacity causes all projects to be affected #12033

Closed
njlaw opened this issue Sep 15, 2022 · 3 comments · Fixed by #12185
Closed

Updating package.json in any capacity causes all projects to be affected #12033

njlaw opened this issue Sep 15, 2022 · 3 comments · Fixed by #12185
Assignees
Labels

Comments

@njlaw
Copy link

njlaw commented Sep 15, 2022

Current Behavior

The implicit dependencies for nx.json and package.json are overridden in getImplicitlyTouchedProjects to make all projects implicitly dependent on any changes to them. E.g., adding or updating a dependency in package.json causes all packages to be considered affected, regardless of the implicitDependencies setting in nx.json.
This is a regression from a previous version, although I haven't nailed down which version introduced this change yet. It works correctly with @nrwl/workspace@11.6.3 and

Expected Behavior

Adding or updating a dependency in package.json should only cause the packages that reference that dependency to be affected, plus any packages specified in implicitDependencies in nx.json.

Steps to Reproduce

  1. Verify there are no outstanding affected projects.
> npx create-nx-workspace@latest --name package-json-test --preset angular --style scss --nxCloud=false --appName frontend
> cd package-json-test
> git status
On branch main
nothing to commit, working tree clean
> nx print-affected | jq '.projects'
[]
  1. Add any package to package.json or edit package.json in any way.
  "dependencies": {
    ...
-   "zone.js": "~0.11.4"
+   "zone.js": "~0.11.4",
+   "random-package": "1.0.0"
  }
  1. Print affected projects.
> nx print-affected | jq '.projects'
[
  "frontend-e2e",
  "frontend"
]

These projects (all the projects in the workspace) should not be present since nothing depends on random-package.

For comparison Nx 11 & 12 output:

[
  "npm:random-package"
]

and Nx 13 outputs:

[]

Reproduction 2

Here is another reproduction that shows the issue from the perspective of an existing dependency: nrwl/nx-examples#227

Environment

 >  NX   Report complete - copy this into the issue template

   Node : 16.15.1
   OS   : linux x64
   pnpm : 7.11.0
   
   nx : 14.7.5
   @nrwl/angular : 14.7.5
   @nrwl/cypress : 14.7.5
   @nrwl/detox : Not Found
   @nrwl/devkit : 14.7.5
   @nrwl/eslint-plugin-nx : 14.7.5
   @nrwl/express : Not Found
   @nrwl/jest : 14.7.5
   @nrwl/js : 14.7.5
   @nrwl/linter : 14.7.5
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : Not Found
   @nrwl/react-native : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 14.7.5
   @nrwl/web : 14.7.5
   @nrwl/workspace : 14.7.5
   typescript : 4.8.3
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:

Other

In trying to see if I was setting options incorrectly, I traced the nx print-affected operation and think the issue lies at least partially in:

const implicits = { ...nxJson.implicitDependencies };
const globalFiles = [
...extractGlobalFilesFromInputs(nxJson, projectGraphNodes),
'nx.json',
'package.json',
];
globalFiles.forEach((file) => {
implicits[file] = '*' as any;
});

As I understand it, this code effectively ignores the nx.json implicitDependencies setting for nx.json and package.json, and treats it as though

{
  "implicitDependencies": {
    "nx.json": "*",
    "package.json": "*"
  }
}

were present.

@FrozenPandaz FrozenPandaz added the scope: core core nx functionality label Sep 23, 2022
@FrozenPandaz FrozenPandaz changed the title Updating package.json or nx.json in any capacity causes all projects to be affected Updating package.json in any capacity causes all projects to be affected Sep 23, 2022
@FrozenPandaz
Copy link
Collaborator

For nx.json, this is accurate. Because we don't store projects in nx.json anymore, pretty much any change to the file will be affect how Nx runs commands (hence affecting all projects it would run)

As for package.json, @meeroslav is working on something that will fix this.

@njlaw
Copy link
Author

njlaw commented Sep 24, 2022

As for package.json, @meeroslav is working on something that will fix this.

Thank you kindly! If there's anything I can do to help, please let me know.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants