forked from Jollyfant/node-seedlink-data-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequire.js
More file actions
28 lines (24 loc) · 763 Bytes
/
require.js
File metadata and controls
28 lines (24 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/*
* NodeJS Require Patch
*
* Patches the default require function to support
* relative imports from the root directory
*
* Author: Mathijs Koymans, 2018
* Copyright: ORFEUS Data Center
* License: MIT
*
*/
const path = require("path");
// Capture the require function in a closure
module.constructor.prototype.require = (function(closure) {
// Relative ("./lib/something") or native module (e.g. http)
// Skip all node_modules includes from dependencies
return function(importPath) {
if(!this.filename.includes("node_modules") && importPath.startsWith(".")) {
return closure.call(this, path.join(__dirname, importPath));
} else {
return closure.call(this, importPath);
}
}
})(module.constructor.prototype.require);