summaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/node_modules/require-uncached/index.js
blob: 63dfada3ecbd756c1e54450a05cf0056ddefa7e6 (plain)
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
29
'use strict';
var path = require('path');
var resolveFrom = require('resolve-from');
var callerPath = require('caller-path');

module.exports = function (moduleId) {
	if (typeof moduleId !== 'string') {
		throw new TypeError('Expected a string');
	}

	var filePath = resolveFrom(path.dirname(callerPath()), moduleId);

	// delete itself from module parent
	if (require.cache[filePath] && require.cache[filePath].parent) {
		var 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);
};