@afterpack/integration-utils 1.0.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -0
- package/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.js
CHANGED
|
@@ -1128,6 +1128,19 @@ const CONFIG_PREFIXES = new Set(CONFIG_KEYS.flatMap((k) => {
|
|
|
1128
1128
|
const parts = k.path.split(".");
|
|
1129
1129
|
return parts.slice(0, -1).map((_, i) => parts.slice(0, i + 1).join("."));
|
|
1130
1130
|
}));
|
|
1131
|
+
const ENV_PREFIX = "AFTERPACK_";
|
|
1132
|
+
function screamingSnake(path) {
|
|
1133
|
+
return path.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/\./g, "_").toUpperCase();
|
|
1134
|
+
}
|
|
1135
|
+
function envName(path) {
|
|
1136
|
+
return `${ENV_PREFIX}${screamingSnake(path)}`;
|
|
1137
|
+
}
|
|
1138
|
+
const CONFIG_BY_ENV_NAME = new Map([...CONFIG_KEYS.map((k) => k.path), ...CONFIG_PREFIXES].map((path) => [envName(path), path]));
|
|
1139
|
+
const ENV_GROUPS = new Set(CONFIG_KEYS.map((k) => screamingSnake(k.path.split(".")[0])));
|
|
1140
|
+
function claimsEnvSuffix(suffix) {
|
|
1141
|
+
for (const group$1 of ENV_GROUPS) if (suffix === group$1 || suffix.startsWith(`${group$1}_`)) return true;
|
|
1142
|
+
return false;
|
|
1143
|
+
}
|
|
1131
1144
|
const CONFIG_CHILDREN = new Map([...CONFIG_PREFIXES].map((prefix) => [prefix, CONFIG_KEYS.filter((k) => k.path.startsWith(`${prefix}.`)).map((k) => k.path)]));
|
|
1132
1145
|
const BY_NORMALIZED = new Map(CONFIG_KEYS.map((k) => [normalizeKey(k.path), k]));
|
|
1133
1146
|
const CHILDREN_BY_NORMALIZED = new Map([...CONFIG_CHILDREN].map(([prefix, children]) => [normalizeKey(prefix), children]));
|
|
@@ -1180,18 +1193,18 @@ function editDistance(a, b) {
|
|
|
1180
1193
|
return prev[b.length];
|
|
1181
1194
|
}
|
|
1182
1195
|
const DOCS_URL = "https://www.afterpack.dev/docs/config";
|
|
1183
|
-
function unknownKeyMessage(path, surface) {
|
|
1196
|
+
function unknownKeyMessage(path, surface, spell = (p) => p) {
|
|
1184
1197
|
const group$1 = CHILDREN_BY_NORMALIZED.get(normalizeKey(path));
|
|
1185
1198
|
if (group$1 && group$1.length > 0) {
|
|
1186
|
-
const list = group$1.map((child) => `\`${child}\``).join(", ");
|
|
1199
|
+
const list = group$1.map((child) => `\`${spell(child)}\``).join(", ");
|
|
1187
1200
|
const tail$1 = group$1.length === 1 ? `did you mean ${list}?` : `its keys are ${list}`;
|
|
1188
1201
|
const canonical$1 = PREFIX_BY_NORMALIZED.get(normalizeKey(path));
|
|
1189
1202
|
const enabled = canonical$1 ? groupBooleanKey(canonical$1) : void 0;
|
|
1190
|
-
const rule = enabled ? `; a boolean here means \`${enabled.path}\`` : "";
|
|
1203
|
+
const rule = enabled ? `; a boolean here means \`${spell(enabled.path)}\`` : "";
|
|
1191
1204
|
return `\`${path}\` is a group of configuration keys, not a key itself (${surface}) — ${tail$1}${rule}`;
|
|
1192
1205
|
}
|
|
1193
1206
|
const suggestion = suggestKey(path);
|
|
1194
|
-
const tail = suggestion ? ` — did you mean \`${suggestion}\`?` : ` — see ${DOCS_URL}`;
|
|
1207
|
+
const tail = suggestion ? ` — did you mean \`${spell(suggestion)}\`?` : ` — see ${DOCS_URL}`;
|
|
1195
1208
|
return `unknown configuration key \`${path}\` (${surface})${tail}`;
|
|
1196
1209
|
}
|
|
1197
1210
|
function isPlainObject(value) {
|
|
@@ -1209,6 +1222,25 @@ function describe(item) {
|
|
|
1209
1222
|
case "region": return "an object with numeric `start` and `end`";
|
|
1210
1223
|
}
|
|
1211
1224
|
}
|
|
1225
|
+
const CONFIG_RESET = Symbol.for("afterpack.config.reset");
|
|
1226
|
+
function isBlank(value) {
|
|
1227
|
+
return typeof value === "string" && value.trim() === "";
|
|
1228
|
+
}
|
|
1229
|
+
function emptyValue(key) {
|
|
1230
|
+
if (key.shape === "list" || key.shape === "mixedList") return [];
|
|
1231
|
+
if (key.shape !== "scalar") return void 0;
|
|
1232
|
+
return key.item.kind === "seed" || key.item.kind === "string" ? CONFIG_RESET : void 0;
|
|
1233
|
+
}
|
|
1234
|
+
function emptyValueMessage(key, written, surface) {
|
|
1235
|
+
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`;
|
|
1236
|
+
}
|
|
1237
|
+
function emptyGroupMessage(group$1, written, surface, spell = (p) => p) {
|
|
1238
|
+
const children = CONFIG_CHILDREN.get(group$1) ?? [];
|
|
1239
|
+
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(", ")}`;
|
|
1240
|
+
}
|
|
1241
|
+
function shownValue(value) {
|
|
1242
|
+
return value === CONFIG_RESET ? "\"\"" : JSON.stringify(value);
|
|
1243
|
+
}
|
|
1212
1244
|
function misdirectedHint(key, value, spell) {
|
|
1213
1245
|
const other = misdirectedTo(key, value);
|
|
1214
1246
|
if (!other) return "";
|
|
@@ -1376,6 +1408,15 @@ function walk(source, prefix, target, issues, surface) {
|
|
|
1376
1408
|
if (value === void 0) continue;
|
|
1377
1409
|
const path = prefix ? `${prefix}.${name}` : name;
|
|
1378
1410
|
const key = CONFIG_BY_PATH.get(path);
|
|
1411
|
+
if (key && isBlank(value)) {
|
|
1412
|
+
const reset = emptyValue(key);
|
|
1413
|
+
if (reset === void 0) issues.push({
|
|
1414
|
+
path,
|
|
1415
|
+
message: emptyValueMessage(key, `"${path}": ${JSON.stringify(value)}`, surface)
|
|
1416
|
+
});
|
|
1417
|
+
else target[name] = reset;
|
|
1418
|
+
continue;
|
|
1419
|
+
}
|
|
1379
1420
|
if (key) {
|
|
1380
1421
|
const failure = checkValue(key, value);
|
|
1381
1422
|
if (failure) {
|
|
@@ -1421,6 +1462,41 @@ function mergeInto(base, override) {
|
|
|
1421
1462
|
function mergeConfig(base, override) {
|
|
1422
1463
|
return deepMerge(base, override);
|
|
1423
1464
|
}
|
|
1465
|
+
function withoutResets(config) {
|
|
1466
|
+
const out = {};
|
|
1467
|
+
for (const [name, value] of Object.entries(config)) {
|
|
1468
|
+
if (value === CONFIG_RESET || value === void 0) continue;
|
|
1469
|
+
if (isPlainObject(value)) {
|
|
1470
|
+
const inner = withoutResets(value);
|
|
1471
|
+
if (Object.keys(inner).length > 0) out[name] = inner;
|
|
1472
|
+
continue;
|
|
1473
|
+
}
|
|
1474
|
+
out[name] = value;
|
|
1475
|
+
}
|
|
1476
|
+
return out;
|
|
1477
|
+
}
|
|
1478
|
+
function appendLists(config, extra) {
|
|
1479
|
+
const out = config;
|
|
1480
|
+
for (const key of CONFIG_KEYS) {
|
|
1481
|
+
if (key.shape !== "list" && key.shape !== "mixedList") continue;
|
|
1482
|
+
const added = getPath(extra, key.path);
|
|
1483
|
+
if (!Array.isArray(added) || added.length === 0) continue;
|
|
1484
|
+
const current = getPath(out, key.path);
|
|
1485
|
+
const base = Array.isArray(current) ? current : [];
|
|
1486
|
+
const fresh = added.filter((item) => !base.some((b) => JSON.stringify(b) === JSON.stringify(item)));
|
|
1487
|
+
setPath(out, key.path, [...base, ...fresh]);
|
|
1488
|
+
}
|
|
1489
|
+
return out;
|
|
1490
|
+
}
|
|
1491
|
+
function mergeLayers(layers, appended = EMPTY_CONFIG) {
|
|
1492
|
+
const merged = layers.reduce(mergeConfig, EMPTY_CONFIG);
|
|
1493
|
+
return appendLists(withoutResets(merged), appended);
|
|
1494
|
+
}
|
|
1495
|
+
function cloudKey(value) {
|
|
1496
|
+
if (typeof value !== "string") return null;
|
|
1497
|
+
const trimmed = value.trim();
|
|
1498
|
+
return trimmed === "" ? null : trimmed;
|
|
1499
|
+
}
|
|
1424
1500
|
function getPath(config, path) {
|
|
1425
1501
|
let current = config;
|
|
1426
1502
|
for (const part of path.split(".")) {
|
|
@@ -1442,17 +1518,19 @@ function setPath(target, path, value) {
|
|
|
1442
1518
|
node[parts[parts.length - 1]] = value;
|
|
1443
1519
|
}
|
|
1444
1520
|
function toEngineConfig(config) {
|
|
1521
|
+
const clean = withoutResets(config);
|
|
1445
1522
|
const out = {};
|
|
1446
1523
|
for (const key of CONFIG_KEYS) {
|
|
1447
1524
|
if (key.surface !== "engine") continue;
|
|
1448
|
-
const value = getPath(
|
|
1525
|
+
const value = getPath(clean, key.path);
|
|
1449
1526
|
if (value === void 0) continue;
|
|
1450
1527
|
setPath(out, key.path, value);
|
|
1451
1528
|
}
|
|
1452
1529
|
return out;
|
|
1453
1530
|
}
|
|
1454
1531
|
function toPluginOptions(config) {
|
|
1455
|
-
const
|
|
1532
|
+
const clean = withoutResets(config);
|
|
1533
|
+
const read = (path) => getPath(clean, path);
|
|
1456
1534
|
const set = (container) => Object.values(container).some((v) => v !== void 0) ? container : void 0;
|
|
1457
1535
|
return {
|
|
1458
1536
|
artifactOptions: {
|
|
@@ -1481,7 +1559,7 @@ function toPluginOptions(config) {
|
|
|
1481
1559
|
format: read("diagnostics.format")
|
|
1482
1560
|
}),
|
|
1483
1561
|
paths: set({ include: read("paths.include") }),
|
|
1484
|
-
key: read("key")
|
|
1562
|
+
key: cloudKey(read("key"))
|
|
1485
1563
|
};
|
|
1486
1564
|
}
|
|
1487
1565
|
|
|
@@ -2012,6 +2090,7 @@ function reportNotices(raw, logger, prefix = (m) => m) {
|
|
|
2012
2090
|
const MIN_CORE_VERSION = "1.0.0";
|
|
2013
2091
|
const SOURCE_TYPE_MIN_CORE_VERSION = "0.2.3";
|
|
2014
2092
|
const FILE_SOURCE_TYPE_MIN_CORE_VERSION = "0.2.5";
|
|
2093
|
+
const NULL_KEY_MIN_CORE_VERSION = "1.1.0";
|
|
2015
2094
|
const CORE_PACKAGE = "@afterpack/core";
|
|
2016
2095
|
const VERSION_PATTERN$1 = /^\d{1,9}\.\d{1,9}\.\d{1,9}(?:[-+][0-9A-Za-z.+-]{1,64})?$/;
|
|
2017
2096
|
const PACKAGE_NAME_PATTERN = /^(?:@[a-z0-9][a-z0-9._-]{0,63}\/)?[a-z0-9][a-z0-9._-]{0,63}$/;
|
|
@@ -2117,6 +2196,21 @@ function coreSupportsSourceType(coreVersion) {
|
|
|
2117
2196
|
function coreSupportsFileSourceType(coreVersion) {
|
|
2118
2197
|
return releaseTriple(coreVersion) !== null && !isBelowVersion(coreVersion, FILE_SOURCE_TYPE_MIN_CORE_VERSION);
|
|
2119
2198
|
}
|
|
2199
|
+
function coreHonoursNullKey(coreVersion) {
|
|
2200
|
+
return !isBelowVersion(coreVersion, NULL_KEY_MIN_CORE_VERSION);
|
|
2201
|
+
}
|
|
2202
|
+
function keySourceForOlderCore(env, startDir) {
|
|
2203
|
+
if ((env.AFTERPACK_KEY ?? "").trim() !== "") return "AFTERPACK_KEY";
|
|
2204
|
+
const path = findUpward(startDir, "afterpack.json");
|
|
2205
|
+
if (!path) return null;
|
|
2206
|
+
try {
|
|
2207
|
+
const parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
2208
|
+
const key = isPlainObject(parsed) ? parsed.key : void 0;
|
|
2209
|
+
return typeof key === "string" && key.trim() !== "" ? path : null;
|
|
2210
|
+
} catch {
|
|
2211
|
+
return null;
|
|
2212
|
+
}
|
|
2213
|
+
}
|
|
2120
2214
|
const CLI_PACKAGE = "afterpack";
|
|
2121
2215
|
function updateCommand(identity, minVersion) {
|
|
2122
2216
|
const core = `${CORE_PACKAGE}@${safeVersionString(minVersion) ?? "latest"}`;
|
|
@@ -2329,9 +2423,157 @@ function loadConfigFile(startDir) {
|
|
|
2329
2423
|
};
|
|
2330
2424
|
}
|
|
2331
2425
|
|
|
2426
|
+
//#endregion
|
|
2427
|
+
//#region src/seed.ts
|
|
2428
|
+
function randomSeed() {
|
|
2429
|
+
const b = randomBytes(8);
|
|
2430
|
+
const hi = b.readUInt32BE(0) & 2097151;
|
|
2431
|
+
const lo = b.readUInt32BE(4);
|
|
2432
|
+
return hi * 4294967296 + lo;
|
|
2433
|
+
}
|
|
2434
|
+
function gitHead() {
|
|
2435
|
+
try {
|
|
2436
|
+
const out = execFileSync("git", ["rev-parse", "HEAD"], { stdio: [
|
|
2437
|
+
"ignore",
|
|
2438
|
+
"pipe",
|
|
2439
|
+
"ignore"
|
|
2440
|
+
] }).toString().trim();
|
|
2441
|
+
return /^[0-9a-f]{7,64}$/i.test(out) ? out : null;
|
|
2442
|
+
} catch {
|
|
2443
|
+
return null;
|
|
2444
|
+
}
|
|
2445
|
+
}
|
|
2446
|
+
const SEED_ENV_VAR = "AFTERPACK_SEED";
|
|
2447
|
+
function parseSeedValue(raw) {
|
|
2448
|
+
return /^-?\d+$/.test(raw) ? Number(raw) : raw;
|
|
2449
|
+
}
|
|
2450
|
+
const SEED_STATE = Symbol.for("afterpack.integration-utils.seed-sessions");
|
|
2451
|
+
function sharedSeedState() {
|
|
2452
|
+
const holder = globalThis;
|
|
2453
|
+
holder[SEED_STATE] ??= {
|
|
2454
|
+
sessions: new Map(),
|
|
2455
|
+
ownEnvExports: []
|
|
2456
|
+
};
|
|
2457
|
+
return holder[SEED_STATE];
|
|
2458
|
+
}
|
|
2459
|
+
const { sessions, ownEnvExports } = sharedSeedState();
|
|
2460
|
+
function isOwnEnvExport(env, value) {
|
|
2461
|
+
return ownEnvExports.some((e) => e.env === env && e.value === value);
|
|
2462
|
+
}
|
|
2463
|
+
function envSeedBeforeOwnExport(env, value) {
|
|
2464
|
+
const own = ownEnvExports.find((e) => e.env === env && e.value === value);
|
|
2465
|
+
return own ? { prior: own.prior } : null;
|
|
2466
|
+
}
|
|
2467
|
+
function openGeneration(root, leg) {
|
|
2468
|
+
let session = sessions.get(root);
|
|
2469
|
+
if (!session) {
|
|
2470
|
+
session = {
|
|
2471
|
+
seed: void 0,
|
|
2472
|
+
generation: 1,
|
|
2473
|
+
legs: [],
|
|
2474
|
+
resolvedByLeg: new Map(),
|
|
2475
|
+
gitFallbackWarned: false
|
|
2476
|
+
};
|
|
2477
|
+
sessions.set(root, session);
|
|
2478
|
+
} else if (session.legs.includes(leg)) {
|
|
2479
|
+
session.seed = void 0;
|
|
2480
|
+
session.generation += 1;
|
|
2481
|
+
session.legs = [];
|
|
2482
|
+
session.resolvedByLeg.clear();
|
|
2483
|
+
session.gitFallbackWarned = false;
|
|
2484
|
+
}
|
|
2485
|
+
session.legs.push(leg);
|
|
2486
|
+
return session;
|
|
2487
|
+
}
|
|
2488
|
+
function pinnedEnvSeed(env) {
|
|
2489
|
+
const fromEnv = env[SEED_ENV_VAR];
|
|
2490
|
+
if (fromEnv == null || fromEnv.trim() === "" || isOwnEnvExport(env, fromEnv)) return void 0;
|
|
2491
|
+
return parseSeedValue(fromEnv);
|
|
2492
|
+
}
|
|
2493
|
+
function gitFallbackNotice(fallback) {
|
|
2494
|
+
const using = fallback ? `falling back to the seed ${JSON.stringify(fallback.seed)} from ${fallback.from}` : "using a fresh random seed for this build";
|
|
2495
|
+
return `[afterpack] seed "git": no git repository / HEAD found; ${using}.`;
|
|
2496
|
+
}
|
|
2497
|
+
function resolveWithinSession(input, session, env, deps) {
|
|
2498
|
+
if (typeof input === "number") return {
|
|
2499
|
+
seed: input,
|
|
2500
|
+
origin: "option"
|
|
2501
|
+
};
|
|
2502
|
+
if (typeof input === "string" && input !== "git") return {
|
|
2503
|
+
seed: input,
|
|
2504
|
+
origin: "option"
|
|
2505
|
+
};
|
|
2506
|
+
const layered = deps.fallback !== void 0;
|
|
2507
|
+
const fromEnv = layered ? void 0 : pinnedEnvSeed(env);
|
|
2508
|
+
if (input === "git") {
|
|
2509
|
+
const head = (deps.gitHead ?? gitHead)();
|
|
2510
|
+
if (head) return {
|
|
2511
|
+
seed: head,
|
|
2512
|
+
origin: "git"
|
|
2513
|
+
};
|
|
2514
|
+
const fallback = layered ? deps.fallback ?? null : fromEnv === void 0 ? null : {
|
|
2515
|
+
seed: fromEnv,
|
|
2516
|
+
origin: "env",
|
|
2517
|
+
from: SEED_ENV_VAR
|
|
2518
|
+
};
|
|
2519
|
+
if (!session.gitFallbackWarned) {
|
|
2520
|
+
session.gitFallbackWarned = true;
|
|
2521
|
+
(deps.warn ?? ((m) => console.warn(m)))(gitFallbackNotice(fallback));
|
|
2522
|
+
}
|
|
2523
|
+
if (fallback) return {
|
|
2524
|
+
seed: fallback.seed,
|
|
2525
|
+
origin: fallback.origin
|
|
2526
|
+
};
|
|
2527
|
+
} else if (fromEnv !== void 0) return {
|
|
2528
|
+
seed: fromEnv,
|
|
2529
|
+
origin: "env"
|
|
2530
|
+
};
|
|
2531
|
+
if (session.seed !== void 0) return {
|
|
2532
|
+
seed: session.seed,
|
|
2533
|
+
origin: "session"
|
|
2534
|
+
};
|
|
2535
|
+
return {
|
|
2536
|
+
seed: (deps.randomSeed ?? randomSeed)(),
|
|
2537
|
+
origin: "fresh"
|
|
2538
|
+
};
|
|
2539
|
+
}
|
|
2540
|
+
function resolveBuildSeed(input, scope, deps = {}) {
|
|
2541
|
+
const env = deps.env ?? process.env;
|
|
2542
|
+
const session = openGeneration(scope.root, scope.leg);
|
|
2543
|
+
const { seed, origin } = resolveWithinSession(input, session, env, deps);
|
|
2544
|
+
if (origin === "env" || origin === "fresh") session.seed = seed;
|
|
2545
|
+
if (origin === "fresh" && (deps.exportToEnv ?? true)) {
|
|
2546
|
+
const value = String(seed);
|
|
2547
|
+
const stale = ownEnvExports.findIndex((e) => e.env === env);
|
|
2548
|
+
const current = env[SEED_ENV_VAR];
|
|
2549
|
+
const prior$1 = stale >= 0 && current === ownEnvExports[stale].value ? ownEnvExports[stale].prior : current;
|
|
2550
|
+
env[SEED_ENV_VAR] = value;
|
|
2551
|
+
if (stale >= 0) ownEnvExports.splice(stale, 1);
|
|
2552
|
+
ownEnvExports.push(prior$1 === void 0 ? {
|
|
2553
|
+
env,
|
|
2554
|
+
value
|
|
2555
|
+
} : {
|
|
2556
|
+
env,
|
|
2557
|
+
value,
|
|
2558
|
+
prior: prior$1
|
|
2559
|
+
});
|
|
2560
|
+
}
|
|
2561
|
+
const prior = [...session.resolvedByLeg].find(([, s]) => s !== seed);
|
|
2562
|
+
session.resolvedByLeg.set(scope.leg, seed);
|
|
2563
|
+
return {
|
|
2564
|
+
seed,
|
|
2565
|
+
origin,
|
|
2566
|
+
legs: [...session.legs],
|
|
2567
|
+
generation: session.generation,
|
|
2568
|
+
mismatch: prior && session.generation === 1 ? {
|
|
2569
|
+
leg: prior[0],
|
|
2570
|
+
seed: prior[1]
|
|
2571
|
+
} : null
|
|
2572
|
+
};
|
|
2573
|
+
}
|
|
2574
|
+
|
|
2332
2575
|
//#endregion
|
|
2333
2576
|
//#region src/config-parse.ts
|
|
2334
|
-
const ENV_PREFIX = "AFTERPACK_";
|
|
2335
2577
|
function splitAssignment(token) {
|
|
2336
2578
|
const eq = token.indexOf("=");
|
|
2337
2579
|
if (eq < 0) return {
|
|
@@ -2360,9 +2602,12 @@ function parseListLiteral(raw) {
|
|
|
2360
2602
|
}
|
|
2361
2603
|
function spellKey(path, surface) {
|
|
2362
2604
|
if (surface === "cli") return `--${path}`;
|
|
2363
|
-
if (surface === "env") return
|
|
2605
|
+
if (surface === "env") return envName(path);
|
|
2364
2606
|
return path;
|
|
2365
2607
|
}
|
|
2608
|
+
function writtenKey(key, surface) {
|
|
2609
|
+
return surface === "env" ? `${ENV_PREFIX}${key.replace(/\./g, "_")}` : spellKey(key, surface);
|
|
2610
|
+
}
|
|
2366
2611
|
function surfaceLabel(surface) {
|
|
2367
2612
|
if (surface === "cli") return "command line";
|
|
2368
2613
|
if (surface === "env") return "environment";
|
|
@@ -2404,10 +2649,36 @@ function kebabIssue(key, surface) {
|
|
|
2404
2649
|
const canonical$1 = suggestion ? ` — the canonical form is \`${spellKey(suggestion, surface)}\`` : " — keys are dot-delimited camelCase";
|
|
2405
2650
|
return {
|
|
2406
2651
|
path: key,
|
|
2407
|
-
message: `kebab-case is not a configuration key (\`${
|
|
2652
|
+
message: `kebab-case is not a configuration key (\`${writtenKey(key, surface)}\`)${canonical$1}`
|
|
2408
2653
|
};
|
|
2409
2654
|
}
|
|
2410
|
-
function
|
|
2655
|
+
function emptyAssignment(key, surface, written) {
|
|
2656
|
+
const spell = (p) => surface === "env" ? envName(p) : spellKey(p, surface);
|
|
2657
|
+
if (CONFIG_PREFIXES.has(key) && !CONFIG_BY_PATH.has(key)) return { issue: {
|
|
2658
|
+
path: key,
|
|
2659
|
+
message: emptyGroupMessage(key, written, surfaceLabel(surface), spell)
|
|
2660
|
+
} };
|
|
2661
|
+
const def = CONFIG_BY_PATH.get(key);
|
|
2662
|
+
if (!def || def.shape === "structured") return void 0;
|
|
2663
|
+
const reset = emptyValue(def);
|
|
2664
|
+
if (reset === void 0) return { issue: {
|
|
2665
|
+
path: key,
|
|
2666
|
+
message: emptyValueMessage(def, written, surfaceLabel(surface))
|
|
2667
|
+
} };
|
|
2668
|
+
return { assignment: {
|
|
2669
|
+
path: def.path,
|
|
2670
|
+
value: reset
|
|
2671
|
+
} };
|
|
2672
|
+
}
|
|
2673
|
+
function writtenEmpty(key, surface, raw) {
|
|
2674
|
+
if (surface === "env") return writtenKey(key, surface);
|
|
2675
|
+
return `${spellKey(key, surface)}=${raw}`;
|
|
2676
|
+
}
|
|
2677
|
+
function parseAssignment(key, raw, surface, written) {
|
|
2678
|
+
if (isBlank(raw)) {
|
|
2679
|
+
const empty = emptyAssignment(key, surface, written ?? writtenEmpty(key, surface, raw));
|
|
2680
|
+
if (empty) return empty;
|
|
2681
|
+
}
|
|
2411
2682
|
const spaced = raw === true ? /^(\S+)[ \t]+(.+)$/.exec(key) : null;
|
|
2412
2683
|
const head = spaced ? CONFIG_BY_PATH.get(spaced[1]) : void 0;
|
|
2413
2684
|
if (spaced && head) return { issue: head.shape === "structured" ? structuredIssue(head, surface) : spaceFormIssue(head.path, spaced[2], surface) };
|
|
@@ -2416,10 +2687,13 @@ function parseAssignment(key, raw, surface) {
|
|
|
2416
2687
|
const boolish = raw === true || typeof parseScalarLiteral(raw) === "boolean";
|
|
2417
2688
|
const path = grouped && boolish ? grouped.path : key;
|
|
2418
2689
|
const def = CONFIG_BY_PATH.get(path);
|
|
2419
|
-
if (!def)
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2690
|
+
if (!def) {
|
|
2691
|
+
const spell = (p) => surface === "env" ? envName(p) : p;
|
|
2692
|
+
return { issue: {
|
|
2693
|
+
path: key,
|
|
2694
|
+
message: unknownKeyMessage(key, surfaceLabel(surface), spell)
|
|
2695
|
+
} };
|
|
2696
|
+
}
|
|
2423
2697
|
if (def.shape === "structured") return { issue: structuredIssue(def, surface) };
|
|
2424
2698
|
if (raw === true) {
|
|
2425
2699
|
const failure$1 = checkValue(def, true);
|
|
@@ -2510,41 +2784,68 @@ function parseCliOptions(argv) {
|
|
|
2510
2784
|
issues
|
|
2511
2785
|
};
|
|
2512
2786
|
}
|
|
2513
|
-
|
|
2514
|
-
|
|
2515
|
-
const
|
|
2516
|
-
const envForm = (path) => `${ENV_PREFIX}${path.replace(/\./g, "_")}`;
|
|
2517
|
-
const spelling = canonicalSpelling(dotted);
|
|
2787
|
+
function unclaimedEnvIssue(name, suffix) {
|
|
2788
|
+
const spelling = canonicalSpelling(suffix);
|
|
2789
|
+
const near = spelling ? void 0 : suggestKey(suffix);
|
|
2518
2790
|
let tail = `see ${DOCS_URL}`;
|
|
2519
|
-
if (spelling && "key" in spelling) tail = `
|
|
2520
|
-
else if (spelling && spelling.group.length === 1) tail = `
|
|
2521
|
-
else if (spelling) tail = `its keys are ${spelling.group.map((k) => `\`${
|
|
2791
|
+
if (spelling && "key" in spelling) tail = `did you mean \`${envName(spelling.key)}\`?`;
|
|
2792
|
+
else if (spelling && spelling.group.length === 1) tail = `did you mean \`${envName(spelling.group[0])}\`?`;
|
|
2793
|
+
else if (spelling) tail = `its keys are ${spelling.group.map((k) => `\`${envName(k)}\``).join(", ")}`;
|
|
2794
|
+
else if (near) tail = `did you mean \`${envName(near)}\`?`;
|
|
2522
2795
|
return {
|
|
2523
2796
|
path: suffix,
|
|
2524
|
-
message: `\`${name}\` is not a configuration variable —
|
|
2797
|
+
message: `\`${name}\` is not a configuration variable — ${tail}`
|
|
2525
2798
|
};
|
|
2526
2799
|
}
|
|
2527
|
-
function
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2800
|
+
function conflictIssue(path, first, second) {
|
|
2801
|
+
return {
|
|
2802
|
+
path,
|
|
2803
|
+
message: `\`${first}\` and \`${second}\` both set \`${path}\`, to different values — keep one: \`${envName(path)}\``
|
|
2804
|
+
};
|
|
2531
2805
|
}
|
|
2532
2806
|
function parseEnvOptions(env) {
|
|
2533
2807
|
const assignments = [];
|
|
2534
2808
|
const issues = [];
|
|
2809
|
+
const setBy = new Map();
|
|
2535
2810
|
for (const name of Object.keys(env).sort()) {
|
|
2536
2811
|
if (!name.startsWith(ENV_PREFIX)) continue;
|
|
2537
2812
|
const suffix = name.slice(ENV_PREFIX.length);
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2813
|
+
let raw = env[name];
|
|
2814
|
+
if (suffix === "" || raw === void 0) continue;
|
|
2815
|
+
let key = suffix.replace(/_/g, ".");
|
|
2541
2816
|
if (!/[a-z]/.test(suffix)) {
|
|
2542
|
-
|
|
2817
|
+
const path$1 = CONFIG_BY_ENV_NAME.get(name);
|
|
2818
|
+
if (path$1 === void 0) {
|
|
2819
|
+
if (isBlank(raw)) continue;
|
|
2820
|
+
if (claimsEnvSuffix(suffix) || canonicalSpelling(suffix) !== void 0) issues.push(unclaimedEnvIssue(name, suffix));
|
|
2821
|
+
continue;
|
|
2822
|
+
}
|
|
2823
|
+
if (name === SEED_ENV_VAR) {
|
|
2824
|
+
const own = envSeedBeforeOwnExport(env, raw);
|
|
2825
|
+
if (own) {
|
|
2826
|
+
if (own.prior === void 0) continue;
|
|
2827
|
+
raw = own.prior;
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2830
|
+
key = path$1;
|
|
2831
|
+
}
|
|
2832
|
+
const parsed = parseAssignment(key, raw, "env", name);
|
|
2833
|
+
if ("issue" in parsed) {
|
|
2834
|
+
issues.push(parsed.issue);
|
|
2543
2835
|
continue;
|
|
2544
2836
|
}
|
|
2545
|
-
const
|
|
2546
|
-
|
|
2547
|
-
|
|
2837
|
+
const { path, value } = parsed.assignment;
|
|
2838
|
+
const prior = setBy.get(path);
|
|
2839
|
+
const written = JSON.stringify(value);
|
|
2840
|
+
if (prior && prior.value !== written) {
|
|
2841
|
+
issues.push(conflictIssue(path, prior.name, name));
|
|
2842
|
+
continue;
|
|
2843
|
+
}
|
|
2844
|
+
setBy.set(path, {
|
|
2845
|
+
name,
|
|
2846
|
+
value: written
|
|
2847
|
+
});
|
|
2848
|
+
assignments.push(parsed.assignment);
|
|
2548
2849
|
}
|
|
2549
2850
|
return {
|
|
2550
2851
|
config: collect(assignments),
|
|
@@ -2733,7 +3034,7 @@ function reportDiagnostics(input) {
|
|
|
2733
3034
|
const cap = verbosity === "all" ? list.length : MAX_INSTANCES_PER_CODE;
|
|
2734
3035
|
for (const d of list.slice(0, cap)) logger.warn(prefix(formatDiagnostic(d)));
|
|
2735
3036
|
const hidden = list.length - cap;
|
|
2736
|
-
if (hidden > 0) logger.warn(prefix(`${list[0].severity} ${code} · +${hidden} more occurrence(s) (
|
|
3037
|
+
if (hidden > 0) logger.warn(prefix(`${list[0].severity} ${code} · +${hidden} more occurrence(s) (AFTERPACK_DIAGNOSTICS_LEVEL=all to list them)`));
|
|
2737
3038
|
}
|
|
2738
3039
|
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).`));
|
|
2739
3040
|
return summary;
|
|
@@ -2963,7 +3264,7 @@ const DIRECTIVE_KEYS = [
|
|
|
2963
3264
|
key: "complexity",
|
|
2964
3265
|
kind: "amplifier",
|
|
2965
3266
|
apply: (delta, value) => {
|
|
2966
|
-
const n = Number(value);
|
|
3267
|
+
const n = value.trim() === "" ? Number.NaN : Number(value);
|
|
2967
3268
|
if (!Number.isFinite(n) || n < 0) return "`complexity` needs a non-negative number";
|
|
2968
3269
|
delta.complexity = n;
|
|
2969
3270
|
return void 0;
|
|
@@ -2973,7 +3274,7 @@ const DIRECTIVE_KEYS = [
|
|
|
2973
3274
|
key: "inflation.max",
|
|
2974
3275
|
kind: "amplifier",
|
|
2975
3276
|
apply: (delta, value) => {
|
|
2976
|
-
const n = Number(value);
|
|
3277
|
+
const n = value.trim() === "" ? Number.NaN : Number(value);
|
|
2977
3278
|
if (!Number.isFinite(n) || n < 0) return "`inflation.max` needs a non-negative number";
|
|
2978
3279
|
delta.inflation = { max: n };
|
|
2979
3280
|
return void 0;
|
|
@@ -3309,127 +3610,6 @@ function captureDirectiveRegions(inputs, handAuthored, enabled = true) {
|
|
|
3309
3610
|
};
|
|
3310
3611
|
}
|
|
3311
3612
|
|
|
3312
|
-
//#endregion
|
|
3313
|
-
//#region src/seed.ts
|
|
3314
|
-
function randomSeed() {
|
|
3315
|
-
const b = randomBytes(8);
|
|
3316
|
-
const hi = b.readUInt32BE(0) & 2097151;
|
|
3317
|
-
const lo = b.readUInt32BE(4);
|
|
3318
|
-
return hi * 4294967296 + lo;
|
|
3319
|
-
}
|
|
3320
|
-
function gitHead() {
|
|
3321
|
-
try {
|
|
3322
|
-
const out = execFileSync("git", ["rev-parse", "HEAD"], { stdio: [
|
|
3323
|
-
"ignore",
|
|
3324
|
-
"pipe",
|
|
3325
|
-
"ignore"
|
|
3326
|
-
] }).toString().trim();
|
|
3327
|
-
return /^[0-9a-f]{7,64}$/i.test(out) ? out : null;
|
|
3328
|
-
} catch {
|
|
3329
|
-
return null;
|
|
3330
|
-
}
|
|
3331
|
-
}
|
|
3332
|
-
const SEED_ENV_VAR = "AFTERPACK_SEED";
|
|
3333
|
-
function parseSeedValue(raw) {
|
|
3334
|
-
return /^-?\d+$/.test(raw) ? Number(raw) : raw;
|
|
3335
|
-
}
|
|
3336
|
-
const SEED_STATE = Symbol.for("afterpack.integration-utils.seed-sessions");
|
|
3337
|
-
function sharedSeedState() {
|
|
3338
|
-
const holder = globalThis;
|
|
3339
|
-
holder[SEED_STATE] ??= {
|
|
3340
|
-
sessions: new Map(),
|
|
3341
|
-
ownEnvExports: []
|
|
3342
|
-
};
|
|
3343
|
-
return holder[SEED_STATE];
|
|
3344
|
-
}
|
|
3345
|
-
const { sessions, ownEnvExports } = sharedSeedState();
|
|
3346
|
-
function isOwnEnvExport(env, value) {
|
|
3347
|
-
return ownEnvExports.some((e) => e.env === env && e.value === value);
|
|
3348
|
-
}
|
|
3349
|
-
function openGeneration(root, leg) {
|
|
3350
|
-
let session = sessions.get(root);
|
|
3351
|
-
if (!session) {
|
|
3352
|
-
session = {
|
|
3353
|
-
seed: void 0,
|
|
3354
|
-
generation: 1,
|
|
3355
|
-
legs: [],
|
|
3356
|
-
resolvedByLeg: new Map(),
|
|
3357
|
-
gitFallbackWarned: false
|
|
3358
|
-
};
|
|
3359
|
-
sessions.set(root, session);
|
|
3360
|
-
} else if (session.legs.includes(leg)) {
|
|
3361
|
-
session.seed = void 0;
|
|
3362
|
-
session.generation += 1;
|
|
3363
|
-
session.legs = [];
|
|
3364
|
-
session.resolvedByLeg.clear();
|
|
3365
|
-
session.gitFallbackWarned = false;
|
|
3366
|
-
}
|
|
3367
|
-
session.legs.push(leg);
|
|
3368
|
-
return session;
|
|
3369
|
-
}
|
|
3370
|
-
function resolveWithinSession(input, session, env, deps) {
|
|
3371
|
-
if (typeof input === "number") return {
|
|
3372
|
-
seed: input,
|
|
3373
|
-
origin: "option"
|
|
3374
|
-
};
|
|
3375
|
-
if (typeof input === "string" && input !== "git") return {
|
|
3376
|
-
seed: input,
|
|
3377
|
-
origin: "option"
|
|
3378
|
-
};
|
|
3379
|
-
if (input === "git") {
|
|
3380
|
-
const head = (deps.gitHead ?? gitHead)();
|
|
3381
|
-
if (head) return {
|
|
3382
|
-
seed: head,
|
|
3383
|
-
origin: "git"
|
|
3384
|
-
};
|
|
3385
|
-
if (!session.gitFallbackWarned) {
|
|
3386
|
-
session.gitFallbackWarned = true;
|
|
3387
|
-
(deps.warn ?? ((m) => console.warn(m)))("[afterpack] seed \"git\": no git repository / HEAD found; using a fresh random seed for this build.");
|
|
3388
|
-
}
|
|
3389
|
-
}
|
|
3390
|
-
const fromEnv = env[SEED_ENV_VAR];
|
|
3391
|
-
if (fromEnv != null && fromEnv !== "" && !isOwnEnvExport(env, fromEnv)) return {
|
|
3392
|
-
seed: parseSeedValue(fromEnv),
|
|
3393
|
-
origin: "env"
|
|
3394
|
-
};
|
|
3395
|
-
if (session.seed !== void 0) return {
|
|
3396
|
-
seed: session.seed,
|
|
3397
|
-
origin: "session"
|
|
3398
|
-
};
|
|
3399
|
-
return {
|
|
3400
|
-
seed: (deps.randomSeed ?? randomSeed)(),
|
|
3401
|
-
origin: "fresh"
|
|
3402
|
-
};
|
|
3403
|
-
}
|
|
3404
|
-
function resolveBuildSeed(input, scope, deps = {}) {
|
|
3405
|
-
const env = deps.env ?? process.env;
|
|
3406
|
-
const session = openGeneration(scope.root, scope.leg);
|
|
3407
|
-
const { seed, origin } = resolveWithinSession(input, session, env, deps);
|
|
3408
|
-
if (origin === "env" || origin === "fresh") session.seed = seed;
|
|
3409
|
-
if (origin === "fresh" && (deps.exportToEnv ?? true)) {
|
|
3410
|
-
const value = String(seed);
|
|
3411
|
-
env[SEED_ENV_VAR] = value;
|
|
3412
|
-
const stale = ownEnvExports.findIndex((e) => e.env === env);
|
|
3413
|
-
if (stale >= 0) ownEnvExports.splice(stale, 1);
|
|
3414
|
-
ownEnvExports.push({
|
|
3415
|
-
env,
|
|
3416
|
-
value
|
|
3417
|
-
});
|
|
3418
|
-
}
|
|
3419
|
-
const prior = [...session.resolvedByLeg].find(([, s]) => s !== seed);
|
|
3420
|
-
session.resolvedByLeg.set(scope.leg, seed);
|
|
3421
|
-
return {
|
|
3422
|
-
seed,
|
|
3423
|
-
origin,
|
|
3424
|
-
legs: [...session.legs],
|
|
3425
|
-
generation: session.generation,
|
|
3426
|
-
mismatch: prior && session.generation === 1 ? {
|
|
3427
|
-
leg: prior[0],
|
|
3428
|
-
seed: prior[1]
|
|
3429
|
-
} : null
|
|
3430
|
-
};
|
|
3431
|
-
}
|
|
3432
|
-
|
|
3433
3613
|
//#endregion
|
|
3434
3614
|
//#region src/telemetry.ts
|
|
3435
3615
|
const API_URL_ENV_VAR$1 = "AFTERPACK_API_URL";
|
|
@@ -3649,7 +3829,7 @@ const TELEMETRY_NOTICE = [
|
|
|
3649
3829
|
"AfterPack: days.",
|
|
3650
3830
|
"AfterPack: It never sends your source, file names, paths, project name, diagnostic",
|
|
3651
3831
|
"AfterPack: message text, or exact byte counts. A clean build sends nothing.",
|
|
3652
|
-
"AfterPack: Turn it off with
|
|
3832
|
+
"AfterPack: Turn it off with AFTERPACK_TELEMETRY_ENABLED=false, --telemetry.enabled=false, or",
|
|
3653
3833
|
"AfterPack: `telemetry: { enabled: false }` in your config.",
|
|
3654
3834
|
"AfterPack: https://www.afterpack.dev/privacy"
|
|
3655
3835
|
];
|
|
@@ -3766,16 +3946,15 @@ function afterpackHashSalt(input) {
|
|
|
3766
3946
|
}));
|
|
3767
3947
|
return createHash("sha256").update(payload).digest("hex").slice(0, 32);
|
|
3768
3948
|
}
|
|
3769
|
-
function isCloudBuild(
|
|
3770
|
-
|
|
3771
|
-
return typeof key === "string" && key.trim() !== "";
|
|
3949
|
+
function isCloudBuild(key) {
|
|
3950
|
+
return cloudKey(key) !== null;
|
|
3772
3951
|
}
|
|
3773
3952
|
function versionEndpoint(env) {
|
|
3774
3953
|
const base = (env[API_URL_ENV_VAR] ?? DEFAULT_API_URL).replace(/\/+$/, "");
|
|
3775
3954
|
return `${base}${VERSION_ENDPOINT_PATH}`;
|
|
3776
3955
|
}
|
|
3777
|
-
async function resolveSaltEngine(env, localEngineVersion, deps = {}) {
|
|
3778
|
-
if (!isCloudBuild(
|
|
3956
|
+
async function resolveSaltEngine(key, env, localEngineVersion, deps = {}) {
|
|
3957
|
+
if (!isCloudBuild(key)) return {
|
|
3779
3958
|
engineVersion: localEngineVersion,
|
|
3780
3959
|
nonce: null,
|
|
3781
3960
|
cloud: false,
|
|
@@ -3810,7 +3989,7 @@ async function resolveSaltEngine(env, localEngineVersion, deps = {}) {
|
|
|
3810
3989
|
}
|
|
3811
3990
|
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.";
|
|
3812
3991
|
function saltSettings(settings, extra = {}) {
|
|
3813
|
-
const { seed: _seed, diagnostics: _diagnostics, artifactOptions, engineConfig,...rest } = settings;
|
|
3992
|
+
const { seed: _seed, seedFallback: _seedFallback, key: _key, diagnostics: _diagnostics, artifactOptions, engineConfig,...rest } = settings;
|
|
3814
3993
|
const { git: _git, telemetry: _telemetry,...output } = artifactOptions ?? {};
|
|
3815
3994
|
const { seed: _engineSeed,...engine } = engineConfig ?? {};
|
|
3816
3995
|
return {
|
|
@@ -3834,9 +4013,10 @@ async function prepareHashSalt(input) {
|
|
|
3834
4013
|
leg: input.leg
|
|
3835
4014
|
}, {
|
|
3836
4015
|
env,
|
|
3837
|
-
warn: input.warn
|
|
4016
|
+
warn: input.warn,
|
|
4017
|
+
fallback: input.seedFallback
|
|
3838
4018
|
});
|
|
3839
|
-
const engine = await resolveSaltEngine(env, input.localEngineVersion, { fetchImpl: input.fetchImpl });
|
|
4019
|
+
const engine = await resolveSaltEngine(input.key, env, input.localEngineVersion, { fetchImpl: input.fetchImpl });
|
|
3840
4020
|
if (engine.probeFailed) input.warn?.(PROBE_FAILED_WARNING);
|
|
3841
4021
|
return {
|
|
3842
4022
|
resolvedSeed,
|
|
@@ -4646,7 +4826,7 @@ function verifyProtectionReceipt(receiptPath, dir, expectedBuildId) {
|
|
|
4646
4826
|
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`);
|
|
4647
4827
|
if (parsed.files.length === 0) problems.push("receipt records zero obfuscated files");
|
|
4648
4828
|
const transformed = parsed.files.filter((f) => f.transformed !== false).length;
|
|
4649
|
-
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
|
|
4829
|
+
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)`);
|
|
4650
4830
|
for (const entry of parsed.files) {
|
|
4651
4831
|
const file = join(dir, entry.path);
|
|
4652
4832
|
if (!existsSync(file)) {
|
|
@@ -5318,6 +5498,7 @@ async function runObfuscationPass(options) {
|
|
|
5318
5498
|
const passStartedAt = options.startedAt ?? Date.now();
|
|
5319
5499
|
const callerAnchored = options.startedAt !== void 0;
|
|
5320
5500
|
const { engine, label, cwd, combinedProtectionMap, artifactOptions = {}, env = process.env } = options;
|
|
5501
|
+
const key = cloudKey(options.key);
|
|
5321
5502
|
const logger = silenceSummaryLines(options.logger ?? DEFAULT_LOGGER, options.diagnostics);
|
|
5322
5503
|
const prefix = (message) => `[${label}] ${message}`;
|
|
5323
5504
|
const style = options.summaryStyle ?? "plugin";
|
|
@@ -5345,7 +5526,8 @@ async function runObfuscationPass(options) {
|
|
|
5345
5526
|
leg: options.buildLeg ?? combinedProtectionMap.buildDir
|
|
5346
5527
|
}, {
|
|
5347
5528
|
env,
|
|
5348
|
-
warn: (m) => logger.warn(m)
|
|
5529
|
+
warn: (m) => logger.warn(m),
|
|
5530
|
+
fallback: options.seedFallback
|
|
5349
5531
|
});
|
|
5350
5532
|
const seed = resolvedSeed.seed;
|
|
5351
5533
|
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.`));
|
|
@@ -5447,6 +5629,10 @@ async function runObfuscationPass(options) {
|
|
|
5447
5629
|
});
|
|
5448
5630
|
const localEngineVersion = await readEngineVersion(engine);
|
|
5449
5631
|
const gateVersion = localEngineVersion ?? options.client?.coreVersion;
|
|
5632
|
+
if (key === null && !coreHonoursNullKey(gateVersion)) {
|
|
5633
|
+
const source = keySourceForOlderCore(env, process.cwd());
|
|
5634
|
+
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)));
|
|
5635
|
+
}
|
|
5450
5636
|
const derivedSourceType = options.sourceType !== void 0 && coreSupportsSourceType(gateVersion) ? options.sourceType : void 0;
|
|
5451
5637
|
if (options.fileSourceTypes && options.engineConfig?.sourceType === void 0 && coreSupportsFileSourceType(gateVersion)) for (const input of inputs) {
|
|
5452
5638
|
const sourceType = options.fileSourceTypes.get(input.path);
|
|
@@ -5462,7 +5648,7 @@ async function runObfuscationPass(options) {
|
|
|
5462
5648
|
engine: options.engineConfig,
|
|
5463
5649
|
renameGlobals: capture.renameGlobals
|
|
5464
5650
|
});
|
|
5465
|
-
const saltEngine = options.cloudEngineExpectation ?? (options.hashedNames ? await resolveSaltEngine(env, localEngineVersion) : null);
|
|
5651
|
+
const saltEngine = options.cloudEngineExpectation ?? (options.hashedNames ? await resolveSaltEngine(key, env, localEngineVersion) : null);
|
|
5466
5652
|
let namesPlan = null;
|
|
5467
5653
|
let hashSalt = null;
|
|
5468
5654
|
if (options.hashedNames && saltEngine && !options.emitToCaller) {
|
|
@@ -5497,7 +5683,7 @@ async function runObfuscationPass(options) {
|
|
|
5497
5683
|
}
|
|
5498
5684
|
}
|
|
5499
5685
|
const localEngineDisplay = installedEngineVersion(options.client?.coreVersion ?? null, localEngineVersion);
|
|
5500
|
-
const announcedEngine = isCloudBuild(
|
|
5686
|
+
const announcedEngine = isCloudBuild(key) ? describeEngine("cloud", saltEngine?.probedCloudVersion ?? null) : describeEngine("local", localEngineDisplay);
|
|
5501
5687
|
if (style !== "cli") {
|
|
5502
5688
|
const engineClause = announcedEngine ? ` with ${announcedEngine}` : "";
|
|
5503
5689
|
logger.log(prefix(`obfuscating ${inputs.length} file(s) at ${describeLevel(options.preset, options.complexity)}${engineClause} ...`));
|
|
@@ -5515,9 +5701,13 @@ async function runObfuscationPass(options) {
|
|
|
5515
5701
|
if (error instanceof WirePathError) throw new Error(prefix(error.message));
|
|
5516
5702
|
throw error;
|
|
5517
5703
|
}
|
|
5704
|
+
const wireConfig = {
|
|
5705
|
+
...wire.config,
|
|
5706
|
+
key
|
|
5707
|
+
};
|
|
5518
5708
|
let batch;
|
|
5519
5709
|
try {
|
|
5520
|
-
batch = wire.toLocal(await engine.processBatch(wire.inputs,
|
|
5710
|
+
batch = wire.toLocal(await engine.processBatch(wire.inputs, wireConfig, context));
|
|
5521
5711
|
} catch (error) {
|
|
5522
5712
|
const cloud = toCloudApiError(error, {
|
|
5523
5713
|
identity: options.client,
|
|
@@ -5812,6 +6002,8 @@ function passSettings(resolved) {
|
|
|
5812
6002
|
return {
|
|
5813
6003
|
artifactOptions: settings.artifactOptions,
|
|
5814
6004
|
seed: settings.seed,
|
|
6005
|
+
seedFallback: settings.seedFallback,
|
|
6006
|
+
key: settings.key,
|
|
5815
6007
|
preset: settings.preset,
|
|
5816
6008
|
complexity: settings.complexity,
|
|
5817
6009
|
regions: settings.regions,
|
|
@@ -5833,9 +6025,33 @@ function unsupportedIssues(unsupported, merged, layers) {
|
|
|
5833
6025
|
}
|
|
5834
6026
|
return out;
|
|
5835
6027
|
}
|
|
5836
|
-
function
|
|
5837
|
-
|
|
5838
|
-
|
|
6028
|
+
function gitSeedFallback(layers) {
|
|
6029
|
+
let top = layers.length - 1;
|
|
6030
|
+
while (top >= 0 && getPath(layers[top].config, "seed") === void 0) top--;
|
|
6031
|
+
if (top < 0 || getPath(layers[top].config, "seed") !== "git") return null;
|
|
6032
|
+
for (let i = top - 1; i >= 0; i--) {
|
|
6033
|
+
const seed = getPath(layers[i].config, "seed");
|
|
6034
|
+
if (seed === void 0 || seed === "git") continue;
|
|
6035
|
+
if (seed === CONFIG_RESET) return null;
|
|
6036
|
+
if (typeof seed !== "number" && typeof seed !== "string") return null;
|
|
6037
|
+
return {
|
|
6038
|
+
seed,
|
|
6039
|
+
origin: layers[i].seedOrigin,
|
|
6040
|
+
from: layers[i].from
|
|
6041
|
+
};
|
|
6042
|
+
}
|
|
6043
|
+
return null;
|
|
6044
|
+
}
|
|
6045
|
+
function settleConfigLayers(layers, appendLists$1) {
|
|
6046
|
+
const config = mergeLayers(layers.map((l) => l.config), appendLists$1);
|
|
6047
|
+
return {
|
|
6048
|
+
config,
|
|
6049
|
+
options: {
|
|
6050
|
+
...toPluginOptions(config),
|
|
6051
|
+
seedFallback: gitSeedFallback(layers)
|
|
6052
|
+
},
|
|
6053
|
+
engineConfig: toEngineConfig(config)
|
|
6054
|
+
};
|
|
5839
6055
|
}
|
|
5840
6056
|
function sameRankConflicts(options, cli) {
|
|
5841
6057
|
const issues = [];
|
|
@@ -5843,10 +6059,10 @@ function sameRankConflicts(options, cli) {
|
|
|
5843
6059
|
const fromOptions = getPath(options, key.path);
|
|
5844
6060
|
const fromCli = getPath(cli, key.path);
|
|
5845
6061
|
if (fromOptions === void 0 || fromCli === void 0) continue;
|
|
5846
|
-
if (
|
|
6062
|
+
if (shownValue(fromOptions) === shownValue(fromCli)) continue;
|
|
5847
6063
|
issues.push({
|
|
5848
6064
|
path: key.path,
|
|
5849
|
-
message: `\`${key.path}\` is set twice at the same precedence — the options object says ${
|
|
6065
|
+
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.`
|
|
5850
6066
|
});
|
|
5851
6067
|
}
|
|
5852
6068
|
return issues;
|
|
@@ -5880,7 +6096,25 @@ function resolvePluginConfig(input) {
|
|
|
5880
6096
|
const normalized = normalizePluginOptions(input.options, localKeys, optionsSurface);
|
|
5881
6097
|
const options = validateConfig(normalized.config, optionsSurface);
|
|
5882
6098
|
const explicit = mergeConfig(options.config, cli.config);
|
|
5883
|
-
const
|
|
6099
|
+
const fileName = file.path ?? CONFIG_FILE_NAME;
|
|
6100
|
+
const settled = settleConfigLayers([
|
|
6101
|
+
{
|
|
6102
|
+
config: file.config,
|
|
6103
|
+
from: fileName,
|
|
6104
|
+
seedOrigin: "option"
|
|
6105
|
+
},
|
|
6106
|
+
{
|
|
6107
|
+
config: env.config,
|
|
6108
|
+
from: "the environment",
|
|
6109
|
+
seedOrigin: "env"
|
|
6110
|
+
},
|
|
6111
|
+
{
|
|
6112
|
+
config: explicit,
|
|
6113
|
+
from: "the command line or plugin options",
|
|
6114
|
+
seedOrigin: "option"
|
|
6115
|
+
}
|
|
6116
|
+
], input.appendLists);
|
|
6117
|
+
const config = settled.config;
|
|
5884
6118
|
const issues = [
|
|
5885
6119
|
...file.issues.map((i) => ` ${file.path ?? CONFIG_FILE_NAME}: ${i.message}`),
|
|
5886
6120
|
...env.issues.map((i) => ` environment: ${i.message}`),
|
|
@@ -5907,8 +6141,7 @@ function resolvePluginConfig(input) {
|
|
|
5907
6141
|
])
|
|
5908
6142
|
];
|
|
5909
6143
|
if (issues.length > 0) throw new Error([`[${input.label}] refusing to build with an invalid configuration:`, ...issues].join("\n"));
|
|
5910
|
-
|
|
5911
|
-
const pluginOptions = toPluginOptions(config);
|
|
6144
|
+
const pluginOptions = settled.options;
|
|
5912
6145
|
const supplied = isPlainObject(input.options) ? input.options : {};
|
|
5913
6146
|
const localArtifactOptions = {};
|
|
5914
6147
|
for (const name of PLUGIN_LOCAL_KEYS) if (supplied[name] !== void 0) localArtifactOptions[name] = supplied[name];
|
|
@@ -5921,7 +6154,7 @@ function resolvePluginConfig(input) {
|
|
|
5921
6154
|
...localArtifactOptions
|
|
5922
6155
|
}
|
|
5923
6156
|
},
|
|
5924
|
-
engineConfig:
|
|
6157
|
+
engineConfig: settled.engineConfig,
|
|
5925
6158
|
configFile: file.path,
|
|
5926
6159
|
positionals: cli.positionals,
|
|
5927
6160
|
help: false,
|
|
@@ -5930,4 +6163,4 @@ function resolvePluginConfig(input) {
|
|
|
5930
6163
|
}
|
|
5931
6164
|
|
|
5932
6165
|
//#endregion
|
|
5933
|
-
export { AFTERPACK_DIR, AfterpackFilesError, AlreadyObfuscatedError, CLOUD_REFUSAL_SUMMARY, CONFIG_FILE_NAME, CONFIG_KEYS, CORE_FLOOR_SUMMARY, CloudApiError, CoreVersionError, DIAG_AFTERPACK_DIR_IN_OUTPUT, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, DIAG_RECEIPT_UNWRITABLE, NEXT_CHUNKS_PREFIX, PROTECTION_RECEIPTS_DIR, SEED_ENV_VAR, UnreadableReceiptError, afterpackHome, angularHashToken, angularServerManifestRefusal, applyBundleOutput,
|
|
6166
|
+
export { AFTERPACK_DIR, AfterpackFilesError, AlreadyObfuscatedError, CLOUD_REFUSAL_SUMMARY, CONFIG_FILE_NAME, CONFIG_KEYS, CORE_FLOOR_SUMMARY, CloudApiError, CoreVersionError, DIAG_AFTERPACK_DIR_IN_OUTPUT, DIAG_ALREADY_OBFUSCATED, DIAG_RECEIPT_UNREADABLE, DIAG_RECEIPT_UNWRITABLE, NEXT_CHUNKS_PREFIX, PROTECTION_RECEIPTS_DIR, SEED_ENV_VAR, UnreadableReceiptError, afterpackHome, angularHashToken, angularServerManifestRefusal, applyBundleOutput, buildDirKey, collectBundleJs, collectJsFiles, collectSourceMaps, collectStylesheets, createTelemetryReporter, decodeDataUri, detectNextBundler, discoverInputSourceMap, ensureAfterpackGitignore, extractSourceMappingURL, findHashTokenReference, findUpward, getPath, installedRequiredLine, isOwnEnvExport, isWithinDir, loadConfigFile, locateProtectionReceipt, mergeLayers, nextChunkToken, normalizePluginOptions, npxAlternative, parseCliOptions, parseEnvOptions, passSettings, planAngularIntegrity, prepareHashSalt, protectionReceiptPath, readEngineVersion, recomputeAngularIntegrity, regenerateCompressedSiblings, removeSourceMaps, reportPolicySaltBits, resolveClientIdentity, resolvePluginConfig, resolveReportPolicy, runObfuscationPass, saltSettings, sanitizeNotices, scanDirectives, serverAddsInfo, settleConfigLayers, sha256Hex, sha256Of, skipNextInternals, sourceTypeForBundle, sourceTypeForOutputFormat, sriPluginRefusal, stagedPath, stripBundleCssSourceMaps, stripCssSourceMappingURLs, sweepOutputTree, toEngineConfig, toPluginOptions, unreferencedHashedFiles, unsaltedAssetsWarning, validateConfig, verifyProtectionReceipt, withSourceMappingURL, withoutCssSourceMappingURL, writeArtifacts, writeDeferredProtectionReceipt, writeFileAtomic, writeProtectionReceipt };
|