diff --git a/index.js b/index.js index ebdccab..52dc976 100644 --- a/index.js +++ b/index.js @@ -22,7 +22,10 @@ class Configstore { path.join('configstore', `${id}.json`); this.path = opts.configPath || path.join(configDir, pathPrefix); - this.all = Object.assign({}, defaults, this.all); + + if (defaults) { + this.all = Object.assign({}, defaults, this.all); + } } get all() { @@ -31,7 +34,6 @@ class Configstore { } catch (err) { // Create dir if it doesn't exist if (err.code === 'ENOENT') { - makeDir.sync(path.dirname(this.path), makeDirOptions); return {}; } diff --git a/test.js b/test.js index 07df43b..c459d9a 100644 --- a/test.js +++ b/test.js @@ -7,7 +7,7 @@ import Configstore from '.'; const configstorePath = new Configstore('configstore-test').path; test.beforeEach(t => { - fs.unlinkSync(configstorePath); + cleanUpFile(); t.context.conf = new Configstore('configstore-test'); }); @@ -118,6 +118,20 @@ test('support `configPath` option', t => { }); test('ensure `.all` is always an object', t => { - fs.unlinkSync(configstorePath); + cleanUpFile(); t.notThrows(() => t.context.conf.get('foo')); }); + +test('the store is NOT created until write', t => { + cleanUpFile(); + const conf = new Configstore('configstore-test'); + t.false(fs.existsSync(conf.path)); + conf.set('foo', 'bar'); + t.true(fs.existsSync(conf.path)); +}); + +function cleanUpFile() { + if (fs.existsSync(configstorePath)) { + fs.unlinkSync(configstorePath); + } +}