@clerc/plugin-friendly-error 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.mjs +5 -148
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,148 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
-
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
11
|
-
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
-
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
14
|
-
key = keys[i];
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
16
|
-
__defProp(to, key, {
|
|
17
|
-
get: ((k) => from[k]).bind(null, key),
|
|
18
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
return to;
|
|
24
|
-
};
|
|
25
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
-
value: mod,
|
|
27
|
-
enumerable: true
|
|
28
|
-
}) : target, mod));
|
|
29
|
-
|
|
30
|
-
//#endregion
|
|
31
|
-
//#region ../../node_modules/.pnpm/picocolors@1.1.1/node_modules/picocolors/picocolors.js
|
|
32
|
-
var require_picocolors = /* @__PURE__ */ __commonJSMin(((exports, module) => {
|
|
33
|
-
let p = process || {}, argv = p.argv || [], env = p.env || {};
|
|
34
|
-
let isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
35
|
-
let formatter = (open, close, replace = open) => (input) => {
|
|
36
|
-
let string = "" + input, index = string.indexOf(close, open.length);
|
|
37
|
-
return ~index ? open + replaceClose(string, close, replace, index) + close : open + string + close;
|
|
38
|
-
};
|
|
39
|
-
let replaceClose = (string, close, replace, index) => {
|
|
40
|
-
let result = "", cursor = 0;
|
|
41
|
-
do {
|
|
42
|
-
result += string.substring(cursor, index) + replace;
|
|
43
|
-
cursor = index + close.length;
|
|
44
|
-
index = string.indexOf(close, cursor);
|
|
45
|
-
} while (~index);
|
|
46
|
-
return result + string.substring(cursor);
|
|
47
|
-
};
|
|
48
|
-
let createColors = (enabled = isColorSupported) => {
|
|
49
|
-
let f = enabled ? formatter : () => String;
|
|
50
|
-
return {
|
|
51
|
-
isColorSupported: enabled,
|
|
52
|
-
reset: f("\x1B[0m", "\x1B[0m"),
|
|
53
|
-
bold: f("\x1B[1m", "\x1B[22m", "\x1B[22m\x1B[1m"),
|
|
54
|
-
dim: f("\x1B[2m", "\x1B[22m", "\x1B[22m\x1B[2m"),
|
|
55
|
-
italic: f("\x1B[3m", "\x1B[23m"),
|
|
56
|
-
underline: f("\x1B[4m", "\x1B[24m"),
|
|
57
|
-
inverse: f("\x1B[7m", "\x1B[27m"),
|
|
58
|
-
hidden: f("\x1B[8m", "\x1B[28m"),
|
|
59
|
-
strikethrough: f("\x1B[9m", "\x1B[29m"),
|
|
60
|
-
black: f("\x1B[30m", "\x1B[39m"),
|
|
61
|
-
red: f("\x1B[31m", "\x1B[39m"),
|
|
62
|
-
green: f("\x1B[32m", "\x1B[39m"),
|
|
63
|
-
yellow: f("\x1B[33m", "\x1B[39m"),
|
|
64
|
-
blue: f("\x1B[34m", "\x1B[39m"),
|
|
65
|
-
magenta: f("\x1B[35m", "\x1B[39m"),
|
|
66
|
-
cyan: f("\x1B[36m", "\x1B[39m"),
|
|
67
|
-
white: f("\x1B[37m", "\x1B[39m"),
|
|
68
|
-
gray: f("\x1B[90m", "\x1B[39m"),
|
|
69
|
-
bgBlack: f("\x1B[40m", "\x1B[49m"),
|
|
70
|
-
bgRed: f("\x1B[41m", "\x1B[49m"),
|
|
71
|
-
bgGreen: f("\x1B[42m", "\x1B[49m"),
|
|
72
|
-
bgYellow: f("\x1B[43m", "\x1B[49m"),
|
|
73
|
-
bgBlue: f("\x1B[44m", "\x1B[49m"),
|
|
74
|
-
bgMagenta: f("\x1B[45m", "\x1B[49m"),
|
|
75
|
-
bgCyan: f("\x1B[46m", "\x1B[49m"),
|
|
76
|
-
bgWhite: f("\x1B[47m", "\x1B[49m"),
|
|
77
|
-
blackBright: f("\x1B[90m", "\x1B[39m"),
|
|
78
|
-
redBright: f("\x1B[91m", "\x1B[39m"),
|
|
79
|
-
greenBright: f("\x1B[92m", "\x1B[39m"),
|
|
80
|
-
yellowBright: f("\x1B[93m", "\x1B[39m"),
|
|
81
|
-
blueBright: f("\x1B[94m", "\x1B[39m"),
|
|
82
|
-
magentaBright: f("\x1B[95m", "\x1B[39m"),
|
|
83
|
-
cyanBright: f("\x1B[96m", "\x1B[39m"),
|
|
84
|
-
whiteBright: f("\x1B[97m", "\x1B[39m"),
|
|
85
|
-
bgBlackBright: f("\x1B[100m", "\x1B[49m"),
|
|
86
|
-
bgRedBright: f("\x1B[101m", "\x1B[49m"),
|
|
87
|
-
bgGreenBright: f("\x1B[102m", "\x1B[49m"),
|
|
88
|
-
bgYellowBright: f("\x1B[103m", "\x1B[49m"),
|
|
89
|
-
bgBlueBright: f("\x1B[104m", "\x1B[49m"),
|
|
90
|
-
bgMagentaBright: f("\x1B[105m", "\x1B[49m"),
|
|
91
|
-
bgCyanBright: f("\x1B[106m", "\x1B[49m"),
|
|
92
|
-
bgWhiteBright: f("\x1B[107m", "\x1B[49m")
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
module.exports = createColors();
|
|
96
|
-
module.exports.createColors = createColors;
|
|
97
|
-
}));
|
|
98
|
-
|
|
99
|
-
//#endregion
|
|
100
|
-
//#region ../../node_modules/.pnpm/kons@0.7.1/node_modules/kons/dist/utils-6230ae77.mjs
|
|
101
|
-
var import_picocolors = /* @__PURE__ */ __toESM(require_picocolors(), 1);
|
|
102
|
-
function parseStack(stack) {
|
|
103
|
-
return stack.split("\n").splice(1).map((l) => l.trim().replace("file://", ""));
|
|
104
|
-
}
|
|
105
|
-
function formatStack(stack) {
|
|
106
|
-
return `
|
|
107
|
-
${parseStack(stack).map((line) => ` ${line.replace(/^at ([\s\S]+) \((.+)\)/, (_, m1, m2) => import_picocolors.default.gray(`at ${m1} (${import_picocolors.default.cyan(m2)})`))}`).join("\n")}`;
|
|
108
|
-
}
|
|
109
|
-
const NEWLINE_RE = /\r?\n/g;
|
|
110
|
-
function formatMessage(messages) {
|
|
111
|
-
return messages.map((m) => {
|
|
112
|
-
if (typeof (m == null ? void 0 : m.stack) === "string") return [m.message, formatStack(m.stack)];
|
|
113
|
-
if (typeof m === "string") return m.split(NEWLINE_RE);
|
|
114
|
-
return m;
|
|
115
|
-
}).flat();
|
|
116
|
-
}
|
|
117
|
-
function createBadge(badgeType, bgColor) {
|
|
118
|
-
const upperType = badgeType.toUpperCase();
|
|
119
|
-
const bgColorFormatter = import_picocolors.default[bgColor];
|
|
120
|
-
return import_picocolors.default.bold(import_picocolors.default.inverse(bgColorFormatter(` ${upperType} `)));
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
//#endregion
|
|
124
|
-
//#region ../../node_modules/.pnpm/kons@0.7.1/node_modules/kons/dist/index.mjs
|
|
125
|
-
function createFormatter(type, bgColor, { target = console.log, textColor, newline = true } = {}) {
|
|
126
|
-
const bgColorFormatter = import_picocolors.default[bgColor];
|
|
127
|
-
const textColorFormatter = textColor ? import_picocolors.default[textColor] : bgColorFormatter;
|
|
128
|
-
return (...messages) => {
|
|
129
|
-
const formattedMessages = formatMessage(messages);
|
|
130
|
-
const badge = createBadge(type, bgColor);
|
|
131
|
-
for (const message of formattedMessages) target(`${badge} ${textColorFormatter(message)}${newline ? "\n" : ""}`);
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
const log = createFormatter("log", "gray");
|
|
135
|
-
const info = createFormatter("info", "blue", { target: console.info });
|
|
136
|
-
const warn = createFormatter("warn", "yellow", { target: console.warn });
|
|
137
|
-
const success = createFormatter("success", "green");
|
|
138
|
-
const error = createFormatter("error", "red", { target: console.error });
|
|
139
|
-
|
|
140
|
-
//#endregion
|
|
141
|
-
//#region src/index.ts
|
|
142
|
-
const friendlyErrorPlugin = ({ target = error } = {}) => definePlugin({ setup: (cli) => cli.errorHandler((err) => {
|
|
143
|
-
target(err.message);
|
|
144
|
-
process.exit(1);
|
|
145
|
-
}) });
|
|
146
|
-
|
|
147
|
-
//#endregion
|
|
148
|
-
export { friendlyErrorPlugin };
|
|
1
|
+
import{definePlugin as e}from"@clerc/core";var t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,s=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),c=(e,t,a,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=i(t),l=0,u=c.length,d;l<u;l++)d=c[l],!o.call(e,d)&&d!==a&&n(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(s=r(t,d))||s.enumerable});return e},l=((e,r,i)=>(i=e==null?{}:t(a(e)),c(r||!e||!e.__esModule?n(i,`default`,{value:e,enumerable:!0}):i,e)))(s(((e,t)=>{let n=process||{},r=n.argv||[],i=n.env||{},a=!(i.NO_COLOR||r.includes(`--no-color`))&&(!!i.FORCE_COLOR||r.includes(`--color`)||n.platform===`win32`||(n.stdout||{}).isTTY&&i.TERM!==`dumb`||!!i.CI),o=(e,t,n=e)=>r=>{let i=``+r,a=i.indexOf(t,e.length);return~a?e+s(i,t,n,a)+t:e+i+t},s=(e,t,n,r)=>{let i=``,a=0;do i+=e.substring(a,r)+n,a=r+t.length,r=e.indexOf(t,a);while(~r);return i+e.substring(a)},c=(e=a)=>{let t=e?o:()=>String;return{isColorSupported:e,reset:t(`\x1B[0m`,`\x1B[0m`),bold:t(`\x1B[1m`,`\x1B[22m`,`\x1B[22m\x1B[1m`),dim:t(`\x1B[2m`,`\x1B[22m`,`\x1B[22m\x1B[2m`),italic:t(`\x1B[3m`,`\x1B[23m`),underline:t(`\x1B[4m`,`\x1B[24m`),inverse:t(`\x1B[7m`,`\x1B[27m`),hidden:t(`\x1B[8m`,`\x1B[28m`),strikethrough:t(`\x1B[9m`,`\x1B[29m`),black:t(`\x1B[30m`,`\x1B[39m`),red:t(`\x1B[31m`,`\x1B[39m`),green:t(`\x1B[32m`,`\x1B[39m`),yellow:t(`\x1B[33m`,`\x1B[39m`),blue:t(`\x1B[34m`,`\x1B[39m`),magenta:t(`\x1B[35m`,`\x1B[39m`),cyan:t(`\x1B[36m`,`\x1B[39m`),white:t(`\x1B[37m`,`\x1B[39m`),gray:t(`\x1B[90m`,`\x1B[39m`),bgBlack:t(`\x1B[40m`,`\x1B[49m`),bgRed:t(`\x1B[41m`,`\x1B[49m`),bgGreen:t(`\x1B[42m`,`\x1B[49m`),bgYellow:t(`\x1B[43m`,`\x1B[49m`),bgBlue:t(`\x1B[44m`,`\x1B[49m`),bgMagenta:t(`\x1B[45m`,`\x1B[49m`),bgCyan:t(`\x1B[46m`,`\x1B[49m`),bgWhite:t(`\x1B[47m`,`\x1B[49m`),blackBright:t(`\x1B[90m`,`\x1B[39m`),redBright:t(`\x1B[91m`,`\x1B[39m`),greenBright:t(`\x1B[92m`,`\x1B[39m`),yellowBright:t(`\x1B[93m`,`\x1B[39m`),blueBright:t(`\x1B[94m`,`\x1B[39m`),magentaBright:t(`\x1B[95m`,`\x1B[39m`),cyanBright:t(`\x1B[96m`,`\x1B[39m`),whiteBright:t(`\x1B[97m`,`\x1B[39m`),bgBlackBright:t(`\x1B[100m`,`\x1B[49m`),bgRedBright:t(`\x1B[101m`,`\x1B[49m`),bgGreenBright:t(`\x1B[102m`,`\x1B[49m`),bgYellowBright:t(`\x1B[103m`,`\x1B[49m`),bgBlueBright:t(`\x1B[104m`,`\x1B[49m`),bgMagentaBright:t(`\x1B[105m`,`\x1B[49m`),bgCyanBright:t(`\x1B[106m`,`\x1B[49m`),bgWhiteBright:t(`\x1B[107m`,`\x1B[49m`)}};t.exports=c(),t.exports.createColors=c}))(),1);function u(e){return e.split(`
|
|
2
|
+
`).splice(1).map(e=>e.trim().replace(`file://`,``))}function d(e){return`
|
|
3
|
+
${u(e).map(e=>` ${e.replace(/^at ([\s\S]+) \((.+)\)/,(e,t,n)=>l.default.gray(`at ${t} (${l.default.cyan(n)})`))}`).join(`
|
|
4
|
+
`)}`}const f=/\r?\n/g;function p(e){return e.map(e=>typeof e?.stack==`string`?[e.message,d(e.stack)]:typeof e==`string`?e.split(f):e).flat()}function m(e,t){let n=e.toUpperCase(),r=l.default[t];return l.default.bold(l.default.inverse(r(` ${n} `)))}function h(e,t,{target:n=console.log,textColor:r,newline:i=!0}={}){let a=l.default[t],o=r?l.default[r]:a;return(...r)=>{let a=p(r),s=m(e,t);for(let e of a)n(`${s} ${o(e)}${i?`
|
|
5
|
+
`:``}`)}}h(`log`,`gray`),h(`info`,`blue`,{target:console.info}),h(`warn`,`yellow`,{target:console.warn}),h(`success`,`green`);const g=h(`error`,`red`,{target:console.error}),_=({target:t=g}={})=>e({setup:e=>e.errorHandler(e=>{t(e.message),process.exit(1)})});export{_ as friendlyErrorPlugin};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clerc/plugin-friendly-error",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "Clerc plugin friendly error",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|
|
41
41
|
"kons": "^0.7.1",
|
|
42
|
-
"@clerc/core": "1.
|
|
42
|
+
"@clerc/core": "1.2.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"@clerc/core": "*"
|