vike 0.4.193 → 0.4.195
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/RenderErrorPage.js +1 -0
- package/__internal/setup.js +1 -0
- package/__internal.js +1 -0
- package/abort.js +1 -0
- package/cli.js +1 -0
- package/client/router.js +1 -0
- package/client.js +1 -0
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +2 -2
- package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +4 -9
- package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +1 -13
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +2 -24
- package/dist/cjs/node/plugin/shared/loggerVite.js +0 -3
- package/dist/cjs/node/runtime/globalContext/loadImportBuild.js +2 -2
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +17 -12
- package/dist/cjs/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/html/injectAssets.js +2 -2
- package/dist/cjs/node/runtime/renderPage/assertArguments.js +3 -3
- package/dist/cjs/node/runtime/renderPage/{createHttpResponseObject.js → createHttpResponse.js} +22 -15
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +3 -5
- package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +4 -3
- package/dist/cjs/node/runtime/renderPage/inferMediaType.js +3 -0
- package/dist/cjs/node/runtime/renderPage/isConfigInvalid.js +4 -2
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -12
- package/dist/cjs/node/runtime/renderPage.js +62 -66
- package/dist/cjs/shared/page-configs/assertPlusFileExport.js +1 -2
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/isArray.js +1 -1
- package/dist/cjs/utils/parseUrl-extras.js +6 -1
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +5 -5
- package/dist/esm/node/plugin/plugins/importBuild/index.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +2 -2
- package/dist/esm/node/plugin/shared/addSsrMiddleware.js +4 -9
- package/dist/esm/node/plugin/shared/loggerNotProd/log.d.ts +0 -7
- package/dist/esm/node/plugin/shared/loggerNotProd/log.js +0 -12
- package/dist/esm/node/plugin/shared/loggerNotProd.d.ts +1 -7
- package/dist/esm/node/plugin/shared/loggerNotProd.js +2 -24
- package/dist/esm/node/plugin/shared/loggerVite.js +1 -4
- package/dist/esm/node/runtime/globalContext/loadImportBuild.js +1 -1
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.d.ts +1 -1
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +17 -12
- package/dist/esm/node/runtime/html/injectAssets/injectHtmlTags.js +1 -1
- package/dist/esm/node/runtime/html/injectAssets.js +2 -2
- package/dist/esm/node/runtime/renderPage/assertArguments.js +3 -3
- package/dist/esm/node/runtime/renderPage/{createHttpResponseObject.d.ts → createHttpResponse.d.ts} +9 -5
- package/dist/esm/node/runtime/renderPage/{createHttpResponseObject.js → createHttpResponse.js} +21 -14
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +3 -5
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.js +4 -3
- package/dist/esm/node/runtime/renderPage/inferMediaType.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/inferMediaType.js +3 -0
- package/dist/esm/node/runtime/renderPage/isConfigInvalid.d.ts +6 -2
- package/dist/esm/node/runtime/renderPage/isConfigInvalid.js +6 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -11
- package/dist/esm/node/runtime/renderPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage.js +62 -66
- package/dist/esm/shared/page-configs/Config.d.ts +1 -1
- package/dist/esm/shared/page-configs/assertPlusFileExport.js +1 -2
- package/dist/esm/shared/route/abort.d.ts +3 -3
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +1 -1
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/isArray.js +1 -1
- package/dist/esm/utils/parseUrl-extras.d.ts +2 -0
- package/dist/esm/utils/parseUrl-extras.js +5 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +66 -66
- package/plugin.js +1 -0
- package/prerender.js +1 -0
- package/routing.js +1 -0
- package/server.js +1 -0
- /package/dist/cjs/node/runtime/renderPage/{createHttpResponseObject → createHttpResponse}/assertNoInfiniteHttpRedirect.js +0 -0
- /package/dist/cjs/node/runtime/renderPage/{createHttpResponseObject → createHttpResponse}/getCacheControl.js +0 -0
- /package/dist/esm/node/runtime/renderPage/{createHttpResponseObject → createHttpResponse}/assertNoInfiniteHttpRedirect.d.ts +0 -0
- /package/dist/esm/node/runtime/renderPage/{createHttpResponseObject → createHttpResponse}/assertNoInfiniteHttpRedirect.js +0 -0
- /package/dist/esm/node/runtime/renderPage/{createHttpResponseObject → createHttpResponse}/getCacheControl.d.ts +0 -0
- /package/dist/esm/node/runtime/renderPage/{createHttpResponseObject → createHttpResponse}/getCacheControl.js +0 -0
|
@@ -10,7 +10,7 @@ const utils_js_1 = require("./utils.js");
|
|
|
10
10
|
const abort_js_1 = require("../../shared/route/abort.js");
|
|
11
11
|
const globalContext_js_1 = require("./globalContext.js");
|
|
12
12
|
const handlePageContextRequestUrl_js_1 = require("./renderPage/handlePageContextRequestUrl.js");
|
|
13
|
-
const
|
|
13
|
+
const createHttpResponse_js_1 = require("./renderPage/createHttpResponse.js");
|
|
14
14
|
const loggerRuntime_js_1 = require("./renderPage/loggerRuntime.js");
|
|
15
15
|
const isNewError_js_1 = require("./renderPage/isNewError.js");
|
|
16
16
|
const assertArguments_js_1 = require("./renderPage/assertArguments.js");
|
|
@@ -23,8 +23,7 @@ const handleErrorWithoutErrorPage_js_1 = require("./renderPage/handleErrorWithou
|
|
|
23
23
|
const loadUserFilesServerSide_js_1 = require("./renderPage/loadUserFilesServerSide.js");
|
|
24
24
|
const resolveRedirects_js_1 = require("./renderPage/resolveRedirects.js");
|
|
25
25
|
const globalObject = (0, utils_js_1.getGlobalObject)('runtime/renderPage.ts', {
|
|
26
|
-
httpRequestsCount: 0
|
|
27
|
-
pendingRequestsCount: 0
|
|
26
|
+
httpRequestsCount: 0
|
|
28
27
|
});
|
|
29
28
|
let renderPage_wrapper = async (_httpRequestId, ret) => ({
|
|
30
29
|
pageContextReturn: await ret()
|
|
@@ -36,33 +35,35 @@ exports.renderPage_addWrapper = renderPage_addWrapper;
|
|
|
36
35
|
// `renderPage()` calls `renderPageNominal()` while ensuring that errors are `console.error(err)` instead of `throw err`, so that Vike never triggers a server shut down. (Throwing an error in an Express.js middleware shuts down the whole Express.js server.)
|
|
37
36
|
async function renderPage(pageContextInit) {
|
|
38
37
|
(0, assertArguments_js_1.assertArguments)(...arguments);
|
|
39
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextInit, 'urlOriginal', 'string'));
|
|
38
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextInit, 'urlOriginal', 'string')); // assertUsage() already implemented at assertArguments()
|
|
40
39
|
(0, utils_js_1.assertEnv)();
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
assertIsUrl(pageContextInit.urlOriginal);
|
|
41
|
+
const urlPathnameWithBase = (0, utils_js_1.parseUrl)(pageContextInit.urlOriginal, '/').pathname;
|
|
42
|
+
assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal);
|
|
43
|
+
if (urlPathnameWithBase.endsWith('/favicon.ico'))
|
|
44
|
+
return getPageContextHttpResponseFavicon404(pageContextInit);
|
|
46
45
|
const httpRequestId = getRequestId();
|
|
47
|
-
const
|
|
48
|
-
logHttpRequest(
|
|
49
|
-
globalObject.pendingRequestsCount++;
|
|
46
|
+
const urlOriginalPretty = (0, utils_js_1.getUrlPretty)(pageContextInit.urlOriginal);
|
|
47
|
+
logHttpRequest(urlOriginalPretty, httpRequestId);
|
|
50
48
|
const { pageContextReturn } = await renderPage_wrapper(httpRequestId, () => renderPageAndPrepare(pageContextInit, httpRequestId));
|
|
51
|
-
logHttpResponse(
|
|
52
|
-
globalObject.pendingRequestsCount--;
|
|
49
|
+
logHttpResponse(urlOriginalPretty, httpRequestId, pageContextReturn);
|
|
53
50
|
(0, utils_js_1.checkType)(pageContextReturn);
|
|
51
|
+
(0, utils_js_1.assert)(pageContextReturn.httpResponse);
|
|
54
52
|
return pageContextReturn;
|
|
55
53
|
}
|
|
56
54
|
exports.renderPage = renderPage;
|
|
57
55
|
async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
58
56
|
// Invalid config
|
|
59
|
-
const handleInvalidConfig = () => {
|
|
57
|
+
const handleInvalidConfig = (err) => {
|
|
60
58
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(picocolors_1.default.bold(picocolors_1.default.red('Error while loading a Vike config file, see error above.')), httpRequestId, 'error');
|
|
61
|
-
const
|
|
62
|
-
return
|
|
59
|
+
const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit);
|
|
60
|
+
return pageContextWithError;
|
|
63
61
|
};
|
|
64
62
|
if (isConfigInvalid_js_1.isConfigInvalid) {
|
|
65
|
-
|
|
63
|
+
if (1 < 2 // Make TS happy
|
|
64
|
+
) {
|
|
65
|
+
return handleInvalidConfig(isConfigInvalid_js_1.isConfigInvalid.err);
|
|
66
|
+
}
|
|
66
67
|
}
|
|
67
68
|
// Prepare context
|
|
68
69
|
let renderContext;
|
|
@@ -75,21 +76,17 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
|
75
76
|
// initGlobalContext_renderPage() and getRenderContext() don't call any user hooks => err isn't thrown from user code.
|
|
76
77
|
(0, utils_js_1.assert)(!(0, abort_js_1.isAbortError)(err));
|
|
77
78
|
(0, loggerRuntime_js_1.logRuntimeError)(err, httpRequestId);
|
|
78
|
-
const
|
|
79
|
-
return
|
|
79
|
+
const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit);
|
|
80
|
+
return pageContextWithError;
|
|
80
81
|
}
|
|
81
82
|
if (isConfigInvalid_js_1.isConfigInvalid) {
|
|
82
|
-
return handleInvalidConfig();
|
|
83
|
+
return handleInvalidConfig(isConfigInvalid_js_1.isConfigInvalid.err);
|
|
83
84
|
}
|
|
84
85
|
else {
|
|
85
86
|
// From now on, renderContext.pageConfigs contains all the configuration data; getVikeConfig() isn't called anymore for this request
|
|
86
87
|
}
|
|
87
88
|
// Check Base URL
|
|
88
|
-
|
|
89
|
-
const pageContextHttpResponse = checkBaseUrl(pageContextInit, httpRequestId);
|
|
90
|
-
if (pageContextHttpResponse)
|
|
91
|
-
return pageContextHttpResponse;
|
|
92
|
-
}
|
|
89
|
+
assertBaseUrl(pageContextInit);
|
|
93
90
|
// Normalize URL
|
|
94
91
|
{
|
|
95
92
|
const pageContextHttpResponse = normalizeUrl(pageContextInit, httpRequestId);
|
|
@@ -185,8 +182,8 @@ async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderC
|
|
|
185
182
|
if (!handled.pageContextReturn) {
|
|
186
183
|
const pageContextAbort = errErrorPage._pageContextAbort;
|
|
187
184
|
(0, utils_js_1.assertWarning)(false, `Failed to render error page because ${picocolors_1.default.cyan(pageContextAbort._abortCall)} was called: make sure ${picocolors_1.default.cyan(pageContextAbort._abortCaller)} doesn't occur while the error page is being rendered.`, { onlyOnce: false });
|
|
188
|
-
const
|
|
189
|
-
return
|
|
185
|
+
const pageContextHttpWithError = getPageContextHttpResponseError(errNominalPage, pageContextInit);
|
|
186
|
+
return pageContextHttpWithError;
|
|
190
187
|
}
|
|
191
188
|
// `throw redirect()` / `throw render(url)`
|
|
192
189
|
return handled.pageContextReturn;
|
|
@@ -194,20 +191,19 @@ async function renderPageAlreadyPrepared(pageContextInit, httpRequestId, renderC
|
|
|
194
191
|
if ((0, isNewError_js_1.isNewError)(errErrorPage, errNominalPage)) {
|
|
195
192
|
(0, loggerRuntime_js_1.logRuntimeError)(errErrorPage, httpRequestId);
|
|
196
193
|
}
|
|
197
|
-
const
|
|
198
|
-
return
|
|
194
|
+
const pageContextWithError = getPageContextHttpResponseError(errNominalPage, pageContextInit);
|
|
195
|
+
return pageContextWithError;
|
|
199
196
|
}
|
|
200
197
|
return pageContextErrorPage;
|
|
201
198
|
}
|
|
202
199
|
}
|
|
203
200
|
function logHttpRequest(urlOriginal, httpRequestId) {
|
|
204
|
-
|
|
205
|
-
(0, loggerRuntime_js_1.logRuntimeInfo)?.(getRequestInfoMessage(urlOriginal), httpRequestId, 'info', clearErrors);
|
|
201
|
+
(0, loggerRuntime_js_1.logRuntimeInfo)?.(getRequestInfoMessage(urlOriginal), httpRequestId, 'info');
|
|
206
202
|
}
|
|
207
203
|
function getRequestInfoMessage(urlOriginal) {
|
|
208
204
|
return `HTTP request: ${prettyUrl(urlOriginal)}`;
|
|
209
205
|
}
|
|
210
|
-
function logHttpResponse(
|
|
206
|
+
function logHttpResponse(urlOriginalPretty, httpRequestId, pageContextReturn) {
|
|
211
207
|
const statusCode = pageContextReturn.httpResponse?.statusCode ?? null;
|
|
212
208
|
let msg;
|
|
213
209
|
let isNominal;
|
|
@@ -218,10 +214,10 @@ function logHttpResponse(urlOriginal, httpRequestId, pageContextReturn) {
|
|
|
218
214
|
// - URL doesn't include Base URL
|
|
219
215
|
// - Can we abort earlier so that `logHttpResponse()` and `logHttpRequest()` aren't even called?
|
|
220
216
|
// - Error loading a Vike config file
|
|
221
|
-
// - We should show `HTTP response ${
|
|
217
|
+
// - We should show `HTTP response ${urlOriginalPretty} ERR` instead.
|
|
222
218
|
// - Maybe we can/should make the error available at pageContext.errorWhileRendering
|
|
223
219
|
(0, utils_js_1.assert)(errorWhileRendering === null || errorWhileRendering === undefined);
|
|
224
|
-
msg = `HTTP response ${prettyUrl(
|
|
220
|
+
msg = `HTTP response ${prettyUrl(urlOriginalPretty)} ${picocolors_1.default.dim('null')}`;
|
|
225
221
|
// Erroneous value (it shoud sometimes be `false`) but it's fine as it doesn't seem to have much of an impact.
|
|
226
222
|
isNominal = true;
|
|
227
223
|
}
|
|
@@ -239,28 +235,33 @@ function logHttpResponse(urlOriginal, httpRequestId, pageContextReturn) {
|
|
|
239
235
|
.find((header) => header[0] === 'Location');
|
|
240
236
|
(0, utils_js_1.assert)(headerRedirect);
|
|
241
237
|
const urlRedirect = headerRedirect[1];
|
|
242
|
-
|
|
238
|
+
urlOriginalPretty = urlRedirect;
|
|
243
239
|
}
|
|
244
|
-
msg = `HTTP ${type} ${prettyUrl(
|
|
240
|
+
msg = `HTTP ${type} ${prettyUrl(urlOriginalPretty)} ${color(statusCode ?? 'ERR')}`;
|
|
245
241
|
}
|
|
246
242
|
}
|
|
247
243
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(msg, httpRequestId, isNominal ? 'info' : 'error');
|
|
248
244
|
}
|
|
249
|
-
function
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
245
|
+
function prettyUrl(url) {
|
|
246
|
+
return picocolors_1.default.bold(decodeURI(url));
|
|
247
|
+
}
|
|
248
|
+
function getPageContextHttpResponseError(err, pageContextInit) {
|
|
249
|
+
const pageContextWithError = createPageContext(pageContextInit);
|
|
250
|
+
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseError)();
|
|
251
|
+
(0, utils_js_1.objectAssign)(pageContextWithError, {
|
|
252
|
+
httpResponse,
|
|
253
253
|
errorWhileRendering: err
|
|
254
254
|
});
|
|
255
|
-
return
|
|
255
|
+
return pageContextWithError;
|
|
256
256
|
}
|
|
257
|
-
function
|
|
258
|
-
const
|
|
259
|
-
(0,
|
|
260
|
-
|
|
261
|
-
|
|
257
|
+
function getPageContextHttpResponseFavicon404(pageContextInit) {
|
|
258
|
+
const pageContext = createPageContext(pageContextInit);
|
|
259
|
+
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseFavicon404)();
|
|
260
|
+
(0, utils_js_1.objectAssign)(pageContext, {
|
|
261
|
+
httpResponse
|
|
262
262
|
});
|
|
263
|
-
|
|
263
|
+
(0, utils_js_1.checkType)(pageContext);
|
|
264
|
+
return pageContext;
|
|
264
265
|
}
|
|
265
266
|
function createPageContext(pageContextInit) {
|
|
266
267
|
const pageContext = {
|
|
@@ -286,6 +287,7 @@ async function renderPageNominal(pageContext) {
|
|
|
286
287
|
}
|
|
287
288
|
}
|
|
288
289
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContext, '_pageId', 'string'));
|
|
290
|
+
(0, utils_js_1.assert)(pageContext.errorWhileRendering === null);
|
|
289
291
|
// Render
|
|
290
292
|
const pageContextAfterRender = await (0, renderPageAlreadyRouted_js_1.renderPageAlreadyRouted)(pageContext);
|
|
291
293
|
(0, utils_js_1.assert)(pageContext === pageContextAfterRender);
|
|
@@ -331,10 +333,12 @@ function getRequestId() {
|
|
|
331
333
|
(0, utils_js_1.assert)(httpRequestId >= 1);
|
|
332
334
|
return httpRequestId;
|
|
333
335
|
}
|
|
334
|
-
function
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
336
|
+
function assertIsUrl(urlOriginal) {
|
|
337
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isUrl)(urlOriginal), `${picocolors_1.default.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${picocolors_1.default.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which isn't a valid URL.`);
|
|
338
|
+
}
|
|
339
|
+
function assertIsNotViteRequest(urlPathname, urlOriginal) {
|
|
340
|
+
const isViteRequest = urlPathname.startsWith('/@vite/client') || urlPathname.startsWith('/@fs/') || urlPathname.startsWith('/__vite_ping');
|
|
341
|
+
(0, utils_js_1.assertUsage)(!isViteRequest, `${picocolors_1.default.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${picocolors_1.default.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which is unexpected because this URL should have already been handled by Vite's development middleware. Make sure to 1. install Vite's development middleware and 2. add Vite's middleware *before* Vike's middleware, see https://vike.dev/renderPage`);
|
|
338
342
|
}
|
|
339
343
|
function normalizeUrl(pageContextInit, httpRequestId) {
|
|
340
344
|
const { trailingSlash, disableUrlNormalization, baseServer } = (0, globalContext_js_1.getGlobalContext)();
|
|
@@ -348,7 +352,7 @@ function normalizeUrl(pageContextInit, httpRequestId) {
|
|
|
348
352
|
if (!urlNormalized)
|
|
349
353
|
return null;
|
|
350
354
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`URL normalized from ${picocolors_1.default.cyan(urlOriginal)} to ${picocolors_1.default.cyan(urlNormalized)} (https://vike.dev/url-normalization)`, httpRequestId, 'info');
|
|
351
|
-
const httpResponse = (0,
|
|
355
|
+
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseRedirect)({ url: urlNormalized, statusCode: 301 }, pageContextInit.urlOriginal);
|
|
352
356
|
const pageContextHttpResponse = createPageContext(pageContextInit);
|
|
353
357
|
(0, utils_js_1.objectAssign)(pageContextHttpResponse, { httpResponse });
|
|
354
358
|
return pageContextHttpResponse;
|
|
@@ -384,7 +388,7 @@ function getPermanentRedirect(pageContextInit, httpRequestId) {
|
|
|
384
388
|
(0, utils_js_1.assert)(urlTarget !== pageContextInit.urlOriginal);
|
|
385
389
|
}
|
|
386
390
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`Permanent redirect defined by your config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
387
|
-
const httpResponse = (0,
|
|
391
|
+
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseRedirect)({ url: urlTarget, statusCode: 301 }, urlWithoutBase);
|
|
388
392
|
const pageContextHttpResponse = createPageContext(pageContextInit);
|
|
389
393
|
(0, utils_js_1.objectAssign)(pageContextHttpResponse, { httpResponse });
|
|
390
394
|
return pageContextHttpResponse;
|
|
@@ -413,7 +417,7 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
413
417
|
else {
|
|
414
418
|
pageContextSerialized = (0, serializePageContextClientSide_js_1.serializePageContextAbort)(pageContextAbort);
|
|
415
419
|
}
|
|
416
|
-
const httpResponse = await (0,
|
|
420
|
+
const httpResponse = await (0, createHttpResponse_js_1.createHttpResponsePageContextJson)(pageContextSerialized);
|
|
417
421
|
const pageContextReturn = { httpResponse };
|
|
418
422
|
return { pageContextReturn };
|
|
419
423
|
}
|
|
@@ -428,7 +432,7 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
428
432
|
if (pageContextAbort._urlRedirect) {
|
|
429
433
|
const pageContextReturn = createPageContext(pageContextInit);
|
|
430
434
|
(0, utils_js_1.objectAssign)(pageContextReturn, pageContextAbort);
|
|
431
|
-
const httpResponse = (0,
|
|
435
|
+
const httpResponse = (0, createHttpResponse_js_1.createHttpResponseRedirect)(pageContextAbort._urlRedirect, (() => {
|
|
432
436
|
const { pathname, searchOriginal } = pageContextNominalPageInit.urlParsed;
|
|
433
437
|
const urlLogical = (0, utils_js_1.createUrlFromComponents)(null, pathname, searchOriginal,
|
|
434
438
|
// The server-side doesn't have access to the hash
|
|
@@ -441,18 +445,10 @@ pageContextNominalPageInit, httpRequestId, renderContext, pageContextErrorPageIn
|
|
|
441
445
|
(0, utils_js_1.assert)(pageContextAbort.abortStatusCode);
|
|
442
446
|
return { pageContextAbort };
|
|
443
447
|
}
|
|
444
|
-
function
|
|
448
|
+
function assertBaseUrl(pageContextInit) {
|
|
445
449
|
const { baseServer } = (0, globalContext_js_1.getGlobalContext)();
|
|
446
450
|
const { urlOriginal } = pageContextInit;
|
|
447
451
|
const { urlWithoutPageContextRequestSuffix } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(urlOriginal);
|
|
448
452
|
const { hasBaseServer } = (0, utils_js_1.parseUrl)(urlWithoutPageContextRequestSuffix, baseServer);
|
|
449
|
-
|
|
450
|
-
(0, loggerRuntime_js_1.logRuntimeInfo)?.(`${getRequestInfoMessage(urlOriginal)} skipped because URL ${prettyUrl(urlOriginal)} doesn't start with Base URL ${prettyUrl(baseServer)} (https://vike.dev/base-url)`, httpRequestId, 'info');
|
|
451
|
-
const pageContextHttpResponseNull = getPageContextHttpResponseNull(pageContextInit);
|
|
452
|
-
return pageContextHttpResponseNull;
|
|
453
|
-
}
|
|
454
|
-
return null;
|
|
455
|
-
}
|
|
456
|
-
function prettyUrl(url) {
|
|
457
|
-
return picocolors_1.default.bold(decodeURI(url));
|
|
453
|
+
(0, utils_js_1.assertUsage)(hasBaseServer, `${picocolors_1.default.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${picocolors_1.default.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which doesn't start with Base URL ${picocolors_1.default.code(baseServer)} (https://vike.dev/base-url)`);
|
|
458
454
|
}
|
|
@@ -24,6 +24,7 @@ function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
|
|
|
24
24
|
}
|
|
25
25
|
const exportDefault = picocolors_1.default.code('export default');
|
|
26
26
|
const exportNamed = picocolors_1.default.code(`export { ${configName} }`);
|
|
27
|
+
(0, utils_js_1.assert)(exportNamesValid.length <= 2);
|
|
27
28
|
if (exportNamesValid.length === 0) {
|
|
28
29
|
(0, utils_js_1.assertUsage)(false, `${filePathToShowToUser} should have a ${exportNamed} or ${exportDefault}`);
|
|
29
30
|
}
|
|
@@ -32,8 +33,6 @@ function assertPlusFileExport(fileExports, filePathToShowToUser, configName) {
|
|
|
32
33
|
onlyOnce: true
|
|
33
34
|
});
|
|
34
35
|
}
|
|
35
|
-
(0, utils_js_1.assert)(exportNamesValid.length === 1);
|
|
36
|
-
(0, utils_js_1.assert)(exportNamesInvalid.length > 0);
|
|
37
36
|
if (!TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext))) {
|
|
38
37
|
exportNamesInvalid.forEach((exportInvalid) => {
|
|
39
38
|
(0, utils_js_1.assertWarning)(false, `${filePathToShowToUser} unexpected ${picocolors_1.default.cyan(`export { ${exportInvalid} }`)}`, {
|
|
@@ -72,7 +72,7 @@ async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
|
|
|
72
72
|
}
|
|
73
73
|
if ((0, utils_js_1.hasProp)(hookReturn.pageContext, 'urlLogical')) {
|
|
74
74
|
(0, utils_js_1.assertUsageUrlPathnameAbsolute)(
|
|
75
|
-
// We type-cast
|
|
75
|
+
// We skip validation and type-cast instead of assertUsage() in order to save client-side KBs
|
|
76
76
|
hookReturn.pageContext.urlLogical, `${errPrefix} returned ${picocolors_1.default.cyan('{ pageContext: { urlLogical } }')} but ${picocolors_1.default.cyan('urlLogical')}`);
|
|
77
77
|
}
|
|
78
78
|
(0, assertPageContextProvidedByUser_js_1.assertPageContextProvidedByUser)(hookReturn.pageContext, {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isArray = void 0;
|
|
4
|
-
//
|
|
4
|
+
// Same as Array.isArray() but typesafe: asserts unknown[] instead of any[]
|
|
5
5
|
function isArray(value) {
|
|
6
6
|
return Array.isArray(value);
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addUrlOrigin = exports.removeUrlOrigin = exports.modifyUrlPathname = exports.removeBaseServer = exports.normalizeUrlPathname = exports.isBaseAssets = exports.prependBase = void 0;
|
|
3
|
+
exports.getUrlPretty = exports.addUrlOrigin = exports.removeUrlOrigin = exports.modifyUrlPathname = exports.removeBaseServer = exports.normalizeUrlPathname = exports.isBaseAssets = exports.prependBase = void 0;
|
|
4
4
|
const parseUrl_js_1 = require("./parseUrl.js");
|
|
5
5
|
const assert_js_1 = require("./assert.js");
|
|
6
6
|
const slice_js_1 = require("./slice.js");
|
|
@@ -103,3 +103,8 @@ function addUrlOrigin(url, origin) {
|
|
|
103
103
|
return urlModified;
|
|
104
104
|
}
|
|
105
105
|
exports.addUrlOrigin = addUrlOrigin;
|
|
106
|
+
function getUrlPretty(url) {
|
|
107
|
+
const { urlModified } = removeUrlOrigin(url);
|
|
108
|
+
return urlModified;
|
|
109
|
+
}
|
|
110
|
+
exports.getUrlPretty = getUrlPretty;
|
|
@@ -20,6 +20,7 @@ import { getErrorPageId } from '../../shared/error-page.js';
|
|
|
20
20
|
const globalObject = getGlobalObject('renderPageClientSide.ts', { renderCounter: 0 });
|
|
21
21
|
async function renderPageClientSide(renderArgs) {
|
|
22
22
|
const { scrollTarget, urlOriginal = getCurrentUrl(), overwriteLastHistoryEntry = false, isBackwardNavigation, pageContextsFromRewrite = [], redirectCount = 0, isUserLandPushStateNavigation, isClientSideNavigation = true } = renderArgs;
|
|
23
|
+
const { previousPageContext } = globalObject;
|
|
23
24
|
const { isRenderOutdated, setHydrationCanBeAborted, isFirstRender } = getIsRenderOutdated();
|
|
24
25
|
// Note that pageContext.isHydration isn't equivalent to isFirstRender
|
|
25
26
|
// - Thus pageContext.isHydration isn't equivalent to !pageContext.isClientSideNavigation
|
|
@@ -41,7 +42,6 @@ async function renderPageClientSide(renderArgs) {
|
|
|
41
42
|
return;
|
|
42
43
|
// onPageTransitionStart()
|
|
43
44
|
if (globalObject.isFirstRenderDone) {
|
|
44
|
-
const { previousPageContext } = globalObject;
|
|
45
45
|
assert(previousPageContext);
|
|
46
46
|
// We use the hook of the previous page in order to be able to call onPageTransitionStart() before fetching the files of the next page.
|
|
47
47
|
// https://github.com/vikejs/vike/issues/1560
|
|
@@ -96,8 +96,8 @@ async function renderPageClientSide(renderArgs) {
|
|
|
96
96
|
}
|
|
97
97
|
assert(hasProp(pageContextFromRoute, '_pageId', 'string')); // Help TS
|
|
98
98
|
const isSamePage = pageContextFromRoute._pageId &&
|
|
99
|
-
|
|
100
|
-
pageContextFromRoute._pageId ===
|
|
99
|
+
previousPageContext?._pageId &&
|
|
100
|
+
pageContextFromRoute._pageId === previousPageContext._pageId;
|
|
101
101
|
if (isUserLandPushStateNavigation && isSamePage) {
|
|
102
102
|
// Skip's Vike's rendering; let the user handle the navigation
|
|
103
103
|
return;
|
|
@@ -170,7 +170,8 @@ async function renderPageClientSide(renderArgs) {
|
|
|
170
170
|
const pageContext = await createPageContext(urlOriginal);
|
|
171
171
|
objectAssign(pageContext, {
|
|
172
172
|
isBackwardNavigation,
|
|
173
|
-
isClientSideNavigation
|
|
173
|
+
isClientSideNavigation,
|
|
174
|
+
_previousPageContext: previousPageContext
|
|
174
175
|
});
|
|
175
176
|
{
|
|
176
177
|
const pageContextFromAllRewrites = getPageContextFromAllRewrites(pageContextsFromRewrite);
|
|
@@ -366,7 +367,6 @@ async function renderPageClientSide(renderArgs) {
|
|
|
366
367
|
// onPageTransitionEnd()
|
|
367
368
|
if (globalObject.isTransitioning) {
|
|
368
369
|
globalObject.isTransitioning = undefined;
|
|
369
|
-
const { previousPageContext } = globalObject;
|
|
370
370
|
assert(previousPageContext);
|
|
371
371
|
assertHook(previousPageContext, 'onPageTransitionEnd');
|
|
372
372
|
const hook = getHook(previousPageContext, 'onPageTransitionEnd');
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { importBuild };
|
|
2
2
|
export { set_ASSETS_MAP };
|
|
3
|
-
import { serverEntryPlugin } from '@brillout/vite-plugin-server-entry/plugin
|
|
3
|
+
import { serverEntryPlugin } from '@brillout/vite-plugin-server-entry/plugin';
|
|
4
4
|
import { assert, getOutDirs, toPosixPath } from '../../utils.js';
|
|
5
5
|
import path from 'path';
|
|
6
6
|
import { createRequire } from 'module';
|
|
@@ -8,7 +8,7 @@ import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-file
|
|
|
8
8
|
import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
9
9
|
import { vikeConfigDependencies, reloadVikeConfig, isVikeConfigFile } from './v1-design/getVikeConfig.js';
|
|
10
10
|
import pc from '@brillout/picocolors';
|
|
11
|
-
import { logConfigInfo
|
|
11
|
+
import { logConfigInfo } from '../../shared/loggerNotProd.js';
|
|
12
12
|
import { getModuleFilePathAbsolute } from '../../shared/getFilePath.js';
|
|
13
13
|
function importUserCode() {
|
|
14
14
|
let config;
|
|
@@ -93,17 +93,13 @@ function handleHotUpdate(ctx, config) {
|
|
|
93
93
|
`${msg} — ${pc.cyan('no HMR')}, see https://vike.dev/on-demand-compiler`,
|
|
94
94
|
'info',
|
|
95
95
|
null,
|
|
96
|
-
true
|
|
97
|
-
clear,
|
|
98
|
-
config
|
|
96
|
+
true
|
|
99
97
|
)
|
|
100
98
|
return
|
|
101
99
|
}
|
|
102
100
|
//*/
|
|
103
|
-
// HMR can resolve errors => we clear previously shown errors.
|
|
104
101
|
// It can hide an error it shouldn't hide (because the error isn't shown again), but it's ok since users can reload the page and the error will be shown again (Vite transpilation errors are shown again upon a page reload).
|
|
105
102
|
if (!isVikeConfig && isViteModule) {
|
|
106
|
-
clearLogs({ clearErrors: true });
|
|
107
103
|
return;
|
|
108
104
|
}
|
|
109
105
|
if (isVikeConfig) {
|
|
@@ -35,7 +35,7 @@ function reloadVikeConfig(userRootDir, outDirRoot) {
|
|
|
35
35
|
handleReloadSideEffects();
|
|
36
36
|
}
|
|
37
37
|
async function handleReloadSideEffects() {
|
|
38
|
-
wasConfigInvalid = isConfigInvalid;
|
|
38
|
+
wasConfigInvalid = !!isConfigInvalid;
|
|
39
39
|
const vikeConfigPromisePrevious = vikeConfigPromise;
|
|
40
40
|
try {
|
|
41
41
|
await vikeConfigPromise;
|
|
@@ -210,7 +210,7 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
|
|
|
210
210
|
else {
|
|
211
211
|
assert(ret === undefined);
|
|
212
212
|
assert(err);
|
|
213
|
-
isConfigInvalid_set(
|
|
213
|
+
isConfigInvalid_set({ err });
|
|
214
214
|
if (!isDev) {
|
|
215
215
|
assert(getViteDevServer() === null);
|
|
216
216
|
throw err;
|
|
@@ -43,14 +43,9 @@ function addSsrMiddleware(middlewares, config, isPreview) {
|
|
|
43
43
|
if (value)
|
|
44
44
|
res.setHeader(name, value);
|
|
45
45
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const { statusCode, headers } = pageContext.httpResponse;
|
|
51
|
-
headers.forEach(([name, value]) => res.setHeader(name, value));
|
|
52
|
-
res.statusCode = statusCode;
|
|
53
|
-
pageContext.httpResponse.pipe(res);
|
|
54
|
-
}
|
|
46
|
+
const { httpResponse } = pageContext;
|
|
47
|
+
httpResponse.headers.forEach(([name, value]) => res.setHeader(name, value));
|
|
48
|
+
res.statusCode = httpResponse.statusCode;
|
|
49
|
+
httpResponse.pipe(res);
|
|
55
50
|
});
|
|
56
51
|
}
|
|
@@ -1,16 +1,9 @@
|
|
|
1
1
|
export { logWithViteTag };
|
|
2
2
|
export { logWithVikeTag };
|
|
3
3
|
export { logDirectly };
|
|
4
|
-
export { isFirstLog };
|
|
5
|
-
export { clearScreen };
|
|
6
|
-
export { screenHasErrors };
|
|
7
4
|
export { applyViteSourceMapToStackTrace };
|
|
8
5
|
import type { LogCategory, LogType } from '../loggerNotProd.js';
|
|
9
|
-
import type { ResolvedConfig } from 'vite';
|
|
10
|
-
declare let isFirstLog: boolean;
|
|
11
|
-
declare let screenHasErrors: boolean;
|
|
12
6
|
declare function logWithVikeTag(msg: string, logType: LogType, category: LogCategory | null, showVikeVersion?: boolean): void;
|
|
13
7
|
declare function logWithViteTag(msg: string, logType: LogType, category: LogCategory | null): void;
|
|
14
8
|
declare function logDirectly(thing: unknown, logType: LogType): void;
|
|
15
|
-
declare function clearScreen(viteConfig: ResolvedConfig): void;
|
|
16
9
|
declare function applyViteSourceMapToStackTrace(thing: unknown): void;
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
export { logWithViteTag };
|
|
2
2
|
export { logWithVikeTag };
|
|
3
3
|
export { logDirectly };
|
|
4
|
-
export { isFirstLog };
|
|
5
|
-
export { clearScreen };
|
|
6
|
-
export { screenHasErrors };
|
|
7
4
|
export { applyViteSourceMapToStackTrace };
|
|
8
5
|
import { assert, projectInfo, stripAnsi, hasProp, assertIsNotProductionRuntime } from '../../utils.js';
|
|
9
6
|
import pc from '@brillout/picocolors';
|
|
10
7
|
import { isErrorDebug } from '../../../shared/isErrorDebug.js';
|
|
11
8
|
import { getViteDevServer } from '../../../runtime/globalContext.js';
|
|
12
9
|
assertIsNotProductionRuntime();
|
|
13
|
-
let isFirstLog = true;
|
|
14
|
-
let screenHasErrors = false;
|
|
15
10
|
function logWithVikeTag(msg, logType, category, showVikeVersion = false) {
|
|
16
11
|
const projectTag = getProjectTag(showVikeVersion);
|
|
17
12
|
msg = prependTags(msg, projectTag, category, logType);
|
|
@@ -36,7 +31,6 @@ function logWithViteTag(msg, logType, category) {
|
|
|
36
31
|
// - Production => logs aren't managed by loggerNotProd.ts => logDirectly() is never called (not even loaded as asserted by assertIsVitePluginCode())
|
|
37
32
|
function logDirectly(thing, logType) {
|
|
38
33
|
applyViteSourceMapToStackTrace(thing);
|
|
39
|
-
isFirstLog = false;
|
|
40
34
|
if (logType === 'info') {
|
|
41
35
|
console.log(thing);
|
|
42
36
|
return;
|
|
@@ -46,7 +40,6 @@ function logDirectly(thing, logType) {
|
|
|
46
40
|
return;
|
|
47
41
|
}
|
|
48
42
|
if (logType === 'error') {
|
|
49
|
-
screenHasErrors = true;
|
|
50
43
|
console.error(thing);
|
|
51
44
|
return;
|
|
52
45
|
}
|
|
@@ -57,11 +50,6 @@ function logDirectly(thing, logType) {
|
|
|
57
50
|
}
|
|
58
51
|
assert(false);
|
|
59
52
|
}
|
|
60
|
-
function clearScreen(viteConfig) {
|
|
61
|
-
// We use Vite's logger in order to respect the user's `clearScreen: false` setting
|
|
62
|
-
viteConfig.logger.clearScreen('error');
|
|
63
|
-
screenHasErrors = false;
|
|
64
|
-
}
|
|
65
53
|
function applyViteSourceMapToStackTrace(thing) {
|
|
66
54
|
if (isErrorDebug())
|
|
67
55
|
return;
|
|
@@ -4,7 +4,6 @@ export { logConfigInfo };
|
|
|
4
4
|
export { logConfigError };
|
|
5
5
|
export { logConfigErrorRecover };
|
|
6
6
|
export { logErrorDebugNote };
|
|
7
|
-
export { clearLogs };
|
|
8
7
|
export type { LogInfo };
|
|
9
8
|
export type { LogInfoArgs };
|
|
10
9
|
export type { LogError };
|
|
@@ -17,18 +16,13 @@ type LogInfo = (...args: LogInfoArgs) => void;
|
|
|
17
16
|
type LogInfoArgs = Parameters<typeof logRuntimeInfo>;
|
|
18
17
|
type LogError = (...args: LogErrorArgs) => void;
|
|
19
18
|
type LogErrorArgs = Parameters<typeof logRuntimeError>;
|
|
20
|
-
declare function logRuntimeInfo(msg: string, httpRequestId: number, logType: LogType
|
|
19
|
+
declare function logRuntimeInfo(msg: string, httpRequestId: number, logType: LogType): void;
|
|
21
20
|
declare function logViteAny(msg: string, logType: LogType, httpRequestId: number | null, prependViteTag: boolean): void;
|
|
22
21
|
declare function logConfigInfo(msg: string, logType: LogType): void;
|
|
23
22
|
declare function logConfigErrorRecover(): void;
|
|
24
23
|
declare function logRuntimeError(err: unknown, httpRequestId: number | null): void;
|
|
25
24
|
declare function logViteError(err: unknown, httpRequestId: number | undefined): void;
|
|
26
25
|
declare function logConfigError(err: unknown): void;
|
|
27
|
-
declare function clearLogs(conditions?: {
|
|
28
|
-
clearErrors?: boolean;
|
|
29
|
-
clearIfFirstLog?: boolean;
|
|
30
|
-
clearAlsoIfConfigIsInvalid?: boolean;
|
|
31
|
-
}): void;
|
|
32
26
|
/** Note shown to user when vike does something risky:
|
|
33
27
|
* - When vike dedupes (i.e. swallows) an error with getHttpRequestAsyncStore().shouldErrorBeSwallowed(err)
|
|
34
28
|
* - When vike modifies the error with getPrettyErrorWithCodeSnippet(err)
|
|
@@ -10,7 +10,6 @@ export { logConfigInfo };
|
|
|
10
10
|
export { logConfigError };
|
|
11
11
|
export { logConfigErrorRecover };
|
|
12
12
|
export { logErrorDebugNote };
|
|
13
|
-
export { clearLogs };
|
|
14
13
|
import { isAbortError } from '../../../shared/route/abort.js';
|
|
15
14
|
import { getViteConfig } from '../../runtime/globalContext.js';
|
|
16
15
|
import { overwriteRuntimeProductionLogger } from '../../runtime/renderPage/loggerRuntime.js';
|
|
@@ -19,18 +18,15 @@ import { getHttpRequestAsyncStore } from './getHttpRequestAsyncStore.js';
|
|
|
19
18
|
import { isErrorDebug } from '../../shared/isErrorDebug.js';
|
|
20
19
|
import { isErrorWithCodeSnippet, getPrettyErrorWithCodeSnippet } from './loggerNotProd/errorWithCodeSnippet.js';
|
|
21
20
|
import { getConfigExecutionErrorIntroMsg, getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js';
|
|
22
|
-
import { logWithVikeTag, logWithViteTag, logDirectly,
|
|
21
|
+
import { logWithVikeTag, logWithViteTag, logDirectly, applyViteSourceMapToStackTrace } from './loggerNotProd/log.js';
|
|
23
22
|
import pc from '@brillout/picocolors';
|
|
24
23
|
import { setAlreadyLogged } from '../../runtime/renderPage/isNewError.js';
|
|
25
|
-
import { isConfigInvalid } from '../../runtime/renderPage/isConfigInvalid.js';
|
|
26
24
|
import { onRuntimeError } from '../../runtime/renderPage/loggerProd.js';
|
|
27
25
|
import { isUserHookError } from '../../../shared/hooks/executeHook.js';
|
|
28
26
|
assertIsNotProductionRuntime();
|
|
29
27
|
overwriteRuntimeProductionLogger(logRuntimeError, logRuntimeInfo);
|
|
30
28
|
overwriteAssertProductionLogger(assertLogger);
|
|
31
|
-
function logRuntimeInfo(msg, httpRequestId, logType
|
|
32
|
-
if (clearErrors)
|
|
33
|
-
clearLogs({ clearErrors: true });
|
|
29
|
+
function logRuntimeInfo(msg, httpRequestId, logType) {
|
|
34
30
|
const category = getCategory(httpRequestId);
|
|
35
31
|
assert(category);
|
|
36
32
|
logWithVikeTag(msg, logType, category);
|
|
@@ -50,7 +46,6 @@ function logConfigInfo(msg, logType) {
|
|
|
50
46
|
}
|
|
51
47
|
function logConfigErrorRecover() {
|
|
52
48
|
const msg = pc.bold(pc.green('Configuration successfully loaded'));
|
|
53
|
-
clearLogs({ clearAlsoIfConfigIsInvalid: true });
|
|
54
49
|
const category = getConfigCategory();
|
|
55
50
|
logWithVikeTag(msg, 'error-recover', category);
|
|
56
51
|
}
|
|
@@ -110,7 +105,6 @@ function logErr(err, httpRequestId = null, errorComesFromVite) {
|
|
|
110
105
|
onRuntimeError(err);
|
|
111
106
|
}
|
|
112
107
|
function logConfigError(err) {
|
|
113
|
-
clearLogs({ clearAlsoIfConfigIsInvalid: true });
|
|
114
108
|
warnIfErrorIsNotObject(err);
|
|
115
109
|
const category = getConfigCategory();
|
|
116
110
|
{
|
|
@@ -173,22 +167,6 @@ function assertLogger(thing, logType) {
|
|
|
173
167
|
const { assertMsg, showVikeVersion } = res;
|
|
174
168
|
logWithVikeTag(assertMsg, logType, category, showVikeVersion);
|
|
175
169
|
}
|
|
176
|
-
function clearLogs(conditions = {}) {
|
|
177
|
-
if (!conditions.clearAlsoIfConfigIsInvalid && isConfigInvalid) {
|
|
178
|
-
// Avoid hiding the config error: the config error is printed only once
|
|
179
|
-
return;
|
|
180
|
-
}
|
|
181
|
-
if (conditions.clearErrors && !screenHasErrors) {
|
|
182
|
-
return;
|
|
183
|
-
}
|
|
184
|
-
if (conditions.clearIfFirstLog && !isFirstLog) {
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
const viteConfig = getViteConfig();
|
|
188
|
-
if (viteConfig) {
|
|
189
|
-
clearScreen(viteConfig);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
170
|
/** Note shown to user when vike does something risky:
|
|
193
171
|
* - When vike dedupes (i.e. swallows) an error with getHttpRequestAsyncStore().shouldErrorBeSwallowed(err)
|
|
194
172
|
* - When vike modifies the error with getPrettyErrorWithCodeSnippet(err)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { improveViteLogs };
|
|
2
2
|
import { assert, removeEmptyLines, trimWithAnsi, trimWithAnsiTrailOnly } from '../utils.js';
|
|
3
|
-
import { logViteError, logViteAny
|
|
3
|
+
import { logViteError, logViteAny } from './loggerNotProd.js';
|
|
4
4
|
import { getHttpRequestAsyncStore } from './getHttpRequestAsyncStore.js';
|
|
5
5
|
import { removeSuperfluousViteLog } from './loggerVite/removeSuperfluousViteLog.js';
|
|
6
6
|
import { isErrorDebug } from '../../shared/isErrorDebug.js';
|
|
@@ -36,9 +36,6 @@ function intercept(logType, config) {
|
|
|
36
36
|
assert(!isErrorDebug());
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
|
-
// Only allow Vite to clear for its first log. All other clearing is controlled by vike.
|
|
40
|
-
if (options.clear)
|
|
41
|
-
clearLogs({ clearIfFirstLog: true });
|
|
42
39
|
// Vite's default logger preprends the "[vite]" tag if and only if options.timestamp is true
|
|
43
40
|
const prependViteTag = options.timestamp || !!store?.httpRequestId;
|
|
44
41
|
logViteAny(msg, logType, store?.httpRequestId ?? null, prependViteTag);
|