@nx/js 23.1.0-rc.1 → 23.1.0-rc.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -16,15 +16,21 @@ import { type Tree } from '@nx/devkit';
16
16
  * when the inferred directory already equals the tsconfig directory: inference
17
17
  * is per-program, and tools like ts-jest's `isolatedModules` compile single
18
18
  * files against the same config, collapsing the common directory below the
19
- * config dir and failing with TS5011. Only composite configs are exempt — their
20
- * `rootDir` defaults to the tsconfig directory in both versions regardless of
21
- * the file set.
19
+ * config dir and failing with TS5011.
20
+ *
21
+ * Composite configs are pinned too, to the tsconfig's own directory. Under `tsc`
22
+ * a composite `rootDir` already defaults there (for any file subset), so `"."`
23
+ * is a no-op — but ts-jest strips `composite` for its per-file transpile, and
24
+ * TypeScript 6 only exempts genuinely-composite programs from the containment
25
+ * check (`!options.composite`), so a composite spec config compiled by ts-jest
26
+ * hits TS5011 all the same. The explicit `"."` survives the strip. Pinning the
27
+ * own directory (not a deeper file-derived value) keeps a real composite build's
28
+ * emit layout unchanged.
22
29
  *
23
30
  * Each config is written on its own; nothing is written to a shared `extends`
24
- * base, so a config never inherits a `rootDir` computed for a sibling. The one
25
- * case that needs care is a config that both needs a `rootDir` and is itself an
26
- * `extends` base: a composite child would inherit the new value and shift its
27
- * emit layout, so each such child is pinned to its own directory to block it.
28
- * Runs only on TypeScript 6 workspaces (gated by `requires`).
31
+ * base, so a config never inherits a `rootDir` computed for a sibling and
32
+ * because every config that emits is given its own explicit `rootDir`, none
33
+ * inherits a value pinned on a base. Runs only on TypeScript 6 workspaces
34
+ * (gated by `requires`).
29
35
  */
30
36
  export default function (tree: Tree): Promise<void>;
@@ -26,16 +26,22 @@ let tsModule;
26
26
  * when the inferred directory already equals the tsconfig directory: inference
27
27
  * is per-program, and tools like ts-jest's `isolatedModules` compile single
28
28
  * files against the same config, collapsing the common directory below the
29
- * config dir and failing with TS5011. Only composite configs are exempt — their
30
- * `rootDir` defaults to the tsconfig directory in both versions regardless of
31
- * the file set.
29
+ * config dir and failing with TS5011.
30
+ *
31
+ * Composite configs are pinned too, to the tsconfig's own directory. Under `tsc`
32
+ * a composite `rootDir` already defaults there (for any file subset), so `"."`
33
+ * is a no-op — but ts-jest strips `composite` for its per-file transpile, and
34
+ * TypeScript 6 only exempts genuinely-composite programs from the containment
35
+ * check (`!options.composite`), so a composite spec config compiled by ts-jest
36
+ * hits TS5011 all the same. The explicit `"."` survives the strip. Pinning the
37
+ * own directory (not a deeper file-derived value) keeps a real composite build's
38
+ * emit layout unchanged.
32
39
  *
33
40
  * Each config is written on its own; nothing is written to a shared `extends`
34
- * base, so a config never inherits a `rootDir` computed for a sibling. The one
35
- * case that needs care is a config that both needs a `rootDir` and is itself an
36
- * `extends` base: a composite child would inherit the new value and shift its
37
- * emit layout, so each such child is pinned to its own directory to block it.
38
- * Runs only on TypeScript 6 workspaces (gated by `requires`).
41
+ * base, so a config never inherits a `rootDir` computed for a sibling and
42
+ * because every config that emits is given its own explicit `rootDir`, none
43
+ * inherits a value pinned on a base. Runs only on TypeScript 6 workspaces
44
+ * (gated by `requires`).
39
45
  */
40
46
  async function default_1(tree) {
41
47
  tsModule ??= (0, ensure_typescript_1.ensureTypescript)();
@@ -54,7 +60,10 @@ async function default_1(tree) {
54
60
  analysis: analyze(ts, absPath, parseConfigHost),
55
61
  };
56
62
  });
