diff --git a/node_modules/read-package-json-fast/README.md b/node_modules/read-package-json-fast/README.md index e9c209be387dd..5ab6adbece825 100644 --- a/node_modules/read-package-json-fast/README.md +++ b/node_modules/read-package-json-fast/README.md @@ -27,6 +27,31 @@ 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. +## 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 data = await readPackageJsonFast('./package.json') +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 the first `"` 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 ;) + ## WHAT THIS MODULE DOES - Parse JSON diff --git a/node_modules/read-package-json-fast/package.json b/node_modules/read-package-json-fast/package.json index 6b449c18bcabc..a59a3b2e86e9b 100644 --- a/node_modules/read-package-json-fast/package.json +++ b/node_modules/read-package-json-fast/package.json @@ -1,6 +1,6 @@ { "name": "read-package-json-fast", - "version": "1.1.3", + "version": "1.2.1", "description": "Like read-package-json, but faster", "author": "Isaac Z. Schlueter (https://izs.me)", "license": "ISC", @@ -18,7 +18,7 @@ "tap": "^14.10.1" }, "dependencies": { - "json-parse-even-better-errors": "^2.0.1", + "json-parse-even-better-errors": "^2.3.0", "npm-normalize-package-bin": "^1.0.1" }, "repository": { diff --git a/package-lock.json b/package-lock.json index 15cc792ff85ab..6d7602a14f231 100644 --- a/package-lock.json +++ b/package-lock.json @@ -146,6 +146,7 @@ "qrcode-terminal": "^0.12.0", "read": "~1.0.7", "read-package-json": "^2.1.1", + "read-package-json-fast": "^1.2.1", "request": "^2.88.0", "retry": "^0.12.0", "rimraf": "^2.6.3", @@ -5406,12 +5407,12 @@ } }, "node_modules/read-package-json-fast": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/read-package-json-fast/-/read-package-json-fast-1.1.3.tgz", - "integrity": "sha512-MmFqiyfCXV2Dmm4jH24DEGhxdkUDFivJQj4oPZQPOKywxR7HWBE6WnMWDAapfFHi3wm1b+mhR+XHlUH0CL8axg==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/read-package-json-fast/-/read-package-json-fast-1.2.1.tgz", + "integrity": "sha512-OFbpwnHcv74Oa5YN5WvbOBfLw6yPmPcwvyJJw/tj9cWFBF7juQUDLDSZiOjEcgzfweWeeROOmbPpNN1qm4hcRg==", "inBundle": true, "dependencies": { - "json-parse-even-better-errors": "^2.0.1", + "json-parse-even-better-errors": "^2.3.0", "npm-normalize-package-bin": "^1.0.1" } }, @@ -13285,11 +13286,11 @@ } }, "read-package-json-fast": { - "version": "1.1.3", - "resolved": "https://registry.npmjs.org/read-package-json-fast/-/read-package-json-fast-1.1.3.tgz", - "integrity": "sha512-MmFqiyfCXV2Dmm4jH24DEGhxdkUDFivJQj4oPZQPOKywxR7HWBE6WnMWDAapfFHi3wm1b+mhR+XHlUH0CL8axg==", + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/read-package-json-fast/-/read-package-json-fast-1.2.1.tgz", + "integrity": "sha512-OFbpwnHcv74Oa5YN5WvbOBfLw6yPmPcwvyJJw/tj9cWFBF7juQUDLDSZiOjEcgzfweWeeROOmbPpNN1qm4hcRg==", "requires": { - "json-parse-even-better-errors": "^2.0.1", + "json-parse-even-better-errors": "^2.3.0", "npm-normalize-package-bin": "^1.0.1" } }, diff --git a/package.json b/package.json index f0ef2053a8e68..eaff78ba6d1b0 100644 --- a/package.json +++ b/package.json @@ -117,7 +117,8 @@ "write-file-atomic": "^2.4.3", "make-fetch-happen": "^8.0.9", "leven": "^3.1.0", - "@npmcli/config": "^1.1.5" + "@npmcli/config": "^1.1.5", + "read-package-json-fast": "^1.2.1" }, "bundleDependencies": [ "@npmcli/arborist", @@ -179,6 +180,7 @@ "qrcode-terminal", "read", "read-package-json", + "read-package-json-fast", "request", "retry", "rimraf",