Skip to content

Commit 7c7f656

Browse files
committed
deps: read-package-json@5.0.2
1 parent 26d2e55 commit 7c7f656

File tree

6 files changed

+139
-10
lines changed

6 files changed

+139
-10
lines changed
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.
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
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/read-package-json/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "read-package-json",
3-
"version": "5.0.1",
3+
"version": "5.0.2",
44
"author": "GitHub Inc.",
55
"description": "The thing npm uses to read package.json files with semantics and defaults and validation",
66
"repository": {
@@ -29,11 +29,11 @@
2929
"glob": "^8.0.1",
3030
"json-parse-even-better-errors": "^2.3.1",
3131
"normalize-package-data": "^4.0.0",
32-
"npm-normalize-package-bin": "^1.0.1"
32+
"npm-normalize-package-bin": "^2.0.0"
3333
},
3434
"devDependencies": {
3535
"@npmcli/eslint-config": "^3.0.1",
36-
"@npmcli/template-oss": "3.4.1",
36+
"@npmcli/template-oss": "3.6.0",
3737
"tap": "^16.0.1"
3838
},
3939
"license": "ISC",
@@ -52,6 +52,6 @@
5252
},
5353
"templateOSS": {
5454
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
55-
"version": "3.4.1"
55+
"version": "3.6.0"
5656
}
5757
}

package-lock.json

+14-5
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
"proc-log": "^2.0.1",
149149
"qrcode-terminal": "^0.12.0",
150150
"read": "~1.0.7",
151-
"read-package-json": "^5.0.1",
151+
"read-package-json": "^5.0.2",
152152
"read-package-json-fast": "^2.0.3",
153153
"readdir-scoped-modules": "^1.1.0",
154154
"rimraf": "^3.0.2",
@@ -6453,15 +6453,15 @@
64536453
}
64546454
},
64556455
"node_modules/read-package-json": {
6456-
"version": "5.0.1",
6457-
"resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-5.0.1.tgz",
6458-
"integrity": "sha512-MALHuNgYWdGW3gKzuNMuYtcSSZbGQm94fAp16xt8VsYTLBjUSc55bLMKe6gzpWue0Tfi6CBgwCSdDAqutGDhMg==",
6456+
"version": "5.0.2",
6457+
"resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-5.0.2.tgz",
6458+
"integrity": "sha512-BSzugrt4kQ/Z0krro8zhTwV1Kd79ue25IhNN/VtHFy1mG/6Tluyi+msc0UpwaoQzxSHa28mntAjIZY6kEgfR9Q==",
64596459
"inBundle": true,
64606460
"dependencies": {
64616461
"glob": "^8.0.1",
64626462
"json-parse-even-better-errors": "^2.3.1",
64636463
"normalize-package-data": "^4.0.0",
6464-
"npm-normalize-package-bin": "^1.0.1"
6464+
"npm-normalize-package-bin": "^2.0.0"
64656465
},
64666466
"engines": {
64676467
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
@@ -6479,6 +6479,15 @@
64796479
"node": ">=10"
64806480
}
64816481
},
6482+
"node_modules/read-package-json/node_modules/npm-normalize-package-bin": {
6483+
"version": "2.0.0",
6484+
"resolved": "https://registry.npmjs.org/npm-normalize-package-bin/-/npm-normalize-package-bin-2.0.0.tgz",
6485+
"integrity": "sha512-awzfKUO7v0FscrSpRoogyNm0sajikhBWpU0QMrW09AMi9n1PoKU6WaIqUzuJSQnpciZZmJ/jMZ2Egfmb/9LiWQ==",
6486+
"inBundle": true,
6487+
"engines": {
6488+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
6489+
}
6490+
},
64826491
"node_modules/read-package-tree": {
64836492
"version": "5.3.1",
64846493
"dev": true,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"proc-log": "^2.0.1",
114114
"qrcode-terminal": "^0.12.0",
115115
"read": "~1.0.7",
116-
"read-package-json": "^5.0.1",
116+
"read-package-json": "^5.0.2",
117117
"read-package-json-fast": "^2.0.3",
118118
"readdir-scoped-modules": "^1.1.0",
119119
"rimraf": "^3.0.2",

0 commit comments

Comments
 (0)