-
Notifications
You must be signed in to change notification settings - Fork 284
Load native addons directly from prebuilds directory #809
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
Conversation
deepak1556
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM, couple of changes
- If an embedder is explicitly building from source by setting this env variable at install time , can we preserve that info and avoid having to check prebuilds folder in
Lines 14 to 18 in 31ca5ce
// Skip copying prebuilds when npm_config_build_from_source is set if (process.env.npm_config_build_from_source === 'true') { console.log('\x1b[33m> Skipping prebuild copy because npm_config_build_from_source is set\x1b[0m'); process.exit(1); } loadNativeModuleat runtime - The current default is unbundled, can you swap the relative order
['..', '.']to preserve it. On the contrary, if there is some config maintained for 1) could that be reused to declare whether module is bundled or unbundled which would makeloadNativeModuleless expensive ?
Yeah that's a good idea! Do you have a preference on how it should be preserved?
Will swap the order. And then consider integrating with the persistence once I have it |
|
Maybe writing some One more followup, can you simplify |
I'm wondering if it makes sense to try to read a file to check which other file to read 🤔 Maybe should just change the load order to give
Yeah absolutely, I'll clean that up. I'm also thinking the post-install script doesn't need to run in the prebuilt case either. Maybe something like this? diff --git a/package.json b/package.json
index 621402c..50365c1 100644
--- a/package.json
+++ b/package.json
@@ -38,8 +38,7 @@
"build": "tsc -b ./src/tsconfig.json",
"watch": "tsc -b -w ./src/tsconfig.json",
"lint": "eslint -c .eslintrc.js --ext .ts src/",
- "install": "node scripts/prebuild.js || node-gyp rebuild",
- "postinstall": "node scripts/post-install.js",
+ "install": "node scripts/prebuild.js || (node-gyp rebuild && node scripts/post-install.js)",
"compileCommands": "node scripts/gen-compile-commands.js",
"test": "cross-env NODE_ENV=test mocha -R spec --exit lib/*.test.js",
"posttest": "npm run lint",
|
👍 , adding to this for the other case of building from source we should just remove the prebuilds folder as part of the install script. So that it tries only
Maybe rename |
Updated! Definitely feels simpler now. Let me know what you think :) |
367f7e7 to
af7fa26
Compare
Tyriar
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall idea is good, I'll let @deepak1556 do final approval.
deepak1556
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
FYI, the current CI checks does not test for loading from prebuilds path, might want to add some workflow as followup https://github.com/microsoft/node-pty/blob/main/.github/workflows/ci.yml
This PR enables loading native addons directly from prebuilds directory.
This makes the install more durable in the event the install script fails or isn't run (e.g. the default when using pnpm: https://pnpm.io/settings#dangerouslyallowallbuilds). With this addition the install step could be simplified to just check for the existence of prebuilds instead of copying them.
It also makes it possible to bundle node-pty, since currently the
../build/Releaserelative path is not achievable when bundling to a single JS file. Hence the addition of checking./for each path.Relates to #46