fix(cli): only write npmrc when necessary

This commit is contained in:
Stephan Bönnemann 2015-07-14 18:30:30 +02:00
parent 0316babf7a
commit caf09c9be0

View File

@ -42,20 +42,23 @@ npmconf.load({}, (err, conf) => {
const registry = conf.get('registry') const registry = conf.get('registry')
const nerfDart = require('./lib/nerf-dart')(registry) const nerfDart = require('./lib/nerf-dart')(registry)
let wroteNpmRc = false
if (env.NPM_TOKEN) { if (env.NPM_TOKEN) {
conf.set(`${nerfDart}:_authToken`, '${NPM_TOKEN}', 'project') conf.set(`${nerfDart}:_authToken`, '${NPM_TOKEN}', 'project')
} else { wroteNpmRc = true
} else if (env.NPM_OLD_TOKEN && env.NPM_EMAIL) {
// Using the old auth token format is not considered part of the public API // Using the old auth token format is not considered part of the public API
// This might go away anytime (i.e. when we have a better testing strategy) // This might go away anytime (i.e. when we have a better testing strategy)
conf.set('_auth', '${NPM_OLD_TOKEN}', 'project') conf.set('_auth', '${NPM_OLD_TOKEN}', 'project')
conf.set('email', '${NPM_EMAIL}', 'project') conf.set('email', '${NPM_EMAIL}', 'project')
wroteNpmRc = true
} }
conf.save('project', (err) => { conf.save('project', (err) => {
if (err) return log.error(PREFIX, 'Failed to save npm config.', err) if (err) return log.error(PREFIX, 'Failed to save npm config.', err)
log.verbose(PREFIX, 'Wrote authToken to .npmrc.') if (wroteNpmRc) log.verbose(PREFIX, 'Wrote authToken to .npmrc.')
require('./pre')(pkg, { require('./pre')(pkg, {
auth: { auth: {
@ -82,6 +85,10 @@ npmconf.load({}, (err, conf) => {
}), null, 2)) }), null, 2))
log.info(PREFIX, `Wrote version ${release.version} to package.json.`) log.info(PREFIX, `Wrote version ${release.version} to package.json.`)
if (options.debug) {
log.error(PREFIX, 'Not publishing in debug mode')
process.exit(1)
}
}) })
}) })
} else if (options.argv.cooked[0] === 'post') { } else if (options.argv.cooked[0] === 'post') {