Skip to content

Commit 2ef9f98

Browse files
authored
deps: bin-links@3.0.0 write-file-atomic@4.0.0 (#4254)
* deps: bin-links@3.0.0 * deps: write-file-atomic@4.0.0
1 parent 14a3d95 commit 2ef9f98

File tree

25 files changed

+298
-249
lines changed

25 files changed

+298
-249
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
const isWindows = require('./is-windows.js')
22
const getPrefix = require('./get-prefix.js')
33
const getNodeModules = require('./get-node-modules.js')
4-
const {dirname} = require('path')
4+
const { dirname } = require('path')
55

6-
module.exports = ({top, path}) =>
6+
module.exports = ({ top, path }) =>
77
!top ? getNodeModules(path) + '/.bin'
8-
: isWindows ? getPrefix(path)
9-
: dirname(getPrefix(path)) + '/bin'
8+
: isWindows ? getPrefix(path)
9+
: dirname(getPrefix(path)) + '/bin'

node_modules/bin-links/lib/check-bin.js

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,74 @@
22
// either rejects or resolves to nothing. return value not relevant.
33
const isWindows = require('./is-windows.js')
44
const binTarget = require('./bin-target.js')
5-
const {resolve, dirname} = require('path')
5+
const { resolve, dirname } = require('path')
66
const readCmdShim = require('read-cmd-shim')
77
const fs = require('fs')
8-
const {promisify} = require('util')
8+
const { promisify } = require('util')
99
const readlink = promisify(fs.readlink)
1010

11-
const checkBin = async ({bin, path, top, global, force}) => {
11+
const checkBin = async ({ bin, path, top, global, force }) => {
1212
// always ok to clobber when forced
1313
// always ok to clobber local bins, or when forced
14-
if (force || !global || !top)
14+
if (force || !global || !top) {
1515
return
16+
}
1617

1718
// ok, need to make sure, then
18-
const target = resolve(binTarget({path, top}), bin)
19+
const target = resolve(binTarget({ path, top }), bin)
1920
path = resolve(path)
20-
return isWindows ? checkShim({target, path}) : checkLink({target, path})
21+
return isWindows ? checkShim({ target, path }) : checkLink({ target, path })
2122
}
2223

2324
// only enoent is allowed. anything else is a problem.
24-
const handleReadLinkError = async ({er, target}) =>
25+
const handleReadLinkError = async ({ er, target }) =>
2526
er.code === 'ENOENT' ? null
26-
: failEEXIST({target})
27+
: failEEXIST({ target })
2728

28-
const checkLink = async ({target, path}) => {
29+
const checkLink = async ({ target, path }) => {
2930
const current = await readlink(target)
30-
.catch(er => handleReadLinkError({er, target}))
31+
.catch(er => handleReadLinkError({ er, target }))
3132

32-
if (!current)
33+
if (!current) {
3334
return
35+
}
3436

3537
const resolved = resolve(dirname(target), current)
3638

37-
if (resolved.toLowerCase().indexOf(path.toLowerCase()) !== 0)
38-
return failEEXIST({target})
39+
if (resolved.toLowerCase().indexOf(path.toLowerCase()) !== 0) {
40+
return failEEXIST({ target })
41+
}
3942
}
4043

41-
const handleReadCmdShimError = ({er, target}) =>
44+
const handleReadCmdShimError = ({ er, target }) =>
4245
er.code === 'ENOENT' ? null
43-
: failEEXIST({target})
46+
: failEEXIST({ target })
4447

45-
const failEEXIST = ({target}) =>
48+
const failEEXIST = ({ target }) =>
4649
Promise.reject(Object.assign(new Error('EEXIST: file already exists'), {
4750
path: target,
4851
code: 'EEXIST',
4952
}))
5053

51-
const checkShim = async ({target, path}) => {
54+
const checkShim = async ({ target, path }) => {
5255
const shims = [
5356
target,
5457
target + '.cmd',
5558
target + '.ps1',
5659
]
5760
await Promise.all(shims.map(async target => {
5861
const current = await readCmdShim(target)
59-
.catch(er => handleReadCmdShimError({er, target}))
62+
.catch(er => handleReadCmdShimError({ er, target }))
6063

61-
if (!current)
64+
if (!current) {
6265
return
66+
}
6367

6468
const resolved = resolve(dirname(target), current.replace(/\\/g, '/'))
6569

66-
if (resolved.toLowerCase().indexOf(path.toLowerCase()) !== 0)
67-
return failEEXIST({target})
70+
if (resolved.toLowerCase().indexOf(path.toLowerCase()) !== 0) {
71+
return failEEXIST({ target })
72+
}
6873
}))
6974
}
7075

node_modules/bin-links/lib/check-bins.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ const normalize = require('npm-normalize-package-bin')
33
const checkBins = async ({ pkg, path, top, global, force }) => {
44
// always ok to clobber when forced
55
// always ok to clobber local bins, or when forced
6-
if (force || !global || !top)
6+
if (force || !global || !top) {
77
return
8+
}
89

910
pkg = normalize(pkg)
10-
if (!pkg.bin)
11+
if (!pkg.bin) {
1112
return
13+
}
1214

1315
await Promise.all(Object.keys(pkg.bin)
14-
.map(bin => checkBin({bin, path, top, global, force})))
16+
.map(bin => checkBin({ bin, path, top, global, force })))
1517
}
1618
module.exports = checkBins

node_modules/bin-links/lib/get-node-modules.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
// {prefix}/node_modules/{name}. Can't rely on pkg.name, because
33
// it might be installed as an alias.
44

5-
const {dirname, basename} = require('path')
5+
const { dirname, basename } = require('path')
66
// this gets called a lot and can't change, so memoize it
77
const memo = new Map()
88
module.exports = path => {
9-
if (memo.has(path))
9+
if (memo.has(path)) {
1010
return memo.get(path)
11+
}
1112

1213
const scopeOrNm = dirname(path)
1314
const nm = basename(scopeOrNm) === 'node_modules' ? scopeOrNm

node_modules/bin-links/lib/get-paths.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
// are present, then we can assume that they're associated.
44
const binTarget = require('./bin-target.js')
55
const manTarget = require('./man-target.js')
6-
const {resolve, basename} = require('path')
6+
const { resolve, basename } = require('path')
77
const isWindows = require('./is-windows.js')
8-
module.exports = ({path, pkg, global, top}) => {
9-
if (top && !global)
8+
module.exports = ({ path, pkg, global, top }) => {
9+
if (top && !global) {
1010
return []
11+
}
1112

1213
const binSet = []
13-
const binTarg = binTarget({path, top})
14+
const binTarg = binTarget({ path, top })
1415
if (pkg.bin) {
1516
for (const bin of Object.keys(pkg.bin)) {
1617
const b = resolve(binTarg, bin)
@@ -22,23 +23,25 @@ module.exports = ({path, pkg, global, top}) => {
2223
}
2324
}
2425

25-
const manTarg = manTarget({path, top})
26+
const manTarg = manTarget({ path, top })
2627
const manSet = []
2728
if (manTarg && pkg.man && Array.isArray(pkg.man) && pkg.man.length) {
2829
for (const man of pkg.man) {
2930
const parseMan = man.match(/(.*\.([0-9]+)(\.gz)?)$/)
3031
// invalid entries invalidate the entire man set
31-
if (!parseMan)
32+
if (!parseMan) {
3233
return binSet
34+
}
3335

3436
const stem = parseMan[1]
3537
const sxn = parseMan[2]
3638
const base = basename(stem)
3739
const absFrom = resolve(path, man)
3840

3941
/* istanbul ignore if - should be impossible */
40-
if (absFrom.indexOf(path) !== 0)
42+
if (absFrom.indexOf(path) !== 0) {
4143
return binSet
44+
}
4245

4346
manSet.push(resolve(manTarg, 'man' + sxn, base))
4447
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
const {dirname} = require('path')
1+
const { dirname } = require('path')
22
const getNodeModules = require('./get-node-modules.js')
33
module.exports = path => dirname(getNodeModules(path))

node_modules/bin-links/index.js renamed to node_modules/bin-links/lib/index.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const linkBins = require('./lib/link-bins.js')
2-
const linkMans = require('./lib/link-mans.js')
1+
const linkBins = require('./link-bins.js')
2+
const linkMans = require('./link-mans.js')
33

44
const binLinks = opts => {
55
const { path, pkg, force, global, top } = opts
@@ -14,27 +14,28 @@ const binLinks = opts => {
1414
// non-global top pkgs don't have any bins or mans linked. From here on
1515
// out, if it's top, we know that it's global, so no need to pass that
1616
// option further down the stack.
17-
if (top && !global)
17+
if (top && !global) {
1818
return Promise.resolve()
19+
}
1920

2021
return Promise.all([
2122
// allow clobbering within the local node_modules/.bin folder.
2223
// only global bins are protected in this way, or else it is
2324
// yet another vector for excessive dependency conflicts.
24-
linkBins({path, pkg, top, force: force || !top}),
25-
linkMans({path, pkg, top, force}),
25+
linkBins({ path, pkg, top, force: force || !top }),
26+
linkMans({ path, pkg, top, force }),
2627
])
2728
}
2829

29-
const shimBin = require('./lib/shim-bin.js')
30-
const linkGently = require('./lib/link-gently.js')
30+
const shimBin = require('./shim-bin.js')
31+
const linkGently = require('./link-gently.js')
3132
const resetSeen = () => {
3233
shimBin.resetSeen()
3334
linkGently.resetSeen()
3435
}
3536

36-
const checkBins = require('./lib/check-bins.js')
37-
const getPaths = require('./lib/get-paths.js')
37+
const checkBins = require('./check-bins.js')
38+
const getPaths = require('./get-paths.js')
3839

3940
module.exports = Object.assign(binLinks, {
4041
checkBins,

node_modules/bin-links/lib/link-bin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ const linkGently = require('./link-gently.js')
22
const fixBin = require('./fix-bin.js')
33

44
// linking bins is simple. just symlink, and if we linked it, fix the bin up
5-
const linkBin = ({path, to, from, absFrom, force}) =>
6-
linkGently({path, to, from, absFrom, force})
5+
const linkBin = ({ path, to, from, absFrom, force }) =>
6+
linkGently({ path, to, from, absFrom, force })
77
.then(linked => linked && fixBin(absFrom))
88

99
module.exports = linkBin

node_modules/bin-links/lib/link-bins.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ const { dirname, resolve, relative } = require('path')
44
const linkBin = isWindows ? require('./shim-bin.js') : require('./link-bin.js')
55
const normalize = require('npm-normalize-package-bin')
66

7-
const linkBins = ({path, pkg, top, force}) => {
7+
const linkBins = ({ path, pkg, top, force }) => {
88
pkg = normalize(pkg)
9-
if (!pkg.bin)
9+
if (!pkg.bin) {
1010
return Promise.resolve([])
11+
}
1112
const promises = []
12-
const target = binTarget({path, top})
13+
const target = binTarget({ path, top })
1314
for (const [key, val] of Object.entries(pkg.bin)) {
1415
const to = resolve(target, key)
1516
const absFrom = resolve(path, val)
1617
const from = relative(dirname(to), absFrom)
17-
promises.push(linkBin({path, from, to, absFrom, force}))
18+
promises.push(linkBin({ path, from, to, absFrom, force }))
1819
}
1920
return Promise.all(promises)
2021
}

node_modules/bin-links/lib/link-gently.js

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ const fs = require('fs')
1111
const symlink = promisify(fs.symlink)
1212
const readlink = promisify(fs.readlink)
1313
const lstat = promisify(fs.lstat)
14-
const throwNonEnoent = er => { if (er.code !== 'ENOENT') throw er }
14+
const throwNonEnoent = er => {
15+
if (er.code !== 'ENOENT') {
16+
throw er
17+
}
18+
}
1519

1620
// even in --force mode, we never create a link over a link we've
1721
// already created. you can have multiple packages in a tree trying
@@ -24,11 +28,12 @@ const rimraf = promisify(require('rimraf'))
2428
const rm = path => rimraf(path, { glob: false })
2529

2630
const SKIP = Symbol('skip - missing or already installed')
27-
const CLOBBER = Symbol('clobber - ours or in forceful mode')
31+
const CLOBBER = Symbol('clobber - ours or in forceful mode')
2832

29-
const linkGently = async ({path, to, from, absFrom, force}) => {
30-
if (seen.has(to))
33+
const linkGently = async ({ path, to, from, absFrom, force }) => {
34+
if (seen.has(to)) {
3135
return true
36+
}
3237
seen.add(to)
3338

3439
// if the script or manpage isn't there, just ignore it.
@@ -40,36 +45,42 @@ const linkGently = async ({path, to, from, absFrom, force}) => {
4045
lstat(to).catch(throwNonEnoent),
4146
]).then(([stFrom, stTo]) => {
4247
// not present in package, skip it
43-
if (!stFrom)
48+
if (!stFrom) {
4449
return SKIP
50+
}
4551

4652
// exists! maybe clobber if we can
4753
if (stTo) {
48-
if (!stTo.isSymbolicLink())
54+
if (!stTo.isSymbolicLink()) {
4955
return force && rm(to).then(() => CLOBBER)
56+
}
5057

5158
return readlink(to).then(target => {
52-
if (target === from)
53-
return SKIP // skip it, already set up like we want it.
59+
if (target === from) {
60+
return SKIP
61+
} // skip it, already set up like we want it.
5462

5563
target = resolve(dirname(to), target)
56-
if (target.indexOf(path) === 0 || force)
64+
if (target.indexOf(path) === 0 || force) {
5765
return rm(to).then(() => CLOBBER)
66+
}
5867
})
5968
} else {
6069
// doesn't exist, dir might not either
6170
return mkdirp(dirname(to))
6271
}
6372
})
64-
.then(skipOrClobber => {
65-
if (skipOrClobber === SKIP)
66-
return false
67-
return symlink(from, to, 'file').catch(er => {
68-
if (skipOrClobber === CLOBBER || force)
69-
return rm(to).then(() => symlink(from, to, 'file'))
70-
throw er
71-
}).then(() => true)
72-
})
73+
.then(skipOrClobber => {
74+
if (skipOrClobber === SKIP) {
75+
return false
76+
}
77+
return symlink(from, to, 'file').catch(er => {
78+
if (skipOrClobber === CLOBBER || force) {
79+
return rm(to).then(() => symlink(from, to, 'file'))
80+
}
81+
throw er
82+
}).then(() => true)
83+
})
7384
}
7485

7586
const resetSeen = () => {

0 commit comments

Comments
 (0)