发布

  • fix(testing)!: migrate @nx/jest to local dist build (#35713)

    frostbyte_neo 发布于 2026-05-17 21:39:48 +00:00

    Current Behavior

    @nx/jest builds into the shared dist/packages/jest directory at the
    workspace root and compiles with commonjs module resolution. It
    exposes no exports map, and first-party packages (@nx/detox,
    @nx/node) reach into @nx/jest/src/* for internal utilities. It also
    still re-exports the long-deprecated jestProjectGenerator alias.

    Expected Behavior

    @nx/jest builds locally into packages/jest/dist/ with nodenext
    module resolution and an exports map, matching the already-migrated
    nx, devkit, and js packages.

    • tsconfig.lib.json / tsconfig.spec.json switched to the nodenext +
      local-dist pattern.
    • package.json gains an exports map (., ./plugin, ./preset,
      ./plugins/resolver, ./internal, plus the JSON configs),
      typesVersions, and a files field.
    • project.json gains release (preserveLocalDependencyProtocols,
      manifestRootsToUpdate) and nx-release-publish configuration.
    • executors.json / generators.json / migrations.json factory and
      schema paths repointed to ./dist/src/....
    • assets.json outputs to the local dist/ and copies
      src/**/schema.json.
    • src/utils/versions.ts resolves its own package.json via a
      @nx/jest self-reference instead of a ../../ relative path, which
      breaks once source compiles into dist/.
    • The @nx/jest:jest executor imports its schema.json statically
      rather than via a dynamic await import.
    • A curated @nx/jest/internal entry (mirroring @nx/devkit/internal)
      replaces deep @nx/jest/src/* imports for first-party consumers;
      @nx/detox and @nx/node are routed through it.
    • A migration (rewrite-jest-internal-subpath-imports) rewrites user
      @nx/jest/src/* imports: named imports/exports of public symbols go to
      @nx/jest, everything else to @nx/jest/internal.
    • A migration (rewrite-jest-project-generator) rewrites
      jestProjectGenerator imported from @nx/jest to
      configurationGenerator.

    The dist-build-migration skill is also updated to document the
    symbol-aware routing rule for the migration step.

    Breaking Changes

    • The deprecated jestProjectGenerator export is removed — its "removed
      in Nx v22" notice is two majors overdue. It was always just an alias for
      configurationGenerator; the rewrite-jest-project-generator migration
      rewrites existing usages automatically.

    Related Issue(s)

    Tracked by Linear NXC-3592 — [M4] [Epic] Migrate @nx/jest to local dist. No GitHub issue.

    Pre-create review (run before PR open)

    Critical

    • The subpath-import migration originally rewrote every @nx/jest/src/*
      import to @nx/jest/internal, which would silently break consumers
      importing a public symbol (e.g. findJestConfig) that way. Fixed
      the migration now partitions named imports/exports: public symbols route
      to @nx/jest, internals to @nx/jest/internal, splitting mixed
      declarations into two.

    Important

    • export { ... } from '@nx/jest/src/*' and additional jest/vi mock
      helpers were not handled by the initial migration. Fixed — export
      declarations are now partitioned like imports, and all eight mock-helper
      methods are covered with tests.

    Suggestions

    • versions.ts self-resolve and the inferred build-base target were
      flagged; both verified correct (matches the @nx/js pattern;
      build-base is inferred by @nx/js/typescript from
      tsconfig.lib.json).
    • Softened an over-broad "used only" comment in eslint.config.mjs.

    Co-authored-by: nx-cloud[bot] <71083854+nx-cloud[bot]@users.noreply.github.com>

    下载附件