UNPKG

602 BJavaScriptView Raw
1const fs = require('fs-extra');
2const path = require('path');
3const resolve = require('resolve');
4const getCwd = require('./get-cwd');
5
6/**
7 * 获取指定 module 在硬盘中的所在目录
8 * @param {string} moduleId
9 * @returns {string}
10 */
11module.exports = moduleId => {
12 let file;
13 try {
14 file = resolve.sync('koot', { basedir: getCwd() });
15 } catch (e) {
16 file = resolve.sync('koot', { basedir: __dirname });
17 }
18
19 if (!file || !fs.existsSync(file))
20 throw new Error(`Module "${moduleId}" not found!`);
21
22 return path.dirname(file);
23};