Fix: static file processed twice if outdir inside static dir (#2543)

Fixes https://github.com/denoland/fresh/issues/2541
This commit is contained in:
Marvin Hagemeister
2024-06-24 18:13:28 +02:00
committed by GitHub
parent a560c17e7b
commit 49839079a4
3 changed files with 11 additions and 0 deletions
+1
View File
@@ -199,6 +199,7 @@ export class Builder implements FreshBuilder {
buildCache.islands.set(island.name, `/${chunk}`); buildCache.islands.set(island.name, `/${chunk}`);
} }
console.trace("FLUSH");
await buildCache.flush(); await buildCache.flush();
if (!dev) { if (!dev) {
+3
View File
@@ -11,18 +11,21 @@ Deno.test({
builder.onTransformStaticFile( builder.onTransformStaticFile(
{ pluginName: "A", filter: /\.css$/ }, { pluginName: "A", filter: /\.css$/ },
() => { () => {
console.trace();
logs.push("A"); logs.push("A");
}, },
); );
builder.onTransformStaticFile( builder.onTransformStaticFile(
{ pluginName: "B", filter: /\.css$/ }, { pluginName: "B", filter: /\.css$/ },
() => { () => {
console.trace();
logs.push("B"); logs.push("B");
}, },
); );
builder.onTransformStaticFile( builder.onTransformStaticFile(
{ pluginName: "C", filter: /\.css$/ }, { pluginName: "C", filter: /\.css$/ },
() => { () => {
console.trace();
logs.push("C"); logs.push("C");
}, },
); );
+7
View File
@@ -143,6 +143,7 @@ export class MemoryBuildCache implements DevBuildCache {
// deno-lint-ignore require-await // deno-lint-ignore require-await
async flush(): Promise<void> { async flush(): Promise<void> {
console.log("FLUSH MEMORY CACHE");
this.#ready.resolve(); this.#ready.resolve();
} }
} }
@@ -201,6 +202,7 @@ export class DiskBuildCache implements DevBuildCache {
async flush(): Promise<void> { async flush(): Promise<void> {
const staticDir = this.config.staticDir; const staticDir = this.config.staticDir;
const outDir = this.config.build.outDir;
if (await fsAdapter.isDirectory(staticDir)) { if (await fsAdapter.isDirectory(staticDir)) {
const entries = fsAdapter.walk(staticDir, { const entries = fsAdapter.walk(staticDir, {
@@ -212,6 +214,11 @@ export class DiskBuildCache implements DevBuildCache {
}); });
for await (const entry of entries) { 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( const result = await this.#transformer.process(
entry.path, entry.path,
"production", "production",