-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathwebpack-diagnostics.ts
40 lines (36 loc) · 1.22 KB
/
webpack-diagnostics.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import * as webpack from 'webpack';
const WebpackError = require('webpack/lib/WebpackError');
const isWebpackFiveOrHigher = (() => {
if (typeof webpack.version === 'string') {
const versionParts = webpack.version.split('.');
if (versionParts[0] && Number(versionParts[0]) >= 5) {
return true;
}
}
return false;
})();
export function addWarning(compilation: webpack.compilation.Compilation, message: string): void {
if (isWebpackFiveOrHigher) {
compilation.warnings.push(new WebpackError(message));
} else {
// Allows building with either Webpack 4 or 5+ types
// tslint:disable-next-line: no-any
compilation.warnings.push(message as any);
}
}
export function addError(compilation: webpack.compilation.Compilation, message: string): void {
if (isWebpackFiveOrHigher) {
compilation.errors.push(new WebpackError(message));
} else {
// Allows building with either Webpack 4 or 5+ types
// tslint:disable-next-line: no-any
compilation.errors.push(new Error(message) as any);
}
}