2025/2/8第一次更新

This commit is contained in:
爱吃咸鱼小猫咪
2025-02-08 18:50:38 +08:00
commit d7af560866
26519 changed files with 5046029 additions and 0 deletions
+2
View File
@@ -0,0 +1,2 @@
import type { TransformResult } from 'vite';
export declare function rewriteConsoleExpr(method: string, id: string, filename: string, code: string, sourceMap?: boolean): TransformResult;
+51
View File
@@ -0,0 +1,51 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.rewriteConsoleExpr = void 0;
const magic_string_1 = __importDefault(require("magic-string"));
const utils_1 = require("../utils");
function rewriteConsoleExpr(method, id, filename, code, sourceMap = false) {
filename = (0, utils_1.normalizePath)(filename);
const re = /(console\.(log|info|debug|warn|error))\(([^)]+)\)/g;
const locate = getLocator(code);
const s = new magic_string_1.default(code);
let match;
while ((match = re.exec(code))) {
const [, expr, type] = match;
s.overwrite(match.index, match.index + expr.length + 1, method + `('${type}','at ${filename}:${locate(match.index).line + 1}',`);
}
if (s.hasChanged()) {
return {
code: s.toString(),
map: sourceMap ? s.generateMap({ hires: true }) : { mappings: '' },
};
}
return { code, map: { mappings: '' } };
}
exports.rewriteConsoleExpr = rewriteConsoleExpr;
function getLocator(source) {
const originalLines = source.split('\n');
const lineOffsets = [];
for (let i = 0, pos = 0; i < originalLines.length; i++) {
lineOffsets.push(pos);
pos += originalLines[i].length + 1;
}
return function locate(index) {
let i = 0;
let j = lineOffsets.length;
while (i < j) {
const m = (i + j) >> 1;
if (index < lineOffsets[m]) {
j = m;
}
else {
i = m + 1;
}
}
const line = i - 1;
const column = index - lineOffsets[line];
return { line, column };
};
}
+11
View File
@@ -0,0 +1,11 @@
import type { LogErrorOptions, LogOptions } from 'vite';
export interface Formatter<T extends LogOptions = LogOptions> {
test: (msg: string, options?: T) => boolean;
format: (msg: string, options?: T) => string;
}
export declare function formatErrMsg(msg: string, options?: LogErrorOptions): string;
export declare const removeNVueInfoFormatter: Formatter;
export declare function formatInfoMsg(msg: string, options?: LogOptions & {
nvue?: boolean;
}): string;
export declare function formatWarnMsg(msg: string, options?: LogOptions): string;
+93
View File
@@ -0,0 +1,93 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.formatWarnMsg = exports.formatInfoMsg = exports.removeNVueInfoFormatter = exports.formatErrMsg = void 0;
const uni_shared_1 = require("@dcloudio/uni-shared");
const shared_1 = require("@vue/shared");
const env_1 = require("../hbx/env");
const alias_1 = require("../hbx/alias");
const log_1 = require("../hbx/log");
const errFormatters = [];
const infoFormatters = [];
const warnFormatters = [];
const initErrFormattersOnce = (0, uni_shared_1.once)(() => {
if ((0, env_1.isInHBuilderX)()) {
errFormatters.push(alias_1.moduleAliasFormatter);
}
errFormatters.push(log_1.errorFormatter);
});
const initInfoFormattersOnce = (0, uni_shared_1.once)(() => {
if ((0, env_1.runByHBuilderX)()) {
if (
// 开发模式下
process.env.UNI_PLATFORM === 'h5' &&
process.env.NODE_ENV !== 'production') {
infoFormatters.push(log_1.h5ServeFormatter);
}
}
infoFormatters.push(log_1.removeInfoFormatter);
});
const initWarnFormattersOnce = (0, uni_shared_1.once)(() => {
warnFormatters.push(log_1.removeWarnFormatter);
});
function formatErrMsg(msg, options) {
if (options && (0, env_1.isInHBuilderX)()) {
options.timestamp = false;
}
initErrFormattersOnce();
const formatter = errFormatters.find(({ test }) => test(msg, options));
if (formatter) {
return formatter.format(msg, options);
}
return msg;
}
exports.formatErrMsg = formatErrMsg;
const REMOVED_NVUE_MSGS = [
(msg) => {
// vite v2.7.10 building for development... (x2)
return msg.includes('vite v') && msg.includes('building ');
},
];
exports.removeNVueInfoFormatter = {
test(msg) {
return !!REMOVED_NVUE_MSGS.find((m) => (0, shared_1.isString)(m) ? msg.includes(m) : m(msg));
},
format() {
return '';
},
};
const nvueInfoFormatters = [];
const initNVueInfoFormattersOnce = (0, uni_shared_1.once)(() => {
nvueInfoFormatters.push(exports.removeNVueInfoFormatter);
});
function formatInfoMsg(msg, options) {
if (options && (0, env_1.isInHBuilderX)()) {
options.timestamp = false;
}
initInfoFormattersOnce();
const formatter = infoFormatters.find(({ test }) => test(msg, options));
if (formatter) {
return formatter.format(msg, options);
}
if (options?.nvue) {
initNVueInfoFormattersOnce();
const formatter = nvueInfoFormatters.find(({ test }) => test(msg, options));
if (formatter) {
return formatter.format(msg, options);
}
}
return msg;
}
exports.formatInfoMsg = formatInfoMsg;
function formatWarnMsg(msg, options) {
if (options && (0, env_1.isInHBuilderX)()) {
options.timestamp = false;
}
initWarnFormattersOnce();
msg = log_1.removeDuplicatePluginFormatter.format(msg);
const formatter = warnFormatters.find(({ test }) => test(msg, options));
if (formatter) {
return formatter.format(msg, options);
}
return msg;
}
exports.formatWarnMsg = formatWarnMsg;
+4
View File
@@ -0,0 +1,4 @@
export { formatErrMsg, formatInfoMsg, formatWarnMsg } from './format';
type LogType = 'error' | 'warn' | 'info' | 'log';
export declare function resetOutput(type: LogType): void;
export declare function output(type: LogType, msg: string): void;
+26
View File
@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.output = exports.resetOutput = exports.formatWarnMsg = exports.formatInfoMsg = exports.formatErrMsg = void 0;
var format_1 = require("./format");
Object.defineProperty(exports, "formatErrMsg", { enumerable: true, get: function () { return format_1.formatErrMsg; } });
Object.defineProperty(exports, "formatInfoMsg", { enumerable: true, get: function () { return format_1.formatInfoMsg; } });
Object.defineProperty(exports, "formatWarnMsg", { enumerable: true, get: function () { return format_1.formatWarnMsg; } });
let lastType;
let lastMsg;
function resetOutput(type) {
if (type === lastType) {
lastType = undefined;
lastMsg = '';
}
}
exports.resetOutput = resetOutput;
function output(type, msg) {
if (type === lastType && msg === lastMsg) {
return;
}
lastMsg = msg;
lastType = type;
const method = type === 'info' ? 'log' : type;
console[method](msg);
}
exports.output = output;