Skip to content

Commit 8c8857d

Browse files
authored
fix(devframe): bundle agnostic ohash digest to keep node:crypto out of browser (#6)
`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.
1 parent 6d9818d commit 8c8857d

4 files changed

Lines changed: 22 additions & 1 deletion

File tree

packages/devframe/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
"human-id": "catalog:inlined",
9090
"immer": "catalog:deps",
9191
"launch-editor": "catalog:deps",
92+
"mlly": "catalog:build",
9293
"obug": "catalog:deps",
9394
"ohash": "catalog:deps",
9495
"open": "catalog:deps",
@@ -100,7 +101,7 @@
100101
"whenexpr": "catalog:deps"
101102
},
102103
"inlinedDependencies": {
103-
"ansis": "4.2.0",
104+
"ansis": "4.3.0",
104105
"bundle-name": "4.1.0",
105106
"default-browser": "5.5.0",
106107
"default-browser-id": "5.0.1",

packages/devframe/tsdown.config.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
import { fileURLToPath } from 'node:url'
2+
import { resolveSync } from 'mlly'
13
import { defineConfig } from 'tsdown'
24

5+
// Resolve `ohash/crypto` without the `node` condition so the pure-JS digest
6+
// is bundled. The default resolution honours `node`, which inlines
7+
// `node:crypto.createHash` into outputs that are later shipped to the
8+
// browser via the `client` entry.
9+
const ohashCryptoAgnostic = fileURLToPath(
10+
resolveSync('ohash/crypto', { url: import.meta.url, conditions: ['import'] }),
11+
)
12+
313
export default defineConfig({
14+
alias: {
15+
'ohash/crypto': ohashCryptoAgnostic,
16+
},
417
entry: {
518
'index': 'src/index.ts',
619
'rpc/index': 'src/rpc/index.ts',

pnpm-lock.yaml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ catalogs:
2323
'@antfu/ni': ^30.1.0
2424
'@nuxt/kit': ^4.4.5
2525
'@preact/preset-vite': ^2.10.5
26+
mlly: ^1.8.2
2627
tsdown: ^0.22.0
2728
tsx: ^4.21.0
2829
turbo: ^2.9.12

0 commit comments

Comments
 (0)