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

import/extensions should have a ignorePackages option. Fixes #414 #827

Merged
merged 6 commits into from
Nov 2, 2017

Conversation

collinsauve
Copy link
Contributor

@collinsauve collinsauve commented May 10, 2017

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.

@coveralls
Copy link

coveralls commented May 10, 2017

Coverage Status

Coverage increased (+0.01%) to 94.927% when pulling 5912a70 on collinsauve:issue414 into bd0e5e3 on benmosher:master.

@coveralls
Copy link

coveralls commented May 10, 2017

Coverage Status

Coverage increased (+0.01%) to 94.927% when pulling 5912a70 on collinsauve:issue414 into bd0e5e3 on benmosher:master.

Copy link
Member

@ljharb ljharb left a 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":
Copy link
Member

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.

Copy link
Member

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

if (!has(modifiers, extension)) { modifiers[extension] = defaultConfig }
return modifiers[extension] === 'always'
const modifier = modifiers[extension]
return (!isModule && modifier === 'ignorePackages') || modifier === 'always'
Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

@collinsauve collinsauve May 11, 2017

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.

@collinsauve
Copy link
Contributor Author

@ljharb object options are already taken by the extensions. Adding anything to the object options will create ambiguity.

@ljharb
Copy link
Member

ljharb commented May 10, 2017

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.

@collinsauve
Copy link
Contributor Author

collinsauve commented May 10, 2017

Say we have a new object type (for now called newProperties ) with props like extensions, and ignorePackages. We now need to add a new item to meta.schema.anyOf.

As far as I understand this schema system, since patternProperties catches all objects we can't use args [newProperties]. For the same reason we also cant use [string, newProperties]. We need to use [string, patternProperties, newProperties] or [patternProperties, newProperties].

Then what's the migration path? Perhaps deprecate [patternProperties] and [string, patternProperties] in verion N and add support for [newProperties] and [string, newProperties] in version N+1? ... And then remove support for [string, patternProperties, newProperties] and [patternProperties, newProperties] in version N + 2.

@ljharb
Copy link
Member

ljharb commented May 10, 2017

ok, so the current schema allows any of:

  1. one item, "always" or "never"
  2. one item, an object of "pattern properties"
  3. two items, "always/never" and an object of "pattern properties".

Indeed, this is problematic, and "patternProperties" should never have had top-level configurable keys.

It seems like the migration path is the following schema:

  1. one item, "always" or "never"
  2. new two items, "always/never" and an object with a "pattern" key (containing pattern properties)
  3. new two items, "always/never" and an object with an "ignorePackages" key
  4. new two items, "always/never" and an object with an "ignorePackages" key and a "pattern" key
  5. new one item, an object with an "ignorePackages" key
  6. new one item, an object with an "ignorePackages" key and a "pattern" key
  7. one item, an object of "pattern properties"
  8. two items, "always/never" and an object of "pattern properties".

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.

@collinsauve
Copy link
Contributor Author

Thanks for that @ljharb, makes sense now. I will try to implement your suggestions tonight or tomorrow.

@collinsauve collinsauve force-pushed the issue414 branch 2 times, most recently from b487d2c to 70ea249 Compare May 12, 2017 21:44
@coveralls
Copy link

coveralls commented May 12, 2017

Coverage Status

Coverage decreased (-0.2%) to 94.743% when pulling 70ea249 on collinsauve:issue414 into bd0e5e3 on benmosher:master.

@collinsauve
Copy link
Contributor Author

I can't really work on building tests for this this (to fix coverage issue) due to #838

@millerized
Copy link
Contributor

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?

🍻

@ljharb
Copy link
Member

ljharb commented Jun 30, 2017

@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.

@jdalton
Copy link

jdalton commented Jul 13, 2017

Awesome PR! Was just looking for a way to configure this.

@millerized
Copy link
Contributor

millerized commented Oct 31, 2017

Hi, @ljharb @collinsauve – I’ve rebased this branch with upstream to fix conflicts and added some test coverage around the ignorePackages option. Please see millerized#1. Please let me know if there is still missing coverage and I will get it in asap. 🍻

@ljharb
Copy link
Member

ljharb commented Oct 31, 2017

Thanks! I've updated the PR with those commits, and will review later today.

@coveralls
Copy link

coveralls commented Oct 31, 2017

Coverage Status

Coverage increased (+0.05%) to 96.084% when pulling a8e8bfb on collinsauve:issue414 into a5844d5 on benmosher:master.

@millerized
Copy link
Contributor

Thanks! I've updated the PR with those commits, and will review later today.

Thanks, @ljharb!

Copy link
Member

@ljharb ljharb left a 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":
Copy link
Member

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

@ljharb ljharb self-assigned this Oct 31, 2017
@millerized
Copy link
Contributor

this still needs an example, and a matching test

Thanks for the reminder, @ljharb. I beleive these commits should suffice. lmk what you think.

Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, LGTM!

@ljharb ljharb requested review from benmosher and jfmengels November 1, 2017 02:50
@ljharb
Copy link
Member

ljharb commented Nov 1, 2017

I'll merge this tomorrow if there's no objections.

@coveralls
Copy link

coveralls commented Nov 1, 2017

Coverage Status

Coverage decreased (-0.01%) to 96.082% when pulling 81d3b36 on collinsauve:issue414 into eca7b4d on benmosher:master.

@millerized
Copy link
Contributor

continuous-integration/appveyor/pr — AppVeyor build failed

Unsure about the AV CI failure. It appears to be a false negative. Perhaps it needs a re-run, @ljharb.

Coverage decreased (-0.01%) to 96.082% when pulling 81d3b36 on collinsauve:issue414 into eca7b4d on benmosher:master.

Coverage decreasing seems odd.

@ljharb
Copy link
Member

ljharb commented Nov 1, 2017

appveyor is passing, but coveralls is throwing errors; you can ignore it.

@millerized
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

5 participants