Skip to content

fix(wasm): sanitize TypeScript declarations and Wasm exports - #123

Merged
byteland-app merged 3 commits into
mainfrom
stitch/sanitize-ts-declarations-and-wasm-exports-jm1-aba0f6bd-aafd-4b2f-9880-05b0fa5219ee
Nov 25, 2026
Merged

byteland-app merged 3 commits into
mainfrom
stitch/sanitize-ts-declarations-and-wasm-exports-jm1-aba0f6bd-aafd-4b2f-9880-05b0fa5219ee

Conversation

@google-labs-stitch

@google-labs-stitch google-labs-stitch Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add scripts/postbuild-wasm.mjs to npm run build:wasm to remove pkg/.gitignore, preserve [Symbol.dispose](): void on Tunelet via a top-level /// <reference lib="esnext.disposable" /> directive, and replace RequestInfo, Response, URL, BufferSource, and WebAssembly in pkg/tunelet.d.ts with module-local structural interfaces without declare global or any other /// <reference ... /> directives.
  • Fail scripts/postbuild-wasm.mjs with an explicit error if any expected wasm-bindgen declaration anchor changes, if an unexpected triple-slash reference appears, or if any ambient DOM/WebAssembly symbol stays in declaration code.
  • Decode undefined HarmonyConfig.voices to 4 with deserialize_with in src/harmony.rs and emit voices?: number | undefined through tsify while keeping pub voices: u8 unchanged.
  • Map "./pkg/tunelet_bg.wasm" and "./tunelet_bg.wasm" to "./pkg/tunelet_bg.wasm" in package.json while keeping the eight-file npm archive contract and .github/workflows/release.yml upload paths unchanged.
  • Update initialize in src/index.ts and the WebAssembly section in README.md so Node.js reads "file:" URL strings and cross-realm file: URL objects from disk with node:fs/promises.
  • Remove ESNext.Disposable and DOM from tsconfig.json, enable exactOptionalPropertyTypes, and verify four strict consumer tsc profiles (node, es2023, dom, and webworker) — including using disposal and { module_or_path } / { module } object arguments for init and initSync — plus runtime .wasm resolution, "file:" string loading, [Symbol.dispose](), and { voices: undefined } handling in scripts/verify-pack.mjs.

Verification

  • cargo fmt --check
  • cargo clippy --locked --lib -- -D warnings
  • cargo build --locked --release
  • RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps
  • cargo package --locked
  • RUSTDOCFLAGS="-D warnings" npm run check:wasm
  • npm run verify:pack

Automated PR initiated by user @byteland-app via Stitch Loop.

- Add scripts/postbuild-wasm.mjs to sanitize pkg/tunelet.d.ts
- Replace Symbol.dispose and DOM types in pkg/tunelet.d.ts
- Decode undefined HarmonyConfig.voices to 4 in src/harmony.rs
- Export the Wasm binary subpaths in package.json
- Read file: URL strings and cross-realm file: URLs in src/index.ts
- Enable exactOptionalPropertyTypes in tsconfig.json without DOM
- Check four strict TypeScript profiles in scripts/verify-pack.mjs
@byteland-app

Copy link
Copy Markdown
Contributor

Review: Preferred over #103, #105, #110, and #119 for TypeScript declaration hygiene (zero declare global pollution, single source of truth from tsify, TS 7.0 WasmMemory parity, and { voices: undefined } fix). Please make two small adjustments:

  1. Update scripts/verify-pack.mjs to use object arguments ({ module_or_path } / { module }) for init and initSync, aligning with test(npm): check the object arguments of the Wasm initializers #82.
  2. Confirm whether we want to strip [Symbol.dispose] or preserve Explicit Resource Management ('using') via /// (note that esnext.disposable does not pollute DOM globals).

