Skip to content

Commit

Permalink
Drop unique-string dependency (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
fregante committed Jul 13, 2024
1 parent d1b5dbc commit 6985be5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
18 changes: 11 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ import fs from 'graceful-fs';
import {xdgConfig} from 'xdg-basedir';
import {writeFileSync} from 'atomically';
import dotProp from 'dot-prop';
import uniqueString from 'unique-string';

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

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

return path.join(configDirectory, pathPrefix);
}

const permissionError = 'You don\'t have access to this file.';
const mkdirOptions = {mode: 0o0700, recursive: true};
const writeFileOptions = {mode: 0o0600};

export default class Configstore {
constructor(id, defaults, options = {}) {
const pathPrefix = options.globalConfigPath ?
path.join(id, 'config.json') :
path.join('configstore', `${id}.json`);

this._path = options.configPath || path.join(configDirectory, pathPrefix);
this._path = options.configPath ?? getConfigDirectory(id, options.globalConfigPath);

if (defaults) {
this.all = {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"atomically": "^2.0.3",
"dot-prop": "^6.0.1",
"graceful-fs": "^4.2.6",
"unique-string": "^3.0.0",
"xdg-basedir": "^5.0.1"
},
"devDependencies": {
Expand Down

0 comments on commit 6985be5

Please sign in to comment.