diff --git a/update/src/update.ts b/update/src/update.ts index 40c72f46..95de33df 100644 --- a/update/src/update.ts +++ b/update/src/update.ts @@ -10,6 +10,8 @@ export const FRESH_VERSION = "2.0.0-alpha.37"; export const PREACT_VERSION = "10.26.9"; export const PREACT_SIGNALS_VERSION = "2.2.1"; +// Function to filter out node_modules and vendor directories from logs +const HIDE_FILES = /[\\/]+(node_modules|vendor)[\\/]+/; export interface DenoJson { lock?: boolean; tasks?: Record; @@ -167,8 +169,11 @@ export async function updateProject(dir: string) { path.join(dir, "**", "*.{js,jsx,ts,tsx}"), ); + // Filter out node_modules and vendor files for user display + const userFiles = sfs.filter((sf) => !HIDE_FILES.test(sf.getFilePath())); + // deno-lint-ignore no-console - console.log(colors.cyan(`📁 Found ${sfs.length} files to process`)); + console.log(colors.cyan(`📁 Found ${userFiles.length} files to process`)); if (sfs.length === 0) { // deno-lint-ignore no-console @@ -213,27 +218,34 @@ export async function updateProject(dir: string) { // Clear the progress line and add a newline await bar.stop(); + // Filter modified files to show only user files + const modifiedFilesToShow = modifiedFilesList.filter((filePath) => + !HIDE_FILES.test(filePath) + ); + // add migration summary // deno-lint-ignore no-console console.log("\n" + colors.bold("📊 Migration Summary:")); // deno-lint-ignore no-console - console.log(` Total files processed: ${sfs.length}`); + console.log(` Total files processed: ${userFiles.length}`); // deno-lint-ignore no-console - console.log(` Successfully modified: ${modifiedFilesList.length}`); + console.log(` Successfully modified: ${modifiedFilesToShow.length}`); // deno-lint-ignore no-console console.log( ` Unmodified (no changes needed): ${ - sfs.length - modifiedFilesList.length + userFiles.length - modifiedFilesToShow.length }`, ); - // Display modified files list - if (modifiedFilesList.length > 0) { + // Display modified files list (filtered) + if (modifiedFilesToShow.length > 0) { // deno-lint-ignore no-console console.log("\n" + colors.bold("📝 Modified Files:")); - modifiedFilesList.forEach((filePath) => { + modifiedFilesToShow.forEach((filePath) => { // show relative path - const relativePath = path.relative(dir, filePath); + let relativePath = path.relative(dir, filePath); + // Ensure consistent path separators for logging + relativePath = relativePath.replace(/\\/g, "/"); // deno-lint-ignore no-console console.log(colors.green(` ✓ ${relativePath}`)); }); diff --git a/update/src/update_test.ts b/update/src/update_test.ts index 3fe02ca6..9505721c 100644 --- a/update/src/update_test.ts +++ b/update/src/update_test.ts @@ -6,6 +6,7 @@ import { updateProject, } from "./update.ts"; import { expect } from "@std/expect"; +import { spy, type SpyCall } from "@std/testing/mock"; import { walk } from "@std/fs/walk"; import { withTmpDir } from "../../src/test_utils.ts"; @@ -703,3 +704,54 @@ Deno.test("update - island files", async () => { `import { IS_BROWSER } from "fresh/runtime";`, ); }); + +Deno.test("update - ignores node_modules and vendor in logs", async () => { + await using _tmp = await withTmpDir(); + const dir = _tmp.dir; + await writeFiles(dir, { + "/deno.json": `{}`, + "/routes/index.tsx": `import { PageProps } from "$fresh/server.ts"; +export default function Foo(props: PageProps) { + return null; +}`, + "/node_modules/foo/bar.ts": + `import { IS_BROWSER } from "$fresh/runtime.ts";`, + "/vendor/foo/bar.ts": `import { IS_BROWSER } from "$fresh/runtime.ts";`, + }); + + const consoleLogSpy = spy(console, "log"); + + try { + await updateProject(dir); + } finally { + consoleLogSpy.restore(); + } + + const files = await readFiles(dir); + + expect(files["/node_modules/foo/bar.ts"]).toEqual( + `import { IS_BROWSER } from "fresh/runtime";`, + ); + expect(files["/vendor/foo/bar.ts"]).toEqual( + `import { IS_BROWSER } from "fresh/runtime";`, + ); + expect(files["/routes/index.tsx"]).toEqual( + `import { PageProps } from "fresh"; +export default function Foo(props: PageProps) { + return null; +}`, + ); + + const fullLog = consoleLogSpy.calls.map((call: SpyCall) => + call.args.join(" ") + ).join( + "\n", + ); + + expect(fullLog).toMatch(/Total files processed: 1/); + expect(fullLog).toMatch(/Successfully modified: 1/); + expect(fullLog).toMatch(/Unmodified \(no changes needed\): 0/); + expect(fullLog).not.toMatch(/node_modules/); + expect(fullLog).not.toMatch(/vendor/); + expect(fullLog).toMatch(/✓ routes\/index.tsx/); +});