Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to NAPI #644

Merged
merged 10 commits into from Jan 26, 2024
Merged

Port to NAPI #644

merged 10 commits into from Jan 26, 2024

Conversation

kkocdko
Copy link
Contributor

@kkocdko kkocdko commented Dec 4, 2023

  • Port current code to NAPI, but ignore onexit support. Thanks to DavidRusso.
  • Implement onexit, fix the "5th pty bug" in Port project to N-API #432 .
  • Port __APPLE__ section in pty_waitpid.
  • Port windows part.
  • Test on CI in my temp repo.

Need no more to say, mainly about compatibility.

About "5th pty bug" in #432

The Napi::AsyncWorker spawn a libuv worker thread which is limited by UV_THREADPOOL_SIZE (default = 4). It's more suitable for IO operations that need this limitation.

I want to taste now!

This PR only modify the native code, so just download from CI (see "Artifacts") then replace the origin files in ./build/Release/. Looking for macOS user because I have no macOS device.

The "5th pty bug" in #432 fixed also.
@kkocdko kkocdko marked this pull request as ready for review December 5, 2023 17:50
Copy link
Contributor Author

@kkocdko kkocdko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good to me, request for a review. @Tyriar @DavidRusso

src/win/winpty.cc Show resolved Hide resolved
src/unix/pty.cc Show resolved Hide resolved
src/unix/pty.cc Show resolved Hide resolved
src/win/path_util.cc Show resolved Hide resolved
@panowl
Copy link

panowl commented Dec 5, 2023

GREAT JOB! I am writing a custom remote serial com program with electron, previously I could only download an extra node 18 for node-pty, after replacing the file with artifact in ci it now runs directly on electron!

@kkocdko kkocdko changed the title Port to NAPI Migrate to NAPI Dec 5, 2023
@kkocdko kkocdko changed the title Migrate to NAPI Port to NAPI Dec 5, 2023
This was referenced Dec 6, 2023
@exsilium
Copy link

exsilium commented Dec 6, 2023

Awesome work! Looking forward to this to land to support Node v21.x

@kkocdko
Copy link
Contributor Author

kkocdko commented Dec 7, 2023

The macOS arm64 test successful here.

@Tyriar
Copy link
Member

Tyriar commented Dec 7, 2023

@deepak1556 @rzhao271 a review for this would be appreciated when you have the time

@deepak1556 deepak1556 added this to the January 2024 milestone Dec 7, 2023
@joaomoreno joaomoreno modified the milestones: January 2024, December / January 2024 Dec 11, 2023
@rajialtooro
Copy link

Wonderful work on this PR @kkocdko

I'm facing this issue with trying to spawn a pty process like this using bunjs, it works normally with node

// code
import { spawn } from 'node-pty';

const term - spawn("bash", [], {name: "xterm", cols: 80, rows: 24});
# error
Error: Usage: pty.fork(file, args, env, cwd, cols, rows, uid, gid, utf8, helperPath, onexit)
    at <anonymous> (native)
    at new UnixTerminal (/application/node_modules/node-pty/lib/unixTerminal.js:104:14)
// package.json
"scripts": {
    "postinstall": "rm -rf ./node_modules/node-pty/build/Release/pty.node && mkdir -p ./node_modules/node-pty/build/Release  && cp ./pty.node ./node_modules/node-pty/build/Release/pty.node"
},
"dependencies": {
    "node-pty": "https://github.com/kkocdko/node-pty.git",
}

I also tried it with the normal node-pty package but got the same error.
do you have any ideas if this is a misconfiguration on my end or a bug ?

@kkocdko
Copy link
Contributor Author

kkocdko commented Dec 15, 2023

@rajialtooro See oven-sh/bun#7685 . IMO this is a bunjs's bug.

@kkocdko
Copy link
Contributor Author

kkocdko commented Dec 25, 2023

I think we should skip bun support, cross version node/electron support is good enough (for most use case).

Bun's NAPI is still weak and unreliable (maybe), after that bun #7685 bug, now I hit another:

napi: napi_define_properties
  Error::Error

uh-oh: napi: napi_define_properties
  Error::Error
bun will crash now 😭😭😭

----- bun meta -----
Bun v1.0.20 (09d51486) Linux x64 #18~22.04.1-Ubuntu SMP Tue Nov 21 19:25:02 UTC 2023
TestCommand: 
Elapsed: 130ms | User: 54ms | Sys: 39ms
RSS: 44.07MB | Peak: 57.67MB | Commit: 44.07MB | Faults: 0
----- bun meta -----

0   0x559017618a7b
1   ???
2   ???
3   ???
4   ???
5   ???
6   ???
7   ??? napi_fatal_error
8   ???
9   ??? Napi::Error::New(napi_env__*)
...

And, merry christmas!

@kkocdko
Copy link
Contributor Author

kkocdko commented Jan 10, 2024

Hi, is there any progress on reviews? 😆

Copy link
Contributor

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for taking the time to work on this refactor!

Sorry for the delayed review, changes LGTM mostly. Left a few style comments, should be good to merge after that.

binding.gyp Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/unix/pty.cc Outdated Show resolved Hide resolved
src/unix/pty.cc Outdated Show resolved Hide resolved
src/win/conpty_console_list.cc Outdated Show resolved Hide resolved
src/win/path_util.h Outdated Show resolved Hide resolved
src/win/winpty.cc Outdated Show resolved Hide resolved
src/win/winpty.cc Outdated Show resolved Hide resolved
src/unix/pty.cc Outdated Show resolved Hide resolved
src/unix/pty.cc Outdated Show resolved Hide resolved
@kkocdko
Copy link
Contributor Author

kkocdko commented Jan 24, 2024

https://github.com/kkocdko/utils4linux/actions/runs/7645893929/job/20835695678

All things done, perhaps.

@deepak1556
Copy link
Contributor

Looks like there are build failures on windows and test failures on macOS

@kkocdko
Copy link
Contributor Author

kkocdko commented Jan 26, 2024

@deepak1556 Fixed.

@deepak1556 deepak1556 modified the milestones: December / January 2024, February 2024 Jan 26, 2024
Copy link
Contributor

@deepak1556 deepak1556 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you!

@deepak1556 deepak1556 merged commit b1fdda4 into microsoft:main Jan 26, 2024
9 checks passed
@lydell lydell mentioned this pull request Mar 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants