Commit 732a08c
chore(core): build nx to local dist and use nodenext (#34111)
## Current Behavior
The `nx` package compiles its TypeScript output to
`../../dist/packages/nx/` (relative to the package root), which places
build artifacts outside the package directory at the repo root level
(`dist/packages/nx/`). This makes the package structure harder to reason
about, complicates the build pipeline, and doesn't align with how most
packages organize their output.
The package uses `"module": "commonjs"` with basic module resolution,
which limits future migration paths toward ESM.
## Expected Behavior
The `nx` package now builds to a local `dist/` directory within the
package itself (`packages/nx/dist/`). This is a cleaner, more standard
layout — like having your tools in your own toolbox instead of scattered
across the workshop.
### Key changes:
**Build configuration (`packages/nx/tsconfig.lib.json`):**
- `outDir` changed from `../../dist/packages/nx` to `dist` (local to
package)
- `module` changed to `nodenext` with `moduleResolution: nodenext`
- Updated `include` patterns to explicitly list source directories
**Package entry points (`packages/nx/package.json`):**
- `bin` paths updated: `./bin/nx.js` → `./dist/bin/nx.js`
- Added `"type": "commonjs"` explicitly
- Added comprehensive `exports` map with `@nx/nx-source` condition for
dev/test resolution back to TS source
- Added `postinstall` path update to `./dist/bin/post-install`
**Module resolution fixes:**
- Created `src/utils/handle-import.ts` — a CJS-first import utility that
falls back to ESM `import()` for ESM-only packages, providing a single
migration point for future ESM work
- Converted dynamic `await import()` calls to
`require(require.resolve())` pattern where needed to satisfy `nodenext`
extension requirements
- Plugin worker spawn path now uses correct `.ts`/`.js` extension based
on runtime context (source vs compiled)
**Test infrastructure:**
- Added custom `jest-resolver.js` for the `nx` package that resolves
`nx/...` imports using the `@nx/nx-source` exports condition, so tests
run against TS source
- Updated `jest.preset.js` with SWC transformer configuration
- Added chalk mock for test compatibility
**CI and tooling:**
- Conformance check updated to build `workspace-plugin` first (the Nx
Cloud runner lacks `@swc-node/register` for TS resolution)
- Conformance rule paths in `nx.json` now point to compiled
`dist/workspace-plugin/src/...` output
- Added `dist` to eslint ignore patterns to prevent linting compiled
output
- Added workspace-plugin build target and updated its dependencies
**Other fixes:**
- Various import path fixes across `create-nx-workspace`, gradle, and
other packages to work with `nodenext` resolution
- Updated e2e test paths to reference the new dist location
- Fixed `.gitignore` and `.npmignore` for the new output structure
## Related Issue(s)
Internal infrastructure improvement — no external issue.
---------
Co-authored-by: nx-cloud[bot] <71083854+nx-cloud[bot]@users.noreply.github.com>
Co-authored-by: Coly010 <Coly010@users.noreply.github.com>
Co-authored-by: FrozenPandaz <jasonjean1993@gmail.com>1 parent d5f51d6 commit 732a08c
267 files changed
Lines changed: 2659 additions & 1399 deletions
File tree
- .github/workflows
- astro-docs
- src/plugins/utils
- e2e
- angular
- dotnet
- esbuild
- expo/src
- jest/src
- maven
- src/utils
- nx/src
- react-native/src
- utils
- graph
- migrate
- project-details
- ui-project-details
- packages
- angular
- src/generators
- application
- library-secondary-entry-point
- __snapshots__
- ngrx
- __snapshots__
- setup-tailwind
- web-worker
- create-nx-plugin
- create-nx-workspace
- bin
- src
- internal-utils
- utils
- ci
- git
- nx
- cypress
- src
- executors/cypress
- utils
- detox
- src/generators/convert-to-inferred
- devkit
- src/utils
- docker
- dotnet
- esbuild
- eslint-plugin
- eslint
- src/executors/lint
- utility
- expo
- src
- generators
- application
- convert-to-inferred
- utils
- express
- gradle
- project-graph
- jest
- src/executors/jest
- js
- src
- executors
- node
- release-publish
- verdaccio
- utils
- code-frames
- typescript
- maven
- module-federation
- src
- plugins/utils
- utils
- nest
- src/generators
- application
- init
- library
- utils
- next
- src/generators/convert-to-inferred
- node
- src/generators/application
- nuxt
- nx
- bin
- src
- adapter
- ai/set-up-ai-agents
- command-line
- add
- affected
- configure-ai-agents
- daemon
- exec
- format
- generate
- graph
- import
- init
- implementation
- dot-nx
- list
- mcp
- migrate
- new
- nx-cloud
- apply-locally
- complete-run
- connect
- download-cloud-client
- fix-ci
- login
- logout
- polygraph
- record
- start-agent
- start-ci-run
- register
- release
- utils
- remote-release-clients
- version
- repair
- report
- reset
- run-many
- run
- show
- sync
- watch
- daemon
- client
- server
- executors
- run-commands
- run-script
- internal-testing-utils
- migrations
- update-16-2-0
- update-17-0-0
- native/watch
- plugins/js/package-json
- project-graph
- plugins
- isolation
- tasks-runner
- life-cycles
- running-tasks
- utils
- playwright
- plugin
- react-native
- src
- generators
- application
- convert-to-inferred
- library
- web-configuration/files/base-vite
- utils
- react
- src/executors/module-federation-static-server
- remix
- rollup
- src/plugins/with-nx
- rsbuild
- rspack
- src/generators/convert-to-inferred
- storybook
- src/generators
- configuration
- migrate-8
- vitest
- vite
- vue
- webpack
- src
- executors
- dev-server
- webpack/lib
- generators/convert-to-inferred
- plugins/nx-webpack-plugin/lib
- utils
- web
- workspace
- jest-mocks
- src
- generators
- new
- preset
- utilities
- scripts
- documentation
- jest-mocks
- tools
- eslint-rules
- workspace-plugin
- src/conformance-rules
- migration-groups
- project-package-json
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
89 | 89 | | |
90 | 90 | | |
91 | 91 | | |
92 | | - | |
| 92 | + | |
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
131 | 131 | | |
132 | 132 | | |
133 | 133 | | |
| 134 | + | |
134 | 135 | | |
135 | 136 | | |
136 | 137 | | |
| |||
145 | 146 | | |
146 | 147 | | |
147 | 148 | | |
148 | | - | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
24 | 30 | | |
25 | 31 | | |
26 | 32 | | |
| |||
33 | 39 | | |
34 | 40 | | |
35 | 41 | | |
36 | | - | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
37 | 49 | | |
38 | 50 | | |
39 | 51 | | |
| |||
Lines changed: 12 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
44 | 55 | | |
45 | 56 | | |
46 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | | - | |
7 | | - | |
| 6 | + | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
200 | 200 | | |
201 | 201 | | |
202 | 202 | | |
203 | | - | |
204 | | - | |
205 | | - | |
| 203 | + | |
206 | 204 | | |
207 | 205 | | |
208 | 206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| |||
0 commit comments