Projekt

Obecné

Profil

Stáhnout (932 Bajtů) Statistiky
| Větev: | Revize:
1
'use strict';
2
const path = require('path');
3
const Module = require('module');
4

    
5
const resolveFrom = (fromDir, moduleId, silent) => {
6
	if (typeof fromDir !== 'string') {
7
		throw new TypeError(`Expected \`fromDir\` to be of type \`string\`, got \`${typeof fromDir}\``);
8
	}
9

    
10
	if (typeof moduleId !== 'string') {
11
		throw new TypeError(`Expected \`moduleId\` to be of type \`string\`, got \`${typeof moduleId}\``);
12
	}
13

    
14
	fromDir = path.resolve(fromDir);
15
	const fromFile = path.join(fromDir, 'noop.js');
16

    
17
	const resolveFileName = () => Module._resolveFilename(moduleId, {
18
		id: fromFile,
19
		filename: fromFile,
20
		paths: Module._nodeModulePaths(fromDir)
21
	});
22

    
23
	if (silent) {
24
		try {
25
			return resolveFileName();
26
		} catch (err) {
27
			return null;
28
		}
29
	}
30

    
31
	return resolveFileName();
32
};
33

    
34
module.exports = (fromDir, moduleId) => resolveFrom(fromDir, moduleId);
35
module.exports.silent = (fromDir, moduleId) => resolveFrom(fromDir, moduleId, true);
(1-1/4)