| [9af201e] | 1 | /*
|
|---|
| 2 | MIT License http://www.opensource.org/licenses/mit-license.php
|
|---|
| 3 | Author Tobias Koppers @sokra
|
|---|
| 4 | */
|
|---|
| 5 |
|
|---|
| 6 | "use strict";
|
|---|
| 7 |
|
|---|
| 8 | /** @typedef {import("../declarations/WebpackOptions").StatsOptions} StatsOptions */
|
|---|
| 9 | /** @typedef {import("../declarations/WebpackOptions").StatsValue} StatsValue */
|
|---|
| 10 | /** @typedef {import("./Compilation")} Compilation */
|
|---|
| 11 | /** @typedef {import("./stats/DefaultStatsFactoryPlugin").StatsCompilation} StatsCompilation */
|
|---|
| 12 |
|
|---|
| 13 | class Stats {
|
|---|
| 14 | /**
|
|---|
| 15 | * Creates an instance of Stats.
|
|---|
| 16 | * @param {Compilation} compilation webpack compilation
|
|---|
| 17 | */
|
|---|
| 18 | constructor(compilation) {
|
|---|
| 19 | this.compilation = compilation;
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | get hash() {
|
|---|
| 23 | return this.compilation.hash;
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | get startTime() {
|
|---|
| 27 | return this.compilation.startTime;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | get endTime() {
|
|---|
| 31 | return this.compilation.endTime;
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | /**
|
|---|
| 35 | * Checks whether this stats has warnings.
|
|---|
| 36 | * @returns {boolean} true if the compilation had a warning
|
|---|
| 37 | */
|
|---|
| 38 | hasWarnings() {
|
|---|
| 39 | return (
|
|---|
| 40 | this.compilation.getWarnings().length > 0 ||
|
|---|
| 41 | this.compilation.children.some((child) => child.getStats().hasWarnings())
|
|---|
| 42 | );
|
|---|
| 43 | }
|
|---|
| 44 |
|
|---|
| 45 | /**
|
|---|
| 46 | * Checks whether this stats has errors.
|
|---|
| 47 | * @returns {boolean} true if the compilation encountered an error
|
|---|
| 48 | */
|
|---|
| 49 | hasErrors() {
|
|---|
| 50 | return (
|
|---|
| 51 | this.compilation.errors.length > 0 ||
|
|---|
| 52 | this.compilation.children.some((child) => child.getStats().hasErrors())
|
|---|
| 53 | );
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | /**
|
|---|
| 57 | * Returns json output.
|
|---|
| 58 | * @param {StatsValue=} options stats options
|
|---|
| 59 | * @returns {StatsCompilation} json output
|
|---|
| 60 | */
|
|---|
| 61 | toJson(options) {
|
|---|
| 62 | const normalizedOptions = this.compilation.createStatsOptions(options, {
|
|---|
| 63 | forToString: false
|
|---|
| 64 | });
|
|---|
| 65 |
|
|---|
| 66 | const statsFactory = this.compilation.createStatsFactory(normalizedOptions);
|
|---|
| 67 |
|
|---|
| 68 | return statsFactory.create("compilation", this.compilation, {
|
|---|
| 69 | compilation: this.compilation
|
|---|
| 70 | });
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | /**
|
|---|
| 74 | * Returns a string representation.
|
|---|
| 75 | * @param {StatsValue=} options stats options
|
|---|
| 76 | * @returns {string} string output
|
|---|
| 77 | */
|
|---|
| 78 | toString(options) {
|
|---|
| 79 | const normalizedOptions = this.compilation.createStatsOptions(options, {
|
|---|
| 80 | forToString: true
|
|---|
| 81 | });
|
|---|
| 82 |
|
|---|
| 83 | const statsFactory = this.compilation.createStatsFactory(normalizedOptions);
|
|---|
| 84 | const statsPrinter = this.compilation.createStatsPrinter(normalizedOptions);
|
|---|
| 85 |
|
|---|
| 86 | const data = statsFactory.create("compilation", this.compilation, {
|
|---|
| 87 | compilation: this.compilation
|
|---|
| 88 | });
|
|---|
| 89 | const result = statsPrinter.print("compilation", data);
|
|---|
| 90 | return result === undefined ? "" : result;
|
|---|
| 91 | }
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | module.exports = Stats;
|
|---|