Skip to content

Commit

Permalink
fix: double file processing if outdir inside static dir
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Jun 24, 2024
1 parent a560c17 commit 5ec562e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/dev/builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ export class Builder implements FreshBuilder {
buildCache.islands.set(island.name, `/${chunk}`);
}

console.trace("FLUSH");
await buildCache.flush();

if (!dev) {
Expand Down
3 changes: 3 additions & 0 deletions src/dev/builder_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
},
);
Expand Down
7 changes: 7 additions & 0 deletions src/dev/dev_build_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ export class MemoryBuildCache implements DevBuildCache {

// deno-lint-ignore require-await
async flush(): Promise<void> {
console.log("FLUSH MEMORY CACHE");
this.#ready.resolve();
}
}
Expand Down Expand Up @@ -201,6 +202,7 @@ export class DiskBuildCache implements DevBuildCache {

async flush(): Promise<void> {
const staticDir = this.config.staticDir;
const outDir = this.config.build.outDir;

if (await fsAdapter.isDirectory(staticDir)) {
const entries = fsAdapter.walk(staticDir, {
Expand All @@ -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",
Expand Down

0 comments on commit 5ec562e

Please sign in to comment.