55 ArrayPrototypeConcat,
66 ArrayPrototypeJoin,
77 ArrayPrototypeShift,
8- JSONParse,
98 JSONStringify,
109 ObjectFreeze,
1110 ObjectGetOwnPropertyNames,
@@ -37,7 +36,7 @@ const { getOptionValue } = require('internal/options');
3736const policy = getOptionValue ( '--experimental-policy' ) ?
3837 require ( 'internal/process/policy' ) :
3938 null ;
40- const { sep, relative, resolve } = require ( 'path' ) ;
39+ const { sep, relative } = require ( 'path' ) ;
4140const preserveSymlinks = getOptionValue ( '--preserve-symlinks' ) ;
4241const preserveSymlinksMain = getOptionValue ( '--preserve-symlinks-main' ) ;
4342const experimentalNetworkImports =
@@ -60,7 +59,6 @@ const {
6059} = require ( 'internal/errors' ) . codes ;
6160
6261const { Module : CJSModule } = require ( 'internal/modules/cjs/loader' ) ;
63- const packageJsonReader = require ( 'internal/modules/package_json_reader' ) ;
6462const { getPackageConfig, getPackageScopeConfig } = require ( 'internal/modules/esm/package_config' ) ;
6563
6664/**
@@ -234,50 +232,6 @@ function legacyMainResolve(packageJSONUrl, packageConfig, base) {
234232 fileURLToPath ( new URL ( '.' , packageJSONUrl ) ) , fileURLToPath ( base ) ) ;
235233}
236234
237- /**
238- * @param {URL } search
239- * @returns {URL | undefined }
240- */
241- function resolveExtensionsWithTryExactName ( search ) {
242- if ( fileExists ( search ) ) return search ;
243- return resolveExtensions ( search ) ;
244- }
245-
246- const extensions = [ '.js' , '.json' , '.node' , '.mjs' ] ;
247-
248- /**
249- * @param {URL } search
250- * @returns {URL | undefined }
251- */
252- function resolveExtensions ( search ) {
253- for ( let i = 0 ; i < extensions . length ; i ++ ) {
254- const extension = extensions [ i ] ;
255- const guess = new URL ( `${ search . pathname } ${ extension } ` , search ) ;
256- if ( fileExists ( guess ) ) return guess ;
257- }
258- return undefined ;
259- }
260-
261- /**
262- * @param {URL } search
263- * @returns {URL | undefined }
264- */
265- function resolveDirectoryEntry ( search ) {
266- const dirPath = fileURLToPath ( search ) ;
267- const pkgJsonPath = resolve ( dirPath , 'package.json' ) ;
268- if ( fileExists ( pkgJsonPath ) ) {
269- const pkgJson = packageJsonReader . read ( pkgJsonPath ) ;
270- if ( pkgJson . containsKeys ) {
271- const { main } = JSONParse ( pkgJson . string ) ;
272- if ( main != null ) {
273- const mainUrl = pathToFileURL ( resolve ( dirPath , main ) ) ;
274- return resolveExtensionsWithTryExactName ( mainUrl ) ;
275- }
276- }
277- }
278- return resolveExtensions ( new URL ( 'index' , search ) ) ;
279- }
280-
281235const encodedSepRegEx = / % 2 F | % 5 C / i;
282236/**
283237 * @param {URL } resolved
@@ -291,25 +245,7 @@ function finalizeResolution(resolved, base, preserveSymlinks) {
291245 resolved . pathname , 'must not include encoded "/" or "\\" characters' ,
292246 fileURLToPath ( base ) ) ;
293247
294- let path = fileURLToPath ( resolved ) ;
295- if ( getOptionValue ( '--experimental-specifier-resolution' ) === 'node' ) {
296- let file = resolveExtensionsWithTryExactName ( resolved ) ;
297-
298- // Directory
299- if ( file === undefined ) {
300- file = StringPrototypeEndsWith ( path , '/' ) ?
301- ( resolveDirectoryEntry ( resolved ) || resolved ) : resolveDirectoryEntry ( new URL ( `${ resolved } /` ) ) ;
302-
303- if ( file === resolved ) return file ;
304-
305- if ( file === undefined ) {
306- throw new ERR_MODULE_NOT_FOUND (
307- resolved . pathname , fileURLToPath ( base ) , 'module' ) ;
308- }
309- }
310-
311- path = file ;
312- }
248+ const path = fileURLToPath ( resolved ) ;
313249
314250 const stats = tryStatSync ( StringPrototypeEndsWith ( path , '/' ) ?
315251 StringPrototypeSlice ( path , - 1 ) : path ) ;
0 commit comments