Skip to content

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

Merged
devongovett merged 7 commits into
parcel-bundler:v2from
marcins:mszczepanski/glob-node-resolver
May 23, 2022
Merged

Support using packages in imports resolved by the glob resolver#8097
devongovett merged 7 commits into
parcel-bundler:v2from
marcins:mszczepanski/glob-node-resolver

Conversation

@marcins

@marcins marcins commented May 16, 2022

Copy link
Copy Markdown
Contributor

↪️ 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

@devongovett devongovett left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

@devongovett devongovett left a comment

Copy link
Copy Markdown
Member

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