summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/import-fresh/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'tools/node_modules/eslint/node_modules/import-fresh/index.js')
-rw-r--r--tools/node_modules/eslint/node_modules/import-fresh/index.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/node_modules/eslint/node_modules/import-fresh/index.js b/tools/node_modules/eslint/node_modules/import-fresh/index.js
new file mode 100644
index 0000000000..7abc670619
--- /dev/null
+++ b/tools/node_modules/eslint/node_modules/import-fresh/index.js
@@ -0,0 +1,29 @@
+'use strict';
+const path = require('path');
+const resolveFrom = require('resolve-from');
+const parentModule = require('parent-module');
+
+module.exports = moduleId => {
+ if (typeof moduleId !== 'string') {
+ throw new TypeError('Expected a string');
+ }
+
+ const filePath = resolveFrom(path.dirname(parentModule(__filename)), moduleId);
+
+ // Delete itself from module parent
+ if (require.cache[filePath] && require.cache[filePath].parent) {
+ let i = require.cache[filePath].parent.children.length;
+
+ while (i--) {
+ if (require.cache[filePath].parent.children[i].id === filePath) {
+ require.cache[filePath].parent.children.splice(i, 1);
+ }
+ }
+ }
+
+ // Delete module from cache
+ delete require.cache[filePath];
+
+ // Return fresh module
+ return require(filePath);
+};