mirror of
https://github.com/hex248/ob248.com.git
synced 2026-02-08 02:33:02 +00:00
merge new into master
This commit is contained in:
38
node_modules/enhanced-resolve/lib/util/fs.js
generated
vendored
Normal file
38
node_modules/enhanced-resolve/lib/util/fs.js
generated
vendored
Normal file
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
MIT License http://www.opensource.org/licenses/mit-license.php
|
||||
Author Natsu @xiaoxiaojx
|
||||
*/
|
||||
|
||||
"use strict";
|
||||
|
||||
/** @typedef {import("../Resolver").FileSystem} FileSystem */
|
||||
|
||||
/**
|
||||
* Read and parse JSON file
|
||||
* @template T
|
||||
* @param {FileSystem} fileSystem the file system
|
||||
* @param {string} jsonFilePath absolute path to JSON file
|
||||
* @returns {Promise<T>} parsed JSON content
|
||||
*/
|
||||
async function readJson(fileSystem, jsonFilePath) {
|
||||
const { readJson } = fileSystem;
|
||||
if (readJson) {
|
||||
return new Promise((resolve, reject) => {
|
||||
readJson(jsonFilePath, (err, content) => {
|
||||
if (err) return reject(err);
|
||||
resolve(/** @type {T} */ (content));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const buf = await new Promise((resolve, reject) => {
|
||||
fileSystem.readFile(jsonFilePath, (err, data) => {
|
||||
if (err) return reject(err);
|
||||
resolve(data);
|
||||
});
|
||||
});
|
||||
|
||||
return JSON.parse(/** @type {string} */ (buf.toString()));
|
||||
}
|
||||
|
||||
module.exports.readJson = readJson;
|
||||
Reference in New Issue
Block a user