Skip to content

Commit 31dcbfb

Browse files
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>
1 parent 3c43d98 commit 31dcbfb

File tree

2 files changed

+72
-8
lines changed

2 files changed

+72
-8
lines changed

update/src/update.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ export const FRESH_VERSION = "2.0.0-alpha.37";
1010
export const PREACT_VERSION = "10.26.9";
1111
export const PREACT_SIGNALS_VERSION = "2.2.1";
1212

13+
// Function to filter out node_modules and vendor directories from logs
14+
const HIDE_FILES = /[\\/]+(node_modules|vendor)[\\/]+/;
1315
export interface DenoJson {
1416
lock?: boolean;
1517
tasks?: Record<string, string>;
@@ -167,8 +169,11 @@ export async function updateProject(dir: string) {
167169
path.join(dir, "**", "*.{js,jsx,ts,tsx}"),
168170
);
169171

172+
// Filter out node_modules and vendor files for user display
173+
const userFiles = sfs.filter((sf) => !HIDE_FILES.test(sf.getFilePath()));
174+
170175
// deno-lint-ignore no-console
171-
console.log(colors.cyan(`📁 Found ${sfs.length} files to process`));
176+
console.log(colors.cyan(`📁 Found ${userFiles.length} files to process`));
172177

173178
if (sfs.length === 0) {
174179
// deno-lint-ignore no-console
@@ -213,27 +218,34 @@ export async function updateProject(dir: string) {
213218
// Clear the progress line and add a newline
214219
await bar.stop();
215220

221+
// Filter modified files to show only user files
222+
const modifiedFilesToShow = modifiedFilesList.filter((filePath) =>
223+
!HIDE_FILES.test(filePath)
224+
);
225+
216226
// add migration summary
217227
// deno-lint-ignore no-console
218228
console.log("\n" + colors.bold("📊 Migration Summary:"));
219229
// deno-lint-ignore no-console
220-
console.log(` Total files processed: ${sfs.length}`);
230+
console.log(` Total files processed: ${userFiles.length}`);
221231
// deno-lint-ignore no-console
222-
console.log(` Successfully modified: ${modifiedFilesList.length}`);
232+
console.log(` Successfully modified: ${modifiedFilesToShow.length}`);
223233
// deno-lint-ignore no-console
224234
console.log(
225235
` Unmodified (no changes needed): ${
226-
sfs.length - modifiedFilesList.length
236+
userFiles.length - modifiedFilesToShow.length
227237
}`,
228238
);
229239

230-
// Display modified files list
231-
if (modifiedFilesList.length > 0) {
240+
// Display modified files list (filtered)
241+
if (modifiedFilesToShow.length > 0) {
232242
// deno-lint-ignore no-console
233243
console.log("\n" + colors.bold("📝 Modified Files:"));
234-
modifiedFilesList.forEach((filePath) => {
244+
modifiedFilesToShow.forEach((filePath) => {
235245
// show relative path
236-
const relativePath = path.relative(dir, filePath);
246+
let relativePath = path.relative(dir, filePath);
247+
// Ensure consistent path separators for logging
248+
relativePath = relativePath.replace(/\\/g, "/");
237249
// deno-lint-ignore no-console
238250
console.log(colors.green(` ✓ ${relativePath}`));
239251
});

update/src/update_test.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
updateProject,
77
} from "./update.ts";
88
import { expect } from "@std/expect";
9+
import { spy, type SpyCall } from "@std/testing/mock";
910
import { walk } from "@std/fs/walk";
1011
import { withTmpDir } from "../../src/test_utils.ts";
1112

@@ -703,3 +704,54 @@ Deno.test("update - island files", async () => {
703704
`import { IS_BROWSER } from "fresh/runtime";`,
704705
);
705706
});
707+
708+
Deno.test("update - ignores node_modules and vendor in logs", async () => {
709+
await using _tmp = await withTmpDir();
710+
const dir = _tmp.dir;
711+
await writeFiles(dir, {
712+
"/deno.json": `{}`,
713+
"/routes/index.tsx": `import { PageProps } from "$fresh/server.ts";
714+
export default function Foo(props: PageProps) {
715+
return null;
716+
}`,
717+
"/node_modules/foo/bar.ts":
718+
`import { IS_BROWSER } from "$fresh/runtime.ts";`,
719+
"/vendor/foo/bar.ts": `import { IS_BROWSER } from "$fresh/runtime.ts";`,
720+
});
721+
722+
const consoleLogSpy = spy(console, "log");
723+
724+
try {
725+
await updateProject(dir);
726+
} finally {
727+
consoleLogSpy.restore();
728+
}
729+
730+
const files = await readFiles(dir);
731+
732+
expect(files["/node_modules/foo/bar.ts"]).toEqual(
733+
`import { IS_BROWSER } from "fresh/runtime";`,
734+
);
735+
expect(files["/vendor/foo/bar.ts"]).toEqual(
736+
`import { IS_BROWSER } from "fresh/runtime";`,
737+
);
738+
expect(files["/routes/index.tsx"]).toEqual(
739+
`import { PageProps } from "fresh";
740+
export default function Foo(props: PageProps) {
741+
return null;
742+
}`,
743+
);
744+
745+
const fullLog = consoleLogSpy.calls.map((call: SpyCall) =>
746+
call.args.join(" ")
747+
).join(
748+
"\n",
749+
);
750+
751+
expect(fullLog).toMatch(/Total files processed: 1/);
752+
expect(fullLog).toMatch(/Successfully modified: 1/);
753+
expect(fullLog).toMatch(/Unmodified \(no changes needed\): 0/);
754+
expect(fullLog).not.toMatch(/node_modules/);
755+
expect(fullLog).not.toMatch(/vendor/);
756+
expect(fullLog).toMatch(/ routes\/index.tsx/);
757+
});

0 commit comments

Comments
 (0)