ci: strip dead default-module-path branch from pg-wasm web build#199
ci: strip dead default-module-path branch from pg-wasm web build#199rubenhensen wants to merge 1 commit into
Conversation
wasm-bindgen's `--target web` output emits an unreachable
`module_or_path = new URL('index_bg.wasm', import.meta.url)` branch in
__wbg_init. Webpack 5 statically resolves it as an asset import at build
time even though it never fires for callers that pass module_or_path
explicitly (e.g. @e4a/pg-js), producing 'Can't resolve index_bg.wasm'
errors in downstream consumers.
wasm-pack does not expose wasm-bindgen's --omit-default-module-path flag,
so strip the branch from the generated index.js after the build. The
strip fails loudly if the pattern is gone so a future wasm-bindgen change
can't silently no-op it. The bundler target has no init function and is
unaffected.
Fixes #153
|
Dobby hit a rate limit mid-task and had to pause. Resets 6/12/2026, 4:00:00 PM. I'll automatically resume where I left off — no work lost! |
|
Opened #222 as an alternative that resolves the same issue via wasm-bindgen's wasm-pack 0.15.0 (the version CI installs) exposes this flag through crate-manifest metadata: [package.metadata.wasm-pack.profile.release.wasm-bindgen]
omit-default-module-path = trueVerified locally: with this set, Advantages over this PR: it's a |
Summary
The
@e4a/pg-wasmweb target generated bywasm-pack build --target webships an unreachable default-value branch in__wbg_init:Webpack 5 statically analyzes
new URL("...", import.meta.url)as an asset import and tries to resolveindex_bg.wasmat build time — even though the branch never fires for callers that always passmodule_or_pathexplicitly (e.g.@e4a/pg-js, which inlines the WASM as base64). Downstream consumers therefore hitModule not found: Can't resolve 'index_bg.wasm'.wasm-packdoes not expose wasm-bindgen's--omit-default-module-pathflag, so this PR adds a post-build step todelivery.yml'spublish-wasmjob that strips the branch from the generatedpg-wasm/pkg/web/index.js. The strip:ifcondition so a wasm-bindgen version change to e.g.typeof module_or_path === 'undefined'still matches.exit 1) if the pattern is gone, so a future wasm-bindgen change can't silently no-op the strip and ship the regression again.The bundler target is unaffected — it emits
import * as wasm from "./index_bg.wasm"with no__wbg_initfunction and nonew URL(...)branch — so no strip is needed there (this corrects fix-option 2 in the issue body).Verification
Built the web target locally with
wasm-pack 0.14.0and confirmed against the real generated output:pg-wasm/pkg/web/index.jsbefore stripping.nodescript from this PR removes the 3-line block, leaving zeroindex_bg.wasmreferences.__wbg_initflow is intact — control passes straight into thetypeof module_or_path === 'string' || ... instanceof Request || ... instanceof URLpath that fires when a caller passesmodule_or_pathexplicitly.node --checkpasses on the stripped file.Behavior change: a caller that invokes
init()with no argument now gets a runtime error at instantiate time instead of a webpack build-time error — exactly what--omit-default-module-pathproduces. All current consumers passmodule_or_path, so they are unaffected.Downstream
Once a new
@e4a/pg-wasmships with this fix,@e4a/pg-jsonly needs a dep bump + republish, and theparser: { url: false }webpack workaround in downstream consumers can be removed.Fixes #153