Skip to content

Commit 7fbf6f7

Browse files
committed
1 parent 7c7f656 commit 7fbf6f7

File tree

7 files changed

+138
-10
lines changed

7 files changed

+138
-10
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
The ISC License
2+
3+
Copyright (c) npm, Inc.
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
15+
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// pass in a manifest with a 'bin' field here, and it'll turn it
2+
// into a properly santized bin object
3+
const { join, basename } = require('path')
4+
5+
const normalize = pkg =>
6+
!pkg.bin ? removeBin(pkg)
7+
: typeof pkg.bin === 'string' ? normalizeString(pkg)
8+
: Array.isArray(pkg.bin) ? normalizeArray(pkg)
9+
: typeof pkg.bin === 'object' ? normalizeObject(pkg)
10+
: removeBin(pkg)
11+
12+
const normalizeString = pkg => {
13+
if (!pkg.name) {
14+
return removeBin(pkg)
15+
}
16+
pkg.bin = { [pkg.name]: pkg.bin }
17+
return normalizeObject(pkg)
18+
}
19+
20+
const normalizeArray = pkg => {
21+
pkg.bin = pkg.bin.reduce((acc, k) => {
22+
acc[basename(k)] = k
23+
return acc
24+
}, {})
25+
return normalizeObject(pkg)
26+
}
27+
28+
const removeBin = pkg => {
29+
delete pkg.bin
30+
return pkg
31+
}
32+
33+
const normalizeObject = pkg => {
34+
const orig = pkg.bin
35+
const clean = {}
36+
let hasBins = false
37+
Object.keys(orig).forEach(binKey => {
38+
const base = join('/', basename(binKey.replace(/\\|:/g, '/'))).slice(1)
39+
40+
if (typeof orig[binKey] !== 'string' || !base) {
41+
return
42+
}
43+
44+
const binTarget = join('/', orig[binKey])
45+
.replace(/\\/g, '/').slice(1)
46+
47+
if (!binTarget) {
48+
return
49+
}
50+
51+
clean[base] = binTarget
52+
hasBins = true
53+
})
54+
55+
if (hasBins) {
56+
pkg.bin = clean
57+
} else {
58+
delete pkg.bin
59+
}
60+
61+
return pkg
62+
}
63+
64+
module.exports = normalize
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "npm-normalize-package-bin",
3+
"version": "2.0.0",
4+
"description": "Turn any flavor of allowable package.json bin into a normalized object",
5+
"main": "lib/index.js",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/npm/npm-normalize-package-bin.git"
9+
},
10+
"author": "GitHub Inc.",
11+
"license": "ISC",
12+
"scripts": {
13+
"test": "tap",
14+
"snap": "tap",
15+
"preversion": "npm test",
16+
"postversion": "npm publish",
17+
"postpublish": "git push origin --follow-tags",
18+
"lint": "eslint \"**/*.js\"",
19+
"postlint": "template-oss-check",
20+
"template-oss-apply": "template-oss-apply --force",
21+
"lintfix": "npm run lint -- --fix",
22+
"prepublishOnly": "git push origin --follow-tags",
23+
"posttest": "npm run lint"
24+
},
25+
"devDependencies": {
26+
"@npmcli/eslint-config": "^3.1.0",
27+
"@npmcli/template-oss": "3.5.0",
28+
"tap": "^16.3.0"
29+
},
30+
"files": [
31+
"bin/",
32+
"lib/"
33+
],
34+
"engines": {
35+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
36+
},
37+
"templateOSS": {
38+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
39+
"version": "3.5.0"
40+
}
41+
}

