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

Ensure npm run is being called instead of npx run #94

Merged
merged 2 commits into from
Nov 9, 2022
Merged

Ensure npm run is being called instead of npx run #94

merged 2 commits into from
Nov 9, 2022

Conversation

MarmadileManteater
Copy link
Contributor

Related Issue:

#93

Problem:

If you run npm-run-all using npx (EX: npx npm-run-all clean build:dev test), it will prompt you to install runjs if it is not already installed.

Screenshot_2022-10-28_13-41-05

Then, it will throw an error that looks something like this:
image

This is because running npx npm-run-all causes process.env.npm_execpath to point to npx instead of npm.

npm_cli_is_npx

The underlying command ends up something like npx run clean which will attempt to run runjs instead of running the npm scripts, and of course, clean isn't a javascript file or anything that runjs can do anything with, so that is why it throws.

For reference, this is what it looks like when I intentionally run runjs in place of npm run.
image
If you look here at run.js, you can see the code that is being unintentionally ran by npm-run-all.

I am pretty sure this problem is related to mysticatea#196. The error looks to be exactly the same, and on my machine, yarn aliases to npx yarn which would cause yarn to throw an error where npm would work fine.
yarn:
image
npm:
image

Additional Information

I also modified how yarn is detected because I modified npmPath (which was how yarn was being detected previously). Before, isYarn was false when npx was used in conjunction with yarn. With these changes, it should actually detect yarn even if you run yarn using npx. (EX npx yarn dev)

before:
before
after:
image

Before, `isYarn` would be false if you ran yarn using `npx`.
npm_execpath points to npx if you are
running this inside of npx
@bcomnes
Copy link
Owner

bcomnes commented Nov 8, 2022

Cool, excited to get this fix in!

@codecov-commenter
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@bf91f94). Click here to learn what that means.
The diff coverage is n/a.

@@            Coverage Diff            @@
##             master      #94   +/-   ##
=========================================
  Coverage          ?   96.15%           
=========================================
  Files             ?       22           
  Lines             ?     1923           
  Branches          ?        0           
=========================================
  Hits              ?     1849           
  Misses            ?       74           
  Partials          ?        0           
Flag Coverage Δ
ubuntu-latest-18 96.15% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@bcomnes
Copy link
Owner

bcomnes commented Nov 9, 2022

Cool, thanks for the detailed information and patch. Lets try it out.

@bcomnes bcomnes merged commit da913f9 into bcomnes:master Nov 9, 2022
@bcomnes
Copy link
Owner

bcomnes commented Nov 9, 2022

@MarmadileManteater MarmadileManteater deleted the runjs-being-called-instead-of-npm-run branch November 9, 2022 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants