Skip to content

Commit ef1c8a4

Browse files
committed
Fix CLI for npm global install — build src/ to dist/ with tsc
Node refuses to run .ts files from node_modules/. The CLI and daemon now run from dist/ (compiled by tsc). Tests and exports updated to use dist/ for subprocess spawning. npm run build is now required before using the CLI locally.
1 parent 0bb700c commit ef1c8a4

8 files changed

Lines changed: 35 additions & 14 deletions

File tree

.gitignore

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

bin/pty

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import { fileURLToPath } from 'node:url';
55
import { dirname, join } from 'node:path';
66

77
const __dirname = dirname(fileURLToPath(import.meta.url));
8-
const cli = join(__dirname, 'cli.js');
8+
const cli = join(__dirname, '..', 'dist', 'cli.js');
99

1010
if (!existsSync(cli)) {
11-
console.error('bin/cli.js not found. Run: npm run build');
11+
console.error('dist/cli.js not found. Run: npm run build');
1212
process.exit(1);
1313
}
1414

package.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@myobie/pty",
3-
"version": "0.1.1",
3+
"version": "0.1.2",
44
"description": "Persistent terminal sessions with detach/attach support",
55
"type": "module",
66
"license": "MIT",
@@ -19,7 +19,7 @@
1919
],
2020
"files": [
2121
"bin/",
22-
"src/",
22+
"dist/",
2323
"completions/",
2424
"docs/",
2525
"README.md",
@@ -29,11 +29,17 @@
2929
"pty": "./bin/pty"
3030
},
3131
"exports": {
32-
"./testing": "./src/testing/index.ts",
33-
"./tui": "./src/tui/index.ts"
32+
"./testing": {
33+
"types": "./dist/testing/index.d.ts",
34+
"default": "./dist/testing/index.js"
35+
},
36+
"./tui": {
37+
"types": "./dist/tui/index.d.ts",
38+
"default": "./dist/tui/index.js"
39+
}
3440
},
3541
"scripts": {
36-
"build": "esbuild src/cli.ts --bundle --platform=node --format=esm --outfile=bin/cli.js --external:node-pty --external:@xterm/headless --external:@xterm/addon-serialize --external:@preact/signals-core",
42+
"build": "tsc -p tsconfig.build.json",
3743
"prepublishOnly": "npm run build",
3844
"prepare": "git config core.hooksPath githooks 2>/dev/null || true; chmod +x node_modules/node-pty/prebuilds/darwin-*/spawn-helper 2>/dev/null || true; sh scripts/update-nix-hash.sh 2>/dev/null || true",
3945
"install-completions": "sh scripts/install-completions.sh",

src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ export class PtyServer {
390390
}
391391

392392
/** Entry point when this file is run as the daemon process. */
393-
if (process.argv[1]?.endsWith("/server.ts")) {
393+
if (process.argv[1]?.endsWith("/server.js")) {
394394
const config = JSON.parse(process.env.PTY_SERVER_CONFIG ?? "{}");
395395
if (!config.name || !config.command) {
396396
console.error("PTY_SERVER_CONFIG env var required");

src/spawn.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export async function spawnDaemon(
1818
const rows = stdout.rows ?? 24;
1919
const cols = stdout.columns ?? 80;
2020

21-
const serverModule = path.join(__dirname, "server.ts");
21+
const serverModule = path.join(__dirname, "server.js");
2222
const config = JSON.stringify({
2323
name,
2424
command,

tests/screenshot.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ describe("screenshot: high-throughput output", () => {
861861
describe("daemon spawning", () => {
862862
const __dirname = path.dirname(fileURLToPath(import.meta.url));
863863
const nodeBin = process.execPath;
864-
const serverModule = path.join(__dirname, "..", "src", "server.ts");
864+
const serverModule = path.join(__dirname, "..", "dist", "server.js");
865865

866866
it(
867867
"daemon starts and serves a session via the node spawn mechanism",
@@ -1034,7 +1034,7 @@ describe("daemon spawning", () => {
10341034
describe("immediate attach after daemon start", () => {
10351035
const __dirname = path.dirname(fileURLToPath(import.meta.url));
10361036
const nodeBin = process.execPath;
1037-
const serverModule = path.join(__dirname, "..", "src", "server.ts");
1037+
const serverModule = path.join(__dirname, "..", "dist", "server.js");
10381038

10391039
async function spawnDaemonAndWaitForSocket(
10401040
name: string,

tests/tui.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import { Session } from "../src/testing/index.ts";
88

99
const __dirname = path.dirname(fileURLToPath(import.meta.url));
1010
const nodeBin = process.execPath;
11-
const cliPath = path.join(__dirname, "..", "src", "cli.ts");
12-
const serverModule = path.join(__dirname, "..", "src", "server.ts");
11+
const cliPath = path.join(__dirname, "..", "dist", "cli.js");
12+
const serverModule = path.join(__dirname, "..", "dist", "server.js");
1313

1414
// Each test gets its own temp session dir
1515
const testRoot = fs.mkdtempSync(path.join(os.tmpdir(), "ptui-"));

tsconfig.build.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2022",
4+
"module": "Node16",
5+
"moduleResolution": "Node16",
6+
"strict": true,
7+
"esModuleInterop": true,
8+
"skipLibCheck": true,
9+
"outDir": "dist",
10+
"declaration": true,
11+
"rewriteRelativeImportExtensions": true
12+
},
13+
"include": ["src"],
14+
"exclude": ["node_modules"]
15+
}

0 commit comments

Comments
 (0)