UNPKG

1.48 kBJavaScriptView Raw
1///@ts-check
2"use strict";
3const colors = require("ansi-colors");
4const color = require("./color");
5const log = require("./logger");
6
7/**
8 * @param {string} TITLE
9 * @param {string} [sub]
10 */
11module.exports = function(TITLE, sub) {
12 TITLE = color(TITLE);
13 if (sub) {
14 TITLE += " " + colors.whiteBright(`<${colors.bold.underline(sub)}>`);
15 }
16 /**
17 * @param {any} info
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.yellow(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};