Framework updates

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2026-03-04 23:20:19 +00:00
parent a89daf3d43
commit 3ed8517b2a
891 changed files with 11126 additions and 9600 deletions

View File

@@ -5,18 +5,27 @@
"use strict";
const stripJsonComments = require("./strip-json-comments");
/** @typedef {import("../Resolver").FileSystem} FileSystem */
/**
* Read and parse JSON file
* @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) {
async function readJson(fileSystem, jsonFilePath, options = {}) {
const { stripComments = false } = options;
const { readJson } = fileSystem;
if (readJson) {
if (readJson && !stripComments) {
return new Promise((resolve, reject) => {
readJson(jsonFilePath, (err, content) => {
if (err) return reject(err);
@@ -32,7 +41,12 @@ async function readJson(fileSystem, jsonFilePath) {
});
});
return JSON.parse(/** @type {string} */ (buf.toString()));
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;