Skip to content

Commit 0bb700c

Browse files
committed
Bundle CLI for npm global install compatibility (fixes #3)
Node refuses to type-strip .ts files under node_modules/, so `pty` failed after `npm install -g`. The CLI entry point is now bundled to a single bin/cli.js via esbuild during prepublishOnly. The testing and TUI exports remain .ts — consumers' toolchains handle those.
1 parent 1c8ff25 commit 0bb700c

5 files changed

Lines changed: 503 additions & 5 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules/
2+
bin/cli.js
23
result

bin/pty

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
#!/usr/bin/env node
2+
import { existsSync } from 'node:fs';
23
import { spawnSync } from 'node:child_process';
34
import { fileURLToPath } from 'node:url';
45
import { dirname, join } from 'node:path';
56

67
const __dirname = dirname(fileURLToPath(import.meta.url));
7-
const cli = join(__dirname, '..', 'src', 'cli.ts');
8+
const cli = join(__dirname, 'cli.js');
9+
10+
if (!existsSync(cli)) {
11+
console.error('bin/cli.js not found. Run: npm run build');
12+
process.exit(1);
13+
}
814

915
const result = spawnSync(process.execPath, [cli, ...process.argv.slice(2)], {
1016
stdio: 'inherit',

flake.nix

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,19 @@
2929

3030
# Generated from package-lock.json.
3131
# Regenerate with: nix run nixpkgs#prefetch-npm-deps -- package-lock.json
32-
npmDepsHash = "sha256-rl5s8czRezWu0Fri4xWoMUkazBQfVXfuUf9hvBGw3Qw=";
32+
npmDepsHash = "sha256-ZE3elAZKDLlig0Pe6KrGvLO8xlmF+9WqYHl3v0KFfXs=";
3333

3434
# node-pty has native code that needs these at build time
3535
nativeBuildInputs = with pkgs; [ python3 pkg-config ];
3636
buildInputs = pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
3737
pkgs.apple-sdk_15
3838
];
3939

40-
# No compile step — Node runs TypeScript directly via type stripping.
41-
dontNpmBuild = true;
40+
buildPhase = ''
41+
runHook preBuild
42+
npm run build
43+
runHook postBuild
44+
'';
4245

4346
# Install outside of node_modules so Node's TypeScript stripping works.
4447
# (Node refuses to strip types for files under node_modules/)

0 commit comments

Comments
 (0)