@absolutejs/changelog 0.7.1 → 0.8.0
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.
- package/CHANGELOG.md +7 -0
- package/changelog.json +17 -0
- package/dist/apply.d.ts +5 -1
- package/dist/applyDependencies.d.ts +13 -0
- package/dist/applyMethods.d.ts +16 -0
- package/dist/cli.js +25 -2
- package/dist/cli.js.map +5 -5
- package/dist/index.d.ts +2 -1
- package/dist/index.js +281 -57
- package/dist/index.js.map +9 -7
- package/dist/types.d.ts +39 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,142 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/apply.ts
|
|
3
|
+
import ts2 from "typescript";
|
|
4
|
+
|
|
5
|
+
// src/applyMethods.ts
|
|
3
6
|
import ts from "typescript";
|
|
7
|
+
var IDENTIFIER = /^[A-Za-z_$][\w$]*$/u;
|
|
8
|
+
var PASSES_INSTANCE = new Set(["use", "group", "guard"]);
|
|
9
|
+
var MAX_HOPS = 200;
|
|
10
|
+
var unwrap = (node) => {
|
|
11
|
+
if (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isNonNullExpression(node) || ts.isSatisfiesExpression(node) || ts.isAwaitExpression(node))
|
|
12
|
+
return unwrap(node.expression);
|
|
13
|
+
return node;
|
|
14
|
+
};
|
|
15
|
+
var importsOwner = (statement, owner) => ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier) && statement.moduleSpecifier.text === owner.module;
|
|
16
|
+
var bindingsOf = (file, owner) => {
|
|
17
|
+
const binding = { names: new Set, namespaces: new Set, owner };
|
|
18
|
+
const clauses = file.statements.filter((statement) => importsOwner(statement, owner)).map((statement) => statement.importClause?.namedBindings).filter((clause) => clause !== undefined);
|
|
19
|
+
for (const clause of clauses) {
|
|
20
|
+
if (ts.isNamespaceImport(clause))
|
|
21
|
+
binding.namespaces.add(clause.name.text);
|
|
22
|
+
else
|
|
23
|
+
clause.elements.filter((element) => (element.propertyName ?? element.name).text === owner.export).forEach((element) => binding.names.add(element.name.text));
|
|
24
|
+
}
|
|
25
|
+
return binding;
|
|
26
|
+
};
|
|
27
|
+
var halvesOf = (node) => {
|
|
28
|
+
if (ts.isPropertyAccessExpression(node))
|
|
29
|
+
return { left: node.expression, right: node.name };
|
|
30
|
+
if (ts.isQualifiedName(node))
|
|
31
|
+
return { left: node.left, right: node.right };
|
|
32
|
+
return;
|
|
33
|
+
};
|
|
34
|
+
var namesOwner = (node, binding) => {
|
|
35
|
+
if (ts.isIdentifier(node))
|
|
36
|
+
return binding.names.has(node.text);
|
|
37
|
+
const halves = halvesOf(node);
|
|
38
|
+
if (halves === undefined)
|
|
39
|
+
return false;
|
|
40
|
+
const { left, right } = halves;
|
|
41
|
+
return ts.isIdentifier(left) && binding.namespaces.has(left.text) && ts.isIdentifier(right) && right.text === binding.owner.export;
|
|
42
|
+
};
|
|
43
|
+
var typedAsOwner = (type, binding) => type !== undefined && ts.isTypeReferenceNode(type) && namesOwner(type.typeName, binding);
|
|
44
|
+
var parameterFor = (node) => {
|
|
45
|
+
let scope = node.parent;
|
|
46
|
+
while (scope !== undefined) {
|
|
47
|
+
const found = ts.isFunctionLike(scope) ? scope.parameters.find((parameter) => ts.isIdentifier(parameter.name) && parameter.name.text === node.text) : undefined;
|
|
48
|
+
if (found !== undefined)
|
|
49
|
+
return found;
|
|
50
|
+
scope = scope.parent;
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
};
|
|
54
|
+
var handedBy = (parameter) => {
|
|
55
|
+
const handler = parameter.parent;
|
|
56
|
+
if (!ts.isArrowFunction(handler) && !ts.isFunctionExpression(handler))
|
|
57
|
+
return;
|
|
58
|
+
if (handler.parameters[0] !== parameter)
|
|
59
|
+
return;
|
|
60
|
+
const call = handler.parent;
|
|
61
|
+
if (!ts.isCallExpression(call) || !call.arguments.includes(handler))
|
|
62
|
+
return;
|
|
63
|
+
const callee = call.expression;
|
|
64
|
+
return ts.isPropertyAccessExpression(callee) && PASSES_INSTANCE.has(callee.name.text) ? callee.expression : undefined;
|
|
65
|
+
};
|
|
66
|
+
var variablesOf = (file) => {
|
|
67
|
+
const declared = [];
|
|
68
|
+
const collect = (node) => {
|
|
69
|
+
if (ts.isVariableDeclaration(node) && ts.isIdentifier(node.name))
|
|
70
|
+
declared.push({ declaration: node, name: node.name.text });
|
|
71
|
+
ts.forEachChild(node, collect);
|
|
72
|
+
};
|
|
73
|
+
collect(file);
|
|
74
|
+
return declared;
|
|
75
|
+
};
|
|
76
|
+
var applyEdits = (source, edits) => [...edits].sort((left, right) => right.start - left.start).reduce((out, edit) => out.slice(0, edit.start) + edit.text + out.slice(edit.end), source);
|
|
77
|
+
var applyMethods = (input) => {
|
|
78
|
+
const { file, methods, source } = input;
|
|
79
|
+
const unchanged = { changed: false, notes: [], source };
|
|
80
|
+
const renameOf = new Map(Object.entries(methods.renames).filter(([before, after]) => IDENTIFIER.test(before) && IDENTIFIER.test(after)));
|
|
81
|
+
if (renameOf.size === 0)
|
|
82
|
+
return unchanged;
|
|
83
|
+
const binding = bindingsOf(file, methods.owner);
|
|
84
|
+
if (binding.names.size === 0 && binding.namespaces.size === 0)
|
|
85
|
+
return unchanged;
|
|
86
|
+
const instances = new Set;
|
|
87
|
+
const step = (node) => {
|
|
88
|
+
if (ts.isNewExpression(node))
|
|
89
|
+
return namesOwner(node.expression, binding);
|
|
90
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression))
|
|
91
|
+
return unwrap(node.expression.expression);
|
|
92
|
+
if (!ts.isIdentifier(node))
|
|
93
|
+
return false;
|
|
94
|
+
const parameter = parameterFor(node);
|
|
95
|
+
if (parameter === undefined)
|
|
96
|
+
return instances.has(node.text);
|
|
97
|
+
if (typedAsOwner(parameter.type, binding))
|
|
98
|
+
return true;
|
|
99
|
+
const receiver = handedBy(parameter);
|
|
100
|
+
return receiver === undefined ? false : unwrap(receiver);
|
|
101
|
+
};
|
|
102
|
+
const isInstance = (expression) => {
|
|
103
|
+
let current = unwrap(expression);
|
|
104
|
+
for (let hops = 0;hops < MAX_HOPS; hops += 1) {
|
|
105
|
+
if (typeof current === "boolean")
|
|
106
|
+
return current;
|
|
107
|
+
current = step(current);
|
|
108
|
+
}
|
|
109
|
+
return current === true;
|
|
110
|
+
};
|
|
111
|
+
const variables = variablesOf(file);
|
|
112
|
+
const newlyFound = () => variables.filter(({ declaration, name }) => !instances.has(name) && (typedAsOwner(declaration.type, binding) || declaration.initializer !== undefined && isInstance(declaration.initializer)));
|
|
113
|
+
let found = newlyFound();
|
|
114
|
+
while (found.length > 0) {
|
|
115
|
+
found.forEach(({ name }) => instances.add(name));
|
|
116
|
+
found = newlyFound();
|
|
117
|
+
}
|
|
118
|
+
const edits = [];
|
|
119
|
+
const visit = (node) => {
|
|
120
|
+
if (ts.isCallExpression(node) && ts.isPropertyAccessExpression(node.expression) && renameOf.has(node.expression.name.text) && isInstance(node.expression.expression)) {
|
|
121
|
+
const { name } = node.expression;
|
|
122
|
+
edits.push({
|
|
123
|
+
end: name.getEnd(),
|
|
124
|
+
start: name.getStart(file),
|
|
125
|
+
text: renameOf.get(name.text) ?? name.text
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
ts.forEachChild(node, visit);
|
|
129
|
+
};
|
|
130
|
+
visit(file);
|
|
131
|
+
if (edits.length === 0)
|
|
132
|
+
return unchanged;
|
|
133
|
+
const changed = {
|
|
134
|
+
changed: true,
|
|
135
|
+
notes: [],
|
|
136
|
+
source: applyEdits(source, edits)
|
|
137
|
+
};
|
|
138
|
+
return changed;
|
|
139
|
+
};
|
|
4
140
|
|
|
5
141
|
// src/types.ts
|
|
6
142
|
var CHANGE_KINDS = [
|
|
@@ -18,21 +154,22 @@ var CHANGELOG_CONTRACT = 1;
|
|
|
18
154
|
var CHANGELOG_FILE = "changelog.json";
|
|
19
155
|
var CHANGELOG_MARKDOWN = "CHANGELOG.md";
|
|
20
156
|
var UNRELEASED_DIRECTORY = "changelog/unreleased";
|
|
157
|
+
var isDependencyMigration = (migration) => ("dependencies" in migration);
|
|
21
158
|
var isDisruptive = (change) => change.kind === "breaking" || change.kind === "removed";
|
|
22
159
|
var isMechanical = (migration) => !("manual" in migration);
|
|
23
160
|
|
|
24
161
|
// src/apply.ts
|
|
25
|
-
var
|
|
162
|
+
var IDENTIFIER2 = /^[A-Za-z_$][\w$]*$/u;
|
|
26
163
|
var SPECIFIER = /^[@a-zA-Z0-9._~-][a-zA-Z0-9._~/-]*$/u;
|
|
27
|
-
var
|
|
28
|
-
var kindOf = (path) => /\.[cm]?ts$/u.test(path) ?
|
|
29
|
-
var parse = (source, path) =>
|
|
164
|
+
var applyEdits2 = (source, edits) => [...edits].sort((left, right) => right.start - left.start).reduce((out, edit) => out.slice(0, edit.start) + edit.text + out.slice(edit.end), source);
|
|
165
|
+
var kindOf = (path) => /\.[cm]?ts$/u.test(path) ? ts2.ScriptKind.TS : ts2.ScriptKind.TSX;
|
|
166
|
+
var parse = (source, path) => ts2.createSourceFile(path, source, ts2.ScriptTarget.Latest, true, kindOf(path));
|
|
30
167
|
var belongsTo = (specifier, name) => specifier === name || specifier.startsWith(`${name}/`);
|
|
31
|
-
var moduleTextOf = (statement) => statement.moduleSpecifier !== undefined &&
|
|
168
|
+
var moduleTextOf = (statement) => statement.moduleSpecifier !== undefined && ts2.isStringLiteral(statement.moduleSpecifier) ? statement.moduleSpecifier.text : undefined;
|
|
32
169
|
var portsOf = (file) => {
|
|
33
170
|
const found = [];
|
|
34
171
|
for (const statement of file.statements) {
|
|
35
|
-
if (!
|
|
172
|
+
if (!ts2.isImportDeclaration(statement) && !ts2.isExportDeclaration(statement))
|
|
36
173
|
continue;
|
|
37
174
|
const module = moduleTextOf(statement);
|
|
38
175
|
if (module !== undefined)
|
|
@@ -41,10 +178,10 @@ var portsOf = (file) => {
|
|
|
41
178
|
return found;
|
|
42
179
|
};
|
|
43
180
|
var namedElementsOf = (statement) => {
|
|
44
|
-
const clause =
|
|
181
|
+
const clause = ts2.isImportDeclaration(statement) ? statement.importClause?.namedBindings : statement.exportClause;
|
|
45
182
|
if (clause === undefined)
|
|
46
183
|
return;
|
|
47
|
-
if (
|
|
184
|
+
if (ts2.isNamedImports(clause) || ts2.isNamedExports(clause))
|
|
48
185
|
return clause;
|
|
49
186
|
return;
|
|
50
187
|
};
|
|
@@ -54,46 +191,46 @@ var declaresLocally = (file, name) => {
|
|
|
54
191
|
const visit = (node) => {
|
|
55
192
|
if (found)
|
|
56
193
|
return;
|
|
57
|
-
const declares = (
|
|
194
|
+
const declares = (ts2.isVariableDeclaration(node) || ts2.isFunctionDeclaration(node) || ts2.isClassDeclaration(node) || ts2.isInterfaceDeclaration(node) || ts2.isTypeAliasDeclaration(node) || ts2.isEnumDeclaration(node) || ts2.isParameter(node) || ts2.isBindingElement(node)) && node.name !== undefined && ts2.isIdentifier(node.name) && node.name.text === name;
|
|
58
195
|
if (declares)
|
|
59
196
|
found = true;
|
|
60
197
|
else
|
|
61
|
-
|
|
198
|
+
ts2.forEachChild(node, visit);
|
|
62
199
|
};
|
|
63
|
-
|
|
200
|
+
ts2.forEachChild(file, visit);
|
|
64
201
|
return found;
|
|
65
202
|
};
|
|
66
203
|
var isReference = (node) => {
|
|
67
204
|
const { parent } = node;
|
|
68
205
|
if (parent === undefined)
|
|
69
206
|
return false;
|
|
70
|
-
if (
|
|
207
|
+
if (ts2.isPropertyAccessExpression(parent) && parent.name === node)
|
|
71
208
|
return false;
|
|
72
|
-
if (
|
|
209
|
+
if (ts2.isQualifiedName(parent) && parent.right === node)
|
|
73
210
|
return false;
|
|
74
|
-
if (
|
|
211
|
+
if (ts2.isPropertyAssignment(parent) && parent.name === node)
|
|
75
212
|
return false;
|
|
76
|
-
if (
|
|
213
|
+
if (ts2.isBindingElement(parent) && parent.propertyName === node)
|
|
77
214
|
return false;
|
|
78
|
-
if (
|
|
215
|
+
if (ts2.isJsxAttribute(parent) && parent.name === node)
|
|
79
216
|
return false;
|
|
80
|
-
if ((
|
|
217
|
+
if ((ts2.isMethodDeclaration(parent) || ts2.isPropertyDeclaration(parent) || ts2.isPropertySignature(parent) || ts2.isMethodSignature(parent) || ts2.isEnumMember(parent)) && parent.name === node)
|
|
81
218
|
return false;
|
|
82
|
-
if ((
|
|
219
|
+
if ((ts2.isImportSpecifier(parent) || ts2.isExportSpecifier(parent) || ts2.isImportClause(parent) || ts2.isNamespaceImport(parent)) && true)
|
|
83
220
|
return false;
|
|
84
|
-
return !
|
|
221
|
+
return !ts2.isDeclarationStatement(parent);
|
|
85
222
|
};
|
|
86
223
|
var referencesTo = (file, name) => {
|
|
87
224
|
const found = [];
|
|
88
225
|
const shorthand = [];
|
|
89
226
|
const visit = (node) => {
|
|
90
|
-
if (
|
|
227
|
+
if (ts2.isShorthandPropertyAssignment(node) && node.name.text === name)
|
|
91
228
|
shorthand.push(node);
|
|
92
|
-
else if (
|
|
229
|
+
else if (ts2.isIdentifier(node) && node.text === name && isReference(node))
|
|
93
230
|
found.push(node);
|
|
94
|
-
|
|
231
|
+
ts2.forEachChild(node, visit);
|
|
95
232
|
};
|
|
96
|
-
|
|
233
|
+
ts2.forEachChild(file, visit);
|
|
97
234
|
return { references: found, shorthand };
|
|
98
235
|
};
|
|
99
236
|
var withoutElement = (elements, dropped, file) => {
|
|
@@ -103,7 +240,7 @@ var withoutElement = (elements, dropped, file) => {
|
|
|
103
240
|
var isTypeOnly = (statement, element) => {
|
|
104
241
|
if (element.isTypeOnly)
|
|
105
242
|
return true;
|
|
106
|
-
return
|
|
243
|
+
return ts2.isImportDeclaration(statement) ? statement.importClause?.isTypeOnly === true : statement.isTypeOnly;
|
|
107
244
|
};
|
|
108
245
|
var quoteOf = (statement, file) => statement.moduleSpecifier?.getText(file).startsWith('"') === true ? '"' : "'";
|
|
109
246
|
var renameTargetsIn = (input) => portsOf(input.file).filter(({ module }) => belongsTo(module, input.packageName)).flatMap(({ statement }) => {
|
|
@@ -157,7 +294,7 @@ var renameOneImport = (input) => {
|
|
|
157
294
|
};
|
|
158
295
|
var applyRename = (input) => {
|
|
159
296
|
const { file, packageName, rename, source } = input;
|
|
160
|
-
if (!
|
|
297
|
+
if (!IDENTIFIER2.test(rename.to))
|
|
161
298
|
return {
|
|
162
299
|
changed: false,
|
|
163
300
|
notes: [`\`${rename.to}\` is not a name, so this rename was not applied`],
|
|
@@ -185,7 +322,7 @@ var applyRename = (input) => {
|
|
|
185
322
|
return {
|
|
186
323
|
changed: true,
|
|
187
324
|
notes: done.flatMap((one) => ("note" in one) && one.note ? [one.note] : []),
|
|
188
|
-
source:
|
|
325
|
+
source: applyEdits2(source, edits)
|
|
189
326
|
};
|
|
190
327
|
};
|
|
191
328
|
var applyMoved = (input) => {
|
|
@@ -210,7 +347,7 @@ var applyMoved = (input) => {
|
|
|
210
347
|
continue;
|
|
211
348
|
const quote = quoteOf(statement, file);
|
|
212
349
|
const kept = withoutElement(clause.elements, element, file);
|
|
213
|
-
const carriesDefault =
|
|
350
|
+
const carriesDefault = ts2.isImportDeclaration(statement) && (statement.importClause?.name !== undefined || statement.importClause?.isTypeOnly === true);
|
|
214
351
|
const whole = kept === undefined && !carriesDefault && statement.moduleSpecifier;
|
|
215
352
|
if (whole)
|
|
216
353
|
edits.push({
|
|
@@ -220,10 +357,10 @@ var applyMoved = (input) => {
|
|
|
220
357
|
});
|
|
221
358
|
if (whole)
|
|
222
359
|
continue;
|
|
223
|
-
const keyword =
|
|
360
|
+
const keyword = ts2.isExportDeclaration(statement) ? "export" : "import";
|
|
224
361
|
const typed = isTypeOnly(statement, element) ? "type " : "";
|
|
225
362
|
const carried = element.propertyName ? `${moved.symbol} as ${element.name.text}` : element.name.text;
|
|
226
|
-
const carrier =
|
|
363
|
+
const carrier = ts2.isImportDeclaration(statement) && statement.importClause?.name;
|
|
227
364
|
const emptied = kept === undefined && carrier ? { end: clause.getEnd(), start: carrier.getEnd(), text: "" } : undefined;
|
|
228
365
|
const trimmed = kept === undefined ? undefined : {
|
|
229
366
|
end: clause.getEnd() - 1,
|
|
@@ -240,7 +377,7 @@ ${keyword} ${typed}{ ${carried} } from ${quote}${moved.to}${quote};`
|
|
|
240
377
|
}
|
|
241
378
|
if (edits.length === 0)
|
|
242
379
|
return { changed: false, notes: [], source };
|
|
243
|
-
return { changed: true, notes: [], source:
|
|
380
|
+
return { changed: true, notes: [], source: applyEdits2(source, edits) };
|
|
244
381
|
};
|
|
245
382
|
var applyResubpath = (input) => {
|
|
246
383
|
const { file, resubpath, source } = input;
|
|
@@ -265,7 +402,7 @@ var applyResubpath = (input) => {
|
|
|
265
402
|
}
|
|
266
403
|
if (edits.length === 0)
|
|
267
404
|
return { changed: false, notes: [], source };
|
|
268
|
-
return { changed: true, notes: [], source:
|
|
405
|
+
return { changed: true, notes: [], source: applyEdits2(source, edits) };
|
|
269
406
|
};
|
|
270
407
|
var applyMigration = (source, input) => {
|
|
271
408
|
const { migration, packageName } = input;
|
|
@@ -281,6 +418,10 @@ var applyMigration = (source, input) => {
|
|
|
281
418
|
});
|
|
282
419
|
if ("resubpath" in migration)
|
|
283
420
|
return applyResubpath({ file, resubpath: migration.resubpath, source });
|
|
421
|
+
if ("methods" in migration)
|
|
422
|
+
return applyMethods({ file, methods: migration.methods, source });
|
|
423
|
+
if ("dependencies" in migration)
|
|
424
|
+
return { changed: false, notes: [], source };
|
|
284
425
|
return applyMoved({ file, moved: migration.moved, source });
|
|
285
426
|
};
|
|
286
427
|
var applyMigrations = (source, input) => input.migrations.reduce((carried, migration) => {
|
|
@@ -295,6 +436,65 @@ var applyMigrations = (source, input) => input.migrations.reduce((carried, migra
|
|
|
295
436
|
source: result.source
|
|
296
437
|
};
|
|
297
438
|
}, { changed: false, notes: [], source });
|
|
439
|
+
// src/applyDependencies.ts
|
|
440
|
+
var SECTIONS = [
|
|
441
|
+
"dependencies",
|
|
442
|
+
"devDependencies",
|
|
443
|
+
"peerDependencies",
|
|
444
|
+
"optionalDependencies"
|
|
445
|
+
];
|
|
446
|
+
var RANGE = /^[\w.^~<>=*| -]+$/u;
|
|
447
|
+
var VERSIONED = /^[\^~<>=]*\s*v?\d/u;
|
|
448
|
+
var SCOPE_WILDCARD = "/*";
|
|
449
|
+
var isTable = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
450
|
+
var matches = (pattern, name) => pattern.endsWith(SCOPE_WILDCARD) ? name.startsWith(pattern.slice(0, pattern.length - 1)) : pattern === name;
|
|
451
|
+
var floorOf = (spec) => spec.trim().replace(/^[\^~<>=v\s]+/u, "").split(/[\s|]/u)[0] ?? "";
|
|
452
|
+
var satisfies = (version, range) => {
|
|
453
|
+
try {
|
|
454
|
+
return Bun.semver.satisfies(version, range);
|
|
455
|
+
} catch {
|
|
456
|
+
return false;
|
|
457
|
+
}
|
|
458
|
+
};
|
|
459
|
+
var indentOf = (text) => /\n([ \t]+)"/u.exec(text)?.[1] ?? " ";
|
|
460
|
+
var moves = (migration, name, spec) => {
|
|
461
|
+
const { names, range } = migration.dependencies;
|
|
462
|
+
return typeof spec === "string" && VERSIONED.test(spec) && names.some((pattern) => matches(pattern, name)) && spec !== range && !satisfies(floorOf(spec), range);
|
|
463
|
+
};
|
|
464
|
+
var moveSection = (table, section, migration) => {
|
|
465
|
+
const { range } = migration.dependencies;
|
|
466
|
+
const edits = [];
|
|
467
|
+
for (const [name, spec] of Object.entries(table)) {
|
|
468
|
+
if (!moves(migration, name, spec))
|
|
469
|
+
continue;
|
|
470
|
+
table[name] = range;
|
|
471
|
+
edits.push({ from: spec, name, section, to: range });
|
|
472
|
+
}
|
|
473
|
+
return edits;
|
|
474
|
+
};
|
|
475
|
+
var applyDependencyMigrations = (manifest, migrations) => {
|
|
476
|
+
const unchanged = { edits: [], manifest };
|
|
477
|
+
const wanted = migrations.filter(isDependencyMigration).filter((migration) => RANGE.test(migration.dependencies.range));
|
|
478
|
+
if (wanted.length === 0)
|
|
479
|
+
return unchanged;
|
|
480
|
+
const document = JSON.parse(manifest);
|
|
481
|
+
if (!isTable(document))
|
|
482
|
+
return unchanged;
|
|
483
|
+
const edits = wanted.flatMap((migration) => SECTIONS.flatMap((section) => {
|
|
484
|
+
const table = document[section];
|
|
485
|
+
return isTable(table) ? moveSection(table, section, migration) : [];
|
|
486
|
+
}));
|
|
487
|
+
if (edits.length === 0)
|
|
488
|
+
return unchanged;
|
|
489
|
+
const trailing = manifest.endsWith(`
|
|
490
|
+
`) ? `
|
|
491
|
+
` : "";
|
|
492
|
+
const moved = {
|
|
493
|
+
edits,
|
|
494
|
+
manifest: JSON.stringify(document, null, indentOf(manifest)) + trailing
|
|
495
|
+
};
|
|
496
|
+
return moved;
|
|
497
|
+
};
|
|
298
498
|
// src/authoring.ts
|
|
299
499
|
var change = (entry) => entry;
|
|
300
500
|
var manual = (instruction) => ({
|
|
@@ -442,9 +642,27 @@ var readMigration = (value, where, problems) => {
|
|
|
442
642
|
instruction,
|
|
443
643
|
resubpath: { from: resubpath.from, to: resubpath.to }
|
|
444
644
|
};
|
|
645
|
+
const { methods } = value;
|
|
646
|
+
if (isRecord(methods) && isRecord(methods.owner) && isText(methods.owner.module) && isText(methods.owner.export) && isRecord(methods.renames) && Object.keys(methods.renames).length > 0 && Object.values(methods.renames).every(isText))
|
|
647
|
+
return {
|
|
648
|
+
instruction,
|
|
649
|
+
methods: {
|
|
650
|
+
owner: { export: methods.owner.export, module: methods.owner.module },
|
|
651
|
+
renames: Object.fromEntries(Object.entries(methods.renames).filter((entry) => isText(entry[1])))
|
|
652
|
+
}
|
|
653
|
+
};
|
|
654
|
+
const { dependencies } = value;
|
|
655
|
+
if (isRecord(dependencies) && isText(dependencies.range) && Array.isArray(dependencies.names) && dependencies.names.length > 0 && dependencies.names.every(isText)) {
|
|
656
|
+
const [first, ...rest] = dependencies.names.filter((name) => isText(name));
|
|
657
|
+
if (first !== undefined)
|
|
658
|
+
return {
|
|
659
|
+
dependencies: { names: [first, ...rest], range: dependencies.range },
|
|
660
|
+
instruction
|
|
661
|
+
};
|
|
662
|
+
}
|
|
445
663
|
if (value.manual === true)
|
|
446
664
|
return { instruction, manual: true };
|
|
447
|
-
problems.push(`${where}: migration says neither rename, moved, resubpath nor manual`);
|
|
665
|
+
problems.push(`${where}: migration says neither rename, moved, resubpath, methods, dependencies nor manual`);
|
|
448
666
|
return;
|
|
449
667
|
};
|
|
450
668
|
var readChange = (value, where, problems) => {
|
|
@@ -577,7 +795,7 @@ var symbolsDisturbedBetween = (changelog, from, upto) => new Set(disruptiveBetwe
|
|
|
577
795
|
|
|
578
796
|
// src/surface.ts
|
|
579
797
|
import path from "path";
|
|
580
|
-
import
|
|
798
|
+
import ts3 from "typescript";
|
|
581
799
|
|
|
582
800
|
// src/tarball.ts
|
|
583
801
|
var TAR_BLOCK = 512;
|
|
@@ -632,33 +850,33 @@ var readTar = (archive, keep, limits = {}) => {
|
|
|
632
850
|
|
|
633
851
|
// src/surface.ts
|
|
634
852
|
var DECLARATION = /\.d\.[cm]?ts$/u;
|
|
635
|
-
var parse2 = (source, name) =>
|
|
853
|
+
var parse2 = (source, name) => ts3.createSourceFile(name, source, ts3.ScriptTarget.Latest, true, ts3.ScriptKind.TS);
|
|
636
854
|
var normalize = (text) => text.replace(/\s+/gu, " ").trim();
|
|
637
855
|
var CLOSERS = new Set(["}", ")", "]", ">"]);
|
|
638
856
|
var wordy = (token) => /^[\w$#@]/u.test(token) || /[\w$]$/u.test(token);
|
|
639
857
|
var LAST2 = -1;
|
|
640
858
|
var tokenText = (scanner, scanned, state) => {
|
|
641
|
-
const closesTemplate = scanned ===
|
|
859
|
+
const closesTemplate = scanned === ts3.SyntaxKind.CloseBraceToken && state.templates.at(LAST2) === state.depth;
|
|
642
860
|
const token = closesTemplate ? scanner.reScanTemplateToken(false) : scanned;
|
|
643
|
-
if (closesTemplate && token ===
|
|
861
|
+
if (closesTemplate && token === ts3.SyntaxKind.TemplateTail)
|
|
644
862
|
state.templates.pop();
|
|
645
863
|
if (closesTemplate)
|
|
646
864
|
return scanner.getTokenText();
|
|
647
|
-
if (token ===
|
|
865
|
+
if (token === ts3.SyntaxKind.StringLiteral)
|
|
648
866
|
return JSON.stringify(scanner.getTokenValue());
|
|
649
|
-
if (token ===
|
|
867
|
+
if (token === ts3.SyntaxKind.TemplateHead)
|
|
650
868
|
state.templates.push(state.depth);
|
|
651
|
-
if (token ===
|
|
869
|
+
if (token === ts3.SyntaxKind.OpenBraceToken)
|
|
652
870
|
state.depth += 1;
|
|
653
|
-
if (token ===
|
|
871
|
+
if (token === ts3.SyntaxKind.CloseBraceToken)
|
|
654
872
|
state.depth -= 1;
|
|
655
873
|
return scanner.getTokenText();
|
|
656
874
|
};
|
|
657
875
|
var canonical = (text) => {
|
|
658
|
-
const scanner =
|
|
876
|
+
const scanner = ts3.createScanner(ts3.ScriptTarget.Latest, true, ts3.LanguageVariant.Standard, text);
|
|
659
877
|
const state = { depth: 0, templates: [] };
|
|
660
878
|
const tokens = [];
|
|
661
|
-
for (let token = scanner.scan();token !==
|
|
879
|
+
for (let token = scanner.scan();token !== ts3.SyntaxKind.EndOfFileToken; token = scanner.scan()) {
|
|
662
880
|
const value = tokenText(scanner, token, state);
|
|
663
881
|
if (CLOSERS.has(value) && tokens.at(LAST2) === ",")
|
|
664
882
|
tokens.pop();
|
|
@@ -682,12 +900,12 @@ var resolveFrom = (files, from, specifier) => {
|
|
|
682
900
|
return candidates.find((candidate) => files.has(candidate));
|
|
683
901
|
};
|
|
684
902
|
var declaredNameOf = (statement) => {
|
|
685
|
-
if (
|
|
686
|
-
return statement.name !== undefined &&
|
|
903
|
+
if (ts3.isFunctionDeclaration(statement) || ts3.isClassDeclaration(statement) || ts3.isInterfaceDeclaration(statement) || ts3.isTypeAliasDeclaration(statement) || ts3.isEnumDeclaration(statement) || ts3.isModuleDeclaration(statement))
|
|
904
|
+
return statement.name !== undefined && ts3.isIdentifier(statement.name) ? statement.name.text : undefined;
|
|
687
905
|
return;
|
|
688
906
|
};
|
|
689
|
-
var isExported = (statement) =>
|
|
690
|
-
var variableNamesOf = (statement) => statement.declarationList.declarations.map((declaration) => declaration.name).filter((name) =>
|
|
907
|
+
var isExported = (statement) => ts3.canHaveModifiers(statement) && ts3.getModifiers(statement)?.some((modifier) => modifier.kind === ts3.SyntaxKind.ExportKeyword) === true;
|
|
908
|
+
var variableNamesOf = (statement) => statement.declarationList.declarations.map((declaration) => declaration.name).filter((name) => ts3.isIdentifier(name)).map((name) => name.text);
|
|
691
909
|
var declarationsIn = (file) => {
|
|
692
910
|
const found = new Map;
|
|
693
911
|
for (const statement of file.statements) {
|
|
@@ -695,7 +913,7 @@ var declarationsIn = (file) => {
|
|
|
695
913
|
const named = declaredNameOf(statement);
|
|
696
914
|
if (named !== undefined)
|
|
697
915
|
found.set(named, text);
|
|
698
|
-
if (!
|
|
916
|
+
if (!ts3.isVariableStatement(statement))
|
|
699
917
|
continue;
|
|
700
918
|
for (const name of variableNamesOf(statement))
|
|
701
919
|
found.set(name, text);
|
|
@@ -715,7 +933,7 @@ var declaresTypes = (manifest) => {
|
|
|
715
933
|
var contributionOf = (input) => {
|
|
716
934
|
const { file, files, from, local, seen, statement } = input;
|
|
717
935
|
const nothing = [];
|
|
718
|
-
if (
|
|
936
|
+
if (ts3.isExportAssignment(statement))
|
|
719
937
|
return [
|
|
720
938
|
[
|
|
721
939
|
statement.isExportEquals === true ? "export=" : "default",
|
|
@@ -727,19 +945,19 @@ var contributionOf = (input) => {
|
|
|
727
945
|
return [
|
|
728
946
|
[named, local.get(named) ?? normalize(statement.getText(file))]
|
|
729
947
|
];
|
|
730
|
-
if (
|
|
948
|
+
if (ts3.isVariableStatement(statement) && isExported(statement)) {
|
|
731
949
|
const text = normalize(statement.getText(file));
|
|
732
950
|
return variableNamesOf(statement).map((name) => [name, text]);
|
|
733
951
|
}
|
|
734
|
-
if (!
|
|
952
|
+
if (!ts3.isExportDeclaration(statement))
|
|
735
953
|
return nothing;
|
|
736
|
-
const specifier = statement.moduleSpecifier !== undefined &&
|
|
954
|
+
const specifier = statement.moduleSpecifier !== undefined && ts3.isStringLiteral(statement.moduleSpecifier) ? statement.moduleSpecifier.text : undefined;
|
|
737
955
|
const target = specifier === undefined ? undefined : resolveFrom(files, from, specifier);
|
|
738
956
|
const theirs = target === undefined ? new Map : exportsOf(files, target, new Set(seen));
|
|
739
957
|
const clause = statement.exportClause;
|
|
740
958
|
if (clause === undefined)
|
|
741
959
|
return [...theirs].filter(([name]) => name !== "default" && name !== "export=");
|
|
742
|
-
if (
|
|
960
|
+
if (ts3.isNamespaceExport(clause))
|
|
743
961
|
return [[clause.name.text, `export * as ${clause.name.text}`]];
|
|
744
962
|
return clause.elements.map((element) => {
|
|
745
963
|
const sourceName = (element.propertyName ?? element.name).text;
|
|
@@ -846,9 +1064,9 @@ var parametersOf = (declaration) => {
|
|
|
846
1064
|
return "";
|
|
847
1065
|
const found = [];
|
|
848
1066
|
const visit = (node) => {
|
|
849
|
-
if (
|
|
1067
|
+
if (ts3.isFunctionTypeNode(node) || ts3.isFunctionDeclaration(node) || ts3.isMethodSignature(node) || ts3.isMethodDeclaration(node) || ts3.isConstructSignatureDeclaration(node) || ts3.isConstructorDeclaration(node))
|
|
850
1068
|
found.push(node.parameters.map((parameter) => canonical(parameter.getText())).join(", "));
|
|
851
|
-
|
|
1069
|
+
ts3.forEachChild(node, visit);
|
|
852
1070
|
};
|
|
853
1071
|
visit(statement);
|
|
854
1072
|
return found.join(" | ");
|
|
@@ -859,9 +1077,9 @@ var membersOf = (declaration) => {
|
|
|
859
1077
|
if (statement === undefined)
|
|
860
1078
|
return members;
|
|
861
1079
|
const visit = (node) => {
|
|
862
|
-
if ((
|
|
1080
|
+
if ((ts3.isPropertySignature(node) || ts3.isMethodSignature(node) || ts3.isPropertyDeclaration(node) || ts3.isMethodDeclaration(node) || ts3.isEnumMember(node)) && node.name !== undefined && (ts3.isIdentifier(node.name) || ts3.isStringLiteral(node.name)))
|
|
863
1081
|
members.add(node.name.text);
|
|
864
|
-
|
|
1082
|
+
ts3.forEachChild(node, visit);
|
|
865
1083
|
};
|
|
866
1084
|
visit(statement);
|
|
867
1085
|
return members;
|
|
@@ -1208,6 +1426,10 @@ var migrationLine = (migration) => {
|
|
|
1208
1426
|
return `Import \`${migration.moved.symbol}\` from \`${migration.moved.to}\` instead of \`${migration.moved.from}\`.`;
|
|
1209
1427
|
if ("resubpath" in migration)
|
|
1210
1428
|
return `Import from \`${migration.resubpath.to}\` instead of \`${migration.resubpath.from}\`.`;
|
|
1429
|
+
if ("methods" in migration)
|
|
1430
|
+
return `${Object.entries(migration.methods.renames).map(([before, after]) => `\`.${before}()\` is now \`.${after}()\``).join(", ")} on \`${migration.methods.owner.export}\`.`;
|
|
1431
|
+
if ("dependencies" in migration)
|
|
1432
|
+
return `Move ${migration.dependencies.names.map((name) => `\`${name}\``).join(", ")} to \`${migration.dependencies.range}\`.`;
|
|
1211
1433
|
return migration.instruction;
|
|
1212
1434
|
};
|
|
1213
1435
|
var renderChange = (change) => {
|
|
@@ -1292,6 +1514,7 @@ export {
|
|
|
1292
1514
|
CHANGE_KINDS,
|
|
1293
1515
|
DISRUPTIVE_KINDS,
|
|
1294
1516
|
UNRELEASED_DIRECTORY,
|
|
1517
|
+
applyDependencyMigrations,
|
|
1295
1518
|
applyMigration,
|
|
1296
1519
|
applyMigrations,
|
|
1297
1520
|
asText,
|
|
@@ -1307,6 +1530,7 @@ export {
|
|
|
1307
1530
|
diffSurface,
|
|
1308
1531
|
disruptiveBetween,
|
|
1309
1532
|
forgetRegistry,
|
|
1533
|
+
isDependencyMigration,
|
|
1310
1534
|
isDisruptive,
|
|
1311
1535
|
isMechanical,
|
|
1312
1536
|
isPackageName,
|
|
@@ -1339,5 +1563,5 @@ export {
|
|
|
1339
1563
|
validateChange
|
|
1340
1564
|
};
|
|
1341
1565
|
|
|
1342
|
-
//# debugId=
|
|
1566
|
+
//# debugId=0052F7389999EA8F64756E2164756E21
|
|
1343
1567
|
//# sourceMappingURL=index.js.map
|