@tafrahq/wt-tunnel-client 0.7.0 → 0.11.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/README.md CHANGED
@@ -15,17 +15,19 @@ frpc (this worktree) app.feat-x.dev.example.com → http://127.0.0.1:4123
15
15
 
16
16
  ## Install
17
17
 
18
+ The package is published to npm. It needs Node.js 26 or later.
19
+
18
20
  ```sh
19
21
  npm install -g @tafrahq/wt-tunnel-client # or add it as a devDependency
20
22
  ```
21
23
 
22
- The package is on npm from 0.7.0. Earlier versions are on GitHub Packages, which needs a GitHub token to install from.
24
+ To install without a GitHub token, build it from a checkout, as the [root README](https://github.com/tafrahq/wt-tunnel#install) shows.
23
25
 
24
26
  Up to 0.4.0 the client was published as `@tafrahq/wt-tunnel`; from 0.5.0 that name is the server setup CLI, so install `@tafrahq/wt-tunnel-client`.
25
27
 
26
28
  Requirements:
27
29
 
28
- - Node.js 22 or later.
30
+ - Node.js 26 or later.
29
31
  - Linux or macOS, on amd64 or arm64, for the machine that runs the worktrees. Windows is not supported.
30
32
  - A running wt-tunnel server, and its tunnel token.
31
33
 
@@ -160,7 +162,7 @@ The frpc log records each host the server accepted or refused. It is the first p
160
162
 
161
163
  ## Development
162
164
 
163
- This package is `apps/client` in the [wt-tunnel monorepo](https://github.com/tafrahq/wt-tunnel/blob/main/README.md), which describes how to install, check and build it. `pnpm build` here runs tsdown unbundled: one dist file per source file, with the dependencies external. The workspace-only `@tafrahq/wt-tunnel-contract` package is compiled into `dist/`, so it is not a dependency of the published package.
165
+ This package is `apps/client` in the [wt-tunnel monorepo](https://github.com/tafrahq/wt-tunnel/blob/main/README.md), which describes how to install, check and build it. `nub run build` here runs tsdown unbundled: one dist file per source file, with the dependencies external. The workspace-only `@tafrahq/wt-tunnel-contract` package is compiled into `dist/`, so it is not a dependency of the published package.
164
166
 
165
167
  The package ships the built `dist/`, the TypeScript sources in `src/` (source maps point at them), and `llms.txt`, the same layout Effect uses for its packages.
166
168
 
package/dist/bin.js CHANGED
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env node
2
+ import { binProgram } from "./packages/contract/src/bin.js";
2
3
  import { run } from "./cli.js";
3
- import { createRequire } from "node:module";
4
4
  import { NodeRuntime, NodeServices } from "@effect/platform-node";
5
- import { Console, Effect, Schema } from "effect";
5
+ import { Effect } from "effect";
6
6
  // src/bin.ts
7
- const PackageJson = Schema.Struct({ version: Schema.String });
8
- const packageJson = createRequire(import.meta.url)("../package.json");
9
- const program = Schema.decodeUnknownEffect(PackageJson)(packageJson).pipe(Effect.orDie, Effect.flatMap(({ version }) => run(version)), Effect.catchTag("WtTunnelError", ({ message }) => Console.error(`wt-tunnel-client: ${message}`).pipe(Effect.andThen(Effect.sync(() => {
10
- process.exitCode = 1;
11
- })))), Effect.provide(NodeServices.layer));
12
- NodeRuntime.runMain(program);
7
+ const program = binProgram({
8
+ expected: "WtTunnelError",
9
+ name: "wt-tunnel-client",
10
+ url: import.meta.url
11
+ }, run);
12
+ NodeRuntime.runMain(program.pipe(Effect.provide(NodeServices.layer)));
13
13
  export {};
14
14
 
15
15
  //# sourceMappingURL=bin.js.map
package/dist/bin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bin.js","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\nimport { createRequire } from 'node:module';\n\nimport { NodeRuntime, NodeServices } from '@effect/platform-node';\nimport { Console, Effect, Schema } from 'effect';\n\nimport { run } from './cli.ts';\n\nconst PackageJson = Schema.Struct({ version: Schema.String });\nconst packageJson: unknown = createRequire(import.meta.url)('../package.json');\n\nconst program = Schema.decodeUnknownEffect(PackageJson)(packageJson).pipe(\n Effect.orDie,\n Effect.flatMap(({ version }) => run(version)),\n // Expected failures carry a message written for the user; skip the stack trace.\n Effect.catchTag('WtTunnelError', ({ message }: { readonly message: string }) =>\n Console.error(`wt-tunnel-client: ${message}`).pipe(\n Effect.andThen(\n Effect.sync(() => {\n process.exitCode = 1;\n }),\n ),\n ),\n ),\n Effect.provide(NodeServices.layer),\n);\n\nNodeRuntime.runMain(program);\n"],"mappings":";;;;;;AAQA,MAAM,cAAc,OAAO,OAAO,EAAE,SAAS,OAAO,OAAO,CAAC;AAC5D,MAAM,cAAuB,cAAc,YAAY,GAAG,CAAC,CAAC,iBAAiB;AAE7E,MAAM,UAAU,OAAO,oBAAoB,WAAW,CAAC,CAAC,WAAW,CAAC,CAAC,KACnE,OAAO,OACP,OAAO,SAAS,EAAE,cAAc,IAAI,OAAO,CAAC,GAE5C,OAAO,SAAS,kBAAkB,EAAE,cAClC,QAAQ,MAAM,qBAAqB,SAAS,CAAC,CAAC,KAC5C,OAAO,QACL,OAAO,WAAW;CAChB,QAAQ,WAAW;AACrB,CAAC,CACH,CACF,CACF,GACA,OAAO,QAAQ,aAAa,KAAK,CACnC;AAEA,YAAY,QAAQ,OAAO"}
1
+ {"version":3,"file":"bin.js","names":[],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n// fallow-ignore-file coverage-gaps -- only hands cli.ts's run to NodeRuntime; cli.test.ts runs run in-process, and packages/contract/src/bin.test.ts tests binProgram\nimport { NodeRuntime, NodeServices } from '@effect/platform-node';\nimport { binProgram } from '@tafrahq/wt-tunnel-contract/bin';\nimport { Effect } from 'effect';\n\nimport { run } from './cli.ts';\n\nconst program = binProgram(\n { expected: 'WtTunnelError', name: 'wt-tunnel-client', url: import.meta.url },\n run,\n);\n\nNodeRuntime.runMain(program.pipe(Effect.provide(NodeServices.layer)));\n"],"mappings":";;;;;;AAQA,MAAM,UAAU,WACd;CAAE,UAAU;CAAiB,MAAM;CAAoB,KAAK,YAAY;AAAI,GAC5E,GACF;AAEA,YAAY,QAAQ,QAAQ,KAAK,OAAO,QAAQ,aAAa,KAAK,CAAC,CAAC"}
@@ -105,6 +105,6 @@ const pinnedBinary = (pin, destination) => Effect.gen(function* cachedOrDownload
105
105
  tarball
106
106
  });
107
107
  });
108
- export { InstallError, cacheHome, installTarballEntry, pinnedBinary, tarballFor };
108
+ export { cacheHome, installTarballEntry, pinnedBinary, tarballFor };
109
109
 
110
110
  //# sourceMappingURL=install.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"install.js","names":[],"sources":["../../../../../../packages/binaries/src/install.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { access, chmod, mkdir, rename, writeFile } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { basename, dirname, join } from 'node:path';\nimport { promisify } from 'node:util';\nimport { gunzip } from 'node:zlib';\n\nimport { Console, Effect, Schema } from 'effect';\n\n/*\n * The alias stops `unicorn/throw-new-error` from reading this class factory, whose name ends in\n * `Error`, as an error thrown without `new`.\n */\nconst { TaggedError: taggedErrorClass } = Schema;\n\nclass InstallError extends taggedErrorClass<InstallError>()('InstallError', {\n message: Schema.String,\n}) {}\n\n/** A release tarball and the SHA-256 it must have. */\ninterface Tarball {\n readonly sha256: string;\n readonly url: string;\n}\n\n/** One executable at one version, with a tarball per `<process.platform>-<process.arch>`. */\ninterface Pin {\n readonly name: string;\n readonly tarballs: Readonly<Partial<Record<string, Tarball>>>;\n readonly version: string;\n}\n\nconst executableMode = 0o755;\n\nconst tarBlock = 512;\nconst tarName = { end: 100, start: 0 } as const;\nconst tarSize = { end: 136, start: 124 } as const;\nconst tarType = { end: 157, start: 156 } as const;\nconst octal = 8;\n/** Old tar writes NUL, ustar writes '0', for a regular file. */\nconst regularFileTypes: ReadonlySet<string> = new Set(['0', '\\0']);\n\n/** A header block's fields; undefined for the zero block that ends the archive. */\nconst tarHeader = (\n block: Buffer,\n): { readonly path: string; readonly regularFile: boolean; readonly size: number } | undefined => {\n const path = block.toString('utf8', tarName.start, tarName.end).replace(/\\0.*$/su, '');\n const size = Number.parseInt(block.toString('ascii', tarSize.start, tarSize.end).trim(), octal);\n if (path === '' || Number.isNaN(size)) {\n return undefined;\n }\n const regularFile = regularFileTypes.has(block.toString('ascii', tarType.start, tarType.end));\n return { path, regularFile, size };\n};\n\n/**\n * The bytes of the regular file named `name` (in any directory) in a tar archive. Reading the one\n * entry in process means nothing in the archive decides which paths get written.\n */\nconst tarEntry = (archive: Buffer, name: string): Buffer | undefined => {\n let offset = 0;\n while (offset + tarBlock <= archive.length) {\n const header = tarHeader(archive.subarray(offset, offset + tarBlock));\n if (header === undefined) {\n return undefined;\n }\n const data = offset + tarBlock;\n if (header.regularFile && basename(header.path) === name) {\n return archive.subarray(data, data + header.size);\n }\n offset = data + Math.ceil(header.size / tarBlock) * tarBlock;\n }\n return undefined;\n};\n\ntype FetchBytes = (url: string) => Promise<Uint8Array>;\n\nconst fetchBytes: FetchBytes = async (url) => {\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}`);\n }\n return new Uint8Array(await response.arrayBuffer());\n};\n\nconst installFailed = (pin: Pin, message: string) =>\n new InstallError({ message: `Could not install ${pin.name}: ${message}` });\n\n/** The rename is atomic, so a concurrent install sees no file or a complete one. */\nconst placeExecutable = async (destination: string, bytes: Buffer) => {\n await mkdir(dirname(destination), { recursive: true });\n const temp = `${destination}.${process.pid}.tmp`;\n await writeFile(temp, bytes);\n await chmod(temp, executableMode);\n await rename(temp, destination);\n};\n\nconst verifiedDownload = (pin: Pin, tarball: Tarball, download: FetchBytes) =>\n Effect.gen(function* downloadThenHash() {\n yield* Console.log(`Downloading ${pin.name} ${pin.version} from ${tarball.url}`);\n const bytes = yield* Effect.tryPromise({\n catch: (cause) => installFailed(pin, `${tarball.url}: ${String(cause)}`),\n try: () => download(tarball.url),\n });\n const actual = createHash('sha256').update(bytes).digest('hex');\n if (actual !== tarball.sha256) {\n return yield* installFailed(\n pin,\n `${tarball.url} has SHA-256 ${actual}, expected ${tarball.sha256}. Nothing was installed.`,\n );\n }\n return bytes;\n });\n\n/** Where to install from and to. */\ninterface Install {\n readonly destination: string;\n readonly download: FetchBytes;\n readonly tarball: Tarball;\n}\n\n/** Downloads the tarball, checks its SHA-256, and moves only the pinned executable into place. */\nconst installTarballEntry = (pin: Pin, { destination, download, tarball }: Install) =>\n Effect.gen(function* downloadVerifyExtract() {\n const bytes = yield* verifiedDownload(pin, tarball, download);\n const archive = yield* Effect.promise(() => promisify(gunzip)(bytes));\n const executable = tarEntry(archive, pin.name);\n if (executable === undefined) {\n return yield* installFailed(pin, `${tarball.url} holds no ${pin.name}.`);\n }\n yield* Effect.promise(() => placeExecutable(destination, executable));\n return destination;\n });\n\nconst tarballFor = (pin: Pin, platform: string, arch: string) =>\n pin.tarballs[`${platform}-${arch}`];\n\n/** The user's cache directory: `$XDG_CACHE_HOME`, else the platform's usual place. */\nconst cacheHome = () =>\n process.env.XDG_CACHE_HOME ??\n (process.platform === 'darwin'\n ? join(homedir(), 'Library', 'Caches')\n : join(homedir(), '.cache'));\n\nconst exists = (path: string) =>\n Effect.promise(async () => {\n try {\n await access(path);\n return true;\n } catch {\n return false;\n }\n });\n\n/** The executable at `destination`, downloaded there on first use. */\nconst pinnedBinary = (pin: Pin, destination: string) =>\n Effect.gen(function* cachedOrDownload() {\n if (yield* exists(destination)) {\n return destination;\n }\n const tarball = tarballFor(pin, process.platform, process.arch);\n if (tarball === undefined) {\n return yield* installFailed(\n pin,\n `no pinned ${pin.version} build for ${process.platform} ${process.arch}.`,\n );\n }\n return yield* installTarballEntry(pin, { destination, download: fetchBytes, tarball });\n });\n\nexport { cacheHome, InstallError, installTarballEntry, pinnedBinary, tarballFor };\nexport type { FetchBytes, Install, Pin, Tarball };\n"],"mappings":";;;;;;;;AAaA,MAAM,EAAE,aAAa,qBAAqB;AAE1C,IAAM,eAAN,cAA2B,iBAA+B,CAAC,CAAC,gBAAgB,EAC1E,SAAS,OAAO,OAClB,CAAC,CAAC,CAAC,CAAC;AAeJ,MAAM,iBAAiB;AAEvB,MAAM,WAAW;AACjB,MAAM,UAAU;CAAE,KAAK;CAAK,OAAO;AAAE;AACrC,MAAM,UAAU;CAAE,KAAK;CAAK,OAAO;AAAI;AACvC,MAAM,UAAU;CAAE,KAAK;CAA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ClB,KAAK,QAAQ,GAAG,WAAW,QAAQ,IACnC,KAAK,QAAQ,GAAG,QAAQ;AAE9B,MAAM,UAAU,SACd,OAAO,QAAQ,YAAY;CACzB,IAAI;EACF,MAAM,OAAO,IAAI;EACjB,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF,CAAC;;AAGH,MAAM,gBAAgB,KAAU,gBAC9B,OAAO,IAAI,UAAU,mBAAmB;CACtC,IAAI,OAAO,OAAO,WAAW,GAC3B,OAAO;CAET,MAAM,UAAU,WAAW,KAAK,QAAQ,UAAU,QAAQ,IAAI;CAC9D,IAAI,YAAY,KAAA,GACd,OAAO,OAAO,cACZ,KACA,aAAa,IAAI,QAAQ,aAAa,QAAQ,SAAS,GAAG,QAAQ,KAAK,EACzE;CAEF,OAAO,OAAO,oBAAoB,KAAK;EAAE;EAAa,UAAU;EAAY;CAAQ,CAAC;AACvF,CAAC"}
1
+ {"version":3,"file":"install.js","names":[],"sources":["../../../../../../packages/binaries/src/install.ts"],"sourcesContent":["import { createHash } from 'node:crypto';\nimport { access, chmod, mkdir, rename, writeFile } from 'node:fs/promises';\nimport { homedir } from 'node:os';\nimport { basename, dirname, join } from 'node:path';\nimport { promisify } from 'node:util';\nimport { gunzip } from 'node:zlib';\n\nimport { Console, Effect, Schema } from 'effect';\n\n/*\n * The alias stops `unicorn/throw-new-error` from reading this class factory, whose name ends in\n * `Error`, as an error thrown without `new`.\n */\nconst { TaggedError: taggedErrorClass } = Schema;\n\nclass InstallError extends taggedErrorClass<InstallError>()('InstallError', {\n message: Schema.String,\n}) {}\n\n/** A release tarball and the SHA-256 it must have. */\ninterface Tarball {\n readonly sha256: string;\n readonly url: string;\n}\n\n/** One executable at one version, with a tarball per `<process.platform>-<process.arch>`. */\ninterface Pin {\n readonly name: string;\n readonly tarballs: Readonly<Partial<Record<string, Tarball>>>;\n readonly version: string;\n}\n\nconst executableMode = 0o755;\n\nconst tarBlock = 512;\nconst tarName = { end: 100, start: 0 } as const;\nconst tarSize = { end: 136, start: 124 } as const;\nconst tarType = { end: 157, start: 156 } as const;\nconst octal = 8;\n/** Old tar writes NUL, ustar writes '0', for a regular file. */\nconst regularFileTypes: ReadonlySet<string> = new Set(['0', '\\0']);\n\n/** A header block's fields; undefined for the zero block that ends the archive. */\nconst tarHeader = (\n block: Buffer,\n): { readonly path: string; readonly regularFile: boolean; readonly size: number } | undefined => {\n const path = block.toString('utf8', tarName.start, tarName.end).replace(/\\0.*$/su, '');\n const size = Number.parseInt(block.toString('ascii', tarSize.start, tarSize.end).trim(), octal);\n if (path === '' || Number.isNaN(size)) {\n return undefined;\n }\n const regularFile = regularFileTypes.has(block.toString('ascii', tarType.start, tarType.end));\n return { path, regularFile, size };\n};\n\n/**\n * The bytes of the regular file named `name` (in any directory) in a tar archive. Reading the one\n * entry in process means nothing in the archive decides which paths get written.\n */\nconst tarEntry = (archive: Buffer, name: string): Buffer | undefined => {\n let offset = 0;\n while (offset + tarBlock <= archive.length) {\n const header = tarHeader(archive.subarray(offset, offset + tarBlock));\n if (header === undefined) {\n return undefined;\n }\n const data = offset + tarBlock;\n if (header.regularFile && basename(header.path) === name) {\n return archive.subarray(data, data + header.size);\n }\n offset = data + Math.ceil(header.size / tarBlock) * tarBlock;\n }\n return undefined;\n};\n\ntype FetchBytes = (url: string) => Promise<Uint8Array>;\n\nconst fetchBytes: FetchBytes = async (url) => {\n const response = await fetch(url);\n if (!response.ok) {\n throw new Error(`HTTP ${response.status}`);\n }\n return new Uint8Array(await response.arrayBuffer());\n};\n\nconst installFailed = (pin: Pin, message: string) =>\n new InstallError({ message: `Could not install ${pin.name}: ${message}` });\n\n/** The rename is atomic, so a concurrent install sees no file or a complete one. */\nconst placeExecutable = async (destination: string, bytes: Buffer) => {\n await mkdir(dirname(destination), { recursive: true });\n const temp = `${destination}.${process.pid}.tmp`;\n await writeFile(temp, bytes);\n await chmod(temp, executableMode);\n await rename(temp, destination);\n};\n\nconst verifiedDownload = (pin: Pin, tarball: Tarball, download: FetchBytes) =>\n Effect.gen(function* downloadThenHash() {\n yield* Console.log(`Downloading ${pin.name} ${pin.version} from ${tarball.url}`);\n const bytes = yield* Effect.tryPromise({\n catch: (cause) => installFailed(pin, `${tarball.url}: ${String(cause)}`),\n try: () => download(tarball.url),\n });\n const actual = createHash('sha256').update(bytes).digest('hex');\n if (actual !== tarball.sha256) {\n return yield* installFailed(\n pin,\n `${tarball.url} has SHA-256 ${actual}, expected ${tarball.sha256}. Nothing was installed.`,\n );\n }\n return bytes;\n });\n\n/** Where to install from and to. */\ninterface Install {\n readonly destination: string;\n readonly download: FetchBytes;\n readonly tarball: Tarball;\n}\n\n/** Downloads the tarball, checks its SHA-256, and moves only the pinned executable into place. */\nconst installTarballEntry = (pin: Pin, { destination, download, tarball }: Install) =>\n Effect.gen(function* downloadVerifyExtract() {\n const bytes = yield* verifiedDownload(pin, tarball, download);\n const archive = yield* Effect.promise(() => promisify(gunzip)(bytes));\n const executable = tarEntry(archive, pin.name);\n if (executable === undefined) {\n return yield* installFailed(pin, `${tarball.url} holds no ${pin.name}.`);\n }\n yield* Effect.promise(() => placeExecutable(destination, executable));\n return destination;\n });\n\nconst tarballFor = (pin: Pin, platform: string, arch: string) =>\n pin.tarballs[`${platform}-${arch}`];\n\n/** The user's cache directory: `$XDG_CACHE_HOME`, else the platform's usual place. */\nconst cacheHome = () =>\n process.env.XDG_CACHE_HOME ??\n (process.platform === 'darwin'\n ? join(homedir(), 'Library', 'Caches')\n : join(homedir(), '.cache'));\n\nconst exists = (path: string) =>\n Effect.promise(async () => {\n try {\n await access(path);\n return true;\n } catch {\n return false;\n }\n });\n\n/** The executable at `destination`, downloaded there on first use. */\nconst pinnedBinary = (pin: Pin, destination: string) =>\n Effect.gen(function* cachedOrDownload() {\n if (yield* exists(destination)) {\n return destination;\n }\n const tarball = tarballFor(pin, process.platform, process.arch);\n if (tarball === undefined) {\n return yield* installFailed(\n pin,\n `no pinned ${pin.version} build for ${process.platform} ${process.arch}.`,\n );\n }\n return yield* installTarballEntry(pin, { destination, download: fetchBytes, tarball });\n });\n\nexport { cacheHome, installTarballEntry, pinnedBinary, tarballFor };\nexport type { FetchBytes, Install, Pin, Tarball };\n"],"mappings":";;;;;;;;AAaA,MAAM,EAAE,aAAa,qBAAqB;AAE1C,IAAM,eAAN,cAA2B,iBAA+B,CAAC,CAAC,gBAAgB,EAC1E,SAAS,OAAO,OAClB,CAAC,CAAC,CAAC,CAAC;AAeJ,MAAM,iBAAiB;AAEvB,MAAM,WAAW;AACjB,MAAM,UAAU;CAAE,KAAK;CAAK,OAAO;AAAE;AACrC,MAAM,UAAU;CAAE,KAAK;CAAK,OAAO;AAAI;AACvC,MAAM,UAAU;CAAE,KAAK;CAAK,OAAO;AAAI;AACvC,MAAM,QAAQ;;AAEd,MAAM,mCAAwC,IAAI,IAAI,CAAC,KAAK,IAAI,CAAC;;AAGjE,MAAM,aACJ,UACgG;CAChG,MAAM,OAAO,MAAM,SAAS,QAAQ,QAAQ,OAAO,QAAQ,GAAG,CAAC,CAAC,QAAQ,WAAW,EAAE;CACrF,MAAM,OAAO,OAAO,SAAS,MAAM,SAAS,SAAS,QAAQ,OAAO,QAAQ,GAAG,CAAC,CAAC,KAAK,GAAG,KAAK;CAC9F,IAAI,SAAS,MAAM,OAAO,MAAM,IAAI,GAClC;CAGF,OAAO;EAAE;EAAM,aADK,iBAAiB,IAAI,MAAM,SAAS,SAAS,QAAQ,OAAO,QAAQ,GAAG,CAClE;EAAG;CAAK;AACnC;;;;;AAMA,MAAM,YAAY,SAAiB,SAAqC;CACtE,IAAI,SAAS;CACb,OAAO,SAAS,YAAY,QAAQ,QAAQ;EAC1C,MAAM,SAAS,UAAU,QAAQ,SAAS,QAAQ,SAAS,QAAQ,CAAC;EACpE,IAAI,WAAW,KAAA,GACb;EAEF,MAAM,OAAO,SAAS;EACtB,IAAI,OAAO,eAAe,SAAS,OAAO,IAAI,MAAM,MAClD,OAAO,QAAQ,SAAS,MAAM,OAAO,OAAO,IAAI;EAElD,SAAS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,KAAK,SAAS,QAAQ;CAC5D,MAAM,UAAU,OAAO,OAAO,cAAc,UAAU,MAAM,CAAC,CAAC,KAAK,CAAC;CACpE,MAAM,aAAa,SAAS,SAAS,IAAI,IAAI;CAC7C,IAAI,eAAe,KAAA,GACjB,OAAO,OAAO,cAAc,KAAK,GAAG,QAAQ,IAAI,YAAY,IAAI,KAAK,EAAE;CAEzE,OAAO,OAAO,cAAc,gBAAgB,aAAa,UAAU,CAAC;CACpE,OAAO;AACT,CAAC;AAEH,MAAM,cAAc,KAAU,UAAkB,SAC9C,IAAI,SAAS,GAAG,SAAS,GAAG;;AAG9B,MAAM,kBACJ,QAAQ,IAAI,mBACX,QAAQ,aAAa,WAClB,KAAK,QAAQ,GAAG,WAAW,QAAQ,IACnC,KAAK,QAAQ,GAAG,QAAQ;AAE9B,MAAM,UAAU,SACd,OAAO,QAAQ,YAAY;CACzB,IAAI;EACF,MAAM,OAAO,IAAI;EACjB,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF,CAAC;;AAGH,MAAM,gBAAgB,KAAU,gBAC9B,OAAO,IAAI,UAAU,mBAAmB;CACtC,IAAI,OAAO,OAAO,WAAW,GAC3B,OAAO;CAET,MAAM,UAAU,WAAW,KAAK,QAAQ,UAAU,QAAQ,IAAI;CAC9D,IAAI,YAAY,KAAA,GACd,OAAO,OAAO,cACZ,KACA,aAAa,IAAI,QAAQ,aAAa,QAAQ,SAAS,GAAG,QAAQ,KAAK,EACzE;CAEF,OAAO,OAAO,oBAAoB,KAAK;EAAE;EAAa,UAAU;EAAY;CAAQ,CAAC;AACvF,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { createRequire } from "node:module";
2
+ import { Console, Effect, Schema } from "effect";
3
+ // ../../packages/contract/src/bin.ts
4
+ const PackageJson = Schema.Struct({ version: Schema.String });
5
+ /** The version in the package.json one level above the built bin at `binUrl`. */
6
+ const packageVersion = (binUrl) => {
7
+ const packageJson = createRequire(binUrl)("../package.json");
8
+ return Schema.decodeUnknownEffect(PackageJson)(packageJson).pipe(Effect.map(({ version }) => version), Effect.orDie);
9
+ };
10
+ /**
11
+ * Runs the CLI at the version of the package whose bin is at `url`. `name` is the name it prints.
12
+ * An `expected` failure carries a message written for the user, so it is printed as `<name>:
13
+ * <message>` without a stack trace, and the bin exits 1.
14
+ */
15
+ const binProgram = (bin, run) => packageVersion(bin.url).pipe(Effect.flatMap(run), Effect.catchIf((failure) => failure._tag === bin.expected, ({ message }) => Console.error(`${bin.name}: ${message}`).pipe(Effect.andThen(Effect.sync(() => {
16
+ process.exitCode = 1;
17
+ })))));
18
+ export { binProgram };
19
+
20
+ //# sourceMappingURL=bin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bin.js","names":[],"sources":["../../../../../../packages/contract/src/bin.ts"],"sourcesContent":["import { createRequire } from 'node:module';\n\nimport { Console, Effect, Schema } from 'effect';\n\nconst PackageJson = Schema.Struct({ version: Schema.String });\n\n/** The version in the package.json one level above the built bin at `binUrl`. */\nconst packageVersion = (binUrl: string) => {\n const packageJson: unknown = createRequire(binUrl)('../package.json');\n return Schema.decodeUnknownEffect(PackageJson)(packageJson).pipe(\n Effect.map(({ version }) => version),\n Effect.orDie,\n );\n};\n\n/**\n * Runs the CLI at the version of the package whose bin is at `url`. `name` is the name it prints.\n * An `expected` failure carries a message written for the user, so it is printed as `<name>:\n * <message>` without a stack trace, and the bin exits 1.\n */\nconst binProgram = <\n Failure extends { readonly _tag: string },\n Requirements,\n Tag extends Extract<Failure, { readonly message: string }>['_tag'],\n>(\n bin: { readonly expected: Tag; readonly name: string; readonly url: string },\n run: (version: string) => Effect.Effect<void, Failure, Requirements>,\n) =>\n packageVersion(bin.url).pipe(\n Effect.flatMap(run),\n Effect.catchIf(\n (failure): failure is Extract<Failure, { readonly _tag: Tag; readonly message: string }> =>\n failure._tag === bin.expected,\n ({ message }) =>\n Console.error(`${bin.name}: ${message}`).pipe(\n Effect.andThen(\n Effect.sync(() => {\n process.exitCode = 1;\n }),\n ),\n ),\n ),\n );\n\nexport { binProgram };\n"],"mappings":";;;AAIA,MAAM,cAAc,OAAO,OAAO,EAAE,SAAS,OAAO,OAAO,CAAC;;AAG5D,MAAM,kBAAkB,WAAmB;CACzC,MAAM,cAAuB,cAAc,MAAM,CAAC,CAAC,iBAAiB;CACpE,OAAO,OAAO,oBAAoB,WAAW,CAAC,CAAC,WAAW,CAAC,CAAC,KAC1D,OAAO,KAAK,EAAE,cAAc,OAAO,GACnC,OAAO,KACT;AACF;;;;;;AAOA,MAAM,cAKJ,KACA,QAEA,eAAe,IAAI,GAAG,CAAC,CAAC,KACtB,OAAO,QAAQ,GAAG,GAClB,OAAO,SACJ,YACC,QAAQ,SAAS,IAAI,WACtB,EAAE,cACD,QAAQ,MAAM,GAAG,IAAI,KAAK,IAAI,SAAS,CAAC,CAAC,KACvC,OAAO,QACL,OAAO,WAAW;CAChB,QAAQ,WAAW;AACrB,CAAC,CACH,CACF,CACJ,CACF"}
package/llms.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  # wt-tunnel-client
2
2
 
3
- > Command-line tool (`@tafrahq/wt-tunnel-client`, Node 22+) that gives each git worktree private HTTPS URLs, such as `https://app.feat-x.dev.example.com`, through a self-hosted tunnel server (frps behind Caddy and a sign-in with Google, GitHub, Microsoft or Cloudflare Access). One frpc per worktree; no ports in URLs; no root and no open port on the dev machine.
3
+ > Command-line tool (`@tafrahq/wt-tunnel-client`, Node.js 26 or later) that gives each git worktree private HTTPS URLs, such as `https://app.feat-x.dev.example.com`, through a self-hosted tunnel server (frps behind Caddy and a sign-in with Google, GitHub, Microsoft or Cloudflare Access). One frpc per worktree; no ports in URLs; no root and no open port on the dev machine.
4
4
 
5
5
  Key facts:
6
6
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tafrahq/wt-tunnel-client",
3
- "version": "0.7.0",
3
+ "version": "0.11.0",
4
4
  "description": "Private HTTPS URLs for every git worktree, through a self-hosted frp tunnel server behind a sign-in (Google, GitHub, Microsoft or Cloudflare Access): one frpc per worktree, no ports in the URLs, no root on the dev machine.",
5
5
  "keywords": [
6
6
  "cli",
@@ -19,7 +19,7 @@
19
19
  "worktree",
20
20
  "wt-tunnel"
21
21
  ],
22
- "homepage": "https://github.com/tafrahq/wt-tunnel/tree/main/apps/client#readme",
22
+ "homepage": "https://wt.tafrahq.com",
23
23
  "bugs": {
24
24
  "url": "https://github.com/tafrahq/wt-tunnel/issues"
25
25
  },
@@ -44,22 +44,23 @@
44
44
  "access": "public"
45
45
  },
46
46
  "dependencies": {
47
- "@effect/platform-node": "4.0.6",
48
- "effect": "4.0.6"
47
+ "@effect/platform-node": "4.0.7",
48
+ "@effect/platform-node-shared": "4.0.7",
49
+ "effect": "4.0.7"
49
50
  },
50
51
  "devDependencies": {
51
- "@effect/vitest": "^4.0.6",
52
+ "@effect/vitest": "4.0.7",
52
53
  "@tafrahq/wt-tunnel-binaries": "0.0.0",
53
54
  "@tafrahq/wt-tunnel-contract": "0.0.0",
54
- "@types/node": "^22.20.5",
55
+ "@types/node": "^26.6.6",
55
56
  "tsdown": "0.23.2",
56
57
  "vitest": "^5.0.5"
57
58
  },
58
59
  "engines": {
59
- "node": ">=22"
60
+ "node": ">=26"
60
61
  },
61
62
  "scripts": {
62
- "build": "tsdown && node dist/bin.js --version",
63
+ "build": "tsdown && nub dist/bin.js --version",
63
64
  "typecheck": "tsc --noEmit",
64
65
  "test": "vitest run"
65
66
  }
package/src/bin.ts CHANGED
@@ -1,28 +1,14 @@
1
1
  #!/usr/bin/env node
2
- import { createRequire } from 'node:module';
3
-
2
+ // fallow-ignore-file coverage-gaps -- only hands cli.ts's run to NodeRuntime; cli.test.ts runs run in-process, and packages/contract/src/bin.test.ts tests binProgram
4
3
  import { NodeRuntime, NodeServices } from '@effect/platform-node';
5
- import { Console, Effect, Schema } from 'effect';
4
+ import { binProgram } from '@tafrahq/wt-tunnel-contract/bin';
5
+ import { Effect } from 'effect';
6
6
 
7
7
  import { run } from './cli.ts';
8
8
 
9
- const PackageJson = Schema.Struct({ version: Schema.String });
10
- const packageJson: unknown = createRequire(import.meta.url)('../package.json');
11
-
12
- const program = Schema.decodeUnknownEffect(PackageJson)(packageJson).pipe(
13
- Effect.orDie,
14
- Effect.flatMap(({ version }) => run(version)),
15
- // Expected failures carry a message written for the user; skip the stack trace.
16
- Effect.catchTag('WtTunnelError', ({ message }: { readonly message: string }) =>
17
- Console.error(`wt-tunnel-client: ${message}`).pipe(
18
- Effect.andThen(
19
- Effect.sync(() => {
20
- process.exitCode = 1;
21
- }),
22
- ),
23
- ),
24
- ),
25
- Effect.provide(NodeServices.layer),
9
+ const program = binProgram(
10
+ { expected: 'WtTunnelError', name: 'wt-tunnel-client', url: import.meta.url },
11
+ run,
26
12
  );
27
13
 
28
- NodeRuntime.runMain(program);
14
+ NodeRuntime.runMain(program.pipe(Effect.provide(NodeServices.layer)));