MCPcopy
hub / github.com/freshframework/fresh / configureServer

Function configureServer

packages/plugin-vite/src/plugins/server_snapshot.ts:73–124  ·  view source on GitHub ↗
(viteServer)

Source from the content-addressed store, hash-verified

71 });
72 },
73 configureServer(viteServer) {
74 server = viteServer;
75
76 viteServer.watcher.on("all", (ev, filePath) => {
77 const { client, ssr } = viteServer.environments;
78
79 // We can't just check if it's in the client module graph
80 // because plugins like tailwindcss import _everything_.
81 // Instead, we walk up the module graph to see if the file
82 // is imported by an island or the client entry file.
83 const mods = client.moduleGraph.getModulesByFile(filePath);
84 if (mods !== undefined) {
85 const seen = new Set<EnvironmentModuleNode>();
86 const maybe = Array.from(mods);
87 for (let i = 0; i < maybe.length; i++) {
88 const mod = maybe[i];
89
90 const isIslandFile = walkUp(
91 mod,
92 (m) => m.file !== null && islandsByFile.has(m.file),
93 seen,
94 );
95
96 // No need to notify manually, vite takes care of this.
97 if (isIslandFile) return;
98 }
99 }
100
101 // Check for route files. We need to invalidate the snapshot if
102 // they are removed or added.
103 if (
104 (ev === "add" || ev === "unlink") &&
105 !/[\\/]+\(_[^)]+\)[\\/]+/.test(filePath)
106 ) {
107 const relRoutes = path.relative(options.routeDir, filePath);
108 if (!relRoutes.startsWith("..")) {
109 const mod = ssr.moduleGraph.getModuleById(`\0${modName}`);
110 if (mod !== undefined) {
111 // Clear state
112 islands.clear();
113 islandsByFile.clear();
114 islandSpecByName.clear();
115
116 ssr.moduleGraph.invalidateModule(mod);
117 }
118 }
119 }
120
121 // Finally, notify the client
122 viteServer.ws.send("fresh:reload");
123 });
124 },
125 resolveId: {
126 filter: {
127 id: /fresh:server-snapshot/,

Callers

nothing calls this directly

Calls 3

walkUpFunction · 0.85
clearMethod · 0.80
sendMethod · 0.80

Tested by

no test coverage detected