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

Support using packages in imports resolved by the glob resolver #8097

Merged

Conversation

marcins
Copy link
Contributor

@marcins marcins commented May 16, 2022

↪️ Pull Request

Implements the ability for the glob resolver to resolve globs in packages, fixes #7945.

💻 Examples

With this change the glob resolver will work with a glob like import('@scope/pkg/i18n/*.js'), by first resolving @scope/pkg to a path, and then appending /i18n/*.js.

🚨 Test instructions

An integration test has been added for both a regular require as well as an async import. Please provide feedback if the tests added are not comprehensive enough.

✔️ PR Todo

  • Added/updated unit integration tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

Copy link
Member

@devongovett devongovett left a comment

Choose a reason for hiding this comment

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

Looks good thanks!


module.exports = async function () {
await promise.all([scoped, unscoped]);
return scoped.a + scoped.b + unscoped.x + unscoped.y;
Copy link
Member

Choose a reason for hiding this comment

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

I think it should be Promise.all? And each key on the returned object from import() is a function that also resolves to a promise, so this should be await scoped.a() + await scoped.b() ...

name: 'index.js',
assets: ['*.js', '*.js', 'a.js', 'b.js', 'x.js', 'y.js', 'index.js'],
},
]);
Copy link
Member

Choose a reason for hiding this comment

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

Probably should run the resulting bundle here as in the other tests to ensure it actually works

// if the specifier does not start with /, ~, or . then it's not a path but package-ish - we resolve
// the package first, and then append the rest of the path
if (!/^[/~.]/.test(specifier)) {
specifier = path.normalize(specifier);
Copy link
Member

Choose a reason for hiding this comment

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

I think globs are supposed to always use / as a separator, even on Windows. See https://github.com/micromatch/micromatch#backslashes. So this might not be needed.

@marcins marcins force-pushed the mszczepanski/glob-node-resolver branch from 925fec2 to a6502dc Compare May 18, 2022 00:44
Copy link
Member

@devongovett devongovett left a comment

Choose a reason for hiding this comment

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

Thanks, this looks great!

@devongovett devongovett merged commit 03fb352 into parcel-bundler:v2 May 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Should @parcel/resolver-glob support importing from packages?
2 participants