@absolutejs/changelog 0.7.1 → 0.8.1
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 +14 -0
- package/changelog.json +31 -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 +307 -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,91 @@ 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 spanOf = (text, section) => {
|
|
460
|
+
const opening = new RegExp(`"${section}"\\s*:\\s*\\{`, "u").exec(text);
|
|
461
|
+
if (opening === null)
|
|
462
|
+
return;
|
|
463
|
+
const start = opening.index + opening[0].length;
|
|
464
|
+
let depth = 1;
|
|
465
|
+
let quoted = false;
|
|
466
|
+
for (let index = start;index < text.length; index += 1) {
|
|
467
|
+
const character = text[index];
|
|
468
|
+
const escaped = quoted && text[index - 1] === "\\";
|
|
469
|
+
if (character === '"' && !escaped)
|
|
470
|
+
quoted = !quoted;
|
|
471
|
+
else if (!quoted && character === "{")
|
|
472
|
+
depth += 1;
|
|
473
|
+
else if (!quoted && character === "}")
|
|
474
|
+
depth -= 1;
|
|
475
|
+
if (depth === 0)
|
|
476
|
+
return { end: index, start };
|
|
477
|
+
}
|
|
478
|
+
return;
|
|
479
|
+
};
|
|
480
|
+
var escapeRegExp = (text) => text.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
|
|
481
|
+
var editText = (text, edit) => {
|
|
482
|
+
const span = spanOf(text, edit.section);
|
|
483
|
+
if (span === undefined)
|
|
484
|
+
return text;
|
|
485
|
+
const inside = text.slice(span.start, span.end);
|
|
486
|
+
const entry = new RegExp(`("${escapeRegExp(edit.name)}"\\s*:\\s*")${escapeRegExp(edit.from)}"`, "u");
|
|
487
|
+
return text.slice(0, span.start) + inside.replace(entry, (_, key) => `${key}${edit.to}"`) + text.slice(span.end);
|
|
488
|
+
};
|
|
489
|
+
var moves = (migration, name, spec) => {
|
|
490
|
+
const { names, range } = migration.dependencies;
|
|
491
|
+
return typeof spec === "string" && VERSIONED.test(spec) && names.some((pattern) => matches(pattern, name)) && spec !== range && !satisfies(floorOf(spec), range);
|
|
492
|
+
};
|
|
493
|
+
var moveSection = (table, section, migration) => {
|
|
494
|
+
const { range } = migration.dependencies;
|
|
495
|
+
const edits = [];
|
|
496
|
+
for (const [name, spec] of Object.entries(table)) {
|
|
497
|
+
if (!moves(migration, name, spec))
|
|
498
|
+
continue;
|
|
499
|
+
table[name] = range;
|
|
500
|
+
edits.push({ from: spec, name, section, to: range });
|
|
501
|
+
}
|
|
502
|
+
return edits;
|
|
503
|
+
};
|
|
504
|
+
var applyDependencyMigrations = (manifest, migrations) => {
|
|
505
|
+
const unchanged = { edits: [], manifest };
|
|
506
|
+
const wanted = migrations.filter(isDependencyMigration).filter((migration) => RANGE.test(migration.dependencies.range));
|
|
507
|
+
if (wanted.length === 0)
|
|
508
|
+
return unchanged;
|
|
509
|
+
const document = JSON.parse(manifest);
|
|
510
|
+
if (!isTable(document))
|
|
511
|
+
return unchanged;
|
|
512
|
+
const edits = wanted.flatMap((migration) => SECTIONS.flatMap((section) => {
|
|
513
|
+
const table = document[section];
|
|
514
|
+
return isTable(table) ? moveSection(table, section, migration) : [];
|
|
515
|
+
}));
|
|
516
|
+
if (edits.length === 0)
|
|
517
|
+
return unchanged;
|
|
518
|
+
const moved = {
|
|
519
|
+
edits,
|
|
520
|
+
manifest: edits.reduce(editText, manifest)
|
|
521
|
+
};
|
|
522
|
+
return moved;
|
|
523
|
+
};
|
|
298
524
|
// src/authoring.ts
|
|
299
525
|
var change = (entry) => entry;
|
|
300
526
|
var manual = (instruction) => ({
|
|
@@ -442,9 +668,27 @@ var readMigration = (value, where, problems) => {
|
|
|
442
668
|
instruction,
|
|
443
669
|
resubpath: { from: resubpath.from, to: resubpath.to }
|
|
444
670
|
};
|
|
671
|
+
const { methods } = value;
|
|
672
|
+
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))
|
|
673
|
+
return {
|
|
674
|
+
instruction,
|
|
675
|
+
methods: {
|
|
676
|
+
owner: { export: methods.owner.export, module: methods.owner.module },
|
|
677
|
+
renames: Object.fromEntries(Object.entries(methods.renames).filter((entry) => isText(entry[1])))
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
const { dependencies } = value;
|
|
681
|
+
if (isRecord(dependencies) && isText(dependencies.range) && Array.isArray(dependencies.names) && dependencies.names.length > 0 && dependencies.names.every(isText)) {
|
|
682
|
+
const [first, ...rest] = dependencies.names.filter((name) => isText(name));
|
|
683
|
+
if (first !== undefined)
|
|
684
|
+
return {
|
|
685
|
+
dependencies: { names: [first, ...rest], range: dependencies.range },
|
|
686
|
+
instruction
|
|
687
|
+
};
|
|
688
|
+
}
|
|
445
689
|
if (value.manual === true)
|
|
446
690
|
return { instruction, manual: true };
|
|
447
|
-
problems.push(`${where}: migration says neither rename, moved, resubpath nor manual`);
|
|
691
|
+
problems.push(`${where}: migration says neither rename, moved, resubpath, methods, dependencies nor manual`);
|
|
448
692
|
return;
|
|
449
693
|
};
|
|
450
694
|
var readChange = (value, where, problems) => {
|
|
@@ -577,7 +821,7 @@ var symbolsDisturbedBetween = (changelog, from, upto) => new Set(disruptiveBetwe
|
|
|
577
821
|
|
|
578
822
|
// src/surface.ts
|
|
579
823
|
import path from "path";
|
|
580
|
-
import
|
|
824
|
+
import ts3 from "typescript";
|
|
581
825
|
|
|
582
826
|
// src/tarball.ts
|
|
583
827
|
var TAR_BLOCK = 512;
|
|
@@ -632,33 +876,33 @@ var readTar = (archive, keep, limits = {}) => {
|
|
|
632
876
|
|
|
633
877
|
// src/surface.ts
|
|
634
878
|
var DECLARATION = /\.d\.[cm]?ts$/u;
|
|
635
|
-
var parse2 = (source, name) =>
|
|
879
|
+
var parse2 = (source, name) => ts3.createSourceFile(name, source, ts3.ScriptTarget.Latest, true, ts3.ScriptKind.TS);
|
|
636
880
|
var normalize = (text) => text.replace(/\s+/gu, " ").trim();
|
|
637
881
|
var CLOSERS = new Set(["}", ")", "]", ">"]);
|
|
638
882
|
var wordy = (token) => /^[\w$#@]/u.test(token) || /[\w$]$/u.test(token);
|
|
639
883
|
var LAST2 = -1;
|
|
640
884
|
var tokenText = (scanner, scanned, state) => {
|
|
641
|
-
const closesTemplate = scanned ===
|
|
885
|
+
const closesTemplate = scanned === ts3.SyntaxKind.CloseBraceToken && state.templates.at(LAST2) === state.depth;
|
|
642
886
|
const token = closesTemplate ? scanner.reScanTemplateToken(false) : scanned;
|
|
643
|
-
if (closesTemplate && token ===
|
|
887
|
+
if (closesTemplate && token === ts3.SyntaxKind.TemplateTail)
|
|
644
888
|
state.templates.pop();
|
|
645
889
|
if (closesTemplate)
|
|
646
890
|
return scanner.getTokenText();
|
|
647
|
-
if (token ===
|
|
891
|
+
if (token === ts3.SyntaxKind.StringLiteral)
|
|
648
892
|
return JSON.stringify(scanner.getTokenValue());
|
|
649
|
-
if (token ===
|
|
893
|
+
if (token === ts3.SyntaxKind.TemplateHead)
|
|
650
894
|
state.templates.push(state.depth);
|
|
651
|
-
if (token ===
|
|
895
|
+
if (token === ts3.SyntaxKind.OpenBraceToken)
|
|
652
896
|
state.depth += 1;
|
|
653
|
-
if (token ===
|
|
897
|
+
if (token === ts3.SyntaxKind.CloseBraceToken)
|
|
654
898
|
state.depth -= 1;
|
|
655
899
|
return scanner.getTokenText();
|
|
656
900
|
};
|
|
657
901
|
var canonical = (text) => {
|
|
658
|
-
const scanner =
|
|
902
|
+
const scanner = ts3.createScanner(ts3.ScriptTarget.Latest, true, ts3.LanguageVariant.Standard, text);
|
|
659
903
|
const state = { depth: 0, templates: [] };
|
|
660
904
|
const tokens = [];
|
|
661
|
-
for (let token = scanner.scan();token !==
|
|
905
|
+
for (let token = scanner.scan();token !== ts3.SyntaxKind.EndOfFileToken; token = scanner.scan()) {
|
|
662
906
|
const value = tokenText(scanner, token, state);
|
|
663
907
|
if (CLOSERS.has(value) && tokens.at(LAST2) === ",")
|
|
664
908
|
tokens.pop();
|
|
@@ -682,12 +926,12 @@ var resolveFrom = (files, from, specifier) => {
|
|
|
682
926
|
return candidates.find((candidate) => files.has(candidate));
|
|
683
927
|
};
|
|
684
928
|
var declaredNameOf = (statement) => {
|
|
685
|
-
if (
|
|
686
|
-
return statement.name !== undefined &&
|
|
929
|
+
if (ts3.isFunctionDeclaration(statement) || ts3.isClassDeclaration(statement) || ts3.isInterfaceDeclaration(statement) || ts3.isTypeAliasDeclaration(statement) || ts3.isEnumDeclaration(statement) || ts3.isModuleDeclaration(statement))
|
|
930
|
+
return statement.name !== undefined && ts3.isIdentifier(statement.name) ? statement.name.text : undefined;
|
|
687
931
|
return;
|
|
688
932
|
};
|
|
689
|
-
var isExported = (statement) =>
|
|
690
|
-
var variableNamesOf = (statement) => statement.declarationList.declarations.map((declaration) => declaration.name).filter((name) =>
|
|
933
|
+
var isExported = (statement) => ts3.canHaveModifiers(statement) && ts3.getModifiers(statement)?.some((modifier) => modifier.kind === ts3.SyntaxKind.ExportKeyword) === true;
|
|
934
|
+
var variableNamesOf = (statement) => statement.declarationList.declarations.map((declaration) => declaration.name).filter((name) => ts3.isIdentifier(name)).map((name) => name.text);
|
|
691
935
|
var declarationsIn = (file) => {
|
|
692
936
|
const found = new Map;
|
|
693
937
|
for (const statement of file.statements) {
|
|
@@ -695,7 +939,7 @@ var declarationsIn = (file) => {
|
|
|
695
939
|
const named = declaredNameOf(statement);
|
|
696
940
|
if (named !== undefined)
|
|
697
941
|
found.set(named, text);
|
|
698
|
-
if (!
|
|
942
|
+
if (!ts3.isVariableStatement(statement))
|
|
699
943
|
continue;
|
|
700
944
|
for (const name of variableNamesOf(statement))
|
|
701
945
|
found.set(name, text);
|
|
@@ -715,7 +959,7 @@ var declaresTypes = (manifest) => {
|
|
|
715
959
|
var contributionOf = (input) => {
|
|
716
960
|
const { file, files, from, local, seen, statement } = input;
|
|
717
961
|
const nothing = [];
|
|
718
|
-
if (
|
|
962
|
+
if (ts3.isExportAssignment(statement))
|
|
719
963
|
return [
|
|
720
964
|
[
|
|
721
965
|
statement.isExportEquals === true ? "export=" : "default",
|
|
@@ -727,19 +971,19 @@ var contributionOf = (input) => {
|
|
|
727
971
|
return [
|
|
728
972
|
[named, local.get(named) ?? normalize(statement.getText(file))]
|
|
729
973
|
];
|
|
730
|
-
if (
|
|
974
|
+
if (ts3.isVariableStatement(statement) && isExported(statement)) {
|
|
731
975
|
const text = normalize(statement.getText(file));
|
|
732
976
|
return variableNamesOf(statement).map((name) => [name, text]);
|
|
733
977
|
}
|
|
734
|
-
if (!
|
|
978
|
+
if (!ts3.isExportDeclaration(statement))
|
|
735
979
|
return nothing;
|
|
736
|
-
const specifier = statement.moduleSpecifier !== undefined &&
|
|
980
|
+
const specifier = statement.moduleSpecifier !== undefined && ts3.isStringLiteral(statement.moduleSpecifier) ? statement.moduleSpecifier.text : undefined;
|
|
737
981
|
const target = specifier === undefined ? undefined : resolveFrom(files, from, specifier);
|
|
738
982
|
const theirs = target === undefined ? new Map : exportsOf(files, target, new Set(seen));
|
|
739
983
|
const clause = statement.exportClause;
|
|
740
984
|
if (clause === undefined)
|
|
741
985
|
return [...theirs].filter(([name]) => name !== "default" && name !== "export=");
|
|
742
|
-
if (
|
|
986
|
+
if (ts3.isNamespaceExport(clause))
|
|
743
987
|
return [[clause.name.text, `export * as ${clause.name.text}`]];
|
|
744
988
|
return clause.elements.map((element) => {
|
|
745
989
|
const sourceName = (element.propertyName ?? element.name).text;
|
|
@@ -846,9 +1090,9 @@ var parametersOf = (declaration) => {
|
|
|
846
1090
|
return "";
|
|
847
1091
|
const found = [];
|
|
848
1092
|
const visit = (node) => {
|
|
849
|
-
if (
|
|
1093
|
+
if (ts3.isFunctionTypeNode(node) || ts3.isFunctionDeclaration(node) || ts3.isMethodSignature(node) || ts3.isMethodDeclaration(node) || ts3.isConstructSignatureDeclaration(node) || ts3.isConstructorDeclaration(node))
|
|
850
1094
|
found.push(node.parameters.map((parameter) => canonical(parameter.getText())).join(", "));
|
|
851
|
-
|
|
1095
|
+
ts3.forEachChild(node, visit);
|
|
852
1096
|
};
|
|
853
1097
|
visit(statement);
|
|
854
1098
|
return found.join(" | ");
|
|
@@ -859,9 +1103,9 @@ var membersOf = (declaration) => {
|
|
|
859
1103
|
if (statement === undefined)
|
|
860
1104
|
return members;
|
|
861
1105
|
const visit = (node) => {
|
|
862
|
-
if ((
|
|
1106
|
+
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
1107
|
members.add(node.name.text);
|
|
864
|
-
|
|
1108
|
+
ts3.forEachChild(node, visit);
|
|
865
1109
|
};
|
|
866
1110
|
visit(statement);
|
|
867
1111
|
return members;
|
|
@@ -1208,6 +1452,10 @@ var migrationLine = (migration) => {
|
|
|
1208
1452
|
return `Import \`${migration.moved.symbol}\` from \`${migration.moved.to}\` instead of \`${migration.moved.from}\`.`;
|
|
1209
1453
|
if ("resubpath" in migration)
|
|
1210
1454
|
return `Import from \`${migration.resubpath.to}\` instead of \`${migration.resubpath.from}\`.`;
|
|
1455
|
+
if ("methods" in migration)
|
|
1456
|
+
return `${Object.entries(migration.methods.renames).map(([before, after]) => `\`.${before}()\` is now \`.${after}()\``).join(", ")} on \`${migration.methods.owner.export}\`.`;
|
|
1457
|
+
if ("dependencies" in migration)
|
|
1458
|
+
return `Move ${migration.dependencies.names.map((name) => `\`${name}\``).join(", ")} to \`${migration.dependencies.range}\`.`;
|
|
1211
1459
|
return migration.instruction;
|
|
1212
1460
|
};
|
|
1213
1461
|
var renderChange = (change) => {
|
|
@@ -1292,6 +1540,7 @@ export {
|
|
|
1292
1540
|
CHANGE_KINDS,
|
|
1293
1541
|
DISRUPTIVE_KINDS,
|
|
1294
1542
|
UNRELEASED_DIRECTORY,
|
|
1543
|
+
applyDependencyMigrations,
|
|
1295
1544
|
applyMigration,
|
|
1296
1545
|
applyMigrations,
|
|
1297
1546
|
asText,
|
|
@@ -1307,6 +1556,7 @@ export {
|
|
|
1307
1556
|
diffSurface,
|
|
1308
1557
|
disruptiveBetween,
|
|
1309
1558
|
forgetRegistry,
|
|
1559
|
+
isDependencyMigration,
|
|
1310
1560
|
isDisruptive,
|
|
1311
1561
|
isMechanical,
|
|
1312
1562
|
isPackageName,
|
|
@@ -1339,5 +1589,5 @@ export {
|
|
|
1339
1589
|
validateChange
|
|
1340
1590
|
};
|
|
1341
1591
|
|
|
1342
|
-
//# debugId=
|
|
1592
|
+
//# debugId=3115E62F0A26C60F64756E2164756E21
|
|
1343
1593
|
//# sourceMappingURL=index.js.map
|