go-npm icon indicating copy to clipboard operation
go-npm copied to clipboard

Yarn Install does not work

Open sanathkr opened this issue 8 years ago • 4 comments

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

sanathkr avatar Aug 23 '17 14:08 sanathkr

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 ?

mhart avatar Aug 23 '17 15:08 mhart

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

sanathkr avatar Aug 23 '17 15:08 sanathkr

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

mhart avatar Aug 23 '17 15:08 mhart

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

sanathkr avatar Aug 27 '17 04:08 sanathkr