@@ -78,9 +78,19 @@ function resolve(specifier, parentURL) {
78
78
}
79
79
80
80
const isMain = parentURL === undefined ;
81
- if ( isMain )
81
+ if ( isMain ) {
82
82
parentURL = pathToFileURL ( `${ process . cwd ( ) } /` ) . href ;
83
83
84
+ // This is the initial entry point to the program, and --input-type has
85
+ // been passed as an option; but --input-type can only be used with
86
+ // --eval, --print or STDIN string input. It is not allowed with file
87
+ // input, to avoid user confusion over how expansive the effect of the
88
+ // flag should be (i.e. entry point only, package scope surrounding the
89
+ // entry point, etc.).
90
+ if ( typeFlag )
91
+ throw new ERR_INPUT_TYPE_NOT_ALLOWED ( ) ;
92
+ }
93
+
84
94
let url = moduleWrapResolve ( specifier , parentURL ) ;
85
95
86
96
if ( isMain ? ! preserveSymlinksMain : ! preserveSymlinks ) {
@@ -93,27 +103,13 @@ function resolve(specifier, parentURL) {
93
103
url . hash = old . hash ;
94
104
}
95
105
96
- const type = getPackageType ( url . href ) ;
97
-
98
106
const ext = extname ( url . pathname ) ;
99
- const extMap =
100
- type !== TYPE_MODULE ? legacyExtensionFormatMap : extensionFormatMap ;
101
- let format = extMap [ ext ] ;
102
-
103
- if ( isMain && typeFlag ) {
104
- // This is the initial entry point to the program, and --input-type has
105
- // been passed as an option; but --input-type can only be used with
106
- // --eval, --print or STDIN string input. It is not allowed with file
107
- // input, to avoid user confusion over how expansive the effect of the
108
- // flag should be (i.e. entry point only, package scope surrounding the
109
- // entry point, etc.).
110
- throw new ERR_INPUT_TYPE_NOT_ALLOWED ( ) ;
111
- }
107
+ let format = extensionFormatMap [ ext ] ;
108
+ if ( ext === '.js' || ( ! format && isMain ) )
109
+ format = getPackageType ( url . href ) === TYPE_MODULE ? 'module' : 'commonjs' ;
112
110
if ( ! format ) {
113
- if ( isMain )
114
- format = type === TYPE_MODULE ? 'module' : 'commonjs' ;
115
- else if ( esModuleSpecifierResolution === 'node' )
116
- format = 'commonjs' ;
111
+ if ( esModuleSpecifierResolution === 'node' )
112
+ format = legacyExtensionFormatMap [ ext ] ;
117
113
else
118
114
throw new ERR_UNKNOWN_FILE_EXTENSION ( fileURLToPath ( url ) ) ;
119
115
}
0 commit comments