Replace custom require loader with process.dlopen
and using static path to node.napi.node
#71
Labels
process.dlopen
and using static path to node.napi.node
#71
Specification
Native bindings is currently loaded using
requireBinding
. This is integrated into our native addon packaging style using optional dependencies.However this won't work as part of ESM. So it has to be changed to using
dlopen
in preparation for ESM migration.Furthermore,
require
supports thepackage.json
specification ofmain
. Which we are currently setting tonode.napi.node
. However instead we just fix statically where our.node
files will be, and that it will always be in@matrixai/quic-linux-x64/node.napi.node
.This means
dlopen
should work better, and plus it becomes simpler to use when it comes to integrating into esbuild bundling andpkg
.In particular it means:
esbuild
needs to specify@matrixai/quic-linux-x64
as an external package, since esbuild cannot bundle such a thing - this is done by setting it inoptionalDependencies
and passing it to theexternal
option inawait esbuild.build(esbuildOptions)
. - The reason it is inoptionalDependencies
is because this allows it to be installed into thenode_modules
so when anix-build
occurs, it will in fact exist when esbuild is running. This we cannot really automate, and we have to do this for all native addons. Seepackage.json
in Polykey-CLI.pkg
needs to specify an asset asnode_modules/@matrixai/quic-linux-x64/node.napi.node
. - Currently we're using node-gyp-build to auto-find native modules, however this does not work for our custom optional dependency structure. So currently this is also manually specified.I think it should be possible to update our native module finding code to look for
node.napi.node
that is within our direct dependencies too, by just iterating through the root directory of each package, then it should be possible to make that automatic as well. That would reduce this:Down to:
Since it would be auto-found.
Additional context
Tasks
The text was updated successfully, but these errors were encountered: