@nx/devkit 23.0.0-beta.24 → 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.
|
@@ -55,20 +55,28 @@ function rewriteCreateNodesV2Types(source) {
|
|
|
55
55
|
const sourceFile = ts.createSourceFile('tmp.ts', source, ts.ScriptTarget.Latest,
|
|
56
56
|
/* setParentNodes */ true, ts.ScriptKind.TSX);
|
|
57
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();
|
|
58
63
|
for (const stmt of sourceFile.statements) {
|
|
59
64
|
if (ts.isImportDeclaration(stmt)) {
|
|
60
|
-
collectImportRewrite(sourceFile, stmt, changes);
|
|
65
|
+
collectImportRewrite(sourceFile, stmt, changes, localRenames);
|
|
61
66
|
}
|
|
62
67
|
else if (ts.isExportDeclaration(stmt)) {
|
|
63
68
|
collectExportRewrite(sourceFile, stmt, changes);
|
|
64
69
|
}
|
|
65
70
|
}
|
|
71
|
+
if (localRenames.size > 0) {
|
|
72
|
+
collectUsageRewrites(sourceFile, localRenames, changes);
|
|
73
|
+
}
|
|
66
74
|
return changes.length > 0 ? (0, string_change_1.applyChangesToString)(source, changes) : source;
|
|
67
75
|
}
|
|
68
76
|
function isDevkitSpecifier(node) {
|
|
69
77
|
return ts.isStringLiteral(node) && node.text === DEVKIT_SPECIFIER;
|
|
70
78
|
}
|
|
71
|
-
function collectImportRewrite(sourceFile, stmt, changes) {
|
|
79
|
+
function collectImportRewrite(sourceFile, stmt, changes, localRenames) {
|
|
72
80
|
if (!isDevkitSpecifier(stmt.moduleSpecifier)) {
|
|
73
81
|
return;
|
|
74
82
|
}
|
|
@@ -76,8 +84,62 @@ function collectImportRewrite(sourceFile, stmt, changes) {
|
|
|
76
84
|
if (!namedBindings || !ts.isNamedImports(namedBindings)) {
|
|
77
85
|
return;
|
|
78
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
|
+
}
|
|
79
99
|
rewriteNamedBindings(sourceFile, namedBindings, changes);
|
|
80
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
|
+
}
|
|
81
143
|
function collectExportRewrite(sourceFile, stmt, changes) {
|
|
82
144
|
if (!stmt.moduleSpecifier || !isDevkitSpecifier(stmt.moduleSpecifier)) {
|
|
83
145
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/devkit",
|
|
3
|
-
"version": "23.0.0-beta.
|
|
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.
|
|
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
|
".": {
|