Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to suppress prepublish hook on yarn install #684

Closed
acarl005 opened this issue Oct 11, 2016 · 13 comments
Closed

How to suppress prepublish hook on yarn install #684

acarl005 opened this issue Oct 11, 2016 · 13 comments

Comments

@acarl005
Copy link

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.

@ljharb
Copy link

ljharb commented Oct 11, 2016

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.

@acarl005
Copy link
Author

in-publish works. Thanks!

@inikulin
Copy link
Contributor

inikulin commented Oct 13, 2016

@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.

@acarl005
Copy link
Author

@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.

@inikulin
Copy link
Contributor

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

@acarl005
Copy link
Author

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.

@acarl005 acarl005 reopened this Oct 13, 2016
@ljharb
Copy link

ljharb commented Oct 14, 2016

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.

@inikulin
Copy link
Contributor

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.

@acarl005
Copy link
Author

acarl005 commented Oct 14, 2016

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.

@inikulin
Copy link
Contributor

I'm working on a fix

@jquense
Copy link

jquense commented Dec 11, 2017

as far as I can see npm doesn't run prepublish as of v5. should yarn also switch?

@AshCoolman
Copy link

^ I think so.

Its murder to try and install a few packages in a big lerna monorepo

@DrSensor
Copy link

Agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants