Skip to content

Commit

Permalink
cwd option overrides projectName option
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Jul 11, 2016
1 parent c432292 commit 622f648
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Conf {
const pkgPath = pkgUp.sync(parentDir);
opts = Object.assign({projectName: require(pkgPath).name}, opts);

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

Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ Default: System default [user config directory](https://github.com/sindresorhus/

**You most likely don't need this.**

Overrides `projectName`.

The only use-case I can think of is having the config located in the app directory or on some external storage.

### Instance
Expand Down
15 changes: 15 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,18 @@ test('automatic `projectName` inference', t => {
t.true(conf.path.includes('conf'));
del.sync(conf.path, {force: true});
});

test.only('`cwd` option overrides `projectName` option', t => {
const cwd = tempfile();

let conf;
t.notThrows(() => {
conf = new Conf({cwd, projectName: ''});
});

t.true(conf.path.startsWith(cwd));
t.is(conf.get('foo'), undefined);
conf.set('foo', fixture);
t.is(conf.get('foo'), fixture);
del.sync(conf.path, {force: true});
});

0 comments on commit 622f648

Please sign in to comment.