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

Function tryFsResolve

packages/vite/src/node/plugins/resolve.ts:553–576  ·  view source on GitHub ↗
(
  fsPath: string,
  options: InternalResolveOptions,
  tryIndex = true,
  skipPackageJson = false,
)

Source from the content-addressed store, hash-verified

551}
552
553export function tryFsResolve(
554 fsPath: string,
555 options: InternalResolveOptions,
556 tryIndex = true,
557 skipPackageJson = false,
558): string | undefined {
559 // Dependencies like es5-ext use `#` in their paths. We don't support `#` in user
560 // source code so we only need to perform the check for dependencies.
561 // We don't support `?` in node_modules paths, so we only need to check in this branch.
562 const hashIndex = fsPath.indexOf('#')
563 if (hashIndex >= 0 && isInNodeModules(fsPath)) {
564 const queryIndex = fsPath.indexOf('?')
565 // We only need to check foo#bar?baz and foo#bar, ignore foo?bar#baz
566 if (queryIndex < 0 || queryIndex > hashIndex) {
567 const file = queryIndex > hashIndex ? fsPath.slice(0, queryIndex) : fsPath
568 const res = tryCleanFsResolve(file, options, tryIndex, skipPackageJson)
569 if (res) return res + fsPath.slice(file.length)
570 }
571 }
572
573 const { file, postfix } = splitFileAndPostfix(fsPath)
574 const res = tryCleanFsResolve(file, options, tryIndex, skipPackageJson)
575 if (res) return res + postfix
576}
577
578const knownTsOutputRE = /\.(?:js|mjs|cjs|jsx)$/
579const isPossibleTsOutput = (url: string): boolean => knownTsOutputRE.test(url)

Callers 4

handlerFunction · 0.90
handlerFunction · 0.90
resolvePackageEntryFunction · 0.85
resolveDeepImportFunction · 0.85

Calls 3

isInNodeModulesFunction · 0.90
splitFileAndPostfixFunction · 0.90
tryCleanFsResolveFunction · 0.85

Tested by

no test coverage detected