Skip to content

fix(devframe): bundle agnostic ohash digest to keep node:crypto out of browser#6

Merged
antfu merged 1 commit into
mainfrom
antfu/ohash-bundle-agnostic-v1
May 12, 2026
Merged

fix(devframe): bundle agnostic ohash digest to keep node:crypto out of browser#6
antfu merged 1 commit into
mainfrom
antfu/ohash-bundle-agnostic-v1

Conversation

@antfu
Copy link
Copy Markdown
Contributor

@antfu antfu commented May 12, 2026

Summary

  • ohash's main entry imports digest from ohash/crypto, whose conditional exports pick node (which imports node:crypto.createHash) when bundled by tsdown. That digest was being inlined into dist/utils/hash.mjs and transitively re-exported through dist/client/index.mjs via rpc/cache.ts, so every browser consumer of devframe/client ended up with a node:crypto import — broken.
  • Force the agnostic (pure-JS) variant by aliasing ohash/crypto to the path produced by mlly.resolveSync with conditions: ['import'], skipping the node branch only for this specifier (other deps keep normal resolution).
  • Add mlly to the build catalog and to devframe's devDependencies so the build-time resolution is properly declared. No source change needed — the alias is transparent to utils/hash.ts.

Test plan

  • pnpm buildgrep -RE "node:crypto|createHash" packages/devframe/dist/ returns no matches; bundled hash chunk now embeds ohash/dist/crypto/js/index.mjs.
  • pnpm test — 283 tests pass, snapshots in dumps.test.ts.snap unchanged (JS and Node digests are bit-identical for SHA-256 + base64url).
  • pnpm lint and pnpm typecheck clean.

…f browser

`ohash/crypto` resolves to its `node` variant under tsdown's default
conditions, inlining `node:crypto.createHash` into the bundled
`utils/hash.mjs` chunk that is transitively re-exported through the
`client` entry. Force the agnostic (pure-JS) variant by aliasing
`ohash/crypto` to the path produced by `mlly.resolveSync` without the
`node` condition. Both implementations emit identical SHA-256 +
base64url output, so existing hash snapshots remain stable.
@netlify
Copy link
Copy Markdown

netlify Bot commented May 12, 2026

Deploy Preview for devfra ready!

Name Link
🔨 Latest commit ce2b876
🔍 Latest deploy log https://app.netlify.com/projects/devfra/deploys/6a02ec7b9997d300086c2cb9
😎 Deploy Preview https://deploy-preview-6--devfra.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@antfu antfu merged commit 8c8857d into main May 12, 2026
11 checks passed
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