Skip to content

Commit

Permalink
fix: ensure file paths in snapshot.json uses / (#2704)
Browse files Browse the repository at this point in the history
Avoids `\\\\` paths ending up in `snapshot.json` when using `deno task
build` on Windows. Backslashes do not which pathnames in URLs, so these
assets are not returned.

Closes #2703
  • Loading branch information
csvn authored Oct 15, 2024
1 parent dd55558 commit 628832a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/dev/builder_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,33 @@ Deno.test({
sanitizeResources: false,
});

Deno.test({
name: "Builder - handles Windows paths",
fn: async () => {
const builder = new Builder();
const tmp = await Deno.makeTempDir();
await Deno.mkdir(path.join(tmp, "images"));
await Deno.writeTextFile(
path.join(tmp, "images", "batman.svg"),
"<svg></svg>",
);
const app = new App({
staticDir: tmp,
build: {
outDir: path.join(tmp, "dist"),
},
});
await builder.build(app);

const snapshotJson = await Deno.readTextFile(
path.join(tmp, "dist", "snapshot.json"),
);
expect(snapshotJson).toContain("/images/batman.svg");
},
sanitizeOps: false,
sanitizeResources: false,
});

Deno.test({
name: "Builder - hashes CSS urls by default",
fn: async () => {
Expand Down
3 changes: 2 additions & 1 deletion src/dev/dev_build_cache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { BuildCache, StaticFile } from "../build_cache.ts";
import * as path from "@std/path";
import { SEPARATOR as WINDOWS_SEPARATOR } from "@std/path/windows/constants";
import type { ResolvedFreshConfig } from "../config.ts";
import type { BuildSnapshot } from "../build_cache.ts";
import { encodeHex } from "@std/encoding/hex";
Expand Down Expand Up @@ -174,7 +175,7 @@ export class DiskBuildCache implements DevBuildCache {

addUnprocessedFile(pathname: string): void {
this.#unprocessedFiles.set(
pathname,
pathname.replaceAll(WINDOWS_SEPARATOR, "/"),
path.join(this.config.staticDir, pathname),
);
}
Expand Down

0 comments on commit 628832a

Please sign in to comment.