tailscale-proxy 0.0.1 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/launcher.js +70 -12
- package/package.json +8 -9
package/bin/launcher.js
CHANGED
|
@@ -1,27 +1,85 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
|
+
// Resolves the native `tsp` binary and execs it. Primary path: the per-platform
|
|
5
|
+
// optionalDependency package (installed automatically by npm). Fallback: download
|
|
6
|
+
// the matching binary from the GitHub release and cache it — so `npx
|
|
7
|
+
// tailscale-proxy` always just works, even if the optional package was skipped.
|
|
8
|
+
|
|
4
9
|
const { spawnSync } = require("node:child_process");
|
|
10
|
+
const fs = require("node:fs");
|
|
11
|
+
const os = require("node:os");
|
|
12
|
+
const path = require("node:path");
|
|
5
13
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
14
|
+
const REPO = "meabed/tailscale-proxy";
|
|
15
|
+
const VERSION = require("../package.json").version;
|
|
16
|
+
|
|
17
|
+
const PLATFORM = process.platform; // 'darwin' | 'linux' | 'win32'
|
|
18
|
+
const ARCH = process.arch; // 'x64' | 'arm64'
|
|
19
|
+
const EXE = PLATFORM === "win32" ? "tsp.exe" : "tsp";
|
|
20
|
+
|
|
21
|
+
// goreleaser archive naming uses Go's GOOS/GOARCH.
|
|
22
|
+
const GOOS = PLATFORM === "win32" ? "windows" : PLATFORM;
|
|
23
|
+
const GOARCH = ARCH === "x64" ? "amd64" : ARCH;
|
|
24
|
+
|
|
25
|
+
function fromOptionalDep() {
|
|
12
26
|
try {
|
|
13
|
-
return require.resolve(
|
|
27
|
+
return require.resolve(`tailscale-proxy-${PLATFORM}-${ARCH}/bin/${EXE}`);
|
|
14
28
|
} catch {
|
|
15
29
|
return null;
|
|
16
30
|
}
|
|
17
31
|
}
|
|
18
32
|
|
|
19
|
-
|
|
20
|
-
|
|
33
|
+
function cacheDir() {
|
|
34
|
+
const base = process.env.XDG_CACHE_HOME || path.join(os.homedir(), ".cache");
|
|
35
|
+
return path.join(base, "tailscale-proxy", `v${VERSION}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function fromCache() {
|
|
39
|
+
const p = path.join(cacheDir(), EXE);
|
|
40
|
+
return fs.existsSync(p) ? p : null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function downloadToCache() {
|
|
44
|
+
const ext = PLATFORM === "win32" ? "zip" : "tar.gz";
|
|
45
|
+
const asset = `tsp_${GOOS}_${GOARCH}.${ext}`;
|
|
46
|
+
const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${asset}`;
|
|
47
|
+
const dir = cacheDir();
|
|
48
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
49
|
+
const archive = path.join(dir, asset);
|
|
50
|
+
|
|
51
|
+
process.stderr.write(`tailscale-proxy: fetching ${asset} (v${VERSION})…\n`);
|
|
52
|
+
const dl = spawnSync("curl", ["-fsSL", "-o", archive, url], { stdio: ["ignore", "ignore", "inherit"] });
|
|
53
|
+
if (dl.status !== 0) {
|
|
54
|
+
throw new Error(`download failed: ${url}`);
|
|
55
|
+
}
|
|
56
|
+
// `tar` extracts both .tar.gz and .zip on macOS/Linux/Windows-10+.
|
|
57
|
+
const ex = spawnSync("tar", ["-xf", archive, "-C", dir], { stdio: ["ignore", "ignore", "inherit"] });
|
|
58
|
+
if (ex.status !== 0) {
|
|
59
|
+
throw new Error(`extract failed: ${archive}`);
|
|
60
|
+
}
|
|
61
|
+
fs.rmSync(archive, { force: true });
|
|
62
|
+
const bin = path.join(dir, EXE);
|
|
63
|
+
if (!fs.existsSync(bin)) {
|
|
64
|
+
throw new Error(`binary ${EXE} not found in ${asset}`);
|
|
65
|
+
}
|
|
66
|
+
fs.chmodSync(bin, 0o755);
|
|
67
|
+
return bin;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function resolveBinary() {
|
|
71
|
+
return fromOptionalDep() || fromCache() || downloadToCache();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let bin;
|
|
75
|
+
try {
|
|
76
|
+
bin = resolveBinary();
|
|
77
|
+
} catch (err) {
|
|
21
78
|
console.error(
|
|
22
|
-
`tailscale-proxy:
|
|
23
|
-
|
|
24
|
-
`
|
|
79
|
+
`tailscale-proxy: could not obtain a binary for ${PLATFORM}-${ARCH} (v${VERSION}).\n` +
|
|
80
|
+
`${err.message}\n` +
|
|
81
|
+
`Install from source instead: go install github.com/${REPO}@latest\n` +
|
|
82
|
+
`Releases: https://github.com/${REPO}/releases`
|
|
25
83
|
);
|
|
26
84
|
process.exit(1);
|
|
27
85
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tailscale-proxy",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Discover local dev servers by port and expose them through one Tailscale Serve/Funnel entry, routed by project name.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"tailscale",
|
|
@@ -71,19 +71,18 @@
|
|
|
71
71
|
"semantic-release": "^25.0.3"
|
|
72
72
|
},
|
|
73
73
|
"optionalDependencies": {
|
|
74
|
-
"tailscale-proxy-darwin-arm64": "0.0
|
|
75
|
-
"tailscale-proxy-darwin-x64": "0.0
|
|
76
|
-
"tailscale-proxy-linux-x64": "0.0
|
|
77
|
-
"tailscale-proxy-linux-arm64": "0.0
|
|
78
|
-
"tailscale-proxy-win32-x64": "0.0
|
|
79
|
-
"tailscale-proxy-win32-arm64": "0.0
|
|
74
|
+
"tailscale-proxy-darwin-arm64": "1.0.0",
|
|
75
|
+
"tailscale-proxy-darwin-x64": "1.0.0",
|
|
76
|
+
"tailscale-proxy-linux-x64": "1.0.0",
|
|
77
|
+
"tailscale-proxy-linux-arm64": "1.0.0",
|
|
78
|
+
"tailscale-proxy-win32-x64": "1.0.0",
|
|
79
|
+
"tailscale-proxy-win32-arm64": "1.0.0"
|
|
80
80
|
},
|
|
81
81
|
"packageManager": "bun@1.3.14",
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">= 18.0"
|
|
84
84
|
},
|
|
85
85
|
"publishConfig": {
|
|
86
|
-
"access": "public"
|
|
87
|
-
"provenance": true
|
|
86
|
+
"access": "public"
|
|
88
87
|
}
|
|
89
88
|
}
|