From c0a866d027eed809cf7d4bdf119237faeeef176e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 9 Apr 2026 07:48:38 +0000 Subject: [PATCH] fix: improve update tool output for Fresh 2 projects (#3754) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary - Detects whether a project is already on Fresh 2 by checking `deno.json` imports - Shows "Updating Fresh to X.Y.Z..." instead of "Starting Fresh 1 to Fresh 2 migration..." for existing Fresh 2 projects - Only shows "Breaking changes may require additional manual updates" warning for actual Fresh 1→2 migrations - Summary/completion messages adapt accordingly ("Update" vs "Migration") Closes #3688 --------- Co-authored-by: Claude Opus 4.6 (1M context) --- packages/update/src/mod.ts | 8 ----- packages/update/src/update.ts | 63 +++++++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 15 deletions(-) diff --git a/packages/update/src/mod.ts b/packages/update/src/mod.ts index 7a27e548..074f5101 100644 --- a/packages/update/src/mod.ts +++ b/packages/update/src/mod.ts @@ -29,14 +29,6 @@ console.log(colors.bgRgb8( )); // deno-lint-ignore no-console console.log(); -// deno-lint-ignore no-console -console.log( - colors.italic( - "Note: Breaking changes may require additional manual updates.", - ), -); -// deno-lint-ignore no-console -console.log(); let unresolvedDirectory = Deno.args[0]; if (flags._.length !== 1) { diff --git a/packages/update/src/update.ts b/packages/update/src/update.ts index 745034ae..8b3a8a6e 100644 --- a/packages/update/src/update.ts +++ b/packages/update/src/update.ts @@ -86,10 +86,44 @@ const compat = new Set([ "UnknownPageProps", ]); +async function detectFresh2(dir: string): Promise { + for (const filename of ["deno.json", "deno.jsonc"]) { + try { + const content = await Deno.readTextFile(path.join(dir, filename)); + const config = JSONC.parse(content) as DenoJson; + const imports = config.imports; + if (imports) { + // Fresh 2 uses "fresh" or "@fresh/core" as the import specifier + if (imports["fresh"]?.includes("@fresh/core")) { + return true; + } + } + } catch { + // File doesn't exist, try next + } + } + return false; +} + export async function updateProject(dir: string) { - // add initial log - // deno-lint-ignore no-console - console.log(colors.blue("🚀 Starting Fresh 1 to Fresh 2 migration...")); + // Detect if the project is already on Fresh 2 by checking imports + const isFresh2 = await detectFresh2(dir); + + if (isFresh2) { + // deno-lint-ignore no-console + console.log(colors.blue(`🔄 Updating Fresh to ${FRESH_VERSION}...`)); + } else { + // deno-lint-ignore no-console + console.log(colors.blue("🚀 Starting Fresh 1 to Fresh 2 migration...")); + // deno-lint-ignore no-console + console.log( + colors.italic( + "Note: Breaking changes may require additional manual updates.", + ), + ); + // deno-lint-ignore no-console + console.log(); + } // deno-lint-ignore no-console console.log(colors.yellow("📝 Updating configuration files...")); @@ -194,7 +228,13 @@ export async function updateProject(dir: string) { if (filesToProcess.length === 0) { // deno-lint-ignore no-console - console.log(colors.green("🎉 Migration completed successfully!")); + console.log( + colors.green( + isFresh2 + ? "🎉 Update completed successfully!" + : "🎉 Migration completed successfully!", + ), + ); return; } @@ -238,9 +278,11 @@ export async function updateProject(dir: string) { // Clear the progress line and add a newline await bar.stop(); - // add migration summary // deno-lint-ignore no-console - console.log("\n" + colors.bold("📊 Migration Summary:")); + console.log( + "\n" + + colors.bold(isFresh2 ? "📊 Update Summary:" : "📊 Migration Summary:"), + ); // deno-lint-ignore no-console console.log(` Total files processed: ${filesToProcess.length}`); // deno-lint-ignore no-console @@ -267,7 +309,14 @@ export async function updateProject(dir: string) { } // deno-lint-ignore no-console - console.log("\n" + colors.green("🎉 Migration completed successfully!")); + console.log( + "\n" + + colors.green( + isFresh2 + ? "🎉 Update completed successfully!" + : "🎉 Migration completed successfully!", + ), + ); } async function updateFile(sourceFile: tsmorph.SourceFile): Promise {