node v6.5.0
yarn v0.15.1
NPM provides some shell environment variables during the installation process. I use one of them to suppress the prepublish hook after npm install, for I find it counterintuitive. Here is an example in a prepublish.sh.
if node -e "process.exit(($npm_config_argv).original[0].indexOf('pu') === 0)"; then
exit 0;
fi
$npm_config_argv is not present on yarn install, so this throws a SyntaxError. It would be a nice feature if yarn provided something analogous.
You can do this compatibly with the in-publish package. As horrifically bad as prepublish-on-install is, it would be worse imo for yarn to deviate from npm here.
in-publish works. Thanks!
@acarl005 Can you clarify which version of yarn you are using, please? For me it's still doesn't work on 0.15.1:
"scripts": {
"prepublish": "node -e \"console.log(process.env['npm_config_argv'])\""
},
$ yarn
yarn install v0.15.1
success Already up-to-date.
$ node -e "console.log(process.env['npm_config_argv'])"
undefined
Done in 0.38s.
Meanwhile npm works as expected:
$ npm install
> [email protected] prepublish d:\Work\test-project
> node -e "console.log(process.env['npm_config_argv'])"
{"remain":[],"cooked":["install"],"original":["install"]}
I'm on Windows 8.1 if it matters.
@inikulin I'm using yarn v0.15.1. I got it working by installing in-publish and then changing my prepublish hook like so:
{
"prepublish": "in-publish && source ./scripts/prepublish.sh || not-in-publish"
}
I'm on OSX btw.
Well, it still doesn't work properly. It just hits that line: https://github.com/iarna/in-publish/blob/master/index.js#L6 there it can't parse process.env['npm_config_argv']:
This time I'm running my macOS machine:
โฏ yarn
yarn install v0.15.1
success Already up-to-date.
$ in-publish && echo "Publish" || echo "Not in publish"
Not in publish
โฏ yarn publish
yarn publish v0.15.1
[1/4] Bumping version...
info Current version: 1.0.0
question New version: 1.1.1
info New version: 1.1.1
[2/4] Logging in...
question npm username: inikulin
question npm email: [email protected]
question npm password:
success Logged in.
[3/4] Publishing...
$ in-publish && echo "Publish" || echo "Not in publish"
Not in publish
\cc @kittens
I see. It worked for me insofar as it suppressed the prepublish hook on yarn install, which is what I wanted.
However, it is NOT working when I do yarn publish. I have to use npm publish when publishing.
The environment variable $npm_config_argv is still undefined so in-publish _always_ fails.
It would still be nice if yarn provided an analogous environment variable, like $yarn_config_argv in order to get the full functionality.
It would need to provide the exact same environment variable - $npm_config_argv - to truly get the same functionality without changing all existing npm packages that rely on it.
It would need to provide the exact same environment variable - $npm_config_argv
I guess it will be a bit complicated, because you need to map yarn commands to npm commands. In meantime having some marker variables like yarn_installing and yarn_publishing will be an acceptable workaround.
I know that full backwards-compatibility is unrealistic. But having some marker variable would but great. Then I could write (and possibly publish) my own script to work for both yarn and npm. Either that or someone will update in-publish to work with both.
I'm working on a fix
as far as I can see npm doesn't run prepublish as of v5. should yarn also switch?
^ I think so.
Its murder to try and install a few packages in a big lerna monorepo
Agree
Most helpful comment
as far as I can see npm doesn't run prepublish as of v5. should yarn also switch?