1 |
|
2 | "use strict";
|
3 | const colors = require("ansi-colors");
|
4 | const color = require("./color");
|
5 | const log = require("./logger");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | module.exports = function(TITLE, sub) {
|
12 | TITLE = color(TITLE);
|
13 | if (sub) {
|
14 | TITLE += " " + colors.whiteBright(`<${colors.bold.underline(sub)}>`);
|
15 | }
|
16 | |
17 |
|
18 |
|
19 | function logError(info) {
|
20 | const skip = process.env.NO_WARN;
|
21 | if (!skip) {
|
22 | if (typeof info === "string" || !info) {
|
23 | log.warn(TITLE, info || "");
|
24 | } else {
|
25 | log.warn(TITLE, colors.yellowBright(info.message || ""), colors.gray.bgYellowBright.bold(info.code || ""));
|
26 |
|
27 | if (info.loc) {
|
28 | log.warn(
|
29 | colors.gray("↓"),
|
30 | colors.bgYellow.gray("warning"),
|
31 | "@line",
|
32 | colors.yellowBright(info.loc.line),
|
33 | "col",
|
34 | colors.yellowBright(info.loc.column),
|
35 | "in",
|
36 | colors.blue.underline(info.loc.file || ""),
|
37 | colors.gray("↓\n") + info.frame,
|
38 | );
|
39 | }
|
40 | if (info.url) {
|
41 | log.warn("see →", colors.blue.underline(info.url), "for warning detail.");
|
42 | }
|
43 | }
|
44 | }
|
45 | }
|
46 | return logError;
|
47 | };
|