Skip to content
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

Isaacs/new config #1688

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/npx-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const removed = new Set([
...removedOpts
])

const { types, shorthands } = require('../lib/config/defaults.js')
const { types, shorthands } = require('../lib/utils/config.js')
const npmSwitches = Object.entries(types)
.filter(([key, type]) => type === Boolean ||
(Array.isArray(type) && type.includes(Boolean)))
Expand Down
6 changes: 1 addition & 5 deletions lib/adduser.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,6 @@ const getAuthType = ({ authType }) => {
return type
}

const saveConfig = () => new Promise((resolve, reject) => {
npm.config.save('user', er => er ? reject(er) : resolve())
})

const updateConfig = async ({ newCreds, registry, scope }) => {
npm.config.del('_token', 'user') // prevent legacy pollution

Expand All @@ -53,7 +49,7 @@ const updateConfig = async ({ newCreds, registry, scope }) => {
}

npm.config.setCredentialsByURI(registry, newCreds)
await saveConfig()
await npm.config.save('user')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

}

const adduser = async (args) => {
Expand Down
3 changes: 1 addition & 2 deletions lib/bin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const osenv = require('osenv')
const npm = require('./npm.js')
const output = require('./utils/output.js')
const usageUtil = require('./utils/usage.js')
Expand All @@ -7,7 +6,7 @@ const cmd = (args, cb) => bin(args).then(() => cb()).catch(cb)
const usage = usageUtil('bin', 'npm bin [-g]')
const bin = async (args, cb) => {
const b = npm.bin
const PATH = osenv.path()
const PATH = require('./utils/path.js')
output(b)
if (npm.flatOptions.global && !PATH.includes(b)) {
console.error('(not in PATH env variable)')
Expand Down
27 changes: 10 additions & 17 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ module.exports = (process) => {
checkForUnsupportedNode()

const npm = require('../lib/npm.js')
const { defs: { shorthands, types } } = require('../lib/config/core.js')
const errorHandler = require('../lib/utils/error-handler.js')
const nopt = require('nopt')

// if npm is called as "npmg" or "npm_g", then
// run in global mode.
Expand All @@ -29,19 +27,6 @@ module.exports = (process) => {

log.verbose('cli', process.argv)

const conf = nopt(types, shorthands, process.argv)
npm.argv = conf.argv.remain

if (conf.version) {
console.log(npm.version)
return errorHandler.exit(0)
}

if (conf.versions) {
npm.argv = ['version']
conf.usage = false
}

log.info('using', 'npm@%s', npm.version)
log.info('using', 'node@%s', process.version)

Expand All @@ -50,10 +35,18 @@ module.exports = (process) => {

// now actually fire up npm and run the command.
// this is how to use npm programmatically:
conf._exit = true
const updateNotifier = require('../lib/utils/update-notifier.js')
npm.load(conf, async er => {
npm.load(async er => {
if (er) return errorHandler(er)
if (npm.config.get('version', 'cli')) {
console.log(npm.version)
return errorHandler.exit(0)
}

if (npm.config.get('versions', 'cli')) {
npm.argv = ['version']
npm.config.set('usage', false, 'cli')
}

npm.updateNotification = await updateNotifier(npm)

Expand Down
Loading