source: trip-planner-front/node_modules/yargs/lib/apply-extends.js@ b738035

Last change on this file since b738035 was e29cc2e, checked in by Ema <ema_spirova@…>, 3 years ago

primeNG components

  • Property mode set to 100644
File size: 1.5 KB
RevLine 
[6a3a178]1
2'use strict'
3const fs = require('fs')
4const path = require('path')
5const YError = require('./yerror')
6
7let previouslyVisitedConfigs = []
8
9function checkForCircularExtends (cfgPath) {
10 if (previouslyVisitedConfigs.indexOf(cfgPath) > -1) {
11 throw new YError(`Circular extended configurations: '${cfgPath}'.`)
12 }
13}
14
15function getPathToDefaultConfig (cwd, pathToExtend) {
16 return path.resolve(cwd, pathToExtend)
17}
18
19function applyExtends (config, cwd) {
20 let defaultConfig = {}
21
22 if (config.hasOwnProperty('extends')) {
23 if (typeof config.extends !== 'string') return defaultConfig
24 const isPath = /\.json|\..*rc$/.test(config.extends)
25 let pathToDefault = null
26 if (!isPath) {
27 try {
28 pathToDefault = require.resolve(config.extends)
29 } catch (err) {
30 // most likely this simply isn't a module.
31 }
32 } else {
33 pathToDefault = getPathToDefaultConfig(cwd, config.extends)
34 }
35 // maybe the module uses key for some other reason,
36 // err on side of caution.
37 if (!pathToDefault && !isPath) return config
38
39 checkForCircularExtends(pathToDefault)
40
41 previouslyVisitedConfigs.push(pathToDefault)
42
43 defaultConfig = isPath ? JSON.parse(fs.readFileSync(pathToDefault, 'utf8')) : require(config.extends)
44 delete config.extends
45 defaultConfig = applyExtends(defaultConfig, path.dirname(pathToDefault))
46 }
47
48 previouslyVisitedConfigs = []
49
50 return Object.assign({}, defaultConfig, config)
51}
52
53module.exports = applyExtends
Note: See TracBrowser for help on using the repository browser.