Skip to content

Commit 26c6bbc

Browse files
committed
fix(misc): more fixes
1 parent 334de16 commit 26c6bbc

2 files changed

Lines changed: 23 additions & 16 deletions

File tree

packages/core/supabase-js/test/bundle-hermes-compat.test.cjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* - No new Function() calls -> browsers with a strict Content-Security-Policy
88
* (no 'unsafe-eval') block new Function() identically to eval() at runtime.
99
*
10-
* Both constraints are satisfied by telling Rolldown to honor the `require`
11-
* export condition when building dist/index.cjs (see tsdown.config.ts).
12-
* @supabase/tracing's `require` condition points at its tsc-built CJS output
13-
* (dist/main/), where dynamic `import()` has already been lowered to require().
10+
* Both constraints are satisfied by aliasing @supabase/tracing to its
11+
* `main`-field file (dist/main/index.js) for the CJS bundle — see
12+
* tsdown.config.ts. That file is tsc's CJS output, where the dynamic
13+
* `import()` has already been lowered to a runtime `require()`.
1414
*
1515
* Run with: node test/bundle-hermes-compat.test.cjs
1616
*/

packages/core/supabase-js/tsdown.config.ts

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { defineConfig } from 'tsdown'
2+
import { createRequire } from 'module'
23
import { fileURLToPath } from 'url'
34
import { dirname, join } from 'path'
45

@@ -28,21 +29,27 @@ export default defineConfig([
2829
target: 'es2017',
2930
inputOptions: (_options, format) => {
3031
if (format === 'cjs') {
31-
// Rolldown defaults to the 'import' export condition even when emitting
32-
// CJS, so @supabase/tracing's ESM source (with native `import()`) ends
33-
// up inlined into dist/index.cjs. hermesc (Hermes bytecode compiler for
34-
// React Native release builds) rejects `import()` at parse time, before
35-
// dead-code elimination — so the syntax has to be physically absent
36-
// from the CJS bundle.
32+
// Rolldown inlines @supabase/tracing's ESM source (with native
33+
// `import()`) into dist/index.cjs even when emitting CJS — its
34+
// `import` export condition wins because Rolldown prefers ESM
35+
// source for tree-shaking, regardless of `resolve.conditionNames`.
36+
// hermesc (Hermes bytecode compiler for React Native release
37+
// builds) rejects `import()` at parse time, before dead-code
38+
// elimination, so the syntax has to be physically absent from the
39+
// CJS bundle.
3740
//
38-
// Tell Rolldown to honor the 'require' export condition for this build.
39-
// For @supabase/tracing that resolves to dist/main/index.js — tsc's
40-
// CJS output, where dynamic `import()` has been lowered to require().
41-
// dist/index.mjs intentionally keeps native `import()` (valid ESM,
42-
// not blocked by browser CSP, and Hermes never sees the ESM bundle).
41+
// Alias @supabase/tracing directly to its `main`-field file. This
42+
// bypasses exports-conditions resolution entirely and pins the CJS
43+
// bundle to tsc's CJS output (dist/main/index.js), where the
44+
// dynamic `import()` has been lowered to a runtime `require()`.
45+
// dist/index.mjs intentionally keeps the native `import()` — it's
46+
// valid ESM, isn't blocked by browser CSP, and Hermes never sees
47+
// the ESM bundle (Metro pulls the `require` condition).
4348
return {
4449
resolve: {
45-
conditionNames: ['require', 'node', 'default'],
50+
alias: {
51+
'@supabase/tracing': createRequire(import.meta.url).resolve('@supabase/tracing'),
52+
},
4653
},
4754
}
4855
}

0 commit comments

Comments
 (0)