-
Notifications
You must be signed in to change notification settings - Fork 251
Closed
Labels
Description
Motivation ("The Why")
Example
For my packages published as prebuilt native addons, I config the native packages cross-platform as optionalDependencies to let npm choose the suitable one to download. And I can avoid written postinstall scripts to download them in this way.
Like canvas package:
The @napi-rs/canvas package is published for users depending on it directly:
{
"name": "@napi-rs/canvas",
"version": "0.1.6",
"optionalDependencies": {
"@napi-rs/canvas-linux-x64-gnu": "0.1.6",
"@napi-rs/canvas-linux-x64-musl": "0.1.6",
"@napi-rs/canvas-darwin-x64": "0.1.6",
"@napi-rs/canvas-win32-x64": "0.1.6",
"@napi-rs/canvas-linux-aarch64-gnu": "0.1.6",
"@napi-rs/canvas-linux-aarch64-musl": "0.1.6"
}
}And the packages include prebuilt native addons:
{
"name": "@napi-rs/canvas-linux-x64-musl",
"version": "0.1.6",
"os": ["linux"],
"cpu": ["x64"],
"main": "skia.linux-x64-musl.node",
"files": ["skia.linux-x64-musl.node"]
}{
"name": "@napi-rs/canvas-linux-x64-gnu",
"version": "0.1.6",
"os": ["linux"],
"cpu": ["x64"],
"main": "skia.linux-x64-gnu.node",
"files": ["skia.linux-x64-gnu.node"]
}In the macOS/Windows/FreeBSD this mechanism works fine, but on the Linux systems, npm will download two native binding packages, both gnu and musl. It will significantly increase the install size. The install size of @napi-rs/canvas on linux-x64 systems is 37mb which could be the half of it.
References
yisibl, hyj1991, styfle, controversial, janpio and 1 more