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

Separate detection for npm and Yarn #9

Closed
pladaria opened this issue Oct 8, 2019 · 6 comments · Fixed by #10
Closed

Separate detection for npm and Yarn #9

pladaria opened this issue Oct 8, 2019 · 6 comments · Fixed by #10

Comments

@pladaria
Copy link

pladaria commented Oct 8, 2019

I found this library gives false positives when used in a lifecycle script, for example, importing is-npm in a script called by prepublishOnly returns true when executing yarn publish.

This worked for me:

const isNpm = process.env.npm_execpath.includes('npm-cli.js');
@sindresorhus
Copy link
Owner

From the package description:

Check if your code is running as an npm or yarn script

@pladaria
Copy link
Author

pladaria commented Oct 8, 2019

Sorry, I thought this package had a different purpose...

@pladaria pladaria closed this as completed Oct 8, 2019
@sindresorhus
Copy link
Owner

I'm curious about your use-case. Why do you need to explicitly know whether it's npm or Yarn?

@pladaria
Copy link
Author

pladaria commented Oct 8, 2019

I'm using yarn in my project, with a .yarnrc configuration (ignored by npm) so the results of executing npm publish and yarn publish are different.

In a prepublishOnly script I'm performing some checks, one of them is to detect if the command was executed with npm and throw an error in that case.

@sindresorhus sindresorhus reopened this Oct 8, 2019
@sindresorhus
Copy link
Owner

Hmm, I think we could maybe do a breaking release and make it:

-const {isNpm} = require('is-npm');
+const {isNpmOrYarn, isNpm, isYarn} = require('is-npm');

That would also make it more explicit.

@sindresorhus sindresorhus changed the title False positive Separate detection for npm and Yarn Oct 8, 2019
@pladaria
Copy link
Author

pladaria commented Oct 8, 2019

Nice, thanks

mjswensen added a commit to mjswensen/is-npm that referenced this issue Oct 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants