Skip to content

Bump wasm-bindgen and fix patch.mjs to handle new wasm-bindgen output format#82

Open
Copilot wants to merge 2 commits intomainfrom
copilot/fix-ci-failure
Open

Bump wasm-bindgen and fix patch.mjs to handle new wasm-bindgen output format#82
Copilot wants to merge 2 commits intomainfrom
copilot/fix-ci-failure

Conversation

Copy link
Contributor

Copilot AI commented Dec 1, 2025

This PR bumps wasm-bindgen1 and related dependencies (js-sys, web-sys).

Due to changes in wasm-bindgen, our patch.mjs and patch_async.mjs needed updating too. Below is an LLM summary of these changes:


wasm-bindgen 0.2.108 changed its CJS output format, breaking the patch.mjs/patch_async.mjs CJS→ESM transform scripts.

Key differences in newer wasm-bindgen output:

  • exports.XXX = XXX; instead of module.exports.XXX = ...
  • const wasmPath/const wasmBytes instead of const path/const bytes
  • No var exports = module.exports preamble

Changes to src/bin/patch.mjs and src/bin/patch_async.mjs

  • Export enums inline — match Object.freeze declarations and add export keyword directly, replacing the duplicate re-export approach that caused the name collision
  • Export standalone functions — use a callback-based regex to detect functions with corresponding exports.XXX = XXX; lines and add export to their declarations
  • Map exports.*imports.* — convert bare exports.XXX = XXX; (undefined in ESM scope) to imports.XXX = XXX; for the globalThis.pubky registry
  • Define const imports = {} at top of generated ESM output (no longer provided by wasm-bindgen boilerplate)
  • Broaden wasm-loading regex to match both old (const path/const bytes) and new (const wasmPath/const wasmBytes) variable names, capturing the actual bytes variable name for use in the replacement
// Export enums (Object.freeze declarations)
.replace(/\nconst (\w+) = Object\.freeze/g, "\nexport const $1 = Object.freeze")
// Export standalone functions that are assigned to exports
.replace(/\nfunction (\w+)\(/g, (match, name, offset, str) => {
  if (str.includes(`exports.${name} = ${name};`)) {
    return `\nexport function ${name}(`;
  }
  return match;
})
// Replace exports.X = X; with imports.X = X; (for newer wasm-bindgen)
.replace(/\nexports\.(\w+) = (\w+);/g, "\nimports.$1 = $2;")

Footnotes

  1. See changelog (0.2.100 - 0.2.108): https://github.com/wasm-bindgen/wasm-bindgen/blob/main/CHANGELOG.md

Copilot AI changed the title [WIP] Fix CI failure in pubky-app-specs Fix patch.mjs to handle new wasm-bindgen 0.2.103+ output format Dec 1, 2025
Copilot AI requested a review from ok300 December 1, 2025 16:14
@ok300 ok300 marked this pull request as ready for review December 1, 2025 16:17
@ok300 ok300 requested a review from tipogi December 1, 2025 16:19
@ok300 ok300 mentioned this pull request Dec 1, 2025
@ok300 ok300 changed the base branch from chore/bump-crate-deps to main December 4, 2025 04:14
@ok300 ok300 force-pushed the copilot/fix-ci-failure branch 2 times, most recently from 516a8f7 to 4bcd557 Compare December 4, 2025 04:17
@ok300 ok300 changed the title Fix patch.mjs to handle new wasm-bindgen 0.2.103+ output format Bump wasm-bindgen and fix patch.mjs to handle new wasm-bindgen output format Dec 4, 2025
Fix JS binding patch scripts for wasm-bindgen 0.2.108 CJS output changes
@ok300 ok300 force-pushed the copilot/fix-ci-failure branch from 4bcd557 to 63d89d6 Compare February 18, 2026 08:51
@ok300 ok300 unassigned Copilot and ok300 Feb 18, 2026
@ok300
Copy link
Contributor

ok300 commented Feb 18, 2026

I updated these dependencies to latest and re-generated the patch fixes.

The new patch changes are considerably smaller and simpler than the previous version of this PR (see diff).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments