@@ -14,6 +14,8 @@ const cjsMockFallback = `throw new Error('Mocking loaded ESM modules in not poss
1414let resolveSrc , globLib
1515
1616const packageJSONs = new Map ( )
17+ const reactNativeMaps = new Map ( )
18+ const reactNativeResolves = new Map ( )
1719
1820function findPackageJSON ( file ) {
1921 if ( packageJSONs . has ( file ) ) return packageJSONs . get ( file )
@@ -43,8 +45,6 @@ function findPackageJSON(file) {
4345 return null
4446}
4547
46- const reactNativeMaps = new Map ( )
47-
4848async function mapReactNative ( context ) {
4949 const pkg = findPackageJSON ( context )
5050 if ( ! pkg ) return [ null ]
@@ -584,6 +584,9 @@ export const build = async (...files) => {
584584
585585 // This whole hack is needed because of https://github.com/evanw/esbuild/issues/4427
586586 if ( process . env . EXODUS_TEST_IS_BAREBONE ) {
587+ const key = JSON . stringify ( args )
588+ if ( reactNativeResolves . has ( key ) ) return reactNativeResolves . get ( key )
589+
587590 // Modules are mapped pre-resolve against importer
588591 if ( ! / ^ [ . / ] / u. test ( path ) ) {
589592 const { map } = await mapReactNative ( args . importer )
@@ -600,7 +603,10 @@ export const build = async (...files) => {
600603 const r = await esbuildResolve ( path , { ...opts , namespace : 'exodus-test.bundle' } )
601604
602605 // Errors can only default to usual resolution to support e.g. optional dynamic require()
603- if ( ! r . path || r . errors . length > 0 || r . warnings . length > 0 || r . external ) return
606+ if ( ! r . path || r . errors . length > 0 || r . warnings . length > 0 || r . external ) {
607+ reactNativeResolves . set ( key , undefined )
608+ return
609+ }
604610
605611 // Resolved files are mapped post-resolve against their package
606612 const { map, main, dir } = await mapReactNative ( r . path )
@@ -619,6 +625,7 @@ export const build = async (...files) => {
619625 }
620626 }
621627
628+ reactNativeResolves . set ( key , r )
622629 return r
623630 }
624631 }
0 commit comments