";
break;
case LogType.info:
color = colors.green;
prefix = " ";
break;
case LogType.log:
color = colors.bold;
break;
case LogType.trace:
case LogType.debug:
color = colors.normal;
break;
case LogType.status:
color = colors.magenta;
prefix = " ";
break;
case LogType.profile:
color = colors.magenta;
prefix = " ";
break;
case LogType.profileEnd:
color = colors.magenta;
prefix = "
";
break;
case LogType.time:
color = colors.magenta;
prefix = " ";
break;
case LogType.group:
color = colors.cyan;
prefix = "<-> ";
break;
case LogType.groupCollapsed:
color = colors.cyan;
prefix = "<+> ";
break;
case LogType.groupEnd:
if (indent.length >= 2)
indent = indent.slice(0, indent.length - 2);
continue;
}
if (entry.message) {
for (const line of entry.message.split("\n")) {
colors.normal(`${indent}${prefix}`);
color(line);
newline();
}
}
if (entry.trace) {
for (const line of entry.trace) {
colors.normal(`${indent}| ${line}`);
newline();
}
}
switch (entry.type) {
case LogType.group:
indent += " ";
break;
}
}
if (logData.filteredEntries) {
colors.normal(`+ ${logData.filteredEntries} hidden lines`);
newline();
}
}
}
}
if (obj._showWarnings && obj.warnings) {
for (const warning of obj.warnings) {
newline();
colors.yellow(`WARNING in ${warning}`);
newline();
}
}
if (obj._showErrors && obj.errors) {
for (const error of obj.errors) {
newline();
colors.red(`ERROR in ${error}`);
newline();
}
}
if (obj.children) {
for (const child of obj.children) {
const childString = Stats.jsonToString(child, useColors);
if (childString) {
if (child.name) {
colors.normal("Child ");
colors.bold(child.name);
colors.normal(":");
} else {
colors.normal("Child");
}
newline();
buf.push(" ");
buf.push(childString.replace(/\n/g, "\n "));
newline();
}
}
}
if (obj.needAdditionalPass) {
colors.yellow(
"Compilation needs an additional pass and will compile again."
);
}
while (buf[buf.length - 1] === "\n") {
buf.pop();
}
return buf.join("");
}
static presetToOptions(name) {
// Accepted values: none, errors-only, minimal, normal, detailed, verbose
// Any other falsy value will behave as 'none', truthy values as 'normal'
const pn =
(typeof name === "string" && name.toLowerCase()) || name || "none";
switch (pn) {
case "none":
return {
all: false
};
case "verbose":
return {
entrypoints: true,
chunkGroups: true,
modules: false,
chunks: true,
chunkModules: true,
chunkOrigins: true,
depth: true,
env: true,
reasons: true,
usedExports: true,
providedExports: true,
optimizationBailout: true,
errorDetails: true,
publicPath: true,
logging: "verbose",
exclude: false,
maxModules: Infinity
};
case "detailed":
return {
entrypoints: true,
chunkGroups: true,
chunks: true,
chunkModules: false,
chunkOrigins: true,
depth: true,
usedExports: true,
providedExports: true,
optimizationBailout: true,
errorDetails: true,
publicPath: true,
logging: true,
exclude: false,
maxModules: Infinity
};
case "minimal":
return {
all: false,
modules: true,
maxModules: 0,
errors: true,
warnings: true,
logging: "warn"
};
case "errors-only":
return {
all: false,
errors: true,
moduleTrace: true,
logging: "error"
};
case "errors-warnings":
return {
all: false,
errors: true,
warnings: true,
logging: "warn"
};
default:
return {};
}
}
static getChildOptions(options, idx) {
let innerOptions;
if (Array.isArray(options.children)) {
if (idx < options.children.length) {
innerOptions = options.children[idx];
}
} else if (typeof options.children === "object" && options.children) {
innerOptions = options.children;
}
if (typeof innerOptions === "boolean" || typeof innerOptions === "string") {
innerOptions = Stats.presetToOptions(innerOptions);
}
if (!innerOptions) {
return options;
}
const childOptions = Object.assign({}, options);
delete childOptions.children; // do not inherit children
return Object.assign(childOptions, innerOptions);
}
}
module.exports = Stats;