Skip to content
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: allow nested dependency selector to be used for optimizeDeps.include for SSR #18506

Merged
merged 10 commits into from
Oct 31, 2024
Prev Previous commit
Next Next commit
refactor: depsOptimizer always exists
  • Loading branch information
sapphi-red committed Oct 29, 2024
commit c32f40ed6cd3d5a4cd58167fac25474b674da3f3
18 changes: 7 additions & 11 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
DEP_VERSION_RE,
ENV_ENTRY,
FS_PREFIX,
OPTIMIZABLE_ENTRY_RE,
SPECIAL_QUERY_RE,
} from '../constants'
import {
Expand Down Expand Up @@ -865,14 +864,11 @@ export function tryNodeResolve(
}

// if we reach here, it's a valid dep import that hasn't been optimized.
const isJsType = depsOptimizer
? isOptimizable(resolved, depsOptimizer.options)
: OPTIMIZABLE_ENTRY_RE.test(resolved)

const exclude = depsOptimizer?.options.exclude
const isJsType = isOptimizable(resolved, depsOptimizer.options)
const exclude = depsOptimizer.options.exclude

const skipOptimization =
depsOptimizer?.options.noDiscovery ||
depsOptimizer.options.noDiscovery ||
!isJsType ||
(importer && isInNodeModules(importer)) ||
exclude?.includes(pkgId) ||
Expand All @@ -886,16 +882,16 @@ export function tryNodeResolve(
// otherwise we may introduce duplicated modules for externalized files
// from pre-bundled deps.
if (!isBuild) {
const versionHash = depsOptimizer!.metadata.browserHash
const versionHash = depsOptimizer.metadata.browserHash
if (versionHash && isJsType) {
resolved = injectQuery(resolved, `v=${versionHash}`)
}
}
} else {
// this is a missing import, queue optimize-deps re-run and
// get a resolved its optimized info
const optimizedInfo = depsOptimizer!.registerMissingImport(id, resolved)
resolved = depsOptimizer!.getOptimizedDepId(optimizedInfo)
const optimizedInfo = depsOptimizer.registerMissingImport(id, resolved)
resolved = depsOptimizer.getOptimizedDepId(optimizedInfo)
}

if (!options.idOnly && !options.scan && isBuild) {
Expand All @@ -906,7 +902,7 @@ export function tryNodeResolve(
moduleSideEffects: pkg.hasSideEffects(resolved),
}
} else {
return { id: resolved! }
return { id: resolved }
}
}

Expand Down