Skip to content

fix(js): support auto mode for non-pnpm lock files in affected detection#35141

Open
llwt wants to merge 26 commits intomasterfrom
NXC-4185
Open

fix(js): support auto mode for non-pnpm lock files in affected detection#35141
llwt wants to merge 26 commits intomasterfrom
NXC-4185

Conversation

@llwt
Copy link
Copy Markdown
Member

@llwt llwt commented Apr 1, 2026

Current Behavior

The projectsAffectedByDependencyUpdates: "auto" setting only works for pnpm lock files. For npm (package-lock.json), yarn (yarn.lock), and bun (bun.lock/bun.lockb), auto mode silently returns an empty array -- meaning lockfile-only changes (e.g. npm audit fix, transitive dependency updates) produce zero affected projects.

Expected Behavior

Auto mode detects affected projects from lock file changes for all supported package managers:

  • pnpm (pnpm-lock.yaml): Inspects the importers section to determine exactly which workspace projects had dependency changes (unchanged).
  • npm (package-lock.json): Inspects the packages entries to determine which workspace projects had dependency changes.
  • bun (bun.lock): Inspects the workspaces section to determine which workspace projects had dependency changes.
  • yarn (yarn.lock): The lock file is a flat list with no per-project structure, so all projects are marked as affected when any dependency changes.
  • Binary lock files (bun.lockb) / WholeFileChange: Cannot be parsed for granular changes, so all projects are marked as affected.

The implementation uses a LOCK_FILE_RESOLVERS map with a SupportedLockFile type guard so that adding a new lock file format requires adding exactly one entry -- no separate lists to keep in sync.

Related Issue(s)

Follow-up to #34937 which documented the pnpm-only limitation.

Fixes NXC-4185
Fixes #35173

llwt added 8 commits April 1, 2026 23:04
Add failing tests for NXC-4185 covering projectsAffectedByDependencyUpdates
"auto" mode with npm, yarn, bun.lock, and bun.lockb. Each test uses
format-appropriate JSON diff paths matching the real lock file structure.

The .failing() tests document the current bug where auto mode silently
returns [] for non-pnpm package managers.
The projectsAffectedByDependencyUpdates "auto" setting previously only
worked for pnpm lock files, silently returning [] for npm, yarn, and bun.
This meant lockfile-only changes (e.g. npm audit fix, transitive dep
updates) produced zero affected projects for non-pnpm package managers.

Now each lock file format is handled:
- pnpm: parses "importers" to identify affected project paths (unchanged)
- npm: parses "packages" keys to extract project paths from node_modules paths
- yarn: returns all projects (flat format with no per-project structure)
- bun: parses "workspaces" to identify affected project paths
- binary files (bun.lockb): returns all projects as a safe fallback
The projectsAffectedByDependencyUpdates "auto" setting previously only
worked for pnpm lock files, silently returning [] for npm, yarn, and bun.
This meant lockfile-only changes (e.g. npm audit fix, transitive dep
updates) produced zero affected projects for non-pnpm package managers.

Now each lock file format is handled via a LOCK_FILE_RESOLVERS map:
- pnpm: parses "importers" to identify affected project paths (unchanged)
- npm: parses "packages" keys to extract project paths from node_modules paths
- yarn: returns all projects (flat format with no per-project structure)
- bun: parses "workspaces" to identify affected project paths
- binary files (bun.lockb): returns all projects as a safe fallback
…e managers

Pull in documentation from docs/js-plugin-config-options branch and update
to reflect that "auto" mode now works for all package managers, not just
pnpm. Includes per-package-manager behavior details in the affected docs
and updated reference table in nx-json.
Use a SupportedLockFile type guard with satisfies instead of
Record<string, ...> so the map index is type-safe. If the guard
fails to match, return null (all projects affected) rather than
calling an undefined function.
Remove analyze-source-files rewrite and nx-json plugins config section
that document analyzeSourceFiles, analyzePackageJson, and analyzeLockfile.
Those changes belong in the original docs/js-plugin-config-options branch,
not in this fix for projectsAffectedByDependencyUpdates.
@llwt llwt requested a review from a team as a code owner April 1, 2026 23:00
@llwt llwt requested a review from leosvelperez April 1, 2026 23:00
@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 1, 2026

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit bfd4922
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69fbe224825960000821b85d
😎 Deploy Preview https://deploy-preview-35141--nx-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 1, 2026

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit bfd4922
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69fbe224c5c83b0008b08b70
😎 Deploy Preview https://deploy-preview-35141--nx-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Apr 1, 2026

