@afterpack/integration-utils 1.0.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +34 -0
- package/dist/index.cjs +418 -184
- package/dist/index.d.cts +42 -20
- package/dist/index.d.ts +42 -20
- package/dist/index.js +416 -183
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -1416,6 +1416,19 @@ const CONFIG_PREFIXES = new Set(CONFIG_KEYS.flatMap((k) => {
|
|
|
1416
1416
|
const parts = k.path.split(".");
|
|
1417
1417
|
return parts.slice(0, -1).map((_, i) => parts.slice(0, i + 1).join("."));
|
|
1418
1418
|
}));
|
|
1419
|
+
const ENV_PREFIX = "AFTERPACK_";
|
|
1420
|
+
function screamingSnake(path) {
|
|
1421
|
+
return path.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/\./g, "_").toUpperCase();
|
|
1422
|
+
}
|
|
1423
|
+
function envName(path) {
|
|
1424
|
+
return `${ENV_PREFIX}${screamingSnake(path)}`;
|
|
1425
|
+
}
|
|
1426
|
+
const CONFIG_BY_ENV_NAME = new Map([...CONFIG_KEYS.map((k) => k.path), ...CONFIG_PREFIXES].map((path) => [envName(path), path]));
|
|
1427
|
+
const ENV_GROUPS = new Set(CONFIG_KEYS.map((k) => screamingSnake(k.path.split(".")[0])));
|
|
1428
|
+
function claimsEnvSuffix(suffix) {
|
|
1429
|
+
for (const group$1 of ENV_GROUPS) if (suffix === group$1 || suffix.startsWith(`${group$1}_`)) return true;
|
|
1430
|
+
return false;
|
|
1431
|
+
}
|
|
1419
1432
|
const CONFIG_CHILDREN = new Map([...CONFIG_PREFIXES].map((prefix) => [prefix, CONFIG_KEYS.filter((k) => k.path.startsWith(`${prefix}.`)).map((k) => k.path)]));
|
|
1420
1433
|
const BY_NORMALIZED = new Map(CONFIG_KEYS.map((k) => [normalizeKey(k.path), k]));
|
|
1421
1434
|
const CHILDREN_BY_NORMALIZED = new Map([...CONFIG_CHILDREN].map(([prefix, children]) => [normalizeKey(prefix), children]));
|
|
@@ -1468,18 +1481,18 @@ function editDistance(a, b) {
|
|
|
1468
1481
|
return prev[b.length];
|
|
1469
1482
|
}
|
|
1470
1483
|
const DOCS_URL = "https://www.afterpack.dev/docs/config";
|
|
1471
|
-
function unknownKeyMessage(path, surface) {
|
|
1484
|
+
function unknownKeyMessage(path, surface, spell = (p) => p) {
|
|
1472
1485
|
const group$1 = CHILDREN_BY_NORMALIZED.get(normalizeKey(path));
|
|
1473
1486
|
if (group$1 && group$1.length > 0) {
|
|
1474
|
-
const list = group$1.map((child) => `\`${child}\``).join(", ");
|
|
1487
|
+
const list = group$1.map((child) => `\`${spell(child)}\``).join(", ");
|
|
1475
1488
|
const tail$1 = group$1.length === 1 ? `did you mean ${list}?` : `its keys are ${list}`;
|
|
1476
1489
|
const canonical$1 = PREFIX_BY_NORMALIZED.get(normalizeKey(path));
|
|
1477
1490
|
const enabled = canonical$1 ? groupBooleanKey(canonical$1) : void 0;
|
|
1478
|
-
const rule = enabled ? `; a boolean here means \`${enabled.path}\`` : "";
|
|
1491
|
+
const rule = enabled ? `; a boolean here means \`${spell(enabled.path)}\`` : "";
|
|
1479
1492
|
return `\`${path}\` is a group of configuration keys, not a key itself (${surface}) — ${tail$1}${rule}`;
|
|
1480
1493
|
}
|
|
1481
1494
|
const suggestion = suggestKey(path);
|
|
1482
|
-
const tail = suggestion ? ` — did you mean \`${suggestion}\`?` : ` — see ${DOCS_URL}`;
|
|
1495
|
+
const tail = suggestion ? ` — did you mean \`${spell(suggestion)}\`?` : ` — see ${DOCS_URL}`;
|
|
1483
1496
|
return `unknown configuration key \`${path}\` (${surface})${tail}`;
|
|
1484
1497
|
}
|
|
1485
1498
|
function isPlainObject(value) {
|
|
@@ -1497,6 +1510,25 @@ function describe(item) {
|
|
|
1497
1510
|
case "region": return "an object with numeric `start` and `end`";
|
|
1498
1511
|
}
|
|
1499
1512
|
}
|
|
1513
|
+
const CONFIG_RESET = Symbol.for("afterpack.config.reset");
|
|
1514
|
+
function isBlank(value) {
|
|
1515
|
+
return typeof value === "string" && value.trim() === "";
|
|
1516
|
+
}
|
|
1517
|
+
function emptyValue(key) {
|
|
1518
|
+
if (key.shape === "list" || key.shape === "mixedList") return [];
|
|
1519
|
+
if (key.shape !== "scalar") return void 0;
|
|
1520
|
+
return key.item.kind === "seed" || key.item.kind === "string" ? CONFIG_RESET : void 0;
|
|
1521
|
+
}
|
|
1522
|
+
function emptyValueMessage(key, written, surface) {
|
|
1523
|
+
return `\`${key.path}\` is empty in \`${written}\` (${surface}) — an empty value resets only \`key\`, \`seed\` and list keys to their default, and \`${key.path}\` has no empty form: set it to ${describe(key.item)}, or remove it`;
|
|
1524
|
+
}
|
|
1525
|
+
function emptyGroupMessage(group$1, written, surface, spell = (p) => p) {
|
|
1526
|
+
const children = CONFIG_CHILDREN.get(group$1) ?? [];
|
|
1527
|
+
return `\`${written}\` is empty and names the group \`${group$1}\`, not a key (${surface}) — set one of its keys instead: ${children.map((child) => `\`${spell(child)}\``).join(", ")}`;
|
|
1528
|
+
}
|
|
1529
|
+
function shownValue(value) {
|
|
1530
|
+
return value === CONFIG_RESET ? "\"\"" : JSON.stringify(value);
|
|
1531
|
+
}
|
|
1500
1532
|
function misdirectedHint(key, value, spell) {
|
|
1501
1533
|
const other = misdirectedTo(key, value);
|
|
1502
1534
|
if (!other) return "";
|
|
@@ -1664,6 +1696,15 @@ function walk(source, prefix, target, issues, surface) {
|
|
|
1664
1696
|
if (value === void 0) continue;
|
|
1665
1697
|
const path = prefix ? `${prefix}.${name}` : name;
|
|
1666
1698
|
const key = CONFIG_BY_PATH.get(path);
|
|
1699
|
+
if (key && isBlank(value)) {
|
|
1700
|
+
const reset = emptyValue(key);
|
|
1701
|
+
if (reset === void 0) issues.push({
|
|
1702
|
+
path,
|
|
1703
|
+
message: emptyValueMessage(key, `"${path}": ${JSON.stringify(value)}`, surface)
|
|
1704
|
+
});
|
|
1705
|
+
else target[name] = reset;
|
|
1706
|
+
continue;
|
|
1707
|
+
}
|
|
1667
1708
|
if (key) {
|
|
1668
1709
|
const failure = checkValue(key, value);
|
|
1669
1710
|
if (failure) {
|
|
@@ -1709,6 +1750,41 @@ function mergeInto(base, override) {
|
|
|
1709
1750
|
function mergeConfig(base, override) {
|
|
1710
1751
|
return deepMerge(base, override);
|
|
1711
1752
|
}
|
|
1753
|
+
function withoutResets(config) {
|
|
1754
|
+
const out = {};
|
|
1755
|
+
for (const [name, value] of Object.entries(config)) {
|
|
1756
|
+
if (value === CONFIG_RESET || value === void 0) continue;
|
|
1757
|
+
if (isPlainObject(value)) {
|
|
1758
|
+
const inner = withoutResets(value);
|
|
1759
|
+
if (Object.keys(inner).length > 0) out[name] = inner;
|
|
1760
|
+
continue;
|
|
1761
|
+
}
|
|
1762
|
+
out[name] = value;
|
|
1763
|
+
}
|
|
1764
|
+
return out;
|
|
1765
|
+
}
|
|
1766
|
+
function appendLists(config, extra) {
|
|
1767
|
+
const out = config;
|
|
1768
|
+
for (const key of CONFIG_KEYS) {
|
|
1769
|
+
if (key.shape !== "list" && key.shape !== "mixedList") continue;
|
|
1770
|
+
const added = getPath(extra, key.path);
|
|
1771
|
+
if (!Array.isArray(added) || added.length === 0) continue;
|
|
1772
|
+
const current = getPath(out, key.path);
|
|
1773
|
+
const base = Array.isArray(current) ? current : [];
|
|
1774
|
+
const fresh = added.filter((item) => !base.some((b) => JSON.stringify(b) === JSON.stringify(item)));
|
|
1775
|
+
setPath(out, key.path, [...base, ...fresh]);
|
|
1776
|
+
}
|
|
1777
|
+
return out;
|
|
1778
|
+
}
|
|
1779
|
+
function mergeLayers(layers, appended = EMPTY_CONFIG) {
|
|
1780
|
+
const merged = layers.reduce(mergeConfig, EMPTY_CONFIG);
|
|
1781
|
+
return appendLists(withoutResets(merged), appended);
|
|
1782
|
+
}
|
|
1783
|
+
function cloudKey(value) {
|
|
1784
|
+
if (typeof value !== "string") return null;
|
|
1785
|
+
const trimmed = value.trim();
|
|
1786
|
+
return trimmed === "" ? null : trimmed;
|
|
1787
|
+
}
|
|
1712
1788
|
function getPath(config, path) {
|
|
1713
1789
|
let current = config;
|
|
1714
1790
|
for (const part of path.split(".")) {
|
|
@@ -1730,17 +1806,19 @@ function setPath(target, path, value) {
|
|
|
1730
1806
|
node[parts[parts.length - 1]] = value;
|
|
1731
1807
|
}
|
|
1732
1808
|
function toEngineConfig(config) {
|
|
1809
|
+
const clean = withoutResets(config);
|
|
1733
1810
|
const out = {};
|
|
1734
1811
|
for (const key of CONFIG_KEYS) {
|
|
1735
1812
|
if (key.surface !== "engine") continue;
|
|
1736
|
-
const value = getPath(
|
|
1813
|
+
const value = getPath(clean, key.path);
|
|
1737
1814
|
if (value === void 0) continue;
|
|
1738
1815
|
setPath(out, key.path, value);
|
|
1739
1816
|
}
|
|
1740
1817
|
return out;
|
|
1741
1818
|
}
|
|
1742
1819
|
function toPluginOptions(config) {
|
|
1743
|
-
const
|
|
1820
|
+
const clean = withoutResets(config);
|
|
1821
|
+
const read = (path) => getPath(clean, path);
|
|
1744
1822
|
const set = (container) => Object.values(container).some((v) => v !== void 0) ? container : void 0;
|
|
1745
1823
|
return {
|
|
1746
1824
|
artifactOptions: {
|
|
@@ -1769,7 +1847,7 @@ function toPluginOptions(config) {
|
|
|
1769
1847
|
format: read("diagnostics.format")
|
|
1770
1848
|
}),
|
|
1771
1849
|
paths: set({ include: read("paths.include") }),
|
|
1772
|
-
key: read("key")
|
|
1850
|
+
key: cloudKey(read("key"))
|
|
1773
1851
|
};
|
|
1774
1852
|
}
|
|
1775
1853
|
|
|
@@ -2300,6 +2378,7 @@ function reportNotices(raw, logger, prefix = (m) => m) {
|
|
|
2300
2378
|
const MIN_CORE_VERSION = "1.0.0";
|
|
2301
2379
|
const SOURCE_TYPE_MIN_CORE_VERSION = "0.2.3";
|
|
2302
2380
|
const FILE_SOURCE_TYPE_MIN_CORE_VERSION = "0.2.5";
|
|
2381
|
+
const NULL_KEY_MIN_CORE_VERSION = "1.1.0";
|
|
2303
2382
|
const CORE_PACKAGE = "@afterpack/core";
|
|
2304
2383
|
const VERSION_PATTERN$1 = /^\d{1,9}\.\d{1,9}\.\d{1,9}(?:[-+][0-9A-Za-z.+-]{1,64})?$/;
|
|
2305
2384
|
const PACKAGE_NAME_PATTERN = /^(?:@[a-z0-9][a-z0-9._-]{0,63}\/)?[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
@@ -2405,6 +2484,21 @@ function coreSupportsSourceType(coreVersion) {
|
|
|
2405
2484
|
function coreSupportsFileSourceType(coreVersion) {
|
|
2406
2485
|
return releaseTriple(coreVersion) !== null && !isBelowVersion(coreVersion, FILE_SOURCE_TYPE_MIN_CORE_VERSION);
|
|
2407
2486
|
}
|
|
2487
|
+
function coreHonoursNullKey(coreVersion) {
|
|
2488
|
+
return !isBelowVersion(coreVersion, NULL_KEY_MIN_CORE_VERSION);
|
|
2489
|
+
}
|
|
2490
|
+
function keySourceForOlderCore(env, startDir) {
|
|
2491
|
+
if ((env.AFTERPACK_KEY ?? "").trim() !== "") return "AFTERPACK_KEY";
|
|
2492
|
+
const path = findUpward(startDir, "afterpack.json");
|
|
2493
|
+
if (!path) return null;
|
|
2494
|
+
try {
|
|
2495
|
+
const parsed = JSON.parse((0, node_fs.readFileSync)(path, "utf8"));
|
|
2496
|
+
const key = isPlainObject(parsed) ? parsed.key : void 0;
|
|
2497
|
+
return typeof key === "string" && key.trim() !== "" ? path : null;
|
|
2498
|
+
} catch {
|
|
2499
|
+
return null;
|
|
2500
|
+
}
|
|
2501
|
+
}
|
|
2408
2502
|
const CLI_PACKAGE = "afterpack";
|
|
2409
2503
|
function updateCommand(identity, minVersion) {
|
|
2410
2504
|
const core = `${CORE_PACKAGE}@${safeVersionString(minVersion) ?? "latest"}`;
|
|
@@ -2617,9 +2711,157 @@ function loadConfigFile(startDir) {
|
|
|
2617
2711
|
};
|
|
2618
2712
|
}
|
|
2619
2713
|
|
|
2714
|
+
//#endregion
|
|
2715
|
+
//#region src/seed.ts
|
|
2716
|
+
function randomSeed() {
|
|
2717
|
+
const b = (0, node_crypto.randomBytes)(8);
|
|
2718
|
+
const hi = b.readUInt32BE(0) & 2097151;
|
|
2719
|
+
const lo = b.readUInt32BE(4);
|
|
2720
|
+
return hi * 4294967296 + lo;
|
|
2721
|
+
}
|
|
2722
|
+
function gitHead() {
|
|
2723
|
+
try {
|
|
2724
|
+
const out = (0, node_child_process.execFileSync)("git", ["rev-parse", "HEAD"], { stdio: [
|
|
2725
|
+
"ignore",
|
|
2726
|
+
"pipe",
|
|
2727
|
+
"ignore"
|
|
2728
|
+
] }).toString().trim();
|
|
2729
|
+
return /^[0-9a-f]{7,64}$/i.test(out) ? out : null;
|
|
2730
|
+
} catch {
|
|
2731
|
+
return null;
|
|
2732
|
+
}
|
|
2733
|
+
}
|
|
2734
|
+
const SEED_ENV_VAR = "AFTERPACK_SEED";
|
|
2735
|
+
function parseSeedValue(raw) {
|
|
2736
|
+
return /^-?\d+$/.test(raw) ? Number(raw) : raw;
|
|
2737
|
+
}
|
|
2738
|
+
const SEED_STATE = Symbol.for("afterpack.integration-utils.seed-sessions");
|
|
2739
|
+
function sharedSeedState() {
|
|
2740
|
+
const holder = globalThis;
|
|
2741
|
+
holder[SEED_STATE] ??= {
|
|
2742
|
+
sessions: new Map(),
|
|
2743
|
+
ownEnvExports: []
|
|
2744
|
+
};
|
|
2745
|
+
return holder[SEED_STATE];
|
|
2746
|
+
}
|
|
2747
|
+
const { sessions, ownEnvExports } = sharedSeedState();
|
|
2748
|
+
function isOwnEnvExport(env, value) {
|
|
2749
|
+
return ownEnvExports.some((e) => e.env === env && e.value === value);
|
|
2750
|
+
}
|
|
2751
|
+
function envSeedBeforeOwnExport(env, value) {
|
|
2752
|
+
const own = ownEnvExports.find((e) => e.env === env && e.value === value);
|
|
2753
|
+
return own ? { prior: own.prior } : null;
|
|
2754
|
+
}
|
|
2755
|
+
function openGeneration(root, leg) {
|
|
2756
|
+
let session = sessions.get(root);
|
|
2757
|
+
if (!session) {
|
|
2758
|
+
session = {
|
|
2759
|
+
seed: void 0,
|
|
2760
|
+
generation: 1,
|
|
2761
|
+
legs: [],
|
|
2762
|
+
resolvedByLeg: new Map(),
|
|
2763
|
+
gitFallbackWarned: false
|
|
2764
|
+
};
|
|
2765
|
+
sessions.set(root, session);
|
|
2766
|
+
} else if (session.legs.includes(leg)) {
|
|
2767
|
+
session.seed = void 0;
|
|
2768
|
+
session.generation += 1;
|
|
2769
|
+
session.legs = [];
|
|
2770
|
+
session.resolvedByLeg.clear();
|
|
2771
|
+
session.gitFallbackWarned = false;
|
|
2772
|
+
}
|
|
2773
|
+
session.legs.push(leg);
|
|
2774
|
+
return session;
|
|
2775
|
+
}
|
|
2776
|
+
function pinnedEnvSeed(env) {
|
|
2777
|
+
const fromEnv = env[SEED_ENV_VAR];
|
|
2778
|
+
if (fromEnv == null || fromEnv.trim() === "" || isOwnEnvExport(env, fromEnv)) return void 0;
|
|
2779
|
+
return parseSeedValue(fromEnv);
|
|
2780
|
+
}
|
|
2781
|
+
function gitFallbackNotice(fallback) {
|
|
2782
|
+
const using = fallback ? `falling back to the seed ${JSON.stringify(fallback.seed)} from ${fallback.from}` : "using a fresh random seed for this build";
|
|
2783
|
+
return `[afterpack] seed "git": no git repository / HEAD found; ${using}.`;
|
|
2784
|
+
}
|
|
2785
|
+
function resolveWithinSession(input, session, env, deps) {
|
|
2786
|
+
if (typeof input === "number") return {
|
|
2787
|
+
seed: input,
|
|
2788
|
+
origin: "option"
|
|
2789
|
+
};
|
|
2790
|
+
if (typeof input === "string" && input !== "git") return {
|
|
2791
|
+
seed: input,
|
|
2792
|
+
origin: "option"
|
|
2793
|
+
};
|
|
2794
|
+
const layered = deps.fallback !== void 0;
|
|
2795
|
+
const fromEnv = layered ? void 0 : pinnedEnvSeed(env);
|
|
2796
|
+
if (input === "git") {
|
|
2797
|
+
const head = (deps.gitHead ?? gitHead)();
|
|
2798
|
+
if (head) return {
|
|
2799
|
+
seed: head,
|
|
2800
|
+
origin: "git"
|
|
2801
|
+
};
|
|
2802
|
+
const fallback = layered ? deps.fallback ?? null : fromEnv === void 0 ? null : {
|
|
2803
|
+
seed: fromEnv,
|
|
2804
|
+
origin: "env",
|
|
2805
|
+
from: SEED_ENV_VAR
|
|
2806
|
+
};
|
|
2807
|
+
if (!session.gitFallbackWarned) {
|
|
2808
|
+
session.gitFallbackWarned = true;
|
|
2809
|
+
(deps.warn ?? ((m) => console.warn(m)))(gitFallbackNotice(fallback));
|
|
2810
|
+
}
|
|
2811
|
+
if (fallback) return {
|
|
2812
|
+
seed: fallback.seed,
|
|
2813
|
+
origin: fallback.origin
|
|
2814
|
+
};
|
|
2815
|
+
} else if (fromEnv !== void 0) return {
|
|
2816
|
+
seed: fromEnv,
|
|
2817
|
+
origin: "env"
|
|
2818
|
+
};
|
|
2819
|
+
if (session.seed !== void 0) return {
|
|
2820
|
+
seed: session.seed,
|
|
2821
|
+
origin: "session"
|
|
2822
|
+
};
|
|
2823
|
+
return {
|
|
2824
|
+
seed: (deps.randomSeed ?? randomSeed)(),
|
|
2825
|
+
origin: "fresh"
|
|
2826
|
+
};
|
|
2827
|
+
}
|
|
2828
|
+
function resolveBuildSeed(input, scope, deps = {}) {
|
|
2829
|
+
const env = deps.env ?? process.env;
|
|
2830
|
+
const session = openGeneration(scope.root, scope.leg);
|
|
2831
|
+
const { seed, origin } = resolveWithinSession(input, session, env, deps);
|
|
2832
|
+
if (origin === "env" || origin === "fresh") session.seed = seed;
|
|
2833
|
+
if (origin === "fresh" && (deps.exportToEnv ?? true)) {
|
|
2834
|
+
const value = String(seed);
|
|
2835
|
+
const stale = ownEnvExports.findIndex((e) => e.env === env);
|
|
2836
|
+
const current = env[SEED_ENV_VAR];
|
|
2837
|
+
const prior$1 = stale >= 0 && current === ownEnvExports[stale].value ? ownEnvExports[stale].prior : current;
|
|
2838
|
+
env[SEED_ENV_VAR] = value;
|
|
2839
|
+
if (stale >= 0) ownEnvExports.splice(stale, 1);
|
|
2840
|
+
ownEnvExports.push(prior$1 === void 0 ? {
|
|
2841
|
+
env,
|
|
2842
|
+
value
|
|
2843
|
+
} : {
|
|
2844
|
+
env,
|
|
2845
|
+
value,
|
|
2846
|
+
prior: prior$1
|
|
2847
|
+
});
|
|
2848
|
+
}
|
|
2849
|
+
const prior = [...session.resolvedByLeg].find(([, s]) => s !== seed);
|
|
2850
|
+
session.resolvedByLeg.set(scope.leg, seed);
|
|
2851
|
+
return {
|
|
2852
|
+
seed,
|
|
2853
|
+
origin,
|
|
2854
|
+
legs: [...session.legs],
|
|
2855
|
+
generation: session.generation,
|
|
2856
|
+
mismatch: prior && session.generation === 1 ? {
|
|
2857
|
+
leg: prior[0],
|
|
2858
|
+
seed: prior[1]
|
|
2859
|
+
} : null
|
|
2860
|
+
};
|
|
2861
|
+
}
|
|
2862
|
+
|
|
2620
2863
|
//#endregion
|
|
2621
2864
|
//#region src/config-parse.ts
|
|
2622
|
-
const ENV_PREFIX = "AFTERPACK_";
|
|
2623
2865
|
function splitAssignment(token) {
|
|
2624
2866
|
const eq = token.indexOf("=");
|
|
2625
2867
|
if (eq < 0) return {
|
|
@@ -2648,9 +2890,12 @@ function parseListLiteral(raw) {
|
|
|
2648
2890
|
}
|
|
2649
2891
|
function spellKey(path, surface) {
|
|
2650
2892
|
if (surface === "cli") return `--${path}`;
|
|
2651
|
-
if (surface === "env") return
|
|
2893
|
+
if (surface === "env") return envName(path);
|
|
2652
2894
|
return path;
|
|
2653
2895
|
}
|
|
2896
|
+
function writtenKey(key, surface) {
|
|
2897
|
+
return surface === "env" ? `${ENV_PREFIX}${key.replace(/\./g, "_")}` : spellKey(key, surface);
|
|
2898
|
+
}
|
|
2654
2899
|
function surfaceLabel(surface) {
|
|
2655
2900
|
if (surface === "cli") return "command line";
|
|
2656
2901
|
if (surface === "env") return "environment";
|
|
@@ -2692,10 +2937,36 @@ function kebabIssue(key, surface) {
|
|
|
2692
2937
|
const canonical$1 = suggestion ? ` — the canonical form is \`${spellKey(suggestion, surface)}\`` : " — keys are dot-delimited camelCase";
|
|
2693
2938
|
return {
|
|
2694
2939
|
path: key,
|
|
2695
|
-
message: `kebab-case is not a configuration key (\`${
|
|
2940
|
+
message: `kebab-case is not a configuration key (\`${writtenKey(key, surface)}\`)${canonical$1}`
|
|
2696
2941
|
};
|
|
2697
2942
|
}
|
|
2698
|
-
function
|
|
2943
|
+
function emptyAssignment(key, surface, written) {
|
|
2944
|
+
const spell = (p) => surface === "env" ? envName(p) : spellKey(p, surface);
|
|
2945
|
+
if (CONFIG_PREFIXES.has(key) && !CONFIG_BY_PATH.has(key)) return { issue: {
|
|
2946
|
+
path: key,
|
|
2947
|
+
message: emptyGroupMessage(key, written, surfaceLabel(surface), spell)
|
|
2948
|
+
} };
|
|
2949
|
+
const def = CONFIG_BY_PATH.get(key);
|
|
2950
|
+
if (!def || def.shape === "structured") return void 0;
|
|
2951
|
+
const reset = emptyValue(def);
|
|
2952
|
+
if (reset === void 0) return { issue: {
|
|
2953
|
+
path: key,
|
|
2954
|
+
message: emptyValueMessage(def, written, surfaceLabel(surface))
|
|
2955
|
+
} };
|
|
2956
|
+
return { assignment: {
|
|
2957
|
+
path: def.path,
|
|
2958
|
+
value: reset
|
|
2959
|
+
} };
|
|
2960
|
+
}
|
|
2961
|
+
function writtenEmpty(key, surface, raw) {
|
|
2962
|
+
if (surface === "env") return writtenKey(key, surface);
|
|
2963
|
+
return `${spellKey(key, surface)}=${raw}`;
|
|
2964
|
+
}
|
|
2965
|
+
function parseAssignment(key, raw, surface, written) {
|
|
2966
|
+
if (isBlank(raw)) {
|
|
2967
|
+
const empty = emptyAssignment(key, surface, written ?? writtenEmpty(key, surface, raw));
|
|
2968
|
+
if (empty) return empty;
|
|
2969
|
+
}
|
|
2699
2970
|
const spaced = raw === true ? /^(\S+)[ \t]+(.+)$/.exec(key) : null;
|
|
2700
2971
|
const head = spaced ? CONFIG_BY_PATH.get(spaced[1]) : void 0;
|
|
2701
2972
|
if (spaced && head) return { issue: head.shape === "structured" ? structuredIssue(head, surface) : spaceFormIssue(head.path, spaced[2], surface) };
|
|
@@ -2704,10 +2975,13 @@ function parseAssignment(key, raw, surface) {
|
|
|
2704
2975
|
const boolish = raw === true || typeof parseScalarLiteral(raw) === "boolean";
|
|
2705
2976
|
const path = grouped && boolish ? grouped.path : key;
|
|
2706
2977
|
const def = CONFIG_BY_PATH.get(path);
|
|
2707
|
-
if (!def)
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2978
|
+
if (!def) {
|
|
2979
|
+
const spell = (p) => surface === "env" ? envName(p) : p;
|
|
2980
|
+
return { issue: {
|
|
2981
|
+
path: key,
|
|
2982
|
+
message: unknownKeyMessage(key, surfaceLabel(surface), spell)
|
|
2983
|
+
} };
|
|
2984
|
+
}
|
|
2711
2985
|
if (def.shape === "structured") return { issue: structuredIssue(def, surface) };
|
|
2712
2986
|
if (raw === true) {
|
|
2713
2987
|
const failure$1 = checkValue(def, true);
|
|
@@ -2798,41 +3072,68 @@ function parseCliOptions(argv) {
|
|
|
2798
3072
|
issues
|
|
2799
3073
|
};
|
|
2800
3074
|
}
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
const
|
|
2804
|
-
const envForm = (path) => `${ENV_PREFIX}${path.replace(/\./g, "_")}`;
|
|
2805
|
-
const spelling = canonicalSpelling(dotted);
|
|
3075
|
+
function unclaimedEnvIssue(name, suffix) {
|
|
3076
|
+
const spelling = canonicalSpelling(suffix);
|
|
3077
|
+
const near = spelling ? void 0 : suggestKey(suffix);
|
|
2806
3078
|
let tail = `see ${DOCS_URL}`;
|
|
2807
|
-
if (spelling && "key" in spelling) tail = `
|
|
2808
|
-
else if (spelling && spelling.group.length === 1) tail = `
|
|
2809
|
-
else if (spelling) tail = `its keys are ${spelling.group.map((k) => `\`${
|
|
3079
|
+
if (spelling && "key" in spelling) tail = `did you mean \`${envName(spelling.key)}\`?`;
|
|
3080
|
+
else if (spelling && spelling.group.length === 1) tail = `did you mean \`${envName(spelling.group[0])}\`?`;
|
|
3081
|
+
else if (spelling) tail = `its keys are ${spelling.group.map((k) => `\`${envName(k)}\``).join(", ")}`;
|
|
3082
|
+
else if (near) tail = `did you mean \`${envName(near)}\`?`;
|
|
2810
3083
|
return {
|
|
2811
3084
|
path: suffix,
|
|
2812
|
-
message: `\`${name}\` is not a configuration variable —
|
|
3085
|
+
message: `\`${name}\` is not a configuration variable — ${tail}`
|
|
2813
3086
|
};
|
|
2814
3087
|
}
|
|
2815
|
-
function
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
3088
|
+
function conflictIssue(path, first, second) {
|
|
3089
|
+
return {
|
|
3090
|
+
path,
|
|
3091
|
+
message: `\`${first}\` and \`${second}\` both set \`${path}\`, to different values — keep one: \`${envName(path)}\``
|
|
3092
|
+
};
|
|
2819
3093
|
}
|
|
2820
3094
|
function parseEnvOptions(env) {
|
|
2821
3095
|
const assignments = [];
|
|
2822
3096
|
const issues = [];
|
|
3097
|
+
const setBy = new Map();
|
|
2823
3098
|
for (const name of Object.keys(env).sort()) {
|
|
2824
3099
|
if (!name.startsWith(ENV_PREFIX)) continue;
|
|
2825
3100
|
const suffix = name.slice(ENV_PREFIX.length);
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
3101
|
+
let raw = env[name];
|
|
3102
|
+
if (suffix === "" || raw === void 0) continue;
|
|
3103
|
+
let key = suffix.replace(/_/g, ".");
|
|
2829
3104
|
if (!/[a-z]/.test(suffix)) {
|
|
2830
|
-
|
|
3105
|
+
const path$1 = CONFIG_BY_ENV_NAME.get(name);
|
|
3106
|
+
if (path$1 === void 0) {
|
|
3107
|
+
if (isBlank(raw)) continue;
|
|
3108
|
+
if (claimsEnvSuffix(suffix) || canonicalSpelling(suffix) !== void 0) issues.push(unclaimedEnvIssue(name, suffix));
|
|
3109
|
+
continue;
|
|
3110
|
+
}
|
|
3111
|
+
if (name === SEED_ENV_VAR) {
|
|
3112
|
+
const own = envSeedBeforeOwnExport(env, raw);
|
|
3113
|
+
if (own) {
|
|
3114
|
+
if (own.prior === void 0) continue;
|
|
3115
|
+
raw = own.prior;
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
key = path$1;
|
|
3119
|
+
}
|
|
3120
|
+
const parsed = parseAssignment(key, raw, "env", name);
|
|
3121
|
+
if ("issue" in parsed) {
|
|
3122
|
+
issues.push(parsed.issue);
|
|
2831
3123
|
continue;
|
|
2832
3124
|
}
|
|
2833
|
-
const
|
|
2834
|
-
|
|
2835
|
-
|
|
3125
|
+
const { path, value } = parsed.assignment;
|
|
3126
|
+
const prior = setBy.get(path);
|
|
3127
|
+
const written = JSON.stringify(value);
|
|
3128
|
+
if (prior && prior.value !== written) {
|
|
3129
|
+
issues.push(conflictIssue(path, prior.name, name));
|
|
3130
|
+
continue;
|
|
3131
|
+
}
|
|
3132
|
+
setBy.set(path, {
|
|
3133
|
+
name,
|
|
3134
|
+
value: written
|
|
3135
|
+
});
|
|
3136
|
+
assignments.push(parsed.assignment);
|
|
2836
3137
|
}
|
|
2837
3138
|
return {
|
|
2838
3139
|
config: collect(assignments),
|
|
@@ -3021,7 +3322,7 @@ function reportDiagnostics(input) {
|
|
|
3021
3322
|
const cap = verbosity === "all" ? list.length : MAX_INSTANCES_PER_CODE;
|
|
3022
3323
|
for (const d of list.slice(0, cap)) logger.warn(prefix(formatDiagnostic(d)));
|
|
3023
3324
|
const hidden = list.length - cap;
|
|
3024
|
-
if (hidden > 0) logger.warn(prefix(`${list[0].severity} ${code} · +${hidden} more occurrence(s) (
|
|
3325
|
+
if (hidden > 0) logger.warn(prefix(`${list[0].severity} ${code} · +${hidden} more occurrence(s) (AFTERPACK_DIAGNOSTICS_LEVEL=all to list them)`));
|
|
3025
3326
|
}
|
|
3026
3327
|
if (summary.critical > 0) logger.warn(prefix(`${summary.critical} critical diagnostic(s) above are engine bugs — please report them at ${ISSUES_URL}, quoting the code(s).`));
|
|
3027
3328
|
return summary;
|
|
@@ -3251,7 +3552,7 @@ const DIRECTIVE_KEYS = [
|
|
|
3251
3552
|
key: "complexity",
|
|
3252
3553
|
kind: "amplifier",
|
|
3253
3554
|
apply: (delta, value) => {
|
|
3254
|
-
const n = Number(value);
|
|
3555
|
+
const n = value.trim() === "" ? Number.NaN : Number(value);
|
|
3255
3556
|
if (!Number.isFinite(n) || n < 0) return "`complexity` needs a non-negative number";
|
|
3256
3557
|
delta.complexity = n;
|
|
3257
3558
|
return void 0;
|
|
@@ -3261,7 +3562,7 @@ const DIRECTIVE_KEYS = [
|
|
|
3261
3562
|
key: "inflation.max",
|
|
3262
3563
|
kind: "amplifier",
|
|
3263
3564
|
apply: (delta, value) => {
|
|
3264
|
-
const n = Number(value);
|
|
3565
|
+
const n = value.trim() === "" ? Number.NaN : Number(value);
|
|
3265
3566
|
if (!Number.isFinite(n) || n < 0) return "`inflation.max` needs a non-negative number";
|
|
3266
3567
|
delta.inflation = { max: n };
|
|
3267
3568
|
return void 0;
|
|
@@ -3597,127 +3898,6 @@ function captureDirectiveRegions(inputs, handAuthored, enabled = true) {
|
|
|
3597
3898
|
};
|
|
3598
3899
|
}
|
|
3599
3900
|
|
|
3600
|
-
//#endregion
|
|
3601
|
-
//#region src/seed.ts
|
|
3602
|
-
function randomSeed() {
|
|
3603
|
-
const b = (0, node_crypto.randomBytes)(8);
|
|
3604
|
-
const hi = b.readUInt32BE(0) & 2097151;
|
|
3605
|
-
const lo = b.readUInt32BE(4);
|
|
3606
|
-
return hi * 4294967296 + lo;
|
|
3607
|
-
}
|
|
3608
|
-
function gitHead() {
|
|
3609
|
-
try {
|
|
3610
|
-
const out = (0, node_child_process.execFileSync)("git", ["rev-parse", "HEAD"], { stdio: [
|
|
3611
|
-
"ignore",
|
|
3612
|
-
"pipe",
|
|
3613
|
-
"ignore"
|
|
3614
|
-
] }).toString().trim();
|
|
3615
|
-
return /^[0-9a-f]{7,64}$/i.test(out) ? out : null;
|
|
3616
|
-
} catch {
|
|
3617
|
-
return null;
|
|
3618
|
-
}
|
|
3619
|
-
}
|
|
3620
|
-
const SEED_ENV_VAR = "AFTERPACK_SEED";
|
|
3621
|
-
function parseSeedValue(raw) {
|
|
3622
|
-
return /^-?\d+$/.test(raw) ? Number(raw) : raw;
|
|
3623
|
-
}
|
|
3624
|
-
const SEED_STATE = Symbol.for("afterpack.integration-utils.seed-sessions");
|
|
3625
|
-
function sharedSeedState() {
|
|
3626
|
-
const holder = globalThis;
|
|
3627
|
-
holder[SEED_STATE] ??= {
|
|
3628
|
-
sessions: new Map(),
|
|
3629
|
-
ownEnvExports: []
|
|
3630
|
-
};
|
|
3631
|
-
return holder[SEED_STATE];
|
|
3632
|
-
}
|
|
3633
|
-
const { sessions, ownEnvExports } = sharedSeedState();
|
|
3634
|
-
function isOwnEnvExport(env, value) {
|
|
3635
|
-
return ownEnvExports.some((e) => e.env === env && e.value === value);
|
|
3636
|
-
}
|
|
3637
|
-
function openGeneration(root, leg) {
|
|
3638
|
-
let session = sessions.get(root);
|
|
3639
|
-
if (!session) {
|
|
3640
|
-
session = {
|
|
3641
|
-
seed: void 0,
|
|
3642
|
-
generation: 1,
|
|
3643
|
-
legs: [],
|
|
3644
|
-
resolvedByLeg: new Map(),
|
|
3645
|
-
gitFallbackWarned: false
|
|
3646
|
-
};
|
|
3647
|
-
sessions.set(root, session);
|
|
3648
|
-
} else if (session.legs.includes(leg)) {
|
|
3649
|
-
session.seed = void 0;
|
|
3650
|
-
session.generation += 1;
|
|
3651
|
-
session.legs = [];
|
|
3652
|
-
session.resolvedByLeg.clear();
|
|
3653
|
-
session.gitFallbackWarned = false;
|
|
3654
|
-
}
|
|
3655
|
-
session.legs.push(leg);
|
|
3656
|
-
return session;
|
|
3657
|
-
}
|
|
3658
|
-
function resolveWithinSession(input, session, env, deps) {
|
|
3659
|
-
if (typeof input === "number") return {
|
|
3660
|
-
seed: input,
|
|
3661
|
-
origin: "option"
|
|
3662
|
-
};
|
|
3663
|
-
if (typeof input === "string" && input !== "git") return {
|
|
3664
|
-
seed: input,
|
|
3665
|
-
origin: "option"
|
|
3666
|
-
};
|
|
3667
|
-
if (input === "git") {
|
|
3668
|
-
const head = (deps.gitHead ?? gitHead)();
|
|
3669
|
-
if (head) return {
|
|
3670
|
-
seed: head,
|
|
3671
|
-
origin: "git"
|
|
3672
|
-
};
|
|
3673
|
-
if (!session.gitFallbackWarned) {
|
|
3674
|
-
session.gitFallbackWarned = true;
|
|
3675
|
-
(deps.warn ?? ((m) => console.warn(m)))("[afterpack] seed \"git\": no git repository / HEAD found; using a fresh random seed for this build.");
|
|
3676
|
-
}
|
|
3677
|
-
}
|
|
3678
|
-
const fromEnv = env[SEED_ENV_VAR];
|
|
3679
|
-
if (fromEnv != null && fromEnv !== "" && !isOwnEnvExport(env, fromEnv)) return {
|
|
3680
|
-
seed: parseSeedValue(fromEnv),
|
|
3681
|
-
origin: "env"
|
|
3682
|
-
};
|
|
3683
|
-
if (session.seed !== void 0) return {
|
|
3684
|
-
seed: session.seed,
|
|
3685
|
-
origin: "session"
|
|
3686
|
-
};
|
|
3687
|
-
return {
|
|
3688
|
-
seed: (deps.randomSeed ?? randomSeed)(),
|
|
3689
|
-
origin: "fresh"
|
|
3690
|
-
};
|
|
3691
|
-
}
|
|
3692
|
-
function resolveBuildSeed(input, scope, deps = {}) {
|
|
3693
|
-
const env = deps.env ?? process.env;
|
|
3694
|
-
const session = openGeneration(scope.root, scope.leg);
|
|
3695
|
-
const { seed, origin } = resolveWithinSession(input, session, env, deps);
|
|
3696
|
-
if (origin === "env" || origin === "fresh") session.seed = seed;
|
|
3697
|
-
if (origin === "fresh" && (deps.exportToEnv ?? true)) {
|
|
3698
|
-
const value = String(seed);
|
|
3699
|
-
env[SEED_ENV_VAR] = value;
|
|
3700
|
-
const stale = ownEnvExports.findIndex((e) => e.env === env);
|
|
3701
|
-
if (stale >= 0) ownEnvExports.splice(stale, 1);
|
|
3702
|
-
ownEnvExports.push({
|
|
3703
|
-
env,
|
|
3704
|
-
value
|
|
3705
|
-
});
|
|
3706
|
-
}
|
|
3707
|
-
const prior = [...session.resolvedByLeg].find(([, s]) => s !== seed);
|
|
3708
|
-
session.resolvedByLeg.set(scope.leg, seed);
|
|
3709
|
-
return {
|
|
3710
|
-
seed,
|
|
3711
|
-
origin,
|
|
3712
|
-
legs: [...session.legs],
|
|
3713
|
-
generation: session.generation,
|
|
3714
|
-
mismatch: prior && session.generation === 1 ? {
|
|
3715
|
-
leg: prior[0],
|
|
3716
|
-
seed: prior[1]
|
|
3717
|
-
} : null
|
|
3718
|
-
};
|
|
3719
|
-
}
|
|
3720
|
-
|
|
3721
3901
|
//#endregion
|
|
3722
3902
|
//#region src/telemetry.ts
|
|
3723
3903
|
const API_URL_ENV_VAR$1 = "AFTERPACK_API_URL";
|
|
@@ -3937,7 +4117,7 @@ const TELEMETRY_NOTICE = [
|
|
|
3937
4117
|
"AfterPack: days.",
|
|
3938
4118
|
"AfterPack: It never sends your source, file names, paths, project name, diagnostic",
|
|
3939
4119
|
"AfterPack: message text, or exact byte counts. A clean build sends nothing.",
|
|
3940
|
-
"AfterPack: Turn it off with
|
|
4120
|
+
"AfterPack: Turn it off with AFTERPACK_TELEMETRY_ENABLED=false, --telemetry.enabled=false, or",
|
|
3941
4121
|
"AfterPack: `telemetry: { enabled: false }` in your config.",
|
|
3942
4122
|
"AfterPack: https://www.afterpack.dev/privacy"
|
|
3943
4123
|
];
|
|
@@ -4054,16 +4234,15 @@ function afterpackHashSalt(input) {
|
|
|
4054
4234
|
}));
|
|
4055
4235
|
return (0, node_crypto.createHash)("sha256").update(payload).digest("hex").slice(0, 32);
|
|
4056
4236
|
}
|
|
4057
|
-
function isCloudBuild(
|
|
4058
|
-
|
|
4059
|
-
return typeof key === "string" && key.trim() !== "";
|
|
4237
|
+
function isCloudBuild(key) {
|
|
4238
|
+
return cloudKey(key) !== null;
|
|
4060
4239
|
}
|
|
4061
4240
|
function versionEndpoint(env) {
|
|
4062
4241
|
const base = (env[API_URL_ENV_VAR] ?? DEFAULT_API_URL).replace(/\/+$/, "");
|
|
4063
4242
|
return `${base}${VERSION_ENDPOINT_PATH}`;
|
|
4064
4243
|
}
|
|
4065
|
-
async function resolveSaltEngine(env, localEngineVersion, deps = {}) {
|
|
4066
|
-
if (!isCloudBuild(
|
|
4244
|
+
async function resolveSaltEngine(key, env, localEngineVersion, deps = {}) {
|
|
4245
|
+
if (!isCloudBuild(key)) return {
|
|
4067
4246
|
engineVersion: localEngineVersion,
|
|
4068
4247
|
nonce: null,
|
|
4069
4248
|
cloud: false,
|
|
@@ -4098,7 +4277,7 @@ async function resolveSaltEngine(env, localEngineVersion, deps = {}) {
|
|
|
4098
4277
|
}
|
|
4099
4278
|
const PROBE_FAILED_WARNING = "could not read the cloud engine version from the API, so output file names carry a random nonce this build only. They are safe, but a pinned seed will not reproduce them. Re-run when the API is reachable to get stable names.";
|
|
4100
4279
|
function saltSettings(settings, extra = {}) {
|
|
4101
|
-
const { seed: _seed, diagnostics: _diagnostics, artifactOptions, engineConfig,...rest } = settings;
|
|
4280
|
+
const { seed: _seed, seedFallback: _seedFallback, key: _key, diagnostics: _diagnostics, artifactOptions, engineConfig,...rest } = settings;
|
|
4102
4281
|
const { git: _git, telemetry: _telemetry,...output } = artifactOptions ?? {};
|
|
4103
4282
|
const { seed: _engineSeed,...engine } = engineConfig ?? {};
|
|
4104
4283
|
return {
|
|
@@ -4122,9 +4301,10 @@ async function prepareHashSalt(input) {
|
|
|
4122
4301
|
leg: input.leg
|
|
4123
4302
|
}, {
|
|
4124
4303
|
env,
|
|
4125
|
-
warn: input.warn
|
|
4304
|
+
warn: input.warn,
|
|
4305
|
+
fallback: input.seedFallback
|
|
4126
4306
|
});
|
|
4127
|
-
const engine = await resolveSaltEngine(env, input.localEngineVersion, { fetchImpl: input.fetchImpl });
|
|
4307
|
+
const engine = await resolveSaltEngine(input.key, env, input.localEngineVersion, { fetchImpl: input.fetchImpl });
|
|
4128
4308
|
if (engine.probeFailed) input.warn?.(PROBE_FAILED_WARNING);
|
|
4129
4309
|
return {
|
|
4130
4310
|
resolvedSeed,
|
|
@@ -4934,7 +5114,7 @@ function verifyProtectionReceipt(receiptPath, dir, expectedBuildId) {
|
|
|
4934
5114
|
if (expectedBuildId != null && parsed.buildId !== expectedBuildId) problems.push(`receipt is for build ${String(parsed.buildId)}, but this output is build ${expectedBuildId} — the tree was rebuilt without the AfterPack wrapper`);
|
|
4935
5115
|
if (parsed.files.length === 0) problems.push("receipt records zero obfuscated files");
|
|
4936
5116
|
const transformed = parsed.files.filter((f) => f.transformed !== false).length;
|
|
4937
|
-
if (parsed.files.length > 0 && transformed === 0) problems.push(`receipt lists ${parsed.files.length} file(s) but the engine changed NONE of them — this build shipped its source (check \`paths.exclude\` and
|
|
5117
|
+
if (parsed.files.length > 0 && transformed === 0) problems.push(`receipt lists ${parsed.files.length} file(s) but the engine changed NONE of them — this build shipped its source (check \`paths.exclude\` and AFTERPACK_PATHS_EXCLUDE)`);
|
|
4938
5118
|
for (const entry of parsed.files) {
|
|
4939
5119
|
const file = (0, node_path.join)(dir, entry.path);
|
|
4940
5120
|
if (!(0, node_fs.existsSync)(file)) {
|
|
@@ -5606,6 +5786,7 @@ async function runObfuscationPass(options) {
|
|
|
5606
5786
|
const passStartedAt = options.startedAt ?? Date.now();
|
|
5607
5787
|
const callerAnchored = options.startedAt !== void 0;
|
|
5608
5788
|
const { engine, label, cwd, combinedProtectionMap, artifactOptions = {}, env = process.env } = options;
|
|
5789
|
+
const key = cloudKey(options.key);
|
|
5609
5790
|
const logger = silenceSummaryLines(options.logger ?? DEFAULT_LOGGER, options.diagnostics);
|
|
5610
5791
|
const prefix = (message) => `[${label}] ${message}`;
|
|
5611
5792
|
const style = options.summaryStyle ?? "plugin";
|
|
@@ -5633,7 +5814,8 @@ async function runObfuscationPass(options) {
|
|
|
5633
5814
|
leg: options.buildLeg ?? combinedProtectionMap.buildDir
|
|
5634
5815
|
}, {
|
|
5635
5816
|
env,
|
|
5636
|
-
warn: (m) => logger.warn(m)
|
|
5817
|
+
warn: (m) => logger.warn(m),
|
|
5818
|
+
fallback: options.seedFallback
|
|
5637
5819
|
});
|
|
5638
5820
|
const seed = resolvedSeed.seed;
|
|
5639
5821
|
if (resolvedSeed.mismatch) logger.warn(prefix(`build seed ${seed} does not match leg "${resolvedSeed.mismatch.leg}" of this same build, which used ${resolvedSeed.mismatch.seed} — pin the same \`seed\` on every leg (or none) so the bundles share one polymorphic layout.`));
|
|
@@ -5735,6 +5917,10 @@ async function runObfuscationPass(options) {
|
|
|
5735
5917
|
});
|
|
5736
5918
|
const localEngineVersion = await readEngineVersion(engine);
|
|
5737
5919
|
const gateVersion = localEngineVersion ?? options.client?.coreVersion;
|
|
5920
|
+
if (key === null && !coreHonoursNullKey(gateVersion)) {
|
|
5921
|
+
const source = keySourceForOlderCore(env, process.cwd());
|
|
5922
|
+
if (source) throw new Error(prefix(`no key is set for this build, but ${CORE_PACKAGE} ${gateVersion} reads the key itself and would build in the cloud with the key from ${source}. Update to ${CORE_PACKAGE} ${NULL_KEY_MIN_CORE_VERSION} or newer: ` + updateCommand(options.client, NULL_KEY_MIN_CORE_VERSION)));
|
|
5923
|
+
}
|
|
5738
5924
|
const derivedSourceType = options.sourceType !== void 0 && coreSupportsSourceType(gateVersion) ? options.sourceType : void 0;
|
|
5739
5925
|
if (options.fileSourceTypes && options.engineConfig?.sourceType === void 0 && coreSupportsFileSourceType(gateVersion)) for (const input of inputs) {
|
|
5740
5926
|
const sourceType = options.fileSourceTypes.get(input.path);
|
|
@@ -5750,7 +5936,7 @@ async function runObfuscationPass(options) {
|
|
|
5750
5936
|
engine: options.engineConfig,
|
|
5751
5937
|
renameGlobals: capture.renameGlobals
|
|
5752
5938
|
});
|
|
5753
|
-
const saltEngine = options.cloudEngineExpectation ?? (options.hashedNames ? await resolveSaltEngine(env, localEngineVersion) : null);
|
|
5939
|
+
const saltEngine = options.cloudEngineExpectation ?? (options.hashedNames ? await resolveSaltEngine(key, env, localEngineVersion) : null);
|
|
5754
5940
|
let namesPlan = null;
|
|
5755
5941
|
let hashSalt = null;
|
|
5756
5942
|
if (options.hashedNames && saltEngine && !options.emitToCaller) {
|
|
@@ -5785,7 +5971,7 @@ async function runObfuscationPass(options) {
|
|
|
5785
5971
|
}
|
|
5786
5972
|
}
|
|
5787
5973
|
const localEngineDisplay = installedEngineVersion(options.client?.coreVersion ?? null, localEngineVersion);
|
|
5788
|
-
const announcedEngine = isCloudBuild(
|
|
5974
|
+
const announcedEngine = isCloudBuild(key) ? describeEngine("cloud", saltEngine?.probedCloudVersion ?? null) : describeEngine("local", localEngineDisplay);
|
|
5789
5975
|
if (style !== "cli") {
|
|
5790
5976
|
const engineClause = announcedEngine ? ` with ${announcedEngine}` : "";
|
|
5791
5977
|
logger.log(prefix(`obfuscating ${inputs.length} file(s) at ${describeLevel(options.preset, options.complexity)}${engineClause} ...`));
|
|
@@ -5803,9 +5989,13 @@ async function runObfuscationPass(options) {
|
|
|
5803
5989
|
if (error instanceof WirePathError) throw new Error(prefix(error.message));
|
|
5804
5990
|
throw error;
|
|
5805
5991
|
}
|
|
5992
|
+
const wireConfig = {
|
|
5993
|
+
...wire.config,
|
|
5994
|
+
key
|
|
5995
|
+
};
|
|
5806
5996
|
let batch;
|
|
5807
5997
|
try {
|
|
5808
|
-
batch = wire.toLocal(await engine.processBatch(wire.inputs,
|
|
5998
|
+
batch = wire.toLocal(await engine.processBatch(wire.inputs, wireConfig, context));
|
|
5809
5999
|
} catch (error) {
|
|
5810
6000
|
const cloud = toCloudApiError(error, {
|
|
5811
6001
|
identity: options.client,
|
|
@@ -6100,6 +6290,8 @@ function passSettings(resolved) {
|
|
|
6100
6290
|
return {
|
|
6101
6291
|
artifactOptions: settings.artifactOptions,
|
|
6102
6292
|
seed: settings.seed,
|
|
6293
|
+
seedFallback: settings.seedFallback,
|
|
6294
|
+
key: settings.key,
|
|
6103
6295
|
preset: settings.preset,
|
|
6104
6296
|
complexity: settings.complexity,
|
|
6105
6297
|
regions: settings.regions,
|
|
@@ -6121,9 +6313,33 @@ function unsupportedIssues(unsupported, merged, layers) {
|
|
|
6121
6313
|
}
|
|
6122
6314
|
return out;
|
|
6123
6315
|
}
|
|
6124
|
-
function
|
|
6125
|
-
|
|
6126
|
-
|
|
6316
|
+
function gitSeedFallback(layers) {
|
|
6317
|
+
let top = layers.length - 1;
|
|
6318
|
+
while (top >= 0 && getPath(layers[top].config, "seed") === void 0) top--;
|
|
6319
|
+
if (top < 0 || getPath(layers[top].config, "seed") !== "git") return null;
|
|
6320
|
+
for (let i = top - 1; i >= 0; i--) {
|
|
6321
|
+
const seed = getPath(layers[i].config, "seed");
|
|
6322
|
+
if (seed === void 0 || seed === "git") continue;
|
|
6323
|
+
if (seed === CONFIG_RESET) return null;
|
|
6324
|
+
if (typeof seed !== "number" && typeof seed !== "string") return null;
|
|
6325
|
+
return {
|
|
6326
|
+
seed,
|
|
6327
|
+
origin: layers[i].seedOrigin,
|
|
6328
|
+
from: layers[i].from
|
|
6329
|
+
};
|
|
6330
|
+
}
|
|
6331
|
+
return null;
|
|
6332
|
+
}
|
|
6333
|
+
function settleConfigLayers(layers, appendLists$1) {
|
|
6334
|
+
const config = mergeLayers(layers.map((l) => l.config), appendLists$1);
|
|
6335
|
+
return {
|
|
6336
|
+
config,
|
|
6337
|
+
options: {
|
|
6338
|
+
...toPluginOptions(config),
|
|
6339
|
+
seedFallback: gitSeedFallback(layers)
|
|
6340
|
+
},
|
|
6341
|
+
engineConfig: toEngineConfig(config)
|
|
6342
|
+
};
|
|
6127
6343
|
}
|
|
6128
6344
|
function sameRankConflicts(options, cli) {
|
|
6129
6345
|
const issues = [];
|
|
@@ -6131,10 +6347,10 @@ function sameRankConflicts(options, cli) {
|
|
|
6131
6347
|
const fromOptions = getPath(options, key.path);
|
|
6132
6348
|
const fromCli = getPath(cli, key.path);
|
|
6133
6349
|
if (fromOptions === void 0 || fromCli === void 0) continue;
|
|
6134
|
-
if (
|
|
6350
|
+
if (shownValue(fromOptions) === shownValue(fromCli)) continue;
|
|
6135
6351
|
issues.push({
|
|
6136
6352
|
path: key.path,
|
|
6137
|
-
message: `\`${key.path}\` is set twice at the same precedence — the options object says ${
|
|
6353
|
+
message: `\`${key.path}\` is set twice at the same precedence — the options object says ${shownValue(fromOptions)}, the command line says ${shownValue(fromCli)}. A flag and an option rank equally, so neither wins: set it in one of them, or move it to afterpack.json.`
|
|
6138
6354
|
});
|
|
6139
6355
|
}
|
|
6140
6356
|
return issues;
|
|
@@ -6168,7 +6384,25 @@ function resolvePluginConfig(input) {
|
|
|
6168
6384
|
const normalized = normalizePluginOptions(input.options, localKeys, optionsSurface);
|
|
6169
6385
|
const options = validateConfig(normalized.config, optionsSurface);
|
|
6170
6386
|
const explicit = mergeConfig(options.config, cli.config);
|
|
6171
|
-
const
|
|
6387
|
+
const fileName = file.path ?? CONFIG_FILE_NAME;
|
|
6388
|
+
const settled = settleConfigLayers([
|
|
6389
|
+
{
|
|
6390
|
+
config: file.config,
|
|
6391
|
+
from: fileName,
|
|
6392
|
+
seedOrigin: "option"
|
|
6393
|
+
},
|
|
6394
|
+
{
|
|
6395
|
+
config: env.config,
|
|
6396
|
+
from: "the environment",
|
|
6397
|
+
seedOrigin: "env"
|
|
6398
|
+
},
|
|
6399
|
+
{
|
|
6400
|
+
config: explicit,
|
|
6401
|
+
from: "the command line or plugin options",
|
|
6402
|
+
seedOrigin: "option"
|
|
6403
|
+
}
|
|
6404
|
+
], input.appendLists);
|
|
6405
|
+
const config = settled.config;
|
|
6172
6406
|
const issues = [
|
|
6173
6407
|
...file.issues.map((i) => ` ${file.path ?? CONFIG_FILE_NAME}: ${i.message}`),
|
|
6174
6408
|
...env.issues.map((i) => ` environment: ${i.message}`),
|
|
@@ -6195,8 +6429,7 @@ function resolvePluginConfig(input) {
|
|
|
6195
6429
|
])
|
|
6196
6430
|
];
|
|
6197
6431
|
if (issues.length > 0) throw new Error([`[${input.label}] refusing to build with an invalid configuration:`, ...issues].join("\n"));
|
|
6198
|
-
|
|
6199
|
-
const pluginOptions = toPluginOptions(config);
|
|
6432
|
+
const pluginOptions = settled.options;
|
|
6200
6433
|
const supplied = isPlainObject(input.options) ? input.options : {};
|
|
6201
6434
|
const localArtifactOptions = {};
|
|
6202
6435
|
for (const name of PLUGIN_LOCAL_KEYS) if (supplied[name] !== void 0) localArtifactOptions[name] = supplied[name];
|
|
@@ -6209,7 +6442,7 @@ function resolvePluginConfig(input) {
|
|
|
6209
6442
|
...localArtifactOptions
|
|
6210
6443
|
}
|
|
6211
6444
|
},
|
|
6212
|
-
engineConfig:
|
|
6445
|
+
engineConfig: settled.engineConfig,
|
|
6213
6446
|
configFile: file.path,
|
|
6214
6447
|
positionals: cli.positionals,
|
|
6215
6448
|
help: false,
|
|
@@ -6239,7 +6472,6 @@ exports.afterpackHome = afterpackHome;
|
|
|
6239
6472
|
exports.angularHashToken = angularHashToken;
|
|
6240
6473
|
exports.angularServerManifestRefusal = angularServerManifestRefusal;
|
|
6241
6474
|
exports.applyBundleOutput = applyBundleOutput;
|
|
6242
|
-
exports.applyResolvedKey = applyResolvedKey;
|
|
6243
6475
|
exports.buildDirKey = buildDirKey;
|
|
6244
6476
|
exports.collectBundleJs = collectBundleJs;
|
|
6245
6477
|
exports.collectJsFiles = collectJsFiles;
|
|
@@ -6255,10 +6487,11 @@ exports.findHashTokenReference = findHashTokenReference;
|
|
|
6255
6487
|
exports.findUpward = findUpward;
|
|
6256
6488
|
exports.getPath = getPath;
|
|
6257
6489
|
exports.installedRequiredLine = installedRequiredLine;
|
|
6490
|
+
exports.isOwnEnvExport = isOwnEnvExport;
|
|
6258
6491
|
exports.isWithinDir = isWithinDir;
|
|
6259
6492
|
exports.loadConfigFile = loadConfigFile;
|
|
6260
6493
|
exports.locateProtectionReceipt = locateProtectionReceipt;
|
|
6261
|
-
exports.
|
|
6494
|
+
exports.mergeLayers = mergeLayers;
|
|
6262
6495
|
exports.nextChunkToken = nextChunkToken;
|
|
6263
6496
|
exports.normalizePluginOptions = normalizePluginOptions;
|
|
6264
6497
|
exports.npxAlternative = npxAlternative;
|
|
@@ -6281,6 +6514,7 @@ exports.saltSettings = saltSettings;
|
|
|
6281
6514
|
exports.sanitizeNotices = sanitizeNotices;
|
|
6282
6515
|
exports.scanDirectives = scanDirectives;
|
|
6283
6516
|
exports.serverAddsInfo = serverAddsInfo;
|
|
6517
|
+
exports.settleConfigLayers = settleConfigLayers;
|
|
6284
6518
|
exports.sha256Hex = sha256Hex;
|
|
6285
6519
|
exports.sha256Of = sha256Of;
|
|
6286
6520
|
exports.skipNextInternals = skipNextInternals;
|