@nx/playwright 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,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,136 @@
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/playwright` 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([
13
+ '@nx/playwright/plugin',
14
+ ]);
15
+ let ts;
16
+ async function migrateCreateNodesV2ToCreateNodes(tree) {
17
+ let touchedCount = 0;
18
+ (0, devkit_1.visitNotIgnoredFiles)(tree, '.', (filePath) => {
19
+ if (!TS_EXTENSIONS.some((ext) => filePath.endsWith(ext))) {
20
+ return;
21
+ }
22
+ const original = tree.read(filePath, 'utf-8');
23
+ if (!original || !original.includes(DEPRECATED_NAME)) {
24
+ return;
25
+ }
26
+ const updated = rewriteCreateNodesV2Imports(original, TARGET_SPECIFIERS);
27
+ if (updated !== original) {
28
+ tree.write(filePath, updated);
29
+ touchedCount += 1;
30
+ }
31
+ });
32
+ if (touchedCount > 0) {
33
+ devkit_1.logger.info(`Renamed \`${DEPRECATED_NAME}\` imports to \`${CANONICAL_NAME}\` in ${touchedCount} file(s).`);
34
+ }
35
+ await (0, devkit_1.formatFiles)(tree);
36
+ }
37
+ /**
38
+ * Rewrites named imports and re-exports of `createNodesV2` to `createNodes`
39
+ * when they come from one of the given module specifiers. Only the named
40
+ * bindings are touched — the module specifier, the `import`/`export` keyword,
41
+ * any `type` modifier, and any default import are left untouched.
42
+ */
43
+ function rewriteCreateNodesV2Imports(source, specifiers) {
44
+ ts ??= (0, devkit_1.ensurePackage)('typescript', '*');
45
+ const sourceFile = ts.createSourceFile('tmp.ts', source, ts.ScriptTarget.Latest,
46
+ /* setParentNodes */ true, ts.ScriptKind.TSX);
47
+ const changes = [];
48
+ for (const stmt of sourceFile.statements) {
49
+ if (ts.isImportDeclaration(stmt)) {
50
+ collectImportRewrite(sourceFile, stmt, specifiers, changes);
51
+ }
52
+ else if (ts.isExportDeclaration(stmt)) {
53
+ collectExportRewrite(sourceFile, stmt, specifiers, changes);
54
+ }
55
+ }
56
+ return changes.length > 0 ? (0, devkit_1.applyChangesToString)(source, changes) : source;
57
+ }
58
+ function isTargetSpecifier(node, specifiers) {
59
+ return ts.isStringLiteral(node) && specifiers.has(node.text);
60
+ }
61
+ function collectImportRewrite(sourceFile, stmt, specifiers, changes) {
62
+ if (!isTargetSpecifier(stmt.moduleSpecifier, specifiers)) {
63
+ return;
64
+ }
65
+ const namedBindings = stmt.importClause?.namedBindings;
66
+ // Only `import { ... }` carries renameable named bindings. `import x`,
67
+ // `import * as ns`, and side-effect imports reference the module wholesale
68
+ // and keep working through the `createNodesV2` runtime alias, so we leave
69
+ // them be. A mixed `import def, { createNodesV2 }` still has its named
70
+ // bindings rewritten below — the default binding is untouched.
71
+ if (!namedBindings || !ts.isNamedImports(namedBindings)) {
72
+ return;
73
+ }
74
+ rewriteNamedBindings(sourceFile, namedBindings, changes);
75
+ }
76
+ function collectExportRewrite(sourceFile, stmt, specifiers, changes) {
77
+ if (!stmt.moduleSpecifier ||
78
+ !isTargetSpecifier(stmt.moduleSpecifier, specifiers)) {
79
+ return;
80
+ }
81
+ // `export { ... } from '...'` can be rewritten; `export * from '...'` has no
82
+ // named bindings to rename.
83
+ if (!stmt.exportClause || !ts.isNamedExports(stmt.exportClause)) {
84
+ return;
85
+ }
86
+ rewriteNamedBindings(sourceFile, stmt.exportClause, changes);
87
+ }
88
+ /**
89
+ * Re-renders the `{ ... }` of a named import/export, renaming any
90
+ * `createNodesV2` specifier to `createNodes`. If renaming would collide with a
91
+ * `createNodes` that is already present (e.g. `{ createNodes, createNodesV2 }`),
92
+ * the duplicate is dropped. Returns without recording a change when the binding
93
+ * list contains no `createNodesV2`.
94
+ */
95
+ function rewriteNamedBindings(sourceFile, namedBindings, changes) {
96
+ const elements = namedBindings.elements;
97
+ const hasDeprecated = elements.some((el) => (el.propertyName ?? el.name).text === DEPRECATED_NAME);
98
+ if (!hasDeprecated) {
99
+ return;
100
+ }
101
+ const seen = new Set();
102
+ const rendered = [];
103
+ for (const el of elements) {
104
+ const text = renderSpecifier(el);
105
+ if (!seen.has(text)) {
106
+ seen.add(text);
107
+ rendered.push(text);
108
+ }
109
+ }
110
+ const start = namedBindings.getStart(sourceFile);
111
+ changes.push({
112
+ type: devkit_1.ChangeType.Delete,
113
+ start,
114
+ length: namedBindings.getEnd() - start,
115
+ }, {
116
+ type: devkit_1.ChangeType.Insert,
117
+ index: start,
118
+ text: `{ ${rendered.join(', ')} }`,
119
+ });
120
+ }
121
+ function renderSpecifier(el) {
122
+ const typePrefix = el.isTypeOnly ? 'type ' : '';
123
+ const rename = (name) => name === DEPRECATED_NAME ? CANONICAL_NAME : name;
124
+ // `{ name }` — no alias, so the local binding follows the rename.
125
+ if (!el.propertyName) {
126
+ return `${typePrefix}${rename(el.name.text)}`;
127
+ }
128
+ // `{ propertyName as name }` — only the imported (left) side is renamed; the
129
+ // local alias is preserved. A now-redundant alias such as
130
+ // `createNodesV2 as createNodes` collapses to `createNodes`.
131
+ const canonicalImported = rename(el.propertyName.text);
132
+ const localName = el.name.text;
133
+ return canonicalImported === localName
134
+ ? `${typePrefix}${localName}`
135
+ : `${typePrefix}${canonicalImported} as ${localName}`;
136
+ }
package/migrations.json CHANGED
@@ -1,3 +1,10 @@
1
1
  {
2
- "generators": {}
2
+ "generators": {
3
+ "update-23-0-0-migrate-create-nodes-v2-import": {
4
+ "version": "23.0.0-beta.24",
5
+ "description": "Rename imports of `createNodesV2` from `@nx/playwright/plugin` to the canonical `createNodes` export.",
6
+ "implementation": "./dist/src/migrations/update-23-0-0/migrate-create-nodes-v2-to-create-nodes",
7
+ "documentation": "./dist/src/migrations/update-23-0-0/migrate-create-nodes-v2-to-create-nodes.md"
8
+ }
9
+ }
3
10
  }
