2013-01-31 01:49:25 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2018-07-30 23:08:51 +08:00
|
|
|
|
2017-01-05 01:24:55 +08:00
|
|
|
"use strict";
|
2013-01-31 01:49:25 +08:00
|
|
|
|
2018-07-20 19:35:01 +08:00
|
|
|
/** @typedef {import("./Compilation")} Compilation */
|
2018-12-10 18:34:59 +08:00
|
|
|
|
2017-01-05 01:24:55 +08:00
|
|
|
class Stats {
|
2018-07-20 19:35:01 +08:00
|
|
|
/**
|
|
|
|
* @param {Compilation} compilation webpack compilation
|
|
|
|
*/
|
2017-01-05 01:24:55 +08:00
|
|
|
constructor(compilation) {
|
|
|
|
this.compilation = compilation;
|
|
|
|
this.hash = compilation.hash;
|
2018-03-29 12:49:00 +08:00
|
|
|
this.startTime = undefined;
|
|
|
|
this.endTime = undefined;
|
2017-01-05 01:24:55 +08:00
|
|
|
}
|
2013-01-31 01:49:25 +08:00
|
|
|
|
2018-12-10 18:34:59 +08:00
|
|
|
/**
|
2020-06-04 14:04:07 +08:00
|
|
|
* @returns {boolean} true if the compilation had a warning
|
2018-12-10 18:34:59 +08:00
|
|
|
*/
|
2017-01-05 01:24:55 +08:00
|
|
|
hasWarnings() {
|
2018-02-25 09:00:20 +08:00
|
|
|
return (
|
|
|
|
this.compilation.warnings.length > 0 ||
|
|
|
|
this.compilation.children.some(child => child.getStats().hasWarnings())
|
|
|
|
);
|
2015-08-03 17:01:29 +08:00
|
|
|
}
|
2015-07-13 06:20:09 +08:00
|
|
|
|
2018-12-10 18:34:59 +08:00
|
|
|
/**
|
2020-06-04 14:04:07 +08:00
|
|
|
* @returns {boolean} true if the compilation encountered an error
|
2018-12-10 18:34:59 +08:00
|
|
|
*/
|
2017-01-05 01:24:55 +08:00
|
|
|
hasErrors() {
|
2018-02-25 09:00:20 +08:00
|
|
|
return (
|
|
|
|
this.compilation.errors.length > 0 ||
|
|
|
|
this.compilation.children.some(child => child.getStats().hasErrors())
|
|
|
|
);
|
2015-07-13 06:20:09 +08:00
|
|
|
}
|
2017-01-05 01:24:55 +08:00
|
|
|
|
2018-12-19 01:29:12 +08:00
|
|
|
toJson(options) {
|
|
|
|
options = this.compilation.createStatsOptions(options, {
|
|
|
|
forToString: false
|
2015-04-17 16:17:10 +08:00
|
|
|
});
|
2016-11-29 08:38:17 +08:00
|
|
|
|
2018-12-19 01:29:12 +08:00
|
|
|
const statsFactory = this.compilation.createStatsFactory(options);
|
2018-04-21 19:20:23 +08:00
|
|
|
|
2018-12-19 01:29:12 +08:00
|
|
|
return statsFactory.create("compilation", this.compilation, {
|
|
|
|
compilation: this.compilation,
|
|
|
|
startTime: this.startTime,
|
|
|
|
endTime: this.endTime
|
|
|
|
});
|
2013-01-31 01:49:25 +08:00
|
|
|
}
|
2016-11-05 02:43:24 +08:00
|
|
|
|
2017-01-05 01:24:55 +08:00
|
|
|
toString(options) {
|
2018-12-19 01:29:12 +08:00
|
|
|
options = this.compilation.createStatsOptions(options, {
|
|
|
|
forToString: true
|
|
|
|
});
|
2017-01-05 01:24:55 +08:00
|
|
|
|
2018-12-19 01:29:12 +08:00
|
|
|
const statsFactory = this.compilation.createStatsFactory(options);
|
|
|
|
const statsPrinter = this.compilation.createStatsPrinter(options);
|
2017-01-11 17:51:58 +08:00
|
|
|
|
2018-12-19 01:29:12 +08:00
|
|
|
const data = statsFactory.create("compilation", this.compilation, {
|
|
|
|
compilation: this.compilation,
|
|
|
|
startTime: this.startTime,
|
|
|
|
endTime: this.endTime
|
|
|
|
});
|
|
|
|
const result = statsPrinter.print("compilation", data);
|
|
|
|
return result === undefined ? "" : result;
|
2015-08-03 17:01:29 +08:00
|
|
|
}
|
2017-01-05 01:24:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Stats;
|