From e5bdbb874e0772e55f6a434d42002ceeea112cb2 Mon Sep 17 00:00:00 2001 From: Callum Morris Date: Fri, 14 Apr 2023 12:26:28 +1200 Subject: [PATCH] Choose regex expression to replace require line based on whether strict flag used --- tasks/partial_bundle.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tasks/partial_bundle.js b/tasks/partial_bundle.js index 083ccce5a7c..9fc64ae0ada 100644 --- a/tasks/partial_bundle.js +++ b/tasks/partial_bundle.js @@ -34,13 +34,11 @@ module.exports = function partialBundle(tasks, opts) { excludes.forEach(function(t) { var WHITESPACE_BEFORE = '\\s*'; // remove require - var newCode = partialIndex.replace( - new RegExp( - WHITESPACE_BEFORE + - 'require\\(\'\\./' + t + '\'\\),' + '|' + - 'require\\(\'\\.\\./src/traces/' + t + '/strict\'\\),', - 'g'), '' - ); + const regEx = (strict) ? + WHITESPACE_BEFORE + 'require\\(\'\\.\\./src/traces/' + t + '/strict\'\\),' : + WHITESPACE_BEFORE + 'require\\(\'\\./' + t + '\'\\),'; + + var newCode = partialIndex.replace(new RegExp(regEx, 'g'), ''); // test removal if(newCode === partialIndex) {