@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.cjs
CHANGED
|
@@ -763,418 +763,6 @@ function warnIfPublicPath(artifactPath, logger = DEFAULT_LOGGER) {
|
|
|
763
763
|
return true;
|
|
764
764
|
}
|
|
765
765
|
|
|
766
|
-
//#endregion
|
|
767
|
-
//#region src/source-map.ts
|
|
768
|
-
const SOURCE_MAPPING_URL_RE = /\/\/[#@]\s*sourceMappingURL=(\S+)\s*$/gm;
|
|
769
|
-
const SOURCE_MAPPING_URL_LINE_RE = /^[ \t]*\/\/[#@]\s*sourceMappingURL=\S+[ \t]*\r?\n?/gm;
|
|
770
|
-
const CSS_SOURCE_MAPPING_URL_RE = /[ \t]*\/\*[#@]\s*sourceMappingURL=[^\s*]+\s*\*\/\s*$/;
|
|
771
|
-
function withSourceMappingURL(code, url) {
|
|
772
|
-
const stripped = code.replace(SOURCE_MAPPING_URL_LINE_RE, "");
|
|
773
|
-
if (url == null) return stripped;
|
|
774
|
-
const separator = stripped.length > 0 && !stripped.endsWith("\n") ? "\n" : "";
|
|
775
|
-
return `${stripped}${separator}//# sourceMappingURL=${url}\n`;
|
|
776
|
-
}
|
|
777
|
-
function withoutCssSourceMappingURL(css) {
|
|
778
|
-
return css.replace(CSS_SOURCE_MAPPING_URL_RE, "");
|
|
779
|
-
}
|
|
780
|
-
function extractSourceMappingURL(code) {
|
|
781
|
-
let last = null;
|
|
782
|
-
for (const match of code.matchAll(SOURCE_MAPPING_URL_RE)) last = match[1];
|
|
783
|
-
return last;
|
|
784
|
-
}
|
|
785
|
-
function isRemoteSourceMappingURL(url) {
|
|
786
|
-
return /^https?:\/\//i.test(url) || url.startsWith("//");
|
|
787
|
-
}
|
|
788
|
-
function decodeDataUri(url) {
|
|
789
|
-
if (!url.startsWith("data:")) return null;
|
|
790
|
-
const comma = url.indexOf(",");
|
|
791
|
-
if (comma === -1) return null;
|
|
792
|
-
const meta = url.slice(5, comma);
|
|
793
|
-
const payload = url.slice(comma + 1);
|
|
794
|
-
try {
|
|
795
|
-
if (/;base64/i.test(meta)) return Buffer.from(payload, "base64").toString("utf8");
|
|
796
|
-
return decodeURIComponent(payload);
|
|
797
|
-
} catch {
|
|
798
|
-
return null;
|
|
799
|
-
}
|
|
800
|
-
}
|
|
801
|
-
function discoverInputSourceMap(jsPath, code) {
|
|
802
|
-
const adjacent = `${jsPath}.map`;
|
|
803
|
-
if ((0, node_fs.existsSync)(adjacent)) try {
|
|
804
|
-
return (0, node_fs.readFileSync)(adjacent, "utf8");
|
|
805
|
-
} catch {}
|
|
806
|
-
let source = code;
|
|
807
|
-
if (source == null) try {
|
|
808
|
-
source = (0, node_fs.readFileSync)(jsPath, "utf8");
|
|
809
|
-
} catch {
|
|
810
|
-
return null;
|
|
811
|
-
}
|
|
812
|
-
const url = extractSourceMappingURL(source);
|
|
813
|
-
if (url == null) return null;
|
|
814
|
-
if (url.startsWith("data:")) return decodeDataUri(url);
|
|
815
|
-
if (isRemoteSourceMappingURL(url)) return null;
|
|
816
|
-
let mapPath;
|
|
817
|
-
try {
|
|
818
|
-
mapPath = (0, node_path.isAbsolute)(url) ? url : (0, node_path.resolve)((0, node_path.dirname)(jsPath), decodeURIComponent(url));
|
|
819
|
-
} catch {
|
|
820
|
-
return null;
|
|
821
|
-
}
|
|
822
|
-
if (!(0, node_fs.existsSync)(mapPath)) return null;
|
|
823
|
-
try {
|
|
824
|
-
return (0, node_fs.readFileSync)(mapPath, "utf8");
|
|
825
|
-
} catch {
|
|
826
|
-
return null;
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
|
|
830
|
-
//#endregion
|
|
831
|
-
//#region src/bundle.ts
|
|
832
|
-
const BUNDLE_JS_RE = /\.[cm]?js$/;
|
|
833
|
-
const CSS_MAP_RE = /\.css\.map$/;
|
|
834
|
-
function collectBundleJs(bundle, outDir) {
|
|
835
|
-
const files = [];
|
|
836
|
-
const inputs = new Map();
|
|
837
|
-
const entries = new Map();
|
|
838
|
-
for (const [fileName, entry] of Object.entries(bundle)) {
|
|
839
|
-
if (!BUNDLE_JS_RE.test(fileName)) continue;
|
|
840
|
-
const source = entry.type === "chunk" ? entry.code : typeof entry.source === "string" ? entry.source : void 0;
|
|
841
|
-
if (source === void 0) continue;
|
|
842
|
-
const filePath = (0, node_path.resolve)(outDir, fileName);
|
|
843
|
-
files.push(filePath);
|
|
844
|
-
entries.set(filePath, entry);
|
|
845
|
-
inputs.set(filePath, {
|
|
846
|
-
source,
|
|
847
|
-
sourceMap: entry.map ? entry.map.toString() : null
|
|
848
|
-
});
|
|
849
|
-
}
|
|
850
|
-
return {
|
|
851
|
-
files,
|
|
852
|
-
inputs,
|
|
853
|
-
entries
|
|
854
|
-
};
|
|
855
|
-
}
|
|
856
|
-
function dataUri(json) {
|
|
857
|
-
return `data:application/json;charset=utf-8;base64,${Buffer.from(json, "utf8").toString("base64")}`;
|
|
858
|
-
}
|
|
859
|
-
function applyBundleOutput(bundle, entry, out, policy) {
|
|
860
|
-
if (entry.type !== "chunk") {
|
|
861
|
-
entry.source = out.code;
|
|
862
|
-
return;
|
|
863
|
-
}
|
|
864
|
-
const mapName = entry.sourcemapFileName ?? null;
|
|
865
|
-
const inlineMap = mapName == null && entry.map != null;
|
|
866
|
-
const emitMap = policy.sourceMap && out.sourceMap != null;
|
|
867
|
-
let url = null;
|
|
868
|
-
if (emitMap && out.sourceMap != null) {
|
|
869
|
-
if (mapName != null && bundle[mapName]) {
|
|
870
|
-
bundle[mapName].source = out.sourceMap;
|
|
871
|
-
url = (0, node_path.basename)(mapName);
|
|
872
|
-
} else if (inlineMap) url = dataUri(out.sourceMap);
|
|
873
|
-
} else {
|
|
874
|
-
if (mapName != null) delete bundle[mapName];
|
|
875
|
-
entry.map = null;
|
|
876
|
-
}
|
|
877
|
-
entry.code = withSourceMappingURL(out.code, policy.emitSourceMappingURL ? url : null);
|
|
878
|
-
}
|
|
879
|
-
function stripBundleCssSourceMaps(bundle) {
|
|
880
|
-
for (const [fileName, entry] of Object.entries(bundle)) {
|
|
881
|
-
if (CSS_MAP_RE.test(fileName)) {
|
|
882
|
-
delete bundle[fileName];
|
|
883
|
-
continue;
|
|
884
|
-
}
|
|
885
|
-
if (entry.type !== "asset" || !fileName.endsWith(".css") || entry.source === void 0) continue;
|
|
886
|
-
const css = typeof entry.source === "string" ? entry.source : Buffer.from(entry.source).toString("utf8");
|
|
887
|
-
const stripped = withoutCssSourceMappingURL(css);
|
|
888
|
-
if (stripped !== css) entry.source = stripped;
|
|
889
|
-
}
|
|
890
|
-
}
|
|
891
|
-
|
|
892
|
-
//#endregion
|
|
893
|
-
//#region src/glob.ts
|
|
894
|
-
function normalize(value) {
|
|
895
|
-
return value.includes("\\") ? value.replaceAll("\\", "/") : value;
|
|
896
|
-
}
|
|
897
|
-
function segments(value) {
|
|
898
|
-
return value.split("/").filter((part) => part !== "");
|
|
899
|
-
}
|
|
900
|
-
function isAnchored(pattern) {
|
|
901
|
-
if (pattern.startsWith("/")) return true;
|
|
902
|
-
return pattern.length >= 2 && pattern[1] === ":" && /^[A-Za-z]$/.test(pattern[0]);
|
|
903
|
-
}
|
|
904
|
-
function segmentMatches(pattern, seg) {
|
|
905
|
-
if (!pattern.includes("*") && !pattern.includes("?")) return pattern === seg;
|
|
906
|
-
const p = [...pattern];
|
|
907
|
-
const s = [...seg];
|
|
908
|
-
let pi = 0;
|
|
909
|
-
let si = 0;
|
|
910
|
-
let star = -1;
|
|
911
|
-
let starSi = 0;
|
|
912
|
-
while (si < s.length) if (pi < p.length && p[pi] === "*") {
|
|
913
|
-
star = pi;
|
|
914
|
-
starSi = si;
|
|
915
|
-
pi += 1;
|
|
916
|
-
} else if (pi < p.length && (p[pi] === "?" || p[pi] === s[si])) {
|
|
917
|
-
pi += 1;
|
|
918
|
-
si += 1;
|
|
919
|
-
} else if (star >= 0) {
|
|
920
|
-
pi = star + 1;
|
|
921
|
-
starSi += 1;
|
|
922
|
-
si = starSi;
|
|
923
|
-
} else return false;
|
|
924
|
-
return p.slice(pi).every((c) => c === "*");
|
|
925
|
-
}
|
|
926
|
-
function segmentsMatch(pattern, path) {
|
|
927
|
-
let pi = 0;
|
|
928
|
-
let si = 0;
|
|
929
|
-
let star = -1;
|
|
930
|
-
let starSi = 0;
|
|
931
|
-
while (si < path.length) if (pi < pattern.length && pattern[pi] === "**") {
|
|
932
|
-
star = pi;
|
|
933
|
-
starSi = si;
|
|
934
|
-
pi += 1;
|
|
935
|
-
} else if (pi < pattern.length && segmentMatches(pattern[pi], path[si])) {
|
|
936
|
-
pi += 1;
|
|
937
|
-
si += 1;
|
|
938
|
-
} else if (star >= 0) {
|
|
939
|
-
pi = star + 1;
|
|
940
|
-
starSi += 1;
|
|
941
|
-
si = starSi;
|
|
942
|
-
} else return false;
|
|
943
|
-
return pattern.slice(pi).every((s) => s === "**");
|
|
944
|
-
}
|
|
945
|
-
function matchesPath(pattern, path) {
|
|
946
|
-
const pat = normalize(pattern);
|
|
947
|
-
const parts = segments(pat);
|
|
948
|
-
if (parts.length === 0) return false;
|
|
949
|
-
const segs = segments(normalize(path));
|
|
950
|
-
if (isAnchored(pat)) return segmentsMatch(parts, segs);
|
|
951
|
-
for (let i = 0; i <= segs.length; i++) if (segmentsMatch(parts, segs.slice(i))) return true;
|
|
952
|
-
return false;
|
|
953
|
-
}
|
|
954
|
-
function reachesInto(pattern, dir) {
|
|
955
|
-
const pat = normalize(pattern);
|
|
956
|
-
const parts = segments(pat);
|
|
957
|
-
if (parts.length === 0) return false;
|
|
958
|
-
if (!isAnchored(pat)) return true;
|
|
959
|
-
for (let k = 1; k <= parts.length; k++) if (matchesPath(`/${parts.slice(0, k).join("/")}`, dir)) return true;
|
|
960
|
-
return false;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
//#endregion
|
|
964
|
-
//#region src/collect.ts
|
|
965
|
-
const BACKUP_RE = /\.backup\.[0-9a-f]{8}\.[cm]?js$/;
|
|
966
|
-
const NODE_MODULES = "node_modules";
|
|
967
|
-
function isCollectableJs(name) {
|
|
968
|
-
if (BACKUP_RE.test(name)) return false;
|
|
969
|
-
return name.endsWith(".js") || name.endsWith(".mjs") || name.endsWith(".cjs");
|
|
970
|
-
}
|
|
971
|
-
function statOrNull(path) {
|
|
972
|
-
try {
|
|
973
|
-
return (0, node_fs.statSync)(path);
|
|
974
|
-
} catch {
|
|
975
|
-
return null;
|
|
976
|
-
}
|
|
977
|
-
}
|
|
978
|
-
function collectJsFiles(target, options = {}) {
|
|
979
|
-
const stat = statOrNull(target);
|
|
980
|
-
if (!stat) return [];
|
|
981
|
-
if (!stat.isDirectory()) return isCollectableJs((0, node_path.basename)(target)) ? [target] : [];
|
|
982
|
-
return walkJs(target, options.include ?? [], false, options.onNestedProject);
|
|
983
|
-
}
|
|
984
|
-
function entriesOf(dir) {
|
|
985
|
-
try {
|
|
986
|
-
return (0, node_fs.readdirSync)(dir, { withFileTypes: true });
|
|
987
|
-
} catch {
|
|
988
|
-
return [];
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
function kindOf(entry, full) {
|
|
992
|
-
if (entry.isDirectory()) return "dir";
|
|
993
|
-
if (entry.isFile()) return "file";
|
|
994
|
-
const stat = statOrNull(full);
|
|
995
|
-
if (!stat) return null;
|
|
996
|
-
return stat.isDirectory() ? "dir" : "file";
|
|
997
|
-
}
|
|
998
|
-
function isNestedProject(dir) {
|
|
999
|
-
return (0, node_fs.existsSync)((0, node_path.join)(dir, "package.json"));
|
|
1000
|
-
}
|
|
1001
|
-
function walkJs(dir, include, readmitted, onNestedProject) {
|
|
1002
|
-
const out = [];
|
|
1003
|
-
for (const entry of entriesOf(dir)) {
|
|
1004
|
-
const name = entry.name;
|
|
1005
|
-
const full = (0, node_path.join)(dir, name);
|
|
1006
|
-
const kind = kindOf(entry, full);
|
|
1007
|
-
if (kind === null) continue;
|
|
1008
|
-
if (kind === "dir") {
|
|
1009
|
-
const skipped = name === NODE_MODULES;
|
|
1010
|
-
if (!skipped && !readmitted && isNestedProject(full)) {
|
|
1011
|
-
onNestedProject?.(full);
|
|
1012
|
-
continue;
|
|
1013
|
-
}
|
|
1014
|
-
if (skipped && !include.some((pattern) => reachesInto(pattern, full))) continue;
|
|
1015
|
-
out.push(...walkJs(full, include, readmitted || skipped, onNestedProject));
|
|
1016
|
-
} else if (isCollectableJs(name)) {
|
|
1017
|
-
if (readmitted && !include.some((pattern) => matchesPath(pattern, full))) continue;
|
|
1018
|
-
out.push(full);
|
|
1019
|
-
}
|
|
1020
|
-
}
|
|
1021
|
-
return out;
|
|
1022
|
-
}
|
|
1023
|
-
const SOURCE_MAP_RE = /\.(?:[cm]?js|css)\.map$/;
|
|
1024
|
-
function collectFiles(dir, accept) {
|
|
1025
|
-
if (!(0, node_fs.existsSync)(dir)) return [];
|
|
1026
|
-
const out = [];
|
|
1027
|
-
for (const entry of entriesOf(dir)) {
|
|
1028
|
-
const name = entry.name;
|
|
1029
|
-
const full = (0, node_path.join)(dir, name);
|
|
1030
|
-
const kind = kindOf(entry, full);
|
|
1031
|
-
if (kind === null) continue;
|
|
1032
|
-
if (kind === "dir") out.push(...collectFiles(full, accept));
|
|
1033
|
-
else if (accept(name)) out.push(full);
|
|
1034
|
-
}
|
|
1035
|
-
return out;
|
|
1036
|
-
}
|
|
1037
|
-
function collectSourceMaps(dir) {
|
|
1038
|
-
return collectFiles(dir, (name) => SOURCE_MAP_RE.test(name));
|
|
1039
|
-
}
|
|
1040
|
-
function collectStylesheets(dir) {
|
|
1041
|
-
return collectFiles(dir, (name) => name.endsWith(".css"));
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
//#endregion
|
|
1045
|
-
//#region src/notices.ts
|
|
1046
|
-
const NOTICE_MESSAGE_LIMIT = 500;
|
|
1047
|
-
const NOTICE_LIMIT = 5;
|
|
1048
|
-
const NOTICE_CODE_LIMIT = 64;
|
|
1049
|
-
const NOTICE_HOSTS = new Set(["afterpack.dev", "www.afterpack.dev"]);
|
|
1050
|
-
const ESC = 27;
|
|
1051
|
-
const BEL = 7;
|
|
1052
|
-
const C1_CSI = 155;
|
|
1053
|
-
const C1_OSC = 157;
|
|
1054
|
-
function isControl(code) {
|
|
1055
|
-
return code < 32 || code >= 127 && code <= 159;
|
|
1056
|
-
}
|
|
1057
|
-
function isInvisibleFormat(code) {
|
|
1058
|
-
return code === 1564 || code >= 8203 && code <= 8207 || code >= 8234 && code <= 8238 || code >= 8288 && code <= 8297 || code === 65279;
|
|
1059
|
-
}
|
|
1060
|
-
function skipCsi(text, from) {
|
|
1061
|
-
let i = from;
|
|
1062
|
-
while (i < text.length) {
|
|
1063
|
-
const c = text.charCodeAt(i);
|
|
1064
|
-
i += 1;
|
|
1065
|
-
if (c >= 64 && c <= 126) return i;
|
|
1066
|
-
}
|
|
1067
|
-
return i;
|
|
1068
|
-
}
|
|
1069
|
-
function skipOsc(text, from) {
|
|
1070
|
-
let i = from;
|
|
1071
|
-
while (i < text.length) {
|
|
1072
|
-
const c = text.charCodeAt(i);
|
|
1073
|
-
if (c === BEL) return i + 1;
|
|
1074
|
-
if (c === ESC) return text.charCodeAt(i + 1) === 92 ? i + 2 : i + 1;
|
|
1075
|
-
if (c === 156) return i + 1;
|
|
1076
|
-
i += 1;
|
|
1077
|
-
}
|
|
1078
|
-
return i;
|
|
1079
|
-
}
|
|
1080
|
-
function stripTerminalControls(text) {
|
|
1081
|
-
let out = "";
|
|
1082
|
-
let i = 0;
|
|
1083
|
-
while (i < text.length) {
|
|
1084
|
-
const c = text.charCodeAt(i);
|
|
1085
|
-
if (c === ESC) {
|
|
1086
|
-
const next = text.charCodeAt(i + 1);
|
|
1087
|
-
if (next === 91) i = skipCsi(text, i + 2);
|
|
1088
|
-
else if (next === 93) i = skipOsc(text, i + 2);
|
|
1089
|
-
else i += Number.isNaN(next) ? 1 : 2;
|
|
1090
|
-
continue;
|
|
1091
|
-
}
|
|
1092
|
-
if (c === C1_CSI) {
|
|
1093
|
-
i = skipCsi(text, i + 1);
|
|
1094
|
-
continue;
|
|
1095
|
-
}
|
|
1096
|
-
if (c === C1_OSC) {
|
|
1097
|
-
i = skipOsc(text, i + 1);
|
|
1098
|
-
continue;
|
|
1099
|
-
}
|
|
1100
|
-
if (isControl(c)) {
|
|
1101
|
-
out += c === 9 || c === 10 || c === 13 ? " " : "";
|
|
1102
|
-
i += 1;
|
|
1103
|
-
continue;
|
|
1104
|
-
}
|
|
1105
|
-
if (c === 8232 || c === 8233) {
|
|
1106
|
-
out += " ";
|
|
1107
|
-
i += 1;
|
|
1108
|
-
continue;
|
|
1109
|
-
}
|
|
1110
|
-
if (isInvisibleFormat(c)) {
|
|
1111
|
-
i += 1;
|
|
1112
|
-
continue;
|
|
1113
|
-
}
|
|
1114
|
-
out += text[i];
|
|
1115
|
-
i += 1;
|
|
1116
|
-
}
|
|
1117
|
-
return out;
|
|
1118
|
-
}
|
|
1119
|
-
function sanitizeServerText(value, limit = NOTICE_MESSAGE_LIMIT) {
|
|
1120
|
-
if (typeof value !== "string") return "";
|
|
1121
|
-
const clean = stripTerminalControls(value).replace(/\s+/g, " ").trim();
|
|
1122
|
-
if (clean.length <= limit) return clean;
|
|
1123
|
-
const chars = Array.from(clean);
|
|
1124
|
-
return chars.length > limit ? chars.slice(0, limit).join("") : clean;
|
|
1125
|
-
}
|
|
1126
|
-
function sanitizeNoticeUrl(value) {
|
|
1127
|
-
if (typeof value !== "string") return null;
|
|
1128
|
-
let url;
|
|
1129
|
-
try {
|
|
1130
|
-
url = new URL(value.trim());
|
|
1131
|
-
} catch {
|
|
1132
|
-
return null;
|
|
1133
|
-
}
|
|
1134
|
-
if (url.protocol !== "https:") return null;
|
|
1135
|
-
if (!NOTICE_HOSTS.has(url.hostname) || url.port !== "") return null;
|
|
1136
|
-
if (url.username !== "" || url.password !== "") return null;
|
|
1137
|
-
const href = url.href;
|
|
1138
|
-
return href.length <= NOTICE_MESSAGE_LIMIT ? href : null;
|
|
1139
|
-
}
|
|
1140
|
-
function noticeSeverity(value) {
|
|
1141
|
-
if (value === "info") return "info";
|
|
1142
|
-
if (value === "error" || value === "critical") return "error";
|
|
1143
|
-
return "warning";
|
|
1144
|
-
}
|
|
1145
|
-
function sanitizeNotices(raw) {
|
|
1146
|
-
if (!Array.isArray(raw)) return [];
|
|
1147
|
-
const out = [];
|
|
1148
|
-
for (const entry of raw) {
|
|
1149
|
-
if (out.length >= NOTICE_LIMIT) break;
|
|
1150
|
-
if (typeof entry !== "object" || entry === null) continue;
|
|
1151
|
-
const n = entry;
|
|
1152
|
-
const message = sanitizeServerText(n.message);
|
|
1153
|
-
if (message === "") continue;
|
|
1154
|
-
out.push({
|
|
1155
|
-
severity: noticeSeverity(n.severity),
|
|
1156
|
-
code: sanitizeServerText(n.code, NOTICE_CODE_LIMIT),
|
|
1157
|
-
message,
|
|
1158
|
-
url: sanitizeNoticeUrl(n.url)
|
|
1159
|
-
});
|
|
1160
|
-
}
|
|
1161
|
-
return out;
|
|
1162
|
-
}
|
|
1163
|
-
function formatNotice(notice) {
|
|
1164
|
-
const head = notice.severity === "info" ? "AfterPack notice" : `AfterPack ${notice.severity}`;
|
|
1165
|
-
const tail = notice.url ? ` ${notice.url}` : "";
|
|
1166
|
-
return `${head}: ${notice.message}${tail}`;
|
|
1167
|
-
}
|
|
1168
|
-
function reportNotices(raw, logger, prefix = (m) => m) {
|
|
1169
|
-
const notices = sanitizeNotices(raw);
|
|
1170
|
-
for (const notice of notices) {
|
|
1171
|
-
const line = prefix(formatNotice(notice));
|
|
1172
|
-
if (notice.severity === "info" || !logger.warn) logger.log(line);
|
|
1173
|
-
else logger.warn(line);
|
|
1174
|
-
}
|
|
1175
|
-
return notices;
|
|
1176
|
-
}
|
|
1177
|
-
|
|
1178
766
|
//#endregion
|
|
1179
767
|
//#region src/registry.ts
|
|
1180
768
|
const PRESET_VALUES = [
|
|
@@ -1184,6 +772,20 @@ const PRESET_VALUES = [
|
|
|
1184
772
|
"hard",
|
|
1185
773
|
"extreme"
|
|
1186
774
|
];
|
|
775
|
+
const SOURCE_TYPE_VALUES = [
|
|
776
|
+
"auto",
|
|
777
|
+
"module",
|
|
778
|
+
"script"
|
|
779
|
+
];
|
|
780
|
+
const MODULE_OUTPUT_FORMATS = new Set([
|
|
781
|
+
"es",
|
|
782
|
+
"esm",
|
|
783
|
+
"esmodule",
|
|
784
|
+
"module"
|
|
785
|
+
]);
|
|
786
|
+
function sourceTypeForOutputFormat(format) {
|
|
787
|
+
return typeof format === "string" && MODULE_OUTPUT_FORMATS.has(format.toLowerCase()) ? "module" : void 0;
|
|
788
|
+
}
|
|
1187
789
|
const TRANSFORM_KIND_VALUES = [
|
|
1188
790
|
"stringEncoding",
|
|
1189
791
|
"controlFlowFlatten",
|
|
@@ -1233,6 +835,18 @@ const CONFIG_KEYS = [
|
|
|
1233
835
|
},
|
|
1234
836
|
default: "light"
|
|
1235
837
|
},
|
|
838
|
+
{
|
|
839
|
+
path: "sourceType",
|
|
840
|
+
shape: "scalar",
|
|
841
|
+
scope: "program",
|
|
842
|
+
tier: "free",
|
|
843
|
+
surface: "engine",
|
|
844
|
+
item: {
|
|
845
|
+
kind: "enum",
|
|
846
|
+
values: SOURCE_TYPE_VALUES
|
|
847
|
+
},
|
|
848
|
+
default: "auto"
|
|
849
|
+
},
|
|
1236
850
|
{
|
|
1237
851
|
path: "complexity",
|
|
1238
852
|
shape: "scalar",
|
|
@@ -1536,438 +1150,845 @@ const CONFIG_KEYS = [
|
|
|
1536
1150
|
},
|
|
1537
1151
|
default: "detected from the environment"
|
|
1538
1152
|
},
|
|
1539
|
-
{
|
|
1540
|
-
path: "directives.enabled",
|
|
1541
|
-
shape: "scalar",
|
|
1542
|
-
scope: "program",
|
|
1543
|
-
tier: "free",
|
|
1544
|
-
surface: "build",
|
|
1545
|
-
item: { kind: "boolean" },
|
|
1546
|
-
default: "true"
|
|
1153
|
+
{
|
|
1154
|
+
path: "directives.enabled",
|
|
1155
|
+
shape: "scalar",
|
|
1156
|
+
scope: "program",
|
|
1157
|
+
tier: "free",
|
|
1158
|
+
surface: "build",
|
|
1159
|
+
item: { kind: "boolean" },
|
|
1160
|
+
default: "true"
|
|
1161
|
+
},
|
|
1162
|
+
{
|
|
1163
|
+
path: "diagnostics.level",
|
|
1164
|
+
shape: "scalar",
|
|
1165
|
+
scope: "program",
|
|
1166
|
+
tier: "free",
|
|
1167
|
+
surface: "build",
|
|
1168
|
+
item: {
|
|
1169
|
+
kind: "enum",
|
|
1170
|
+
values: [
|
|
1171
|
+
"summary",
|
|
1172
|
+
"all",
|
|
1173
|
+
"none"
|
|
1174
|
+
]
|
|
1175
|
+
},
|
|
1176
|
+
default: "summary"
|
|
1177
|
+
},
|
|
1178
|
+
{
|
|
1179
|
+
path: "diagnostics.format",
|
|
1180
|
+
shape: "scalar",
|
|
1181
|
+
scope: "program",
|
|
1182
|
+
tier: "free",
|
|
1183
|
+
surface: "cli",
|
|
1184
|
+
item: {
|
|
1185
|
+
kind: "enum",
|
|
1186
|
+
values: ["text", "json"]
|
|
1187
|
+
},
|
|
1188
|
+
default: "text"
|
|
1189
|
+
},
|
|
1190
|
+
{
|
|
1191
|
+
path: "telemetry.enabled",
|
|
1192
|
+
shape: "scalar",
|
|
1193
|
+
scope: "program",
|
|
1194
|
+
tier: "free",
|
|
1195
|
+
surface: "build",
|
|
1196
|
+
item: { kind: "boolean" },
|
|
1197
|
+
default: "true"
|
|
1198
|
+
},
|
|
1199
|
+
{
|
|
1200
|
+
path: "key",
|
|
1201
|
+
shape: "scalar",
|
|
1202
|
+
scope: "program",
|
|
1203
|
+
tier: "pro",
|
|
1204
|
+
surface: "build",
|
|
1205
|
+
item: { kind: "string" },
|
|
1206
|
+
default: "unset; builds run locally with basic protection"
|
|
1207
|
+
}
|
|
1208
|
+
];
|
|
1209
|
+
const EMPTY_CONFIG = {};
|
|
1210
|
+
const CONFIG_BY_PATH = new Map(CONFIG_KEYS.map((k) => [k.path, k]));
|
|
1211
|
+
const CONFIG_PREFIXES = new Set(CONFIG_KEYS.flatMap((k) => {
|
|
1212
|
+
const parts = k.path.split(".");
|
|
1213
|
+
return parts.slice(0, -1).map((_, i) => parts.slice(0, i + 1).join("."));
|
|
1214
|
+
}));
|
|
1215
|
+
const CONFIG_CHILDREN = new Map([...CONFIG_PREFIXES].map((prefix) => [prefix, CONFIG_KEYS.filter((k) => k.path.startsWith(`${prefix}.`)).map((k) => k.path)]));
|
|
1216
|
+
const BY_NORMALIZED = new Map(CONFIG_KEYS.map((k) => [normalizeKey(k.path), k]));
|
|
1217
|
+
const CHILDREN_BY_NORMALIZED = new Map([...CONFIG_CHILDREN].map(([prefix, children]) => [normalizeKey(prefix), children]));
|
|
1218
|
+
const PREFIX_BY_NORMALIZED = new Map([...CONFIG_PREFIXES].map((prefix) => [normalizeKey(prefix), prefix]));
|
|
1219
|
+
function normalizeKey(key) {
|
|
1220
|
+
return key.replace(/[-_.]/g, "").toLowerCase();
|
|
1221
|
+
}
|
|
1222
|
+
function groupBooleanKey(path) {
|
|
1223
|
+
if (!CONFIG_PREFIXES.has(path)) return void 0;
|
|
1224
|
+
return CONFIG_BY_PATH.get(`${path}.enabled`);
|
|
1225
|
+
}
|
|
1226
|
+
function nearestName(name, candidates) {
|
|
1227
|
+
const target = normalizeKey(name);
|
|
1228
|
+
let best;
|
|
1229
|
+
for (const candidate of candidates) {
|
|
1230
|
+
const distance = editDistance(target, normalizeKey(candidate));
|
|
1231
|
+
if (distance > Math.max(2, Math.floor(target.length / 4))) continue;
|
|
1232
|
+
if (!best || distance < best.distance) best = {
|
|
1233
|
+
name: candidate,
|
|
1234
|
+
distance
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1237
|
+
return best?.name;
|
|
1238
|
+
}
|
|
1239
|
+
function suggestKey(key) {
|
|
1240
|
+
const exact = BY_NORMALIZED.get(normalizeKey(key));
|
|
1241
|
+
if (exact) return exact.path;
|
|
1242
|
+
const near = nearestName(key, CONFIG_KEYS.map((k) => k.path));
|
|
1243
|
+
if (near) return near;
|
|
1244
|
+
const tail = normalizeKey(key);
|
|
1245
|
+
const owners = CONFIG_KEYS.filter((k) => normalizeKey(k.path.slice(k.path.lastIndexOf(".") + 1)) === tail);
|
|
1246
|
+
return owners.length === 1 ? owners[0].path : void 0;
|
|
1247
|
+
}
|
|
1248
|
+
function canonicalSpelling(name) {
|
|
1249
|
+
const norm$1 = normalizeKey(name);
|
|
1250
|
+
const key = BY_NORMALIZED.get(norm$1);
|
|
1251
|
+
if (key) return { key: key.path };
|
|
1252
|
+
const group$1 = CHILDREN_BY_NORMALIZED.get(norm$1);
|
|
1253
|
+
return group$1 && group$1.length > 0 ? { group: group$1 } : void 0;
|
|
1254
|
+
}
|
|
1255
|
+
function editDistance(a, b) {
|
|
1256
|
+
const prev = new Array(b.length + 1);
|
|
1257
|
+
const next = new Array(b.length + 1);
|
|
1258
|
+
for (let j = 0; j <= b.length; j++) prev[j] = j;
|
|
1259
|
+
for (let i = 1; i <= a.length; i++) {
|
|
1260
|
+
next[0] = i;
|
|
1261
|
+
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));
|
|
1262
|
+
for (let j = 0; j <= b.length; j++) prev[j] = next[j];
|
|
1263
|
+
}
|
|
1264
|
+
return prev[b.length];
|
|
1265
|
+
}
|
|
1266
|
+
const DOCS_URL = "https://www.afterpack.dev/docs/config";
|
|
1267
|
+
function unknownKeyMessage(path, surface) {
|
|
1268
|
+
const group$1 = CHILDREN_BY_NORMALIZED.get(normalizeKey(path));
|
|
1269
|
+
if (group$1 && group$1.length > 0) {
|
|
1270
|
+
const list = group$1.map((child) => `\`${child}\``).join(", ");
|
|
1271
|
+
const tail$1 = group$1.length === 1 ? `did you mean ${list}?` : `its keys are ${list}`;
|
|
1272
|
+
const canonical = PREFIX_BY_NORMALIZED.get(normalizeKey(path));
|
|
1273
|
+
const enabled = canonical ? groupBooleanKey(canonical) : void 0;
|
|
1274
|
+
const rule = enabled ? `; a boolean here means \`${enabled.path}\`` : "";
|
|
1275
|
+
return `\`${path}\` is a group of configuration keys, not a key itself (${surface}) — ${tail$1}${rule}`;
|
|
1276
|
+
}
|
|
1277
|
+
const suggestion = suggestKey(path);
|
|
1278
|
+
const tail = suggestion ? ` — did you mean \`${suggestion}\`?` : ` — see ${DOCS_URL}`;
|
|
1279
|
+
return `unknown configuration key \`${path}\` (${surface})${tail}`;
|
|
1280
|
+
}
|
|
1281
|
+
function isPlainObject(value) {
|
|
1282
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
1283
|
+
}
|
|
1284
|
+
function describe(item) {
|
|
1285
|
+
switch (item.kind) {
|
|
1286
|
+
case "boolean": return "true or false";
|
|
1287
|
+
case "number": return item.integer ? `an integer >= ${item.min}` : `a number >= ${item.min}`;
|
|
1288
|
+
case "unbounded": return `a number >= ${item.min}, or the string "${item.unlimited}"`;
|
|
1289
|
+
case "string": return "a string";
|
|
1290
|
+
case "enum": return `one of: ${item.values.join(", ")}`;
|
|
1291
|
+
case "seed": return "a number, any string, or \"git\"";
|
|
1292
|
+
case "reserved": return "a name, or { \"glob\": \"…\", \"names\": [\"…\"] }";
|
|
1293
|
+
case "region": return "an object with numeric `start` and `end`";
|
|
1294
|
+
}
|
|
1295
|
+
}
|
|
1296
|
+
function misdirectedHint(key, value, spell) {
|
|
1297
|
+
const other = misdirectedTo(key, value);
|
|
1298
|
+
if (!other) return "";
|
|
1299
|
+
const written = spell(other.path, String(value));
|
|
1300
|
+
return ` — \`${String(value)}\` is a \`${other.path}\` value; write \`${written}\` instead`;
|
|
1301
|
+
}
|
|
1302
|
+
const isFiniteNumber = (v) => typeof v === "number" && Number.isFinite(v);
|
|
1303
|
+
const isTransformKinds = (v) => Array.isArray(v) && v.every((k) => TRANSFORM_KIND_VALUES.includes(k));
|
|
1304
|
+
const KINDS = `a list of: ${TRANSFORM_KIND_VALUES.join(", ")}`;
|
|
1305
|
+
const isNonNegative = (v) => isFiniteNumber(v) && v >= 0;
|
|
1306
|
+
function group(fields) {
|
|
1307
|
+
return {
|
|
1308
|
+
is: isPlainObject,
|
|
1309
|
+
want: "an object",
|
|
1310
|
+
fields
|
|
1311
|
+
};
|
|
1312
|
+
}
|
|
1313
|
+
const REGION_FIELDS = {
|
|
1314
|
+
start: {
|
|
1315
|
+
required: true,
|
|
1316
|
+
is: isFiniteNumber,
|
|
1317
|
+
want: "a number"
|
|
1318
|
+
},
|
|
1319
|
+
end: {
|
|
1320
|
+
required: true,
|
|
1321
|
+
is: isFiniteNumber,
|
|
1322
|
+
want: "a number"
|
|
1547
1323
|
},
|
|
1548
|
-
{
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
scope: "program",
|
|
1552
|
-
tier: "free",
|
|
1553
|
-
surface: "build",
|
|
1554
|
-
item: {
|
|
1555
|
-
kind: "enum",
|
|
1556
|
-
values: [
|
|
1557
|
-
"summary",
|
|
1558
|
-
"all",
|
|
1559
|
-
"none"
|
|
1560
|
-
]
|
|
1561
|
-
},
|
|
1562
|
-
default: "summary"
|
|
1324
|
+
complexity: {
|
|
1325
|
+
is: isNonNegative,
|
|
1326
|
+
want: "a number >= 0"
|
|
1563
1327
|
},
|
|
1564
|
-
{
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1328
|
+
inflation: group({ max: {
|
|
1329
|
+
is: isNonNegative,
|
|
1330
|
+
want: "a number >= 0"
|
|
1331
|
+
} }),
|
|
1332
|
+
strings: group({ encode: {
|
|
1333
|
+
is: (v) => typeof v === "boolean",
|
|
1334
|
+
want: "true or false"
|
|
1335
|
+
} }),
|
|
1336
|
+
transforms: group({
|
|
1337
|
+
only: {
|
|
1338
|
+
is: isTransformKinds,
|
|
1339
|
+
want: KINDS
|
|
1573
1340
|
},
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
{
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
tier: "free",
|
|
1590
|
-
surface: "build",
|
|
1591
|
-
item: { kind: "boolean" },
|
|
1592
|
-
default: "false"
|
|
1341
|
+
deny: {
|
|
1342
|
+
is: isTransformKinds,
|
|
1343
|
+
want: KINDS
|
|
1344
|
+
}
|
|
1345
|
+
}),
|
|
1346
|
+
label: {
|
|
1347
|
+
is: (v) => typeof v === "string",
|
|
1348
|
+
want: "a string"
|
|
1349
|
+
}
|
|
1350
|
+
};
|
|
1351
|
+
const RESERVED_FIELDS = {
|
|
1352
|
+
glob: {
|
|
1353
|
+
required: true,
|
|
1354
|
+
is: (v) => typeof v === "string",
|
|
1355
|
+
want: "a string"
|
|
1593
1356
|
},
|
|
1594
|
-
{
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1357
|
+
names: {
|
|
1358
|
+
required: true,
|
|
1359
|
+
is: (v) => Array.isArray(v) && v.every((n) => typeof n === "string"),
|
|
1360
|
+
want: "a list of names"
|
|
1361
|
+
}
|
|
1362
|
+
};
|
|
1363
|
+
function leafNames(spec, prefix) {
|
|
1364
|
+
return Object.entries(spec).flatMap(([name, field]) => field.fields ? leafNames(field.fields, `${prefix}${name}.`) : [prefix + name]);
|
|
1365
|
+
}
|
|
1366
|
+
function checkFields(spec, value, prefix = "") {
|
|
1367
|
+
for (const name of Object.keys(value)) {
|
|
1368
|
+
if (name in spec) continue;
|
|
1369
|
+
const near = nearestName(prefix + name, Object.keys(spec).map((n) => prefix + n));
|
|
1370
|
+
return `item has an unknown field \`${prefix}${name}\`` + (near ? ` — did you mean \`${near}\`?` : "") + ` (allowed: ${leafNames(spec, prefix).join(", ")})`;
|
|
1371
|
+
}
|
|
1372
|
+
for (const [name, field] of Object.entries(spec)) {
|
|
1373
|
+
const present = value[name];
|
|
1374
|
+
if (present === void 0) {
|
|
1375
|
+
if (field.required) return `item is missing \`${prefix}${name}\` (${field.want})`;
|
|
1376
|
+
continue;
|
|
1377
|
+
}
|
|
1378
|
+
if (!field.is(present)) return `item's \`${prefix}${name}\` must be ${field.want}, got ${JSON.stringify(present)}`;
|
|
1379
|
+
if (field.fields) {
|
|
1380
|
+
const nested = checkFields(field.fields, present, `${prefix}${name}.`);
|
|
1381
|
+
if (nested) return nested;
|
|
1382
|
+
}
|
|
1383
|
+
}
|
|
1384
|
+
return void 0;
|
|
1385
|
+
}
|
|
1386
|
+
function expected(item, value) {
|
|
1387
|
+
return `expected ${describe(item)}, got ${JSON.stringify(value)}`;
|
|
1388
|
+
}
|
|
1389
|
+
function checkItem(item, value) {
|
|
1390
|
+
switch (item.kind) {
|
|
1391
|
+
case "boolean": return typeof value === "boolean" ? void 0 : expected(item, value);
|
|
1392
|
+
case "number": {
|
|
1393
|
+
if (typeof value !== "number" || !Number.isFinite(value)) return expected(item, value);
|
|
1394
|
+
if (value < item.min) return expected(item, value);
|
|
1395
|
+
if (item.integer && !Number.isInteger(value)) return expected(item, value);
|
|
1396
|
+
return void 0;
|
|
1397
|
+
}
|
|
1398
|
+
case "unbounded": {
|
|
1399
|
+
if (value === item.unlimited) return void 0;
|
|
1400
|
+
if (typeof value === "number" && Number.isFinite(value) && value >= item.min) return void 0;
|
|
1401
|
+
return `${expected(item, value)} — there is no \`Infinity\` in JSON; write "${item.unlimited}"`;
|
|
1402
|
+
}
|
|
1403
|
+
case "string": return typeof value === "string" ? void 0 : expected(item, value);
|
|
1404
|
+
case "enum": return typeof value === "string" && item.values.includes(value) ? void 0 : expected(item, value);
|
|
1405
|
+
case "seed": return typeof value === "number" || typeof value === "string" ? void 0 : expected(item, value);
|
|
1406
|
+
case "reserved": {
|
|
1407
|
+
if (typeof value === "string") return void 0;
|
|
1408
|
+
if (!isPlainObject(value)) return expected(item, value);
|
|
1409
|
+
return checkFields(RESERVED_FIELDS, value);
|
|
1410
|
+
}
|
|
1411
|
+
case "region": {
|
|
1412
|
+
if (!isPlainObject(value)) return expected(item, value);
|
|
1413
|
+
return checkFields(REGION_FIELDS, value);
|
|
1414
|
+
}
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
function checkValue(key, value) {
|
|
1418
|
+
if (key.shape === "scalar") {
|
|
1419
|
+
const failure = checkItem(key.item, value);
|
|
1420
|
+
return failure ? `\`${key.path}\`: ${failure}` : void 0;
|
|
1421
|
+
}
|
|
1422
|
+
if (!Array.isArray(value)) return `\`${key.path}\`: expected a list of values, got ${JSON.stringify(value)}`;
|
|
1423
|
+
for (const entry of value) {
|
|
1424
|
+
const failure = checkItem(key.item, entry);
|
|
1425
|
+
if (failure) return `\`${key.path}\`: ${failure}`;
|
|
1426
|
+
}
|
|
1427
|
+
return void 0;
|
|
1428
|
+
}
|
|
1429
|
+
function misdirectedTo(key, value) {
|
|
1430
|
+
if (key.namedValuesOf === void 0 || typeof value !== "string") return void 0;
|
|
1431
|
+
const other = CONFIG_BY_PATH.get(key.namedValuesOf);
|
|
1432
|
+
if (!other || other.shape !== "scalar") return void 0;
|
|
1433
|
+
return checkItem(other.item, value) === void 0 ? other : void 0;
|
|
1434
|
+
}
|
|
1435
|
+
function validateConfig(input, surface) {
|
|
1436
|
+
const issues = [];
|
|
1437
|
+
const config = {};
|
|
1438
|
+
if (input === void 0 || input === null) return {
|
|
1439
|
+
config,
|
|
1440
|
+
issues
|
|
1441
|
+
};
|
|
1442
|
+
if (!isPlainObject(input)) {
|
|
1443
|
+
issues.push({
|
|
1444
|
+
path: "",
|
|
1445
|
+
message: `configuration (${surface}) must be an object`
|
|
1446
|
+
});
|
|
1447
|
+
return {
|
|
1448
|
+
config,
|
|
1449
|
+
issues
|
|
1450
|
+
};
|
|
1451
|
+
}
|
|
1452
|
+
walk(input, "", config, issues, surface);
|
|
1453
|
+
return {
|
|
1454
|
+
config,
|
|
1455
|
+
issues
|
|
1456
|
+
};
|
|
1457
|
+
}
|
|
1458
|
+
function walk(source, prefix, target, issues, surface) {
|
|
1459
|
+
for (const [name, value] of Object.entries(source)) {
|
|
1460
|
+
if (value === void 0) continue;
|
|
1461
|
+
const path = prefix ? `${prefix}.${name}` : name;
|
|
1462
|
+
const key = CONFIG_BY_PATH.get(path);
|
|
1463
|
+
if (key) {
|
|
1464
|
+
const failure = checkValue(key, value);
|
|
1465
|
+
if (failure) {
|
|
1466
|
+
const hint = misdirectedHint(key, value, (p, v) => `"${p}": ${JSON.stringify(v)}`);
|
|
1467
|
+
issues.push({
|
|
1468
|
+
path,
|
|
1469
|
+
message: `${failure} (${surface})${hint}`
|
|
1470
|
+
});
|
|
1471
|
+
} else target[name] = value;
|
|
1472
|
+
continue;
|
|
1473
|
+
}
|
|
1474
|
+
if (CONFIG_PREFIXES.has(path)) {
|
|
1475
|
+
if (isPlainObject(value)) {
|
|
1476
|
+
const nested = {};
|
|
1477
|
+
walk(value, path, nested, issues, surface);
|
|
1478
|
+
if (Object.keys(nested).length > 0) target[name] = nested;
|
|
1479
|
+
continue;
|
|
1480
|
+
}
|
|
1481
|
+
const enabled = groupBooleanKey(path);
|
|
1482
|
+
if (enabled && typeof value === "boolean") {
|
|
1483
|
+
target[name] = { enabled: value };
|
|
1484
|
+
continue;
|
|
1485
|
+
}
|
|
1486
|
+
}
|
|
1487
|
+
issues.push({
|
|
1488
|
+
path,
|
|
1489
|
+
message: unknownKeyMessage(path, surface)
|
|
1490
|
+
});
|
|
1602
1491
|
}
|
|
1603
|
-
];
|
|
1604
|
-
const EMPTY_CONFIG = {};
|
|
1605
|
-
const CONFIG_BY_PATH = new Map(CONFIG_KEYS.map((k) => [k.path, k]));
|
|
1606
|
-
const CONFIG_PREFIXES = new Set(CONFIG_KEYS.flatMap((k) => {
|
|
1607
|
-
const parts = k.path.split(".");
|
|
1608
|
-
return parts.slice(0, -1).map((_, i) => parts.slice(0, i + 1).join("."));
|
|
1609
|
-
}));
|
|
1610
|
-
const CONFIG_CHILDREN = new Map([...CONFIG_PREFIXES].map((prefix) => [prefix, CONFIG_KEYS.filter((k) => k.path.startsWith(`${prefix}.`)).map((k) => k.path)]));
|
|
1611
|
-
const BY_NORMALIZED = new Map(CONFIG_KEYS.map((k) => [normalizeKey(k.path), k]));
|
|
1612
|
-
const CHILDREN_BY_NORMALIZED = new Map([...CONFIG_CHILDREN].map(([prefix, children]) => [normalizeKey(prefix), children]));
|
|
1613
|
-
const PREFIX_BY_NORMALIZED = new Map([...CONFIG_PREFIXES].map((prefix) => [normalizeKey(prefix), prefix]));
|
|
1614
|
-
function normalizeKey(key) {
|
|
1615
|
-
return key.replace(/[-_.]/g, "").toLowerCase();
|
|
1616
|
-
}
|
|
1617
|
-
function groupBooleanKey(path) {
|
|
1618
|
-
if (!CONFIG_PREFIXES.has(path)) return void 0;
|
|
1619
|
-
return CONFIG_BY_PATH.get(`${path}.enabled`);
|
|
1620
1492
|
}
|
|
1621
|
-
function
|
|
1622
|
-
const
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
const
|
|
1626
|
-
|
|
1627
|
-
if (!best || distance < best.distance) best = {
|
|
1628
|
-
name: candidate,
|
|
1629
|
-
distance
|
|
1630
|
-
};
|
|
1493
|
+
function deepMerge(base, override) {
|
|
1494
|
+
const out = { ...base };
|
|
1495
|
+
for (const [name, value] of Object.entries(override)) {
|
|
1496
|
+
if (value === void 0) continue;
|
|
1497
|
+
const existing = out[name];
|
|
1498
|
+
out[name] = isPlainObject(value) && isPlainObject(existing) ? deepMerge(existing, value) : value;
|
|
1631
1499
|
}
|
|
1632
|
-
return
|
|
1633
|
-
}
|
|
1634
|
-
function suggestKey(key) {
|
|
1635
|
-
const exact = BY_NORMALIZED.get(normalizeKey(key));
|
|
1636
|
-
if (exact) return exact.path;
|
|
1637
|
-
const near = nearestName(key, CONFIG_KEYS.map((k) => k.path));
|
|
1638
|
-
if (near) return near;
|
|
1639
|
-
const tail = normalizeKey(key);
|
|
1640
|
-
const owners = CONFIG_KEYS.filter((k) => normalizeKey(k.path.slice(k.path.lastIndexOf(".") + 1)) === tail);
|
|
1641
|
-
return owners.length === 1 ? owners[0].path : void 0;
|
|
1500
|
+
return out;
|
|
1642
1501
|
}
|
|
1643
|
-
function
|
|
1644
|
-
|
|
1645
|
-
const key = BY_NORMALIZED.get(norm$1);
|
|
1646
|
-
if (key) return { key: key.path };
|
|
1647
|
-
const group$1 = CHILDREN_BY_NORMALIZED.get(norm$1);
|
|
1648
|
-
return group$1 && group$1.length > 0 ? { group: group$1 } : void 0;
|
|
1502
|
+
function mergeInto(base, override) {
|
|
1503
|
+
return deepMerge(base, override);
|
|
1649
1504
|
}
|
|
1650
|
-
function
|
|
1651
|
-
|
|
1652
|
-
const next = new Array(b.length + 1);
|
|
1653
|
-
for (let j = 0; j <= b.length; j++) prev[j] = j;
|
|
1654
|
-
for (let i = 1; i <= a.length; i++) {
|
|
1655
|
-
next[0] = i;
|
|
1656
|
-
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));
|
|
1657
|
-
for (let j = 0; j <= b.length; j++) prev[j] = next[j];
|
|
1658
|
-
}
|
|
1659
|
-
return prev[b.length];
|
|
1505
|
+
function mergeConfig(base, override) {
|
|
1506
|
+
return deepMerge(base, override);
|
|
1660
1507
|
}
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
const
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
const tail$1 = group$1.length === 1 ? `did you mean ${list}?` : `its keys are ${list}`;
|
|
1667
|
-
const canonical = PREFIX_BY_NORMALIZED.get(normalizeKey(path));
|
|
1668
|
-
const enabled = canonical ? groupBooleanKey(canonical) : void 0;
|
|
1669
|
-
const rule = enabled ? `; a boolean here means \`${enabled.path}\`` : "";
|
|
1670
|
-
return `\`${path}\` is a group of configuration keys, not a key itself (${surface}) — ${tail$1}${rule}`;
|
|
1508
|
+
function getPath(config, path) {
|
|
1509
|
+
let current = config;
|
|
1510
|
+
for (const part of path.split(".")) {
|
|
1511
|
+
if (!isPlainObject(current)) return void 0;
|
|
1512
|
+
current = current[part];
|
|
1671
1513
|
}
|
|
1672
|
-
|
|
1673
|
-
const tail = suggestion ? ` — did you mean \`${suggestion}\`?` : ` — see ${DOCS_URL}`;
|
|
1674
|
-
return `unknown configuration key \`${path}\` (${surface})${tail}`;
|
|
1514
|
+
return current;
|
|
1675
1515
|
}
|
|
1676
|
-
function
|
|
1677
|
-
return
|
|
1516
|
+
function nest(path, value) {
|
|
1517
|
+
return path.split(".").reduceRight((inner, segment) => ({ [segment]: inner }), value);
|
|
1678
1518
|
}
|
|
1679
|
-
function
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
case "enum": return `one of: ${item.values.join(", ")}`;
|
|
1686
|
-
case "seed": return "a number, any string, or \"git\"";
|
|
1687
|
-
case "reserved": return "a name, or { \"glob\": \"…\", \"names\": [\"…\"] }";
|
|
1688
|
-
case "region": return "an object with numeric `start` and `end`";
|
|
1519
|
+
function setPath(target, path, value) {
|
|
1520
|
+
const parts = path.split(".");
|
|
1521
|
+
let node = target;
|
|
1522
|
+
for (const part of parts.slice(0, -1)) {
|
|
1523
|
+
if (!isPlainObject(node[part])) node[part] = {};
|
|
1524
|
+
node = node[part];
|
|
1689
1525
|
}
|
|
1526
|
+
node[parts[parts.length - 1]] = value;
|
|
1690
1527
|
}
|
|
1691
|
-
function
|
|
1692
|
-
const
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1528
|
+
function toEngineConfig(config) {
|
|
1529
|
+
const out = {};
|
|
1530
|
+
for (const key of CONFIG_KEYS) {
|
|
1531
|
+
if (key.surface !== "engine") continue;
|
|
1532
|
+
const value = getPath(config, key.path);
|
|
1533
|
+
if (value === void 0) continue;
|
|
1534
|
+
setPath(out, key.path, value);
|
|
1535
|
+
}
|
|
1536
|
+
return out;
|
|
1696
1537
|
}
|
|
1697
|
-
|
|
1698
|
-
const
|
|
1699
|
-
const
|
|
1700
|
-
const isNonNegative = (v) => isFiniteNumber(v) && v >= 0;
|
|
1701
|
-
function group(fields) {
|
|
1538
|
+
function toPluginOptions(config) {
|
|
1539
|
+
const read = (path) => getPath(config, path);
|
|
1540
|
+
const set = (container) => Object.values(container).some((v) => v !== void 0) ? container : void 0;
|
|
1702
1541
|
return {
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1542
|
+
artifactOptions: {
|
|
1543
|
+
protectionMap: set({ enabled: read("protectionMap.enabled") }),
|
|
1544
|
+
sourceMap: set({
|
|
1545
|
+
enabled: read("sourceMap.enabled"),
|
|
1546
|
+
emitUrl: read("sourceMap.emitUrl")
|
|
1547
|
+
}),
|
|
1548
|
+
build: set({
|
|
1549
|
+
backup: read("build.backup"),
|
|
1550
|
+
mode: read("build.mode")
|
|
1551
|
+
}),
|
|
1552
|
+
telemetry: set({ enabled: read("telemetry.enabled") })
|
|
1553
|
+
},
|
|
1554
|
+
seed: read("seed"),
|
|
1555
|
+
preset: read("preset"),
|
|
1556
|
+
complexity: read("complexity"),
|
|
1557
|
+
regions: read("regions"),
|
|
1558
|
+
directives: {
|
|
1559
|
+
enabled: read("directives.enabled") ?? DIRECTIVES_ENABLED_DEFAULT,
|
|
1560
|
+
explicit: read("directives.enabled") !== void 0
|
|
1561
|
+
},
|
|
1562
|
+
build: set({ autorun: read("build.autorun") }),
|
|
1563
|
+
diagnostics: set({
|
|
1564
|
+
level: read("diagnostics.level"),
|
|
1565
|
+
format: read("diagnostics.format")
|
|
1566
|
+
}),
|
|
1567
|
+
paths: set({ include: read("paths.include") }),
|
|
1568
|
+
key: read("key")
|
|
1706
1569
|
};
|
|
1707
1570
|
}
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
}
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
}
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1571
|
+
|
|
1572
|
+
//#endregion
|
|
1573
|
+
//#region src/source-map.ts
|
|
1574
|
+
const SOURCE_MAPPING_URL_RE = /\/\/[#@]\s*sourceMappingURL=(\S+)\s*$/gm;
|
|
1575
|
+
const SOURCE_MAPPING_URL_LINE_RE = /^[ \t]*\/\/[#@]\s*sourceMappingURL=\S+[ \t]*\r?\n?/gm;
|
|
1576
|
+
const CSS_SOURCE_MAPPING_URL_RE = /[ \t]*\/\*[#@]\s*sourceMappingURL=[^\s*]+\s*\*\/\s*$/;
|
|
1577
|
+
function withSourceMappingURL(code, url) {
|
|
1578
|
+
const stripped = code.replace(SOURCE_MAPPING_URL_LINE_RE, "");
|
|
1579
|
+
if (url == null) return stripped;
|
|
1580
|
+
const separator = stripped.length > 0 && !stripped.endsWith("\n") ? "\n" : "";
|
|
1581
|
+
return `${stripped}${separator}//# sourceMappingURL=${url}\n`;
|
|
1582
|
+
}
|
|
1583
|
+
function withoutCssSourceMappingURL(css) {
|
|
1584
|
+
return css.replace(CSS_SOURCE_MAPPING_URL_RE, "");
|
|
1585
|
+
}
|
|
1586
|
+
function extractSourceMappingURL(code) {
|
|
1587
|
+
let last = null;
|
|
1588
|
+
for (const match of code.matchAll(SOURCE_MAPPING_URL_RE)) last = match[1];
|
|
1589
|
+
return last;
|
|
1590
|
+
}
|
|
1591
|
+
function isRemoteSourceMappingURL(url) {
|
|
1592
|
+
return /^https?:\/\//i.test(url) || url.startsWith("//");
|
|
1593
|
+
}
|
|
1594
|
+
function decodeDataUri(url) {
|
|
1595
|
+
if (!url.startsWith("data:")) return null;
|
|
1596
|
+
const comma = url.indexOf(",");
|
|
1597
|
+
if (comma === -1) return null;
|
|
1598
|
+
const meta = url.slice(5, comma);
|
|
1599
|
+
const payload = url.slice(comma + 1);
|
|
1600
|
+
try {
|
|
1601
|
+
if (/;base64/i.test(meta)) return Buffer.from(payload, "base64").toString("utf8");
|
|
1602
|
+
return decodeURIComponent(payload);
|
|
1603
|
+
} catch {
|
|
1604
|
+
return null;
|
|
1605
|
+
}
|
|
1606
|
+
}
|
|
1607
|
+
function discoverInputSourceMap(jsPath, code) {
|
|
1608
|
+
const adjacent = `${jsPath}.map`;
|
|
1609
|
+
if ((0, node_fs.existsSync)(adjacent)) try {
|
|
1610
|
+
return (0, node_fs.readFileSync)(adjacent, "utf8");
|
|
1611
|
+
} catch {}
|
|
1612
|
+
let source = code;
|
|
1613
|
+
if (source == null) try {
|
|
1614
|
+
source = (0, node_fs.readFileSync)(jsPath, "utf8");
|
|
1615
|
+
} catch {
|
|
1616
|
+
return null;
|
|
1617
|
+
}
|
|
1618
|
+
const url = extractSourceMappingURL(source);
|
|
1619
|
+
if (url == null) return null;
|
|
1620
|
+
if (url.startsWith("data:")) return decodeDataUri(url);
|
|
1621
|
+
if (isRemoteSourceMappingURL(url)) return null;
|
|
1622
|
+
let mapPath;
|
|
1623
|
+
try {
|
|
1624
|
+
mapPath = (0, node_path.isAbsolute)(url) ? url : (0, node_path.resolve)((0, node_path.dirname)(jsPath), decodeURIComponent(url));
|
|
1625
|
+
} catch {
|
|
1626
|
+
return null;
|
|
1744
1627
|
}
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
want: "a string"
|
|
1751
|
-
},
|
|
1752
|
-
names: {
|
|
1753
|
-
required: true,
|
|
1754
|
-
is: (v) => Array.isArray(v) && v.every((n) => typeof n === "string"),
|
|
1755
|
-
want: "a list of names"
|
|
1628
|
+
if (!(0, node_fs.existsSync)(mapPath)) return null;
|
|
1629
|
+
try {
|
|
1630
|
+
return (0, node_fs.readFileSync)(mapPath, "utf8");
|
|
1631
|
+
} catch {
|
|
1632
|
+
return null;
|
|
1756
1633
|
}
|
|
1757
|
-
};
|
|
1758
|
-
function leafNames(spec, prefix) {
|
|
1759
|
-
return Object.entries(spec).flatMap(([name, field]) => field.fields ? leafNames(field.fields, `${prefix}${name}.`) : [prefix + name]);
|
|
1760
1634
|
}
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1635
|
+
|
|
1636
|
+
//#endregion
|
|
1637
|
+
//#region src/bundle.ts
|
|
1638
|
+
const BUNDLE_JS_RE = /\.[cm]?js$/;
|
|
1639
|
+
const CSS_MAP_RE = /\.css\.map$/;
|
|
1640
|
+
function collectBundleJs(bundle, outDir) {
|
|
1641
|
+
const files = [];
|
|
1642
|
+
const inputs = new Map();
|
|
1643
|
+
const entries = new Map();
|
|
1644
|
+
for (const [fileName, entry] of Object.entries(bundle)) {
|
|
1645
|
+
if (!BUNDLE_JS_RE.test(fileName)) continue;
|
|
1646
|
+
const source = entry.type === "chunk" ? entry.code : typeof entry.source === "string" ? entry.source : void 0;
|
|
1647
|
+
if (source === void 0) continue;
|
|
1648
|
+
const filePath = (0, node_path.resolve)(outDir, fileName);
|
|
1649
|
+
files.push(filePath);
|
|
1650
|
+
entries.set(filePath, entry);
|
|
1651
|
+
inputs.set(filePath, {
|
|
1652
|
+
source,
|
|
1653
|
+
sourceMap: entry.map ? entry.map.toString() : null
|
|
1654
|
+
});
|
|
1766
1655
|
}
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1656
|
+
return {
|
|
1657
|
+
files,
|
|
1658
|
+
inputs,
|
|
1659
|
+
entries
|
|
1660
|
+
};
|
|
1661
|
+
}
|
|
1662
|
+
function sourceTypeForBundle(format, entries) {
|
|
1663
|
+
for (const entry of entries) if (entry.type !== "chunk") return void 0;
|
|
1664
|
+
return sourceTypeForOutputFormat(format);
|
|
1665
|
+
}
|
|
1666
|
+
function dataUri(json) {
|
|
1667
|
+
return `data:application/json;charset=utf-8;base64,${Buffer.from(json, "utf8").toString("base64")}`;
|
|
1668
|
+
}
|
|
1669
|
+
function applyBundleOutput(bundle, entry, out, policy) {
|
|
1670
|
+
if (entry.type !== "chunk") {
|
|
1671
|
+
entry.source = out.code;
|
|
1672
|
+
return;
|
|
1673
|
+
}
|
|
1674
|
+
const mapName = entry.sourcemapFileName ?? null;
|
|
1675
|
+
const inlineMap = mapName == null && entry.map != null;
|
|
1676
|
+
const emitMap = policy.sourceMap && out.sourceMap != null;
|
|
1677
|
+
let url = null;
|
|
1678
|
+
if (emitMap && out.sourceMap != null) {
|
|
1679
|
+
if (mapName != null && bundle[mapName]) {
|
|
1680
|
+
bundle[mapName].source = out.sourceMap;
|
|
1681
|
+
url = (0, node_path.basename)(mapName);
|
|
1682
|
+
} else if (inlineMap) url = dataUri(out.sourceMap);
|
|
1683
|
+
} else {
|
|
1684
|
+
if (mapName != null) delete bundle[mapName];
|
|
1685
|
+
entry.map = null;
|
|
1686
|
+
}
|
|
1687
|
+
entry.code = withSourceMappingURL(out.code, policy.emitSourceMappingURL ? url : null);
|
|
1688
|
+
}
|
|
1689
|
+
function stripBundleCssSourceMaps(bundle) {
|
|
1690
|
+
for (const [fileName, entry] of Object.entries(bundle)) {
|
|
1691
|
+
if (CSS_MAP_RE.test(fileName)) {
|
|
1692
|
+
delete bundle[fileName];
|
|
1771
1693
|
continue;
|
|
1772
1694
|
}
|
|
1773
|
-
if (
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
}
|
|
1695
|
+
if (entry.type !== "asset" || !fileName.endsWith(".css") || entry.source === void 0) continue;
|
|
1696
|
+
const css = typeof entry.source === "string" ? entry.source : Buffer.from(entry.source).toString("utf8");
|
|
1697
|
+
const stripped = withoutCssSourceMappingURL(css);
|
|
1698
|
+
if (stripped !== css) entry.source = stripped;
|
|
1778
1699
|
}
|
|
1779
|
-
return void 0;
|
|
1780
1700
|
}
|
|
1781
|
-
|
|
1782
|
-
|
|
1701
|
+
|
|
1702
|
+
//#endregion
|
|
1703
|
+
//#region src/glob.ts
|
|
1704
|
+
function normalize(value) {
|
|
1705
|
+
return value.includes("\\") ? value.replaceAll("\\", "/") : value;
|
|
1783
1706
|
}
|
|
1784
|
-
function
|
|
1785
|
-
|
|
1786
|
-
case "boolean": return typeof value === "boolean" ? void 0 : expected(item, value);
|
|
1787
|
-
case "number": {
|
|
1788
|
-
if (typeof value !== "number" || !Number.isFinite(value)) return expected(item, value);
|
|
1789
|
-
if (value < item.min) return expected(item, value);
|
|
1790
|
-
if (item.integer && !Number.isInteger(value)) return expected(item, value);
|
|
1791
|
-
return void 0;
|
|
1792
|
-
}
|
|
1793
|
-
case "unbounded": {
|
|
1794
|
-
if (value === item.unlimited) return void 0;
|
|
1795
|
-
if (typeof value === "number" && Number.isFinite(value) && value >= item.min) return void 0;
|
|
1796
|
-
return `${expected(item, value)} — there is no \`Infinity\` in JSON; write "${item.unlimited}"`;
|
|
1797
|
-
}
|
|
1798
|
-
case "string": return typeof value === "string" ? void 0 : expected(item, value);
|
|
1799
|
-
case "enum": return typeof value === "string" && item.values.includes(value) ? void 0 : expected(item, value);
|
|
1800
|
-
case "seed": return typeof value === "number" || typeof value === "string" ? void 0 : expected(item, value);
|
|
1801
|
-
case "reserved": {
|
|
1802
|
-
if (typeof value === "string") return void 0;
|
|
1803
|
-
if (!isPlainObject(value)) return expected(item, value);
|
|
1804
|
-
return checkFields(RESERVED_FIELDS, value);
|
|
1805
|
-
}
|
|
1806
|
-
case "region": {
|
|
1807
|
-
if (!isPlainObject(value)) return expected(item, value);
|
|
1808
|
-
return checkFields(REGION_FIELDS, value);
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1707
|
+
function segments(value) {
|
|
1708
|
+
return value.split("/").filter((part) => part !== "");
|
|
1811
1709
|
}
|
|
1812
|
-
function
|
|
1813
|
-
if (
|
|
1814
|
-
|
|
1815
|
-
|
|
1816
|
-
|
|
1817
|
-
if (!
|
|
1818
|
-
|
|
1819
|
-
|
|
1820
|
-
|
|
1710
|
+
function isAnchored(pattern) {
|
|
1711
|
+
if (pattern.startsWith("/")) return true;
|
|
1712
|
+
return pattern.length >= 2 && pattern[1] === ":" && /^[A-Za-z]$/.test(pattern[0]);
|
|
1713
|
+
}
|
|
1714
|
+
function segmentMatches(pattern, seg) {
|
|
1715
|
+
if (!pattern.includes("*") && !pattern.includes("?")) return pattern === seg;
|
|
1716
|
+
const p = [...pattern];
|
|
1717
|
+
const s = [...seg];
|
|
1718
|
+
let pi = 0;
|
|
1719
|
+
let si = 0;
|
|
1720
|
+
let star = -1;
|
|
1721
|
+
let starSi = 0;
|
|
1722
|
+
while (si < s.length) if (pi < p.length && p[pi] === "*") {
|
|
1723
|
+
star = pi;
|
|
1724
|
+
starSi = si;
|
|
1725
|
+
pi += 1;
|
|
1726
|
+
} else if (pi < p.length && (p[pi] === "?" || p[pi] === s[si])) {
|
|
1727
|
+
pi += 1;
|
|
1728
|
+
si += 1;
|
|
1729
|
+
} else if (star >= 0) {
|
|
1730
|
+
pi = star + 1;
|
|
1731
|
+
starSi += 1;
|
|
1732
|
+
si = starSi;
|
|
1733
|
+
} else return false;
|
|
1734
|
+
return p.slice(pi).every((c) => c === "*");
|
|
1735
|
+
}
|
|
1736
|
+
function segmentsMatch(pattern, path) {
|
|
1737
|
+
let pi = 0;
|
|
1738
|
+
let si = 0;
|
|
1739
|
+
let star = -1;
|
|
1740
|
+
let starSi = 0;
|
|
1741
|
+
while (si < path.length) if (pi < pattern.length && pattern[pi] === "**") {
|
|
1742
|
+
star = pi;
|
|
1743
|
+
starSi = si;
|
|
1744
|
+
pi += 1;
|
|
1745
|
+
} else if (pi < pattern.length && segmentMatches(pattern[pi], path[si])) {
|
|
1746
|
+
pi += 1;
|
|
1747
|
+
si += 1;
|
|
1748
|
+
} else if (star >= 0) {
|
|
1749
|
+
pi = star + 1;
|
|
1750
|
+
starSi += 1;
|
|
1751
|
+
si = starSi;
|
|
1752
|
+
} else return false;
|
|
1753
|
+
return pattern.slice(pi).every((s) => s === "**");
|
|
1754
|
+
}
|
|
1755
|
+
function matchesPath(pattern, path) {
|
|
1756
|
+
const pat = normalize(pattern);
|
|
1757
|
+
const parts = segments(pat);
|
|
1758
|
+
if (parts.length === 0) return false;
|
|
1759
|
+
const segs = segments(normalize(path));
|
|
1760
|
+
if (isAnchored(pat)) return segmentsMatch(parts, segs);
|
|
1761
|
+
for (let i = 0; i <= segs.length; i++) if (segmentsMatch(parts, segs.slice(i))) return true;
|
|
1762
|
+
return false;
|
|
1763
|
+
}
|
|
1764
|
+
function reachesInto(pattern, dir) {
|
|
1765
|
+
const pat = normalize(pattern);
|
|
1766
|
+
const parts = segments(pat);
|
|
1767
|
+
if (parts.length === 0) return false;
|
|
1768
|
+
if (!isAnchored(pat)) return true;
|
|
1769
|
+
for (let k = 1; k <= parts.length; k++) if (matchesPath(`/${parts.slice(0, k).join("/")}`, dir)) return true;
|
|
1770
|
+
return false;
|
|
1771
|
+
}
|
|
1772
|
+
|
|
1773
|
+
//#endregion
|
|
1774
|
+
//#region src/collect.ts
|
|
1775
|
+
const BACKUP_RE = /\.backup\.[0-9a-f]{8}\.[cm]?js$/;
|
|
1776
|
+
const NODE_MODULES = "node_modules";
|
|
1777
|
+
function isCollectableJs(name) {
|
|
1778
|
+
if (BACKUP_RE.test(name)) return false;
|
|
1779
|
+
return name.endsWith(".js") || name.endsWith(".mjs") || name.endsWith(".cjs");
|
|
1780
|
+
}
|
|
1781
|
+
function statOrNull(path) {
|
|
1782
|
+
try {
|
|
1783
|
+
return (0, node_fs.statSync)(path);
|
|
1784
|
+
} catch {
|
|
1785
|
+
return null;
|
|
1821
1786
|
}
|
|
1822
|
-
return void 0;
|
|
1823
1787
|
}
|
|
1824
|
-
function
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
if (!
|
|
1828
|
-
return
|
|
1788
|
+
function collectJsFiles(target, options = {}) {
|
|
1789
|
+
const stat = statOrNull(target);
|
|
1790
|
+
if (!stat) return [];
|
|
1791
|
+
if (!stat.isDirectory()) return isCollectableJs((0, node_path.basename)(target)) ? [target] : [];
|
|
1792
|
+
return walkJs(target, options.include ?? [], false, options.onNestedProject);
|
|
1829
1793
|
}
|
|
1830
|
-
function
|
|
1831
|
-
|
|
1832
|
-
|
|
1833
|
-
|
|
1834
|
-
|
|
1835
|
-
issues
|
|
1836
|
-
};
|
|
1837
|
-
if (!isPlainObject(input)) {
|
|
1838
|
-
issues.push({
|
|
1839
|
-
path: "",
|
|
1840
|
-
message: `configuration (${surface}) must be an object`
|
|
1841
|
-
});
|
|
1842
|
-
return {
|
|
1843
|
-
config,
|
|
1844
|
-
issues
|
|
1845
|
-
};
|
|
1794
|
+
function entriesOf(dir) {
|
|
1795
|
+
try {
|
|
1796
|
+
return (0, node_fs.readdirSync)(dir, { withFileTypes: true });
|
|
1797
|
+
} catch {
|
|
1798
|
+
return [];
|
|
1846
1799
|
}
|
|
1847
|
-
walk(input, "", config, issues, surface);
|
|
1848
|
-
return {
|
|
1849
|
-
config,
|
|
1850
|
-
issues
|
|
1851
|
-
};
|
|
1852
1800
|
}
|
|
1853
|
-
function
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
|
|
1857
|
-
|
|
1858
|
-
|
|
1859
|
-
|
|
1860
|
-
|
|
1861
|
-
|
|
1862
|
-
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
if (
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
continue;
|
|
1875
|
-
}
|
|
1876
|
-
const enabled = groupBooleanKey(path);
|
|
1877
|
-
if (enabled && typeof value === "boolean") {
|
|
1878
|
-
target[name] = { enabled: value };
|
|
1801
|
+
function kindOf(entry, full) {
|
|
1802
|
+
if (entry.isDirectory()) return "dir";
|
|
1803
|
+
if (entry.isFile()) return "file";
|
|
1804
|
+
const stat = statOrNull(full);
|
|
1805
|
+
if (!stat) return null;
|
|
1806
|
+
return stat.isDirectory() ? "dir" : "file";
|
|
1807
|
+
}
|
|
1808
|
+
function isNestedProject(dir) {
|
|
1809
|
+
return (0, node_fs.existsSync)((0, node_path.join)(dir, "package.json"));
|
|
1810
|
+
}
|
|
1811
|
+
function walkJs(dir, include, readmitted, onNestedProject) {
|
|
1812
|
+
const out = [];
|
|
1813
|
+
for (const entry of entriesOf(dir)) {
|
|
1814
|
+
const name = entry.name;
|
|
1815
|
+
const full = (0, node_path.join)(dir, name);
|
|
1816
|
+
const kind = kindOf(entry, full);
|
|
1817
|
+
if (kind === null) continue;
|
|
1818
|
+
if (kind === "dir") {
|
|
1819
|
+
const skipped = name === NODE_MODULES;
|
|
1820
|
+
if (!skipped && !readmitted && isNestedProject(full)) {
|
|
1821
|
+
onNestedProject?.(full);
|
|
1879
1822
|
continue;
|
|
1880
1823
|
}
|
|
1824
|
+
if (skipped && !include.some((pattern) => reachesInto(pattern, full))) continue;
|
|
1825
|
+
out.push(...walkJs(full, include, readmitted || skipped, onNestedProject));
|
|
1826
|
+
} else if (isCollectableJs(name)) {
|
|
1827
|
+
if (readmitted && !include.some((pattern) => matchesPath(pattern, full))) continue;
|
|
1828
|
+
out.push(full);
|
|
1881
1829
|
}
|
|
1882
|
-
issues.push({
|
|
1883
|
-
path,
|
|
1884
|
-
message: unknownKeyMessage(path, surface)
|
|
1885
|
-
});
|
|
1886
1830
|
}
|
|
1831
|
+
return out;
|
|
1887
1832
|
}
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1833
|
+
const SOURCE_MAP_RE = /\.(?:[cm]?js|css)\.map$/;
|
|
1834
|
+
function collectFiles(dir, accept) {
|
|
1835
|
+
if (!(0, node_fs.existsSync)(dir)) return [];
|
|
1836
|
+
const out = [];
|
|
1837
|
+
for (const entry of entriesOf(dir)) {
|
|
1838
|
+
const name = entry.name;
|
|
1839
|
+
const full = (0, node_path.join)(dir, name);
|
|
1840
|
+
const kind = kindOf(entry, full);
|
|
1841
|
+
if (kind === null) continue;
|
|
1842
|
+
if (kind === "dir") out.push(...collectFiles(full, accept));
|
|
1843
|
+
else if (accept(name)) out.push(full);
|
|
1894
1844
|
}
|
|
1895
1845
|
return out;
|
|
1896
1846
|
}
|
|
1897
|
-
function
|
|
1898
|
-
return
|
|
1847
|
+
function collectSourceMaps(dir) {
|
|
1848
|
+
return collectFiles(dir, (name) => SOURCE_MAP_RE.test(name));
|
|
1899
1849
|
}
|
|
1900
|
-
function
|
|
1901
|
-
return
|
|
1850
|
+
function collectStylesheets(dir) {
|
|
1851
|
+
return collectFiles(dir, (name) => name.endsWith(".css"));
|
|
1902
1852
|
}
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1853
|
+
|
|
1854
|
+
//#endregion
|
|
1855
|
+
//#region src/notices.ts
|
|
1856
|
+
const NOTICE_MESSAGE_LIMIT = 500;
|
|
1857
|
+
const NOTICE_LIMIT = 5;
|
|
1858
|
+
const NOTICE_CODE_LIMIT = 64;
|
|
1859
|
+
const NOTICE_HOSTS = new Set(["afterpack.dev", "www.afterpack.dev"]);
|
|
1860
|
+
const ESC = 27;
|
|
1861
|
+
const BEL = 7;
|
|
1862
|
+
const C1_CSI = 155;
|
|
1863
|
+
const C1_OSC = 157;
|
|
1864
|
+
function isControl(code) {
|
|
1865
|
+
return code < 32 || code >= 127 && code <= 159;
|
|
1866
|
+
}
|
|
1867
|
+
function isInvisibleFormat(code) {
|
|
1868
|
+
return code === 1564 || code >= 8203 && code <= 8207 || code >= 8234 && code <= 8238 || code >= 8288 && code <= 8297 || code === 65279;
|
|
1869
|
+
}
|
|
1870
|
+
function skipCsi(text, from) {
|
|
1871
|
+
let i = from;
|
|
1872
|
+
while (i < text.length) {
|
|
1873
|
+
const c = text.charCodeAt(i);
|
|
1874
|
+
i += 1;
|
|
1875
|
+
if (c >= 64 && c <= 126) return i;
|
|
1908
1876
|
}
|
|
1909
|
-
return
|
|
1877
|
+
return i;
|
|
1910
1878
|
}
|
|
1911
|
-
function
|
|
1912
|
-
|
|
1879
|
+
function skipOsc(text, from) {
|
|
1880
|
+
let i = from;
|
|
1881
|
+
while (i < text.length) {
|
|
1882
|
+
const c = text.charCodeAt(i);
|
|
1883
|
+
if (c === BEL) return i + 1;
|
|
1884
|
+
if (c === ESC) return text.charCodeAt(i + 1) === 92 ? i + 2 : i + 1;
|
|
1885
|
+
if (c === 156) return i + 1;
|
|
1886
|
+
i += 1;
|
|
1887
|
+
}
|
|
1888
|
+
return i;
|
|
1913
1889
|
}
|
|
1914
|
-
function
|
|
1915
|
-
|
|
1916
|
-
let
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1890
|
+
function stripTerminalControls(text) {
|
|
1891
|
+
let out = "";
|
|
1892
|
+
let i = 0;
|
|
1893
|
+
while (i < text.length) {
|
|
1894
|
+
const c = text.charCodeAt(i);
|
|
1895
|
+
if (c === ESC) {
|
|
1896
|
+
const next = text.charCodeAt(i + 1);
|
|
1897
|
+
if (next === 91) i = skipCsi(text, i + 2);
|
|
1898
|
+
else if (next === 93) i = skipOsc(text, i + 2);
|
|
1899
|
+
else i += Number.isNaN(next) ? 1 : 2;
|
|
1900
|
+
continue;
|
|
1901
|
+
}
|
|
1902
|
+
if (c === C1_CSI) {
|
|
1903
|
+
i = skipCsi(text, i + 1);
|
|
1904
|
+
continue;
|
|
1905
|
+
}
|
|
1906
|
+
if (c === C1_OSC) {
|
|
1907
|
+
i = skipOsc(text, i + 1);
|
|
1908
|
+
continue;
|
|
1909
|
+
}
|
|
1910
|
+
if (isControl(c)) {
|
|
1911
|
+
out += c === 9 || c === 10 || c === 13 ? " " : "";
|
|
1912
|
+
i += 1;
|
|
1913
|
+
continue;
|
|
1914
|
+
}
|
|
1915
|
+
if (c === 8232 || c === 8233) {
|
|
1916
|
+
out += " ";
|
|
1917
|
+
i += 1;
|
|
1918
|
+
continue;
|
|
1919
|
+
}
|
|
1920
|
+
if (isInvisibleFormat(c)) {
|
|
1921
|
+
i += 1;
|
|
1922
|
+
continue;
|
|
1923
|
+
}
|
|
1924
|
+
out += text[i];
|
|
1925
|
+
i += 1;
|
|
1920
1926
|
}
|
|
1921
|
-
|
|
1927
|
+
return out;
|
|
1922
1928
|
}
|
|
1923
|
-
function
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1929
|
+
function sanitizeServerText(value, limit = NOTICE_MESSAGE_LIMIT) {
|
|
1930
|
+
if (typeof value !== "string") return "";
|
|
1931
|
+
const clean = stripTerminalControls(value).replace(/\s+/g, " ").trim();
|
|
1932
|
+
if (clean.length <= limit) return clean;
|
|
1933
|
+
const chars = Array.from(clean);
|
|
1934
|
+
return chars.length > limit ? chars.slice(0, limit).join("") : clean;
|
|
1935
|
+
}
|
|
1936
|
+
function sanitizeNoticeUrl(value) {
|
|
1937
|
+
if (typeof value !== "string") return null;
|
|
1938
|
+
let url;
|
|
1939
|
+
try {
|
|
1940
|
+
url = new URL(value.trim());
|
|
1941
|
+
} catch {
|
|
1942
|
+
return null;
|
|
1943
|
+
}
|
|
1944
|
+
if (url.protocol !== "https:") return null;
|
|
1945
|
+
if (!NOTICE_HOSTS.has(url.hostname) || url.port !== "") return null;
|
|
1946
|
+
if (url.username !== "" || url.password !== "") return null;
|
|
1947
|
+
const href = url.href;
|
|
1948
|
+
return href.length <= NOTICE_MESSAGE_LIMIT ? href : null;
|
|
1949
|
+
}
|
|
1950
|
+
function noticeSeverity(value) {
|
|
1951
|
+
if (value === "info") return "info";
|
|
1952
|
+
if (value === "error" || value === "critical") return "error";
|
|
1953
|
+
return "warning";
|
|
1954
|
+
}
|
|
1955
|
+
function sanitizeNotices(raw) {
|
|
1956
|
+
if (!Array.isArray(raw)) return [];
|
|
1957
|
+
const out = [];
|
|
1958
|
+
for (const entry of raw) {
|
|
1959
|
+
if (out.length >= NOTICE_LIMIT) break;
|
|
1960
|
+
if (typeof entry !== "object" || entry === null) continue;
|
|
1961
|
+
const n = entry;
|
|
1962
|
+
const message = sanitizeServerText(n.message);
|
|
1963
|
+
if (message === "") continue;
|
|
1964
|
+
out.push({
|
|
1965
|
+
severity: noticeSeverity(n.severity),
|
|
1966
|
+
code: sanitizeServerText(n.code, NOTICE_CODE_LIMIT),
|
|
1967
|
+
message,
|
|
1968
|
+
url: sanitizeNoticeUrl(n.url)
|
|
1969
|
+
});
|
|
1930
1970
|
}
|
|
1931
1971
|
return out;
|
|
1932
1972
|
}
|
|
1933
|
-
function
|
|
1934
|
-
const
|
|
1935
|
-
const
|
|
1936
|
-
return {
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
}),
|
|
1947
|
-
allowUnobfuscated: read("allowUnobfuscated"),
|
|
1948
|
-
telemetry: set({ enabled: read("telemetry.enabled") })
|
|
1949
|
-
},
|
|
1950
|
-
seed: read("seed"),
|
|
1951
|
-
preset: read("preset"),
|
|
1952
|
-
complexity: read("complexity"),
|
|
1953
|
-
regions: read("regions"),
|
|
1954
|
-
directives: {
|
|
1955
|
-
enabled: read("directives.enabled") ?? DIRECTIVES_ENABLED_DEFAULT,
|
|
1956
|
-
explicit: read("directives.enabled") !== void 0
|
|
1957
|
-
},
|
|
1958
|
-
build: set({ autorun: read("build.autorun") }),
|
|
1959
|
-
diagnostics: set({
|
|
1960
|
-
level: read("diagnostics.level"),
|
|
1961
|
-
format: read("diagnostics.format")
|
|
1962
|
-
}),
|
|
1963
|
-
paths: set({ include: read("paths.include") }),
|
|
1964
|
-
key: read("key")
|
|
1965
|
-
};
|
|
1973
|
+
function formatNotice(notice) {
|
|
1974
|
+
const head = notice.severity === "info" ? "AfterPack notice" : `AfterPack ${notice.severity}`;
|
|
1975
|
+
const tail = notice.url ? ` ${notice.url}` : "";
|
|
1976
|
+
return `${head}: ${notice.message}${tail}`;
|
|
1977
|
+
}
|
|
1978
|
+
function reportNotices(raw, logger, prefix = (m) => m) {
|
|
1979
|
+
const notices = sanitizeNotices(raw);
|
|
1980
|
+
for (const notice of notices) {
|
|
1981
|
+
const line = prefix(formatNotice(notice));
|
|
1982
|
+
if (notice.severity === "info" || !logger.warn) logger.log(line);
|
|
1983
|
+
else logger.warn(line);
|
|
1984
|
+
}
|
|
1985
|
+
return notices;
|
|
1966
1986
|
}
|
|
1967
1987
|
|
|
1968
1988
|
//#endregion
|
|
1969
1989
|
//#region src/compat.ts
|
|
1970
1990
|
const MIN_CORE_VERSION = "0.2.0";
|
|
1991
|
+
const SOURCE_TYPE_MIN_CORE_VERSION = "0.2.3";
|
|
1971
1992
|
const CORE_PACKAGE = "@afterpack/core";
|
|
1972
1993
|
const VERSION_PATTERN$1 = /^\d{1,9}\.\d{1,9}\.\d{1,9}(?:[-+][0-9A-Za-z.+-]{1,64})?$/;
|
|
1973
1994
|
const PACKAGE_NAME_PATTERN = /^(?:@[a-z0-9][a-z0-9._-]{0,63}\/)?[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
@@ -2039,6 +2060,9 @@ function isBelowVersion(version, minimum) {
|
|
|
2039
2060
|
for (let i = 0; i < 3; i++) if (have[i] !== need[i]) return have[i] < need[i];
|
|
2040
2061
|
return false;
|
|
2041
2062
|
}
|
|
2063
|
+
function coreSupportsSourceType(coreVersion) {
|
|
2064
|
+
return releaseTriple(coreVersion) !== null && !isBelowVersion(coreVersion, SOURCE_TYPE_MIN_CORE_VERSION);
|
|
2065
|
+
}
|
|
2042
2066
|
const CLI_PACKAGE = "afterpack";
|
|
2043
2067
|
function updateCommand(identity, minVersion) {
|
|
2044
2068
|
const core = `${CORE_PACKAGE}@${safeVersionString(minVersion) ?? "latest"}`;
|
|
@@ -2715,6 +2739,7 @@ function buildEngineConfig(options) {
|
|
|
2715
2739
|
if (options.complexity !== void 0) defaults.complexity = options.complexity;
|
|
2716
2740
|
if (options.preset !== void 0) defaults.preset = options.preset;
|
|
2717
2741
|
else if (options.complexity === void 0) defaults.preset = DEFAULT_PRESET;
|
|
2742
|
+
if (options.sourceType !== void 0) defaults.sourceType = options.sourceType;
|
|
2718
2743
|
const config = mergeInto({
|
|
2719
2744
|
...defaults,
|
|
2720
2745
|
sourceMap,
|
|
@@ -3778,7 +3803,7 @@ function fmtElapsed(ms) {
|
|
|
3778
3803
|
function formatPassSummary(input, style, colorGlyph = (glyph) => glyph) {
|
|
3779
3804
|
const head = style === "cli" ? colorGlyph("✓") : `[${input.label}]`;
|
|
3780
3805
|
const files = input.fileCount === 1 ? "file" : "files";
|
|
3781
|
-
const tail =
|
|
3806
|
+
const tail = input.noOpCount > 0 ? ` · ${input.noOpCount} no-op (unchanged)` : "";
|
|
3782
3807
|
return `${head} Protected ${input.fileCount} ${files} · ${fmtBytes(input.inputBytes)} → ${fmtBytes(input.outputBytes)}${tail} · ${fmtElapsed(input.elapsedMs)}`;
|
|
3783
3808
|
}
|
|
3784
3809
|
|
|
@@ -4121,7 +4146,7 @@ function fileFailure(f, source) {
|
|
|
4121
4146
|
if (reason) return reason;
|
|
4122
4147
|
return f.status === "failure" ? "empty output" : `the engine reported status "${sanitizeServerText(f.status, 32)}"`;
|
|
4123
4148
|
}
|
|
4124
|
-
if (
|
|
4149
|
+
if (f.unobfuscated === true) return "the engine could not obfuscate it and returned the original source — update @afterpack/core";
|
|
4125
4150
|
if (f.code === "" && source.trim() !== "") return sanitizeServerText(f.error) || "empty output";
|
|
4126
4151
|
return null;
|
|
4127
4152
|
}
|
|
@@ -4256,11 +4281,14 @@ async function runObfuscationPass(options) {
|
|
|
4256
4281
|
env,
|
|
4257
4282
|
cwd
|
|
4258
4283
|
});
|
|
4284
|
+
const localEngineVersion = await readEngineVersion(engine);
|
|
4285
|
+
const derivedSourceType = options.sourceType !== void 0 && coreSupportsSourceType(localEngineVersion ?? options.client?.coreVersion) ? options.sourceType : void 0;
|
|
4259
4286
|
const engineConfig = buildEngineConfig({
|
|
4260
4287
|
policy,
|
|
4261
4288
|
seed,
|
|
4262
4289
|
preset: options.preset,
|
|
4263
4290
|
complexity: options.complexity,
|
|
4291
|
+
sourceType: derivedSourceType,
|
|
4264
4292
|
regions: capture.regions,
|
|
4265
4293
|
engine: options.engineConfig,
|
|
4266
4294
|
renameGlobals: capture.renameGlobals
|
|
@@ -4298,7 +4326,7 @@ async function runObfuscationPass(options) {
|
|
|
4298
4326
|
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."));
|
|
4299
4327
|
const telemetry = options.telemetry;
|
|
4300
4328
|
const telemetryEnabled = telemetry != null && resolveTelemetryEnabled(artifactOptions.telemetry?.enabled, env);
|
|
4301
|
-
const engineVersion = (batch.source === "cloud" ? safeVersionString(batch.engineVersion) : null) ??
|
|
4329
|
+
const engineVersion = (batch.source === "cloud" ? safeVersionString(batch.engineVersion) : null) ?? localEngineVersion;
|
|
4302
4330
|
if (telemetry && telemetryEnabled) {
|
|
4303
4331
|
const facts = {
|
|
4304
4332
|
label,
|
|
@@ -4318,7 +4346,6 @@ async function runObfuscationPass(options) {
|
|
|
4318
4346
|
const outputs = [];
|
|
4319
4347
|
let inputBytes = 0;
|
|
4320
4348
|
let outputBytes = 0;
|
|
4321
|
-
const unobfuscatedFiles = [];
|
|
4322
4349
|
let noOp = 0;
|
|
4323
4350
|
const transformedFiles = [];
|
|
4324
4351
|
const verified = [];
|
|
@@ -4329,8 +4356,7 @@ async function runObfuscationPass(options) {
|
|
|
4329
4356
|
if (failure !== null) throw new Error(prefix(`failed to obfuscate ${f.path}: ${failure}`));
|
|
4330
4357
|
inputBytes += Buffer.byteLength(source);
|
|
4331
4358
|
outputBytes += Buffer.byteLength(f.code);
|
|
4332
|
-
if (f.
|
|
4333
|
-
else if (f.code === source) noOp += 1;
|
|
4359
|
+
if (f.code === source) noOp += 1;
|
|
4334
4360
|
else transformedFiles.push(f.path);
|
|
4335
4361
|
if (policy.protectionMap && f.protectionMap != null) protectionMapDocs.push(f.protectionMap);
|
|
4336
4362
|
verified.push({
|
|
@@ -4338,8 +4364,6 @@ async function runObfuscationPass(options) {
|
|
|
4338
4364
|
source
|
|
4339
4365
|
});
|
|
4340
4366
|
}
|
|
4341
|
-
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.`));
|
|
4342
|
-
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`));
|
|
4343
4367
|
const writtenFiles = [];
|
|
4344
4368
|
const emittedFiles = [];
|
|
4345
4369
|
for (const { result: f, source } of verified) {
|
|
@@ -4423,7 +4447,6 @@ async function runObfuscationPass(options) {
|
|
|
4423
4447
|
fileCount: files.length,
|
|
4424
4448
|
inputBytes,
|
|
4425
4449
|
outputBytes,
|
|
4426
|
-
unobfuscatedCount: unobfuscatedFiles.length,
|
|
4427
4450
|
noOpCount: noOp,
|
|
4428
4451
|
elapsedMs: totalMs
|
|
4429
4452
|
}, style, options.colorGlyph) + seedSuffix);
|
|
@@ -4658,6 +4681,8 @@ exports.sanitizeNotices = sanitizeNotices;
|
|
|
4658
4681
|
exports.scanDirectives = scanDirectives;
|
|
4659
4682
|
exports.serverAddsInfo = serverAddsInfo;
|
|
4660
4683
|
exports.sha256Of = sha256Of;
|
|
4684
|
+
exports.sourceTypeForBundle = sourceTypeForBundle;
|
|
4685
|
+
exports.sourceTypeForOutputFormat = sourceTypeForOutputFormat;
|
|
4661
4686
|
exports.stripBundleCssSourceMaps = stripBundleCssSourceMaps;
|
|
4662
4687
|
exports.toEngineConfig = toEngineConfig;
|
|
4663
4688
|
exports.toPluginOptions = toPluginOptions;
|