node_modules/bin-links/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bin-links",
3-
"version": "3.0.2",
3+
"version": "3.0.3",
44
"description": "JavaScript package binary linker",
55
"main": "./lib/index.js",
66
"scripts": {
@@ -28,7 +28,7 @@
2828
"dependencies": {
2929
"cmd-shim": "^5.0.0",
3030
"mkdirp-infer-owner": "^2.0.0",
31-
"npm-normalize-package-bin": "^1.0.0",
31+
"npm-normalize-package-bin": "^2.0.0",
3232
"read-cmd-shim": "^3.0.0",
3333
"rimraf": "^3.0.0",
3434
"write-file-atomic": "^4.0.0"

package-lock.json

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,13 +1544,13 @@
15441544
}
15451545
},
15461546
"node_modules/bin-links": {
1547-
"version": "3.0.2",
1548-
"resolved": "https://registry.npmjs.org/bin-links/-/bin-links-3.0.2.tgz",
1549-
"integrity": "sha512-+oSWBdbCUK6X4LOCSrU36fWRzZNaK7/evX7GozR9xwl2dyiVi3UOUwTyyOVYI1FstgugfsM9QESRrWo7gjCYbg==",
1547+
"version": "3.0.3",
1548+
"resolved": "https://registry.npmjs.org/bin-links/-/bin-links-3.0.3.tgz",
1549+
"integrity": "sha512-zKdnMPWEdh4F5INR07/eBrodC7QrF5JKvqskjz/ZZRXg5YSAZIbn8zGhbhUrElzHBZ2fvEQdOU59RHcTG3GiwA==",
15501550
"dependencies": {
15511551
"cmd-shim": "^5.0.0",
15521552
"mkdirp-infer-owner": "^2.0.0",
1553-
"npm-normalize-package-bin": "^1.0.0",
1553+
"npm-normalize-package-bin": "^2.0.0",
15541554
"read-cmd-shim": "^3.0.0",
15551555
"rimraf": "^3.0.0",
15561556
"write-file-atomic": "^4.0.0"
@@ -1559,6 +1559,14 @@
15591559
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
15601560
}
15611561
},
1562+
"node_modules/bin-links/node_modules/npm-normalize-package-bin": {
1563+
"version": "2.0.0",
1564+
"resolved": "https://registry.npmjs.org/npm-normalize-package-bin/-/npm-normalize-package-bin-2.0.0.tgz",
1565+
"integrity": "sha512-awzfKUO7v0FscrSpRoogyNm0sajikhBWpU0QMrW09AMi9n1PoKU6WaIqUzuJSQnpciZZmJ/jMZ2Egfmb/9LiWQ==",
1566+
"engines": {
1567+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
1568+
}
1569+
},
15621570
"node_modules/binary-extensions": {
15631571
"version": "2.2.0",
15641572
"license": "MIT",
@@ -10510,7 +10518,7 @@
1051010518
"@npmcli/package-json": "^2.0.0",
1051110519
"@npmcli/query": "^1.2.0",
1051210520
"@npmcli/run-script": "^4.1.3",
10513-
"bin-links": "^3.0.0",
10521+
"bin-links": "^3.0.3",
1051410522
"cacache": "^16.1.3",
1051510523
"common-ancestor-path": "^1.0.1",
1051610524
"json-parse-even-better-errors": "^2.3.1",
@@ -10617,7 +10625,7 @@
1061710625
"devDependencies": {
1061810626
"@npmcli/eslint-config": "^3.1.0",
1061910627
"@npmcli/template-oss": "3.5.0",
10620-
"bin-links": "^3.0.0",
10628+
"bin-links": "^3.0.3",
1062110629
"minify-registry-metadata": "^2.2.0",
1062210630
"mkdirp": "^1.0.4",
1062310631
"tap": "^16.0.1"

workspaces/arborist/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"@npmcli/package-json": "^2.0.0",
1414
"@npmcli/query": "^1.2.0",
1515
"@npmcli/run-script": "^4.1.3",
16-
"bin-links": "^3.0.0",
16+
"bin-links": "^3.0.3",
1717
"cacache": "^16.1.3",
1818
"common-ancestor-path": "^1.0.1",
1919
"json-parse-even-better-errors": "^2.3.1",

workspaces/libnpmexec/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"devDependencies": {
5252
"@npmcli/eslint-config": "^3.1.0",
5353
"@npmcli/template-oss": "3.5.0",
54-
"bin-links": "^3.0.0",
54+
"bin-links": "^3.0.3",
5555
"minify-registry-metadata": "^2.2.0",
5656
"mkdirp": "^1.0.4",
5757
"tap": "^16.0.1"

0 commit comments

Comments
 (0)