go-npm
go-npm copied to clipboard
Yarn Install does not work
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
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 ?
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
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
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