-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix --if-present cascading to child npm run scripts #3589
Conversation
The correct way to do this is by putting As written, this PR would mean that It might be worth a conversation to see if not cascading For context, we do not export the |
I guess the bigger question is: why don't you want it to persist? The |
Thanks for getting back!
TIL, I'll have a look at this. Maybe that could be the perfect compromise between cascading and not cascading. Flag: doesn't cascade. static (for lack of a better term) config: does cascade.
Yeah, I thought about this too and wasn't sure if setting this as a config was even an "advertised" use case. I couldn't find anything in the docs about it. Which of course doesn't mean it's not there.
You may not even know what the Do you have any idea how this could be tested or if it needs testing? |
It makes a lot of sense to me that if-present would not cascade - the point of doing |
Right, and if you did Makes sense to me. I wonder if there are other configs like this, where it doesn't make sense to cascade them through the environment? |
The mock config in the tests is something we know needs to be fixed, and there was a PR to fix it that ran into unrelated issues surrounding how our coverage works. Looks like I may need to re prioritize getting that PR over the finish line #3463 |
This is an attempt to fix #3352
Given a package.json like:
npm run --if-present present
would result in exit code 0, even though the second npm run call doesn't specify the--if-present
flag.With this PR, this would now throw throw an error:
If
--if-present
is specified in the second script, this will continue to successfully return.npm run --if-present present
returns exit code 0.A few notes:
I have no idea if the change might have an adverse effect on anything else or if it's the right approach at all. Feedback is welcome! :)
I was also wondering if similar changes need to be applied to other flags (like
--silent
), but probably not?I have tried to write tests, but I'm a bit stuck because
cli/test/lib/run-script.js
Line 16 in f9381de
Also I'm not sure the mocked npm could be used if a script uses
npm run some-other-script
inside that test?