@nx/devkit 23.0.0-beta.23 → 23.0.0-beta.25

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.
@@ -0,0 +1,10 @@
1
+ import { type Tree } from 'nx/src/devkit-exports';
2
+ export declare const CREATE_NODES_V2_TYPE_RENAMES: ReadonlyMap<string, string>;
3
+ export default function renameCreateNodesV2Types(tree: Tree): Promise<void>;
4
+ /**
5
+ * Rewrites named imports and re-exports of the deprecated `*V2` plugin types
6
+ * from `@nx/devkit` to their canonical names. Only the named bindings are
7
+ * touched — the module specifier, the `import`/`export` keyword, any `type`
8
+ * modifier, and any default import are left untouched.
9
+ */
10
+ export declare function rewriteCreateNodesV2Types(source: string): string;
@@ -0,0 +1,199 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CREATE_NODES_V2_TYPE_RENAMES = void 0;
4
+ exports.default = renameCreateNodesV2Types;
5
+ exports.rewriteCreateNodesV2Types = rewriteCreateNodesV2Types;
6
+ const devkit_exports_1 = require("nx/src/devkit-exports");
7
+ const format_files_1 = require("../../generators/format-files");
8
+ const visit_not_ignored_files_1 = require("../../generators/visit-not-ignored-files");
9
+ const package_json_1 = require("../../utils/package-json");
10
+ const string_change_1 = require("../../utils/string-change");
11
+ const versions_1 = require("../../utils/versions");
12
+ const TS_EXTENSIONS = ['.ts', '.tsx', '.cts', '.mts'];
13
+ const DEVKIT_SPECIFIER = '@nx/devkit';
14
+ // The `*V2` plugin types were renamed to their canonical un-suffixed names in
15
+ // Nx 23. The `V2` names remain as `@deprecated` aliases, so this migration only
16
+ // moves callers onto the canonical names. (`CreateNodesResultV2` is renamed to
17
+ // `CreateNodesResultArray`, not `CreateNodesResult`, which is an unrelated type.)
18
+ exports.CREATE_NODES_V2_TYPE_RENAMES = new Map([
19
+ ['CreateNodesV2', 'CreateNodes'],
20
+ ['CreateNodesContextV2', 'CreateNodesContext'],
21
+ ['CreateNodesResultV2', 'CreateNodesResultArray'],
22
+ ['CreateNodesFunctionV2', 'CreateNodesFunction'],
23
+ ['NxPluginV2', 'NxPlugin'],
24
+ ]);
25
+ let ts;
26
+ async function renameCreateNodesV2Types(tree) {
27
+ let touchedCount = 0;
28
+ (0, visit_not_ignored_files_1.visitNotIgnoredFiles)(tree, '.', (filePath) => {
29
+ if (!TS_EXTENSIONS.some((ext) => filePath.endsWith(ext))) {
30
+ return;
31
+ }
32
+ const original = tree.read(filePath, 'utf-8');
33
+ if (!original || !original.includes('V2')) {
34
+ return;
35
+ }
36
+ const updated = rewriteCreateNodesV2Types(original);
37
+ if (updated !== original) {
38
+ tree.write(filePath, updated);
39
+ touchedCount += 1;
40
+ }
41
+ });
42
+ if (touchedCount > 0) {
43
+ devkit_exports_1.logger.info(`Renamed deprecated CreateNodes V2 type imports from @nx/devkit in ${touchedCount} file(s).`);
44
+ }
45
+ await (0, format_files_1.formatFiles)(tree);
46
+ }
47
+ /**
48
+ * Rewrites named imports and re-exports of the deprecated `*V2` plugin types
49
+ * from `@nx/devkit` to their canonical names. Only the named bindings are
50
+ * touched — the module specifier, the `import`/`export` keyword, any `type`
51
+ * modifier, and any default import are left untouched.
52
+ */
53
+ function rewriteCreateNodesV2Types(source) {
54
+ ts ??= (0, package_json_1.ensurePackage)('typescript', versions_1.typescriptVersion);
55
+ const sourceFile = ts.createSourceFile('tmp.ts', source, ts.ScriptTarget.Latest,
56
+ /* setParentNodes */ true, ts.ScriptKind.TSX);
57
+ const changes = [];
58
+ // Local bindings whose name changes as a result of rewriting a non-aliased
59
+ // import specifier (e.g. `import { CreateNodesV2 }` -> `import { CreateNodes }`).
60
+ // Every in-body reference to such a binding must be renamed too, otherwise the
61
+ // rewritten import leaves a dangling reference to the old name.
62
+ const localRenames = new Map();
63
+ for (const stmt of sourceFile.statements) {
64
+ if (ts.isImportDeclaration(stmt)) {
65
+ collectImportRewrite(sourceFile, stmt, changes, localRenames);
66
+ }
67
+ else if (ts.isExportDeclaration(stmt)) {
68
+ collectExportRewrite(sourceFile, stmt, changes);
69
+ }
70
+ }
71
+ if (localRenames.size > 0) {
72
+ collectUsageRewrites(sourceFile, localRenames, changes);
73
+ }
74
+ return changes.length > 0 ? (0, string_change_1.applyChangesToString)(source, changes) : source;
75
+ }
76
+ function isDevkitSpecifier(node) {
77
+ return ts.isStringLiteral(node) && node.text === DEVKIT_SPECIFIER;
78
+ }
79
+ function collectImportRewrite(sourceFile, stmt, changes, localRenames) {
80
+ if (!isDevkitSpecifier(stmt.moduleSpecifier)) {
81
+ return;
82
+ }
83
+ const namedBindings = stmt.importClause?.namedBindings;
84
+ if (!namedBindings || !ts.isNamedImports(namedBindings)) {
85
+ return;
86
+ }
87
+ // A non-aliased specifier (`{ CreateNodesV2 }`) renames the local binding, so
88
+ // its in-body references must be rewritten as well. An aliased specifier
89
+ // (`{ CreateNodesV2 as Foo }`) keeps the local name `Foo`, so it does not.
90
+ for (const el of namedBindings.elements) {
91
+ if (el.propertyName) {
92
+ continue;
93
+ }
94
+ const canonical = exports.CREATE_NODES_V2_TYPE_RENAMES.get(el.name.text);
95
+ if (canonical) {
96
+ localRenames.set(el.name.text, canonical);
97
+ }
98
+ }
99
+ rewriteNamedBindings(sourceFile, namedBindings, changes);
100
+ }
101
+ /**
102
+ * Renames in-body references (type annotations, value usages) of bindings that
103
+ * were renamed by an import rewrite. References inside import/export
104
+ * declarations are left to the binding rewrite, and member positions
105
+ * (`foo.CreateNodesV2`, `NS.CreateNodesV2`) are not standalone references to the
106
+ * imported binding, so they are skipped.
107
+ */
108
+ function collectUsageRewrites(sourceFile, localRenames, changes) {
109
+ const visit = (node) => {
110
+ if (ts.isIdentifier(node) &&
111
+ localRenames.has(node.text) &&
112
+ isRenameableReference(node)) {
113
+ const start = node.getStart(sourceFile);
114
+ changes.push({ type: string_change_1.ChangeType.Delete, start, length: node.getEnd() - start }, {
115
+ type: string_change_1.ChangeType.Insert,
116
+ index: start,
117
+ text: localRenames.get(node.text),
118
+ });
119
+ }
120
+ ts.forEachChild(node, visit);
121
+ };
122
+ ts.forEachChild(sourceFile, visit);
123
+ }
124
+ function isRenameableReference(id) {
125
+ const parent = id.parent;
126
+ // `foo.CreateNodesV2` — the member name is not the imported binding.
127
+ if (ts.isPropertyAccessExpression(parent) && parent.name === id) {
128
+ return false;
129
+ }
130
+ // `NS.CreateNodesV2` in a type position — same reasoning.
131
+ if (ts.isQualifiedName(parent) && parent.right === id) {
132
+ return false;
133
+ }
134
+ // Anything inside an import/export declaration is handled by the binding
135
+ // rewrite; skip it here to avoid touching the specifier twice.
136
+ for (let n = id; n; n = n.parent) {
137
+ if (ts.isImportDeclaration(n) || ts.isExportDeclaration(n)) {
138
+ return false;
139
+ }
140
+ }
141
+ return true;
142
+ }
143
+ function collectExportRewrite(sourceFile, stmt, changes) {
144
+ if (!stmt.moduleSpecifier || !isDevkitSpecifier(stmt.moduleSpecifier)) {
145
+ return;
146
+ }
147
+ if (!stmt.exportClause || !ts.isNamedExports(stmt.exportClause)) {
148
+ return;
149
+ }
150
+ rewriteNamedBindings(sourceFile, stmt.exportClause, changes);
151
+ }
152
+ /**
153
+ * Re-renders the `{ ... }` of a named import/export, renaming any deprecated
154
+ * `*V2` type to its canonical name. If renaming would collide with a canonical
155
+ * name that is already present, the duplicate is dropped. Returns without
156
+ * recording a change when the binding list contains none of the renamed types.
157
+ */
158
+ function rewriteNamedBindings(sourceFile, namedBindings, changes) {
159
+ const elements = namedBindings.elements;
160
+ const hasRenamed = elements.some((el) => exports.CREATE_NODES_V2_TYPE_RENAMES.has((el.propertyName ?? el.name).text));
161
+ if (!hasRenamed) {
162
+ return;
163
+ }
164
+ const seen = new Set();
165
+ const rendered = [];
166
+ for (const el of elements) {
167
+ const text = renderSpecifier(el);
168
+ if (!seen.has(text)) {
169
+ seen.add(text);
170
+ rendered.push(text);
171
+ }
172
+ }
173
+ const start = namedBindings.getStart(sourceFile);
174
+ changes.push({
175
+ type: string_change_1.ChangeType.Delete,
176
+ start,
177
+ length: namedBindings.getEnd() - start,
178
+ }, {
179
+ type: string_change_1.ChangeType.Insert,
180
+ index: start,
181
+ text: `{ ${rendered.join(', ')} }`,
182
+ });
183
+ }
184
+ function renderSpecifier(el) {
185
+ const typePrefix = el.isTypeOnly ? 'type ' : '';
186
+ const rename = (name) => exports.CREATE_NODES_V2_TYPE_RENAMES.get(name) ?? name;
187
+ // `{ name }` — no alias, so the local binding follows the rename.
188
+ if (!el.propertyName) {
189
+ return `${typePrefix}${rename(el.name.text)}`;
190
+ }
191
+ // `{ propertyName as name }` — only the imported (left) side is renamed; the
192
+ // local alias is preserved. A now-redundant alias such as
193
+ // `CreateNodesV2 as CreateNodes` collapses to `CreateNodes`.
194
+ const canonicalImported = rename(el.propertyName.text);
195
+ const localName = el.name.text;
196
+ return canonicalImported === localName
197
+ ? `${typePrefix}${localName}`
198
+ : `${typePrefix}${canonicalImported} as ${localName}`;
199
+ }
@@ -0,0 +1,29 @@
1
+ #### Rename deprecated CreateNodes `V2` types from `@nx/devkit`
2
+
3
+ The canonical plugin API types lost their `V2` suffix in Nx 23. The `V2` names are kept as `@deprecated` aliases, but new code should use the canonical names:
4
+
5
+ | Deprecated (`@nx/devkit`) | Canonical |
6
+ | ------------------------- | ------------------------ |
7
+ | `CreateNodesV2` | `CreateNodes` |
8
+ | `CreateNodesContextV2` | `CreateNodesContext` |
9
+ | `CreateNodesResultV2` | `CreateNodesResultArray` |
10
+ | `CreateNodesFunctionV2` | `CreateNodesFunction` |
11
+ | `NxPluginV2` | `NxPlugin` |
12
+
13
+ This migration scans every `.ts`, `.tsx`, `.cts`, and `.mts` file in your workspace and rewrites named imports and re-exports of these types from `@nx/devkit` to their canonical names.
14
+
15
+ #### Sample Code Changes
16
+
17
+ ##### Before
18
+
19
+ ```ts
20
+ import type { CreateNodesV2, CreateNodesContextV2 } from '@nx/devkit';
21
+ ```
22
+
23
+ ##### After
24
+
25
+ ```ts
26
+ import type { CreateNodes, CreateNodesContext } from '@nx/devkit';
27
+ ```
28
+
29
+ Aliases are preserved (`CreateNodesV2 as CN` becomes `CreateNodes as CN`), and if a file already imports both names (`{ CreateNodes, CreateNodesV2 }`) the redundant binding is dropped. The unrelated `CreateNodesResult` type is left untouched.
package/migrations.json CHANGED
@@ -5,6 +5,12 @@
5
5
  "description": "Rewrite imports from `@nx/devkit/src/...` to `@nx/devkit` (for public symbols) or `@nx/devkit/internal` (for the rest), since deep imports are no longer reachable through the package's `exports` map.",
