diff options
author | claudiahdz <cghr1990@gmail.com> | 2020-02-19 00:17:29 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-05-08 04:11:51 +0300 |
commit | b9bc4f04019a9c8af266e28d95d38f0d1e25d1f7 (patch) | |
tree | 0c262a7fa0f4f1a0e6b16ac578491a5aaa92b7bc /node_modules/read-package-json-fast | |
parent | 0a30b0d8a1c448b6d89d781ad81f46117d014953 (diff) |
pacote@11.0.0
Diffstat (limited to 'node_modules/read-package-json-fast')
-rw-r--r-- | node_modules/read-package-json-fast/LICENSE | 15 | ||||
-rw-r--r-- | node_modules/read-package-json-fast/README.md | 54 | ||||
-rw-r--r-- | node_modules/read-package-json-fast/index.js | 82 | ||||
-rw-r--r-- | node_modules/read-package-json-fast/package.json | 65 |
4 files changed, 216 insertions, 0 deletions
diff --git a/node_modules/read-package-json-fast/LICENSE b/node_modules/read-package-json-fast/LICENSE new file mode 100644 index 000000000..20a476254 --- /dev/null +++ b/node_modules/read-package-json-fast/LICENSE @@ -0,0 +1,15 @@ +The ISC License + +Copyright (c) npm, Inc. and Contributors + +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. diff --git a/node_modules/read-package-json-fast/README.md b/node_modules/read-package-json-fast/README.md new file mode 100644 index 000000000..e9c209be3 --- /dev/null +++ b/node_modules/read-package-json-fast/README.md @@ -0,0 +1,54 @@ +# read-package-json-fast + +Like [`read-package-json`](http://npm.im/read-package-json), but faster and +more accepting of "missing" data. + +This is only suitable for reading package.json files in a node_modules +tree, since it doesn't do the various cleanups, normalization, and warnings +that are beneficial at the root level in a package being published. + +## USAGE + +```js +const rpj = require('read-package-json-fast') + +// typical promisey type API +rpj('/path/to/package.json') + .then(data => ...) + .catch(er => ...) + +// or just normalize a package manifest +const normalized = rpj.normalize(packageJsonObject) +``` + +Errors raised from parsing will use +[`json-parse-even-better-errors`](http://npm.im/json-parse-even-better-errors), +so they'll be of type `JSONParseError` and have a `code: 'EJSONPARSE'` +property. Errors will also always have a `path` member referring to the +path originally passed into the function. + +## WHAT THIS MODULE DOES + +- Parse JSON +- Normalize `bundledDependencies`/`bundleDependencies` naming to just + `bundleDependencies` (without the extra `d`) +- Handle `true`, `false`, or object values passed to `bundleDependencies` +- Normalize `funding: <string>` to `funding: { url: <string> }` +- Remove any `scripts` members that are not a string value. +- Normalize a string `bin` member to `{ [name]: bin }`. +- Fold `optionalDependencies` into `dependencies`. +- Set the `_id` property if name and version are set. (This is + load-bearing in a few places within the npm CLI.) + +## WHAT THIS MODULE DOES NOT DO + +- Warn about invalid/missing name, version, repository, etc. +- Extract a description from the `README.md` file, or attach the readme to + the parsed data object. +- Read the `HEAD` value out of the `.git` folder. +- Warn about potentially typo'ed scripts (eg, `tset` instead of `test`) +- Check to make sure that all the files in the `files` field exist and are + valid files. +- Fix bundleDependencies that are not listed in `dependencies`. +- Fix `dependencies` fields that are not strictly objects of string values. +- Anything involving the `directories` field (ie, bins, mans, and so on). diff --git a/node_modules/read-package-json-fast/index.js b/node_modules/read-package-json-fast/index.js new file mode 100644 index 000000000..bfef5d6ab --- /dev/null +++ b/node_modules/read-package-json-fast/index.js @@ -0,0 +1,82 @@ +const {promisify} = require('util') +const fs = require('fs') +const readFile = promisify(fs.readFile) +const parse = require('json-parse-even-better-errors') +const rpj = path => readFile(path, 'utf8') + .then(data => normalize(parse(data))) + .catch(er => { + er.path = path + throw er + }) +const normalizePackageBin = require('npm-normalize-package-bin') + +const normalize = data => { + add_id(data) + fixBundled(data) + foldinOptionalDeps(data) + fixScripts(data) + fixFunding(data) + normalizePackageBin(data) + return data +} + +rpj.normalize = normalize + +const add_id = data => { + if (data.name && data.version) + data._id = `${data.name}@${data.version}` + return data +} + +const foldinOptionalDeps = data => { + const od = data.optionalDependencies + if (od && typeof od === 'object') { + data.dependencies = data.dependencies || {} + for (const [name, spec] of Object.entries(od)) { + data.dependencies[name] = spec + } + } + return data +} + +const fixBundled = data => { + const bdd = data.bundledDependencies + const bd = data.bundleDependencies === undefined ? bdd + : data.bundleDependencies + + if (bd === false) + data.bundleDependencies = [] + else if (bd === true) + data.bundleDependencies = Object.keys(data.dependencies || {}) + else if (bd && typeof bd === 'object') { + if (!Array.isArray(bd)) + data.bundleDependencies = Object.keys(bd) + else + data.bundleDependencies = bd + } else + delete data.bundleDependencies + + delete data.bundledDependencies + return data +} + +const fixScripts = data => { + if (!data.scripts || typeof data.scripts !== 'object') { + delete data.scripts + return data + } + + for (const [name, script] of Object.entries(data.scripts)) { + if (typeof script !== 'string') + delete data.scripts[name] + } + return data +} + +const fixFunding = data => { + if (data.funding && typeof data.funding === 'string') + data.funding = { url: data.funding } + return data +} + +module.exports = rpj diff --git a/node_modules/read-package-json-fast/package.json b/node_modules/read-package-json-fast/package.json new file mode 100644 index 000000000..de166a8f2 --- /dev/null +++ b/node_modules/read-package-json-fast/package.json @@ -0,0 +1,65 @@ +{ + "_from": "read-package-json-fast@^1.1.3", + "_id": "read-package-json-fast@1.1.3", + "_inBundle": false, + "_integrity": "sha512-MmFqiyfCXV2Dmm4jH24DEGhxdkUDFivJQj4oPZQPOKywxR7HWBE6WnMWDAapfFHi3wm1b+mhR+XHlUH0CL8axg==", + "_location": "/read-package-json-fast", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "read-package-json-fast@^1.1.3", + "name": "read-package-json-fast", + "escapedName": "read-package-json-fast", + "rawSpec": "^1.1.3", + "saveSpec": null, + "fetchSpec": "^1.1.3" + }, + "_requiredBy": [ + "/@npmcli/installed-package-contents", + "/pacote" + ], + "_resolved": "https://registry.npmjs.org/read-package-json-fast/-/read-package-json-fast-1.1.3.tgz", + "_shasum": "3b78464ea8f3c4447f3358635390b6946dc0737e", + "_spec": "read-package-json-fast@^1.1.3", + "_where": "/Users/claudiahdz/npm/cli/node_modules/pacote", + "author": { + "name": "Isaac Z. Schlueter", + "email": "i@izs.me", + "url": "https://izs.me" + }, + "bugs": { + "url": "https://github.com/npm/read-package-json-fast/issues" + }, + "bundleDependencies": false, + "dependencies": { + "json-parse-even-better-errors": "^2.0.1", + "npm-normalize-package-bin": "^1.0.1" + }, + "deprecated": false, + "description": "Like read-package-json, but faster", + "devDependencies": { + "tap": "^14.10.1" + }, + "files": [ + "index.js" + ], + "homepage": "https://github.com/npm/read-package-json-fast#readme", + "license": "ISC", + "name": "read-package-json-fast", + "repository": { + "type": "git", + "url": "git+https://github.com/npm/read-package-json-fast.git" + }, + "scripts": { + "postpublish": "git push origin --follow-tags", + "postversion": "npm publish", + "preversion": "npm test", + "snap": "tap", + "test": "tap" + }, + "tap": { + "check-coverage": true + }, + "version": "1.1.3" +} |