vike
Version:
The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.
55 lines (54 loc) • 2.58 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.improveViteLogs = improveViteLogs;
const utils_js_1 = require("../utils.js");
const loggerNotProd_js_1 = require("./loggerNotProd.js");
const getHttpRequestAsyncStore_js_1 = require("./getHttpRequestAsyncStore.js");
const removeSuperfluousViteLog_js_1 = require("./loggerVite/removeSuperfluousViteLog.js");
const isErrorDebug_js_1 = require("../../shared/isErrorDebug.js");
function improveViteLogs(config) {
intercept('info', config);
intercept('warn', config);
intercept('error', config);
}
function intercept(logType, config) {
config.logger[logType] = (msg, options = {}) => {
(0, utils_js_1.assert)(!(0, isErrorDebug_js_1.isErrorDebug)());
if ((0, removeSuperfluousViteLog_js_1.removeSuperfluousViteLog)(msg))
return;
if (!!options.timestamp) {
msg = (0, utils_js_1.trimWithAnsi)(msg);
}
else {
// No timestamp => no "[vite]" tag prepended => we don't trim the beginning of the message
msg = (0, utils_js_1.trimWithAnsiTrailOnly)(msg);
}
msg = cleanFirstViteLog(msg);
const store = (0, getHttpRequestAsyncStore_js_1.getHttpRequestAsyncStore)();
if (options.error) {
// Vite does a poor job of handling errors.
// - It doesn't format error code snippets.
// - It only shows error.message which means that crucial information such as error.id isn't shown to the user.
(0, loggerNotProd_js_1.logViteError)(options.error, store?.httpRequestId);
// We swallow Vite's message: we didn't see it add any value so far.
// - It can even be confusing, such as the following:
// ```
// Error when evaluating SSR module virtual:vike:pageConfigLazy:server:/pages/abort: failed to import "/pages/abort/+Page.mdx"
// ```
(0, utils_js_1.assert)(!(0, isErrorDebug_js_1.isErrorDebug)());
return;
}
// Vite's default logger preprends the "[vite]" tag if and only if options.timestamp is true
const prependViteTag = options.timestamp || !!store?.httpRequestId;
(0, loggerNotProd_js_1.logViteAny)(msg, logType, store?.httpRequestId ?? null, prependViteTag);
};
}
function cleanFirstViteLog(msg) {
const isFirstVitLog = msg.includes('VITE') && msg.includes('ready');
if (isFirstVitLog) {
return (0, utils_js_1.removeEmptyLines)(msg);
}
else {
return msg;
}
}