@nx/js 23.0.0-beta.22 → 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.
@@ -8,17 +8,24 @@ const expectedNpmPublishJsonKeys = [
8
8
  'size',
9
9
  'filename',
10
10
  ];
11
- // Regular expression to match JSON-like objects, including nested objects (which the expected npm publish output will have, e.g. in its "files" array)
12
- // /{(?:[^{}]|{[^{}]*})*}/g
13
- // /{ : Matches the opening brace of a JSON object
14
- // (?: ) : Non-capturing group to apply quantifiers
15
- // [^{}] : Matches any character except for braces
16
- // | : OR
17
- // {[^{}]*} : Matches nested JSON objects
18
- // * : The non-capturing group (i.e. any character except for braces OR nested JSON objects) can repeat zero or more times
19
- // } : Matches the closing brace of a JSON object
20
- // /g : Global flag to match all occurrences in the string
21
- const jsonRegex = /{(?:[^{}]|{[^{}]*})*}/g;
11
+ // Regular expression to match JSON-like objects, including up to two levels of
12
+ // nested objects.
13
+ // /{(?:[^{}]|{(?:[^{}]|{[^{}]*})*})*}/g
14
+ // Two levels of nesting are required to support both shapes of npm/pnpm publish
15
+ // output:
16
+ // - Older npm (<= 11.13) prints the publish summary as a flat object whose only
17
+ // nesting is its own "files" array (one level deep).
18
+ // - Newer npm (>= 11.16, bundled with Node 26) nests that same summary under the
19
+ // package name, e.g. { "@scope/pkg": { ...id/name/files... } }, adding a
20
+ // second level. pnpm publish nests the same way when run from the workspace
21
+ // root. Matching two levels lets us capture the wrapper object in the nested
22
+ // case so its braces are not left behind in beforeJsonData/afterJsonData.
23
+ const jsonRegex = /{(?:[^{}]|{(?:[^{}]|{[^{}]*})*})*}/g;
24
+ function isNpmPublishSummary(value) {
25
+ return (typeof value === 'object' &&
26
+ value !== null &&
27
+ expectedNpmPublishJsonKeys.every((key) => value[key] !== undefined));
28
+ }
22
29
  function extractNpmPublishJsonData(str) {
23
30
  const jsonMatches = str.match(jsonRegex);
24
31
  if (jsonMatches) {
@@ -28,21 +35,39 @@ function extractNpmPublishJsonData(str) {
28
35
  continue;
29
36
  }
30
37
  // Full JSON parsing to identify the JSON object
38
+ let parsedJson;
31
39
  try {
32
- const parsedJson = JSON.parse(match);
33
- if (!expectedNpmPublishJsonKeys.every((key) => parsedJson[key] !== undefined)) {
34
- continue;
35
- }
36
- const jsonStartIndex = str.indexOf(match);
37
- return {
38
- beforeJsonData: str.slice(0, jsonStartIndex),
39
- jsonData: parsedJson,
40
- afterJsonData: str.slice(jsonStartIndex + match.length),
41
- };
40
+ parsedJson = JSON.parse(match);
42
41
  }
43
42
  catch {
44
43
  // Ignore parsing errors for unrelated JSON blocks
44
+ continue;
45
+ }
46
+ // npm <= 11.13 emits the summary as a flat object, while npm >= 11.16 (and
47
+ // pnpm publish run from the workspace root) nest it one level deep under the
48
+ // package name. Support both by unwrapping a single level when the matched
49
+ // object isn't itself the summary.
50
+ let publishData = null;
51
+ if (isNpmPublishSummary(parsedJson)) {
52
+ publishData = parsedJson;
53
+ }
54
+ else if (typeof parsedJson === 'object' && parsedJson !== null) {
55
+ for (const value of Object.values(parsedJson)) {
56
+ if (isNpmPublishSummary(value)) {
57
+ publishData = value;
58
+ break;
59
+ }
60
+ }
61
+ }
62
+ if (!publishData) {
63
+ continue;
45
64
  }
65
+ const jsonStartIndex = str.indexOf(match);
66
+ return {
67
+ beforeJsonData: str.slice(0, jsonStartIndex),
68
+ jsonData: publishData,
69
+ afterJsonData: str.slice(jsonStartIndex + match.length),
70
+ };
46
71
  }
47
72
  }
