fix(linter): do not infer projects from package.json files outside the workspaces - #36510
Draft
FrozenPandaz wants to merge 2 commits into
Draft
fix(linter): do not infer projects from package.json files outside the workspaces#36510FrozenPandaz wants to merge 2 commits into
FrozenPandaz wants to merge 2 commits into
Conversation
…e workspaces
The plugin's glob includes `**/package.json`, and `splitConfigFiles` promoted
every matching directory to a project root. Nested marker files — a
`{"sideEffects": false}` next to a bundle, a polyfill directory's stub — have
no `name`, so the whole graph then fails:
NX Failed to process project graph.
The projects in the following directories have no name provided:
- packages/unenv-preset/src/runtime/polyfill
Filter package.json files through the package manager's workspaces globs, the
same guard Nx core's own package-json plugin applies. A package.json sitting
next to a project.json is still a project regardless of the globs.
When no workspaces are declared the filter is skipped entirely: the patterns
come back empty and the matcher would reject everything, including the root
package.json of a standalone repo that is itself the project.
Verified against this repo: the 145-project graph is identical either way.
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for nx-dev ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
|
View your CI Pipeline Execution ↗ for commit fbc14e3
☁️ Nx Cloud last updated this comment at |
Contributor
There was a problem hiding this comment.
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.
🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.
🎓 Learn more about Self-Healing CI on nx.dev
…e workspaces [Self-Healing CI Rerun]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Current Behavior
@nx/eslint's inference plugin globs**/package.json, andsplitConfigFilespromotes every matching directory to a project root:Nested
package.jsonfiles are very often markers, not projects — a{"sideEffects": false}beside a bundle, a polyfill directory stub, aworkers-sitefolder. Those have noname, so once promoted they fail the entire graph:The throw is unconditional (
project-nodes-manager.ts:268), so one stray marker file takes down the whole workspace — and the error names a directory the user never asked to be a project, which makes it hard to trace back to the linter plugin.Nx core's own package-json plugin already guards against exactly this in
packages/nx/src/plugins/package-json/create-nodes.ts:@nx/eslintdid not.Expected Behavior
Package.json files are filtered through the package manager's workspaces globs before becoming project roots, reusing the core helpers (
buildPackageJsonPatterns/buildPackageJsonWorkspacesMatcher) so the two plugins cannot drift. A package.json sitting next to aproject.jsonis still a project regardless of the globs.The non-obvious part
The "no workspaces declared" case has to skip the filter entirely:
With no
workspacesfield,buildPackageJsonPatternsreturns empty patterns and the matcher rejects everything — including the rootpackage.jsonof a standalone repo that is the project. Filtering unconditionally deletes the root project and breaks the existing'.'tests. This guard is load-bearing, not defensive.Validation
Test-first. The new spec was confirmed red against the unfixed plugin, and the failure is precisely the bug:
Green after the fix.
build,testandlintall pass for@nx/eslint(31 tests; the single remaining lint warning is a pre-existing skipped test atplugin.spec.ts:89).No collateral damage. I captured
nx show projectsfor this repo with and without the change: 145 projects, byte-identical both ways. The fix only removes bogus promotions — it does not drop a single real project. The pre-existing test asserting that a namelessapps/my-app/package.jsondoes get a node (no workspaces declared) still passes, which is the guard above doing its job.Related Issue(s)
NXC-4746 — https://linear.app/nxdev/issue/NXC-4746/nxeslint-infers-projects-from-packagejson-files-outside-the-package
The same defect exists in
@nx/oxlintand is being fixed on #36491, where it was originally found. This half is independent and ships today, so it is split out here.