@@ -78,9 +78,19 @@ function resolve(specifier, parentURL) {
7878 }
7979
8080 const isMain = parentURL === undefined ;
81- if ( isMain )
81+ if ( isMain ) {
8282 parentURL = pathToFileURL ( `${ process . cwd ( ) } /` ) . href ;
8383
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+
8494 let url = moduleWrapResolve ( specifier , parentURL ) ;
8595
8696 if ( isMain ? ! preserveSymlinksMain : ! preserveSymlinks ) {
@@ -93,27 +103,13 @@ function resolve(specifier, parentURL) {
93103 url . hash = old . hash ;
94104 }
95105
96- const type = getPackageType ( url . href ) ;
97-
98106 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' ;
112110 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 ] ;
117113 else
118114 throw new ERR_UNKNOWN_FILE_EXTENSION ( fileURLToPath ( url ) ) ;
119115 }
0 commit comments