stim 1.8.0 → 1.10.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/README.md +23 -155
- package/dist/{android-DWssqHQ8.mjs → android-787HhP5w.mjs} +168 -39
- package/dist/{android-BRgBYzU0.mjs → android-DBkeHwpm.mjs} +250 -200
- package/dist/{android-DeYdjjBP.mjs → android-DPov-fv2.mjs} +2 -2
- package/dist/{android-cas-SWIjzeuL.mjs → android-cas-CITmIeWY.mjs} +22 -14
- package/dist/android-cas-compiler.mjs +2 -2
- package/dist/app-install-CrJ6t_bv.mjs +819 -0
- package/dist/budget-BP4jZZL4.mjs +620 -0
- package/dist/build-progress-BXx-ZBe4.mjs +512 -0
- package/dist/{cache-manifest-CYJi8-Hx.mjs → cache-manifest-Pubfp8wV.mjs} +4 -4
- package/dist/cache-manifest.mjs +1 -1
- package/dist/cli.mjs +22 -19
- package/dist/collector-run.d.mts +7 -1
- package/dist/collector-run.mjs +10 -9
- package/dist/{command-output-B3ycpsYv.mjs → command-output-D5z2_bcF.mjs} +11 -2
- package/dist/{config-B7iyKWkL.mjs → config-BEq0Qw_a.mjs} +134 -121
- package/dist/{dependency-state-D0M7oKA7.mjs → dependency-state-r9UesA9a.mjs} +2 -2
- package/dist/{deps-oCXVNEqQ.mjs → deps-DP4eWqea.mjs} +8 -5
- package/dist/{detached-entry-Bpo6ZY_I.mjs → detached-entry-DJHoca49.mjs} +1 -1
- package/dist/{device-BUoZyMoR.mjs → dev-client-92U593KT.mjs} +1090 -660
- package/dist/{device-RdujjHLB.mjs → device-DhTZe7L4.mjs} +13 -20
- package/dist/{build-lock-CgtsB6TV.mjs → device-lease-CbEaIk7b.mjs} +481 -27
- package/dist/{device-pool-BxRwdufO.mjs → device-pool-Di8Q-9Ro.mjs} +7 -7
- package/dist/{device-remote-ByN8P6CB.mjs → device-remote-Dy1jGj3U.mjs} +645 -119
- package/dist/{doctor-BMt156qe.mjs → doctor-B-inAJmt.mjs} +137 -113
- package/dist/{error-diagnostics-D1Kaf-eT.mjs → error-diagnostics-xxWKNO3-.mjs} +22 -17
- package/dist/exec-DK8KaVHK.mjs +133 -0
- package/dist/{gc-v2YcoJvm.mjs → gc-ChPFZMRC.mjs} +836 -813
- package/dist/{guide-BTAlD1_y.mjs → guide-DwmaD_Wa.mjs} +953 -209
- package/dist/guide-status-CWvti2Lg.mjs +125 -0
- package/dist/idle-DpRLp5lj.mjs +157 -0
- package/dist/{build-slots-C-oAHRT1.mjs → in-use-CjUluqIX.mjs} +102 -8
- package/dist/{ios-BcCiI4TS.mjs → ios-B2Fpqvlb.mjs} +60 -71
- package/dist/{ios-BP04pY5f.mjs → ios-Dd-hYJBh.mjs} +241 -234
- package/dist/{ios-device-CFXA46ez.mjs → ios-device-BiOsSVzd.mjs} +3 -2
- package/dist/{ios-device-CauFJiYx.mjs → ios-device-CtRdEVjx.mjs} +149 -52
- package/dist/launch-verify-CQS_Kg-C.mjs +365 -0
- package/dist/{logs-CakdBTtm.mjs → logs-MARIy6m9.mjs} +20 -15
- package/dist/metro-BWLOJ_Wr.mjs +409 -0
- package/dist/{named-ports-DzMOlmaX.mjs → named-ports-DiTfSz6p.mjs} +4 -4
- package/dist/{ndjson-BZwI1NBv.mjs → ndjson-CDY9IkVC.mjs} +23 -43
- package/dist/{ndjson-DvHSsNU9.d.mts → ndjson-Du3j0AQ9.d.mts} +1 -0
- package/dist/{ownership-Cp52QAK1.mjs → ownership-D2xbLVoz.mjs} +2 -3
- package/dist/{teardown-BJqEzPo_.mjs → ownership-DZjdx8Gq.mjs} +664 -612
- package/dist/{ports-BIbJaKNW.mjs → ports-CLSSFOuz.mjs} +3 -3
- package/dist/{process-output-Dl5uKE03.mjs → process-output-Fpl8PYi8.mjs} +1 -1
- package/dist/{project-DDZWf_16.mjs → project-BXZzOABt.mjs} +8 -3
- package/dist/{reload-BdypPbjM.mjs → reload-DoETJ3rl.mjs} +11 -13
- package/dist/{server-bare-BQkyxa_b.mjs → server-bare-DVbb7kXH.mjs} +2 -2
- package/dist/{server-expo-BVAA1OqJ.mjs → server-expo-BvOCeakp.mjs} +8 -7
- package/dist/server-expo-DBVTdult.mjs +2 -0
- package/dist/{settings-BXXorVM2.mjs → settings-DOugPlPz.mjs} +59 -159
- package/dist/settings-EWYNwe72.mjs +378 -0
- package/dist/settings.schema.json +1064 -0
- package/dist/simslim-Ca3487H6.mjs +436 -0
- package/dist/{slot-launch-ZUUe0TQP.mjs → slot-launch-C5cg0fmk.mjs} +4 -4
- package/dist/spawn-claims-CUleC2cM.mjs +49 -0
- package/dist/{start-CmxtOKjU.mjs → start-F9gv5dcC.mjs} +159 -114
- package/dist/start-VoFsPSes.mjs +2 -0
- package/dist/{state-DZobzxLW.mjs → state-WGdIbi_d.mjs} +5 -3
- package/dist/{stats-BYcZ6n1h.mjs → stats-BAgJaLA4.mjs} +66 -5
- package/dist/{stats-CLg5RuDS.mjs → stats-DBYJ5bxL.mjs} +4 -4
- package/dist/status-DLCD-o3s.mjs +764 -0
- package/dist/status-Dr4fRkym.mjs +216 -0
- package/dist/{guide-status-Craq9z0t.mjs → stim-installations-CINXy_su.mjs} +3 -122
- package/dist/{stop-C8JW6kKp.mjs → stop-Dj4pfmyv.mjs} +111 -31
- package/dist/{stop-B1kOpYei.mjs → stop-ZvOeTmKb.mjs} +2 -2
- package/dist/supervisor-run.d.mts +11 -2
- package/dist/supervisor-run.mjs +228 -42
- package/dist/{workspace-process-lock-BYfZz_S-.mjs → workspace-process-lock-BXA96myD.mjs} +14 -9
- package/dist/workspaces-BTUyFfkv.mjs +1003 -0
- package/dist/worktree-4aZg2NnI.mjs +2 -0
- package/dist/{worktree-CFLA-6MX.mjs → worktree-BMS7GeqB.mjs} +523 -61
- package/dist/{worktree-FG_ZKKdb.mjs → worktree-BlizKDpZ.mjs} +200 -54
- package/dist/{xcode-B6YaWeg0.mjs → xcode-B2tBkf0m.mjs} +66 -57
- package/package.json +6 -6
- package/skill/SKILL.md +2 -0
- package/dist/app-install-BDbsSgCl.mjs +0 -1175
- package/dist/dev-client-BmT-ioFI.mjs +0 -797
- package/dist/device-lease-Ffz_M5t0.mjs +0 -359
- package/dist/exec-B29XNuhP.mjs +0 -77
- package/dist/logs-query-BGL-Pl12.mjs +0 -290
- package/dist/metro-C7bcJ0uo.mjs +0 -233
- package/dist/ownership-wolE-0Do.mjs +0 -470
- package/dist/public-http-probe-CyMDrQ3c.mjs +0 -61
- package/dist/reclaim-KJ-0uWEF.mjs +0 -361
- package/dist/server-expo-YDDG3eP7.mjs +0 -2
- package/dist/spawn-entry-nCE6m770.mjs +0 -14
- package/dist/status-DdkLki47.mjs +0 -426
- package/dist/workspace-state-BT5E3SA2.mjs +0 -146
- package/dist/{metro-store-CDDZHtPl.mjs → metro-store-DzeWkfqW.mjs} +1 -1
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import { E as writeConfigSetting, T as withConfigLock$1, d as getConfigPath$1, g as loadConfig$1, m as getRepoSettings, p as getProjectSettings } from "./config-BEq0Qw_a.mjs";
|
|
2
|
+
import { s as gitCommonDir, y as repoRoot } from "./worktree-BlizKDpZ.mjs";
|
|
3
|
+
import { o as findProjectRoot, t as NO_PROJECT_REFUSAL } from "./project-BXZzOABt.mjs";
|
|
4
|
+
import { D as readCommittedSettings, L as unknownSettingKeys } from "./settings-DOugPlPz.mjs";
|
|
5
|
+
import { existsSync, readFileSync, renameSync, unlinkSync, writeFileSync } from "node:fs";
|
|
6
|
+
import { SETTINGS, SETTING_SCOPES, coerceSettingText, isJsonObject, isSensitiveReference, settingDefinition, settingValueError } from "@stim-cli/core/state";
|
|
7
|
+
import { join } from "node:path";
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
//#region src/commands/settings.ts
|
|
10
|
+
const MASK = "********";
|
|
11
|
+
const PRECEDENCE = [
|
|
12
|
+
"workspace",
|
|
13
|
+
"repo",
|
|
14
|
+
"committed",
|
|
15
|
+
"machine"
|
|
16
|
+
];
|
|
17
|
+
var Refusal = class extends Error {
|
|
18
|
+
code;
|
|
19
|
+
remedy;
|
|
20
|
+
constructor(code, message, remedy) {
|
|
21
|
+
super(message);
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.remedy = remedy;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
function readContext(env) {
|
|
27
|
+
const projectPath = findProjectRoot(process.cwd());
|
|
28
|
+
const start = projectPath ?? process.cwd();
|
|
29
|
+
const common = gitCommonDir(start);
|
|
30
|
+
return {
|
|
31
|
+
projectPath,
|
|
32
|
+
gitCommonDir: common,
|
|
33
|
+
repoRoot: common ? repoRoot(start) ?? projectPath : null,
|
|
34
|
+
machine: loadConfig$1(),
|
|
35
|
+
env
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function valueAt(settings, key) {
|
|
39
|
+
let node = settings;
|
|
40
|
+
for (const segment of key.split(".")) {
|
|
41
|
+
if (!isJsonObject(node)) return void 0;
|
|
42
|
+
node = node[segment];
|
|
43
|
+
}
|
|
44
|
+
return node;
|
|
45
|
+
}
|
|
46
|
+
function committedDirectory(context, setting) {
|
|
47
|
+
return setting?.committedAt === "repository" ? repositoryDirectory(context) : appDirectory(context);
|
|
48
|
+
}
|
|
49
|
+
function repositoryDirectory(context) {
|
|
50
|
+
return context.repoRoot ?? context.projectPath;
|
|
51
|
+
}
|
|
52
|
+
function appDirectory(context) {
|
|
53
|
+
return context.projectPath ?? context.repoRoot;
|
|
54
|
+
}
|
|
55
|
+
function layerFile(context, scope, setting) {
|
|
56
|
+
const machineFile = getConfigPath$1();
|
|
57
|
+
if (scope === "machine") return machineFile;
|
|
58
|
+
if (scope === "workspace") return context.projectPath ? `${machineFile} (projects["${context.projectPath}"].settings)` : null;
|
|
59
|
+
if (scope === "repo") return context.gitCommonDir ? `${machineFile} (repos["${context.gitCommonDir}"].settings)` : null;
|
|
60
|
+
const directory = committedDirectory(context, setting);
|
|
61
|
+
return directory ? join(directory, ".stim.json") : null;
|
|
62
|
+
}
|
|
63
|
+
function layerSettings(context, scope, setting) {
|
|
64
|
+
if (scope === "machine") return context.machine ?? {};
|
|
65
|
+
if (scope === "workspace") return context.projectPath ? getProjectSettings(context.projectPath) : {};
|
|
66
|
+
if (scope === "repo") return context.gitCommonDir ? getRepoSettings(context.gitCommonDir) : {};
|
|
67
|
+
return readCommittedSettings(committedDirectory(context, setting));
|
|
68
|
+
}
|
|
69
|
+
function masked(setting, value) {
|
|
70
|
+
return setting.sensitive && value !== void 0 && value !== null ? MASK : value;
|
|
71
|
+
}
|
|
72
|
+
function settingEntry(context, setting) {
|
|
73
|
+
const layers = {};
|
|
74
|
+
for (const scope of PRECEDENCE) {
|
|
75
|
+
if (!setting.scopes.includes(scope) || layerFile(context, scope, setting) === null) continue;
|
|
76
|
+
const value = valueAt(layerSettings(context, scope, setting), setting.key);
|
|
77
|
+
if (value !== void 0) layers[scope] = masked(setting, value);
|
|
78
|
+
}
|
|
79
|
+
const envValue = setting.env ? context.env[setting.env] : void 0;
|
|
80
|
+
const env = setting.env && envValue ? {
|
|
81
|
+
name: setting.env,
|
|
82
|
+
value: String(masked(setting, envValue))
|
|
83
|
+
} : void 0;
|
|
84
|
+
const scopedHome = !env && setting.scopedHomeValue !== void 0 && context.env.STIM_HOME;
|
|
85
|
+
const winner = PRECEDENCE.find((scope) => scope in layers);
|
|
86
|
+
let value = null;
|
|
87
|
+
let origin = null;
|
|
88
|
+
if (env) {
|
|
89
|
+
value = masked(setting, envSettingValue(setting, envValue));
|
|
90
|
+
origin = "env";
|
|
91
|
+
} else if (scopedHome) {
|
|
92
|
+
value = setting.scopedHomeValue;
|
|
93
|
+
origin = "env";
|
|
94
|
+
} else if (winner) {
|
|
95
|
+
value = layers[winner];
|
|
96
|
+
origin = winner;
|
|
97
|
+
} else if (setting.default !== void 0) {
|
|
98
|
+
value = setting.default;
|
|
99
|
+
origin = "default";
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
key: setting.key,
|
|
103
|
+
value,
|
|
104
|
+
origin,
|
|
105
|
+
layers,
|
|
106
|
+
...env ? { env } : scopedHome ? { env: {
|
|
107
|
+
name: "STIM_HOME",
|
|
108
|
+
value: context.env.STIM_HOME
|
|
109
|
+
} } : {},
|
|
110
|
+
...setting.sensitive ? { sensitive: true } : {}
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
function unknownEntries(context) {
|
|
114
|
+
const sources = [
|
|
115
|
+
{
|
|
116
|
+
scope: "machine",
|
|
117
|
+
file: layerFile(context, "machine", null),
|
|
118
|
+
settings: { optimizations: context.machine?.optimizations }
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
scope: "workspace",
|
|
122
|
+
file: layerFile(context, "workspace", null),
|
|
123
|
+
settings: layerSettings(context, "workspace", null)
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
scope: "repo",
|
|
127
|
+
file: layerFile(context, "repo", null),
|
|
128
|
+
settings: layerSettings(context, "repo", null)
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
scope: "committed",
|
|
132
|
+
file: layerFile(context, "committed", null),
|
|
133
|
+
settings: layerSettings(context, "committed", null)
|
|
134
|
+
}
|
|
135
|
+
];
|
|
136
|
+
const repository = repositoryDirectory(context);
|
|
137
|
+
if (repository && repository !== appDirectory(context)) sources.push({
|
|
138
|
+
scope: "committed",
|
|
139
|
+
file: join(repository, ".stim.json"),
|
|
140
|
+
settings: readCommittedSettings(repository)
|
|
141
|
+
});
|
|
142
|
+
return sources.flatMap(({ scope, file, settings }) => file === null ? [] : unknownSettingKeys(settings).map((key) => ({
|
|
143
|
+
key,
|
|
144
|
+
scope,
|
|
145
|
+
file,
|
|
146
|
+
value: valueAt(settings, key)
|
|
147
|
+
})));
|
|
148
|
+
}
|
|
149
|
+
function settingsPayload(context) {
|
|
150
|
+
const files = {};
|
|
151
|
+
for (const scope of SETTING_SCOPES) {
|
|
152
|
+
const file = layerFile(context, scope, null);
|
|
153
|
+
if (file) files[scope] = file;
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
project: context.projectPath,
|
|
157
|
+
files,
|
|
158
|
+
settings: SETTINGS.map((setting) => settingEntry(context, setting)),
|
|
159
|
+
unknown: unknownEntries(context)
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function requireSetting(key) {
|
|
163
|
+
const setting = settingDefinition(key);
|
|
164
|
+
if (setting) return setting;
|
|
165
|
+
throw new Refusal("STIM_BAD_ARG", `${JSON.stringify(key)} is not a Stim setting.`, "Run `stim settings` to list every setting, or `stim guide settings` for what each one does.");
|
|
166
|
+
}
|
|
167
|
+
function readScope(raw, setting) {
|
|
168
|
+
if (raw === void 0) {
|
|
169
|
+
if (setting.scopes.length === 1) return setting.scopes[0];
|
|
170
|
+
throw new Refusal("STIM_BAD_ARG", `${setting.key} can live in more than one layer, so the command needs --scope.`, `Pass --scope ${setting.scopes.join("|")}.`);
|
|
171
|
+
}
|
|
172
|
+
if (!SETTING_SCOPES.includes(raw)) throw new Refusal("STIM_BAD_ARG", `--scope takes ${SETTING_SCOPES.join(", ")}, not ${JSON.stringify(raw)}.`, null);
|
|
173
|
+
const scope = raw;
|
|
174
|
+
if (!setting.scopes.includes(scope)) throw new Refusal("STIM_BAD_ARG", `${setting.key} is not read from the ${scope} layer.`, `Pass --scope ${setting.scopes.join("|")}.`);
|
|
175
|
+
return scope;
|
|
176
|
+
}
|
|
177
|
+
function requireLayer(context, scope, setting) {
|
|
178
|
+
const file = layerFile(context, scope, setting);
|
|
179
|
+
if (file) return file;
|
|
180
|
+
if (scope === "repo") throw new Refusal("STIM_BAD_ARG", "The repo layer is keyed by a Git repository, and this directory is not inside one.", "Run this from inside the repository, or pick another --scope.");
|
|
181
|
+
throw new Refusal(NO_PROJECT_REFUSAL.code, NO_PROJECT_REFUSAL.message, NO_PROJECT_REFUSAL.remedy);
|
|
182
|
+
}
|
|
183
|
+
function example(setting) {
|
|
184
|
+
switch (setting.type.kind) {
|
|
185
|
+
case "boolean": return "false";
|
|
186
|
+
case "number": return String(setting.default ?? setting.type.minimum ?? 1);
|
|
187
|
+
case "strings": return `'["node_modules"]'`;
|
|
188
|
+
case "object": return `'{"key": "value"}'`;
|
|
189
|
+
case "choice": return setting.type.choices[0];
|
|
190
|
+
default: return "<value>";
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
function parseSettingValue(setting, raw) {
|
|
194
|
+
const invalid = (expected) => new Refusal("STIM_BAD_ARG", `Invalid ${setting.key} value ${JSON.stringify(raw)}. Expected ${expected}.`, `For example: stim settings set ${setting.key} ${example(setting)}${setting.scopes.length > 1 ? ` --scope ${setting.scopes[0]}` : ""}`);
|
|
195
|
+
const kind = setting.type.kind;
|
|
196
|
+
const value = coerceSettingText(setting, raw);
|
|
197
|
+
const error = settingValueError(setting, value);
|
|
198
|
+
if (error) throw invalid(kind === "strings" || kind === "object" ? `${error}, written as JSON` : error);
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
function envSettingValue(setting, raw) {
|
|
202
|
+
const value = coerceSettingText(setting, raw);
|
|
203
|
+
const error = settingValueError(setting, value);
|
|
204
|
+
if (error) throw new Refusal("STIM_BAD_ARG", `Invalid ${setting.env} value ${JSON.stringify(raw)}. Expected ${error}.`, `Fix the environment variable, or unset it and run \`stim settings set ${setting.key} ${example(setting)}\`.`);
|
|
205
|
+
return value;
|
|
206
|
+
}
|
|
207
|
+
function committedTarget(context, setting) {
|
|
208
|
+
const directory = committedDirectory(context, setting);
|
|
209
|
+
if (!directory) throw new Refusal(NO_PROJECT_REFUSAL.code, NO_PROJECT_REFUSAL.message, NO_PROJECT_REFUSAL.remedy);
|
|
210
|
+
return join(directory, ".stim.json");
|
|
211
|
+
}
|
|
212
|
+
function writeCommitted(file, key, value) {
|
|
213
|
+
return withConfigLock$1(() => {
|
|
214
|
+
const exists = existsSync(file);
|
|
215
|
+
const text = exists ? readFileSync(file, "utf-8") : "";
|
|
216
|
+
let parsed = {};
|
|
217
|
+
if (exists && text.trim() !== "") try {
|
|
218
|
+
parsed = JSON.parse(text);
|
|
219
|
+
} catch (error) {
|
|
220
|
+
throw new Refusal("STIM_BAD_ARG", `${file} is not valid JSON: ${error.message}`, `Repair ${file}, then run the command again.`);
|
|
221
|
+
}
|
|
222
|
+
if (!isJsonObject(parsed)) throw new Refusal("STIM_BAD_ARG", `${file} is not a JSON object.`, `Repair ${file}, then run the command again.`);
|
|
223
|
+
const parts = key.split(".");
|
|
224
|
+
const chain = [parsed];
|
|
225
|
+
for (const part of parts.slice(0, -1)) {
|
|
226
|
+
const node = chain.at(-1);
|
|
227
|
+
if (!isJsonObject(node[part])) {
|
|
228
|
+
if (value === void 0) return false;
|
|
229
|
+
node[part] = {};
|
|
230
|
+
}
|
|
231
|
+
chain.push(node[part]);
|
|
232
|
+
}
|
|
233
|
+
const leaf = parts.at(-1);
|
|
234
|
+
const parent = chain.at(-1);
|
|
235
|
+
if (value === void 0) {
|
|
236
|
+
if (!(leaf in parent)) return false;
|
|
237
|
+
delete parent[leaf];
|
|
238
|
+
for (let index = chain.length - 1; index > 0; index--) {
|
|
239
|
+
if (Object.keys(chain[index]).length > 0) break;
|
|
240
|
+
delete chain[index - 1][parts[index - 1]];
|
|
241
|
+
}
|
|
242
|
+
} else parent[leaf] = value;
|
|
243
|
+
const indent = /\n([ \t]+)"/.exec(text)?.[1] ?? 2;
|
|
244
|
+
const tmp = `${file}.${process.pid}.${Math.random().toString(36).slice(2)}.tmp`;
|
|
245
|
+
writeFileSync(tmp, `${JSON.stringify(parsed, null, indent)}\n`);
|
|
246
|
+
try {
|
|
247
|
+
renameSync(tmp, file);
|
|
248
|
+
} catch (error) {
|
|
249
|
+
try {
|
|
250
|
+
unlinkSync(tmp);
|
|
251
|
+
} catch {}
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
function writeSetting(context, setting, scope, value) {
|
|
258
|
+
if (scope === "committed") return writeCommitted(committedTarget(context, setting), setting.key, value);
|
|
259
|
+
if (scope === "machine") return writeConfigSetting({ scope }, setting.key, value);
|
|
260
|
+
if (scope === "workspace") return writeConfigSetting({
|
|
261
|
+
scope,
|
|
262
|
+
projectPath: context.projectPath
|
|
263
|
+
}, setting.key, value);
|
|
264
|
+
return writeConfigSetting({
|
|
265
|
+
scope,
|
|
266
|
+
gitCommonDir: context.gitCommonDir
|
|
267
|
+
}, setting.key, value);
|
|
268
|
+
}
|
|
269
|
+
function formatValue(value) {
|
|
270
|
+
return typeof value === "string" ? value : JSON.stringify(value);
|
|
271
|
+
}
|
|
272
|
+
const CONSOLE = {
|
|
273
|
+
out: (line) => console.log(line),
|
|
274
|
+
note: (line) => console.error(line)
|
|
275
|
+
};
|
|
276
|
+
function run(json, io, action) {
|
|
277
|
+
try {
|
|
278
|
+
action();
|
|
279
|
+
} catch (error) {
|
|
280
|
+
const code = error.code;
|
|
281
|
+
if (!(error instanceof Refusal) && !(typeof code === "string" && code.startsWith("STIM_"))) throw error;
|
|
282
|
+
const failure = {
|
|
283
|
+
code,
|
|
284
|
+
message: error.message,
|
|
285
|
+
remedy: error instanceof Refusal ? error.remedy : null
|
|
286
|
+
};
|
|
287
|
+
io.note(chalk.red(`${failure.code}: ${failure.message}`));
|
|
288
|
+
if (failure.remedy) io.note(chalk.dim(failure.remedy));
|
|
289
|
+
if (json) io.out(JSON.stringify(failure));
|
|
290
|
+
process.exitCode = 1;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
function wantsJson(opts, command) {
|
|
294
|
+
return Boolean(opts.json ?? command.parent?.opts().json);
|
|
295
|
+
}
|
|
296
|
+
function registerSettings(program, io = CONSOLE, env = process.env) {
|
|
297
|
+
const settings = program.command("settings").description("Show every Stim setting with its effective value and layer, or change one").option("--json", "print every setting, its origin, and each layer value as JSON").action((opts) => run(Boolean(opts.json), io, () => {
|
|
298
|
+
const payload = settingsPayload(readContext(env));
|
|
299
|
+
if (opts.json) {
|
|
300
|
+
io.out(JSON.stringify(payload));
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
303
|
+
const width = Math.max(...payload.settings.map((entry) => entry.key.length));
|
|
304
|
+
for (const entry of payload.settings) {
|
|
305
|
+
const origin = entry.origin ?? "unset";
|
|
306
|
+
const shown = entry.origin === null ? "" : formatValue(entry.value);
|
|
307
|
+
io.out(`${entry.key.padEnd(width)} ${shown}${shown ? " " : ""}${chalk.dim(`(${origin})`)}`);
|
|
308
|
+
}
|
|
309
|
+
for (const entry of payload.unknown) io.note(chalk.yellow(`Warning: ${entry.key} in ${entry.file} is not read by Stim.`));
|
|
310
|
+
}));
|
|
311
|
+
settings.command("get <key>").description("Print the effective value of a setting, or its value in one layer").option("--scope <scope>", `read one layer: ${SETTING_SCOPES.join(", ")}`).option("--json", "print the setting entry as JSON").action((key, opts, command) => run(wantsJson(opts, command), io, () => {
|
|
312
|
+
const setting = requireSetting(key);
|
|
313
|
+
const scope = opts.scope === void 0 ? null : readScope(opts.scope, setting);
|
|
314
|
+
const context = readContext(env);
|
|
315
|
+
const entry = settingEntry(context, setting);
|
|
316
|
+
const value = scope ? entry.layers[scope] ?? null : entry.value;
|
|
317
|
+
if (wantsJson(opts, command)) {
|
|
318
|
+
io.out(JSON.stringify(scope ? {
|
|
319
|
+
key,
|
|
320
|
+
scope,
|
|
321
|
+
file: layerFile(context, scope, setting),
|
|
322
|
+
value
|
|
323
|
+
} : entry));
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
if (value !== null) io.out(formatValue(value));
|
|
327
|
+
}));
|
|
328
|
+
settings.command("set <key> <value>").description("Write a setting to one layer").option("--scope <scope>", `the layer to write: ${SETTING_SCOPES.join(", ")}`).option("--json", "print the written setting as JSON").action((key, raw, opts, command) => run(wantsJson(opts, command), io, () => {
|
|
329
|
+
const setting = requireSetting(key);
|
|
330
|
+
const scope = readScope(opts.scope, setting);
|
|
331
|
+
const value = parseSettingValue(setting, raw);
|
|
332
|
+
if (setting.sensitive && scope === "committed" && !isSensitiveReference(value)) throw new Refusal("STIM_BAD_ARG", `${key} is sensitive, so a committed .stim.json takes only an env: or file: reference, never the secret.`, `Set the secret with --scope workspace or --scope repo, or commit a reference such as env:MY_KEYSTORE_PASSWORD.`);
|
|
333
|
+
const context = readContext(env);
|
|
334
|
+
const file = requireLayer(context, scope, setting);
|
|
335
|
+
const changed = writeSetting(context, setting, scope, value);
|
|
336
|
+
report(io, wantsJson(opts, command), {
|
|
337
|
+
key,
|
|
338
|
+
scope,
|
|
339
|
+
file,
|
|
340
|
+
changed
|
|
341
|
+
}, setting, readContext(env), "set");
|
|
342
|
+
}));
|
|
343
|
+
settings.command("unset <key>").description("Remove a setting from one layer").option("--scope <scope>", `the layer to clear: ${SETTING_SCOPES.join(", ")}`).option("--json", "print the setting after removal as JSON").action((key, opts, command) => run(wantsJson(opts, command), io, () => {
|
|
344
|
+
const setting = requireSetting(key);
|
|
345
|
+
const scope = readScope(opts.scope, setting);
|
|
346
|
+
const context = readContext(env);
|
|
347
|
+
const file = requireLayer(context, scope, setting);
|
|
348
|
+
const changed = writeSetting(context, setting, scope, void 0);
|
|
349
|
+
report(io, wantsJson(opts, command), {
|
|
350
|
+
key,
|
|
351
|
+
scope,
|
|
352
|
+
file,
|
|
353
|
+
changed
|
|
354
|
+
}, setting, readContext(env), "unset");
|
|
355
|
+
}));
|
|
356
|
+
}
|
|
357
|
+
function report(io, json, write, setting, context, verb) {
|
|
358
|
+
const entry = settingEntry(context, setting);
|
|
359
|
+
if (json) {
|
|
360
|
+
io.out(JSON.stringify({
|
|
361
|
+
...write,
|
|
362
|
+
setting: entry
|
|
363
|
+
}));
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
const effective = entry.origin === null ? "unset" : `${formatValue(entry.value)} (${entry.origin})`;
|
|
367
|
+
if (!write.changed) {
|
|
368
|
+
io.out(`${write.key} was not set in ${write.file}; effective value: ${effective}`);
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const shown = verb === "set" ? ` = ${formatValue(entry.layers[write.scope])}` : "";
|
|
372
|
+
io.out(`${verb} ${write.key}${shown} in ${write.file}; effective value: ${effective}`);
|
|
373
|
+
}
|
|
374
|
+
function settingsCommand(program) {
|
|
375
|
+
registerSettings(program);
|
|
376
|
+
}
|
|
377
|
+
//#endregion
|
|
378
|
+
export { settingsCommand as default, registerSettings };
|