release: WRNexusJS 0.2.40
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@wrnexus/dev-server",
|
||||
"version": "0.2.39",
|
||||
"version": "0.2.40",
|
||||
"type": "module",
|
||||
"main": "src/index.ts",
|
||||
"exports": {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
import { existsSync, rmSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
|
||||
export interface ResetDevCacheOptions {
|
||||
rootDir?: string;
|
||||
cacheDir?: string;
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
export function resetDevCache(options: ResetDevCacheOptions = {}): string {
|
||||
const rootDir = resolve(options.rootDir ?? process.cwd());
|
||||
|
||||
const cacheDir = resolve(rootDir, options.cacheDir ?? ".wrnexus");
|
||||
|
||||
if (options.enabled === false) {
|
||||
return cacheDir;
|
||||
}
|
||||
|
||||
// Safety: never allow deleting the project root.
|
||||
if (cacheDir === rootDir) {
|
||||
throw new Error("Refusing to remove the project root as the WRNexus cache directory.");
|
||||
}
|
||||
|
||||
if (existsSync(cacheDir)) {
|
||||
rmSync(cacheDir, {
|
||||
recursive: true,
|
||||
force: true,
|
||||
maxRetries: 3,
|
||||
retryDelay: 100,
|
||||
});
|
||||
|
||||
console.log(`[wrnexus] cleared generated cache: ${cacheDir}`);
|
||||
}
|
||||
|
||||
return cacheDir;
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import { createDevAssetServer } from "./assets.ts";
|
||||
import { HmrHub } from "./hmr.ts";
|
||||
import { startWatcher } from "./watch.ts";
|
||||
export { RESTART_EXIT_CODE } from "./restart.ts";
|
||||
import { resetDevCache } from "./cache.ts";
|
||||
|
||||
export interface ServeOptions {
|
||||
appDir: string;
|
||||
@@ -122,6 +123,12 @@ export async function startServer(opts: ServeOptions): Promise<RunningServer> {
|
||||
const router = buildRouter(appDir, { componentDirs: [uiComponentsDir()] });
|
||||
const styleEntry = opts.styleEntry ?? null;
|
||||
const appRoot = dirname(appDir);
|
||||
|
||||
resetDevCache({
|
||||
rootDir: appRoot,
|
||||
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"));
|
||||
|
||||
Reference in New Issue
Block a user