@clerc/plugin-friendly-error 1.0.3 → 1.1.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/README.md CHANGED
@@ -2,23 +2,9 @@
2
2
 
3
3
  [![NPM version](https://img.shields.io/npm/v/@clerc/plugin-friendly-error?color=a1b858&label=)](https://www.npmjs.com/package/@clerc/plugin-friendly-error)
4
4
 
5
- Clerc plugin to show friendly error message.
5
+ ## Documenation
6
6
 
7
- ## 📦 Installation
8
-
9
- ```bash
10
- $ npm install @clerc/plugin-friendly-error
11
- $ yarn add @clerc/plugin-friendly-error
12
- $ pnpm add @clerc/plugin-friendly-error
13
- ```
14
-
15
- ## 🚀 Usage
16
-
17
- ```ts
18
- import { friendlyErrorPlugin } from "@clerc/plugin-friendly-error";
19
-
20
- cli.use(friendlyErrorPlugin());
21
- ```
7
+ Read the [documentation](https://clerc.so1ve.dev/official-plugins/plugin-friendly-error.html) for more details.
22
8
 
23
9
  ## 📝 License
24
10
 
package/dist/index.mjs ADDED
@@ -0,0 +1,148 @@
1
+ import { definePlugin } from "@clerc/core";
2
+
3
+ //#region rolldown:runtime
4
+ var __create = Object.create;
5
+ var __defProp = Object.defineProperty;
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clerc/plugin-friendly-error",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "author": "Ray <i@mk1.io> (https://github.com/so1ve)",
5
5
  "type": "module",
6
6
  "description": "Clerc plugin friendly error",
@@ -25,30 +25,21 @@
25
25
  "license": "MIT",
26
26
  "sideEffects": false,
27
27
  "exports": {
28
- ".": "./dist/index.js"
29
- },
30
- "main": "./dist/index.js",
31
- "module": "./dist/index.js",
32
- "types": "dist/index.d.ts",
33
- "typesVersions": {
34
- "*": {
35
- "*": [
36
- "./dist/*",
37
- "./dist/index.d.ts"
38
- ]
39
- }
28
+ ".": "./dist/index.mjs",
29
+ "./package.json": "./package.json"
40
30
  },
31
+ "main": "./dist/index.mjs",
32
+ "module": "./dist/index.mjs",
33
+ "types": "./dist/index.d.mts",
41
34
  "files": [
42
35
  "dist"
43
36
  ],
44
37
  "publishConfig": {
45
38
  "access": "public"
46
39
  },
47
- "dependencies": {
48
- "kons": "^0.7.1"
49
- },
50
40
  "devDependencies": {
51
- "@clerc/core": "1.0.3"
41
+ "kons": "^0.7.1",
42
+ "@clerc/core": "1.1.0"
52
43
  },
53
44
  "peerDependencies": {
54
45
  "@clerc/core": "*"
package/dist/index.js DELETED
@@ -1,11 +0,0 @@
1
- import { definePlugin } from "@clerc/core";
2
- import * as kons from "kons";
3
-
4
- //#region src/index.ts
5
- const friendlyErrorPlugin = ({ target = kons.error } = {}) => definePlugin({ setup: (cli) => cli.errorHandler((err) => {
6
- target(err.message);
7
- process.exit(1);
8
- }) });
9
-
10
- //#endregion
11
- export { friendlyErrorPlugin };
File without changes