-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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
fix(dynamicImportVars): correct glob pattern for paths with parentheses #17940
Conversation
|
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.
The fix looks great 👍 Can we also add a test for this in playground/dynamic-import
?
@bluwy Hi, I ran the tests on my Mac, and they all passed. I'm not sure why there's a failing on CI: Windows. |
It seems there's two |
normalizeGlobPattern( | ||
await toAbsoluteGlob(rawPattern, root, importer, resolve), | ||
), |
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.
Given that the problem is that toAbsoluteGlob
escaping the characters unnecessary, how about not using that function?
Checking the toAbsoluteGlob
function, most of the code is handling about globs and escaping the paths. I think it would be trimmed down to:
// replace `normalizeGlobPattern` + `toAbsoluteGlob` with
const dir = importer ? dirname(importer) : root
const normalized = rawPattern[0] === '/' ? posix.join(root, rawPattern.slice(1)) : posix.join(dir, rawPattern)
// pass it to `newRawPattern`
let newRawPattern = posix.relative(posix.dirname(importer), normalized)
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.
OK, I'll fix this.
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.
Thank you!
/ecosystem-ci run |
📝 Ran ecosystem CI on
✅ astro, ladle, laravel, marko, nuxt, previewjs, quasar, qwik, rakkas, storybook, unocss, vite-environment-examples, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-svelte, vite-plugin-vue, vite-setup-catalogue, vitepress, vitest, vuepress |
/ecosystem-ci run redwoodjs |
Description
fixes #11824
In the
transformDynamicImport
method, thenewRawPattern
is generated usingposix.relative(from, to)
. Sinceto
is generated throughtoAbsoluteGlob()
, if it contains parentheses, they will be escaped, resulting in an incorrect relative path when executed.For example:
Since both parameters are valid paths when calling this method, parentheses should be allowed.