MCPcopy
hub / github.com/vitejs/vite / ensureVersionQuery

Function ensureVersionQuery

packages/vite/src/node/plugins/resolve.ts:525–551  ·  view source on GitHub ↗
(
  resolved: string,
  id: string,
  options: InternalResolveOptions,
  depsOptimizer?: DepsOptimizer,
)

Source from the content-addressed store, hash-verified

523}
524
525function ensureVersionQuery(
526 resolved: string,
527 id: string,
528 options: InternalResolveOptions,
529 depsOptimizer?: DepsOptimizer,
530): string {
531 if (
532 !options.isBuild &&
533 !options.scan &&
534 depsOptimizer &&
535 !(resolved === normalizedClientEntry || resolved === normalizedEnvEntry)
536 ) {
537 // Ensure that direct imports of node_modules have the same version query
538 // as if they would have been imported through a bare import
539 // Use the original id to do the check as the resolved id may be the real
540 // file path after symlinks resolution
541 const isNodeModule = isInNodeModules(id) || isInNodeModules(resolved)
542
543 if (isNodeModule && !DEP_VERSION_RE.test(resolved)) {
544 const versionHash = depsOptimizer.metadata.browserHash
545 if (versionHash && isOptimizable(resolved, depsOptimizer.options)) {
546 resolved = injectQuery(resolved, `v=${versionHash}`)
547 }
548 }
549 }
550 return resolved
551}
552
553export function tryFsResolve(
554 fsPath: string,

Callers 1

oxcResolvePluginFunction · 0.85

Calls 3

isInNodeModulesFunction · 0.90
isOptimizableFunction · 0.90
injectQueryFunction · 0.90

Tested by

no test coverage detected