@nx/js 23.0.0-beta.23 → 23.0.0-beta.24

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,9 @@
1
+ import { type Tree } from '@nx/devkit';
2
+ export default function migrateCreateNodesV2ToCreateNodes(tree: Tree): Promise<void>;
3
+ /**
4
+ * Rewrites named imports and re-exports of `createNodesV2` to `createNodes`
5
+ * when they come from one of the given module specifiers. Only the named
6
+ * bindings are touched — the module specifier, the `import`/`export` keyword,
7
+ * any `type` modifier, and any default import are left untouched.
8
+ */
9
+ export declare function rewriteCreateNodesV2Imports(source: string, specifiers: ReadonlySet<string>): string;
@@ -0,0 +1,134 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = migrateCreateNodesV2ToCreateNodes;
4
+ exports.rewriteCreateNodesV2Imports = rewriteCreateNodesV2Imports;
5
+ const devkit_1 = require("@nx/devkit");
6
+ const TS_EXTENSIONS = ['.ts', '.tsx', '.cts', '.mts'];
7
+ const DEPRECATED_NAME = 'createNodesV2';
8
+ const CANONICAL_NAME = 'createNodes';
9
+ // Module specifiers from which `@nx/js` publicly exposes `createNodesV2`.
10
+ // A named import or re-export of `createNodesV2` from one of these is rewritten
11
+ // to the canonical `createNodes` export.
12
+ const TARGET_SPECIFIERS = new Set(['@nx/js/typescript']);
13
+ let ts;
14
+ async function migrateCreateNodesV2ToCreateNodes(tree) {
15
+ let touchedCount = 0;
16
+ (0, devkit_1.visitNotIgnoredFiles)(tree, '.', (filePath) => {
17
+ if (!TS_EXTENSIONS.some((ext) => filePath.endsWith(ext))) {
18
+ return;
19
+ }
20
+ const original = tree.read(filePath, 'utf-8');
21
+ if (!original || !original.includes(DEPRECATED_NAME)) {
22
+ return;
23
+ }
24
+ const updated = rewriteCreateNodesV2Imports(original, TARGET_SPECIFIERS);
25
+ if (updated !== original) {
26
+ tree.write(filePath, updated);
27
+ touchedCount += 1;
28
+ }
29
+ });
30
+ if (touchedCount > 0) {
31
+ devkit_1.logger.info(`Renamed \`${DEPRECATED_NAME}\` imports to \`${CANONICAL_NAME}\` in ${touchedCount} file(s).`);
32
+ }
33
+ await (0, devkit_1.formatFiles)(tree);
34
+ }
35
+ /**
36
+ * Rewrites named imports and re-exports of `createNodesV2` to `createNodes`
37
+ * when they come from one of the given module specifiers. Only the named
38
+ * bindings are touched — the module specifier, the `import`/`export` keyword,
39
+ * any `type` modifier, and any default import are left untouched.
40
+ */
41
+ function rewriteCreateNodesV2Imports(source, specifiers) {
42
+ ts ??= (0, devkit_1.ensurePackage)('typescript', '*');
43
+ const sourceFile = ts.createSourceFile('tmp.ts', source, ts.ScriptTarget.Latest,
44
+ /* setParentNodes */ true, ts.ScriptKind.TSX);
45
+ const changes = [];
46
+ for (const stmt of sourceFile.statements) {
47
+ if (ts.isImportDeclaration(stmt)) {
48
+ collectImportRewrite(sourceFile, stmt, specifiers, changes);
49
+ }
50
+ else if (ts.isExportDeclaration(stmt)) {
51
+ collectExportRewrite(sourceFile, stmt, specifiers, changes);
52
+ }
53
+ }
54
+ return changes.length > 0 ? (0, devkit_1.applyChangesToString)(source, changes) : source;
55
+ }
56
+ function isTargetSpecifier(node, specifiers) {
57
+ return ts.isStringLiteral(node) && specifiers.has(node.text);
58
+ }
59
+ function collectImportRewrite(sourceFile, stmt, specifiers, changes) {
60
+ if (!isTargetSpecifier(stmt.moduleSpecifier, specifiers)) {
61
+ return;
62
+ }
63
+ const namedBindings = stmt.importClause?.namedBindings;
64
+ // Only `import { ... }` carries renameable named bindings. `import x`,
65
+ // `import * as ns`, and side-effect imports reference the module wholesale
66
+ // and keep working through the `createNodesV2` runtime alias, so we leave
67
+ // them be. A mixed `import def, { createNodesV2 }` still has its named
68
+ // bindings rewritten below — the default binding is untouched.
69
+ if (!namedBindings || !ts.isNamedImports(namedBindings)) {
70
+ return;
71
+ }
72
+ rewriteNamedBindings(sourceFile, namedBindings, changes);
73
+ }
74
+ function collectExportRewrite(sourceFile, stmt, specifiers, changes) {
75
+ if (!stmt.moduleSpecifier ||
76
+ !isTargetSpecifier(stmt.moduleSpecifier, specifiers)) {
77
+ return;
78
+ }
79
+ // `export { ... } from '...'` can be rewritten; `export * from '...'` has no
80
+ // named bindings to rename.
81
+ if (!stmt.exportClause || !ts.isNamedExports(stmt.exportClause)) {
82
+ return;
83
+ }
84
+ rewriteNamedBindings(sourceFile, stmt.exportClause, changes);
85
+ }
86
+ /**
87
+ * Re-renders the `{ ... }` of a named import/export, renaming any
88
+ * `createNodesV2` specifier to `createNodes`. If renaming would collide with a
89
+ * `createNodes` that is already present (e.g. `{ createNodes, createNodesV2 }`),
90
+ * the duplicate is dropped. Returns without recording a change when the binding
91
+ * list contains no `createNodesV2`.
92
+ */
93
+ function rewriteNamedBindings(sourceFile, namedBindings, changes) {
94
+ const elements = namedBindings.elements;
95
+ const hasDeprecated = elements.some((el) => (el.propertyName ?? el.name).text === DEPRECATED_NAME);
96
+ if (!hasDeprecated) {
97
+ return;
98
+ }
99
+ const seen = new Set();
100
+ const rendered = [];
101
+ for (const el of elements) {
102
+ const text = renderSpecifier(el);
103
+ if (!seen.has(text)) {
104
+ seen.add(text);
105
+ rendered.push(text);
106
+ }
107
+ }
108
+ const start = namedBindings.getStart(sourceFile);
109
+ changes.push({
110
+ type: devkit_1.ChangeType.Delete,
111
+ start,
112
+ length: namedBindings.getEnd() - start,
113
+ }, {
114
+ type: devkit_1.ChangeType.Insert,
115
+ index: start,
116
+ text: `{ ${rendered.join(', ')} }`,
117
+ });
118
+ }
119
+ function renderSpecifier(el) {
120
+ const typePrefix = el.isTypeOnly ? 'type ' : '';
121
+ const rename = (name) => name === DEPRECATED_NAME ? CANONICAL_NAME : name;
122
+ // `{ name }` — no alias, so the local binding follows the rename.
123
+ if (!el.propertyName) {
124
+ return `${typePrefix}${rename(el.name.text)}`;
125
+ }
126
+ // `{ propertyName as name }` — only the imported (left) side is renamed; the
127
+ // local alias is preserved. A now-redundant alias such as
128
+ // `createNodesV2 as createNodes` collapses to `createNodes`.
129
+ const canonicalImported = rename(el.propertyName.text);
130
+ const localName = el.name.text;
131
+ return canonicalImported === localName
132
+ ? `${typePrefix}${localName}`
133
+ : `${typePrefix}${canonicalImported} as ${localName}`;
134
+ }
@@ -0,0 +1,25 @@
1
+ #### Rename `createNodesV2` imports to `createNodes`
2
+
3
+ `@nx/js` renamed its primary inferred-plugin export from `createNodesV2` to `createNodes`. The `createNodesV2` name is preserved as a deprecated alias for now, but new code should use `createNodes`.
4
+
5
+ This migration scans every `.ts`, `.tsx`, `.cts`, and `.mts` file in your workspace and rewrites named imports and re-exports of `createNodesV2` from `@nx/js/typescript` to `createNodes`.
6
+
7
+ #### Sample Code Changes
8
+
9
+ ##### Before
10
+
11
+ ```ts
12
+ import { createNodesV2 } from '@nx/js/typescript';
13
+ ```
14
+
15
+ ##### After
16
+
17
+ ```ts
18
+ import { createNodes } from '@nx/js/typescript';
19
+ ```
20
+
21
+ 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.
22
+
23
+ #### What is not rewritten
24
+
25
+ Only static `import`/`export` named bindings from `@nx/js/typescript` are rewritten. Namespace imports, dynamic `import(...)`, `require(...)` destructuring, and property access such as `plugin.createNodesV2` are left untouched — they keep working through the `createNodesV2` runtime alias. Update those by hand if you want to drop the deprecated name everywhere.
@@ -394,6 +394,12 @@ function getInputs(namedInputs, config, tsConfig, internalProjectReferences, wor
394
394
  ts.Extension.Dmts,
395
395
  ts.Extension.Mjs,
396
396
  ];