48
73
  // No applicable jsonData detected, the whole contents is the beforeJsonData
@@ -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.
@@ -1,4 +1,4 @@
1
- import { type CreateDependencies, type CreateNodesV2 } from '@nx/devkit';
1
+ import { type CreateDependencies, type CreateNodes } from '@nx/devkit';
2
2
  export interface TscPluginOptions {
3
3
  compiler?: 'tsc' | 'tsgo';
4
4
  typecheck?: boolean | {
@@ -19,5 +19,5 @@ export interface TscPluginOptions {
19
19
  */
20
20
  export declare const createDependencies: CreateDependencies;
21
21
  export declare const PLUGIN_NAME = "@nx/js/typescript";
22
- export declare const createNodesV2: CreateNodesV2<TscPluginOptions>;
23
- export declare const createNodes: CreateNodesV2<TscPluginOptions>;
22
+ export declare const createNodesV2: CreateNodes<TscPluginOptions>;
23
+ export declare const createNodes: CreateNodes<TscPluginOptions>;
@@ -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
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ensureProjectIsIncludedInPluginRegistrations = ensureProjectIsIncludedInPluginRegistrations;
4
4
  const devkit_internals_1 = require("nx/src/devkit-internals");
5
+ const picomatch = require("picomatch");
5
6
  function ensureProjectIsIncludedInPluginRegistrations(nxJson, projectRoot, buildTargetName) {
6
7
  nxJson.plugins ??= [];
7
8
  let isIncluded = false;
@@ -26,7 +27,13 @@ function ensureProjectIsIncludedInPluginRegistrations(nxJson, projectRoot, build
26
27
  }
27
28
  else {
28
29
  // check if the project would be included by the plugin registration
29
- const matchingConfigFiles = (0, devkit_internals_1.findMatchingConfigFiles)([`${projectRoot}/tsconfig.json`], '**/tsconfig.json', registration.include, registration.exclude);
30
+ // Only consider the tsconfig if the @nx/js/typescript plugin would
31
+ // actually process it (its path matches the plugin's createNodes glob)
32
+ // before the registration's include/exclude filters are applied.
33
+ const tsconfigPath = `${projectRoot}/tsconfig.json`;
34
+ const matchingConfigFiles = picomatch('**/tsconfig.json', { dot: true })(tsconfigPath)
35
+ ? (0, devkit_internals_1.findMatchingConfigFiles)([tsconfigPath], registration.include, registration.exclude)
36
+ : [];
30
37
  if (matchingConfigFiles.length) {
31
38
  // it's included by the plugin registration, check if the user-specified options would result
32
39
  // in the appropriate build task being inferred, if not, we need to exclude it
@@ -96,7 +96,7 @@ function resolvePathsBaseUrl(tsconfigPath) {
96
96
  const absolute = (0, path_1.resolve)(queue.shift());
97
97
  const dir = (0, path_1.dirname)(absolute);
98
98
  try {
99
- const raw = JSON.parse((0, fs_1.readFileSync)(absolute, 'utf-8'));
99
+ const raw = (0, devkit_1.readJsonFile)(absolute);
100
100
  chain.push({ dir, raw });
101
101
  const exts = raw.extends
102
102
  ? Array.isArray(raw.extends)
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.22",
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/devkit": "23.0.0-beta.22",
148
- "@nx/workspace": "23.0.0-beta.22"
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.22"
151
+ "nx": "23.0.0-beta.24"
152
152
  },
153
153
  "peerDependencies": {
154
154
  "@swc/cli": ">=0.6.0 <0.9.0",