diff --git a/src/config.ts b/src/config.ts index bf063bc46..8e53688ce 100644 --- a/src/config.ts +++ b/src/config.ts @@ -233,7 +233,7 @@ function readPages(root: string, md: MarkdownIt): Page[] { return pages; } -let currentDate: Date | null = null; +export let currentDate: Date | null = null; /** For testing only! */ export function setCurrentDate(date: Date | null): void { diff --git a/src/javascript/module.ts b/src/javascript/module.ts index 46daa8f47..03f5e1f5a 100644 --- a/src/javascript/module.ts +++ b/src/javascript/module.ts @@ -6,6 +6,7 @@ import {extname, join} from "node:path/posix"; import type {Program} from "acorn"; import type {TransformOptions} from "esbuild"; import {transform, transformSync} from "esbuild"; +import {currentDate} from "../config.js"; import {resolveJsrImport} from "../jsr.js"; import {resolveNodeImport} from "../node.js"; import {resolveNpmImport} from "../npm.js"; @@ -199,7 +200,7 @@ export function getFileInfo(root: string, path: string): FileInfo | undefined { const stat = statSync(key); if (!stat.isFile()) return; // ignore non-files accessSync(key, constants.R_OK); // verify that file is readable - mtimeMs = Math.floor(stat.mtimeMs); + mtimeMs = Math.floor((currentDate ?? stat.mtimeMs) as number); size = stat.size; } catch { fileInfoCache.delete(key); // delete stale entry diff --git a/src/loader.ts b/src/loader.ts index 324f1a8e1..8e28ace79 100644 --- a/src/loader.ts +++ b/src/loader.ts @@ -300,7 +300,7 @@ export class LoaderResolver { getOutputFileHash(name: string): string { const info = this.getOutputInfo(name); if (!info) throw new Error(`output file not found: ${name}`); - return info.hash; + return createHash("sha256").update(info.hash).update(String(info.mtimeMs)).digest("hex"); } getSourceInfo(name: string): FileInfo | undefined { diff --git a/test/build-test.ts b/test/build-test.ts index da7726f6c..b477d58fd 100644 --- a/test/build-test.ts +++ b/test/build-test.ts @@ -32,6 +32,7 @@ const failureTests = ["missing-file", "missing-import"]; describe("build", () => { before(() => setCurrentDate(new Date("2024-01-10T16:00:00"))); + after(() => setCurrentDate(null)); mockJsDelivr(); mockJsr(); mockDuckDB(); @@ -233,9 +234,6 @@ class TestEffects extends FileBuildEffects { contents = contents.replace(/^(\s* + + +
+ +
+

test

+
+
+ +
+ +