diff options
Diffstat (limited to 'deps/npm/node_modules/bin-links/lib/link-gently.js')
-rw-r--r-- | deps/npm/node_modules/bin-links/lib/link-gently.js | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/deps/npm/node_modules/bin-links/lib/link-gently.js b/deps/npm/node_modules/bin-links/lib/link-gently.js index 6a6e555de7c..671ce38a586 100644 --- a/deps/npm/node_modules/bin-links/lib/link-gently.js +++ b/deps/npm/node_modules/bin-links/lib/link-gently.js @@ -11,7 +11,11 @@ const fs = require('fs') const symlink = promisify(fs.symlink) const readlink = promisify(fs.readlink) const lstat = promisify(fs.lstat) -const throwNonEnoent = er => { if (er.code !== 'ENOENT') throw er } +const throwNonEnoent = er => { + if (er.code !== 'ENOENT') { + throw er + } +} // even in --force mode, we never create a link over a link we've // already created. you can have multiple packages in a tree trying @@ -24,11 +28,12 @@ const rimraf = promisify(require('rimraf')) const rm = path => rimraf(path, { glob: false }) const SKIP = Symbol('skip - missing or already installed') -const CLOBBER = Symbol('clobber - ours or in forceful mode') +const CLOBBER = Symbol('clobber - ours or in forceful mode') -const linkGently = async ({path, to, from, absFrom, force}) => { - if (seen.has(to)) +const linkGently = async ({ path, to, from, absFrom, force }) => { + if (seen.has(to)) { return true + } seen.add(to) // if the script or manpage isn't there, just ignore it. @@ -40,36 +45,42 @@ const linkGently = async ({path, to, from, absFrom, force}) => { lstat(to).catch(throwNonEnoent), ]).then(([stFrom, stTo]) => { // not present in package, skip it - if (!stFrom) + if (!stFrom) { return SKIP + } // exists! maybe clobber if we can if (stTo) { - if (!stTo.isSymbolicLink()) + if (!stTo.isSymbolicLink()) { return force && rm(to).then(() => CLOBBER) + } return readlink(to).then(target => { - if (target === from) - return SKIP // skip it, already set up like we want it. + if (target === from) { + return SKIP + } // skip it, already set up like we want it. target = resolve(dirname(to), target) - if (target.indexOf(path) === 0 || force) + if (target.indexOf(path) === 0 || force) { return rm(to).then(() => CLOBBER) + } }) } else { // doesn't exist, dir might not either return mkdirp(dirname(to)) } }) - .then(skipOrClobber => { - if (skipOrClobber === SKIP) - return false - return symlink(from, to, 'file').catch(er => { - if (skipOrClobber === CLOBBER || force) - return rm(to).then(() => symlink(from, to, 'file')) - throw er - }).then(() => true) - }) + .then(skipOrClobber => { + if (skipOrClobber === SKIP) { + return false + } + return symlink(from, to, 'file').catch(er => { + if (skipOrClobber === CLOBBER || force) { + return rm(to).then(() => symlink(from, to, 'file')) + } + throw er + }).then(() => true) + }) } const resetSeen = () => { |