fix(dev): consolidate generated cache directories
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wrnexus/cli",
|
||||
"version": "0.8.30",
|
||||
"version": "0.8.31",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"exports": {
|
||||
|
||||
@@ -540,6 +540,7 @@ export async function runGateway(root: string, args: string[]): Promise<void> {
|
||||
|
||||
const hostname = hostArg?.split("=")[1] ?? environmentConfig.hostname;
|
||||
|
||||
// The published CLI bundle carries the matching gateway/cache lifecycle.
|
||||
const { startGateway } = await import("@wrnexus/dev-server");
|
||||
|
||||
await startGateway({
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wrnexus/dev-server",
|
||||
"version": "0.8.28",
|
||||
"version": "0.8.29",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"exports": {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { existsSync, rmSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { existsSync, readdirSync, rmSync } from "node:fs";
|
||||
import { join, resolve } from "node:path";
|
||||
|
||||
export interface ResetDevCacheOptions {
|
||||
rootDir?: string;
|
||||
@@ -7,6 +7,19 @@ export interface ResetDevCacheOptions {
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
function removeLegacyProcessCaches(rootDir: string): void {
|
||||
if (!existsSync(rootDir)) return;
|
||||
for (const entry of readdirSync(rootDir, { withFileTypes: true })) {
|
||||
if (!entry.isDirectory() || !/^\.wrnexus-\d+$/.test(entry.name)) continue;
|
||||
rmSync(join(rootDir, entry.name), {
|
||||
recursive: true,
|
||||
force: true,
|
||||
maxRetries: 3,
|
||||
retryDelay: 100,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function resetDevCache(options: ResetDevCacheOptions = {}): string {
|
||||
const rootDir = resolve(options.rootDir ?? process.cwd());
|
||||
|
||||
@@ -16,6 +29,8 @@ export function resetDevCache(options: ResetDevCacheOptions = {}): string {
|
||||
return cacheDir;
|
||||
}
|
||||
|
||||
removeLegacyProcessCaches(rootDir);
|
||||
|
||||
// Safety: never allow deleting the project root.
|
||||
if (cacheDir === rootDir) {
|
||||
throw new Error("Refusing to remove the project root as the WRNexus cache directory.");
|
||||
|
||||
@@ -288,10 +288,9 @@ export async function startServer(opts: ServeOptions): Promise<RunningServer> {
|
||||
|
||||
const pluginContributions = await pluginRunner.contributions();
|
||||
const virtualModules = new Map<string, string>();
|
||||
// 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}`);
|
||||
// Keep generated artifacts under the single framework state directory.
|
||||
// Startup clears this cache and removes legacy PID-suffixed cache folders.
|
||||
const cacheDir = join(appRoot, ".wrnexus", "cache");
|
||||
const virtualDir = join(cacheDir, "virtual");
|
||||
mkdirSync(virtualDir, { recursive: true });
|
||||
for (const [index, module] of pluginContributions.virtualModules.entries()) {
|
||||
|
||||
@@ -63,14 +63,14 @@ export default defineAuthz({ permissions: { "post:read": { title: "View posts" }
|
||||
try {
|
||||
expect(hasAuthzCatalog()).toBe(true);
|
||||
expect(getAuthzCatalog().permissions.has("post:read")).toBe(true);
|
||||
const cacheDir = join(appDir, "..", `.wrnexus-${process.pid}`);
|
||||
const cacheDir = join(appDir, "..", ".wrnexus", "cache");
|
||||
mkdirSync(cacheDir, { recursive: true });
|
||||
writeFileSync(join(cacheDir, "generated.js"), "generated", "utf8");
|
||||
expect(existsSync(cacheDir)).toBe(true);
|
||||
} finally {
|
||||
server.stop();
|
||||
}
|
||||
expect(existsSync(join(appDir, "..", `.wrnexus-${process.pid}`))).toBe(false);
|
||||
expect(existsSync(join(appDir, "..", ".wrnexus", "cache"))).toBe(false);
|
||||
});
|
||||
|
||||
test("an app with no app/authz declarations boots without throwing", async () => {
|
||||
|
||||
@@ -18,7 +18,7 @@ test("per-process dev caches are excluded from root and example project tools",
|
||||
const projects = ["basic-app", "inter-app-api-showcase"].map((name) =>
|
||||
join(root, "examples", name),
|
||||
);
|
||||
const caches = projects.map((project) => join(project, ".wrnexus-123"));
|
||||
const caches = projects.map((project) => join(project, ".wrnexus", "cache"));
|
||||
|
||||
for (const project of projects) {
|
||||
const projectEslint = readFileSync(join(project, "eslint.config.js"), "utf8");
|
||||
|
||||
Reference in New Issue
Block a user