package/package.json CHANGED
@@ -1,12 +1,11 @@
1
1
  {
2
2
  "name": "@nx/playwright",
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": [
7
7
  "dist",
8
8
  "!dist/tsconfig.tsbuildinfo",
9
- "!dist/spec",
10
9
  "migrations.json",
11
10
  "executors.json",
12
11
  "generators.json"
@@ -72,18 +71,19 @@
72
71
  "executors": "./executors.json",
73
72
  "generators": "./generators.json",
74
73
  "nx-migrations": {
75
- "migrations": "./migrations.json"
74
+ "migrations": "./migrations.json",
75
+ "supportsOptionalUpdates": true
76
76
  },
77
77
  "dependencies": {
78
78
  "tslib": "^2.3.0",
79
79
  "minimatch": "10.2.5",
80
80
  "semver": "^7.6.3",
81
- "@nx/devkit": "23.0.0-beta.23",
82
- "@nx/eslint": "23.0.0-beta.23",
83
- "@nx/js": "23.0.0-beta.23"
81
+ "@nx/devkit": "23.0.0-beta.25",
82
+ "@nx/eslint": "23.0.0-beta.25",
83
+ "@nx/js": "23.0.0-beta.25"
84
84
  },
85
85
  "devDependencies": {
86
- "nx": "23.0.0-beta.23"
86
+ "nx": "23.0.0-beta.25"
87
87
  },
88
88
  "peerDependencies": {
89
89
  "@playwright/test": "^1.36.0"
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });