-
Notifications
You must be signed in to change notification settings - Fork 13
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
Add support for eager via the { eager: true }
argument to import.meta.glob
#43
Add support for eager via the { eager: true }
argument to import.meta.glob
#43
Conversation
packages/babel-plugin-transform-vite-meta-glob/src/__tests__/__snapshots__/index.ts.snap
Show resolved
Hide resolved
f76b1f6
to
0c07dc6
Compare
According to Vite types, globEager is deprecated in favour of supplying an options argument to glob (from importMeta.d.ts 👇🏽) ``` /** * @deprecated Use `import.meta.glob('*', { eager: true })` instead */ globEager: import('./importGlob').ImportGlobEagerFunction ``` This commit adds tests cases to cover the desired behaviour, and the appropriate implementation. The target code was obtained from the Vite docs at [1]. This only supports the eager option, others are not covered here. [1] https://vitejs.dev/guide/features.html#glob-import:~:text=%7B%20eager%3A%20true%20%7D)-,The%20above%20will%20be%20transformed%20into%20the%20following%3A,-js
0c07dc6
to
855a136
Compare
|
||
path.replaceWith(replacement) | ||
} | ||
} |
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 can def be tidied up, but will wait until we're sure that this is producing the right/desired result before doing so
For the record, in my project where tests previously resulted in // package.json
"babel-plugin-transform-vite-meta-glob": "https://gitpkg.now.sh/jazlalli/babel-vite/packages/babel-plugin-transform-vite-meta-glob?pr/support-eager-glob-option"` and adding the plugin into config // babel.config.js
plugins: ["babel-plugin-transform-vite-meta-glob"], All tests run successfully and pass 🟢 |
@mpeyper Hi, could you help review this PR. I need this PR to upgrade vite@v5 |
Hey, sorry, github notifcations are rubbish and I completely missed this one (and the issue it references). It's been a long time since I've looked at the code here, so I'm feeling very rusty and I don't really have the bandwidth at the moment to dig into it all again. That said, the change looks ok to me, especially the snapshot output from the tests, however, I can't see the button to approve the checks to run (It's probably been too long since the commits were made). @jazlalli, if you are still interested in getting this through, could you bump a new commit onto the branch and see if checks come back to life? |
Wild, I also didn't get notifications and its my Organization lmao thanks GitHub... |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #43 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 4 4
Lines 93 130 +37
Branches 32 49 +17
=========================================
+ Hits 93 130 +37 ☔ View full report in Codecov by Sentry. |
It looks like the action failed to release this. I think this project needs a bit of TLC. |
@JacobMGEvans Could you help review this PR #46, just to upgrade node to 20. Also run test on CI in fork repo for sure |
🎉 This PR is included in version 1.1.1 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
🎉 This PR is included in version 1.1.0 🎉 The release is available on npm package (@latest dist-tag) Your semantic-release bot 📦🚀 |
I got some issue with jest if use import.meta.glob with second args {eager: true} everything will be fine if I removed second args cc @jazlalli |
@vctqs1 I’m not sure how including the second argument could break jest parsing of es module syntax? Can you share a repo and open an issue for it? |
sure, let me create sandbox |
@mpeyper sorry for my late response, here is my sandbox
|
🙋🏽 Question
I've targeted the code as specified at https://vitejs.dev/guide/features.html#glob-import, but realise that that might not be what's needed in a Node env, can someone confirm? Should the code produced actually use
require()
?What:
Addresses #42
Adds support for specifying eager import via the
ImportGlobOptions
argument toimport.meta.glob
Why:
import.meta.globEager
is deprecated in favour of the options argument. Without support in this plugin, Babel (and therefore Jest) is unable to understand this syntax.How:
The target for what this should produce was obtained from the Vite docs on Glob Imports. Specifically,
A new visitor is added to target the entire
VariableDeclaration
, and it is replaced with the specified code above.Checklist:
npm run contributors:add
command is not available, and I didn't want to manually modify the contributors sections, seeing as it says not to 🙃