sanathkr / go-npm

Distribute and install Go binaries via NPM
Apache License 2.0
171 stars 56 forks source link

Yarn Install does not work #1

Open sanathkr opened 7 years ago

sanathkr commented 7 years ago

See https://github.com/awslabs/aws-sam-local/issues/87. Need to detect if the installation is coming from Yarn and find the binary path without using npm bin

mhart commented 7 years ago

I just checked and phantomjs-prebuilt seems to work with both npm and yarn – I wonder if it's worth looking into how they do it: https://github.com/Medium/phantomjs ?

sanathkr commented 7 years ago

Interesting. Their installer seems to place the binary within node_modules/phantomjs/lib/phantomjs and have package.json's main property point to phantomjs.js file. Upon running the exec the binary.

In my case, I want the binary to be directly placed under bin directory. That's where the difficulty is.

I need to dig deeper into Yarn to figure out how they handle ./bin directories

mhart commented 7 years ago

Yeah, they just use a more standard method of distributing npm binaries, using the bin property:

https://github.com/Medium/phantomjs/blob/master/package.json#L34-L36

Which links to a shim that executes the "real" binary:

https://github.com/Medium/phantomjs/blob/master/bin/phantomjs

sanathkr commented 7 years ago

The problem with bin directory is, npm requires binaries to be present in bin directory before running postinstall script. I can't use preinstall because go-npm is downloaded as a dependency only after preinstall script runs.

For best compatibility, I should probably follow phantomjs' approach - Have a JS shim placed under bin directory which will exec the go binary. But honestly I don't like this additional layer of indirection.

Need a bit more digging to find the right middleground