Skip to content

Conversation

@mondoreale
Copy link
Contributor

@mondoreale mondoreale commented Jan 19, 2026

Summary

Introduces a Rollup-based bundling system for the SDK, enabling proper platform-specific builds for both Node.js and browser environments with architectural refactoring to support environment-specific code via the @/ path alias pattern.

Key Changes

  • Rollup bundling pipeline - Added rollup.config.mts producing multiple output formats:

    • Node.js: ESM (.js) and CJS (.cjs)
    • Browser: ESM (.js) and CJS (.cjs)
    • UMD: Regular and minified builds for <script> tag usage
  • Platform-specific code organization - Introduced _browser/ and _nodejs/ directories with @/ path alias that resolves to the correct platform at build time:

    • Persistence: Browser uses IndexedDB, Node.js uses SQLite
    • createRSAKeyPair: Browser uses WebCrypto, Node.js uses native crypto
  • TypeScript configuration refactor - Split into tsconfig.node.json and tsconfig.browser.json for separate compilation targets

  • Browser compatibility improvements:

    • Replaced crypto.randomBytes with @noble/post-quantum/utils
    • Added publicEncrypt and privateDecrypt to @streamr/utils
    • Aliased streamreadable-stream and timerstimers-browserify

Known Limitations

  • Persistence.exists() is not implemented for browser (throws error) - this functionality is Node.js only

Future Considerations

  • In the SDK, browser-specific code lives in src/_browser/ and Node.js-specific code in src/_nodejs/. This underscore-prefixed directory pattern could be applied to other packages in the monorepo that need platform-specific implementations.

@github-actions github-actions bot added cli-tools Related to CLI Tools Package utils sdk node labels Jan 19, 2026
@github-actions github-actions bot added network Related to Network Package test-utils Related to Test Utils Package dht Related to DHT package proto-rpc labels Jan 22, 2026
…tils

- Move Persistence interface from Persistence.ts to types.ts
- Update import in PersistenceManager to use type-only import
…directories

- Move `BrowserPersistence` and `ServerPersistence` to `_browser` and `_nodejs`
directories respectively.
- Rename both classes to `Persistence` with named exports, enabling consistent imports via the `@/` path alias that resolves to the appropriate platform directory at build time.
Switch from Node.js `crypto.randomBytes` to `@noble/post-quantum/utils`
`randomBytes` for browser compatibility across encryption utilities
and test files.
Replace migrationsPath with migrationsUrl to use import.meta.url in
shared code, avoiding path/url imports. Node.js Persistence converts
URL to path using fileURLToPath.
The new name matches the pattern.
@github-actions github-actions bot removed network Related to Network Package test-utils Related to Test Utils Package cli-tools Related to CLI Tools Package dht Related to DHT package proto-rpc node labels Jan 23, 2026
@mondoreale mondoreale marked this pull request as ready for review January 23, 2026 14:12
@mondoreale mondoreale requested a review from Copilot January 23, 2026 14:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a comprehensive Rollup-based bundling system to replace Webpack, enabling platform-specific builds for both Node.js and browser environments without requiring polyfills. The refactoring separates platform-specific code using the @/ path alias pattern that resolves to _browser/ or _nodejs/ directories at build time.

Changes:

  • Replaced Webpack with Rollup for SDK and utils packages, producing ESM, CJS, and UMD outputs
  • Split TypeScript configurations into browser and Node.js targets with separate compilation
  • Migrated from crypto.randomBytes to @noble/post-quantum/utils and added publicEncrypt/privateDecrypt wrappers

Reviewed changes

Copilot reviewed 73 out of 77 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/sdk/rollup.config.mts New Rollup configuration for SDK with platform-specific builds
packages/utils/rollup.config.mts Updated external dependencies for browser bundle
packages/sdk/tsconfig.*.json Split TypeScript configs for browser/Node.js compilation
packages/sdk/src/_browser/Persistence.ts Browser-specific IndexedDB persistence implementation
packages/sdk/src/_nodejs/Persistence.ts Node.js-specific SQLite persistence implementation
packages/utils/src/browser/crypto.ts Browser crypto utilities with public-encrypt integration
packages/sdk/webpack.config.js Removed Webpack configuration
release.sh Removed separate SDK browser build step
Various test files Updated imports to use explicit paths instead of barrel exports
Comments suppressed due to low confidence (1)

packages/sdk/src/_browser/Persistence.ts:39

  • The browser Persistence throws an error for the exists() method with message "Method not implemented in browser Persistence." However, the PersistenceContext interface requires this method. This could cause runtime errors if code tries to call exists() on browser persistence. Consider either implementing a browser-compatible version (e.g., checking IndexedDB database existence) or making the method optional in the interface with clear documentation about platform support.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 73 out of 77 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

packages/sdk/src/_browser/Persistence.ts:39

  • The browser Persistence implementation throws an error for the exists() method, but this could cause issues if code tries to use it. Consider returning a stub implementation (e.g., always return true or false) rather than throwing an error, as this would be more resilient to future usage patterns. The Node.js implementation at packages/sdk/src/_nodejs/Persistence.ts:46 provides a real implementation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mondoreale mondoreale merged commit 2c84e0a into bundles Jan 23, 2026
27 checks passed
@mondoreale mondoreale deleted the bundle-sdk branch January 23, 2026 15:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants