(file: string, isUnlink: boolean)
| 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) |
no test coverage detected