release: WRNexusJS 0.2.75

This commit is contained in:
2026-07-21 12:30:46 +05:30
parent 2ca2d02b22
commit 69b6cd431f
100 changed files with 2313 additions and 116 deletions
+73 -1
View File
@@ -31,6 +31,10 @@ import { startWatcher } from "./watch.ts";
export { RESTART_EXIT_CODE } from "./restart.ts";
import { resetDevCache } from "./cache.ts";
import type { DevToolbarConfig } from "@wrnexus/dev-toolbar/types";
import { createDevToolbarCollector, type DevToolbarCollector } from "@wrnexus/dev-toolbar/server";
export interface ServeOptions {
appDir: string;
port?: number;
@@ -62,6 +66,7 @@ export interface ServeOptions {
storage?: StorageConfig;
mobile?: MobileConfig;
pwa?: PwaConfig | false;
devToolbar?: boolean | DevToolbarConfig;
}
export interface RunningServer {
@@ -112,6 +117,40 @@ async function schemaRuntime(router: Router): Promise<string> {
return renderSchemasScript(descriptors);
}
function resolveDevToolbarConfig(
mode: string,
value: ServeOptions["devToolbar"],
): DevToolbarConfig | null {
if (mode !== "development" || value === false) {
return null;
}
if (value === true || value === undefined) {
return {
enabled: true,
position: "bottom-center",
defaultOpen: false,
scanOnNavigation: true,
scanOnHmr: true,
openEditor: true,
};
}
if (value.enabled === false) {
return null;
}
return {
enabled: true,
position: "bottom-center",
defaultOpen: false,
scanOnNavigation: true,
scanOnHmr: true,
openEditor: true,
...value,
};
}
export async function startServer(opts: ServeOptions): Promise<RunningServer> {
const appDir = resolve(opts.appDir);
const mode: Mode = opts.mode ?? "development";
@@ -124,6 +163,12 @@ export async function startServer(opts: ServeOptions): Promise<RunningServer> {
const styleEntry = opts.styleEntry ?? null;
const appRoot = dirname(appDir);
const devToolbarConfig = resolveDevToolbarConfig(mode, opts.devToolbar);
const devToolbarCollector: DevToolbarCollector | undefined = devToolbarConfig
? createDevToolbarCollector()
: undefined;
resetDevCache({
rootDir: appRoot,
enabled: process.env.WRNEXUS_PRESERVE_CACHE !== "1",
@@ -187,6 +232,12 @@ export async function startServer(opts: ServeOptions): Promise<RunningServer> {
);
const hub = hmr ? new HmrHub() : undefined;
const unsubscribeDevToolbar =
devToolbarCollector && hub
? devToolbarCollector.subscribe((issues) => {
hub.broadcastJson({ channel: "toolbar", type: "toolbar:issues", issues });
})
: undefined;
const middleware = middlewareLoader(router);
const runtimeDeps = {
@@ -207,6 +258,14 @@ export async function startServer(opts: ServeOptions): Promise<RunningServer> {
security: opts.security,
hub,
realtimeBus: realtimeBusFromConfig(opts.realtime),
devToolbar:
devToolbarConfig && devToolbarCollector
? {
config: devToolbarConfig,
collector: devToolbarCollector,
root: appRoot,
}
: undefined,
};
const handlers = createHandlers(runtimeDeps);
@@ -252,8 +311,20 @@ export async function startServer(opts: ServeOptions): Promise<RunningServer> {
console.log(`[wrnexus] hot update — ${files.join(", ")}`);
hub.reload();
hub.broadcastJson({
channel: "toolbar",
type: "toolbar:scan",
reason: "source-change",
files,
});
};
watcher = startWatcher({ appDir, hub, assets, onHotChange: hotUpdate });
watcher = startWatcher({
appDir,
hub,
assets,
devToolbarCollector,
onHotChange: hotUpdate,
});
}
const boundPort = server.port ?? port;
@@ -264,6 +335,7 @@ export async function startServer(opts: ServeOptions): Promise<RunningServer> {
router,
stop: () => {
watcher?.close();
unsubscribeDevToolbar?.();
server.stop();
},
};