Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"dist/",
"completions/",
"docs/",
"scripts/postinstall.js",
"README.md",
"LICENSE"
],
Expand All @@ -45,7 +46,7 @@
"scripts": {
"build": "tsc -p tsconfig.build.json",
"prepublishOnly": "npm run build",
"postinstall": "chmod +x node_modules/node-pty/prebuilds/*/spawn-helper 2>/dev/null || true",
"postinstall": "node scripts/postinstall.js",
"prepare": "git config core.hooksPath githooks 2>/dev/null || true; sh scripts/update-nix-hash.sh 2>/dev/null || true",
"install-completions": "sh scripts/install-completions.sh",
"typecheck": "tsc",
Expand Down
46 changes: 46 additions & 0 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Ensure node-pty's prebuilt `spawn-helper` is executable. Necessary because
// node-pty's published tarball ships the file with mode 0644 and its own
// post-install never chmods it. The previous workaround used a relative path
// (`node_modules/node-pty/prebuilds/*/spawn-helper`) which silently no-ops
// under pnpm with `enableGlobalVirtualStore`, where node-pty lives in a
// sibling content-addressed link rather than nested under @myobie/pty.
//
// The root-cause fix belongs in microsoft/node-pty; once that ships, this
// script can be removed entirely.

import * as fs from "node:fs";
import * as path from "node:path";
import { createRequire } from "node:module";
import { pathToFileURL } from "node:url";

if (process.platform === "win32") process.exit(0);

// Resolve from this package's root (package.json sibling), not from the
// script file, so that node-pty is discoverable regardless of whether
// node_modules is nested (npm/yarn/bun) or a sibling link (pnpm GVS).
const pkgDir = path.dirname(new URL(import.meta.url).pathname);
const requireFromPkg = createRequire(
pathToFileURL(path.join(pkgDir, "..", "package.json")),
);

let nodePtyDir;
try {
nodePtyDir = path.dirname(requireFromPkg.resolve("node-pty/package.json"));
} catch {
console.warn("[@myobie/pty] node-pty not found; skipping spawn-helper chmod");
process.exit(0);
}

const helper = path.join(
nodePtyDir,
"prebuilds",
`${process.platform}-${process.arch}`,
"spawn-helper",
);

try {
fs.chmodSync(helper, 0o755);
} catch {
// Acceptable when there's no prebuild for this arch and node-pty was
// built from source — node-gyp produces the binary executable already.
}