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/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