Skip to content

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

@njlaw

Description

@njlaw

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/[email protected] 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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions