refactor: delete the compatibility config surface
This commit is contained in:
@@ -1,59 +0,0 @@
|
||||
export const CURRENT_COMPATIBILITY_DATE = "2026-08-02";
|
||||
export const CURRENT_FRAMEWORK_BEHAVIOUR = 1;
|
||||
|
||||
export interface CompatibilityPolicy {
|
||||
compatibilityDate?: string;
|
||||
frameworkBehaviour?: number;
|
||||
}
|
||||
|
||||
export interface CompatibilityReport {
|
||||
configuredDate?: string;
|
||||
effectiveDate: string;
|
||||
currentDate: string;
|
||||
configuredBehaviour?: number;
|
||||
effectiveBehaviour: number;
|
||||
currentBehaviour: number;
|
||||
needsUpgrade: boolean;
|
||||
future: boolean;
|
||||
messages: string[];
|
||||
}
|
||||
|
||||
export function isCompatibilityDate(value: string): boolean {
|
||||
if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) return false;
|
||||
const date = new Date(`${value}T00:00:00.000Z`);
|
||||
return Number.isFinite(date.getTime()) && date.toISOString().slice(0, 10) === value;
|
||||
}
|
||||
|
||||
export function resolveCompatibility(policy: CompatibilityPolicy): CompatibilityReport {
|
||||
const configuredDate = policy.compatibilityDate;
|
||||
const configuredBehaviour = policy.frameworkBehaviour;
|
||||
const effectiveDate = configuredDate ?? "1970-01-01";
|
||||
const effectiveBehaviour = configuredBehaviour ?? 0;
|
||||
const future =
|
||||
(configuredDate !== undefined && configuredDate > CURRENT_COMPATIBILITY_DATE) ||
|
||||
(configuredBehaviour !== undefined && configuredBehaviour > CURRENT_FRAMEWORK_BEHAVIOUR);
|
||||
const needsUpgrade =
|
||||
!future &&
|
||||
(effectiveDate < CURRENT_COMPATIBILITY_DATE ||
|
||||
effectiveBehaviour < CURRENT_FRAMEWORK_BEHAVIOUR);
|
||||
const messages: string[] = [];
|
||||
if (!configuredDate) messages.push("compatibilityDate is not configured; legacy defaults apply.");
|
||||
if (!configuredBehaviour)
|
||||
messages.push("frameworkBehaviour is not configured; behaviour version 0 applies.");
|
||||
if (future)
|
||||
messages.push("Configuration targets framework behavior newer than this CLI supports.");
|
||||
else if (needsUpgrade)
|
||||
messages.push("A newer compatibility policy is available; review it before upgrading.");
|
||||
else messages.push("Compatibility policy matches the current framework behavior.");
|
||||
return {
|
||||
configuredDate,
|
||||
effectiveDate,
|
||||
currentDate: CURRENT_COMPATIBILITY_DATE,
|
||||
configuredBehaviour,
|
||||
effectiveBehaviour,
|
||||
currentBehaviour: CURRENT_FRAMEWORK_BEHAVIOUR,
|
||||
needsUpgrade,
|
||||
future,
|
||||
messages,
|
||||
};
|
||||
}
|
||||
@@ -17,11 +17,6 @@ import type { StorageConfig } from "@wrnexus/uploader";
|
||||
import type { BrowserCookiesConfig, ThemeConfig } from "./theme.ts";
|
||||
import type { FontConfig } from "./fonts.ts";
|
||||
import { fontCspSources } from "./fonts.ts";
|
||||
import {
|
||||
isCompatibilityDate,
|
||||
resolveCompatibility,
|
||||
type CompatibilityPolicy,
|
||||
} from "./compatibility.ts";
|
||||
|
||||
export type Mode = "development" | "production";
|
||||
|
||||
@@ -230,23 +225,12 @@ export interface TypesConfig {
|
||||
globalTypes?: string;
|
||||
}
|
||||
|
||||
export interface FunctionsConfig {
|
||||
legacyDefaultRuntime?: "current" | "client" | "server" | "shared";
|
||||
}
|
||||
|
||||
export interface StoresConfig {
|
||||
strictMutations?: boolean;
|
||||
persistence?: boolean;
|
||||
}
|
||||
|
||||
export interface CompatibilityConfig {
|
||||
legacyEmit?: boolean;
|
||||
legacyEventProps?: boolean;
|
||||
legacyComponentDiscovery?: boolean;
|
||||
stringLayouts?: boolean;
|
||||
}
|
||||
|
||||
export interface AppConfig extends CompatibilityPolicy {
|
||||
export interface AppConfig {
|
||||
/** Ordered reusable configuration layers; the application always has final precedence. */
|
||||
extends?: string | string[];
|
||||
/** Compiler/dev/build plugins, resolved in deterministic pre/normal/post order. */
|
||||
@@ -260,12 +244,8 @@ export interface AppConfig extends CompatibilityPolicy {
|
||||
imports?: ImportsConfig;
|
||||
/** TypeScript-backed .wrn type checking and declaration generation. */
|
||||
types?: TypesConfig;
|
||||
/** Legacy function runtime behavior for existing applications. */
|
||||
functions?: FunctionsConfig;
|
||||
/** Typed global/page store behavior. */
|
||||
stores?: StoresConfig;
|
||||
/** Temporary v0.5 syntax compatibility switches. */
|
||||
compatibility?: CompatibilityConfig;
|
||||
/** Opt-in APIs that are not yet covered by stable compatibility guarantees. */
|
||||
experimental?: ExperimentalConfig;
|
||||
/** Route and asset budgets plus build analyzer behavior. */
|
||||
@@ -597,32 +577,23 @@ export function defineConfig(config: AppConfig): AppConfig {
|
||||
return config;
|
||||
}
|
||||
|
||||
const REMOVED_CONFIG_KEYS = [
|
||||
"compatibilityDate",
|
||||
"frameworkBehaviour",
|
||||
"functions",
|
||||
"compatibility",
|
||||
] as const;
|
||||
|
||||
export function validateAppConfig(config: AppConfig): ConfigIssue[] {
|
||||
const issues: ConfigIssue[] = [];
|
||||
if (config.compatibilityDate !== undefined && !isCompatibilityDate(config.compatibilityDate)) {
|
||||
issues.push({
|
||||
path: "compatibilityDate",
|
||||
severity: "error",
|
||||
message: "must be a real ISO calendar date in YYYY-MM-DD format",
|
||||
});
|
||||
}
|
||||
if (
|
||||
config.frameworkBehaviour !== undefined &&
|
||||
(!Number.isInteger(config.frameworkBehaviour) || config.frameworkBehaviour < 1)
|
||||
) {
|
||||
issues.push({
|
||||
path: "frameworkBehaviour",
|
||||
severity: "error",
|
||||
message: "must be a positive integer",
|
||||
});
|
||||
}
|
||||
const compatibility = resolveCompatibility(config);
|
||||
if (compatibility.future) {
|
||||
issues.push({
|
||||
path: "compatibilityDate",
|
||||
severity: "error",
|
||||
message: "targets framework behavior newer than this version supports",
|
||||
});
|
||||
for (const key of REMOVED_CONFIG_KEYS) {
|
||||
if ((config as Record<string, unknown>)[key] !== undefined) {
|
||||
issues.push({
|
||||
path: key,
|
||||
severity: "error",
|
||||
message: "was removed; delete it from the configuration",
|
||||
});
|
||||
}
|
||||
}
|
||||
const sampleRate = config.observability?.sampleRate;
|
||||
if (
|
||||
|
||||
@@ -36,13 +36,6 @@ export {
|
||||
resolveConfigLayers,
|
||||
validateAppConfig,
|
||||
} from "./config.ts";
|
||||
export {
|
||||
CURRENT_COMPATIBILITY_DATE,
|
||||
CURRENT_FRAMEWORK_BEHAVIOUR,
|
||||
isCompatibilityDate,
|
||||
resolveCompatibility,
|
||||
} from "./compatibility.ts";
|
||||
export type { CompatibilityPolicy, CompatibilityReport } from "./compatibility.ts";
|
||||
export { findStyleEntry, bundleCss } from "./styles.ts";
|
||||
export type { FontConfig, GoogleFont, LocalFontFace, FontDisplay } from "./fonts.ts";
|
||||
export { renderFontHead, renderProductionFontHead, fontCspSources } from "./fonts.ts";
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
resolveProfile,
|
||||
loadEnv,
|
||||
renderStyles,
|
||||
resolveCompatibility,
|
||||
validateAppConfig,
|
||||
explainAppConfig,
|
||||
} from "../src/index.ts";
|
||||
@@ -16,18 +15,6 @@ afterEach(() => {
|
||||
delete process.env.WRNEXUS_PROFILE;
|
||||
});
|
||||
|
||||
test("compatibility dates pin behavior and reject invalid or future policies", () => {
|
||||
expect(
|
||||
resolveCompatibility({ compatibilityDate: "2026-08-02", frameworkBehaviour: 1 }),
|
||||
).toMatchObject({ needsUpgrade: false, future: false, effectiveBehaviour: 1 });
|
||||
expect(validateAppConfig({ compatibilityDate: "2026-02-31" })).toContainEqual(
|
||||
expect.objectContaining({ path: "compatibilityDate", severity: "error" }),
|
||||
);
|
||||
expect(validateAppConfig({ frameworkBehaviour: 2 })).toContainEqual(
|
||||
expect.objectContaining({ severity: "error" }),
|
||||
);
|
||||
});
|
||||
|
||||
test("observability config requires bounded sampling and a valid OTLP endpoint", () => {
|
||||
expect(validateAppConfig({ observability: { sampleRate: Number.NaN } })).toContainEqual(
|
||||
expect.objectContaining({ path: "observability.sampleRate", severity: "error" }),
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { validateAppConfig } from "../src/config.ts";
|
||||
|
||||
// A stale config must fail loudly. Silently ignoring a removed key leaves
|
||||
// someone believing a flag still applies.
|
||||
const REMOVED = [
|
||||
{ key: "compatibilityDate", config: { compatibilityDate: "2026-08-02" } },
|
||||
{ key: "frameworkBehaviour", config: { frameworkBehaviour: 1 } },
|
||||
{ key: "functions", config: { functions: { legacyDefaultRuntime: "current" } } },
|
||||
{ key: "compatibility", config: { compatibility: { legacyEmit: false } } },
|
||||
];
|
||||
|
||||
for (const { key, config } of REMOVED) {
|
||||
test(`a config still setting "${key}" is rejected with a message naming it`, () => {
|
||||
const issues = validateAppConfig(config as never);
|
||||
const match = issues.find((issue) => issue.path === key || issue.path.startsWith(`${key}.`));
|
||||
|
||||
expect(match).toBeDefined();
|
||||
expect(match!.severity).toBe("error");
|
||||
expect(match!.message.toLowerCase()).toContain("removed");
|
||||
});
|
||||
}
|
||||
|
||||
test("a config without those keys is accepted", () => {
|
||||
const issues = validateAppConfig({} as never);
|
||||
|
||||
expect(issues.filter((issue) => issue.severity === "error")).toEqual([]);
|
||||
});
|
||||
Reference in New Issue
Block a user