fix: do not crash rule no-unpublished-require
#49
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.
Fixes #48
This PR ensures that the rule
no-unpublished-require
does not crash when the package root directory isrequire
d.This is done by making sure that
npmignore.match
is never called if the argument is an empty string, which is the relative path of the root directory. That's because callingnpmignore.match("")
results in an underlying call toignore().createFilter()("")
, where ignore fails with aTypeError
.This works under the assumption that a package can never npmignore its root directory. This does not add logic to check that the
"main"
file defined in package.json (or fallback file index.js) exists or is published.I've wrapped the changed code into function calls to make it better readable, and also to avoid running
isDevPackage()
unnecessarily whenisPrivateFile()
returns truthy.