tunneld 0.1.73 → 0.1.77
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 +8 -6
- package/npm-shrinkwrap.json +18 -18
- package/package.json +5 -5
- package/v1/v1.cjs +189 -79
package/README.md
CHANGED
|
@@ -234,15 +234,17 @@ Every flag and variable in full: [docs/reference.md](./docs/reference.md#flags).
|
|
|
234
234
|
### In the background
|
|
235
235
|
|
|
236
236
|
Under `npx`, `-d` as the first word detaches: the addresses print, the prompt
|
|
237
|
-
comes back, and the tunnel stays up
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
237
|
+
comes back, and the tunnel stays up; run again, it hands back the run
|
|
238
|
+
already going. `npx tunneld -k` ends every tunneld run on the machine,
|
|
239
|
+
detached or not, the way Ctrl+C would, and `-k<pid>` ends just that one.
|
|
240
|
+
`npx tunneld -l` lists them. All three belong to the npm launcher, not to
|
|
241
|
+
tunneld, and aren't available on Windows yet.
|
|
241
242
|
|
|
242
243
|
```sh
|
|
243
244
|
npx tunneld -d :3000 claude
|
|
244
|
-
npx tunneld -
|
|
245
|
-
npx tunneld -
|
|
245
|
+
npx tunneld -l
|
|
246
|
+
npx tunneld -k73146 # end the run with pid 73146
|
|
247
|
+
npx tunneld -k # end every run
|
|
246
248
|
```
|
|
247
249
|
|
|
248
250
|
The launcher also refuses a line that could mean two things:
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tunneld",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.77",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "tunneld",
|
|
9
|
-
"version": "0.1.
|
|
9
|
+
"version": "0.1.77",
|
|
10
10
|
"license": "FSL-1.1-MIT",
|
|
11
11
|
"bin": {
|
|
12
12
|
"tunneld": "v1/v1.cjs"
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
"node": ">=20"
|
|
16
16
|
},
|
|
17
17
|
"optionalDependencies": {
|
|
18
|
-
"@tunnel-pizza/tunneld-darwin-arm64": "0.1.
|
|
19
|
-
"@tunnel-pizza/tunneld-darwin-x64": "0.1.
|
|
20
|
-
"@tunnel-pizza/tunneld-linux-arm64": "0.1.
|
|
21
|
-
"@tunnel-pizza/tunneld-linux-x64": "0.1.
|
|
18
|
+
"@tunnel-pizza/tunneld-darwin-arm64": "0.1.77",
|
|
19
|
+
"@tunnel-pizza/tunneld-darwin-x64": "0.1.77",
|
|
20
|
+
"@tunnel-pizza/tunneld-linux-arm64": "0.1.77",
|
|
21
|
+
"@tunnel-pizza/tunneld-linux-x64": "0.1.77"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"@opencode/plugin": "^2.0.32"
|
|
@@ -30,9 +30,9 @@
|
|
|
30
30
|
}
|
|
31
31
|
},
|
|
32
32
|
"node_modules/@tunnel-pizza/tunneld-darwin-arm64": {
|
|
33
|
-
"version": "0.1.
|
|
34
|
-
"resolved": "https://registry.npmjs.org/@tunnel-pizza/tunneld-darwin-arm64/-/tunneld-darwin-arm64-0.1.
|
|
35
|
-
"integrity": "sha512-
|
|
33
|
+
"version": "0.1.77",
|
|
34
|
+
"resolved": "https://registry.npmjs.org/@tunnel-pizza/tunneld-darwin-arm64/-/tunneld-darwin-arm64-0.1.77.tgz",
|
|
35
|
+
"integrity": "sha512-FceukRm0i7u1jwXesTgVzKrmNGfPh1Y9rUv4DIv0C5KKO16L3X7xaF7VeFIqUUn728q9o8ycgHqS6itK4dOnJA==",
|
|
36
36
|
"cpu": [
|
|
37
37
|
"arm64"
|
|
38
38
|
],
|
|
@@ -43,9 +43,9 @@
|
|
|
43
43
|
]
|
|
44
44
|
},
|
|
45
45
|
"node_modules/@tunnel-pizza/tunneld-darwin-x64": {
|
|
46
|
-
"version": "0.1.
|
|
47
|
-
"resolved": "https://registry.npmjs.org/@tunnel-pizza/tunneld-darwin-x64/-/tunneld-darwin-x64-0.1.
|
|
48
|
-
"integrity": "sha512-
|
|
46
|
+
"version": "0.1.77",
|
|
47
|
+
"resolved": "https://registry.npmjs.org/@tunnel-pizza/tunneld-darwin-x64/-/tunneld-darwin-x64-0.1.77.tgz",
|
|
48
|
+
"integrity": "sha512-AU31bzJ3W6JEMuu0Q1tZcmi4Efo/znHXh4/HDWV9Av/zp3az/gy4JUqPF1rpdn/AvcZMslFmcqwbwzsJr5gRzA==",
|
|
49
49
|
"cpu": [
|
|
50
50
|
"x64"
|
|
51
51
|
],
|
|
@@ -56,9 +56,9 @@
|
|
|
56
56
|
]
|
|
57
57
|
},
|
|
58
58
|
"node_modules/@tunnel-pizza/tunneld-linux-arm64": {
|
|
59
|
-
"version": "0.1.
|
|
60
|
-
"resolved": "https://registry.npmjs.org/@tunnel-pizza/tunneld-linux-arm64/-/tunneld-linux-arm64-0.1.
|
|
61
|
-
"integrity": "sha512-
|
|
59
|
+
"version": "0.1.77",
|
|
60
|
+
"resolved": "https://registry.npmjs.org/@tunnel-pizza/tunneld-linux-arm64/-/tunneld-linux-arm64-0.1.77.tgz",
|
|
61
|
+
"integrity": "sha512-ZPCMyGmg4tN7ihSUrGCG87DIghUgrRUdHLVfx5POODCUHAlEFUTyy/Uo6X25SKq8TOqjvNVNbjvw/n/rgpL+qg==",
|
|
62
62
|
"cpu": [
|
|
63
63
|
"arm64"
|
|
64
64
|
],
|
|
@@ -69,9 +69,9 @@
|
|
|
69
69
|
]
|
|
70
70
|
},
|
|
71
71
|
"node_modules/@tunnel-pizza/tunneld-linux-x64": {
|
|
72
|
-
"version": "0.1.
|
|
73
|
-
"resolved": "https://registry.npmjs.org/@tunnel-pizza/tunneld-linux-x64/-/tunneld-linux-x64-0.1.
|
|
74
|
-
"integrity": "sha512-
|
|
72
|
+
"version": "0.1.77",
|
|
73
|
+
"resolved": "https://registry.npmjs.org/@tunnel-pizza/tunneld-linux-x64/-/tunneld-linux-x64-0.1.77.tgz",
|
|
74
|
+
"integrity": "sha512-v4IGOVYWRcn7UqFT8qPUk/aVYO10DoQOoWXEtsXhPbyqVWzVs5EuxrxwNnexOm93oW9ZobJL2oUTU6i5YqIG2A==",
|
|
75
75
|
"cpu": [
|
|
76
76
|
"x64"
|
|
77
77
|
],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tunneld",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.77",
|
|
4
4
|
"description": "Slice and share your machine on a public URL: a port, a shell, a coding agent, a container, or your whole workspace. One command, no account.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20"
|
|
@@ -64,9 +64,9 @@
|
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
66
|
"optionalDependencies": {
|
|
67
|
-
"@tunnel-pizza/tunneld-darwin-arm64": "0.1.
|
|
68
|
-
"@tunnel-pizza/tunneld-darwin-x64": "0.1.
|
|
69
|
-
"@tunnel-pizza/tunneld-linux-arm64": "0.1.
|
|
70
|
-
"@tunnel-pizza/tunneld-linux-x64": "0.1.
|
|
67
|
+
"@tunnel-pizza/tunneld-darwin-arm64": "0.1.77",
|
|
68
|
+
"@tunnel-pizza/tunneld-darwin-x64": "0.1.77",
|
|
69
|
+
"@tunnel-pizza/tunneld-linux-arm64": "0.1.77",
|
|
70
|
+
"@tunnel-pizza/tunneld-linux-x64": "0.1.77"
|
|
71
71
|
}
|
|
72
72
|
}
|
package/v1/v1.cjs
CHANGED
|
@@ -33,15 +33,16 @@
|
|
|
33
33
|
// and once it signals that its addresses are out the launcher hands the
|
|
34
34
|
// console back.
|
|
35
35
|
// - `-k`, as the only word, ends every run on the machine, detached or
|
|
36
|
-
// not, the way Ctrl-C would, so the teardown runs
|
|
37
|
-
// each run as a file it holds
|
|
38
|
-
// (v1alpha1/cache), and -k ends whatever
|
|
39
|
-
//
|
|
40
|
-
//
|
|
36
|
+
// not, the way Ctrl-C would, so the teardown runs; `-k<pid>` ends the one
|
|
37
|
+
// run with that pid. The binary registers each run as a file it holds
|
|
38
|
+
// open beside its cached spec (v1alpha1/cache), and -k ends whatever
|
|
39
|
+
// holds one.
|
|
40
|
+
// - `-l`, as the only word, lists every run, a line each.
|
|
41
41
|
//
|
|
42
|
-
//
|
|
43
|
-
// sees the line.
|
|
44
|
-
// user and an npx user never mean
|
|
42
|
+
// One flag at most, read only as the first word and stripped before the
|
|
43
|
+
// binary sees the line. Anything else, -kd included, is the binary's, and it
|
|
44
|
+
// refuses them as unknown flags, so a brew user and an npx user never mean
|
|
45
|
+
// different things by the same flag.
|
|
45
46
|
|
|
46
47
|
const { spawn, execFileSync } = require("child_process");
|
|
47
48
|
const fs = require("fs");
|
|
@@ -70,6 +71,14 @@ const POLL_MS = 50;
|
|
|
70
71
|
// What the binary reads to know a launcher is waiting on it; see detach.
|
|
71
72
|
const NOTIFY_ENV = "TUNNELD_NOTIFY_PID";
|
|
72
73
|
|
|
74
|
+
// The status the binary exits with when another run holds this one's
|
|
75
|
+
// lock. Keep in step with RunningCode in v1/v1.go.
|
|
76
|
+
const RUNNING = 75;
|
|
77
|
+
|
|
78
|
+
// Names fd 3, the pipe a detaching launcher reads a refused run's status
|
|
79
|
+
// from: a line of JSON naming the run holding the lock, { pid, env, log }.
|
|
80
|
+
const STATUS_ENV = "TUNNELD_STATUS_FD";
|
|
81
|
+
|
|
73
82
|
function fail(message) {
|
|
74
83
|
console.error(`${WRAPPER_NAME}: ${message}`);
|
|
75
84
|
process.exit(1);
|
|
@@ -351,7 +360,10 @@ function signum(signal) {
|
|
|
351
360
|
//
|
|
352
361
|
// A detached run that ends first — a bad origin, --help, a mint that fails —
|
|
353
362
|
// has already said so on the caller's streams, and its exit status is passed
|
|
354
|
-
// on, so it fails like a foreground one.
|
|
363
|
+
// on, so it fails like a foreground one. One refused because the same run is
|
|
364
|
+
// already going names that run on the status pipe, fd 3, and that run
|
|
365
|
+
// is handed back instead, the way this one would have been: its addresses on
|
|
366
|
+
// stdout, the summary on stderr, status 0. Ctrl-C while waiting ends the run: it
|
|
355
367
|
// is in a session of its own, where the terminal's Ctrl-C does not reach, and
|
|
356
368
|
// nothing has been handed back yet.
|
|
357
369
|
function start(bin, args, detaching) {
|
|
@@ -371,10 +383,11 @@ function start(bin, args, detaching) {
|
|
|
371
383
|
if (detaching) {
|
|
372
384
|
// Listening before the spawn: unheard, SIGUSR2 would end this process.
|
|
373
385
|
process.on("SIGUSR2", () => {
|
|
374
|
-
child.removeAllListeners("
|
|
386
|
+
child.removeAllListeners("close");
|
|
387
|
+
child.stdio[3].destroy();
|
|
375
388
|
child.unref();
|
|
376
389
|
finish(0);
|
|
377
|
-
process.stderr.write(summary(child.pid));
|
|
390
|
+
process.stderr.write(summary(located(child.pid)));
|
|
378
391
|
});
|
|
379
392
|
}
|
|
380
393
|
for (const signal of signals) {
|
|
@@ -394,19 +407,45 @@ function start(bin, args, detaching) {
|
|
|
394
407
|
detaching
|
|
395
408
|
? {
|
|
396
409
|
detached: true,
|
|
397
|
-
stdio: ["ignore", "inherit", "inherit"],
|
|
398
|
-
env: { ...process.env, [NOTIFY_ENV]: String(process.pid) },
|
|
410
|
+
stdio: ["ignore", "inherit", "inherit", "pipe"],
|
|
411
|
+
env: { ...process.env, [NOTIFY_ENV]: String(process.pid), [STATUS_ENV]: "3" },
|
|
399
412
|
}
|
|
400
413
|
: { stdio: "inherit" },
|
|
401
414
|
);
|
|
402
415
|
child.on("error", (err) => fail(`cannot run ${bin}: ${err.message}`));
|
|
403
|
-
|
|
416
|
+
let status = "";
|
|
417
|
+
if (detaching) {
|
|
418
|
+
child.stdio[3].setEncoding("utf8").on("data", (chunk) => (status += chunk));
|
|
419
|
+
}
|
|
420
|
+
// close rather than exit: it waits for the status pipe to be read.
|
|
421
|
+
child.on("close", (code, signal) => {
|
|
422
|
+
const running = code === RUNNING && parse(status);
|
|
423
|
+
if (running?.pid > 0) {
|
|
424
|
+
finish(0);
|
|
425
|
+
process.stdout.write(addresses(running));
|
|
426
|
+
process.stderr.write(summary(running, true));
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
if (code === RUNNING) {
|
|
430
|
+
console.error(
|
|
431
|
+
`${WRAPPER_NAME}: it is running in the background or another terminal: npx ${WRAPPER_NAME} -k ends it`,
|
|
432
|
+
);
|
|
433
|
+
}
|
|
404
434
|
// Node ignores some signals itself (SIGPIPE), so re-raising is
|
|
405
435
|
// unreliable; report a signal death the way a shell does, 128+signum.
|
|
406
436
|
finish(interrupted ? signum(interrupted) : signal ? signum(signal) : (code ?? 1));
|
|
407
437
|
});
|
|
408
438
|
}
|
|
409
439
|
|
|
440
|
+
// parse is the status a refused run wrote, a line of JSON, or null.
|
|
441
|
+
function parse(text) {
|
|
442
|
+
try {
|
|
443
|
+
return JSON.parse(text);
|
|
444
|
+
} catch {
|
|
445
|
+
return null;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
|
|
410
449
|
// paint wraps text in an ANSI style when stderr is a terminal that wants
|
|
411
450
|
// one: not when it is a file or a pipe, not under NO_COLOR, not on a dumb
|
|
412
451
|
// terminal.
|
|
@@ -489,37 +528,74 @@ function prose(host, origins, columns) {
|
|
|
489
528
|
return wrap(words, Math.max(columns, 24) - 2, " ");
|
|
490
529
|
}
|
|
491
530
|
|
|
492
|
-
//
|
|
493
|
-
//
|
|
494
|
-
//
|
|
495
|
-
|
|
496
|
-
// Read from the files the run keeps beside its spec, which it wrote before
|
|
497
|
-
// signalling: <key>.pid, to find the key by the pid, and <key>.env, the
|
|
498
|
-
// settings the run settled on and the hostname it got. A run under
|
|
499
|
-
// --no-cache writes no .env, and gets what the pid file alone can say; its
|
|
500
|
-
// addresses are on stdout above either way.
|
|
501
|
-
function summary(pid) {
|
|
531
|
+
// located is the run pid is, the way a refused run's status names one: its
|
|
532
|
+
// pid, and the paths of its <key>.env and <key>.log, those that exist. The key
|
|
533
|
+
// is found by the <key>.pid naming the pid.
|
|
534
|
+
function located(pid) {
|
|
502
535
|
const dir = cacheDir();
|
|
503
|
-
|
|
536
|
+
const run = { pid };
|
|
504
537
|
try {
|
|
505
|
-
key = fs
|
|
538
|
+
const key = fs
|
|
506
539
|
.readdirSync(dir)
|
|
507
540
|
.filter((n) => n.endsWith(".pid"))
|
|
508
541
|
.map((n) => path.basename(n, ".pid"))
|
|
509
542
|
.find((k) => read(path.join(dir, `${k}.pid`)).trim() === String(pid));
|
|
543
|
+
for (const ext of key ? ["env", "log"] : []) {
|
|
544
|
+
const file = path.join(dir, `${key}.${ext}`);
|
|
545
|
+
if (fs.existsSync(file)) {
|
|
546
|
+
run[ext] = file;
|
|
547
|
+
}
|
|
548
|
+
}
|
|
510
549
|
} catch {
|
|
511
550
|
// No cache directory: nothing more to say than the pid.
|
|
512
551
|
}
|
|
513
|
-
|
|
552
|
+
return run;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// cached is the settings the run <key> cached in <key>.env: empty when there
|
|
556
|
+
// are none.
|
|
557
|
+
function cached(key) {
|
|
558
|
+
return envFile(read(path.join(cacheDir(), `${key}.env`)));
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
// addresses is what run is printed on stdout, one per line, the way the
|
|
562
|
+
// binary prints them: the panel's address alone when there is a panel,
|
|
563
|
+
// otherwise one per origin, routed by ?n when there is more than one. Empty
|
|
564
|
+
// with no cached settings.
|
|
565
|
+
function addresses(run) {
|
|
566
|
+
const env = run.env ? envFile(read(run.env)) : {};
|
|
567
|
+
const host = env.LIBTUNNEL_HOSTNAME;
|
|
568
|
+
if (!host) {
|
|
569
|
+
return "";
|
|
570
|
+
}
|
|
571
|
+
const base = `https://${host}/`;
|
|
572
|
+
const origins = (env.TUNNELD_ORIGINS || "").split(",").filter(Boolean);
|
|
573
|
+
if (origins.length <= 1 || env.TUNNELD_MULTIVIEW === "true") {
|
|
574
|
+
return `${base}\n`;
|
|
575
|
+
}
|
|
576
|
+
return origins.map((_, i) => `${base}?${i}\n`).join("");
|
|
577
|
+
}
|
|
514
578
|
|
|
515
|
-
|
|
579
|
+
// summary is what a detached run is handed back with: the directory it runs
|
|
580
|
+
// in, its pid and its log, then what it shares and the address each origin
|
|
581
|
+
// answers on. run is { pid, env, log }, as located finds it or a refused
|
|
582
|
+
// run's status names it.
|
|
583
|
+
//
|
|
584
|
+
// Read from <key>.env, the settings the run settled on and the hostname it
|
|
585
|
+
// got, which it writes before signalling. A run under --no-cache writes no
|
|
586
|
+
// .env, and gets what its pid and log alone can say; its addresses are on
|
|
587
|
+
// stdout above either way.
|
|
588
|
+
function summary(run, already = false) {
|
|
589
|
+
const env = run.env ? envFile(read(run.env)) : {};
|
|
590
|
+
|
|
591
|
+
const lines = ["", `${bold(`🍕 tunneld is ${already ? "already" : "now"} running in the background`)}`, ""];
|
|
516
592
|
const row = (name, value) => lines.push(` ${dim(name)} ${value}`);
|
|
517
593
|
if (env.PWD) {
|
|
518
594
|
row("cwd", home(env.PWD));
|
|
519
595
|
}
|
|
520
|
-
row("pid", String(pid));
|
|
521
|
-
if (
|
|
522
|
-
row("log", home(
|
|
596
|
+
row("pid", String(run.pid));
|
|
597
|
+
if (run.log) {
|
|
598
|
+
row("log", home(run.log));
|
|
523
599
|
}
|
|
524
600
|
lines.push("");
|
|
525
601
|
|
|
@@ -615,20 +691,11 @@ function alive(pid) {
|
|
|
615
691
|
}
|
|
616
692
|
}
|
|
617
693
|
|
|
618
|
-
//
|
|
619
|
-
//
|
|
620
|
-
//
|
|
621
|
-
//
|
|
622
|
-
|
|
623
|
-
//
|
|
624
|
-
// A file nobody holds is a run that ended without removing it — kill -9, a
|
|
625
|
-
// crash — and is cleared without a word. One still going after STOP_MS is
|
|
626
|
-
// named and the exit status is 1: it was asked, and asking twice changes
|
|
627
|
-
// nothing, since the binary swallows repeats.
|
|
628
|
-
//
|
|
629
|
-
// then, if given, runs once every run is gone, and not at all if one is
|
|
630
|
-
// still there: -kd starts its run only on a clean slate.
|
|
631
|
-
function kill(then) {
|
|
694
|
+
// runs is every registered run, as { pid, key }, sorted by key: whatever
|
|
695
|
+
// holds a <key>.pid in cacheDir, detached or not, npx or brew. A file nobody
|
|
696
|
+
// holds is a run that ended without removing it — kill -9, a crash — and is
|
|
697
|
+
// cleared without a word.
|
|
698
|
+
function runs() {
|
|
632
699
|
const dir = cacheDir();
|
|
633
700
|
let names = [];
|
|
634
701
|
try {
|
|
@@ -639,8 +706,8 @@ function kill(then) {
|
|
|
639
706
|
}
|
|
640
707
|
}
|
|
641
708
|
|
|
642
|
-
const
|
|
643
|
-
for (const name of names.filter((n) => n.endsWith(".pid"))) {
|
|
709
|
+
const found = [];
|
|
710
|
+
for (const name of names.filter((n) => n.endsWith(".pid")).sort()) {
|
|
644
711
|
const file = path.join(dir, name);
|
|
645
712
|
const pids = holders(file);
|
|
646
713
|
if (pids.length === 0) {
|
|
@@ -648,37 +715,80 @@ function kill(then) {
|
|
|
648
715
|
continue;
|
|
649
716
|
}
|
|
650
717
|
for (const pid of pids) {
|
|
651
|
-
if (
|
|
652
|
-
|
|
653
|
-
}
|
|
654
|
-
try {
|
|
655
|
-
process.kill(pid, "SIGINT");
|
|
656
|
-
} catch (err) {
|
|
657
|
-
console.error(`${WRAPPER_NAME}: cannot stop pid ${pid}: ${err.message}`);
|
|
658
|
-
continue;
|
|
718
|
+
if (!found.some((r) => r.pid === pid)) {
|
|
719
|
+
found.push({ pid, key: path.basename(name, ".pid") });
|
|
659
720
|
}
|
|
660
|
-
runs.push({ pid, key: path.basename(name, ".pid") });
|
|
661
721
|
}
|
|
662
722
|
}
|
|
723
|
+
return found;
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
// list prints every run on stdout, a line each: its pid, then its address,
|
|
727
|
+
// directory and origins from its cached settings, or its key when there are
|
|
728
|
+
// none.
|
|
729
|
+
function list() {
|
|
730
|
+
const found = runs();
|
|
731
|
+
if (found.length === 0) {
|
|
732
|
+
console.error(`${WRAPPER_NAME}: no runs`);
|
|
733
|
+
return;
|
|
734
|
+
}
|
|
735
|
+
const width = Math.max(...found.map((r) => String(r.pid).length));
|
|
736
|
+
for (const { pid, key } of found) {
|
|
737
|
+
const env = cached(key);
|
|
738
|
+
const fields = env.LIBTUNNEL_HOSTNAME
|
|
739
|
+
? [
|
|
740
|
+
`https://${env.LIBTUNNEL_HOSTNAME}/`,
|
|
741
|
+
env.PWD && home(env.PWD),
|
|
742
|
+
(env.TUNNELD_ORIGINS || "").split(",").filter(Boolean).map(label).join(", "),
|
|
743
|
+
]
|
|
744
|
+
: [key];
|
|
745
|
+
console.log([String(pid).padEnd(width), ...fields.filter(Boolean)].join(" "));
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// kill ends every run, or only the one whose pid is only, with SIGINT, which
|
|
750
|
+
// is what Ctrl-C sends a foreground run, so each one tears down the way it
|
|
751
|
+
// would there: the programs its origins started, the attach servers, the
|
|
752
|
+
// tunnel. It signals runs and nothing else, so a pid that is no run is
|
|
753
|
+
// refused rather than signalled. It waits for them to finish, and names each
|
|
754
|
+
// one it stopped.
|
|
755
|
+
//
|
|
756
|
+
// One still going after STOP_MS is named and the exit status is 1: it was
|
|
757
|
+
// asked, and asking twice changes nothing, since the binary swallows repeats.
|
|
758
|
+
function kill(only) {
|
|
759
|
+
const stopping = [];
|
|
760
|
+
for (const run of runs()) {
|
|
761
|
+
if (only && run.pid !== only) {
|
|
762
|
+
continue;
|
|
763
|
+
}
|
|
764
|
+
try {
|
|
765
|
+
process.kill(run.pid, "SIGINT");
|
|
766
|
+
} catch (err) {
|
|
767
|
+
console.error(`${WRAPPER_NAME}: cannot stop pid ${run.pid}: ${err.message}`);
|
|
768
|
+
continue;
|
|
769
|
+
}
|
|
770
|
+
stopping.push(run);
|
|
771
|
+
}
|
|
663
772
|
|
|
664
|
-
if (
|
|
665
|
-
if (
|
|
773
|
+
if (stopping.length === 0) {
|
|
774
|
+
if (only) {
|
|
775
|
+
console.error(`${WRAPPER_NAME}: no run with pid ${only}`);
|
|
776
|
+
process.exitCode = 1;
|
|
777
|
+
} else {
|
|
666
778
|
console.error(`${WRAPPER_NAME}: no runs`);
|
|
667
779
|
}
|
|
668
|
-
then?.();
|
|
669
780
|
return;
|
|
670
781
|
}
|
|
671
782
|
|
|
672
783
|
const deadline = Date.now() + STOP_MS;
|
|
673
784
|
const timer = setInterval(() => {
|
|
674
|
-
for (const r of
|
|
785
|
+
for (const r of stopping.filter((r) => !r.done && !alive(r.pid))) {
|
|
675
786
|
r.done = true;
|
|
676
787
|
console.error(`${WRAPPER_NAME}: stopped pid ${r.pid} (${r.key})`);
|
|
677
788
|
}
|
|
678
|
-
const left =
|
|
789
|
+
const left = stopping.filter((r) => !r.done);
|
|
679
790
|
if (left.length === 0) {
|
|
680
791
|
clearInterval(timer);
|
|
681
|
-
then?.();
|
|
682
792
|
return;
|
|
683
793
|
}
|
|
684
794
|
if (Date.now() > deadline) {
|
|
@@ -691,40 +801,40 @@ function kill(then) {
|
|
|
691
801
|
}, POLL_MS);
|
|
692
802
|
}
|
|
693
803
|
|
|
694
|
-
//
|
|
695
|
-
//
|
|
696
|
-
const
|
|
804
|
+
// FLAG is the launcher's own first word, one at most: -d, -l, -k, or -k with
|
|
805
|
+
// a pid and no space between.
|
|
806
|
+
const FLAG = /^-(?:d|l|k([1-9]\d*)?)$/;
|
|
697
807
|
|
|
698
808
|
function main() {
|
|
699
809
|
const argv = process.argv.slice(2);
|
|
700
|
-
const
|
|
701
|
-
const
|
|
702
|
-
const args =
|
|
810
|
+
const match = FLAG.exec(argv[0] ?? "");
|
|
811
|
+
const flag = match ? argv[0].slice(0, 2) : null;
|
|
812
|
+
const args = match ? argv.slice(1) : argv;
|
|
703
813
|
if (flag) {
|
|
704
814
|
refuseOnWindows(flag);
|
|
705
815
|
}
|
|
706
816
|
|
|
707
|
-
if (
|
|
817
|
+
if (flag === "-k") {
|
|
708
818
|
if (args.length > 0) {
|
|
709
|
-
fail(
|
|
819
|
+
fail("-k takes no arguments: it ends every run, or the one -k<pid> names");
|
|
710
820
|
}
|
|
711
|
-
kill();
|
|
821
|
+
kill(match[1] && Number(match[1]));
|
|
822
|
+
return;
|
|
823
|
+
}
|
|
824
|
+
if (flag === "-l") {
|
|
825
|
+
if (args.length > 0) {
|
|
826
|
+
fail("-l takes no arguments: it lists every run");
|
|
827
|
+
}
|
|
828
|
+
list();
|
|
712
829
|
return;
|
|
713
830
|
}
|
|
714
831
|
|
|
715
|
-
// Refused before anything is ended: -kd with a line that could mean two
|
|
716
|
-
// things should not cost the runs it was going to replace.
|
|
717
832
|
const reading = misread(args);
|
|
718
833
|
if (reading) {
|
|
719
834
|
fail(ambiguous(reading, flag ? `npx ${WRAPPER_NAME} ${flag}` : `npx ${WRAPPER_NAME}`));
|
|
720
835
|
}
|
|
721
836
|
|
|
722
|
-
|
|
723
|
-
if (killing) {
|
|
724
|
-
kill(() => start(bin, args, true));
|
|
725
|
-
} else {
|
|
726
|
-
start(bin, args, detaching);
|
|
727
|
-
}
|
|
837
|
+
start(binaryPath(), args, flag === "-d");
|
|
728
838
|
}
|
|
729
839
|
|
|
730
840
|
if (require.main === module) {
|