fix(optimizer): fix optimizeDeps.include glob syntax for ./* exports (#16230)

This commit is contained in:
Hiroshi Ogawa 2024-03-22 21:34:28 +09:00 committed by GitHub
parent 9800c738b5
commit f184c8032b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 36 additions and 0 deletions

View File

@ -95,6 +95,16 @@ export function expandGlobIds(id: string, config: ResolvedConfig): string[] {
ignore: ['node_modules'],
})
.map((filePath) => {
// ensure "./" prefix for inconsistent fast-glob result
// glob.sync("./some-dir/**/*") -> "./some-dir/some-file"
// glob.sync("./**/*") -> "some-dir/some-file"
if (
exportsValue.startsWith('./') &&
!filePath.startsWith('./')
) {
filePath = './' + filePath
}
// "./glob/*": "./dist/glob/*-browser/*.js"
// `filePath`: "./dist/glob/foo-browser/foo.js"
// we need to revert the file path back to the export key by

View File

@ -304,6 +304,10 @@ describe.runIf(isServe)('optimizeDeps config', () => {
'@vitejs/test-dep-optimize-exports-with-glob/glob-dir/foo',
'@vitejs/test-dep-optimize-exports-with-glob/glob-dir/bar',
'@vitejs/test-dep-optimize-exports-with-glob/glob-dir/nested/baz',
'@vitejs/test-dep-optimize-exports-with-root-glob',
'@vitejs/test-dep-optimize-exports-with-root-glob/file1.js',
'@vitejs/test-dep-optimize-exports-with-root-glob/index.js',
'@vitejs/test-dep-optimize-exports-with-root-glob/dir/file2.js',
'@vitejs/test-dep-optimize-with-glob',
'@vitejs/test-dep-optimize-with-glob/index.js',
'@vitejs/test-dep-optimize-with-glob/named.js',

View File

@ -0,0 +1,10 @@
{
"name": "@vitejs/test-dep-optimize-exports-with-root-glob",
"private": true,
"version": "1.0.0",
"type": "module",
"exports": {
".": "./index.js",
"./*": "./*"
}
}

View File

@ -26,6 +26,7 @@
"@vitejs/test-dep-node-env": "file:./dep-node-env",
"@vitejs/test-dep-not-js": "file:./dep-not-js",
"@vitejs/test-dep-optimize-exports-with-glob": "file:./dep-optimize-exports-with-glob",
"@vitejs/test-dep-optimize-exports-with-root-glob": "file:./dep-optimize-exports-with-root-glob",
"@vitejs/test-dep-optimize-with-glob": "file:./dep-optimize-with-glob",
"@vitejs/test-dep-relative-to-main": "file:./dep-relative-to-main",
"@vitejs/test-dep-with-builtin-module-cjs": "file:./dep-with-builtin-module-cjs",

View File

@ -20,6 +20,7 @@ export default defineConfig({
// will throw if optimized (should log warning instead)
'@vitejs/test-non-optimizable-include',
'@vitejs/test-dep-optimize-exports-with-glob/**/*',
'@vitejs/test-dep-optimize-exports-with-root-glob/**/*.js',
'@vitejs/test-dep-optimize-with-glob/**/*.js',
],
exclude: ['@vitejs/test-nested-exclude', '@vitejs/test-dep-non-optimized'],

View File

@ -936,6 +936,9 @@ importers:
'@vitejs/test-dep-optimize-exports-with-glob':
specifier: file:./dep-optimize-exports-with-glob
version: file:playground/optimize-deps/dep-optimize-exports-with-glob
'@vitejs/test-dep-optimize-exports-with-root-glob':
specifier: file:./dep-optimize-exports-with-root-glob
version: file:playground/optimize-deps/dep-optimize-exports-with-root-glob
'@vitejs/test-dep-optimize-with-glob':
specifier: file:./dep-optimize-with-glob
version: file:playground/optimize-deps/dep-optimize-with-glob
@ -1053,6 +1056,8 @@ importers:
playground/optimize-deps/dep-optimize-exports-with-glob: {}
playground/optimize-deps/dep-optimize-exports-with-root-glob: {}
playground/optimize-deps/dep-optimize-with-glob: {}
playground/optimize-deps/dep-relative-to-main: {}
@ -10586,6 +10591,11 @@ packages:
name: '@vitejs/test-dep-optimize-exports-with-glob'
dev: false
file:playground/optimize-deps/dep-optimize-exports-with-root-glob:
resolution: {directory: playground/optimize-deps/dep-optimize-exports-with-root-glob, type: directory}
name: '@vitejs/test-dep-optimize-exports-with-root-glob'
dev: false
file:playground/optimize-deps/dep-optimize-with-glob:
resolution: {directory: playground/optimize-deps/dep-optimize-with-glob, type: directory}
name: '@vitejs/test-dep-optimize-with-glob'