fix: hide node_modules and vendor from update output (#3089)

Added logic to filter out files in node_modules and vendor directories
from user-facing logs and migration summaries in the update process.
Updated tests to verify that these files are processed but not shown in
logs.

close #3082

---------

Co-authored-by: 李嘉图·M·路 <146103794+Ricardo-M-Zheng@users.noreply.github.com>
Co-authored-by: Marvin Hagemeister <marvinhagemeister50@gmail.com>
This commit is contained in:
zhizheng
2025-07-14 15:57:07 +02:00
committed by GitHub
co-authored by 李嘉图·M·路 Marvin Hagemeister
parent 3c43d98a57
commit 31dcbfbb8b
2 changed files with 72 additions and 8 deletions
+20 -8
View File
@@ -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<string, string>;
@@ -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}`));
});
+52
View File
@@ -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/);
});