Framework updates
🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
22
node_modules/enhanced-resolve/lib/util/fs.js
generated
vendored
22
node_modules/enhanced-resolve/lib/util/fs.js
generated
vendored
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user