fix: __FRSH_BUILD_ID is not defined (#1207)

This could happen if the runtime/utils.ts coe was loaded
prior to server/constants.ts, because they had some shared state on
`globalThis`.

I have mitigated this by not relying on global state anymore.

Fixes #1191

---------

Co-authored-by: Asher Gomez <ashersaupingomez@gmail.com>
This commit is contained in:
Luca Casonato
2023-05-30 10:46:44 +10:00
committed by GitHub
co-authored by Asher Gomez
parent 675036b33c
commit 87b087e358
10 changed files with 66 additions and 46 deletions
+1 -20
View File
@@ -1,30 +1,11 @@
import { INTERNAL_PREFIX } from "../runtime/utils.ts";
import { toHashString } from "./deps.ts";
import { BUILD_ID } from "./build_id.ts";
export const REFRESH_JS_URL = `${INTERNAL_PREFIX}/refresh.js`;
export const ALIVE_URL = `${INTERNAL_PREFIX}/alive`;
export const JS_PREFIX = `/js`;
export const DEBUG = !Deno.env.get("DENO_DEPLOYMENT_ID");
const deploymentId = Deno.env.get("DENO_DEPLOYMENT_ID") ||
crypto.randomUUID();
const buildIdHash = await crypto.subtle.digest(
"SHA-1",
new TextEncoder().encode(deploymentId),
);
export const BUILD_ID = toHashString(buildIdHash, "hex");
export function bundleAssetUrl(path: string) {
return `${INTERNAL_PREFIX}${JS_PREFIX}/${BUILD_ID}${path}`;
}
globalThis.__FRSH_BUILD_ID = BUILD_ID;
declare global {
interface Crypto {
randomUUID(): string;
}
// deno-lint-ignore no-var
var __FRSH_BUILD_ID: string;
}