Skip to content
This repository has been archived by the owner on Aug 11, 2022. It is now read-only.

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: #20212
Credit: @buddydvd
Reviewed-By: @iarna
Fixes: #17322
  • Loading branch information
buddydvd authored and iarna committed Apr 9, 2018
1 parent 50d8391 commit 16d739b
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
Expand Up @@ -9,6 +9,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 @@ -113,14 +115,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
Expand Up @@ -153,17 +153,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 16d739b

Please sign in to comment.