@@ -15,30 +15,42 @@ const dynamicImport = async <T>(id: string): Promise<T> => {
15
15
return ( 'default' in imported && imported . default ) || imported ;
16
16
} ;
17
17
18
- /**
19
- * Fake file name to provide {@link moduleResolve} a filename to resolve from the configuration cwd
20
- */
21
- const FAKE_FILE_NAME_FOR_RESOLVER = '__' ;
18
+ const pathSuffixes = [
19
+ '' ,
20
+ '.js' ,
21
+ '.json' ,
22
+ `${ path . sep } index.js` ,
23
+ `${ path . sep } index.json` ,
24
+ ] ;
25
+
26
+ const specifierSuffixes = [ '' , '.js' , '.json' , '/index.js' , '/index.json' ] ;
22
27
23
28
/**
24
29
* @see moduleResolve
25
30
*/
26
- export const resolveFrom = ( specifier : string , parent ?: string ) : string => {
27
- let resolved : URL ;
31
+ export const resolveFrom = ( lookup : string , parent ?: string ) : string => {
32
+ if ( path . isAbsolute ( lookup ) ) {
33
+ for ( const suffix of pathSuffixes ) {
34
+ const filename = lookup + suffix ;
35
+ if ( fs . existsSync ( filename ) ) {
36
+ return filename ;
37
+ }
38
+ }
39
+ }
40
+
28
41
let resolveError : Error | undefined ;
29
42
30
43
const base = pathToFileURL (
31
44
parent
32
45
? fs . statSync ( parent ) . isDirectory ( )
33
- ? path . join ( parent , FAKE_FILE_NAME_FOR_RESOLVER )
46
+ ? path . join ( parent , 'noop.js' )
34
47
: parent
35
48
: import . meta. url
36
49
) ;
37
50
38
- for ( const suffix of [ '' , '.js' , '.json' , '/index.js' , '/index.json' ] ) {
51
+ for ( const suffix of specifierSuffixes ) {
39
52
try {
40
- resolved = moduleResolve ( specifier + suffix , base ) ;
41
- return fileURLToPath ( resolved ) ;
53
+ return fileURLToPath ( moduleResolve ( lookup + suffix , base ) ) ;
42
54
} catch ( err ) {
43
55
if ( ! resolveError ) {
44
56
resolveError = err as Error ;
0 commit comments