MCPcopy
hub / github.com/webpack/webpack / toJson

Method toJson

lib/MultiStats.js:122–192  ·  view source on GitHub ↗

* Returns json output. * @param {StatsValue=} options stats options * @returns {StatsCompilation} json output

(options)

Source from the content-addressed store, hash-verified

120 * @returns {StatsCompilation} json output
121 */
122 toJson(options) {
123 const childOptions = this._createChildOptions(options, {
124 forToString: false
125 });
126 /** @type {KnownStatsCompilation} */
127 const obj = {};
128 obj.children = this.stats.map((stat, idx) => {
129 const obj = stat.toJson(childOptions.children[idx]);
130 const compilationName = stat.compilation.name;
131 const name =
132 compilationName &&
133 identifierUtils.makePathsRelative(
134 stat.compilation.compiler.context,
135 compilationName,
136 stat.compilation.compiler.root
137 );
138 obj.name = name;
139 return obj;
140 });
141 if (childOptions.version) {
142 obj.version = obj.children[0].version;
143 }
144 if (childOptions.hash) {
145 obj.hash = obj.children.map((j) => j.hash).join("");
146 }
147 /**
148 * Returns result.
149 * @param {StatsCompilation} j stats error
150 * @param {StatsError} obj Stats error
151 * @returns {StatsError} result
152 */
153 const mapError = (j, obj) => ({
154 ...obj,
155 compilerPath: obj.compilerPath ? `${j.name}.${obj.compilerPath}` : j.name
156 });
157 if (childOptions.errors) {
158 obj.errors = [];
159 for (const j of obj.children) {
160 const errors =
161 /** @type {NonNullable<KnownStatsCompilation["errors"]>} */
162 (j.errors);
163 for (const i of errors) {
164 obj.errors.push(mapError(j, i));
165 }
166 }
167 }
168 if (childOptions.warnings) {
169 obj.warnings = [];
170 for (const j of obj.children) {
171 const warnings =
172 /** @type {NonNullable<KnownStatsCompilation["warnings"]>} */
173 (j.warnings);
174 for (const i of warnings) {
175 obj.warnings.push(mapError(j, i));
176 }
177 }
178 }
179 if (childOptions.errorsCount) {

Callers

nothing calls this directly

Calls 2

_createChildOptionsMethod · 0.95
pushMethod · 0.45

Tested by

no test coverage detected