(ctx)
| 5057 | }, |
| 5058 | |
| 5059 | async handleHotUpdate(ctx) { |
| 5060 | const { file, server } = ctx; |
| 5061 | if (!wss) { |
| 5062 | return; |
| 5063 | } |
| 5064 | // Graph update for this file change (wrapped to avoid aborting rest of handler) |
| 5065 | try { |
| 5066 | const mod = server.moduleGraph.getModuleById(file) || server.moduleGraph.getModuleById(file + '?vue'); |
| 5067 | if (mod) { |
| 5068 | const deps = Array.from(mod.importedModules) |
| 5069 | .map((m) => (m.id || '').replace(/\?.*$/, '')) |
| 5070 | .filter(Boolean); |
| 5071 | const transformed = await server.transformRequest(mod.id!); |
| 5072 | const code = transformed?.code || ''; |
| 5073 | upsertGraphModule((mod.id || '').replace(/\?.*$/, ''), code, deps); |
| 5074 | } |
| 5075 | } catch (e) { |
| 5076 | if (verbose) console.warn('[hmr-ws][v2] failed graph update', e); |
| 5077 | } |
| 5078 | |
| 5079 | const root = server.config.root || process.cwd(); |
| 5080 | const srcDir = `${root}/src`; |
| 5081 | const coreDir = `${root}/core`; |
| 5082 | const appDir = `${root}/${APP_ROOT_DIR}`; |
| 5083 | const normalizedFile = file.split(path.sep).join('/'); |
| 5084 | const inSrcOrCore = normalizedFile.includes(srcDir) || normalizedFile.includes(coreDir); |
| 5085 | const inApp = normalizedFile.includes(appDir); |
| 5086 | const shouldIgnore = !(inSrcOrCore || inApp); |
| 5087 | if (shouldIgnore) return; |
| 5088 | if (verbose) console.log(`[hmr-ws] Hot update for: ${file}`); |
| 5089 | |
| 5090 | // Handle CSS updates |
| 5091 | if (file.endsWith('.css')) { |
| 5092 | try { |
| 5093 | let rel = '/' + path.posix.normalize(path.relative(root, file)).split(path.sep).join('/'); |
| 5094 | |
| 5095 | const origin = getServerOrigin(server); |
| 5096 | const msg = { |
| 5097 | type: 'ns:css-updates', |
| 5098 | origin, |
| 5099 | updates: [ |
| 5100 | { |
| 5101 | type: 'css-update', |
| 5102 | path: rel, |
| 5103 | acceptedPath: rel, |
| 5104 | timestamp: Date.now(), |
| 5105 | }, |
| 5106 | ], |
| 5107 | }; |
| 5108 | |
| 5109 | wss.clients.forEach((client) => { |
| 5110 | if (client.readyState === client.OPEN) { |
| 5111 | client.send(JSON.stringify(msg)); |
| 5112 | } |
| 5113 | }); |
| 5114 | } catch (error) { |
| 5115 | console.warn('[hmr-ws] CSS update failed:', error); |
| 5116 | } |
nothing calls this directly
no test coverage detected