57
- // Phase 2: pin each config that needs a `rootDir` on its own.
63
+ // Phase 2: pin each config that needs a `rootDir` on its own. Every config
64
+ // that emits is given its own explicit value here — including composites,
65
+ // pinned to their own directory — so none is left to inherit a `rootDir` this
66
+ // migration pins on a base.
58
67
  let changed = 0;
59
68
  for (const c of candidates) {
60
69
  if (c.analysis.kind === 'write') {
@@ -64,36 +73,6 @@ async function default_1(tree) {
64
73
  }
65
74
  }
66
75
  }
67
- // Phase 3: shield composite configs that now inherit a pinned `rootDir` from
68
- // a base. Re-parse each from the tree (so Phase 2's writes are visible); when
69
- // TypeScript reports an inherited `rootDir` where there was none, pin the
70
- // config to its own directory so its emit layout does not shift. Repeat until
71
- // stable, since shielding one config can turn it into a base for another. The
72
- // tree-backed host lets TypeScript resolve `extends`; the `readDirectory`
73
- // no-op skips the unused file scan.
74
- const readFile = (filePath) => tree.read(filePath, 'utf-8') ?? undefined;
75
- const treeParseHost = {
76
- ...ts.sys,
77
- readFile,
78
- readDirectory: () => [],
79
- };
80
- const shielded = new Set();
81
- let added = true;
82
- while (added) {
83
- added = false;
84
- for (const c of candidates) {
85
- if (c.analysis.kind !== 'composite' || shielded.has(c.relPath)) {
86
- continue;
87
- }
88
- if (inheritsRootDir(ts, treeParseHost, readFile, c.relPath)) {
89
- if (setRootDir(tree, c.relPath, '.')) {
90
- changed++;
91
- }
92
- shielded.add(c.relPath);
93
- added = true;
94
- }
95
- }
96
- }
97
76
  if (changed > 0) {
98
77
  await (0, devkit_1.formatFiles)(tree);
99
78
  }
