Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow global installed configuration
Fixes #1973
  • Loading branch information
ybiquitous committed Sep 7, 2018
1 parent 5512cc2 commit 60bf3b3
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/utils/getModulePath.js
Expand Up @@ -2,18 +2,25 @@
"use strict";

const configurationError = require("./configurationError");
const resolve = require("path").resolve;
const resolveFrom = require("resolve-from");

module.exports = function(
const GLOBAL_NODE_MODULES = resolve(__dirname, "../../../../node_modules/");

module.exports = function getModulePath(
basedir /*: string*/,
lookup /*: string*/
) /*: string*/ {
// First try to resolve from the provided directory,
// then try to resolve from process.cwd.
// 1. Try to resolve from the provided directory
// 2. Try to resolve from `process.cwd`
// 3. Try to resolve from global `node_modules` directory
let path = resolveFrom.silent(basedir, lookup);
if (!path) {
path = resolveFrom.silent(process.cwd(), lookup);
}
if (!path) {
path = resolveFrom.silent(GLOBAL_NODE_MODULES, lookup);
}
if (!path) {
throw configurationError(
`Could not find "${lookup}". Do you need a \`configBasedir\`?`
Expand Down

0 comments on commit 60bf3b3

Please sign in to comment.