(server: ViteDevServer)
| 2350 | emitDelta([], [id]); |
| 2351 | } |
| 2352 | async function populateInitialGraph(server: ViteDevServer) { |
| 2353 | if (graph.size) return; // already populated |
| 2354 | const root = server.config.root || process.cwd(); |
| 2355 | // Avoid direct require in ESM build: lazily obtain fs & path via createRequire or dynamic import |
| 2356 | let fs: typeof import('fs'); |
| 2357 | let pathMod: typeof import('path'); |
| 2358 | try { |
| 2359 | // Prefer createRequire to stay synchronous |
| 2360 | const req = createRequire(import.meta.url); |
| 2361 | fs = req('fs'); |
| 2362 | pathMod = req('path'); |
| 2363 | } catch { |
| 2364 | // Fallback to dynamic imports (should not normally happen) |
| 2365 | fs = await import('fs'); |
| 2366 | pathMod = await import('path'); |
| 2367 | } |
| 2368 | async function walk(dir: string) { |
| 2369 | for (const name of fs.readdirSync(dir)) { |
| 2370 | const full = pathMod.join(dir, name); |
| 2371 | if (name === 'node_modules' || name.startsWith('.')) continue; |
| 2372 | try { |
| 2373 | const stat = fs.statSync(full); |
| 2374 | if (stat.isDirectory()) await walk(full); |
| 2375 | else if (stat.isFile()) { |
| 2376 | if (/\.(vue|ts|js|mjs|tsx|jsx)$/.test(name)) { |
| 2377 | const rel = '/' + pathMod.relative(root, full).split(pathMod.sep).join('/'); |
| 2378 | // Transform via Vite to gather deps (ignore failures) |
| 2379 | try { |
| 2380 | const transformed = await server.transformRequest(rel); |
| 2381 | const code = transformed?.code || ''; |
| 2382 | const deps: string[] = []; |
| 2383 | // fallback to import relationships via moduleGraph |
| 2384 | const modNode = server.moduleGraph.getModuleById(full) || server.moduleGraph.getModuleById(rel); |
| 2385 | if (modNode) { |
| 2386 | for (const m of modNode.importedModules) { |
| 2387 | if (m.id) deps.push(m.id.split('?')[0]); |
| 2388 | } |
| 2389 | } |
| 2390 | upsertGraphModule(rel, code, deps); |
| 2391 | } catch {} |
| 2392 | } |
| 2393 | } |
| 2394 | } catch {} |
| 2395 | } |
| 2396 | } |
| 2397 | try { |
| 2398 | await walk(pathMod.join(root, 'src')); |
| 2399 | } catch {} |
| 2400 | } |
| 2401 | return { |
| 2402 | name: 'nativescript-hmr-websocket', |
| 2403 | apply: 'serve', |
no test coverage detected