Skip to content

Commit

Permalink
fix(optimizer): fix optimizeDeps.include glob syntax for ./* expo…
Browse files Browse the repository at this point in the history
…rts (#16230)
  • Loading branch information
hi-ogawa authored Mar 22, 2024
1 parent 9800c73 commit f184c80
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/vite/src/node/optimizer/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions playground/optimize-deps/__tests__/optimize-deps.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Empty file.
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "@vitejs/test-dep-optimize-exports-with-root-glob",
"private": true,
"version": "1.0.0",
"type": "module",
"exports": {
".": "./index.js",
"./*": "./*"
}
}
1 change: 1 addition & 0 deletions playground/optimize-deps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions playground/optimize-deps/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down
10 changes: 10 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f184c80

Please sign in to comment.