vike 0.4.232-commit-1690f53 → 0.4.232
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/cjs/node/prerender/runPrerender.js +4 -9
- package/dist/cjs/node/runtime/renderPage/execHookServer.js +4 -1
- package/dist/cjs/node/runtime/renderPage/{execHookDataAndOnBeforeRender.js → executeOnBeforeRenderAndDataHooks.js} +2 -2
- package/dist/cjs/node/runtime/renderPage/{execHookOnRenderHtml.js → executeOnRenderHtmlHook.js} +3 -3
- package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +13 -18
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +11 -11
- package/dist/cjs/node/runtime/renderPage.js +48 -55
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +2 -0
- package/dist/cjs/shared/createPageContextShared.js +3 -1
- package/dist/cjs/shared/hooks/execHook.js +54 -31
- package/dist/cjs/shared/route/{execHookGuard.js → executeGuardHook.js} +3 -3
- package/dist/cjs/shared/route/{execHookOnBeforeRoute.js → executeOnBeforeRouteHook.js} +4 -4
- package/dist/cjs/shared/route/index.js +2 -3
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/styleFileRE.js +0 -1
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +2 -2
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +9 -9
- package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +62 -97
- package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +4 -11
- package/dist/esm/client/runtime-server-routing/entry.js +2 -2
- package/dist/esm/client/shared/{execHookOnRenderClient.d.ts → executeOnRenderClientHook.d.ts} +2 -2
- package/dist/esm/client/shared/{execHookOnRenderClient.js → executeOnRenderClientHook.js} +4 -4
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.d.ts +4 -12
- package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +4 -4
- package/dist/esm/node/prerender/runPrerender.d.ts +4 -250
- package/dist/esm/node/prerender/runPrerender.js +6 -11
- package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +3 -3
- package/dist/esm/node/runtime/renderPage/execHookServer.js +4 -1
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.d.ts +6 -0
- package/dist/esm/node/runtime/renderPage/{execHookDataAndOnBeforeRender.js → executeOnBeforeRenderAndDataHooks.js} +2 -2
- package/dist/esm/node/runtime/renderPage/{execHookOnRenderHtml.d.ts → executeOnRenderHtmlHook.d.ts} +2 -2
- package/dist/esm/node/runtime/renderPage/{execHookOnRenderHtml.js → executeOnRenderHtmlHook.js} +4 -4
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +6 -15
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +13 -18
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +13 -13
- package/dist/esm/node/runtime/renderPage.js +50 -57
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +2 -0
- package/dist/esm/shared/createPageContextShared.js +3 -1
- package/dist/esm/shared/hooks/execHook.d.ts +28 -14
- package/dist/esm/shared/hooks/execHook.js +54 -31
- package/dist/esm/shared/route/executeGuardHook.d.ts +8 -0
- package/dist/esm/shared/route/{execHookGuard.js → executeGuardHook.js} +4 -4
- package/dist/esm/shared/route/{execHookOnBeforeRoute.d.ts → executeOnBeforeRouteHook.d.ts} +2 -2
- package/dist/esm/shared/route/{execHookOnBeforeRoute.js → executeOnBeforeRouteHook.js} +5 -5
- package/dist/esm/shared/route/index.js +2 -3
- package/dist/esm/shared/route/resolveRouteFunction.js +2 -2
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/styleFileRE.js +0 -1
- package/package.json +1 -1
- package/dist/esm/node/runtime/renderPage/execHookDataAndOnBeforeRender.d.ts +0 -6
- package/dist/esm/shared/route/execHookGuard.d.ts +0 -8
|
@@ -67,7 +67,6 @@ const getOutDirs_js_1 = require("../vite/shared/getOutDirs.js");
|
|
|
67
67
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
68
68
|
const getProxyForPublicUsage_js_1 = require("../../shared/getProxyForPublicUsage.js");
|
|
69
69
|
const resolveRedirects_js_1 = require("../runtime/renderPage/resolveRedirects.js");
|
|
70
|
-
const utils_js_2 = require("../runtime/utils.js");
|
|
71
70
|
const docLink = 'https://vike.dev/i18n#pre-rendering';
|
|
72
71
|
async function runPrerender(options = {}, trigger) {
|
|
73
72
|
(0, context_js_1.setWasPrerenderRun)(trigger);
|
|
@@ -254,7 +253,7 @@ async function callOnBeforePrerenderStartHooks(prerenderContext, globalContext,
|
|
|
254
253
|
if (doNotPrerenderList.find((p) => p.pageId === pageId))
|
|
255
254
|
return;
|
|
256
255
|
const { hookName, hookFilePath } = hook;
|
|
257
|
-
const prerenderResult = await (0, execHook_js_1.
|
|
256
|
+
const prerenderResult = await (0, execHook_js_1.execHookWithoutPageContext)(() => hook.hookFn(), hook);
|
|
258
257
|
const result = normalizeOnPrerenderHookResult(prerenderResult, hookFilePath, hookName);
|
|
259
258
|
// Handle result
|
|
260
259
|
await Promise.all(result.map(async ({ url, pageContext }) => {
|
|
@@ -361,7 +360,7 @@ async function createPageContextPrerendering(urlOriginal, prerenderContext, glob
|
|
|
361
360
|
routeParams: {},
|
|
362
361
|
});
|
|
363
362
|
}
|
|
364
|
-
(0,
|
|
363
|
+
(0, utils_js_1.objectAssign)(pageContext, await (0, loadPageConfigsLazyServerSide_js_1.loadPageConfigsLazyServerSide)(pageContext));
|
|
365
364
|
let usesClientRouter;
|
|
366
365
|
{
|
|
367
366
|
const { pageId } = pageContext;
|
|
@@ -482,7 +481,7 @@ async function callOnPrerenderStartHook(prerenderContext, globalContext, concurr
|
|
|
482
481
|
(0, utils_js_1.preservePropertyGetters)(pageContext);
|
|
483
482
|
});
|
|
484
483
|
const prerenderContextPublic = preparePrerenderContextForPublicUsage(prerenderContext);
|
|
485
|
-
let result = await (0, execHook_js_1.
|
|
484
|
+
let result = await (0, execHook_js_1.execHookWithoutPageContext)(() => hookFn(prerenderContextPublic), onPrerenderStartHook);
|
|
486
485
|
// Before applying result
|
|
487
486
|
prerenderContext.pageContexts.forEach((pageContext) => {
|
|
488
487
|
;
|
|
@@ -764,13 +763,9 @@ function getRedirectHtml(urlTarget) {
|
|
|
764
763
|
<meta charset="UTF-8">
|
|
765
764
|
<meta http-equiv="refresh" content="0;url=${urlTargetSafe}">
|
|
766
765
|
<title>Redirect ${urlTargetSafe}</title>
|
|
767
|
-
<style>body{opacity:0}</style>
|
|
768
|
-
<noscript>
|
|
769
|
-
<style>body{opacity:1}</style>
|
|
770
|
-
</noscript>
|
|
771
766
|
</head>
|
|
772
767
|
<body style="min-height: 100vh; margin: 0; font-family: sans-serif; display: flex; justify-content: center; align-items: center; transition: opacity 0.3s;">
|
|
773
|
-
<script>setTimeout(()=>{document.body.style.opacity=1},
|
|
768
|
+
<script>document.body.style.opacity=0; setTimeout(()=>{document.body.style.opacity=1},1000);</script>
|
|
774
769
|
<div>
|
|
775
770
|
<h1>Redirect <a href="${urlTargetSafe}"><code style="background-color: #eaeaea; padding: 3px 5px; border-radius: 4px;">${urlTargetSafe}</code></a></h1>
|
|
776
771
|
<p>If you aren't redirected, click the link above.</p>
|
|
@@ -4,5 +4,8 @@ exports.execHookServer = execHookServer;
|
|
|
4
4
|
const execHook_js_1 = require("../../../shared/hooks/execHook.js");
|
|
5
5
|
const preparePageContextForPublicUsageServer_js_1 = require("./preparePageContextForPublicUsageServer.js");
|
|
6
6
|
async function execHookServer(hookName, pageContext) {
|
|
7
|
-
return await (0, execHook_js_1.execHook)(hookName, pageContext,
|
|
7
|
+
return await (0, execHook_js_1.execHook)(hookName, pageContext, (p) => {
|
|
8
|
+
(0, preparePageContextForPublicUsageServer_js_1.preparePageContextForPublicUsageServer)(p);
|
|
9
|
+
return p;
|
|
10
|
+
});
|
|
8
11
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.executeOnBeforeRenderAndDataHooks = executeOnBeforeRenderAndDataHooks;
|
|
4
4
|
const assertOnBeforeRenderHookReturn_js_1 = require("../../../shared/assertOnBeforeRenderHookReturn.js");
|
|
5
5
|
const execHookServer_js_1 = require("./execHookServer.js");
|
|
6
|
-
async function
|
|
6
|
+
async function executeOnBeforeRenderAndDataHooks(pageContext) {
|
|
7
7
|
if (pageContext._pageContextAlreadyProvidedByOnPrerenderHook) {
|
|
8
8
|
return;
|
|
9
9
|
}
|
package/dist/cjs/node/runtime/renderPage/{execHookOnRenderHtml.js → executeOnRenderHtmlHook.js}
RENAMED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.executeOnRenderHtmlHook = executeOnRenderHtmlHook;
|
|
7
7
|
const renderHtml_js_1 = require("../html/renderHtml.js");
|
|
8
8
|
const getHook_js_1 = require("../../../shared/hooks/getHook.js");
|
|
9
9
|
const utils_js_1 = require("../utils.js");
|
|
@@ -14,10 +14,10 @@ const assertHookReturnedObject_js_1 = require("../../../shared/assertHookReturne
|
|
|
14
14
|
const loggerRuntime_js_1 = require("../loggerRuntime.js");
|
|
15
15
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
16
16
|
const execHook_js_1 = require("../../../shared/hooks/execHook.js");
|
|
17
|
-
async function
|
|
17
|
+
async function executeOnRenderHtmlHook(pageContext) {
|
|
18
18
|
const hook = getRenderHook(pageContext);
|
|
19
19
|
(0, utils_js_1.objectAssign)(pageContext, { _renderHook: hook });
|
|
20
|
-
const { hookReturn } = await (0, execHook_js_1.
|
|
20
|
+
const { hookReturn } = await (0, execHook_js_1.execHookSingleWithReturn)(hook, pageContext, preparePageContextForPublicUsageServer_js_1.preparePageContextForPublicUsageServer);
|
|
21
21
|
const { documentHtml, pageContextProvidedByRenderHook, pageContextPromise, injectFilter } = processHookReturnValue(hookReturn, hook);
|
|
22
22
|
Object.assign(pageContext, pageContextProvidedByRenderHook);
|
|
23
23
|
(0, utils_js_1.objectAssign)(pageContext, { _pageContextPromise: pageContextPromise });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.loadPageConfigsLazyServerSide = loadPageConfigsLazyServerSide;
|
|
4
4
|
const getPageFiles_js_1 = require("../../../shared/getPageFiles.js");
|
|
5
5
|
const resolveVikeConfigPublic_js_1 = require("../../../shared/page-configs/resolveVikeConfigPublic.js");
|
|
6
6
|
const analyzePageClientSide_js_1 = require("../../../shared/getPageFiles/analyzePageClientSide.js");
|
|
@@ -10,13 +10,6 @@ const debugPageFiles_js_1 = require("./debugPageFiles.js");
|
|
|
10
10
|
const findPageConfig_js_1 = require("../../../shared/page-configs/findPageConfig.js");
|
|
11
11
|
const analyzePage_js_1 = require("./analyzePage.js");
|
|
12
12
|
const loadConfigValues_js_1 = require("../../../shared/page-configs/loadConfigValues.js");
|
|
13
|
-
const execHookServer_js_1 = require("./execHookServer.js");
|
|
14
|
-
async function loadPageConfigsLazyServerSideAndExecHook(pageContext) {
|
|
15
|
-
const pageContextAddendum = await loadPageConfigsLazyServerSide(pageContext);
|
|
16
|
-
(0, utils_js_1.objectAssign)(pageContext, pageContextAddendum);
|
|
17
|
-
await (0, execHookServer_js_1.execHookServer)('onCreatePageContext', pageContext);
|
|
18
|
-
return pageContext;
|
|
19
|
-
}
|
|
20
13
|
async function loadPageConfigsLazyServerSide(pageContext) {
|
|
21
14
|
const pageConfig = (0, findPageConfig_js_1.findPageConfig)(pageContext._globalContext._pageConfigs, pageContext.pageId); // Make pageConfig globally available as pageContext._pageConfig ?
|
|
22
15
|
const globalContext = pageContext._globalContext;
|
|
@@ -93,16 +86,18 @@ async function loadPageConfigsLazyServerSide(pageContext) {
|
|
|
93
86
|
return pageAssetsOldFormat;
|
|
94
87
|
},
|
|
95
88
|
});
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
89
|
+
{
|
|
90
|
+
(0, debugPageFiles_js_1.debugPageFiles)({
|
|
91
|
+
pageContext,
|
|
92
|
+
isHtmlOnly,
|
|
93
|
+
isClientRouting,
|
|
94
|
+
pageFilesLoaded,
|
|
95
|
+
pageFilesClientSide,
|
|
96
|
+
pageFilesServerSide,
|
|
97
|
+
clientEntries,
|
|
98
|
+
clientDependencies,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
106
101
|
return pageContextAddendum;
|
|
107
102
|
}
|
|
108
103
|
async function loadPageUserFiles(pageFilesAll, pageConfig, pageConfigGlobal, pageId, isDev) {
|
|
@@ -11,12 +11,12 @@ const utils_js_1 = require("../utils.js");
|
|
|
11
11
|
const serializeContext_js_1 = require("../html/serializeContext.js");
|
|
12
12
|
const createHttpResponse_js_1 = require("./createHttpResponse.js");
|
|
13
13
|
const loadPageConfigsLazyServerSide_js_1 = require("./loadPageConfigsLazyServerSide.js");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const executeOnRenderHtmlHook_js_1 = require("./executeOnRenderHtmlHook.js");
|
|
15
|
+
const executeOnBeforeRenderAndDataHooks_js_1 = require("./executeOnBeforeRenderAndDataHooks.js");
|
|
16
16
|
const loggerRuntime_js_1 = require("../loggerRuntime.js");
|
|
17
17
|
const isNewError_js_1 = require("./isNewError.js");
|
|
18
18
|
const preparePageContextForPublicUsageServer_js_1 = require("./preparePageContextForPublicUsageServer.js");
|
|
19
|
-
const
|
|
19
|
+
const executeGuardHook_js_1 = require("../../../shared/route/executeGuardHook.js");
|
|
20
20
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
21
21
|
const isServerSideError_js_1 = require("../../../shared/misc/isServerSideError.js");
|
|
22
22
|
async function renderPageAlreadyRouted(pageContext) {
|
|
@@ -28,16 +28,16 @@ async function renderPageAlreadyRouted(pageContext) {
|
|
|
28
28
|
(0, utils_js_1.assert)(isError ===
|
|
29
29
|
(pageContext.pageId ===
|
|
30
30
|
(0, error_page_js_1.getErrorPageId)(pageContext._globalContext._pageFilesAll, pageContext._globalContext._pageConfigs)));
|
|
31
|
-
(0, utils_js_1.
|
|
31
|
+
(0, utils_js_1.objectAssign)(pageContext, await (0, loadPageConfigsLazyServerSide_js_1.loadPageConfigsLazyServerSide)(pageContext));
|
|
32
32
|
if (!isError) {
|
|
33
|
-
await (0,
|
|
33
|
+
await (0, executeGuardHook_js_1.executeGuardHook)(pageContext, (pageContext) => (0, preparePageContextForPublicUsageServer_js_1.preparePageContextForPublicUsageServer)(pageContext));
|
|
34
34
|
}
|
|
35
35
|
if (!isError) {
|
|
36
|
-
await (0,
|
|
36
|
+
await (0, executeOnBeforeRenderAndDataHooks_js_1.executeOnBeforeRenderAndDataHooks)(pageContext);
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
39
|
try {
|
|
40
|
-
await (0,
|
|
40
|
+
await (0, executeOnBeforeRenderAndDataHooks_js_1.executeOnBeforeRenderAndDataHooks)(pageContext);
|
|
41
41
|
}
|
|
42
42
|
catch (err) {
|
|
43
43
|
if ((0, isNewError_js_1.isNewError)(err, pageContext.errorWhileRendering)) {
|
|
@@ -54,7 +54,7 @@ async function renderPageAlreadyRouted(pageContext) {
|
|
|
54
54
|
(0, utils_js_1.objectAssign)(pageContext, { httpResponse });
|
|
55
55
|
return pageContext;
|
|
56
56
|
}
|
|
57
|
-
const renderHookResult = await (0,
|
|
57
|
+
const renderHookResult = await (0, executeOnRenderHtmlHook_js_1.executeOnRenderHtmlHook)(pageContext);
|
|
58
58
|
const { htmlRender, renderHook } = renderHookResult;
|
|
59
59
|
const httpResponse = await (0, createHttpResponse_js_1.createHttpResponsePage)(htmlRender, renderHook, pageContext);
|
|
60
60
|
(0, utils_js_1.objectAssign)(pageContext, { httpResponse });
|
|
@@ -67,10 +67,10 @@ async function prerenderPage(pageContext) {
|
|
|
67
67
|
});
|
|
68
68
|
/* Should we execute the guard() hook upon pre-rendering? Is there a use case for this?
|
|
69
69
|
* - It isn't trivial to implement, as it requires to duplicate / factor out the isAbortError() handling
|
|
70
|
-
await
|
|
70
|
+
await executeGuardHook(pageContext, (pageContext) => preparePageContextForPublicUsageServer(pageContext))
|
|
71
71
|
*/
|
|
72
|
-
await (0,
|
|
73
|
-
const { htmlRender, renderHook } = await (0,
|
|
72
|
+
await (0, executeOnBeforeRenderAndDataHooks_js_1.executeOnBeforeRenderAndDataHooks)(pageContext);
|
|
73
|
+
const { htmlRender, renderHook } = await (0, executeOnRenderHtmlHook_js_1.executeOnRenderHtmlHook)(pageContext);
|
|
74
74
|
(0, utils_js_1.assertUsage)(htmlRender !== null, `Cannot pre-render ${picocolors_1.default.cyan(pageContext.urlOriginal)} because the ${renderHook.hookName}() hook defined by ${renderHook.hookFilePath} didn't return an HTML string.`);
|
|
75
75
|
(0, utils_js_1.assert)(pageContext.isClientSideNavigation === false);
|
|
76
76
|
const documentHtml = await (0, renderHtml_js_1.getHtmlString)(htmlRender);
|
|
@@ -143,66 +143,59 @@ async function renderPageAlreadyPrepared(pageContextBegin, globalContext, httpRe
|
|
|
143
143
|
else {
|
|
144
144
|
(0, utils_js_1.assert)(errNominalPage);
|
|
145
145
|
(0, utils_js_1.assert)(pageContextNominalPageSuccess === undefined);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
//
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
// - throw render(url)
|
|
163
|
-
// - throw render(abortStatusCode) if .pageContext.json request
|
|
164
|
-
return handled.pageContextReturn;
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
// - throw render(abortStatusCode) if not .pageContext.json request
|
|
146
|
+
(0, utils_js_1.assert)(pageContextNominalPageBegin);
|
|
147
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextNominalPageBegin, 'urlOriginal', 'string'));
|
|
148
|
+
const pageContextErrorPageInit = await getPageContextErrorPageInit(pageContextBegin, errNominalPage, pageContextNominalPageBegin);
|
|
149
|
+
// Handle `throw redirect()` and `throw render()` while rendering nominal page
|
|
150
|
+
if ((0, abort_js_1.isAbortError)(errNominalPage)) {
|
|
151
|
+
const handled = await handleAbortError(errNominalPage, pageContextsFromRewrite, pageContextBegin, pageContextNominalPageBegin, httpRequestId, pageContextErrorPageInit, globalContext);
|
|
152
|
+
if (handled.pageContextReturn) {
|
|
153
|
+
// - throw redirect()
|
|
154
|
+
// - throw render(url)
|
|
155
|
+
// - throw render(abortStatusCode) if .pageContext.json request
|
|
156
|
+
return handled.pageContextReturn;
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
// - throw render(abortStatusCode) if not .pageContext.json request
|
|
160
|
+
}
|
|
161
|
+
Object.assign(pageContextErrorPageInit, handled.pageContextAbort);
|
|
168
162
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
163
|
+
{
|
|
164
|
+
const errorPageId = (0, error_page_js_1.getErrorPageId)(globalContext._pageFilesAll, globalContext._pageConfigs);
|
|
165
|
+
if (!errorPageId) {
|
|
166
|
+
(0, utils_js_1.objectAssign)(pageContextErrorPageInit, { pageId: null });
|
|
167
|
+
return (0, handleErrorWithoutErrorPage_js_1.handleErrorWithoutErrorPage)(pageContextErrorPageInit);
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
(0, utils_js_1.objectAssign)(pageContextErrorPageInit, { pageId: errorPageId });
|
|
171
|
+
}
|
|
176
172
|
}
|
|
177
|
-
|
|
178
|
-
|
|
173
|
+
let pageContextErrorPage;
|
|
174
|
+
try {
|
|
175
|
+
pageContextErrorPage = await (0, renderPageAlreadyRouted_js_1.renderPageAlreadyRouted)(pageContextErrorPageInit);
|
|
179
176
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
const pageContextHttpWithError = getPageContextHttpResponseError(errNominalPage, pageContextBegin);
|
|
194
|
-
return pageContextHttpWithError;
|
|
177
|
+
catch (errErrorPage) {
|
|
178
|
+
// Handle `throw redirect()` and `throw render()` while rendering error page
|
|
179
|
+
if ((0, abort_js_1.isAbortError)(errErrorPage)) {
|
|
180
|
+
const handled = await handleAbortError(errErrorPage, pageContextsFromRewrite, pageContextBegin, pageContextNominalPageBegin, httpRequestId, pageContextErrorPageInit, globalContext);
|
|
181
|
+
// throw render(abortStatusCode)
|
|
182
|
+
if (!handled.pageContextReturn) {
|
|
183
|
+
const pageContextAbort = errErrorPage._pageContextAbort;
|
|
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 });
|
|
185
|
+
const pageContextHttpWithError = getPageContextHttpResponseError(errNominalPage, pageContextBegin);
|
|
186
|
+
return pageContextHttpWithError;
|
|
187
|
+
}
|
|
188
|
+
// `throw redirect()` / `throw render(url)`
|
|
189
|
+
return handled.pageContextReturn;
|
|
195
190
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
191
|
+
if ((0, isNewError_js_1.isNewError)(errErrorPage, errNominalPage)) {
|
|
192
|
+
(0, loggerRuntime_js_1.logRuntimeError)(errErrorPage, httpRequestId);
|
|
193
|
+
}
|
|
194
|
+
const pageContextWithError = getPageContextHttpResponseError(errNominalPage, pageContextBegin);
|
|
195
|
+
return pageContextWithError;
|
|
201
196
|
}
|
|
202
|
-
|
|
203
|
-
return pageContextWithError;
|
|
197
|
+
return pageContextErrorPage;
|
|
204
198
|
}
|
|
205
|
-
return pageContextErrorPage;
|
|
206
199
|
}
|
|
207
200
|
function logHttpRequest(urlOriginal, httpRequestId) {
|
|
208
201
|
(0, loggerRuntime_js_1.logRuntimeInfo)?.(getRequestInfoMessage(urlOriginal), httpRequestId, 'info');
|
|
@@ -424,7 +417,7 @@ pageContextNominalPageBegin, httpRequestId, pageContextErrorPageInit, globalCont
|
|
|
424
417
|
(0, utils_js_1.objectAssign)(pageContext, { pageId: errorPageId });
|
|
425
418
|
(0, utils_js_1.objectAssign)(pageContext, pageContextAbort);
|
|
426
419
|
(0, utils_js_1.objectAssign)(pageContext, pageContextErrorPageInit, true);
|
|
427
|
-
(0, utils_js_1.
|
|
420
|
+
(0, utils_js_1.objectAssign)(pageContext, await (0, loadPageConfigsLazyServerSide_js_1.loadPageConfigsLazyServerSide)(pageContext));
|
|
428
421
|
// We include pageContextInit: we don't only serialize pageContextAbort because the error page may need to access pageContextInit
|
|
429
422
|
pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext);
|
|
430
423
|
}
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPageContextShared = createPageContextShared;
|
|
4
4
|
exports.createPageContextObject = createPageContextObject;
|
|
5
|
+
const execHook_js_1 = require("./hooks/execHook.js");
|
|
6
|
+
const preparePageContextForPublicUsage_js_1 = require("./preparePageContextForPublicUsage.js");
|
|
5
7
|
const utils_js_1 = require("./utils.js");
|
|
6
|
-
// TODO/now: make this and parents sync
|
|
7
8
|
async function createPageContextShared(pageContextCreated, pageConfigGlobal, vikeConfigPublicGlobal) {
|
|
8
9
|
(0, utils_js_1.objectAssign)(pageContextCreated, vikeConfigPublicGlobal);
|
|
10
|
+
await (0, execHook_js_1.execHookGlobal)('onCreatePageContext', pageConfigGlobal, pageContextCreated, pageContextCreated, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage);
|
|
9
11
|
return pageContextCreated;
|
|
10
12
|
}
|
|
11
13
|
function createPageContextObject() {
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.execHook = execHook;
|
|
4
|
+
exports.execHookSingle = execHookSingle;
|
|
5
|
+
exports.execHookSingleWithReturn = execHookSingleWithReturn;
|
|
6
|
+
exports.execHookErrorHandling = execHookErrorHandling;
|
|
7
|
+
exports.execHooksErrorHandling = execHooksErrorHandling;
|
|
8
|
+
exports.execHookWithoutPageContext = execHookWithoutPageContext;
|
|
4
9
|
exports.execHookGlobal = execHookGlobal;
|
|
5
|
-
exports.
|
|
6
|
-
exports.execHookDirectSingle = execHookDirectSingle;
|
|
7
|
-
exports.execHookDirectSingleWithReturn = execHookDirectSingleWithReturn;
|
|
8
|
-
exports.execHookDirectWithoutPageContext = execHookDirectWithoutPageContext;
|
|
9
|
-
exports.execHookDirectSync = execHookDirectSync;
|
|
10
|
+
exports.execHookSync = execHookSync;
|
|
10
11
|
exports.getPageContext = getPageContext;
|
|
11
12
|
exports.providePageContext = providePageContext;
|
|
12
13
|
exports.isUserHookError = isUserHookError;
|
|
@@ -20,48 +21,70 @@ const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/execHook.t
|
|
|
20
21
|
userHookErrors: new WeakMap(),
|
|
21
22
|
pageContext: null,
|
|
22
23
|
});
|
|
24
|
+
async function execHookSingle(hook, pageContext, preparePageContextForPublicUsage) {
|
|
25
|
+
const res = await execHooksErrorHandling([hook], pageContext, preparePageContextForPublicUsage);
|
|
26
|
+
if ('err' in res)
|
|
27
|
+
throw res.err;
|
|
28
|
+
const { hookReturn } = res.hooks[0];
|
|
29
|
+
(0, assert_js_1.assertUsage)(hookReturn === undefined, `The ${hook.hookName}() hook defined by ${hook.hookFilePath} isn't allowed to return a value`);
|
|
30
|
+
}
|
|
31
|
+
async function execHookSingleWithReturn(hook, pageContext, preparePageContextForPublicUsage) {
|
|
32
|
+
const res = await execHooksErrorHandling([hook], pageContext, preparePageContextForPublicUsage);
|
|
33
|
+
if ('err' in res)
|
|
34
|
+
throw res.err;
|
|
35
|
+
const { hookReturn } = res.hooks[0];
|
|
36
|
+
return { hookReturn };
|
|
37
|
+
}
|
|
23
38
|
async function execHook(hookName, pageContext, preparePageContextForPublicUsage) {
|
|
39
|
+
const res = await execHookErrorHandling(hookName, pageContext, preparePageContextForPublicUsage);
|
|
40
|
+
if ('err' in res)
|
|
41
|
+
throw res.err;
|
|
42
|
+
return res.hooks;
|
|
43
|
+
}
|
|
44
|
+
async function execHookErrorHandling(hookName, pageContext, preparePageContextForPublicUsage) {
|
|
24
45
|
const hooks = (0, getHook_js_1.getHookFromPageContextNew)(hookName, pageContext);
|
|
25
|
-
return
|
|
46
|
+
return execHooksErrorHandling(hooks, pageContext, preparePageContextForPublicUsage);
|
|
47
|
+
}
|
|
48
|
+
async function execHooksErrorHandling(hooks, pageContext, preparePageContextForPublicUsage) {
|
|
49
|
+
if (!hooks.length)
|
|
50
|
+
return { hooks: [] };
|
|
51
|
+
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
52
|
+
let hooksWithResult;
|
|
53
|
+
let err;
|
|
54
|
+
try {
|
|
55
|
+
hooksWithResult = await Promise.all(hooks.map(async (hook) => {
|
|
56
|
+
const hookReturn = await execHookAsync(() => hook.hookFn(pageContextForPublicUsage), hook, pageContextForPublicUsage);
|
|
57
|
+
return { ...hook, hookReturn };
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
catch (err_) {
|
|
61
|
+
err = err_;
|
|
62
|
+
}
|
|
63
|
+
if (hooksWithResult) {
|
|
64
|
+
return { hooks: hooksWithResult };
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
return { hooks, err };
|
|
68
|
+
}
|
|
26
69
|
}
|
|
27
70
|
async function execHookGlobal(hookName, pageConfigGlobal, pageContext, hookArg, prepareForPublicUsage) {
|
|
28
71
|
const hooks = (0, getHook_js_1.getHookFromPageConfigGlobalCumulative)(pageConfigGlobal, hookName);
|
|
29
72
|
const hookArgForPublicUsage = prepareForPublicUsage(hookArg);
|
|
30
73
|
await Promise.all(hooks.map(async (hook) => {
|
|
31
|
-
await
|
|
74
|
+
await execHookAsync(() => hook.hookFn(hookArgForPublicUsage), hook, pageContext);
|
|
32
75
|
}));
|
|
33
76
|
}
|
|
34
|
-
async function execHookDirect(hooks, pageContext, preparePageContextForPublicUsage) {
|
|
35
|
-
if (!hooks.length)
|
|
36
|
-
return [];
|
|
37
|
-
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
38
|
-
const hooksWithResult = await Promise.all(hooks.map(async (hook) => {
|
|
39
|
-
const hookReturn = await execHookDirectAsync(() => hook.hookFn(pageContextForPublicUsage), hook, pageContextForPublicUsage);
|
|
40
|
-
return { ...hook, hookReturn };
|
|
41
|
-
}));
|
|
42
|
-
return hooksWithResult;
|
|
43
|
-
}
|
|
44
|
-
async function execHookDirectSingle(hook, pageContext, preparePageContextForPublicUsage) {
|
|
45
|
-
const hooksWithResult = await execHookDirect([hook], pageContext, preparePageContextForPublicUsage);
|
|
46
|
-
const { hookReturn } = hooksWithResult[0];
|
|
47
|
-
(0, assert_js_1.assertUsage)(hookReturn === undefined, `The ${hook.hookName}() hook defined by ${hook.hookFilePath} isn't allowed to return a value`);
|
|
48
|
-
}
|
|
49
|
-
async function execHookDirectSingleWithReturn(hook, pageContext, preparePageContextForPublicUsage) {
|
|
50
|
-
const hooksWithResult = await execHookDirect([hook], pageContext, preparePageContextForPublicUsage);
|
|
51
|
-
const { hookReturn } = hooksWithResult[0];
|
|
52
|
-
return { hookReturn };
|
|
53
|
-
}
|
|
54
77
|
function isUserHookError(err) {
|
|
55
78
|
if (!(0, isObject_js_1.isObject)(err))
|
|
56
79
|
return false;
|
|
57
80
|
return globalObject.userHookErrors.get(err) ?? false;
|
|
58
81
|
}
|
|
59
|
-
async function
|
|
82
|
+
async function execHookWithoutPageContext(hookFnCaller, hook) {
|
|
60
83
|
const { hookName, hookFilePath, hookTimeout } = hook;
|
|
61
|
-
const hookReturn = await
|
|
84
|
+
const hookReturn = await execHookAsync(hookFnCaller, { hookName, hookFilePath, hookTimeout }, null);
|
|
62
85
|
return hookReturn;
|
|
63
86
|
}
|
|
64
|
-
function
|
|
87
|
+
function execHookAsync(hookFnCaller, hook, pageContextForPublicUsage) {
|
|
65
88
|
const { hookName, hookFilePath, hookTimeout: { error: timeoutErr, warning: timeoutWarn }, } = hook;
|
|
66
89
|
let resolve;
|
|
67
90
|
let reject;
|
|
@@ -105,7 +128,7 @@ function execHookDirectAsync(hookFnCaller, hook, pageContextForPublicUsage) {
|
|
|
105
128
|
})();
|
|
106
129
|
return promise;
|
|
107
130
|
}
|
|
108
|
-
function
|
|
131
|
+
function execHookSync(hook, pageContext, preparePageContextForPublicUsage) {
|
|
109
132
|
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
110
133
|
providePageContextInternal(pageContextForPublicUsage);
|
|
111
134
|
const hookReturn = hook.hookFn(pageContextForPublicUsage);
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.executeGuardHook = executeGuardHook;
|
|
4
4
|
const getHook_js_1 = require("../hooks/getHook.js");
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
6
|
const execHook_js_1 = require("../hooks/execHook.js");
|
|
7
7
|
const errIntro = 'The guard() hook defined by';
|
|
8
|
-
async function
|
|
8
|
+
async function executeGuardHook(pageContext, prepareForPublicUsage) {
|
|
9
9
|
let hook;
|
|
10
10
|
if (pageContext._globalContext._pageFilesAll.length > 0) {
|
|
11
11
|
// TODO/v1-release: remove
|
|
@@ -19,7 +19,7 @@ async function execHookGuard(pageContext, prepareForPublicUsage) {
|
|
|
19
19
|
}
|
|
20
20
|
if (!hook)
|
|
21
21
|
return;
|
|
22
|
-
await (0, execHook_js_1.
|
|
22
|
+
await (0, execHook_js_1.execHookSingle)(hook, pageContext, prepareForPublicUsage);
|
|
23
23
|
}
|
|
24
24
|
function findPageGuard(pageId, pageFilesAll) {
|
|
25
25
|
const pageRouteFile = pageFilesAll.find((p) => p.pageId === pageId && p.fileType === '.page.route');
|
|
@@ -3,14 +3,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.executeOnBeforeRouteHook = executeOnBeforeRouteHook;
|
|
7
7
|
const assertPageContextProvidedByUser_js_1 = require("../assertPageContextProvidedByUser.js");
|
|
8
8
|
const utils_js_1 = require("./utils.js");
|
|
9
9
|
const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
|
|
10
10
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
11
|
const execHook_js_1 = require("../hooks/execHook.js");
|
|
12
12
|
const preparePageContextForPublicUsage_js_1 = require("../preparePageContextForPublicUsage.js");
|
|
13
|
-
async function
|
|
13
|
+
async function executeOnBeforeRouteHook(pageContext) {
|
|
14
14
|
const pageContextFromOnBeforeRouteHook = {};
|
|
15
15
|
if (!pageContext._globalContext._onBeforeRouteHook)
|
|
16
16
|
return null;
|
|
@@ -39,9 +39,9 @@ async function execHookOnBeforeRoute(pageContext) {
|
|
|
39
39
|
return pageContextFromOnBeforeRouteHook;
|
|
40
40
|
}
|
|
41
41
|
async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
|
|
42
|
-
let { hookReturn } = (0, execHook_js_1.
|
|
42
|
+
let { hookReturn } = (0, execHook_js_1.execHookSync)(onBeforeRouteHook, pageContext, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage);
|
|
43
43
|
(0, resolveRouteFunction_js_1.assertSyncRouting)(hookReturn, `The onBeforeRoute() hook ${onBeforeRouteHook.hookFilePath}`);
|
|
44
|
-
// TODO/v1-release: make
|
|
44
|
+
// TODO/v1-release: make executeOnBeforeRouteHook() and route() sync
|
|
45
45
|
hookReturn = await hookReturn;
|
|
46
46
|
const errPrefix = `The onBeforeRoute() hook defined by ${onBeforeRouteHook.hookFilePath}`;
|
|
47
47
|
(0, utils_js_1.assertUsage)(hookReturn === null ||
|
|
@@ -14,16 +14,15 @@ const utils_js_1 = require("./utils.js");
|
|
|
14
14
|
const resolvePrecedence_js_1 = require("./resolvePrecedence.js");
|
|
15
15
|
const resolveRouteString_js_1 = require("./resolveRouteString.js");
|
|
16
16
|
const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
|
|
17
|
-
const
|
|
17
|
+
const executeOnBeforeRouteHook_js_1 = require("./executeOnBeforeRouteHook.js");
|
|
18
18
|
const debug_js_1 = require("./debug.js");
|
|
19
19
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
20
|
-
// TODO/next-major-release: make it sync
|
|
21
20
|
async function route(pageContext, skipOnBeforeRouteHook) {
|
|
22
21
|
(0, debug_js_1.debug)('Pages routes:', pageContext._globalContext._pageRoutes);
|
|
23
22
|
const pageContextFromRoute = {};
|
|
24
23
|
// onBeforeRoute()
|
|
25
24
|
if (!skipOnBeforeRouteHook) {
|
|
26
|
-
const pageContextFromOnBeforeRouteHook = await (0,
|
|
25
|
+
const pageContextFromOnBeforeRouteHook = await (0, executeOnBeforeRouteHook_js_1.executeOnBeforeRouteHook)(pageContext);
|
|
27
26
|
if (pageContextFromOnBeforeRouteHook) {
|
|
28
27
|
if (pageContextFromOnBeforeRouteHook._routingProvidedByOnBeforeRouteHook) {
|
|
29
28
|
(0, utils_js_1.assert)(pageContextFromOnBeforeRouteHook.pageId);
|
|
@@ -12,7 +12,7 @@ const preparePageContextForPublicUsage_js_1 = require("../preparePageContextForP
|
|
|
12
12
|
const utils_js_1 = require("./utils.js");
|
|
13
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
14
|
async function resolveRouteFunction(routeFunction, pageContext, routeFunctionFilePath) {
|
|
15
|
-
let { hookReturn: result } = (0, execHook_js_1.
|
|
15
|
+
let { hookReturn: result } = (0, execHook_js_1.execHookSync)({
|
|
16
16
|
hookFn: routeFunction,
|
|
17
17
|
hookFilePath: routeFunctionFilePath,
|
|
18
18
|
hookName: 'route',
|
|
@@ -2,5 +2,4 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.styleFileRE = void 0;
|
|
4
4
|
// Copied from https://github.com/vitejs/vite/blob/d649daba7682791178b711d9a3e44a6b5d00990c/packages/vite/src/node/plugins/css.ts#L90-L91
|
|
5
|
-
// spellcheck-ignore
|
|
6
5
|
exports.styleFileRE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss)($|\?)/;
|
|
@@ -421,8 +421,8 @@ declare function getPageContextFromClientHooks(pageContext: {
|
|
|
421
421
|
} & {
|
|
422
422
|
urlOriginal: string;
|
|
423
423
|
}>;
|
|
424
|
-
type
|
|
425
|
-
declare function execHookClient(hookName: HookName, pageContext:
|
|
424
|
+
type PageContextExecuteHookClient = VikeConfigPublicPageLazy & PageContextForPublicUsageClient;
|
|
425
|
+
declare function execHookClient(hookName: HookName, pageContext: PageContextExecuteHookClient): Promise<(import("../../shared/hooks/getHook.js").HookLoc & {
|
|
426
426
|
hookFn: (arg: import("../../shared/preparePageContextForPublicUsage.js").PageContextPrepareMinimum | import("../../shared/prepareGlobalContextForPublicUsage.js").GlobalContextPrepareMinimum) => unknown;
|
|
427
427
|
hookTimeout: import("../../shared/hooks/getHook.js").HookTimeout;
|
|
428
428
|
} & {
|