Skip to content

Commit

Permalink
feat(optimizer): check optimizeDeps.extensions for scannable files (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey authored Oct 6, 2023
1 parent e7d7a6f commit 23ef8a1
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions packages/vite/src/node/optimizer/scan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ async function computeEntries(config: ResolvedConfig) {
// Non-supported entry file types and virtual files should not be scanned for
// dependencies.
entries = entries.filter(
(entry) => isScannable(entry) && fs.existsSync(entry),
(entry) =>
isScannable(entry, config.optimizeDeps.extensions) &&
fs.existsSync(entry),
)

return entries
Expand Down Expand Up @@ -520,7 +522,7 @@ function esbuildScanPlugin(
depImports[id] = resolved
}
return externalUnlessEntry({ path: id })
} else if (isScannable(resolved)) {
} else if (isScannable(resolved, config.optimizeDeps.extensions)) {
const namespace = htmlTypesRE.test(resolved) ? 'html' : undefined
// linked package, keep crawling
return {
Expand Down Expand Up @@ -576,7 +578,10 @@ function esbuildScanPlugin(
},
})
if (resolved) {
if (shouldExternalizeDep(resolved, id) || !isScannable(resolved)) {
if (
shouldExternalizeDep(resolved, id) ||
!isScannable(resolved, config.optimizeDeps.extensions)
) {
return externalUnlessEntry({ path: id })
}

Expand Down Expand Up @@ -659,8 +664,13 @@ function shouldExternalizeDep(resolvedId: string, rawId: string): boolean {
return false
}

function isScannable(id: string): boolean {
return JS_TYPES_RE.test(id) || htmlTypesRE.test(id)
function isScannable(id: string, extensions: string[] | undefined): boolean {
return (
JS_TYPES_RE.test(id) ||
htmlTypesRE.test(id) ||
extensions?.includes(path.extname(id)) ||
false
)
}

// esbuild v0.18 only transforms decorators when `experimentalDecorators` is set to `true`.
Expand Down

0 comments on commit 23ef8a1

Please sign in to comment.