electron-builder 27.0.0-alpha.2 → 27.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1051 @@
1
+ import { createRequire } from "node:module";
2
+ import * as path from "path";
3
+ import { AZURE_KNOWN_FIELDS, ELECTRON_DOWNLOAD_DROPPED, MAC_SIGN_FIELDS, MAC_UNIVERSAL_FIELDS, SNAP_BASES } from "./migrate-schema.js";
4
+ const _require = createRequire(import.meta.url);
5
+ // `typescript` is intentionally NOT a dependency of electron-builder — it is loaded lazily (same
6
+ // pattern as js-yaml/json5/toml) and the feature degrades to manual steps when it is unavailable.
7
+ // Types are kept loose (`any`) on purpose so no `typescript` types are required at compile time.
8
+ let tsModuleCache;
9
+ export function loadTypeScript() {
10
+ if (tsModuleCache !== undefined) {
11
+ return tsModuleCache;
12
+ }
13
+ try {
14
+ tsModuleCache = _require("typescript");
15
+ }
16
+ catch {
17
+ tsModuleCache = null;
18
+ }
19
+ return tsModuleCache;
20
+ }
21
+ /**
22
+ * Migrates a programmatic JS/TS electron-builder config (the same v26→v27 transforms as
23
+ * {@link migrateConfig}) by surgically rewriting the source text. The TypeScript parser is used only
24
+ * to locate node ranges; everything outside an edited range is preserved byte-for-byte, so comments,
25
+ * imports, functions, and formatting are untouched.
26
+ *
27
+ * Pure: source string in, result out. No file I/O. Returns status "unsupported" (with the source
28
+ * unchanged) when typescript is not installed or the config cannot be statically reduced to a single
29
+ * object literal (function that builds the object dynamically, spreads, computed keys, …).
30
+ */
31
+ export function migrateProgrammaticSource(sourceText, fileName) {
32
+ const ts = loadTypeScript();
33
+ if (ts == null) {
34
+ return { code: sourceText, changes: [], warnings: [], status: "unsupported", unsupportedReason: "typescript-not-installed" };
35
+ }
36
+ const scriptKind = scriptKindFor(ts, fileName);
37
+ const sf = ts.createSourceFile(fileName, sourceText, ts.ScriptTarget.Latest, /* setParentNodes */ true, scriptKind);
38
+ const codemod = new ConfigCodemod(ts, sf, sourceText);
39
+ const located = codemod.locateConfigObject();
40
+ if (located.objLit == null) {
41
+ return { code: sourceText, changes: [], warnings: [], status: "unsupported", unsupportedReason: located.reason };
42
+ }
43
+ codemod.run(located.objLit);
44
+ if (codemod.edits.length === 0) {
45
+ return { code: sourceText, changes: codemod.changes, warnings: codemod.warnings, status: "no-op" };
46
+ }
47
+ return { code: codemod.apply(), changes: codemod.changes, warnings: codemod.warnings, status: "migrated" };
48
+ }
49
+ function scriptKindFor(ts, fileName) {
50
+ const ext = path.extname(fileName).toLowerCase();
51
+ switch (ext) {
52
+ case ".ts":
53
+ case ".cts":
54
+ case ".mts":
55
+ return ts.ScriptKind.TS;
56
+ case ".tsx":
57
+ return ts.ScriptKind.TSX;
58
+ case ".jsx":
59
+ return ts.ScriptKind.JSX;
60
+ default:
61
+ return ts.ScriptKind.JS;
62
+ }
63
+ }
64
+ class ConfigCodemod {
65
+ constructor(ts, sf, text) {
66
+ this.ts = ts;
67
+ this.sf = sf;
68
+ this.text = text;
69
+ this.edits = [];
70
+ this.changes = [];
71
+ this.warnings = [];
72
+ this.indentUnit = " ";
73
+ }
74
+ // ── Locate the config object literal ──────────────────────────────────────
75
+ locateConfigObject() {
76
+ const ts = this.ts;
77
+ const candidates = [];
78
+ for (const stmt of this.sf.statements) {
79
+ if (ts.isExportAssignment(stmt)) {
80
+ // `export default <expr>` and `export = <expr>`
81
+ candidates.push(stmt.expression);
82
+ }
83
+ else if (ts.isExpressionStatement(stmt) && ts.isBinaryExpression(stmt.expression) && stmt.expression.operatorToken.kind === ts.SyntaxKind.EqualsToken) {
84
+ const lhs = stmt.expression.left;
85
+ if (this.isModuleExportsTarget(lhs)) {
86
+ candidates.push(stmt.expression.right);
87
+ }
88
+ }
89
+ else if (ts.isFunctionDeclaration(stmt) && this.hasDefaultExport(stmt)) {
90
+ // `export default function () { return {...} }`
91
+ const lit = this.literalFromFunctionLike(stmt);
92
+ if (lit != null) {
93
+ candidates.push(lit);
94
+ }
95
+ }
96
+ }
97
+ // Inline `build({ config: {...} })` form (programmatic-usage.md). Search the whole tree.
98
+ this.forEachDescendant(this.sf, node => {
99
+ const cfg = this.configArgOfBuildCall(node);
100
+ if (cfg != null) {
101
+ candidates.push(cfg);
102
+ }
103
+ });
104
+ let reason = "no electron-builder config object literal found (expected a default/module.exports object export or a build({ config }) call)";
105
+ for (const candidate of candidates) {
106
+ const resolved = this.resolveToObjectLiteral(candidate, 0);
107
+ if (resolved.objLit != null) {
108
+ return { objLit: resolved.objLit };
109
+ }
110
+ if (resolved.reason != null) {
111
+ reason = resolved.reason;
112
+ }
113
+ }
114
+ return { reason };
115
+ }
116
+ isModuleExportsTarget(lhs) {
117
+ const ts = this.ts;
118
+ if (!ts.isPropertyAccessExpression(lhs)) {
119
+ return false;
120
+ }
121
+ // module.exports = ... OR exports.default = ...
122
+ if (ts.isIdentifier(lhs.expression) && lhs.expression.text === "module" && lhs.name.text === "exports") {
123
+ return true;
124
+ }
125
+ if (ts.isIdentifier(lhs.expression) && lhs.expression.text === "exports" && lhs.name.text === "default") {
126
+ return true;
127
+ }
128
+ return false;
129
+ }
130
+ hasDefaultExport(node) {
131
+ const ts = this.ts;
132
+ const mods = node.modifiers;
133
+ if (mods == null) {
134
+ return false;
135
+ }
136
+ let hasExport = false;
137
+ let hasDefault = false;
138
+ for (const m of mods) {
139
+ if (m.kind === ts.SyntaxKind.ExportKeyword) {
140
+ hasExport = true;
141
+ }
142
+ if (m.kind === ts.SyntaxKind.DefaultKeyword) {
143
+ hasDefault = true;
144
+ }
145
+ }
146
+ return hasExport && hasDefault;
147
+ }
148
+ configArgOfBuildCall(node) {
149
+ const ts = this.ts;
150
+ if (!ts.isCallExpression(node)) {
151
+ return null;
152
+ }
153
+ const callee = node.expression;
154
+ const isBuild = (ts.isIdentifier(callee) && callee.text === "build") || (ts.isPropertyAccessExpression(callee) && callee.name.text === "build");
155
+ if (!isBuild || node.arguments.length === 0) {
156
+ return null;
157
+ }
158
+ const arg0 = node.arguments[0];
159
+ if (!ts.isObjectLiteralExpression(arg0)) {
160
+ return null;
161
+ }
162
+ const configProp = this.getProp(arg0, "config");
163
+ return configProp != null && ts.isPropertyAssignment(configProp) ? configProp.initializer : null;
164
+ }
165
+ resolveToObjectLiteral(expr, depth) {
166
+ const ts = this.ts;
167
+ if (depth > 6) {
168
+ return { reason: "config export could not be resolved (too many indirections)" };
169
+ }
170
+ const node = this.unwrap(expr);
171
+ if (ts.isObjectLiteralExpression(node)) {
172
+ if (this.hasSpreadOrComputed(node)) {
173
+ return { reason: "config object uses a spread (`...`) or computed key, which cannot be migrated automatically" };
174
+ }
175
+ return { objLit: node };
176
+ }
177
+ if (ts.isIdentifier(node)) {
178
+ const init = this.findVariableInitializer(node.text);
179
+ if (init == null) {
180
+ return { reason: `config export references "${node.text}", which is not a local object literal` };
181
+ }
182
+ return this.resolveToObjectLiteral(init, depth + 1);
183
+ }
184
+ if (ts.isArrowFunction(node) || ts.isFunctionExpression(node)) {
185
+ const lit = this.literalFromFunctionLike(node);
186
+ if (lit == null) {
187
+ return { reason: "config is a function that does not return a single object literal — migrate it manually" };
188
+ }
189
+ return this.resolveToObjectLiteral(lit, depth + 1);
190
+ }
191
+ return { reason: "config export is not an object literal — migrate it manually" };
192
+ }
193
+ /** Unwraps parentheses and type-only wrappers (`as`, `satisfies`, `!`, `<T>x`) to the inner expression. */
194
+ unwrap(node) {
195
+ const ts = this.ts;
196
+ let n = node;
197
+ for (;;) {
198
+ if (ts.isParenthesizedExpression(n) ||
199
+ ts.isAsExpression(n) ||
200
+ (ts.isSatisfiesExpression && ts.isSatisfiesExpression(n)) ||
201
+ ts.isNonNullExpression(n) ||
202
+ ts.isTypeAssertionExpression?.(n)) {
203
+ n = n.expression;
204
+ }
205
+ else {
206
+ return n;
207
+ }
208
+ }
209
+ }
210
+ hasSpreadOrComputed(objLit) {
211
+ const ts = this.ts;
212
+ for (const p of objLit.properties) {
213
+ if (ts.isSpreadAssignment(p)) {
214
+ return true;
215
+ }
216
+ if (p.name != null && ts.isComputedPropertyName(p.name)) {
217
+ return true;
218
+ }
219
+ }
220
+ return false;
221
+ }
222
+ findVariableInitializer(name) {
223
+ const ts = this.ts;
224
+ for (const stmt of this.sf.statements) {
225
+ if (!ts.isVariableStatement(stmt)) {
226
+ continue;
227
+ }
228
+ for (const decl of stmt.declarationList.declarations) {
229
+ if (ts.isIdentifier(decl.name) && decl.name.text === name && decl.initializer != null) {
230
+ return decl.initializer;
231
+ }
232
+ }
233
+ }
234
+ return null;
235
+ }
236
+ /** Returns the single object-literal expression a function-like trivially yields, or null. */
237
+ literalFromFunctionLike(fn) {
238
+ const ts = this.ts;
239
+ const body = fn.body;
240
+ if (body == null) {
241
+ return null;
242
+ }
243
+ if (!ts.isBlock(body)) {
244
+ // arrow expression body: `() => ({...})` / `() => obj`
245
+ return body;
246
+ }
247
+ const returns = [];
248
+ this.collectReturns(body, returns);
249
+ if (returns.length !== 1 || returns[0].expression == null) {
250
+ return null;
251
+ }
252
+ return returns[0].expression;
253
+ }
254
+ collectReturns(node, out) {
255
+ const ts = this.ts;
256
+ const visit = (n) => {
257
+ // Don't descend into nested functions — their returns are not the config's.
258
+ if (ts.isFunctionDeclaration(n) || ts.isFunctionExpression(n) || ts.isArrowFunction(n)) {
259
+ return;
260
+ }
261
+ if (ts.isReturnStatement(n)) {
262
+ out.push(n);
263
+ }
264
+ n.forEachChild(visit);
265
+ };
266
+ node.forEachChild(visit);
267
+ }
268
+ forEachDescendant(node, cb) {
269
+ const visit = (n) => {
270
+ cb(n);
271
+ n.forEachChild(visit);
272
+ };
273
+ node.forEachChild(visit);
274
+ }
275
+ // ── Run all rules ─────────────────────────────────────────────────────────
276
+ run(root) {
277
+ this.indentUnit = this.detectIndentUnit(root);
278
+ this.ruleRemoveKeys(root, ["electronCompile"], "removed electronCompile (unsupported since v27; migrate to electron-vite, esbuild, or webpack)");
279
+ this.ruleRemoveKeys(root, ["framework", "nodeVersion", "launchUiVersion"], key => `removed ${key} (Electron is the only supported framework in v27)`);
280
+ this.ruleNativeModules(root);
281
+ this.ruleAsar(root);
282
+ this.ruleAppImageSystemIntegration(root);
283
+ this.rulePublish(root, "publish");
284
+ for (const platform of ["mac", "win", "linux"]) {
285
+ const p = this.getObjectProp(root, platform);
286
+ if (p != null) {
287
+ this.rulePublish(p, "publish", platform + ".");
288
+ }
289
+ }
290
+ this.ruleSnap(root);
291
+ this.ruleHelperBundleId(root);
292
+ this.ruleSquirrelNoMsi(root);
293
+ this.ruleWinSign(root);
294
+ for (const platform of ["mac", "mas", "masDev"]) {
295
+ const p = this.getObjectProp(root, platform);
296
+ if (p != null) {
297
+ this.ruleMacSigning(p, platform);
298
+ this.ruleMacUniversal(p, platform);
299
+ }
300
+ }
301
+ this.ruleElectronDownload(root);
302
+ }
303
+ // ── Rules ───────────────────────────────────────────────────────────────
304
+ ruleRemoveKeys(obj, keys, description) {
305
+ for (const key of keys) {
306
+ const prop = this.getProp(obj, key);
307
+ if (prop != null) {
308
+ this.removeProp(prop);
309
+ this.changes.push({ key, description: typeof description === "function" ? description(key) : description });
310
+ }
311
+ }
312
+ }
313
+ ruleNativeModules(root) {
314
+ const sources = [];
315
+ const extraEntries = [];
316
+ for (const key of ["buildDependenciesFromSource", "nodeGypRebuild", "npmRebuild"]) {
317
+ const prop = this.getProp(root, key);
318
+ if (prop != null) {
319
+ sources.push({ prop });
320
+ this.changes.push({ key, description: `moved ${key} → nativeModules.${key}` });
321
+ }
322
+ }
323
+ const nativeRebuilder = this.getProp(root, "nativeRebuilder");
324
+ if (nativeRebuilder != null) {
325
+ sources.push({ prop: nativeRebuilder, renameTo: "rebuildMode" });
326
+ this.changes.push({ key: "nativeRebuilder", description: "renamed nativeRebuilder → nativeModules.rebuildMode" });
327
+ }
328
+ const npmSkip = this.getProp(root, "npmSkipBuildFromSource");
329
+ if (npmSkip != null && this.ts.isPropertyAssignment(npmSkip)) {
330
+ const hasBds = this.getProp(root, "buildDependenciesFromSource") != null;
331
+ if (!hasBds) {
332
+ extraEntries.push(`buildDependenciesFromSource: ${this.negate(npmSkip.initializer)}`);
333
+ }
334
+ this.removeProp(npmSkip);
335
+ this.changes.push({ key: "npmSkipBuildFromSource", description: "renamed npmSkipBuildFromSource → buildDependenciesFromSource (then grouped under nativeModules)" });
336
+ }
337
+ if (sources.length === 0 && extraEntries.length === 0) {
338
+ return;
339
+ }
340
+ const ok = this.moveInto(root, "nativeModules", sources, extraEntries);
341
+ if (!ok) {
342
+ this.warnings.push("nativeModules already exists but is not an object literal; move buildDependenciesFromSource/nodeGypRebuild/npmRebuild/rebuildMode into it manually.");
343
+ }
344
+ }
345
+ ruleAsar(root) {
346
+ const ts = this.ts;
347
+ const asarProp = this.getProp(root, "asar");
348
+ const asarVal = asarProp != null && ts.isPropertyAssignment(asarProp) ? this.unwrap(asarProp.initializer) : null;
349
+ const asarIsFalse = asarVal != null && asarVal.kind === ts.SyntaxKind.FalseKeyword;
350
+ const asarIsTrue = asarVal != null && asarVal.kind === ts.SyntaxKind.TrueKeyword;
351
+ const asarIsObject = asarVal != null && ts.isObjectLiteralExpression(asarVal);
352
+ if (asarIsFalse) {
353
+ if (this.getProp(root, "asar-unpack") != null || this.getProp(root, "asar-unpack-dir") != null || this.getProp(root, "asarUnpack") != null) {
354
+ this.warnings.push("asar is false but asar-unpack/asarUnpack is also set. asar: false disables packaging entirely; remove the unpack keys or enable asar manually.");
355
+ }
356
+ return;
357
+ }
358
+ // Collect unpack sources (root-level hyphenated/camel + nested asar.unpackDir).
359
+ const unpackSources = [];
360
+ const collectUnpack = (key, descKey, desc) => {
361
+ const prop = this.getProp(root, key);
362
+ if (prop != null && ts.isPropertyAssignment(prop)) {
363
+ unpackSources.push(prop.initializer);
364
+ this.removeProp(prop);
365
+ this.changes.push({ key: descKey, description: desc });
366
+ }
367
+ };
368
+ collectUnpack("asar-unpack", "asar-unpack", "renamed asar-unpack → asar.unpack");
369
+ collectUnpack("asar-unpack-dir", "asar-unpack-dir", "renamed asar-unpack-dir → asar.unpack");
370
+ collectUnpack("asarUnpack", "asarUnpack", "moved asarUnpack → asar.unpack");
371
+ if (asarIsObject) {
372
+ const nestedUnpackDir = this.getProp(asarVal, "unpackDir");
373
+ if (nestedUnpackDir != null && ts.isPropertyAssignment(nestedUnpackDir)) {
374
+ unpackSources.push(nestedUnpackDir.initializer);
375
+ this.removeProp(nestedUnpackDir);
376
+ this.changes.push({ key: "asar.unpackDir", description: "moved asar.unpackDir → asar.unpack" });
377
+ }
378
+ }
379
+ const childRenames = [];
380
+ const collectChild = (key, renameTo, desc) => {
381
+ const prop = this.getProp(root, key);
382
+ if (prop != null && ts.isPropertyAssignment(prop)) {
383
+ childRenames.push({ renameTo, value: prop.initializer });
384
+ this.removeProp(prop);
385
+ this.changes.push({ key, description: desc });
386
+ }
387
+ };
388
+ collectChild("disableSanityCheckAsar", "disableSanityCheck", "moved disableSanityCheckAsar → asar.disableSanityCheck");
389
+ collectChild("disableAsarIntegrity", "disableIntegrity", "moved disableAsarIntegrity → asar.disableIntegrity");
390
+ if (unpackSources.length === 0 && childRenames.length === 0 && !asarIsTrue) {
391
+ return;
392
+ }
393
+ const buildEntries = (childIndent) => {
394
+ const out = [];
395
+ if (unpackSources.length === 1) {
396
+ out.push(`unpack: ${this.valueText(unpackSources[0], childIndent)}`);
397
+ }
398
+ else if (unpackSources.length > 1) {
399
+ out.push(`unpack: ${this.mergeArrays(unpackSources)}`);
400
+ }
401
+ for (const c of childRenames) {
402
+ out.push(`${c.renameTo}: ${this.valueText(c.value, childIndent)}`);
403
+ }
404
+ return out;
405
+ };
406
+ if (asarIsObject) {
407
+ this.insertIntoObject(asarVal, buildEntries(this.propIndentFor(asarVal)));
408
+ return;
409
+ }
410
+ if (asarIsTrue) {
411
+ const braceIndent = this.lineIndentAt(this.start(asarProp.initializer));
412
+ const entries = buildEntries(braceIndent + this.indentUnit);
413
+ if (entries.length === 0) {
414
+ this.removeProp(asarProp);
415
+ }
416
+ else {
417
+ this.replaceValue(asarProp.initializer, this.objectLiteralTextAt(entries, braceIndent));
418
+ }
419
+ this.changes.push({ key: "asar", description: "replaced asar: true with asar object (true is no longer a valid value)" });
420
+ return;
421
+ }
422
+ // No asar prop yet — create one on root.
423
+ this.createChild(root, "asar", buildEntries(this.propIndentFor(root) + this.indentUnit));
424
+ }
425
+ ruleAppImageSystemIntegration(root) {
426
+ const appImage = this.getObjectProp(root, "appImage");
427
+ if (appImage == null) {
428
+ return;
429
+ }
430
+ const si = this.getProp(appImage, "systemIntegration");
431
+ if (si == null) {
432
+ return;
433
+ }
434
+ const appImageProp = this.getProp(root, "appImage");
435
+ if (appImage.properties.length === 1) {
436
+ this.removeProp(appImageProp);
437
+ }
438
+ else {
439
+ this.removeProp(si);
440
+ }
441
+ this.changes.push({ key: "appImage.systemIntegration", description: "removed appImage.systemIntegration (handled automatically by AppImageLauncher in v27)" });
442
+ }
443
+ rulePublish(parent, key, prefix = "") {
444
+ const ts = this.ts;
445
+ const prop = this.getProp(parent, key);
446
+ if (prop == null || !ts.isPropertyAssignment(prop)) {
447
+ return;
448
+ }
449
+ const value = this.unwrap(prop.initializer);
450
+ const entries = ts.isArrayLiteralExpression(value) ? value.elements : [value];
451
+ let changed = false;
452
+ for (const entry of entries) {
453
+ const obj = this.unwrap(entry);
454
+ if (!ts.isObjectLiteralExpression(obj)) {
455
+ continue;
456
+ }
457
+ const provider = this.stringLiteralValue(this.getProp(obj, "provider"));
458
+ const vPrefixed = this.getProp(obj, "vPrefixedTagName");
459
+ if (vPrefixed == null || !ts.isPropertyAssignment(vPrefixed)) {
460
+ continue;
461
+ }
462
+ if (provider === "github") {
463
+ const isFalse = vPrefixed.initializer.kind === ts.SyntaxKind.FalseKeyword;
464
+ this.replaceRange(this.start(vPrefixed), vPrefixed.end, `tagNamePrefix: ${isFalse ? '""' : '"v"'}`);
465
+ changed = true;
466
+ }
467
+ else if (provider === "gitlab") {
468
+ this.removeProp(vPrefixed);
469
+ changed = true;
470
+ }
471
+ }
472
+ if (changed) {
473
+ this.changes.push({
474
+ key: `${prefix}${key}[].vPrefixedTagName`,
475
+ description: "replaced vPrefixedTagName with tagNamePrefix on GitHub publish entries; removed from GitLab entries",
476
+ });
477
+ }
478
+ }
479
+ ruleSnap(root) {
480
+ const ts = this.ts;
481
+ const snapProp = this.getProp(root, "snap");
482
+ if (snapProp == null || !ts.isPropertyAssignment(snapProp)) {
483
+ return;
484
+ }
485
+ const snap = this.unwrap(snapProp.initializer);
486
+ if (!ts.isObjectLiteralExpression(snap)) {
487
+ this.removeProp(snapProp);
488
+ this.changes.push({ key: "snap", description: "removed empty snap config (use snapcraft in v27)" });
489
+ return;
490
+ }
491
+ const baseProp = this.getProp(snap, "base");
492
+ let base = this.stringLiteralValue(baseProp);
493
+ const restProps = snap.properties.filter((p) => p !== baseProp);
494
+ if (base === "custom") {
495
+ const childIndent = this.propIndentFor(root) + this.indentUnit;
496
+ const entries = ['base: "custom"', ...restProps.map((p) => this.entryText(p, childIndent))];
497
+ this.removeProp(snapProp);
498
+ this.createChild(root, "snapcraft", entries);
499
+ this.changes.push({ key: "snap", description: "moved snap (base: custom) → snapcraft verbatim" });
500
+ return;
501
+ }
502
+ let assumed = false;
503
+ if (base == null || !SNAP_BASES.has(base)) {
504
+ if (base != null) {
505
+ this.warnings.push(`snap config had an unrecognized base "${base}"; assumed "core20". Verify the snapcraft.base value (core18/core20/core22/core24/custom).`);
506
+ }
507
+ else {
508
+ this.warnings.push('snap config had no "base"; assumed "core20" for snapcraft. Verify and adjust the base if needed (core18/core20/core22/core24).');
509
+ }
510
+ base = "core20";
511
+ assumed = true;
512
+ }
513
+ const baseChildIndent = this.propIndentFor(root) + this.indentUnit + this.indentUnit;
514
+ const nestedEntries = restProps.map((p) => this.entryText(p, baseChildIndent));
515
+ const snapcraftChildIndent = this.propIndentFor(root) + this.indentUnit;
516
+ const nestedObject = nestedEntries.length > 0 ? this.objectLiteralTextAt(nestedEntries, snapcraftChildIndent) : "{}";
517
+ const entries = [`base: "${base}"`, `${base}: ${nestedObject}`];
518
+ this.removeProp(snapProp);
519
+ this.createChild(root, "snapcraft", entries);
520
+ this.changes.push({ key: "snap", description: `moved snap → snapcraft.${base}${assumed ? " (base defaulted to core20)" : ""}` });
521
+ }
522
+ ruleHelperBundleId(root) {
523
+ const prop = this.getProp(root, "helper-bundle-id");
524
+ if (prop == null || !this.ts.isPropertyAssignment(prop)) {
525
+ return;
526
+ }
527
+ const mac = this.getObjectProp(root, "mac");
528
+ if (mac != null && this.getProp(mac, "helperBundleId") != null) {
529
+ this.removeProp(prop);
530
+ this.changes.push({ key: "helper-bundle-id", description: "moved helper-bundle-id → mac.helperBundleId" });
531
+ return;
532
+ }
533
+ const ok = this.moveInto(root, "mac", [{ prop, renameTo: "helperBundleId" }], []);
534
+ if (ok) {
535
+ this.changes.push({ key: "helper-bundle-id", description: "moved helper-bundle-id → mac.helperBundleId" });
536
+ }
537
+ else {
538
+ this.warnings.push("mac already exists but is not an object literal; move helper-bundle-id → mac.helperBundleId manually.");
539
+ }
540
+ }
541
+ ruleSquirrelNoMsi(root) {
542
+ const ts = this.ts;
543
+ const sq = this.getObjectProp(root, "squirrelWindows");
544
+ if (sq == null) {
545
+ return;
546
+ }
547
+ const noMsi = this.getProp(sq, "noMsi");
548
+ if (noMsi == null || !ts.isPropertyAssignment(noMsi)) {
549
+ return;
550
+ }
551
+ if (this.getProp(sq, "msi") != null) {
552
+ this.removeProp(noMsi);
553
+ }
554
+ else {
555
+ this.replaceRange(this.start(noMsi), noMsi.end, `msi: ${this.negate(noMsi.initializer)}`);
556
+ }
557
+ this.changes.push({ key: "squirrelWindows.noMsi", description: "replaced squirrelWindows.noMsi → squirrelWindows.msi (inverted boolean)" });
558
+ }
559
+ ruleWinSign(root) {
560
+ const ts = this.ts;
561
+ const win = this.getObjectProp(root, "win");
562
+ if (win == null) {
563
+ return;
564
+ }
565
+ let signSet = this.getProp(win, "sign") != null;
566
+ const signAndEdit = this.getProp(win, "signAndEditExecutable");
567
+ if (signAndEdit != null && ts.isPropertyAssignment(signAndEdit)) {
568
+ const isFalse = signAndEdit.initializer.kind === ts.SyntaxKind.FalseKeyword;
569
+ this.removeProp(signAndEdit);
570
+ if (isFalse) {
571
+ this.warnings.push("win.signAndEditExecutable: false was used to skip both resource editing and signing. In v27, resource editing always runs. To skip signing only, set win.sign: false. There is no v27 equivalent that also skips resource editing — apply resources manually if needed.");
572
+ }
573
+ else {
574
+ this.changes.push({ key: "win.signAndEditExecutable", description: "removed win.signAndEditExecutable (resource editing always runs in v27; was the default)" });
575
+ }
576
+ }
577
+ const signExe = this.getProp(win, "signExecutable");
578
+ if (signExe != null && ts.isPropertyAssignment(signExe)) {
579
+ const isFalse = signExe.initializer.kind === ts.SyntaxKind.FalseKeyword;
580
+ this.removeProp(signExe);
581
+ if (isFalse && !signSet) {
582
+ this.createChild(win, "sign", [], "false");
583
+ signSet = true;
584
+ this.changes.push({ key: "win.signExecutable", description: "replaced win.signExecutable: false with win.sign: false (disables signing; resource editing still runs)" });
585
+ }
586
+ else {
587
+ this.changes.push({ key: "win.signExecutable", description: "removed win.signExecutable (signing is enabled by default when credentials are available)" });
588
+ }
589
+ }
590
+ const azure = this.getObjectProp(win, "azureSignOptions");
591
+ const signtool = this.getObjectProp(win, "signtoolOptions");
592
+ const hasAzure = azure != null;
593
+ const hasSigntool = signtool != null;
594
+ if (!hasAzure && !hasSigntool) {
595
+ return;
596
+ }
597
+ const originalSign = this.getProp(win, "sign");
598
+ const signAlreadySet = signSet || (originalSign != null && ts.isPropertyAssignment(originalSign) && originalSign.initializer.kind !== ts.SyntaxKind.NullKeyword);
599
+ if (signAlreadySet) {
600
+ this.warnings.push(`win.sign is already set alongside ${hasAzure ? "win.azureSignOptions" : "win.signtoolOptions"}. Remove the legacy key manually after verifying win.sign is correct.`);
601
+ return;
602
+ }
603
+ if (hasAzure && hasSigntool) {
604
+ this.warnings.push("Both win.azureSignOptions and win.signtoolOptions are set. win.signtoolOptions will be dropped and win.azureSignOptions will be migrated to win.sign: { type: 'azure', … } (Azure took priority in v26). Verify the migrated win.sign block is correct for your project.");
605
+ this.removeProp(this.getProp(win, "signtoolOptions"));
606
+ }
607
+ if (hasAzure) {
608
+ this.buildWinAzureSign(win, azure);
609
+ this.removeProp(this.getProp(win, "azureSignOptions"));
610
+ this.changes.push({ key: "win.azureSignOptions", description: 'moved win.azureSignOptions → win.sign: { type: "azure", … }' });
611
+ }
612
+ else {
613
+ this.buildWinSigntoolSign(win, signtool);
614
+ this.removeProp(this.getProp(win, "signtoolOptions"));
615
+ this.changes.push({ key: "win.signtoolOptions", description: 'moved win.signtoolOptions → win.sign: { type: "signtool", … }' });
616
+ }
617
+ }
618
+ buildWinSigntoolSign(win, signtool) {
619
+ const ts = this.ts;
620
+ const childIndent = this.propIndentFor(win) + this.indentUnit;
621
+ const entries = [];
622
+ for (const p of signtool.properties) {
623
+ if (ts.isPropertyAssignment(p) && this.propName(p) === "type") {
624
+ continue;
625
+ }
626
+ entries.push(this.entryText(p, childIndent));
627
+ }
628
+ entries.push('type: "signtool"');
629
+ this.createChild(win, "sign", entries);
630
+ }
631
+ buildWinAzureSign(win, azure) {
632
+ const ts = this.ts;
633
+ const childIndent = this.propIndentFor(win) + this.indentUnit;
634
+ const metaIndent = childIndent + this.indentUnit;
635
+ const knownEntries = [];
636
+ const metaEntries = [];
637
+ const extraKeys = [];
638
+ let existingMeta = null;
639
+ for (const p of azure.properties) {
640
+ if (!ts.isPropertyAssignment(p)) {
641
+ continue;
642
+ }
643
+ const name = this.propName(p);
644
+ if (name === "type") {
645
+ continue;
646
+ }
647
+ if (name === "additionalMetadata") {
648
+ existingMeta = this.unwrap(p.initializer);
649
+ continue;
650
+ }
651
+ const isString = ts.isStringLiteral(p.initializer);
652
+ if (AZURE_KNOWN_FIELDS.has(name)) {
653
+ knownEntries.push(this.entryText(p, childIndent));
654
+ }
655
+ else if (isString) {
656
+ metaEntries.push(this.entryText(p, metaIndent));
657
+ extraKeys.push(name);
658
+ }
659
+ else {
660
+ // Unknown non-string field — keep verbatim so nothing is silently dropped.
661
+ knownEntries.push(this.entryText(p, childIndent));
662
+ }
663
+ }
664
+ if (existingMeta != null && ts.isObjectLiteralExpression(existingMeta)) {
665
+ for (const p of existingMeta.properties) {
666
+ metaEntries.push(this.entryText(p, metaIndent));
667
+ }
668
+ }
669
+ const signEntries = [...knownEntries];
670
+ if (metaEntries.length > 0) {
671
+ signEntries.push(`additionalMetadata: ${this.objectLiteralTextAt(metaEntries, childIndent)}`);
672
+ this.changes.push({ key: "win.azureSignOptions", description: `moved extra keys [${extraKeys.join(", ")}] into win.sign.additionalMetadata` });
673
+ }
674
+ signEntries.push('type: "azure"');
675
+ this.createChild(win, "sign", signEntries);
676
+ }
677
+ ruleMacSigning(platform, name) {
678
+ const ts = this.ts;
679
+ const present = MAC_SIGN_FIELDS.filter(f => this.getProp(platform, f) != null);
680
+ const signIgnore = this.getProp(platform, "signIgnore");
681
+ const hasSignIgnore = signIgnore != null;
682
+ const existingSignProp = this.getProp(platform, "sign");
683
+ const existingSign = existingSignProp != null && ts.isPropertyAssignment(existingSignProp) ? this.unwrap(existingSignProp.initializer) : null;
684
+ const signIsCustom = existingSign != null && (ts.isStringLiteral(existingSign) || ts.isArrowFunction(existingSign) || ts.isFunctionExpression(existingSign) || ts.isIdentifier(existingSign));
685
+ const signIsNull = existingSign != null && existingSign.kind === ts.SyntaxKind.NullKeyword;
686
+ if (present.length === 0 && !hasSignIgnore) {
687
+ if (signIsNull) {
688
+ this.removeProp(existingSignProp);
689
+ this.changes.push({ key: `${name}.sign`, description: `removed ${name}.sign: null (v26 "no custom signer" = v27 default; sign: null now means skip signing)` });
690
+ }
691
+ return;
692
+ }
693
+ if (signIsCustom) {
694
+ const fields = [...present, ...(hasSignIgnore ? ["signIgnore"] : [])].join(", ");
695
+ this.warnings.push(`${name}.sign is a custom signing function/path, which cannot hold options. Move [${fields}] into an ElectronSignOptions object manually, or keep the custom signer and drop them.`);
696
+ return;
697
+ }
698
+ const sources = [];
699
+ for (const f of present) {
700
+ const prop = this.getProp(platform, f);
701
+ sources.push({ prop });
702
+ this.changes.push({ key: `${name}.${f}`, description: `moved ${name}.${f} → ${name}.sign.${f}` });
703
+ }
704
+ if (hasSignIgnore) {
705
+ sources.push({ prop: signIgnore, renameTo: "ignore" });
706
+ this.changes.push({ key: `${name}.signIgnore`, description: `renamed ${name}.signIgnore → ${name}.sign.ignore` });
707
+ }
708
+ // A bare `sign: null` should be dropped before we build the options object.
709
+ if (signIsNull) {
710
+ this.removeProp(existingSignProp);
711
+ }
712
+ this.moveInto(platform, "sign", sources, [], /* treatNullAsAbsent */ true);
713
+ }
714
+ ruleMacUniversal(platform, name) {
715
+ const present = MAC_UNIVERSAL_FIELDS.filter(f => this.getProp(platform, f) != null);
716
+ if (present.length === 0) {
717
+ return;
718
+ }
719
+ const sources = present.map(f => {
720
+ this.changes.push({ key: `${name}.${f}`, description: `moved ${name}.${f} → ${name}.universal.${f}` });
721
+ return { prop: this.getProp(platform, f) };
722
+ });
723
+ const ok = this.moveInto(platform, "universal", sources, []);
724
+ if (!ok) {
725
+ this.warnings.push(`${name}.universal already exists but is not an object literal; move ${present.join(", ")} into it manually.`);
726
+ }
727
+ }
728
+ ruleElectronDownload(root) {
729
+ const ts = this.ts;
730
+ const prop = this.getProp(root, "electronDownload");
731
+ if (prop == null || !ts.isPropertyAssignment(prop)) {
732
+ return;
733
+ }
734
+ const old = this.unwrap(prop.initializer);
735
+ if (!ts.isObjectLiteralExpression(old)) {
736
+ this.renameKey(prop, "electronGet");
737
+ this.changes.push({ key: "electronDownload", description: "renamed electronDownload → electronGet" });
738
+ return;
739
+ }
740
+ const childIndent = this.propIndentFor(root) + this.indentUnit;
741
+ const entries = [];
742
+ const dropped = [];
743
+ let mirrorValueText = null;
744
+ let existingMirrorOptions = null;
745
+ for (const p of old.properties) {
746
+ if (!ts.isPropertyAssignment(p)) {
747
+ continue;
748
+ }
749
+ const name = this.propName(p);
750
+ if (name === "mirror") {
751
+ mirrorValueText = this.valueText(p.initializer, childIndent + this.indentUnit);
752
+ continue;
753
+ }
754
+ if (name === "isVerifyChecksum") {
755
+ if (p.initializer.kind === ts.SyntaxKind.FalseKeyword) {
756
+ entries.push("unsafelyDisableChecksums: true");
757
+ }
758
+ else {
759
+ this.warnings.push("electronGet: isVerifyChecksum had a non-false value; review electronGet.unsafelyDisableChecksums manually.");
760
+ }
761
+ continue;
762
+ }
763
+ if (ELECTRON_DOWNLOAD_DROPPED.includes(name)) {
764
+ dropped.push(name);
765
+ continue;
766
+ }
767
+ if (name === "mirrorOptions") {
768
+ existingMirrorOptions = this.unwrap(p.initializer);
769
+ continue;
770
+ }
771
+ entries.push(this.entryText(p, childIndent));
772
+ }
773
+ if (mirrorValueText != null || existingMirrorOptions != null) {
774
+ const moInner = [];
775
+ if (existingMirrorOptions != null && ts.isObjectLiteralExpression(existingMirrorOptions)) {
776
+ for (const p of existingMirrorOptions.properties) {
777
+ moInner.push(this.entryText(p, childIndent + this.indentUnit));
778
+ }
779
+ }
780
+ if (mirrorValueText != null) {
781
+ moInner.push(`mirror: ${mirrorValueText}`);
782
+ }
783
+ entries.push(`mirrorOptions: ${this.objectLiteralTextAt(moInner, childIndent)}`);
784
+ }
785
+ if (dropped.length > 0) {
786
+ this.warnings.push(`electronGet (formerly electronDownload) dropped [${dropped.join(", ")}] — these have no equivalent in @electron/get v5. Set a mirror via electronGet.mirrorOptions if needed.`);
787
+ }
788
+ this.removeProp(prop);
789
+ this.createChild(root, "electronGet", entries);
790
+ this.changes.push({
791
+ key: "electronDownload",
792
+ description: "renamed electronDownload → electronGet (mirror → mirrorOptions.mirror; isVerifyChecksum → unsafelyDisableChecksums)",
793
+ });
794
+ }
795
+ // ── Edit primitives ───────────────────────────────────────────────────────
796
+ /**
797
+ * Moves `sources` properties into a child object `childKey` of `parent` (creating it when absent).
798
+ * Returns false when the child exists but is not an object literal (caller should warn).
799
+ */
800
+ moveInto(parent, childKey, sources, extraEntries, treatNullAsAbsent = false) {
801
+ const ts = this.ts;
802
+ const existingProp = this.getProp(parent, childKey);
803
+ let existingObj = null;
804
+ if (existingProp != null && ts.isPropertyAssignment(existingProp)) {
805
+ const v = this.unwrap(existingProp.initializer);
806
+ if (ts.isObjectLiteralExpression(v)) {
807
+ existingObj = v;
808
+ }
809
+ else if (!(treatNullAsAbsent && v.kind === ts.SyntaxKind.NullKeyword)) {
810
+ return false;
811
+ }
812
+ }
813
+ if (existingObj != null) {
814
+ const childIndent = this.propIndentFor(existingObj);
815
+ const entries = sources.map(s => this.entryText(s.prop, childIndent, s.renameTo)).concat(extraEntries);
816
+ for (const s of sources) {
817
+ this.removeProp(s.prop);
818
+ }
819
+ this.insertIntoObject(existingObj, entries);
820
+ return true;
821
+ }
822
+ const childIndent = this.propIndentFor(parent) + this.indentUnit;
823
+ const entries = sources.map(s => this.entryText(s.prop, childIndent, s.renameTo)).concat(extraEntries);
824
+ for (const s of sources) {
825
+ this.removeProp(s.prop);
826
+ }
827
+ this.createChild(parent, childKey, entries);
828
+ return true;
829
+ }
830
+ /** Prepends `childKey: { entries }` (or `childKey: rawValue`) as the first property of `parent`. */
831
+ createChild(parent, childKey, entries, rawValue) {
832
+ const parentPropIndent = this.propIndentFor(parent);
833
+ const value = rawValue != null ? rawValue : this.objectLiteralTextAt(entries, parentPropIndent);
834
+ const braceEnd = this.start(parent) + 1;
835
+ this.insertEdit(braceEnd, `\n${parentPropIndent}${childKey}: ${value},`);
836
+ }
837
+ /** Inserts already-built "key: value" entries as the first properties of `objLit`. */
838
+ insertIntoObject(objLit, entries) {
839
+ if (entries.length === 0) {
840
+ return;
841
+ }
842
+ const propIndent = this.propIndentFor(objLit);
843
+ const braceEnd = this.start(objLit) + 1;
844
+ const body = entries.map(e => `\n${propIndent}${e},`).join("");
845
+ if (objLit.properties.length > 0) {
846
+ this.insertEdit(braceEnd, body);
847
+ }
848
+ else {
849
+ const objLineIndent = this.lineIndentAt(this.start(objLit));
850
+ this.insertEdit(braceEnd, body + `\n${objLineIndent}`);
851
+ }
852
+ }
853
+ /** Renders a multi-line object literal whose closing brace aligns to `braceIndent`. */
854
+ objectLiteralTextAt(entries, braceIndent) {
855
+ if (entries.length === 0) {
856
+ return "{}";
857
+ }
858
+ const propIndent = braceIndent + this.indentUnit;
859
+ const body = entries.map(e => `\n${propIndent}${e},`).join("");
860
+ return `{${body}\n${braceIndent}}`;
861
+ }
862
+ removeProp(prop) {
863
+ if (prop == null) {
864
+ return;
865
+ }
866
+ this.replaceRange(prop.pos, this.endWithTrailingComma(prop), "");
867
+ }
868
+ renameKey(prop, newName) {
869
+ this.replaceRange(this.start(prop.name), prop.name.end, newName);
870
+ }
871
+ replaceValue(valueNode, newText) {
872
+ this.replaceRange(this.start(valueNode), valueNode.end, newText);
873
+ }
874
+ /** "key: value" text for a property, re-indenting a multi-line value to `targetIndent`. */
875
+ entryText(prop, targetIndent, renameTo) {
876
+ if (prop.name == null) {
877
+ // Spread assignment (`...x`) or other nameless member — capture verbatim, re-indented.
878
+ return this.reindent(this.text.slice(this.start(prop), prop.end), this.lineIndentAt(this.start(prop)), targetIndent);
879
+ }
880
+ const keyText = renameTo != null ? renameTo : this.text.slice(this.start(prop.name), prop.name.end);
881
+ if (this.ts.isPropertyAssignment(prop)) {
882
+ return `${keyText}: ${this.valueText(prop.initializer, targetIndent)}`;
883
+ }
884
+ if (this.ts.isShorthandPropertyAssignment(prop)) {
885
+ return keyText;
886
+ }
887
+ // Method / accessor — capture verbatim, re-indented.
888
+ return this.reindent(this.text.slice(this.start(prop), prop.end), this.lineIndentAt(this.start(prop)), targetIndent);
889
+ }
890
+ /** Source text of a value node, re-indenting continuation lines from its original to `targetIndent`. */
891
+ valueText(valueNode, targetIndent) {
892
+ const raw = this.text.slice(this.start(valueNode), valueNode.end);
893
+ if (!raw.includes("\n")) {
894
+ return raw;
895
+ }
896
+ const fromIndent = this.lineIndentAt(this.start(valueNode));
897
+ return this.reindent(raw, fromIndent, targetIndent);
898
+ }
899
+ mergeArrays(valueNodes) {
900
+ const ts = this.ts;
901
+ const elems = [];
902
+ for (const v of valueNodes) {
903
+ const node = this.unwrap(v);
904
+ if (ts.isArrayLiteralExpression(node)) {
905
+ for (const el of node.elements) {
906
+ elems.push(this.text.slice(this.start(el), el.end));
907
+ }
908
+ }
909
+ else {
910
+ elems.push(this.text.slice(this.start(node), node.end));
911
+ }
912
+ }
913
+ return `[${elems.join(", ")}]`;
914
+ }
915
+ negate(valueNode) {
916
+ const ts = this.ts;
917
+ if (valueNode.kind === ts.SyntaxKind.TrueKeyword) {
918
+ return "false";
919
+ }
920
+ if (valueNode.kind === ts.SyntaxKind.FalseKeyword) {
921
+ return "true";
922
+ }
923
+ return `!(${this.text.slice(this.start(valueNode), valueNode.end)})`;
924
+ }
925
+ // ── Low-level helpers ──────────────────────────────────────────────────────
926
+ start(node) {
927
+ return node.getStart(this.sf);
928
+ }
929
+ getProp(objLit, name) {
930
+ const ts = this.ts;
931
+ for (const p of objLit.properties) {
932
+ if (p.name == null) {
933
+ continue;
934
+ }
935
+ let key;
936
+ if (ts.isIdentifier(p.name) || ts.isStringLiteral(p.name) || ts.isNumericLiteral(p.name)) {
937
+ key = p.name.text;
938
+ }
939
+ else {
940
+ continue;
941
+ }
942
+ if (key === name) {
943
+ return p;
944
+ }
945
+ }
946
+ return null;
947
+ }
948
+ getObjectProp(objLit, name) {
949
+ const ts = this.ts;
950
+ const prop = this.getProp(objLit, name);
951
+ if (prop == null || !ts.isPropertyAssignment(prop)) {
952
+ return null;
953
+ }
954
+ const v = this.unwrap(prop.initializer);
955
+ return ts.isObjectLiteralExpression(v) ? v : null;
956
+ }
957
+ propName(prop) {
958
+ const ts = this.ts;
959
+ if (prop.name != null && (ts.isIdentifier(prop.name) || ts.isStringLiteral(prop.name) || ts.isNumericLiteral(prop.name))) {
960
+ return prop.name.text;
961
+ }
962
+ return undefined;
963
+ }
964
+ stringLiteralValue(prop) {
965
+ const ts = this.ts;
966
+ if (prop == null || !ts.isPropertyAssignment(prop)) {
967
+ return undefined;
968
+ }
969
+ const v = this.unwrap(prop.initializer);
970
+ return ts.isStringLiteral(v) ? v.text : undefined;
971
+ }
972
+ endWithTrailingComma(prop) {
973
+ let i = prop.end;
974
+ while (i < this.text.length && (this.text[i] === " " || this.text[i] === "\t")) {
975
+ i++;
976
+ }
977
+ return this.text[i] === "," ? i + 1 : prop.end;
978
+ }
979
+ lineIndentAt(pos) {
980
+ let i = pos;
981
+ while (i > 0 && this.text[i - 1] !== "\n") {
982
+ i--;
983
+ }
984
+ let j = i;
985
+ while (j < this.text.length && (this.text[j] === " " || this.text[j] === "\t")) {
986
+ j++;
987
+ }
988
+ return this.text.slice(i, j);
989
+ }
990
+ detectIndentUnit(root) {
991
+ const braceIndent = this.lineIndentAt(this.start(root));
992
+ for (const p of root.properties) {
993
+ const pi = this.lineIndentAt(this.start(p));
994
+ if (pi.length > braceIndent.length) {
995
+ return pi.slice(braceIndent.length);
996
+ }
997
+ }
998
+ return " ";
999
+ }
1000
+ propIndentFor(objLit) {
1001
+ for (const p of objLit.properties) {
1002
+ return this.lineIndentAt(this.start(p));
1003
+ }
1004
+ return this.lineIndentAt(this.start(objLit)) + this.indentUnit;
1005
+ }
1006
+ reindent(text, fromIndent, toIndent) {
1007
+ const delta = toIndent.length - fromIndent.length;
1008
+ if (delta === 0) {
1009
+ return text;
1010
+ }
1011
+ const lines = text.split("\n");
1012
+ return lines
1013
+ .map((line, idx) => {
1014
+ if (idx === 0) {
1015
+ return line;
1016
+ }
1017
+ if (delta > 0) {
1018
+ return " ".repeat(delta) + line;
1019
+ }
1020
+ let removed = 0;
1021
+ let k = 0;
1022
+ while (k < line.length && removed < -delta && line[k] === " ") {
1023
+ k++;
1024
+ removed++;
1025
+ }
1026
+ return line.slice(k);
1027
+ })
1028
+ .join("\n");
1029
+ }
1030
+ replaceRange(start, end, text) {
1031
+ this.edits.push({ start, end, text });
1032
+ }
1033
+ insertEdit(pos, text) {
1034
+ this.edits.push({ start: pos, end: pos, text });
1035
+ }
1036
+ apply() {
1037
+ const edits = [...this.edits].sort((a, b) => a.start - b.start || a.end - b.end);
1038
+ let out = "";
1039
+ let cursor = 0;
1040
+ for (const e of edits) {
1041
+ if (e.start < cursor) {
1042
+ throw new Error(`overlapping edits at ${e.start} (cursor ${cursor})`);
1043
+ }
1044
+ out += this.text.slice(cursor, e.start) + e.text;
1045
+ cursor = e.end;
1046
+ }
1047
+ out += this.text.slice(cursor);
1048
+ return out;
1049
+ }
1050
+ }
1051
+ //# sourceMappingURL=migrate-schema-programmatic.js.map