Support tilde paths ("~" prefix) in readConfig/Sync APIs (for "file" parameter and "extends" keys).

This commit is contained in:
David Anson 2022-05-16 22:57:11 -07:00
parent 5505deb1c9
commit ffc4d56918
6 changed files with 132 additions and 31 deletions

View file

@ -1021,3 +1021,16 @@ function deepFreeze(obj) {
return obj;
}
module.exports.deepFreeze = deepFreeze;
/**
* Expands a path with a tilde to an absolute path.
*
* @param {string} file Path that may begin with a tilde.
* @param {Object} os Node.js "os" module.
* @returns {string} Absolute path (or original path).
*/
function expandTildePath(file, os) {
const homedir = os && os.homedir();
return homedir ? file.replace(/^~($|\/|\\)/, `${homedir}$1`) : file;
}
module.exports.expandTildePath = expandTildePath;