Skip to content

feat(npm): add conditional Node.js and browser package entries - #119

Open
google-labs-stitch[bot] wants to merge 5 commits into
mainfrom
stitch/conditional-node-browser-entries-jm0-60329ac7-4a9c-4ac8-a145-0cbb87778762
Open

google-labs-stitch[bot] wants to merge 5 commits into
mainfrom
stitch/conditional-node-browser-entries-jm0-60329ac7-4a9c-4ac8-a145-0cbb87778762

Conversation

@google-labs-stitch

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

Copy link
Copy Markdown
Contributor

Summary

  • Add conditional src/node.ts and src/browser.ts entries alongside a shared src/shared.ts helper while keeping src/index.ts (dist/index.js and dist/index.d.ts) with identical exported signatures (including TuneletAudioViews) for bundler-free browser deployments and "main" fallback.
  • Keep "main": "./dist/index.js" and "types": "./dist/index.d.ts", and configure conditional "browser", "node" and fallback package exports for "." in package.json on top of main.
  • Keep main's scripts/postbuild-wasm.mjs, scripts/normalize-jsdoc.mjs, .githooks/*, .github/*, Cargo.lock and Rust sources unchanged so Tunelet[Symbol.dispose](): void, TuneletAudioViews[Symbol.dispose](): void (/// <reference lib="esnext.disposable" />), TypeScript 7.0 WasmMemory typing, normalized JSDoc comments, .wasm subpath exports, Float32 buffers, humanize / flexTune, Telemetry pitch fields and Float32Array voice slices, scalar ParameterControl events and { voices: undefined } handling stay intact without duplication.
  • Accept "file:" URL strings and cross-realm URL objects across entries, and resolve pkg/tunelet_bg.wasm from the installed package in src/node.ts if ../pkg/tunelet_bg.wasm is absent.
  • Update AGENTS.md, README.md and scripts/verify-pack.mjs on top of main to document src/browser.ts, src/node.ts, src/index.ts and src/shared.ts and verify both tunelet and @bytelandtechnology/tunelet fourteen-file archives, --ignore-scripts prebuilt checks, --out-dir checksum output, browser bundle isolation, Tunelet[Symbol.dispose]() and TuneletAudioViews[Symbol.dispose]() with using disposal, Float32 copied and in-place views, Telemetry and ParameterControl runtime/type/JSDoc checks, dist/index.js, dist/node.js and dist/browser.js runtime and HTTP loaders, normalized JSDoc comments and strict TypeScript 7.0 profiles (node, es2023-bundler, es2023-nodenext, dom and webworker).

Verification

  • cargo rustc --locked --lib --release -- -D warnings
  • RUSTFLAGS="-D warnings" cargo build --locked --release
  • cargo fmt --check
  • cargo clippy --locked --lib -- -D warnings
  • RUSTDOCFLAGS="-D warnings" cargo doc --locked --no-deps
  • cargo rustdoc --locked --lib -- -D warnings
  • cargo package --locked
  • npm run check:wasm
  • npm run verify:pack -- --out-dir /tmp/verify-pack-out (sha256sum --check --strict) and npm run build:ts && npm run verify:pack -- --ignore-scripts

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

- Split src/index.ts into src/node.ts, src/browser.ts and src/shared.ts
- Export conditional node and default entries and .wasm subpaths
- Sanitize pkg/tunelet.d.ts in scripts/postbuild-wasm.mjs
- Accept file: strings, cross-realm URLs and flat bundles in Node.js
- Decode undefined HarmonyConfig.voices as 4 for strict TypeScript
- Verify archive files, runtime loaders and four tsc profiles
@byteland-app

Copy link
Copy Markdown
Contributor

Review: Conditional Node.js/browser exports are worth exploring if bundlers warn on node:fs/promises, but removing dist/index.js breaks documented bundler-free browser deployments, 'main' points to ./dist/browser.js, and WasmMemory is missing TS 7.0's toFixedLengthBuffer()/toResizableBuffer() methods. Let's land #123 first and revisit conditional exports as a backward-compatible follow-up that keeps dist/index.js and complete WasmMemory typing.