397
+ // A spec is an implicit glob over a directory if its last component has no
398
+ // extension and no glob characters. TypeScript normalizes the path before
399
+ // checking its last component, so specs like "." and ".." resolve to a
400
+ // directory name first.
401
+ // https://github.com/microsoft/TypeScript/blob/19b777260b26aac5707b1efd34202054164d4a9d/src/compiler/utilities.ts#L9577-L9585
402
+ const isImplicitGlobSpec = (spec) => !/[.*?]/.test((0, node_path_1.basename)((0, node_path_1.resolve)(absoluteProjectRoot, spec)));
397
403
  const normalizeInput = (input, config) => {
398
404
  const extensions = config.options.allowJs
399
405
  ? [...allSupportedExtensions]
@@ -401,13 +407,9 @@ function getInputs(namedInputs, config, tsConfig, internalProjectReferences, wor
401
407
  if (config.options.resolveJsonModule) {
402
408
  extensions.push(ts.Extension.Json);
403
409
  }
404
- const segments = input.split('/');
405
- // An "includes" path "foo" is implicitly a glob "foo/**/*" if its last
406
- // segment has no extension, and does not contain any glob characters
407
- // itself.
408
- // https://github.com/microsoft/TypeScript/blob/19b777260b26aac5707b1efd34202054164d4a9d/src/compiler/utilities.ts#L9577-L9585
409
- if (!/[.*?]/.test(segments.at(-1))) {
410
- return extensions.map((ext) => `${segments.join('/')}/**/*${ext}`);
410
+ // An "includes" path "foo" is implicitly a glob "foo/**/*"
411
+ if (isImplicitGlobSpec(input)) {
412
+ return extensions.map((ext) => `${input}/**/*${ext}`);
411
413
  }
412
414
  return [input];
413
415
  };
@@ -440,6 +442,24 @@ function getInputs(namedInputs, config, tsConfig, internalProjectReferences, wor
440
442
  }
441
443
  });
