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
-
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
bin
path for the platformI then have an entry-point package that acts as a proxy to download the package that contains the platform specific binary
When a user installs the entry package;
npm
,yarn
andpnpm
will ignore the packages that don't have a matchingos
andarch
field.Currently, no package manager creates a link to the
bin
for 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 thinbin
target that acts as a proxy to redirect to the correct target.Initially
bin.cmd
is 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 samebin
target 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.cmd
with the following contents:And if it's a *nix OS it will modify the
bin.cmd
with this:Limitations
This mostly works, however it doesn't work for
pnpm
,yarn4
and 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