@@ -110,12 +89,14 @@ function analyze(ts, absPath, parseConfigHost) {
110
89
  if (!setsEmitGate(options) || fileNames.length === 0) {
111
90
  return { kind: 'inert' };
112
91
  }
113
- // Composite already defaults `rootDir` to the tsconfig's own directory in both
114
- // 5.x and 6.0, so the 6.0 change leaves it alone. Never pin a file-derived
115
- // value; only shield it from a `rootDir` this migration pins on an `extends`
116
- // base.
92
+ // Composite: pin the tsconfig's own directory, not a file-derived value.
93
+ // `rootDir` already defaults there under `tsc`, so `"."` preserves a real
94
+ // composite build's emit layout but ts-jest strips `composite` for its
95
+ // per-file transpile, and TS6 only skips the containment check for genuinely
96
+ // composite programs, so an unpinned composite spec config still fails with
97
+ // TS5011 under ts-jest. The explicit pin survives the strip.
117
98
  if (options.composite) {
118
- return { kind: 'composite' };
99
+ return { kind: 'write', dirAbs: toPosix((0, node_path_1.dirname)(absPath)) };
119
100
  }
120
101
  const commonDir = computeCommonSourceDirectory(ts, fileNames, options, projectReferences);
121
102
  if (!commonDir) {
@@ -128,18 +109,6 @@ function analyze(ts, absPath, parseConfigHost) {
128
109
  // fails with TS5011.
129
110
  return { kind: 'write', dirAbs: toPosix(commonDir).replace(/\/+$/, '') };
130
111
  }
131
- // True when TypeScript resolves an inherited `rootDir` for the config. A
132
- // composite config sets none of its own (or it would be `has-rootDir`), so any
133
- // `rootDir` reported here comes from a base this migration just pinned, and
134
- // inheriting it would shift the config's emit layout.
135
- function inheritsRootDir(ts, parseHost, readFile, relPath) {
136
- const config = ts.readConfigFile(relPath, readFile).config;
137
- if (!config) {
138
- return false;
139
- }
140
- const { options } = ts.parseJsonConfigFileContent(config, parseHost, (0, node_path_1.dirname)(relPath));
141
- return options.rootDir != null;
142
- }
143
112
  // Any of these makes TypeScript run the source-file containment / common-source
144
113
  // computation that emits TS5011 / TS6059 when `rootDir` is absent.
145
114
  function setsEmitGate(o) {
@@ -2,9 +2,11 @@
2
2
 
3
3
  Before TypeScript 6, a tsconfig that did not set `rootDir` had it inferred as the common directory of the program's non-declaration input files. TypeScript 6 changed that default to the tsconfig's own directory. A program whose files resolve outside that directory (most commonly a spec or e2e tsconfig that imports another project's source through a `paths` alias) now hard-fails with `TS5011` or `TS6059` because a file falls outside the assumed root.
4
4
 
5
- For every project `tsconfig*.json` that does not already set `rootDir` (directly or through `extends`), this migration pins `rootDir` to exactly the directory TypeScript 5 would have inferred, so both compilation and emit layout stay the same under TypeScript 6. The value is computed by the TypeScript compiler itself, so it matches `tsc` exactly, including project-reference redirects. The pin is written even when the inferred directory already equals the tsconfig directory: inference is per-program, and a tool that compiles a subset of the config's files — ts-jest with `isolatedModules` builds a program per test file — re-infers a deeper common directory from that subset and fails with `TS5011`. Configs that cannot hit the error are skipped: ones without an output option (`outDir`, `outFile`, `sourceRoot`, `mapRoot`, or `declaration` + `declarationDir`), ones with no input files, and composite projects (whose `rootDir` defaults to the tsconfig directory in both versions, for any file subset). The migration only runs when the workspace is on TypeScript 6.
5
+ For every project `tsconfig*.json` that does not already set `rootDir` (directly or through `extends`), this migration pins `rootDir` to exactly the directory TypeScript 5 would have inferred, so both compilation and emit layout stay the same under TypeScript 6. The value is computed by the TypeScript compiler itself, so it matches `tsc` exactly, including project-reference redirects. The pin is written even when the inferred directory already equals the tsconfig directory: inference is per-program, and a tool that compiles a subset of the config's files — ts-jest with `isolatedModules` builds a program per test file — re-infers a deeper common directory from that subset and fails with `TS5011`. Configs that cannot hit the error are skipped: ones without an output option (`outDir`, `outFile`, `sourceRoot`, `mapRoot`, or `declaration` + `declarationDir`), and ones with no input files. The migration only runs when the workspace is on TypeScript 6.
6
6
 
7
- Each config is updated on its own; the migration never writes `rootDir` to a shared `extends` base, so a config never inherits a value computed for a sibling. The one case that needs care is a config that both needs a `rootDir` and is itself an `extends` base: a composite child would inherit the new value and emit to the wrong place, so each such child is pinned to its own directory to keep the default it had.
7
+ Composite projects are pinned to their own directory (`"."`). Under `tsc` a composite `rootDir` already defaults there, so the pin is a no-op for a real composite build but ts-jest strips `composite` for its per-file transpile, and TypeScript 6 only exempts genuinely-composite programs from the containment check, so a composite spec config compiled by ts-jest still fails with `TS5011` without an explicit `rootDir`. Pinning the own directory (rather than a deeper file-derived value) keeps the composite build's emit layout unchanged while fixing the ts-jest case.
8
+
9
+ Each config is updated on its own; the migration never writes `rootDir` to a shared `extends` base, so a config never inherits a value computed for a sibling. Because every config that emits is given its own explicit `rootDir`, none is left to inherit a value pinned on a base.
8
10
 
9
11
  #### Sample Code Changes
10
12
 
@@ -1,7 +1,7 @@
1
1
  export declare const nxVersion: any;
2
2
  export declare const esbuildVersion = "^0.27.0";
3
3
  export declare const prettierVersion = "~3.6.2";
4
- export declare const swcCliVersion = "~0.8.0";
4
+ export declare const swcCliVersion = "~0.8.1";
5
5
  export declare const swcCoreVersion = "~1.15.5";
6
6
  export declare const swcHelpersVersion = "~0.5.18";
7
7
  export declare const swcNodeVersion = "~1.11.1";
@@ -5,7 +5,7 @@ const path_1 = require("path");
5
5
  exports.nxVersion = require((0, path_1.join)('@nx/js', 'package.json')).version;
6
6
  exports.esbuildVersion = '^0.27.0';
7
7
  exports.prettierVersion = '~3.6.2';
8
- exports.swcCliVersion = '~0.8.0';
8
+ exports.swcCliVersion = '~0.8.1';
9
9
  exports.swcCoreVersion = '~1.15.5';
10
10
  exports.swcHelpersVersion = '~0.5.18';
11
11
  exports.swcNodeVersion = '~1.11.1';
package/migrations.json CHANGED
@@ -39,8 +39,8 @@
39
39
  "documentation": "./dist/src/migrations/update-23-1-0/add-ignore-deprecations-for-ts6.md"
40
40
  },
41
41
  "23-1-0-set-tsconfig-root-dir-for-ts6": {
42
- "version": "23.1.0-rc.1",
43
- "description": "Sets an explicit `rootDir` on project `tsconfig*.json` files that lack one, pinned to the source directory TypeScript 5 inferred implicitly, so programs keep compiling and emitting the same layout under TypeScript 6, which otherwise hard-fails with TS5011 or TS6059 (for example a spec tsconfig importing another project's source through a `paths` alias). The pin is written even when the inferred directory already equals the tsconfig directory, because tools like ts-jest with `isolatedModules` compile a program per file and re-infer a deeper directory from that subset. The value is computed by the compiler, so emit layout is unchanged. Each config is written on its own; the migration never writes to a shared `extends` base, so a config never inherits a value computed for a sibling. Composite projects are not given an inferred `rootDir`, since it already defaults to the tsconfig directory in both versions; a composite that extends a base receiving a pinned `rootDir` is itself pinned to its own directory to preserve that default.",
42
+ "version": "23.1.0-rc.2",
43
+ "description": "Sets an explicit `rootDir` on project `tsconfig*.json` files that lack one, pinned to the source directory TypeScript 5 inferred implicitly, so programs keep compiling and emitting the same layout under TypeScript 6, which otherwise hard-fails with TS5011 or TS6059 (for example a spec tsconfig importing another project's source through a `paths` alias). The pin is written even when the inferred directory already equals the tsconfig directory, because tools like ts-jest with `isolatedModules` compile a program per file and re-infer a deeper directory from that subset. The value is computed by the compiler, so emit layout is unchanged. Each config is written on its own; the migration never writes to a shared `extends` base, so a config never inherits a value computed for a sibling. Composite projects are pinned to their own directory: `rootDir` already defaults there under `tsc` so it is a no-op for a real composite build, but ts-jest strips `composite` for its per-file transpile and the explicit value is needed to avoid TS5011 there.",
44
44
  "requires": {
45
45
  "typescript": ">=6.0.0"
46
46
  },
@@ -139,6 +139,18 @@
139
139
  "alwaysAddToPackageJson": false
140
140
  }
141
141
  }
142
+ },
143
+ "23.1.0-swc-cli": {
144
+ "version": "23.1.0-rc.3",
145
+ "requires": {
146
+ "@swc/cli": ">=0.8.0 <0.8.1"
147
+ },
148
+ "packages": {
149
+ "@swc/cli": {
150
+ "version": "~0.8.1",
151
+ "alwaysAddToPackageJson": false
152
+ }
153
+ }
142
154
  }
143
155
  }
144
156
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "23.1.0-rc.1",
3
+ "version": "23.1.0-rc.3",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -144,11 +144,11 @@
144
144
  "source-map-support": "0.5.19",
145
145
  "tinyglobby": "^0.2.12",
146
146
  "tslib": "^2.3.0",
147
- "@nx/devkit": "23.1.0-rc.1",
148
- "@nx/workspace": "23.1.0-rc.1"
147
+ "@nx/devkit": "23.1.0-rc.3",
148
+ "@nx/workspace": "23.1.0-rc.3"
149
149
  },
150
150
  "devDependencies": {
151
- "nx": "23.1.0-rc.1"
151
+ "nx": "23.1.0-rc.3"
152
152
  },
153
153
  "peerDependencies": {
154
154
  "@swc/cli": ">=0.6.0 <0.9.0",