6
6
  "implementation": "./dist/src/migrations/update-23-0-0/update-deep-imports",
7
7
  "documentation": "./dist/src/migrations/update-23-0-0/update-deep-imports.md"
8
+ },
9
+ "update-23-0-0-rename-create-nodes-v2-types": {
10
+ "version": "23.0.0-beta.24",
11
+ "description": "Rename deprecated CreateNodes `V2` type imports (CreateNodesV2, CreateNodesContextV2, CreateNodesResultV2, CreateNodesFunctionV2, NxPluginV2) from `@nx/devkit` to their canonical names.",
12
+ "implementation": "./dist/src/migrations/update-23-0-0/rename-create-nodes-v2-types",
13
+ "documentation": "./dist/src/migrations/update-23-0-0/rename-create-nodes-v2-types.md"
8
14
  }
9
15
  },
10
16
  "packageJsonUpdates": {},
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/devkit",
3
- "version": "23.0.0-beta.23",
3
+ "version": "23.0.0-beta.25",
4
4
  "private": false,
5
5
  "type": "commonjs",
6
6
  "files": [
@@ -60,7 +60,7 @@
60
60
  },
61
61
  "devDependencies": {
62
62
  "jest": "30.3.0",
63
- "nx": "23.0.0-beta.23"
63
+ "nx": "23.0.0-beta.25"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "nx": ">= 22 <= 24 || ^23.0.0-0"
@@ -69,7 +69,8 @@
69
69
  "access": "public"
70
70
  },
71
71
  "nx-migrations": {
72
- "migrations": "./migrations.json"
72
+ "migrations": "./migrations.json",
73
+ "supportsOptionalUpdates": true
73
74
  },
74
75
  "exports": {
75
76
  ".": {