|
1 | 1 | import { defineConfig } from 'tsdown' |
| 2 | +import { createRequire } from 'module' |
2 | 3 | import { fileURLToPath } from 'url' |
3 | 4 | import { dirname, join } from 'path' |
4 | 5 |
|
@@ -28,21 +29,27 @@ export default defineConfig([ |
28 | 29 | target: 'es2017', |
29 | 30 | inputOptions: (_options, format) => { |
30 | 31 | 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. |
37 | 40 | // |
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). |
43 | 48 | return { |
44 | 49 | resolve: { |
45 | | - conditionNames: ['require', 'node', 'default'], |
| 50 | + alias: { |
| 51 | + '@supabase/tracing': createRequire(import.meta.url).resolve('@supabase/tracing'), |
| 52 | + }, |
46 | 53 | }, |
47 | 54 | } |
48 | 55 | } |
|
0 commit comments