configstore
Advanced tools
Comparing version 6.0.0 to 7.0.0
47
index.js
@@ -1,10 +0,23 @@ | ||
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 writeFileAtomic from 'write-file-atomic'; | ||
import dotProp from 'dot-prop'; | ||
import uniqueString from 'unique-string'; | ||
import {writeFileSync} from 'atomically'; | ||
import { | ||
getProperty, | ||
setProperty, | ||
hasProperty, | ||
deleteProperty, | ||
} from 'dot-prop'; | ||
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.'; | ||
@@ -16,12 +29,8 @@ const mkdirOptions = {mode: 0o0700, recursive: true}; | ||
constructor(id, defaults, options = {}) { | ||
const pathPrefix = options.globalConfigPath ? | ||
path.join(id, 'config.json') : | ||
path.join('configstore', `${id}.json`); | ||
this._path = options.configPath ?? getConfigDirectory(id, options.globalConfigPath); | ||
this._path = options.configPath || path.join(configDirectory, pathPrefix); | ||
if (defaults) { | ||
this.all = { | ||
...defaults, | ||
...this.all | ||
...this.all, | ||
}; | ||
@@ -47,3 +56,3 @@ } | ||
if (error.name === 'SyntaxError') { | ||
writeFileAtomic.sync(this._path, '', writeFileOptions); | ||
writeFileSync(this._path, '', writeFileOptions); | ||
return {}; | ||
@@ -61,3 +70,3 @@ } | ||
writeFileAtomic.sync(this._path, JSON.stringify(value, undefined, '\t'), writeFileOptions); | ||
writeFileSync(this._path, JSON.stringify(value, undefined, '\t'), writeFileOptions); | ||
} catch (error) { | ||
@@ -78,3 +87,3 @@ // Improve the message of permission errors | ||
get(key) { | ||
return dotProp.get(this.all, key); | ||
return getProperty(this.all, key); | ||
} | ||
@@ -87,6 +96,6 @@ | ||
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); | ||
} | ||
@@ -98,3 +107,3 @@ | ||
has(key) { | ||
return dotProp.has(this.all, key); | ||
return hasProperty(this.all, key); | ||
} | ||
@@ -104,3 +113,3 @@ | ||
const config = this.all; | ||
dotProp.delete(config, key); | ||
deleteProperty(config, key); | ||
this.all = config; | ||
@@ -107,0 +116,0 @@ } |
{ | ||
"name": "configstore", | ||
"version": "6.0.0", | ||
"version": "7.0.0", | ||
"description": "Easily load and save config without having to think about where and how", | ||
@@ -15,4 +15,5 @@ "license": "BSD-2-Clause", | ||
"exports": "./index.js", | ||
"sideEffects": false, | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=18" | ||
}, | ||
@@ -39,11 +40,10 @@ "scripts": { | ||
"dependencies": { | ||
"dot-prop": "^6.0.1", | ||
"graceful-fs": "^4.2.6", | ||
"unique-string": "^3.0.0", | ||
"write-file-atomic": "^3.0.3", | ||
"xdg-basedir": "^5.0.1" | ||
"atomically": "^2.0.3", | ||
"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" | ||
}, | ||
@@ -50,0 +50,0 @@ "ava": { |
@@ -13,5 +13,5 @@ # configstore | ||
```sh | ||
npm install configstore | ||
``` | ||
$ npm install configstore | ||
``` | ||
@@ -21,2 +21,3 @@ ## Usage | ||
```js | ||
import fs from 'node:fs'; | ||
import Configstore from 'configstore'; | ||
@@ -129,13 +130,1 @@ | ||
``` | ||
--- | ||
<div align="center"> | ||
<b> | ||
<a href="https://tidelift.com/subscription/pkg/npm-configstore?utm_source=npm-configstore&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a> | ||
</b> | ||
<br> | ||
<sub> | ||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. | ||
</sub> | ||
</div> |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4
96
7277
128
+ Addedatomically@^2.0.3
+ Addedatomically@2.0.3(transitive)
+ Addeddot-prop@9.0.0(transitive)
+ Addedstubborn-fs@1.2.5(transitive)
+ Addedtype-fest@4.26.1(transitive)
+ Addedwhen-exit@2.1.3(transitive)
- Removedunique-string@^3.0.0
- Removedwrite-file-atomic@^3.0.3
- Removedcrypto-random-string@4.0.0(transitive)
- Removeddot-prop@6.0.1(transitive)
- Removedimurmurhash@0.1.4(transitive)
- Removedis-obj@2.0.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedsignal-exit@3.0.7(transitive)
- Removedtype-fest@1.4.0(transitive)
- Removedtypedarray-to-buffer@3.1.5(transitive)
- Removedunique-string@3.0.0(transitive)
- Removedwrite-file-atomic@3.0.3(transitive)
Updateddot-prop@^9.0.0
Updatedgraceful-fs@^4.2.11
Updatedxdg-basedir@^5.1.0