Skip to content

[v7] Update output of npm install command #1017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
9941a0a
feat: drop support for node v6 and v8
claudiahdz Feb 4, 2020
b53336b
[email protected]
Jan 31, 2020
a634f99
[email protected]
claudiahdz Feb 18, 2020
661f088
test: removing test for no scoped deps, dropping constraint for v7 of…
Feb 4, 2020
2ba9364
[email protected]
claudiahdz Feb 6, 2020
52347a3
[email protected]
claudiahdz Feb 6, 2020
d121526
[email protected]
claudiahdz Feb 6, 2020
b865973
[email protected]
claudiahdz Feb 6, 2020
3161078
[email protected]
claudiahdz Feb 6, 2020
fae7c52
[email protected]
claudiahdz Feb 18, 2020
f7cf6af
create a flat options object to pass to deps
isaacs Feb 14, 2020
ed30363
@npmcli/[email protected]
claudiahdz Feb 18, 2020
1469b9d
@npmcli/[email protected]
Feb 19, 2020
5e10052
[email protected]
Feb 19, 2020
150f686
[email protected]
Feb 19, 2020
b30f070
[email protected]
Feb 20, 2020
9dcb7c8
feat: removed libnpm
Feb 20, 2020
972e5b6
chore: update/removed usages of libnpm
Feb 20, 2020
c23746a
[email protected], dedupe some dependencies in node_modules
isaacs Feb 19, 2020
068e104
@npmcli/[email protected]
isaacs Feb 20, 2020
fbe9f3b
fix: add scriptShell to flatOptions
isaacs Feb 20, 2020
12bbeca
deps: hoist hosted-git-info to top, remove extraneous deps
isaacs Feb 21, 2020
f50194e
wip: remove install
claudiahdz Feb 18, 2020
4f4602b
wip: Use @npmcli/arborist to install packages locally
Feb 19, 2020
ae76252
fix: add scriptShell to flatOptions
isaacs Feb 20, 2020
5bd1acf
@npmcli/[email protected]
isaacs Feb 24, 2020
ae3e404
[email protected]
isaacs Feb 26, 2020
e2a4976
Use de-figged npm-profile
isaacs Feb 25, 2020
f6f19f0
Do not open URL in a browser unless valid
isaacs Mar 2, 2020
fda2ce0
[email protected]
Mar 2, 2020
5e19233
fix: updated usage of libnpmhook; removed figgy-pudding
Mar 2, 2020
ce607b3
[email protected]
Mar 2, 2020
35990af
fix: updated usage of libnpmorg; removed figgy-pudding
Mar 2, 2020
eb63cb5
[email protected]
Mar 2, 2020
86e70ae
fix: updated usage of libnpmorg; removed figgy-pudding/bluebird
Mar 3, 2020
9bbc4a5
[email protected]
isaacs Mar 3, 2020
3cd8bbc
fix: updated usage of libnpmsearch
Mar 3, 2020
64efbe9
refactor otplease, remove figgy-pudding and bluebird
isaacs Mar 3, 2020
37808cc
Remove deprecation warnings from npm.flatOptions properties
isaacs Mar 3, 2020
a1ed918
[email protected]
isaacs Mar 3, 2020
5a36ee2
Remove bluebird, figgy-pudding from several smaller commands
isaacs Mar 3, 2020
924d85b
feat: updated the way we handle identity fetching
Mar 5, 2020
0f3d84e
fix: lining; removal of BB remnant
Mar 5, 2020
6e03b68
de-terse the star command output picture logic
isaacs Mar 5, 2020
bc3c1b0
view: raise proper ENOENT if package.json is missing
isaacs Mar 5, 2020
5b19653
[email protected]
isaacs Mar 5, 2020
46a1f45
remove parse-json util, use json-parse-even-better-errors
isaacs Mar 5, 2020
500010a
team: no need to override flatOptions.description
isaacs Mar 5, 2020
bf3370b
Remove two remaining BB remnants
isaacs Mar 5, 2020
1e0ee77
feat: updated 'npm install' command
Mar 10, 2020
4c82c62
@npmcli/[email protected]
Mar 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
strategy:
fail-fast: false
matrix:
node-version: [6.x, 8.x, 10.x, 12.x]
node-version: [10.x, 12.x, 13.x]
os: [ubuntu-latest]

runs-on: ${{ matrix.os }}
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ os:
- windows

node_js:
- 13
- 12
- 10
- 8
- 6

env: "DEPLOY_VERSION=testing"

Expand Down
43 changes: 19 additions & 24 deletions lib/access.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
'use strict'
/* eslint-disable standard/no-callback-literal */

const BB = require('bluebird')

const figgyPudding = require('figgy-pudding')
const libaccess = require('libnpm/access')
const npmConfig = require('./config/figgy-config.js')
const libaccess = require('libnpmaccess')
const npm = require('./npm.js')
const output = require('./utils/output.js')
const otplease = require('./utils/otplease.js')
const path = require('path')
const prefix = require('./npm.js').prefix
const readPackageJson = BB.promisify(require('read-package-json'))
const { prefix } = npm
const { promisify } = require('util')
const readPackageJson = promisify(require('read-package-json'))
const usage = require('./utils/usage.js')
const whoami = require('./whoami.js')
const getIdentity = require('./utils/get-identity')

module.exports = access

Expand All @@ -35,10 +33,6 @@ access.subcommands = [
'2fa-required', '2fa-not-required'
]

const AccessConfig = figgyPudding({
json: {}
})

function UsageError (msg = '') {
throw Object.assign(new Error(
(msg ? `\nUsage: ${msg}\n\n` : '') +
Expand Down Expand Up @@ -75,12 +69,12 @@ access.completion = function (opts, cb) {
}

function access ([cmd, ...args], cb) {
return BB.try(() => {
return Promise.resolve().then(() => {
const fn = access.subcommands.includes(cmd) && access[cmd]
if (!cmd) { UsageError('Subcommand is required.') }
if (!fn) { UsageError(`${cmd} is not a recognized subcommand.`) }

return fn(args, AccessConfig(npmConfig()))
return fn(args, { ...npm.flatOptions })
}).then(
x => cb(null, x),
err => err.code === 'EUSAGE' ? cb(err.message) : cb(err)
Expand All @@ -96,7 +90,7 @@ access.restricted = ([pkg], opts) => {
}

access.grant = ([perms, scopeteam, pkg], opts) => {
return BB.try(() => {
return Promise.resolve().then(() => {
if (!perms || (perms !== 'read-only' && perms !== 'read-write')) {
UsageError('First argument must be either `read-only` or `read-write.`')
}
Expand All @@ -117,7 +111,7 @@ access.grant = ([perms, scopeteam, pkg], opts) => {
}

access.revoke = ([scopeteam, pkg], opts) => {
return BB.try(() => {
return Promise.resolve().then(() => {
if (!scopeteam) {
UsageError('`<scope:team>` argument is required.')
}
Expand All @@ -143,9 +137,11 @@ access['2fa-not-required'] = access.tfaNotRequired = ([pkg], opts) => {
}

access['ls-packages'] = access.lsPackages = ([owner], opts) => {
return (
owner ? BB.resolve(owner) : BB.fromNode(cb => whoami([], true, cb))
).then(owner => {
const getOwnerPromise = (owner)
? Promise.resolve(owner)
: getIdentity(opts)

return getOwnerPromise(owner).then(owner => {
return libaccess.lsPackages(owner, opts)
}).then(pkgs => {
// TODO - print these out nicely (breaking change)
Expand All @@ -162,16 +158,15 @@ access['ls-collaborators'] = access.lsCollaborators = ([pkg, usr], opts) => {
})
}

access['edit'] = () => BB.reject(new Error('edit subcommand is not implemented yet'))
access['edit'] = () => Promise.reject(new Error('edit subcommand is not implemented yet'))

function modifyPackage (pkg, opts, fn, requireScope = true) {
return getPackage(pkg, requireScope).then(pkgName =>
otplease(opts, opts => fn(pkgName, opts))
)
return getPackage(pkg, requireScope)
.then(pkgName => otplease(opts, opts => fn(pkgName, opts)))
}

function getPackage (name, requireScope = true) {
return BB.try(() => {
return Promise.resolve().then(() => {
if (name && name.trim()) {
return name.trim()
} else {
Expand Down
10 changes: 5 additions & 5 deletions lib/adduser.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ try {

adduser.usage = usage(
'adduser',
'npm adduser [--registry=url] [--scope=@orgname] [--auth-type=legacy] [--always-auth]'
'npm adduser [--registry=url] [--scope=@orgname] [--always-auth]'
)

function adduser (args, cb) {
Expand All @@ -21,9 +21,9 @@ function adduser (args, cb) {
))
}

let registry = npm.config.get('registry')
const scope = npm.config.get('scope')
const creds = npm.config.getCredentialsByURI(npm.config.get('registry'))
let registry = npm.flatOptions.registry
const scope = npm.flatOptions.scope
const creds = npm.config.getCredentialsByURI(registry)

if (scope) {
const scopedRegistry = npm.config.get(scope + ':registry')
Expand All @@ -35,7 +35,7 @@ function adduser (args, cb) {

let auth
try {
auth = require('./auth/' + npm.config.get('auth-type'))
auth = require('./auth/' + npm.flatOptions.authType)
} catch (e) {
return cb(new Error('no such auth module'))
}
Expand Down
2 changes: 1 addition & 1 deletion lib/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const fs = require('graceful-fs')
const Installer = require('./install.js').Installer
const lockVerify = require('lock-verify')
const log = require('npmlog')
const npa = require('libnpm/parse-arg')
const npa = require('npm-package-arg')
const npm = require('./npm.js')
const npmConfig = require('./config/figgy-config.js')
const output = require('./utils/output.js')
Expand Down
22 changes: 9 additions & 13 deletions lib/auth/legacy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict'

const read = require('../utils/read-user-info.js')
const profile = require('libnpm/profile')
const profile = require('npm-profile')
const log = require('npmlog')
const figgyPudding = require('figgy-pudding')
const npmConfig = require('../config/figgy-config.js')
const npm = require('../npm.js')
const output = require('../utils/output.js')
const openUrl = require('../utils/open-url')

Expand All @@ -26,16 +25,13 @@ const loginPrompter = (creds) => {
})
}

const LoginOpts = figgyPudding({
'always-auth': {},
creds: {},
log: {default: () => log},
registry: {},
scope: {}
})

module.exports.login = (creds = {}, registry, scope, cb) => {
const opts = LoginOpts(npmConfig()).concat({scope, registry, creds})
const opts = {
...npm.flatOptions,
scope,
registry,
creds
}
login(opts).then((newCreds) => cb(null, newCreds)).catch(cb)
}

Expand Down Expand Up @@ -66,7 +62,7 @@ function login (opts) {
newCreds.username = opts.creds.username
newCreds.password = opts.creds.password
newCreds.email = opts.creds.email
newCreds.alwaysAuth = opts['always-auth']
newCreds.alwaysAuth = opts.alwaysAuth
}

const usermsg = opts.creds.username ? ' user ' + opts.creds.username : ''
Expand Down
37 changes: 18 additions & 19 deletions lib/auth/sso.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
'use strict'

const BB = require('bluebird')
// XXX: To date, npm Enterprise Legacy is the only system that ever
// implemented support for this type of login. A better way to do
// SSO is to use the WebLogin type of login supported by the npm-login
// module. This more forward-looking login style is, ironically,
// supported by the '--auth-type=legacy' type of login.
// When and if npm Enterprise Legacy is no longer supported by the npm
// CLI, we can remove this, and fold the lib/auth/legacy.js back into
// lib/adduser.js

const figgyPudding = require('figgy-pudding')
const log = require('npmlog')
const npmConfig = require('../config/figgy-config.js')
const npm = require('../npm.js')
const npmFetch = require('npm-registry-fetch')
const output = require('../utils/output.js')
const openUrl = BB.promisify(require('../utils/open-url.js'))
const { promisify } = require('util')
const openUrl = promisify(require('../utils/open-url.js'))
const otplease = require('../utils/otplease.js')
const profile = require('libnpm/profile')

const SsoOpts = figgyPudding({
ssoType: 'sso-type',
'sso-type': {},
ssoPollFrequency: 'sso-poll-frequency',
'sso-poll-frequency': {}
})
const profile = require('npm-profile')

module.exports.login = function login (creds, registry, scope, cb) {
const opts = SsoOpts(npmConfig()).concat({creds, registry, scope})
log.warn('deprecated', 'SSO --auth-type is deprecated')
const opts = { ...npm.flatOptions, creds, registry, scope }
const ssoType = opts.ssoType
if (!ssoType) { return cb(new Error('Missing option: sso-type')) }

Expand All @@ -45,18 +46,18 @@ module.exports.login = function login (creds, registry, scope, cb) {
output('Logged in as %s%s on %s.', username, scopeMessage, registry)
return {token}
})
}).nodeify(cb)
}).then(res => cb(null, res), cb)
}

function pollForSession (registry, token, opts) {
log.info('adduser', 'Polling for validated SSO session')
return npmFetch.json(
'/-/whoami', opts.concat({registry, forceAuth: {token}})
'/-/whoami', { ...opts, registry, forceAuth: { token } }
).then(
({username}) => username,
err => {
if (err.code === 'E401') {
return sleep(opts['sso-poll-frequency']).then(() => {
return sleep(opts.ssoPollFrequency).then(() => {
return pollForSession(registry, token, opts)
})
} else {
Expand All @@ -67,7 +68,5 @@ function pollForSession (registry, token, opts) {
}

function sleep (time) {
return new BB((resolve) => {
setTimeout(resolve, time)
})
return new Promise((resolve) => setTimeout(resolve, time))
}
33 changes: 21 additions & 12 deletions lib/cache.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
'use strict'
/* eslint-disable standard/no-callback-literal */

const BB = require('bluebird')

const assert = require('assert')
const cacache = require('cacache')
const finished = BB.promisify(require('mississippi').finished)
const { promisify } = 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 output = require('./utils/output.js')
const pacote = require('pacote')
const path = require('path')
const rm = BB.promisify(require('./utils/gently-rm.js'))
const unbuild = BB.promisify(npm.commands.unbuild)
const rimraf = require('rimraf')
const unbuild = promisify(npm.commands.unbuild)

cache.usage = 'npm cache add <tarball file>' +
'\nnpm cache add <folder>' +
Expand Down Expand Up @@ -65,14 +62,14 @@ cache.clean = clean
function clean (args) {
if (!args) args = []
if (args.length) {
return BB.reject(new Error('npm cache clear does not accept arguments'))
return Promise.reject(new Error('npm cache clear does not accept arguments'))
}
const cachePath = path.join(npm.cache, '_cacache')
if (!npm.config.get('force')) {
return BB.reject(new Error("As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead. On the other hand, if you're debugging an issue with the installer, you can use `npm install --cache /tmp/empty-cache` to use a temporary cache instead of nuking the actual one.\n\nIf you're sure you want to delete the entire cache, rerun this command with --force."))
return Promise.reject(new Error("As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead. On the other hand, if you're debugging an issue with the installer, you can use `npm install --cache /tmp/empty-cache` to use a temporary cache instead of nuking the actual one.\n\nIf you're sure you want to delete the entire cache, rerun this command with --force."))
}
// TODO - remove specific packages or package versions
return rm(cachePath)
return rimraf(cachePath)
}

// npm cache add <tarball-url>
Expand Down Expand Up @@ -105,9 +102,13 @@ function add (args, where) {
spec = args[0]
}
log.verbose('cache add', 'spec', spec)
if (!spec) return BB.reject(new Error(usage))
if (!spec) return Promise.reject(new Error(usage))
log.silly('cache add', 'parsed spec', spec)
return finished(pacote.tarball.stream(spec, npmConfig({where})).resume())
const opts = { ...npm.flatOptions, where }
return pacote.tarball.stream(spec, stream => {
stream.resume()
return stream.promise()
}, opts)
}

cache.verify = verify
Expand All @@ -128,10 +129,18 @@ function verify () {
})
}

// XXX is this used anywhere? can it be removed?
cache.unpack = unpack
function unpack (pkg, ver, unpackTarget, dmode, fmode, uid, gid) {
return unbuild([unpackTarget], true).then(() => {
const opts = npmConfig({dmode, fmode, uid, gid, offline: true})
const opts = {
...npm.flatOptions,
dmode,
fmode,
uid,
gid,
offline: true
}
return pacote.extract(npa.resolve(pkg, ver), unpackTarget, opts)
})
}
6 changes: 6 additions & 0 deletions lib/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ Object.defineProperty(exports, 'defaults', {get: function () {
'ham-it-up': false,
heading: 'npm',
'if-present': false,
include: [],
'include-staged': false,
'ignore-prepublish': false,
'ignore-scripts': false,
'init-module': path.resolve(home, '.npm-init.js'),
Expand All @@ -185,6 +187,7 @@ Object.defineProperty(exports, 'defaults', {get: function () {
'node-options': null,
'node-version': process.version,
'offline': false,
omit: [],
'onload-script': false,
only: null,
optional: true,
Expand Down Expand Up @@ -304,6 +307,8 @@ exports.types = {
'ham-it-up': Boolean,
'heading': String,
'if-present': Boolean,
include: [Array, 'dev', 'optional', 'peer'],
'include-staged': Boolean,
'ignore-prepublish': Boolean,
'ignore-scripts': Boolean,
'init-module': path,
Expand All @@ -328,6 +333,7 @@ exports.types = {
'node-version': [null, semver],
'noproxy': [null, String, Array],
offline: Boolean,
omit: [Array, 'dev', 'optional', 'peer'],
'onload-script': [null, String],
only: [null, 'dev', 'development', 'prod', 'production'],
optional: Boolean,
Expand Down
Loading