Replies: 1 comment
-
|
I also considered parsing the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am authoring an npm package that distributes native binaries. Native binaries are compiled and therefore they are platform specific.
To reduce the download burden on consumers, I have split the binaries into multiple packages, each containing their respective platform binary.
Each package specifies the appropriate
binpath for the platform{ "name": "@alshdavid/mach-linux-amd64", "bin": { "mach": "bin/mach" }, "os": ["linux"], "arch": ["x64"] }{ "name": "@alshdavid/mach-windows-amd64", "bin": { "mach": "bin\\mach.exe" }, "os": ["win32"], "arch": ["x64"] }I then have an entry-point package that acts as a proxy to download the package that contains the platform specific binary
{ "name": "@alshdavid/mach", "optionalDependencies": { "@alshdavid/mach-linux-amd64": "0.0.22", "@alshdavid/mach-linux-arm64": "0.0.22", "@alshdavid/mach-macos-amd64": "0.0.22", "@alshdavid/mach-macos-arm64": "0.0.22", "@alshdavid/mach-windows-amd64": "0.0.22", "@alshdavid/mach-windows-arm64": "0.0.22" } }When a user installs the entry package;
npm,yarnandpnpmwill ignore the packages that don't have a matchingosandarchfield.Currently, no package manager creates a link to the
binfor theoptionalDependency, they seem to only create links for direct dependencies.I would like to tell the package managers to use the bin for their platform.
My current solution
Right now in my entry package (
@alshdavid/mach), I have added a thinbintarget that acts as a proxy to redirect to the correct target.{ "name": "@alshdavid/mach", "bin": { "mach": "bin.cmd" }, "scripts": { "postinstall": "node postinstall.mjs" } //...Initially
bin.cmdis an empty file, there to provide something for npm/yarn/pnpm to link against.Windows uses the file extension to determine how to run the file where *nix systems will use the
#!. The extension is ignored for *nix systems allowing me to use the samebintarget for all OSes (I have runchmod +x bin.cmd).My postinstall script will detect the OS and if it's Windows, it will modify the
bin.cmdwith the following contents:And if it's a *nix OS it will modify the
bin.cmdwith this:Limitations
This mostly works, however it doesn't work for
pnpm,yarn4and I am unsure if it will work for global installations.Is there an idiomatic way that works across the package managers that allows me to target the correct binary from an optionalDependency for my application?
Beta Was this translation helpful? Give feedback.
All reactions