Skip to content

fix(core): sandbox exclusions, multi-line typeof import detection, global ensurePackage mock#35056

Merged
FrozenPandaz merged 6 commits into
masterfrom
fix/sandboxing-and-import-analyzer
Mar 31, 2026
Merged

fix(core): sandbox exclusions, multi-line typeof import detection, global ensurePackage mock#35056
FrozenPandaz merged 6 commits into
masterfrom
fix/sandboxing-and-import-analyzer

Conversation

@FrozenPandaz

Copy link
Copy Markdown
Contributor

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)

@netlify

netlify Bot commented Mar 27, 2026

Copy link
Copy Markdown

Deploy Preview for nx-docs ready!

Name Link
🔨 Latest commit f587b8a
🔍 Latest deploy log https://app.netlify.com/projects/nx-docs/deploys/69caf01d1fb6330008852778
😎 Deploy Preview https://deploy-preview-35056--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

netlify Bot commented Mar 27, 2026

Copy link
Copy Markdown

Deploy Preview for nx-dev ready!

Name Link
🔨 Latest commit f587b8a
🔍 Latest deploy log https://app.netlify.com/projects/nx-dev/deploys/69caf01d8f0e5a0008be17f5
😎 Deploy Preview https://deploy-preview-35056--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

nx-cloud Bot commented Mar 27, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit f587b8a

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

☁️ Nx Cloud last updated this comment at 2026-03-30 22:14:40 UTC

@nx-cloud nx-cloud Bot left a comment

Copy link
Copy Markdown
Contributor

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

@FrozenPandaz FrozenPandaz marked this pull request as ready for review March 30, 2026 14:16
@FrozenPandaz FrozenPandaz requested a review from a team as a code owner March 30, 2026 14:16
@FrozenPandaz FrozenPandaz requested a review from MaxKless March 30, 2026 14:16
FrozenPandaz and others added 6 commits March 30, 2026 17:49
… 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]
@FrozenPandaz FrozenPandaz force-pushed the fix/sandboxing-and-import-analyzer branch from 7533e70 to f587b8a Compare March 30, 2026 21:50
@FrozenPandaz FrozenPandaz merged commit c59040f into master Mar 31, 2026
24 checks passed
@FrozenPandaz FrozenPandaz deleted the fix/sandboxing-and-import-analyzer branch March 31, 2026 15:25
FrozenPandaz added a commit that referenced this pull request Mar 31, 2026
…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)
@github-actions

github-actions Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

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.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants