diff options
author | David Hu <davidjhu@gmail.com> | 2018-03-31 03:58:08 +0300 |
---|---|---|
committer | Rebecca Turner <me@re-becca.org> | 2018-04-11 04:22:24 +0300 |
commit | f8ec520732bda687bc58d9da0873dadb2d65ca96 (patch) | |
tree | e1bfbeda64497ce819ba59fd0190157686733d2c /lib/config.js | |
parent | f9de7ef3a1089ceb2610cd27bbd4b4bc2979c4de (diff) |
config: only create config dir before write
This change fixes the bug that creates
unnecessary ./etc folder when calling npm
with the --prefix flag.
PR-URL: https://github.com/npm/npm/pull/20212
Credit: @buddydvd
Reviewed-By: @iarna
Fixes: #17322
Diffstat (limited to 'lib/config.js')
-rw-r--r-- | lib/config.js | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/config.js b/lib/config.js index a6862808f..0d4161d3b 100644 --- a/lib/config.js +++ b/lib/config.js @@ -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') @@ -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)) + } + ) + }) }) }) } |