Skip to content
forked from npm/cli

Commit

Permalink
deps: read-package-json@5.0.2
Browse files Browse the repository at this point in the history
  • Loading branch information
lukekarrys committed Aug 25, 2022
1 parent 26d2e55 commit 7c7f656
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
The ISC License

Copyright (c) npm, Inc.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// pass in a manifest with a 'bin' field here, and it'll turn it
// into a properly santized bin object
const { join, basename } = require('path')

const normalize = pkg =>
!pkg.bin ? removeBin(pkg)
: typeof pkg.bin === 'string' ? normalizeString(pkg)
: Array.isArray(pkg.bin) ? normalizeArray(pkg)
: typeof pkg.bin === 'object' ? normalizeObject(pkg)
: removeBin(pkg)

const normalizeString = pkg => {
if (!pkg.name) {
return removeBin(pkg)
}
pkg.bin = { [pkg.name]: pkg.bin }
return normalizeObject(pkg)
}

const normalizeArray = pkg => {
pkg.bin = pkg.bin.reduce((acc, k) => {
acc[basename(k)] = k
return acc
}, {})
return normalizeObject(pkg)
}

const removeBin = pkg => {
delete pkg.bin
return pkg
}

const normalizeObject = pkg => {
const orig = pkg.bin
const clean = {}
let hasBins = false
Object.keys(orig).forEach(binKey => {
const base = join('/', basename(binKey.replace(/\\|:/g, '/'))).slice(1)

if (typeof orig[binKey] !== 'string' || !base) {
return
}

const binTarget = join('/', orig[binKey])
.replace(/\\/g, '/').slice(1)

if (!binTarget) {
return
}

clean[base] = binTarget
hasBins = true
})

if (hasBins) {
pkg.bin = clean
} else {
delete pkg.bin
}

return pkg
}

module.exports = normalize
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "npm-normalize-package-bin",
"version": "2.0.0",
"description": "Turn any flavor of allowable package.json bin into a normalized object",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "https://github.com/npm/npm-normalize-package-bin.git"
},
"author": "GitHub Inc.",
"license": "ISC",
"scripts": {
"test": "tap",
"snap": "tap",
"preversion": "npm test",
"postversion": "npm publish",
"postpublish": "git push origin --follow-tags",
"lint": "eslint \"**/*.js\"",
"postlint": "template-oss-check",
"template-oss-apply": "template-oss-apply --force",
"lintfix": "npm run lint -- --fix",
"prepublishOnly": "git push origin --follow-tags",
"posttest": "npm run lint"
},
"devDependencies": {
"@npmcli/eslint-config": "^3.1.0",
"@npmcli/template-oss": "3.5.0",
"tap": "^16.3.0"
},
"files": [
"bin/",
"lib/"
],
"engines": {
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "3.5.0"
}
}
8 changes: 4 additions & 4 deletions node_modules/read-package-json/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "read-package-json",
"version": "5.0.1",
"version": "5.0.2",
"author": "GitHub Inc.",
"description": "The thing npm uses to read package.json files with semantics and defaults and validation",
"repository": {
Expand Down Expand Up @@ -29,11 +29,11 @@
"glob": "^8.0.1",
"json-parse-even-better-errors": "^2.3.1",
"normalize-package-data": "^4.0.0",
"npm-normalize-package-bin": "^1.0.1"
"npm-normalize-package-bin": "^2.0.0"
},
"devDependencies": {
"@npmcli/eslint-config": "^3.0.1",
"@npmcli/template-oss": "3.4.1",
"@npmcli/template-oss": "3.6.0",
"tap": "^16.0.1"
},
"license": "ISC",
Expand All @@ -52,6 +52,6 @@
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "3.4.1"
"version": "3.6.0"
}
}
19 changes: 14 additions & 5 deletions package-lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
"proc-log": "^2.0.1",
"qrcode-terminal": "^0.12.0",
"read": "~1.0.7",
"read-package-json": "^5.0.1",
"read-package-json": "^5.0.2",
"read-package-json-fast": "^2.0.3",
"readdir-scoped-modules": "^1.1.0",
"rimraf": "^3.0.2",
Expand Down Expand Up @@ -6453,15 +6453,15 @@
}
},
"node_modules/read-package-json": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-5.0.1.tgz",
"integrity": "sha512-MALHuNgYWdGW3gKzuNMuYtcSSZbGQm94fAp16xt8VsYTLBjUSc55bLMKe6gzpWue0Tfi6CBgwCSdDAqutGDhMg==",
"version": "5.0.2",
"resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-5.0.2.tgz",
"integrity": "sha512-BSzugrt4kQ/Z0krro8zhTwV1Kd79ue25IhNN/VtHFy1mG/6Tluyi+msc0UpwaoQzxSHa28mntAjIZY6kEgfR9Q==",
"inBundle": true,
"dependencies": {
"glob": "^8.0.1",
"json-parse-even-better-errors": "^2.3.1",
"normalize-package-data": "^4.0.0",
"npm-normalize-package-bin": "^1.0.1"
"npm-normalize-package-bin": "^2.0.0"
},
"engines": {
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
Expand All @@ -6479,6 +6479,15 @@
"node": ">=10"
}
},
"node_modules/read-package-json/node_modules/npm-normalize-package-bin": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/npm-normalize-package-bin/-/npm-normalize-package-bin-2.0.0.tgz",
"integrity": "sha512-awzfKUO7v0FscrSpRoogyNm0sajikhBWpU0QMrW09AMi9n1PoKU6WaIqUzuJSQnpciZZmJ/jMZ2Egfmb/9LiWQ==",
"inBundle": true,
"engines": {
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
}
},
"node_modules/read-package-tree": {
"version": "5.3.1",
"dev": true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
"proc-log": "^2.0.1",
"qrcode-terminal": "^0.12.0",
"read": "~1.0.7",
"read-package-json": "^5.0.1",
"read-package-json": "^5.0.2",
"read-package-json-fast": "^2.0.3",
"readdir-scoped-modules": "^1.1.0",
"rimraf": "^3.0.2",
Expand Down

0 comments on commit 7c7f656

Please sign in to comment.