webpack/lib/Stats.js

74 lines
1.7 KiB
JavaScript
Raw Normal View History

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
"use strict";
2013-01-31 01:49:25 +08:00
/** @typedef {import("./Compilation")} Compilation */
2018-12-10 18:34:59 +08:00
class Stats {
/**
* @param {Compilation} compilation webpack compilation
*/
constructor(compilation) {
this.compilation = compilation;
this.hash = compilation.hash;
this.startTime = undefined;
this.endTime = undefined;
}
2013-01-31 01:49:25 +08:00
2018-12-10 18:34:59 +08:00
/**
* @returns {boolean} true if the compilation encountered an error
*/
hasWarnings() {
2018-02-25 09:00:20 +08:00
return (
this.compilation.warnings.length > 0 ||
this.compilation.children.some(child => child.getStats().hasWarnings())
);
}
2015-07-13 06:20:09 +08:00
2018-12-10 18:34:59 +08:00
/**
* @returns {boolean} true if the compilation had a warning
*/
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
}
toJson(options) {
options = this.compilation.createStatsOptions(options, {
forToString: false
2015-04-17 16:17:10 +08:00
});
const statsFactory = this.compilation.createStatsFactory(options);
return statsFactory.create("compilation", this.compilation, {
compilation: this.compilation,
startTime: this.startTime,
endTime: this.endTime
});
2013-01-31 01:49:25 +08:00
}
toString(options) {
options = this.compilation.createStatsOptions(options, {
forToString: true
});
const statsFactory = this.compilation.createStatsFactory(options);
const statsPrinter = this.compilation.createStatsPrinter(options);
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;
}
}
module.exports = Stats;