sim-setup 1.0.64-preview.343.1 → 1.0.64-preview.344.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +75 -22
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -3406,6 +3406,14 @@ var init_context = __esm(() => {
|
|
|
3406
3406
|
// src/env-files.ts
|
|
3407
3407
|
import { existsSync as existsSync3, readFileSync as readFileSync3, renameSync as renameSync2 } from "node:fs";
|
|
3408
3408
|
import path3 from "node:path";
|
|
3409
|
+
function verbatimValue(raw) {
|
|
3410
|
+
const trimmed = raw.trim();
|
|
3411
|
+
if (trimmed.startsWith('"') || trimmed.startsWith("'")) {
|
|
3412
|
+
const end = trimmed.indexOf(trimmed[0], 1);
|
|
3413
|
+
return end === -1 ? trimmed : trimmed.slice(0, end + 1);
|
|
3414
|
+
}
|
|
3415
|
+
return trimmed.replace(/\s+#.*$/, "").trim();
|
|
3416
|
+
}
|
|
3409
3417
|
function parseValue(raw) {
|
|
3410
3418
|
const trimmed = raw.trim();
|
|
3411
3419
|
if (trimmed.startsWith('"') || trimmed.startsWith("'")) {
|
|
@@ -3430,25 +3438,43 @@ function readEnvFile(target) {
|
|
|
3430
3438
|
const filePath = ENV_PATHS[target];
|
|
3431
3439
|
const exists = existsSync3(filePath);
|
|
3432
3440
|
const content = exists ? readFileSync3(filePath, "utf8") : "";
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3441
|
+
const verbatim = new Map;
|
|
3442
|
+
for (const line of content.split(`
|
|
3443
|
+
`)) {
|
|
3444
|
+
const match = LINE_RE.exec(line);
|
|
3445
|
+
if (match)
|
|
3446
|
+
verbatim.set(match[1], verbatimValue(match[2]));
|
|
3438
3447
|
}
|
|
3448
|
+
return { target, path: filePath, exists, content, vars: parseEnv(content), verbatim };
|
|
3449
|
+
}
|
|
3450
|
+
function spellEnvValue(value) {
|
|
3451
|
+
if (/[\r\n]/.test(value))
|
|
3452
|
+
return { refusal: "it contains a line break" };
|
|
3439
3453
|
if (value.includes("$")) {
|
|
3440
3454
|
if (/["\\`]/.test(value)) {
|
|
3441
|
-
|
|
3455
|
+
return { refusal: "it mixes $ with a double quote, backslash, or backtick" };
|
|
3442
3456
|
}
|
|
3443
|
-
return `"${value.replaceAll("$", "\\$")}"
|
|
3457
|
+
return { text: `"${value.replaceAll("$", "\\$")}"` };
|
|
3458
|
+
}
|
|
3459
|
+
if (value === value.trim() && !value.includes("#") && !/^["'`]/.test(value)) {
|
|
3460
|
+
return { text: value };
|
|
3444
3461
|
}
|
|
3445
|
-
if (value === value.trim() && !value.includes("#") && !/^["'`]/.test(value))
|
|
3446
|
-
return value;
|
|
3447
3462
|
if (!value.includes("'"))
|
|
3448
|
-
return `'${value}'
|
|
3463
|
+
return { text: `'${value}'` };
|
|
3449
3464
|
if (!/["\\`]/.test(value))
|
|
3450
|
-
return `"${value}"
|
|
3451
|
-
|
|
3465
|
+
return { text: `"${value}"` };
|
|
3466
|
+
return { refusal: "it mixes quotes with a # or edge whitespace" };
|
|
3467
|
+
}
|
|
3468
|
+
function envValueRefusal(value) {
|
|
3469
|
+
const spelling = spellEnvValue(value);
|
|
3470
|
+
return "refusal" in spelling ? spelling.refusal : undefined;
|
|
3471
|
+
}
|
|
3472
|
+
function formatEnvValue(key, value) {
|
|
3473
|
+
const spelling = spellEnvValue(value);
|
|
3474
|
+
if ("refusal" in spelling) {
|
|
3475
|
+
throw new Error(`${key} cannot be written to an environment file: ${spelling.refusal}`);
|
|
3476
|
+
}
|
|
3477
|
+
return spelling.text;
|
|
3452
3478
|
}
|
|
3453
3479
|
function upsertEnv(content, key, value) {
|
|
3454
3480
|
const lines = content.split(`
|
|
@@ -5896,6 +5922,23 @@ var init_twins = __esm(() => {
|
|
|
5896
5922
|
});
|
|
5897
5923
|
|
|
5898
5924
|
// src/checks.ts
|
|
5925
|
+
function holdsReference(file, key) {
|
|
5926
|
+
return /(^|[^\\])\$/.test(file.verbatim.get(key) ?? "");
|
|
5927
|
+
}
|
|
5928
|
+
function sameEnvValue(a, b, key) {
|
|
5929
|
+
if (a.vars.get(key) !== b.vars.get(key))
|
|
5930
|
+
return false;
|
|
5931
|
+
if (!holdsReference(a, key) && !holdsReference(b, key))
|
|
5932
|
+
return true;
|
|
5933
|
+
return a.verbatim.get(key) === b.verbatim.get(key);
|
|
5934
|
+
}
|
|
5935
|
+
function mirrorBlocker(file, key, value) {
|
|
5936
|
+
if (holdsReference(file, key)) {
|
|
5937
|
+
return "it contains a $ reference, so copy it and the variables it uses by hand";
|
|
5938
|
+
}
|
|
5939
|
+
const refusal = envValueRefusal(value);
|
|
5940
|
+
return refusal && `${refusal}, so copy it by hand`;
|
|
5941
|
+
}
|
|
5899
5942
|
function detectLayout(env) {
|
|
5900
5943
|
if (env.sim.exists || env.realtime.exists || env.db.exists)
|
|
5901
5944
|
return "split";
|
|
@@ -5952,8 +5995,9 @@ function checkFiles(ctx) {
|
|
|
5952
5995
|
const values = {};
|
|
5953
5996
|
for (const key of keys) {
|
|
5954
5997
|
const value = ctx.env.sim.vars.get(key);
|
|
5955
|
-
if (value && !isPlaceholder(value))
|
|
5998
|
+
if (value && !isPlaceholder(value) && !mirrorBlocker(ctx.env.sim, key, value)) {
|
|
5956
5999
|
values[key] = value;
|
|
6000
|
+
}
|
|
5957
6001
|
}
|
|
5958
6002
|
writeEnvValues(target, values);
|
|
5959
6003
|
} : undefined
|
|
@@ -5964,6 +6008,8 @@ function checkFiles(ctx) {
|
|
|
5964
6008
|
function autofixForMissing(ctx, target, key) {
|
|
5965
6009
|
const simValue = ctx.env.sim.vars.get(key);
|
|
5966
6010
|
if (target !== "sim" && SHARED_KEYS.includes(key) && simValue && !isPlaceholder(simValue)) {
|
|
6011
|
+
if (mirrorBlocker(ctx.env.sim, key, simValue))
|
|
6012
|
+
return;
|
|
5967
6013
|
return () => writeEnvValues(target, { [key]: simValue });
|
|
5968
6014
|
}
|
|
5969
6015
|
if (MIN_32_KEYS.has(key)) {
|
|
@@ -5993,12 +6039,13 @@ function checkSchema(ctx) {
|
|
|
5993
6039
|
continue;
|
|
5994
6040
|
}
|
|
5995
6041
|
if (isPlaceholder(value)) {
|
|
6042
|
+
const autofix = MIN_32_KEYS.has(key) ? autofixForMissing(ctx, target, key) : undefined;
|
|
5996
6043
|
findings.push({
|
|
5997
6044
|
group: "schema",
|
|
5998
6045
|
status: production ? "fail" : "warn",
|
|
5999
6046
|
message: `${rel(file)}: ${key} still has the .env.example placeholder`,
|
|
6000
|
-
fix:
|
|
6001
|
-
autofix
|
|
6047
|
+
fix: autofix ? "doctor --fix sets a real value" : `replace the placeholder in ${rel(file)}`,
|
|
6048
|
+
autofix
|
|
6002
6049
|
});
|
|
6003
6050
|
continue;
|
|
6004
6051
|
}
|
|
@@ -6052,13 +6099,14 @@ function checkConsistency(ctx) {
|
|
|
6052
6099
|
const realtimeValue = realtime.vars.get(key);
|
|
6053
6100
|
if (!simValue || !realtimeValue)
|
|
6054
6101
|
continue;
|
|
6055
|
-
if (
|
|
6102
|
+
if (!sameEnvValue(sim, realtime, key)) {
|
|
6103
|
+
const blocker = mirrorBlocker(sim, key, simValue);
|
|
6056
6104
|
findings.push({
|
|
6057
6105
|
group: "consistency",
|
|
6058
6106
|
status: "fail",
|
|
6059
6107
|
message: `${key} differs between apps/sim/.env and apps/realtime/.env`,
|
|
6060
|
-
fix: "doctor --fix mirrors the apps/sim/.env value",
|
|
6061
|
-
autofix: () => writeEnvValues("realtime", { [key]: simValue })
|
|
6108
|
+
fix: blocker ? `mirror the apps/sim/.env value: ${blocker}` : "doctor --fix mirrors the apps/sim/.env value",
|
|
6109
|
+
autofix: blocker ? undefined : () => writeEnvValues("realtime", { [key]: simValue })
|
|
6062
6110
|
});
|
|
6063
6111
|
}
|
|
6064
6112
|
}
|
|
@@ -6066,13 +6114,14 @@ function checkConsistency(ctx) {
|
|
|
6066
6114
|
if (sim.exists && db.exists) {
|
|
6067
6115
|
const simDsn = sim.vars.get("DATABASE_URL");
|
|
6068
6116
|
const dbDsn = db.vars.get("DATABASE_URL");
|
|
6069
|
-
if (simDsn && dbDsn &&
|
|
6117
|
+
if (simDsn && dbDsn && !sameEnvValue(sim, db, "DATABASE_URL")) {
|
|
6118
|
+
const blocker = mirrorBlocker(sim, "DATABASE_URL", simDsn);
|
|
6070
6119
|
findings.push({
|
|
6071
6120
|
group: "consistency",
|
|
6072
6121
|
status: "fail",
|
|
6073
6122
|
message: "DATABASE_URL differs between apps/sim/.env and packages/db/.env — migrations would hit a different database",
|
|
6074
|
-
fix: "doctor --fix mirrors the apps/sim/.env value",
|
|
6075
|
-
autofix: () => writeEnvValues("db", { DATABASE_URL: simDsn })
|
|
6123
|
+
fix: blocker ? `mirror the apps/sim/.env value: ${blocker}` : "doctor --fix mirrors the apps/sim/.env value",
|
|
6124
|
+
autofix: blocker ? undefined : () => writeEnvValues("db", { DATABASE_URL: simDsn })
|
|
6076
6125
|
});
|
|
6077
6126
|
}
|
|
6078
6127
|
}
|
|
@@ -12585,7 +12634,11 @@ async function down(install) {
|
|
|
12585
12634
|
async function reset2(install) {
|
|
12586
12635
|
const target = install ? ` ${describeInstall(install)} will be removed.` : "";
|
|
12587
12636
|
if (install?.kind !== "k8s" && executableExists("docker") && !dockerReachable()) {
|
|
12588
|
-
|
|
12637
|
+
const hints = [`start Docker, then re-run ${theme.command("npx sim-setup reset")}`];
|
|
12638
|
+
if (!install) {
|
|
12639
|
+
hints.push(`if Sim runs on Kubernetes, switch kubectl to its cluster's context and re-run`);
|
|
12640
|
+
}
|
|
12641
|
+
throw new SetupError("Docker isn't reachable, so the managed containers and volumes can't be removed. Your env files were left in place.", hints);
|
|
12589
12642
|
}
|
|
12590
12643
|
const ok = await confirm2({
|
|
12591
12644
|
message: theme.error(`Reset archives your .env files and wipes managed data (volumes).${target} Continue?`),
|