feat(cli): migrate away the dead config keys
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -554,6 +554,33 @@ function migrateImportedLayout(
|
||||
* migrations must preserve semantics and are protected by update backups.
|
||||
*/
|
||||
|
||||
/** Remove a `key: <scalar>` line from a config source, e.g. `compatibilityDate: "..."`. */
|
||||
function removeScalarConfigKey(source: string, key: string): string {
|
||||
return source.replace(new RegExp(`^[ \\t]*${key}:.*\\n`, "m"), "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a `key: { ... }` object property from a config source, using balanced-brace
|
||||
* scanning so a nested `{ ... }` inside the value can't truncate the removal early.
|
||||
*/
|
||||
function removeObjectConfigKey(source: string, key: string): string {
|
||||
const match = new RegExp(`^[ \\t]*${key}\\s*:\\s*\\{`, "m").exec(source);
|
||||
if (!match) return source;
|
||||
const lineStart = match.index;
|
||||
const openBrace = match.index + match[0].length - 1;
|
||||
const closeBrace = findMatching(source, openBrace);
|
||||
if (closeBrace < 0) return source;
|
||||
|
||||
let end = closeBrace + 1;
|
||||
while (source[end] === " " || source[end] === "\t") end++;
|
||||
if (source[end] === ",") end++;
|
||||
while (source[end] === " " || source[end] === "\t") end++;
|
||||
if (source[end] === "\r") end++;
|
||||
if (source[end] === "\n") end++;
|
||||
|
||||
return source.slice(0, lineStart) + source.slice(end);
|
||||
}
|
||||
|
||||
const MIGRATIONS: Migration[] = [
|
||||
{
|
||||
version: "0.8.0",
|
||||
@@ -820,6 +847,27 @@ const MIGRATIONS: Migration[] = [
|
||||
// no application source rewrite is required.
|
||||
},
|
||||
},
|
||||
{
|
||||
version: "0.9.0",
|
||||
id: "remove-dead-config-keys",
|
||||
description: "Delete compatibilityDate, frameworkBehaviour, functions, and compatibility",
|
||||
apply(ctx) {
|
||||
const file = join(ctx.appRoot, "wrnexus.config.ts");
|
||||
if (!existsSync(file)) return;
|
||||
|
||||
const before = readFileSync(file, "utf8");
|
||||
let after = before;
|
||||
after = removeScalarConfigKey(after, "compatibilityDate");
|
||||
after = removeScalarConfigKey(after, "frameworkBehaviour");
|
||||
after = removeObjectConfigKey(after, "functions");
|
||||
after = removeObjectConfigKey(after, "compatibility");
|
||||
|
||||
if (after === before) return;
|
||||
|
||||
ctx.report.changedAutomatically.push(`${file}: removed dead compatibility keys`);
|
||||
if (!ctx.dryRun) writeFileSync(file, after, "utf8");
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
/** Release tooling uses this to require an explicit migration entry per version. */
|
||||
|
||||
Reference in New Issue
Block a user