Fix: Handle error when running init without npm #9169
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix init command crashing on machines that don't have npm installed #9102 .
Before:
After:
What is the purpose of this pull request? (put an "X" next to item)
[ ] Documentation update
[ X ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofixing to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:
What changes did you make? (Give an overview)
Modify
fetchPeerDependencies()
function in npm-util to retun null if the npm process exited with anENOENT
error.Modify
installSyncSaveDev()
function in npm-util to log an error message if the npm process exited with anENOENT
error.Write new tests for
fetchPeerDependencies()
andinstallSyncSaveDev()
to cover these scenarios.Modify the sync stub in other
installSyncSaveDev()
tests to return an object more similar to the child_process object specified in the node.js docs, to avoid undefined field errors.Is there anything you'd like reviewers to focus on?
I'm not sure if returning
null
infetchPeerDependencies()
might be the best way of error handling. A consequence of this is thatgetPeerDependencies()
also has to return null in this scenario. Let me know if you think there are better alternatives.With this change,
hasESLintVersionConflict()
could potentially throw an error when trying to access theeslint
field of a null object. I decided check for null and use an empty object instead, which results in the function returning false in this scenario. I'm not sure what consequences might this change have, and I couldn't figure out a way to test it since it is a private method.