@afterpack/protection-map 1.0.3 → 1.1.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 +22 -0
- package/package.json +1 -1
- package/template.html +425 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
The full changelog, including cloud and dashboard changes, is at https://www.afterpack.dev/changelog.
|
|
4
4
|
|
|
5
|
+
## 1.1.0 - 2026-11-28
|
|
6
|
+
|
|
7
|
+
Cloud builds of any size, all-caps variables and empty values that reset
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- **Cloud:** A Pro cloud build of any size runs as one build. The server splits a large build into parts, and you get one entry in the builds list, one usage charge and one Protection Map that merges every part. The 200-file limit on a cloud build is gone with the 1.1.0 CLI and plugins; older versions keep sending each build as one request, within that limit. A build that is cancelled or drops gives back what it reserved for files it did not deliver.
|
|
12
|
+
- **Dashboard:** A cloud build in progress shows as building, with the bytes it has reserved. Once it finishes, its page shows what was billed and what went back.
|
|
13
|
+
- **Plugins:** An empty value resets `key`, `seed` or a list option to its default and overrides `afterpack.json`: `AFTERPACK_KEY=` builds locally on Free, and `AFTERPACK_SEED=` draws a fresh seed. Before, an empty seed pinned one fixed seed, in the plugins and in `@afterpack/core` and `@afterpack/wasm` alike. An empty value for any other option, such as `AFTERPACK_PRESET=`, now fails the build with an error naming the option, and so do `complexity=` and `inflation.max=` in a directive. ([Empty values](https://www.afterpack.dev/docs/config#empty-values))
|
|
14
|
+
- **Engine:** In `@afterpack/core`, `key: null` builds locally on Free without reading `AFTERPACK_KEY` or `afterpack.json`.
|
|
15
|
+
- **CLI:** `afterpack network keygen` prints a key pair for network protection, which arrives in a later release.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- **Plugins:** Every option's environment variable is spelled in capitals: `strings.minLength` is `AFTERPACK_STRINGS_MIN_LENGTH`. The spelling that keeps the option's case, `AFTERPACK_strings_minLength`, still works. Setting both spellings of one option to different values fails the build. An all-caps variable that looks like an option but matches none, such as `AFTERPACK_SOURCEMAP_ENABLED`, fails with the right spelling. ([Configuration](https://www.afterpack.dev/docs/config))
|
|
20
|
+
- **Plugins:** The CLI and plugins read `key` only from `--key=`, `AFTERPACK_KEY` and the `afterpack.json` they read the rest of the configuration from. A key in another `afterpack.json`, such as one at a monorepo root above the project's own, no longer applies. If your key lives only in a monorepo-root `afterpack.json`, move it to `AFTERPACK_KEY` or the project's own `afterpack.json`. With an engine older than 1.1.0, a build that would pick up such a key fails and names the update to install. ([Key lookup](https://www.afterpack.dev/docs/config#key-lookup))
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- **Plugins:** `seed: "git"` with no commit to read falls back to the seed in `AFTERPACK_SEED`, then the one in `afterpack.json`.
|
|
25
|
+
- **Plugins:** Astro's server build adds its entries to `strings.preserveLiterals` instead of replacing the list from `afterpack.json` or the environment.
|
|
26
|
+
|
|
5
27
|
## 1.0.3 - 2026-11-13
|
|
6
28
|
|
|
7
29
|
A smaller WebAssembly engine and a `super` fix
|
package/package.json
CHANGED
package/template.html
CHANGED
|
@@ -1337,6 +1337,405 @@ async function afterpackInflateBase64Gzip(b64) {
|
|
|
1337
1337
|
var buf = await new Response(stream).arrayBuffer();
|
|
1338
1338
|
return new TextDecoder().decode(buf);
|
|
1339
1339
|
}
|
|
1340
|
+
|
|
1341
|
+
var afterpackBuildProjectFileTree = (function () {
|
|
1342
|
+
const REVERSAL_CLASS_ORDER = ["preserved", "renamed-encoded", "flattened-fused", "destroyed-fused"];
|
|
1343
|
+
|
|
1344
|
+
function round4(v) {
|
|
1345
|
+
return Math.round(v * 1e4) / 1e4;
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
function isRuntimeSource(rawPath) {
|
|
1349
|
+
const p = rawPath ?? "";
|
|
1350
|
+
if (p.includes("[turbopack]") || p.includes("[next]")) return true;
|
|
1351
|
+
if (/(^|\/)webpack\/(runtime|bootstrap)/.test(p)) return true;
|
|
1352
|
+
if (p.includes("webpack://_N_E/webpack/")) return true;
|
|
1353
|
+
if (/node_modules\/\.pnpm\/next[@/]/.test(p)) return true;
|
|
1354
|
+
if (/(^|\/)node_modules\/next\//.test(p)) return true;
|
|
1355
|
+
return false;
|
|
1356
|
+
}
|
|
1357
|
+
|
|
1358
|
+
function cleanSourcePath(rawPath) {
|
|
1359
|
+
let p = rawPath ?? "";
|
|
1360
|
+
p = p.replace(/^turbopack:\/\/\/\[project\]\//, "");
|
|
1361
|
+
p = p.replace(/^turbopack:\/\/\//, "");
|
|
1362
|
+
p = p.replace(/^webpack:\/\/_N_E\/\.\//, "");
|
|
1363
|
+
p = p.replace(/^webpack:\/\/_N_E\//, "");
|
|
1364
|
+
p = p.replace(/^webpack:\/\//, "");
|
|
1365
|
+
p = p.replace(/^\.\//, "");
|
|
1366
|
+
p = p.replace(/node_modules\/\.pnpm\/[^/]+\/node_modules\//, "node_modules/");
|
|
1367
|
+
return p;
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
function computeAggregate(
|
|
1371
|
+
regions,
|
|
1372
|
+
spotlights,
|
|
1373
|
+
renamedCount = 0,
|
|
1374
|
+
directives = [],
|
|
1375
|
+
extractedCount = 0,
|
|
1376
|
+
) {
|
|
1377
|
+
const regionCount = regions.length;
|
|
1378
|
+
let sumEntropy = 0;
|
|
1379
|
+
let maxEntropy = 0;
|
|
1380
|
+
let minEntropy = regionCount === 0 ? 0 : 1;
|
|
1381
|
+
let totalTransforms = 0;
|
|
1382
|
+
let decodeOps = 0;
|
|
1383
|
+
let callFrames = 0;
|
|
1384
|
+
let sizeDeltaEstTotal = 0;
|
|
1385
|
+
const classCounts = {
|
|
1386
|
+
preserved: 0,
|
|
1387
|
+
"renamed-encoded": 0,
|
|
1388
|
+
"flattened-fused": 0,
|
|
1389
|
+
"destroyed-fused": 0,
|
|
1390
|
+
};
|
|
1391
|
+
let maxClassRank = 0;
|
|
1392
|
+
for (const r of regions) {
|
|
1393
|
+
const e = typeof r.entropy === "number" ? r.entropy : 0;
|
|
1394
|
+
sumEntropy += e;
|
|
1395
|
+
if (e > maxEntropy) maxEntropy = e;
|
|
1396
|
+
if (e < minEntropy) minEntropy = e;
|
|
1397
|
+
totalTransforms += r.transformCount ?? (Array.isArray(r.lineage) ? r.lineage.length : 0);
|
|
1398
|
+
if (r.perf) {
|
|
1399
|
+
decodeOps += r.perf.decodeOps ?? 0;
|
|
1400
|
+
callFrames += r.perf.callFrames ?? 0;
|
|
1401
|
+
}
|
|
1402
|
+
sizeDeltaEstTotal += r.sizeDeltaEst ?? 0;
|
|
1403
|
+
const cls = r.reversalClass;
|
|
1404
|
+
if (cls != null && cls in classCounts) classCounts[cls] += 1;
|
|
1405
|
+
const rank = REVERSAL_CLASS_ORDER.indexOf(cls);
|
|
1406
|
+
if (rank > maxClassRank) maxClassRank = rank;
|
|
1407
|
+
}
|
|
1408
|
+
let leakCount = 0;
|
|
1409
|
+
for (const s of spotlights) if (s.severity === "leak") leakCount += 1;
|
|
1410
|
+
return {
|
|
1411
|
+
avgEntropy: round4(regionCount === 0 ? 0 : sumEntropy / regionCount),
|
|
1412
|
+
maxEntropy: round4(maxEntropy),
|
|
1413
|
+
minEntropy: round4(regionCount === 0 ? 0 : minEntropy),
|
|
1414
|
+
totalTransforms,
|
|
1415
|
+
renamedCount,
|
|
1416
|
+
extractedCount,
|
|
1417
|
+
weakRegions: spotlights.length,
|
|
1418
|
+
leakCount,
|
|
1419
|
+
perfCostTotal: { decodeOps, callFrames },
|
|
1420
|
+
sizeDeltaEstTotal,
|
|
1421
|
+
classSummary: { ...classCounts, maxClassReached: REVERSAL_CLASS_ORDER[maxClassRank] },
|
|
1422
|
+
directives,
|
|
1423
|
+
};
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
const SPAN_PACK_LIMIT = 1 << 25;
|
|
1427
|
+
|
|
1428
|
+
function packable(v, limit) {
|
|
1429
|
+
return v >= 0 && v < limit && (v | 0) === v;
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
function spanKey(start, end, kind) {
|
|
1433
|
+
if (packable(start, SPAN_PACK_LIMIT) && packable(end, SPAN_PACK_LIMIT) && packable(kind, 4)) {
|
|
1434
|
+
return (start * SPAN_PACK_LIMIT + end) * 4 + kind;
|
|
1435
|
+
}
|
|
1436
|
+
return `${start},${end},${kind}`;
|
|
1437
|
+
}
|
|
1438
|
+
|
|
1439
|
+
function sortTriples(flat) {
|
|
1440
|
+
const count = (flat.length / 3) | 0;
|
|
1441
|
+
const order = new Uint32Array(count);
|
|
1442
|
+
for (let i = 0; i < count; i++) order[i] = i;
|
|
1443
|
+
order.sort((x, y) => {
|
|
1444
|
+
const a = x * 3;
|
|
1445
|
+
const b = y * 3;
|
|
1446
|
+
return flat[a] - flat[b] || flat[a + 1] - flat[b + 1] || flat[a + 2] - flat[b + 2];
|
|
1447
|
+
});
|
|
1448
|
+
const out = new Array(count * 3);
|
|
1449
|
+
for (let i = 0; i < count; i++) {
|
|
1450
|
+
out[i * 3] = flat[order[i] * 3];
|
|
1451
|
+
out[i * 3 + 1] = flat[order[i] * 3 + 1];
|
|
1452
|
+
out[i * 3 + 2] = flat[order[i] * 3 + 2];
|
|
1453
|
+
}
|
|
1454
|
+
return out;
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
function mergeComplexitySpans(entries) {
|
|
1458
|
+
const lowest = new Map();
|
|
1459
|
+
for (const e of entries) {
|
|
1460
|
+
const flat = e.complexitySpans ?? [];
|
|
1461
|
+
for (let i = 0; i + 2 < flat.length; i += 3) {
|
|
1462
|
+
const key = spanKey(flat[i], flat[i + 1], 0);
|
|
1463
|
+
const seen = lowest.get(key);
|
|
1464
|
+
if (!seen) lowest.set(key, [flat[i], flat[i + 1], flat[i + 2]]);
|
|
1465
|
+
else if (flat[i + 2] < seen[2]) seen[2] = flat[i + 2];
|
|
1466
|
+
}
|
|
1467
|
+
}
|
|
1468
|
+
return sortTriples([...lowest.values()].flat());
|
|
1469
|
+
}
|
|
1470
|
+
|
|
1471
|
+
function mergeKindOrder(tables) {
|
|
1472
|
+
const next = new Map();
|
|
1473
|
+
const inDegree = new Map();
|
|
1474
|
+
for (const t of tables) {
|
|
1475
|
+
for (const name of t) {
|
|
1476
|
+
if (!next.has(name)) {
|
|
1477
|
+
next.set(name, new Set());
|
|
1478
|
+
inDegree.set(name, 0);
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
}
|
|
1482
|
+
for (const t of tables) {
|
|
1483
|
+
for (let i = 1; i < t.length; i++) {
|
|
1484
|
+
const after = next.get(t[i - 1]);
|
|
1485
|
+
if (t[i] === t[i - 1] || after.has(t[i])) continue;
|
|
1486
|
+
after.add(t[i]);
|
|
1487
|
+
inDegree.set(t[i], (inDegree.get(t[i]) ?? 0) + 1);
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
const order = [];
|
|
1491
|
+
const ready = [...next.keys()].filter((n) => inDegree.get(n) === 0).sort();
|
|
1492
|
+
while (ready.length) {
|
|
1493
|
+
const name = ready.shift();
|
|
1494
|
+
order.push(name);
|
|
1495
|
+
for (const m of next.get(name)) {
|
|
1496
|
+
const d = (inDegree.get(m) ?? 0) - 1;
|
|
1497
|
+
inDegree.set(m, d);
|
|
1498
|
+
if (d === 0) {
|
|
1499
|
+
ready.push(m);
|
|
1500
|
+
ready.sort();
|
|
1501
|
+
}
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
for (const name of [...next.keys()].sort()) if (!order.includes(name)) order.push(name);
|
|
1505
|
+
return order;
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
function mergeDeclarationLane(entries) {
|
|
1509
|
+
const tables = entries.map((e) =>
|
|
1510
|
+
Array.isArray(e.declarationKinds)
|
|
1511
|
+
? e.declarationKinds.filter((k) => typeof k === "string")
|
|
1512
|
+
: [],
|
|
1513
|
+
);
|
|
1514
|
+
const order = mergeKindOrder(tables);
|
|
1515
|
+
const rank = new Map(order.map((name, i) => [name, i]));
|
|
1516
|
+
const seen = new Set();
|
|
1517
|
+
const flat = [];
|
|
1518
|
+
for (const e of entries) {
|
|
1519
|
+
const kinds = Array.isArray(e.declarationKinds) ? e.declarationKinds : [];
|
|
1520
|
+
const spans = e.declarationSpans ?? [];
|
|
1521
|
+
for (let i = 0; i + 2 < spans.length; i += 3) {
|
|
1522
|
+
const k = rank.get(kinds[spans[i + 2]]);
|
|
1523
|
+
if (k === undefined) continue;
|
|
1524
|
+
const key = spanKey(spans[i], spans[i + 1], k);
|
|
1525
|
+
if (seen.has(key)) continue;
|
|
1526
|
+
seen.add(key);
|
|
1527
|
+
flat.push(spans[i], spans[i + 1], k);
|
|
1528
|
+
}
|
|
1529
|
+
}
|
|
1530
|
+
const used = [...new Set(flat.filter((_, i) => i % 3 === 2))].sort((a, b) => a - b);
|
|
1531
|
+
const compact = new Map(used.map((k, i) => [k, i]));
|
|
1532
|
+
for (let i = 2; i < flat.length; i += 3) flat[i] = compact.get(flat[i]);
|
|
1533
|
+
return { declarationKinds: used.map((k) => order[k]), declarationSpans: sortTriples(flat) };
|
|
1534
|
+
}
|
|
1535
|
+
|
|
1536
|
+
function mergeEntries(entries, path) {
|
|
1537
|
+
const regions = [];
|
|
1538
|
+
const seenRegion = new Set();
|
|
1539
|
+
const spotlights = [];
|
|
1540
|
+
const seenSpot = new Set();
|
|
1541
|
+
const renamedSpans = [];
|
|
1542
|
+
const seenRenamed = new Set();
|
|
1543
|
+
const extractedFlat = [];
|
|
1544
|
+
const seenExtracted = new Set();
|
|
1545
|
+
const directives = [];
|
|
1546
|
+
const seenDirective = new Set();
|
|
1547
|
+
for (const e of entries) {
|
|
1548
|
+
for (const r of e.regions ?? []) {
|
|
1549
|
+
const key = Array.isArray(r.span) ? `${r.span[0]},${r.span[1]}` : `~${regions.length}`;
|
|
1550
|
+
if (seenRegion.has(key)) continue;
|
|
1551
|
+
seenRegion.add(key);
|
|
1552
|
+
regions.push(r);
|
|
1553
|
+
}
|
|
1554
|
+
for (const s of e.spotlights ?? []) {
|
|
1555
|
+
const sp = Array.isArray(s.span) ? `${s.span[0]},${s.span[1]}` : "";
|
|
1556
|
+
const key = `${sp}|${s.severity ?? ""}|${s.sample ?? ""}`;
|
|
1557
|
+
if (seenSpot.has(key)) continue;
|
|
1558
|
+
seenSpot.add(key);
|
|
1559
|
+
spotlights.push(s);
|
|
1560
|
+
}
|
|
1561
|
+
for (const rn of e.renamedSpans ?? []) {
|
|
1562
|
+
const key = spanKey(rn[0], rn[1], 0);
|
|
1563
|
+
if (seenRenamed.has(key)) continue;
|
|
1564
|
+
seenRenamed.add(key);
|
|
1565
|
+
renamedSpans.push(rn);
|
|
1566
|
+
}
|
|
1567
|
+
const flat = e.extractedSpans ?? [];
|
|
1568
|
+
for (let i = 0; i + 2 < flat.length; i += 3) {
|
|
1569
|
+
const key = spanKey(flat[i], flat[i + 1], flat[i + 2]);
|
|
1570
|
+
if (seenExtracted.has(key)) continue;
|
|
1571
|
+
seenExtracted.add(key);
|
|
1572
|
+
extractedFlat.push(flat[i], flat[i + 1], flat[i + 2]);
|
|
1573
|
+
}
|
|
1574
|
+
const agg = e.aggregate;
|
|
1575
|
+
for (const d of agg?.directives ?? []) {
|
|
1576
|
+
const key = typeof d === "string" ? d : JSON.stringify(d);
|
|
1577
|
+
if (seenDirective.has(key)) continue;
|
|
1578
|
+
seenDirective.add(key);
|
|
1579
|
+
directives.push(d);
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
renamedSpans.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
1583
|
+
const extractedCount = (extractedFlat.length / 3) | 0;
|
|
1584
|
+
const extractedSpans = sortTriples(extractedFlat);
|
|
1585
|
+
regions.sort((a, b) => {
|
|
1586
|
+
const er = (b.entropyRaw ?? 0) - (a.entropyRaw ?? 0);
|
|
1587
|
+
if (er !== 0) return er;
|
|
1588
|
+
const as = Array.isArray(a.span) ? a.span[0] : 0;
|
|
1589
|
+
const bs = Array.isArray(b.span) ? b.span[0] : 0;
|
|
1590
|
+
if (as !== bs) return as - bs;
|
|
1591
|
+
const ae = Array.isArray(a.span) ? a.span[1] : 0;
|
|
1592
|
+
const be = Array.isArray(b.span) ? b.span[1] : 0;
|
|
1593
|
+
return ae - be;
|
|
1594
|
+
});
|
|
1595
|
+
const rep = entries.find((e) => e.file?.sourceOrigin === "original") ?? entries[0];
|
|
1596
|
+
const file = { ...(rep.file ?? {}), path, sourceOrigin: "original" };
|
|
1597
|
+
let outputSum = 0;
|
|
1598
|
+
let bundledSum = 0;
|
|
1599
|
+
let sawOutput = false;
|
|
1600
|
+
let sawBundled = false;
|
|
1601
|
+
let anyEstimated = false;
|
|
1602
|
+
for (const e of entries) {
|
|
1603
|
+
const m = e.file;
|
|
1604
|
+
if (!m) continue;
|
|
1605
|
+
if (typeof m.outputSize === "number" && Number.isFinite(m.outputSize)) {
|
|
1606
|
+
outputSum += m.outputSize;
|
|
1607
|
+
sawOutput = true;
|
|
1608
|
+
}
|
|
1609
|
+
if (typeof m.bundledInputSize === "number" && Number.isFinite(m.bundledInputSize)) {
|
|
1610
|
+
bundledSum += m.bundledInputSize;
|
|
1611
|
+
sawBundled = true;
|
|
1612
|
+
}
|
|
1613
|
+
if (m.outputSizeEstimated) anyEstimated = true;
|
|
1614
|
+
}
|
|
1615
|
+
if (sawBundled) file.bundledInputSize = bundledSum;
|
|
1616
|
+
if (sawOutput) {
|
|
1617
|
+
file.outputSize = outputSum;
|
|
1618
|
+
file.outputSizeEstimated = anyEstimated;
|
|
1619
|
+
}
|
|
1620
|
+
const denom = sawBundled && bundledSum > 0 ? bundledSum : file.inputSize;
|
|
1621
|
+
if (sawOutput && typeof denom === "number" && denom > 0) {
|
|
1622
|
+
file.inflationRatio = round4(outputSum / denom);
|
|
1623
|
+
} else if (sawOutput) {
|
|
1624
|
+
file.inflationRatio = 0;
|
|
1625
|
+
}
|
|
1626
|
+
return {
|
|
1627
|
+
file,
|
|
1628
|
+
regions,
|
|
1629
|
+
spotlights,
|
|
1630
|
+
renamedSpans,
|
|
1631
|
+
extractedSpans,
|
|
1632
|
+
...(entries.some((e) => Array.isArray(e.complexitySpans))
|
|
1633
|
+
? { complexitySpans: mergeComplexitySpans(entries) }
|
|
1634
|
+
: {}),
|
|
1635
|
+
...(entries.some((e) => Array.isArray(e.declarationSpans))
|
|
1636
|
+
? mergeDeclarationLane(entries)
|
|
1637
|
+
: {}),
|
|
1638
|
+
aggregate: computeAggregate(
|
|
1639
|
+
regions,
|
|
1640
|
+
spotlights,
|
|
1641
|
+
renamedSpans.length,
|
|
1642
|
+
directives,
|
|
1643
|
+
extractedCount,
|
|
1644
|
+
),
|
|
1645
|
+
};
|
|
1646
|
+
}
|
|
1647
|
+
|
|
1648
|
+
function buildProjectFileTree(files) {
|
|
1649
|
+
const byPath = new Map();
|
|
1650
|
+
const pathOrder = [];
|
|
1651
|
+
for (const raw of files) {
|
|
1652
|
+
const entry = raw;
|
|
1653
|
+
const file = entry?.file;
|
|
1654
|
+
if (!file) continue;
|
|
1655
|
+
if (file.sourceOrigin !== "original") continue;
|
|
1656
|
+
if (isRuntimeSource(file.path)) continue;
|
|
1657
|
+
const clean = cleanSourcePath(file.path);
|
|
1658
|
+
const srcKey = file.originalSource ?? "";
|
|
1659
|
+
let bySrc = byPath.get(clean);
|
|
1660
|
+
if (!bySrc) {
|
|
1661
|
+
bySrc = new Map();
|
|
1662
|
+
byPath.set(clean, bySrc);
|
|
1663
|
+
pathOrder.push(clean);
|
|
1664
|
+
}
|
|
1665
|
+
const group = bySrc.get(srcKey);
|
|
1666
|
+
if (group) group.push(entry);
|
|
1667
|
+
else bySrc.set(srcKey, [entry]);
|
|
1668
|
+
}
|
|
1669
|
+
const out = [];
|
|
1670
|
+
for (const clean of pathOrder) {
|
|
1671
|
+
const bySrc = byPath.get(clean);
|
|
1672
|
+
const variants = [...bySrc.values()];
|
|
1673
|
+
variants.forEach((entries, i) => {
|
|
1674
|
+
const path = i === 0 ? clean : `${clean}#${i + 1}`;
|
|
1675
|
+
const merged = mergeEntries(entries, path);
|
|
1676
|
+
if (i > 0 && merged.file) merged.file.pathCollision = true;
|
|
1677
|
+
out.push(merged);
|
|
1678
|
+
});
|
|
1679
|
+
}
|
|
1680
|
+
return out;
|
|
1681
|
+
}
|
|
1682
|
+
|
|
1683
|
+
return buildProjectFileTree;
|
|
1684
|
+
})();
|
|
1685
|
+
|
|
1686
|
+
function afterpackUncollidedFile(file) {
|
|
1687
|
+
const rest = { ...file, path: file.path.replace(/#\d+$/, "") };
|
|
1688
|
+
delete rest.pathCollision;
|
|
1689
|
+
return rest;
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
function afterpackMergeDocuments(docs) {
|
|
1693
|
+
if (docs.length === 1) return docs[0];
|
|
1694
|
+
const entries = [];
|
|
1695
|
+
let head = null;
|
|
1696
|
+
let generatedAt = null;
|
|
1697
|
+
const storedAggregate = new Map();
|
|
1698
|
+
for (const doc of docs) {
|
|
1699
|
+
if (!doc) continue;
|
|
1700
|
+
if (!head || (head.engine == null && doc.engine != null)) head = doc;
|
|
1701
|
+
if (doc.generatedAt != null && (generatedAt == null || doc.generatedAt > generatedAt)) {
|
|
1702
|
+
generatedAt = doc.generatedAt;
|
|
1703
|
+
}
|
|
1704
|
+
for (const entry of doc.files || []) {
|
|
1705
|
+
const file = entry && entry.file;
|
|
1706
|
+
for (const r of (entry && entry.regions) || []) storedAggregate.set(r, entry.aggregate);
|
|
1707
|
+
entries.push(
|
|
1708
|
+
file && file.pathCollision && typeof file.path === "string"
|
|
1709
|
+
? { ...entry, file: afterpackUncollidedFile(file) }
|
|
1710
|
+
: entry,
|
|
1711
|
+
);
|
|
1712
|
+
}
|
|
1713
|
+
}
|
|
1714
|
+
head = head || {};
|
|
1715
|
+
const files = afterpackBuildProjectFileTree(entries);
|
|
1716
|
+
for (const f of files) {
|
|
1717
|
+
const from = new Set(f.regions.map((r) => storedAggregate.get(r)));
|
|
1718
|
+
if (from.size !== 1) continue;
|
|
1719
|
+
const [stored] = from;
|
|
1720
|
+
if (!stored) continue;
|
|
1721
|
+
for (const k of ["avgEntropy", "maxEntropy", "minEntropy"]) {
|
|
1722
|
+
if (typeof stored[k] === "number") f.aggregate[k] = stored[k];
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
return {
|
|
1726
|
+
schemaVersion: head.schemaVersion,
|
|
1727
|
+
...(head.spanUnits !== undefined ? { spanUnits: head.spanUnits } : {}),
|
|
1728
|
+
generatedAt,
|
|
1729
|
+
engine: head.engine !== undefined ? head.engine : null,
|
|
1730
|
+
files,
|
|
1731
|
+
};
|
|
1732
|
+
}
|
|
1733
|
+
|
|
1734
|
+
async function afterpackDecodeSlice(slice) {
|
|
1735
|
+
return typeof slice === "string"
|
|
1736
|
+
? afterpackDecodeDocument(JSON.parse(await afterpackInflateBase64Gzip(slice)))
|
|
1737
|
+
: slice;
|
|
1738
|
+
}
|
|
1340
1739
|
</script>
|
|
1341
1740
|
<script>
|
|
1342
1741
|
(async function () {
|
|
@@ -1347,16 +1746,38 @@ async function afterpackInflateBase64Gzip(b64) {
|
|
|
1347
1746
|
var MAP_BYTES = null;
|
|
1348
1747
|
var codeBodyEl = document.getElementById("code-body");
|
|
1349
1748
|
try {
|
|
1749
|
+
var payloadBytes = function (text) {
|
|
1750
|
+
return text.charAt(0) === "{"
|
|
1751
|
+
? new TextEncoder().encode(text).length
|
|
1752
|
+
: Math.floor(text.replace(/=+$/, "").length * 3 / 4);
|
|
1753
|
+
};
|
|
1350
1754
|
var payload = dataEl.textContent.trim();
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1755
|
+
if (payload.charAt(0) === "[") {
|
|
1756
|
+
var slices = JSON.parse(payload);
|
|
1757
|
+
payload = null;
|
|
1758
|
+
MAP_BYTES = slices.reduce(function (sum, slice) {
|
|
1759
|
+
return sum + payloadBytes(typeof slice === "string" ? slice : JSON.stringify(slice));
|
|
1760
|
+
}, 0);
|
|
1761
|
+
codeBodyEl.textContent = "Loading…";
|
|
1762
|
+
var docs = [];
|
|
1763
|
+
for (var si = 0; si < slices.length; si++) {
|
|
1764
|
+
docs.push(await afterpackDecodeSlice(slices[si]));
|
|
1765
|
+
slices[si] = null;
|
|
1766
|
+
}
|
|
1767
|
+
slices = null;
|
|
1768
|
+
DATA = afterpackMergeDocuments(docs);
|
|
1769
|
+
docs = null;
|
|
1770
|
+
} else if (payload.charAt(0) === "{") {
|
|
1771
|
+
MAP_BYTES = payloadBytes(payload);
|
|
1355
1772
|
DATA = JSON.parse(payload);
|
|
1773
|
+
payload = null;
|
|
1356
1774
|
} else {
|
|
1775
|
+
MAP_BYTES = payloadBytes(payload);
|
|
1357
1776
|
codeBodyEl.textContent = "Loading…";
|
|
1358
1777
|
var json = await afterpackInflateBase64Gzip(payload);
|
|
1778
|
+
payload = null;
|
|
1359
1779
|
DATA = afterpackDecodeDocument(JSON.parse(json));
|
|
1780
|
+
json = null;
|
|
1360
1781
|
}
|
|
1361
1782
|
} catch (e) {
|
|
1362
1783
|
codeBodyEl.textContent = "Couldn't open this Protection Map: " + e.message;
|