Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 27, 2025

Summary

Refactors @streamr/utils to eliminate polyfill requirements by implementing platform-specific builds for Node.js and browser environments using Rollup, with separate crypto/MD5 implementations and module aliasing.

Changes

Build system and packaging:

  • Dual-build system using Rollup to generate separate Node.js (ESM/CJS) and browser bundles
  • Package exports configured for conditional loading based on environment
  • Simplified build pipeline: removed tsconfig.rollup.json, use tsx to execute .mts config directly
  • Fixed rollup config to reference compiled output in dist/ rather than source paths
  • TypeScript project references for Node, browser, Jest, and Karma builds

Cross-platform crypto and environment:

  • Platform-specific crypto implementations (src/node/crypto.ts, src/browser/crypto.ts)
  • Platform-specific MD5 hashing (src/node/md5.ts, src/browser/md5.ts)
  • Environment variable abstraction (src/node/env.ts, src/browser/env.ts) replaces direct process.env access
  • Browser shims for os and buffer modules
  • Safe crypto global check using globalThis to handle non-secure contexts

Code quality improvements:

  • Keccak instance now local const instead of module-level mutable variable
  • Jest config aligned with tsconfig to use Node.js implementations in tests
  • Module aliases (@crypto, @md5, @/) configured across Jest, Karma, and Rollup

Limitations and future improvements

  • Rollup config must be pre-compiled to .mjs for Node 20 compatibility (.mts direct execution fails)
  • Browser crypto requires secure context (HTTPS); graceful degradation could be improved

Checklist before requesting a review

  • Is this a breaking change? If it is, be clear in summary.
  • Read through code myself one more time.
  • Make sure any and all TODO comments left behind are meant to be left in.
  • Has reasonable passing test coverage?
  • Updated changelog if applicable.
  • Updated documentation if applicable.

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Refactor utils package for better cross-platform support refactor [NET-1606]: Make utils package work without polyfilling Dec 27, 2025
@linear
Copy link

linear bot commented Dec 27, 2025

@mondoreale
Copy link
Contributor

I'll copy over the new desc. Cheers.

@mondoreale mondoreale closed this Dec 27, 2025
@mondoreale mondoreale deleted the copilot/sub-pr-3279 branch December 27, 2025 23:38
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.

3 participants