Comparing version 2.3.0 to 3.0.0
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
module.exports = function merge(target, source) { | ||
@@ -2,0 +4,0 @@ if (source === undefined) { |
@@ -0,1 +1,3 @@ | ||
"use strict"; | ||
module.exports = function pMap(array, iteratee) { | ||
@@ -2,0 +4,0 @@ const { then } = array; |
@@ -31,3 +31,3 @@ #!/usr/bin/env node | ||
sorted: true, | ||
}) | ||
}), | ||
); | ||
@@ -77,3 +77,8 @@ stdout.write("\n"); | ||
const opts = { appDir, appName, ignoreUnknownFormats: true }; | ||
const opts = { | ||
appDir, | ||
appName, | ||
ignoreUnknownFormats: true, | ||
initialLoad: true, | ||
}; | ||
const printPaths = print.bind(undefined, cliOpts.paths); | ||
@@ -80,0 +85,0 @@ |
@@ -89,5 +89,5 @@ "use strict"; | ||
silent: true, | ||
}).catch(ignoreAccessErrors) | ||
}).catch(ignoreAccessErrors), | ||
).then(flatten), | ||
readFile | ||
readFile, | ||
); | ||
@@ -94,0 +94,0 @@ }, |
62
index.js
@@ -24,20 +24,17 @@ "use strict"; | ||
if (typeof value === "string") { | ||
return Promise.resolve( | ||
value[0] === "~" && (value[1] === "/" || value[1] === "\\") | ||
? homedir() + value.slice(1) | ||
: RELATIVE_PATH_RE.test(value) | ||
return value[0] === "~" && (value[1] === "/" || value[1] === "\\") | ||
? homedir() + value.slice(1) | ||
: RELATIVE_PATH_RE.test(value) | ||
? resolvePath(base, value) | ||
: value | ||
); | ||
: value; | ||
} | ||
if (value !== null && typeof value === "object") { | ||
return pMap(Object.keys(value), (key) => | ||
resolvePaths(value[key], base).then((resolved) => { | ||
value[key] = resolved; | ||
}) | ||
).then(() => value); | ||
for (const key of Object.keys(value)) { | ||
value[key] = resolvePaths(value[key], base); | ||
} | ||
return value; | ||
} | ||
return Promise.resolve(value); | ||
return value; | ||
} | ||
@@ -49,3 +46,3 @@ | ||
appName, | ||
{ appDir, defaults, entries: whitelist, ignoreUnknownFormats = false } = {} | ||
{ appDir, defaults, entries: whitelist, ignoreUnknownFormats = false } = {}, | ||
) { | ||
@@ -81,8 +78,11 @@ const useWhitelist = whitelist !== undefined; | ||
.then((data) => | ||
data.reduce((acc, cfg) => { | ||
if (cfg !== undefined) { | ||
merge(acc, cfg); | ||
} | ||
return acc; | ||
}, merge({}, defaults)) | ||
data.reduce( | ||
(acc, cfg) => { | ||
if (cfg !== undefined) { | ||
merge(acc, cfg); | ||
} | ||
return acc; | ||
}, | ||
merge({}, defaults), | ||
), | ||
); | ||
@@ -94,3 +94,3 @@ } | ||
exports.watch = function watch({ appName, ...opts }, cb) { | ||
exports.watch = function watch({ appName, initialLoad = false, ...opts }, cb) { | ||
return new Promise((resolve, reject) => { | ||
@@ -128,9 +128,23 @@ const dirs = []; | ||
.once("error", reject) | ||
.once("ready", (...args) => { | ||
loadWrapper(); | ||
resolve(function unsubscribe() { | ||
.once("ready", () => { | ||
function unsubscribe() { | ||
return watcher.close(); | ||
}); | ||
} | ||
if (initialLoad) { | ||
load(appName, opts).then( | ||
(config) => { | ||
cb(undefined, config); | ||
resolve(unsubscribe); | ||
}, | ||
(error) => { | ||
const rejectOriginal = () => reject(error); | ||
unsubscribe().then(rejectOriginal, rejectOriginal); | ||
}, | ||
); | ||
} else { | ||
resolve(unsubscribe); | ||
} | ||
}); | ||
}); | ||
}; |
{ | ||
"name": "app-conf", | ||
"version": "2.3.0", | ||
"version": "3.0.0", | ||
"license": "ISC", | ||
@@ -25,3 +25,3 @@ "author": "Julien Fontanet <julien.fontanet@isonoe.net> (http://julien.isonoe.net/)", | ||
"engines": { | ||
"node": ">=8.10" | ||
"node": ">=9.9" | ||
}, | ||
@@ -31,3 +31,3 @@ "dependencies": { | ||
"debug": "^4.1.0", | ||
"glob": "^7.1.3", | ||
"glob": "^8.1.0", | ||
"lodash": "^4.17.11", | ||
@@ -39,30 +39,25 @@ "make-error": "^1.3.5", | ||
"devDependencies": { | ||
"eslint": "^8.15.0", | ||
"eslint-config-prettier": "^8.2.0", | ||
"eslint-config-standard": "^17.0.0", | ||
"eslint-plugin-import": "^2.14.0", | ||
"eslint-plugin-n": "^15.2.0", | ||
"eslint-plugin-promise": "^6.0.0", | ||
"husky": "^4", | ||
"lint-staged": "^12", | ||
"mock-fs": "^5.1.2", | ||
"prettier": "^2.2.1", | ||
"rimraf": "^3.0.0", | ||
"tap": "^16.2.0" | ||
"eslint": "^8.57.0", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-config-standard": "^17.1.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-n": "^16.6.2", | ||
"eslint-plugin-promise": "^6.1.1", | ||
"husky": "^9.0.11", | ||
"lint-staged": "^15.2.2", | ||
"mock-fs": "^5.2.0", | ||
"prettier": "^3.2.5", | ||
"test": "^3.3.0" | ||
}, | ||
"scripts": { | ||
"dev-test": "tap --no-check-coverage --watch", | ||
"test": "tap --no-check-coverage" | ||
"test": "node--test && true", | ||
"prepare": "husky" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "lint-staged && npm run test" | ||
} | ||
}, | ||
"lint-staged": { | ||
"*.js": [ | ||
"prettier --write", | ||
"eslint --ignore-pattern '!*'" | ||
] | ||
"*": [ | ||
"npm test", | ||
"prettier --ignore-unknown --write" | ||
], | ||
"*.{{,c,m}j,t}s{,x}": "eslint --ignore-pattern '!*'" | ||
} | ||
} |
@@ -72,2 +72,13 @@ # app-conf | ||
// if set to true the configuration will be loaded before waiting for | ||
// changes | ||
// | ||
// in that case, the returned promise will reject if the initial load | ||
// failed, or will resolve after the callback has been called with the | ||
// initial configuration | ||
// | ||
// because the async call to `watchConfig()` will not have returned yet, | ||
// `stopWatching()` will not be available in this first callback call | ||
initialLoad: false, | ||
// all other options are passed to load() | ||
@@ -86,3 +97,3 @@ }, | ||
console.log("config has been loaded", config); | ||
} | ||
}, | ||
); | ||
@@ -89,0 +100,0 @@ ``` |
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
Possible typosquat attack
Supply chain riskThere is a package with a similar name that is downloaded much more often.
Did you mean |
---|
npm-conf |
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
19072
11
448
130
0
+ Addedbrace-expansion@2.0.1(transitive)
+ Addedglob@8.1.0(transitive)
+ Addedminimatch@5.1.6(transitive)
- Removedbrace-expansion@1.1.11(transitive)
- Removedconcat-map@0.0.1(transitive)
- Removedglob@7.2.3(transitive)
- Removedminimatch@3.1.2(transitive)
- Removedpath-is-absolute@1.0.1(transitive)
Updatedglob@^8.1.0