fix(core): sandbox exclusions, multi-line typeof import detection, global ensurePackage mock#35056
Conversation
✅ 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. |
|
View your CI Pipeline Execution ↗ for commit f587b8a
☁️ Nx Cloud last updated this comment at |
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
… reads tsc --build reads .tsbuildinfo files as an optimization hint to skip recompilation. These are outputs of the build, not true inputs, so sandboxing should not flag them. The nx-plugin-checks lint rule reads schema.json from dist/ directories because executors.json points there. Exclude dist JSON reads for lint targets since the lint output is unaffected by schema content.
The import analyzer failed to detect `typeof import('...')` when it
spanned multiple lines inside generic type parameters, e.g.:
ensurePackage<
typeof import('@nx/playwright')
>('@nx/playwright', nxVersion);
The newline between `<` and `import()` reset the import type to Dynamic,
losing the static context set by the generic opener. Fix by tracking open
angle bracket depth and preserving import type across newlines inside
generics.
This caused packages like @nx/playwright and @nx/storybook to be missing
from the dependency graph when only referenced via ensurePackage.
Move the ensurePackage mock into the global unit-test-setup.js so all tests automatically resolve ensurePackage calls from source code via jest.requireActual instead of from node_modules. Remove the per-file @nx/devkit mocks that were duplicating this logic.
Move the ensurePackage mock into the global unit-test-setup.js so all tests automatically resolve ensurePackage calls from source code via jest.requireActual instead of from node_modules. Remove the per-file @nx/devkit mocks that were duplicating this logic. [Self-Healing CI Rerun]
Move the ensurePackage mock into the global unit-test-setup.js so all tests automatically resolve ensurePackage calls from source code via jest.requireActual instead of from node_modules. Remove the per-file @nx/devkit mocks that were duplicating this logic. [Self-Healing CI Rerun]
7533e70 to
f587b8a
Compare
…obal ensurePackage mock (#35056) ## Current Behavior 1. **Sandboxing false positives**: `tsc --build` reads `.tsbuildinfo` files as an optimization hint, and the `nx-plugin-checks` lint rule reads `schema.json` from `dist/` directories. Both are flagged as sandbox violations even though they don't affect caching correctness. 2. **Missing dependencies in project graph**: `typeof import('...')` inside multi-line generic type parameters (e.g. `ensurePackage<typeof import('@nx/playwright')>()`) is not detected by the import analyzer. The newline between `<` and `import()` resets the import type to Dynamic, so packages like `@nx/playwright` and `@nx/storybook` are missing from the dependency graph. 3. **ensurePackage mock duplication**: Multiple test files individually mock `@nx/devkit` just to override `ensurePackage` so it resolves from source instead of `node_modules`. This is repetitive and easy to miss in new tests. ## Expected Behavior 1. **Sandboxing**: `.tsbuildinfo` reads are globally excluded. `dist/**/*.json` reads are excluded for lint targets. 2. **Import analyzer**: `typeof import('...')` inside multi-line generics is correctly detected as a static import by tracking angle bracket depth and preserving import type across newlines inside generics. 3. **ensurePackage mock**: A global `ensurePackage` mock in `scripts/unit-test-setup.js` replaces per-file mocks, using `jest.requireActual` to resolve from source code. ## Related Issue(s) <!-- No directly related open issues found --> --------- Co-authored-by: nx-cloud[bot] <71083854+nx-cloud[bot]@users.noreply.github.com> (cherry picked from commit c59040f)
|
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Current Behavior
Sandboxing false positives:
tsc --buildreads.tsbuildinfofiles as an optimization hint, and thenx-plugin-checkslint rule readsschema.jsonfromdist/directories. Both are flagged as sandbox violations even though they don't affect caching correctness.Missing dependencies in project graph:
typeof import('...')inside multi-line generic type parameters (e.g.ensurePackage<typeof import('@nx/playwright')>()) is not detected by the import analyzer. The newline between<andimport()resets the import type to Dynamic, so packages like@nx/playwrightand@nx/storybookare missing from the dependency graph.ensurePackage mock duplication: Multiple test files individually mock
@nx/devkitjust to overrideensurePackageso it resolves from source instead ofnode_modules. This is repetitive and easy to miss in new tests.Expected Behavior
Sandboxing:
.tsbuildinforeads are globally excluded.dist/**/*.jsonreads are excluded for lint targets.Import analyzer:
typeof import('...')inside multi-line generics is correctly detected as a static import by tracking angle bracket depth and preserving import type across newlines inside generics.ensurePackage mock: A global
ensurePackagemock inscripts/unit-test-setup.jsreplaces per-file mocks, usingjest.requireActualto resolve from source code.Related Issue(s)