Skip to content

Commit 732a08c

Browse files
Coly010nx-cloud[bot]FrozenPandaz
authored
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

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
pnpm nx-cloud record -- nx sync:check
9090
pids+=($!)
9191
92-
pnpm nx-cloud record -- nx-cloud conformance:check
92+
pnpm nx build workspace-plugin && pnpm nx-cloud record -- pnpm nx conformance:check
9393
pids+=($!)
9494
9595
pnpm nx run-many -t check-imports check-lock-files check-codeowners --parallel=1 --no-dte &

.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ packages/angular-rspack/README.md
131131
packages/angular-rspack-compiler/README.md
132132
packages/dotnet/README.md
133133
packages/maven/README.md
134+
packages/nx/README.md
134135

135136
test-output
136137
test-results
@@ -145,4 +146,11 @@ test-results
145146
.nx/polygraph
146147
.claude/worktrees
147148

148-
.nx/self-healing
149+
.nx/self-healing
150+
# Nx Typings Output
151+
packages/nx/**/*.d.ts
152+
!packages/nx/src/utils/perf-hooks.d.ts
153+
!packages/nx/src/ai/set-up-ai-agents/schema.d.ts
154+
!packages/nx/src/native/index.d.ts
155+
e2e/**/*.d.ts
156+
e2e/**/*.d.ts.map

astro-docs/project.json

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@
2020
"dependsOn": [
2121
"prebuild-banner",
2222
{
23-
"projects": ["devkit", "create-nx-workspace", "dotnet", "maven"],
23+
"projects": [
24+
"nx",
25+
"devkit",
26+
"create-nx-workspace",
27+
"dotnet",
28+
"maven"
29+
],
2430
"target": "build"
2531
}
2632
],
@@ -33,7 +39,13 @@
3339
"dependsOn": [
3440
"prebuild-banner",
3541
{
36-
"projects": ["devkit", "create-nx-workspace", "dotnet", "maven"],
42+
"projects": [
43+
"nx",
44+
"devkit",
45+
"create-nx-workspace",
46+
"dotnet",
47+
"maven"
48+
],
3749
"target": "build"
3850
}
3951
],

astro-docs/src/plugins/utils/get-schema-example-content.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,18 @@ export function getExampleForSchema(
4040
}
4141
const exampleFilePath = schema[EXAMPLE_SCHEMA_KEY];
4242
const schemaDirName = dirname(schemaPath);
43-
const docPath = resolvePath(schemaDirName, exampleFilePath);
43+
let docPath = resolvePath(schemaDirName, exampleFilePath);
44+
45+
// If the resolved path doesn't exist and the schema is in a dist/ directory,
46+
// try resolving from the source tree instead, since docs files
47+
// may not be copied to dist during the build.
48+
if (!existsSync(docPath) && schemaPath.includes('/dist/src/')) {
49+
const sourceSchemaDir = dirname(schemaPath.replace('/dist/src/', '/src/'));
50+
const sourceDocPath = resolvePath(sourceSchemaDir, exampleFilePath);
51+
if (existsSync(sourceDocPath)) {
52+
docPath = sourceDocPath;
53+
}
54+
}
4455

4556
if (!existsSync(docPath)) {
4657
throw new Error(

e2e/angular/tsconfig.spec.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"**/*.test.js",
1414
"**/*.spec.jsx",
1515
"**/*.test.jsx",
16+
"src/**/*.ts",
1617
"**/*.d.ts",
1718
"jest.config.ts"
1819
]

e2e/dotnet/tsconfig.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
{
22
"extends": "../../tsconfig.base.json",
33
"compilerOptions": {
4-
"allowJs": true
4+
"types": ["node", "jest"]
55
},
6-
"include": ["**/*.ts", "**/*.js"],
7-
"exclude": ["node_modules", "dist"],
6+
"include": [],
7+
"files": [],
88
"references": [
99
{
1010
"path": "../utils"
11+
},
12+
{
13+
"path": "./tsconfig.spec.json"
1114
}
1215
]
1316
}

e2e/esbuild/tsconfig.spec.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"**/*.test.js",
1414
"**/*.spec.jsx",
1515
"**/*.test.jsx",
16+
"src/**/*.ts",
1617
"**/*.d.ts",
1718
"jest.config.ts"
1819
]

e2e/expo/src/expo-legacy.test.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,7 @@ describe('@nx/expo (legacy)', () => {
200200
it('should tsc app', async () => {
201201
expect(() => {
202202
const pmc = getPackageManagerCommand();
203-
runCommand(
204-
`${pmc.runUninstalledPackage} tsc -p apps/${appName}/tsconfig.app.json`
205-
);
203+
runCommand(`${pmc.exec} tsc -p apps/${appName}/tsconfig.app.json`);
206204
checkFilesExist(
207205
`dist/out-tsc/apps/${appName}/src/app/App.js`,
208206
`dist/out-tsc/apps/${appName}/src/app/App.d.ts`,

e2e/jest/src/jest.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('Jest', () => {
3131
const results = await runCLIAsync(`test ${name} --skip-nx-cache`, {
3232
silenceError: true,
3333
env: {
34-
...process.env, // need to set this for some reason, or else get "env: node: No such file or directory"
34+
...getStrippedEnvironmentVariables(),
3535
NODE_ENV: 'foobar',
3636
},
3737
});

e2e/maven/src/utils/create-maven-project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
unlinkSync,
1515
chmodSync,
1616
} from 'fs';
17-
import * as extract from 'extract-zip';
17+
import extract from 'extract-zip';
1818

1919
async function downloadFile(
2020
url: string,

0 commit comments

Comments
 (0)