-
Notifications
You must be signed in to change notification settings - Fork 43
Bundle sdk for browser (no polyfills required!), and for Node.js
#3358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
415cec0 to
1cf013c
Compare
…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.
¯\_(ツ)_/¯
Funny how drilling for them deps turn the whole thing into a maze.
This will, potentially, resolve the issues with `nightwatch`.
7afa666 to
f9179dc
Compare
f9179dc to
e768bda
Compare
There was a problem hiding this 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.randomBytesto@noble/post-quantum/utilsand addedpublicEncrypt/privateDecryptwrappers
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 callexists()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.
Both work but empty string is confusing.
There was a problem hiding this 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.
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.mtsproducing multiple output formats:.js) and CJS (.cjs).js) and CJS (.cjs)<script>tag usagePlatform-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 SQLitecreateRSAKeyPair: Browser uses WebCrypto, Node.js uses native cryptoTypeScript configuration refactor - Split into
tsconfig.node.jsonandtsconfig.browser.jsonfor separate compilation targetsBrowser compatibility improvements:
crypto.randomByteswith@noble/post-quantum/utilspublicEncryptandprivateDecryptto@streamr/utilsstream→readable-streamandtimers→timers-browserifyKnown Limitations
Persistence.exists()is not implemented for browser (throws error) - this functionality is Node.js onlyFuture Considerations
src/_browser/and Node.js-specific code insrc/_nodejs/. This underscore-prefixed directory pattern could be applied to other packages in the monorepo that need platform-specific implementations.