diff --git a/packages/dev-server/src/index.ts b/packages/dev-server/src/index.ts index 2113e7fc..5a98f0fd 100644 --- a/packages/dev-server/src/index.ts +++ b/packages/dev-server/src/index.ts @@ -272,7 +272,11 @@ export async function startServer(opts: ServeOptions): Promise { const pluginContributions = await pluginRunner.contributions(); const virtualModules = new Map(); - const virtualDir = join(appRoot, ".wrnexus", "virtual"); + // A live dev server and a test process can share an app root. Keeping the + // generated artifacts in a process-specific directory prevents a test boot + // from deleting the running server's client modules. + const cacheDir = join(appRoot, `.wrnexus-${process.pid}`); + const virtualDir = join(cacheDir, "virtual"); mkdirSync(virtualDir, { recursive: true }); for (const [index, module] of pluginContributions.virtualModules.entries()) { const output = join(virtualDir, `plugin-${index}.ts`); @@ -327,12 +331,13 @@ export async function startServer(opts: ServeOptions): Promise { resetDevCache({ rootDir: appRoot, + cacheDir, enabled: process.env.WRNEXUS_PRESERVE_CACHE !== "1", }); // Compile every `.wrn` into ONE cache dir at the project root, instead of a // `.wrnexus/` next to each source file (and inside node_modules UI dirs). - setCompileCacheDir(join(appRoot, ".wrnexus")); + setCompileCacheDir(cacheDir); const theme = resolveThemeConfig(opts.theme); const uiStylesPath = uiCssPath();