refactor: delete the compatibility config surface

This commit is contained in:
2026-08-20 01:11:35 +05:30
parent d19595c7ba
commit 5c8f3ede54
14 changed files with 46 additions and 261 deletions
-76
View File
@@ -1,76 +0,0 @@
import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
import { basename, join, resolve } from "node:path";
import {
CURRENT_COMPATIBILITY_DATE,
CURRENT_FRAMEWORK_BEHAVIOUR,
loadRawConfig,
resolveCompatibility,
} from "@wrnexus/styles";
const CONFIG_NAMES = ["wrnexus.config.ts", "wrnexus.config.js", "wrnexus.config.mjs"];
function configPath(root: string): string | undefined {
return CONFIG_NAMES.map((name) => join(root, name)).find(existsSync);
}
export async function compatibilityReport(appRoot: string) {
return resolveCompatibility(await loadRawConfig(resolve(appRoot)));
}
export function upgradeCompatibility(appRoot: string): {
file: string;
backup: string;
changed: boolean;
} {
const root = resolve(appRoot);
const file = configPath(root);
if (!file) throw new Error("WRN-COMPATIBILITY-NO-CONFIG: wrnexus.config.ts was not found.");
const source = readFileSync(file, "utf8");
let updated = source;
const replace = (name: string, value: string) => {
const pattern = new RegExp(`(^\\s*${name}\\s*:\\s*)(?:["'][^"']*["']|\\d+)(\\s*,?)`, "m");
if (pattern.test(updated)) updated = updated.replace(pattern, `$1${value}$2`);
else {
const object = /(?:const\s+config[^=]*=|defineConfig\s*\(|export\s+default)\s*\{/m;
if (!object.test(updated))
throw new Error("WRN-COMPATIBILITY-CONFIG-SHAPE: unable to locate the root config object.");
updated = updated.replace(object, (match) => `${match}\n ${name}: ${value},`);
}
};
replace("compatibilityDate", JSON.stringify(CURRENT_COMPATIBILITY_DATE));
replace("frameworkBehaviour", String(CURRENT_FRAMEWORK_BEHAVIOUR));
if (updated === source) return { file, backup: "", changed: false };
const directory = join(root, ".wrnexus", "compatibility-backups");
mkdirSync(directory, { recursive: true });
const backup = join(directory, `${Date.now()}-${basename(file)}`);
copyFileSync(file, backup);
writeFileSync(file, updated, "utf8");
return { file, backup, changed: true };
}
export async function runCompatibilityCommand(
appRoot: string,
command = "check",
args: string[] = [],
): Promise<boolean> {
if (command === "upgrade") {
const result = upgradeCompatibility(appRoot);
if (args.includes("--json")) console.log(JSON.stringify(result, null, 2));
else
console.log(
result.changed
? `✓ Compatibility policy upgraded\n backup: ${result.backup}`
: "✓ Compatibility policy already current",
);
}
const report = await compatibilityReport(appRoot);
if (args.includes("--json")) console.log(JSON.stringify(report, null, 2));
else {
console.log(`Compatibility date: ${report.effectiveDate} (current ${report.currentDate})`);
console.log(
`Framework behaviour: ${report.effectiveBehaviour} (current ${report.currentBehaviour})`,
);
for (const message of report.messages) console.log(`- ${message}`);
}
return !report.needsUpgrade && !report.future;
}
-9
View File
@@ -260,8 +260,6 @@ trim_trailing_whitespace = true
"wrnexus.config.ts": `import type { AppConfig } from "@wrnexus/styles";
const config: AppConfig = {
compatibilityDate: "2026-08-02",
frameworkBehaviour: 1,
// v0.8 defaults: explicit imports, strict template types, safe stores, and
// automatic progressive navigation. Package plugins are discovered from the
// installed packages above; add custom plugins to this array when needed.
@@ -275,14 +273,7 @@ const config: AppConfig = {
checkComponentProps: true,
generateDeclarations: true,
},
functions: { legacyDefaultRuntime: "current" },
stores: { strictMutations: true, persistence: true },
compatibility: {
legacyEmit: false,
legacyEventProps: false,
legacyComponentDiscovery: false,
stringLayouts: false,
},
experimental: {},
performance: {
-12
View File
@@ -72,8 +72,6 @@ Usage:
Run unit | component | api | browser | visual | accessibility | performance
wrnexus profiles [app-dir] List config profiles (dev/prod/uat/…) and their env files
wrnexus doctor [app-dir] [--fix] Check project health; optionally apply safe repairs
wrnexus compatibility <check|explain|upgrade> [app-dir]
Inspect or explicitly upgrade behavior defaults
wrnexus contracts <check|snapshot> [app-dir]
Detect breaking boundary contract changes
wrnexus security <audit|headers|test> [app-dir]
@@ -292,16 +290,6 @@ async function main(): Promise<void> {
if (!healthy) process.exitCode = 1;
break;
}
case "compatibility": {
const { runCompatibilityCommand } = await import("./compatibility-command.ts");
const subcommand = rest.find((value) => !value.startsWith("--")) ?? "check";
const appRoot = rest.filter((value) => !value.startsWith("--"))[1] ?? ".";
if (!["check", "explain", "upgrade"].includes(subcommand))
throw new Error(`WRN-COMPATIBILITY-COMMAND: unknown command '${subcommand}'.`);
const current = await runCompatibilityCommand(appRoot, subcommand, rest);
if (!current && subcommand !== "explain") process.exitCode = 1;
break;
}
case "contracts": {
const { runContractsCommand } = await import("./contracts-command.ts");
const subcommand = rest.find((value) => !value.startsWith("--")) ?? "check";
+2 -2
View File
@@ -385,8 +385,8 @@ function updateV060Config(ctx: MigrationCtx): void {
const file = candidates.map((name) => join(ctx.appRoot, name)).find(existsSync);
if (!file) return;
const current = readFileSync(file, "utf8");
if (/\bimports\s*:/.test(current) && /\bcompatibility\s*:/.test(current)) return;
const insertion = `\n imports: { mode: "compatible", autoImport: true, aliases: { "@": "./app" } },\n types: { strict: false, noImplicitAny: false, strictNullChecks: true, checkTemplates: true, checkComponentProps: true, generateDeclarations: true, globalTypes: "./app/types/global.d.ts" },\n functions: { legacyDefaultRuntime: "current" },\n stores: { strictMutations: true, persistence: true },\n compatibility: { legacyEmit: true, legacyEventProps: true, legacyComponentDiscovery: true, stringLayouts: true },`;
if (/\bimports\s*:/.test(current)) return;
const insertion = `\n imports: { mode: "compatible", autoImport: true, aliases: { "@": "./app" } },\n types: { strict: false, noImplicitAny: false, strictNullChecks: true, checkTemplates: true, checkComponentProps: true, generateDeclarations: true, globalTypes: "./app/types/global.d.ts" },\n stores: { strictMutations: true, persistence: true },`;
const index = current.lastIndexOf("}");
if (index < 0) return;
const next =
-17
View File
@@ -1,17 +0,0 @@
import { expect, test } from "bun:test";
import { mkdtempSync, readFileSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { compatibilityReport, upgradeCompatibility } from "../src/compatibility-command.ts";
test("compatibility upgrade is backed up, current, and idempotent", async () => {
const root = mkdtempSync(join(tmpdir(), "wrnexus-compatibility-"));
const file = join(root, "wrnexus.config.ts");
writeFileSync(file, `export default { port: 3000 };\n`);
const first = upgradeCompatibility(root);
expect(first.changed).toBe(true);
expect(readFileSync(first.backup, "utf8")).toContain("port: 3000");
expect(readFileSync(file, "utf8")).toContain('compatibilityDate: "2026-08-02"');
expect(upgradeCompatibility(root).changed).toBe(false);
expect((await compatibilityReport(root)).needsUpgrade).toBe(false);
});
-1
View File
@@ -96,7 +96,6 @@ test("scaffoldApp includes the complete v0.8 configuration and starter structure
"imports:",
"types:",
"stores:",
"compatibility:",
"performance:",
"observability:",
"tenancy:",