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

Function checkPublicFile

packages/vite/src/node/publicDir.ts:36–64  ·  view source on GitHub ↗
(
  url: string,
  config: ResolvedConfig,
)

Source from the content-addressed store, hash-verified

34}
35
36export function checkPublicFile(
37 url: string,
38 config: ResolvedConfig,
39): string | undefined {
40 // note if the file is in /public, the resolver would have returned it
41 // as-is so it's not going to be a fully resolved path.
42 const { publicDir } = config
43 if (!publicDir || url[0] !== '/') {
44 return
45 }
46
47 const fileName = cleanUrl(url)
48
49 // short-circuit if we have an in-memory publicFiles cache
50 const publicFiles = getPublicFiles(config)
51 if (publicFiles) {
52 return publicFiles.has(fileName)
53 ? normalizePath(path.join(publicDir, fileName))
54 : undefined
55 }
56
57 const publicFile = normalizePath(path.join(publicDir, fileName))
58 if (!publicFile.startsWith(withTrailingSlash(publicDir))) {
59 // can happen if URL starts with '../'
60 return
61 }
62
63 return tryStatSync(publicFile)?.isFile() ? publicFile : undefined
64}

Callers 10

loadAndTransformFunction · 0.90
shouldPreTransformFunction · 0.90
handlerFunction · 0.90
handlerFunction · 0.90
fileToDevUrlFunction · 0.90
fileToBuiltUrlFunction · 0.90
urlToBuiltUrlFunction · 0.90
transformFunction · 0.90
urlResolverFunction · 0.90
resolveFunction · 0.90

Calls 6

cleanUrlFunction · 0.90
normalizePathFunction · 0.90
withTrailingSlashFunction · 0.90
tryStatSyncFunction · 0.90
getPublicFilesFunction · 0.85
hasMethod · 0.80

Tested by

no test coverage detected