442
444
  const normalize = (p) => (p.startsWith('./') ? p.slice(2) : p);
445
+ // Static (non-glob) prefix of a spec, used for subtree coverage checks.
446
+ const staticPrefix = (p) => {
447
+ const segments = normalize(p).split('/');
448
+ const firstGlobSegment = segments.findIndex((s) => /[*?]/.test(s));
449
+ return firstGlobSegment === -1
450
+ ? segments.join('/')
451
+ : segments.slice(0, firstGlobSegment).join('/');
452
+ };
453
+ // A non-glob include spec (an implicit directory glob like "." or "src",
454
+ // or a literal file path) covers an exclude spec if the exclude's static
455
+ // prefix falls within the include's subtree.
456
+ const includeCoversExclude = (includePath, excludePath) => {
457
+ if (/[*?]/.test(includePath)) {
458
+ return false;
459
+ }
460
+ const rel = (0, node_path_1.relative)((0, node_path_1.resolve)(absoluteProjectRoot, normalize(includePath)), (0, node_path_1.resolve)(absoluteProjectRoot, staticPrefix(excludePath)));
461
+ return !rel.startsWith('..') && !(0, node_path_1.isAbsolute)(rel);
462
+ };
443
463
  tsconfig.raw.exclude.forEach((e) => {
444
464
  const excludePath = substituteConfigDir(e);
445
465
  const normalizedExclude = normalize(excludePath);
@@ -448,9 +468,14 @@ function getInputs(namedInputs, config, tsConfig, internalProjectReferences, wor
448
468
  const normalizedInclude = normalize(includePath);
449
469
  const includeMatcher = getOrCreateMatcher(normalizedInclude);
450
470
  return (excludeMatcher(normalizedInclude) ||
451
- includeMatcher(normalizedExclude));
471
+ includeMatcher(normalizedExclude) ||
472
+ includeCoversExclude(includePath, excludePath));
452
473
  })) {
453
- excludePaths.add(excludePath);
474
+ // TS treats an implicit-glob exclude like "dist" as excluding the
475
+ // whole subtree, so emit it as "dist/**/*".
476
+ excludePaths.add(isImplicitGlobSpec(excludePath)
477
+ ? `${excludePath}/**/*`
478
+ : excludePath);
454
479
  }
