Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/yargs/lib/apply-extends.js')
-rw-r--r--deps/npm/node_modules/yargs/lib/apply-extends.js24
1 files changed, 19 insertions, 5 deletions
diff --git a/deps/npm/node_modules/yargs/lib/apply-extends.js b/deps/npm/node_modules/yargs/lib/apply-extends.js
index 530b022ac57..643c91335a0 100644
--- a/deps/npm/node_modules/yargs/lib/apply-extends.js
+++ b/deps/npm/node_modules/yargs/lib/apply-extends.js
@@ -16,12 +16,26 @@ function getPathToDefaultConfig (cwd, pathToExtend) {
return path.resolve(cwd, pathToExtend)
}
-function applyExtends (config, cwd) {
+function mergeDeep (config1, config2) {
+ const target = {}
+ const isObject = obj => obj && typeof obj === 'object' && !Array.isArray(obj)
+ Object.assign(target, config1)
+ for (let key of Object.keys(config2)) {
+ if (isObject(config2[key]) && isObject(target[key])) {
+ target[key] = mergeDeep(config1[key], config2[key])
+ } else {
+ target[key] = config2[key]
+ }
+ }
+ return target
+}
+
+function applyExtends (config, cwd, mergeExtends) {
let defaultConfig = {}
- if (config.hasOwnProperty('extends')) {
+ if (Object.prototype.hasOwnProperty.call(config, 'extends')) {
if (typeof config.extends !== 'string') return defaultConfig
- const isPath = /\.json$/.test(config.extends)
+ const isPath = /\.json|\..*rc$/.test(config.extends)
let pathToDefault = null
if (!isPath) {
try {
@@ -42,12 +56,12 @@ function applyExtends (config, cwd) {
defaultConfig = isPath ? JSON.parse(fs.readFileSync(pathToDefault, 'utf8')) : require(config.extends)
delete config.extends
- defaultConfig = applyExtends(defaultConfig, path.dirname(pathToDefault))
+ defaultConfig = applyExtends(defaultConfig, path.dirname(pathToDefault), mergeExtends)
}
previouslyVisitedConfigs = []
- return Object.assign({}, defaultConfig, config)
+ return mergeExtends ? mergeDeep(defaultConfig, config) : Object.assign({}, defaultConfig, config)
}
module.exports = applyExtends