sim-setup 1.0.63 → 1.0.64-preview.332.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/THIRD_PARTY_LICENSES +13 -0
- package/dist/index.js +68 -22
- package/package.json +1 -1
package/THIRD_PARTY_LICENSES
CHANGED
|
@@ -9,6 +9,19 @@ Copyright (c) 2016-present Vercel, Inc.
|
|
|
9
9
|
chalk
|
|
10
10
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
11
11
|
|
|
12
|
+
fast-string-truncated-width and fast-string-width
|
|
13
|
+
Copyright (c) 2024-present Fabio Spampinato
|
|
14
|
+
|
|
15
|
+
fast-wrap-ansi
|
|
16
|
+
Copyright (c) 2025 James Garbutt
|
|
17
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
|
18
|
+
|
|
19
|
+
ipaddr.js
|
|
20
|
+
Copyright (C) 2011-2017 whitequark <whitequark@whitequark.org>
|
|
21
|
+
|
|
22
|
+
sisteransi
|
|
23
|
+
Copyright (c) 2018 Terkel Gjervig Nielsen
|
|
24
|
+
|
|
12
25
|
The dependencies above are licensed under the MIT License:
|
|
13
26
|
|
|
14
27
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
package/dist/index.js
CHANGED
|
@@ -3333,6 +3333,18 @@ function readEnvFile(target) {
|
|
|
3333
3333
|
const content = exists ? readFileSync3(filePath, "utf8") : "";
|
|
3334
3334
|
return { target, path: filePath, exists, content, vars: parseEnv(content) };
|
|
3335
3335
|
}
|
|
3336
|
+
function formatEnvValue(key, value) {
|
|
3337
|
+
if (/[\r\n]/.test(value)) {
|
|
3338
|
+
throw new Error(`${key} cannot be written to an environment file: it contains a line break`);
|
|
3339
|
+
}
|
|
3340
|
+
if (value === value.trim() && !value.includes("#") && !/^["'`]/.test(value))
|
|
3341
|
+
return value;
|
|
3342
|
+
if (!value.includes("'"))
|
|
3343
|
+
return `'${value}'`;
|
|
3344
|
+
if (!/["\\$`]/.test(value))
|
|
3345
|
+
return `"${value}"`;
|
|
3346
|
+
throw new Error(`${key} cannot be written to an environment file: it mixes quotes with a # or edge whitespace`);
|
|
3347
|
+
}
|
|
3336
3348
|
function upsertEnv(content, key, value) {
|
|
3337
3349
|
const lines = content.split(`
|
|
3338
3350
|
`);
|
|
@@ -3344,7 +3356,7 @@ function upsertEnv(content, key, value) {
|
|
|
3344
3356
|
}
|
|
3345
3357
|
const activeIdx = activeIndexes[0] ?? -1;
|
|
3346
3358
|
const idx = activeIdx !== -1 ? activeIdx : lines.findIndex((l) => commentedRe.test(l));
|
|
3347
|
-
const newLine = `${key}=${value}`;
|
|
3359
|
+
const newLine = `${key}=${formatEnvValue(key, value)}`;
|
|
3348
3360
|
if (idx === -1) {
|
|
3349
3361
|
const trailing = lines.length > 0 && lines[lines.length - 1] === "";
|
|
3350
3362
|
if (trailing)
|
|
@@ -3477,9 +3489,35 @@ var init_executables = () => {};
|
|
|
3477
3489
|
import { spawnSync as spawnSync2 } from "node:child_process";
|
|
3478
3490
|
import net from "node:net";
|
|
3479
3491
|
import os2 from "node:os";
|
|
3492
|
+
function publishedBeyondLoopback(container, containerPort) {
|
|
3493
|
+
const out = commandOutput("docker", [
|
|
3494
|
+
"inspect",
|
|
3495
|
+
container,
|
|
3496
|
+
"--format",
|
|
3497
|
+
`{{json (index .HostConfig.PortBindings "${containerPort}")}}`
|
|
3498
|
+
]);
|
|
3499
|
+
if (!out)
|
|
3500
|
+
return false;
|
|
3501
|
+
try {
|
|
3502
|
+
const bindings = JSON.parse(out);
|
|
3503
|
+
return (bindings ?? []).some((binding) => binding.HostIp !== LOOPBACK_HOST);
|
|
3504
|
+
} catch {
|
|
3505
|
+
return false;
|
|
3506
|
+
}
|
|
3507
|
+
}
|
|
3508
|
+
function exposedManagedContainers(detection) {
|
|
3509
|
+
const exposed = [];
|
|
3510
|
+
if (detection.dbContainer?.managed && publishedBeyondLoopback(DB_CONTAINER, "5432/tcp")) {
|
|
3511
|
+
exposed.push(DB_CONTAINER);
|
|
3512
|
+
}
|
|
3513
|
+
if (detection.redisContainer?.managed && publishedBeyondLoopback(REDIS_CONTAINER, "6379/tcp")) {
|
|
3514
|
+
exposed.push(REDIS_CONTAINER);
|
|
3515
|
+
}
|
|
3516
|
+
return exposed;
|
|
3517
|
+
}
|
|
3480
3518
|
function portOpen(port, timeoutMs = 500) {
|
|
3481
3519
|
return new Promise((resolve) => {
|
|
3482
|
-
const socket = net.connect({ port, host:
|
|
3520
|
+
const socket = net.connect({ port, host: LOOPBACK_HOST });
|
|
3483
3521
|
const done = (result) => {
|
|
3484
3522
|
socket.destroy();
|
|
3485
3523
|
resolve(result);
|
|
@@ -3587,7 +3625,7 @@ async function runDetection() {
|
|
|
3587
3625
|
specs: detectSpecs(dockerRunning)
|
|
3588
3626
|
};
|
|
3589
3627
|
}
|
|
3590
|
-
var MANAGED_LABEL = "managed-by=sim-setup", DB_CONTAINER = "sim-postgres", REDIS_CONTAINER = "sim-redis", SHELL_LLM_KEYS;
|
|
3628
|
+
var MANAGED_LABEL = "managed-by=sim-setup", DB_CONTAINER = "sim-postgres", REDIS_CONTAINER = "sim-redis", LOOPBACK_HOST = "127.0.0.1", SHELL_LLM_KEYS;
|
|
3591
3629
|
var init_detect = __esm(() => {
|
|
3592
3630
|
init_env_files();
|
|
3593
3631
|
init_executables();
|
|
@@ -12449,36 +12487,39 @@ async function reset2(install) {
|
|
|
12449
12487
|
log2.info("Reset cancelled.");
|
|
12450
12488
|
return;
|
|
12451
12489
|
}
|
|
12452
|
-
if (install?.kind === "compose") {
|
|
12453
|
-
const backup = archiveFile(path8.join(install.dir, ".env"));
|
|
12454
|
-
if (backup)
|
|
12455
|
-
log2.step(`Archived ${backup}`);
|
|
12456
|
-
} else {
|
|
12457
|
-
for (const target of ["sim", "realtime", "db", "root"]) {
|
|
12458
|
-
const backup = archiveEnvFile(target);
|
|
12459
|
-
if (backup)
|
|
12460
|
-
log2.step(`Archived ${backup}`);
|
|
12461
|
-
}
|
|
12462
|
-
}
|
|
12463
12490
|
if (install?.kind === "compose") {
|
|
12464
12491
|
dockerRun(composeArgs(install, "down", "-v"), "docker compose down -v failed", install.dir);
|
|
12465
12492
|
log2.step("Containers and volumes removed");
|
|
12466
12493
|
} else if (install?.kind === "dev") {
|
|
12467
12494
|
const names = managedNames(install);
|
|
12468
12495
|
if (names.length)
|
|
12469
|
-
|
|
12470
|
-
spawnSync8("docker", ["volume", "rm", POSTGRES_VOLUME2], {
|
|
12496
|
+
dockerRun(["rm", "-f", ...names], "docker rm failed");
|
|
12497
|
+
const removal = spawnSync8("docker", ["volume", "rm", POSTGRES_VOLUME2], { encoding: "utf8" });
|
|
12498
|
+
if (removal.status !== 0 && spawnSync8("docker", ["volume", "inspect", POSTGRES_VOLUME2], { stdio: "ignore" }).status === 0) {
|
|
12499
|
+
throw new SetupError(`could not remove the ${POSTGRES_VOLUME2} volume: ${removal.stderr.trim()}`);
|
|
12500
|
+
}
|
|
12471
12501
|
log2.step("Managed containers and Postgres volume removed");
|
|
12472
12502
|
} else if (install?.kind === "k8s") {
|
|
12473
12503
|
const uninstall = spawnSync8("helm", ["uninstall", K8S_RELEASE, "--kube-context", install.context, "-n", K8S_NAMESPACE], { stdio: "inherit" });
|
|
12474
12504
|
if (uninstall.status !== 0) {
|
|
12475
|
-
throw new SetupError(`
|
|
12505
|
+
throw new SetupError(`helm uninstall failed — the ${K8S_RELEASE} release is still running and your env files were left in place.`, [
|
|
12476
12506
|
`retry: ${theme.command(`helm uninstall ${K8S_RELEASE} --kube-context ${shq2(install.context)} -n ${K8S_NAMESPACE}`)}`,
|
|
12477
12507
|
`check the release: ${theme.command(`helm status ${K8S_RELEASE} --kube-context ${shq2(install.context)} -n ${K8S_NAMESPACE}`)}`
|
|
12478
12508
|
]);
|
|
12479
12509
|
}
|
|
12480
12510
|
log2.step(`Uninstalled ${K8S_RELEASE}`);
|
|
12481
12511
|
}
|
|
12512
|
+
if (install?.kind === "compose") {
|
|
12513
|
+
const backup = archiveFile(path8.join(install.dir, ".env"));
|
|
12514
|
+
if (backup)
|
|
12515
|
+
log2.step(`Archived ${backup}`);
|
|
12516
|
+
} else {
|
|
12517
|
+
for (const target of ["sim", "realtime", "db", "root"]) {
|
|
12518
|
+
const backup = archiveEnvFile(target);
|
|
12519
|
+
if (backup)
|
|
12520
|
+
log2.step(`Archived ${backup}`);
|
|
12521
|
+
}
|
|
12522
|
+
}
|
|
12482
12523
|
note2(`start fresh with ${theme.command("npx sim-setup")}`, "Reset complete");
|
|
12483
12524
|
}
|
|
12484
12525
|
async function status() {
|
|
@@ -12905,7 +12946,7 @@ var init_compose = __esm(() => {
|
|
|
12905
12946
|
// src/db.ts
|
|
12906
12947
|
import { spawnSync as spawnSync10 } from "node:child_process";
|
|
12907
12948
|
function buildDsn(password, hostPort) {
|
|
12908
|
-
return `postgresql://postgres:${encodeURIComponent(password)}
|
|
12949
|
+
return `postgresql://postgres:${encodeURIComponent(password)}@${LOOPBACK_HOST}:${hostPort}/simstudio`;
|
|
12909
12950
|
}
|
|
12910
12951
|
function docker(args) {
|
|
12911
12952
|
const result = spawnSync10("docker", args, { encoding: "utf8" });
|
|
@@ -13084,7 +13125,7 @@ async function startManagedContainer(detection) {
|
|
|
13084
13125
|
"-e",
|
|
13085
13126
|
"POSTGRES_DB=simstudio",
|
|
13086
13127
|
"-p",
|
|
13087
|
-
`${hostPort}:5432`,
|
|
13128
|
+
`${LOOPBACK_HOST}:${hostPort}:5432`,
|
|
13088
13129
|
"pgvector/pgvector:pg17"
|
|
13089
13130
|
]);
|
|
13090
13131
|
const spin = spinner2();
|
|
@@ -13172,7 +13213,7 @@ function managedRedisUrl() {
|
|
|
13172
13213
|
return null;
|
|
13173
13214
|
const port = result.stdout.trim().split(`
|
|
13174
13215
|
`)[0]?.split(":").pop();
|
|
13175
|
-
return port ? `redis
|
|
13216
|
+
return port ? `redis://${LOOPBACK_HOST}:${port}` : null;
|
|
13176
13217
|
}
|
|
13177
13218
|
async function pingWithSpinner(url, label) {
|
|
13178
13219
|
const spin = spinner2();
|
|
@@ -13183,7 +13224,7 @@ async function pingWithSpinner(url, label) {
|
|
|
13183
13224
|
}
|
|
13184
13225
|
async function startManagedRedis(detection) {
|
|
13185
13226
|
const hostPort = detection.redisPortOpen ? 6380 : 6379;
|
|
13186
|
-
const url = `redis
|
|
13227
|
+
const url = `redis://${LOOPBACK_HOST}:${hostPort}`;
|
|
13187
13228
|
spawnSync11("docker", ["rm", "-f", REDIS_CONTAINER], { stdio: "ignore" });
|
|
13188
13229
|
docker([
|
|
13189
13230
|
"run",
|
|
@@ -13193,7 +13234,7 @@ async function startManagedRedis(detection) {
|
|
|
13193
13234
|
"--label",
|
|
13194
13235
|
"managed-by=sim-setup",
|
|
13195
13236
|
"-p",
|
|
13196
|
-
`${hostPort}:6379`,
|
|
13237
|
+
`${LOOPBACK_HOST}:${hostPort}:6379`,
|
|
13197
13238
|
"redis:7-alpine"
|
|
13198
13239
|
]);
|
|
13199
13240
|
const spin = spinner2();
|
|
@@ -13340,6 +13381,10 @@ async function promptRedis(detection, existing) {
|
|
|
13340
13381
|
return resolveRedis(detection, existing);
|
|
13341
13382
|
}
|
|
13342
13383
|
async function runDevMode(detection, quick) {
|
|
13384
|
+
const exposed = exposedManagedContainers(detection);
|
|
13385
|
+
if (exposed.length > 0) {
|
|
13386
|
+
log2.warn(`${exposed.join(" and ")} ${exposed.length > 1 ? "publish their ports" : "publishes its port"} on every network interface (created by an earlier sim-setup). To keep ${exposed.length > 1 ? "them" : "it"} on ${LOOPBACK_HOST}, stop the app, run ${theme.command("npx sim-setup down")} (data is kept), then re-run ${theme.command("npx sim-setup")}.`);
|
|
13387
|
+
}
|
|
13343
13388
|
const sim = readEnvFile("sim");
|
|
13344
13389
|
const dsn = await resolveDatabase(detection, sim.vars.get("DATABASE_URL"));
|
|
13345
13390
|
const secrets = collectSecrets(sim);
|
|
@@ -13432,6 +13477,7 @@ var init_dev = __esm(() => {
|
|
|
13432
13477
|
init_capability_config();
|
|
13433
13478
|
init_capability_setup();
|
|
13434
13479
|
init_db();
|
|
13480
|
+
init_detect();
|
|
13435
13481
|
init_env_files();
|
|
13436
13482
|
init_errors2();
|
|
13437
13483
|
init_probes();
|