Upgrade minimist to 1.2.6
This CL updates minimist to 1.2.6 to fix a critical security
vulnerability: https://nvd.nist.gov/vuln/detail/CVE-2021-44906
The fix was made by running:
`npm run install-deps audit fix --audit-level=critical`
Bug: none
Change-Id: I51103b525d9969e03000d55af86cebdabc7e0366
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/3591079
Reviewed-by: Mathias Bynens <mathias@chromium.org>
Commit-Queue: Brandon Walderman <brwalder@microsoft.com>
diff --git a/node_modules/jsonfile/CHANGELOG.md b/node_modules/jsonfile/CHANGELOG.md
index 7718857..d772e43 100644
--- a/node_modules/jsonfile/CHANGELOG.md
+++ b/node_modules/jsonfile/CHANGELOG.md
@@ -1,3 +1,29 @@
+6.1.0 / 2020-10-31
+------------------
+
+- Add `finalEOL` option to disable writing final EOL ([#115](https://github.com/jprichardson/node-jsonfile/issues/115), [#137](https://github.com/jprichardson/node-jsonfile/pull/137))
+- Update dependency ([#138](https://github.com/jprichardson/node-jsonfile/pull/138))
+
+6.0.1 / 2020-03-07
+------------------
+
+- Update dependency ([#130](https://github.com/jprichardson/node-jsonfile/pull/130))
+- Fix code style ([#129](https://github.com/jprichardson/node-jsonfile/pull/129))
+
+6.0.0 / 2020-02-24
+------------------
+
+- **BREAKING:** Drop support for Node 6 & 8 ([#128](https://github.com/jprichardson/node-jsonfile/pull/128))
+- **BREAKING:** Do not allow passing `null` as options to `readFile()` or `writeFile()` ([#128](https://github.com/jprichardson/node-jsonfile/pull/128))
+- Refactor internals ([#128](https://github.com/jprichardson/node-jsonfile/pull/128))
+
+5.0.0 / 2018-09-08
+------------------
+
+- **BREAKING:** Drop Node 4 support
+- **BREAKING:** If no callback is passed to an asynchronous method, a promise is now returned ([#109](https://github.com/jprichardson/node-jsonfile/pull/109))
+- Cleanup docs
+
4.0.0 / 2017-07-12
------------------
diff --git a/node_modules/jsonfile/README.md b/node_modules/jsonfile/README.md
index 721685c..910cde0 100644
--- a/node_modules/jsonfile/README.md
+++ b/node_modules/jsonfile/README.md
@@ -1,7 +1,7 @@
Node.js - jsonfile
================
-Easily read/write JSON files.
+Easily read/write JSON files in Node.js. _Note: this module cannot be used in the browser._
[](https://www.npmjs.org/package/jsonfile)
[](http://travis-ci.org/jprichardson/node-jsonfile)
@@ -26,101 +26,152 @@
API
---
+* [`readFile(filename, [options], callback)`](#readfilefilename-options-callback)
+* [`readFileSync(filename, [options])`](#readfilesyncfilename-options)
+* [`writeFile(filename, obj, [options], callback)`](#writefilefilename-obj-options-callback)
+* [`writeFileSync(filename, obj, [options])`](#writefilesyncfilename-obj-options)
+
+----
+
### readFile(filename, [options], callback)
-`options` (`object`, default `undefined`): Pass in any `fs.readFile` options or set `reviver` for a [JSON reviver](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
+`options` (`object`, default `undefined`): Pass in any [`fs.readFile`](https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback) options or set `reviver` for a [JSON reviver](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
- `throws` (`boolean`, default: `true`). If `JSON.parse` throws an error, pass this error to the callback.
If `false`, returns `null` for the object.
```js
-var jsonfile = require('jsonfile')
-var file = '/tmp/data.json'
-jsonfile.readFile(file, function(err, obj) {
+const jsonfile = require('jsonfile')
+const file = '/tmp/data.json'
+jsonfile.readFile(file, function (err, obj) {
+ if (err) console.error(err)
console.dir(obj)
})
```
+You can also use this method with promises. The `readFile` method will return a promise if you do not pass a callback function.
+
+```js
+const jsonfile = require('jsonfile')
+const file = '/tmp/data.json'
+jsonfile.readFile(file)
+ .then(obj => console.dir(obj))
+ .catch(error => console.error(error))
+```
+
+----
### readFileSync(filename, [options])
-`options` (`object`, default `undefined`): Pass in any `fs.readFileSync` options or set `reviver` for a [JSON reviver](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
+`options` (`object`, default `undefined`): Pass in any [`fs.readFileSync`](https://nodejs.org/api/fs.html#fs_fs_readfilesync_path_options) options or set `reviver` for a [JSON reviver](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse).
- `throws` (`boolean`, default: `true`). If an error is encountered reading or parsing the file, throw the error. If `false`, returns `null` for the object.
```js
-var jsonfile = require('jsonfile')
-var file = '/tmp/data.json'
+const jsonfile = require('jsonfile')
+const file = '/tmp/data.json'
console.dir(jsonfile.readFileSync(file))
```
+----
### writeFile(filename, obj, [options], callback)
-`options`: Pass in any `fs.writeFile` options or set `replacer` for a [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Can also pass in `spaces` and override `EOL` string.
+`options`: Pass in any [`fs.writeFile`](https://nodejs.org/api/fs.html#fs_fs_writefile_file_data_options_callback) options or set `replacer` for a [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Can also pass in `spaces`, or override `EOL` string or set `finalEOL` flag as `false` to not save the file with `EOL` at the end.
```js
-var jsonfile = require('jsonfile')
+const jsonfile = require('jsonfile')
-var file = '/tmp/data.json'
-var obj = {name: 'JP'}
+const file = '/tmp/data.json'
+const obj = { name: 'JP' }
jsonfile.writeFile(file, obj, function (err) {
- console.error(err)
+ if (err) console.error(err)
})
```
+Or use with promises as follows:
+
+```js
+const jsonfile = require('jsonfile')
+
+const file = '/tmp/data.json'
+const obj = { name: 'JP' }
+
+jsonfile.writeFile(file, obj)
+ .then(res => {
+ console.log('Write complete')
+ })
+ .catch(error => console.error(error))
+```
+
**formatting with spaces:**
```js
-var jsonfile = require('jsonfile')
+const jsonfile = require('jsonfile')
-var file = '/tmp/data.json'
-var obj = {name: 'JP'}
+const file = '/tmp/data.json'
+const obj = { name: 'JP' }
-jsonfile.writeFile(file, obj, {spaces: 2}, function(err) {
- console.error(err)
+jsonfile.writeFile(file, obj, { spaces: 2 }, function (err) {
+ if (err) console.error(err)
})
```
**overriding EOL:**
```js
-var jsonfile = require('jsonfile')
+const jsonfile = require('jsonfile')
-var file = '/tmp/data.json'
-var obj = {name: 'JP'}
+const file = '/tmp/data.json'
+const obj = { name: 'JP' }
-jsonfile.writeFile(file, obj, {spaces: 2, EOL: '\r\n'}, function(err) {
- console.error(err)
+jsonfile.writeFile(file, obj, { spaces: 2, EOL: '\r\n' }, function (err) {
+ if (err) console.error(err)
+})
+```
+
+
+**disabling the EOL at the end of file:**
+
+```js
+const jsonfile = require('jsonfile')
+
+const file = '/tmp/data.json'
+const obj = { name: 'JP' }
+
+jsonfile.writeFile(file, obj, { spaces: 2, finalEOL: false }, function (err) {
+ if (err) console.log(err)
})
```
**appending to an existing JSON file:**
-You can use `fs.writeFile` option `{flag: 'a'}` to achieve this.
+You can use `fs.writeFile` option `{ flag: 'a' }` to achieve this.
```js
-var jsonfile = require('jsonfile')
+const jsonfile = require('jsonfile')
-var file = '/tmp/mayAlreadyExistedData.json'
-var obj = {name: 'JP'}
+const file = '/tmp/mayAlreadyExistedData.json'
+const obj = { name: 'JP' }
-jsonfile.writeFile(file, obj, {flag: 'a'}, function (err) {
- console.error(err)
+jsonfile.writeFile(file, obj, { flag: 'a' }, function (err) {
+ if (err) console.error(err)
})
```
+----
+
### writeFileSync(filename, obj, [options])
-`options`: Pass in any `fs.writeFileSync` options or set `replacer` for a [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Can also pass in `spaces` and override `EOL` string.
+`options`: Pass in any [`fs.writeFileSync`](https://nodejs.org/api/fs.html#fs_fs_writefilesync_file_data_options) options or set `replacer` for a [JSON replacer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify). Can also pass in `spaces`, or override `EOL` string or set `finalEOL` flag as `false` to not save the file with `EOL` at the end.
```js
-var jsonfile = require('jsonfile')
+const jsonfile = require('jsonfile')
-var file = '/tmp/data.json'
-var obj = {name: 'JP'}
+const file = '/tmp/data.json'
+const obj = { name: 'JP' }
jsonfile.writeFileSync(file, obj)
```
@@ -128,36 +179,47 @@
**formatting with spaces:**
```js
-var jsonfile = require('jsonfile')
+const jsonfile = require('jsonfile')
-var file = '/tmp/data.json'
-var obj = {name: 'JP'}
+const file = '/tmp/data.json'
+const obj = { name: 'JP' }
-jsonfile.writeFileSync(file, obj, {spaces: 2})
+jsonfile.writeFileSync(file, obj, { spaces: 2 })
```
**overriding EOL:**
```js
-var jsonfile = require('jsonfile')
+const jsonfile = require('jsonfile')
-var file = '/tmp/data.json'
-var obj = {name: 'JP'}
+const file = '/tmp/data.json'
+const obj = { name: 'JP' }
-jsonfile.writeFileSync(file, obj, {spaces: 2, EOL: '\r\n'})
+jsonfile.writeFileSync(file, obj, { spaces: 2, EOL: '\r\n' })
+```
+
+**disabling the EOL at the end of file:**
+
+```js
+const jsonfile = require('jsonfile')
+
+const file = '/tmp/data.json'
+const obj = { name: 'JP' }
+
+jsonfile.writeFileSync(file, obj, { spaces: 2, finalEOL: false })
```
**appending to an existing JSON file:**
-You can use `fs.writeFileSync` option `{flag: 'a'}` to achieve this.
+You can use `fs.writeFileSync` option `{ flag: 'a' }` to achieve this.
```js
-var jsonfile = require('jsonfile')
+const jsonfile = require('jsonfile')
-var file = '/tmp/mayAlreadyExistedData.json'
-var obj = {name: 'JP'}
+const file = '/tmp/mayAlreadyExistedData.json'
+const obj = { name: 'JP' }
-jsonfile.writeFileSync(file, obj, {flag: 'a'})
+jsonfile.writeFileSync(file, obj, { flag: 'a' })
```
License
diff --git a/node_modules/jsonfile/index.js b/node_modules/jsonfile/index.js
index d1e5827..0582868 100644
--- a/node_modules/jsonfile/index.js
+++ b/node_modules/jsonfile/index.js
@@ -1,69 +1,58 @@
-var _fs
+let _fs
try {
_fs = require('graceful-fs')
} catch (_) {
_fs = require('fs')
}
+const universalify = require('universalify')
+const { stringify, stripBom } = require('./utils')
-function readFile (file, options, callback) {
- if (callback == null) {
- callback = options
- options = {}
- }
-
+async function _readFile (file, options = {}) {
if (typeof options === 'string') {
- options = {encoding: options}
+ options = { encoding: options }
}
- options = options || {}
- var fs = options.fs || _fs
+ const fs = options.fs || _fs
- var shouldThrow = true
- if ('throws' in options) {
- shouldThrow = options.throws
- }
+ const shouldThrow = 'throws' in options ? options.throws : true
- fs.readFile(file, options, function (err, data) {
- if (err) return callback(err)
+ let data = await universalify.fromCallback(fs.readFile)(file, options)
- data = stripBom(data)
+ data = stripBom(data)
- var obj
- try {
- obj = JSON.parse(data, options ? options.reviver : null)
- } catch (err2) {
- if (shouldThrow) {
- err2.message = file + ': ' + err2.message
- return callback(err2)
- } else {
- return callback(null, null)
- }
+ let obj
+ try {
+ obj = JSON.parse(data, options ? options.reviver : null)
+ } catch (err) {
+ if (shouldThrow) {
+ err.message = `${file}: ${err.message}`
+ throw err
+ } else {
+ return null
}
+ }
- callback(null, obj)
- })
+ return obj
}
-function readFileSync (file, options) {
- options = options || {}
+const readFile = universalify.fromPromise(_readFile)
+
+function readFileSync (file, options = {}) {
if (typeof options === 'string') {
- options = {encoding: options}
+ options = { encoding: options }
}
- var fs = options.fs || _fs
+ const fs = options.fs || _fs
- var shouldThrow = true
- if ('throws' in options) {
- shouldThrow = options.throws
- }
+ const shouldThrow = 'throws' in options ? options.throws : true
try {
- var content = fs.readFileSync(file, options)
+ let content = fs.readFileSync(file, options)
content = stripBom(content)
return JSON.parse(content, options.reviver)
} catch (err) {
if (shouldThrow) {
- err.message = file + ': ' + err.message
+ err.message = `${file}: ${err.message}`
throw err
} else {
return null
@@ -71,64 +60,29 @@
}
}
-function stringify (obj, options) {
- var spaces
- var EOL = '\n'
- if (typeof options === 'object' && options !== null) {
- if (options.spaces) {
- spaces = options.spaces
- }
- if (options.EOL) {
- EOL = options.EOL
- }
- }
+async function _writeFile (file, obj, options = {}) {
+ const fs = options.fs || _fs
- var str = JSON.stringify(obj, options ? options.replacer : null, spaces)
+ const str = stringify(obj, options)
- return str.replace(/\n/g, EOL) + EOL
+ await universalify.fromCallback(fs.writeFile)(file, str, options)
}
-function writeFile (file, obj, options, callback) {
- if (callback == null) {
- callback = options
- options = {}
- }
- options = options || {}
- var fs = options.fs || _fs
+const writeFile = universalify.fromPromise(_writeFile)
- var str = ''
- try {
- str = stringify(obj, options)
- } catch (err) {
- // Need to return whether a callback was passed or not
- if (callback) callback(err, null)
- return
- }
+function writeFileSync (file, obj, options = {}) {
+ const fs = options.fs || _fs
- fs.writeFile(file, str, options, callback)
-}
-
-function writeFileSync (file, obj, options) {
- options = options || {}
- var fs = options.fs || _fs
-
- var str = stringify(obj, options)
+ const str = stringify(obj, options)
// not sure if fs.writeFileSync returns anything, but just in case
return fs.writeFileSync(file, str, options)
}
-function stripBom (content) {
- // we do this because JSON.parse would convert it to a utf8 string if encoding wasn't specified
- if (Buffer.isBuffer(content)) content = content.toString('utf8')
- content = content.replace(/^\uFEFF/, '')
- return content
-}
-
-var jsonfile = {
- readFile: readFile,
- readFileSync: readFileSync,
- writeFile: writeFile,
- writeFileSync: writeFileSync
+const jsonfile = {
+ readFile,
+ readFileSync,
+ writeFile,
+ writeFileSync
}
module.exports = jsonfile
diff --git a/node_modules/jsonfile/package.json b/node_modules/jsonfile/package.json
index 29e783f..4d01eb1 100644
--- a/node_modules/jsonfile/package.json
+++ b/node_modules/jsonfile/package.json
@@ -1,6 +1,6 @@
{
"name": "jsonfile",
- "version": "4.0.0",
+ "version": "6.1.0",
"description": "Easily read/write JSON files.",
"repository": {
"type": "git",
@@ -16,18 +16,21 @@
],
"author": "JP Richardson <jprichardson@gmail.com>",
"license": "MIT",
- "dependencies": {},
+ "dependencies": {
+ "universalify": "^2.0.0"
+ },
"optionalDependencies": {
"graceful-fs": "^4.1.6"
},
"devDependencies": {
- "mocha": "2.x",
+ "mocha": "^8.2.0",
"rimraf": "^2.4.0",
- "standard": "^10.0.3"
+ "standard": "^16.0.1"
},
"main": "index.js",
"files": [
- "index.js"
+ "index.js",
+ "utils.js"
],
"scripts": {
"lint": "standard",
diff --git a/node_modules/jsonfile/utils.js b/node_modules/jsonfile/utils.js
new file mode 100644
index 0000000..b5ff48e
--- /dev/null
+++ b/node_modules/jsonfile/utils.js
@@ -0,0 +1,14 @@
+function stringify (obj, { EOL = '\n', finalEOL = true, replacer = null, spaces } = {}) {
+ const EOF = finalEOL ? EOL : ''
+ const str = JSON.stringify(obj, replacer, spaces)
+
+ return str.replace(/\n/g, EOL) + EOF
+}
+
+function stripBom (content) {
+ // we do this because JSON.parse would convert it to a utf8 string if encoding wasn't specified
+ if (Buffer.isBuffer(content)) content = content.toString('utf8')
+ return content.replace(/^\uFEFF/, '')
+}
+
+module.exports = { stringify, stripBom }