PHP 8.2.30
Preview: apply-extends.js Size: 1.44 KB
//opt/alt/alt-nodejs9/root/lib/node_modules/npm/node_modules/libnpx/node_modules/yargs/lib/apply-extends.js

var fs = require('fs')
var path = require('path')
var assign = require('./assign')
var YError = require('./yerror')

var previouslyVisitedConfigs = []

function checkForCircularExtends (path) {
  if (previouslyVisitedConfigs.indexOf(path) > -1) {
    throw new YError("Circular extended configurations: '" + path + "'.")
  }
}

function getPathToDefaultConfig (cwd, pathToExtend) {
  return path.resolve(cwd, pathToExtend)
}

function applyExtends (config, cwd) {
  var defaultConfig = {}

  if (config.hasOwnProperty('extends')) {
    if (typeof config.extends !== 'string') return defaultConfig
    var isPath = /\.json$/.test(config.extends)
    var pathToDefault = null
    if (!isPath) {
      try {
        pathToDefault = require.resolve(config.extends)
      } catch (err) {
        // most likely this simply isn't a module.
      }
    } else {
      pathToDefault = getPathToDefaultConfig(cwd, config.extends)
    }
    // maybe the module uses key for some other reason,
    // err on side of caution.
    if (!pathToDefault && !isPath) return config

    checkForCircularExtends(pathToDefault)

    previouslyVisitedConfigs.push(pathToDefault)

    defaultConfig = isPath ? JSON.parse(fs.readFileSync(pathToDefault, 'utf8')) : require(config.extends)
    delete config.extends
    defaultConfig = applyExtends(defaultConfig, path.dirname(pathToDefault))
  }

  previouslyVisitedConfigs = []

  return assign(defaultConfig, config)
}

module.exports = applyExtends

Directory Contents

Dirs: 0 × Files: 10

Name Size Perms Modified Actions
1.44 KB lrw-r--r-- 2021-09-28 11:28:14
Edit Download
2.42 KB lrw-r--r-- 2021-09-28 11:28:14
Edit Download
413 B lrw-r--r-- 2021-09-28 11:28:14
Edit Download
11.26 KB lrw-r--r-- 2021-09-28 11:28:14
Edit Download
3.02 KB lrw-r--r-- 2021-09-28 11:28:14
Edit Download
2.10 KB lrw-r--r-- 2021-09-28 11:28:14
Edit Download
267 B lrw-r--r-- 2021-09-28 11:28:14
Edit Download
13.30 KB lrw-r--r-- 2021-09-28 11:28:14
Edit Download
10.15 KB lrw-r--r-- 2021-09-28 11:28:14
Edit Download
241 B lrw-r--r-- 2021-09-28 11:28:14
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).