File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -129,3 +129,6 @@ jobs:
129129
130130 - name : Test CJS requires
131131 run : pnpm nx test:cjs supabase-js
132+
133+ - name : Test Hermes (React Native) compatibility
134+ run : pnpm nx test:hermes-compat supabase-js
Original file line number Diff line number Diff line change 6969 "test:exports" : " attw --pack . --ignore-rules no-resolution" ,
7070 "test:esm" : " node test/module-resolution.test.mjs && node test/module-resolution-cors.test.mjs" ,
7171 "test:cjs" : " node test/module-resolution.test.cjs && node test/module-resolution-cors.test.cjs" ,
72- "test:module-resolution" : " npm run test:exports && npm run test:esm && npm run test:cjs" ,
72+ "test:hermes-compat" : " node test/bundle-hermes-compat.test.cjs" ,
73+ "test:module-resolution" : " npm run test:exports && npm run test:esm && npm run test:cjs && npm run test:hermes-compat" ,
7374 "docs" : " typedoc --entryPoints src/index.ts --entryPoints src/cors.ts --out docs/v2" ,
7475 "docs:json" : " typedoc --entryPoints src/index.ts --entryPoints src/cors.ts --json docs/v2/spec.json --excludeExternals" ,
7576 "serve:coverage" : " pnpm nx test:coverage supabase-js && pnpm dlx serve test/coverage" ,
Original file line number Diff line number Diff line change 1+ /**
2+ * Hermes Compatibility Test
3+ *
4+ * Asserts dist/index.cjs contains no bare import() expressions.
5+ * hermesc (React Native bytecode compiler) rejects import() at parse time —
6+ * before dead-code elimination — so the syntax must be physically absent.
7+ * The only allowed occurrence is inside a new Function() string body, which
8+ * is opaque to all static parsers including hermesc.
9+ *
10+ * Run with: node test/bundle-hermes-compat.test.cjs
11+ */
12+
13+ const assert = require ( 'assert' )
14+ const fs = require ( 'fs' )
15+ const path = require ( 'path' )
16+
17+ console . log ( 'Testing Hermes (React Native) compatibility...\n' )
18+
19+ const cjsPath = path . join ( __dirname , '../dist/index.cjs' )
20+ const cjs = fs . readFileSync ( cjsPath , 'utf8' )
21+ const lines = cjs . split ( '\n' )
22+
23+ let bareImportCount = 0
24+ for ( let i = 0 ; i < lines . length ; i ++ ) {
25+ const line = lines [ i ]
26+ if ( ! line . includes ( 'import(' ) ) continue
27+ if ( ! line . includes ( 'new Function(' ) ) {
28+ bareImportCount ++
29+ console . error (
30+ `❌ Bare import() at line ${ i + 1 } :\n ${ line . trim ( ) } \n` +
31+ ` This breaks hermesc (Hermes bytecode compiler for React Native).`
32+ )
33+ }
34+ }
35+
36+ assert . strictEqual (
37+ bareImportCount ,
38+ 0 ,
39+ `${ bareImportCount } bare import() expression(s) in dist/index.cjs — breaks React Native Hermes builds.`
40+ )
41+
42+ console . log ( '1. No bare import() expressions in dist/index.cjs' )
43+ console . log ( ' ✅ Hermes-safe (React Native compatible)\n' )
44+ console . log ( '🎉 Hermes compatibility test passed!' )
Original file line number Diff line number Diff line change @@ -21,9 +21,7 @@ const OTEL_PKG = '@opentelemetry/api'
2121// absent from the bundle. new Function() bodies are opaque strings to all
2222// static parsers, including hermesc.
2323// eslint-disable-next-line no-new-func
24- const _dynamicImport = new Function ( 'p' , 'return import(p)' ) as (
25- pkg : string
26- ) => Promise < any >
24+ const _dynamicImport = new Function ( 'p' , 'return import(p)' ) as ( pkg : string ) => Promise < any >
2725
2826function loadOtel ( ) : Promise < any | null > {
2927 if ( otelModulePromise === null ) {
You can’t perform that action at this time.
0 commit comments