Skip to content

Commit

Permalink
Choose regex expression to replace require line based on whether stri…
Browse files Browse the repository at this point in the history
…ct flag used
  • Loading branch information
CallumNZ committed Apr 14, 2023
1 parent 3b465ce commit e5bdbb8
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions tasks/partial_bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit e5bdbb8

Please sign in to comment.