Psyduck - 可達鴨 之 鴨力山大2


Server : LiteSpeed
System : Linux premium217.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User : alloknri ( 880)
PHP Version : 8.1.34
Disable Function : NONE
Directory :  /usr/lib/node_modules/npm/lib/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //usr/lib/node_modules/npm/lib/config.js
/* eslint-disable standard/no-callback-literal */
module.exports = config

var log = require('npmlog')
var npm = require('./npm.js')
var npmconf = require('./config/core.js')
var fs = require('graceful-fs')
var writeFileAtomic = require('write-file-atomic')
var types = npmconf.defs.types
var ini = require('ini')
var editor = require('editor')
var os = require('os')
var path = require('path')
var mkdirp = require('gentle-fs').mkdir
var umask = require('./utils/umask')
var usage = require('./utils/usage')
var output = require('./utils/output')
var noProgressTillDone = require('./utils/no-progress-while-running').tillDone

config.usage = usage(
  'config',
  'npm config set <key> <value>' +
  '\nnpm config get [<key>]' +
  '\nnpm config delete <key>' +
  '\nnpm config list [--json]' +
  '\nnpm config edit' +
  '\nnpm set <key> <value>' +
  '\nnpm get [<key>]'
)
config.completion = function (opts, cb) {
  var argv = opts.conf.argv.remain
  if (argv[1] !== 'config') argv.unshift('config')
  if (argv.length === 2) {
    var cmds = ['get', 'set', 'delete', 'ls', 'rm', 'edit']
    if (opts.partialWord !== 'l') cmds.push('list')
    return cb(null, cmds)
  }

  var action = argv[2]
  switch (action) {
    case 'set':
      // todo: complete with valid values, if possible.
      if (argv.length > 3) return cb(null, [])
      // fallthrough
      /* eslint no-fallthrough:0 */
    case 'get':
    case 'delete':
    case 'rm':
      return cb(null, Object.keys(types))
    case 'edit':
    case 'list':
    case 'ls':
      return cb(null, [])
    default:
      return cb(null, [])
  }
}

// npm config set key value
// npm config get key
// npm config list
function config (args, cb) {
  var action = args.shift()
  switch (action) {
    case 'set':
      return set(args[0], args[1], cb)
    case 'get':
      return get(args[0], cb)
    case 'delete':
    case 'rm':
    case 'del':
      return del(args[0], cb)
    case 'list':
    case 'ls':
      return npm.config.get('json') ? listJson(cb) : list(cb)
    case 'edit':
      return edit(cb)
    default:
      return unknown(action, cb)
  }
}

function edit (cb) {
  var e = npm.config.get('editor')
  var which = npm.config.get('global') ? 'global' : 'user'
  var f = npm.config.get(which + 'config')
  if (!e) return cb(new Error('No EDITOR config or environ set.'))
  npm.config.save(which, function (er) {
    if (er) return cb(er)
    fs.readFile(f, 'utf8', function (er, data) {
      if (er) data = ''
      data = [
        ';;;;',
        '; npm ' + (npm.config.get('global')
          ? 'globalconfig' : 'userconfig') + ' file',
        '; this is a simple ini-formatted file',
        '; lines that start with semi-colons are comments.',
        '; read `npm help config` for help on the various options',
        ';;;;',
        '',
        data
      ].concat([
        ';;;;',
        '; all options with default values',
        ';;;;'
      ]).concat(Object.keys(npmconf.defaults).reduce(function (arr, key) {
        var obj = {}
        obj[key] = npmconf.defaults[key]
        if (key === 'logstream') return arr
        return arr.concat(
          ini.stringify(obj)
            .replace(/\n$/m, '')
            .replace(/^/g, '; ')
            .replace(/\n/g, '\n; ')
            .split('\n'))
      }, []))
        .concat([''])
        .join(os.EOL)
      mkdirp(path.dirname(f), function (er) {
        if (er) return cb(er)
        writeFileAtomic(
          f,
          data,
          function (er) {
            if (er) return cb(er)
            editor(f, { editor: e }, noProgressTillDone(cb))
          }
        )
      })
    })
  })
}

function del (key, cb) {
  if (!key) return cb(new Error('no key provided'))
  var where = npm.config.get('global') ? 'global' : 'user'
  npm.config.del(key, where)
  npm.config.save(where, cb)
}

function set (key, val, cb) {
  if (key === undefined) {
    return unknown('', cb)
  }
  if (val === undefined) {
    if (key.indexOf('=') !== -1) {
      var k = key.split('=')
      key = k.shift()
      val = k.join('=')
    } else {
      val = ''
    }
  }
  key = key.trim()
  val = val.trim()
  log.info('config', 'set %j %j', key, val)
  var where = npm.config.get('global') ? 'global' : 'user'
  if (key.match(/umask/)) val = umask.fromString(val)
  npm.config.set(key, val, where)
  npm.config.save(where, cb)
}

function get (key, cb) {
  if (!key) return list(cb)
  if (!publicVar(key)) {
    return cb(new Error('---sekretz---'))
  }
  var val = npm.config.get(key)
  if (key.match(/umask/)) val = umask.toString(val)
  output(val)
  cb()
}

function sort (a, b) {
  return a > b ? 1 : -1
}

function publicVar (k) {
  return !(k.charAt(0) === '_' || k.indexOf(':_') !== -1)
}

function getKeys (data) {
  return Object.keys(data).filter(publicVar).sort(sort)
}

function listJson (cb) {
  const publicConf = npm.config.keys.reduce((publicConf, k) => {
    var value = npm.config.get(k)

    if (publicVar(k) &&
        // argv is not really config, it's command config
        k !== 'argv' &&
        // logstream is a Stream, and would otherwise produce circular refs
        k !== 'logstream') publicConf[k] = value

    return publicConf
  }, {})

  output(JSON.stringify(publicConf, null, 2))
  return cb()
}

function listFromSource (title, conf, long) {
  var confKeys = getKeys(conf)
  var msg = ''

  if (confKeys.length) {
    msg += '; ' + title + '\n'
    confKeys.forEach(function (k) {
      var val = JSON.stringify(conf[k])
      if (conf[k] !== npm.config.get(k)) {
        if (!long) return
        msg += '; ' + k + ' = ' + val + ' (overridden)\n'
      } else msg += k + ' = ' + val + '\n'
    })
    msg += '\n'
  }

  return msg
}

function list (cb) {
  var msg = ''
  var long = npm.config.get('long')

  var cli = npm.config.sources.cli.data
  var cliKeys = getKeys(cli)
  if (cliKeys.length) {
    msg += '; cli configs\n'
    cliKeys.forEach(function (k) {
      if (cli[k] && typeof cli[k] === 'object') return
      if (k === 'argv') return
      msg += k + ' = ' + JSON.stringify(cli[k]) + '\n'
    })
    msg += '\n'
  }

  // env configs
  msg += listFromSource('environment configs', npm.config.sources.env.data, long)

  // project config file
  var project = npm.config.sources.project
  msg += listFromSource('project config ' + project.path, project.data, long)

  // user config file
  msg += listFromSource('userconfig ' + npm.config.get('userconfig'), npm.config.sources.user.data, long)

  // global config file
  msg += listFromSource('globalconfig ' + npm.config.get('globalconfig'), npm.config.sources.global.data, long)

  // builtin config file
  var builtin = npm.config.sources.builtin || {}
  if (builtin && builtin.data) {
    msg += listFromSource('builtin config ' + builtin.path, builtin.data, long)
  }

  // only show defaults if --long
  if (!long) {
    msg += '; node bin location = ' + process.execPath + '\n' +
           '; cwd = ' + process.cwd() + '\n' +
           '; HOME = ' + process.env.HOME + '\n' +
           '; "npm config ls -l" to show all defaults.\n'

    output(msg)
    return cb()
  }

  var defaults = npmconf.defaults
  var defKeys = getKeys(defaults)
  msg += '; default values\n'
  defKeys.forEach(function (k) {
    if (defaults[k] && typeof defaults[k] === 'object') return
    var val = JSON.stringify(defaults[k])
    if (defaults[k] !== npm.config.get(k)) {
      msg += '; ' + k + ' = ' + val + ' (overridden)\n'
    } else msg += k + ' = ' + val + '\n'
  })
  msg += '\n'

  output(msg)
  return cb()
}

function unknown (action, cb) {
  cb('Usage:\n' + config.usage)
}
Name
Size
Permissions
Options
auth
--
drwxr-xr-x
config
--
drwxr-xr-x
doctor
--
drwxr-xr-x
install
--
drwxr-xr-x
search
--
drwxr-xr-x
utils
--
drwxr-xr-x
access.js
5.539 KB
-rw-r--r--
adduser.js
1.306 KB
-rw-r--r--
audit.js
10.558 KB
-rw-r--r--
bin.js
0.503 KB
-rw-r--r--
bugs.js
0.844 KB
-rw-r--r--
build.js
4.438 KB
-rw-r--r--
cache.js
4.661 KB
-rw-r--r--
ci.js
1.31 KB
-rw-r--r--
completion.js
7.107 KB
-rw-r--r--
config.js
7.434 KB
-rw-r--r--
dedupe.js
4.882 KB
-rw-r--r--
deprecate.js
2.106 KB
-rw-r--r--
dist-tag.js
4.105 KB
-rw-r--r--
docs.js
1.038 KB
-rw-r--r--
doctor.js
3.979 KB
-rw-r--r--
edit.js
1.374 KB
-rw-r--r--
explore.js
1.669 KB
-rw-r--r--
fetch-package-metadata.js
3.969 KB
-rw-r--r--
fetch-package-metadata.md
1.769 KB
-rw-r--r--
fund.js
4.908 KB
-rw-r--r--
get.js
0.229 KB
-rw-r--r--
help-search.js
5.642 KB
-rw-r--r--
help.js
6.354 KB
-rw-r--r--
hook.js
4.616 KB
-rw-r--r--
init.js
2.739 KB
-rw-r--r--
install-ci-test.js
0.475 KB
-rw-r--r--
install-test.js
0.495 KB
-rw-r--r--
install.js
36.47 KB
-rw-r--r--
link.js
5.604 KB
-rw-r--r--
logout.js
1.259 KB
-rw-r--r--
ls.js
16.094 KB
-rw-r--r--
npm.js
14.374 KB
-rw-r--r--
org.js
4.176 KB
-rw-r--r--
outdated.js
12.277 KB
-rw-r--r--
owner.js
6.596 KB
-rw-r--r--
pack.js
11.785 KB
-rw-r--r--
ping.js
1.114 KB
-rw-r--r--
prefix.js
0.322 KB
-rw-r--r--
profile.js
11.134 KB
-rw-r--r--
prune.js
2.228 KB
-rw-r--r--
publish.js
5.141 KB
-rw-r--r--
rebuild.js
2.093 KB
-rw-r--r--
repo.js
1.437 KB
-rw-r--r--
restart.js
0.063 KB
-rw-r--r--
root.js
0.313 KB
-rw-r--r--
run-script.js
5.41 KB
-rw-r--r--
search.js
3.361 KB
-rw-r--r--
set.js
0.27 KB
-rw-r--r--
shrinkwrap.js
9.82 KB
-rw-r--r--
star.js
2.106 KB
-rw-r--r--
stars.js
1.029 KB
-rw-r--r--
start.js
0.061 KB
-rw-r--r--
stop.js
0.06 KB
-rw-r--r--
substack.js
0.497 KB
-rw-r--r--
team.js
4.613 KB
-rw-r--r--
test.js
0.365 KB
-rw-r--r--
token.js
6.658 KB
-rw-r--r--
unbuild.js
4.271 KB
-rw-r--r--
uninstall.js
2.208 KB
-rw-r--r--
unpublish.js
3.51 KB
-rw-r--r--
update.js
2.161 KB
-rw-r--r--
version.js
9.794 KB
-rw-r--r--
view.js
15.11 KB
-rw-r--r--
visnup.js
4.008 KB
-rw-r--r--
whoami.js
1.767 KB
-rw-r--r--
xmas.js
1.624 KB
-rw-r--r--