1
1
import fs from 'node:fs'
2
2
import { isBuiltin } from 'node:module'
3
- import { dirname } from 'node:path'
3
+ import path from 'node:path'
4
4
5
5
import { ResolverFactory , CachedInputFileSystem } from 'enhanced-resolve'
6
6
import type { ResolveOptions } from 'enhanced-resolve'
@@ -25,9 +25,9 @@ type NodeResolverOptions = {
25
25
export function createNodeResolver ( {
26
26
extensions = [ '.mjs' , '.cjs' , '.js' , '.json' , '.node' ] ,
27
27
conditionNames = [ 'default' , 'module' , 'import' , 'require' ] ,
28
- mainFields = [ 'main' ] ,
29
- exportsFields = [ 'exports' ] ,
30
- mainFiles = [ 'index' ] ,
28
+ mainFields : _mainFields = [ 'main' ] ,
29
+ exportsFields : _exportsFields = [ 'exports' ] ,
30
+ mainFiles : _mainFiles = [ 'index' ] ,
31
31
fileSystem = new CachedInputFileSystem ( fs , 4 * 1000 ) ,
32
32
...restOptions
33
33
} : Partial < NodeResolverOptions > = { } ) : NewResolver {
@@ -54,9 +54,13 @@ export function createNodeResolver({
54
54
}
55
55
56
56
try {
57
- const path = resolver . resolveSync ( { } , dirname ( sourceFile ) , modulePath )
58
- if ( path ) {
59
- return { found : true , path }
57
+ const resolved = resolver . resolveSync (
58
+ { } ,
59
+ path . dirname ( sourceFile ) ,
60
+ modulePath ,
61
+ )
62
+ if ( resolved ) {
63
+ return { found : true , path : resolved }
60
64
}
61
65
return { found : false }
62
66
} catch {
0 commit comments