diff --git a/node_modules/json-parse-even-better-errors/CHANGELOG.md b/node_modules/json-parse-even-better-errors/CHANGELOG.md new file mode 100644 index 0000000000000..dfd67330a6aba --- /dev/null +++ b/node_modules/json-parse-even-better-errors/CHANGELOG.md @@ -0,0 +1,50 @@ +# Change Log + +All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +## 2.0.0 + +* Add custom error classes + + +## [1.0.2](https://github.com/npm/json-parse-even-better-errors/compare/v1.0.1...v1.0.2) (2018-03-30) + + +### Bug Fixes + +* **messages:** More friendly messages for non-string ([#1](https://github.com/npm/json-parse-even-better-errors/issues/1)) ([a476d42](https://github.com/npm/json-parse-even-better-errors/commit/a476d42)) + + + + +## [1.0.1](https://github.com/npm/json-parse-even-better-errors/compare/v1.0.0...v1.0.1) (2017-08-16) + + +### Bug Fixes + +* **license:** oops. Forgot to update license.md ([efe2958](https://github.com/npm/json-parse-even-better-errors/commit/efe2958)) + + + + +# 1.0.0 (2017-08-15) + + +### Features + +* **init:** Initial Commit ([562c977](https://github.com/npm/json-parse-even-better-errors/commit/562c977)) + + +### BREAKING CHANGES + +* **init:** This is the first commit! + + + + +# 0.1.0 (2017-08-15) + + +### Features + +* **init:** Initial Commit ([9dd1a19](https://github.com/npm/json-parse-even-better-errors/commit/9dd1a19)) diff --git a/node_modules/json-parse-even-better-errors/LICENSE.md b/node_modules/json-parse-even-better-errors/LICENSE.md new file mode 100644 index 0000000000000..6991b7cbb89db --- /dev/null +++ b/node_modules/json-parse-even-better-errors/LICENSE.md @@ -0,0 +1,25 @@ +Copyright 2017 Kat Marchán +Copyright npm, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a +copy of this software and associated documentation files (the "Software"), +to deal in the Software without restriction, including without limitation +the rights to use, copy, modify, merge, publish, distribute, sublicense, +and/or sell copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + +--- + +This library is a fork of 'better-json-errors' by Kat Marchán, extended and +distributed under the terms of the MIT license above. diff --git a/node_modules/json-parse-even-better-errors/README.md b/node_modules/json-parse-even-better-errors/README.md new file mode 100644 index 0000000000000..2799efe69ec84 --- /dev/null +++ b/node_modules/json-parse-even-better-errors/README.md @@ -0,0 +1,96 @@ +# json-parse-even-better-errors + +[`json-parse-even-better-errors`](https://github.com/npm/json-parse-even-better-errors) +is a Node.js library for getting nicer errors out of `JSON.parse()`, +including context and position of the parse errors. + +It also preserves the newline and indentation styles of the JSON data, by +putting them in the object or array in the `Symbol.for('indent')` and +`Symbol.for('newline')` properties. + +## Install + +`$ npm install --save json-parse-even-better-errors` + +## Table of Contents + +* [Example](#example) +* [Features](#features) +* [Contributing](#contributing) +* [API](#api) + * [`parse`](#parse) + +### Example + +```javascript +const parseJson = require('json-parse-even-better-errors') + +parseJson('"foo"') // returns the string 'foo' +parseJson('garbage') // more useful error message +parseJson.noExceptions('garbage') // returns undefined +``` + +### Features + +* Like JSON.parse, but the errors are better. +* Strips a leading byte-order-mark that you sometimes get reading files. +* Has a `noExceptions` method that returns undefined rather than throwing. +* Attaches the newline character(s) used to the `Symbol.for('newline')` + property on objects and arrays. +* Attaches the indentation character(s) used to the `Symbol.for('indent')` + property on objects and arrays. + +## Indentation + +To preserve indentation when the file is saved back to disk, use +`data[Symbol.for('indent')]` as the third argument to `JSON.stringify`, and +if you want to preserve windows `\r\n` newlines, replace the `\n` chars in +the string with `data[Symbol.for('newline')]`. + +For example: + +```js +const txt = await readFile('./package.json', 'utf8') +const data = parseJsonEvenBetterErrors(txt) +const indent = Symbol.for('indent') +const newline = Symbol.for('newline') +// .. do some stuff to the data .. +const string = JSON.stringify(data, null, data[indent]) + '\n' +const eolFixed = data[newline] === '\n' ? string + : string.replace(/\n/g, data[newline]) +await writeFile('./package.json', eolFixed) +``` + +Indentation is determined by looking at the whitespace between the initial +`{` and `[` and the character that follows it. If you have lots of weird +inconsistent indentation, then it won't track that or give you any way to +preserve it. Whether this is a bug or a feature is debatable ;) + +### API + +#### `parse(txt, reviver = null, context = 20)` + +Works just like `JSON.parse`, but will include a bit more information when +an error happens, and attaches a `Symbol.for('indent')` and +`Symbol.for('newline')` on objects and arrays. This throws a +`JSONParseError`. + +#### `parse.noExceptions(txt, reviver = null)` + +Works just like `JSON.parse`, but will return `undefined` rather than +throwing an error. + +#### `class JSONParseError(er, text, context = 20, caller = null)` + +Extends the JavaScript `SyntaxError` class to parse the message and provide +better metadata. + +Pass in the error thrown by the built-in `JSON.parse`, and the text being +parsed, and it'll parse out the bits needed to be helpful. + +`context` defaults to 20. + +Set a `caller` function to trim internal implementation details out of the +stack trace. When calling `parseJson`, this is set to the `parseJson` +function. If not set, then the constructor defaults to itself, so the +stack trace will point to the spot where you call `new JSONParseError`. diff --git a/node_modules/json-parse-even-better-errors/index.js b/node_modules/json-parse-even-better-errors/index.js new file mode 100644 index 0000000000000..86a1fdc1ae809 --- /dev/null +++ b/node_modules/json-parse-even-better-errors/index.js @@ -0,0 +1,121 @@ +'use strict' + +const hexify = char => { + const h = char.charCodeAt(0).toString(16).toUpperCase() + return '0x' + (h.length % 2 ? '0' : '') + h +} + +const parseError = (e, txt, context) => { + if (!txt) { + return { + message: e.message + ' while parsing empty string', + position: 0, + } + } + const badToken = e.message.match(/^Unexpected token (.) .*position\s+(\d+)/i) + const errIdx = badToken ? +badToken[2] + : e.message.match(/^Unexpected end of JSON.*/i) ? txt.length - 1 + : null + + const msg = badToken ? e.message.replace(/^Unexpected token ./, `Unexpected token ${ + JSON.stringify(badToken[1]) + } (${hexify(badToken[1])})`) + : e.message + + if (errIdx !== null && errIdx !== undefined) { + const start = errIdx <= context ? 0 + : errIdx - context + + const end = errIdx + context >= txt.length ? txt.length + : errIdx + context + + const slice = (start === 0 ? '' : '...') + + txt.slice(start, end) + + (end === txt.length ? '' : '...') + + const near = txt === slice ? '' : 'near ' + + return { + message: msg + ` while parsing ${near}${JSON.stringify(slice)}`, + position: errIdx, + } + } else { + return { + message: msg + ` while parsing '${txt.slice(0, context * 2)}'`, + position: 0, + } + } +} + +class JSONParseError extends SyntaxError { + constructor (er, txt, context, caller) { + context = context || 20 + const metadata = parseError(er, txt, context) + super(metadata.message) + Object.assign(this, metadata) + this.code = 'EJSONPARSE' + this.systemError = er + Error.captureStackTrace(this, caller || this.constructor) + } + get name () { return this.constructor.name } + set name (n) {} + get [Symbol.toStringTag] () { return this.constructor.name } +} + +const kIndent = Symbol.for('indent') +const kNewline = Symbol.for('newline') +// only respect indentation if we got a line break, otherwise squash it +// things other than objects and arrays aren't indented, so ignore those +// Important: in both of these regexps, the $1 capture group is the newline +// or undefined, and the $2 capture group is the indent, or undefined. +const formatRE = /^\s*[{\[]((?:\r?\n)+)([\s\t]*)/ +const emptyRE = /^(?:\{\}|\[\])((?:\r?\n)+)?$/ + +const parseJson = (txt, reviver, context) => { + const parseText = stripBOM(txt) + context = context || 20 + try { + // get the indentation so that we can save it back nicely + // if the file starts with {" then we have an indent of '', ie, none + // otherwise, pick the indentation of the next line after the first \n + // If the pattern doesn't match, then it means no indentation. + // JSON.stringify ignores symbols, so this is reasonably safe. + // if the string is '{}' or '[]', then use the default 2-space indent. + const [, newline = '\n', indent = ' '] = parseText.match(emptyRE) || + parseText.match(formatRE) || + [, '', ''] + + const result = JSON.parse(parseText, reviver) + if (result && typeof result === 'object') { + result[kNewline] = newline + result[kIndent] = indent + } + return result + } catch (e) { + if (typeof txt !== 'string' && !Buffer.isBuffer(txt)) { + const isEmptyArray = Array.isArray(txt) && txt.length === 0 + throw Object.assign(new TypeError( + `Cannot parse ${isEmptyArray ? 'an empty array' : String(txt)}` + ), { + code: 'EJSONPARSE', + systemError: e, + }) + } + + throw new JSONParseError(e, parseText, context, parseJson) + } +} + +// Remove byte order marker. This catches EF BB BF (the UTF-8 BOM) +// because the buffer-to-string conversion in `fs.readFileSync()` +// translates it to FEFF, the UTF-16 BOM. +const stripBOM = txt => String(txt).replace(/^\uFEFF/, '') + +module.exports = parseJson +parseJson.JSONParseError = JSONParseError + +parseJson.noExceptions = (txt, reviver) => { + try { + return JSON.parse(stripBOM(txt), reviver) + } catch (e) {} +} diff --git a/node_modules/json-parse-even-better-errors/package.json b/node_modules/json-parse-even-better-errors/package.json new file mode 100644 index 0000000000000..bf5d553d2d88f --- /dev/null +++ b/node_modules/json-parse-even-better-errors/package.json @@ -0,0 +1,64 @@ +{ + "_from": "json-parse-even-better-errors@^2.3.0", + "_id": "json-parse-even-better-errors@2.3.1", + "_inBundle": false, + "_integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==", + "_location": "/json-parse-even-better-errors", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "json-parse-even-better-errors@^2.3.0", + "name": "json-parse-even-better-errors", + "escapedName": "json-parse-even-better-errors", + "rawSpec": "^2.3.0", + "saveSpec": null, + "fetchSpec": "^2.3.0" + }, + "_requiredBy": [ + "/read-package-json" + ], + "_resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", + "_shasum": "7c47805a94319928e05777405dc12e1f7a4ee02d", + "_spec": "json-parse-even-better-errors@^2.3.0", + "_where": "/Users/darcyclarke/Documents/Repos/npm/v6/node_modules/read-package-json", + "author": { + "name": "Kat Marchán", + "email": "kzm@zkat.tech" + }, + "bugs": { + "url": "https://github.com/npm/json-parse-even-better-errors/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "JSON.parse with context information on error", + "devDependencies": { + "tap": "^14.6.5" + }, + "files": [ + "*.js" + ], + "homepage": "https://github.com/npm/json-parse-even-better-errors#readme", + "keywords": [ + "JSON", + "parser" + ], + "license": "MIT", + "main": "index.js", + "name": "json-parse-even-better-errors", + "repository": { + "type": "git", + "url": "git+https://github.com/npm/json-parse-even-better-errors.git" + }, + "scripts": { + "postversion": "npm publish", + "prepublishOnly": "git push --follow-tags", + "preversion": "npm t", + "snap": "tap", + "test": "tap" + }, + "tap": { + "check-coverage": true + }, + "version": "2.3.1" +} diff --git a/node_modules/read-package-json/CHANGELOG.md b/node_modules/read-package-json/CHANGELOG.md index e6f26e59d28ef..4b710cb2ab105 100644 --- a/node_modules/read-package-json/CHANGELOG.md +++ b/node_modules/read-package-json/CHANGELOG.md @@ -2,6 +2,16 @@ All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. + +## [2.1.2](https://github.com/npm/read-package-json/compare/v2.1.1...v2.1.2) (2020-08-20) + + +### Bug Fixes + +* even better json errors, remove graceful-fs ([fdbf082](https://github.com/npm/read-package-json/commit/fdbf082)) + + + ## [2.1.1](https://github.com/npm/read-package-json/compare/v2.1.0...v2.1.1) (2019-12-09) diff --git a/node_modules/read-package-json/package.json b/node_modules/read-package-json/package.json index 7920e43589939..da6201c8f3fa7 100644 --- a/node_modules/read-package-json/package.json +++ b/node_modules/read-package-json/package.json @@ -1,19 +1,19 @@ { - "_from": "read-package-json@2.1.1", - "_id": "read-package-json@2.1.1", + "_from": "read-package-json@2.1.2", + "_id": "read-package-json@2.1.2", "_inBundle": false, - "_integrity": "sha512-dAiqGtVc/q5doFz6096CcnXhpYk0ZN8dEKVkGLU0CsASt8SrgF6SF7OTKAYubfvFhWaqofl+Y8HK19GR8jwW+A==", + "_integrity": "sha512-D1KmuLQr6ZSJS0tW8hf3WGpRlwszJOXZ3E8Yd/DNRaM5d+1wVRZdHlpGBLAuovjr28LbWvjpWkBHMxpRGGjzNA==", "_location": "/read-package-json", "_phantomChildren": {}, "_requested": { "type": "version", "registry": true, - "raw": "read-package-json@2.1.1", + "raw": "read-package-json@2.1.2", "name": "read-package-json", "escapedName": "read-package-json", - "rawSpec": "2.1.1", + "rawSpec": "2.1.2", "saveSpec": null, - "fetchSpec": "2.1.1" + "fetchSpec": "2.1.2" }, "_requiredBy": [ "#USER", @@ -24,10 +24,10 @@ "/read-installed", "/read-package-tree" ], - "_resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-2.1.1.tgz", - "_shasum": "16aa66c59e7d4dad6288f179dd9295fd59bb98f1", - "_spec": "read-package-json@2.1.1", - "_where": "/Users/isaacs/dev/npm/cli", + "_resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-2.1.2.tgz", + "_shasum": "6992b2b66c7177259feb8eaac73c3acd28b9222a", + "_spec": "read-package-json@2.1.2", + "_where": "/Users/darcyclarke/Documents/Repos/npm/v6", "author": { "name": "Isaac Z. Schlueter", "email": "i@izs.me", @@ -39,8 +39,7 @@ "bundleDependencies": false, "dependencies": { "glob": "^7.1.1", - "graceful-fs": "^4.1.2", - "json-parse-better-errors": "^1.0.1", + "json-parse-even-better-errors": "^2.3.0", "normalize-package-data": "^2.0.0", "npm-normalize-package-bin": "^1.0.0" }, @@ -58,9 +57,6 @@ "license": "ISC", "main": "read-json.js", "name": "read-package-json", - "optionalDependencies": { - "graceful-fs": "^4.1.2" - }, "repository": { "type": "git", "url": "git+https://github.com/npm/read-package-json.git" @@ -72,5 +68,5 @@ "release": "standard-version -s", "test": "tap --nyc-arg=--all --coverage test/*.js" }, - "version": "2.1.1" + "version": "2.1.2" } diff --git a/node_modules/read-package-json/read-json.js b/node_modules/read-package-json/read-json.js index 03da84762eb29..0e91e784ec4fd 100644 --- a/node_modules/read-package-json/read-json.js +++ b/node_modules/read-package-json/read-json.js @@ -1,15 +1,10 @@ -var fs -try { - fs = require('graceful-fs') -} catch (er) { - fs = require('fs') -} +var fs = require('fs') var path = require('path') var glob = require('glob') var normalizeData = require('normalize-package-data') -var safeJSON = require('json-parse-better-errors') +var safeJSON = require('json-parse-even-better-errors') var util = require('util') var normalizePackageBin = require('npm-normalize-package-bin') diff --git a/package-lock.json b/package-lock.json index 41644fc6f45bd..e4f27b5a4527d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4257,6 +4257,11 @@ "integrity": "sha1-x6nCvjqFWzQvgqv8ibyFk1tYhPo=", "dev": true }, + "json-parse-even-better-errors": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/json-parse-even-better-errors/-/json-parse-even-better-errors-2.3.1.tgz", + "integrity": "sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==" + }, "json-schema": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", @@ -6198,13 +6203,12 @@ } }, "read-package-json": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-2.1.1.tgz", - "integrity": "sha512-dAiqGtVc/q5doFz6096CcnXhpYk0ZN8dEKVkGLU0CsASt8SrgF6SF7OTKAYubfvFhWaqofl+Y8HK19GR8jwW+A==", + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/read-package-json/-/read-package-json-2.1.2.tgz", + "integrity": "sha512-D1KmuLQr6ZSJS0tW8hf3WGpRlwszJOXZ3E8Yd/DNRaM5d+1wVRZdHlpGBLAuovjr28LbWvjpWkBHMxpRGGjzNA==", "requires": { "glob": "^7.1.1", - "graceful-fs": "^4.1.2", - "json-parse-better-errors": "^1.0.1", + "json-parse-even-better-errors": "^2.3.0", "normalize-package-data": "^2.0.0", "npm-normalize-package-bin": "^1.0.0" } diff --git a/package.json b/package.json index 0a2a3dd1aaf38..4da1411efb1ba 100644 --- a/package.json +++ b/package.json @@ -120,7 +120,7 @@ "read": "~1.0.7", "read-cmd-shim": "^1.0.5", "read-installed": "~4.0.3", - "read-package-json": "^2.1.1", + "read-package-json": "^2.1.2", "read-package-tree": "^5.3.1", "readable-stream": "^3.6.0", "readdir-scoped-modules": "^1.1.0",