@@ -117,6 +117,29 @@ let resolver: Resolver | undefined
117
117
const digestHashObject = ( value : object | null | undefined ) =>
118
118
hashObject ( value ?? { } ) . digest ( 'hex' )
119
119
120
+ let bunCoreModules : Set < string > | undefined
121
+ const getBunCoreModules = ( ) : Set < string > => {
122
+ if ( ! bunCoreModules ) {
123
+ bunCoreModules = new Set < string > ( )
124
+
125
+ const { found, path } = resolve ( 'bun-types' , 'bun-types' )
126
+ if ( found && path ) {
127
+ const regex = / d e c l a r e m o d u l e [ " ' ] ( b u n : \w + ) [ " ' ] / g
128
+ const content = fs . readFileSync ( path , 'utf8' )
129
+ let match : RegExpExecArray | null
130
+
131
+ while ( ( match = regex . exec ( content ) ) !== null ) {
132
+ // The first captured group is at index 1
133
+ if ( match [ 1 ] ) {
134
+ bunCoreModules . add ( match [ 1 ] )
135
+ }
136
+ }
137
+ }
138
+ }
139
+
140
+ return bunCoreModules
141
+ }
142
+
120
143
/**
121
144
* @param source the module to resolve; i.e './some-module'
122
145
* @param file the importing file's full path; i.e. '/usr/local/bin/file.js'
@@ -169,6 +192,16 @@ export function resolve(
169
192
}
170
193
}
171
194
195
+ // match against bun core modules
196
+ if ( getBunCoreModules ( ) . has ( source ) ) {
197
+ log ( 'matched bun core:' , source )
198
+
199
+ return {
200
+ found : true ,
201
+ path : null ,
202
+ }
203
+ }
204
+
172
205
initMappers ( cachedOptions )
173
206
174
207
const mappedPath = getMappedPath ( source , file , cachedOptions . extensions , true )
0 commit comments