diff --git a/rspack.config.js b/rspack.config.js index 99996e5..12030e6 100644 --- a/rspack.config.js +++ b/rspack.config.js @@ -1,12 +1,14 @@ import { defineConfig } from "@rspack/cli"; import { rspack } from "@rspack/core"; import { RsdoctorRspackPlugin } from "@rsdoctor/rspack-plugin"; -import { join } from "path"; -import { fileURLToPath } from "url"; import obfuscator from "javascript-obfuscator"; const { obfuscate } = obfuscator; +import { readFile } from "node:fs/promises"; +import { join } from "path"; +import { fileURLToPath } from "url"; const __dirname = fileURLToPath(new URL(".", import.meta.url)); +const packagemeta = JSON.parse(await readFile("package.json")); export default defineConfig({ // change to production when needed @@ -66,6 +68,9 @@ export default defineConfig({ new rspack.ProvidePlugin({ dbg: [join(__dirname, "src/log.ts"), "default"], }), + new rspack.DefinePlugin({ + VERSION: JSON.stringify(packagemeta.version), + }), process.env.OBFUSCATE === "true" && { apply(compiler) { compiler.hooks.compilation.tap("GyatPlugin", (compilation) => { diff --git a/src/worker/error.ts b/src/worker/error.ts index 30c2726..81405b1 100644 --- a/src/worker/error.ts +++ b/src/worker/error.ts @@ -1,20 +1,18 @@ 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 = ` - 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 = "0.0.1"; - `; + 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)}; + `; return ` - Error + Scramjet @@ -42,9 +40,7 @@ export function errorTemplate(trace: string, fetchedURL: string) {

Scramjet v

- + `;