feat(cli): migrate mode-scoped helpers to shared functions

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-20 11:58:16 +05:30
co-authored by Claude Opus 5
parent 74490964ee
commit e616ed276e
3 changed files with 444 additions and 0 deletions
+38
View File
@@ -35,6 +35,7 @@ import { formatWrn, parse } from "@wrnexus/syntax";
import { AI_GUIDE, CLAUDE_MD } from "./ai-guide.ts";
import { inspectProject, type DoctorCheck } from "./doctor.ts";
import { migrateApisBlock } from "./migrations/apis-block.ts";
import { migrateModeFunctions } from "./migrations/mode-functions.ts";
import { generateApplicationTypes } from "./types.ts";
/** The version of the CLI currently running (its own package.json). */
@@ -869,6 +870,43 @@ const MIGRATIONS: Migration[] = [
if (!ctx.dryRun) writeFileSync(file, after, "utf8");
},
},
{
version: "0.9.0",
id: "move-mode-functions",
description:
"Move mode-scoped helpers out of legacy ssr/client functions blocks into a page-level shared functions block",
apply(ctx) {
const appDirectory = join(ctx.appRoot, "app");
if (!existsSync(appDirectory)) return;
for (const file of walkProjectFiles(appDirectory, ".wrn")) {
const relativeFile = relative(ctx.appRoot, file).replace(/\\/g, "/");
const before = readFileSync(file, "utf8");
let result: ReturnType<typeof migrateModeFunctions>;
try {
result = migrateModeFunctions(before);
} catch (error) {
const message = error instanceof Error ? error.message.split("\n", 1)[0] : String(error);
ctx.report.parseFailures.push(`${relativeFile}: ${message}`);
ctx.log(`! ${relativeFile}: left unchanged because the mode-functions migration failed`);
continue;
}
if ("skip" in result) {
ctx.report.needsReview.push(`${relativeFile}: ${result.skip}`);
continue;
}
if (!result.changed) continue;
ctx.report.changedAutomatically.push(
`${relativeFile}: moved mode-scoped helpers into functions { shared … }`,
);
ctx.log(`~ ${relativeFile}: moved mode-scoped helpers into functions { shared … }`);
if (!ctx.dryRun) writeFileSync(file, result.source, "utf8");
}
},
},
{
version: "0.9.0",
id: "move-api-blocks",