@infosupport/huddle-cli 0.0.0-experiment-109.59.1 → 0.0.0-experiment-109.61.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/node.js +85 -11
- package/package.json +5 -5
package/dist/node.js
CHANGED
|
@@ -64,17 +64,34 @@ function platformNodePackageName(platform = process.platform, arch = process.arc
|
|
|
64
64
|
const target = `${platform}-${arch}`;
|
|
65
65
|
return supported.has(target) ? `@infosupport/huddle-node-${target}` : null;
|
|
66
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* The path segments under a package's bin/ directory where the built
|
|
69
|
+
* executable lives. It stays named `huddle-node` on every platform — nothing
|
|
70
|
+
* that spawns or searches for it should care what a human looking at a
|
|
71
|
+
* process list sees — with one exception: a bare Unix executable has nowhere
|
|
72
|
+
* to carry a "friendly name" at all, so the only way macOS's Finder/Activity
|
|
73
|
+
* Monitor/Dock show one is the bundle wrapping it, not the binary itself
|
|
74
|
+
* (gateway/scripts/build-sea.mjs step 9). Windows gets its friendly name a
|
|
75
|
+
* different way — a rewritten PE version resource, same step 7b, no path
|
|
76
|
+
* change — which is why it isn't singled out here too.
|
|
77
|
+
*/
|
|
78
|
+
function nodeBinSubpath(platform) {
|
|
79
|
+
if (platform === 'win32')
|
|
80
|
+
return ['huddle-node.exe'];
|
|
81
|
+
if (platform === 'darwin')
|
|
82
|
+
return ['Huddle.app', 'Contents', 'MacOS', 'huddle-node'];
|
|
83
|
+
return ['huddle-node'];
|
|
84
|
+
}
|
|
67
85
|
function installedNodeEntry(cliDir, platform = process.platform, arch = process.arch) {
|
|
68
86
|
const pkg = platformNodePackageName(platform, arch);
|
|
69
87
|
if (!pkg)
|
|
70
88
|
return null;
|
|
71
|
-
const executable = platform === 'win32' ? 'huddle-node.exe' : 'huddle-node';
|
|
72
89
|
try {
|
|
73
90
|
// `npm install -g` may hoist optional dependencies beside the CLI package,
|
|
74
91
|
// while a regular install commonly nests them below it. Node's resolver
|
|
75
92
|
// knows both layouts; a hard-coded `cli/node_modules` path does not.
|
|
76
93
|
const manifest = require.resolve(`${pkg}/package.json`, { paths: [path_1.default.resolve(cliDir, '..')] });
|
|
77
|
-
const entry = path_1.default.join(path_1.default.dirname(manifest), 'bin',
|
|
94
|
+
const entry = path_1.default.join(path_1.default.dirname(manifest), 'bin', ...nodeBinSubpath(platform));
|
|
78
95
|
return fs_1.default.existsSync(entry) ? entry : null;
|
|
79
96
|
}
|
|
80
97
|
catch {
|
|
@@ -94,7 +111,7 @@ function explicitNodeEntry(opts, env = process.env) {
|
|
|
94
111
|
function nodeEntryCandidates(cliDir) {
|
|
95
112
|
// A repo checkout: cli/dist/index.js → ../../gateway/dist/index.js, and the
|
|
96
113
|
// same one level up for layouts that nest the build one deeper.
|
|
97
|
-
const
|
|
114
|
+
const platform = process.platform;
|
|
98
115
|
const candidates = [
|
|
99
116
|
path_1.default.resolve(cliDir, '..', '..', 'gateway', 'dist', 'index.js'),
|
|
100
117
|
path_1.default.resolve(cliDir, '..', '..', '..', 'gateway', 'dist', 'index.js'),
|
|
@@ -102,14 +119,20 @@ function nodeEntryCandidates(cliDir) {
|
|
|
102
119
|
// hand. Last, so a checkout keeps winning over a stale download when both
|
|
103
120
|
// exist — the layout of someone working ON Huddle, whose build is the one
|
|
104
121
|
// they mean.
|
|
105
|
-
path_1.default.resolve(cliDir, '..', '..', 'gateway', 'build', 'sea',
|
|
122
|
+
path_1.default.resolve(cliDir, '..', '..', 'gateway', 'build', 'sea', ...nodeBinSubpath(platform)),
|
|
106
123
|
];
|
|
107
124
|
// A checkout takes precedence so contributors always run the code they just
|
|
108
125
|
// built. Installed CLI packages have no checkout sibling and take this path.
|
|
109
126
|
const installed = installedNodeEntry(cliDir);
|
|
110
127
|
if (installed)
|
|
111
128
|
candidates.push(installed);
|
|
112
|
-
candidates.push(path_1.default.join(os_1.default.homedir(), '.huddle',
|
|
129
|
+
candidates.push(path_1.default.join(os_1.default.homedir(), '.huddle', ...nodeBinSubpath(platform)));
|
|
130
|
+
// macOS-only fallback: the flat, unwrapped path this resolved to before the
|
|
131
|
+
// Huddle.app bundle (build-sea.mjs step 9) existed. Kept so a build or a
|
|
132
|
+
// hand-dropped copy from before that change keeps resolving after an
|
|
133
|
+
// upgrade.
|
|
134
|
+
if (platform === 'darwin')
|
|
135
|
+
candidates.push(path_1.default.join(os_1.default.homedir(), '.huddle', 'huddle-node'));
|
|
113
136
|
return candidates;
|
|
114
137
|
}
|
|
115
138
|
/**
|
|
@@ -232,6 +255,42 @@ function readGatewayToken(dataDir) {
|
|
|
232
255
|
` Stop it and re-run: the pid is in ${exports.NODE_PID_FILE}.`);
|
|
233
256
|
}
|
|
234
257
|
}
|
|
258
|
+
/**
|
|
259
|
+
* Waits for the just-spawned Node to answer, then prints the same auto-login
|
|
260
|
+
* link `huddle init` prints — same idea as init's verifyControlChannel-style
|
|
261
|
+
* probing, just against the portal instead of the control channel. Silent on
|
|
262
|
+
* timeout: if Node never comes up, runNode()'s own child 'error'/'exit'
|
|
263
|
+
* handlers already say why, and printing "couldn't find a token" on top of
|
|
264
|
+
* that would just be noise.
|
|
265
|
+
*/
|
|
266
|
+
async function printLoginLinkWhenReady(dataDir, port) {
|
|
267
|
+
const deadline = Date.now() + 20_000;
|
|
268
|
+
while (Date.now() < deadline) {
|
|
269
|
+
for (const url of nodeProbeUrls(port)) {
|
|
270
|
+
try {
|
|
271
|
+
// Any response at all — even 401/500 — proves the API is accepting
|
|
272
|
+
// connections, which is all this needs to know before it goes looking
|
|
273
|
+
// for the token file Node writes at the same point in its own boot.
|
|
274
|
+
await fetch(`${url}/api/auth/status`, { signal: AbortSignal.timeout(1000) });
|
|
275
|
+
const token = readOperatorToken(dataDir);
|
|
276
|
+
if (!token)
|
|
277
|
+
return; // up, but no token file — nothing to offer
|
|
278
|
+
console.log('');
|
|
279
|
+
console.log((0, utils_1.bold)('Open the portal (auto-login link):'));
|
|
280
|
+
console.log((0, utils_1.green)(` ${nodeUrl(port)}/?token=${encodeURIComponent(token)}`));
|
|
281
|
+
console.log((0, utils_1.dim)(' Opens the portal and logs you in automatically.'));
|
|
282
|
+
console.log((0, utils_1.dim)(` Manual token (if you prefer to paste it): ${token}`));
|
|
283
|
+
console.log('');
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
catch {
|
|
287
|
+
// Not up yet on this address, or this address doesn't answer at all
|
|
288
|
+
// (e.g. the ::1 literal on a v4-only host) — try the next one/retry.
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
235
294
|
async function runNode(opts = {}) {
|
|
236
295
|
let entry;
|
|
237
296
|
try {
|
|
@@ -272,6 +331,17 @@ async function runNode(opts = {}) {
|
|
|
272
331
|
console.log((0, utils_1.yellow)(' The firewall still lives in huddle-gateway; this process does not enforce it.'));
|
|
273
332
|
console.log((0, utils_1.dim)(' Ctrl-C to stop.'));
|
|
274
333
|
console.log('');
|
|
334
|
+
// `huddle init` prints an auto-login link once startNodeDetached() confirms
|
|
335
|
+
// Node is up (it can, because it awaits that probe before returning). This
|
|
336
|
+
// command never had an equivalent: it launches the child and immediately
|
|
337
|
+
// awaits its exit, so there was no point after "boot" and before "the
|
|
338
|
+
// process ends" to print anything — an operator running `huddle node` bare
|
|
339
|
+
// got dropped at the portal's login screen with no way to know the token
|
|
340
|
+
// short of digging it out of the data dir by hand. Fixed by polling
|
|
341
|
+
// alongside the awaited exit below, not instead of it: this only reads a
|
|
342
|
+
// token already on disk, it never blocks the child or changes when this
|
|
343
|
+
// function returns.
|
|
344
|
+
void printLoginLinkWhenReady(nodeDataDir(opts, env), port);
|
|
275
345
|
// Foreground on purpose: this is the shape you want while working ON Huddle.
|
|
276
346
|
// `huddle init` uses startNodeDetached() below. stdio inherit so Huddle Node's
|
|
277
347
|
// own logging is what the operator sees.
|
|
@@ -513,12 +583,6 @@ async function startNodeDetached(opts = {}) {
|
|
|
513
583
|
const env = nodeEnv(opts);
|
|
514
584
|
const port = env.HUDDLE_API_PORT ?? String(exports.DEFAULT_NODE_PORT);
|
|
515
585
|
const requestedControlHost = normalizeControlHost(opts.controlHost);
|
|
516
|
-
// Resolved before anything is stopped: if the replacement build can't be
|
|
517
|
-
// found, a mismatched-host Node below should be left running rather than
|
|
518
|
-
// killed and not replaced.
|
|
519
|
-
const entry = resolveNodeEntry(opts, __dirname);
|
|
520
|
-
if (!entry)
|
|
521
|
-
throw new MissingNodeEntryError(nodeEntryCandidates(__dirname)[0]);
|
|
522
586
|
if (await pingNode(port)) {
|
|
523
587
|
// A 200 on the port alone is not proof it's Huddle Node: /api/auth/status
|
|
524
588
|
// is deliberately unauthenticated (so the portal can ask "do I need to log
|
|
@@ -540,6 +604,13 @@ async function startNodeDetached(opts = {}) {
|
|
|
540
604
|
if (runningControlHost === requestedControlHost) {
|
|
541
605
|
return { pid: readNodePid() ?? 0, entry: '(already running)', port, reused: true };
|
|
542
606
|
}
|
|
607
|
+
// Resolve before stopping: a mismatched Node must stay up when the CLI no
|
|
608
|
+
// longer has a local build to replace it with. Keeping this after the
|
|
609
|
+
// reuse path also lets a thin CLI reuse the Node it started earlier even
|
|
610
|
+
// when its optional platform package has since been removed.
|
|
611
|
+
const replacement = resolveNodeEntry(opts, __dirname);
|
|
612
|
+
if (!replacement)
|
|
613
|
+
throw new MissingNodeEntryError(nodeEntryCandidates(__dirname)[0]);
|
|
543
614
|
// Bound to a different control host than asked for: stop it and fall
|
|
544
615
|
// through to spawn a fresh one on the requested host, rather than silently
|
|
545
616
|
// reusing a process the gateway would never actually be able to reach.
|
|
@@ -549,6 +620,9 @@ async function startNodeDetached(opts = {}) {
|
|
|
549
620
|
` Stop it manually (pid in ${exports.NODE_PID_FILE}) and re-run.`);
|
|
550
621
|
}
|
|
551
622
|
}
|
|
623
|
+
const entry = resolveNodeEntry(opts, __dirname);
|
|
624
|
+
if (!entry)
|
|
625
|
+
throw new MissingNodeEntryError(nodeEntryCandidates(__dirname)[0]);
|
|
552
626
|
fs_1.default.mkdirSync(config_1.CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
553
627
|
fs_1.default.mkdirSync(nodeDataDir(opts), { recursive: true, mode: 0o700 });
|
|
554
628
|
// Append, not truncate: the log of the run that just failed is usually the
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@infosupport/huddle-cli",
|
|
3
|
-
"version": "0.0.0-experiment-109.
|
|
3
|
+
"version": "0.0.0-experiment-109.61.1",
|
|
4
4
|
"description": "Huddle CLI — start devcontainers and manage firewall rules",
|
|
5
5
|
"license": "GPL-3.0-or-later",
|
|
6
6
|
"author": "Info Support B.V.",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"node": ">=18"
|
|
33
33
|
},
|
|
34
34
|
"optionalDependencies": {
|
|
35
|
-
"@infosupport/huddle-node-darwin-arm64": "0.0.0-experiment-109.
|
|
36
|
-
"@infosupport/huddle-node-darwin-x64": "0.0.0-experiment-109.
|
|
37
|
-
"@infosupport/huddle-node-linux-x64": "0.0.0-experiment-109.
|
|
38
|
-
"@infosupport/huddle-node-win32-x64": "0.0.0-experiment-109.
|
|
35
|
+
"@infosupport/huddle-node-darwin-arm64": "0.0.0-experiment-109.61.1",
|
|
36
|
+
"@infosupport/huddle-node-darwin-x64": "0.0.0-experiment-109.61.1",
|
|
37
|
+
"@infosupport/huddle-node-linux-x64": "0.0.0-experiment-109.61.1",
|
|
38
|
+
"@infosupport/huddle-node-win32-x64": "0.0.0-experiment-109.61.1"
|
|
39
39
|
},
|
|
40
40
|
"files": [
|
|
41
41
|
"dist"
|