microsoft / node-pty

Fork pseudoterminals in Node.JS
Other
1.48k stars 244 forks source link

Bun support #632

Open enesflow opened 1 year ago

enesflow commented 1 year ago

Environment details

Issue description

Does not work with bun (https://bun.sh)

index.ts

import pty from "node-pty";
const subprocess = pty.spawn("bash", [], {});

error

$ bun run --watch src/index.ts

error: Cannot find module "../build/Debug/pty.node" from "/Users/enes/Code/app/node_modules/node-pty/lib/unixTerminal.js"

error: Cannot find module "../build/Release/pty.node" from "/Users/enes/Code/app/node_modules/node-pty/lib/unixTerminal.js"

I've tried building it with node-gyp

$ cd node_modules/node-pty
$ bunx node-gyp-build

This creates the build/Release folders and its contents, but now it gives this vague error:

$ bun run --watch src/index.ts
dyld[5963]: missing symbol called
error: script "dev" exited with code 9 (SIGKILL)

package.json

{
    "name": "app",
    "version": "1.0.0",
    "module": "src/index.ts",
    "devDependencies": {
        "bun-types": "latest"
    },
    "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1",
        "dev": "bun run --watch src/index.ts"
    },
    "dependencies": {
        "node-pty": "^1.0.0"
    }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2021",
    "module": "ES2022",
    "moduleResolution": "node",
    "types": [
      "bun-types"
    ],
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}
Tyriar commented 1 year ago

I tried this earlier and I don't think bun can work with node-gyp so it can't compile and package the binary

terrywh commented 8 months ago

any new on this? all i can find is an unanswered stackoverflow: https://stackoverflow.com/questions/77950299/alternatives-to-node-pty-for-bun it would be very useful combined with the bun shell

Tyriar commented 8 months ago

As far as I'm aware bun doesn't work with nan/napi/node-gyp so this isn't possible.

Jarred-Sumner commented 8 months ago

There are two bugs here:

1) node-gyp is supported in bun install, but there's a subtle bug with lifecycle scripts that cause it to not run correctly when there's a postinstall script and bindings.gyp both. @dylan-conway is working on a fix. This bug impacts bun install, but does not impact the runtime.

2) Bun's runtime implements napi, but node-pty depends on many Nan/V8 C++ API & libuv symbols which Bun does not implement yet.

Those include:

To find this information, I ran nm -g build/Release/pty.node.

Tyriar commented 8 months ago

@Jarred-Sumner thanks for the info. Can you clarify whether there's anything that should happen in this repo or if it's all on bun's side? I don't mind accepting changes to improve compatibility but don't plan on doing them myself as we don't use bun currently.

karlhorky commented 1 month ago

I think a good part of it is on the side of Bun:

Please follow along in #4290

@190n is actively working on supporting V8 C++ APIs in Bun