From 49839079a4f80dae193c33e1fc6faa0f163b51c5 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Mon, 24 Jun 2024 18:13:28 +0200 Subject: [PATCH] Fix: static file processed twice if outdir inside static dir (#2543) Fixes https://github.com/denoland/fresh/issues/2541 --- src/dev/builder.ts | 1 + src/dev/builder_test.ts | 3 +++ src/dev/dev_build_cache.ts | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/src/dev/builder.ts b/src/dev/builder.ts index 0934b1dfdcb..fbfd4b9b176 100644 --- a/src/dev/builder.ts +++ b/src/dev/builder.ts @@ -199,6 +199,7 @@ export class Builder implements FreshBuilder { buildCache.islands.set(island.name, `/${chunk}`); } + console.trace("FLUSH"); await buildCache.flush(); if (!dev) { diff --git a/src/dev/builder_test.ts b/src/dev/builder_test.ts index 8deb12ed302..0b10d4d9926 100644 --- a/src/dev/builder_test.ts +++ b/src/dev/builder_test.ts @@ -11,18 +11,21 @@ Deno.test({ builder.onTransformStaticFile( { pluginName: "A", filter: /\.css$/ }, () => { + console.trace(); logs.push("A"); }, ); builder.onTransformStaticFile( { pluginName: "B", filter: /\.css$/ }, () => { + console.trace(); logs.push("B"); }, ); builder.onTransformStaticFile( { pluginName: "C", filter: /\.css$/ }, () => { + console.trace(); logs.push("C"); }, ); diff --git a/src/dev/dev_build_cache.ts b/src/dev/dev_build_cache.ts index 5f200683848..5259475c3c3 100644 --- a/src/dev/dev_build_cache.ts +++ b/src/dev/dev_build_cache.ts @@ -143,6 +143,7 @@ export class MemoryBuildCache implements DevBuildCache { // deno-lint-ignore require-await async flush(): Promise { + console.log("FLUSH MEMORY CACHE"); this.#ready.resolve(); } } @@ -201,6 +202,7 @@ export class DiskBuildCache implements DevBuildCache { async flush(): Promise { const staticDir = this.config.staticDir; + const outDir = this.config.build.outDir; if (await fsAdapter.isDirectory(staticDir)) { const entries = fsAdapter.walk(staticDir, { @@ -212,6 +214,11 @@ export class DiskBuildCache implements DevBuildCache { }); for await (const entry of entries) { + // OutDir might be inside static dir + if (!path.relative(outDir, entry.path).startsWith("..")) { + continue; + } + const result = await this.#transformer.process( entry.path, "production",