@afterpack/integration-utils 0.2.1 → 0.2.3
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 +821 -796
- package/dist/index.d.cts +20 -13
- package/dist/index.d.ts +20 -13
- package/dist/index.js +820 -797
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -474,418 +474,6 @@ function warnIfPublicPath(artifactPath, logger = DEFAULT_LOGGER) {
|
|
|
474
474
|
return true;
|
|
475
475
|
}
|
|
476
476
|
|
|
477
|
-
//#endregion
|
|
478
|
-
//#region src/source-map.ts
|
|
479
|
-
const SOURCE_MAPPING_URL_RE = /\/\/[#@]\s*sourceMappingURL=(\S+)\s*$/gm;
|
|
480
|
-
const SOURCE_MAPPING_URL_LINE_RE = /^[ \t]*\/\/[#@]\s*sourceMappingURL=\S+[ \t]*\r?\n?/gm;
|
|
481
|
-
const CSS_SOURCE_MAPPING_URL_RE = /[ \t]*\/\*[#@]\s*sourceMappingURL=[^\s*]+\s*\*\/\s*$/;
|
|
482
|
-
function withSourceMappingURL(code, url) {
|
|
483
|
-
const stripped = code.replace(SOURCE_MAPPING_URL_LINE_RE, "");
|
|
484
|
-
if (url == null) return stripped;
|
|
485
|
-
const separator = stripped.length > 0 && !stripped.endsWith("\n") ? "\n" : "";
|
|
486
|
-
return `${stripped}${separator}//# sourceMappingURL=${url}\n`;
|
|
487
|
-
}
|
|
488
|
-
function withoutCssSourceMappingURL(css) {
|
|
489
|
-
return css.replace(CSS_SOURCE_MAPPING_URL_RE, "");
|
|
490
|
-
}
|
|
491
|
-
function extractSourceMappingURL(code) {
|
|
492
|
-
let last = null;
|
|
493
|
-
for (const match of code.matchAll(SOURCE_MAPPING_URL_RE)) last = match[1];
|
|
494
|
-
return last;
|
|
495
|
-
}
|
|
496
|
-
function isRemoteSourceMappingURL(url) {
|
|
497
|
-
return /^https?:\/\//i.test(url) || url.startsWith("//");
|
|
498
|
-
}
|
|
499
|
-
function decodeDataUri(url) {
|
|
500
|
-
if (!url.startsWith("data:")) return null;
|
|
501
|
-
const comma = url.indexOf(",");
|
|
502
|
-
if (comma === -1) return null;
|
|
503
|
-
const meta = url.slice(5, comma);
|
|
504
|
-
const payload = url.slice(comma + 1);
|
|
505
|
-
try {
|
|
506
|
-
if (/;base64/i.test(meta)) return Buffer.from(payload, "base64").toString("utf8");
|
|
507
|
-
return decodeURIComponent(payload);
|
|
508
|
-
} catch {
|
|
509
|
-
return null;
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
function discoverInputSourceMap(jsPath, code) {
|
|
513
|
-
const adjacent = `${jsPath}.map`;
|
|
514
|
-
if (existsSync(adjacent)) try {
|
|
515
|
-
return readFileSync(adjacent, "utf8");
|
|
516
|
-
} catch {}
|
|
517
|
-
let source = code;
|
|
518
|
-
if (source == null) try {
|
|
519
|
-
source = readFileSync(jsPath, "utf8");
|
|
520
|
-
} catch {
|
|
521
|
-
return null;
|
|
522
|
-
}
|
|
523
|
-
const url = extractSourceMappingURL(source);
|
|
524
|
-
if (url == null) return null;
|
|
525
|
-
if (url.startsWith("data:")) return decodeDataUri(url);
|
|
526
|
-
if (isRemoteSourceMappingURL(url)) return null;
|
|
527
|
-
let mapPath;
|
|
528
|
-
try {
|
|
529
|
-
mapPath = isAbsolute(url) ? url : resolve(dirname(jsPath), decodeURIComponent(url));
|
|
530
|
-
} catch {
|
|
531
|
-
return null;
|
|
532
|
-
}
|
|
533
|
-
if (!existsSync(mapPath)) return null;
|
|
534
|
-
try {
|
|
535
|
-
return readFileSync(mapPath, "utf8");
|
|
536
|
-
} catch {
|
|
537
|
-
return null;
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
|
|
541
|
-
//#endregion
|
|
542
|
-
//#region src/bundle.ts
|
|
543
|
-
const BUNDLE_JS_RE = /\.[cm]?js$/;
|
|
544
|
-
const CSS_MAP_RE = /\.css\.map$/;
|
|
545
|
-
function collectBundleJs(bundle, outDir) {
|
|
546
|
-
const files = [];
|
|
547
|
-
const inputs = new Map();
|
|
548
|
-
const entries = new Map();
|
|
549
|
-
for (const [fileName, entry] of Object.entries(bundle)) {
|
|
550
|
-
if (!BUNDLE_JS_RE.test(fileName)) continue;
|
|
551
|
-
const source = entry.type === "chunk" ? entry.code : typeof entry.source === "string" ? entry.source : void 0;
|
|
552
|
-
if (source === void 0) continue;
|
|
553
|
-
const filePath = resolve(outDir, fileName);
|
|
554
|
-
files.push(filePath);
|
|
555
|
-
entries.set(filePath, entry);
|
|
556
|
-
inputs.set(filePath, {
|
|
557
|
-
source,
|
|
558
|
-
sourceMap: entry.map ? entry.map.toString() : null
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
return {
|
|
562
|
-
files,
|
|
563
|
-
inputs,
|
|
564
|
-
entries
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
function dataUri(json) {
|
|
568
|
-
return `data:application/json;charset=utf-8;base64,${Buffer.from(json, "utf8").toString("base64")}`;
|
|
569
|
-
}
|
|
570
|
-
function applyBundleOutput(bundle, entry, out, policy) {
|
|
571
|
-
if (entry.type !== "chunk") {
|
|
572
|
-
entry.source = out.code;
|
|
573
|
-
return;
|
|
574
|
-
}
|
|
575
|
-
const mapName = entry.sourcemapFileName ?? null;
|
|
576
|
-
const inlineMap = mapName == null && entry.map != null;
|
|
577
|
-
const emitMap = policy.sourceMap && out.sourceMap != null;
|
|
578
|
-
let url = null;
|
|
579
|
-
if (emitMap && out.sourceMap != null) {
|
|
580
|
-
if (mapName != null && bundle[mapName]) {
|
|
581
|
-
bundle[mapName].source = out.sourceMap;
|
|
582
|
-
url = basename(mapName);
|
|
583
|
-
} else if (inlineMap) url = dataUri(out.sourceMap);
|
|
584
|
-
} else {
|
|
585
|
-
if (mapName != null) delete bundle[mapName];
|
|
586
|
-
entry.map = null;
|
|
587
|
-
}
|
|
588
|
-
entry.code = withSourceMappingURL(out.code, policy.emitSourceMappingURL ? url : null);
|
|
589
|
-
}
|
|
590
|
-
function stripBundleCssSourceMaps(bundle) {
|
|
591
|
-
for (const [fileName, entry] of Object.entries(bundle)) {
|
|
592
|
-
if (CSS_MAP_RE.test(fileName)) {
|
|
593
|
-
delete bundle[fileName];
|
|
594
|
-
continue;
|
|
595
|
-
}
|
|
596
|
-
if (entry.type !== "asset" || !fileName.endsWith(".css") || entry.source === void 0) continue;
|
|
597
|
-
const css = typeof entry.source === "string" ? entry.source : Buffer.from(entry.source).toString("utf8");
|
|
598
|
-
const stripped = withoutCssSourceMappingURL(css);
|
|
599
|
-
if (stripped !== css) entry.source = stripped;
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
//#endregion
|
|
604
|
-
//#region src/glob.ts
|
|
605
|
-
function normalize(value) {
|
|
606
|
-
return value.includes("\\") ? value.replaceAll("\\", "/") : value;
|
|
607
|
-
}
|
|
608
|
-
function segments(value) {
|
|
609
|
-
return value.split("/").filter((part) => part !== "");
|
|
610
|
-
}
|
|
611
|
-
function isAnchored(pattern) {
|
|
612
|
-
if (pattern.startsWith("/")) return true;
|
|
613
|
-
return pattern.length >= 2 && pattern[1] === ":" && /^[A-Za-z]$/.test(pattern[0]);
|
|
614
|
-
}
|
|
615
|
-
function segmentMatches(pattern, seg) {
|
|
616
|
-
if (!pattern.includes("*") && !pattern.includes("?")) return pattern === seg;
|
|
617
|
-
const p = [...pattern];
|
|
618
|
-
const s = [...seg];
|
|
619
|
-
let pi = 0;
|
|
620
|
-
let si = 0;
|
|
621
|
-
let star = -1;
|
|
622
|
-
let starSi = 0;
|
|
623
|
-
while (si < s.length) if (pi < p.length && p[pi] === "*") {
|
|
624
|
-
star = pi;
|
|
625
|
-
starSi = si;
|
|
626
|
-
pi += 1;
|
|
627
|
-
} else if (pi < p.length && (p[pi] === "?" || p[pi] === s[si])) {
|
|
628
|
-
pi += 1;
|
|
629
|
-
si += 1;
|
|
630
|
-
} else if (star >= 0) {
|
|
631
|
-
pi = star + 1;
|
|
632
|
-
starSi += 1;
|
|
633
|
-
si = starSi;
|
|
634
|
-
} else return false;
|
|
635
|
-
return p.slice(pi).every((c) => c === "*");
|
|
636
|
-
}
|
|
637
|
-
function segmentsMatch(pattern, path) {
|
|
638
|
-
let pi = 0;
|
|
639
|
-
let si = 0;
|
|
640
|
-
let star = -1;
|
|
641
|
-
let starSi = 0;
|
|
642
|
-
while (si < path.length) if (pi < pattern.length && pattern[pi] === "**") {
|
|
643
|
-
star = pi;
|
|
644
|
-
starSi = si;
|
|
645
|
-
pi += 1;
|
|
646
|
-
} else if (pi < pattern.length && segmentMatches(pattern[pi], path[si])) {
|
|
647
|
-
pi += 1;
|
|
648
|
-
si += 1;
|
|
649
|
-
} else if (star >= 0) {
|
|
650
|
-
pi = star + 1;
|
|
651
|
-
starSi += 1;
|
|
652
|
-
si = starSi;
|
|
653
|
-
} else return false;
|
|
654
|
-
return pattern.slice(pi).every((s) => s === "**");
|
|
655
|
-
}
|
|
656
|
-
function matchesPath(pattern, path) {
|
|
657
|
-
const pat = normalize(pattern);
|
|
658
|
-
const parts = segments(pat);
|
|
659
|
-
if (parts.length === 0) return false;
|
|
660
|
-
const segs = segments(normalize(path));
|
|
661
|
-
if (isAnchored(pat)) return segmentsMatch(parts, segs);
|
|
662
|
-
for (let i = 0; i <= segs.length; i++) if (segmentsMatch(parts, segs.slice(i))) return true;
|
|
663
|
-
return false;
|
|
664
|
-
}
|
|
665
|
-
function reachesInto(pattern, dir) {
|
|
666
|
-
const pat = normalize(pattern);
|
|
667
|
-
const parts = segments(pat);
|
|
668
|
-
if (parts.length === 0) return false;
|
|
669
|
-
if (!isAnchored(pat)) return true;
|
|
670
|
-
for (let k = 1; k <= parts.length; k++) if (matchesPath(`/${parts.slice(0, k).join("/")}`, dir)) return true;
|
|
671
|
-
return false;
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
//#endregion
|
|
675
|
-
//#region src/collect.ts
|
|
676
|
-
const BACKUP_RE = /\.backup\.[0-9a-f]{8}\.[cm]?js$/;
|
|
677
|
-
const NODE_MODULES = "node_modules";
|
|
678
|
-
function isCollectableJs(name) {
|
|
679
|
-
if (BACKUP_RE.test(name)) return false;
|
|
680
|
-
return name.endsWith(".js") || name.endsWith(".mjs") || name.endsWith(".cjs");
|
|
681
|
-
}
|
|
682
|
-
function statOrNull(path) {
|
|
683
|
-
try {
|
|
684
|
-
return statSync(path);
|
|
685
|
-
} catch {
|
|
686
|
-
return null;
|
|
687
|
-
}
|
|
688
|
-
}
|
|
689
|
-
function collectJsFiles(target, options = {}) {
|
|
690
|
-
const stat = statOrNull(target);
|
|
691
|
-
if (!stat) return [];
|
|
692
|
-
if (!stat.isDirectory()) return isCollectableJs(basename(target)) ? [target] : [];
|
|
693
|
-
return walkJs(target, options.include ?? [], false, options.onNestedProject);
|
|
694
|
-
}
|
|
695
|
-
function entriesOf(dir) {
|
|
696
|
-
try {
|
|
697
|
-
return readdirSync(dir, { withFileTypes: true });
|
|
698
|
-
} catch {
|
|
699
|
-
return [];
|
|
700
|
-
}
|
|
701
|
-
}
|
|
702
|
-
function kindOf(entry, full) {
|
|
703
|
-
if (entry.isDirectory()) return "dir";
|
|
704
|
-
if (entry.isFile()) return "file";
|
|
705
|
-
const stat = statOrNull(full);
|
|
706
|
-
if (!stat) return null;
|
|
707
|
-
return stat.isDirectory() ? "dir" : "file";
|
|
708
|
-
}
|
|
709
|
-
function isNestedProject(dir) {
|
|
710
|
-
return existsSync(join(dir, "package.json"));
|
|
711
|
-
}
|
|
712
|
-
function walkJs(dir, include, readmitted, onNestedProject) {
|
|
713
|
-
const out = [];
|
|
714
|
-
for (const entry of entriesOf(dir)) {
|
|
715
|
-
const name = entry.name;
|
|
716
|
-
const full = join(dir, name);
|
|
717
|
-
const kind = kindOf(entry, full);
|
|
718
|
-
if (kind === null) continue;
|
|
719
|
-
if (kind === "dir") {
|
|
720
|
-
const skipped = name === NODE_MODULES;
|
|
721
|
-
if (!skipped && !readmitted && isNestedProject(full)) {
|
|
722
|
-
onNestedProject?.(full);
|
|
723
|
-
continue;
|
|
724
|
-
}
|
|
725
|
-
if (skipped && !include.some((pattern) => reachesInto(pattern, full))) continue;
|
|
726
|
-
out.push(...walkJs(full, include, readmitted || skipped, onNestedProject));
|
|
727
|
-
} else if (isCollectableJs(name)) {
|
|
728
|
-
if (readmitted && !include.some((pattern) => matchesPath(pattern, full))) continue;
|
|
729
|
-
out.push(full);
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
return out;
|
|
733
|
-
}
|
|
734
|
-
const SOURCE_MAP_RE = /\.(?:[cm]?js|css)\.map$/;
|
|
735
|
-
function collectFiles(dir, accept) {
|
|
736
|
-
if (!existsSync(dir)) return [];
|
|
737
|
-
const out = [];
|
|
738
|
-
for (const entry of entriesOf(dir)) {
|
|
739
|
-
const name = entry.name;
|
|
740
|
-
const full = join(dir, name);
|
|
741
|
-
const kind = kindOf(entry, full);
|
|
742
|
-
if (kind === null) continue;
|
|
743
|
-
if (kind === "dir") out.push(...collectFiles(full, accept));
|
|
744
|
-
else if (accept(name)) out.push(full);
|
|
745
|
-
}
|
|
746
|
-
return out;
|
|
747
|
-
}
|
|
748
|
-
function collectSourceMaps(dir) {
|
|
749
|
-
return collectFiles(dir, (name) => SOURCE_MAP_RE.test(name));
|
|
750
|
-
}
|
|
751
|
-
function collectStylesheets(dir) {
|
|
752
|
-
return collectFiles(dir, (name) => name.endsWith(".css"));
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
//#endregion
|
|
756
|
-
//#region src/notices.ts
|
|
757
|
-
const NOTICE_MESSAGE_LIMIT = 500;
|
|
758
|
-
const NOTICE_LIMIT = 5;
|
|
759
|
-
const NOTICE_CODE_LIMIT = 64;
|
|
760
|
-
const NOTICE_HOSTS = new Set(["afterpack.dev", "www.afterpack.dev"]);
|
|
761
|
-
const ESC = 27;
|
|
762
|
-
const BEL = 7;
|
|
763
|
-
const C1_CSI = 155;
|
|
764
|
-
const C1_OSC = 157;
|
|
765
|
-
function isControl(code) {
|
|
766
|
-
return code < 32 || code >= 127 && code <= 159;
|
|
767
|
-
}
|
|
768
|
-
function isInvisibleFormat(code) {
|
|
769
|
-
return code === 1564 || code >= 8203 && code <= 8207 || code >= 8234 && code <= 8238 || code >= 8288 && code <= 8297 || code === 65279;
|
|
770
|
-
}
|
|
771
|
-
function skipCsi(text, from) {
|
|
772
|
-
let i = from;
|
|
773
|
-
while (i < text.length) {
|
|
774
|
-
const c = text.charCodeAt(i);
|
|
775
|
-
i += 1;
|
|
776
|
-
if (c >= 64 && c <= 126) return i;
|
|
777
|
-
}
|
|
778
|
-
return i;
|
|
779
|
-
}
|
|
780
|
-
function skipOsc(text, from) {
|
|
781
|
-
let i = from;
|
|
782
|
-
while (i < text.length) {
|
|
783
|
-
const c = text.charCodeAt(i);
|
|
784
|
-
if (c === BEL) return i + 1;
|
|
785
|
-
if (c === ESC) return text.charCodeAt(i + 1) === 92 ? i + 2 : i + 1;
|
|
786
|
-
if (c === 156) return i + 1;
|
|
787
|
-
i += 1;
|
|
788
|
-
}
|
|
789
|
-
return i;
|
|
790
|
-
}
|
|
791
|
-
function stripTerminalControls(text) {
|
|
792
|
-
let out = "";
|
|
793
|
-
let i = 0;
|
|
794
|
-
while (i < text.length) {
|
|
795
|
-
const c = text.charCodeAt(i);
|
|
796
|
-
if (c === ESC) {
|
|
797
|
-
const next = text.charCodeAt(i + 1);
|
|
798
|
-
if (next === 91) i = skipCsi(text, i + 2);
|
|
799
|
-
else if (next === 93) i = skipOsc(text, i + 2);
|
|
800
|
-
else i += Number.isNaN(next) ? 1 : 2;
|
|
801
|
-
continue;
|
|
802
|
-
}
|
|
803
|
-
if (c === C1_CSI) {
|
|
804
|
-
i = skipCsi(text, i + 1);
|
|
805
|
-
continue;
|
|
806
|
-
}
|
|
807
|
-
if (c === C1_OSC) {
|
|
808
|
-
i = skipOsc(text, i + 1);
|
|
809
|
-
continue;
|
|
810
|
-
}
|
|
811
|
-
if (isControl(c)) {
|
|
812
|
-
out += c === 9 || c === 10 || c === 13 ? " " : "";
|
|
813
|
-
i += 1;
|
|
814
|
-
continue;
|
|
815
|
-
}
|
|
816
|
-
if (c === 8232 || c === 8233) {
|
|
817
|
-
out += " ";
|
|
818
|
-
i += 1;
|
|
819
|
-
continue;
|
|
820
|
-
}
|
|
821
|
-
if (isInvisibleFormat(c)) {
|
|
822
|
-
i += 1;
|
|
823
|
-
continue;
|
|
824
|
-
}
|
|
825
|
-
out += text[i];
|
|
826
|
-
i += 1;
|
|
827
|
-
}
|
|
828
|
-
return out;
|
|
829
|
-
}
|
|
830
|
-
function sanitizeServerText(value, limit = NOTICE_MESSAGE_LIMIT) {
|
|
831
|
-
if (typeof value !== "string") return "";
|
|
832
|
-
const clean = stripTerminalControls(value).replace(/\s+/g, " ").trim();
|
|
833
|
-
if (clean.length <= limit) return clean;
|
|
834
|
-
const chars = Array.from(clean);
|
|
835
|
-
return chars.length > limit ? chars.slice(0, limit).join("") : clean;
|
|
836
|
-
}
|
|
837
|
-
function sanitizeNoticeUrl(value) {
|
|
838
|
-
if (typeof value !== "string") return null;
|
|
839
|
-
let url;
|
|
840
|
-
try {
|
|
841
|
-
url = new URL(value.trim());
|
|
842
|
-
} catch {
|
|
843
|
-
return null;
|
|
844
|
-
}
|
|
845
|
-
if (url.protocol !== "https:") return null;
|
|
846
|
-
if (!NOTICE_HOSTS.has(url.hostname) || url.port !== "") return null;
|
|
847
|
-
if (url.username !== "" || url.password !== "") return null;
|
|
848
|
-
const href = url.href;
|
|
849
|
-
return href.length <= NOTICE_MESSAGE_LIMIT ? href : null;
|
|
850
|
-
}
|
|
851
|
-
function noticeSeverity(value) {
|
|
852
|
-
if (value === "info") return "info";
|
|
853
|
-
if (value === "error" || value === "critical") return "error";
|
|
854
|
-
return "warning";
|
|
855
|
-
}
|
|
856
|
-
function sanitizeNotices(raw) {
|
|
857
|
-
if (!Array.isArray(raw)) return [];
|
|
858
|
-
const out = [];
|
|
859
|
-
for (const entry of raw) {
|
|
860
|
-
if (out.length >= NOTICE_LIMIT) break;
|
|
861
|
-
if (typeof entry !== "object" || entry === null) continue;
|
|
862
|
-
const n = entry;
|
|
863
|
-
const message = sanitizeServerText(n.message);
|
|
864
|
-
if (message === "") continue;
|
|
865
|
-
out.push({
|
|
866
|
-
severity: noticeSeverity(n.severity),
|
|
867
|
-
code: sanitizeServerText(n.code, NOTICE_CODE_LIMIT),
|
|
868
|
-
message,
|
|
869
|
-
url: sanitizeNoticeUrl(n.url)
|
|
870
|
-
});
|
|
871
|
-
}
|
|
872
|
-
return out;
|
|
873
|
-
}
|
|
874
|
-
function formatNotice(notice) {
|
|
875
|
-
const head = notice.severity === "info" ? "AfterPack notice" : `AfterPack ${notice.severity}`;
|
|
876
|
-
const tail = notice.url ? ` ${notice.url}` : "";
|
|
877
|
-
return `${head}: ${notice.message}${tail}`;
|
|
878
|
-
}
|
|
879
|
-
function reportNotices(raw, logger, prefix = (m) => m) {
|
|
880
|
-
const notices = sanitizeNotices(raw);
|
|
881
|
-
for (const notice of notices) {
|
|
882
|
-
const line = prefix(formatNotice(notice));
|
|
883
|
-
if (notice.severity === "info" || !logger.warn) logger.log(line);
|
|
884
|
-
else logger.warn(line);
|
|
885
|
-
}
|
|
886
|
-
return notices;
|
|
887
|
-
}
|
|
888
|
-
|
|
889
477
|
//#endregion
|
|
890
478
|
//#region src/registry.ts
|
|
891
479
|
const PRESET_VALUES = [
|
|
@@ -895,6 +483,20 @@ const PRESET_VALUES = [
|
|
|
895
483
|
"hard",
|
|
896
484
|
"extreme"
|
|
897
485
|
];
|
|
486
|
+
const SOURCE_TYPE_VALUES = [
|
|
487
|
+
"auto",
|
|
488
|
+
"module",
|
|
489
|
+
"script"
|
|
490
|
+
];
|
|
491
|
+
const MODULE_OUTPUT_FORMATS = new Set([
|
|
492
|
+
"es",
|
|
493
|
+
"esm",
|
|
494
|
+
"esmodule",
|
|
495
|
+
"module"
|
|
496
|
+
]);
|
|
497
|
+
function sourceTypeForOutputFormat(format) {
|
|
498
|
+
return typeof format === "string" && MODULE_OUTPUT_FORMATS.has(format.toLowerCase()) ? "module" : void 0;
|
|
499
|
+
}
|
|
898
500
|
const TRANSFORM_KIND_VALUES = [
|
|
899
501
|
"stringEncoding",
|
|
900
502
|
"controlFlowFlatten",
|
|
@@ -944,6 +546,18 @@ const CONFIG_KEYS = [
|
|
|
944
546
|
},
|
|
945
547
|
default: "light"
|
|
946
548
|
},
|
|
549
|
+
{
|
|
550
|
+
path: "sourceType",
|
|
551
|
+
shape: "scalar",
|
|
552
|
+
scope: "program",
|
|
553
|
+
tier: "free",
|
|
554
|
+
surface: "engine",
|
|
555
|
+
item: {
|
|
556
|
+
kind: "enum",
|
|
557
|
+
values: SOURCE_TYPE_VALUES
|
|
558
|
+
},
|
|
559
|
+
default: "auto"
|
|
560
|
+
},
|
|
947
561
|
{
|
|
948
562
|
path: "complexity",
|
|
949
563
|
shape: "scalar",
|
|
@@ -1247,438 +861,845 @@ const CONFIG_KEYS = [
|
|
|
1247
861
|
},
|
|
1248
862
|
default: "detected from the environment"
|
|
1249
863
|
},
|
|
1250
|
-
{
|
|
1251
|
-
path: "directives.enabled",
|
|
1252
|
-
shape: "scalar",
|
|
1253
|
-
scope: "program",
|
|
1254
|
-
tier: "free",
|
|
1255
|
-
surface: "build",
|
|
1256
|
-
item: { kind: "boolean" },
|
|
1257
|
-
default: "true"
|
|
864
|
+
{
|
|
865
|
+
path: "directives.enabled",
|
|
866
|
+
shape: "scalar",
|
|
867
|
+
scope: "program",
|
|
868
|
+
tier: "free",
|
|
869
|
+
surface: "build",
|
|
870
|
+
item: { kind: "boolean" },
|
|
871
|
+
default: "true"
|
|
872
|
+
},
|
|
873
|
+
{
|
|
874
|
+
path: "diagnostics.level",
|
|
875
|
+
shape: "scalar",
|
|
876
|
+
scope: "program",
|
|
877
|
+
tier: "free",
|
|
878
|
+
surface: "build",
|
|
879
|
+
item: {
|
|
880
|
+
kind: "enum",
|
|
881
|
+
values: [
|
|
882
|
+
"summary",
|
|
883
|
+
"all",
|
|
884
|
+
"none"
|
|
885
|
+
]
|
|
886
|
+
},
|
|
887
|
+
default: "summary"
|
|
888
|
+
},
|
|
889
|
+
{
|
|
890
|
+
path: "diagnostics.format",
|
|
891
|
+
shape: "scalar",
|
|
892
|
+
scope: "program",
|
|
893
|
+
tier: "free",
|
|
894
|
+
surface: "cli",
|
|
895
|
+
item: {
|
|
896
|
+
kind: "enum",
|
|
897
|
+
values: ["text", "json"]
|
|
898
|
+
},
|
|
899
|
+
default: "text"
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
path: "telemetry.enabled",
|
|
903
|
+
shape: "scalar",
|
|
904
|
+
scope: "program",
|
|
905
|
+
tier: "free",
|
|
906
|
+
surface: "build",
|
|
907
|
+
item: { kind: "boolean" },
|
|
908
|
+
default: "true"
|
|
909
|
+
},
|
|
910
|
+
{
|
|
911
|
+
path: "key",
|
|
912
|
+
shape: "scalar",
|
|
913
|
+
scope: "program",
|
|
914
|
+
tier: "pro",
|
|
915
|
+
surface: "build",
|
|
916
|
+
item: { kind: "string" },
|
|
917
|
+
default: "unset; builds run locally with basic protection"
|
|
918
|
+
}
|
|
919
|
+
];
|
|
920
|
+
const EMPTY_CONFIG = {};
|
|
921
|
+
const CONFIG_BY_PATH = new Map(CONFIG_KEYS.map((k) => [k.path, k]));
|
|
922
|
+
const CONFIG_PREFIXES = new Set(CONFIG_KEYS.flatMap((k) => {
|
|
923
|
+
const parts = k.path.split(".");
|
|
924
|
+
return parts.slice(0, -1).map((_, i) => parts.slice(0, i + 1).join("."));
|
|
925
|
+
}));
|
|
926
|
+
const CONFIG_CHILDREN = new Map([...CONFIG_PREFIXES].map((prefix) => [prefix, CONFIG_KEYS.filter((k) => k.path.startsWith(`${prefix}.`)).map((k) => k.path)]));
|
|
927
|
+
const BY_NORMALIZED = new Map(CONFIG_KEYS.map((k) => [normalizeKey(k.path), k]));
|
|
928
|
+
const CHILDREN_BY_NORMALIZED = new Map([...CONFIG_CHILDREN].map(([prefix, children]) => [normalizeKey(prefix), children]));
|
|
929
|
+
const PREFIX_BY_NORMALIZED = new Map([...CONFIG_PREFIXES].map((prefix) => [normalizeKey(prefix), prefix]));
|
|
930
|
+
function normalizeKey(key) {
|
|
931
|
+
return key.replace(/[-_.]/g, "").toLowerCase();
|
|
932
|
+
}
|
|
933
|
+
function groupBooleanKey(path) {
|
|
934
|
+
if (!CONFIG_PREFIXES.has(path)) return void 0;
|
|
935
|
+
return CONFIG_BY_PATH.get(`${path}.enabled`);
|
|
936
|
+
}
|
|
937
|
+
function nearestName(name, candidates) {
|
|
938
|
+
const target = normalizeKey(name);
|
|
939
|
+
let best;
|
|
940
|
+
for (const candidate of candidates) {
|
|
941
|
+
const distance = editDistance(target, normalizeKey(candidate));
|
|
942
|
+
if (distance > Math.max(2, Math.floor(target.length / 4))) continue;
|
|
943
|
+
if (!best || distance < best.distance) best = {
|
|
944
|
+
name: candidate,
|
|
945
|
+
distance
|
|
946
|
+
};
|
|
947
|
+
}
|
|
948
|
+
return best?.name;
|
|
949
|
+
}
|
|
950
|
+
function suggestKey(key) {
|
|
951
|
+
const exact = BY_NORMALIZED.get(normalizeKey(key));
|
|
952
|
+
if (exact) return exact.path;
|
|
953
|
+
const near = nearestName(key, CONFIG_KEYS.map((k) => k.path));
|
|
954
|
+
if (near) return near;
|
|
955
|
+
const tail = normalizeKey(key);
|
|
956
|
+
const owners = CONFIG_KEYS.filter((k) => normalizeKey(k.path.slice(k.path.lastIndexOf(".") + 1)) === tail);
|
|
957
|
+
return owners.length === 1 ? owners[0].path : void 0;
|
|
958
|
+
}
|
|
959
|
+
function canonicalSpelling(name) {
|
|
960
|
+
const norm$1 = normalizeKey(name);
|
|
961
|
+
const key = BY_NORMALIZED.get(norm$1);
|
|
962
|
+
if (key) return { key: key.path };
|
|
963
|
+
const group$1 = CHILDREN_BY_NORMALIZED.get(norm$1);
|
|
964
|
+
return group$1 && group$1.length > 0 ? { group: group$1 } : void 0;
|
|
965
|
+
}
|
|
966
|
+
function editDistance(a, b) {
|
|
967
|
+
const prev = new Array(b.length + 1);
|
|
968
|
+
const next = new Array(b.length + 1);
|
|
969
|
+
for (let j = 0; j <= b.length; j++) prev[j] = j;
|
|
970
|
+
for (let i = 1; i <= a.length; i++) {
|
|
971
|
+
next[0] = i;
|
|
972
|
+
for (let j = 1; j <= b.length; j++) next[j] = Math.min(prev[j] + 1, next[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
973
|
+
for (let j = 0; j <= b.length; j++) prev[j] = next[j];
|
|
974
|
+
}
|
|
975
|
+
return prev[b.length];
|
|
976
|
+
}
|
|
977
|
+
const DOCS_URL = "https://www.afterpack.dev/docs/config";
|
|
978
|
+
function unknownKeyMessage(path, surface) {
|
|
979
|
+
const group$1 = CHILDREN_BY_NORMALIZED.get(normalizeKey(path));
|
|
980
|
+
if (group$1 && group$1.length > 0) {
|
|
981
|
+
const list = group$1.map((child) => `\`${child}\``).join(", ");
|
|
982
|
+
const tail$1 = group$1.length === 1 ? `did you mean ${list}?` : `its keys are ${list}`;
|
|
983
|
+
const canonical = PREFIX_BY_NORMALIZED.get(normalizeKey(path));
|
|
984
|
+
const enabled = canonical ? groupBooleanKey(canonical) : void 0;
|
|
985
|
+
const rule = enabled ? `; a boolean here means \`${enabled.path}\`` : "";
|
|
986
|
+
return `\`${path}\` is a group of configuration keys, not a key itself (${surface}) — ${tail$1}${rule}`;
|
|
987
|
+
}
|
|
988
|
+
const suggestion = suggestKey(path);
|
|
989
|
+
const tail = suggestion ? ` — did you mean \`${suggestion}\`?` : ` — see ${DOCS_URL}`;
|
|
990
|
+
return `unknown configuration key \`${path}\` (${surface})${tail}`;
|
|
991
|
+
}
|
|
992
|
+
function isPlainObject(value) {
|
|
993
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
994
|
+
}
|
|
995
|
+
function describe(item) {
|
|
996
|
+
switch (item.kind) {
|
|
997
|
+
case "boolean": return "true or false";
|
|
998
|
+
case "number": return item.integer ? `an integer >= ${item.min}` : `a number >= ${item.min}`;
|
|
999
|
+
case "unbounded": return `a number >= ${item.min}, or the string "${item.unlimited}"`;
|
|
1000
|
+
case "string": return "a string";
|
|
1001
|
+
case "enum": return `one of: ${item.values.join(", ")}`;
|
|
1002
|
+
case "seed": return "a number, any string, or \"git\"";
|
|
1003
|
+
case "reserved": return "a name, or { \"glob\": \"…\", \"names\": [\"…\"] }";
|
|
1004
|
+
case "region": return "an object with numeric `start` and `end`";
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
function misdirectedHint(key, value, spell) {
|
|
1008
|
+
const other = misdirectedTo(key, value);
|
|
1009
|
+
if (!other) return "";
|
|
1010
|
+
const written = spell(other.path, String(value));
|
|
1011
|
+
return ` — \`${String(value)}\` is a \`${other.path}\` value; write \`${written}\` instead`;
|
|
1012
|
+
}
|
|
1013
|
+
const isFiniteNumber = (v) => typeof v === "number" && Number.isFinite(v);
|
|
1014
|
+
const isTransformKinds = (v) => Array.isArray(v) && v.every((k) => TRANSFORM_KIND_VALUES.includes(k));
|
|
1015
|
+
const KINDS = `a list of: ${TRANSFORM_KIND_VALUES.join(", ")}`;
|
|
1016
|
+
const isNonNegative = (v) => isFiniteNumber(v) && v >= 0;
|
|
1017
|
+
function group(fields) {
|
|
1018
|
+
return {
|
|
1019
|
+
is: isPlainObject,
|
|
1020
|
+
want: "an object",
|
|
1021
|
+
fields
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
1024
|
+
const REGION_FIELDS = {
|
|
1025
|
+
start: {
|
|
1026
|
+
required: true,
|
|
1027
|
+
is: isFiniteNumber,
|
|
1028
|
+
want: "a number"
|
|
1029
|
+
},
|
|
1030
|
+
end: {
|
|
1031
|
+
required: true,
|
|
1032
|
+
is: isFiniteNumber,
|
|
1033
|
+
want: "a number"
|
|
1258
1034
|
},
|
|
1259
|
-
{
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
scope: "program",
|
|
1263
|
-
tier: "free",
|
|
1264
|
-
surface: "build",
|
|
1265
|
-
item: {
|
|
1266
|
-
kind: "enum",
|
|
1267
|
-
values: [
|
|
1268
|
-
"summary",
|
|
1269
|
-
"all",
|
|
1270
|
-
"none"
|
|
1271
|
-
]
|
|
1272
|
-
},
|
|
1273
|
-
default: "summary"
|
|
1035
|
+
complexity: {
|
|
1036
|
+
is: isNonNegative,
|
|
1037
|
+
want: "a number >= 0"
|
|
1274
1038
|
},
|
|
1275
|
-
{
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1039
|
+
inflation: group({ max: {
|
|
1040
|
+
is: isNonNegative,
|
|
1041
|
+
want: "a number >= 0"
|
|
1042
|
+
} }),
|
|
1043
|
+
strings: group({ encode: {
|
|
1044
|
+
is: (v) => typeof v === "boolean",
|
|
1045
|
+
want: "true or false"
|
|
1046
|
+
} }),
|
|
1047
|
+
transforms: group({
|
|
1048
|
+
only: {
|
|
1049
|
+
is: isTransformKinds,
|
|
1050
|
+
want: KINDS
|
|
1284
1051
|
},
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
{
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
tier: "free",
|
|
1301
|
-
surface: "build",
|
|
1302
|
-
item: { kind: "boolean" },
|
|
1303
|
-
default: "false"
|
|
1052
|
+
deny: {
|
|
1053
|
+
is: isTransformKinds,
|
|
1054
|
+
want: KINDS
|
|
1055
|
+
}
|
|
1056
|
+
}),
|
|
1057
|
+
label: {
|
|
1058
|
+
is: (v) => typeof v === "string",
|
|
1059
|
+
want: "a string"
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
const RESERVED_FIELDS = {
|
|
1063
|
+
glob: {
|
|
1064
|
+
required: true,
|
|
1065
|
+
is: (v) => typeof v === "string",
|
|
1066
|
+
want: "a string"
|
|
1304
1067
|
},
|
|
1305
|
-
{
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1068
|
+
names: {
|
|
1069
|
+
required: true,
|
|
1070
|
+
is: (v) => Array.isArray(v) && v.every((n) => typeof n === "string"),
|
|
1071
|
+
want: "a list of names"
|
|
1072
|
+
}
|
|
1073
|
+
};
|
|
1074
|
+
function leafNames(spec, prefix) {
|
|
1075
|
+
return Object.entries(spec).flatMap(([name, field]) => field.fields ? leafNames(field.fields, `${prefix}${name}.`) : [prefix + name]);
|
|
1076
|
+
}
|
|
1077
|
+
function checkFields(spec, value, prefix = "") {
|
|
1078
|
+
for (const name of Object.keys(value)) {
|
|
1079
|
+
if (name in spec) continue;
|
|
1080
|
+
const near = nearestName(prefix + name, Object.keys(spec).map((n) => prefix + n));
|
|
1081
|
+
return `item has an unknown field \`${prefix}${name}\`` + (near ? ` — did you mean \`${near}\`?` : "") + ` (allowed: ${leafNames(spec, prefix).join(", ")})`;
|
|
1082
|
+
}
|
|
1083
|
+
for (const [name, field] of Object.entries(spec)) {
|
|
1084
|
+
const present = value[name];
|
|
1085
|
+
if (present === void 0) {
|
|
1086
|
+
if (field.required) return `item is missing \`${prefix}${name}\` (${field.want})`;
|
|
1087
|
+
continue;
|
|
1088
|
+
}
|
|
1089
|
+
if (!field.is(present)) return `item's \`${prefix}${name}\` must be ${field.want}, got ${JSON.stringify(present)}`;
|
|
1090
|
+
if (field.fields) {
|
|
1091
|
+
const nested = checkFields(field.fields, present, `${prefix}${name}.`);
|
|
1092
|
+
if (nested) return nested;
|
|
1093
|
+
}
|
|
1094
|
+
}
|
|
1095
|
+
return void 0;
|
|
1096
|
+
}
|
|
1097
|
+
function expected(item, value) {
|
|
1098
|
+
return `expected ${describe(item)}, got ${JSON.stringify(value)}`;
|
|
1099
|
+
}
|
|
1100
|
+
function checkItem(item, value) {
|
|
1101
|
+
switch (item.kind) {
|
|
1102
|
+
case "boolean": return typeof value === "boolean" ? void 0 : expected(item, value);
|
|
1103
|
+
case "number": {
|
|
1104
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return expected(item, value);
|
|
1105
|
+
if (value < item.min) return expected(item, value);
|
|
1106
|
+
if (item.integer && !Number.isInteger(value)) return expected(item, value);
|
|
1107
|
+
return void 0;
|
|
1108
|
+
}
|
|
1109
|
+
case "unbounded": {
|
|
1110
|
+
if (value === item.unlimited) return void 0;
|
|
1111
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= item.min) return void 0;
|
|
1112
|
+
return `${expected(item, value)} — there is no \`Infinity\` in JSON; write "${item.unlimited}"`;
|
|
1113
|
+
}
|
|
1114
|
+
case "string": return typeof value === "string" ? void 0 : expected(item, value);
|
|
1115
|
+
case "enum": return typeof value === "string" && item.values.includes(value) ? void 0 : expected(item, value);
|
|
1116
|
+
case "seed": return typeof value === "number" || typeof value === "string" ? void 0 : expected(item, value);
|
|
1117
|
+
case "reserved": {
|
|
1118
|
+
if (typeof value === "string") return void 0;
|
|
1119
|
+
if (!isPlainObject(value)) return expected(item, value);
|
|
1120
|
+
return checkFields(RESERVED_FIELDS, value);
|
|
1121
|
+
}
|
|
1122
|
+
case "region": {
|
|
1123
|
+
if (!isPlainObject(value)) return expected(item, value);
|
|
1124
|
+
return checkFields(REGION_FIELDS, value);
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
}
|
|
1128
|
+
function checkValue(key, value) {
|
|
1129
|
+
if (key.shape === "scalar") {
|
|
1130
|
+
const failure = checkItem(key.item, value);
|
|
1131
|
+
return failure ? `\`${key.path}\`: ${failure}` : void 0;
|
|
1132
|
+
}
|
|
1133
|
+
if (!Array.isArray(value)) return `\`${key.path}\`: expected a list of values, got ${JSON.stringify(value)}`;
|
|
1134
|
+
for (const entry of value) {
|
|
1135
|
+
const failure = checkItem(key.item, entry);
|
|
1136
|
+
if (failure) return `\`${key.path}\`: ${failure}`;
|
|
1137
|
+
}
|
|
1138
|
+
return void 0;
|
|
1139
|
+
}
|
|
1140
|
+
function misdirectedTo(key, value) {
|
|
1141
|
+
if (key.namedValuesOf === void 0 || typeof value !== "string") return void 0;
|
|
1142
|
+
const other = CONFIG_BY_PATH.get(key.namedValuesOf);
|
|
1143
|
+
if (!other || other.shape !== "scalar") return void 0;
|
|
1144
|
+
return checkItem(other.item, value) === void 0 ? other : void 0;
|
|
1145
|
+
}
|
|
1146
|
+
function validateConfig(input, surface) {
|
|
1147
|
+
const issues = [];
|
|
1148
|
+
const config = {};
|
|
1149
|
+
if (input === void 0 || input === null) return {
|
|
1150
|
+
config,
|
|
1151
|
+
issues
|
|
1152
|
+
};
|
|
1153
|
+
if (!isPlainObject(input)) {
|
|
1154
|
+
issues.push({
|
|
1155
|
+
path: "",
|
|
1156
|
+
message: `configuration (${surface}) must be an object`
|
|
1157
|
+
});
|
|
1158
|
+
return {
|
|
1159
|
+
config,
|
|
1160
|
+
issues
|
|
1161
|
+
};
|
|
1162
|
+
}
|
|
1163
|
+
walk(input, "", config, issues, surface);
|
|
1164
|
+
return {
|
|
1165
|
+
config,
|
|
1166
|
+
issues
|
|
1167
|
+
};
|
|
1168
|
+
}
|
|
1169
|
+
function walk(source, prefix, target, issues, surface) {
|
|
1170
|
+
for (const [name, value] of Object.entries(source)) {
|
|
1171
|
+
if (value === void 0) continue;
|
|
1172
|
+
const path = prefix ? `${prefix}.${name}` : name;
|
|
1173
|
+
const key = CONFIG_BY_PATH.get(path);
|
|
1174
|
+
if (key) {
|
|
1175
|
+
const failure = checkValue(key, value);
|
|
1176
|
+
if (failure) {
|
|
1177
|
+
const hint = misdirectedHint(key, value, (p, v) => `"${p}": ${JSON.stringify(v)}`);
|
|
1178
|
+
issues.push({
|
|
1179
|
+
path,
|
|
1180
|
+
message: `${failure} (${surface})${hint}`
|
|
1181
|
+
});
|
|
1182
|
+
} else target[name] = value;
|
|
1183
|
+
continue;
|
|
1184
|
+
}
|
|
1185
|
+
if (CONFIG_PREFIXES.has(path)) {
|
|
1186
|
+
if (isPlainObject(value)) {
|
|
1187
|
+
const nested = {};
|
|
1188
|
+
walk(value, path, nested, issues, surface);
|
|
1189
|
+
if (Object.keys(nested).length > 0) target[name] = nested;
|
|
1190
|
+
continue;
|
|
1191
|
+
}
|
|
1192
|
+
const enabled = groupBooleanKey(path);
|
|
1193
|
+
if (enabled && typeof value === "boolean") {
|
|
1194
|
+
target[name] = { enabled: value };
|
|
1195
|
+
continue;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
issues.push({
|
|
1199
|
+
path,
|
|
1200
|
+
message: unknownKeyMessage(path, surface)
|
|
1201
|
+
});
|
|
1313
1202
|
}
|
|
1314
|
-
];
|
|
1315
|
-
const EMPTY_CONFIG = {};
|
|
1316
|
-
const CONFIG_BY_PATH = new Map(CONFIG_KEYS.map((k) => [k.path, k]));
|
|
1317
|
-
const CONFIG_PREFIXES = new Set(CONFIG_KEYS.flatMap((k) => {
|
|
1318
|
-
const parts = k.path.split(".");
|
|
1319
|
-
return parts.slice(0, -1).map((_, i) => parts.slice(0, i + 1).join("."));
|
|
1320
|
-
}));
|
|
1321
|
-
const CONFIG_CHILDREN = new Map([...CONFIG_PREFIXES].map((prefix) => [prefix, CONFIG_KEYS.filter((k) => k.path.startsWith(`${prefix}.`)).map((k) => k.path)]));
|
|
1322
|
-
const BY_NORMALIZED = new Map(CONFIG_KEYS.map((k) => [normalizeKey(k.path), k]));
|
|
1323
|
-
const CHILDREN_BY_NORMALIZED = new Map([...CONFIG_CHILDREN].map(([prefix, children]) => [normalizeKey(prefix), children]));
|
|
1324
|
-
const PREFIX_BY_NORMALIZED = new Map([...CONFIG_PREFIXES].map((prefix) => [normalizeKey(prefix), prefix]));
|
|
1325
|
-
function normalizeKey(key) {
|
|
1326
|
-
return key.replace(/[-_.]/g, "").toLowerCase();
|
|
1327
|
-
}
|
|
1328
|
-
function groupBooleanKey(path) {
|
|
1329
|
-
if (!CONFIG_PREFIXES.has(path)) return void 0;
|
|
1330
|
-
return CONFIG_BY_PATH.get(`${path}.enabled`);
|
|
1331
1203
|
}
|
|
1332
|
-
function
|
|
1333
|
-
const
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
const
|
|
1337
|
-
|
|
1338
|
-
if (!best || distance < best.distance) best = {
|
|
1339
|
-
name: candidate,
|
|
1340
|
-
distance
|
|
1341
|
-
};
|
|
1204
|
+
function deepMerge(base, override) {
|
|
1205
|
+
const out = { ...base };
|
|
1206
|
+
for (const [name, value] of Object.entries(override)) {
|
|
1207
|
+
if (value === void 0) continue;
|
|
1208
|
+
const existing = out[name];
|
|
1209
|
+
out[name] = isPlainObject(value) && isPlainObject(existing) ? deepMerge(existing, value) : value;
|
|
1342
1210
|
}
|
|
1343
|
-
return
|
|
1344
|
-
}
|
|
1345
|
-
function suggestKey(key) {
|
|
1346
|
-
const exact = BY_NORMALIZED.get(normalizeKey(key));
|
|
1347
|
-
if (exact) return exact.path;
|
|
1348
|
-
const near = nearestName(key, CONFIG_KEYS.map((k) => k.path));
|
|
1349
|
-
if (near) return near;
|
|
1350
|
-
const tail = normalizeKey(key);
|
|
1351
|
-
const owners = CONFIG_KEYS.filter((k) => normalizeKey(k.path.slice(k.path.lastIndexOf(".") + 1)) === tail);
|
|
1352
|
-
return owners.length === 1 ? owners[0].path : void 0;
|
|
1211
|
+
return out;
|
|
1353
1212
|
}
|
|
1354
|
-
function
|
|
1355
|
-
|
|
1356
|
-
const key = BY_NORMALIZED.get(norm$1);
|
|
1357
|
-
if (key) return { key: key.path };
|
|
1358
|
-
const group$1 = CHILDREN_BY_NORMALIZED.get(norm$1);
|
|
1359
|
-
return group$1 && group$1.length > 0 ? { group: group$1 } : void 0;
|
|
1213
|
+
function mergeInto(base, override) {
|
|
1214
|
+
return deepMerge(base, override);
|
|
1360
1215
|
}
|
|
1361
|
-
function
|
|
1362
|
-
|
|
1363
|
-
const next = new Array(b.length + 1);
|
|
1364
|
-
for (let j = 0; j <= b.length; j++) prev[j] = j;
|
|
1365
|
-
for (let i = 1; i <= a.length; i++) {
|
|
1366
|
-
next[0] = i;
|
|
1367
|
-
for (let j = 1; j <= b.length; j++) next[j] = Math.min(prev[j] + 1, next[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
1368
|
-
for (let j = 0; j <= b.length; j++) prev[j] = next[j];
|
|
1369
|
-
}
|
|
1370
|
-
return prev[b.length];
|
|
1216
|
+
function mergeConfig(base, override) {
|
|
1217
|
+
return deepMerge(base, override);
|
|
1371
1218
|
}
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
const
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
const tail$1 = group$1.length === 1 ? `did you mean ${list}?` : `its keys are ${list}`;
|
|
1378
|
-
const canonical = PREFIX_BY_NORMALIZED.get(normalizeKey(path));
|
|
1379
|
-
const enabled = canonical ? groupBooleanKey(canonical) : void 0;
|
|
1380
|
-
const rule = enabled ? `; a boolean here means \`${enabled.path}\`` : "";
|
|
1381
|
-
return `\`${path}\` is a group of configuration keys, not a key itself (${surface}) — ${tail$1}${rule}`;
|
|
1219
|
+
function getPath(config, path) {
|
|
1220
|
+
let current = config;
|
|
1221
|
+
for (const part of path.split(".")) {
|
|
1222
|
+
if (!isPlainObject(current)) return void 0;
|
|
1223
|
+
current = current[part];
|
|
1382
1224
|
}
|
|
1383
|
-
|
|
1384
|
-
const tail = suggestion ? ` — did you mean \`${suggestion}\`?` : ` — see ${DOCS_URL}`;
|
|
1385
|
-
return `unknown configuration key \`${path}\` (${surface})${tail}`;
|
|
1225
|
+
return current;
|
|
1386
1226
|
}
|
|
1387
|
-
function
|
|
1388
|
-
return
|
|
1227
|
+
function nest(path, value) {
|
|
1228
|
+
return path.split(".").reduceRight((inner, segment) => ({ [segment]: inner }), value);
|
|
1389
1229
|
}
|
|
1390
|
-
function
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
case "enum": return `one of: ${item.values.join(", ")}`;
|
|
1397
|
-
case "seed": return "a number, any string, or \"git\"";
|
|
1398
|
-
case "reserved": return "a name, or { \"glob\": \"…\", \"names\": [\"…\"] }";
|
|
1399
|
-
case "region": return "an object with numeric `start` and `end`";
|
|
1230
|
+
function setPath(target, path, value) {
|
|
1231
|
+
const parts = path.split(".");
|
|
1232
|
+
let node = target;
|
|
1233
|
+
for (const part of parts.slice(0, -1)) {
|
|
1234
|
+
if (!isPlainObject(node[part])) node[part] = {};
|
|
1235
|
+
node = node[part];
|
|
1400
1236
|
}
|
|
1237
|
+
node[parts[parts.length - 1]] = value;
|
|
1401
1238
|
}
|
|
1402
|
-
function
|
|
1403
|
-
const
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1239
|
+
function toEngineConfig(config) {
|
|
1240
|
+
const out = {};
|
|
1241
|
+
for (const key of CONFIG_KEYS) {
|
|
1242
|
+
if (key.surface !== "engine") continue;
|
|
1243
|
+
const value = getPath(config, key.path);
|
|
1244
|
+
if (value === void 0) continue;
|
|
1245
|
+
setPath(out, key.path, value);
|
|
1246
|
+
}
|
|
1247
|
+
return out;
|
|
1407
1248
|
}
|
|
1408
|
-
|
|
1409
|
-
const
|
|
1410
|
-
const
|
|
1411
|
-
const isNonNegative = (v) => isFiniteNumber(v) && v >= 0;
|
|
1412
|
-
function group(fields) {
|
|
1249
|
+
function toPluginOptions(config) {
|
|
1250
|
+
const read = (path) => getPath(config, path);
|
|
1251
|
+
const set = (container) => Object.values(container).some((v) => v !== void 0) ? container : void 0;
|
|
1413
1252
|
return {
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1253
|
+
artifactOptions: {
|
|
1254
|
+
protectionMap: set({ enabled: read("protectionMap.enabled") }),
|
|
1255
|
+
sourceMap: set({
|
|
1256
|
+
enabled: read("sourceMap.enabled"),
|
|
1257
|
+
emitUrl: read("sourceMap.emitUrl")
|
|
1258
|
+
}),
|
|
1259
|
+
build: set({
|
|
1260
|
+
backup: read("build.backup"),
|
|
1261
|
+
mode: read("build.mode")
|
|
1262
|
+
}),
|
|
1263
|
+
telemetry: set({ enabled: read("telemetry.enabled") })
|
|
1264
|
+
},
|
|
1265
|
+
seed: read("seed"),
|
|
1266
|
+
preset: read("preset"),
|
|
1267
|
+
complexity: read("complexity"),
|
|
1268
|
+
regions: read("regions"),
|
|
1269
|
+
directives: {
|
|
1270
|
+
enabled: read("directives.enabled") ?? DIRECTIVES_ENABLED_DEFAULT,
|
|
1271
|
+
explicit: read("directives.enabled") !== void 0
|
|
1272
|
+
},
|
|
1273
|
+
build: set({ autorun: read("build.autorun") }),
|
|
1274
|
+
diagnostics: set({
|
|
1275
|
+
level: read("diagnostics.level"),
|
|
1276
|
+
format: read("diagnostics.format")
|
|
1277
|
+
}),
|
|
1278
|
+
paths: set({ include: read("paths.include") }),
|
|
1279
|
+
key: read("key")
|
|
1417
1280
|
};
|
|
1418
1281
|
}
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
}
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1449
|
-
|
|
1450
|
-
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1282
|
+
|
|
1283
|
+
//#endregion
|
|
1284
|
+
//#region src/source-map.ts
|
|
1285
|
+
const SOURCE_MAPPING_URL_RE = /\/\/[#@]\s*sourceMappingURL=(\S+)\s*$/gm;
|
|
1286
|
+
const SOURCE_MAPPING_URL_LINE_RE = /^[ \t]*\/\/[#@]\s*sourceMappingURL=\S+[ \t]*\r?\n?/gm;
|
|
1287
|
+
const CSS_SOURCE_MAPPING_URL_RE = /[ \t]*\/\*[#@]\s*sourceMappingURL=[^\s*]+\s*\*\/\s*$/;
|
|
1288
|
+
function withSourceMappingURL(code, url) {
|
|
1289
|
+
const stripped = code.replace(SOURCE_MAPPING_URL_LINE_RE, "");
|
|
1290
|
+
if (url == null) return stripped;
|
|
1291
|
+
const separator = stripped.length > 0 && !stripped.endsWith("\n") ? "\n" : "";
|
|
1292
|
+
return `${stripped}${separator}//# sourceMappingURL=${url}\n`;
|
|
1293
|
+
}
|
|
1294
|
+
function withoutCssSourceMappingURL(css) {
|
|
1295
|
+
return css.replace(CSS_SOURCE_MAPPING_URL_RE, "");
|
|
1296
|
+
}
|
|
1297
|
+
function extractSourceMappingURL(code) {
|
|
1298
|
+
let last = null;
|
|
1299
|
+
for (const match of code.matchAll(SOURCE_MAPPING_URL_RE)) last = match[1];
|
|
1300
|
+
return last;
|
|
1301
|
+
}
|
|
1302
|
+
function isRemoteSourceMappingURL(url) {
|
|
1303
|
+
return /^https?:\/\//i.test(url) || url.startsWith("//");
|
|
1304
|
+
}
|
|
1305
|
+
function decodeDataUri(url) {
|
|
1306
|
+
if (!url.startsWith("data:")) return null;
|
|
1307
|
+
const comma = url.indexOf(",");
|
|
1308
|
+
if (comma === -1) return null;
|
|
1309
|
+
const meta = url.slice(5, comma);
|
|
1310
|
+
const payload = url.slice(comma + 1);
|
|
1311
|
+
try {
|
|
1312
|
+
if (/;base64/i.test(meta)) return Buffer.from(payload, "base64").toString("utf8");
|
|
1313
|
+
return decodeURIComponent(payload);
|
|
1314
|
+
} catch {
|
|
1315
|
+
return null;
|
|
1316
|
+
}
|
|
1317
|
+
}
|
|
1318
|
+
function discoverInputSourceMap(jsPath, code) {
|
|
1319
|
+
const adjacent = `${jsPath}.map`;
|
|
1320
|
+
if (existsSync(adjacent)) try {
|
|
1321
|
+
return readFileSync(adjacent, "utf8");
|
|
1322
|
+
} catch {}
|
|
1323
|
+
let source = code;
|
|
1324
|
+
if (source == null) try {
|
|
1325
|
+
source = readFileSync(jsPath, "utf8");
|
|
1326
|
+
} catch {
|
|
1327
|
+
return null;
|
|
1328
|
+
}
|
|
1329
|
+
const url = extractSourceMappingURL(source);
|
|
1330
|
+
if (url == null) return null;
|
|
1331
|
+
if (url.startsWith("data:")) return decodeDataUri(url);
|
|
1332
|
+
if (isRemoteSourceMappingURL(url)) return null;
|
|
1333
|
+
let mapPath;
|
|
1334
|
+
try {
|
|
1335
|
+
mapPath = isAbsolute(url) ? url : resolve(dirname(jsPath), decodeURIComponent(url));
|
|
1336
|
+
} catch {
|
|
1337
|
+
return null;
|
|
1455
1338
|
}
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
want: "a string"
|
|
1462
|
-
},
|
|
1463
|
-
names: {
|
|
1464
|
-
required: true,
|
|
1465
|
-
is: (v) => Array.isArray(v) && v.every((n) => typeof n === "string"),
|
|
1466
|
-
want: "a list of names"
|
|
1339
|
+
if (!existsSync(mapPath)) return null;
|
|
1340
|
+
try {
|
|
1341
|
+
return readFileSync(mapPath, "utf8");
|
|
1342
|
+
} catch {
|
|
1343
|
+
return null;
|
|
1467
1344
|
}
|
|
1468
|
-
};
|
|
1469
|
-
function leafNames(spec, prefix) {
|
|
1470
|
-
return Object.entries(spec).flatMap(([name, field]) => field.fields ? leafNames(field.fields, `${prefix}${name}.`) : [prefix + name]);
|
|
1471
1345
|
}
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1346
|
+
|
|
1347
|
+
//#endregion
|
|
1348
|
+
//#region src/bundle.ts
|
|
1349
|
+
const BUNDLE_JS_RE = /\.[cm]?js$/;
|
|
1350
|
+
const CSS_MAP_RE = /\.css\.map$/;
|
|
1351
|
+
function collectBundleJs(bundle, outDir) {
|
|
1352
|
+
const files = [];
|
|
1353
|
+
const inputs = new Map();
|
|
1354
|
+
const entries = new Map();
|
|
1355
|
+
for (const [fileName, entry] of Object.entries(bundle)) {
|
|
1356
|
+
if (!BUNDLE_JS_RE.test(fileName)) continue;
|
|
1357
|
+
const source = entry.type === "chunk" ? entry.code : typeof entry.source === "string" ? entry.source : void 0;
|
|
1358
|
+
if (source === void 0) continue;
|
|
1359
|
+
const filePath = resolve(outDir, fileName);
|
|
1360
|
+
files.push(filePath);
|
|
1361
|
+
entries.set(filePath, entry);
|
|
1362
|
+
inputs.set(filePath, {
|
|
1363
|
+
source,
|
|
1364
|
+
sourceMap: entry.map ? entry.map.toString() : null
|
|
1365
|
+
});
|
|
1477
1366
|
}
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1367
|
+
return {
|
|
1368
|
+
files,
|
|
1369
|
+
inputs,
|
|
1370
|
+
entries
|
|
1371
|
+
};
|
|
1372
|
+
}
|
|
1373
|
+
function sourceTypeForBundle(format, entries) {
|
|
1374
|
+
for (const entry of entries) if (entry.type !== "chunk") return void 0;
|
|
1375
|
+
return sourceTypeForOutputFormat(format);
|
|
1376
|
+
}
|
|
1377
|
+
function dataUri(json) {
|
|
1378
|
+
return `data:application/json;charset=utf-8;base64,${Buffer.from(json, "utf8").toString("base64")}`;
|
|
1379
|
+
}
|
|
1380
|
+
function applyBundleOutput(bundle, entry, out, policy) {
|
|
1381
|
+
if (entry.type !== "chunk") {
|
|
1382
|
+
entry.source = out.code;
|
|
1383
|
+
return;
|
|
1384
|
+
}
|
|
1385
|
+
const mapName = entry.sourcemapFileName ?? null;
|
|
1386
|
+
const inlineMap = mapName == null && entry.map != null;
|
|
1387
|
+
const emitMap = policy.sourceMap && out.sourceMap != null;
|
|
1388
|
+
let url = null;
|
|
1389
|
+
if (emitMap && out.sourceMap != null) {
|
|
1390
|
+
if (mapName != null && bundle[mapName]) {
|
|
1391
|
+
bundle[mapName].source = out.sourceMap;
|
|
1392
|
+
url = basename(mapName);
|
|
1393
|
+
} else if (inlineMap) url = dataUri(out.sourceMap);
|
|
1394
|
+
} else {
|
|
1395
|
+
if (mapName != null) delete bundle[mapName];
|
|
1396
|
+
entry.map = null;
|
|
1397
|
+
}
|
|
1398
|
+
entry.code = withSourceMappingURL(out.code, policy.emitSourceMappingURL ? url : null);
|
|
1399
|
+
}
|
|
1400
|
+
function stripBundleCssSourceMaps(bundle) {
|
|
1401
|
+
for (const [fileName, entry] of Object.entries(bundle)) {
|
|
1402
|
+
if (CSS_MAP_RE.test(fileName)) {
|
|
1403
|
+
delete bundle[fileName];
|
|
1482
1404
|
continue;
|
|
1483
1405
|
}
|
|
1484
|
-
if (
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
}
|
|
1406
|
+
if (entry.type !== "asset" || !fileName.endsWith(".css") || entry.source === void 0) continue;
|
|
1407
|
+
const css = typeof entry.source === "string" ? entry.source : Buffer.from(entry.source).toString("utf8");
|
|
1408
|
+
const stripped = withoutCssSourceMappingURL(css);
|
|
1409
|
+
if (stripped !== css) entry.source = stripped;
|
|
1489
1410
|
}
|
|
1490
|
-
return void 0;
|
|
1491
1411
|
}
|
|
1492
|
-
|
|
1493
|
-
|
|
1412
|
+
|
|
1413
|
+
//#endregion
|
|
1414
|
+
//#region src/glob.ts
|
|
1415
|
+
function normalize(value) {
|
|
1416
|
+
return value.includes("\\") ? value.replaceAll("\\", "/") : value;
|
|
1494
1417
|
}
|
|
1495
|
-
function
|
|
1496
|
-
|
|
1497
|
-
case "boolean": return typeof value === "boolean" ? void 0 : expected(item, value);
|
|
1498
|
-
case "number": {
|
|
1499
|
-
if (typeof value !== "number" || !Number.isFinite(value)) return expected(item, value);
|
|
1500
|
-
if (value < item.min) return expected(item, value);
|
|
1501
|
-
if (item.integer && !Number.isInteger(value)) return expected(item, value);
|
|
1502
|
-
return void 0;
|
|
1503
|
-
}
|
|
1504
|
-
case "unbounded": {
|
|
1505
|
-
if (value === item.unlimited) return void 0;
|
|
1506
|
-
if (typeof value === "number" && Number.isFinite(value) && value >= item.min) return void 0;
|
|
1507
|
-
return `${expected(item, value)} — there is no \`Infinity\` in JSON; write "${item.unlimited}"`;
|
|
1508
|
-
}
|
|
1509
|
-
case "string": return typeof value === "string" ? void 0 : expected(item, value);
|
|
1510
|
-
case "enum": return typeof value === "string" && item.values.includes(value) ? void 0 : expected(item, value);
|
|
1511
|
-
case "seed": return typeof value === "number" || typeof value === "string" ? void 0 : expected(item, value);
|
|
1512
|
-
case "reserved": {
|
|
1513
|
-
if (typeof value === "string") return void 0;
|
|
1514
|
-
if (!isPlainObject(value)) return expected(item, value);
|
|
1515
|
-
return checkFields(RESERVED_FIELDS, value);
|
|
1516
|
-
}
|
|
1517
|
-
case "region": {
|
|
1518
|
-
if (!isPlainObject(value)) return expected(item, value);
|
|
1519
|
-
return checkFields(REGION_FIELDS, value);
|
|
1520
|
-
}
|
|
1521
|
-
}
|
|
1418
|
+
function segments(value) {
|
|
1419
|
+
return value.split("/").filter((part) => part !== "");
|
|
1522
1420
|
}
|
|
1523
|
-
function
|
|
1524
|
-
if (
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
if (!
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1421
|
+
function isAnchored(pattern) {
|
|
1422
|
+
if (pattern.startsWith("/")) return true;
|
|
1423
|
+
return pattern.length >= 2 && pattern[1] === ":" && /^[A-Za-z]$/.test(pattern[0]);
|
|
1424
|
+
}
|
|
1425
|
+
function segmentMatches(pattern, seg) {
|
|
1426
|
+
if (!pattern.includes("*") && !pattern.includes("?")) return pattern === seg;
|
|
1427
|
+
const p = [...pattern];
|
|
1428
|
+
const s = [...seg];
|
|
1429
|
+
let pi = 0;
|
|
1430
|
+
let si = 0;
|
|
1431
|
+
let star = -1;
|
|
1432
|
+
let starSi = 0;
|
|
1433
|
+
while (si < s.length) if (pi < p.length && p[pi] === "*") {
|
|
1434
|
+
star = pi;
|
|
1435
|
+
starSi = si;
|
|
1436
|
+
pi += 1;
|
|
1437
|
+
} else if (pi < p.length && (p[pi] === "?" || p[pi] === s[si])) {
|
|
1438
|
+
pi += 1;
|
|
1439
|
+
si += 1;
|
|
1440
|
+
} else if (star >= 0) {
|
|
1441
|
+
pi = star + 1;
|
|
1442
|
+
starSi += 1;
|
|
1443
|
+
si = starSi;
|
|
1444
|
+
} else return false;
|
|
1445
|
+
return p.slice(pi).every((c) => c === "*");
|
|
1446
|
+
}
|
|
1447
|
+
function segmentsMatch(pattern, path) {
|
|
1448
|
+
let pi = 0;
|
|
1449
|
+
let si = 0;
|
|
1450
|
+
let star = -1;
|
|
1451
|
+
let starSi = 0;
|
|
1452
|
+
while (si < path.length) if (pi < pattern.length && pattern[pi] === "**") {
|
|
1453
|
+
star = pi;
|
|
1454
|
+
starSi = si;
|
|
1455
|
+
pi += 1;
|
|
1456
|
+
} else if (pi < pattern.length && segmentMatches(pattern[pi], path[si])) {
|
|
1457
|
+
pi += 1;
|
|
1458
|
+
si += 1;
|
|
1459
|
+
} else if (star >= 0) {
|
|
1460
|
+
pi = star + 1;
|
|
1461
|
+
starSi += 1;
|
|
1462
|
+
si = starSi;
|
|
1463
|
+
} else return false;
|
|
1464
|
+
return pattern.slice(pi).every((s) => s === "**");
|
|
1465
|
+
}
|
|
1466
|
+
function matchesPath(pattern, path) {
|
|
1467
|
+
const pat = normalize(pattern);
|
|
1468
|
+
const parts = segments(pat);
|
|
1469
|
+
if (parts.length === 0) return false;
|
|
1470
|
+
const segs = segments(normalize(path));
|
|
1471
|
+
if (isAnchored(pat)) return segmentsMatch(parts, segs);
|
|
1472
|
+
for (let i = 0; i <= segs.length; i++) if (segmentsMatch(parts, segs.slice(i))) return true;
|
|
1473
|
+
return false;
|
|
1474
|
+
}
|
|
1475
|
+
function reachesInto(pattern, dir) {
|
|
1476
|
+
const pat = normalize(pattern);
|
|
1477
|
+
const parts = segments(pat);
|
|
1478
|
+
if (parts.length === 0) return false;
|
|
1479
|
+
if (!isAnchored(pat)) return true;
|
|
1480
|
+
for (let k = 1; k <= parts.length; k++) if (matchesPath(`/${parts.slice(0, k).join("/")}`, dir)) return true;
|
|
1481
|
+
return false;
|
|
1482
|
+
}
|
|
1483
|
+
|
|
1484
|
+
//#endregion
|
|
1485
|
+
//#region src/collect.ts
|
|
1486
|
+
const BACKUP_RE = /\.backup\.[0-9a-f]{8}\.[cm]?js$/;
|
|
1487
|
+
const NODE_MODULES = "node_modules";
|
|
1488
|
+
function isCollectableJs(name) {
|
|
1489
|
+
if (BACKUP_RE.test(name)) return false;
|
|
1490
|
+
return name.endsWith(".js") || name.endsWith(".mjs") || name.endsWith(".cjs");
|
|
1491
|
+
}
|
|
1492
|
+
function statOrNull(path) {
|
|
1493
|
+
try {
|
|
1494
|
+
return statSync(path);
|
|
1495
|
+
} catch {
|
|
1496
|
+
return null;
|
|
1532
1497
|
}
|
|
1533
|
-
return void 0;
|
|
1534
1498
|
}
|
|
1535
|
-
function
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
if (!
|
|
1539
|
-
return
|
|
1499
|
+
function collectJsFiles(target, options = {}) {
|
|
1500
|
+
const stat = statOrNull(target);
|
|
1501
|
+
if (!stat) return [];
|
|
1502
|
+
if (!stat.isDirectory()) return isCollectableJs(basename(target)) ? [target] : [];
|
|
1503
|
+
return walkJs(target, options.include ?? [], false, options.onNestedProject);
|
|
1540
1504
|
}
|
|
1541
|
-
function
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
issues
|
|
1547
|
-
};
|
|
1548
|
-
if (!isPlainObject(input)) {
|
|
1549
|
-
issues.push({
|
|
1550
|
-
path: "",
|
|
1551
|
-
message: `configuration (${surface}) must be an object`
|
|
1552
|
-
});
|
|
1553
|
-
return {
|
|
1554
|
-
config,
|
|
1555
|
-
issues
|
|
1556
|
-
};
|
|
1505
|
+
function entriesOf(dir) {
|
|
1506
|
+
try {
|
|
1507
|
+
return readdirSync(dir, { withFileTypes: true });
|
|
1508
|
+
} catch {
|
|
1509
|
+
return [];
|
|
1557
1510
|
}
|
|
1558
|
-
walk(input, "", config, issues, surface);
|
|
1559
|
-
return {
|
|
1560
|
-
config,
|
|
1561
|
-
issues
|
|
1562
|
-
};
|
|
1563
1511
|
}
|
|
1564
|
-
function
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
if (
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
continue;
|
|
1586
|
-
}
|
|
1587
|
-
const enabled = groupBooleanKey(path);
|
|
1588
|
-
if (enabled && typeof value === "boolean") {
|
|
1589
|
-
target[name] = { enabled: value };
|
|
1512
|
+
function kindOf(entry, full) {
|
|
1513
|
+
if (entry.isDirectory()) return "dir";
|
|
1514
|
+
if (entry.isFile()) return "file";
|
|
1515
|
+
const stat = statOrNull(full);
|
|
1516
|
+
if (!stat) return null;
|
|
1517
|
+
return stat.isDirectory() ? "dir" : "file";
|
|
1518
|
+
}
|
|
1519
|
+
function isNestedProject(dir) {
|
|
1520
|
+
return existsSync(join(dir, "package.json"));
|
|
1521
|
+
}
|
|
1522
|
+
function walkJs(dir, include, readmitted, onNestedProject) {
|
|
1523
|
+
const out = [];
|
|
1524
|
+
for (const entry of entriesOf(dir)) {
|
|
1525
|
+
const name = entry.name;
|
|
1526
|
+
const full = join(dir, name);
|
|
1527
|
+
const kind = kindOf(entry, full);
|
|
1528
|
+
if (kind === null) continue;
|
|
1529
|
+
if (kind === "dir") {
|
|
1530
|
+
const skipped = name === NODE_MODULES;
|
|
1531
|
+
if (!skipped && !readmitted && isNestedProject(full)) {
|
|
1532
|
+
onNestedProject?.(full);
|
|
1590
1533
|
continue;
|
|
1591
1534
|
}
|
|
1535
|
+
if (skipped && !include.some((pattern) => reachesInto(pattern, full))) continue;
|
|
1536
|
+
out.push(...walkJs(full, include, readmitted || skipped, onNestedProject));
|
|
1537
|
+
} else if (isCollectableJs(name)) {
|
|
1538
|
+
if (readmitted && !include.some((pattern) => matchesPath(pattern, full))) continue;
|
|
1539
|
+
out.push(full);
|
|
1592
1540
|
}
|
|
1593
|
-
issues.push({
|
|
1594
|
-
path,
|
|
1595
|
-
message: unknownKeyMessage(path, surface)
|
|
1596
|
-
});
|
|
1597
1541
|
}
|
|
1542
|
+
return out;
|
|
1598
1543
|
}
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
1544
|
+
const SOURCE_MAP_RE = /\.(?:[cm]?js|css)\.map$/;
|
|
1545
|
+
function collectFiles(dir, accept) {
|
|
1546
|
+
if (!existsSync(dir)) return [];
|
|
1547
|
+
const out = [];
|
|
1548
|
+
for (const entry of entriesOf(dir)) {
|
|
1549
|
+
const name = entry.name;
|
|
1550
|
+
const full = join(dir, name);
|
|
1551
|
+
const kind = kindOf(entry, full);
|
|
1552
|
+
if (kind === null) continue;
|
|
1553
|
+
if (kind === "dir") out.push(...collectFiles(full, accept));
|
|
1554
|
+
else if (accept(name)) out.push(full);
|
|
1605
1555
|
}
|
|
1606
1556
|
return out;
|
|
1607
1557
|
}
|
|
1608
|
-
function
|
|
1609
|
-
return
|
|
1558
|
+
function collectSourceMaps(dir) {
|
|
1559
|
+
return collectFiles(dir, (name) => SOURCE_MAP_RE.test(name));
|
|
1610
1560
|
}
|
|
1611
|
-
function
|
|
1612
|
-
return
|
|
1561
|
+
function collectStylesheets(dir) {
|
|
1562
|
+
return collectFiles(dir, (name) => name.endsWith(".css"));
|
|
1613
1563
|
}
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1564
|
+
|
|
1565
|
+
//#endregion
|
|
1566
|
+
//#region src/notices.ts
|
|
1567
|
+
const NOTICE_MESSAGE_LIMIT = 500;
|
|
1568
|
+
const NOTICE_LIMIT = 5;
|
|
1569
|
+
const NOTICE_CODE_LIMIT = 64;
|
|
1570
|
+
const NOTICE_HOSTS = new Set(["afterpack.dev", "www.afterpack.dev"]);
|
|
1571
|
+
const ESC = 27;
|
|
1572
|
+
const BEL = 7;
|
|
1573
|
+
const C1_CSI = 155;
|
|
1574
|
+
const C1_OSC = 157;
|
|
1575
|
+
function isControl(code) {
|
|
1576
|
+
return code < 32 || code >= 127 && code <= 159;
|
|
1577
|
+
}
|
|
1578
|
+
function isInvisibleFormat(code) {
|
|
1579
|
+
return code === 1564 || code >= 8203 && code <= 8207 || code >= 8234 && code <= 8238 || code >= 8288 && code <= 8297 || code === 65279;
|
|
1580
|
+
}
|
|
1581
|
+
function skipCsi(text, from) {
|
|
1582
|
+
let i = from;
|
|
1583
|
+
while (i < text.length) {
|
|
1584
|
+
const c = text.charCodeAt(i);
|
|
1585
|
+
i += 1;
|
|
1586
|
+
if (c >= 64 && c <= 126) return i;
|
|
1619
1587
|
}
|
|
1620
|
-
return
|
|
1588
|
+
return i;
|
|
1621
1589
|
}
|
|
1622
|
-
function
|
|
1623
|
-
|
|
1590
|
+
function skipOsc(text, from) {
|
|
1591
|
+
let i = from;
|
|
1592
|
+
while (i < text.length) {
|
|
1593
|
+
const c = text.charCodeAt(i);
|
|
1594
|
+
if (c === BEL) return i + 1;
|
|
1595
|
+
if (c === ESC) return text.charCodeAt(i + 1) === 92 ? i + 2 : i + 1;
|
|
1596
|
+
if (c === 156) return i + 1;
|
|
1597
|
+
i += 1;
|
|
1598
|
+
}
|
|
1599
|
+
return i;
|
|
1624
1600
|
}
|
|
1625
|
-
function
|
|
1626
|
-
|
|
1627
|
-
let
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1601
|
+
function stripTerminalControls(text) {
|
|
1602
|
+
let out = "";
|
|
1603
|
+
let i = 0;
|
|
1604
|
+
while (i < text.length) {
|
|
1605
|
+
const c = text.charCodeAt(i);
|
|
1606
|
+
if (c === ESC) {
|
|
1607
|
+
const next = text.charCodeAt(i + 1);
|
|
1608
|
+
if (next === 91) i = skipCsi(text, i + 2);
|
|
1609
|
+
else if (next === 93) i = skipOsc(text, i + 2);
|
|
1610
|
+
else i += Number.isNaN(next) ? 1 : 2;
|
|
1611
|
+
continue;
|
|
1612
|
+
}
|
|
1613
|
+
if (c === C1_CSI) {
|
|
1614
|
+
i = skipCsi(text, i + 1);
|
|
1615
|
+
continue;
|
|
1616
|
+
}
|
|
1617
|
+
if (c === C1_OSC) {
|
|
1618
|
+
i = skipOsc(text, i + 1);
|
|
1619
|
+
continue;
|
|
1620
|
+
}
|
|
1621
|
+
if (isControl(c)) {
|
|
1622
|
+
out += c === 9 || c === 10 || c === 13 ? " " : "";
|
|
1623
|
+
i += 1;
|
|
1624
|
+
continue;
|
|
1625
|
+
}
|
|
1626
|
+
if (c === 8232 || c === 8233) {
|
|
1627
|
+
out += " ";
|
|
1628
|
+
i += 1;
|
|
1629
|
+
continue;
|
|
1630
|
+
}
|
|
1631
|
+
if (isInvisibleFormat(c)) {
|
|
1632
|
+
i += 1;
|
|
1633
|
+
continue;
|
|
1634
|
+
}
|
|
1635
|
+
out += text[i];
|
|
1636
|
+
i += 1;
|
|
1631
1637
|
}
|
|
1632
|
-
|
|
1638
|
+
return out;
|
|
1633
1639
|
}
|
|
1634
|
-
function
|
|
1635
|
-
|
|
1636
|
-
|
|
1637
|
-
|
|
1638
|
-
|
|
1639
|
-
|
|
1640
|
-
|
|
1640
|
+
function sanitizeServerText(value, limit = NOTICE_MESSAGE_LIMIT) {
|
|
1641
|
+
if (typeof value !== "string") return "";
|
|
1642
|
+
const clean = stripTerminalControls(value).replace(/\s+/g, " ").trim();
|
|
1643
|
+
if (clean.length <= limit) return clean;
|
|
1644
|
+
const chars = Array.from(clean);
|
|
1645
|
+
return chars.length > limit ? chars.slice(0, limit).join("") : clean;
|
|
1646
|
+
}
|
|
1647
|
+
function sanitizeNoticeUrl(value) {
|
|
1648
|
+
if (typeof value !== "string") return null;
|
|
1649
|
+
let url;
|
|
1650
|
+
try {
|
|
1651
|
+
url = new URL(value.trim());
|
|
1652
|
+
} catch {
|
|
1653
|
+
return null;
|
|
1654
|
+
}
|
|
1655
|
+
if (url.protocol !== "https:") return null;
|
|
1656
|
+
if (!NOTICE_HOSTS.has(url.hostname) || url.port !== "") return null;
|
|
1657
|
+
if (url.username !== "" || url.password !== "") return null;
|
|
1658
|
+
const href = url.href;
|
|
1659
|
+
return href.length <= NOTICE_MESSAGE_LIMIT ? href : null;
|
|
1660
|
+
}
|
|
1661
|
+
function noticeSeverity(value) {
|
|
1662
|
+
if (value === "info") return "info";
|
|
1663
|
+
if (value === "error" || value === "critical") return "error";
|
|
1664
|
+
return "warning";
|
|
1665
|
+
}
|
|
1666
|
+
function sanitizeNotices(raw) {
|
|
1667
|
+
if (!Array.isArray(raw)) return [];
|
|
1668
|
+
const out = [];
|
|
1669
|
+
for (const entry of raw) {
|
|
1670
|
+
if (out.length >= NOTICE_LIMIT) break;
|
|
1671
|
+
if (typeof entry !== "object" || entry === null) continue;
|
|
1672
|
+
const n = entry;
|
|
1673
|
+
const message = sanitizeServerText(n.message);
|
|
1674
|
+
if (message === "") continue;
|
|
1675
|
+
out.push({
|
|
1676
|
+
severity: noticeSeverity(n.severity),
|
|
1677
|
+
code: sanitizeServerText(n.code, NOTICE_CODE_LIMIT),
|
|
1678
|
+
message,
|
|
1679
|
+
url: sanitizeNoticeUrl(n.url)
|
|
1680
|
+
});
|
|
1641
1681
|
}
|
|
1642
1682
|
return out;
|
|
1643
1683
|
}
|
|
1644
|
-
function
|
|
1645
|
-
const
|
|
1646
|
-
const
|
|
1647
|
-
return {
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
}),
|
|
1658
|
-
allowUnobfuscated: read("allowUnobfuscated"),
|
|
1659
|
-
telemetry: set({ enabled: read("telemetry.enabled") })
|
|
1660
|
-
},
|
|
1661
|
-
seed: read("seed"),
|
|
1662
|
-
preset: read("preset"),
|
|
1663
|
-
complexity: read("complexity"),
|
|
1664
|
-
regions: read("regions"),
|
|
1665
|
-
directives: {
|
|
1666
|
-
enabled: read("directives.enabled") ?? DIRECTIVES_ENABLED_DEFAULT,
|
|
1667
|
-
explicit: read("directives.enabled") !== void 0
|
|
1668
|
-
},
|
|
1669
|
-
build: set({ autorun: read("build.autorun") }),
|
|
1670
|
-
diagnostics: set({
|
|
1671
|
-
level: read("diagnostics.level"),
|
|
1672
|
-
format: read("diagnostics.format")
|
|
1673
|
-
}),
|
|
1674
|
-
paths: set({ include: read("paths.include") }),
|
|
1675
|
-
key: read("key")
|
|
1676
|
-
};
|
|
1684
|
+
function formatNotice(notice) {
|
|
1685
|
+
const head = notice.severity === "info" ? "AfterPack notice" : `AfterPack ${notice.severity}`;
|
|
1686
|
+
const tail = notice.url ? ` ${notice.url}` : "";
|
|
1687
|
+
return `${head}: ${notice.message}${tail}`;
|
|
1688
|
+
}
|
|
1689
|
+
function reportNotices(raw, logger, prefix = (m) => m) {
|
|
1690
|
+
const notices = sanitizeNotices(raw);
|
|
1691
|
+
for (const notice of notices) {
|
|
1692
|
+
const line = prefix(formatNotice(notice));
|
|
1693
|
+
if (notice.severity === "info" || !logger.warn) logger.log(line);
|
|
1694
|
+
else logger.warn(line);
|
|
1695
|
+
}
|
|
1696
|
+
return notices;
|
|
1677
1697
|
}
|
|
1678
1698
|
|
|
1679
1699
|
//#endregion
|
|
1680
1700
|
//#region src/compat.ts
|
|
1681
1701
|
const MIN_CORE_VERSION = "0.2.0";
|
|
1702
|
+
const SOURCE_TYPE_MIN_CORE_VERSION = "0.2.3";
|
|
1682
1703
|
const CORE_PACKAGE = "@afterpack/core";
|
|
1683
1704
|
const VERSION_PATTERN$1 = /^\d{1,9}\.\d{1,9}\.\d{1,9}(?:[-+][0-9A-Za-z.+-]{1,64})?$/;
|
|
1684
1705
|
const PACKAGE_NAME_PATTERN = /^(?:@[a-z0-9][a-z0-9._-]{0,63}\/)?[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
@@ -1750,6 +1771,9 @@ function isBelowVersion(version, minimum) {
|
|
|
1750
1771
|
for (let i = 0; i < 3; i++) if (have[i] !== need[i]) return have[i] < need[i];
|
|
1751
1772
|
return false;
|
|
1752
1773
|
}
|
|
1774
|
+
function coreSupportsSourceType(coreVersion) {
|
|
1775
|
+
return releaseTriple(coreVersion) !== null && !isBelowVersion(coreVersion, SOURCE_TYPE_MIN_CORE_VERSION);
|
|
1776
|
+
}
|
|
1753
1777
|
const CLI_PACKAGE = "afterpack";
|
|
1754
1778
|
function updateCommand(identity, minVersion) {
|
|
1755
1779
|
const core = `${CORE_PACKAGE}@${safeVersionString(minVersion) ?? "latest"}`;
|
|
@@ -2426,6 +2450,7 @@ function buildEngineConfig(options) {
|
|
|
2426
2450
|
if (options.complexity !== void 0) defaults.complexity = options.complexity;
|
|
2427
2451
|
if (options.preset !== void 0) defaults.preset = options.preset;
|
|
2428
2452
|
else if (options.complexity === void 0) defaults.preset = DEFAULT_PRESET;
|
|
2453
|
+
if (options.sourceType !== void 0) defaults.sourceType = options.sourceType;
|
|
2429
2454
|
const config = mergeInto({
|
|
2430
2455
|
...defaults,
|
|
2431
2456
|
sourceMap,
|
|
@@ -3489,7 +3514,7 @@ function fmtElapsed(ms) {
|
|
|
3489
3514
|
function formatPassSummary(input, style, colorGlyph = (glyph) => glyph) {
|
|
3490
3515
|
const head = style === "cli" ? colorGlyph("✓") : `[${input.label}]`;
|
|
3491
3516
|
const files = input.fileCount === 1 ? "file" : "files";
|
|
3492
|
-
const tail =
|
|
3517
|
+
const tail = input.noOpCount > 0 ? ` · ${input.noOpCount} no-op (unchanged)` : "";
|
|
3493
3518
|
return `${head} Protected ${input.fileCount} ${files} · ${fmtBytes(input.inputBytes)} → ${fmtBytes(input.outputBytes)}${tail} · ${fmtElapsed(input.elapsedMs)}`;
|
|
3494
3519
|
}
|
|
3495
3520
|
|
|
@@ -3832,7 +3857,7 @@ function fileFailure(f, source) {
|
|
|
3832
3857
|
if (reason) return reason;
|
|
3833
3858
|
return f.status === "failure" ? "empty output" : `the engine reported status "${sanitizeServerText(f.status, 32)}"`;
|
|
3834
3859
|
}
|
|
3835
|
-
if (
|
|
3860
|
+
if (f.unobfuscated === true) return "the engine could not obfuscate it and returned the original source — update @afterpack/core";
|
|
3836
3861
|
if (f.code === "" && source.trim() !== "") return sanitizeServerText(f.error) || "empty output";
|
|
3837
3862
|
return null;
|
|
3838
3863
|
}
|
|
@@ -3967,11 +3992,14 @@ async function runObfuscationPass(options) {
|
|
|
3967
3992
|
env,
|
|
3968
3993
|
cwd
|
|
3969
3994
|
});
|
|
3995
|
+
const localEngineVersion = await readEngineVersion(engine);
|
|
3996
|
+
const derivedSourceType = options.sourceType !== void 0 && coreSupportsSourceType(localEngineVersion ?? options.client?.coreVersion) ? options.sourceType : void 0;
|
|
3970
3997
|
const engineConfig = buildEngineConfig({
|
|
3971
3998
|
policy,
|
|
3972
3999
|
seed,
|
|
3973
4000
|
preset: options.preset,
|
|
3974
4001
|
complexity: options.complexity,
|
|
4002
|
+
sourceType: derivedSourceType,
|
|
3975
4003
|
regions: capture.regions,
|
|
3976
4004
|
engine: options.engineConfig,
|
|
3977
4005
|
renameGlobals: capture.renameGlobals
|
|
@@ -4009,7 +4037,7 @@ async function runObfuscationPass(options) {
|
|
|
4009
4037
|
if (collected.unknownFiles > 0 && batch.source === "cloud") logger.warn(prefix("engine diagnostics are not returned on the Pro Cloud path — this build's diagnostics were recorded server-side."));
|
|
4010
4038
|
const telemetry = options.telemetry;
|
|
4011
4039
|
const telemetryEnabled = telemetry != null && resolveTelemetryEnabled(artifactOptions.telemetry?.enabled, env);
|
|
4012
|
-
const engineVersion = (batch.source === "cloud" ? safeVersionString(batch.engineVersion) : null) ??
|
|
4040
|
+
const engineVersion = (batch.source === "cloud" ? safeVersionString(batch.engineVersion) : null) ?? localEngineVersion;
|
|
4013
4041
|
if (telemetry && telemetryEnabled) {
|
|
4014
4042
|
const facts = {
|
|
4015
4043
|
label,
|
|
@@ -4029,7 +4057,6 @@ async function runObfuscationPass(options) {
|
|
|
4029
4057
|
const outputs = [];
|
|
4030
4058
|
let inputBytes = 0;
|
|
4031
4059
|
let outputBytes = 0;
|
|
4032
|
-
const unobfuscatedFiles = [];
|
|
4033
4060
|
let noOp = 0;
|
|
4034
4061
|
const transformedFiles = [];
|
|
4035
4062
|
const verified = [];
|
|
@@ -4040,8 +4067,7 @@ async function runObfuscationPass(options) {
|
|
|
4040
4067
|
if (failure !== null) throw new Error(prefix(`failed to obfuscate ${f.path}: ${failure}`));
|
|
4041
4068
|
inputBytes += Buffer.byteLength(source);
|
|
4042
4069
|
outputBytes += Buffer.byteLength(f.code);
|
|
4043
|
-
if (f.
|
|
4044
|
-
else if (f.code === source) noOp += 1;
|
|
4070
|
+
if (f.code === source) noOp += 1;
|
|
4045
4071
|
else transformedFiles.push(f.path);
|
|
4046
4072
|
if (policy.protectionMap && f.protectionMap != null) protectionMapDocs.push(f.protectionMap);
|
|
4047
4073
|
verified.push({
|
|
@@ -4049,8 +4075,6 @@ async function runObfuscationPass(options) {
|
|
|
4049
4075
|
source
|
|
4050
4076
|
});
|
|
4051
4077
|
}
|
|
4052
|
-
if (unobfuscatedFiles.length > 0) if (artifactOptions.allowUnobfuscated === true) for (const name of unobfuscatedFiles) logger.warn(prefix(`${name} could not be obfuscated and SHIPPED AS CLEARTEXT (allowUnobfuscated:true). This is an engine bug — please report it.`));
|
|
4053
|
-
else throw new Error(prefix(`${unobfuscatedFiles.length} file(s) could not be obfuscated and would ship as cleartext: ${unobfuscatedFiles.join(", ")} — fix the engine or set allowUnobfuscated:true`));
|
|
4054
4078
|
const writtenFiles = [];
|
|
4055
4079
|
const emittedFiles = [];
|
|
4056
4080
|
for (const { result: f, source } of verified) {
|
|
@@ -4134,7 +4158,6 @@ async function runObfuscationPass(options) {
|
|
|
4134
4158
|
fileCount: files.length,
|
|
4135
4159
|
inputBytes,
|
|
4136
4160
|
outputBytes,
|
|
4137
|
-
unobfuscatedCount: unobfuscatedFiles.length,
|
|
4138
4161
|
noOpCount: noOp,
|
|
4139
4162
|
elapsedMs: totalMs
|
|
4140
4163
|
}, style, options.colorGlyph) + seedSuffix);
|
|
@@ -4328,4 +4351,4 @@ function resolvePluginConfig(input) {
|
|
|
4328
4351
|
}
|
|
4329
4352
|
|
|
4330
4353
|
//#endregion
|
|
4331
|
-
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, collectStylesheets, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, ensureAfterpackGitignore, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, stripBundleCssSourceMaps, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, withoutCssSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
|
|
4354
|
+
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, collectStylesheets, createTelemetryReporter, decodeDataUri, discoverInputSourceMap, ensureAfterpackGitignore, extractSourceMappingURL, findUpward, getPath, installedRequiredLine, loadConfigFile, mergeConfig, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, sanitizeNotices, scanDirectives, serverAddsInfo, sha256Of, sourceTypeForBundle, sourceTypeForOutputFormat, stripBundleCssSourceMaps, toEngineConfig, toPluginOptions, validateConfig, verifyProtectionReceipt, withSourceMappingURL, withoutCssSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeProtectionReceipt };
|