Skip to content

Commit

Permalink
config: only create config dir before write
Browse files Browse the repository at this point in the history
This change fixes the bug that creates
unnecessary ./etc folder when calling npm
with the --prefix flag.

PR-URL: npm/npm#20212
Credit: @buddydvd
Reviewed-By: @iarna
Fixes: #17322
  • Loading branch information
buddydvd authored and iarna committed Apr 11, 2018
1 parent f9de7ef commit f8ec520
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
21 changes: 13 additions & 8 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ var types = npmconf.defs.types
var ini = require('ini')
var editor = require('editor')
var os = require('os')
var path = require('path')
var mkdirp = require('mkdirp')
var umask = require('./utils/umask')
var usage = require('./utils/usage')
var output = require('./utils/output')
Expand Down Expand Up @@ -114,14 +116,17 @@ function edit (cb) {
}, []))
.concat([''])
.join(os.EOL)
writeFileAtomic(
f,
data,
function (er) {
if (er) return cb(er)
editor(f, { editor: e }, noProgressTillDone(cb))
}
)
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))
}
)
})
})
})
}
Expand Down
11 changes: 2 additions & 9 deletions lib/config/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,17 +155,10 @@ function load_ (builtin, rc, cli, cb) {
// annoying humans and their expectations!
if (conf.get('prefix')) {
var etc = path.resolve(conf.get('prefix'), 'etc')
mkdirp(etc, function () {
defaults.globalconfig = path.resolve(etc, 'npmrc')
defaults.globalignorefile = path.resolve(etc, 'npmignore')
afterUserContinuation()
})
} else {
afterUserContinuation()
defaults.globalconfig = path.resolve(etc, 'npmrc')
defaults.globalignorefile = path.resolve(etc, 'npmignore')
}
}

function afterUserContinuation () {
conf.addFile(conf.get('globalconfig'), 'global')

// move the builtin into the conf stack now.
Expand Down

0 comments on commit f8ec520

Please sign in to comment.