@nylorun/cli 0.3.0-beta → 0.4.1-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -1
- package/README.md +55 -78
- package/dist/{runtime/baseline.js → baseline.js} +0 -1
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +34 -115
- package/dist/doctor.d.ts +1 -12
- package/dist/doctor.js +6 -96
- package/dist/home.d.ts +6 -0
- package/dist/home.js +15 -0
- package/dist/model/host-model.js +1 -1
- package/dist/project/create-tenant.d.ts +3 -1
- package/dist/project/create-tenant.js +3 -2
- package/dist/project/credentials.js +1 -1
- package/dist/project/env.d.ts +3 -0
- package/dist/project/env.js +21 -0
- package/dist/project/link.js +1 -1
- package/dist/project/root.js +2 -1
- package/dist/project/seed.d.ts +6 -0
- package/dist/project/seed.js +9 -7
- package/dist/tenant/commands.js +73 -14
- package/package.json +7 -10
- package/dist/dev-entry.d.ts +0 -5
- package/dist/dev-entry.js +0 -7
- package/dist/dev.d.ts +0 -47
- package/dist/dev.js +0 -278
- package/dist/launcher.d.ts +0 -5
- package/dist/launcher.js +0 -7
- package/dist/project/attach.d.ts +0 -32
- package/dist/project/attach.js +0 -241
- package/dist/runtime/commands.d.ts +0 -16
- package/dist/runtime/commands.js +0 -292
- package/dist/runtime/ephemeral.d.ts +0 -37
- package/dist/runtime/ephemeral.js +0 -84
- package/dist/runtime/exit-codes.d.ts +0 -9
- package/dist/runtime/exit-codes.js +0 -43
- package/dist/runtime/index.d.ts +0 -8
- package/dist/runtime/index.js +0 -6
- package/dist/runtime/launcher.d.ts +0 -81
- package/dist/runtime/launcher.js +0 -243
- package/dist/runtime/progress.d.ts +0 -10
- package/dist/runtime/progress.js +0 -8
- package/dist/runtime/version.d.ts +0 -6
- package/dist/runtime/version.js +0 -27
- /package/dist/{runtime/baseline.d.ts → baseline.d.ts} +0 -0
package/dist/runtime/commands.js
DELETED
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
import { resolve } from "node:path";
|
|
2
|
-
import { CliError } from "../errors.js";
|
|
3
|
-
import { exitCodeForStatusState, } from "./exit-codes.js";
|
|
4
|
-
import { launcher, resolveHome, throwOnLauncherFailure, } from "./launcher.js";
|
|
5
|
-
import { runtimeVersion } from "./version.js";
|
|
6
|
-
export const runtimeUsage = ` runtime up [--port <n>]
|
|
7
|
-
runtime down [--wait] [--force] [--timeout <seconds>]
|
|
8
|
-
runtime status [--json] [--env]
|
|
9
|
-
runtime logs [-f|--follow] [-n <lines>] [--tenant <id>|--all]
|
|
10
|
-
runtime restart [--port <n>] [--allow-downgrade] [--wait|--force]
|
|
11
|
-
runtime run [--port <n>]
|
|
12
|
-
up alias for "runtime up"
|
|
13
|
-
down alias for "runtime down"
|
|
14
|
-
logs alias for "runtime logs"`;
|
|
15
|
-
const usageError = (message) => new CliError(message, 2);
|
|
16
|
-
function parseRuntimeFlags(args, allowed = {}) {
|
|
17
|
-
const booleans = new Set();
|
|
18
|
-
const values = new Map();
|
|
19
|
-
const rest = [];
|
|
20
|
-
const booleanNames = new Set(allowed.booleans ?? []);
|
|
21
|
-
const valueNames = new Set(allowed.values ?? []);
|
|
22
|
-
for (let index = 0; index < args.length; index += 1) {
|
|
23
|
-
const arg = args[index];
|
|
24
|
-
if (!arg.startsWith("-")) {
|
|
25
|
-
rest.push(arg);
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
if (booleanNames.has(arg)) {
|
|
29
|
-
if (booleans.has(arg))
|
|
30
|
-
throw usageError(`${arg} may only be supplied once.`);
|
|
31
|
-
booleans.add(arg);
|
|
32
|
-
continue;
|
|
33
|
-
}
|
|
34
|
-
if (valueNames.has(arg)) {
|
|
35
|
-
if (values.has(arg))
|
|
36
|
-
throw usageError(`${arg} may only be supplied once.`);
|
|
37
|
-
const value = args[++index];
|
|
38
|
-
if (!value || value.startsWith("-"))
|
|
39
|
-
throw usageError(`${arg} requires a value.`);
|
|
40
|
-
values.set(arg, value);
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
throw usageError(`Unknown flag ${arg}.\n${runtimeUsage}`);
|
|
44
|
-
}
|
|
45
|
-
return { rest, booleans, values };
|
|
46
|
-
}
|
|
47
|
-
function parsePort(value) {
|
|
48
|
-
if (value === undefined)
|
|
49
|
-
return undefined;
|
|
50
|
-
const port = Number(value);
|
|
51
|
-
if (!Number.isInteger(port) || port < 0 || port > 65535)
|
|
52
|
-
throw usageError("--port must be an integer between 0 and 65535.");
|
|
53
|
-
return port;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* `nylorun runtime …` and the `up` / `down` / `logs` aliases.
|
|
57
|
-
* Dispatch from `cli.ts` is owned by WS-F2 (one-line import change).
|
|
58
|
-
*/
|
|
59
|
-
export async function runtimeCommand(args, options = {}) {
|
|
60
|
-
const home = options.home ??
|
|
61
|
-
(options.env?.NYLORUN_HOME
|
|
62
|
-
? resolve(options.env.NYLORUN_HOME)
|
|
63
|
-
: resolveHome());
|
|
64
|
-
const handle = options.handle ??
|
|
65
|
-
(await launcher(home, { env: options.env }));
|
|
66
|
-
const [verb, ...rest] = args;
|
|
67
|
-
if (verb === "up" || verb === "start") {
|
|
68
|
-
const flags = parseRuntimeFlags(rest, {
|
|
69
|
-
values: ["--port"],
|
|
70
|
-
});
|
|
71
|
-
if (flags.rest.length)
|
|
72
|
-
throw usageError(runtimeUsage);
|
|
73
|
-
const port = parsePort(flags.values.get("--port"));
|
|
74
|
-
const invokeArgs = ["up"];
|
|
75
|
-
if (port !== undefined)
|
|
76
|
-
invokeArgs.push("--port", String(port));
|
|
77
|
-
const outcome = await handle.invoke(invokeArgs);
|
|
78
|
-
throwOnLauncherFailure(outcome);
|
|
79
|
-
const result = outcome.result ?? {};
|
|
80
|
-
const url = typeof result.url === "string" ? result.url : undefined;
|
|
81
|
-
const started = result.started === true;
|
|
82
|
-
if (url && started) {
|
|
83
|
-
console.log(`Started the Runtime Host at ${url}${result.pid ? ` (pid ${result.pid})` : ""}. It stays running; stop it with "nylorun runtime down".`);
|
|
84
|
-
}
|
|
85
|
-
printUpResult(result);
|
|
86
|
-
console.log(`\n→ npx nylorun dev`);
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
if (verb === "down" || verb === "stop") {
|
|
90
|
-
const flags = parseRuntimeFlags(rest, {
|
|
91
|
-
booleans: ["--wait", "--force"],
|
|
92
|
-
values: ["--timeout"],
|
|
93
|
-
});
|
|
94
|
-
if (flags.rest.length)
|
|
95
|
-
throw usageError(runtimeUsage);
|
|
96
|
-
if (flags.booleans.has("--wait") && flags.booleans.has("--force")) {
|
|
97
|
-
throw usageError("Use either --wait or --force, not both.");
|
|
98
|
-
}
|
|
99
|
-
const invokeArgs = ["down"];
|
|
100
|
-
if (flags.booleans.has("--wait"))
|
|
101
|
-
invokeArgs.push("--wait");
|
|
102
|
-
if (flags.booleans.has("--force"))
|
|
103
|
-
invokeArgs.push("--force");
|
|
104
|
-
if (flags.values.has("--timeout")) {
|
|
105
|
-
const seconds = Number(flags.values.get("--timeout"));
|
|
106
|
-
if (!Number.isFinite(seconds) || seconds <= 0)
|
|
107
|
-
throw usageError("--timeout must be a positive number of seconds.");
|
|
108
|
-
invokeArgs.push("--timeout", String(seconds));
|
|
109
|
-
}
|
|
110
|
-
const outcome = await handle.invoke(invokeArgs);
|
|
111
|
-
throwOnLauncherFailure(outcome);
|
|
112
|
-
const stopped = outcome.result?.stopped === true;
|
|
113
|
-
console.log(stopped
|
|
114
|
-
? `Stopped the Runtime Host. host.json and Tenants are kept under the Host root.`
|
|
115
|
-
: `No Runtime Host is running.`);
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
if (verb === "status") {
|
|
119
|
-
const flags = parseRuntimeFlags(rest, {
|
|
120
|
-
booleans: ["--json", "--env"],
|
|
121
|
-
values: ["--output"],
|
|
122
|
-
});
|
|
123
|
-
if (flags.rest.length)
|
|
124
|
-
throw usageError(runtimeUsage);
|
|
125
|
-
const json = flags.booleans.has("--json") || flags.values.get("--output") === "json";
|
|
126
|
-
if (flags.values.has("--output") &&
|
|
127
|
-
flags.values.get("--output") !== "json" &&
|
|
128
|
-
flags.values.get("--output") !== "text") {
|
|
129
|
-
throw usageError("--output must be text or json.");
|
|
130
|
-
}
|
|
131
|
-
if (flags.booleans.has("--env")) {
|
|
132
|
-
if (options.envHook)
|
|
133
|
-
await options.envHook();
|
|
134
|
-
else {
|
|
135
|
-
console.log("# runtime status --env requires a Project link (nylorun dev). Coming in a later release.");
|
|
136
|
-
}
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const outcome = await handle.invoke(["status"]);
|
|
140
|
-
throwOnLauncherFailure(outcome);
|
|
141
|
-
const result = outcome.result ?? {};
|
|
142
|
-
if (json) {
|
|
143
|
-
console.log(JSON.stringify({
|
|
144
|
-
...result,
|
|
145
|
-
node: handle.runtime.node,
|
|
146
|
-
recommendedRuntimeVersion: runtimeVersion(),
|
|
147
|
-
}, null, 2));
|
|
148
|
-
}
|
|
149
|
-
else {
|
|
150
|
-
printStatus(result, handle);
|
|
151
|
-
}
|
|
152
|
-
const state = typeof result.state === "string" ? result.state : undefined;
|
|
153
|
-
const code = exitCodeForStatusState(state);
|
|
154
|
-
if (code !== undefined)
|
|
155
|
-
process.exitCode = code;
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
if (verb === "logs") {
|
|
159
|
-
const flags = parseRuntimeFlags(rest, {
|
|
160
|
-
booleans: ["-f", "--follow", "--all"],
|
|
161
|
-
values: ["-n", "--lines", "--tenant"],
|
|
162
|
-
});
|
|
163
|
-
if (flags.rest.length)
|
|
164
|
-
throw usageError(runtimeUsage);
|
|
165
|
-
if (flags.booleans.has("--all") && flags.values.has("--tenant")) {
|
|
166
|
-
throw usageError("Use either --tenant or --all, not both.");
|
|
167
|
-
}
|
|
168
|
-
const linesRaw = flags.values.get("-n") ?? flags.values.get("--lines");
|
|
169
|
-
const lines = linesRaw !== undefined ? Number(linesRaw) : 200;
|
|
170
|
-
if (!Number.isInteger(lines) || lines < 1)
|
|
171
|
-
throw usageError("-n must be a positive integer.");
|
|
172
|
-
const follow = flags.booleans.has("-f") || flags.booleans.has("--follow");
|
|
173
|
-
const invokeArgs = ["logs", "--lines", String(lines)];
|
|
174
|
-
if (follow)
|
|
175
|
-
invokeArgs.push("--follow");
|
|
176
|
-
if (flags.booleans.has("--all"))
|
|
177
|
-
invokeArgs.push("--all");
|
|
178
|
-
if (flags.values.has("--tenant")) {
|
|
179
|
-
invokeArgs.push("--tenant", flags.values.get("--tenant"));
|
|
180
|
-
}
|
|
181
|
-
const outcome = follow
|
|
182
|
-
? await handle.invokeStreaming(invokeArgs)
|
|
183
|
-
: await handle.invoke(invokeArgs);
|
|
184
|
-
if (outcome.exitCode !== 0) {
|
|
185
|
-
if (outcome.error?.code === "not_found" ||
|
|
186
|
-
/no .*log/i.test(outcome.error?.message ?? outcome.stderr)) {
|
|
187
|
-
throw new CliError(`No Runtime Host log under ${home}. Start one with "nylorun runtime up".`, 3);
|
|
188
|
-
}
|
|
189
|
-
throwOnLauncherFailure(outcome);
|
|
190
|
-
}
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
if (verb === "restart") {
|
|
194
|
-
const flags = parseRuntimeFlags(rest, {
|
|
195
|
-
booleans: ["--allow-downgrade", "--wait", "--force"],
|
|
196
|
-
values: ["--port"],
|
|
197
|
-
});
|
|
198
|
-
if (flags.rest.length)
|
|
199
|
-
throw usageError(runtimeUsage);
|
|
200
|
-
if (flags.booleans.has("--wait") && flags.booleans.has("--force")) {
|
|
201
|
-
throw usageError("Use either --wait or --force, not both.");
|
|
202
|
-
}
|
|
203
|
-
const port = parsePort(flags.values.get("--port"));
|
|
204
|
-
const invokeArgs = ["restart"];
|
|
205
|
-
if (port !== undefined)
|
|
206
|
-
invokeArgs.push("--port", String(port));
|
|
207
|
-
if (flags.booleans.has("--allow-downgrade"))
|
|
208
|
-
invokeArgs.push("--allow-downgrade");
|
|
209
|
-
if (flags.booleans.has("--wait"))
|
|
210
|
-
invokeArgs.push("--wait");
|
|
211
|
-
if (flags.booleans.has("--force"))
|
|
212
|
-
invokeArgs.push("--force");
|
|
213
|
-
const outcome = await handle.invoke(invokeArgs);
|
|
214
|
-
throwOnLauncherFailure(outcome);
|
|
215
|
-
printUpResult(outcome.result ?? {});
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
if (verb === "run") {
|
|
219
|
-
const flags = parseRuntimeFlags(rest, {
|
|
220
|
-
values: ["--port"],
|
|
221
|
-
});
|
|
222
|
-
if (flags.rest.length)
|
|
223
|
-
throw usageError(runtimeUsage);
|
|
224
|
-
const port = parsePort(flags.values.get("--port"));
|
|
225
|
-
const invokeArgs = ["run"];
|
|
226
|
-
if (port !== undefined)
|
|
227
|
-
invokeArgs.push("--port", String(port));
|
|
228
|
-
const outcome = await handle.invokeStreaming(invokeArgs);
|
|
229
|
-
throwOnLauncherFailure(outcome);
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
throw usageError(runtimeUsage);
|
|
233
|
-
}
|
|
234
|
-
function printUpResult(result) {
|
|
235
|
-
const lines = [
|
|
236
|
-
["Host", typeof result.hostId === "string" ? result.hostId : undefined],
|
|
237
|
-
["URL", typeof result.url === "string" ? result.url : undefined],
|
|
238
|
-
[
|
|
239
|
-
"PID",
|
|
240
|
-
typeof result.pid === "number" ? String(result.pid) : undefined,
|
|
241
|
-
],
|
|
242
|
-
[
|
|
243
|
-
"Version",
|
|
244
|
-
typeof result.version === "string" ? result.version : undefined,
|
|
245
|
-
],
|
|
246
|
-
[
|
|
247
|
-
"Started",
|
|
248
|
-
result.started === true
|
|
249
|
-
? "yes"
|
|
250
|
-
: result.started === false
|
|
251
|
-
? "already running"
|
|
252
|
-
: undefined,
|
|
253
|
-
],
|
|
254
|
-
];
|
|
255
|
-
const width = Math.max(...lines.map(([label]) => label.length));
|
|
256
|
-
for (const [label, value] of lines) {
|
|
257
|
-
if (value !== undefined)
|
|
258
|
-
console.log(`${label.padEnd(width)} ${value}`);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
function printStatus(result, handle) {
|
|
262
|
-
const lines = [
|
|
263
|
-
["Home", typeof result.home === "string" ? result.home : undefined],
|
|
264
|
-
["State", typeof result.state === "string" ? result.state : undefined],
|
|
265
|
-
["Host", typeof result.hostId === "string" ? result.hostId : undefined],
|
|
266
|
-
["URL", typeof result.url === "string" ? result.url : undefined],
|
|
267
|
-
[
|
|
268
|
-
"PID",
|
|
269
|
-
typeof result.pid === "number" ? String(result.pid) : undefined,
|
|
270
|
-
],
|
|
271
|
-
[
|
|
272
|
-
"Version",
|
|
273
|
-
typeof result.version === "string" ? result.version : undefined,
|
|
274
|
-
],
|
|
275
|
-
[
|
|
276
|
-
"Last started",
|
|
277
|
-
typeof result.runtimeVersion === "string"
|
|
278
|
-
? result.runtimeVersion
|
|
279
|
-
: undefined,
|
|
280
|
-
],
|
|
281
|
-
["Installed", `${handle.runtime.version} (${handle.runtime.bin})`],
|
|
282
|
-
["Node", handle.runtime.node],
|
|
283
|
-
["Recommended", runtimeVersion()],
|
|
284
|
-
];
|
|
285
|
-
const width = Math.max(...lines.map(([label]) => label.length));
|
|
286
|
-
for (const [label, value] of lines) {
|
|
287
|
-
if (value !== undefined)
|
|
288
|
-
console.log(`${label.padEnd(width)} ${value}`);
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
export { runtimeVersion } from "./version.js";
|
|
292
|
-
export { launcher } from "./launcher.js";
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { createAdmin as defaultCreateAdmin } from "@nylorun/admin";
|
|
2
|
-
import type { Admin } from "@nylorun/admin";
|
|
3
|
-
import { type LauncherOptions } from "./launcher.js";
|
|
4
|
-
export interface EphemeralOptions extends LauncherOptions {
|
|
5
|
-
/** Temporary Host root. Default: a new directory under os.tmpdir(). */
|
|
6
|
-
home?: string;
|
|
7
|
-
/** Tenant display name. Default: directory basename or "ephemeral". */
|
|
8
|
-
name?: string;
|
|
9
|
-
/** Injected Admin factory (tests). Default: `@nylorun/admin` createAdmin. */
|
|
10
|
-
createAdmin?: typeof defaultCreateAdmin;
|
|
11
|
-
/** Abort / cleanup signal (tests and SIGINT wiring). */
|
|
12
|
-
signal?: AbortSignal;
|
|
13
|
-
}
|
|
14
|
-
export interface EphemeralTenant {
|
|
15
|
-
id: string;
|
|
16
|
-
name: string;
|
|
17
|
-
}
|
|
18
|
-
export interface EphemeralRuntime {
|
|
19
|
-
home: string;
|
|
20
|
-
url: string;
|
|
21
|
-
hostId: string;
|
|
22
|
-
version: string;
|
|
23
|
-
tenant: EphemeralTenant;
|
|
24
|
-
applicationKey: string;
|
|
25
|
-
admin: Admin;
|
|
26
|
-
/** Stop the Host and delete the temporary home. */
|
|
27
|
-
close(): Promise<void>;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* `nylorun dev --ephemeral` Host setup (D§12):
|
|
31
|
-
* temporary home, start Host on port 0, `createAdmin({ home })`, `createTenant`.
|
|
32
|
-
*
|
|
33
|
-
* Uses launcher `up --port 0` (detached Host) rather than foreground `run`, so
|
|
34
|
-
* the CLI can continue with Project setup / tsx watch and still `down` on exit.
|
|
35
|
-
* Semantically matches D§12: temporary home, free port, createTenant, cleanup.
|
|
36
|
-
*/
|
|
37
|
-
export declare function startEphemeral(options?: EphemeralOptions): Promise<EphemeralRuntime>;
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { mkdtemp, rm } from "node:fs/promises";
|
|
2
|
-
import { tmpdir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { createAdmin as defaultCreateAdmin } from "@nylorun/admin";
|
|
5
|
-
import { CliError } from "../errors.js";
|
|
6
|
-
import { launcher, throwOnLauncherFailure, } from "./launcher.js";
|
|
7
|
-
/**
|
|
8
|
-
* `nylorun dev --ephemeral` Host setup (D§12):
|
|
9
|
-
* temporary home, start Host on port 0, `createAdmin({ home })`, `createTenant`.
|
|
10
|
-
*
|
|
11
|
-
* Uses launcher `up --port 0` (detached Host) rather than foreground `run`, so
|
|
12
|
-
* the CLI can continue with Project setup / tsx watch and still `down` on exit.
|
|
13
|
-
* Semantically matches D§12: temporary home, free port, createTenant, cleanup.
|
|
14
|
-
*/
|
|
15
|
-
export async function startEphemeral(options = {}) {
|
|
16
|
-
const home = options.home ??
|
|
17
|
-
(await mkdtemp(join(tmpdir(), "nylorun-ephemeral-")));
|
|
18
|
-
const createAdminFn = options.createAdmin ?? defaultCreateAdmin;
|
|
19
|
-
const env = options.env ?? process.env;
|
|
20
|
-
const handle = await launcher(home, { env });
|
|
21
|
-
const up = await handle.invoke(["up", "--port", "0"], { env });
|
|
22
|
-
throwOnLauncherFailure(up);
|
|
23
|
-
const result = up.result ?? {};
|
|
24
|
-
const url = typeof result.url === "string" ? result.url : undefined;
|
|
25
|
-
if (!url) {
|
|
26
|
-
throw new CliError(`Ephemeral Runtime Host started without a URL under ${home}.`, 7);
|
|
27
|
-
}
|
|
28
|
-
const ready = {
|
|
29
|
-
url,
|
|
30
|
-
hostId: typeof result.hostId === "string" ? result.hostId : "host_unknown",
|
|
31
|
-
version: typeof result.version === "string"
|
|
32
|
-
? result.version
|
|
33
|
-
: handle.runtime.version,
|
|
34
|
-
};
|
|
35
|
-
const admin = createAdminFn({ home });
|
|
36
|
-
const name = options.name ??
|
|
37
|
-
home.split(/[/\\]/).filter(Boolean).pop() ??
|
|
38
|
-
"ephemeral";
|
|
39
|
-
const created = await admin.createTenant({ name });
|
|
40
|
-
const tenant = {
|
|
41
|
-
id: created.tenant.id,
|
|
42
|
-
name: created.tenant.name ?? name,
|
|
43
|
-
};
|
|
44
|
-
let closed = false;
|
|
45
|
-
let closing;
|
|
46
|
-
const close = async () => {
|
|
47
|
-
if (closing)
|
|
48
|
-
return closing;
|
|
49
|
-
closing = (async () => {
|
|
50
|
-
if (closed)
|
|
51
|
-
return;
|
|
52
|
-
closed = true;
|
|
53
|
-
try {
|
|
54
|
-
const down = await handle.invoke(["down", "--force"], { env });
|
|
55
|
-
if (down.exitCode !== 0)
|
|
56
|
-
throwOnLauncherFailure(down);
|
|
57
|
-
}
|
|
58
|
-
catch {
|
|
59
|
-
/* best-effort stop */
|
|
60
|
-
}
|
|
61
|
-
await rm(home, { recursive: true, force: true }).catch(() => undefined);
|
|
62
|
-
})();
|
|
63
|
-
return closing;
|
|
64
|
-
};
|
|
65
|
-
if (options.signal) {
|
|
66
|
-
const onAbort = () => {
|
|
67
|
-
void close();
|
|
68
|
-
};
|
|
69
|
-
if (options.signal.aborted)
|
|
70
|
-
void close();
|
|
71
|
-
else
|
|
72
|
-
options.signal.addEventListener("abort", onAbort, { once: true });
|
|
73
|
-
}
|
|
74
|
-
return {
|
|
75
|
-
home,
|
|
76
|
-
url: ready.url,
|
|
77
|
-
hostId: ready.hostId,
|
|
78
|
-
version: ready.version,
|
|
79
|
-
tenant,
|
|
80
|
-
applicationKey: created.applicationKey,
|
|
81
|
-
admin,
|
|
82
|
-
close,
|
|
83
|
-
};
|
|
84
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ErrorCode } from "@nylorun/agents";
|
|
2
|
-
/**
|
|
3
|
-
* Map launcher error codes (and a few Host states) to Tenants-era CLI exit codes.
|
|
4
|
-
* See cli/README.md exit code table.
|
|
5
|
-
*/
|
|
6
|
-
export declare const LAUNCHER_ERROR_EXIT_CODES: Record<string, number>;
|
|
7
|
-
export declare function exitCodeForLauncherError(code: ErrorCode | string | undefined): number;
|
|
8
|
-
/** `runtime status` when the Host is not running. */
|
|
9
|
-
export declare function exitCodeForStatusState(state: string | undefined): number | undefined;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Map launcher error codes (and a few Host states) to Tenants-era CLI exit codes.
|
|
3
|
-
* See cli/README.md exit code table.
|
|
4
|
-
*/
|
|
5
|
-
export const LAUNCHER_ERROR_EXIT_CODES = {
|
|
6
|
-
foreign_port: 4,
|
|
7
|
-
host_start_failed: 7,
|
|
8
|
-
incompatible_host: 5,
|
|
9
|
-
protocol_unsupported: 5,
|
|
10
|
-
// Everything else falls through to 1.
|
|
11
|
-
platform_unsupported: 1,
|
|
12
|
-
launcher_failed: 1,
|
|
13
|
-
lock_timeout: 1,
|
|
14
|
-
host_unresponsive: 1,
|
|
15
|
-
host_schema_newer: 1,
|
|
16
|
-
host_format_newer: 1,
|
|
17
|
-
downgrade_refused: 1,
|
|
18
|
-
upgrade_failed: 1,
|
|
19
|
-
active_work: 1,
|
|
20
|
-
not_found: 1,
|
|
21
|
-
connection_missing: 1,
|
|
22
|
-
host_rejected: 1,
|
|
23
|
-
origin_rejected: 1,
|
|
24
|
-
unsupported_media_type: 1,
|
|
25
|
-
tenant_conflict: 1,
|
|
26
|
-
};
|
|
27
|
-
export function exitCodeForLauncherError(code) {
|
|
28
|
-
if (!code)
|
|
29
|
-
return 1;
|
|
30
|
-
return LAUNCHER_ERROR_EXIT_CODES[code] ?? 1;
|
|
31
|
-
}
|
|
32
|
-
/** `runtime status` when the Host is not running. */
|
|
33
|
-
export function exitCodeForStatusState(state) {
|
|
34
|
-
if (state === "running")
|
|
35
|
-
return undefined;
|
|
36
|
-
if (state === "foreign-port")
|
|
37
|
-
return 4;
|
|
38
|
-
if (state === "stopped" || state === "absent")
|
|
39
|
-
return 3;
|
|
40
|
-
if (state === "unresponsive")
|
|
41
|
-
return 1;
|
|
42
|
-
return 3;
|
|
43
|
-
}
|
package/dist/runtime/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export { baselineEnv } from "./baseline.js";
|
|
2
|
-
export { runtimeVersion } from "./version.js";
|
|
3
|
-
export { findOnPath, launcher, runtimeInstallCommand, throwOnLauncherFailure, } from "./launcher.js";
|
|
4
|
-
export type { InstalledRuntime, LauncherHandle, LauncherInvokeResult, LauncherJsonEvent, LauncherOptions, } from "./launcher.js";
|
|
5
|
-
export { runtimeCommand, runtimeUsage } from "./commands.js";
|
|
6
|
-
export { startEphemeral } from "./ephemeral.js";
|
|
7
|
-
export type { EphemeralOptions, EphemeralRuntime, EphemeralTenant, } from "./ephemeral.js";
|
|
8
|
-
export { LAUNCHER_ERROR_EXIT_CODES, exitCodeForLauncherError, exitCodeForStatusState, } from "./exit-codes.js";
|
package/dist/runtime/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { baselineEnv } from "./baseline.js";
|
|
2
|
-
export { runtimeVersion } from "./version.js";
|
|
3
|
-
export { findOnPath, launcher, runtimeInstallCommand, throwOnLauncherFailure, } from "./launcher.js";
|
|
4
|
-
export { runtimeCommand, runtimeUsage } from "./commands.js";
|
|
5
|
-
export { startEphemeral } from "./ephemeral.js";
|
|
6
|
-
export { LAUNCHER_ERROR_EXIT_CODES, exitCodeForLauncherError, exitCodeForStatusState, } from "./exit-codes.js";
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { type ProgressEvent } from "./progress.js";
|
|
2
|
-
/** The launcher command `@nylorun/runtime` installs (npm bin). */
|
|
3
|
-
export declare const LAUNCHER_BIN = "nylorun-runtime";
|
|
4
|
-
/** Resolve NYLORUN_HOME, an explicit home, or `~/.nylorun`. */
|
|
5
|
-
export declare function resolveHome(home?: string): string;
|
|
6
|
-
export type LauncherJsonEvent = ProgressEvent | {
|
|
7
|
-
type: "result";
|
|
8
|
-
[field: string]: unknown;
|
|
9
|
-
} | {
|
|
10
|
-
type: "error";
|
|
11
|
-
code: string;
|
|
12
|
-
message: string;
|
|
13
|
-
remedy: string;
|
|
14
|
-
details?: unknown;
|
|
15
|
-
} | {
|
|
16
|
-
type: "log";
|
|
17
|
-
source: "host" | "tenant";
|
|
18
|
-
tenantId?: string;
|
|
19
|
-
line: string;
|
|
20
|
-
};
|
|
21
|
-
export interface LauncherInvokeResult {
|
|
22
|
-
events: LauncherJsonEvent[];
|
|
23
|
-
result?: Record<string, unknown>;
|
|
24
|
-
error?: {
|
|
25
|
-
code: string;
|
|
26
|
-
message: string;
|
|
27
|
-
remedy: string;
|
|
28
|
-
details?: unknown;
|
|
29
|
-
};
|
|
30
|
-
exitCode: number;
|
|
31
|
-
/** Raw stdout (NDJSON). */
|
|
32
|
-
stdout: string;
|
|
33
|
-
stderr: string;
|
|
34
|
-
}
|
|
35
|
-
/** The installed Runtime a handle runs, as its `version` command reports it. */
|
|
36
|
-
export interface InstalledRuntime {
|
|
37
|
-
/** `nylorun-runtime` found on PATH. */
|
|
38
|
-
readonly bin: string;
|
|
39
|
-
readonly version: string;
|
|
40
|
-
/** Node the Runtime reported (the Host runs on the same Node). */
|
|
41
|
-
readonly node: string;
|
|
42
|
-
}
|
|
43
|
-
export interface LauncherHandle {
|
|
44
|
-
readonly home: string;
|
|
45
|
-
readonly runtime: InstalledRuntime;
|
|
46
|
-
/**
|
|
47
|
-
* Run a launcher command with `--json --home`. Progress events are rendered
|
|
48
|
-
* to stderr by default. Returns parsed events and the process exit code.
|
|
49
|
-
*/
|
|
50
|
-
invoke(args: readonly string[], options?: InvokeOptions): Promise<LauncherInvokeResult>;
|
|
51
|
-
/**
|
|
52
|
-
* Long-running invoke (e.g. `run`, `logs --follow`). Resolves when the
|
|
53
|
-
* child exits; streams progress/log events as they arrive.
|
|
54
|
-
*/
|
|
55
|
-
invokeStreaming(args: readonly string[], options?: InvokeOptions): Promise<LauncherInvokeResult>;
|
|
56
|
-
}
|
|
57
|
-
export interface InvokeOptions {
|
|
58
|
-
env?: NodeJS.ProcessEnv;
|
|
59
|
-
onEvent?: (event: LauncherJsonEvent) => void;
|
|
60
|
-
/** When false, skip default progress rendering. Default true. */
|
|
61
|
-
renderProgress?: boolean;
|
|
62
|
-
signal?: AbortSignal;
|
|
63
|
-
}
|
|
64
|
-
export interface LauncherOptions {
|
|
65
|
-
/** Environment for the launcher, including the PATH it is found on. */
|
|
66
|
-
env?: NodeJS.ProcessEnv;
|
|
67
|
-
}
|
|
68
|
-
/** Install command shown whenever the Runtime is missing or incompatible. */
|
|
69
|
-
export declare function runtimeInstallCommand(): string;
|
|
70
|
-
/** Find `name` on PATH (with PATHEXT on Windows). */
|
|
71
|
-
export declare function findOnPath(name: string, env: NodeJS.ProcessEnv): string | undefined;
|
|
72
|
-
/**
|
|
73
|
-
* Find the installed Runtime's launcher on PATH and check it speaks this CLI's
|
|
74
|
-
* launcher and Host protocols. Never downloads or installs anything: a missing
|
|
75
|
-
* Runtime is a prerequisite error that names the install command.
|
|
76
|
-
*/
|
|
77
|
-
export declare function launcher(home: string, options?: LauncherOptions): Promise<LauncherHandle>;
|
|
78
|
-
/**
|
|
79
|
-
* Throw CliError with the Tenants-era exit code for a failed launcher invoke.
|
|
80
|
-
*/
|
|
81
|
-
export declare function throwOnLauncherFailure(outcome: LauncherInvokeResult): void;
|