diff --git a/index.js b/index.js index f792b91..98ad806 100644 --- a/index.js +++ b/index.js @@ -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.'); } diff --git a/readme.md b/readme.md index be5ebfa..af39600 100644 --- a/readme.md +++ b/readme.md @@ -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 diff --git a/test.js b/test.js index d96d027..d2b1870 100644 --- a/test.js +++ b/test.js @@ -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}); +});