@@ -63,15 +63,20 @@ const realpathCache = new SafeMap();
6363let _loaderStat = null ;
6464let _loaderReadFile = null ;
6565let _loaderRealpath = null ;
66+ let _loaderLegacyMainResolve = null ;
67+ let _loaderGetFormatOfExtensionlessFile = null ;
6668
6769/**
6870 * Set override functions for the module loader's fs operations.
69- * @param {{ stat?: Function, readFile?: Function, realpath?: Function } } overrides
71+ * @param {{ stat?: Function, readFile?: Function, realpath?: Function,
72+ * legacyMainResolve?: Function, getFormatOfExtensionlessFile?: Function }} overrides
7073 */
71- function setLoaderFsOverrides ( { stat, readFile, realpath } ) {
74+ function setLoaderFsOverrides ( { stat, readFile, realpath, legacyMainResolve , getFormatOfExtensionlessFile } ) {
7275 _loaderStat = stat ;
7376 _loaderReadFile = readFile ;
7477 _loaderRealpath = realpath ;
78+ _loaderLegacyMainResolve = legacyMainResolve ;
79+ _loaderGetFormatOfExtensionlessFile = getFormatOfExtensionlessFile ;
7580}
7681
7782/**
@@ -113,6 +118,34 @@ function toRealPath(requestPath) {
113118 } ) ;
114119}
115120
121+ /**
122+ * Wrapper for internalBinding('fs').legacyMainResolve that supports VFS toggle.
123+ * @param {string } pkgPath The package directory path
124+ * @param {string } main The package main field
125+ * @param {string } base The base URL string
126+ * @returns {number }
127+ */
128+ function loaderLegacyMainResolve ( pkgPath , main , base ) {
129+ if ( _loaderLegacyMainResolve !== null ) {
130+ const result = _loaderLegacyMainResolve ( pkgPath , main , base ) ;
131+ if ( result !== undefined ) { return result ; }
132+ }
133+ return internalFsBinding . legacyMainResolve ( pkgPath , main , base ) ;
134+ }
135+
136+ /**
137+ * Wrapper for internalBinding('fs').getFormatOfExtensionlessFile that supports VFS toggle.
138+ * @param {string } path The file path
139+ * @returns {number }
140+ */
141+ function loaderGetFormatOfExtensionlessFile ( path ) {
142+ if ( _loaderGetFormatOfExtensionlessFile !== null ) {
143+ const result = _loaderGetFormatOfExtensionlessFile ( path ) ;
144+ if ( result !== undefined ) { return result ; }
145+ }
146+ return internalFsBinding . getFormatOfExtensionlessFile ( path ) ;
147+ }
148+
116149// Toggleable overrides for package.json C++ methods (VFS support).
117150let _loaderReadPackageJSON = null ;
118151let _loaderGetNearestParentPackageJSON = null ;
@@ -643,9 +676,11 @@ module.exports = {
643676 getCjsConditionsArray,
644677 getCompileCacheDir,
645678 initializeCjsConditions,
679+ loaderGetFormatOfExtensionlessFile,
646680 loaderGetNearestParentPackageJSON,
647681 loaderGetPackageScopeConfig,
648682 loaderGetPackageType,
683+ loaderLegacyMainResolve,
649684 loaderReadFile,
650685 loaderReadPackageJSON,
651686 loaderStat,
0 commit comments