From 0d723d3e0514b27285cb36d42a4fd477f4997571 Mon Sep 17 00:00:00 2001 From: Leon Zandman Date: Sun, 10 May 2026 00:26:47 +0200 Subject: [PATCH] Init fix. --- src/core/lib/Zstd.mjs | 3 ++- webpack.config.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/core/lib/Zstd.mjs b/src/core/lib/Zstd.mjs index a7e013be..6178307b 100644 --- a/src/core/lib/Zstd.mjs +++ b/src/core/lib/Zstd.mjs @@ -22,7 +22,8 @@ let initPromise = null; */ export function zstdInit() { if (!initPromise) { - initPromise = init(); + const wasmUrl = `${self.docURL}/assets/zstd.wasm`; + initPromise = init(wasmUrl); } return initPromise; } diff --git a/webpack.config.js b/webpack.config.js index 4c6c00ba..564040f0 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -99,6 +99,10 @@ module.exports = { context: "node_modules/node-forge/dist", from: "prime.worker.min.js", to: "assets/forge/" + }, { + context: "node_modules/@bokuweb/zstd-wasm/dist/web/", + from: "zstd.wasm", + to: "assets/" } ] }), @@ -110,6 +114,17 @@ module.exports = { operations: [ new ReplaceOperation("once", "if (pixelSize < elementMinSize)", "if (false)") ] + }, + { + // @bokuweb/zstd-wasm's init() unconditionally evaluates + // `new URL("./zstd.wasm", import.meta.url)` before checking + // whether a path was passed in. Webpack's `publicPath: ""` + // makes that base URL invalid and the constructor throws. + // Neuter the offending line; we always pass a path from Zstd.mjs. + test: /@bokuweb[\/\\]zstd-wasm[\/\\]dist[\/\\]web[\/\\]index\.web\.js$/, + operations: [ + new ReplaceOperation("once", "new URL(`./zstd.wasm`, import.meta.url).href", "''") + ] } ] })