aboutsummaryrefslogtreecommitdiff
path: root/node_modules/time-require/src/requireHook.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-03-27 21:01:33 +0100
committerFlorian Dold <florian.dold@gmail.com>2019-03-27 21:01:33 +0100
commitcc97a4dd2a967e1c2273bd5f4c5f49a5bf2e2585 (patch)
tree92c5d88706a6ffc654d1b133618d357890e7096b /node_modules/time-require/src/requireHook.js
parent3771b4d6b67b34c130f3a9a1a15f42deefdb2eda (diff)
remove node_modules
Diffstat (limited to 'node_modules/time-require/src/requireHook.js')
-rw-r--r--node_modules/time-require/src/requireHook.js93
1 files changed, 0 insertions, 93 deletions
diff --git a/node_modules/time-require/src/requireHook.js b/node_modules/time-require/src/requireHook.js
deleted file mode 100644
index ebafbb603..000000000
--- a/node_modules/time-require/src/requireHook.js
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * requireHook - module wrapping a function that register require() listener and returns hook/unhook control
- *
- * @author Ciprian Popa (cyparu)
- * @since 0.0.1
- * @version 0.0.1
- */
-
-"use strict";
-
-var Module = require("module").Module,
- _load = Module._load,
- _hookedAt, _listener;
-
-/**
- * Module hooker function that will replace Module._load and invoke the _listener with module and timing information
- *
- * @function _hooker
- */
-function _hooker(name, parent) {
- var timeIn = Date.now(),
- exports = _load.apply(Module, arguments),
- timeOut = Date.now(),
- mod = parent.children[parent.children.length - 1]; // should be the last loaded children
- // call the listener
- _listener({
- name: name,
- parent: parent,
- module: mod,
- filename: mod ? mod.filename : name,
- exports: exports,
- requiredOn: timeIn,
- startedIn: timeOut - timeIn
- });
- return exports;
-}
-
-/**
- * Hook Node's require() so the configured callback will be invocked with additional module and time loading information information
- *
- * @param {Function} [listener] - optional listener if
- * @method hook
- */
-function _hook(listener) {
- if (typeof listener !== "undefined") {
- if (typeof listener !== "function") {
- throw new Error("The optional parameter for hook() should be a function but was " + (typeof listener));
- }
- // set the listener
- _listener = listener;
- }
- // set the hoocker loader
- Module._load = _hooker;
- // mark hooked time
- _hookedAt = new Date();
-}
-
-/**
- * Unhook Node's require() to the original function
- *
- * @method unhook
- */
-function _unhook() {
- // set the original loader
- Module._load = _load;
- // reset hooking time
- _hookedAt = undefined;
-}
-
-/**
- * Export a function that set the callback and return hook/unhook control functionality
- *
- * @function
- * @param {Function} listener - require() listener
- * @param {Boolean} [autohook=true] - optional flag telling if the hooking will be started automatically
- * @return hook/unhook control function
- */
-module.exports = function(listener, autohook) {
- if (typeof listener !== "function") {
- throw new Error("The hooking function should be set");
- }
- // set the listener
- _listener = listener;
- // if autohook (by default),
- if (autohook !== false) {
- _hook();
- }
- return {
- hookedAt: _hookedAt,
- hook: _hook,
- unhook: _unhook
- };
-};