Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
feat(nodejs-base): do not hook require when not necessary (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Marton authored and mayurkale22 committed Jul 3, 2019
1 parent 1f57125 commit 69dddde
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,18 @@ export class PluginLoader {
*/
loadPlugins(pluginList: PluginNames) {
if (this.hookState === HookState.UNINITIALIZED) {
hook(Object.keys(pluginList), (exports, name, basedir) => {
const modulesToHook = Object.keys(pluginList);

// Do not hook require when no module is provided. In this case it is
// not necessary. With skipping this step we lower our footprint in
// customer applications and require-in-the-middle won't show up in CPU
// frames.
if (modulesToHook.length === 0) {
this.hookState = HookState.DISABLED;
return;
}

hook(modulesToHook, (exports, name, basedir) => {
if (this.hookState !== HookState.ENABLED) {
return exports;
}
Expand Down

0 comments on commit 69dddde

Please sign in to comment.