@@ -77,6 +77,8 @@ var sharedData = initializeSharedData({
77
77
errorPrepareStackTraceHook : undefined ,
78
78
/** @type {HookState } */
79
79
processEmitHook : undefined ,
80
+ /** @type {HookState } */
81
+ moduleResolveFilenameHook : undefined ,
80
82
81
83
// If true, the caches are reset before a stack trace formatting operation
82
84
emptyCacheBetweenOperations : false ,
@@ -639,9 +641,14 @@ exports.install = function(options) {
639
641
// Redirect subsequent imports of "source-map-support"
640
642
// to this package
641
643
const { redirectConflictingLibrary = true , onConflictingLibraryRedirect} = options ;
642
- if ( redirectConflictingLibrary ) {
643
- const originalResolveFilename = Module . _resolveFilename ;
644
- Module . _resolveFilename = function resolveFilenameProxy ( request , parent , isMain , options ) {
644
+ if ( redirectConflictingLibrary && ! sharedData . moduleResolveFilenameHook ) {
645
+ const originalValue = Module . _resolveFilename ;
646
+ sharedData . moduleResolveFilenameHook = {
647
+ enabled : true ,
648
+ originalValue,
649
+ installedValue : undefined
650
+ }
651
+ Module . _resolveFilename = sharedData . moduleResolveFilenameHook . installedValue = function ( request , parent , isMain , options ) {
645
652
// Match all source-map-support entrypoints: source-map-support, source-map-support/register
646
653
if ( request === 'source-map-support' ) {
647
654
const newRequest = require . resolve ( './' ) ;
@@ -652,7 +659,7 @@ exports.install = function(options) {
652
659
if ( onConflictingLibraryRedirect ) onConflictingLibraryRedirect ( request , parent , isMain , options , newRequest ) ;
653
660
request = newRequest ;
654
661
}
655
- return originalResolveFilename . call ( this , request , parent , isMain , options ) ;
662
+ return originalValue . call ( this , request , parent , isMain , options ) ;
656
663
}
657
664
}
658
665
@@ -759,6 +766,16 @@ exports.uninstall = function() {
759
766
}
760
767
sharedData . errorPrepareStackTraceHook = undefined ;
761
768
}
769
+ if ( sharedData . moduleResolveFilenameHook ) {
770
+ // Disable behavior
771
+ sharedData . moduleResolveFilenameHook . enabled = false ;
772
+ // If possible, remove our hook function. May not be possible if subsequent third-party hooks have wrapped around us.
773
+ var Module = dynamicRequire ( module , 'module' ) ;
774
+ if ( Module . _resolveFilename === sharedData . moduleResolveFilenameHook . installedValue ) {
775
+ Module . _resolveFilename = sharedData . moduleResolveFilenameHook . originalValue ;
776
+ }
777
+ sharedData . moduleResolveFilenameHook = undefined ;
778
+ }
762
779
}
763
780
764
781
exports . resetRetrieveHandlers = function ( ) {
0 commit comments