Skip to content

Commit

Permalink
Replace make-dir with fs.mkdirSync (#76)
Browse files Browse the repository at this point in the history
Co-authored-by: Sindre Sorhus <sindresorhus@gmail.com>
  • Loading branch information
takenspc and sindresorhus committed Apr 5, 2021
1 parent ab81102 commit 5825c70
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 0 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
- 14
- 12
- 10
- 8
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
Expand Down
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
const path = require('path');
const os = require('os');
const fs = require('graceful-fs');
const makeDir = require('make-dir');
const xdgBasedir = require('xdg-basedir');
const writeFileAtomic = require('write-file-atomic');
const dotProp = require('dot-prop');
const uniqueString = require('unique-string');

const configDirectory = xdgBasedir.config || path.join(os.tmpdir(), uniqueString());
const permissionError = 'You don\'t have access to this file.';
const makeDirOptions = {mode: 0o0700};
const mkdirOptions = {mode: 0o0700, recursive: true};
const writeFileOptions = {mode: 0o0600};

class Configstore {
Expand Down Expand Up @@ -56,7 +55,7 @@ class Configstore {
set all(value) {
try {
// Make sure the folder exists as it could have been deleted in the meantime
makeDir.sync(path.dirname(this.path), makeDirOptions);
fs.mkdirSync(path.dirname(this.path), mkdirOptions);

writeFileAtomic.sync(this.path, JSON.stringify(value, undefined, '\t'), writeFileOptions);
} catch (error) {
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"url": "https://sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10.13"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -35,7 +35,6 @@
"dependencies": {
"dot-prop": "^5.2.0",
"graceful-fs": "^4.1.2",
"make-dir": "^3.0.0",
"unique-string": "^2.0.0",
"write-file-atomic": "^3.0.0",
"xdg-basedir": "^4.0.0"
Expand Down
11 changes: 11 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,14 @@ test('the store is NOT created until write', t => {
config.set('foo', 'bar');
t.true(fs.existsSync(config.path));
});

test('ensure necessary sub-directories are created', t => {
const customPath = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'configstore-recursive-')), 'foo', 'bar', 'baz.json');
const config = new Configstore('ignored-namespace', undefined, {
globalConfigPath: true,
configPath: customPath
});
t.false(fs.existsSync(config.path));
config.set('foo', 'bar');
t.true(fs.existsSync(config.path));
});

0 comments on commit 5825c70

Please sign in to comment.