Skip to content

Commit 592e7a0

Browse files
bartlomiejuclaude
andcommitted
fix: improve update tool output for Fresh 2 projects (#3688)
The updater now detects whether a project is already on Fresh 2 and adjusts its messaging accordingly. Fresh 2 patch/minor updates no longer show "Starting Fresh 1 to Fresh 2 migration..." or the breaking changes warning. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 895bcac commit 592e7a0

2 files changed

Lines changed: 55 additions & 15 deletions

File tree

β€Žpackages/update/src/mod.tsβ€Ž

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ console.log(colors.bgRgb8(
2929
));
3030
// deno-lint-ignore no-console
3131
console.log();
32-
// deno-lint-ignore no-console
33-
console.log(
34-
colors.italic(
35-
"Note: Breaking changes may require additional manual updates.",
36-
),
37-
);
38-
// deno-lint-ignore no-console
39-
console.log();
4032

4133
let unresolvedDirectory = Deno.args[0];
4234
if (flags._.length !== 1) {

β€Žpackages/update/src/update.tsβ€Ž

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,44 @@ const compat = new Set([
8686
"UnknownPageProps",
8787
]);
8888

89+
async function detectFresh2(dir: string): Promise<boolean> {
90+
for (const filename of ["deno.json", "deno.jsonc"]) {
91+
try {
92+
const content = await Deno.readTextFile(path.join(dir, filename));
93+
const config = JSONC.parse(content) as DenoJson;
94+
const imports = config.imports;
95+
if (imports) {
96+
// Fresh 2 uses "fresh" or "@fresh/core" as the import specifier
97+
if (imports["fresh"]?.includes("@fresh/core")) {
98+
return true;
99+
}
100+
}
101+
} catch {
102+
// File doesn't exist, try next
103+
}
104+
}
105+
return false;
106+
}
107+
89108
export async function updateProject(dir: string) {
90-
// add initial log
91-
// deno-lint-ignore no-console
92-
console.log(colors.blue("πŸš€ Starting Fresh 1 to Fresh 2 migration..."));
109+
// Detect if the project is already on Fresh 2 by checking imports
110+
const isFresh2 = await detectFresh2(dir);
111+
112+
if (isFresh2) {
113+
// deno-lint-ignore no-console
114+
console.log(colors.blue(`πŸ”„ Updating Fresh to ${FRESH_VERSION}...`));
115+
} else {
116+
// deno-lint-ignore no-console
117+
console.log(colors.blue("πŸš€ Starting Fresh 1 to Fresh 2 migration..."));
118+
// deno-lint-ignore no-console
119+
console.log(
120+
colors.italic(
121+
"Note: Breaking changes may require additional manual updates.",
122+
),
123+
);
124+
// deno-lint-ignore no-console
125+
console.log();
126+
}
93127

94128
// deno-lint-ignore no-console
95129
console.log(colors.yellow("πŸ“ Updating configuration files..."));
@@ -194,7 +228,13 @@ export async function updateProject(dir: string) {
194228

195229
if (filesToProcess.length === 0) {
196230
// deno-lint-ignore no-console
197-
console.log(colors.green("πŸŽ‰ Migration completed successfully!"));
231+
console.log(
232+
colors.green(
233+
isFresh2
234+
? "πŸŽ‰ Update completed successfully!"
235+
: "πŸŽ‰ Migration completed successfully!",
236+
),
237+
);
198238
return;
199239
}
200240

@@ -238,9 +278,10 @@ export async function updateProject(dir: string) {
238278
// Clear the progress line and add a newline
239279
await bar.stop();
240280

241-
// add migration summary
242281
// deno-lint-ignore no-console
243-
console.log("\n" + colors.bold("πŸ“Š Migration Summary:"));
282+
console.log(
283+
"\n" + colors.bold(isFresh2 ? "πŸ“Š Update Summary:" : "πŸ“Š Migration Summary:"),
284+
);
244285
// deno-lint-ignore no-console
245286
console.log(` Total files processed: ${filesToProcess.length}`);
246287
// deno-lint-ignore no-console
@@ -267,7 +308,14 @@ export async function updateProject(dir: string) {
267308
}
268309

269310
// deno-lint-ignore no-console
270-
console.log("\n" + colors.green("πŸŽ‰ Migration completed successfully!"));
311+
console.log(
312+
"\n" +
313+
colors.green(
314+
isFresh2
315+
? "πŸŽ‰ Update completed successfully!"
316+
: "πŸŽ‰ Migration completed successfully!",
317+
),
318+
);
271319
}
272320

273321
async function updateFile(sourceFile: tsmorph.SourceFile): Promise<boolean> {

0 commit comments

Comments
Β (0)