Skip to content

Commit

Permalink
Fix path derivation logic (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
buddydvd authored and sindresorhus committed Apr 1, 2019
1 parent 277d70a commit bb26c4f
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,6 @@ const checkValueType = (key, value) => {

class Conf {
constructor(options) {
const pkgPath = pkgUp.sync(parentDir);

options = {
// Can't use `require` because of Webpack being annoying:
// https://github.com/webpack/webpack/issues/196
projectName: pkgPath && JSON.parse(fs.readFileSync(pkgPath, 'utf8')).name,
...options
};

if (!options.projectName && !options.cwd) {
throw new Error('Project name could not be inferred. Please specify the `projectName` option.');
}

options = {
configName: 'config',
fileExtension: 'json',
Expand All @@ -57,6 +44,17 @@ class Conf {
};

if (!options.cwd) {
if (!options.projectName) {
const pkgPath = pkgUp.sync(parentDir);
// Can't use `require` because of Webpack being annoying:
// https://github.com/webpack/webpack/issues/196
options.projectName = pkgPath && JSON.parse(fs.readFileSync(pkgPath, 'utf8')).name;
}

if (!options.projectName) {
throw new Error('Project name could not be inferred. Please specify the `projectName` option.');
}

options.cwd = envPaths(options.projectName, {suffix: options.projectSuffix}).config;
}

Expand Down

0 comments on commit bb26c4f

Please sign in to comment.