Files
gniza4cp/whm/gniza4cp-whm/assets/node_modules/enhanced-resolve/lib/util/fs.js
shuki a162536585 Rename product from gniza to gniza4cp across entire codebase
- CLI binary: bin/gniza -> bin/gniza4cp
- Install path: /usr/local/gniza4cp/
- Config path: /etc/gniza4cp/
- Log path: /var/log/gniza4cp/
- WHM plugin: gniza4cp-whm/
- cPanel plugin: cpanel/gniza4cp/
- AdminBin: Gniza4cp::Restore
- Perl modules: Gniza4cpWHM::*, Gniza4cpCPanel::*
- DaisyUI theme: gniza4cp
- All internal references, branding, paths updated
- Git remote updated to gniza4cp repo
2026-03-05 21:03:30 +02:00

53 lines
1.5 KiB
JavaScript

/*
MIT License http://www.opensource.org/licenses/mit-license.php
Author Natsu @xiaoxiaojx
*/
"use strict";
const stripJsonComments = require("./strip-json-comments");
/** @typedef {import("../Resolver").FileSystem} FileSystem */
/**
* @typedef {object} ReadJsonOptions
* @property {boolean=} stripComments Whether to strip JSONC comments
*/
/**
* Read and parse JSON file (supports JSONC with comments)
* @template T
* @param {FileSystem} fileSystem the file system
* @param {string} jsonFilePath absolute path to JSON file
* @param {ReadJsonOptions} options Options
* @returns {Promise<T>} parsed JSON content
*/
async function readJson(fileSystem, jsonFilePath, options = {}) {
const { stripComments = false } = options;
const { readJson } = fileSystem;
if (readJson && !stripComments) {
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);
});
});
const jsonText = /** @type {string} */ (buf.toString());
// Strip comments to support JSONC (e.g., tsconfig.json with comments)
const jsonWithoutComments = stripComments
? stripJsonComments(jsonText, { trailingCommas: true, whitespace: true })
: jsonText;
return JSON.parse(jsonWithoutComments);
}
module.exports.readJson = readJson;