Skip to content

Commit 79fc706

Browse files
committed
1 parent ad99360 commit 79fc706

File tree

10 files changed

+159
-119
lines changed

10 files changed

+159
-119
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ const checkShim = async ({ target, path }) => {
5757
target + '.cmd',
5858
target + '.ps1',
5959
]
60-
await Promise.all(shims.map(async target => {
61-
const current = await readCmdShim(target)
62-
.catch(er => handleReadCmdShimError({ er, target }))
60+
await Promise.all(shims.map(async shim => {
61+
const current = await readCmdShim(shim)
62+
.catch(er => handleReadCmdShimError({ er, target: shim }))
6363

6464
if (!current) {
6565
return
6666
}
6767

68-
const resolved = resolve(dirname(target), current.replace(/\\/g, '/'))
68+
const resolved = resolve(dirname(shim), current.replace(/\\/g, '/'))
6969

7070
if (resolved.toLowerCase().indexOf(path.toLowerCase()) !== 0) {
71-
return failEEXIST({ target })
71+
return failEEXIST({ target: shim })
7272
}
7373
}))
7474
}

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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, extname } = require('path')
77
const isWindows = require('./is-windows.js')
88
module.exports = ({ path, pkg, global, top }) => {
99
if (top && !global) {
@@ -27,23 +27,14 @@ module.exports = ({ path, pkg, global, top }) => {
2727
const manSet = []
2828
if (manTarg && pkg.man && Array.isArray(pkg.man) && pkg.man.length) {
2929
for (const man of pkg.man) {
30-
const parseMan = man.match(/(.*\.([0-9]+)(\.gz)?)$/)
31-
// invalid entries invalidate the entire man set
32-
if (!parseMan) {
30+
if (!/.\.[0-9]+(\.gz)?$/.test(man)) {
3331
return binSet
3432
}
3533

36-
const stem = parseMan[1]
37-
const sxn = parseMan[2]
38-
const base = basename(stem)
39-
const absFrom = resolve(path, man)
34+
const section = extname(basename(man, '.gz')).slice(1)
35+
const base = basename(man)
4036

41-
/* istanbul ignore if - should be impossible */
42-
if (absFrom.indexOf(path) !== 0) {
43-
return binSet
44-
}
45-
46-
manSet.push(resolve(manTarg, 'man' + sxn, base))
37+
manSet.push(resolve(manTarg, 'man' + section, base))
4738
}
4839
}
4940

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const linkMans = ({ path, pkg, top, force }) => {
1111
// break any links to c:\\blah or /foo/blah or ../blah
1212
// and filter out duplicates
1313
const set = [...new Set(pkg.man.map(man =>
14-
man ? join('/', man).replace(/\\|:/g, '/').substr(1) : null)
14+
man ? join('/', man).replace(/\\|:/g, '/').slice(1) : null)
1515
.filter(man => typeof man === 'string'))]
1616

1717
return Promise.all(set.map(man => {

node_modules/bin-links/package.json

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bin-links",
3-
"version": "3.0.0",
3+
"version": "3.0.1",
44
"description": "JavaScript package binary linker",
55
"main": "./lib/index.js",
66
"scripts": {
@@ -9,14 +9,15 @@
99
"prepublishOnly": "git push origin --follow-tags",
1010
"snap": "tap",
1111
"test": "tap",
12-
"lint": "eslint '**/*.js'",
13-
"postlint": "npm-template-check",
12+
"lint": "eslint \"**/*.js\"",
13+
"postlint": "template-oss-check",
1414
"lintfix": "npm run lint -- --fix",
15-
"posttest": "npm run lint"
15+
"posttest": "npm run lint",
16+
"template-oss-apply": "template-oss-apply --force"
1617
},
1718
"repository": {
1819
"type": "git",
19-
"url": "git://github.com/npm/bin-links.git"
20+
"url": "https://github.com/npm/bin-links.git"
2021
},
2122
"keywords": [
2223
"npm",
@@ -25,15 +26,16 @@
2526
],
2627
"license": "ISC",
2728
"dependencies": {
28-
"cmd-shim": "^4.0.1",
29+
"cmd-shim": "^5.0.0",
2930
"mkdirp-infer-owner": "^2.0.0",
3031
"npm-normalize-package-bin": "^1.0.0",
31-
"read-cmd-shim": "^2.0.0",
32+
"read-cmd-shim": "^3.0.0",
3233
"rimraf": "^3.0.0",
3334
"write-file-atomic": "^4.0.0"
3435
},
3536
"devDependencies": {
36-
"@npmcli/template-oss": "^2.5.0",
37+
"@npmcli/eslint-config": "^3.0.1",
38+
"@npmcli/template-oss": "3.2.2",
3739
"mkdirp": "^1.0.3",
3840
"require-inject": "^1.4.4",
3941
"tap": "^15.0.10"
@@ -43,15 +45,16 @@
4345
"coverage-map": "map.js"
4446
},
4547
"files": [
46-
"bin",
47-
"lib"
48+
"bin/",
49+
"lib/"
4850
],
4951
"engines": {
50-
"node": "^12.13.0 || ^14.15.0 || >=16"
52+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
5153
},
5254
"author": "GitHub Inc.",
5355
"templateOSS": {
56+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
5457
"windowsCI": false,
55-
"version": "2.5.0"
58+
"version": "3.2.2"
5659
}
5760
}

node_modules/cmd-shim/index.js renamed to node_modules/cmd-shim/lib/index.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@
88
// Write a binroot/pkg.bin + ".cmd" file that has this line in it:
99
// @<prog> <args...> %dp0%<target> %*
1010

11-
const {promisify} = require('util')
11+
const { promisify } = require('util')
1212
const fs = require('fs')
1313
const writeFile = promisify(fs.writeFile)
1414
const readFile = promisify(fs.readFile)
1515
const chmod = promisify(fs.chmod)
1616
const stat = promisify(fs.stat)
1717
const unlink = promisify(fs.unlink)
1818

19-
const {dirname, relative} = require('path')
19+
const { dirname, relative } = require('path')
2020
const mkdir = require('mkdirp-infer-owner')
21-
const toBatchSyntax = require('./lib/to-batch-syntax')
22-
const shebangExpr = /^#\!\s*(?:\/usr\/bin\/env)?\s*([^ \t]+=[^ \t]+\s+)*\s*([^ \t]+)(.*)$/
21+
const toBatchSyntax = require('./to-batch-syntax')
22+
const shebangExpr = /^#!\s*(?:\/usr\/bin\/env\s*((?:[^ \t=]+=[^ \t=]+\s+)*))?([^ \t]+)(.*)$/
2323

2424
const cmdShimIfExists = (from, to) =>
2525
stat(from).then(() => cmdShim(from, to), () => {})
@@ -47,14 +47,15 @@ const writeShim = (from, to) =>
4747
.then(data => {
4848
const firstLine = data.trim().split(/\r*\n/)[0]
4949
const shebang = firstLine.match(shebangExpr)
50-
if (!shebang) return writeShim_(from, to)
50+
if (!shebang) {
51+
return writeShim_(from, to)
52+
}
5153
const vars = shebang[1] || ''
5254
const prog = shebang[2]
5355
const args = shebang[3] || ''
5456
return writeShim_(from, to, prog, args, vars)
5557
}, er => writeShim_(from, to))
5658

57-
5859
const writeShim_ = (from, to, prog, args, variables) => {
5960
let shTarget = relative(dirname(to), from)
6061
let target = shTarget.split('/').join('\\')
@@ -94,8 +95,8 @@ const writeShim_ = (from, to, prog, args, variables) => {
9495

9596
let cmd
9697
if (longProg) {
97-
shLongProg = shLongProg.trim();
98-
args = args.trim();
98+
shLongProg = shLongProg.trim()
99+
args = args.trim()
99100
const variablesBatch = toBatchSyntax.convertToSetCommands(variables)
100101
cmd = head
101102
+ variablesBatch
@@ -110,7 +111,7 @@ const writeShim_ = (from, to, prog, args, variables) => {
110111
// prevent "Terminate Batch Job? (Y/n)" message
111112
// https://github.com/npm/cli/issues/969#issuecomment-737496588
112113
+ 'endLocal & goto #_undefined_# 2>NUL || title %COMSPEC% & '
113-
+ `"%_prog%" ${args} ${target} %*\r\n`
114+
+ `"%_prog%" ${args} ${target} %*\r\n`
114115
} else {
115116
cmd = `${head}${prog} ${args} ${target} %*\r\n`
116117
}
@@ -128,7 +129,7 @@ const writeShim_ = (from, to, prog, args, variables) => {
128129
// exec node "$basedir/node_modules/npm/bin/npm-cli.js" "$@"
129130
// fi
130131

131-
let sh = "#!/bin/sh\n"
132+
let sh = '#!/bin/sh\n'
132133

133134
sh = sh
134135
+ `basedir=$(dirname "$(echo "$0" | sed -e 's,\\\\,/,g')")\n`
@@ -182,7 +183,7 @@ const writeShim_ = (from, to, prog, args, variables) => {
182183
+ '$basedir=Split-Path $MyInvocation.MyCommand.Definition -Parent\n'
183184
+ '\n'
184185
+ '$exe=""\n'
185-
+ 'if ($PSVersionTable.PSVersion -lt \"6.0\" -or $IsWindows) {\n'
186+
+ 'if ($PSVersionTable.PSVersion -lt "6.0" -or $IsWindows) {\n'
186187
+ ' # Fix case when both the Windows and Linux builds of Node\n'
187188
+ ' # are installed in the same directory\n'
188189
+ ' $exe=".exe"\n'

node_modules/cmd-shim/lib/to-batch-syntax.js

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,48 @@ exports.replaceDollarWithPercentPair = replaceDollarWithPercentPair
22
exports.convertToSetCommand = convertToSetCommand
33
exports.convertToSetCommands = convertToSetCommands
44

5-
function convertToSetCommand(key, value) {
6-
var line = ""
7-
key = key || ""
8-
key = key.trim()
9-
value = value || ""
10-
value = value.trim()
11-
if(key && value && value.length > 0) {
12-
line = "@SET " + key + "=" + replaceDollarWithPercentPair(value) + "\r\n"
13-
}
14-
return line
5+
function convertToSetCommand (key, value) {
6+
var line = ''
7+
key = key || ''
8+
key = key.trim()
9+
value = value || ''
10+
value = value.trim()
11+
if (key && value && value.length > 0) {
12+
line = '@SET ' + key + '=' + replaceDollarWithPercentPair(value) + '\r\n'
13+
}
14+
return line
1515
}
1616

17-
function extractVariableValuePairs(declarations) {
18-
var pairs = {}
19-
declarations.map(function(declaration) {
20-
var split = declaration.split("=")
21-
pairs[split[0]]=split[1]
22-
})
23-
return pairs
17+
function extractVariableValuePairs (declarations) {
18+
var pairs = {}
19+
declarations.map(function (declaration) {
20+
var split = declaration.split('=')
21+
pairs[split[0]] = split[1]
22+
})
23+
return pairs
2424
}
2525

26-
function convertToSetCommands(variableString) {
27-
var variableValuePairs = extractVariableValuePairs(variableString.split(" "))
28-
var variableDeclarationsAsBatch = ""
29-
Object.keys(variableValuePairs).forEach(function (key) {
30-
variableDeclarationsAsBatch += convertToSetCommand(key, variableValuePairs[key])
31-
})
32-
return variableDeclarationsAsBatch
26+
function convertToSetCommands (variableString) {
27+
var variableValuePairs = extractVariableValuePairs(variableString.split(' '))
28+
var variableDeclarationsAsBatch = ''
29+
Object.keys(variableValuePairs).forEach(function (key) {
30+
variableDeclarationsAsBatch += convertToSetCommand(key, variableValuePairs[key])
31+
})
32+
return variableDeclarationsAsBatch
3333
}
3434

35-
function replaceDollarWithPercentPair(value) {
36-
var dollarExpressions = /\$\{?([^\$@#\?\- \t{}:]+)\}?/g
37-
var result = ""
38-
var startIndex = 0
39-
do {
40-
var match = dollarExpressions.exec(value)
41-
if(match) {
42-
var betweenMatches = value.substring(startIndex, match.index) || ""
43-
result += betweenMatches + "%" + match[1] + "%"
44-
startIndex = dollarExpressions.lastIndex
45-
}
46-
} while (dollarExpressions.lastIndex > 0)
47-
result += value.substr(startIndex)
48-
return result
35+
function replaceDollarWithPercentPair (value) {
36+
var dollarExpressions = /\$\{?([^$@#?\- \t{}:]+)\}?/g
37+
var result = ''
38+
var startIndex = 0
39+
do {
40+
var match = dollarExpressions.exec(value)
41+
if (match) {
42+
var betweenMatches = value.substring(startIndex, match.index) || ''
43+
result += betweenMatches + '%' + match[1] + '%'
44+
startIndex = dollarExpressions.lastIndex
45+
}
46+
} while (dollarExpressions.lastIndex > 0)
47+
result += value.slice(startIndex)
48+
return result
4949
}
50-
51-

node_modules/cmd-shim/package.json

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
{
22
"name": "cmd-shim",
3-
"version": "4.1.0",
3+
"version": "5.0.0",
44
"description": "Used in npm for command line application support",
55
"scripts": {
66
"test": "tap",
77
"snap": "tap",
88
"preversion": "npm test",
99
"postversion": "npm publish",
10-
"postpublish": "git push origin --follow-tags"
10+
"postpublish": "git push origin --follow-tags",
11+
"lint": "eslint \"**/*.js\"",
12+
"postlint": "template-oss-check",
13+
"template-oss-apply": "template-oss-apply --force",
14+
"lintfix": "npm run lint -- --fix",
15+
"prepublishOnly": "git push origin --follow-tags",
16+
"posttest": "npm run lint"
1117
},
1218
"repository": {
1319
"type": "git",
@@ -18,19 +24,27 @@
1824
"mkdirp-infer-owner": "^2.0.0"
1925
},
2026
"devDependencies": {
21-
"rimraf": "~2.2.8",
22-
"tap": "^14.10.6"
27+
"@npmcli/eslint-config": "^3.0.1",
28+
"@npmcli/template-oss": "3.2.2",
29+
"rimraf": "^3.0.2",
30+
"tap": "^16.0.1"
2331
},
2432
"files": [
25-
"index.js",
26-
"lib"
33+
"bin/",
34+
"lib/"
2735
],
36+
"main": "lib/index.js",
2837
"tap": {
2938
"before": "test/00-setup.js",
3039
"after": "test/zz-cleanup.js",
3140
"check-coverage": true
3241
},
3342
"engines": {
34-
"node": ">=10"
43+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
44+
},
45+
"author": "GitHub Inc.",
46+
"templateOSS": {
47+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
48+
"version": "3.2.2"
3549
}
3650
}

node_modules/read-cmd-shim/index.js renamed to node_modules/read-cmd-shim/lib/index.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require('fs')
2-
const {promisify} = require('util')
3-
const {readFileSync} = fs
2+
const { promisify } = require('util')
3+
const { readFileSync } = fs
44
const readFile = promisify(fs.readFile)
55

66
const extractPath = (path, cmdshimContents) => {
@@ -53,15 +53,19 @@ const readCmdShim = path => {
5353
Error.captureStackTrace(er, readCmdShim)
5454
return readFile(path).then(contents => {
5555
const destination = extractPath(path, contents.toString())
56-
if (destination) return destination
56+
if (destination) {
57+
return destination
58+
}
5759
return Promise.reject(notaShim(path, er))
5860
}, readFileEr => Promise.reject(wrapError(readFileEr, er)))
5961
}
6062

6163
const readCmdShimSync = path => {
6264
const contents = readFileSync(path)
6365
const destination = extractPath(path, contents.toString())
64-
if (!destination) throw notaShim(path)
66+
if (!destination) {
67+
throw notaShim(path)
68+
}
6569
return destination
6670
}
6771

0 commit comments

Comments
 (0)