Skip to content

Commit 2f5e5b1

Browse files
authored
chore(linter): declare @nx/jest as optional peer dependency (#35377)
## Current Behavior `packages/eslint/src/generators/workspace-rules-project/workspace-rules-project.ts:37` calls `ensurePackage<typeof import('@nx/jest')>('@nx/jest', nxVersion)`. This runtime-optional reference (type-only import plus a string argument) is invisible to Nx's static project-graph analysis, so the graph has no `@nx/eslint → @nx/jest` edge today. Combined with the custom jest resolver in `scripts/patched-jest-resolver.js` — which maps `@nx/jest` subpaths to workspace source — the `eslint:test` task ends up reading `packages/jest/index.ts` and 19 files under `packages/jest/src/**` at module-load time. Those reads are undeclared inputs and are flagged as sandbox violations by the staging sandbox reports. ## Expected Behavior Declaring `@nx/jest` as an **optional** `peerDependency` of `@nx/eslint` materializes the missing edge in Nx's project graph (the graph reader in `explicit-package-json-dependencies.ts` walks `peerDependencies` alongside `dependencies`). The inferred test-task input `^production` is transitive, so `packages/jest/**` production source is then covered as declared inputs of `eslint:test` and the 20 violations disappear. `peerDependenciesMeta.@nx/jest.optional: true` keeps `@nx/jest` off the user's install surface — package managers don't auto-install it and don't warn about missing optional peers. Users who invoke the `workspace-rules-project` generator with jest scaffolding still get `@nx/jest` via the existing `ensurePackage` runtime install path, unchanged.
1 parent 2a3b0e5 commit 2f5e5b1

3 files changed

Lines changed: 13 additions & 3 deletions

File tree

packages/eslint/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"generators": "./generators.json",
3333
"executors": "./executors.json",
3434
"peerDependencies": {
35+
"@nx/jest": "workspace:*",
3536
"@zkochan/js-yaml": "0.0.7",
3637
"eslint": "^8.0.0 || ^9.0.0 || ^10.0.0"
3738
},
@@ -46,6 +47,9 @@
4647
"nx": "workspace:*"
4748
},
4849
"peerDependenciesMeta": {
50+
"@nx/jest": {
51+
"optional": true
52+
},
4953
"@zkochan/js-yaml": {
5054
"optional": true
5155
}

packages/eslint/tsconfig.lib.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515
],
1616
"include": ["**/*.ts"],
1717
"references": [
18-
{
19-
"path": "../nx/tsconfig.lib.json"
20-
},
2118
{
2219
"path": "../js/tsconfig.lib.json"
2320
},
2421
{
2522
"path": "../devkit/tsconfig.lib.json"
23+
},
24+
{
25+
"path": "../nx/tsconfig.lib.json"
26+
},
27+
{
28+
"path": "../jest/tsconfig.lib.json"
2629
}
2730
]
2831
}

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)