- Merge origin/main into the feature branch
- Pass object arguments to init and initSync in verify-pack.mjs
- Check SyncInitInput parity across the four TypeScript profiles
- Add a reference to esnext.disposable at the top of pkg/tunelet.d.ts.
- Keep [Symbol.dispose]() on Tunelet in scripts/postbuild-wasm.mjs.
- Reject any other triple-slash reference in pkg/tunelet.d.ts.
- Check using and object initializers in scripts/verify-pack.mjs.
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Addressed both adjustments in 7b2b615 and 27ac68b:

  1. init / initSync object arguments (#82): Merged main and updated scripts/verify-pack.mjs so all four TypeScript consumer profiles check init() / init({ module_or_path: source }), rootInitSync({ module: syncSource }), and wasmInitSync({ module: syncSource }) (with SyncInitInput parity), alongside runtime child-process checks for wasmModule.default({ module_or_path }), initSync({ module }), and wasmModule.initSync({ module }).
  2. Explicit Resource Management ([Symbol.dispose]): Confirmed that preserving [Symbol.dispose](): void via /// <reference lib="esnext.disposable" /> is strictly better—pkg/tunelet.js already attaches Tunelet.prototype[Symbol.dispose] = Tunelet.prototype.free at runtime, 0.3.3 already exposed [Symbol.dispose](): void publicly, and esnext.disposable resolves using cleanly under "lib": ["ES2020"] without leaking DOM globals. Updated scripts/postbuild-wasm.mjs to prepend /// <reference lib="esnext.disposable" />, assert Tunelet[Symbol.dispose] stays intact, and reject any other /// <reference ... /> directive, and added using and runtime [Symbol.dispose]() assertions to scripts/verify-pack.mjs.

google-labs-stitch Bot added a commit that referenced this pull request Nov 25, 2026
- Delete scripts/normalize-wasm-pkg.mjs in favor of #123
- Restore package.json, tsconfig.json and AGENTS.md to main
- Restore the TypeScript and default checks in scripts/verify-pack.mjs
- Keep the isolated node:http loader checks in scripts/verify-pack.mjs
@byteland-app
byteland-app merged commit 254ce7d into main Nov 25, 2026
1 check passed
@byteland-app
byteland-app deleted the stitch/sanitize-ts-declarations-and-wasm-exports-jm1-aba0f6bd-aafd-4b2f-9880-05b0fa5219ee branch November 25, 2026 14:27
byteland-app pushed a commit that referenced this pull request Nov 25, 2026
* fix(npm): normalize Wasm types and verify HTTP loaders

- Add esnext.disposable and portable global types to pkg/tunelet.d.ts
- Replace RequestInfo and BufferSource aliases before tsc runs
- Remove synthetic DOM and disposable libs from tsconfig.json
- Check browser, WebWorker and NodeNext consumers in verify-pack.mjs
- Test HTTP loaders, 404 retries, buffers, modules and initSync
- Verify both tunelet and @bytelandtechnology/tunelet archives
- Document the declaration matrix and loader checks in AGENTS.md

* test(npm): keep only the HTTP loader checks in verify-pack

- Delete scripts/normalize-wasm-pkg.mjs in favor of #123
- Restore package.json, tsconfig.json and AGENTS.md to main
- Restore the TypeScript and default checks in scripts/verify-pack.mjs
- Keep the isolated node:http loader checks in scripts/verify-pack.mjs

---------

Co-authored-by: google-labs-stitch[bot] <315546542+google-labs-stitch[bot]@users.noreply.github.com>
google-labs-stitch Bot added a commit that referenced this pull request Nov 25, 2026
- Merge main with #105, #123 and #135 into the branch.
- Run postbuild-wasm.mjs before normalize-jsdoc.mjs in build:wasm.
- Convert ControlActivity rustdoc links into TypeScript names.
- Check the ControlActivity JSDoc and @throws tag in verify-pack.mjs.
google-labs-stitch Bot added a commit that referenced this pull request Nov 25, 2026
- Clear periods with clear_dirty_ring and reset lead_periods spans (#92)
- Keep mono Choir and Harmony synthesis in LowLatency mode (#102)
- Decode undefined latencyMode to Standard for strict TypeScript (#123)
- Keep ControlActivity queries and fused formant envelopes (#30, #135)
google-labs-stitch Bot added a commit that referenced this pull request Nov 25, 2026
- Merge main 0.3.4 with #123 and #135 into the Float32 branch.
- Change TuneletAudioViews memory to InitOutput["memory"] in index.ts.
- Check Float32 and TuneletAudioViews in all verify-pack tsc profiles.
- Update README.md with InitOutput["memory"] and controlActivity().
google-labs-stitch Bot added a commit that referenced this pull request Nov 25, 2026
- Merge main at v0.3.4 into the mix and bypass branch.
- Keep the correction key reset documentation from #46 in Processor.
- Decode undefined mix and bypass fields in Wasm as in #123.
- Add undefined to optional mix and bypass TypeScript declarations.
- Update README.md for undefined optional fields and v0.3.4 queries.
google-labs-stitch Bot added a commit that referenced this pull request Nov 25, 2026
- Merge the latest main branch into the feature branch.
- Keep the shared history imports from #92 in src/resynthesis.rs.
- Decode undefined vibratoPreserve to 0 for #123.
- Check optional vibratoPreserve in scripts/verify-pack.mjs.
- Document undefined optional fields in README.md.
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.

1 participant