@@ -79,7 +79,13 @@ const {
79
79
maybeCacheSourceMap,
80
80
} = require ( 'internal/source_map/source_map_cache' ) ;
81
81
const { pathToFileURL, fileURLToPath, isURLInstance } = require ( 'internal/url' ) ;
82
- const { deprecate, kEmptyObject, filterOwnProperties, setOwnProperty } = require ( 'internal/util' ) ;
82
+ const {
83
+ deprecate,
84
+ emitExperimentalWarning,
85
+ kEmptyObject,
86
+ filterOwnProperties,
87
+ setOwnProperty,
88
+ } = require ( 'internal/util' ) ;
83
89
const vm = require ( 'vm' ) ;
84
90
const assert = require ( 'internal/assert' ) ;
85
91
const fs = require ( 'fs' ) ;
@@ -163,6 +169,18 @@ function stat(filename) {
163
169
return result ;
164
170
}
165
171
172
+ let _stat = stat ;
173
+ ObjectDefineProperty ( Module , '_stat' , {
174
+ __proto__ : null ,
175
+ get ( ) { return _stat ; } ,
176
+ set ( stat ) {
177
+ emitExperimentalWarning ( 'Module._stat' ) ;
178
+ _stat = stat ;
179
+ return true ;
180
+ } ,
181
+ configurable : true ,
182
+ } ) ;
183
+
166
184
function updateChildren ( parent , child , scan ) {
167
185
const children = parent ?. children ;
168
186
if ( children && ! ( scan && ArrayPrototypeIncludes ( children , child ) ) )
@@ -335,6 +353,18 @@ function readPackage(requestPath) {
335
353
}
336
354
}
337
355
356
+ let _readPackage = readPackage ;
357
+ ObjectDefineProperty ( Module , '_readPackage' , {
358
+ __proto__ : null ,
359
+ get ( ) { return _readPackage ; } ,
360
+ set ( readPackage ) {
361
+ emitExperimentalWarning ( 'Module._readPackage' ) ;
362
+ _readPackage = readPackage ;
363
+ return true ;
364
+ } ,
365
+ configurable : true ,
366
+ } ) ;
367
+
338
368
function readPackageScope ( checkPath ) {
339
369
const rootSeparatorIndex = StringPrototypeIndexOf ( checkPath , sep ) ;
340
370
let separatorIndex ;
@@ -343,7 +373,7 @@ function readPackageScope(checkPath) {
343
373
checkPath = StringPrototypeSlice ( checkPath , 0 , separatorIndex ) ;
344
374
if ( StringPrototypeEndsWith ( checkPath , sep + 'node_modules' ) )
345
375
return false ;
346
- const pjson = readPackage ( checkPath + sep ) ;
376
+ const pjson = _readPackage ( checkPath + sep ) ;
347
377
if ( pjson ) return {
348
378
data : pjson ,
349
379
path : checkPath ,
@@ -353,7 +383,7 @@ function readPackageScope(checkPath) {
353
383
}
354
384
355
385
function tryPackage ( requestPath , exts , isMain , originalPath ) {
356
- const pkg = readPackage ( requestPath ) ?. main ;
386
+ const pkg = _readPackage ( requestPath ) ?. main ;
357
387
358
388
if ( ! pkg ) {
359
389
return tryExtensions ( path . resolve ( requestPath , 'index' ) , exts , isMain ) ;
@@ -399,7 +429,7 @@ const realpathCache = new SafeMap();
399
429
// keep symlinks intact, otherwise resolve to the
400
430
// absolute realpath.
401
431
function tryFile ( requestPath , isMain ) {
402
- const rc = stat ( requestPath ) ;
432
+ const rc = _stat ( requestPath ) ;
403
433
if ( rc !== 0 ) return ;
404
434
if ( preserveSymlinks && ! isMain ) {
405
435
return path . resolve ( requestPath ) ;
@@ -493,7 +523,7 @@ function resolveExports(nmPath, request) {
493
523
if ( ! name )
494
524
return ;
495
525
const pkgPath = path . resolve ( nmPath , name ) ;
496
- const pkg = readPackage ( pkgPath ) ;
526
+ const pkg = _readPackage ( pkgPath ) ;
497
527
if ( pkg ?. exports != null ) {
498
528
try {
499
529
return finalizeEsmResolution ( packageExportsResolve (
@@ -533,7 +563,7 @@ Module._findPath = function(request, paths, isMain) {
533
563
for ( let i = 0 ; i < paths . length ; i ++ ) {
534
564
// Don't search further if path doesn't exist
535
565
const curPath = paths [ i ] ;
536
- if ( curPath && stat ( curPath ) < 1 ) continue ;
566
+ if ( curPath && _stat ( curPath ) < 1 ) continue ;
537
567
538
568
if ( ! absoluteRequest ) {
539
569
const exportsResolved = resolveExports ( curPath , request ) ;
@@ -544,7 +574,7 @@ Module._findPath = function(request, paths, isMain) {
544
574
const basePath = path . resolve ( curPath , request ) ;
545
575
let filename ;
546
576
547
- const rc = stat ( basePath ) ;
577
+ const rc = _stat ( basePath ) ;
548
578
if ( ! trailingSlash ) {
549
579
if ( rc === 0 ) { // File.
550
580
if ( ! isMain ) {
0 commit comments