View your CI Pipeline Execution ↗ for commit 37715d5

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ❌ Failed 15m 54s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 2s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 14s View ↗
nx build workspace-plugin ✅ Succeeded <1s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 19s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 5s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-07 01:11:25 UTC

Comment thread packages/nx/src/plugins/js/project-graph/affected/lock-file-changes.ts Outdated
Replace the TODO comment with an actual logger.warn() call when an
unsupported lock file reaches the auto mode resolver. Add a test
for the unrecognized lock file case.
@llwt llwt marked this pull request as draft April 1, 2026 23:34
llwt added 4 commits April 2, 2026 01:40
Refactor auto mode to extract changed package names from lock file
diffs and return matching external node names from the project graph.
The existing graph reversal in filterAffected then walks from those
nodes to find affected workspace projects.

- Resolvers now extract package names instead of project paths
- Uses projectGraph.externalNodes to look up changed packages
- Yarn lock files can now identify specific changed packages instead
  of falling back to "all projects affected"
- Root-level npm dependency changes are now detected
- Removes RootPathLookup class (no longer needed)
Replace the JSON-diff-based heuristic for detecting changed packages with
a parser-based approach that reuses Nx's existing lock file parsers. The
base and head revisions are parsed and their external-node maps diffed
to identify packages whose versions actually changed, which avoids
brittle per-format path matching and correctly handles yarn.lock (which
JsonDiff could not meaningfully traverse).
@llwt llwt marked this pull request as ready for review April 17, 2026 19:40
@llwt llwt marked this pull request as draft April 17, 2026 19:44
nx-cloud[bot]

This comment was marked as outdated.

llwt added 3 commits April 17, 2026 16:36
Use is-odd and left-pad to avoid transitive dependency overlap that caused
the isolation test to fail. is-even@1.0.0 transitively depends on is-odd,
so bumping is-odd rippled through both libs.
@llwt llwt marked this pull request as ready for review April 17, 2026 20:51
Run the affected-auto-lockfile suite against pnpm, yarn, npm, and bun so
each supported lock-file parser is exercised end-to-end.
@FrozenPandaz FrozenPandaz added the priority: medium Medium Priority (not high, not low priority) label Apr 23, 2026
nx-cloud[bot]

This comment was marked as outdated.

nx-cloud Bot and others added 2 commits May 4, 2026 18:36
nx-cloud[bot]

This comment was marked as outdated.

AgentEnder and others added 3 commits May 6, 2026 17:28
Two CI failures caught after merging master into NXC-4185:

- getLockFileNodesForName defaulted to PackageJson = {}, which fails
  TypeScript's strict requirement that PackageJson has name/version.
  Cast the default literal so the runtime semantics (empty fallback for
  npm/pnpm/etc., real packageJson for yarn/bun) are preserved without a
  non-null assertion at the yarn/bun call site.

- calculateFileChanges' bun.lockb test inherited the existsSync=false
  mock from the previous "deleted file" test, causing it to return
  DeletedFileChange instead of LockFileChange. Mock existsSync=true
  inside the test so it does not depend on prior test state.
The previous commit (15eed2f) accidentally truncated lock-file.ts to
only the first 130 lines. Restoring full file content with the original
fix intact (PackageJson default cast and bun.lockb test mock).
nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

AgentEnder and others added 2 commits May 6, 2026 20:00
Yarn v4 requires the lockfile to be refreshed after creating a new
workspace package; without it, subsequent yarn operations fail with
"This package doesn't seem to be present in your lockfile". Adding an
intermediate install between the two @nx/js:lib generations in the
beforeAll setup unblocks the yarn-specific e2e and is a no-op for
pnpm/npm/bun.

Root cause analysis from Nx Cloud Self-Healing.
nx-cloud[bot]

This comment was marked as outdated.

nx-cloud[bot]

This comment was marked as outdated.

Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nx Cloud has identified a flaky task in your failed CI:

🔂 Since the failure was identified as flaky, we triggered a CI rerun by adding an empty commit to this branch.

Nx Cloud View detailed reasoning in Nx Cloud ↗

🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.


🎓 Learn more about Self-Healing CI on nx.dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: medium Medium Priority (not high, not low priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@nx/js plugin projectsAffectedByDependencyUpdates does not account for "resolutions" in package.json

3 participants