Is it possible to publish a unique NPM package?
What do you mean by "unique npm package"? There is already binary npm packages available for esbuild if you mean that.
I mean one package to be cross-platform, so I can install it in my project and I dont need worry about OS
Binaries aren't cross-platform so not really, unless the owner makes a package that packages all binaries and use a script to execute one conditionally depending on the platform but it isn't really a good idea, makes package bigger and have to depend on a script to startup.
I will definitely do this at some point. I took a stab at it earlier but couldn't figure out a great way to do it without having to host the binary somewhere myself, which I'd like to avoid if possible. My current plan is to figure out some way of having the install script invoke npm recursively to install the platform specific package. I'm not sure how straightforward that is. Please let me know if there are existing examples of packages that do this well.
Right i forgot npm had a way to publish prebuilt binaries. I know that https://github.com/Automattic/node-canvas does this to provide prebuilt binaries for the C++ code, it seems like they use a "binary" field in their package.json
@pollen5 I know that binaries are not cross-platform but what I suggested is to have a NPM package which identifies and install the right binary due the platform. I don't know if it is only possible with node-gyp.
@pollen5 This binary
property is related to node-pre-gyp package
Great idea, current format with different packages add a lot of pain to open source projects that want to use that library.
You might publish a single package which lists every platform as an optional dependency. Npm/yarn will figure out which one to install based on the "os" field of the package.json. Example of that being used by the google-closure-compiler npm package:
https://github.com/google/closure-compiler-npm/blob/8a8c255015cf7bc46846449f3e706bc3c596f72d/packages/google-closure-compiler/package.json#L46
Wouldn't it be possible to publish a package with the Go source files, and an install
/postinstall
script (that should be just make
)?
Yeah, the user should have Go and make already installed... but it's not that hard to install them, and I think that's kinda the same thing that node-fibers does 馃
I was hoping that optional dependencies would work since they seem like the closest thing to what I want. However, they didn't end up working.
Optional dependencies sometimes randomly cause npm to install the binary in node_modules/esbuild/node_modules/esbuild-darwin-64
instead of node_modules/esbuild-darwin-64
. This means npx esbuild
no longer works because the binary lives in node_modules/esbuild/node_modules/.bin/esbuild
instead of node_modules/.bin/esbuild
. You can still do npm explore esbuild -- npx esbuild
to run it but I don't want to make people do that.
I'll have to figure something else out.
Most helpful comment
I will definitely do this at some point. I took a stab at it earlier but couldn't figure out a great way to do it without having to host the binary somewhere myself, which I'd like to avoid if possible. My current plan is to figure out some way of having the install script invoke npm recursively to install the platform specific package. I'm not sure how straightforward that is. Please let me know if there are existing examples of packages that do this well.