detective icon indicating copy to clipboard operation
detective copied to clipboard

ignore require() calls inside already browserified bundles

Open goto-bus-stop opened this issue 7 years ago • 5 comments

If a function expression declares a require parameter, its body is not analyzed for require() calls. This is mostly helpful for bundles that were already browserified, detective will ignore the calls to browser-pack's require runtime.

Doing full scope analysis using scope-analyzer would slow things down by at least about 30%; this patch however has no measurable performance hit and addresses the most common case of how require might end up redefined.

Fixes https://github.com/browserify/browserify/issues/1773#event-1490701098

goto-bus-stop avatar Feb 13 '18 12:02 goto-bus-stop

Will do this for browserify 17 if there are no complaints by then

goto-bus-stop avatar Apr 11 '18 12:04 goto-bus-stop

What happens if someone has unbrowserified code that has a function argument named “require”?

ljharb avatar Apr 11 '18 14:04 ljharb

calls to that argument would not be collected as dependencies of the file. I considered that but thought that it would be very rare. But the check could be tightened further to check for the full {id:[function(require){},{}]} pattern at fairly little cost.

goto-bus-stop avatar Apr 11 '18 15:04 goto-bus-stop

I think making it as strict as possible is a good idea, just in case. People may have even copy pasted browserify preambles into their code, and it’d be good to maximize what works.

ljharb avatar Apr 11 '18 15:04 ljharb

Did this ever land? Asking for https://github.com/browserify/browserify/issues/1817

NHQ avatar Mar 18 '22 03:03 NHQ