MCPcopy
hub / github.com/webpack/webpack / errorsSpaceLimit

Function errorsSpaceLimit

lib/stats/DefaultStatsFactoryPlugin.js:2014–2070  ·  view source on GitHub ↗
(errors, max)

Source from the content-addressed store, hash-verified

2012 * @returns {[StatsError[], number]} error space limit
2013 */
2014const errorsSpaceLimit = (errors, max) => {
2015 let filtered = 0;
2016 // Can not fit into limit
2017 // print only messages
2018 if (errors.length + 1 >= max) {
2019 return [
2020 errors.map((error) => {
2021 if (typeof error === "string" || !error.details) return error;
2022 filtered++;
2023 return { ...error, details: "" };
2024 }),
2025 filtered
2026 ];
2027 }
2028 let fullLength = errors.length;
2029 let result = errors;
2030
2031 let i = 0;
2032 for (; i < errors.length; i++) {
2033 const error = errors[i];
2034 if (typeof error !== "string" && error.details) {
2035 const splitted = error.details.split("\n");
2036 const len = splitted.length;
2037 fullLength += len;
2038 if (fullLength > max) {
2039 result = i > 0 ? errors.slice(0, i) : [];
2040 const overLimit = fullLength - max + 1;
2041 const error = errors[i++];
2042 result.push({
2043 ...error,
2044 details:
2045 /** @type {string} */
2046 (error.details).split("\n").slice(0, -overLimit).join("\n"),
2047 filteredDetails: overLimit
2048 });
2049 filtered = errors.length - i;
2050 for (; i < errors.length; i++) {
2051 const error = errors[i];
2052 if (typeof error === "string" || !error.details) result.push(error);
2053 result.push({ ...error, details: "" });
2054 }
2055 break;
2056 } else if (fullLength === max) {
2057 result = errors.slice(0, ++i);
2058 filtered = errors.length - i;
2059 for (; i < errors.length; i++) {
2060 const error = errors[i];
2061 if (typeof error === "string" || !error.details) result.push(error);
2062 result.push({ ...error, details: "" });
2063 }
2064 break;
2065 }
2066 }
2067 }
2068
2069 return [result, filtered];
2070};
2071

Callers 1

Calls 3

splitMethod · 0.80
sliceMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected