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

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclaudiahdz <cghr1990@gmail.com>2020-04-01 00:18:46 +0300
committerisaacs <i@izs.me>2020-05-08 04:12:58 +0300
commitca4c3795fe5ed58b5828208c18e785ecea13baf4 (patch)
tree515c162deab322f5897d740c5abaeb0066ec433c
parent82e5db952cb82b282a7bafecb6a9c02c6a9c7060 (diff)
chore: remove figgy-pudding from cli
-rw-r--r--lib/config/figgy-config.js87
-rw-r--r--lib/outdated.js33
-rw-r--r--lib/unpublish.js190
-rw-r--r--test/tap/config-meta.js9
4 files changed, 105 insertions, 214 deletions
diff --git a/lib/config/figgy-config.js b/lib/config/figgy-config.js
deleted file mode 100644
index d704d1502..000000000
--- a/lib/config/figgy-config.js
+++ /dev/null
@@ -1,87 +0,0 @@
-'use strict'
-
-const BB = require('bluebird')
-
-const crypto = require('crypto')
-const figgyPudding = require('figgy-pudding')
-const log = require('npmlog')
-const npm = require('../npm.js')
-const pack = require('../pack.js')
-const path = require('path')
-
-const npmSession = npm.session = crypto.randomBytes(8).toString('hex')
-log.verbose('npm-session', npmSession)
-
-const SCOPE_REGISTRY_REGEX = /@.*:registry$/gi
-const NpmConfig = figgyPudding({}, {
- other (key) {
- return key.match(SCOPE_REGISTRY_REGEX)
- }
-})
-
-let baseConfig
-
-module.exports = mkConfig
-function mkConfig (...providers) {
- if (!baseConfig) {
- baseConfig = NpmConfig(npm.config, {
- // Add some non-npm-config opts by hand.
- cache: path.join(npm.config.get('cache'), '_cacache'),
- // NOTE: npm has some magic logic around color distinct from the config
- // value, so we have to override it here
- color: !!npm.color,
- dirPacker: pack.packGitDep,
- hashAlgorithm: 'sha1',
- includeDeprecated: false,
- log,
- 'npm-session': npmSession,
- 'project-scope': npm.projectScope,
- refer: npm.referer,
- dmode: npm.modes.exec,
- fmode: npm.modes.file,
- umask: npm.modes.umask,
- npmVersion: npm.version,
- tmp: npm.tmp,
- Promise: BB
- })
- const ownerStats = calculateOwner()
- if (ownerStats.uid != null || ownerStats.gid != null) {
- baseConfig = baseConfig.concat(ownerStats)
- }
- }
- let conf = baseConfig.concat(...providers)
- // Adapt some other configs if missing
- if (npm.config.get('prefer-online') === undefined) {
- conf = conf.concat({
- 'prefer-online': npm.config.get('cache-max') <= 0
- })
- }
- if (npm.config.get('prefer-online') === undefined) {
- conf = conf.concat({
- 'prefer-online': npm.config.get('cache-min') >= 9999
- })
- }
- return conf
-}
-
-let effectiveOwner
-function calculateOwner () {
- if (!effectiveOwner) {
- effectiveOwner = { uid: 0, gid: 0 }
-
- // Pretty much only on windows
- if (!process.getuid) {
- return effectiveOwner
- }
-
- effectiveOwner.uid = +process.getuid()
- effectiveOwner.gid = +process.getgid()
-
- if (effectiveOwner.uid === 0) {
- if (process.env.SUDO_UID) effectiveOwner.uid = +process.env.SUDO_UID
- if (process.env.SUDO_GID) effectiveOwner.gid = +process.env.SUDO_GID
- }
- }
-
- return effectiveOwner
-}
diff --git a/lib/outdated.js b/lib/outdated.js
index abce6cd29..b16eba0a7 100644
--- a/lib/outdated.js
+++ b/lib/outdated.js
@@ -34,8 +34,6 @@ const pickManifest = require('npm-pick-manifest')
const fetchPackageMetadata = require('./fetch-package-metadata.js')
const mutateIntoLogicalTree = require('./install/mutate-into-logical-tree.js')
const npm = require('./npm.js')
-const npmConfig = require('./config/figgy-config.js')
-const figgyPudding = require('figgy-pudding')
const { packument } = require('pacote')
const long = npm.config.get('long')
const isExtraneous = require('./install/is-extraneous.js')
@@ -45,26 +43,9 @@ const moduleName = require('./utils/module-name.js')
const output = require('./utils/output.js')
const ansiTrim = require('./utils/ansi-trim')
-const OutdatedConfig = figgyPudding({
- also: {},
- color: {},
- depth: {},
- dev: 'development',
- development: {},
- global: {},
- json: {},
- only: {},
- parseable: {},
- prod: 'production',
- production: {},
- save: {},
- 'save-dev': {},
- 'save-optional': {}
-})
-
function uniq (list) {
- // we maintain the array because we need an array, not iterator, return
- // value.
+ // we maintain the array because we need an array,
+ // not iterator, return value
var uniqed = []
var seen = new Set()
list.forEach(function (item) {
@@ -87,11 +68,11 @@ function outdated (args, silent, cb) {
cb = silent
silent = false
}
- let opts = OutdatedConfig(npmConfig())
+ let opts = npm.flatOptions
var dir = path.resolve(npm.dir, '..')
// default depth for `outdated` is 0 (cf. `ls`)
- if (opts.depth === Infinity) opts = opts.concat({depth: 0})
+ if (opts.depth === Infinity) opts = { ...opts, depth: 0 }
readPackageTree(dir, andComputeMetadata(function (er, tree) {
if (!tree) return cb(er)
@@ -372,9 +353,11 @@ function shouldUpdate (args, tree, dep, has, req, depth, pkgpath, opts, cb, type
} else if (parsed.type === 'remote') {
return doIt('remote', 'remote')
} else {
- return packument(parsed, opts.concat({
+ return packument(parsed, {
+ ...opts,
'prefer-online': true
- })).nodeify(updateDeps)
+ })
+ .then(() => updateDeps())
}
function doIt (wanted, latest) {
diff --git a/lib/unpublish.js b/lib/unpublish.js
index 2d766e831..533d307eb 100644
--- a/lib/unpublish.js
+++ b/lib/unpublish.js
@@ -1,110 +1,114 @@
-/* eslint-disable standard/no-callback-literal */
'use strict'
-module.exports = unpublish
-
-const BB = require('bluebird')
-
-const figgyPudding = require('figgy-pudding')
-const libaccess = require('libnpmaccess')
-const libunpub = require('libnpmpublish').unpublish
+const path = require('path')
+const util = require('util')
const log = require('npmlog')
const npa = require('npm-package-arg')
-const npm = require('./npm.js')
-const npmConfig = require('./config/figgy-config.js')
+const libaccess = require('libnpmaccess')
const npmFetch = require('npm-registry-fetch')
-const otplease = require('./utils/otplease.js')
-const output = require('./utils/output.js')
-const path = require('path')
-const readJson = BB.promisify(require('read-package-json'))
+const libunpub = require('libnpmpublish').unpublish
+const readJson = util.promisify(require('read-package-json'))
+
+const npm = require('./npm.js')
const usage = require('./utils/usage.js')
-const whoami = BB.promisify(require('./whoami.js'))
+const output = require('./utils/output.js')
+const otplease = require('./utils/otplease.js')
+const whoami = util.promisify(require('./whoami.js'))
+
+cmd.usage = usage('unpublish', 'npm unpublish [<@scope>/]<pkg>[@<version>]')
-unpublish.usage = usage('unpublish', 'npm unpublish [<@scope>/]<pkg>[@<version>]')
+module.exports = cmd
+function cmd(args, cb) {
+ unpublish(args, cb)
+ .then((ret) => cb(null, ret))
+ .catch((err) => err.code === 'EUSAGE' ? cb(err.message) : cb(err))
+}
-function UsageError () {
- throw Object.assign(new Error(`Usage: ${unpublish.usage}`), {
- code: 'EUSAGE'
- })
+cmd.completion = (args, cb) => {
+ completion(args)
+ .then(() => cb())
+ .catch(cb)
}
+async function completion(args) {
+ const { partialWord, conf } = args
+
+ if (conf.argv.remain.length >= 3) return cb()
+
+ const username = await whoami([], true)
+ if (!username) { return [] }
+ const opts = npm.flatOptions
+
+ const access = await libaccess.lsPackages(username, opts)
+ // do a bit of filtering at this point, so that we don't need
+ // to fetch versions for more than one thing, but also don't
+ // accidentally a whole project
+ let pkgs = Object.keys(access)
+ if (!partialWord || !pkgs.length) return pkgs
-const UnpublishConfig = figgyPudding({
- force: {},
- loglevel: {},
- silent: {}
-})
-
-unpublish.completion = function (cliOpts, cb) {
- if (cliOpts.conf.argv.remain.length >= 3) return cb()
-
- whoami([], true).then(username => {
- if (!username) { return [] }
- const opts = UnpublishConfig(npmConfig())
- return libaccess.lsPackages(username, opts).then(access => {
- // do a bit of filtering at this point, so that we don't need
- // to fetch versions for more than one thing, but also don't
- // accidentally a whole project.
- let pkgs = Object.keys(access)
- if (!cliOpts.partialWord || !pkgs.length) { return pkgs }
- const pp = npa(cliOpts.partialWord).name
- pkgs = pkgs.filter(p => !p.indexOf(pp))
- if (pkgs.length > 1) return pkgs
- return npmFetch.json(npa(pkgs[0]).escapedName, opts).then(doc => {
- const vers = Object.keys(doc.versions)
- if (!vers.length) {
- return pkgs
- } else {
- return vers.map(v => `${pkgs[0]}@${v}`)
- }
- })
- })
- }).nodeify(cb)
+ const pp = npa(partialWord).name
+ pkgs = pkgs.filter(p => !p.indexOf(pp))
+ if (pkgs.length > 1) return pkgs
+
+ const json = await npmFetch.json(npa(pkgs[0]).escapedName, opts)
+ const versions = Object.keys(json.versions)
+ if (!versions.length) {
+ return pkgs
+ } else {
+ return versions.map(v => `${pkgs[0]}@${v}`)
+ }
}
-function unpublish (args, cb) {
- if (args.length > 1) return cb(unpublish.usage)
+async function unpublish (args, cb) {
+ if (args.length > 1) return cb(cmd.usage)
const spec = args.length && npa(args[0])
- const opts = UnpublishConfig(npmConfig())
- const version = spec.rawSpec
- BB.try(() => {
- log.silly('unpublish', 'args[0]', args[0])
- log.silly('unpublish', 'spec', spec)
- if (!version && !opts.force) {
- throw Object.assign(new Error(
- 'Refusing to delete entire project.\n' +
- 'Run with --force to do this.\n' +
- unpublish.usage
- ), {code: 'EUSAGE'})
- }
- if (!spec || path.resolve(spec.name) === npm.localPrefix) {
- // if there's a package.json in the current folder, then
- // read the package name and version out of that.
- const cwdJson = path.join(npm.localPrefix, 'package.json')
- return readJson(cwdJson).then(data => {
- log.verbose('unpublish', data)
- return otplease(opts, opts => {
- return libunpub(npa.resolve(data.name, data.version), opts.concat(data.publishConfig))
+ const opts = npm.flatOptions
+ const { force, silent, loglevel } = opts
+ let ret
+
+ log.silly('unpublish', 'args[0]', args[0])
+ log.silly('unpublish', 'spec', spec)
+
+ if (!spec.rawSpec && !force) {
+ throw Object.assign(new Error(
+ 'Refusing to delete entire project.\n' +
+ 'Run with --force to do this.\n' +
+ cmd.usage
+ ), {code: 'EUSAGE'})
+ }
+
+ if (!spec || path.resolve(spec.name) === npm.localPrefix) {
+ // if there's a package.json in the current folder, then
+ // read the package name and version out of that.
+ const pkgJson = path.join(npm.localPrefix, 'package.json')
+ const manifest = await readJson(pkgJson)
+
+ log.verbose('unpublish', manifest)
+
+ const { name, version, publishConfig } = manifest
+ const pkgJsonSpec = npa.resolve(name, version)
+
+ try {
+ ret = await otplease(opts, opts => libunpub(pkgJsonSpec, { ...opts, publishConfig }))
+ } catch (err) {
+ if (err && err.code !== 'ENOENT' && err.code !== 'ENOTDIR') {
+ throw err
+ } else {
+ throw Object.assign(new Error(`Usage: ${unpublish.usage}`), {
+ code: 'EUSAGE'
})
- }, err => {
- if (err && err.code !== 'ENOENT' && err.code !== 'ENOTDIR') {
- throw err
- } else {
- UsageError()
- }
- })
- } else {
- return otplease(opts, opts => libunpub(spec, opts))
- }
- }).then(
- ret => {
- if (!opts.silent && opts.loglevel !== 'silent') {
- output(`- ${spec.name}${
- spec.type === 'version' ? `@${spec.rawSpec}` : ''
- }`)
}
- cb(null, ret)
- },
- err => err.code === 'EUSAGE' ? cb(err.message) : cb(err)
- )
+ }
+
+ } else {
+ ret = await otplease(opts, opts => libunpub(spec, opts))
+ }
+
+ if (!silent && loglevel !== 'silent') {
+ output(`- ${spec.name}${
+ spec.type === 'version' ? `@${spec.rawSpec}` : ''
+ }`)
+ }
+
+ return ret
}
diff --git a/test/tap/config-meta.js b/test/tap/config-meta.js
index a98d5e6c4..3c03ab816 100644
--- a/test/tap/config-meta.js
+++ b/test/tap/config-meta.js
@@ -110,15 +110,6 @@ test('check configs', function (t) {
}
}
- // TODO - needs better figgy-pudding introspection
- // for (var c2 in DOC) {
- // if (c2 !== 'versions' && c2 !== 'version' && c2 !== 'init.version' && c2 !== 'ham-it-up') {
- // t.ok(CONFS[c2], 'config in doc should be used somewhere ' + c2)
- // t.ok(types.indexOf(c2) !== -1, 'should be defined in npmconf ' + c2)
- // t.ok(defaults.indexOf(c2) !== -1, 'should have default in npmconf ' + c2)
- // }
- // }
-
types.forEach(function (c) {
if (!c.match(/^_/) && c !== 'argv' && !c.match(/^versions?$/) && c !== 'ham-it-up') {
t.ok(DOC[c], 'defined type should be documented ' + c)