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

Function onFileAddUnlink

packages/vite/src/node/server/index.ts:859–895  ·  view source on GitHub ↗
(file: string, isUnlink: boolean)

Source from the content-addressed store, hash-verified

857 }
858
859 const onFileAddUnlink = async (file: string, isUnlink: boolean) => {
860 file = normalizePath(file)
861 reloadOnTsconfigChange(server, file)
862
863 await Promise.all(
864 Object.values(server.environments).map((environment) =>
865 environment.pluginContainer.watchChange(file, {
866 event: isUnlink ? 'delete' : 'create',
867 }),
868 ),
869 )
870
871 if (publicDir && publicFiles) {
872 if (file.startsWith(publicDir)) {
873 const path = file.slice(publicDir.length)
874 publicFiles[isUnlink ? 'delete' : 'add'](path)
875 if (!isUnlink) {
876 const clientModuleGraph = server.environments.client.moduleGraph
877 const moduleWithSamePath =
878 await clientModuleGraph.getModuleByUrl(path)
879 const etag = moduleWithSamePath?.transformResult?.etag
880 if (etag) {
881 // The public file should win on the next request over a module with the
882 // same path. Prevent the transform etag fast path from serving the module
883 clientModuleGraph.etagToModuleMap.delete(etag)
884 }
885 }
886 }
887 }
888 if (isUnlink) {
889 // invalidate module graph cache on file change
890 for (const environment of Object.values(server.environments)) {
891 environment.moduleGraph.onFileDelete(file)
892 }
893 }
894 await onHMRUpdate(isUnlink ? 'delete' : 'create', file)
895 }
896
897 const onFileChange = async (file: string) => {
898 file = normalizePath(file)

Callers 1

_createServerFunction · 0.85

Calls 7

normalizePathFunction · 0.90
reloadOnTsconfigChangeFunction · 0.90
onHMRUpdateFunction · 0.85
deleteMethod · 0.80
watchChangeMethod · 0.45
getModuleByUrlMethod · 0.45
onFileDeleteMethod · 0.45

Tested by

no test coverage detected