From 9ea9863ced5f1bf86e7adfe226eeba3345ba8f93 Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Fri, 11 Oct 2024 17:35:06 -0500 Subject: [PATCH] feat: add commithash to error screen --- rspack.config.js | 9 +++++++++ src/worker/error.ts | 29 +++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/rspack.config.js b/rspack.config.js index 1868a44..f9f8e75 100644 --- a/rspack.config.js +++ b/rspack.config.js @@ -3,6 +3,7 @@ import { rspack } from "@rspack/core"; import { RsdoctorRspackPlugin } from "@rsdoctor/rspack-plugin"; import { readFile } from "node:fs/promises"; +import { execSync } from "node:child_process"; import { join } from "path"; import { fileURLToPath } from "url"; const __dirname = fileURLToPath(new URL(".", import.meta.url)); @@ -66,6 +67,14 @@ export default defineConfig({ new rspack.DefinePlugin({ VERSION: JSON.stringify(packagemeta.version), }), + new rspack.DefinePlugin({ + COMMITHASH: JSON.stringify( + execSync("git rev-parse HEAD", { encoding: "utf-8" }).replace( + /\r?\n|\r/g, + "" + ) + ), + }), process.env.DEBUG === "true" ? new RsdoctorRspackPlugin({ supports: { diff --git a/src/worker/error.ts b/src/worker/error.ts index dddf830..ab8139c 100644 --- a/src/worker/error.ts +++ b/src/worker/error.ts @@ -1,14 +1,15 @@ export function errorTemplate(trace: string, fetchedURL: string) { - // turn script into a data URI so we don"t have to escape any HTML values - const script = ` + // turn script into a data URI so we don"t have to escape any HTML values + const script = ` errorTrace.value = ${JSON.stringify(trace)}; fetchedURL.textContent = ${JSON.stringify(fetchedURL)}; for (const node of document.querySelectorAll("#hostname")) node.textContent = ${JSON.stringify(location.hostname)}; reload.addEventListener("click", () => location.reload()); version.textContent = ${JSON.stringify(VERSION)}; + build.textContent = ${JSON.stringify(COMMITHASH)}; `; - return ` + return `
@@ -155,7 +156,7 @@ export function errorTemplate(trace: string, fetchedURL: string) {Scramjet v
+Scramjet v (build )