-
Notifications
You must be signed in to change notification settings - Fork 64
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
fix: instruct prebuild-install to download napi builds #47
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Do you really want to just take the first N-API version that it finds here? Isn't that a bit tricky? What if a native module supports multiple versions, like v3 and v4? I'm actually curious how
prebuild-install
finds which version to download, will check laterThere 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.
You're right it probably should do something more intelligent, but because of abi stability this will produce something that is guaranteed to work while maybe not optimal, assuming the first is the lowest number.
This is definitely something that can be improved, but wasn't necessary for me to get something that worked (and none of the packages I use target multiple napi versions)
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.
Bingo! https://github.com/inspiredware/napi-build-utils/blob/master/index.js#L166-L179
This is used by
prebuild-install
. They look atprocess.versions.napi
and select the highest available N-API version that's compatible with the currently running NodeJS version. Will do a quick check if we can implement something similar here as well :)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.
Good news! It's not necessary to provide a target, because
prebuild-install
will automatically determine the most appropriate N-API version if the given runtime is N-API 🎉: https://github.com/prebuild/prebuild-install/blob/master/rc.js#L48-L50After removing the
--target
, it indeed automatically finds the right N-API version: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.
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.
What runtime will it be using though?
For example if targeting a version of electron based around node 14, and you are running node 10 will that produce the correct result? I would expect it to be run in your node 10, and so get it wrong
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.
I just tested this hypothesis by testing this PR without the
target
being passed toprebuild-install
.I tested with native binary
@dennisameling/keytar-temp@7.4.100-beta
which has N-API prebuilds for N-API v3, v6 and v7 on Windows x64.Test: Electron 11, NodeJS 14.15.5
Electron 11.2.3
process.versions.napi = 6
Node 14.15.5
process.versions.napi = 7
prebuild-install
now tries to install a binary for N-API version 11.2.3, which is obviously incorrect as it's the Electron version.So you're right, we do need to pass the target N-API version. Just for info,
prebuild-install
also looks atbinary.napi_versions
in the package's config, so the approach you took here should be totally valid.Looking only at the first
napi_version
in the arrayThis approach is probably OK for now - in most cases, like you mentioned, it should take the lowest available N-API version from
binary.napi_versions
which should be fine. Looking forward, I already tried to do some research if we can do something similar to https://github.com/inspiredware/napi-build-utils/blob/master/index.js#L166-L179, but then for Electron.The problem is this:
process.versions.napi
, just like in Node itself. It returns the highest supported N-API version;6
for example.prebuild-install
leverages Electron'spackage.json
to get the Electron version, and uses that to set itstarget
version. The highest supported N-API version isn't mentioned in thepackage.json
, so AFAIK there's no way to retrieve Electron's N-API version without running Electron itself first.lovell/sharp
worked around this by explicitly settingnpm_config_target=3
in theirpackage.json
. However, this won't help them as soon as they need to support multiple N-API versions.I probably could create an issue in the
electron
repo for this - we could ask for a static way to receive the highest supported N-API for the installed Electron version. What do you think?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.
Yeah an issue with electron would be good. Doesn't really help us here right now as that will only make it into the next version, but at some point in the future it will. They already have
electron --version
andelectron --abi
, so adding anelectron --napi
would be reasonable.Until that is a thing, we could spin up electron with a very minimal script to extract the napi version
eg
electron napi-version.js
napi-version.js:
This wouldn't be hard to do, but I think it would be more appropriate to do on the js side, and feed it in alongside the platform and architecture.
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.
Issue created in
electron/electron
: electron/electron#27842