@@ -26,6 +26,8 @@ const pathSuffixes = [
26
26
27
27
const specifierSuffixes = [ '' , '.js' , '.json' , '/index.js' , '/index.json' ] ;
28
28
29
+ const conditions = new Set ( [ 'import' , 'node' ] ) ;
30
+
29
31
/**
30
32
* @see moduleResolve
31
33
*/
@@ -51,7 +53,7 @@ export const resolveFrom = (lookup: string, parent?: string): string => {
51
53
52
54
for ( const suffix of specifierSuffixes ) {
53
55
try {
54
- return fileURLToPath ( moduleResolve ( lookup + suffix , base ) ) ;
56
+ return fileURLToPath ( moduleResolve ( lookup + suffix , base , conditions ) ) ;
55
57
} catch ( err ) {
56
58
if ( ! resolveError ) {
57
59
resolveError = err as Error ;
@@ -175,7 +177,7 @@ function resolveConfig(
175
177
raw : string ,
176
178
context : ResolveExtendsContext = { }
177
179
) : string {
178
- const resolve = context . resolve || tryResolveId ;
180
+ const resolve = context . resolve || resolveId ;
179
181
const id = getId ( raw , context . prefix ) ;
180
182
181
183
let resolved : string ;
@@ -192,20 +194,6 @@ function resolveConfig(
192
194
return resolved ;
193
195
}
194
196
195
- function tryResolveId ( id : string , context : ResolveExtendsContext ) {
196
- const cwd = context . cwd || process . cwd ( ) ;
197
-
198
- for ( const suffix of [ '' , '.js' , '.json' , '/index.js' , '/index.json' ] ) {
199
- try {
200
- return fileURLToPath (
201
- moduleResolve ( id + suffix , pathToFileURL ( path . join ( cwd , id ) ) )
202
- ) ;
203
- } catch { }
204
- }
205
-
206
- return resolveId ( id , context ) ;
207
- }
208
-
209
197
function resolveId (
210
198
specifier : string ,
211
199
context : ResolveExtendsContext = { }
0 commit comments