@afterpack/integration-utils 0.1.0 → 0.2.0-rc.20260930T1421
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/dist/index.cjs +151 -71
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +129 -65
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -79,6 +79,7 @@ const LINEAGE_COLUMNS = [
|
|
|
79
79
|
"category",
|
|
80
80
|
"phase",
|
|
81
81
|
"entropyGain",
|
|
82
|
+
"credit",
|
|
82
83
|
"sizeDeltaEst",
|
|
83
84
|
"label"
|
|
84
85
|
];
|
|
@@ -169,6 +170,7 @@ function encodeCompact(data, { includeLineage = true } = {}) {
|
|
|
169
170
|
intern("category", st.category),
|
|
170
171
|
intern("phase", st.phase),
|
|
171
172
|
st.entropyGain,
|
|
173
|
+
st.credit == null ? 0 : st.credit,
|
|
172
174
|
st.sizeDeltaEst,
|
|
173
175
|
st.label == null ? null : st.label
|
|
174
176
|
]);
|
|
@@ -203,7 +205,12 @@ function encodeCompact(data, { includeLineage = true } = {}) {
|
|
|
203
205
|
},
|
|
204
206
|
aggregate: fdoc.aggregate,
|
|
205
207
|
...fdoc.renamedSpans?.length ? { renamedSpans: fdoc.renamedSpans } : {},
|
|
206
|
-
...fdoc.extractedSpans?.length ? { extractedSpans: fdoc.extractedSpans } : {}
|
|
208
|
+
...fdoc.extractedSpans?.length ? { extractedSpans: fdoc.extractedSpans } : {},
|
|
209
|
+
...fdoc.complexitySpans?.length ? { complexitySpans: fdoc.complexitySpans } : {},
|
|
210
|
+
...fdoc.declarationSpans?.length ? {
|
|
211
|
+
declarationKinds: fdoc.declarationKinds,
|
|
212
|
+
declarationSpans: fdoc.declarationSpans
|
|
213
|
+
} : {}
|
|
207
214
|
};
|
|
208
215
|
});
|
|
209
216
|
const prunedDict = {};
|
|
@@ -213,6 +220,7 @@ function encodeCompact(data, { includeLineage = true } = {}) {
|
|
|
213
220
|
...data && data.spanUnits !== void 0 ? { spanUnits: data.spanUnits } : {},
|
|
214
221
|
generatedAt: data && data.generatedAt !== void 0 ? data.generatedAt : null,
|
|
215
222
|
engine: data && data.engine !== void 0 ? data.engine : null,
|
|
223
|
+
...data && data.totals !== void 0 ? { totals: data.totals } : {},
|
|
216
224
|
legend,
|
|
217
225
|
dict: prunedDict,
|
|
218
226
|
columns: {
|
|
@@ -226,7 +234,8 @@ function encodeCompact(data, { includeLineage = true } = {}) {
|
|
|
226
234
|
|
|
227
235
|
//#endregion
|
|
228
236
|
//#region ../protection-map/render-core.mjs
|
|
229
|
-
const LINEAGE_EMBED_CAP =
|
|
237
|
+
const LINEAGE_EMBED_CAP = 200;
|
|
238
|
+
const LINEAGE_TOTAL_BUDGET = 2e4;
|
|
230
239
|
const PLACEHOLDER = "__AFTERPACK_DATA__";
|
|
231
240
|
function defaultTemplatePath() {
|
|
232
241
|
return (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href).resolve("@afterpack/protection-map/template.html");
|
|
@@ -241,12 +250,18 @@ function normalizeToFiles(raw) {
|
|
|
241
250
|
function capLineage(data) {
|
|
242
251
|
let cappedRegions = 0;
|
|
243
252
|
let totalLineageStepsRemoved = 0;
|
|
244
|
-
|
|
253
|
+
let remaining = LINEAGE_TOTAL_BUDGET;
|
|
254
|
+
for (const fileDoc of data.files || []) for (const region of fileDoc?.regions || []) {
|
|
255
|
+
if (!Array.isArray(region.lineage)) continue;
|
|
245
256
|
const originalLength = region.lineage.length;
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
257
|
+
const allow = Math.min(LINEAGE_EMBED_CAP, Math.max(0, remaining));
|
|
258
|
+
if (originalLength > allow) {
|
|
259
|
+
region.lineage = region.lineage.slice(0, allow);
|
|
260
|
+
region.lineageCapped = originalLength;
|
|
261
|
+
cappedRegions += 1;
|
|
262
|
+
totalLineageStepsRemoved += originalLength - allow;
|
|
263
|
+
}
|
|
264
|
+
remaining -= region.lineage.length;
|
|
250
265
|
}
|
|
251
266
|
return {
|
|
252
267
|
cappedRegions,
|
|
@@ -315,15 +330,7 @@ function findUpward(startDir, fileName, options = {}) {
|
|
|
315
330
|
//#endregion
|
|
316
331
|
//#region src/artifacts.ts
|
|
317
332
|
const AFTERPACK_DIR = ".afterpack";
|
|
318
|
-
const
|
|
319
|
-
".afterpack/",
|
|
320
|
-
"*.protectionMap.html",
|
|
321
|
-
"protectionMap.html",
|
|
322
|
-
"*.backup.*",
|
|
323
|
-
"*.map"
|
|
324
|
-
];
|
|
325
|
-
const GITIGNORE_FILE = ".gitignore";
|
|
326
|
-
const GITIGNORE_BLOCK_HEADER = "# AfterPack artifacts (auto-added)";
|
|
333
|
+
const AFTERPACK_GITIGNORE_CONTENT = "*\n";
|
|
327
334
|
const PUBLIC_SEGMENTS = new Set([
|
|
328
335
|
"public",
|
|
329
336
|
"static",
|
|
@@ -376,8 +383,9 @@ function writeArtifacts(input) {
|
|
|
376
383
|
}
|
|
377
384
|
if (mode === "single" && policy.protectionMap && protectionMapJson != null) {
|
|
378
385
|
(0, node_fs.mkdirSync)(afterpackDir, { recursive: true });
|
|
386
|
+
ensureAfterpackGitignore(afterpackDir);
|
|
379
387
|
const pmPath = (0, node_path.join)(afterpackDir, (0, node_path.basename)(paths.protectionMapPath));
|
|
380
|
-
if (policy.protectionMapInProd)
|
|
388
|
+
if (policy.protectionMapInProd) logProtectionMapInProd(pmPath, logger);
|
|
381
389
|
else logger.log(`[afterpack] wrote Protection Map -> ${pmPath} (gitignored; set protectionMap.enabled:false to skip)`);
|
|
382
390
|
const { html } = renderProtectionMapHtml(protectionMapJson);
|
|
383
391
|
(0, node_fs.writeFileSync)(pmPath, html);
|
|
@@ -477,6 +485,96 @@ function spanKey(start, end, kind) {
|
|
|
477
485
|
if (packable(start, SPAN_PACK_LIMIT) && packable(end, SPAN_PACK_LIMIT) && packable(kind, 4)) return (start * SPAN_PACK_LIMIT + end) * 4 + kind;
|
|
478
486
|
return `${start},${end},${kind}`;
|
|
479
487
|
}
|
|
488
|
+
function sortTriples(flat) {
|
|
489
|
+
const count = flat.length / 3 | 0;
|
|
490
|
+
const order = new Uint32Array(count);
|
|
491
|
+
for (let i = 0; i < count; i++) order[i] = i;
|
|
492
|
+
order.sort((x, y) => {
|
|
493
|
+
const a = x * 3;
|
|
494
|
+
const b = y * 3;
|
|
495
|
+
return flat[a] - flat[b] || flat[a + 1] - flat[b + 1] || flat[a + 2] - flat[b + 2];
|
|
496
|
+
});
|
|
497
|
+
const out = new Array(count * 3);
|
|
498
|
+
for (let i = 0; i < count; i++) {
|
|
499
|
+
out[i * 3] = flat[order[i] * 3];
|
|
500
|
+
out[i * 3 + 1] = flat[order[i] * 3 + 1];
|
|
501
|
+
out[i * 3 + 2] = flat[order[i] * 3 + 2];
|
|
502
|
+
}
|
|
503
|
+
return out;
|
|
504
|
+
}
|
|
505
|
+
function mergeComplexitySpans(entries) {
|
|
506
|
+
const lowest = new Map();
|
|
507
|
+
for (const e of entries) {
|
|
508
|
+
const flat = e.complexitySpans ?? [];
|
|
509
|
+
for (let i = 0; i + 2 < flat.length; i += 3) {
|
|
510
|
+
const key = spanKey(flat[i], flat[i + 1], 0);
|
|
511
|
+
const seen = lowest.get(key);
|
|
512
|
+
if (!seen) lowest.set(key, [
|
|
513
|
+
flat[i],
|
|
514
|
+
flat[i + 1],
|
|
515
|
+
flat[i + 2]
|
|
516
|
+
]);
|
|
517
|
+
else if (flat[i + 2] < seen[2]) seen[2] = flat[i + 2];
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
return sortTriples([...lowest.values()].flat());
|
|
521
|
+
}
|
|
522
|
+
function mergeKindOrder(tables) {
|
|
523
|
+
const next = new Map();
|
|
524
|
+
const inDegree = new Map();
|
|
525
|
+
for (const t of tables) for (const name of t) if (!next.has(name)) {
|
|
526
|
+
next.set(name, new Set());
|
|
527
|
+
inDegree.set(name, 0);
|
|
528
|
+
}
|
|
529
|
+
for (const t of tables) for (let i = 1; i < t.length; i++) {
|
|
530
|
+
const after = next.get(t[i - 1]);
|
|
531
|
+
if (t[i] === t[i - 1] || after.has(t[i])) continue;
|
|
532
|
+
after.add(t[i]);
|
|
533
|
+
inDegree.set(t[i], (inDegree.get(t[i]) ?? 0) + 1);
|
|
534
|
+
}
|
|
535
|
+
const order = [];
|
|
536
|
+
const ready = [...next.keys()].filter((n) => inDegree.get(n) === 0).sort();
|
|
537
|
+
while (ready.length) {
|
|
538
|
+
const name = ready.shift();
|
|
539
|
+
order.push(name);
|
|
540
|
+
for (const m of next.get(name)) {
|
|
541
|
+
const d = (inDegree.get(m) ?? 0) - 1;
|
|
542
|
+
inDegree.set(m, d);
|
|
543
|
+
if (d === 0) {
|
|
544
|
+
ready.push(m);
|
|
545
|
+
ready.sort();
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
for (const name of [...next.keys()].sort()) if (!order.includes(name)) order.push(name);
|
|
550
|
+
return order;
|
|
551
|
+
}
|
|
552
|
+
function mergeDeclarationLane(entries) {
|
|
553
|
+
const tables = entries.map((e) => Array.isArray(e.declarationKinds) ? e.declarationKinds.filter((k) => typeof k === "string") : []);
|
|
554
|
+
const order = mergeKindOrder(tables);
|
|
555
|
+
const rank = new Map(order.map((name, i) => [name, i]));
|
|
556
|
+
const seen = new Set();
|
|
557
|
+
const flat = [];
|
|
558
|
+
for (const e of entries) {
|
|
559
|
+
const kinds = Array.isArray(e.declarationKinds) ? e.declarationKinds : [];
|
|
560
|
+
const spans = e.declarationSpans ?? [];
|
|
561
|
+
for (let i = 0; i + 2 < spans.length; i += 3) {
|
|
562
|
+
const k = rank.get(kinds[spans[i + 2]]);
|
|
563
|
+
if (k === void 0) continue;
|
|
564
|
+
const key = spanKey(spans[i], spans[i + 1], k);
|
|
565
|
+
if (seen.has(key)) continue;
|
|
566
|
+
seen.add(key);
|
|
567
|
+
flat.push(spans[i], spans[i + 1], k);
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
const used = [...new Set(flat.filter((_, i) => i % 3 === 2))].sort((a, b) => a - b);
|
|
571
|
+
const compact = new Map(used.map((k, i) => [k, i]));
|
|
572
|
+
for (let i = 2; i < flat.length; i += 3) flat[i] = compact.get(flat[i]);
|
|
573
|
+
return {
|
|
574
|
+
declarationKinds: used.map((k) => order[k]),
|
|
575
|
+
declarationSpans: sortTriples(flat)
|
|
576
|
+
};
|
|
577
|
+
}
|
|
480
578
|
function mergeEntries(entries, path) {
|
|
481
579
|
const regions = [];
|
|
482
580
|
const seenRegion = new Set();
|
|
@@ -525,21 +623,7 @@ function mergeEntries(entries, path) {
|
|
|
525
623
|
}
|
|
526
624
|
renamedSpans.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
527
625
|
const extractedCount = extractedFlat.length / 3 | 0;
|
|
528
|
-
const
|
|
529
|
-
for (let i = 0; i < extractedCount; i++) order[i] = i;
|
|
530
|
-
order.sort((x, y) => {
|
|
531
|
-
const a = x * 3;
|
|
532
|
-
const b = y * 3;
|
|
533
|
-
return extractedFlat[a] - extractedFlat[b] || extractedFlat[a + 1] - extractedFlat[b + 1] || extractedFlat[a + 2] - extractedFlat[b + 2];
|
|
534
|
-
});
|
|
535
|
-
const extractedSpans = new Array(extractedCount * 3);
|
|
536
|
-
for (let i = 0; i < extractedCount; i++) {
|
|
537
|
-
const from = order[i] * 3;
|
|
538
|
-
const to = i * 3;
|
|
539
|
-
extractedSpans[to] = extractedFlat[from];
|
|
540
|
-
extractedSpans[to + 1] = extractedFlat[from + 1];
|
|
541
|
-
extractedSpans[to + 2] = extractedFlat[from + 2];
|
|
542
|
-
}
|
|
626
|
+
const extractedSpans = sortTriples(extractedFlat);
|
|
543
627
|
regions.sort((a, b) => {
|
|
544
628
|
const er = (b.entropyRaw ?? 0) - (a.entropyRaw ?? 0);
|
|
545
629
|
if (er !== 0) return er;
|
|
@@ -588,6 +672,8 @@ function mergeEntries(entries, path) {
|
|
|
588
672
|
spotlights,
|
|
589
673
|
renamedSpans,
|
|
590
674
|
extractedSpans,
|
|
675
|
+
...entries.some((e) => Array.isArray(e.complexitySpans)) ? { complexitySpans: mergeComplexitySpans(entries) } : {},
|
|
676
|
+
...entries.some((e) => Array.isArray(e.declarationSpans)) ? mergeDeclarationLane(entries) : {},
|
|
591
677
|
aggregate: computeAggregate(regions, spotlights, renamedSpans.length, directives, extractedCount)
|
|
592
678
|
};
|
|
593
679
|
}
|
|
@@ -631,8 +717,9 @@ function writeCombinedProtectionMap(input) {
|
|
|
631
717
|
const logger = input.logger ?? DEFAULT_LOGGER;
|
|
632
718
|
if (!policy.protectionMap || docs.length === 0) return null;
|
|
633
719
|
(0, node_fs.mkdirSync)(afterpackDir, { recursive: true });
|
|
720
|
+
ensureAfterpackGitignore(afterpackDir);
|
|
634
721
|
const outPath = (0, node_path.join)(afterpackDir, input.fileName ?? (0, node_path.basename)(combinedProtectionMapPath(buildDir)));
|
|
635
|
-
if (policy.protectionMapInProd)
|
|
722
|
+
if (policy.protectionMapInProd) logProtectionMapInProd(outPath, logger);
|
|
636
723
|
else logger.log(`[afterpack] wrote Protection Map -> ${outPath} (gitignored; set protectionMap.enabled:false to skip)`);
|
|
637
724
|
const flat = docs.flatMap((doc) => {
|
|
638
725
|
if (!doc) return [];
|
|
@@ -650,28 +737,23 @@ function writeCombinedProtectionMap(input) {
|
|
|
650
737
|
(0, node_fs.writeFileSync)(outPath, html);
|
|
651
738
|
return outPath;
|
|
652
739
|
}
|
|
653
|
-
function
|
|
654
|
-
|
|
740
|
+
function logProtectionMapInProd(pmPath, logger) {
|
|
741
|
+
const rel = (0, node_path.relative)(process.cwd(), pmPath);
|
|
742
|
+
const display = rel.startsWith("..") ? pmPath : rel;
|
|
743
|
+
logger.log(`[afterpack] Protection Map -> ${display} (local only, not deployed)`);
|
|
655
744
|
}
|
|
656
|
-
function
|
|
657
|
-
|
|
745
|
+
function afterpackRoot(dir) {
|
|
746
|
+
const resolved = (0, node_path.resolve)(dir);
|
|
747
|
+
const segments$1 = resolved.split(node_path.sep);
|
|
748
|
+
const index = segments$1.lastIndexOf(AFTERPACK_DIR);
|
|
749
|
+
return index === -1 ? resolved : segments$1.slice(0, index + 1).join(node_path.sep);
|
|
658
750
|
}
|
|
659
|
-
function
|
|
660
|
-
const
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
} catch {
|
|
666
|
-
existing = "";
|
|
667
|
-
}
|
|
668
|
-
const present = new Set(existing.split(/\r?\n/).map((l) => l.trim()));
|
|
669
|
-
const missing = GITIGNORE_ENTRIES.filter((e) => !present.has(e));
|
|
670
|
-
if (missing.length === 0) return [];
|
|
671
|
-
const prefix = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
|
|
672
|
-
const block = `${prefix}\n${GITIGNORE_BLOCK_HEADER}\n${missing.join("\n")}\n`;
|
|
673
|
-
(0, node_fs.writeFileSync)(gitignorePath, existing + block);
|
|
674
|
-
return missing;
|
|
751
|
+
function ensureAfterpackGitignore(afterpackDir) {
|
|
752
|
+
const root = afterpackRoot(afterpackDir);
|
|
753
|
+
const gitignorePath = (0, node_path.join)(root, ".gitignore");
|
|
754
|
+
if ((0, node_fs.existsSync)(gitignorePath)) return;
|
|
755
|
+
(0, node_fs.mkdirSync)(root, { recursive: true });
|
|
756
|
+
(0, node_fs.writeFileSync)(gitignorePath, AFTERPACK_GITIGNORE_CONTENT);
|
|
675
757
|
}
|
|
676
758
|
function warnIfPublicPath(artifactPath, logger = DEFAULT_LOGGER) {
|
|
677
759
|
const segments$1 = artifactPath.split(/[\\/]/).filter(Boolean);
|
|
@@ -1140,7 +1222,7 @@ const CONFIG_KEYS = [
|
|
|
1140
1222
|
kind: "number",
|
|
1141
1223
|
min: 0
|
|
1142
1224
|
},
|
|
1143
|
-
default: "the preset's value; light is
|
|
1225
|
+
default: "the preset's value; light is 5",
|
|
1144
1226
|
namedValuesOf: "preset"
|
|
1145
1227
|
},
|
|
1146
1228
|
{
|
|
@@ -1154,7 +1236,7 @@ const CONFIG_KEYS = [
|
|
|
1154
1236
|
min: 0,
|
|
1155
1237
|
unlimited: UNLIMITED
|
|
1156
1238
|
},
|
|
1157
|
-
default: "
|
|
1239
|
+
default: "unset"
|
|
1158
1240
|
},
|
|
1159
1241
|
{
|
|
1160
1242
|
path: "strings.encode",
|
|
@@ -1864,7 +1946,7 @@ function toPluginOptions(config) {
|
|
|
1864
1946
|
|
|
1865
1947
|
//#endregion
|
|
1866
1948
|
//#region src/compat.ts
|
|
1867
|
-
const MIN_CORE_VERSION = "0.
|
|
1949
|
+
const MIN_CORE_VERSION = "0.2.0";
|
|
1868
1950
|
const CORE_PACKAGE = "@afterpack/core";
|
|
1869
1951
|
const VERSION_PATTERN$1 = /^\d{1,9}\.\d{1,9}\.\d{1,9}(?:[-+][0-9A-Za-z.+-]{1,64})?$/;
|
|
1870
1952
|
const PACKAGE_NAME_PATTERN = /^(?:@[a-z0-9][a-z0-9._-]{0,63}\/)?[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
@@ -2567,7 +2649,8 @@ function detectProduction(env = {}, opts = {}) {
|
|
|
2567
2649
|
function resolveReportPolicy(env = {}, userOpts = {}, signals = {}) {
|
|
2568
2650
|
const isProduction = detectProduction(env, userOpts);
|
|
2569
2651
|
const hasBundlerSourcemap = signals.hasBundlerSourcemap ?? false;
|
|
2570
|
-
const
|
|
2652
|
+
const isCI = env.CI === "true" || env.CI === "1";
|
|
2653
|
+
const protectionMap = userOpts.protectionMap?.enabled ?? (hasBundlerSourcemap && !isCI);
|
|
2571
2654
|
const autoEnableBundlerSourcemap = userOpts.protectionMap?.enabled === true && !hasBundlerSourcemap;
|
|
2572
2655
|
const emitSourceMappingURL = userOpts.sourceMap?.emitUrl ?? !isProduction;
|
|
2573
2656
|
const backup = userOpts.build?.backup ?? !signals.inPlaceOutput;
|
|
@@ -2593,15 +2676,12 @@ const DEFAULT_PRESET = "light";
|
|
|
2593
2676
|
function presetTarget(preset) {
|
|
2594
2677
|
switch (preset) {
|
|
2595
2678
|
case "minify": return 0;
|
|
2596
|
-
case "light": return
|
|
2597
|
-
case "medium": return
|
|
2598
|
-
case "hard": return
|
|
2599
|
-
case "extreme": return
|
|
2679
|
+
case "light": return 5;
|
|
2680
|
+
case "medium": return 7;
|
|
2681
|
+
case "hard": return 12;
|
|
2682
|
+
case "extreme": return 25;
|
|
2600
2683
|
}
|
|
2601
2684
|
}
|
|
2602
|
-
function effectiveComplexityTarget(preset, complexity) {
|
|
2603
|
-
return complexity ?? presetTarget(preset ?? DEFAULT_PRESET);
|
|
2604
|
-
}
|
|
2605
2685
|
function buildEngineConfig(options) {
|
|
2606
2686
|
const { filePath, policy, seed = 0, engine } = options;
|
|
2607
2687
|
const perFileMap = "inputSourceMap" in options;
|
|
@@ -2611,9 +2691,9 @@ function buildEngineConfig(options) {
|
|
|
2611
2691
|
const sourceMap = { sourcesContent };
|
|
2612
2692
|
if (smEnabled !== void 0) sourceMap.enabled = smEnabled;
|
|
2613
2693
|
const defaults = {};
|
|
2614
|
-
|
|
2694
|
+
if (options.complexity !== void 0) defaults.complexity = options.complexity;
|
|
2615
2695
|
if (options.preset !== void 0) defaults.preset = options.preset;
|
|
2616
|
-
if (options.
|
|
2696
|
+
else if (options.complexity === void 0) defaults.preset = DEFAULT_PRESET;
|
|
2617
2697
|
const config = mergeInto({
|
|
2618
2698
|
...defaults,
|
|
2619
2699
|
sourceMap,
|
|
@@ -4039,7 +4119,7 @@ function describeLevel(preset, complexity) {
|
|
|
4039
4119
|
async function runObfuscationPass(options) {
|
|
4040
4120
|
const passStartedAt = options.startedAt ?? Date.now();
|
|
4041
4121
|
const callerAnchored = options.startedAt !== void 0;
|
|
4042
|
-
const { files, engine, label,
|
|
4122
|
+
const { files, engine, label, cwd, combinedProtectionMap, artifactOptions = {}, env = process.env } = options;
|
|
4043
4123
|
const logger = silenceSummaryLines(options.logger ?? DEFAULT_LOGGER, options.diagnostics);
|
|
4044
4124
|
const prefix = (message) => `[${label}] ${message}`;
|
|
4045
4125
|
const style = options.summaryStyle ?? "plugin";
|
|
@@ -4055,7 +4135,7 @@ async function runObfuscationPass(options) {
|
|
|
4055
4135
|
})), already.files, already.receiptPath, combinedProtectionMap.buildDir);
|
|
4056
4136
|
}
|
|
4057
4137
|
const resolvedSeed = resolveBuildSeed(options.seed, {
|
|
4058
|
-
root:
|
|
4138
|
+
root: cwd,
|
|
4059
4139
|
leg: options.buildLeg ?? combinedProtectionMap.buildDir
|
|
4060
4140
|
}, {
|
|
4061
4141
|
env,
|
|
@@ -4130,7 +4210,6 @@ async function runObfuscationPass(options) {
|
|
|
4130
4210
|
hasBundlerSourcemap,
|
|
4131
4211
|
inPlaceOutput: true
|
|
4132
4212
|
});
|
|
4133
|
-
ensureGitignore(combinedProtectionMap.buildDir);
|
|
4134
4213
|
if (policy.autoEnableBundlerSourcemap && options.messages?.autoEnableBundlerSourcemap) logger.warn(prefix(options.messages.autoEnableBundlerSourcemap));
|
|
4135
4214
|
if (options.emitToCaller && artifactOptions.build?.backup === true) logger.warn(prefix("build.backup:true is not available on this build — the obfuscated output is handed back in memory, so there is no emitted file for a `.backup.<hash>` copy to sit beside."));
|
|
4136
4215
|
const capture = captureDirectiveRegions(inputs, options.regions, directivesEnabled && !bundledCapture && !(postMinifyMode && inputs.length > 1));
|
|
@@ -4154,7 +4233,7 @@ async function runObfuscationPass(options) {
|
|
|
4154
4233
|
if (policy.protectionMap && files.length > 0 && mappedInputs > 0 && mappedInputs < files.length) logger.warn(prefix(`source-map coverage: ${mappedInputs}/${files.length} chunk(s) had a discoverable input source map — the other ${files.length - mappedInputs} are attributed only as opaque dist chunks, so the Protection Map under-reports their original sources.`));
|
|
4155
4234
|
const git = artifactOptions.git === false ? null : detectGitContext(artifactOptions.git ?? null, {
|
|
4156
4235
|
env,
|
|
4157
|
-
cwd
|
|
4236
|
+
cwd
|
|
4158
4237
|
});
|
|
4159
4238
|
const engineConfig = buildEngineConfig({
|
|
4160
4239
|
policy,
|
|
@@ -4202,7 +4281,7 @@ async function runObfuscationPass(options) {
|
|
|
4202
4281
|
if (telemetry && telemetryEnabled) {
|
|
4203
4282
|
const facts = {
|
|
4204
4283
|
label,
|
|
4205
|
-
projectRoot:
|
|
4284
|
+
projectRoot: cwd,
|
|
4206
4285
|
diagnostics: collected.diagnostics,
|
|
4207
4286
|
fileCount: files.length,
|
|
4208
4287
|
durationMs: engineEndedAt - passStartedAt,
|
|
@@ -4537,6 +4616,7 @@ exports.collectSourceMaps = collectSourceMaps;
|
|
|
4537
4616
|
exports.createTelemetryReporter = createTelemetryReporter;
|
|
4538
4617
|
exports.decodeDataUri = decodeDataUri;
|
|
4539
4618
|
exports.discoverInputSourceMap = discoverInputSourceMap;
|
|
4619
|
+
exports.ensureAfterpackGitignore = ensureAfterpackGitignore;
|
|
4540
4620
|
exports.extractSourceMappingURL = extractSourceMappingURL;
|
|
4541
4621
|
exports.findUpward = findUpward;
|
|
4542
4622
|
exports.getPath = getPath;
|
package/dist/index.d.cts
CHANGED
|
@@ -91,7 +91,7 @@ declare const CONFIG_KEYS: readonly [{
|
|
|
91
91
|
readonly kind: "number";
|
|
92
92
|
readonly min: 0;
|
|
93
93
|
};
|
|
94
|
-
readonly default: "the preset's value; light is
|
|
94
|
+
readonly default: "the preset's value; light is 5";
|
|
95
95
|
readonly namedValuesOf: "preset";
|
|
96
96
|
}, {
|
|
97
97
|
readonly path: "inflation.max";
|
|
@@ -104,7 +104,7 @@ declare const CONFIG_KEYS: readonly [{
|
|
|
104
104
|
readonly min: 0;
|
|
105
105
|
readonly unlimited: "unlimited";
|
|
106
106
|
};
|
|
107
|
-
readonly default: "
|
|
107
|
+
readonly default: "unset";
|
|
108
108
|
}, {
|
|
109
109
|
readonly path: "strings.encode";
|
|
110
110
|
readonly shape: "scalar";
|
|
@@ -688,6 +688,7 @@ interface WriteArtifactsResult {
|
|
|
688
688
|
wroteSourceMappingURL: boolean;
|
|
689
689
|
}
|
|
690
690
|
declare function writeArtifacts(input: WriteArtifactsInput): WriteArtifactsResult;
|
|
691
|
+
declare function ensureAfterpackGitignore(afterpackDir: string): void;
|
|
691
692
|
//#endregion
|
|
692
693
|
//#region src/notices.d.ts
|
|
693
694
|
interface CloudNotice {
|
|
@@ -1003,7 +1004,7 @@ interface ObfuscationPassOptions {
|
|
|
1003
1004
|
emitToCaller?: boolean;
|
|
1004
1005
|
engine: ObfuscationEngine;
|
|
1005
1006
|
label: string;
|
|
1006
|
-
|
|
1007
|
+
cwd: string;
|
|
1007
1008
|
combinedProtectionMap: CombinedProtectionMapTarget;
|
|
1008
1009
|
artifactOptions?: AfterpackArtifactOptions;
|
|
1009
1010
|
hasBundlerSourcemap?: boolean;
|
|
@@ -1144,4 +1145,4 @@ declare function extractSourceMappingURL(code: string): string | null;
|
|
|
1144
1145
|
declare function decodeDataUri(url: string): string | null;
|
|
1145
1146
|
declare function discoverInputSourceMap(jsPath: string, code?: string): string | null;
|
|
1146
1147
|
//#endregion
|
|
1147
|
-
export { type AfterpackArtifactOptions, type AfterpackConfig, type AfterpackPluginOptions, AlreadyObfuscatedError, type ArtifactMode, type BuildContext, type BuildEngineConfigOptions, type BundleEntryLike, type BundleJs, CLOUD_REFUSAL_SUMMARY, CONFIG_FILE_NAME, CONFIG_KEYS, CORE_FLOOR_SUMMARY, type CapturedDirective, type CapturedModule, type CliParseResult, type ClientIdentity, CloudApiError, type CloudErrorKind, type CloudNotice, type CollectJsOptions, type CombinedProtectionMapTarget, type ConfigIssue, type ConfigKeyDef, type ConfigScope, type ConfigSurface, type ConfigTier, type CoreConfig, type CoreConfigSubset, CoreVersionError, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, type DiagnosticsSummary, type DiagnosticsVerbosity, type DirectiveDiagnostic, type DirectiveManifest, type EngineBatchResult, type EngineDiagnostic, type EngineDiagnosticData, type EngineFileInput, type EngineFileResult, type EngineSeverity, type EngineSpan, type EnvLike, type EnvParseResult, type GitBuildContext, type GlobReserved, type InMemoryInput, type InMemoryOutput, type LoadedConfigFile, type Logger, type NormalizedPluginOptions, type NoticeLogger, type NoticeSeverity, type ObfuscationEngine, type ObfuscationPassOptions, type ObfuscationPassResult, type OutputBundleLike, PROTECTION_RECEIPT_FILE, type PassMessages, type PassReceiptIdentity, type PassSettings, type PassTiming, type PluginConfigInput, type PluginOptionsView, type Preset, type ProtectionReceipt, type ProtectionReceiptFile, type ProtectionVerification, type RegionConfig, type ReportPolicy, type ReportPolicySignals, type ResolvedPluginConfig, SEED_ENV_VAR, type SafeNotice, type SeedOption, type SeedOrigin, type TelemetryContext, type TelemetryDiagnostic, type TelemetryDiagnosticData, type TelemetryFacts, type TelemetryPayload, type TelemetryReporter, type TelemetryReporterDeps, type TelemetrySeverity, type TelemetrySpan, type TransformKind, UnreadableReceiptError, type ValidationResult, type ValueShape, type ValueType, type WriteArtifactsInput, type WriteArtifactsResult, type WriteProtectionReceiptInput, applyBundleOutput, applyResolvedKey, collectBundleJs, collectJsFiles, collectSourceMaps, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
|
|
1148
|
+
export { type AfterpackArtifactOptions, type AfterpackConfig, type AfterpackPluginOptions, AlreadyObfuscatedError, type ArtifactMode, type BuildContext, type BuildEngineConfigOptions, type BundleEntryLike, type BundleJs, CLOUD_REFUSAL_SUMMARY, CONFIG_FILE_NAME, CONFIG_KEYS, CORE_FLOOR_SUMMARY, type CapturedDirective, type CapturedModule, type CliParseResult, type ClientIdentity, CloudApiError, type CloudErrorKind, type CloudNotice, type CollectJsOptions, type CombinedProtectionMapTarget, type ConfigIssue, type ConfigKeyDef, type ConfigScope, type ConfigSurface, type ConfigTier, type CoreConfig, type CoreConfigSubset, CoreVersionError, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, type DiagnosticsSummary, type DiagnosticsVerbosity, type DirectiveDiagnostic, type DirectiveManifest, type EngineBatchResult, type EngineDiagnostic, type EngineDiagnosticData, type EngineFileInput, type EngineFileResult, type EngineSeverity, type EngineSpan, type EnvLike, type EnvParseResult, type GitBuildContext, type GlobReserved, type InMemoryInput, type InMemoryOutput, type LoadedConfigFile, type Logger, type NormalizedPluginOptions, type NoticeLogger, type NoticeSeverity, type ObfuscationEngine, type ObfuscationPassOptions, type ObfuscationPassResult, type OutputBundleLike, PROTECTION_RECEIPT_FILE, type PassMessages, type PassReceiptIdentity, type PassSettings, type PassTiming, type PluginConfigInput, type PluginOptionsView, type Preset, type ProtectionReceipt, type ProtectionReceiptFile, type ProtectionVerification, type RegionConfig, type ReportPolicy, type ReportPolicySignals, type ResolvedPluginConfig, SEED_ENV_VAR, type SafeNotice, type SeedOption, type SeedOrigin, type TelemetryContext, type TelemetryDiagnostic, type TelemetryDiagnosticData, type TelemetryFacts, type TelemetryPayload, type TelemetryReporter, type TelemetryReporterDeps, type TelemetrySeverity, type TelemetrySpan, type TransformKind, UnreadableReceiptError, type ValidationResult, type ValueShape, type ValueType, type WriteArtifactsInput, type WriteArtifactsResult, type WriteProtectionReceiptInput, applyBundleOutput, applyResolvedKey, collectBundleJs, collectJsFiles, collectSourceMaps, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, ensureAfterpackGitignore, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
|
package/dist/index.d.ts
CHANGED
|
@@ -91,7 +91,7 @@ declare const CONFIG_KEYS: readonly [{
|
|
|
91
91
|
readonly kind: "number";
|
|
92
92
|
readonly min: 0;
|
|
93
93
|
};
|
|
94
|
-
readonly default: "the preset's value; light is
|
|
94
|
+
readonly default: "the preset's value; light is 5";
|
|
95
95
|
readonly namedValuesOf: "preset";
|
|
96
96
|
}, {
|
|
97
97
|
readonly path: "inflation.max";
|
|
@@ -104,7 +104,7 @@ declare const CONFIG_KEYS: readonly [{
|
|
|
104
104
|
readonly min: 0;
|
|
105
105
|
readonly unlimited: "unlimited";
|
|
106
106
|
};
|
|
107
|
-
readonly default: "
|
|
107
|
+
readonly default: "unset";
|
|
108
108
|
}, {
|
|
109
109
|
readonly path: "strings.encode";
|
|
110
110
|
readonly shape: "scalar";
|
|
@@ -688,6 +688,7 @@ interface WriteArtifactsResult {
|
|
|
688
688
|
wroteSourceMappingURL: boolean;
|
|
689
689
|
}
|
|
690
690
|
declare function writeArtifacts(input: WriteArtifactsInput): WriteArtifactsResult;
|
|
691
|
+
declare function ensureAfterpackGitignore(afterpackDir: string): void;
|
|
691
692
|
//#endregion
|
|
692
693
|
//#region src/notices.d.ts
|
|
693
694
|
interface CloudNotice {
|
|
@@ -1003,7 +1004,7 @@ interface ObfuscationPassOptions {
|
|
|
1003
1004
|
emitToCaller?: boolean;
|
|
1004
1005
|
engine: ObfuscationEngine;
|
|
1005
1006
|
label: string;
|
|
1006
|
-
|
|
1007
|
+
cwd: string;
|
|
1007
1008
|
combinedProtectionMap: CombinedProtectionMapTarget;
|
|
1008
1009
|
artifactOptions?: AfterpackArtifactOptions;
|
|
1009
1010
|
hasBundlerSourcemap?: boolean;
|
|
@@ -1144,4 +1145,4 @@ declare function extractSourceMappingURL(code: string): string | null;
|
|
|
1144
1145
|
declare function decodeDataUri(url: string): string | null;
|
|
1145
1146
|
declare function discoverInputSourceMap(jsPath: string, code?: string): string | null;
|
|
1146
1147
|
//#endregion
|
|
1147
|
-
export { type AfterpackArtifactOptions, type AfterpackConfig, type AfterpackPluginOptions, AlreadyObfuscatedError, type ArtifactMode, type BuildContext, type BuildEngineConfigOptions, type BundleEntryLike, type BundleJs, CLOUD_REFUSAL_SUMMARY, CONFIG_FILE_NAME, CONFIG_KEYS, CORE_FLOOR_SUMMARY, type CapturedDirective, type CapturedModule, type CliParseResult, type ClientIdentity, CloudApiError, type CloudErrorKind, type CloudNotice, type CollectJsOptions, type CombinedProtectionMapTarget, type ConfigIssue, type ConfigKeyDef, type ConfigScope, type ConfigSurface, type ConfigTier, type CoreConfig, type CoreConfigSubset, CoreVersionError, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, type DiagnosticsSummary, type DiagnosticsVerbosity, type DirectiveDiagnostic, type DirectiveManifest, type EngineBatchResult, type EngineDiagnostic, type EngineDiagnosticData, type EngineFileInput, type EngineFileResult, type EngineSeverity, type EngineSpan, type EnvLike, type EnvParseResult, type GitBuildContext, type GlobReserved, type InMemoryInput, type InMemoryOutput, type LoadedConfigFile, type Logger, type NormalizedPluginOptions, type NoticeLogger, type NoticeSeverity, type ObfuscationEngine, type ObfuscationPassOptions, type ObfuscationPassResult, type OutputBundleLike, PROTECTION_RECEIPT_FILE, type PassMessages, type PassReceiptIdentity, type PassSettings, type PassTiming, type PluginConfigInput, type PluginOptionsView, type Preset, type ProtectionReceipt, type ProtectionReceiptFile, type ProtectionVerification, type RegionConfig, type ReportPolicy, type ReportPolicySignals, type ResolvedPluginConfig, SEED_ENV_VAR, type SafeNotice, type SeedOption, type SeedOrigin, type TelemetryContext, type TelemetryDiagnostic, type TelemetryDiagnosticData, type TelemetryFacts, type TelemetryPayload, type TelemetryReporter, type TelemetryReporterDeps, type TelemetrySeverity, type TelemetrySpan, type TransformKind, UnreadableReceiptError, type ValidationResult, type ValueShape, type ValueType, type WriteArtifactsInput, type WriteArtifactsResult, type WriteProtectionReceiptInput, applyBundleOutput, applyResolvedKey, collectBundleJs, collectJsFiles, collectSourceMaps, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
|
|
1148
|
+
export { type AfterpackArtifactOptions, type AfterpackConfig, type AfterpackPluginOptions, AlreadyObfuscatedError, type ArtifactMode, type BuildContext, type BuildEngineConfigOptions, type BundleEntryLike, type BundleJs, CLOUD_REFUSAL_SUMMARY, CONFIG_FILE_NAME, CONFIG_KEYS, CORE_FLOOR_SUMMARY, type CapturedDirective, type CapturedModule, type CliParseResult, type ClientIdentity, CloudApiError, type CloudErrorKind, type CloudNotice, type CollectJsOptions, type CombinedProtectionMapTarget, type ConfigIssue, type ConfigKeyDef, type ConfigScope, type ConfigSurface, type ConfigTier, type CoreConfig, type CoreConfigSubset, CoreVersionError, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, type DiagnosticsSummary, type DiagnosticsVerbosity, type DirectiveDiagnostic, type DirectiveManifest, type EngineBatchResult, type EngineDiagnostic, type EngineDiagnosticData, type EngineFileInput, type EngineFileResult, type EngineSeverity, type EngineSpan, type EnvLike, type EnvParseResult, type GitBuildContext, type GlobReserved, type InMemoryInput, type InMemoryOutput, type LoadedConfigFile, type Logger, type NormalizedPluginOptions, type NoticeLogger, type NoticeSeverity, type ObfuscationEngine, type ObfuscationPassOptions, type ObfuscationPassResult, type OutputBundleLike, PROTECTION_RECEIPT_FILE, type PassMessages, type PassReceiptIdentity, type PassSettings, type PassTiming, type PluginConfigInput, type PluginOptionsView, type Preset, type ProtectionReceipt, type ProtectionReceiptFile, type ProtectionVerification, type RegionConfig, type ReportPolicy, type ReportPolicySignals, type ResolvedPluginConfig, SEED_ENV_VAR, type SafeNotice, type SeedOption, type SeedOrigin, type TelemetryContext, type TelemetryDiagnostic, type TelemetryDiagnosticData, type TelemetryFacts, type TelemetryPayload, type TelemetryReporter, type TelemetryReporterDeps, type TelemetrySeverity, type TelemetrySpan, type TransformKind, UnreadableReceiptError, type ValidationResult, type ValueShape, type ValueType, type WriteArtifactsInput, type WriteArtifactsResult, type WriteProtectionReceiptInput, applyBundleOutput, applyResolvedKey, collectBundleJs, collectJsFiles, collectSourceMaps, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, ensureAfterpackGitignore, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
|
package/dist/index.js
CHANGED
|
@@ -41,15 +41,7 @@ function findUpward(startDir, fileName, options = {}) {
|
|
|
41
41
|
//#endregion
|
|
42
42
|
//#region src/artifacts.ts
|
|
43
43
|
const AFTERPACK_DIR = ".afterpack";
|
|
44
|
-
const
|
|
45
|
-
".afterpack/",
|
|
46
|
-
"*.protectionMap.html",
|
|
47
|
-
"protectionMap.html",
|
|
48
|
-
"*.backup.*",
|
|
49
|
-
"*.map"
|
|
50
|
-
];
|
|
51
|
-
const GITIGNORE_FILE = ".gitignore";
|
|
52
|
-
const GITIGNORE_BLOCK_HEADER = "# AfterPack artifacts (auto-added)";
|
|
44
|
+
const AFTERPACK_GITIGNORE_CONTENT = "*\n";
|
|
53
45
|
const PUBLIC_SEGMENTS = new Set([
|
|
54
46
|
"public",
|
|
55
47
|
"static",
|
|
@@ -102,8 +94,9 @@ function writeArtifacts(input) {
|
|
|
102
94
|
}
|
|
103
95
|
if (mode === "single" && policy.protectionMap && protectionMapJson != null) {
|
|
104
96
|
mkdirSync(afterpackDir, { recursive: true });
|
|
97
|
+
ensureAfterpackGitignore(afterpackDir);
|
|
105
98
|
const pmPath = join(afterpackDir, basename(paths.protectionMapPath));
|
|
106
|
-
if (policy.protectionMapInProd)
|
|
99
|
+
if (policy.protectionMapInProd) logProtectionMapInProd(pmPath, logger);
|
|
107
100
|
else logger.log(`[afterpack] wrote Protection Map -> ${pmPath} (gitignored; set protectionMap.enabled:false to skip)`);
|
|
108
101
|
const { html } = renderProtectionMapHtml(protectionMapJson);
|
|
109
102
|
writeFileSync(pmPath, html);
|
|
@@ -203,6 +196,96 @@ function spanKey(start, end, kind) {
|
|
|
203
196
|
if (packable(start, SPAN_PACK_LIMIT) && packable(end, SPAN_PACK_LIMIT) && packable(kind, 4)) return (start * SPAN_PACK_LIMIT + end) * 4 + kind;
|
|
204
197
|
return `${start},${end},${kind}`;
|
|
205
198
|
}
|
|
199
|
+
function sortTriples(flat) {
|
|
200
|
+
const count = flat.length / 3 | 0;
|
|
201
|
+
const order = new Uint32Array(count);
|
|
202
|
+
for (let i = 0; i < count; i++) order[i] = i;
|
|
203
|
+
order.sort((x, y) => {
|
|
204
|
+
const a = x * 3;
|
|
205
|
+
const b = y * 3;
|
|
206
|
+
return flat[a] - flat[b] || flat[a + 1] - flat[b + 1] || flat[a + 2] - flat[b + 2];
|
|
207
|
+
});
|
|
208
|
+
const out = new Array(count * 3);
|
|
209
|
+
for (let i = 0; i < count; i++) {
|
|
210
|
+
out[i * 3] = flat[order[i] * 3];
|
|
211
|
+
out[i * 3 + 1] = flat[order[i] * 3 + 1];
|
|
212
|
+
out[i * 3 + 2] = flat[order[i] * 3 + 2];
|
|
213
|
+
}
|
|
214
|
+
return out;
|
|
215
|
+
}
|
|
216
|
+
function mergeComplexitySpans(entries) {
|
|
217
|
+
const lowest = new Map();
|
|
218
|
+
for (const e of entries) {
|
|
219
|
+
const flat = e.complexitySpans ?? [];
|
|
220
|
+
for (let i = 0; i + 2 < flat.length; i += 3) {
|
|
221
|
+
const key = spanKey(flat[i], flat[i + 1], 0);
|
|
222
|
+
const seen = lowest.get(key);
|
|
223
|
+
if (!seen) lowest.set(key, [
|
|
224
|
+
flat[i],
|
|
225
|
+
flat[i + 1],
|
|
226
|
+
flat[i + 2]
|
|
227
|
+
]);
|
|
228
|
+
else if (flat[i + 2] < seen[2]) seen[2] = flat[i + 2];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
return sortTriples([...lowest.values()].flat());
|
|
232
|
+
}
|
|
233
|
+
function mergeKindOrder(tables) {
|
|
234
|
+
const next = new Map();
|
|
235
|
+
const inDegree = new Map();
|
|
236
|
+
for (const t of tables) for (const name of t) if (!next.has(name)) {
|
|
237
|
+
next.set(name, new Set());
|
|
238
|
+
inDegree.set(name, 0);
|
|
239
|
+
}
|
|
240
|
+
for (const t of tables) for (let i = 1; i < t.length; i++) {
|
|
241
|
+
const after = next.get(t[i - 1]);
|
|
242
|
+
if (t[i] === t[i - 1] || after.has(t[i])) continue;
|
|
243
|
+
after.add(t[i]);
|
|
244
|
+
inDegree.set(t[i], (inDegree.get(t[i]) ?? 0) + 1);
|
|
245
|
+
}
|
|
246
|
+
const order = [];
|
|
247
|
+
const ready = [...next.keys()].filter((n) => inDegree.get(n) === 0).sort();
|
|
248
|
+
while (ready.length) {
|
|
249
|
+
const name = ready.shift();
|
|
250
|
+
order.push(name);
|
|
251
|
+
for (const m of next.get(name)) {
|
|
252
|
+
const d = (inDegree.get(m) ?? 0) - 1;
|
|
253
|
+
inDegree.set(m, d);
|
|
254
|
+
if (d === 0) {
|
|
255
|
+
ready.push(m);
|
|
256
|
+
ready.sort();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
for (const name of [...next.keys()].sort()) if (!order.includes(name)) order.push(name);
|
|
261
|
+
return order;
|
|
262
|
+
}
|
|
263
|
+
function mergeDeclarationLane(entries) {
|
|
264
|
+
const tables = entries.map((e) => Array.isArray(e.declarationKinds) ? e.declarationKinds.filter((k) => typeof k === "string") : []);
|
|
265
|
+
const order = mergeKindOrder(tables);
|
|
266
|
+
const rank = new Map(order.map((name, i) => [name, i]));
|
|
267
|
+
const seen = new Set();
|
|
268
|
+
const flat = [];
|
|
269
|
+
for (const e of entries) {
|
|
270
|
+
const kinds = Array.isArray(e.declarationKinds) ? e.declarationKinds : [];
|
|
271
|
+
const spans = e.declarationSpans ?? [];
|
|
272
|
+
for (let i = 0; i + 2 < spans.length; i += 3) {
|
|
273
|
+
const k = rank.get(kinds[spans[i + 2]]);
|
|
274
|
+
if (k === void 0) continue;
|
|
275
|
+
const key = spanKey(spans[i], spans[i + 1], k);
|
|
276
|
+
if (seen.has(key)) continue;
|
|
277
|
+
seen.add(key);
|
|
278
|
+
flat.push(spans[i], spans[i + 1], k);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const used = [...new Set(flat.filter((_, i) => i % 3 === 2))].sort((a, b) => a - b);
|
|
282
|
+
const compact = new Map(used.map((k, i) => [k, i]));
|
|
283
|
+
for (let i = 2; i < flat.length; i += 3) flat[i] = compact.get(flat[i]);
|
|
284
|
+
return {
|
|
285
|
+
declarationKinds: used.map((k) => order[k]),
|
|
286
|
+
declarationSpans: sortTriples(flat)
|
|
287
|
+
};
|
|
288
|
+
}
|
|
206
289
|
function mergeEntries(entries, path) {
|
|
207
290
|
const regions = [];
|
|
208
291
|
const seenRegion = new Set();
|
|
@@ -251,21 +334,7 @@ function mergeEntries(entries, path) {
|
|
|
251
334
|
}
|
|
252
335
|
renamedSpans.sort((a, b) => a[0] - b[0] || a[1] - b[1]);
|
|
253
336
|
const extractedCount = extractedFlat.length / 3 | 0;
|
|
254
|
-
const
|
|
255
|
-
for (let i = 0; i < extractedCount; i++) order[i] = i;
|
|
256
|
-
order.sort((x, y) => {
|
|
257
|
-
const a = x * 3;
|
|
258
|
-
const b = y * 3;
|
|
259
|
-
return extractedFlat[a] - extractedFlat[b] || extractedFlat[a + 1] - extractedFlat[b + 1] || extractedFlat[a + 2] - extractedFlat[b + 2];
|
|
260
|
-
});
|
|
261
|
-
const extractedSpans = new Array(extractedCount * 3);
|
|
262
|
-
for (let i = 0; i < extractedCount; i++) {
|
|
263
|
-
const from = order[i] * 3;
|
|
264
|
-
const to = i * 3;
|
|
265
|
-
extractedSpans[to] = extractedFlat[from];
|
|
266
|
-
extractedSpans[to + 1] = extractedFlat[from + 1];
|
|
267
|
-
extractedSpans[to + 2] = extractedFlat[from + 2];
|
|
268
|
-
}
|
|
337
|
+
const extractedSpans = sortTriples(extractedFlat);
|
|
269
338
|
regions.sort((a, b) => {
|
|
270
339
|
const er = (b.entropyRaw ?? 0) - (a.entropyRaw ?? 0);
|
|
271
340
|
if (er !== 0) return er;
|
|
@@ -314,6 +383,8 @@ function mergeEntries(entries, path) {
|
|
|
314
383
|
spotlights,
|
|
315
384
|
renamedSpans,
|
|
316
385
|
extractedSpans,
|
|
386
|
+
...entries.some((e) => Array.isArray(e.complexitySpans)) ? { complexitySpans: mergeComplexitySpans(entries) } : {},
|
|
387
|
+
...entries.some((e) => Array.isArray(e.declarationSpans)) ? mergeDeclarationLane(entries) : {},
|
|
317
388
|
aggregate: computeAggregate(regions, spotlights, renamedSpans.length, directives, extractedCount)
|
|
318
389
|
};
|
|
319
390
|
}
|
|
@@ -357,8 +428,9 @@ function writeCombinedProtectionMap(input) {
|
|
|
357
428
|
const logger = input.logger ?? DEFAULT_LOGGER;
|
|
358
429
|
if (!policy.protectionMap || docs.length === 0) return null;
|
|
359
430
|
mkdirSync(afterpackDir, { recursive: true });
|
|
431
|
+
ensureAfterpackGitignore(afterpackDir);
|
|
360
432
|
const outPath = join(afterpackDir, input.fileName ?? basename(combinedProtectionMapPath(buildDir)));
|
|
361
|
-
if (policy.protectionMapInProd)
|
|
433
|
+
if (policy.protectionMapInProd) logProtectionMapInProd(outPath, logger);
|
|
362
434
|
else logger.log(`[afterpack] wrote Protection Map -> ${outPath} (gitignored; set protectionMap.enabled:false to skip)`);
|
|
363
435
|
const flat = docs.flatMap((doc) => {
|
|
364
436
|
if (!doc) return [];
|
|
@@ -376,28 +448,23 @@ function writeCombinedProtectionMap(input) {
|
|
|
376
448
|
writeFileSync(outPath, html);
|
|
377
449
|
return outPath;
|
|
378
450
|
}
|
|
379
|
-
function
|
|
380
|
-
|
|
451
|
+
function logProtectionMapInProd(pmPath, logger) {
|
|
452
|
+
const rel = relative(process.cwd(), pmPath);
|
|
453
|
+
const display = rel.startsWith("..") ? pmPath : rel;
|
|
454
|
+
logger.log(`[afterpack] Protection Map -> ${display} (local only, not deployed)`);
|
|
381
455
|
}
|
|
382
|
-
function
|
|
383
|
-
|
|
456
|
+
function afterpackRoot(dir) {
|
|
457
|
+
const resolved = resolve(dir);
|
|
458
|
+
const segments$1 = resolved.split(sep);
|
|
459
|
+
const index = segments$1.lastIndexOf(AFTERPACK_DIR);
|
|
460
|
+
return index === -1 ? resolved : segments$1.slice(0, index + 1).join(sep);
|
|
384
461
|
}
|
|
385
|
-
function
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
} catch {
|
|
392
|
-
existing = "";
|
|
393
|
-
}
|
|
394
|
-
const present = new Set(existing.split(/\r?\n/).map((l) => l.trim()));
|
|
395
|
-
const missing = GITIGNORE_ENTRIES.filter((e) => !present.has(e));
|
|
396
|
-
if (missing.length === 0) return [];
|
|
397
|
-
const prefix = existing.length > 0 && !existing.endsWith("\n") ? "\n" : "";
|
|
398
|
-
const block = `${prefix}\n${GITIGNORE_BLOCK_HEADER}\n${missing.join("\n")}\n`;
|
|
399
|
-
writeFileSync(gitignorePath, existing + block);
|
|
400
|
-
return missing;
|
|
462
|
+
function ensureAfterpackGitignore(afterpackDir) {
|
|
463
|
+
const root = afterpackRoot(afterpackDir);
|
|
464
|
+
const gitignorePath = join(root, ".gitignore");
|
|
465
|
+
if (existsSync(gitignorePath)) return;
|
|
466
|
+
mkdirSync(root, { recursive: true });
|
|
467
|
+
writeFileSync(gitignorePath, AFTERPACK_GITIGNORE_CONTENT);
|
|
401
468
|
}
|
|
402
469
|
function warnIfPublicPath(artifactPath, logger = DEFAULT_LOGGER) {
|
|
403
470
|
const segments$1 = artifactPath.split(/[\\/]/).filter(Boolean);
|
|
@@ -866,7 +933,7 @@ const CONFIG_KEYS = [
|
|
|
866
933
|
kind: "number",
|
|
867
934
|
min: 0
|
|
868
935
|
},
|
|
869
|
-
default: "the preset's value; light is
|
|
936
|
+
default: "the preset's value; light is 5",
|
|
870
937
|
namedValuesOf: "preset"
|
|
871
938
|
},
|
|
872
939
|
{
|
|
@@ -880,7 +947,7 @@ const CONFIG_KEYS = [
|
|
|
880
947
|
min: 0,
|
|
881
948
|
unlimited: UNLIMITED
|
|
882
949
|
},
|
|
883
|
-
default: "
|
|
950
|
+
default: "unset"
|
|
884
951
|
},
|
|
885
952
|
{
|
|
886
953
|
path: "strings.encode",
|
|
@@ -1590,7 +1657,7 @@ function toPluginOptions(config) {
|
|
|
1590
1657
|
|
|
1591
1658
|
//#endregion
|
|
1592
1659
|
//#region src/compat.ts
|
|
1593
|
-
const MIN_CORE_VERSION = "0.
|
|
1660
|
+
const MIN_CORE_VERSION = "0.2.0";
|
|
1594
1661
|
const CORE_PACKAGE = "@afterpack/core";
|
|
1595
1662
|
const VERSION_PATTERN$1 = /^\d{1,9}\.\d{1,9}\.\d{1,9}(?:[-+][0-9A-Za-z.+-]{1,64})?$/;
|
|
1596
1663
|
const PACKAGE_NAME_PATTERN = /^(?:@[a-z0-9][a-z0-9._-]{0,63}\/)?[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
@@ -2293,7 +2360,8 @@ function detectProduction(env = {}, opts = {}) {
|
|
|
2293
2360
|
function resolveReportPolicy(env = {}, userOpts = {}, signals = {}) {
|
|
2294
2361
|
const isProduction = detectProduction(env, userOpts);
|
|
2295
2362
|
const hasBundlerSourcemap = signals.hasBundlerSourcemap ?? false;
|
|
2296
|
-
const
|
|
2363
|
+
const isCI = env.CI === "true" || env.CI === "1";
|
|
2364
|
+
const protectionMap = userOpts.protectionMap?.enabled ?? (hasBundlerSourcemap && !isCI);
|
|
2297
2365
|
const autoEnableBundlerSourcemap = userOpts.protectionMap?.enabled === true && !hasBundlerSourcemap;
|
|
2298
2366
|
const emitSourceMappingURL = userOpts.sourceMap?.emitUrl ?? !isProduction;
|
|
2299
2367
|
const backup = userOpts.build?.backup ?? !signals.inPlaceOutput;
|
|
@@ -2319,15 +2387,12 @@ const DEFAULT_PRESET = "light";
|
|
|
2319
2387
|
function presetTarget(preset) {
|
|
2320
2388
|
switch (preset) {
|
|
2321
2389
|
case "minify": return 0;
|
|
2322
|
-
case "light": return
|
|
2323
|
-
case "medium": return
|
|
2324
|
-
case "hard": return
|
|
2325
|
-
case "extreme": return
|
|
2390
|
+
case "light": return 5;
|
|
2391
|
+
case "medium": return 7;
|
|
2392
|
+
case "hard": return 12;
|
|
2393
|
+
case "extreme": return 25;
|
|
2326
2394
|
}
|
|
2327
2395
|
}
|
|
2328
|
-
function effectiveComplexityTarget(preset, complexity) {
|
|
2329
|
-
return complexity ?? presetTarget(preset ?? DEFAULT_PRESET);
|
|
2330
|
-
}
|
|
2331
2396
|
function buildEngineConfig(options) {
|
|
2332
2397
|
const { filePath, policy, seed = 0, engine } = options;
|
|
2333
2398
|
const perFileMap = "inputSourceMap" in options;
|
|
@@ -2337,9 +2402,9 @@ function buildEngineConfig(options) {
|
|
|
2337
2402
|
const sourceMap = { sourcesContent };
|
|
2338
2403
|
if (smEnabled !== void 0) sourceMap.enabled = smEnabled;
|
|
2339
2404
|
const defaults = {};
|
|
2340
|
-
|
|
2405
|
+
if (options.complexity !== void 0) defaults.complexity = options.complexity;
|
|
2341
2406
|
if (options.preset !== void 0) defaults.preset = options.preset;
|
|
2342
|
-
if (options.
|
|
2407
|
+
else if (options.complexity === void 0) defaults.preset = DEFAULT_PRESET;
|
|
2343
2408
|
const config = mergeInto({
|
|
2344
2409
|
...defaults,
|
|
2345
2410
|
sourceMap,
|
|
@@ -3765,7 +3830,7 @@ function describeLevel(preset, complexity) {
|
|
|
3765
3830
|
async function runObfuscationPass(options) {
|
|
3766
3831
|
const passStartedAt = options.startedAt ?? Date.now();
|
|
3767
3832
|
const callerAnchored = options.startedAt !== void 0;
|
|
3768
|
-
const { files, engine, label,
|
|
3833
|
+
const { files, engine, label, cwd, combinedProtectionMap, artifactOptions = {}, env = process.env } = options;
|
|
3769
3834
|
const logger = silenceSummaryLines(options.logger ?? DEFAULT_LOGGER, options.diagnostics);
|
|
3770
3835
|
const prefix = (message) => `[${label}] ${message}`;
|
|
3771
3836
|
const style = options.summaryStyle ?? "plugin";
|
|
@@ -3781,7 +3846,7 @@ async function runObfuscationPass(options) {
|
|
|
3781
3846
|
})), already.files, already.receiptPath, combinedProtectionMap.buildDir);
|
|
3782
3847
|
}
|
|
3783
3848
|
const resolvedSeed = resolveBuildSeed(options.seed, {
|
|
3784
|
-
root:
|
|
3849
|
+
root: cwd,
|
|
3785
3850
|
leg: options.buildLeg ?? combinedProtectionMap.buildDir
|
|
3786
3851
|
}, {
|
|
3787
3852
|
env,
|
|
@@ -3856,7 +3921,6 @@ async function runObfuscationPass(options) {
|
|
|
3856
3921
|
hasBundlerSourcemap,
|
|
3857
3922
|
inPlaceOutput: true
|
|
3858
3923
|
});
|
|
3859
|
-
ensureGitignore(combinedProtectionMap.buildDir);
|
|
3860
3924
|
if (policy.autoEnableBundlerSourcemap && options.messages?.autoEnableBundlerSourcemap) logger.warn(prefix(options.messages.autoEnableBundlerSourcemap));
|
|
3861
3925
|
if (options.emitToCaller && artifactOptions.build?.backup === true) logger.warn(prefix("build.backup:true is not available on this build — the obfuscated output is handed back in memory, so there is no emitted file for a `.backup.<hash>` copy to sit beside."));
|
|
3862
3926
|
const capture = captureDirectiveRegions(inputs, options.regions, directivesEnabled && !bundledCapture && !(postMinifyMode && inputs.length > 1));
|
|
@@ -3880,7 +3944,7 @@ async function runObfuscationPass(options) {
|
|
|
3880
3944
|
if (policy.protectionMap && files.length > 0 && mappedInputs > 0 && mappedInputs < files.length) logger.warn(prefix(`source-map coverage: ${mappedInputs}/${files.length} chunk(s) had a discoverable input source map — the other ${files.length - mappedInputs} are attributed only as opaque dist chunks, so the Protection Map under-reports their original sources.`));
|
|
3881
3945
|
const git = artifactOptions.git === false ? null : detectGitContext(artifactOptions.git ?? null, {
|
|
3882
3946
|
env,
|
|
3883
|
-
cwd
|
|
3947
|
+
cwd
|
|
3884
3948
|
});
|
|
3885
3949
|
const engineConfig = buildEngineConfig({
|
|
3886
3950
|
policy,
|
|
@@ -3928,7 +3992,7 @@ async function runObfuscationPass(options) {
|
|
|
3928
3992
|
if (telemetry && telemetryEnabled) {
|
|
3929
3993
|
const facts = {
|
|
3930
3994
|
label,
|
|
3931
|
-
projectRoot:
|
|
3995
|
+
projectRoot: cwd,
|
|
3932
3996
|
diagnostics: collected.diagnostics,
|
|
3933
3997
|
fileCount: files.length,
|
|
3934
3998
|
durationMs: engineEndedAt - passStartedAt,
|
|
@@ -4243,4 +4307,4 @@ function resolvePluginConfig(input) {
|
|
|
4243
4307
|
}
|
|
4244
4308
|
|
|
4245
4309
|
//#endregion
|
|
4246
|
-
export { AlreadyObfuscatedError, CLOUD_REFUSAL_SUMMARY, CONFIG_FILE_NAME, CONFIG_KEYS, CORE_FLOOR_SUMMARY, CloudApiError, CoreVersionError, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, PROTECTION_RECEIPT_FILE, SEED_ENV_VAR, UnreadableReceiptError, applyBundleOutput, applyResolvedKey, collectBundleJs, collectJsFiles, collectSourceMaps, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
|
|
4310
|
+
export { AlreadyObfuscatedError, CLOUD_REFUSAL_SUMMARY, CONFIG_FILE_NAME, CONFIG_KEYS, CORE_FLOOR_SUMMARY, CloudApiError, CoreVersionError, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, PROTECTION_RECEIPT_FILE, SEED_ENV_VAR, UnreadableReceiptError, applyBundleOutput, applyResolvedKey, collectBundleJs, collectJsFiles, collectSourceMaps, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, ensureAfterpackGitignore, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@afterpack/integration-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0-rc.20260930T1421",
|
|
4
4
|
"description": "Internal shared code for the AfterPack CLI and framework plugins",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@jridgewell/sourcemap-codec": "^1.5.5",
|
|
29
|
-
"@afterpack/protection-map": "0.
|
|
29
|
+
"@afterpack/protection-map": "0.2.0-rc.20260930T1421"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@biomejs/biome": "2.4.4",
|