fix: escape characters in dynamic import (fix #11824)
Description
fix #11824
Additional context
What is the purpose of this pull request?
- [x] Bug fix
- [ ] New Feature
- [ ] Documentation update
- [ ] Other
Before submitting the PR, please make sure you do the following
- [x] Read the Contributing Guidelines.
- [x] Read the Pull Request Guidelines and follow the PR Title Convention.
- [x] Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
- [x] Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g.
fixes #123). - [x] Ideally, include relevant tests that fail without this PR but pass with it.
Thanks for the PR!
I digged this down and found that dynamicImportToGlob returns ./(foo)/*.js when ./(foo)/${name}.js is passed.
https://github.com/rollup/plugins/blob/bc5cf91a042b88e14a1da9ba25f501d92591ca8a/packages/dynamic-import-vars/src/dynamic-import-to-glob.js#L79
But I expect this function to return ./\(foo\)/*.js instead.
I guess @rollup/plugin-dynamic-import-vars has a similar bug because of this reason.
I think it's better to fix plugin-dynamic-import-vars.
Thanks for the PR!
I digged this down and found that
dynamicImportToGlobreturns./(foo)/*.jswhen./(foo)/${name}.jsis passed. https://github.com/rollup/plugins/blob/bc5cf91a042b88e14a1da9ba25f501d92591ca8a/packages/dynamic-import-vars/src/dynamic-import-to-glob.js#L79 But I expect this function to return./\(foo\)/*.jsinstead.I guess
@rollup/plugin-dynamic-import-varshas a similar bug because of this reason. I think it's better to fix plugin-dynamic-import-vars.
Yeah. I've aware of that. But the thing is that not only dynamicImportVars needs to support that but also importMetaGlob . e.g:
import.meta.glob(`../(parenthesis)/**/*.js`)
In that case, I expect users to escape the parenthesis. Unlike import(`./foo/${mod}.js`), import.meta.glob recieves a glob pattern and not a import specifier.
The glob matching is done via fast-glob - check out its documentation for supported glob patterns. https://vitejs.dev/guide/features.html#glob-import:~:text=The%20glob%20matching%20is%20done%20via%20fast%2Dglob%20%2D%20check%20out%20its%20documentation%20for%20supported%20glob%20patterns.
So in the example you showed, I expect users to write import.meta.glob(`../\(parenthesis\)/**/*.js`).
Alright. Let's submit this bug to @rollup/plugin-dynamic-import-vars upstream. You can close this PR
Let's close this one in favour of fixing upstream then. Thanks for starting the work on this!