MCPcopy
hub / github.com/webpack/webpack / readJson

Function readJson

lib/util/fs.js:675–692  ·  view source on GitHub ↗
(fs, p, callback)

Source from the content-addressed store, hash-verified

673 * @returns {void}
674 */
675const readJson = (fs, p, callback) => {
676 if ("readJson" in fs) {
677 return /** @type {NonNullable<InputFileSystem["readJson"]>} */ (
678 fs.readJson
679 )(p, callback);
680 }
681 fs.readFile(p, (err, buf) => {
682 if (err) return callback(err);
683 /** @type {JsonObject} */
684 let data;
685 try {
686 data = JSON.parse(/** @type {Buffer} */ (buf).toString("utf8"));
687 } catch (err1) {
688 return callback(/** @type {Error} */ (err1));
689 }
690 return callback(null, data);
691 });
692};
693
694/**
695 * Lstat readlink absolute.

Callers 1

tryLoadCurrentFunction · 0.85

Calls 4

readFileMethod · 0.80
callbackFunction · 0.50
parseMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected