@absolutejs/changelog 0.7.0 → 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 +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 +82 -27
- package/dist/cli.js.map +6 -6
- package/dist/index.d.ts +2 -1
- package/dist/index.js +371 -115
- package/dist/index.js.map +10 -8
- 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) => ({
|
|
@@ -430,11 +630,11 @@ var readMigration = (value, where, problems) => {
|
|
|
430
630
|
instruction,
|
|
431
631
|
rename: { from: rename.from, to: rename.to }
|
|
432
632
|
};
|
|
433
|
-
const { moved
|
|
434
|
-
if (isRecord(
|
|
633
|
+
const { moved } = value;
|
|
634
|
+
if (isRecord(moved) && isText(moved.symbol) && isText(moved.from) && isText(moved.to))
|
|
435
635
|
return {
|
|
436
636
|
instruction,
|
|
437
|
-
moved: { from:
|
|
637
|
+
moved: { from: moved.from, symbol: moved.symbol, to: moved.to }
|
|
438
638
|
};
|
|
439
639
|
const { resubpath } = value;
|
|
440
640
|
if (isRecord(resubpath) && isText(resubpath.from) && isText(resubpath.to))
|
|
@@ -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) => {
|
|
@@ -527,12 +745,12 @@ var readRelease = (value, where, problems) => {
|
|
|
527
745
|
};
|
|
528
746
|
var validateChange = (value, where = "entry") => {
|
|
529
747
|
const problems = [];
|
|
530
|
-
const
|
|
531
|
-
if (
|
|
748
|
+
const change = readChange(value, where, problems);
|
|
749
|
+
if (change === undefined) {
|
|
532
750
|
const failed = { problems };
|
|
533
751
|
return failed;
|
|
534
752
|
}
|
|
535
|
-
const read = { change
|
|
753
|
+
const read = { change };
|
|
536
754
|
return read;
|
|
537
755
|
};
|
|
538
756
|
var parseChangelog = (value) => {
|
|
@@ -558,26 +776,26 @@ var parseChangelog = (value) => {
|
|
|
558
776
|
};
|
|
559
777
|
};
|
|
560
778
|
var releasesBetween = (changelog, from, upto) => [...changelog.releases].filter((release) => compareVersions(release.version, from) > 0 && compareVersions(release.version, upto) <= 0).sort((left, right) => compareVersions(left.version, right.version));
|
|
561
|
-
var changesBetween = (changelog, from, upto) => releasesBetween(changelog, from, upto).flatMap((release) => release.changes.map((
|
|
562
|
-
const found = { change
|
|
779
|
+
var changesBetween = (changelog, from, upto) => releasesBetween(changelog, from, upto).flatMap((release) => release.changes.map((change) => {
|
|
780
|
+
const found = { change, version: release.version };
|
|
563
781
|
return found;
|
|
564
782
|
}));
|
|
565
783
|
var isDisruptiveAt = (found) => isDisruptive(found.change);
|
|
566
784
|
var disruptiveBetween = (changelog, from, upto) => changesBetween(changelog, from, upto).filter(isDisruptiveAt);
|
|
567
785
|
var mechanicalMigrations = (migrations) => migrations.filter((found) => isMechanical(found.migration));
|
|
568
|
-
var migrationsBetween = (changelog, from, upto) => disruptiveBetween(changelog, from, upto).map(({ change
|
|
786
|
+
var migrationsBetween = (changelog, from, upto) => disruptiveBetween(changelog, from, upto).map(({ change, version }) => {
|
|
569
787
|
const found = {
|
|
570
|
-
migration:
|
|
571
|
-
symbols:
|
|
788
|
+
migration: change.migration,
|
|
789
|
+
symbols: change.symbols,
|
|
572
790
|
version
|
|
573
791
|
};
|
|
574
792
|
return found;
|
|
575
793
|
});
|
|
576
|
-
var symbolsDisturbedBetween = (changelog, from, upto) => new Set(disruptiveBetween(changelog, from, upto).flatMap(({ change
|
|
794
|
+
var symbolsDisturbedBetween = (changelog, from, upto) => new Set(disruptiveBetween(changelog, from, upto).flatMap(({ change }) => change.symbols));
|
|
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,8 +850,40 @@ 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();
|
|
855
|
+
var CLOSERS = new Set(["}", ")", "]", ">"]);
|
|
856
|
+
var wordy = (token) => /^[\w$#@]/u.test(token) || /[\w$]$/u.test(token);
|
|
857
|
+
var LAST2 = -1;
|
|
858
|
+
var tokenText = (scanner, scanned, state) => {
|
|
859
|
+
const closesTemplate = scanned === ts3.SyntaxKind.CloseBraceToken && state.templates.at(LAST2) === state.depth;
|
|
860
|
+
const token = closesTemplate ? scanner.reScanTemplateToken(false) : scanned;
|
|
861
|
+
if (closesTemplate && token === ts3.SyntaxKind.TemplateTail)
|
|
862
|
+
state.templates.pop();
|
|
863
|
+
if (closesTemplate)
|
|
864
|
+
return scanner.getTokenText();
|
|
865
|
+
if (token === ts3.SyntaxKind.StringLiteral)
|
|
866
|
+
return JSON.stringify(scanner.getTokenValue());
|
|
867
|
+
if (token === ts3.SyntaxKind.TemplateHead)
|
|
868
|
+
state.templates.push(state.depth);
|
|
869
|
+
if (token === ts3.SyntaxKind.OpenBraceToken)
|
|
870
|
+
state.depth += 1;
|
|
871
|
+
if (token === ts3.SyntaxKind.CloseBraceToken)
|
|
872
|
+
state.depth -= 1;
|
|
873
|
+
return scanner.getTokenText();
|
|
874
|
+
};
|
|
875
|
+
var canonical = (text) => {
|
|
876
|
+
const scanner = ts3.createScanner(ts3.ScriptTarget.Latest, true, ts3.LanguageVariant.Standard, text);
|
|
877
|
+
const state = { depth: 0, templates: [] };
|
|
878
|
+
const tokens = [];
|
|
879
|
+
for (let token = scanner.scan();token !== ts3.SyntaxKind.EndOfFileToken; token = scanner.scan()) {
|
|
880
|
+
const value = tokenText(scanner, token, state);
|
|
881
|
+
if (CLOSERS.has(value) && tokens.at(LAST2) === ",")
|
|
882
|
+
tokens.pop();
|
|
883
|
+
tokens.push(value);
|
|
884
|
+
}
|
|
885
|
+
return tokens.reduce((joined, token, index) => index > 0 && wordy(tokens[index - 1] ?? "") && wordy(token) ? `${joined} ${token}` : `${joined}${token}`, "");
|
|
886
|
+
};
|
|
637
887
|
var resolveFrom = (files, from, specifier) => {
|
|
638
888
|
if (!specifier.startsWith("."))
|
|
639
889
|
return;
|
|
@@ -650,12 +900,12 @@ var resolveFrom = (files, from, specifier) => {
|
|
|
650
900
|
return candidates.find((candidate) => files.has(candidate));
|
|
651
901
|
};
|
|
652
902
|
var declaredNameOf = (statement) => {
|
|
653
|
-
if (
|
|
654
|
-
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;
|
|
655
905
|
return;
|
|
656
906
|
};
|
|
657
|
-
var isExported = (statement) =>
|
|
658
|
-
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);
|
|
659
909
|
var declarationsIn = (file) => {
|
|
660
910
|
const found = new Map;
|
|
661
911
|
for (const statement of file.statements) {
|
|
@@ -663,7 +913,7 @@ var declarationsIn = (file) => {
|
|
|
663
913
|
const named = declaredNameOf(statement);
|
|
664
914
|
if (named !== undefined)
|
|
665
915
|
found.set(named, text);
|
|
666
|
-
if (!
|
|
916
|
+
if (!ts3.isVariableStatement(statement))
|
|
667
917
|
continue;
|
|
668
918
|
for (const name of variableNamesOf(statement))
|
|
669
919
|
found.set(name, text);
|
|
@@ -683,7 +933,7 @@ var declaresTypes = (manifest) => {
|
|
|
683
933
|
var contributionOf = (input) => {
|
|
684
934
|
const { file, files, from, local, seen, statement } = input;
|
|
685
935
|
const nothing = [];
|
|
686
|
-
if (
|
|
936
|
+
if (ts3.isExportAssignment(statement))
|
|
687
937
|
return [
|
|
688
938
|
[
|
|
689
939
|
statement.isExportEquals === true ? "export=" : "default",
|
|
@@ -695,19 +945,19 @@ var contributionOf = (input) => {
|
|
|
695
945
|
return [
|
|
696
946
|
[named, local.get(named) ?? normalize(statement.getText(file))]
|
|
697
947
|
];
|
|
698
|
-
if (
|
|
948
|
+
if (ts3.isVariableStatement(statement) && isExported(statement)) {
|
|
699
949
|
const text = normalize(statement.getText(file));
|
|
700
950
|
return variableNamesOf(statement).map((name) => [name, text]);
|
|
701
951
|
}
|
|
702
|
-
if (!
|
|
952
|
+
if (!ts3.isExportDeclaration(statement))
|
|
703
953
|
return nothing;
|
|
704
|
-
const specifier = statement.moduleSpecifier !== undefined &&
|
|
954
|
+
const specifier = statement.moduleSpecifier !== undefined && ts3.isStringLiteral(statement.moduleSpecifier) ? statement.moduleSpecifier.text : undefined;
|
|
705
955
|
const target = specifier === undefined ? undefined : resolveFrom(files, from, specifier);
|
|
706
956
|
const theirs = target === undefined ? new Map : exportsOf(files, target, new Set(seen));
|
|
707
957
|
const clause = statement.exportClause;
|
|
708
958
|
if (clause === undefined)
|
|
709
959
|
return [...theirs].filter(([name]) => name !== "default" && name !== "export=");
|
|
710
|
-
if (
|
|
960
|
+
if (ts3.isNamespaceExport(clause))
|
|
711
961
|
return [[clause.name.text, `export * as ${clause.name.text}`]];
|
|
712
962
|
return clause.elements.map((element) => {
|
|
713
963
|
const sourceName = (element.propertyName ?? element.name).text;
|
|
@@ -799,7 +1049,7 @@ var SHAPE = {
|
|
|
799
1049
|
types: "types",
|
|
800
1050
|
unknown: "unknown"
|
|
801
1051
|
};
|
|
802
|
-
var isStub = (declaration) =>
|
|
1052
|
+
var isStub = (declaration) => /^export\s*\{/u.test(declaration);
|
|
803
1053
|
var signatureOf = (declaration) => {
|
|
804
1054
|
const file = parse2(`${declaration}
|
|
805
1055
|
`, "declaration.d.ts");
|
|
@@ -814,9 +1064,9 @@ var parametersOf = (declaration) => {
|
|
|
814
1064
|
return "";
|
|
815
1065
|
const found = [];
|
|
816
1066
|
const visit = (node) => {
|
|
817
|
-
if (
|
|
818
|
-
found.push(node.parameters.map((parameter) =>
|
|
819
|
-
|
|
1067
|
+
if (ts3.isFunctionTypeNode(node) || ts3.isFunctionDeclaration(node) || ts3.isMethodSignature(node) || ts3.isMethodDeclaration(node) || ts3.isConstructSignatureDeclaration(node) || ts3.isConstructorDeclaration(node))
|
|
1068
|
+
found.push(node.parameters.map((parameter) => canonical(parameter.getText())).join(", "));
|
|
1069
|
+
ts3.forEachChild(node, visit);
|
|
820
1070
|
};
|
|
821
1071
|
visit(statement);
|
|
822
1072
|
return found.join(" | ");
|
|
@@ -827,20 +1077,20 @@ var membersOf = (declaration) => {
|
|
|
827
1077
|
if (statement === undefined)
|
|
828
1078
|
return members;
|
|
829
1079
|
const visit = (node) => {
|
|
830
|
-
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)))
|
|
831
1081
|
members.add(node.name.text);
|
|
832
|
-
|
|
1082
|
+
ts3.forEachChild(node, visit);
|
|
833
1083
|
};
|
|
834
1084
|
visit(statement);
|
|
835
1085
|
return members;
|
|
836
1086
|
};
|
|
837
1087
|
var sameNames = (left, right) => left.size === right.size && [...left].every((name) => right.has(name));
|
|
838
|
-
var changeShape = (
|
|
839
|
-
if (isStub(
|
|
1088
|
+
var changeShape = (change) => {
|
|
1089
|
+
if (isStub(change.before) !== isStub(change.after))
|
|
840
1090
|
return SHAPE.unknown;
|
|
841
|
-
if (parametersOf(
|
|
1091
|
+
if (parametersOf(change.before) !== parametersOf(change.after))
|
|
842
1092
|
return SHAPE.parameters;
|
|
843
|
-
if (!sameNames(membersOf(
|
|
1093
|
+
if (!sameNames(membersOf(change.before), membersOf(change.after)))
|
|
844
1094
|
return SHAPE.members;
|
|
845
1095
|
return SHAPE.types;
|
|
846
1096
|
};
|
|
@@ -857,7 +1107,7 @@ var diffSurface = (before, after) => {
|
|
|
857
1107
|
const lost = was.entries.filter((entry) => !now.entries.includes(entry));
|
|
858
1108
|
if (lost.length > 0)
|
|
859
1109
|
withdrawn.push({ from: lost, name });
|
|
860
|
-
if (now.declaration !== was.declaration)
|
|
1110
|
+
if (canonical(now.declaration) !== canonical(was.declaration))
|
|
861
1111
|
changed.push({
|
|
862
1112
|
after: now.declaration,
|
|
863
1113
|
before: was.declaration,
|
|
@@ -875,12 +1125,12 @@ var diffSurface = (before, after) => {
|
|
|
875
1125
|
withdrawn
|
|
876
1126
|
};
|
|
877
1127
|
};
|
|
878
|
-
var notable = (diff) => diff.changed.filter((
|
|
1128
|
+
var notable = (diff) => diff.changed.filter((change) => change.shape === "parameters" || change.shape === "members");
|
|
879
1129
|
|
|
880
1130
|
// src/entries.ts
|
|
881
|
-
var loadEntry = async (
|
|
1131
|
+
var loadEntry = async (path) => {
|
|
882
1132
|
try {
|
|
883
|
-
const module = await import(pathToFileURL(
|
|
1133
|
+
const module = await import(pathToFileURL(path).href);
|
|
884
1134
|
const named = typeof module === "object" && module !== null && "change" in module ? module.change : undefined;
|
|
885
1135
|
const exported = named ?? (typeof module === "object" && module !== null && "default" in module ? module.default : undefined);
|
|
886
1136
|
const read = { exported };
|
|
@@ -898,10 +1148,10 @@ var OUTPUT_DIRECTORIES = ["dist", "build", "lib", "types", "out"];
|
|
|
898
1148
|
var newestUnder = async (root) => {
|
|
899
1149
|
const found = await readdir(root, { withFileTypes: true }).catch(() => []);
|
|
900
1150
|
const times = await Promise.all(found.map(async (entry) => {
|
|
901
|
-
const
|
|
1151
|
+
const path = join(root, entry.name);
|
|
902
1152
|
if (entry.isDirectory())
|
|
903
|
-
return newestUnder(
|
|
904
|
-
return stat(
|
|
1153
|
+
return newestUnder(path);
|
|
1154
|
+
return stat(path).then((stats) => stats.mtimeMs, () => 0);
|
|
905
1155
|
}));
|
|
906
1156
|
return Math.max(0, ...times);
|
|
907
1157
|
};
|
|
@@ -957,8 +1207,8 @@ var loadUnreleased = async (packageRoot) => {
|
|
|
957
1207
|
}
|
|
958
1208
|
return { entries, problems };
|
|
959
1209
|
};
|
|
960
|
-
var readJsonFile = async (
|
|
961
|
-
const source = await readFile(
|
|
1210
|
+
var readJsonFile = async (path) => {
|
|
1211
|
+
const source = await readFile(path, "utf8").catch(() => {
|
|
962
1212
|
return;
|
|
963
1213
|
});
|
|
964
1214
|
if (source === undefined)
|
|
@@ -976,39 +1226,39 @@ var strayEntries = async (packageRoot) => {
|
|
|
976
1226
|
};
|
|
977
1227
|
// src/reconcile.ts
|
|
978
1228
|
var migrationHolds = (input) => {
|
|
979
|
-
const { after, change
|
|
1229
|
+
const { after, change, subpaths } = input;
|
|
980
1230
|
const wrong = [];
|
|
981
|
-
const { migration } =
|
|
1231
|
+
const { migration } = change;
|
|
982
1232
|
if ("rename" in migration) {
|
|
983
1233
|
const { from } = migration.rename;
|
|
984
1234
|
const into = migration.rename.to;
|
|
985
1235
|
if (!after.has(into))
|
|
986
|
-
wrong.push(`\`${
|
|
1236
|
+
wrong.push(`\`${change.summary}\` renames to \`${into}\`, which this version does not export`);
|
|
987
1237
|
if (after.has(from))
|
|
988
|
-
wrong.push(`\`${
|
|
989
|
-
if (!
|
|
990
|
-
wrong.push(`\`${
|
|
1238
|
+
wrong.push(`\`${change.summary}\` renames \`${from}\` away, but this version still exports it`);
|
|
1239
|
+
if (!change.symbols.includes(from))
|
|
1240
|
+
wrong.push(`\`${change.summary}\` renames \`${from}\`, which is not in its own symbols`);
|
|
991
1241
|
}
|
|
992
1242
|
if ("moved" in migration) {
|
|
993
1243
|
const { symbol } = migration.moved;
|
|
994
1244
|
const into = migration.moved.to;
|
|
995
1245
|
if (!after.has(symbol))
|
|
996
|
-
wrong.push(`\`${
|
|
1246
|
+
wrong.push(`\`${change.summary}\` moves \`${symbol}\`, which this version does not export`);
|
|
997
1247
|
if (subpaths.size > 0 && !subpaths.has(into))
|
|
998
|
-
wrong.push(`\`${
|
|
1248
|
+
wrong.push(`\`${change.summary}\` moves \`${symbol}\` to \`${into}\`, which is not an entry point of this package`);
|
|
999
1249
|
}
|
|
1000
1250
|
if ("resubpath" in migration && subpaths.size > 0 && !subpaths.has(migration.resubpath.to))
|
|
1001
|
-
wrong.push(`\`${
|
|
1002
|
-
if (
|
|
1003
|
-
for (const symbol of
|
|
1251
|
+
wrong.push(`\`${change.summary}\` points at \`${migration.resubpath.to}\`, which is not an entry point of this package`);
|
|
1252
|
+
if (change.kind === "removed") {
|
|
1253
|
+
for (const symbol of change.symbols)
|
|
1004
1254
|
if (after.has(symbol))
|
|
1005
|
-
wrong.push(`\`${
|
|
1255
|
+
wrong.push(`\`${change.summary}\` says \`${symbol}\` was removed, but this version still exports it`);
|
|
1006
1256
|
}
|
|
1007
1257
|
return wrong;
|
|
1008
1258
|
};
|
|
1009
1259
|
var describeReconciliation = (found) => {
|
|
1010
1260
|
const lines = [];
|
|
1011
|
-
const
|
|
1261
|
+
const moved = {
|
|
1012
1262
|
members: "changed the members of its type",
|
|
1013
1263
|
parameters: "changed what it is called with",
|
|
1014
1264
|
removed: "is no longer exported",
|
|
@@ -1016,27 +1266,27 @@ var describeReconciliation = (found) => {
|
|
|
1016
1266
|
withdrawn: "is no longer exported from"
|
|
1017
1267
|
};
|
|
1018
1268
|
for (const entry of found.unannounced)
|
|
1019
|
-
lines.push(entry.kind === "withdrawn" ? `\`${entry.name}\` ${
|
|
1269
|
+
lines.push(entry.kind === "withdrawn" ? `\`${entry.name}\` ${moved.withdrawn} ${(entry.from ?? []).join(", ")} and no entry says so` : `\`${entry.name}\` ${moved[entry.kind]} and no entry says so`);
|
|
1020
1270
|
for (const name of found.unknownSymbols)
|
|
1021
1271
|
lines.push(`an entry names \`${name}\`, which this package does not export`);
|
|
1022
1272
|
lines.push(...found.wrongMigrations);
|
|
1023
1273
|
return lines;
|
|
1024
1274
|
};
|
|
1025
1275
|
var reconcile = (input) => {
|
|
1026
|
-
const disruptive = new Set(input.changes.filter(isDisruptive).flatMap((
|
|
1027
|
-
const mentioned = new Set(input.changes.flatMap((
|
|
1276
|
+
const disruptive = new Set(input.changes.filter(isDisruptive).flatMap((change) => [...change.symbols]));
|
|
1277
|
+
const mentioned = new Set(input.changes.flatMap((change) => [...change.symbols ?? []]));
|
|
1028
1278
|
const unannounced = [
|
|
1029
1279
|
...input.diff.removed.filter((name) => !disruptive.has(name)).map((name) => ({ kind: "removed", name })),
|
|
1030
1280
|
...input.diff.withdrawn.filter((entry) => !disruptive.has(entry.name)).map((entry) => ({ from: entry.from, kind: "withdrawn", name: entry.name })),
|
|
1031
|
-
...input.diff.changed.filter((
|
|
1281
|
+
...input.diff.changed.filter((change) => !mentioned.has(change.name) && change.shape !== "unknown").map((change) => ({ kind: change.shape, name: change.name }))
|
|
1032
1282
|
];
|
|
1033
1283
|
const unknownSymbols = [
|
|
1034
|
-
...new Set(input.changes.flatMap((
|
|
1284
|
+
...new Set(input.changes.flatMap((change) => [...change.symbols ?? []]).filter((name) => !input.known.has(name)))
|
|
1035
1285
|
];
|
|
1036
1286
|
const { after } = input;
|
|
1037
|
-
const wrongMigrations = after === undefined ? [] : input.changes.filter(isDisruptive).flatMap((
|
|
1287
|
+
const wrongMigrations = after === undefined ? [] : input.changes.filter(isDisruptive).flatMap((change) => migrationHolds({
|
|
1038
1288
|
after,
|
|
1039
|
-
change
|
|
1289
|
+
change,
|
|
1040
1290
|
subpaths: input.subpaths ?? new Set
|
|
1041
1291
|
}));
|
|
1042
1292
|
return { unannounced, unknownSymbols, wrongMigrations };
|
|
@@ -1135,7 +1385,7 @@ var publishedChangelog = async (name, version, options = {}) => {
|
|
|
1135
1385
|
const archive = await packageArchive(name, version, options);
|
|
1136
1386
|
if (!archive)
|
|
1137
1387
|
return;
|
|
1138
|
-
const file = readTar(archive, (
|
|
1388
|
+
const file = readTar(archive, (path) => path === CHANGELOG_FILE).get(CHANGELOG_FILE);
|
|
1139
1389
|
if (!file)
|
|
1140
1390
|
return;
|
|
1141
1391
|
try {
|
|
@@ -1176,21 +1426,25 @@ var migrationLine = (migration) => {
|
|
|
1176
1426
|
return `Import \`${migration.moved.symbol}\` from \`${migration.moved.to}\` instead of \`${migration.moved.from}\`.`;
|
|
1177
1427
|
if ("resubpath" in migration)
|
|
1178
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}\`.`;
|
|
1179
1433
|
return migration.instruction;
|
|
1180
1434
|
};
|
|
1181
|
-
var renderChange = (
|
|
1182
|
-
const symbols =
|
|
1183
|
-
const lines = [`- **${
|
|
1184
|
-
if (
|
|
1185
|
-
lines.push(` ${
|
|
1186
|
-
if (isDisruptive(
|
|
1187
|
-
lines.push(` _Migration:_ ${
|
|
1188
|
-
const mechanical = migrationLine(
|
|
1189
|
-
if (mechanical !==
|
|
1435
|
+
var renderChange = (change) => {
|
|
1436
|
+
const symbols = change.symbols && change.symbols.length > 0 ? ` (${change.symbols.map((name) => `\`${name}\``).join(", ")})` : "";
|
|
1437
|
+
const lines = [`- **${change.summary}**${symbols}`];
|
|
1438
|
+
if (change.detail !== undefined)
|
|
1439
|
+
lines.push(` ${change.detail}`);
|
|
1440
|
+
if (isDisruptive(change)) {
|
|
1441
|
+
lines.push(` _Migration:_ ${change.migration.instruction}`);
|
|
1442
|
+
const mechanical = migrationLine(change.migration);
|
|
1443
|
+
if (mechanical !== change.migration.instruction)
|
|
1190
1444
|
lines.push(` _Applied automatically:_ ${mechanical}`);
|
|
1191
1445
|
}
|
|
1192
|
-
if (
|
|
1193
|
-
lines.push(` See ${
|
|
1446
|
+
if (change.reference !== undefined)
|
|
1447
|
+
lines.push(` See ${change.reference}.`);
|
|
1194
1448
|
return lines.join(`
|
|
1195
1449
|
`);
|
|
1196
1450
|
};
|
|
@@ -1217,13 +1471,13 @@ var renderChangelogJson = (changelog) => `${JSON.stringify({
|
|
|
1217
1471
|
contract: CHANGELOG_CONTRACT,
|
|
1218
1472
|
name: changelog.name,
|
|
1219
1473
|
releases: [...changelog.releases].sort((left, right) => compareVersions(right.version, left.version)).map((release) => ({
|
|
1220
|
-
changes: release.changes.map((
|
|
1221
|
-
...
|
|
1222
|
-
kind:
|
|
1223
|
-
...isDisruptive(
|
|
1224
|
-
...
|
|
1225
|
-
summary:
|
|
1226
|
-
...
|
|
1474
|
+
changes: release.changes.map((change) => ({
|
|
1475
|
+
...change.detail === undefined ? {} : { detail: change.detail },
|
|
1476
|
+
kind: change.kind,
|
|
1477
|
+
...isDisruptive(change) ? { migration: change.migration } : {},
|
|
1478
|
+
...change.reference === undefined ? {} : { reference: change.reference },
|
|
1479
|
+
summary: change.summary,
|
|
1480
|
+
...change.symbols && change.symbols.length > 0 ? { symbols: change.symbols } : {}
|
|
1227
1481
|
})),
|
|
1228
1482
|
date: release.date,
|
|
1229
1483
|
...release.note === undefined ? {} : { note: release.note },
|
|
@@ -1260,6 +1514,7 @@ export {
|
|
|
1260
1514
|
CHANGE_KINDS,
|
|
1261
1515
|
DISRUPTIVE_KINDS,
|
|
1262
1516
|
UNRELEASED_DIRECTORY,
|
|
1517
|
+
applyDependencyMigrations,
|
|
1263
1518
|
applyMigration,
|
|
1264
1519
|
applyMigrations,
|
|
1265
1520
|
asText,
|
|
@@ -1275,6 +1530,7 @@ export {
|
|
|
1275
1530
|
diffSurface,
|
|
1276
1531
|
disruptiveBetween,
|
|
1277
1532
|
forgetRegistry,
|
|
1533
|
+
isDependencyMigration,
|
|
1278
1534
|
isDisruptive,
|
|
1279
1535
|
isMechanical,
|
|
1280
1536
|
isPackageName,
|
|
@@ -1307,5 +1563,5 @@ export {
|
|
|
1307
1563
|
validateChange
|
|
1308
1564
|
};
|
|
1309
1565
|
|
|
1310
|
-
//# debugId=
|
|
1566
|
+
//# debugId=0052F7389999EA8F64756E2164756E21
|
|
1311
1567
|
//# sourceMappingURL=index.js.map
|