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

Feat: import.meta.glob and import.meta.globEager support #2881

Merged
merged 22 commits into from
Mar 31, 2021

Conversation

natemoo-re
Copy link
Contributor

@natemoo-re natemoo-re commented Mar 16, 2021

Changes

Following up on #1165, this PR implements import.meta.glob and import.meta.globEager which mirror Vite's Glob Import support.

Testing

Added tests in test/build/import-glob but these might need to be more thorough? LMK if you can think of any edge cases I'm missing.

Docs

TODO

@vercel
Copy link

vercel bot commented Mar 16, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/pikapkg/snowpack/32VyjnDKximn3J9U7TKec1MUSMSX
✅ Preview: https://snowpack-git-feat-glob-import-pikapkg.vercel.app

@geddski
Copy link
Contributor

geddski commented Mar 16, 2021

I'm pumped for this :)

@@ -486,6 +486,11 @@ export function removeTrailingSlash(path: string) {
return path.replace(/[/\\]+$/, '');
}

/** It's `Array.splice`, but for Strings! */
Copy link
Collaborator

Choose a reason for hiding this comment

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

🎉


it('import.meta.glob does not import its own source file', () => {
expect(stripWS(files['/_dist_/globSelf.js'])).not.toContain('globSelf.js');
});
Copy link
Collaborator

@drwpow drwpow Mar 17, 2021

Choose a reason for hiding this comment

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

👍🏻 Great tests. These test everything that I can think of. We may have someone requesting x or y for import globs down the line, but I think this is a great first cut (and may be all we ever need for import globs!)

Copy link
Collaborator

@drwpow drwpow left a comment

Choose a reason for hiding this comment

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

Awesome!

@FredKSchott
Copy link
Owner

Reviewed in person, some notes:

  • import.meta.glob lexer - optimize with a quick (forgiving) regex before even lexing the file
  • support comments in lexer
  • make sure es-module-lexer utils are properly licensed

@FredKSchott FredKSchott merged commit 598f05a into main Mar 31, 2021
Triage automation moved this from Evaluating PR to Closed Mar 31, 2021
@FredKSchott FredKSchott deleted the feat-glob-import branch March 31, 2021 01:16
@FredKSchott FredKSchott removed this from Closed in Triage Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

import.meta.context, import.meta.importAll or import globs
4 participants