Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

app-conf

Package Overview
Dependencies
Maintainers
3
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

app-conf - npm Package Compare versions

Comparing version 0.8.0 to 0.9.0

14

entries.js

@@ -46,3 +46,4 @@ "use strict";

name: "vendor",
read: opts => pMap(glob(j(opts.appDir, "config.*")), readFile),
dir: opts => opts.appDir,
read: (_, dir) => pMap(glob(j(dir, "config.*")), readFile),
},

@@ -53,3 +54,4 @@

name: "system",
read: opts => pMap(glob(j("/etc", opts.appName, "config.*")), readFile),
dir: opts => j("/etc", opts.appName),
read: (_, dir) => pMap(glob(j(dir, "config.*")), readFile),
},

@@ -60,8 +62,8 @@

name: "global",
read: opts => {
dir: opts => {
const configDir = xdgBasedir.config;
return configDir === undefined
? []
: pMap(glob(j(configDir, opts.appName, "config.*")), readFile);
return configDir && j(configDir, opts.appName);
},
read: (_, dir) =>
dir === undefined ? [] : pMap(glob(j(dir, "config.*")), readFile),
},

@@ -68,0 +70,0 @@

@@ -5,2 +5,3 @@ "use strict";

const chokidar = require("chokidar");
const dirname = require("path").dirname;

@@ -65,7 +66,12 @@ const homedir = require("os").homedir;

}
return pMap(entries, entry =>
useWhitelist && !whitelist.has(entry.name)
? []
: entry.read({ appDir, appName })
)
const entryOpts = { appDir, appName };
return pMap(entries, entry => {
if (useWhitelist && !whitelist.has(entry.name)) {
return [];
}
const dirFn = entry.dir;
const dir = typeof dirFn === "function" ? dirFn(entryOpts) : dirFn;
return entry.read(entryOpts, dir);
})
.then(files => {

@@ -94,5 +100,43 @@ files = flatten(files);

}
exports.load = load;
// ===================================================================
exports.load = load;
exports.watch = function watch({ appName, ...opts }, cb) {
return new Promise((resolve, reject) => {
const { appDir } = opts;
if (appDir === undefined) {
throw new TypeError("appDir must be defined");
}
const dirs = [];
const entryOpts = { appName, appDir };
entries.forEach(entry => {
const dirFn = entry.dir;
const dir = typeof dirFn === "function" ? dirFn(entryOpts) : dirFn;
if (dir !== undefined) {
dirs.push(dir);
}
});
const watcher = chokidar.watch(dirs, {
depth: 0,
ignoreInitial: true,
ignorePermissionErrors: true,
});
const loadWrapper = () => {
load(appName, opts).then(config => cb(undefined, config), cb);
};
watcher
.on("all", loadWrapper)
.once("error", reject)
.once("ready", (...args) => {
loadWrapper();
resolve(function unsubscribe() {
return watcher.close();
});
});
});
};
{
"name": "app-conf",
"version": "0.8.0",
"version": "0.9.0",
"license": "ISC",

@@ -22,5 +22,6 @@ "author": "Julien Fontanet <julien.fontanet@isonoe.net> (http://julien.isonoe.net/)",

"engines": {
"node": ">=6"
"node": ">=8.10"
},
"dependencies": {
"chokidar": "^3.5.1",
"debug": "^4.1.0",

@@ -30,3 +31,3 @@ "glob": "^7.1.3",

"make-error": "^1.3.5",
"promise-toolbox": "^0.14.0",
"promise-toolbox": "^0.16.0",
"xdg-basedir": "^3.0.0"

@@ -33,0 +34,0 @@ },

@@ -54,2 +54,34 @@ # app-conf

### `watch(opts, cb)`
This method reload the configuration every time it might have changed.
```js
const watchConfig = require("app-conf").watch;
const stopWatching = await watchConfig(
{
// contrary to `load`, this option is required
appDir: __dirname,
// contrary to `load`, this is part of the options
appName: "my-application",
// all other options are passed to load()
},
(error, config) => {
if (error !== undefined) {
console.warn("loading config has failed");
// we might not want to retry on changes
stopWatching();
return;
}
console.log("config has been loaded", config);
}
);
```
## Contributing

@@ -56,0 +88,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc