vike 0.4.247-commit-14351e3 → 0.4.247-commit-9b74d50
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/client/runtime-client-routing/history.d.ts +5 -2
- package/dist/client/runtime-client-routing/history.js +52 -29
- package/dist/client/runtime-client-routing/initOnPopState.js +5 -3
- package/dist/node/api/dev.d.ts +4 -1
- package/dist/node/api/dev.js +55 -3
- package/dist/node/api/utils.d.ts +3 -0
- package/dist/node/api/utils.js +3 -0
- package/dist/node/cli/entry.js +1 -17
- package/dist/node/vite/plugins/build/pluginModuleBanner.js +20 -8
- package/dist/node/vite/plugins/pluginCommon.d.ts +1 -0
- package/dist/node/vite/plugins/pluginCommon.js +2 -0
- package/dist/node/vite/plugins/pluginDev.js +11 -8
- package/dist/node/vite/plugins/pluginReplaceConstantsGlobalThis.d.ts +2 -0
- package/dist/node/vite/plugins/pluginReplaceConstantsGlobalThis.js +5 -4
- package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.js +3 -2
- package/dist/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +2 -1
- package/dist/node/vite/shared/loggerDev/errorWithCodeSnippet.d.ts +2 -1
- package/dist/node/vite/shared/loggerDev/errorWithCodeSnippet.js +5 -8
- package/dist/node/vite/shared/loggerDev.js +32 -43
- package/dist/node/vite/shared/loggerVite.d.ts +15 -2
- package/dist/node/vite/shared/loggerVite.js +108 -11
- package/dist/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.d.ts +3 -2
- package/dist/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +4 -2
- package/dist/node/vite/shared/resolveVikeConfigInternal.js +3 -3
- package/dist/server/{runtime/onLoad.js → onLoad.js} +8 -5
- package/dist/server/runtime/renderPageServer/addErrorHint.d.ts +1 -1
- package/dist/server/runtime/renderPageServer/addErrorHint.js +4 -8
- package/dist/server/runtime/renderPageServer.js +10 -3
- package/dist/server/utils.d.ts +1 -0
- package/dist/server/utils.js +2 -1
- package/dist/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/utils/PROJECT_VERSION.js +1 -1
- package/dist/utils/assert.js +8 -4
- package/dist/utils/colorVike.d.ts +2 -0
- package/dist/utils/colorVike.js +5 -0
- package/dist/utils/colors.d.ts +2 -0
- package/dist/utils/colors.js +5 -0
- package/dist/utils/debug.js +13 -9
- package/dist/utils/formatHintLog.d.ts +1 -1
- package/dist/utils/formatHintLog.js +6 -8
- package/dist/utils/getBetterError.d.ts +7 -1
- package/dist/utils/getBetterError.js +38 -10
- package/package.json +2 -2
- package/dist/node/vite/shared/loggerVite/removeSuperfluousViteLog.d.ts +0 -6
- package/dist/node/vite/shared/loggerVite/removeSuperfluousViteLog.js +0 -24
- /package/dist/server/{runtime/onLoad.d.ts → onLoad.d.ts} +0 -0
|
@@ -12,7 +12,7 @@ export { logErrorServerDev };
|
|
|
12
12
|
import { isAbortError } from '../../../shared-server-client/route/abort.js';
|
|
13
13
|
import { getViteConfig } from '../../../server/runtime/globalContext.js';
|
|
14
14
|
import { assertPageContext_logRuntime, setLogRuntimeDev, } from '../../../server/runtime/loggerRuntime.js';
|
|
15
|
-
import { addOnBeforeAssertErr, assert, assertIsNotProductionRuntime, formatHintLog, hasGreen, hasProp, hasRed, hasYellow, isDebugError, stripAnsi, } from '../utils.js';
|
|
15
|
+
import { addOnBeforeAssertErr, assert, assertIsNotProductionRuntime, colorVike, colorVite, formatHintLog, hasGreen, hasProp, hasRed, hasYellow, isDebugError, stripAnsi, } from '../utils.js';
|
|
16
16
|
import { isErrorWithCodeSnippet, getPrettyErrorWithCodeSnippet } from './loggerDev/errorWithCodeSnippet.js';
|
|
17
17
|
import { getConfigExecutionErrorIntroMsg, getConfigBuildErrorFormatted, } from './resolveVikeConfigInternal/transpileAndExecuteFile.js';
|
|
18
18
|
import pc from '@brillout/picocolors';
|
|
@@ -27,6 +27,8 @@ addOnBeforeAssertErr((err) => {
|
|
|
27
27
|
// We must directly apply vite.ssrFixStacktrace() to `assertWarning(..., { showStackTrace: true })` because warnings aren't caught by the try-catch of renderPageServer()
|
|
28
28
|
applyViteSourceMapToStackTrace(err);
|
|
29
29
|
});
|
|
30
|
+
// Note shown to user when Vike completely modifies the error message (which is somewhat risky)
|
|
31
|
+
const errorDebugNote = pc.dim(formatHintLog("Error isn't helpful? See https://vike.dev/debug#verbose-errors"));
|
|
30
32
|
function logRuntimeInfoDev(msg, pageContext, logType) {
|
|
31
33
|
assertPageContext_logRuntime(pageContext);
|
|
32
34
|
const tagSource = getTagSource(pageContext?._requestId);
|
|
@@ -55,10 +57,9 @@ function logErrorServerDev(err, pageContext, errorComesFromVite = false) {
|
|
|
55
57
|
// We handle transpile errors globally because wrapping viteDevServer.ssrLoadModule() wouldn't be enough: transpile errors can be thrown not only when calling viteDevServer.ssrLoadModule() but also later when loading user code with import() (since Vite lazy-transpiles import() calls)
|
|
56
58
|
const viteConfig = getViteConfig();
|
|
57
59
|
assert(viteConfig);
|
|
58
|
-
|
|
59
|
-
assert(stripAnsi(
|
|
60
|
-
message =
|
|
61
|
-
message = appendErrorDebugNote(message);
|
|
60
|
+
const errMsgFormatted = getPrettyErrorWithCodeSnippet(err, viteConfig.root);
|
|
61
|
+
assert(stripAnsi(errMsgFormatted).startsWith('Failed to transpile'));
|
|
62
|
+
const message = `${getTags(errMsgFormatted, '[vite]', tagSource, 'error')}${errMsgFormatted}\n${errorDebugNote}`;
|
|
62
63
|
const errBetter = getBetterError(err, { message, hideStack: true });
|
|
63
64
|
logErr(errBetter);
|
|
64
65
|
return;
|
|
@@ -67,8 +68,7 @@ function logErrorServerDev(err, pageContext, errorComesFromVite = false) {
|
|
|
67
68
|
const errMsgFormatted = getConfigBuildErrorFormatted(err);
|
|
68
69
|
if (errMsgFormatted) {
|
|
69
70
|
assert(stripAnsi(errMsgFormatted).startsWith('Failed to transpile'));
|
|
70
|
-
|
|
71
|
-
message = prependTags(message, '[vike]', tagSource, 'error');
|
|
71
|
+
const message = `${getTagsError(errMsgFormatted, tagSource)}${errMsgFormatted}\n${errorDebugNote}`;
|
|
72
72
|
const errBetter = getBetterError(err, { message, hideStack: true });
|
|
73
73
|
logErr(errBetter);
|
|
74
74
|
return;
|
|
@@ -78,9 +78,8 @@ function logErrorServerDev(err, pageContext, errorComesFromVite = false) {
|
|
|
78
78
|
const errIntro = getConfigExecutionErrorIntroMsg(err);
|
|
79
79
|
if (errIntro) {
|
|
80
80
|
assert(stripAnsi(errIntro).startsWith('Failed to execute'));
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const errBetter = getBetterError(err, { message });
|
|
81
|
+
const prepend = `${getTagsError(errIntro, tagSource)}${errIntro}\n`;
|
|
82
|
+
const errBetter = getBetterError(err, { message: { prepend } });
|
|
84
83
|
logErr(errBetter);
|
|
85
84
|
return;
|
|
86
85
|
}
|
|
@@ -90,26 +89,24 @@ function logErrorServerDev(err, pageContext, errorComesFromVite = false) {
|
|
|
90
89
|
if (hook) {
|
|
91
90
|
const { hookName, hookFilePath } = hook;
|
|
92
91
|
const errIntro = pc.red(`Following error was thrown by the ${hookName}() hook defined at ${hookFilePath}`);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const errBetter = getBetterError(err, { message });
|
|
92
|
+
const prepend = `${getTagsError(errIntro, tagSource)}${errIntro}\n`;
|
|
93
|
+
const errBetter = getBetterError(err, { message: { prepend } });
|
|
96
94
|
logErr(errBetter);
|
|
97
95
|
return;
|
|
98
96
|
}
|
|
99
97
|
}
|
|
100
98
|
if (tagSource) {
|
|
101
99
|
const errIntro = pc.bold(pc.red(`[Error] ${errorComesFromVite ? 'Transpilation error' : 'An error was thrown'}:`));
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
const errBetter = getBetterError(err, { message });
|
|
100
|
+
const prepend = `${getTagsError(errIntro, tagSource)}${errIntro}\n`;
|
|
101
|
+
const errBetter = getBetterError(err, { message: { prepend } });
|
|
105
102
|
logErr(errBetter);
|
|
106
103
|
return;
|
|
107
104
|
}
|
|
108
105
|
logErr(err);
|
|
109
106
|
}
|
|
110
|
-
function logDev(msg, logType, tagSource, tagTool,
|
|
111
|
-
if (!
|
|
112
|
-
msg =
|
|
107
|
+
function logDev(msg, logType, tagSource, tagTool, doNotAddTags) {
|
|
108
|
+
if (!doNotAddTags) {
|
|
109
|
+
msg = getTags(msg, tagTool, tagSource, logType) + msg;
|
|
113
110
|
}
|
|
114
111
|
if (logType === 'info') {
|
|
115
112
|
console.log(msg);
|
|
@@ -130,11 +127,6 @@ function logDev(msg, logType, tagSource, tagTool, doNotPrependTags) {
|
|
|
130
127
|
}
|
|
131
128
|
assert(false);
|
|
132
129
|
}
|
|
133
|
-
// Note shown to user when Vike modifies errors in a risky fashion.
|
|
134
|
-
function appendErrorDebugNote(errMsg) {
|
|
135
|
-
const errorDebugNote = pc.dim(formatHintLog("Error isn't helpful? See https://vike.dev/debug#verbose-errors"));
|
|
136
|
-
return errMsg + '\n' + errorDebugNote;
|
|
137
|
-
}
|
|
138
130
|
function getTagSource(requestId = null) {
|
|
139
131
|
const requestIdFromStore = getHttpRequestId_withAsyncHook();
|
|
140
132
|
if (requestIdFromStore !== null) {
|
|
@@ -148,7 +140,7 @@ function getTagSource(requestId = null) {
|
|
|
148
140
|
if (requestId === null)
|
|
149
141
|
return null;
|
|
150
142
|
// const tagSource = requestId % 2 === 1 ? (`request-${requestId}` as const) : (`request(${requestId})` as const)
|
|
151
|
-
const tagSource = `request
|
|
143
|
+
const tagSource = `request-${requestId}`;
|
|
152
144
|
return tagSource;
|
|
153
145
|
}
|
|
154
146
|
function applyViteSourceMapToStackTrace(thing) {
|
|
@@ -162,29 +154,26 @@ function applyViteSourceMapToStackTrace(thing) {
|
|
|
162
154
|
// Apply Vite's source maps
|
|
163
155
|
viteDevServer.ssrFixStacktrace(thing);
|
|
164
156
|
}
|
|
165
|
-
function
|
|
166
|
-
|
|
157
|
+
function getTagsError(msg, tagSource) {
|
|
158
|
+
return getTags(msg, '[vike]', tagSource, 'error');
|
|
159
|
+
}
|
|
160
|
+
function getTags(msg, tagTool, tagSource, logType) {
|
|
161
|
+
const tagToolColored = (() => {
|
|
167
162
|
if (logType === 'error' && !hasRed(msg))
|
|
168
|
-
return pc.bold(pc.red(
|
|
163
|
+
return pc.bold(pc.red(tagTool));
|
|
169
164
|
if (logType === 'error-resolve' && !hasGreen(msg))
|
|
170
|
-
return pc.bold(pc.green(
|
|
165
|
+
return pc.bold(pc.green(tagTool));
|
|
171
166
|
if (logType === 'warn' && !hasYellow(msg))
|
|
172
|
-
return pc.yellow(
|
|
167
|
+
return pc.yellow(tagTool);
|
|
173
168
|
if (tagTool === '[vite]')
|
|
174
|
-
return
|
|
169
|
+
return colorVite(tagTool);
|
|
175
170
|
if (tagTool === '[vike]')
|
|
176
|
-
return
|
|
171
|
+
return colorVike(tagTool);
|
|
177
172
|
assert(false);
|
|
178
|
-
};
|
|
179
|
-
let tag = color(tagTool);
|
|
180
|
-
if (tagSource) {
|
|
181
|
-
tag = tag + pc.dim(`[${tagSource}]`);
|
|
182
|
-
}
|
|
173
|
+
})();
|
|
183
174
|
const timestamp = pc.dim(new Date().toLocaleTimeString());
|
|
184
|
-
const whitespace = /\s|\[/.test(stripAnsi(msg)[0]) ? '' : ' ';
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
const errMsg = String(err?.message || '');
|
|
189
|
-
return errIntro + '\n' + errMsg;
|
|
175
|
+
const whitespace = (/\s|\[/.test(stripAnsi(msg)[0]) ? '' : ' ');
|
|
176
|
+
const tagSourceStr = (!tagSource ? '' : pc.dim(`[${tagSource}]`));
|
|
177
|
+
const tags = `${timestamp} ${tagToolColored}${tagSourceStr}${whitespace}`;
|
|
178
|
+
return tags;
|
|
190
179
|
}
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { interceptViteLogs };
|
|
2
|
+
export { processStartupLog };
|
|
3
|
+
export { swallowViteLogForceOptimization_enable };
|
|
4
|
+
export { swallowViteLogForceOptimization_disable };
|
|
5
|
+
export { swallowViteLogConnected };
|
|
6
|
+
export { swallowViteLogConnected_clean };
|
|
2
7
|
import type { ResolvedConfig } from 'vite';
|
|
3
|
-
declare function
|
|
8
|
+
declare function interceptViteLogs(config: ResolvedConfig): void;
|
|
9
|
+
declare function processStartupLog(firstLine: string, config: ResolvedConfig): {
|
|
10
|
+
firstLine: string;
|
|
11
|
+
isCompact: boolean;
|
|
12
|
+
};
|
|
13
|
+
declare function swallowViteLogForceOptimization_enable(): void;
|
|
14
|
+
declare function swallowViteLogForceOptimization_disable(): void;
|
|
15
|
+
declare function swallowViteLogConnected(): void;
|
|
16
|
+
declare function swallowViteLogConnected_clean(): void;
|
|
@@ -1,17 +1,32 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export { interceptViteLogs };
|
|
2
|
+
export { processStartupLog };
|
|
3
|
+
export { swallowViteLogForceOptimization_enable };
|
|
4
|
+
export { swallowViteLogForceOptimization_disable };
|
|
5
|
+
export { swallowViteLogConnected };
|
|
6
|
+
export { swallowViteLogConnected_clean };
|
|
7
|
+
import { assert, getGlobalObject, isDebugError, removeEmptyLines, trimWithAnsi, trimWithAnsiTrailOnly, } from '../utils.js';
|
|
3
8
|
import { getHttpRequestId_withAsyncHook } from '../../../server/runtime/asyncHook.js';
|
|
4
9
|
import { logErrorServerDev, logVite } from './loggerDev.js';
|
|
5
|
-
|
|
6
|
-
|
|
10
|
+
const globalObject = getGlobalObject('vite/shared/loggerDev.ts', {
|
|
11
|
+
processStartupLog_isCompact: null,
|
|
12
|
+
processStartupLog_hasViteLoggedStartup: null,
|
|
13
|
+
processStartupLog_hasViteLoggedHelpShortcut: null,
|
|
14
|
+
swallowViteLogForceOptimization_enabled: false,
|
|
15
|
+
swallowViteLogConnected_originalConsoleLog: null,
|
|
16
|
+
});
|
|
17
|
+
function interceptViteLogs(config) {
|
|
18
|
+
if (isDebugError())
|
|
19
|
+
return;
|
|
7
20
|
intercept('info', config);
|
|
8
21
|
intercept('warn', config);
|
|
9
22
|
intercept('error', config);
|
|
10
23
|
}
|
|
11
24
|
function intercept(loggerType, config) {
|
|
25
|
+
let isBeginning = true;
|
|
26
|
+
setTimeout(() => (isBeginning = false), 10 * 1000);
|
|
12
27
|
config.logger[loggerType] = (msg, options = {}) => {
|
|
13
28
|
assert(!isDebugError());
|
|
14
|
-
if (
|
|
29
|
+
if (swallowViteLogForceOptimization(msg))
|
|
15
30
|
return;
|
|
16
31
|
if (!!options.timestamp) {
|
|
17
32
|
msg = trimWithAnsi(msg);
|
|
@@ -20,7 +35,9 @@ function intercept(loggerType, config) {
|
|
|
20
35
|
// No timestamp => no "[vite]" tag prepended => we don't trim the beginning of the message
|
|
21
36
|
msg = trimWithAnsiTrailOnly(msg);
|
|
22
37
|
}
|
|
23
|
-
|
|
38
|
+
if (isBeginning) {
|
|
39
|
+
msg = processStartupLog_onViteLog(msg, config);
|
|
40
|
+
}
|
|
24
41
|
if (options.error) {
|
|
25
42
|
// Vite does a poor job of handling errors.
|
|
26
43
|
// - It doesn't format error code snippets.
|
|
@@ -41,12 +58,92 @@ function intercept(loggerType, config) {
|
|
|
41
58
|
logVite(msg, loggerType, requestId, prependViteTag);
|
|
42
59
|
};
|
|
43
60
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
61
|
+
// - Clears screen if zero previous log
|
|
62
|
+
// - Manages new lines
|
|
63
|
+
function processStartupLog(firstLine, config) {
|
|
64
|
+
const shouldClear = processStartupLog_shouldClear(config);
|
|
65
|
+
if (shouldClear) {
|
|
66
|
+
config.logger.clearScreen('info');
|
|
48
67
|
}
|
|
49
68
|
else {
|
|
50
|
-
|
|
69
|
+
// Remove leading new line (for both Vite and Vike's startup log)
|
|
70
|
+
firstLine = removeEmptyLines(firstLine);
|
|
71
|
+
}
|
|
72
|
+
return { firstLine, isCompact: !shouldClear };
|
|
73
|
+
}
|
|
74
|
+
function processStartupLog_shouldClear(config) {
|
|
75
|
+
const hasLoggedBefore = process.stdout.bytesWritten !== 0 || process.stderr.bytesWritten !== 0;
|
|
76
|
+
const notDisabled = config.clearScreen !== false;
|
|
77
|
+
const shouldClear = notDisabled && !hasLoggedBefore;
|
|
78
|
+
return shouldClear;
|
|
79
|
+
}
|
|
80
|
+
function processStartupLog_onViteLog(msg, config) {
|
|
81
|
+
{
|
|
82
|
+
const isFirstVitLog = msg.includes('VITE') && msg.includes('ready');
|
|
83
|
+
if (isFirstVitLog && !globalObject.processStartupLog_hasViteLoggedStartup) {
|
|
84
|
+
globalObject.processStartupLog_hasViteLoggedStartup = true;
|
|
85
|
+
let { firstLine, isCompact } = processStartupLog(msg, config);
|
|
86
|
+
globalObject.processStartupLog_isCompact = isCompact;
|
|
87
|
+
if (!isCompact)
|
|
88
|
+
firstLine += '\n';
|
|
89
|
+
return firstLine;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
{
|
|
93
|
+
const isViteHelpShortcutLog = msg.includes('press') && msg.includes('to show help');
|
|
94
|
+
if (isViteHelpShortcutLog && !globalObject.processStartupLog_hasViteLoggedHelpShortcut) {
|
|
95
|
+
globalObject.processStartupLog_hasViteLoggedHelpShortcut = true;
|
|
96
|
+
if (globalObject.processStartupLog_hasViteLoggedStartup && globalObject.processStartupLog_isCompact === false) {
|
|
97
|
+
return msg + '\n';
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return msg;
|
|
102
|
+
}
|
|
103
|
+
function swallowViteLogForceOptimization(msg) {
|
|
104
|
+
if (!globalObject.swallowViteLogForceOptimization_enabled) {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
if (msg.toLowerCase().includes('forced') && msg.toLowerCase().includes('optimization')) {
|
|
108
|
+
assert(msg === 'Forced re-optimization of dependencies', msg); // assertion fails => Vite changed its message => update this function
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
function swallowViteLogForceOptimization_enable() {
|
|
114
|
+
if (isDebugError())
|
|
115
|
+
return;
|
|
116
|
+
globalObject.swallowViteLogForceOptimization_enabled = true;
|
|
117
|
+
}
|
|
118
|
+
function swallowViteLogForceOptimization_disable() {
|
|
119
|
+
globalObject.swallowViteLogForceOptimization_enabled = false;
|
|
120
|
+
}
|
|
121
|
+
// Suppress "[vite] connected." message. (It doesn't go through Vite's logger thus we must monkey patch the console.log() function.)
|
|
122
|
+
function swallowViteLogConnected() {
|
|
123
|
+
if (isDebugError())
|
|
124
|
+
return;
|
|
125
|
+
if (globalObject.swallowViteLogConnected_originalConsoleLog)
|
|
126
|
+
return;
|
|
127
|
+
globalObject.swallowViteLogConnected_originalConsoleLog = console.log;
|
|
128
|
+
console.log = swallowViteLogConnected_logPatch;
|
|
129
|
+
setTimeout(swallowViteLogConnected_clean, 3000);
|
|
130
|
+
}
|
|
131
|
+
// Remove console.log() monkey patch
|
|
132
|
+
function swallowViteLogConnected_clean() {
|
|
133
|
+
// Don't remove console.log() patches from other libraries (e.g. instrumentation)
|
|
134
|
+
if (console.log === swallowViteLogConnected_logPatch)
|
|
135
|
+
return;
|
|
136
|
+
assert(globalObject.swallowViteLogConnected_originalConsoleLog);
|
|
137
|
+
console.log = globalObject.swallowViteLogConnected_originalConsoleLog;
|
|
138
|
+
globalObject.swallowViteLogConnected_originalConsoleLog = null;
|
|
139
|
+
}
|
|
140
|
+
function swallowViteLogConnected_logPatch(...args) {
|
|
141
|
+
const originalConsoleLog = globalObject.swallowViteLogConnected_originalConsoleLog;
|
|
142
|
+
assert(originalConsoleLog);
|
|
143
|
+
const msg = args.join(' ');
|
|
144
|
+
if (msg === '[vite] connected.') {
|
|
145
|
+
swallowViteLogConnected_clean();
|
|
146
|
+
return; // swallow
|
|
51
147
|
}
|
|
148
|
+
originalConsoleLog.apply(console, args);
|
|
52
149
|
}
|
|
@@ -13,6 +13,7 @@ type EsbuildCache = {
|
|
|
13
13
|
vikeConfigDependencies: Set<string>;
|
|
14
14
|
};
|
|
15
15
|
declare function transpileAndExecuteFile(filePath: FilePathResolved, userRootDir: string, isExtensionConfig: boolean, esbuildCache: EsbuildCache): Promise<FileExports>;
|
|
16
|
-
declare function getConfigBuildErrorFormatted(err: unknown):
|
|
17
|
-
|
|
16
|
+
declare function getConfigBuildErrorFormatted(err: unknown): `Failed to transpile ${string} because:
|
|
17
|
+
${string}` | null;
|
|
18
|
+
declare function getConfigExecutionErrorIntroMsg(err: unknown): `Failed to execute ${string} because:` | null;
|
|
18
19
|
declare function isTemporaryBuildFile(filePath: string): boolean;
|
|
@@ -322,7 +322,8 @@ function getConfigBuildErrorFormatted(err) {
|
|
|
322
322
|
if (!(formatted in err))
|
|
323
323
|
return null;
|
|
324
324
|
assert(typeof err[formatted] === 'string');
|
|
325
|
-
|
|
325
|
+
const errMsgFormatted = err[formatted];
|
|
326
|
+
return errMsgFormatted;
|
|
326
327
|
}
|
|
327
328
|
async function formatBuildErr(err, filePath) {
|
|
328
329
|
assert(isObject(err) && err.errors);
|
|
@@ -333,7 +334,8 @@ async function formatBuildErr(err, filePath) {
|
|
|
333
334
|
.map((m) => m.trim())
|
|
334
335
|
.join('\n');
|
|
335
336
|
const msgIntro = getErrIntroMsg('transpile', filePath);
|
|
336
|
-
|
|
337
|
+
const errMsgFormatted = `${msgIntro}\n${msgEsbuild}`;
|
|
338
|
+
err[formatted] = errMsgFormatted;
|
|
337
339
|
}
|
|
338
340
|
const execErrIntroMsg = new WeakMap();
|
|
339
341
|
function getConfigExecutionErrorIntroMsg(err) {
|
|
@@ -15,7 +15,7 @@ import { configDefinitionsBuiltIn, } from './resolveVikeConfigInternal/configDef
|
|
|
15
15
|
import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, applyFilesystemRoutingRootEffect, } from './resolveVikeConfigInternal/filesystemRouting.js';
|
|
16
16
|
import { getViteDevServer, vikeConfigErrorRecoverMsg } from '../../../server/runtime/globalContext.js';
|
|
17
17
|
import { logConfigInfo, logErrorServerDev } from './loggerDev.js';
|
|
18
|
-
import {
|
|
18
|
+
import { swallowViteLogForceOptimization_enable, swallowViteLogForceOptimization_disable } from './loggerVite.js';
|
|
19
19
|
import pc from '@brillout/picocolors';
|
|
20
20
|
import { getConfigDefinedAt, getDefinedByString, } from '../../../shared-server-client/page-configs/getConfigDefinedAt.js';
|
|
21
21
|
import { loadPointerImport, loadValueFile } from './resolveVikeConfigInternal/loadFileAtConfigTime.js';
|
|
@@ -1106,7 +1106,7 @@ function resolvePrerenderContext(vikeConfig) {
|
|
|
1106
1106
|
function restartViteDevServer() {
|
|
1107
1107
|
const viteDevServer = getViteDevServer();
|
|
1108
1108
|
assert(viteDevServer);
|
|
1109
|
-
|
|
1109
|
+
swallowViteLogForceOptimization_enable();
|
|
1110
1110
|
(async () => {
|
|
1111
1111
|
try {
|
|
1112
1112
|
await viteDevServer.restart(true);
|
|
@@ -1116,7 +1116,7 @@ function restartViteDevServer() {
|
|
|
1116
1116
|
console.error(err);
|
|
1117
1117
|
}
|
|
1118
1118
|
})();
|
|
1119
|
-
|
|
1119
|
+
swallowViteLogForceOptimization_disable();
|
|
1120
1120
|
}
|
|
1121
1121
|
function getVikeConfigDummy(esbuildCache) {
|
|
1122
1122
|
const pageConfigsDummy = [];
|
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
export { onLoad };
|
|
2
|
-
import { assertIsNotBrowser } from '
|
|
3
|
-
import { assertNodeVersion } from '
|
|
4
|
-
import { setAlwaysShowStackTrace } from '
|
|
2
|
+
import { assertIsNotBrowser } from '../utils/assertIsNotBrowser.js';
|
|
3
|
+
import { assertNodeVersion } from '../utils/assertNodeVersion.js';
|
|
4
|
+
import { setAlwaysShowStackTrace } from '../utils/assert.js';
|
|
5
5
|
import { installRequireShim } from '@brillout/require-shim';
|
|
6
|
-
import { isDebugError } from '
|
|
6
|
+
import { isDebugError } from '../utils/debug.js';
|
|
7
7
|
function onLoad() {
|
|
8
8
|
assertIsNotBrowser();
|
|
9
9
|
assertNodeVersion();
|
|
10
|
-
if (isDebugError())
|
|
10
|
+
if (isDebugError()) {
|
|
11
|
+
// Is also executed upon `$ vike build` because node/vite/utils.ts imports server/utils.ts
|
|
12
|
+
Error.stackTraceLimit = Infinity;
|
|
11
13
|
setAlwaysShowStackTrace();
|
|
14
|
+
}
|
|
12
15
|
addEcosystemStamp();
|
|
13
16
|
installRequireShim();
|
|
14
17
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { addErrorHint };
|
|
2
2
|
export { getErrorHint };
|
|
3
3
|
declare function addErrorHint(error: unknown): unknown;
|
|
4
|
-
declare function getErrorHint(error: unknown):
|
|
4
|
+
declare function getErrorHint(error: unknown): "The error could be a CJS/ESM issue, see https://vike.dev/broken-npm-package" | `To fix this error, see ${string}` | null;
|
|
@@ -84,22 +84,18 @@ function addErrorHint(error) {
|
|
|
84
84
|
/* Collect errors for ./addErrorHint.spec.ts
|
|
85
85
|
collectError(error)
|
|
86
86
|
//*/
|
|
87
|
-
|
|
87
|
+
const hint = getErrorHint(error);
|
|
88
88
|
if (!hint)
|
|
89
89
|
return error;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
let message = String(error?.message || '');
|
|
93
|
-
message = message + '\n' + hint;
|
|
94
|
-
const errBetter = getBetterError(error, { message });
|
|
95
|
-
return errBetter;
|
|
90
|
+
const append = `\n${pc.bold(formatHintLog(hint))}`;
|
|
91
|
+
return getBetterError(error, { message: { append } });
|
|
96
92
|
}
|
|
97
93
|
function getErrorHint(error) {
|
|
98
94
|
{
|
|
99
95
|
const knownErr = isKnownError(error);
|
|
100
96
|
if (knownErr) {
|
|
101
97
|
if (knownErr.link) {
|
|
102
|
-
return hintLinkPrefix
|
|
98
|
+
return `${hintLinkPrefix}${knownErr.link}`;
|
|
103
99
|
}
|
|
104
100
|
else {
|
|
105
101
|
return hintDefault;
|
|
@@ -219,8 +219,15 @@ function logHttpRequest(urlOriginal, pageContextInit, requestId) {
|
|
|
219
219
|
const pageContext_logRuntime = getPageContext_logRuntimeEarly(pageContextInit, requestId);
|
|
220
220
|
logRuntimeInfo?.(getRequestInfoMessage(urlOriginal), pageContext_logRuntime, 'info');
|
|
221
221
|
}
|
|
222
|
+
/*
|
|
223
|
+
const arrowRight = pc.dim('>>')
|
|
224
|
+
const arrowLeft = pc.dim('<<')
|
|
225
|
+
/*/
|
|
226
|
+
const arrowRight = pc.dim('»');
|
|
227
|
+
const arrowLeft = pc.dim('«');
|
|
228
|
+
//*/
|
|
222
229
|
function getRequestInfoMessage(urlOriginal) {
|
|
223
|
-
return `HTTP request
|
|
230
|
+
return `HTTP request ${arrowRight} ${prettyUrl(urlOriginal)}`;
|
|
224
231
|
}
|
|
225
232
|
function logHttpResponse(urlOriginalPretty, pageContextReturn) {
|
|
226
233
|
const statusCode = pageContextReturn.httpResponse?.statusCode ?? null;
|
|
@@ -236,7 +243,7 @@ function logHttpResponse(urlOriginalPretty, pageContextReturn) {
|
|
|
236
243
|
// - We should show `HTTP response ${urlOriginalPretty} ERR` instead.
|
|
237
244
|
// - Maybe we can/should make the error available at pageContext.errorWhileRendering
|
|
238
245
|
assert(errorWhileRendering === null || errorWhileRendering === undefined);
|
|
239
|
-
msg = `HTTP response ${prettyUrl(urlOriginalPretty)} ${pc.dim('null')}`;
|
|
246
|
+
msg = `HTTP response ${arrowLeft} ${prettyUrl(urlOriginalPretty)} ${pc.dim('null')}`;
|
|
240
247
|
// Erroneous value (it should sometimes be `false`) but it's fine as it doesn't seem to have much of an impact.
|
|
241
248
|
isNominal = true;
|
|
242
249
|
}
|
|
@@ -245,7 +252,7 @@ function logHttpResponse(urlOriginalPretty, pageContextReturn) {
|
|
|
245
252
|
isNominal = isSuccess || statusCode === 404;
|
|
246
253
|
const color = (s) => pc.bold(isSuccess ? pc.green(String(s)) : pc.red(String(s)));
|
|
247
254
|
const isRedirect = statusCode && 300 <= statusCode && statusCode <= 399;
|
|
248
|
-
const type = isRedirect ? 'redirect' :
|
|
255
|
+
const type = isRedirect ? 'redirect' : `response ${arrowLeft}`;
|
|
249
256
|
if (isRedirect) {
|
|
250
257
|
assert(pageContextReturn.httpResponse);
|
|
251
258
|
const headerRedirect = pageContextReturn.httpResponse.headers
|
package/dist/server/utils.d.ts
CHANGED
|
@@ -43,6 +43,7 @@ export * from '../utils/path.js';
|
|
|
43
43
|
export * from '../utils/isHtml.js';
|
|
44
44
|
export * from '../utils/virtualFileId.js';
|
|
45
45
|
export * from '../utils/colors.js';
|
|
46
|
+
export * from '../utils/colorVike.js';
|
|
46
47
|
export * from '../utils/getTerminalWidth.js';
|
|
47
48
|
export * from '../utils/truncateString.js';
|
|
48
49
|
export * from '../utils/formatHintLog.js';
|
package/dist/server/utils.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Utils needed by Vike's server runtime
|
|
2
2
|
import '../utils/trackLogs.js';
|
|
3
3
|
// We call onLoad() here so that it's called even when only a subset of the runtime is loaded. (Making the assert() calls inside onLoad() a lot stronger.)
|
|
4
|
-
import { onLoad } from './
|
|
4
|
+
import { onLoad } from './onLoad.js';
|
|
5
5
|
onLoad();
|
|
6
6
|
export * from '../utils/assert.js';
|
|
7
7
|
export * from '../utils/cast.js';
|
|
@@ -47,6 +47,7 @@ export * from '../utils/path.js';
|
|
|
47
47
|
export * from '../utils/isHtml.js';
|
|
48
48
|
export * from '../utils/virtualFileId.js';
|
|
49
49
|
export * from '../utils/colors.js';
|
|
50
|
+
export * from '../utils/colorVike.js';
|
|
50
51
|
export * from '../utils/getTerminalWidth.js';
|
|
51
52
|
export * from '../utils/truncateString.js';
|
|
52
53
|
export * from '../utils/formatHintLog.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.247-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.247-commit-9b74d50";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.247-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.247-commit-9b74d50';
|
package/dist/utils/assert.js
CHANGED
|
@@ -11,6 +11,7 @@ import { assertSingleInstance_onAssertModuleLoad } from './assertSingleInstance.
|
|
|
11
11
|
import { createErrorWithCleanStackTrace } from './createErrorWithCleanStackTrace.js';
|
|
12
12
|
import { getGlobalObject } from './getGlobalObject.js';
|
|
13
13
|
import { PROJECT_VERSION } from './PROJECT_VERSION.js';
|
|
14
|
+
import { colorVike } from './colorVike.js';
|
|
14
15
|
import pc from '@brillout/picocolors';
|
|
15
16
|
const globalObject = getGlobalObject('utils/assert.ts', {
|
|
16
17
|
alreadyLogged: new Set(),
|
|
@@ -20,7 +21,6 @@ const projectTag = `[vike]`;
|
|
|
20
21
|
const projectTagWithVersion = `[vike@${PROJECT_VERSION}]`;
|
|
21
22
|
const bugTag = 'Bug';
|
|
22
23
|
const numberOfStackTraceLinesToRemove = 2;
|
|
23
|
-
// @__NO_SIDE_EFFECTS__
|
|
24
24
|
function assert(condition, debugInfo) {
|
|
25
25
|
if (condition)
|
|
26
26
|
return;
|
|
@@ -122,8 +122,12 @@ function addOnBeforeAssertErr(onBeforeAssertErr) {
|
|
|
122
122
|
}
|
|
123
123
|
function addPrefixAssertType(msg, tag) {
|
|
124
124
|
let prefix = `[${tag}]`;
|
|
125
|
-
|
|
126
|
-
|
|
125
|
+
if (tag === 'Warning') {
|
|
126
|
+
prefix = pc.yellow(prefix);
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
prefix = pc.bold(pc.red(prefix));
|
|
130
|
+
}
|
|
127
131
|
return `${prefix}${msg}`;
|
|
128
132
|
}
|
|
129
133
|
function addWhitespace(msg) {
|
|
@@ -136,7 +140,7 @@ function addWhitespace(msg) {
|
|
|
136
140
|
}
|
|
137
141
|
function addPrefixProjectName(msg, showProjectVersion = false) {
|
|
138
142
|
const prefix = showProjectVersion ? projectTagWithVersion : projectTag;
|
|
139
|
-
return `${prefix}${msg}`;
|
|
143
|
+
return `${colorVike(prefix)}${msg}`;
|
|
140
144
|
}
|
|
141
145
|
function isVikeBug(err) {
|
|
142
146
|
return String(err).includes(`[${bugTag}]`);
|
package/dist/utils/colors.d.ts
CHANGED
|
@@ -2,6 +2,8 @@ export { stripAnsi };
|
|
|
2
2
|
export { hasRed };
|
|
3
3
|
export { hasGreen };
|
|
4
4
|
export { hasYellow };
|
|
5
|
+
export { colorVite };
|
|
6
|
+
declare function colorVite<Str extends string>(str: Str): Str;
|
|
5
7
|
declare function stripAnsi(string: string): string;
|
|
6
8
|
declare function hasRed(str: string): boolean;
|
|
7
9
|
declare function hasGreen(str: string): boolean;
|
package/dist/utils/colors.js
CHANGED
|
@@ -2,9 +2,14 @@ export { stripAnsi };
|
|
|
2
2
|
export { hasRed };
|
|
3
3
|
export { hasGreen };
|
|
4
4
|
export { hasYellow };
|
|
5
|
+
export { colorVite };
|
|
6
|
+
import pc from '@brillout/picocolors';
|
|
5
7
|
import { assertIsNotBrowser } from './assertIsNotBrowser.js';
|
|
6
8
|
assertIsNotBrowser();
|
|
7
9
|
const ansiRegex = getAnsiRegex();
|
|
10
|
+
function colorVite(str) {
|
|
11
|
+
return pc.bold(pc.cyan(str));
|
|
12
|
+
}
|
|
8
13
|
// Copied from https://github.com/chalk/strip-ansi/blob/1fdc531d4046cbaa830460f5c74452bf1f0a0884/index.js
|
|
9
14
|
function stripAnsi(string) {
|
|
10
15
|
// Even though the regex is global, we don't need to reset the `.lastIndex`
|