Skip to content

Commit a4e1648

Browse files
committed
ensure disabled hook fn remains disabled when subsequent hook is installed on top if it
1 parent a0fdd9b commit a4e1648

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

source-map-support.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,12 @@ var sharedData = initializeSharedData({
7777
errorPrepareStackTraceHook: undefined,
7878
/** @type {HookState} */
7979
processEmitHook: undefined,
80-
/** @type {HookState & { onConflictingLibraryRedirectArr: Array<(request: string, parent: any, isMain: boolean, redirectedRequest: string) => void> }} */
80+
/** @type {HookState} */
8181
moduleResolveFilenameHook: undefined,
8282

83+
/** @type {Array<(request: string, parent: any, isMain: boolean, redirectedRequest: string) => void>} */
84+
onConflictingLibraryRedirectArr: [],
85+
8386
// If true, the caches are reset before a stack trace formatting operation
8487
emptyCacheBetweenOperations: false,
8588

@@ -644,14 +647,13 @@ exports.install = function(options) {
644647
if(redirectConflictingLibrary) {
645648
if (!sharedData.moduleResolveFilenameHook) {
646649
const originalValue = Module._resolveFilename;
647-
sharedData.moduleResolveFilenameHook = {
650+
const moduleResolveFilenameHook = sharedData.moduleResolveFilenameHook = {
648651
enabled: true,
649652
originalValue,
650653
installedValue: undefined,
651-
onConflictingLibraryRedirectArr: []
652654
}
653655
Module._resolveFilename = sharedData.moduleResolveFilenameHook.installedValue = function (request, parent, isMain, options) {
654-
if (sharedData.moduleResolveFilenameHook && sharedData.moduleResolveFilenameHook.enabled) {
656+
if (moduleResolveFilenameHook.enabled) {
655657
// Match all source-map-support entrypoints: source-map-support, source-map-support/register
656658
let requestRedirect;
657659
if (request === 'source-map-support') {
@@ -662,7 +664,7 @@ exports.install = function(options) {
662664

663665
if (requestRedirect !== undefined) {
664666
const newRequest = require.resolve(requestRedirect);
665-
for (const cb of sharedData.moduleResolveFilenameHook.onConflictingLibraryRedirectArr) {
667+
for (const cb of sharedData.onConflictingLibraryRedirectArr) {
666668
cb(request, parent, isMain, options, newRequest);
667669
}
668670
request = newRequest;
@@ -673,7 +675,7 @@ exports.install = function(options) {
673675
}
674676
}
675677
if (onConflictingLibraryRedirect) {
676-
sharedData.moduleResolveFilenameHook.onConflictingLibraryRedirectArr.push(onConflictingLibraryRedirect);
678+
sharedData.onConflictingLibraryRedirectArr.push(onConflictingLibraryRedirect);
677679
}
678680
}
679681

@@ -790,6 +792,7 @@ exports.uninstall = function() {
790792
}
791793
sharedData.moduleResolveFilenameHook = undefined;
792794
}
795+
sharedData.onConflictingLibraryRedirectArr.length = 0;
793796
}
794797

795798
exports.resetRetrieveHandlers = function() {

0 commit comments

Comments
 (0)