@nasti-toolchain/nasti 2.5.0 → 2.5.2
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 +34 -2
- package/dist/build-CENae4VM.js +748 -0
- package/dist/build-CENae4VM.js.map +1 -0
- package/dist/build-vjh6h7PB.cjs +786 -0
- package/dist/build-vjh6h7PB.cjs.map +1 -0
- package/dist/cli.cjs +166 -7608
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.d.cts +1 -2
- package/dist/cli.d.ts +1 -2
- package/dist/cli.js +166 -7606
- package/dist/cli.js.map +1 -1
- package/dist/client/hmr.cjs +0 -19
- package/dist/client/hmr.d.cts +14 -12
- package/dist/client/hmr.d.cts.map +1 -0
- package/dist/client/hmr.d.ts +14 -12
- package/dist/client/hmr.d.ts.map +1 -0
- package/dist/client/hmr.js +1 -1
- package/dist/dev-engine-DJL9sfv5.cjs +473 -0
- package/dist/dev-engine-DJL9sfv5.cjs.map +1 -0
- package/dist/dev-engine-DapuTPIz.js +469 -0
- package/dist/dev-engine-DapuTPIz.js.map +1 -0
- package/dist/electron-Bj8H-BJ6.js +278 -0
- package/dist/electron-Bj8H-BJ6.js.map +1 -0
- package/dist/electron-D0PSXz-a.cjs +316 -0
- package/dist/electron-D0PSXz-a.cjs.map +1 -0
- package/dist/electron-dev-BzI2IFnR.cjs +272 -0
- package/dist/electron-dev-BzI2IFnR.cjs.map +1 -0
- package/dist/electron-dev-CM15gsFp.js +251 -0
- package/dist/electron-dev-CM15gsFp.js.map +1 -0
- package/dist/env-GY7K1zPK.js +833 -0
- package/dist/env-GY7K1zPK.js.map +1 -0
- package/dist/env-lOj3yw8v.cjs +924 -0
- package/dist/env-lOj3yw8v.cjs.map +1 -0
- package/dist/environment-B2jCrhY2.js +1361 -0
- package/dist/environment-B2jCrhY2.js.map +1 -0
- package/dist/environment-CjmvoHIG.cjs +1443 -0
- package/dist/environment-CjmvoHIG.cjs.map +1 -0
- package/dist/index.cjs +453 -7976
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +872 -817
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +872 -817
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +418 -7939
- package/dist/index.js.map +1 -1
- package/dist/logger-BVZwdqqT.js +116 -0
- package/dist/logger-BVZwdqqT.js.map +1 -0
- package/dist/logger-M7AuVVTV.cjs +171 -0
- package/dist/logger-M7AuVVTV.cjs.map +1 -0
- package/dist/runnable-environment-BjoOvdDa.js +1345 -0
- package/dist/runnable-environment-BjoOvdDa.js.map +1 -0
- package/dist/runnable-environment-ByA3DHQ6.cjs +1351 -0
- package/dist/runnable-environment-ByA3DHQ6.cjs.map +1 -0
- package/dist/server-Bqgl25z0.js +1871 -0
- package/dist/server-Bqgl25z0.js.map +1 -0
- package/dist/server-BynlMdFc.cjs +1895 -0
- package/dist/server-BynlMdFc.cjs.map +1 -0
- package/package.json +20 -10
- package/dist/client/hmr.cjs.map +0 -1
- package/dist/client/hmr.js.map +0 -1
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import "node:module";
|
|
2
|
+
import readline from "node:readline";
|
|
3
|
+
import pc from "picocolors";
|
|
4
|
+
//#region \0rolldown/runtime.js
|
|
5
|
+
var __defProp = Object.defineProperty;
|
|
6
|
+
var __exportAll = (all, no_symbols) => {
|
|
7
|
+
let target = {};
|
|
8
|
+
for (var name in all) __defProp(target, name, {
|
|
9
|
+
get: all[name],
|
|
10
|
+
enumerable: true
|
|
11
|
+
});
|
|
12
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
13
|
+
return target;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/core/logger.ts
|
|
17
|
+
var logger_exports = /* @__PURE__ */ __exportAll({
|
|
18
|
+
LogLevels: () => LogLevels,
|
|
19
|
+
createLogger: () => createLogger,
|
|
20
|
+
printServerUrls: () => printServerUrls
|
|
21
|
+
});
|
|
22
|
+
const LogLevels = {
|
|
23
|
+
silent: 0,
|
|
24
|
+
error: 1,
|
|
25
|
+
warn: 2,
|
|
26
|
+
info: 3
|
|
27
|
+
};
|
|
28
|
+
let lastType;
|
|
29
|
+
let lastMsg;
|
|
30
|
+
let sameCount = 0;
|
|
31
|
+
function getTimeFormatter() {
|
|
32
|
+
return new Intl.DateTimeFormat(void 0, {
|
|
33
|
+
hour: "numeric",
|
|
34
|
+
minute: "numeric",
|
|
35
|
+
second: "numeric"
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function createLogger(level = "info", options = {}) {
|
|
39
|
+
if (options.customLogger) return options.customLogger;
|
|
40
|
+
const timeFormatter = getTimeFormatter();
|
|
41
|
+
const loggedErrors = /* @__PURE__ */ new WeakSet();
|
|
42
|
+
const { prefix = "[nasti]", allowClearScreen = true, console: console_ = console } = options;
|
|
43
|
+
const thresh = LogLevels[level];
|
|
44
|
+
const canClearScreen = allowClearScreen && process.stdout.isTTY && !process.env.CI;
|
|
45
|
+
const clear = canClearScreen ? clearScreen : () => {};
|
|
46
|
+
function format(type, msg, options = {}) {
|
|
47
|
+
if (options.timestamp) {
|
|
48
|
+
const tag = type === "info" ? pc.cyan(pc.bold(prefix)) : type === "warn" ? pc.yellow(pc.bold(prefix)) : pc.red(pc.bold(prefix));
|
|
49
|
+
return `${pc.dim(timeFormatter.format(/* @__PURE__ */ new Date()))} ${tag} ${msg}`;
|
|
50
|
+
}
|
|
51
|
+
return msg;
|
|
52
|
+
}
|
|
53
|
+
function output(type, msg, options = {}) {
|
|
54
|
+
if (thresh < LogLevels[type]) return;
|
|
55
|
+
const method = type === "info" ? "log" : type;
|
|
56
|
+
if (options.error) loggedErrors.add(options.error);
|
|
57
|
+
if (canClearScreen) {
|
|
58
|
+
if (type === lastType && msg === lastMsg) {
|
|
59
|
+
sameCount++;
|
|
60
|
+
clear();
|
|
61
|
+
console_[method](format(type, msg, options), pc.yellow(`(x${sameCount + 1})`));
|
|
62
|
+
} else {
|
|
63
|
+
sameCount = 0;
|
|
64
|
+
lastMsg = msg;
|
|
65
|
+
lastType = type;
|
|
66
|
+
if (options.clear) clear();
|
|
67
|
+
console_[method](format(type, msg, options));
|
|
68
|
+
}
|
|
69
|
+
} else console_[method](format(type, msg, options));
|
|
70
|
+
}
|
|
71
|
+
const warnedMessages = /* @__PURE__ */ new Set();
|
|
72
|
+
const logger = {
|
|
73
|
+
hasWarned: false,
|
|
74
|
+
info(msg, opts) {
|
|
75
|
+
output("info", msg, opts);
|
|
76
|
+
},
|
|
77
|
+
warn(msg, opts) {
|
|
78
|
+
logger.hasWarned = true;
|
|
79
|
+
output("warn", msg, opts);
|
|
80
|
+
},
|
|
81
|
+
warnOnce(msg, opts) {
|
|
82
|
+
if (warnedMessages.has(msg)) return;
|
|
83
|
+
logger.hasWarned = true;
|
|
84
|
+
output("warn", msg, opts);
|
|
85
|
+
warnedMessages.add(msg);
|
|
86
|
+
},
|
|
87
|
+
error(msg, opts) {
|
|
88
|
+
output("error", msg, opts);
|
|
89
|
+
},
|
|
90
|
+
clearScreen(type) {
|
|
91
|
+
if (thresh >= LogLevels[type]) clear();
|
|
92
|
+
},
|
|
93
|
+
hasErrorLogged(error) {
|
|
94
|
+
return loggedErrors.has(error);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
return logger;
|
|
98
|
+
}
|
|
99
|
+
function clearScreen() {
|
|
100
|
+
const repeatCount = process.stdout.rows - 2;
|
|
101
|
+
const blank = repeatCount > 0 ? "\n".repeat(repeatCount) : "";
|
|
102
|
+
console.log(blank);
|
|
103
|
+
readline.cursorTo(process.stdout, 0, 0);
|
|
104
|
+
readline.clearScreenDown(process.stdout);
|
|
105
|
+
}
|
|
106
|
+
/** 打印 dev server 地址:➜ Local / Network,端口加粗 */
|
|
107
|
+
function printServerUrls(urls, info) {
|
|
108
|
+
const colorUrl = (url) => pc.cyan(url.replace(/:(\d+)\//, (_, port) => `:${pc.bold(port)}/`));
|
|
109
|
+
for (const url of urls.local) info(` ${pc.green("➜")} ${pc.bold("Local")}: ${colorUrl(url)}`);
|
|
110
|
+
for (const url of urls.network) info(` ${pc.green("➜")} ${pc.bold("Network")}: ${colorUrl(url)}`);
|
|
111
|
+
if (urls.network.length === 0) info(pc.dim(` ${pc.green("➜")} ${pc.bold("Network")}: use `) + pc.bold("--host") + pc.dim(" to expose"));
|
|
112
|
+
}
|
|
113
|
+
//#endregion
|
|
114
|
+
export { __exportAll as a, printServerUrls as i, createLogger as n, logger_exports as r, LogLevels as t };
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=logger-BVZwdqqT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-BVZwdqqT.js","names":[],"sources":["../src/core/logger.ts"],"sourcesContent":["// Logger - 真正的日志系统(仿 Vite node/logger.ts)\n// 接线 config.logLevel,统一 dev/build 输出面\nimport readline from 'node:readline'\nimport pc from 'picocolors'\n\nexport type LogType = 'error' | 'warn' | 'info'\nexport type LogLevel = LogType | 'silent'\n\nexport interface LogOptions {\n /** 是否清屏(仅 allowClearScreen 且 TTY 下生效) */\n clear?: boolean\n /** 是否带 HH:mm:ss 时间戳前缀 */\n timestamp?: boolean\n /** 关联的 Error(用于 hasErrorLogged 去重) */\n error?: Error | null\n}\n\nexport interface Logger {\n info(msg: string, options?: LogOptions): void\n warn(msg: string, options?: LogOptions): void\n /** 同一条 warn 整个进程只输出一次 */\n warnOnce(msg: string, options?: LogOptions): void\n error(msg: string, options?: LogOptions): void\n clearScreen(type: LogType): void\n /** 该 Error 是否已经走 logger.error 输出过(避免 CLI 兜底重复打印) */\n hasErrorLogged(error: Error): boolean\n hasWarned: boolean\n}\n\nexport interface LoggerOptions {\n prefix?: string\n allowClearScreen?: boolean\n customLogger?: Logger\n console?: Console\n}\n\nexport const LogLevels: Record<LogLevel, number> = {\n silent: 0,\n error: 1,\n warn: 2,\n info: 3,\n}\n\nlet lastType: LogType | undefined\nlet lastMsg: string | undefined\nlet sameCount = 0\n\nfunction getTimeFormatter(): Intl.DateTimeFormat {\n return new Intl.DateTimeFormat(undefined, {\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n })\n}\n\nexport function createLogger(\n level: LogLevel = 'info',\n options: LoggerOptions = {},\n): Logger {\n if (options.customLogger) {\n return options.customLogger\n }\n\n const timeFormatter = getTimeFormatter()\n const loggedErrors = new WeakSet<Error>()\n const { prefix = '[nasti]', allowClearScreen = true, console: console_ = console } = options\n const thresh = LogLevels[level]\n const canClearScreen =\n allowClearScreen && process.stdout.isTTY && !process.env.CI\n const clear = canClearScreen ? clearScreen : () => {}\n\n function format(type: LogType, msg: string, options: LogOptions = {}): string {\n if (options.timestamp) {\n const tag =\n type === 'info'\n ? pc.cyan(pc.bold(prefix))\n : type === 'warn'\n ? pc.yellow(pc.bold(prefix))\n : pc.red(pc.bold(prefix))\n return `${pc.dim(timeFormatter.format(new Date()))} ${tag} ${msg}`\n }\n return msg\n }\n\n function output(type: LogType, msg: string, options: LogOptions = {}): void {\n if (thresh < LogLevels[type]) return\n const method = type === 'info' ? 'log' : type\n\n if (options.error) {\n loggedErrors.add(options.error)\n }\n if (canClearScreen) {\n // 同消息折叠为 (xN)\n if (type === lastType && msg === lastMsg) {\n sameCount++\n clear()\n console_[method](format(type, msg, options), pc.yellow(`(x${sameCount + 1})`))\n } else {\n sameCount = 0\n lastMsg = msg\n lastType = type\n if (options.clear) clear()\n console_[method](format(type, msg, options))\n }\n } else {\n console_[method](format(type, msg, options))\n }\n }\n\n const warnedMessages = new Set<string>()\n\n const logger: Logger = {\n hasWarned: false,\n info(msg, opts) {\n output('info', msg, opts)\n },\n warn(msg, opts) {\n logger.hasWarned = true\n output('warn', msg, opts)\n },\n warnOnce(msg, opts) {\n if (warnedMessages.has(msg)) return\n logger.hasWarned = true\n output('warn', msg, opts)\n warnedMessages.add(msg)\n },\n error(msg, opts) {\n output('error', msg, opts)\n },\n clearScreen(type) {\n if (thresh >= LogLevels[type]) clear()\n },\n hasErrorLogged(error) {\n return loggedErrors.has(error)\n },\n }\n\n return logger\n}\n\nfunction clearScreen(): void {\n const repeatCount = process.stdout.rows - 2\n const blank = repeatCount > 0 ? '\\n'.repeat(repeatCount) : ''\n console.log(blank)\n readline.cursorTo(process.stdout, 0, 0)\n readline.clearScreenDown(process.stdout)\n}\n\nexport interface ServerUrls {\n local: string[]\n network: string[]\n}\n\n/** 打印 dev server 地址:➜ Local / Network,端口加粗 */\nexport function printServerUrls(\n urls: ServerUrls,\n info: Logger['info'],\n): void {\n const colorUrl = (url: string) =>\n pc.cyan(url.replace(/:(\\d+)\\//, (_, port) => `:${pc.bold(port)}/`))\n for (const url of urls.local) {\n info(` ${pc.green('➜')} ${pc.bold('Local')}: ${colorUrl(url)}`)\n }\n for (const url of urls.network) {\n info(` ${pc.green('➜')} ${pc.bold('Network')}: ${colorUrl(url)}`)\n }\n if (urls.network.length === 0) {\n info(\n pc.dim(` ${pc.green('➜')} ${pc.bold('Network')}: use `) +\n pc.bold('--host') +\n pc.dim(' to expose'),\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,YAAsC;CACjD,QAAQ;CACR,OAAO;CACP,MAAM;CACN,MAAM;AACR;AAEA,IAAI;AACJ,IAAI;AACJ,IAAI,YAAY;AAEhB,SAAS,mBAAwC;CAC/C,OAAO,IAAI,KAAK,eAAe,KAAA,GAAW;EACxC,MAAM;EACN,QAAQ;EACR,QAAQ;CACV,CAAC;AACH;AAEA,SAAgB,aACd,QAAkB,QAClB,UAAyB,CAAC,GAClB;CACR,IAAI,QAAQ,cACV,OAAO,QAAQ;CAGjB,MAAM,gBAAgB,iBAAiB;CACvC,MAAM,+BAAe,IAAI,QAAe;CACxC,MAAM,EAAE,SAAS,WAAW,mBAAmB,MAAM,SAAS,WAAW,YAAY;CACrF,MAAM,SAAS,UAAU;CACzB,MAAM,iBACJ,oBAAoB,QAAQ,OAAO,SAAS,CAAC,QAAQ,IAAI;CAC3D,MAAM,QAAQ,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GACxB,eAAe,IAAI,GAAG;EACxB;EACA,MAAM,KAAK,MAAM;GACf,OAAO,SAAS,KAAK,IAAI;EAC3B;EACA,YAAY,MAAM;GAChB,IAAI,UAAU,UAAU,OAAO,MAAM;EACvC;EACA,eAAe,OAAO;GACpB,OAAO,aAAa,IAAI,KAAK;EAC/B;CACF;CAEA,OAAO;AACT;AAEA,SAAS,cAAoB;CAC3B,MAAM,cAAc,QAAQ,OAAO,OAAO;CAC1C,MAAM,QAAQ,cAAc,IAAI,KAAK,OAAO,WAAW,IAAI;CAC3D,QAAQ,IAAI,KAAK;CACjB,SAAS,SAAS,QAAQ,QAAQ,GAAG,CAAC;CACtC,SAAS,gBAAgB,QAAQ,MAAM;AACzC;;AAQA,SAAgB,gBACd,MACA,MACM;CACN,MAAM,YAAY,QAChB,GAAG,KAAK,IAAI,QAAQ,aAAa,GAAG,SAAS,IAAI,GAAG,KAAK,IAAI,EAAE,EAAE,CAAC;CACpE,KAAK,MAAM,OAAO,KAAK,OACrB,KAAK,KAAK,GAAG,MAAM,GAAG,EAAE,IAAI,GAAG,KAAK,OAAO,EAAE,MAAM,SAAS,GAAG,GAAG;CAEpE,KAAK,MAAM,OAAO,KAAK,SACrB,KAAK,KAAK,GAAG,MAAM,GAAG,EAAE,IAAI,GAAG,KAAK,SAAS,EAAE,IAAI,SAAS,GAAG,GAAG;CAEpE,IAAI,KAAK,QAAQ,WAAW,GAC1B,KACE,GAAG,IAAI,KAAK,GAAG,MAAM,GAAG,EAAE,IAAI,GAAG,KAAK,SAAS,EAAE,OAAO,IACtD,GAAG,KAAK,QAAQ,IAChB,GAAG,IAAI,YAAY,CACvB;AAEJ"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __exportAll = (all, no_symbols) => {
|
|
9
|
+
let target = {};
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
15
|
+
return target;
|
|
16
|
+
};
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
19
|
+
key = keys[i];
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
21
|
+
get: ((k) => from[k]).bind(null, key),
|
|
22
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return to;
|
|
26
|
+
};
|
|
27
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
//#endregion
|
|
32
|
+
let node_readline = require("node:readline");
|
|
33
|
+
node_readline = __toESM(node_readline, 1);
|
|
34
|
+
let picocolors = require("picocolors");
|
|
35
|
+
picocolors = __toESM(picocolors, 1);
|
|
36
|
+
//#region src/core/logger.ts
|
|
37
|
+
var logger_exports = /* @__PURE__ */ __exportAll({
|
|
38
|
+
LogLevels: () => LogLevels,
|
|
39
|
+
createLogger: () => createLogger,
|
|
40
|
+
printServerUrls: () => printServerUrls
|
|
41
|
+
});
|
|
42
|
+
const LogLevels = {
|
|
43
|
+
silent: 0,
|
|
44
|
+
error: 1,
|
|
45
|
+
warn: 2,
|
|
46
|
+
info: 3
|
|
47
|
+
};
|
|
48
|
+
let lastType;
|
|
49
|
+
let lastMsg;
|
|
50
|
+
let sameCount = 0;
|
|
51
|
+
function getTimeFormatter() {
|
|
52
|
+
return new Intl.DateTimeFormat(void 0, {
|
|
53
|
+
hour: "numeric",
|
|
54
|
+
minute: "numeric",
|
|
55
|
+
second: "numeric"
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function createLogger(level = "info", options = {}) {
|
|
59
|
+
if (options.customLogger) return options.customLogger;
|
|
60
|
+
const timeFormatter = getTimeFormatter();
|
|
61
|
+
const loggedErrors = /* @__PURE__ */ new WeakSet();
|
|
62
|
+
const { prefix = "[nasti]", allowClearScreen = true, console: console_ = console } = options;
|
|
63
|
+
const thresh = LogLevels[level];
|
|
64
|
+
const canClearScreen = allowClearScreen && process.stdout.isTTY && !process.env.CI;
|
|
65
|
+
const clear = canClearScreen ? clearScreen : () => {};
|
|
66
|
+
function format(type, msg, options = {}) {
|
|
67
|
+
if (options.timestamp) {
|
|
68
|
+
const tag = type === "info" ? picocolors.default.cyan(picocolors.default.bold(prefix)) : type === "warn" ? picocolors.default.yellow(picocolors.default.bold(prefix)) : picocolors.default.red(picocolors.default.bold(prefix));
|
|
69
|
+
return `${picocolors.default.dim(timeFormatter.format(/* @__PURE__ */ new Date()))} ${tag} ${msg}`;
|
|
70
|
+
}
|
|
71
|
+
return msg;
|
|
72
|
+
}
|
|
73
|
+
function output(type, msg, options = {}) {
|
|
74
|
+
if (thresh < LogLevels[type]) return;
|
|
75
|
+
const method = type === "info" ? "log" : type;
|
|
76
|
+
if (options.error) loggedErrors.add(options.error);
|
|
77
|
+
if (canClearScreen) {
|
|
78
|
+
if (type === lastType && msg === lastMsg) {
|
|
79
|
+
sameCount++;
|
|
80
|
+
clear();
|
|
81
|
+
console_[method](format(type, msg, options), picocolors.default.yellow(`(x${sameCount + 1})`));
|
|
82
|
+
} else {
|
|
83
|
+
sameCount = 0;
|
|
84
|
+
lastMsg = msg;
|
|
85
|
+
lastType = type;
|
|
86
|
+
if (options.clear) clear();
|
|
87
|
+
console_[method](format(type, msg, options));
|
|
88
|
+
}
|
|
89
|
+
} else console_[method](format(type, msg, options));
|
|
90
|
+
}
|
|
91
|
+
const warnedMessages = /* @__PURE__ */ new Set();
|
|
92
|
+
const logger = {
|
|
93
|
+
hasWarned: false,
|
|
94
|
+
info(msg, opts) {
|
|
95
|
+
output("info", msg, opts);
|
|
96
|
+
},
|
|
97
|
+
warn(msg, opts) {
|
|
98
|
+
logger.hasWarned = true;
|
|
99
|
+
output("warn", msg, opts);
|
|
100
|
+
},
|
|
101
|
+
warnOnce(msg, opts) {
|
|
102
|
+
if (warnedMessages.has(msg)) return;
|
|
103
|
+
logger.hasWarned = true;
|
|
104
|
+
output("warn", msg, opts);
|
|
105
|
+
warnedMessages.add(msg);
|
|
106
|
+
},
|
|
107
|
+
error(msg, opts) {
|
|
108
|
+
output("error", msg, opts);
|
|
109
|
+
},
|
|
110
|
+
clearScreen(type) {
|
|
111
|
+
if (thresh >= LogLevels[type]) clear();
|
|
112
|
+
},
|
|
113
|
+
hasErrorLogged(error) {
|
|
114
|
+
return loggedErrors.has(error);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
return logger;
|
|
118
|
+
}
|
|
119
|
+
function clearScreen() {
|
|
120
|
+
const repeatCount = process.stdout.rows - 2;
|
|
121
|
+
const blank = repeatCount > 0 ? "\n".repeat(repeatCount) : "";
|
|
122
|
+
console.log(blank);
|
|
123
|
+
node_readline.default.cursorTo(process.stdout, 0, 0);
|
|
124
|
+
node_readline.default.clearScreenDown(process.stdout);
|
|
125
|
+
}
|
|
126
|
+
/** 打印 dev server 地址:➜ Local / Network,端口加粗 */
|
|
127
|
+
function printServerUrls(urls, info) {
|
|
128
|
+
const colorUrl = (url) => picocolors.default.cyan(url.replace(/:(\d+)\//, (_, port) => `:${picocolors.default.bold(port)}/`));
|
|
129
|
+
for (const url of urls.local) info(` ${picocolors.default.green("➜")} ${picocolors.default.bold("Local")}: ${colorUrl(url)}`);
|
|
130
|
+
for (const url of urls.network) info(` ${picocolors.default.green("➜")} ${picocolors.default.bold("Network")}: ${colorUrl(url)}`);
|
|
131
|
+
if (urls.network.length === 0) info(picocolors.default.dim(` ${picocolors.default.green("➜")} ${picocolors.default.bold("Network")}: use `) + picocolors.default.bold("--host") + picocolors.default.dim(" to expose"));
|
|
132
|
+
}
|
|
133
|
+
//#endregion
|
|
134
|
+
Object.defineProperty(exports, "LogLevels", {
|
|
135
|
+
enumerable: true,
|
|
136
|
+
get: function() {
|
|
137
|
+
return LogLevels;
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
Object.defineProperty(exports, "__exportAll", {
|
|
141
|
+
enumerable: true,
|
|
142
|
+
get: function() {
|
|
143
|
+
return __exportAll;
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
Object.defineProperty(exports, "__toESM", {
|
|
147
|
+
enumerable: true,
|
|
148
|
+
get: function() {
|
|
149
|
+
return __toESM;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
Object.defineProperty(exports, "createLogger", {
|
|
153
|
+
enumerable: true,
|
|
154
|
+
get: function() {
|
|
155
|
+
return createLogger;
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
Object.defineProperty(exports, "logger_exports", {
|
|
159
|
+
enumerable: true,
|
|
160
|
+
get: function() {
|
|
161
|
+
return logger_exports;
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
Object.defineProperty(exports, "printServerUrls", {
|
|
165
|
+
enumerable: true,
|
|
166
|
+
get: function() {
|
|
167
|
+
return printServerUrls;
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
//# sourceMappingURL=logger-M7AuVVTV.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger-M7AuVVTV.cjs","names":["pc"],"sources":["../src/core/logger.ts"],"sourcesContent":["// Logger - 真正的日志系统(仿 Vite node/logger.ts)\n// 接线 config.logLevel,统一 dev/build 输出面\nimport readline from 'node:readline'\nimport pc from 'picocolors'\n\nexport type LogType = 'error' | 'warn' | 'info'\nexport type LogLevel = LogType | 'silent'\n\nexport interface LogOptions {\n /** 是否清屏(仅 allowClearScreen 且 TTY 下生效) */\n clear?: boolean\n /** 是否带 HH:mm:ss 时间戳前缀 */\n timestamp?: boolean\n /** 关联的 Error(用于 hasErrorLogged 去重) */\n error?: Error | null\n}\n\nexport interface Logger {\n info(msg: string, options?: LogOptions): void\n warn(msg: string, options?: LogOptions): void\n /** 同一条 warn 整个进程只输出一次 */\n warnOnce(msg: string, options?: LogOptions): void\n error(msg: string, options?: LogOptions): void\n clearScreen(type: LogType): void\n /** 该 Error 是否已经走 logger.error 输出过(避免 CLI 兜底重复打印) */\n hasErrorLogged(error: Error): boolean\n hasWarned: boolean\n}\n\nexport interface LoggerOptions {\n prefix?: string\n allowClearScreen?: boolean\n customLogger?: Logger\n console?: Console\n}\n\nexport const LogLevels: Record<LogLevel, number> = {\n silent: 0,\n error: 1,\n warn: 2,\n info: 3,\n}\n\nlet lastType: LogType | undefined\nlet lastMsg: string | undefined\nlet sameCount = 0\n\nfunction getTimeFormatter(): Intl.DateTimeFormat {\n return new Intl.DateTimeFormat(undefined, {\n hour: 'numeric',\n minute: 'numeric',\n second: 'numeric',\n })\n}\n\nexport function createLogger(\n level: LogLevel = 'info',\n options: LoggerOptions = {},\n): Logger {\n if (options.customLogger) {\n return options.customLogger\n }\n\n const timeFormatter = getTimeFormatter()\n const loggedErrors = new WeakSet<Error>()\n const { prefix = '[nasti]', allowClearScreen = true, console: console_ = console } = options\n const thresh = LogLevels[level]\n const canClearScreen =\n allowClearScreen && process.stdout.isTTY && !process.env.CI\n const clear = canClearScreen ? clearScreen : () => {}\n\n function format(type: LogType, msg: string, options: LogOptions = {}): string {\n if (options.timestamp) {\n const tag =\n type === 'info'\n ? pc.cyan(pc.bold(prefix))\n : type === 'warn'\n ? pc.yellow(pc.bold(prefix))\n : pc.red(pc.bold(prefix))\n return `${pc.dim(timeFormatter.format(new Date()))} ${tag} ${msg}`\n }\n return msg\n }\n\n function output(type: LogType, msg: string, options: LogOptions = {}): void {\n if (thresh < LogLevels[type]) return\n const method = type === 'info' ? 'log' : type\n\n if (options.error) {\n loggedErrors.add(options.error)\n }\n if (canClearScreen) {\n // 同消息折叠为 (xN)\n if (type === lastType && msg === lastMsg) {\n sameCount++\n clear()\n console_[method](format(type, msg, options), pc.yellow(`(x${sameCount + 1})`))\n } else {\n sameCount = 0\n lastMsg = msg\n lastType = type\n if (options.clear) clear()\n console_[method](format(type, msg, options))\n }\n } else {\n console_[method](format(type, msg, options))\n }\n }\n\n const warnedMessages = new Set<string>()\n\n const logger: Logger = {\n hasWarned: false,\n info(msg, opts) {\n output('info', msg, opts)\n },\n warn(msg, opts) {\n logger.hasWarned = true\n output('warn', msg, opts)\n },\n warnOnce(msg, opts) {\n if (warnedMessages.has(msg)) return\n logger.hasWarned = true\n output('warn', msg, opts)\n warnedMessages.add(msg)\n },\n error(msg, opts) {\n output('error', msg, opts)\n },\n clearScreen(type) {\n if (thresh >= LogLevels[type]) clear()\n },\n hasErrorLogged(error) {\n return loggedErrors.has(error)\n },\n }\n\n return logger\n}\n\nfunction clearScreen(): void {\n const repeatCount = process.stdout.rows - 2\n const blank = repeatCount > 0 ? '\\n'.repeat(repeatCount) : ''\n console.log(blank)\n readline.cursorTo(process.stdout, 0, 0)\n readline.clearScreenDown(process.stdout)\n}\n\nexport interface ServerUrls {\n local: string[]\n network: string[]\n}\n\n/** 打印 dev server 地址:➜ Local / Network,端口加粗 */\nexport function printServerUrls(\n urls: ServerUrls,\n info: Logger['info'],\n): void {\n const colorUrl = (url: string) =>\n pc.cyan(url.replace(/:(\\d+)\\//, (_, port) => `:${pc.bold(port)}/`))\n for (const url of urls.local) {\n info(` ${pc.green('➜')} ${pc.bold('Local')}: ${colorUrl(url)}`)\n }\n for (const url of urls.network) {\n info(` ${pc.green('➜')} ${pc.bold('Network')}: ${colorUrl(url)}`)\n }\n if (urls.network.length === 0) {\n info(\n pc.dim(` ${pc.green('➜')} ${pc.bold('Network')}: use `) +\n pc.bold('--host') +\n pc.dim(' to expose'),\n )\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoCA,MAAa,YAAsC;CACjD,QAAQ;CACR,OAAO;CACP,MAAM;CACN,MAAM;AACR;AAEA,IAAI;AACJ,IAAI;AACJ,IAAI,YAAY;AAEhB,SAAS,mBAAwC;CAC/C,OAAO,IAAI,KAAK,eAAe,KAAA,GAAW;EACxC,MAAM;EACN,QAAQ;EACR,QAAQ;CACV,CAAC;AACH;AAEA,SAAgB,aACd,QAAkB,QAClB,UAAyB,CAAC,GAClB;CACR,IAAI,QAAQ,cACV,OAAO,QAAQ;CAGjB,MAAM,gBAAgB,iBAAiB;CACvC,MAAM,+BAAe,IAAI,QAAe;CACxC,MAAM,EAAE,SAAS,WAAW,mBAAmB,MAAM,SAAS,WAAW,YAAY;CACrF,MAAM,SAAS,UAAU;CACzB,MAAM,iBACJ,oBAAoB,QAAQ,OAAO,SAAS,CAAC,QAAQ,IAAI;CAC3D,MAAM,QAAQ,iBAAiB,oBAAoB,CAAC;CAEpD,SAAS,OAAO,MAAe,KAAa,UAAsB,CAAC,GAAW;EAC5E,IAAI,QAAQ,WAAW;GACrB,MAAM,MACJ,SAAS,SACLA,WAAAA,QAAG,KAAKA,WAAAA,QAAG,KAAK,MAAM,CAAC,IACvB,SAAS,SACPA,WAAAA,QAAG,OAAOA,WAAAA,QAAG,KAAK,MAAM,CAAC,IACzBA,WAAAA,QAAG,IAAIA,WAAAA,QAAG,KAAK,MAAM,CAAC;GAC9B,OAAO,GAAGA,WAAAA,QAAG,IAAI,cAAc,uBAAO,IAAI,KAAK,CAAC,CAAC,EAAE,GAAG,IAAI,GAAG;EAC/D;EACA,OAAO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