- Restore src/index.ts for direct browser and main imports
- Point main and types to dist/index.js and dist/index.d.ts
- Export conditional browser and node entries in package.json
- Add TypeScript 7.0 buffer methods to WasmMemory
- Merge main into scripts/verify-pack.mjs for both archives
- Check initializer object arguments in scripts/verify-pack.mjs
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Updated this PR to make the conditional exports backward-compatible and synced with main (v0.3.3):

  • Restored dist/index.js and dist/index.d.ts: Restored src/index.ts (and kept dist/index.js alongside dist/browser.js in the README.md bundler-free browser deployment instructions) so direct HTTP imports and import maps targeting dist/index.js continue to work without any static Node.js imports, while conditional "browser" and "node" exports give bundlers a node:-free dist/browser.js and a static Node.js dist/node.js entry.
  • Restored "main" and "types": Pointed "main" and "types" in package.json back to "./dist/index.js" and "./dist/index.d.ts" (working in both Node.js and browsers), while "exports"."." routes "browser", "node", and fallback conditions to their dedicated entries.
  • Completed TypeScript 7.0 WasmMemory typing: Added toFixedLengthBuffer(): ArrayBuffer; and toResizableBuffer(): ArrayBuffer; to WasmMemory in scripts/postbuild-wasm.mjs and verified InitOutput["memory"] assignability to WebAssembly.Memory in the dom and webworker TypeScript 7.0 profiles.
  • Merged main (v0.3.3): Preserved dual tunelet / @bytelandtechnology/tunelet archive checks, --out-dir + SHA256SUMS.txt release output (ci(release): verify and publish unscoped and scoped archives #118), and { module_or_path } / { module } object initializer arguments (test(npm): check the object arguments of the Wasm initializers #82) in scripts/verify-pack.mjs.

@byteland-app

Copy link
Copy Markdown
Contributor

Round 2 review: Thank you for restoring dist/index.js and completing TS 7.0 WasmMemory typing. However, scripts/postbuild-wasm.mjs and scripts/verify-pack.mjs still strip TuneletSymbol.dispose and forbid /// , which breaks TypeScript 'using' support. Since #123 already lands the .d.ts hygiene, { voices: undefined } fix, and .wasm exports while preserving Symbol.dispose via /// , please rebase onto #123, drop the duplicate postbuild-wasm.mjs / harmony.rs changes, and keep Symbol.dispose intact if we still want conditional Node/browser entries.

- Merge main to use upstream postbuild-wasm.mjs and harmony.rs
- Keep Tunelet[Symbol.dispose]() in verify-pack.mjs checks
- Share isUrlLike across the browser, node and index entries
- Check TypeScript 'using' disposal and HTTP Wasm loaders
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Synced this PR with main (v0.3.4, including #123, #105, #90, #120, and #135) and addressed all Round 2 review points:

  • Dropped duplicate scripts/postbuild-wasm.mjs and src/harmony.rs changes: Checked out main's scripts/postbuild-wasm.mjs and src/harmony.rs verbatim so neither file has any diff against main.
  • Preserved Tunelet[Symbol.dispose]() and using support: Kept /// <reference lib="esnext.disposable" /> and [Symbol.dispose](): void intact in pkg/tunelet.d.ts (re-exported through dist/node.d.ts, dist/browser.d.ts, and dist/index.d.ts), updated scripts/verify-pack.mjs to assert both are present in pkg/tunelet.d.ts, verified runtime disposableProcessor[Symbol.dispose]() across entries, and added using disposal checks (for both the package root and direct dist/index.js imports) across all five strict TypeScript 7.0 consumer profiles (node, es2023-bundler, es2023-nodenext, dom, and webworker).
  • Preserved upstream main checks and docs: Merged verifyHttpLoaders (test(npm): verify HTTP Wasm loaders in verify-pack #105) in scripts/verify-pack.mjs (extending HTTP checks to dist/browser.js and dist/index.js), kept controlActivity() (feat: add control activity queries #135) in README.md and entry doc comments, and kept --release in npm run check:wasm (ci: share Wasm setup with split caches and run release checks #90).

@byteland-app

Copy link
Copy Markdown
Contributor

Round 3 review: Approved — great work rebasing onto #123, dropping duplicate changes, and preserving TuneletSymbol.dispose with esnext.disposable. Please rebase onto updated main after #107 and #117 (keeping normalize-jsdoc.mjs chained in build:wasm and exporting TuneletAudioViews from the conditional entries).

…de-browser-entries-jm0-60329ac7-4a9c-4ac8-a145-0cbb87778762

- Share TuneletAudioViews across node, browser and index entries
- Keep normalize-jsdoc.mjs in build:wasm and clean dist in build:ts
- Merge Float32, correction, JSDoc and prebuilt checks in verify-pack
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Synced this PR with updated main (0850e25, including #107, #117, and #45) in 2e793dd and addressed all Round 3 review items:

  • Synced onto updated main (fix(npm): normalize JSDoc comments at the package boundary #107, feat: expose Float32 buffers in Wasm for in-place audio #117, and feat(resynthesis): add humanize and flex-tune controls #45): Merged origin/main (0850e25) cleanly while keeping scripts/postbuild-wasm.mjs, scripts/normalize-jsdoc.mjs, .githooks/*, and all Rust sources identical to main.
  • Kept normalize-jsdoc.mjs chained in build:wasm: Preserved && node scripts/postbuild-wasm.mjs && node scripts/normalize-jsdoc.mjs in package.json and extended verifyNormalizedJsDoc in scripts/verify-pack.mjs across all packed dist/*.{js,d.ts} and pkg/tunelet.{js,d.ts} files.
  • Exported TuneletAudioViews from conditional entries: Defined TuneletAudioViews (including TuneletAudioViews[Symbol.dispose](): void) in src/shared.ts and re-exported it from src/node.ts, src/browser.ts, and src/index.ts, with constructor identity, Float32 in-place buffer rebinding, and TypeScript 7.0 using disposal verified across node, es2023-bundler, es2023-nodenext, dom, and webworker profiles in scripts/verify-pack.mjs.

@byteland-app

Copy link
Copy Markdown
Contributor

Review: Conditional browser / node entries, AudioWorkletGlobalScope guards, and the expanded verify-pack.mjs matrix look solid.

Please sync onto updated main (#139, #131, #104, #61), preserving #131's check:wasm in package.json and #104/#61's runtime and JSDoc checks in scripts/verify-pack.mjs. While syncing, please also update README.md line 663 and AGENTS.md to mention src/browser.ts, src/node.ts, and src/shared.ts alongside src/index.ts.

…de-browser-entries-jm0-60329ac7-4a9c-4ac8-a145-0cbb87778762

- Keep check:wasm in package.json and clean dist in build:ts
- Keep Telemetry and ParameterControl checks in verify-pack.mjs
- List browser, node and shared entries in README.md and AGENTS.md
@google-labs-stitch

Copy link
Copy Markdown
Contributor Author

Synced this PR with updated main (8880205, including #139, #131, #104, and #61) in 27f85b6 and addressed all review items:

  • Preserved #131 in package.json: Kept check:wasm (cargo clippy --locked --release --lib --target wasm32-unknown-unknown --features wasm -- -D warnings && cargo rustdoc --locked --release --lib --target wasm32-unknown-unknown --features wasm -- -D warnings) and build:wasm (... && node scripts/postbuild-wasm.mjs && node scripts/normalize-jsdoc.mjs) intact while cleaning dist before tsc in build:ts.
  • Preserved #104 and #61 checks in scripts/verify-pack.mjs: Kept Telemetry pitch fields and Float32Array voice slices runtime (voiceRatios, voiceGains, voiceCount, voiced, targetMidiNote), type-declaration (Telemetry, voiceSlices), and JSDoc (telemetryInterfaceMatch) checks alongside scalar ParameterControl runtime and type-declaration checks (dryMix, humanize, flexTune) across all five strict TypeScript 7.0 profiles.
  • Updated README.md and AGENTS.md: Updated README.md (### npm package) and AGENTS.md (Core rules, Repository map, and Build and verify) in ASD-STE100 to list src/browser.ts, src/node.ts, and src/shared.ts alongside src/index.ts.

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