@kaynooo/cli-stack 0.7.2 → 0.8.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/README.md +1 -18
- package/dist/cli.js +310 -574
- package/package.json +7 -7
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# stack
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A stable host port per service name for Claude Code, the same on every machine.
|
|
4
4
|
|
|
5
5
|
```sh
|
|
6
6
|
bun install -g @kaynooo/cli-stack
|
|
@@ -11,22 +11,5 @@ bun install -g @kaynooo/cli-stack
|
|
|
11
11
|
| Command | What it does |
|
|
12
12
|
| --- | --- |
|
|
13
13
|
| `stack port <name>` | prints the port the name always hashes to (32-bit FNV-1a, 1024-32767), so a service keeps the same port on every machine |
|
|
14
|
-
| `stack audit [dir]` | cross-checks `release.config.ts` in `dir` (the current directory) against the compose files it syncs |
|
|
15
14
|
|
|
16
15
|
`stack port` takes `--min` and `--max` to change the range: the default stops below 32768, where Linux starts handing out ephemeral ports, `--min` refuses anything under 1024, and `--max` goes up to 65535. The hash used to lose precision past 2^53 and the range ran to 65535, so every name now maps to a different port than before; a port already written in a compose file keeps working, only a newly picked one comes out different. When something on this machine already listens on the port it says so on stderr; the number is still printed and the exit code stays 0. `--json` prints `{name, port, listening}`.
|
|
17
|
-
|
|
18
|
-
## Audit
|
|
19
|
-
|
|
20
|
-
The checks, in the order they are reported:
|
|
21
|
-
|
|
22
|
-
- `sync` and `build`: every `deploySyncFiles` entry, `sourceDir`, `buildContext`, `dockerfile` and buildSecret `src` (a leading `~` is the home directory) exists, and a buildSecret `env` is set in the shell.
|
|
23
|
-
- `compose`: `docker compose config` succeeds on the base file and on each overlay merged over it. The base is the shortest compose file name among `deploySyncFiles`.
|
|
24
|
-
- `env`: every `${VAR}`, `${VAR:?msg}` or bare `$VAR` without a default is in `requiredServerEnv`, and every listed key is referenced; the `$${VAR}` escape and commented lines are skipped.
|
|
25
|
-
- `version`: each `versionEnv` is interpolated by a compose file, and each `*_VERSION` a compose file interpolates is declared by a release.
|
|
26
|
-
- `image`, `restart` and `post-deploy`: services the config names exist, and registry images are built by a release.
|
|
27
|
-
- `health` and `routing`: restarted services have a healthcheck, ports and traefik labels live in overlays, and `composeArgs` does not drop them.
|
|
28
|
-
- `layout`, `nuxt` and `gitignore`: bind mounts appear in the base file's header, `NUXT_*` variables match the runtime config, and `.release-logs` and `.release-worktrees` are ignored.
|
|
29
|
-
|
|
30
|
-
Exit codes: 0 no error (warnings allowed), 1 at least one error, 2 no `release.config.ts`. `--json` prints `{ root, composeFiles, findings }` where a finding is `{ level, check, message }`.
|
|
31
|
-
|
|
32
|
-
It needs docker for `docker compose config`. When the package `release.config.ts` imports `defineConfig` from is not installed, a stand-in that returns its argument is used.
|
package/dist/cli.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
#!/usr/bin/env -S bun --no-env-file --config=/dev/null
|
|
2
2
|
// @bun
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
var __esm = (fn, res, err) => () => {
|
|
4
|
+
if (fn)
|
|
5
|
+
try {
|
|
6
|
+
res = fn(fn = 0);
|
|
7
|
+
} catch (e) {
|
|
8
|
+
err = [e];
|
|
9
|
+
}
|
|
10
|
+
if (err)
|
|
11
|
+
throw err[0];
|
|
12
|
+
return res;
|
|
13
|
+
};
|
|
12
14
|
|
|
13
15
|
// ../kit/src/mode.ts
|
|
14
16
|
import process2 from "process";
|
|
15
|
-
var MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
16
|
-
var AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
17
17
|
function isSet(value) {
|
|
18
18
|
return value !== undefined && value !== "" && value !== "0" && value.toLowerCase() !== "false";
|
|
19
19
|
}
|
|
@@ -27,12 +27,13 @@ function outputMode(stream = process2.stdout, env = process2.env) {
|
|
|
27
27
|
return "terminal";
|
|
28
28
|
return isSet(env.CI) ? "ci" : "pipe";
|
|
29
29
|
}
|
|
30
|
+
var MODES, AGENT_VARIABLES;
|
|
31
|
+
var init_mode = __esm(() => {
|
|
32
|
+
MODES = new Set(["terminal", "ci", "agent", "pipe"]);
|
|
33
|
+
AGENT_VARIABLES = ["CLAUDECODE", "AI_AGENT"];
|
|
34
|
+
});
|
|
30
35
|
|
|
31
|
-
//
|
|
32
|
-
import process6 from "process";
|
|
33
|
-
|
|
34
|
-
// ../../node_modules/.bun/@kaynooo+utils@3.0.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
35
|
-
var G = /^[a-f0-9]+$/i;
|
|
36
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/chunk-x450vn3m.js
|
|
36
37
|
function b(r) {
|
|
37
38
|
let e = r.startsWith("#") ? r.slice(1) : r;
|
|
38
39
|
if (!G.test(e))
|
|
@@ -43,11 +44,6 @@ function b(r) {
|
|
|
43
44
|
throw Error(`Invalid hex color length: ${e.length}`);
|
|
44
45
|
return [Number.parseInt(e.slice(0, 2), 16), Number.parseInt(e.slice(2, 4), 16), Number.parseInt(e.slice(4, 6), 16)];
|
|
45
46
|
}
|
|
46
|
-
var B = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
47
|
-
let [l, n, c] = b(r);
|
|
48
|
-
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
49
|
-
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
50
|
-
var h = new Set(["", "1", "2", "3", "true"]);
|
|
51
47
|
function C(r, e = globalThis.process?.env ?? {}) {
|
|
52
48
|
if (e.FORCE_COLOR !== undefined)
|
|
53
49
|
return h.has(e.FORCE_COLOR);
|
|
@@ -84,13 +80,21 @@ function f(r, e = []) {
|
|
|
84
80
|
function Fe(r = {}) {
|
|
85
81
|
return f(r);
|
|
86
82
|
}
|
|
87
|
-
var
|
|
83
|
+
var G, B, h, o;
|
|
84
|
+
var init_chunk_x450vn3m = __esm(() => {
|
|
85
|
+
G = /^[a-f0-9]+$/i;
|
|
86
|
+
B = { reset: [0, 0], bold: [1, 22], dim: [2, 22], italic: [3, 23], underline: [4, 24], inverse: [7, 27], hidden: [8, 28], strikethrough: [9, 29], black: [30, 39], red: [31, 39], green: [32, 39], yellow: [33, 39], blue: [34, 39], magenta: [35, 39], cyan: [36, 39], white: [37, 39], gray: [90, 39], grey: [90, 39], blackBright: [90, 39], redBright: [91, 39], greenBright: [92, 39], yellowBright: [93, 39], blueBright: [94, 39], magentaBright: [95, 39], cyanBright: [96, 39], whiteBright: [97, 39], bgBlack: [40, 49], bgRed: [41, 49], bgGreen: [42, 49], bgYellow: [43, 49], bgBlue: [44, 49], bgMagenta: [45, 49], bgCyan: [46, 49], bgWhite: [47, 49], bgBlackBright: [100, 49], bgRedBright: [101, 49], bgGreenBright: [102, 49], bgYellowBright: [103, 49], bgBlueBright: [104, 49], bgMagentaBright: [105, 49], bgCyanBright: [106, 49], bgWhiteBright: [107, 49], rgb: (r, e, l, n = "fg") => [`${n === "fg" ? 38 : 48};2;${r};${e};${l}`, n === "fg" ? 39 : 49], hex: (r, e = "fg") => {
|
|
87
|
+
let [l, n, c] = b(r);
|
|
88
|
+
return [`${e === "fg" ? 38 : 48};2;${l};${n};${c}`, e === "fg" ? 39 : 49];
|
|
89
|
+
}, ansi256: (r, e = "fg") => [`${e === "fg" ? 38 : 48};5;${r}`, e === "fg" ? 39 : 49] };
|
|
90
|
+
h = new Set(["", "1", "2", "3", "true"]);
|
|
91
|
+
o = Fe();
|
|
92
|
+
});
|
|
88
93
|
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
import process5 from "process";
|
|
94
|
+
// ../../node_modules/.bun/@kaynooo+utils@3.1.0+4c7ddab9986847c5/node_modules/@kaynooo/utils/dist/tools/colors.js
|
|
95
|
+
var init_colors = __esm(() => {
|
|
96
|
+
init_chunk_x450vn3m();
|
|
97
|
+
});
|
|
94
98
|
|
|
95
99
|
// ../kit/src/config.ts
|
|
96
100
|
import { existsSync } from "fs";
|
|
@@ -106,6 +110,9 @@ function findUp(names, from = process3.cwd(), stop = () => false) {
|
|
|
106
110
|
return;
|
|
107
111
|
}
|
|
108
112
|
}
|
|
113
|
+
var init_config = __esm(() => {
|
|
114
|
+
init_args();
|
|
115
|
+
});
|
|
109
116
|
|
|
110
117
|
// ../kit/src/user-config.ts
|
|
111
118
|
import { homedir } from "os";
|
|
@@ -118,36 +125,18 @@ function configBase(where = {}) {
|
|
|
118
125
|
function userConfigPath(bin, where = {}) {
|
|
119
126
|
return join2(configBase(where), "kaynooo-cli", `${bin}.json`);
|
|
120
127
|
}
|
|
128
|
+
var init_user_config = () => {};
|
|
121
129
|
|
|
122
130
|
// ../kit/src/theme.ts
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
128
|
-
bins: {},
|
|
129
|
-
gradient: ["#c084fc", "#67e8f9"]
|
|
130
|
-
};
|
|
131
|
-
var BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
132
|
-
var MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
133
|
-
var ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
134
|
-
var PRESETS = {
|
|
135
|
-
default: {},
|
|
136
|
-
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
137
|
-
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
138
|
-
ascii: { glyphs: ASCII }
|
|
139
|
-
};
|
|
140
|
-
var STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
141
|
-
var HEX = /^#[0-9a-f]{6}$/i;
|
|
142
|
-
var CONTROL = /\p{Cc}/u;
|
|
143
|
-
var MAX_FILE_BYTES = 64 * 1024;
|
|
144
|
-
var SPACES = /\s+/;
|
|
131
|
+
import { existsSync as existsSync2, readFileSync, statSync } from "fs";
|
|
132
|
+
import { homedir as homedir2 } from "os";
|
|
133
|
+
import { join as join3, resolve as resolve2 } from "path";
|
|
134
|
+
import process5 from "process";
|
|
145
135
|
function isColorSpec(spec) {
|
|
146
136
|
if (typeof spec === "number")
|
|
147
137
|
return Number.isInteger(spec) && spec >= 0 && spec <= 255;
|
|
148
138
|
return typeof spec === "string" && spec.trim() !== "" && spec.trim().split(SPACES).every((token) => STYLES.has(token) || HEX.test(token));
|
|
149
139
|
}
|
|
150
|
-
var CUBE = [0, 95, 135, 175, 215, 255];
|
|
151
140
|
function cubeLevel(channel) {
|
|
152
141
|
return CUBE.reduce((best, value, level) => Math.abs(value - channel) < Math.abs(CUBE[best] - channel) ? level : best, 0);
|
|
153
142
|
}
|
|
@@ -252,7 +241,6 @@ function applyFile(theme, file, where, warn) {
|
|
|
252
241
|
function endsWalk(home) {
|
|
253
242
|
return (dir) => dir === resolve2(home) || existsSync2(join3(dir, ".git"));
|
|
254
243
|
}
|
|
255
|
-
var warned = new Set;
|
|
256
244
|
function warnOnce(message) {
|
|
257
245
|
if (warned.has(message))
|
|
258
246
|
return;
|
|
@@ -289,8 +277,6 @@ function loadTheme({ env = process5.env, from = process5.cwd(), home = homedir2(
|
|
|
289
277
|
}
|
|
290
278
|
return { theme, sources, preset };
|
|
291
279
|
}
|
|
292
|
-
var current;
|
|
293
|
-
var currentKey = "";
|
|
294
280
|
function activeTheme() {
|
|
295
281
|
const key = `${process5.cwd()}\x00${process5.env.KIT_THEME ?? ""}\x00${process5.env.XDG_CONFIG_HOME ?? ""}`;
|
|
296
282
|
if (current === undefined || key !== currentKey) {
|
|
@@ -299,9 +285,38 @@ function activeTheme() {
|
|
|
299
285
|
}
|
|
300
286
|
return current;
|
|
301
287
|
}
|
|
288
|
+
var ENDS, DEFAULT, BRIGHT, MONO, ASCII, PRESETS, STYLES, HEX, CONTROL, MAX_FILE_BYTES, SPACES, CUBE, warned, current, currentKey = "";
|
|
289
|
+
var init_theme = __esm(() => {
|
|
290
|
+
init_config();
|
|
291
|
+
init_user_config();
|
|
292
|
+
ENDS = new Map;
|
|
293
|
+
DEFAULT = {
|
|
294
|
+
colors: { accent: "cyan", id: "yellow", path: "blue", label: "dim", value: "bold", ok: "green", warn: "yellow", problem: "red", note: "dim", plan: "magenta", passed: "green", failed: "red", running: "cyan", queued: "yellow", skipped: "dim" },
|
|
295
|
+
glyphs: { ok: "\u2713", warn: "\u25B2", problem: "\u2717", note: "\u203A", plan: "\u25C7", passed: "\u2713", failed: "\u2717", running: "\u25CF", queued: "\u25CB", skipped: "-", bar: "\u2501", rule: "\u2500", corner: "\u256D", open: "\u2022", leaf: "\xB7", guide: "\u2502" },
|
|
296
|
+
accents: ["cyan", "magenta", "green", "blue", "yellow", "redBright"],
|
|
297
|
+
bins: {},
|
|
298
|
+
gradient: ["#c084fc", "#67e8f9"]
|
|
299
|
+
};
|
|
300
|
+
BRIGHT = { accent: "cyanBright", id: "yellowBright", path: "blueBright", label: "white", value: "bold whiteBright", ok: "greenBright", warn: "yellowBright", problem: "redBright", note: "white", plan: "magentaBright", passed: "greenBright", failed: "redBright", running: "cyanBright", queued: "yellowBright", skipped: "white" };
|
|
301
|
+
MONO = { accent: "bold", id: "bold", path: "underline", label: "dim", value: "bold", ok: "bold", warn: "bold", problem: "bold", note: "dim", plan: "dim", passed: "bold", failed: "bold", running: "bold", queued: "dim", skipped: "dim" };
|
|
302
|
+
ASCII = { ok: "+", warn: "!", problem: "x", note: ">", plan: "?", passed: "+", failed: "x", running: "*", queued: "o", skipped: "-", bar: "#", rule: "-", corner: "+", open: "*", leaf: "-", guide: "|" };
|
|
303
|
+
PRESETS = {
|
|
304
|
+
default: {},
|
|
305
|
+
"high-contrast": { colors: BRIGHT, accents: ["cyanBright", "magentaBright", "greenBright", "blueBright", "yellowBright", "redBright"], gradient: ["#d8b4fe", "#a5f3fc"] },
|
|
306
|
+
mono: { colors: MONO, accents: ["bold"], gradient: undefined },
|
|
307
|
+
ascii: { glyphs: ASCII }
|
|
308
|
+
};
|
|
309
|
+
STYLES = new Set(["bold", "dim", "italic", "underline", "inverse", "strikethrough", "black", "red", "green", "yellow", "blue", "magenta", "cyan", "white", "gray", "grey", "blackBright", "redBright", "greenBright", "yellowBright", "blueBright", "magentaBright", "cyanBright", "whiteBright"]);
|
|
310
|
+
HEX = /^#[0-9a-f]{6}$/i;
|
|
311
|
+
CONTROL = /\p{Cc}/u;
|
|
312
|
+
MAX_FILE_BYTES = 64 * 1024;
|
|
313
|
+
SPACES = /\s+/;
|
|
314
|
+
CUBE = [0, 95, 135, 175, 215, 255];
|
|
315
|
+
warned = new Set;
|
|
316
|
+
});
|
|
302
317
|
|
|
303
318
|
// ../kit/src/style.ts
|
|
304
|
-
|
|
319
|
+
import process6 from "process";
|
|
305
320
|
function takesControlCodes(stream, env = process6.env) {
|
|
306
321
|
return stream.isTTY === true && env.NO_COLOR === undefined && env.NODE_DISABLE_COLORS === undefined && env.TERM !== "dumb" && outputMode(stream, env) === "terminal";
|
|
307
322
|
}
|
|
@@ -320,17 +335,24 @@ function marked(mark, text, stream, detail, env = process6.env) {
|
|
|
320
335
|
function warn(text, detail) {
|
|
321
336
|
console.error(marked("warn", text, process6.stderr, detail));
|
|
322
337
|
}
|
|
323
|
-
var STATUS_WORDS
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
338
|
+
var MARK_WORDS, STATUS_WORDS, STATUS_OF;
|
|
339
|
+
var init_style = __esm(() => {
|
|
340
|
+
init_colors();
|
|
341
|
+
init_mode();
|
|
342
|
+
init_theme();
|
|
343
|
+
MARK_WORDS = { ok: "ok:", warn: "warning:", problem: "error:", note: "note:", plan: "would:" };
|
|
344
|
+
STATUS_WORDS = {
|
|
345
|
+
passed: ["passed", "success", "succeeded", "ok"],
|
|
346
|
+
failed: ["failed", "failure", "error", "errored"],
|
|
347
|
+
running: ["running", "in_progress", "started", "holding"],
|
|
348
|
+
queued: ["queued", "waiting", "pending", "created", "blocked", "scheduled"],
|
|
349
|
+
skipped: ["skipped", "cancelled", "canceled", "manual"]
|
|
350
|
+
};
|
|
351
|
+
STATUS_OF = new Map(Object.entries(STATUS_WORDS).flatMap(([status, words]) => words.map((word) => [word, status])));
|
|
352
|
+
});
|
|
331
353
|
|
|
332
354
|
// ../kit/src/format.ts
|
|
333
|
-
|
|
355
|
+
import process7 from "process";
|
|
334
356
|
function formatSeconds(total) {
|
|
335
357
|
let rest = Math.max(0, Math.round(total));
|
|
336
358
|
const amounts = UNITS.map(([unit, size]) => {
|
|
@@ -351,21 +373,44 @@ function upTo(text, separator) {
|
|
|
351
373
|
const end = text.indexOf(separator);
|
|
352
374
|
return end === -1 ? text : text.slice(0, end);
|
|
353
375
|
}
|
|
354
|
-
var ESCAPE = String.fromCharCode(27);
|
|
355
376
|
function jsonText(value, replacer, { stream = process7.stdout, env = process7.env } = {}) {
|
|
356
377
|
return JSON.stringify(value, replacer, outputMode(stream, env) === "agent" ? undefined : 2);
|
|
357
378
|
}
|
|
358
379
|
function printJson(value) {
|
|
359
380
|
console.log(jsonText(value));
|
|
360
381
|
}
|
|
382
|
+
var UNITS, ESCAPE;
|
|
383
|
+
var init_format = __esm(() => {
|
|
384
|
+
init_mode();
|
|
385
|
+
init_style();
|
|
386
|
+
UNITS = [["d", 86400], ["h", 3600], ["m", 60], ["s", 1]];
|
|
387
|
+
ESCAPE = String.fromCharCode(27);
|
|
388
|
+
});
|
|
361
389
|
|
|
362
390
|
// ../kit/src/help.ts
|
|
363
391
|
import process8 from "process";
|
|
364
|
-
var OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
365
|
-
var USAGE_PREFIX = /^usage:\s*/i;
|
|
366
|
-
var FULL_STOP = /\.$/;
|
|
367
392
|
function usageLine(usage, colors = paint(process8.stdout)) {
|
|
368
|
-
|
|
393
|
+
const lines = usage.replace(USAGE_PREFIX, "").split(`
|
|
394
|
+
`);
|
|
395
|
+
const blank = lines.indexOf("");
|
|
396
|
+
const synopses = blank === -1 ? lines : lines.slice(0, blank);
|
|
397
|
+
const details = blank === -1 ? [] : lines.slice(blank + 1);
|
|
398
|
+
const colon = synopses[0].indexOf(": ");
|
|
399
|
+
const inline = synopses[0].slice(colon + 2);
|
|
400
|
+
const summary = colon === -1 ? details.shift() : `${inline.charAt(0).toUpperCase()}${inline.slice(1)}`;
|
|
401
|
+
if (colon !== -1)
|
|
402
|
+
synopses[0] = synopses[0].slice(0, colon);
|
|
403
|
+
const head = `${colors.bold("Usage:")} ${synopses.map((line) => line.replaceAll(OPTIONAL, (part) => colors.dim(part))).join(`
|
|
404
|
+
`)}`;
|
|
405
|
+
const lead = summary === undefined ? [] : ["", colors.bold(prose(summary, colors))];
|
|
406
|
+
const rest = details.length === 0 ? [] : ["", ...details.map((line) => prose(line, colors))];
|
|
407
|
+
return [head, ...lead, ...rest].join(`
|
|
408
|
+
`);
|
|
409
|
+
}
|
|
410
|
+
function prose(line, colors) {
|
|
411
|
+
if (colors.cyan("x") === "x")
|
|
412
|
+
return line;
|
|
413
|
+
return line.replaceAll(PROSE_MARKS, (match, code, flag) => code === undefined ? colors.cyan(flag ?? match) : colors.bold(code));
|
|
369
414
|
}
|
|
370
415
|
function helpText(usage, options, colors = paint(process8.stdout), { examples = [], exits = [] } = {}) {
|
|
371
416
|
return [usageLine(usage, colors), "", colors.bold("Options:"), ...optionRows(options, colors), ...exitRows(exits, colors), ...exampleRows(examples, colors)].join(`
|
|
@@ -400,7 +445,6 @@ function exampleRows(examples, colors = paint(process8.stdout)) {
|
|
|
400
445
|
return [];
|
|
401
446
|
return ["", colors.bold("Examples:"), ...examples.map((example) => typeof example === "string" ? ` ${example}` : ` ${example[0]} ${colors.dim(`# ${example[1]}`)}`)];
|
|
402
447
|
}
|
|
403
|
-
var MAX_INLINE_CHOICES = 24;
|
|
404
448
|
function optionRows(options, colors = paint(process8.stdout)) {
|
|
405
449
|
const rows = Object.entries(options).map(([name, option]) => {
|
|
406
450
|
const short = option.short === undefined ? " " : `${colors.cyan(`-${option.short}`)}, `;
|
|
@@ -415,6 +459,15 @@ function optionRows(options, colors = paint(process8.stdout)) {
|
|
|
415
459
|
const width = Math.max(0, ...rows.map((row) => row.width));
|
|
416
460
|
return rows.map((row) => row.description === "" ? ` ${row.flag}` : ` ${row.flag}${" ".repeat(width - row.width)} ${colors.dim(row.description)}`);
|
|
417
461
|
}
|
|
462
|
+
var OPTIONAL, USAGE_PREFIX, FULL_STOP, PROSE_MARKS, MAX_INLINE_CHOICES = 24;
|
|
463
|
+
var init_help = __esm(() => {
|
|
464
|
+
init_mode();
|
|
465
|
+
init_style();
|
|
466
|
+
OPTIONAL = /(?<!\x1B)\[[^\]]+\]/g;
|
|
467
|
+
USAGE_PREFIX = /^usage:\s*/i;
|
|
468
|
+
FULL_STOP = /\.$/;
|
|
469
|
+
PROSE_MARKS = /`([^`\n]+)`|(?<![\w-])(--[a-z][\w-]*|-[a-z](?![\w-]))/gi;
|
|
470
|
+
});
|
|
418
471
|
|
|
419
472
|
// ../kit/src/text.ts
|
|
420
473
|
function distance(a, b) {
|
|
@@ -442,8 +495,9 @@ function closest(name, names) {
|
|
|
442
495
|
const [best] = names.map((known) => ({ known, far: distance(name, known) })).sort((a, b) => a.far - b.far);
|
|
443
496
|
return best !== undefined && best.far <= (name.length < 4 ? 1 : 2) ? best.known : undefined;
|
|
444
497
|
}
|
|
498
|
+
var init_text = () => {};
|
|
499
|
+
|
|
445
500
|
// ../kit/src/input.ts
|
|
446
|
-
var WHOLE = /^\d+$/;
|
|
447
501
|
function wholeNumber(value, name, fallback, min = 1) {
|
|
448
502
|
if (value === undefined)
|
|
449
503
|
return fallback;
|
|
@@ -452,40 +506,25 @@ function wholeNumber(value, name, fallback, min = 1) {
|
|
|
452
506
|
badUsage(`${name.startsWith("<") ? name : `--${name}`} takes a whole number from ${min}, not ${value}`);
|
|
453
507
|
return number;
|
|
454
508
|
}
|
|
509
|
+
var WHOLE;
|
|
510
|
+
var init_input = __esm(() => {
|
|
511
|
+
init_args();
|
|
512
|
+
WHOLE = /^\d+$/;
|
|
513
|
+
});
|
|
455
514
|
|
|
456
515
|
// ../kit/src/args.ts
|
|
457
|
-
|
|
516
|
+
import process9 from "process";
|
|
517
|
+
import { parseArgs } from "util";
|
|
458
518
|
function jsonOption(holds) {
|
|
459
519
|
return { type: "boolean", description: holds === undefined ? "print JSON" : `print JSON: ${holds}` };
|
|
460
520
|
}
|
|
461
|
-
class Exit extends Error {
|
|
462
|
-
code;
|
|
463
|
-
hint;
|
|
464
|
-
constructor(message, code, hint) {
|
|
465
|
-
super(message);
|
|
466
|
-
this.code = code;
|
|
467
|
-
this.hint = hint;
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
521
|
function fail(message, code = 2, hint) {
|
|
471
522
|
throw new Exit(message, code, hint);
|
|
472
523
|
}
|
|
473
|
-
|
|
474
|
-
class UsageError extends Exit {
|
|
475
|
-
constructor(message, hint) {
|
|
476
|
-
super(message, 2, hint);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
524
|
function badUsage(message) {
|
|
480
525
|
throw new UsageError(message);
|
|
481
526
|
}
|
|
482
527
|
|
|
483
|
-
class HelpShown extends Exit {
|
|
484
|
-
constructor() {
|
|
485
|
-
super("help shown", 0);
|
|
486
|
-
}
|
|
487
|
-
}
|
|
488
|
-
|
|
489
528
|
class Completing {
|
|
490
529
|
options;
|
|
491
530
|
positionals;
|
|
@@ -496,11 +535,6 @@ class Completing {
|
|
|
496
535
|
this.candidates = candidates;
|
|
497
536
|
}
|
|
498
537
|
}
|
|
499
|
-
var completion = { active: false };
|
|
500
|
-
var OUTPUT_OPTIONS = {
|
|
501
|
-
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
502
|
-
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
503
|
-
};
|
|
504
538
|
function applyOutput(color, plain, env = process9.env) {
|
|
505
539
|
const when = plain === true ? "never" : color ?? "auto";
|
|
506
540
|
if (when === "auto")
|
|
@@ -654,7 +688,6 @@ function parseError(error) {
|
|
|
654
688
|
const message = upTo(error instanceof Error ? error.message : String(error), ". ");
|
|
655
689
|
return `${message.charAt(0).toLowerCase()}${message.slice(1)}`;
|
|
656
690
|
}
|
|
657
|
-
var UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
658
691
|
function nearestOption(message, options, allowNegative) {
|
|
659
692
|
const typed = UNKNOWN_OPTION.exec(message)?.[1];
|
|
660
693
|
if (typed === undefined)
|
|
@@ -670,6 +703,61 @@ function nearestOption(message, options, allowNegative) {
|
|
|
670
703
|
const meant = closest(word, known.map((flag) => flag.replace(DASHES, "")));
|
|
671
704
|
return meant === undefined ? undefined : `did you mean ${known.find((flag) => flag.replace(DASHES, "") === meant)}?`;
|
|
672
705
|
}
|
|
706
|
+
var DASHES, EXIT, Exit, UsageError, HelpShown, completion, OUTPUT_OPTIONS, UNKNOWN_OPTION;
|
|
707
|
+
var init_args = __esm(() => {
|
|
708
|
+
init_format();
|
|
709
|
+
init_help();
|
|
710
|
+
init_text();
|
|
711
|
+
init_help();
|
|
712
|
+
init_input();
|
|
713
|
+
DASHES = /^-+/;
|
|
714
|
+
EXIT = Symbol.for("@kaynooo/cli-kit/Exit");
|
|
715
|
+
Exit = class Exit extends Error {
|
|
716
|
+
code;
|
|
717
|
+
hint;
|
|
718
|
+
[EXIT] = true;
|
|
719
|
+
constructor(message, code, hint) {
|
|
720
|
+
super(message);
|
|
721
|
+
this.code = code;
|
|
722
|
+
this.hint = hint;
|
|
723
|
+
}
|
|
724
|
+
static [Symbol.hasInstance](value) {
|
|
725
|
+
if (this !== Exit)
|
|
726
|
+
return Function.prototype[Symbol.hasInstance].call(this, value);
|
|
727
|
+
return typeof value === "object" && value !== null && value[EXIT] === true;
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
UsageError = class UsageError extends Exit {
|
|
731
|
+
constructor(message, hint) {
|
|
732
|
+
super(message, 2, hint);
|
|
733
|
+
}
|
|
734
|
+
};
|
|
735
|
+
HelpShown = class HelpShown extends Exit {
|
|
736
|
+
constructor() {
|
|
737
|
+
super("help shown", 0);
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
completion = { active: false };
|
|
741
|
+
OUTPUT_OPTIONS = {
|
|
742
|
+
color: { type: "string", choices: ["auto", "always", "never"], description: "auto (the default) colours on a terminal alone" },
|
|
743
|
+
plain: { type: "boolean", description: "plain text, no colour or spinner: --color never" }
|
|
744
|
+
};
|
|
745
|
+
UNKNOWN_OPTION = /^unknown option '(-[^']+)'/;
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
// ../kit/src/folders.ts
|
|
749
|
+
var SKIPPED_FOLDERS;
|
|
750
|
+
var init_folders = __esm(() => {
|
|
751
|
+
init_user_config();
|
|
752
|
+
SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
// src/cli.ts
|
|
756
|
+
import process16 from "process";
|
|
757
|
+
|
|
758
|
+
// ../kit/src/index.ts
|
|
759
|
+
init_args();
|
|
760
|
+
|
|
673
761
|
// ../kit/src/argv.ts
|
|
674
762
|
import { readFileSync as readFileSync2, realpathSync } from "fs";
|
|
675
763
|
import { resolve as resolve3 } from "path";
|
|
@@ -694,15 +782,73 @@ function scriptArgs(argv = process10.argv.slice(2), cmdline = commandLine(), scr
|
|
|
694
782
|
const after = at === -1 ? [] : cmdline.slice(at + 1);
|
|
695
783
|
return after[0] === "--" && after.length === argv.length + 1 && argv.every((word, index) => word === after[index + 1]) ? after : argv;
|
|
696
784
|
}
|
|
785
|
+
// ../kit/src/chart.ts
|
|
786
|
+
init_format();
|
|
787
|
+
init_mode();
|
|
788
|
+
init_style();
|
|
789
|
+
init_theme();
|
|
790
|
+
// ../kit/src/ci.ts
|
|
791
|
+
init_args();
|
|
792
|
+
init_format();
|
|
793
|
+
|
|
697
794
|
// ../kit/src/progress.ts
|
|
795
|
+
init_format();
|
|
796
|
+
init_style();
|
|
797
|
+
init_theme();
|
|
698
798
|
var ESC = String.fromCharCode(27);
|
|
699
799
|
var ESCAPE_CODE = new RegExp(`${ESC}(?:\\[[\\x30-\\x3F]*[\\x20-\\x2F]*[\\x40-\\x7E]|\\][^\\u0007${ESC}]*(?:\\u0007|${ESC}\\\\))`, "y");
|
|
700
800
|
var RESET_STYLE = `${ESC}[0m`;
|
|
701
801
|
var CLOSE_LINK = `${ESC}]8;;${ESC}\\`;
|
|
802
|
+
|
|
803
|
+
// ../kit/src/ci.ts
|
|
804
|
+
init_style();
|
|
805
|
+
|
|
806
|
+
// ../kit/src/tool.ts
|
|
807
|
+
init_format();
|
|
702
808
|
// ../kit/src/cli.ts
|
|
809
|
+
init_args();
|
|
703
810
|
import { readFileSync as readFileSync3, realpathSync as realpathSync2 } from "fs";
|
|
704
811
|
import { dirname as dirname3, join as join5 } from "path";
|
|
705
|
-
import
|
|
812
|
+
import process14 from "process";
|
|
813
|
+
|
|
814
|
+
// ../kit/src/askpass.ts
|
|
815
|
+
import process11 from "process";
|
|
816
|
+
var SOCKET_VARIABLE = "KAYNOOO_ASKPASS_SOCKET";
|
|
817
|
+
async function askpassClient(argv) {
|
|
818
|
+
const socketPath = process11.env[SOCKET_VARIABLE];
|
|
819
|
+
if (socketPath === undefined)
|
|
820
|
+
return;
|
|
821
|
+
const request = { prompt: argv[0] ?? "", ...process11.env.SSH_ASKPASS_PROMPT === "none" ? { notice: true } : {} };
|
|
822
|
+
const { promise, resolve } = Promise.withResolvers();
|
|
823
|
+
let received = "";
|
|
824
|
+
try {
|
|
825
|
+
await Bun.connect({
|
|
826
|
+
unix: socketPath,
|
|
827
|
+
socket: {
|
|
828
|
+
open: (socket) => void socket.write(`${JSON.stringify(request)}
|
|
829
|
+
`),
|
|
830
|
+
data: (_, chunk) => {
|
|
831
|
+
received += chunk.toString();
|
|
832
|
+
},
|
|
833
|
+
close: () => resolve(received),
|
|
834
|
+
error: () => resolve("")
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
} catch {
|
|
838
|
+
return 1;
|
|
839
|
+
}
|
|
840
|
+
const reply = await promise;
|
|
841
|
+
if (reply === "")
|
|
842
|
+
return 1;
|
|
843
|
+
const { answer } = JSON.parse(reply);
|
|
844
|
+
if (request.notice === true)
|
|
845
|
+
return 0;
|
|
846
|
+
if (answer === undefined)
|
|
847
|
+
return 1;
|
|
848
|
+
process11.stdout.write(`${answer}
|
|
849
|
+
`);
|
|
850
|
+
return 0;
|
|
851
|
+
}
|
|
706
852
|
|
|
707
853
|
// ../kit/src/completions.ts
|
|
708
854
|
var COMPLETION_SHELLS = ["fish", "bash", "zsh"];
|
|
@@ -765,28 +911,34 @@ compdef __kaynooo_cli_complete ${bins.join(" ")}
|
|
|
765
911
|
}
|
|
766
912
|
|
|
767
913
|
// ../kit/src/notify.ts
|
|
768
|
-
|
|
914
|
+
init_format();
|
|
915
|
+
init_mode();
|
|
916
|
+
import process12 from "process";
|
|
769
917
|
var NOTIFY_AFTER_MS = 1e4;
|
|
770
918
|
var CANCELLED = 130;
|
|
771
919
|
function base64(text) {
|
|
772
920
|
return Buffer.from(text).toString("base64");
|
|
773
921
|
}
|
|
774
|
-
function notification(title, body, env =
|
|
775
|
-
const id = `kit${
|
|
922
|
+
function notification(title, body, env = process12.env) {
|
|
923
|
+
const id = `kit${process12.pid}`;
|
|
776
924
|
const codes = [`\x1B]99;i=${id}:d=0:o=unfocused:e=1;${base64(title)}\x1B\\`, `\x1B]99;i=${id}:p=body:e=1;${base64(body)}\x1B\\`];
|
|
777
925
|
return codes.map((code) => env.TMUX === undefined || env.TMUX === "" ? code : `\x1BPtmux;${code.replaceAll("\x1B", "\x1B\x1B")}\x1B\\`).join("");
|
|
778
926
|
}
|
|
779
|
-
function notifyEnd(command, code, ms, { stream =
|
|
927
|
+
function notifyEnd(command, code, ms, { stream = process12.stderr, env = process12.env } = {}) {
|
|
780
928
|
if (ms < NOTIFY_AFTER_MS || code === CANCELLED || outputMode(stream, env) !== "terminal")
|
|
781
929
|
return;
|
|
782
930
|
stream.write(notification(command, code === 0 ? `done in ${formatDuration(ms)}` : `failed with exit ${code} after ${formatDuration(ms)}`, env));
|
|
783
931
|
}
|
|
784
932
|
|
|
933
|
+
// ../kit/src/cli.ts
|
|
934
|
+
init_style();
|
|
935
|
+
init_text();
|
|
936
|
+
|
|
785
937
|
// ../kit/src/usage.ts
|
|
786
938
|
import { appendFileSync, mkdirSync } from "fs";
|
|
787
939
|
import { homedir as homedir3 } from "os";
|
|
788
940
|
import { dirname as dirname2, isAbsolute, join as join4 } from "path";
|
|
789
|
-
import
|
|
941
|
+
import process13 from "process";
|
|
790
942
|
|
|
791
943
|
// ../kit/src/logs.ts
|
|
792
944
|
var DAY_MS = 24 * 60 * 60 * 1000;
|
|
@@ -800,14 +952,14 @@ var usageError;
|
|
|
800
952
|
function noteUsageError(message) {
|
|
801
953
|
usageError = message;
|
|
802
954
|
}
|
|
803
|
-
function stateHome(env =
|
|
955
|
+
function stateHome(env = process13.env) {
|
|
804
956
|
const dir = env.XDG_STATE_HOME;
|
|
805
957
|
return dir !== undefined && isAbsolute(dir) ? dir : join4(homedir3(), ".local", "state");
|
|
806
958
|
}
|
|
807
|
-
function usagePath(env =
|
|
959
|
+
function usagePath(env = process13.env) {
|
|
808
960
|
return join4(stateHome(env), CLI_FOLDER, "usage.jsonl");
|
|
809
961
|
}
|
|
810
|
-
function usageRecorded(env =
|
|
962
|
+
function usageRecorded(env = process13.env) {
|
|
811
963
|
const off = env.KAYNOOO_CLI_NO_USAGE;
|
|
812
964
|
return env.NODE_ENV !== "test" && (off === undefined || off === "" || off === "0");
|
|
813
965
|
}
|
|
@@ -816,12 +968,12 @@ function flagNames(argv) {
|
|
|
816
968
|
const names = (end === -1 ? argv : argv.slice(0, end)).filter((word) => word.startsWith("-") && word !== "-").map((word) => word.includes("=") ? word.slice(0, word.indexOf("=")) : word);
|
|
817
969
|
return [...new Set(names)].filter((name) => name.length <= LONGEST_NAME && FLAG_NAME.test(name));
|
|
818
970
|
}
|
|
819
|
-
function usageEntry(bin, command, argv, code, now = new Date) {
|
|
971
|
+
function usageEntry(bin, command, argv, code, { ms, now = new Date } = {}) {
|
|
820
972
|
const unknown = code === 2 && usageError !== undefined ? UNKNOWN_OPTION2.exec(usageError)?.[1] : undefined;
|
|
821
973
|
usageError = undefined;
|
|
822
|
-
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown } };
|
|
974
|
+
return { at: now.toISOString(), bin, ...command === undefined ? {} : { command }, flags: flagNames(argv), code, ...unknown === undefined ? {} : { unknown }, ...ms === undefined ? {} : { ms: Math.round(ms) } };
|
|
823
975
|
}
|
|
824
|
-
function recordUsage(entry, env =
|
|
976
|
+
function recordUsage(entry, env = process13.env) {
|
|
825
977
|
if (!usageRecorded(env))
|
|
826
978
|
return;
|
|
827
979
|
try {
|
|
@@ -915,8 +1067,8 @@ async function help2({ path, header, summary: lazySummary, commands, defaultComm
|
|
|
915
1067
|
`);
|
|
916
1068
|
}
|
|
917
1069
|
function printError(prefix, message, hint, cause) {
|
|
918
|
-
const colors = paint(
|
|
919
|
-
const styled = takesControlCodes(
|
|
1070
|
+
const colors = paint(process14.stderr);
|
|
1071
|
+
const styled = takesControlCodes(process14.stderr);
|
|
920
1072
|
const head = styled ? `${colors.red.bold("error")} ${colors.dim(`${prefix}:`)}` : `error: ${prefix}:`;
|
|
921
1073
|
const under = (label, text, tint) => text === undefined ? "" : `
|
|
922
1074
|
${styled ? tint(label) : `${label}:`} ${text}`;
|
|
@@ -959,11 +1111,11 @@ async function dispatch(level, typed, { version, redact }) {
|
|
|
959
1111
|
}
|
|
960
1112
|
}
|
|
961
1113
|
if (name === undefined && level.path.length > 1) {
|
|
962
|
-
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1114
|
+
console.error(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stderr));
|
|
963
1115
|
return 2;
|
|
964
1116
|
}
|
|
965
1117
|
if (name === undefined || name === "help" || name === "--help" || name === "-h") {
|
|
966
|
-
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]),
|
|
1118
|
+
console.log(await help2(await expand(level, [...level.path.slice(1), ...argv]), process14.stdout));
|
|
967
1119
|
return 0;
|
|
968
1120
|
}
|
|
969
1121
|
if (level.path.length === 1 && (name === "--version" || name === "-v")) {
|
|
@@ -1109,6 +1261,9 @@ function packageVersion(entry = Bun.main) {
|
|
|
1109
1261
|
}
|
|
1110
1262
|
async function runCli(cli, argv = scriptArgs()) {
|
|
1111
1263
|
const version = cli.version ?? packageVersion();
|
|
1264
|
+
const answered = await askpassClient(argv);
|
|
1265
|
+
if (answered !== undefined)
|
|
1266
|
+
return answered;
|
|
1112
1267
|
if (argv[0] === COMPLETE)
|
|
1113
1268
|
return printCandidates(candidates(scopeOf(cli.commands, cli.extraCommands, cli.aliases), cli.defaultCommand, argv.slice(1)));
|
|
1114
1269
|
if (argv[0] === COMPLETIONS || argv[0]?.startsWith(`${COMPLETIONS}=`) === true)
|
|
@@ -1119,7 +1274,7 @@ async function runCli(cli, argv = scriptArgs()) {
|
|
|
1119
1274
|
notifyEnd(command === undefined ? cli.name : `${cli.name} ${command}`, code, performance.now() - started);
|
|
1120
1275
|
if (cli.usage !== false) {
|
|
1121
1276
|
try {
|
|
1122
|
-
recordUsage(usageEntry(cli.name, command, argv, code));
|
|
1277
|
+
recordUsage(usageEntry(cli.name, command, argv, code, { ms: performance.now() - started }));
|
|
1123
1278
|
} catch {}
|
|
1124
1279
|
}
|
|
1125
1280
|
return code;
|
|
@@ -1139,465 +1294,47 @@ function commandPath(scope, argv) {
|
|
|
1139
1294
|
}
|
|
1140
1295
|
return path.length === 0 ? undefined : path.join(" ");
|
|
1141
1296
|
}
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
}
|
|
1156
|
-
// ../kit/src/folders.ts
|
|
1157
|
-
var SKIPPED_FOLDERS = new Set(["node_modules", "vendor", "dist", "build", "target", "coverage", "venv", "__pycache__"]);
|
|
1297
|
+
|
|
1298
|
+
// ../kit/src/index.ts
|
|
1299
|
+
init_config();
|
|
1300
|
+
|
|
1301
|
+
// ../kit/src/excerpt.ts
|
|
1302
|
+
init_text();
|
|
1303
|
+
|
|
1304
|
+
// ../kit/src/index.ts
|
|
1305
|
+
init_folders();
|
|
1306
|
+
init_format();
|
|
1307
|
+
|
|
1308
|
+
// ../kit/src/git.ts
|
|
1309
|
+
init_args();
|
|
1158
1310
|
// ../kit/src/limit.ts
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
badUsage("--limit and --full exclude each other");
|
|
1168
|
-
if (values.full === true || values.json === true && values.limit === undefined)
|
|
1169
|
-
return Number.POSITIVE_INFINITY;
|
|
1170
|
-
return wholeNumber(values.limit, "limit", fallback);
|
|
1171
|
-
}
|
|
1172
|
-
function moreFooter(more) {
|
|
1173
|
-
return `${more} more, rerun with --full`;
|
|
1174
|
-
}
|
|
1175
|
-
function capped(rows, limit) {
|
|
1176
|
-
const more = rows.length - limit;
|
|
1177
|
-
return more > 0 ? { shown: rows.slice(0, limit), footer: moreFooter(more) } : { shown: [...rows], footer: undefined };
|
|
1178
|
-
}
|
|
1311
|
+
init_args();
|
|
1312
|
+
|
|
1313
|
+
// ../kit/src/index.ts
|
|
1314
|
+
init_mode();
|
|
1315
|
+
|
|
1316
|
+
// ../kit/src/report.ts
|
|
1317
|
+
init_style();
|
|
1318
|
+
init_text();
|
|
1179
1319
|
// ../kit/src/secrets.ts
|
|
1180
1320
|
var SECRET_WORDS = new Set(["key", "pass", "pwd", "auth", "salt", "cookie", "session", "jwt", "ssn", "iban", "card", "cvv", "otp"]);
|
|
1181
1321
|
// ../kit/src/sessions.ts
|
|
1182
1322
|
var {Glob } = globalThis.Bun;
|
|
1183
1323
|
var SESSION_FILES = new Glob("*.json");
|
|
1184
1324
|
var ACCOUNT_DIRS = new Glob("*/sessions");
|
|
1185
|
-
// src/commands/audit.ts
|
|
1186
|
-
import { homedir as homedir4 } from "os";
|
|
1187
|
-
import { resolve as resolve5 } from "path";
|
|
1188
|
-
import process16 from "process";
|
|
1189
|
-
|
|
1190
|
-
// src/audit/compose.ts
|
|
1191
|
-
import { join as join6 } from "path";
|
|
1192
|
-
var dockerCompose = async (root, files) => {
|
|
1193
|
-
const result = await compose(["config", "--no-interpolate", "--format", "json"], { flags: ["--project-directory", root, ...files.flatMap((file) => ["-f", join6(root, file)])], env: { COMPOSE_FILE: "" } });
|
|
1194
|
-
if (result.code !== 0)
|
|
1195
|
-
throw new Error(composeError(result));
|
|
1196
|
-
return JSON.parse(result.stdout);
|
|
1197
|
-
};
|
|
1198
1325
|
|
|
1199
|
-
// src/
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
return result.findings.filter((finding) => finding.level === "error");
|
|
1205
|
-
}
|
|
1206
|
-
function section2(heading, findings, limit) {
|
|
1207
|
-
const { shown, footer } = capped(findings, limit);
|
|
1208
|
-
return findings.length === 0 ? [] : [heading, ...shown.map(line), ...footer === undefined ? [] : [` ${footer}`], ""];
|
|
1209
|
-
}
|
|
1210
|
-
function render(result, limit = Number.POSITIVE_INFINITY) {
|
|
1211
|
-
const errors = errorsOf(result);
|
|
1212
|
-
const warnings = result.findings.filter((finding) => finding.level === "warn");
|
|
1213
|
-
if (result.findings.length === 0)
|
|
1214
|
-
return marked("ok", `${basename(result.root)}: compose ${result.composeFiles.join(", ")} and release.config.ts agree.`, process15.stdout);
|
|
1215
|
-
return [
|
|
1216
|
-
...section2("Errors", errors, limit),
|
|
1217
|
-
...section2("Warnings", warnings, limit),
|
|
1218
|
-
`${errors.length} error(s), ${warnings.length} warning(s)`
|
|
1219
|
-
].join(`
|
|
1220
|
-
`);
|
|
1221
|
-
}
|
|
1222
|
-
|
|
1223
|
-
// src/audit/run.ts
|
|
1224
|
-
import { existsSync as existsSync5 } from "fs";
|
|
1225
|
-
import { join as join9 } from "path";
|
|
1226
|
-
|
|
1227
|
-
// src/audit/checks.ts
|
|
1228
|
-
import { existsSync as existsSync3, readFileSync as readFileSync4 } from "fs";
|
|
1229
|
-
import { isAbsolute as isAbsolute2, join as join7, relative, resolve as resolve4 } from "path";
|
|
1230
|
-
var ENV_REF = /(?<!\$)\$(?:\{([A-Z_]\w*)(\s*:?[-?+][^}]*)?\}|([A-Z_]\w*))/gi;
|
|
1231
|
-
var REQUIRED_OPERATOR = /^\s*:?\?/;
|
|
1232
|
-
var COMMENT_START = /(?:^|\s)#.*$/;
|
|
1233
|
-
var QUOTES = /['"]/g;
|
|
1234
|
-
var YAML_FILE = /\.ya?ml$/;
|
|
1235
|
-
var LEADING_DOT_SLASH = /^\.\//;
|
|
1236
|
-
var SERVICES_KEY = /^services:/m;
|
|
1237
|
-
var EXEC_SERVICE = /\{compose\}(?:\s+--\S+)*\s+(?:exec|run)\s+(?:-\S+\s+)*([\w-]+)/;
|
|
1238
|
-
var services = (model) => Object.entries(model?.services ?? {});
|
|
1239
|
-
function before(text, separator) {
|
|
1240
|
-
const at = text.indexOf(separator);
|
|
1241
|
-
return at < 0 ? text : text.slice(0, at);
|
|
1242
|
-
}
|
|
1243
|
-
var stripDotSlash = (file) => file.replace(LEADING_DOT_SLASH, "");
|
|
1244
|
-
function composeLayout(root, config) {
|
|
1245
|
-
const composeFiles = (config.deploySyncFiles ?? []).map(stripDotSlash).filter((file) => YAML_FILE.test(file) && existsSync3(join7(root, file)));
|
|
1246
|
-
const [base] = composeFiles.toSorted((a, b) => a.length - b.length);
|
|
1247
|
-
return { composeFiles, base, overlays: composeFiles.filter((file) => file !== base) };
|
|
1248
|
-
}
|
|
1249
|
-
function syncFindings(root, config) {
|
|
1250
|
-
return (config.deploySyncFiles ?? []).filter((file) => !existsSync3(join7(root, stripDotSlash(file)))).map((file) => ({ level: "error", check: "sync", message: `deploySyncFiles entry does not exist: ${file}` }));
|
|
1251
|
-
}
|
|
1252
|
-
function buildFindings(root, releases, env, home) {
|
|
1253
|
-
const findings = [];
|
|
1254
|
-
const missing = (release, key) => {
|
|
1255
|
-
const path = release[key];
|
|
1256
|
-
if (path !== undefined && path !== "" && !existsSync3(join7(root, path)))
|
|
1257
|
-
findings.push({ level: "error", check: "build", message: `${release.slug}: ${key} does not exist: ${path}` });
|
|
1258
|
-
};
|
|
1259
|
-
for (const release of releases) {
|
|
1260
|
-
missing(release, "sourceDir");
|
|
1261
|
-
missing(release, "buildContext");
|
|
1262
|
-
missing(release, "dockerfile");
|
|
1263
|
-
for (const secret of release.buildSecrets ?? []) {
|
|
1264
|
-
if (secret.src !== undefined && secret.src !== "") {
|
|
1265
|
-
const path = secret.src.startsWith("~") ? join7(home, secret.src.slice(1)) : resolve4(root, secret.src);
|
|
1266
|
-
if (!existsSync3(path))
|
|
1267
|
-
findings.push({ level: "error", check: "build", message: `${release.slug}: buildSecret "${secret.id}" src does not exist: ${secret.src}` });
|
|
1268
|
-
}
|
|
1269
|
-
if (secret.env !== undefined && secret.env !== "" && (env[secret.env] ?? "") === "")
|
|
1270
|
-
findings.push({ level: "warn", check: "build", message: `${release.slug}: buildSecret "${secret.id}" reads $${secret.env}, unset in this shell` });
|
|
1271
|
-
}
|
|
1272
|
-
}
|
|
1273
|
-
return findings;
|
|
1274
|
-
}
|
|
1275
|
-
function withoutComment(line) {
|
|
1276
|
-
const comment = COMMENT_START.exec(line);
|
|
1277
|
-
if (comment === null || (line.slice(0, comment.index).match(QUOTES)?.length ?? 0) % 2 === 1)
|
|
1278
|
-
return line;
|
|
1279
|
-
return line.slice(0, comment.index);
|
|
1280
|
-
}
|
|
1281
|
-
function envRefs(root, composeFiles) {
|
|
1282
|
-
return composeFiles.flatMap((file) => {
|
|
1283
|
-
const text = readFileSync4(join7(root, file), "utf8").split(`
|
|
1284
|
-
`).map(withoutComment).join(`
|
|
1285
|
-
`);
|
|
1286
|
-
return [...text.matchAll(ENV_REF)].map((match) => ({ name: match[1] ?? match[3], defaulted: match[2] !== undefined && !REQUIRED_OPERATOR.test(match[2]), file }));
|
|
1287
|
-
});
|
|
1288
|
-
}
|
|
1289
|
-
function envFindings(refs, required) {
|
|
1290
|
-
const findings = [];
|
|
1291
|
-
const level = required.length > 0 ? "error" : "warn";
|
|
1292
|
-
for (const name of new Set(refs.filter((ref) => !ref.defaulted).map((ref) => ref.name))) {
|
|
1293
|
-
if (!name.endsWith("_VERSION") && !required.includes(name))
|
|
1294
|
-
findings.push({ level, check: "env", message: `\${${name}} has no default in ${refs.find((ref) => ref.name === name)?.file} and is not in requiredServerEnv` });
|
|
1295
|
-
}
|
|
1296
|
-
for (const name of required) {
|
|
1297
|
-
if (!refs.some((ref) => ref.name === name))
|
|
1298
|
-
findings.push({ level: "warn", check: "env", message: `requiredServerEnv lists ${name}, which no compose file references` });
|
|
1299
|
-
}
|
|
1300
|
-
return findings;
|
|
1301
|
-
}
|
|
1302
|
-
function versionFindings(refs, releases) {
|
|
1303
|
-
const findings = [];
|
|
1304
|
-
const inCompose = new Set(refs.filter((ref) => ref.name.endsWith("_VERSION")).map((ref) => ref.name));
|
|
1305
|
-
const inConfig = new Set(releases.map((release) => release.versionEnv).filter((name) => typeof name === "string" && name !== ""));
|
|
1306
|
-
for (const name of inConfig) {
|
|
1307
|
-
if (!inCompose.has(name))
|
|
1308
|
-
findings.push({ level: "error", check: "version", message: `versionEnv ${name} is never interpolated by a compose file` });
|
|
1309
|
-
}
|
|
1310
|
-
for (const name of inCompose) {
|
|
1311
|
-
if (!inConfig.has(name))
|
|
1312
|
-
findings.push({ level: "error", check: "version", message: `compose interpolates \${${name}}, which no release declares as versionEnv` });
|
|
1313
|
-
}
|
|
1314
|
-
return findings;
|
|
1315
|
-
}
|
|
1316
|
-
function imageFindings(config, releases, model) {
|
|
1317
|
-
const registry = config.registry ?? "";
|
|
1318
|
-
if (registry === "")
|
|
1319
|
-
return [];
|
|
1320
|
-
const declared = new Set(releases.filter((release) => release.image !== undefined && release.image !== "").map((release) => `${registry}/${release.image}`));
|
|
1321
|
-
const findings = [];
|
|
1322
|
-
for (const [name, service] of services(model)) {
|
|
1323
|
-
const repo = service.image === undefined ? undefined : before(service.image, ":");
|
|
1324
|
-
if (repo !== undefined && repo.startsWith(registry) && !declared.has(repo))
|
|
1325
|
-
findings.push({ level: "warn", check: "image", message: `service "${name}" pulls ${repo}, which no release in this config builds` });
|
|
1326
|
-
}
|
|
1327
|
-
return findings;
|
|
1328
|
-
}
|
|
1329
|
-
function restartFindings(config, releases, model, base) {
|
|
1330
|
-
if (model === undefined)
|
|
1331
|
-
return [];
|
|
1332
|
-
const known = new Set(Object.keys(model.services ?? {}));
|
|
1333
|
-
const findings = [];
|
|
1334
|
-
for (const release of releases) {
|
|
1335
|
-
for (const service of release.restartServices ?? []) {
|
|
1336
|
-
if (!known.has(service))
|
|
1337
|
-
findings.push({ level: "error", check: "restart", message: `${release.slug}: restartServices names "${service}", absent from ${base}` });
|
|
1338
|
-
}
|
|
1339
|
-
}
|
|
1340
|
-
for (const server of config.servers ?? []) {
|
|
1341
|
-
for (const [slug, override] of Object.entries(server.releaseOverrides ?? {})) {
|
|
1342
|
-
for (const service of override.restartServices ?? []) {
|
|
1343
|
-
if (!known.has(service))
|
|
1344
|
-
findings.push({ level: "error", check: "restart", message: `server ${server.name}: releaseOverrides.${slug} names service "${service}", absent from ${base}` });
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
return findings;
|
|
1349
|
-
}
|
|
1350
|
-
function postDeployFindings(releases, model, base) {
|
|
1351
|
-
if (model === undefined)
|
|
1352
|
-
return [];
|
|
1353
|
-
const known = new Set(Object.keys(model.services ?? {}));
|
|
1354
|
-
const findings = [];
|
|
1355
|
-
for (const release of releases) {
|
|
1356
|
-
for (const command of release.postDeployCommands ?? []) {
|
|
1357
|
-
const target = EXEC_SERVICE.exec(command)?.[1];
|
|
1358
|
-
if (target !== undefined && !known.has(target))
|
|
1359
|
-
findings.push({ level: "warn", check: "post-deploy", message: `${release.slug}: post-deploy command targets service "${target}", absent from ${base}` });
|
|
1360
|
-
}
|
|
1361
|
-
}
|
|
1362
|
-
return findings;
|
|
1363
|
-
}
|
|
1364
|
-
var gatedServices = (releases) => new Set(releases.flatMap((release) => release.restartServices ?? []));
|
|
1365
|
-
function healthFindings(gated, model) {
|
|
1366
|
-
return [...gated].filter((name) => {
|
|
1367
|
-
const service = model?.services?.[name];
|
|
1368
|
-
return service !== undefined && (service.healthcheck === undefined || service.healthcheck === null);
|
|
1369
|
-
}).map((name) => ({ level: "warn", check: "health", message: `service "${name}" is restarted by a release but declares no healthcheck, so --wait will not gate it` }));
|
|
1370
|
-
}
|
|
1371
|
-
function routingFindings(config, gated, model, base, overlays) {
|
|
1372
|
-
if (overlays.length === 0)
|
|
1373
|
-
return [];
|
|
1374
|
-
const findings = [];
|
|
1375
|
-
for (const name of gated) {
|
|
1376
|
-
const service = model?.services?.[name];
|
|
1377
|
-
if (service === undefined)
|
|
1378
|
-
continue;
|
|
1379
|
-
if (service.ports !== undefined && service.ports.length > 0)
|
|
1380
|
-
findings.push({ level: "error", check: "routing", message: `service "${name}" publishes ports in ${base}; publishing belongs in an overlay` });
|
|
1381
|
-
if (Object.keys(service.labels ?? {}).some((key) => key.startsWith("traefik.")))
|
|
1382
|
-
findings.push({ level: "error", check: "routing", message: `service "${name}" carries traefik labels in ${base}; routing belongs in an overlay` });
|
|
1383
|
-
}
|
|
1384
|
-
const composeArgs = config.composeArgs ?? [];
|
|
1385
|
-
if (composeArgs.length > 0)
|
|
1386
|
-
findings.push({ level: "error", check: "routing", message: `composeArgs is set (${composeArgs.join(" ")}) while ${overlays.length} overlay(s) exist: -f overrides each server's COMPOSE_FILE and drops them` });
|
|
1387
|
-
for (const server of config.servers ?? []) {
|
|
1388
|
-
if (server.composeArgs !== undefined && server.composeArgs.length > 0)
|
|
1389
|
-
findings.push({ level: "warn", check: "routing", message: `server ${server.name} sets composeArgs; prefer its own COMPOSE_FILE` });
|
|
1390
|
-
}
|
|
1391
|
-
return findings;
|
|
1392
|
-
}
|
|
1393
|
-
var SOURCE_END = /:(?![-+?=])/;
|
|
1394
|
-
var DEFAULTED_VARIABLE = /\$\{[A-Z_]\w*:?-([^}$]*)\}/gi;
|
|
1395
|
-
function relativeSource(root, written) {
|
|
1396
|
-
const source = written?.replaceAll(DEFAULTED_VARIABLE, "$1");
|
|
1397
|
-
if (source === undefined || source.includes("$"))
|
|
1398
|
-
return;
|
|
1399
|
-
if (source.startsWith("."))
|
|
1400
|
-
return source;
|
|
1401
|
-
const inRoot = relative(resolve4(root), source);
|
|
1402
|
-
return isAbsolute2(source) && inRoot !== "" && !inRoot.startsWith("..") ? `./${inRoot}` : undefined;
|
|
1403
|
-
}
|
|
1404
|
-
function layoutFindings(root, base, model) {
|
|
1405
|
-
if (base === undefined)
|
|
1406
|
-
return [];
|
|
1407
|
-
const header = readFileSync4(join7(root, base), "utf8").split(SERVICES_KEY)[0] ?? "";
|
|
1408
|
-
const findings = [];
|
|
1409
|
-
for (const [name, service] of services(model)) {
|
|
1410
|
-
for (const volume of service.volumes ?? []) {
|
|
1411
|
-
const source = relativeSource(root, typeof volume === "string" ? volume.split(SOURCE_END)[0] : volume.source);
|
|
1412
|
-
if (source !== undefined && !header.includes(stripDotSlash(source)))
|
|
1413
|
-
findings.push({ level: "warn", check: "layout", message: `service "${name}" bind-mounts ${source}, absent from the header's expected server layout` });
|
|
1414
|
-
}
|
|
1415
|
-
}
|
|
1416
|
-
return findings;
|
|
1417
|
-
}
|
|
1418
|
-
function gitignoreFindings(root) {
|
|
1419
|
-
const path = join7(root, ".gitignore");
|
|
1420
|
-
const text = existsSync3(path) ? readFileSync4(path, "utf8") : "";
|
|
1421
|
-
return [".release-logs", ".release-worktrees"].filter((entry) => !text.includes(entry)).map((entry) => ({ level: "warn", check: "gitignore", message: `${entry}/ is not in .gitignore` }));
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
// src/audit/nuxt.ts
|
|
1425
|
-
import { existsSync as existsSync4, readFileSync as readFileSync5 } from "fs";
|
|
1426
|
-
import { basename as basename2, join as join8 } from "path";
|
|
1427
|
-
var CAMEL_BOUNDARY = /([a-z0-9])([A-Z])/g;
|
|
1428
|
-
var KEY = /([A-Z_]\w*)\s*(?:\?\s*)?:/gi;
|
|
1429
|
-
var OPENS_BRACE = /^\s*\{/;
|
|
1430
|
-
var envVarFor = (key) => key.replace(CAMEL_BOUNDARY, "$1_$2").toUpperCase();
|
|
1431
|
-
function braceBody(text, from) {
|
|
1432
|
-
const open = text.indexOf("{", from);
|
|
1433
|
-
if (open < 0)
|
|
1434
|
-
return;
|
|
1435
|
-
let depth = 0;
|
|
1436
|
-
for (let i = open;i < text.length; i++) {
|
|
1437
|
-
if (text[i] === "{")
|
|
1438
|
-
depth++;
|
|
1439
|
-
else if (text[i] === "}" && --depth === 0)
|
|
1440
|
-
return { body: text.slice(open + 1, i), end: i };
|
|
1441
|
-
}
|
|
1442
|
-
return;
|
|
1443
|
-
}
|
|
1444
|
-
function leafPaths(body, prefix = []) {
|
|
1445
|
-
const paths = [];
|
|
1446
|
-
const key = new RegExp(KEY);
|
|
1447
|
-
for (let match = key.exec(body);match !== null; match = key.exec(body)) {
|
|
1448
|
-
const name = match[1];
|
|
1449
|
-
const after = match.index + match[0].length;
|
|
1450
|
-
if (OPENS_BRACE.test(body.slice(after))) {
|
|
1451
|
-
const inner = braceBody(body, after);
|
|
1452
|
-
if (inner === undefined)
|
|
1453
|
-
continue;
|
|
1454
|
-
paths.push(...leafPaths(inner.body, [...prefix, name]));
|
|
1455
|
-
key.lastIndex = inner.end + 1;
|
|
1456
|
-
} else {
|
|
1457
|
-
paths.push([...prefix, name]);
|
|
1458
|
-
}
|
|
1459
|
-
}
|
|
1460
|
-
return paths;
|
|
1461
|
-
}
|
|
1462
|
-
function schemaEnvNames(schema, iface, prefix) {
|
|
1463
|
-
const at = schema.indexOf(`interface ${iface}`);
|
|
1464
|
-
const body = at < 0 ? undefined : braceBody(schema, at);
|
|
1465
|
-
return body === undefined ? [] : leafPaths(body.body).map((path) => prefix + path.map(envVarFor).join("_"));
|
|
1466
|
-
}
|
|
1467
|
-
function nuxtFindings(root, releases, model) {
|
|
1468
|
-
const findings = [];
|
|
1469
|
-
const dirs = [...new Set(releases.map((release) => release.buildContext).filter((context) => context !== undefined && context !== ""))].map((dir) => join8(root, dir)).filter((dir) => existsSync4(join8(dir, "nuxt.config.ts")));
|
|
1470
|
-
for (const dir of dirs) {
|
|
1471
|
-
const schemaPath = [join8(dir, ".nuxt/types/schema.d.ts"), join8(dir, ".nuxt/types/runtime-config.d.ts")].find((path) => existsSync4(path));
|
|
1472
|
-
let allowed;
|
|
1473
|
-
let level = "error";
|
|
1474
|
-
let source;
|
|
1475
|
-
if (schemaPath !== undefined) {
|
|
1476
|
-
const schema = readFileSync5(schemaPath, "utf8");
|
|
1477
|
-
allowed = new Set([
|
|
1478
|
-
...schemaEnvNames(schema, "SharedRuntimeConfig", "NUXT_"),
|
|
1479
|
-
...schemaEnvNames(schema, "SharedPublicRuntimeConfig", "NUXT_PUBLIC_")
|
|
1480
|
-
]);
|
|
1481
|
-
source = `${basename2(dir)}/${schemaPath.slice(dir.length + 1)}`;
|
|
1482
|
-
} else {
|
|
1483
|
-
const config = readFileSync5(join8(dir, "nuxt.config.ts"), "utf8");
|
|
1484
|
-
const at = config.indexOf("runtimeConfig:");
|
|
1485
|
-
const block = at < 0 ? undefined : braceBody(config, at);
|
|
1486
|
-
if (block === undefined)
|
|
1487
|
-
continue;
|
|
1488
|
-
allowed = new Set(leafPaths(block.body).map((path) => path[0] === "public" ? `NUXT_PUBLIC_${path.slice(1).map(envVarFor).join("_")}` : `NUXT_${path.map(envVarFor).join("_")}`));
|
|
1489
|
-
level = "warn";
|
|
1490
|
-
source = `${basename2(dir)}/nuxt.config.ts (run \`nuxt prepare\` in ${basename2(dir)} for the resolved config, modules included)`;
|
|
1491
|
-
}
|
|
1492
|
-
for (const [name, service] of Object.entries(model?.services ?? {})) {
|
|
1493
|
-
for (const key of Object.keys(service.environment ?? {})) {
|
|
1494
|
-
if (key.startsWith("NUXT_") && !allowed.has(key))
|
|
1495
|
-
findings.push({ level, check: "nuxt", message: `service "${name}" sets ${key}, which matches no runtimeConfig key in ${source}` });
|
|
1496
|
-
}
|
|
1497
|
-
}
|
|
1498
|
-
}
|
|
1499
|
-
return findings;
|
|
1500
|
-
}
|
|
1501
|
-
|
|
1502
|
-
// src/audit/run.ts
|
|
1503
|
-
var CONFIG_FILE = "release.config.ts";
|
|
1504
|
-
var DEFINE_CONFIG_IMPORT = /import\s*\{[^}]*\bdefineConfig\b[^}]*\}\s*from\s*['"]([^'"]+)['"]/;
|
|
1505
|
-
function installed(specifier, root) {
|
|
1506
|
-
try {
|
|
1507
|
-
Bun.resolveSync(specifier, root);
|
|
1508
|
-
return true;
|
|
1509
|
-
} catch {
|
|
1510
|
-
return false;
|
|
1511
|
-
}
|
|
1512
|
-
}
|
|
1513
|
-
async function loadConfig(root) {
|
|
1514
|
-
const specifier = DEFINE_CONFIG_IMPORT.exec(await Bun.file(join9(root, CONFIG_FILE)).text())?.[1];
|
|
1515
|
-
if (specifier !== undefined && !installed(specifier, root)) {
|
|
1516
|
-
Bun.plugin({
|
|
1517
|
-
name: "release-stand-in",
|
|
1518
|
-
setup(build) {
|
|
1519
|
-
build.module(specifier, () => ({ exports: { defineConfig: (config) => config }, loader: "object" }));
|
|
1520
|
-
}
|
|
1521
|
-
});
|
|
1522
|
-
}
|
|
1523
|
-
const config = (await import(join9(root, CONFIG_FILE))).default;
|
|
1524
|
-
if (config === undefined)
|
|
1525
|
-
fail(`${CONFIG_FILE} has no default export`);
|
|
1526
|
-
return config;
|
|
1527
|
-
}
|
|
1528
|
-
async function composeModels(options, base, overlays) {
|
|
1529
|
-
const findings = [];
|
|
1530
|
-
const load = async (files) => {
|
|
1531
|
-
try {
|
|
1532
|
-
return await options.loadCompose(options.root, files);
|
|
1533
|
-
} catch (error) {
|
|
1534
|
-
findings.push({ level: "error", check: "compose", message: `docker compose config failed for ${files.join(" + ")}: ${error instanceof Error ? error.message : String(error)}` });
|
|
1535
|
-
return;
|
|
1536
|
-
}
|
|
1537
|
-
};
|
|
1538
|
-
if (base === undefined) {
|
|
1539
|
-
findings.push({ level: "warn", check: "compose", message: "no compose file among deploySyncFiles, so every check that reads the compose model was skipped" });
|
|
1540
|
-
return { model: undefined, findings };
|
|
1541
|
-
}
|
|
1542
|
-
const model = await load([base]);
|
|
1543
|
-
for (const overlay of overlays)
|
|
1544
|
-
await load([base, overlay]);
|
|
1545
|
-
return { model, findings };
|
|
1546
|
-
}
|
|
1547
|
-
async function audit(config, options) {
|
|
1548
|
-
const { root } = options;
|
|
1549
|
-
const releases = config.releases ?? [];
|
|
1550
|
-
const required = config.requiredServerEnv ?? [];
|
|
1551
|
-
const { composeFiles, base, overlays } = composeLayout(root, config);
|
|
1552
|
-
const compose = await composeModels(options, base, overlays);
|
|
1553
|
-
const refs = envRefs(root, composeFiles);
|
|
1554
|
-
const gated = gatedServices(releases);
|
|
1555
|
-
const findings = [
|
|
1556
|
-
...syncFindings(root, config),
|
|
1557
|
-
...buildFindings(root, releases, options.env, options.home),
|
|
1558
|
-
...compose.findings,
|
|
1559
|
-
...envFindings(refs, required),
|
|
1560
|
-
...versionFindings(refs, releases),
|
|
1561
|
-
...imageFindings(config, releases, compose.model),
|
|
1562
|
-
...restartFindings(config, releases, compose.model, base),
|
|
1563
|
-
...postDeployFindings(releases, compose.model, base),
|
|
1564
|
-
...healthFindings(gated, compose.model),
|
|
1565
|
-
...routingFindings(config, gated, compose.model, base, overlays),
|
|
1566
|
-
...layoutFindings(root, base, compose.model),
|
|
1567
|
-
...nuxtFindings(root, releases, compose.model),
|
|
1568
|
-
...gitignoreFindings(root)
|
|
1569
|
-
];
|
|
1570
|
-
return { root, composeFiles, findings };
|
|
1571
|
-
}
|
|
1572
|
-
var hasConfig = (root) => existsSync5(join9(root, CONFIG_FILE));
|
|
1573
|
-
|
|
1574
|
-
// src/commands/audit.ts
|
|
1575
|
-
var usage2 = `stack audit [dir]
|
|
1576
|
-
|
|
1577
|
-
Cross-checks ${CONFIG_FILE} in dir (the current directory) against the compose files it syncs: sync files and build inputs exist, env variables are required or defaulted, versionEnv matches the compose interpolation, restart and post-deploy services exist, healthchecks, routing in overlays, bind mounts documented in the header, Nuxt runtimeConfig keys and .gitignore.
|
|
1578
|
-
Lists at most 25 errors and 25 warnings, the count of the rest after them (--limit <n>, --full for all); --json is never cut.
|
|
1579
|
-
Needs docker for \`docker compose config\`.
|
|
1580
|
-
|
|
1581
|
-
Exits 0 when it finds no error, 1 when it finds one, 2 when there is no ${CONFIG_FILE}.`;
|
|
1582
|
-
var AUDIT_LIMIT = 25;
|
|
1583
|
-
var options = {
|
|
1584
|
-
...limitOptions(AUDIT_LIMIT),
|
|
1585
|
-
json: jsonOption("{ root, composeFiles, findings }")
|
|
1586
|
-
};
|
|
1587
|
-
async function audit2(args, overrides = {}) {
|
|
1588
|
-
const parsed = parse(args, usage2, options);
|
|
1589
|
-
const root = resolve5(parsed.positionals[0] ?? ".");
|
|
1590
|
-
if (!hasConfig(root)) {
|
|
1591
|
-
fail(`no ${CONFIG_FILE} in ${root}`);
|
|
1592
|
-
}
|
|
1593
|
-
const result = await audit(await loadConfig(root), { root, loadCompose: dockerCompose, env: process16.env, home: homedir4(), ...overrides });
|
|
1594
|
-
if (parsed.values.json === true)
|
|
1595
|
-
printJson(result);
|
|
1596
|
-
else
|
|
1597
|
-
console.log(render(result, limitOf(parsed.values, AUDIT_LIMIT)));
|
|
1598
|
-
return errorsOf(result).length > 0 ? 1 : 0;
|
|
1599
|
-
}
|
|
1326
|
+
// ../kit/src/index.ts
|
|
1327
|
+
init_style();
|
|
1328
|
+
init_text();
|
|
1329
|
+
init_theme();
|
|
1330
|
+
init_user_config();
|
|
1600
1331
|
|
|
1332
|
+
// ../kit/src/watch.ts
|
|
1333
|
+
init_args();
|
|
1334
|
+
init_input();
|
|
1335
|
+
init_style();
|
|
1336
|
+
// ../kit/src/workspace-root.ts
|
|
1337
|
+
init_user_config();
|
|
1601
1338
|
// src/port.ts
|
|
1602
1339
|
var MIN_PORT = 1024;
|
|
1603
1340
|
var MAX_PORT = 65535;
|
|
@@ -1622,19 +1359,19 @@ function isListening(port) {
|
|
|
1622
1359
|
}
|
|
1623
1360
|
|
|
1624
1361
|
// src/commands/port.ts
|
|
1625
|
-
var
|
|
1362
|
+
var usage2 = `stack port <name>
|
|
1626
1363
|
|
|
1627
1364
|
Prints the port a name always hashes to (32-bit FNV-1a, ${MIN_PORT}-${DEFAULT_MAX_PORT} by default, below Linux's ephemeral range), so a service keeps the same port on every machine.
|
|
1628
1365
|
Says on stderr when something already listens on it; the exit code stays 0.
|
|
1629
1366
|
|
|
1630
1367
|
Exits 0 when it printed the port, 2 on a usage error.`;
|
|
1631
|
-
var
|
|
1368
|
+
var options = {
|
|
1632
1369
|
min: { type: "string", description: `lowest port (${MIN_PORT}, nothing lower is allowed)` },
|
|
1633
1370
|
max: { type: "string", description: `highest port (${DEFAULT_MAX_PORT}, up to ${MAX_PORT})` },
|
|
1634
1371
|
json: jsonOption("{name, port, listening}")
|
|
1635
1372
|
};
|
|
1636
1373
|
async function port(args) {
|
|
1637
|
-
const parsed = parse(args,
|
|
1374
|
+
const parsed = parse(args, usage2, options);
|
|
1638
1375
|
const [name] = parsed.positionals;
|
|
1639
1376
|
if (name === undefined)
|
|
1640
1377
|
fail("a name is needed");
|
|
@@ -1654,13 +1391,12 @@ async function port(args) {
|
|
|
1654
1391
|
}
|
|
1655
1392
|
|
|
1656
1393
|
// src/cli.ts
|
|
1657
|
-
|
|
1394
|
+
process16.exitCode = await runCli({
|
|
1658
1395
|
name: "stack",
|
|
1659
|
-
about: "a stable port per service name
|
|
1660
|
-
replaces: "picking a free host port by hand
|
|
1661
|
-
examples: ["stack port api", ["stack
|
|
1396
|
+
about: "a stable port per service name",
|
|
1397
|
+
replaces: "picking a free host port by hand",
|
|
1398
|
+
examples: ["stack port api", ["stack port api --json", "the port and whether something listens on it"]],
|
|
1662
1399
|
commands: {
|
|
1663
|
-
port: { run: port, summary: "the port a name always hashes to, with a warning when something already listens on it" }
|
|
1664
|
-
audit: { run: audit2, summary: "cross-check release.config.ts against its compose files" }
|
|
1400
|
+
port: { run: port, summary: "the port a name always hashes to, with a warning when something already listens on it" }
|
|
1665
1401
|
}
|
|
1666
1402
|
});
|
package/package.json
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaynooo/cli-stack",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"description": "stack: a stable port per service name,
|
|
4
|
+
"version": "0.8.1",
|
|
5
|
+
"description": "stack: a stable host port per service name, the same on every machine.",
|
|
6
6
|
"author": "Kaynooo <contact@kaynooo.fr>",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"homepage": "https://
|
|
8
|
+
"homepage": "https://github.com/Kayno0o/cli/tree/main/packages/stack#readme",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://
|
|
11
|
+
"url": "git+https://github.com/Kayno0o/cli.git",
|
|
12
12
|
"directory": "packages/stack"
|
|
13
13
|
},
|
|
14
|
-
"bugs": "https://
|
|
15
|
-
"keywords": ["docker", "compose", "port", "
|
|
14
|
+
"bugs": "https://github.com/Kayno0o/cli/issues",
|
|
15
|
+
"keywords": ["docker", "compose", "port", "cli", "bun"],
|
|
16
16
|
"bin": {
|
|
17
17
|
"stack": "./dist/cli.js"
|
|
18
18
|
},
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"stack": "$npm_execpath src/cli.ts"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@kaynooo/cli-kit": "0.
|
|
31
|
+
"@kaynooo/cli-kit": "0.46.0"
|
|
32
32
|
}
|
|
33
33
|
}
|