Skip to content

Commit b12ac01

Browse files
committed
1 parent 7fbf6f7 commit b12ac01

File tree

7 files changed

+139
-10
lines changed

7 files changed

+139
-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/npm-pick-manifest/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "npm-pick-manifest",
3-
"version": "7.0.1",
3+
"version": "7.0.2",
44
"description": "Resolves a matching manifest from a package metadata document according to standard npm semver resolution rules.",
55
"main": "./lib",
66
"files": [
@@ -33,7 +33,7 @@
3333
"license": "ISC",
3434
"dependencies": {
3535
"npm-install-checks": "^5.0.0",
36-
"npm-normalize-package-bin": "^1.0.1",
36+
"npm-normalize-package-bin": "^2.0.0",
3737
"npm-package-arg": "^9.0.0",
3838
"semver": "^7.3.5"
3939
},

package-lock.json

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
"npm-audit-report": "^3.0.0",
137137
"npm-install-checks": "^5.0.0",
138138
"npm-package-arg": "^9.1.0",
139-
"npm-pick-manifest": "^7.0.1",
139+
"npm-pick-manifest": "^7.0.2",
140140
"npm-profile": "^6.2.0",
141141
"npm-registry-fetch": "^13.3.1",
142142
"npm-user-validate": "^1.0.1",
@@ -5516,20 +5516,29 @@
55165516
}
55175517
},
55185518
"node_modules/npm-pick-manifest": {
5519-
"version": "7.0.1",
5520-
"resolved": "https://registry.npmjs.org/npm-pick-manifest/-/npm-pick-manifest-7.0.1.tgz",
5521-
"integrity": "sha512-IA8+tuv8KujbsbLQvselW2XQgmXWS47t3CB0ZrzsRZ82DbDfkcFunOaPm4X7qNuhMfq+FmV7hQT4iFVpHqV7mg==",
5519+
"version": "7.0.2",
5520+
"resolved": "https://registry.npmjs.org/npm-pick-manifest/-/npm-pick-manifest-7.0.2.tgz",
5521+
"integrity": "sha512-gk37SyRmlIjvTfcYl6RzDbSmS9Y4TOBXfsPnoYqTHARNgWbyDiCSMLUpmALDj4jjcTZpURiEfsSHJj9k7EV4Rw==",
55225522
"inBundle": true,
55235523
"dependencies": {
55245524
"npm-install-checks": "^5.0.0",
5525-
"npm-normalize-package-bin": "^1.0.1",
5525+
"npm-normalize-package-bin": "^2.0.0",
55265526
"npm-package-arg": "^9.0.0",
55275527
"semver": "^7.3.5"
55285528
},
55295529
"engines": {
55305530
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
55315531
}
55325532
},
5533+
"node_modules/npm-pick-manifest/node_modules/npm-normalize-package-bin": {
5534+
"version": "2.0.0",
5535+
"resolved": "https://registry.npmjs.org/npm-normalize-package-bin/-/npm-normalize-package-bin-2.0.0.tgz",
5536+
"integrity": "sha512-awzfKUO7v0FscrSpRoogyNm0sajikhBWpU0QMrW09AMi9n1PoKU6WaIqUzuJSQnpciZZmJ/jMZ2Egfmb/9LiWQ==",
5537+
"inBundle": true,
5538+
"engines": {
5539+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
5540+
}
5541+
},
55335542
"node_modules/npm-profile": {
55345543
"version": "6.2.1",
55355544
"resolved": "https://registry.npmjs.org/npm-profile/-/npm-profile-6.2.1.tgz",
@@ -10529,7 +10538,7 @@
1052910538
"nopt": "^6.0.0",
1053010539
"npm-install-checks": "^5.0.0",
1053110540
"npm-package-arg": "^9.0.0",
10532-
"npm-pick-manifest": "^7.0.0",
10541+
"npm-pick-manifest": "^7.0.2",
1053310542
"npm-registry-fetch": "^13.0.0",
1053410543
"npmlog": "^6.0.2",
1053510544
"pacote": "^13.6.1",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
"npm-audit-report": "^3.0.0",
102102
"npm-install-checks": "^5.0.0",
103103
"npm-package-arg": "^9.1.0",
104-
"npm-pick-manifest": "^7.0.1",
104+
"npm-pick-manifest": "^7.0.2",
105105
"npm-profile": "^6.2.0",
106106
"npm-registry-fetch": "^13.3.1",
107107
"npm-user-validate": "^1.0.1",

workspaces/arborist/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"nopt": "^6.0.0",
2525
"npm-install-checks": "^5.0.0",
2626
"npm-package-arg": "^9.0.0",
27-
"npm-pick-manifest": "^7.0.0",
27+
"npm-pick-manifest": "^7.0.2",
2828
"npm-registry-fetch": "^13.0.0",
2929
"npmlog": "^6.0.2",
3030
"pacote": "^13.6.1",

0 commit comments

Comments
 (0)