Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies #95

Merged
merged 9 commits into from
Jul 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import path from 'path';
import os from 'os';
import path from 'node:path';
import os from 'node:os';
import fs from 'graceful-fs';
import {xdgConfig} from 'xdg-basedir';
import {writeFileSync} from 'atomically';
import dotProp from 'dot-prop';
import {
getProperty,
setProperty,
hasProperty,
deleteProperty,
} from 'dot-prop';

function getConfigDirectory(id, globalConfigPath) {
const pathPrefix = globalConfigPath ?
path.join(id, 'config.json') :
path.join('configstore', `${id}.json`);
const pathPrefix = globalConfigPath
? path.join(id, 'config.json')
: path.join('configstore', `${id}.json`);

const configDirectory = xdgConfig || fs.mkdtempSync(fs.realpathSync(os.tmpdir()) + path.sep);
const configDirectory = xdgConfig ?? fs.mkdtempSync(fs.realpathSync(os.tmpdir()) + path.sep);

return path.join(configDirectory, pathPrefix);
}
Expand All @@ -26,7 +31,7 @@ export default class Configstore {
if (defaults) {
this.all = {
...defaults,
...this.all
...this.all,
};
}
}
Expand Down Expand Up @@ -76,30 +81,30 @@ export default class Configstore {
}

get(key) {
return dotProp.get(this.all, key);
return getProperty(this.all, key);
}

set(key, value) {
const config = this.all;

if (arguments.length === 1) {
for (const k of Object.keys(key)) {
dotProp.set(config, k, key[k]);
setProperty(config, k, key[k]);
}
} else {
dotProp.set(config, key, value);
setProperty(config, key, value);
}

this.all = config;
}

has(key) {
return dotProp.has(this.all, key);
return hasProperty(this.all, key);
}

delete(key) {
const config = this.all;
dotProp.delete(config, key);
deleteProperty(config, key);
this.all = config;
}

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@
],
"dependencies": {
"atomically": "^2.0.3",
"dot-prop": "^6.0.1",
"graceful-fs": "^4.2.6",
"xdg-basedir": "^5.0.1"
"dot-prop": "^9.0.0",
"graceful-fs": "^4.2.11",
"xdg-basedir": "^5.1.0"
},
"devDependencies": {
"ava": "^3.15.0",
"xo": "^0.38.2"
"ava": "^6.1.3",
"xo": "^0.58.0"
},
"ava": {
"serial": true
Expand Down
20 changes: 10 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs';
import path from 'path';
import os from 'os';
import fs from 'node:fs';
import path from 'node:path';
import os from 'node:os';
import test from 'ava';
import Configstore from './index.js';

Expand Down Expand Up @@ -33,17 +33,17 @@ test('.set() with object and .get()', t => {
baz: {
boo: 'foo',
foo: {
bar: 'baz'
}
}
bar: 'baz',
},
},
});
t.is(config.get('foo1'), 'bar1');
t.is(config.get('foo2'), 'bar2');
t.deepEqual(config.get('baz'), {
boo: 'foo',
foo: {
bar: 'baz'
}
bar: 'baz',
},
});
t.is(config.get('baz.boo'), 'foo');
t.deepEqual(config.get('baz.foo'), {bar: 'baz'});
Expand Down Expand Up @@ -119,7 +119,7 @@ test('support `configPath` option', t => {
const customPath = path.join(os.tmpdir(), 'configstore-custom-path', 'foo.json');
const config = new Configstore('ignored-namespace', {}, {
globalConfigPath: true,
configPath: customPath
configPath: customPath,
});
t.regex(config.path, /configstore-custom-path(\/|\\)foo.json$/);
});
Expand All @@ -144,7 +144,7 @@ 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
configPath: customPath,
});
t.false(fs.existsSync(config.path));
config.set('foo', 'bar');
Expand Down