455
480
  });
456
481
  }
package/migrations.json CHANGED
@@ -22,6 +22,12 @@
22
22
  "version": "23.0.0-beta.14",
23
23
  "description": "Rewrites `@nx/js/src/*` subpath imports to the new `@nx/js/internal` entry. The `./src/*` wildcard has been removed from `@nx/js`'s exports map; `@nx/js/src/release/version-actions` is preserved as a non-wildcard entry for back-compat with existing nx.json release configs. If a rewritten import resolves to a symbol that lives on the public `@nx/js` entry (e.g. `libraryGenerator`, `extractTsConfigBase`, `resolvePathsBaseUrl`), change the specifier to `@nx/js`.",
24
24
  "factory": "./dist/src/migrations/update-23-0-0/rewrite-internal-subpath-imports"
25
+ },
26
+ "update-23-0-0-migrate-create-nodes-v2-import": {
27
+ "version": "23.0.0-beta.24",
28
+ "description": "Rename imports of `createNodesV2` from `@nx/js/typescript` to the canonical `createNodes` export.",
29
+ "implementation": "./dist/src/migrations/update-23-0-0/migrate-create-nodes-v2-to-create-nodes",
30
+ "documentation": "./dist/src/migrations/update-23-0-0/migrate-create-nodes-v2-to-create-nodes.md"
25
31
  }
26
32
  },
27
33
  "packageJsonUpdates": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/js",
3
- "version": "23.0.0-beta.23",
3
+ "version": "23.0.0-beta.24",
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/workspace": "23.0.0-beta.23",
148
- "@nx/devkit": "23.0.0-beta.23"
147
+ "@nx/workspace": "23.0.0-beta.24",
148
+ "@nx/devkit": "23.0.0-beta.24"
149
149
  },
150
150
  "devDependencies": {
151
- "nx": "23.0.0-beta.23"
151
+ "nx": "23.0.0-beta.24"
152
152
  },
153
153
  "peerDependencies": {
154
154
  "@swc/cli": ">=0.6.0 <0.9.0",