-
-
Notifications
You must be signed in to change notification settings - Fork 237
/
issue-webpack-error.ts
37 lines (28 loc) · 1.17 KB
/
issue-webpack-error.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
import path from 'path';
import chalk from 'chalk';
import webpack from 'webpack';
import type { FormatterPathType } from '../formatter';
import { forwardSlash } from '../utils/path/forward-slash';
import { relativeToContext } from '../utils/path/relative-to-context';
import type { Issue } from './issue';
import { formatIssueLocation } from './issue-location';
class IssueWebpackError extends webpack.WebpackError {
readonly hideStack = true;
constructor(message: string, pathType: FormatterPathType, readonly issue: Issue) {
super(message);
// to display issue location using `loc` property, webpack requires `error.module` which
// should be a NormalModule instance.
// to avoid such a dependency, we do a workaround - error.file will contain formatted location instead
if (issue.file) {
this.file =
pathType === 'absolute'
? forwardSlash(path.resolve(issue.file))
: relativeToContext(issue.file, process.cwd());
if (issue.location) {
this.file += `:${chalk.green.bold(formatIssueLocation(issue.location))}`;
}
}
Error.captureStackTrace(this, this.constructor);
}
}
export { IssueWebpackError };