-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
import/extensions should have a ignorePackages option. Fixes #414 #827
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think rather than expanding the string option, it would be better to add an object option.
I would want ignorePackages
for all enforcement, always or never, and arguably that should be the default (assuming it only applies to the "main", and never to any additional entry points).
@@ -86,6 +86,30 @@ import express from 'express/index.js'; | |||
import * as path from 'path'; | |||
``` | |||
|
|||
The following patterns are considered problems when configuration set to "ignorePackages": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add an example of require('foo/bar.js')
still being required with both "always" and "ignorePackages" set.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this still needs an example, and a matching test
src/rules/extensions.js
Outdated
if (!has(modifiers, extension)) { modifiers[extension] = defaultConfig } | ||
return modifiers[extension] === 'always' | ||
const modifier = modifiers[extension] | ||
return (!isModule && modifier === 'ignorePackages') || modifier === 'always' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it should not be ignored just because it's an external package, rather only when it's the "main" of an external package.
In other words, require('foo')
and require('@foo/bar')
should be ignored, but subpaths under these should not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! I'm not well versed in all of the possible import permutations, but here's a regex I just made up. Can you tell me if I'm missing something?
^(([\w]((?!\/).)*)|(@[^\/]+\/?[^\/]+))$
This matches the following:
foo
foo2
foo.js
@foo
@foo2
@foo.js
@foo/bar
@foo2/bar
@foo2.js/bar
@foo2.js/bar.js
And will not match the following:
foo/bar
foo2/bar
foo/bar2
foo/bar.js
foo/bar/hello
@foo2/bar/hello
@foo2/bar/hello.js
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd really prefer to avoid complex regexes if we can, but your matches look good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This regex is probably better understood if I split it:
// src/core/importType.js
// Similar to isExternalModule, but does not allow "/"
const externalModuleMainRegExp = /^[\w]((?!\/).)*$/
export function isExternalModuleMain(path, name, settings) {
return externalModuleMainRegExp.test(name) && isExternalPath(path, name, settings)
}
// Similar to isScoped, but only allows 1 occurrence of "/"
const scopedMainRegExp = /^@[^\/]+\/?[^\/]+$/
export function isScopedMain(name) {
return scopedMainRegExp.test(name)
}
Then just OR these.
@ljharb object options are already taken by the extensions. Adding anything to the object options will create ambiguity. |
That's true. We could allow for a separate object, though, in either order, and later, migrate the extensions options to an "extensions" key in that new object, and deprecate/remove the top-level extensions config object. |
Say we have a new object type (for now called As far as I understand this schema system, since Then what's the migration path? Perhaps deprecate |
ok, so the current schema allows any of:
Indeed, this is problematic, and "patternProperties" should never have had top-level configurable keys. It seems like the migration path is the following schema:
And then, we'd deprecate and eventually remove the "object of pattern properties" schemas (the last two above), and when they were removed, we'd be able to collapse the 5 new schema types into one or two. |
Thanks for that @ljharb, makes sense now. I will try to implement your suggestions tonight or tomorrow. |
b487d2c
to
70ea249
Compare
I can't really work on building tests for this this (to fix coverage issue) due to #838 |
Hi, @collinsauve @ljharb – great work here. I am not a formal contributor yet, but I am curious if there is anything I can do help get this moving again? 🍻 |
@millerized if you can contribute a commit to improve coverage on top of this PR, and link it here, I can push it to the branch - I think that's the main thing that's missing. |
Awesome PR! Was just looking for a way to configure this. |
Hi, @ljharb @collinsauve – I’ve rebased this branch with upstream to fix conflicts and added some test coverage around the |
Thanks! I've updated the PR with those commits, and will review later today. |
Thanks, @ljharb! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM pending one more comment!
@@ -86,6 +86,30 @@ import express from 'express/index.js'; | |||
import * as path from 'path'; | |||
``` | |||
|
|||
The following patterns are considered problems when configuration set to "ignorePackages": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this still needs an example, and a matching test
Thanks for the reminder, @ljharb. I beleive these commits should suffice. lmk what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM!
I'll merge this tomorrow if there's no objections. |
Unsure about the AV CI failure. It appears to be a false negative. Perhaps it needs a re-run, @ljharb.
Coverage decreasing seems odd. |
appveyor is passing, but coveralls is throwing errors; you can ignore it. |
Gtk. Thanks, @ljharb. Any last items to address or are we ready to merge? |
For issue #414
Unfortunately I cannot run the tests from this repo on my machine (lots of unexplained failures) so I will have trouble writing additional tests for this new behavior.