vike 0.4.229-commit-7056ef0 → 0.4.229-commit-e27d672
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/client/server-routing-runtime/utils.js +1 -0
- package/dist/cjs/client/shared/{preparePageContextForUserConsumptionClientSide.js → preparePageContextForPublicUsageClientShared.js} +14 -19
- package/dist/cjs/node/api/build.js +1 -5
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +2 -2
- package/dist/cjs/node/prerender/runPrerender.js +40 -36
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +13 -27
- package/dist/cjs/node/runtime/html/serializeContext.js +1 -1
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +4 -8
- package/dist/cjs/node/runtime/renderPage/execHookServer.js +11 -0
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +9 -9
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -12
- package/dist/cjs/node/runtime/renderPage/preparePageContextForPublicUsageServer.js +10 -0
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -3
- package/dist/cjs/node/runtime/renderPage.js +4 -4
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/shared/NOT_SERIALIZABLE.js +0 -1
- package/dist/cjs/shared/addIs404ToPageProps.js +0 -7
- package/dist/cjs/shared/createGlobalContextShared.js +6 -3
- package/dist/cjs/shared/createPageContextShared.js +12 -3
- package/dist/cjs/shared/getPageContext.js +3 -3
- package/dist/cjs/shared/getPageContextUrlComputed.js +2 -36
- package/dist/cjs/shared/getProxyForPublicUsage.js +55 -0
- package/dist/cjs/shared/hooks/execHook.js +164 -0
- package/dist/cjs/shared/page-configs/getUserFriendlyConfigs.js +17 -15
- package/dist/cjs/shared/prepareGlobalContextForPublicUsage.js +10 -0
- package/dist/cjs/shared/preparePageContextForPublicUsage.js +75 -0
- package/dist/cjs/shared/route/abort.js +2 -2
- package/dist/cjs/shared/route/executeGuardHook.js +4 -9
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +4 -3
- package/dist/cjs/shared/route/index.js +2 -4
- package/dist/cjs/shared/route/loadPageRoutes.js +6 -0
- package/dist/cjs/shared/route/resolveRouteFunction.js +14 -10
- package/dist/cjs/shared/utils.js +1 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/objectAssign.js +3 -3
- package/dist/cjs/utils/objectDefineProperty.js +1 -1
- package/dist/esm/client/client-routing-runtime/createPageContextClientSide.d.ts +10 -7
- package/dist/esm/client/client-routing-runtime/createPageContextClientSide.js +8 -10
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +397 -20
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +15 -15
- package/dist/esm/client/client-routing-runtime/globalContext.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/prefetch.d.ts +3 -8
- package/dist/esm/client/client-routing-runtime/preparePageContextForPublicUsageClient.d.ts +11 -0
- package/dist/esm/client/client-routing-runtime/preparePageContextForPublicUsageClient.js +5 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +135 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +66 -72
- package/dist/esm/client/client-routing-runtime/utils.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/utils.js +1 -0
- package/dist/esm/client/server-routing-runtime/createPageContextClientSide.d.ts +8 -6
- package/dist/esm/client/server-routing-runtime/createPageContextClientSide.js +8 -10
- package/dist/esm/client/server-routing-runtime/entry.js +4 -6
- package/dist/esm/client/server-routing-runtime/globalContext.d.ts +1 -0
- package/dist/esm/client/server-routing-runtime/preparePageContextForPublicUsageClient.d.ts +9 -0
- package/dist/esm/client/server-routing-runtime/preparePageContextForPublicUsageClient.js +5 -0
- package/dist/esm/client/server-routing-runtime/utils.d.ts +1 -0
- package/dist/esm/client/server-routing-runtime/utils.js +1 -0
- package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +1 -0
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +3 -3
- package/dist/esm/client/shared/executeOnRenderClientHook.js +4 -13
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +13 -0
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.js +39 -0
- package/dist/esm/node/api/build.js +1 -2
- package/dist/esm/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +15 -115
- package/dist/esm/node/prerender/runPrerender.js +40 -36
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/globalContext.d.ts +5 -373
- package/dist/esm/node/runtime/globalContext.js +14 -28
- package/dist/esm/node/runtime/html/serializeContext.d.ts +1 -1
- package/dist/esm/node/runtime/html/serializeContext.js +1 -1
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +15 -62
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +5 -9
- package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +12 -0
- package/dist/esm/node/runtime/renderPage/execHookServer.js +9 -0
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +9 -9
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +4 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -12
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +20 -0
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.js +8 -0
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +15 -115
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -3
- package/dist/esm/node/runtime/renderPage.d.ts +10 -60
- package/dist/esm/node/runtime/renderPage.js +4 -4
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/shared/NOT_SERIALIZABLE.js +0 -1
- package/dist/esm/shared/addIs404ToPageProps.d.ts +1 -6
- package/dist/esm/shared/addIs404ToPageProps.js +1 -8
- package/dist/esm/shared/createGlobalContextShared.d.ts +2 -0
- package/dist/esm/shared/createGlobalContextShared.js +7 -4
- package/dist/esm/shared/createPageContextShared.d.ts +6 -2
- package/dist/esm/shared/createPageContextShared.js +13 -4
- package/dist/esm/shared/getPageContext.d.ts +1 -1
- package/dist/esm/shared/getPageContext.js +1 -1
- package/dist/esm/shared/getPageContextUrlComputed.d.ts +2 -5
- package/dist/esm/shared/getPageContextUrlComputed.js +3 -37
- package/dist/esm/shared/getProxyForPublicUsage.d.ts +4 -0
- package/dist/esm/shared/getProxyForPublicUsage.js +53 -0
- package/dist/esm/shared/hooks/execHook.d.ts +63 -0
- package/dist/esm/shared/hooks/execHook.js +162 -0
- package/dist/esm/shared/hooks/getHook.d.ts +3 -1
- package/dist/esm/shared/page-configs/Config.d.ts +3 -3
- package/dist/esm/shared/page-configs/getUserFriendlyConfigs.js +18 -16
- package/dist/esm/shared/prepareGlobalContextForPublicUsage.d.ts +7 -0
- package/dist/esm/shared/prepareGlobalContextForPublicUsage.js +8 -0
- package/dist/esm/shared/preparePageContextForPublicUsage.d.ts +13 -0
- package/dist/esm/shared/preparePageContextForPublicUsage.js +73 -0
- package/dist/esm/shared/route/abort.js +1 -1
- package/dist/esm/shared/route/executeGuardHook.d.ts +4 -3
- package/dist/esm/shared/route/executeGuardHook.js +4 -9
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +4 -3
- package/dist/esm/shared/route/index.js +2 -4
- package/dist/esm/shared/route/loadPageRoutes.d.ts +2 -1
- package/dist/esm/shared/route/loadPageRoutes.js +7 -1
- package/dist/esm/shared/route/resolveRouteFunction.d.ts +2 -2
- package/dist/esm/shared/route/resolveRouteFunction.js +14 -10
- package/dist/esm/shared/types.d.ts +13 -3
- package/dist/esm/shared/utils.d.ts +1 -0
- package/dist/esm/shared/utils.js +1 -0
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/objectAssign.d.ts +1 -1
- package/dist/esm/utils/objectAssign.js +3 -3
- package/dist/esm/utils/objectDefineProperty.d.ts +0 -1
- package/dist/esm/utils/objectDefineProperty.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/client/shared/getPageContextProxyForUser.js +0 -16
- package/dist/cjs/node/runtime/renderPage/executeHookServer.js +0 -11
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +0 -16
- package/dist/cjs/shared/hooks/executeHook.js +0 -108
- package/dist/cjs/shared/preparePageContextForUserConsumption.js +0 -34
- package/dist/cjs/utils/getPublicProxy.js +0 -27
- package/dist/esm/client/shared/getPageContextProxyForUser.d.ts +0 -2
- package/dist/esm/client/shared/getPageContextProxyForUser.js +0 -14
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +0 -12
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.js +0 -44
- package/dist/esm/node/runtime/renderPage/executeHookServer.d.ts +0 -13
- package/dist/esm/node/runtime/renderPage/executeHookServer.js +0 -9
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +0 -24
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +0 -14
- package/dist/esm/shared/hooks/executeHook.d.ts +0 -34
- package/dist/esm/shared/hooks/executeHook.js +0 -106
- package/dist/esm/shared/preparePageContextForUserConsumption.d.ts +0 -5
- package/dist/esm/shared/preparePageContextForUserConsumption.js +0 -32
- package/dist/esm/utils/getPublicProxy.d.ts +0 -2
- package/dist/esm/utils/getPublicProxy.js +0 -25
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
export { execHook };
|
|
2
|
+
export { execHookSingle };
|
|
3
|
+
export { execHookSingleWithReturn };
|
|
4
|
+
export { execHookErrorHandling };
|
|
5
|
+
export { execHooksErrorHandling };
|
|
6
|
+
export { execHookWithoutPageContext };
|
|
7
|
+
export { execHookGlobal };
|
|
8
|
+
export { execHookSync };
|
|
9
|
+
export { getPageContext };
|
|
10
|
+
export { providePageContext };
|
|
11
|
+
export { isUserHookError };
|
|
12
|
+
import { getProjectError, assertWarning, assertUsage } from '../../utils/assert.js';
|
|
13
|
+
import { getGlobalObject } from '../../utils/getGlobalObject.js';
|
|
14
|
+
import { humanizeTime } from '../../utils/humanizeTime.js';
|
|
15
|
+
import { isObject } from '../../utils/isObject.js';
|
|
16
|
+
import { getHookFromPageConfigGlobalCumulative, getHookFromPageContextNew } from './getHook.js';
|
|
17
|
+
import { preparePageContextForPublicUsage } from '../preparePageContextForPublicUsage.js';
|
|
18
|
+
const globalObject = getGlobalObject('utils/execHook.ts', {
|
|
19
|
+
userHookErrors: new WeakMap(),
|
|
20
|
+
pageContext: null
|
|
21
|
+
});
|
|
22
|
+
async function execHookSingle(hook, pageContext, preparePageContextForPublicUsage) {
|
|
23
|
+
const res = await execHooksErrorHandling([hook], pageContext, preparePageContextForPublicUsage);
|
|
24
|
+
if ('err' in res)
|
|
25
|
+
throw res.err;
|
|
26
|
+
const { hookReturn } = res.hooks[0];
|
|
27
|
+
assertUsage(hookReturn === undefined, `The ${hook.hookName}() hook defined by ${hook.hookFilePath} isn't allowed to return a value`);
|
|
28
|
+
}
|
|
29
|
+
async function execHookSingleWithReturn(hook, pageContext, preparePageContextForPublicUsage) {
|
|
30
|
+
const res = await execHooksErrorHandling([hook], pageContext, preparePageContextForPublicUsage);
|
|
31
|
+
if ('err' in res)
|
|
32
|
+
throw res.err;
|
|
33
|
+
const { hookReturn } = res.hooks[0];
|
|
34
|
+
return { hookReturn };
|
|
35
|
+
}
|
|
36
|
+
async function execHook(hookName, pageContext, preparePageContextForPublicUsage) {
|
|
37
|
+
const res = await execHookErrorHandling(hookName, pageContext, preparePageContextForPublicUsage);
|
|
38
|
+
if ('err' in res)
|
|
39
|
+
throw res.err;
|
|
40
|
+
return res.hooks;
|
|
41
|
+
}
|
|
42
|
+
async function execHookErrorHandling(hookName, pageContext, preparePageContextForPublicUsage) {
|
|
43
|
+
const hooks = getHookFromPageContextNew(hookName, pageContext);
|
|
44
|
+
return execHooksErrorHandling(hooks, pageContext, preparePageContextForPublicUsage);
|
|
45
|
+
}
|
|
46
|
+
async function execHooksErrorHandling(hooks, pageContext, preparePageContextForPublicUsage) {
|
|
47
|
+
if (!hooks.length)
|
|
48
|
+
return { hooks: [] };
|
|
49
|
+
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
50
|
+
let hooksWithResult;
|
|
51
|
+
let err;
|
|
52
|
+
try {
|
|
53
|
+
hooksWithResult = await Promise.all(hooks.map(async (hook) => {
|
|
54
|
+
const hookReturn = await execHookAsync(() => hook.hookFn(pageContextForPublicUsage), hook, pageContextForPublicUsage);
|
|
55
|
+
return { ...hook, hookReturn };
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
catch (err_) {
|
|
59
|
+
err = err_;
|
|
60
|
+
}
|
|
61
|
+
if (hooksWithResult) {
|
|
62
|
+
return { hooks: hooksWithResult };
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
return { hooks, err };
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async function execHookGlobal(hookName, pageConfigGlobal, pageContext, hookArg, prepareForPublicUsage) {
|
|
69
|
+
const hooks = getHookFromPageConfigGlobalCumulative(pageConfigGlobal, hookName);
|
|
70
|
+
const hookArgForPublicUsage = prepareForPublicUsage(hookArg);
|
|
71
|
+
await Promise.all(hooks.map(async (hook) => {
|
|
72
|
+
await execHookAsync(() => hook.hookFn(hookArgForPublicUsage), hook, pageContext);
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
function isUserHookError(err) {
|
|
76
|
+
if (!isObject(err))
|
|
77
|
+
return false;
|
|
78
|
+
return globalObject.userHookErrors.get(err) ?? false;
|
|
79
|
+
}
|
|
80
|
+
async function execHookWithoutPageContext(hookFnCaller, hook) {
|
|
81
|
+
const { hookName, hookFilePath, hookTimeout } = hook;
|
|
82
|
+
const hookReturn = await execHookAsync(hookFnCaller, { hookName, hookFilePath, hookTimeout }, null);
|
|
83
|
+
return hookReturn;
|
|
84
|
+
}
|
|
85
|
+
function execHookAsync(hookFnCaller, hook, pageContextForPublicUsage) {
|
|
86
|
+
const { hookName, hookFilePath, hookTimeout: { error: timeoutErr, warning: timeoutWarn } } = hook;
|
|
87
|
+
let resolve;
|
|
88
|
+
let reject;
|
|
89
|
+
const promise = new Promise((resolve_, reject_) => {
|
|
90
|
+
resolve = (ret) => {
|
|
91
|
+
clearTimeouts();
|
|
92
|
+
resolve_(ret);
|
|
93
|
+
};
|
|
94
|
+
reject = (err) => {
|
|
95
|
+
clearTimeouts();
|
|
96
|
+
reject_(err);
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
const clearTimeouts = () => {
|
|
100
|
+
if (currentTimeoutWarn)
|
|
101
|
+
clearTimeout(currentTimeoutWarn);
|
|
102
|
+
if (currentTimeoutErr)
|
|
103
|
+
clearTimeout(currentTimeoutErr);
|
|
104
|
+
};
|
|
105
|
+
const currentTimeoutWarn = isNotDisabled(timeoutWarn) &&
|
|
106
|
+
setTimeout(() => {
|
|
107
|
+
assertWarning(false, `The ${hookName}() hook defined by ${hookFilePath} is slow: it's taking more than ${humanizeTime(timeoutWarn)} (https://vike.dev/hooksTimeout)`, { onlyOnce: false });
|
|
108
|
+
}, timeoutWarn);
|
|
109
|
+
const currentTimeoutErr = isNotDisabled(timeoutErr) &&
|
|
110
|
+
setTimeout(() => {
|
|
111
|
+
const err = getProjectError(`The ${hookName}() hook defined by ${hookFilePath} timed out: it didn't finish after ${humanizeTime(timeoutErr)} (https://vike.dev/hooksTimeout)`);
|
|
112
|
+
reject(err);
|
|
113
|
+
}, timeoutErr);
|
|
114
|
+
(async () => {
|
|
115
|
+
try {
|
|
116
|
+
providePageContext(pageContextForPublicUsage);
|
|
117
|
+
const ret = await hookFnCaller();
|
|
118
|
+
resolve(ret);
|
|
119
|
+
}
|
|
120
|
+
catch (err) {
|
|
121
|
+
if (isObject(err)) {
|
|
122
|
+
globalObject.userHookErrors.set(err, { hookName, hookFilePath });
|
|
123
|
+
}
|
|
124
|
+
reject(err);
|
|
125
|
+
}
|
|
126
|
+
})();
|
|
127
|
+
return promise;
|
|
128
|
+
}
|
|
129
|
+
function execHookSync(hook, pageContext, preparePageContextForPublicUsage) {
|
|
130
|
+
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
131
|
+
providePageContext(pageContextForPublicUsage);
|
|
132
|
+
const hookReturn = hook.hookFn(pageContextForPublicUsage);
|
|
133
|
+
return { hookReturn };
|
|
134
|
+
}
|
|
135
|
+
function isNotDisabled(timeout) {
|
|
136
|
+
return !!timeout && timeout !== Infinity;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Access `pageContext` object inside Vike hooks, in order to create universal hooks.
|
|
140
|
+
*
|
|
141
|
+
* https://vike.dev/getPageContext
|
|
142
|
+
*/
|
|
143
|
+
function getPageContext() {
|
|
144
|
+
const { pageContext } = globalObject;
|
|
145
|
+
if (!pageContext)
|
|
146
|
+
return pageContext;
|
|
147
|
+
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
148
|
+
return pageContextForPublicUsage;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Provide `pageContext` for universal hooks.
|
|
152
|
+
*
|
|
153
|
+
* https://vike.dev/getPageContext
|
|
154
|
+
*/
|
|
155
|
+
function providePageContext(pageContext) {
|
|
156
|
+
globalObject.pageContext = pageContext;
|
|
157
|
+
// Promise.resolve() is quicker than process.nextTick() and setImmediate()
|
|
158
|
+
// https://stackoverflow.com/questions/67949576/process-nexttick-before-promise-resolve-then
|
|
159
|
+
Promise.resolve().then(() => {
|
|
160
|
+
globalObject.pageContext = null;
|
|
161
|
+
});
|
|
162
|
+
}
|
|
@@ -12,6 +12,8 @@ export { getHookTimeoutDefault };
|
|
|
12
12
|
import type { PageConfigUserFriendlyOld } from '../getPageFiles.js';
|
|
13
13
|
import type { HookNameOld, HookNamePage, HookNameGlobal, HookName } from '../page-configs/Config.js';
|
|
14
14
|
import type { PageConfigGlobalRuntime, PageConfigRuntime } from '../page-configs/PageConfig.js';
|
|
15
|
+
import type { GlobalContextPrepareMinimum } from '../prepareGlobalContextForPublicUsage.js';
|
|
16
|
+
import type { PageContextPrepareMinimum } from '../preparePageContextForPublicUsage.js';
|
|
15
17
|
type Hook = HookLoc & {
|
|
16
18
|
hookFn: HookFn;
|
|
17
19
|
hookTimeout: HookTimeout;
|
|
@@ -20,7 +22,7 @@ type HookLoc = {
|
|
|
20
22
|
hookName: HookNameOld;
|
|
21
23
|
hookFilePath: string;
|
|
22
24
|
};
|
|
23
|
-
type HookFn = (arg:
|
|
25
|
+
type HookFn = (arg: PageContextPrepareMinimum | GlobalContextPrepareMinimum) => unknown;
|
|
24
26
|
type HookTimeout = {
|
|
25
27
|
error: number | false;
|
|
26
28
|
warning: number | false;
|
|
@@ -46,8 +46,8 @@ import type { GlobalContext, PageContextClient, PageContextServer } from '../typ
|
|
|
46
46
|
import type { InlineConfig } from 'vite';
|
|
47
47
|
type HookNameOld = HookName | HookNameOldDesign;
|
|
48
48
|
type HookName = HookNamePage | HookNameGlobal;
|
|
49
|
-
type HookNamePage = 'onHydrationEnd' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onRenderHtml' | 'onRenderClient' | 'guard' | 'data' | 'onData';
|
|
50
|
-
type HookNameGlobal = '
|
|
49
|
+
type HookNamePage = 'onHydrationEnd' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onRenderHtml' | 'onRenderClient' | 'guard' | 'data' | 'onData' | 'route';
|
|
50
|
+
type HookNameGlobal = 'onBeforeRoute' | 'onPrerenderStart' | 'onCreatePageContext' | 'onCreateGlobalContext';
|
|
51
51
|
type HookNameOldDesign = 'render' | 'prerender' | 'onBeforePrerender';
|
|
52
52
|
type ConfigNameBuiltIn = Exclude<keyof Config, keyof VikeVitePluginOptions | 'onBeforeRoute' | 'onPrerenderStart' | 'vite' | 'redirects'> | 'prerender' | 'isClientRuntimeLoaded' | 'onBeforeRenderEnv' | 'dataEnv' | 'hooksTimeout' | 'clientHooks' | 'middleware';
|
|
53
53
|
type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | 'disableAutoFullBuild' | 'includeAssetsImportedByServer' | 'baseAssets' | 'baseServer' | 'redirects' | 'trailingSlash' | 'disableUrlNormalization' | 'vite';
|
|
@@ -347,7 +347,7 @@ type ConfigBuiltIn = {
|
|
|
347
347
|
* https://vike.dev/data
|
|
348
348
|
*/
|
|
349
349
|
data?: DataAsync<unknown> | DataSync<unknown> | ImportString | null;
|
|
350
|
-
/**
|
|
350
|
+
/** Hook called as soon as `pageContext.data` is available.
|
|
351
351
|
*
|
|
352
352
|
* https://vike.dev/onData
|
|
353
353
|
*/
|
|
@@ -4,7 +4,7 @@ export { getUserFriendlyConfigsPageLazy };
|
|
|
4
4
|
import { assertDefaultExports, forbiddenDefaultExports } from '../getPageFiles/assert_exports_old_design.js';
|
|
5
5
|
import { getConfigDefinedAtOptional, getDefinedAtString } from './getConfigDefinedAt.js';
|
|
6
6
|
import { getConfigValueFilePathToShowToUser } from './helpers.js';
|
|
7
|
-
import { assert, isObject, assertWarning, assertUsage, makeLast, isBrowser, isScriptFile, isTemplateFile } from '../utils.js';
|
|
7
|
+
import { assert, isObject, assertWarning, assertUsage, makeLast, isBrowser, isScriptFile, isTemplateFile, objectDefineProperty } from '../utils.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
function getUserFriendlyConfigsPageEager(pageConfigGlobalValues, pageConfig, pageConfigValues) {
|
|
10
10
|
const pageConfigUserFriendly = getUserFriendlyConfigs_public({ pageConfigGlobalValues, pageConfigValues });
|
|
@@ -92,7 +92,7 @@ pageConfigGlobal) {
|
|
|
92
92
|
configsComputed: {}
|
|
93
93
|
};
|
|
94
94
|
}
|
|
95
|
-
const pageExports =
|
|
95
|
+
const pageExports = {};
|
|
96
96
|
const exports = {};
|
|
97
97
|
Object.entries(exportsAll).forEach(([exportName, values]) => {
|
|
98
98
|
values.forEach(({ exportValue, _fileType, _isFromDefaultExport }) => {
|
|
@@ -115,9 +115,23 @@ pageConfigGlobal) {
|
|
|
115
115
|
// TODO/eventually: deprecate/remove every prop below
|
|
116
116
|
configEntries,
|
|
117
117
|
exports,
|
|
118
|
-
exportsAll
|
|
119
|
-
pageExports
|
|
118
|
+
exportsAll
|
|
120
119
|
};
|
|
120
|
+
// TODO/v1-release: remove
|
|
121
|
+
objectDefineProperty(pageContextExports, 'pageExports', {
|
|
122
|
+
get: () => {
|
|
123
|
+
// We only show the warning in Node.js because when using Client Routing Vue integration uses `Object.assign(pageContextReactive, pageContext)` which will wrongully trigger the warning. There is no cross-browser way to catch whether the property accessor was initiated by an `Object.assign()` call.
|
|
124
|
+
if (!isBrowser()) {
|
|
125
|
+
assertWarning(false, 'pageContext.pageExports is outdated, use pageContext.exports instead', {
|
|
126
|
+
onlyOnce: true,
|
|
127
|
+
showStackTrace: true
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return pageExports;
|
|
131
|
+
},
|
|
132
|
+
enumerable: false,
|
|
133
|
+
configurable: true
|
|
134
|
+
});
|
|
121
135
|
return pageContextExports;
|
|
122
136
|
}
|
|
123
137
|
// V1 design
|
|
@@ -244,15 +258,3 @@ function getExportValues(pageFile) {
|
|
|
244
258
|
});
|
|
245
259
|
return exportValues;
|
|
246
260
|
}
|
|
247
|
-
// TODO/v1-release: remove
|
|
248
|
-
function createObjectWithDeprecationWarning() {
|
|
249
|
-
return new Proxy({}, {
|
|
250
|
-
get(...args) {
|
|
251
|
-
// We only show the warning in Node.js because when using Client Routing Vue integration uses `Object.assign(pageContextReactive, pageContext)` which will wrongully trigger the warning. There is no cross-browser way to catch whether the property accessor was initiated by an `Object.assign()` call.
|
|
252
|
-
if (!isBrowser()) {
|
|
253
|
-
assertWarning(false, '`pageContext.pageExports` is outdated. Use `pageContext.exports` instead, see https://vike.dev/exports', { onlyOnce: true, showStackTrace: true });
|
|
254
|
-
}
|
|
255
|
-
return Reflect.get(...args);
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { prepareGlobalContextForPublicUsage };
|
|
2
|
+
export type { GlobalContextPrepareMinimum };
|
|
3
|
+
type GlobalContextPrepareMinimum = {
|
|
4
|
+
_isOriginalObject: true;
|
|
5
|
+
isGlobalContext: true;
|
|
6
|
+
};
|
|
7
|
+
declare function prepareGlobalContextForPublicUsage<GlobalContext extends GlobalContextPrepareMinimum>(globalContext: GlobalContext): GlobalContext;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { prepareGlobalContextForPublicUsage };
|
|
2
|
+
import { getProxyForPublicUsage } from './getProxyForPublicUsage.js';
|
|
3
|
+
import { assert } from './utils.js';
|
|
4
|
+
function prepareGlobalContextForPublicUsage(globalContext) {
|
|
5
|
+
assert(globalContext._isOriginalObject); // ensure we preserve the original object reference
|
|
6
|
+
const globalContextPublic = getProxyForPublicUsage(globalContext, 'globalContext');
|
|
7
|
+
return globalContextPublic;
|
|
8
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { preparePageContextForPublicUsage };
|
|
2
|
+
export { assertPropertyGetters };
|
|
3
|
+
export type { PageContextPrepareMinimum };
|
|
4
|
+
import { type GlobalContextPrepareMinimum } from './prepareGlobalContextForPublicUsage.js';
|
|
5
|
+
type PageContextPrepareMinimum = {
|
|
6
|
+
_isOriginalObject: true;
|
|
7
|
+
isPageContext: true;
|
|
8
|
+
_globalContext: GlobalContextPrepareMinimum;
|
|
9
|
+
};
|
|
10
|
+
declare function preparePageContextForPublicUsage<PageContext extends PageContextPrepareMinimum>(pageContext: PageContext): PageContext & {
|
|
11
|
+
globalContext: GlobalContextPrepareMinimum;
|
|
12
|
+
};
|
|
13
|
+
declare function assertPropertyGetters(pageContext: Record<string, unknown>): void;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export { preparePageContextForPublicUsage };
|
|
2
|
+
export { assertPropertyGetters };
|
|
3
|
+
import { assert, assertWarning, compareString, isPropertyGetter, objectAssign } from './utils.js';
|
|
4
|
+
import { addIs404ToPageProps } from './addIs404ToPageProps.js';
|
|
5
|
+
import { prepareGlobalContextForPublicUsage } from './prepareGlobalContextForPublicUsage.js';
|
|
6
|
+
import { getProxyForPublicUsage } from './getProxyForPublicUsage.js';
|
|
7
|
+
function preparePageContextForPublicUsage(pageContext) {
|
|
8
|
+
assert(!pageContext.globalContext); // pageContext.globalContext should only be available to users — Vike itself should use pageContext._globalContext instead
|
|
9
|
+
assert(pageContext._isOriginalObject); // ensure we preserve the original object reference
|
|
10
|
+
const globalContextPublic = prepareGlobalContextForPublicUsage(pageContext._globalContext);
|
|
11
|
+
objectAssign(pageContext, {
|
|
12
|
+
globalContext: globalContextPublic
|
|
13
|
+
});
|
|
14
|
+
addIs404ToPageProps(pageContext);
|
|
15
|
+
// TODO/next-major-release: remove
|
|
16
|
+
if (!('_pageId' in pageContext)) {
|
|
17
|
+
Object.defineProperty(pageContext, '_pageId', {
|
|
18
|
+
get() {
|
|
19
|
+
assertWarning(false, 'pageContext._pageId has been renamed to pageContext.pageId', {
|
|
20
|
+
showStackTrace: true,
|
|
21
|
+
onlyOnce: true
|
|
22
|
+
});
|
|
23
|
+
return pageContext.pageId;
|
|
24
|
+
},
|
|
25
|
+
enumerable: false
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
// For a more readable `console.log(pageContext)` output
|
|
29
|
+
sortPageContext(pageContext);
|
|
30
|
+
const pageContextPublic = getProxyForPublicUsage(pageContext, 'pageContext',
|
|
31
|
+
// We must skip it in the client-side because of the reactivity mechanism of UI frameworks like Solid.
|
|
32
|
+
// - TODO/now: double check whether that's true
|
|
33
|
+
true, pageContext.globalContext);
|
|
34
|
+
return pageContextPublic;
|
|
35
|
+
}
|
|
36
|
+
// Sort `pageContext` keys alphabetically, in order to make reading the `console.log(pageContext)` output easier
|
|
37
|
+
function sortPageContext(pageContext) {
|
|
38
|
+
let descriptors = Object.getOwnPropertyDescriptors(pageContext);
|
|
39
|
+
for (const key of Object.keys(pageContext))
|
|
40
|
+
delete pageContext[key];
|
|
41
|
+
descriptors = Object.fromEntries(Object.entries(descriptors).sort(([key1], [key2]) => compareString(key1, key2)));
|
|
42
|
+
Object.defineProperties(pageContext, descriptors);
|
|
43
|
+
}
|
|
44
|
+
function assertPropertyGetters(pageContext) {
|
|
45
|
+
/*
|
|
46
|
+
If the isPropertyGetter() assertions fail then it's most likely because Object.assign() was used instead of `objectAssign()`:
|
|
47
|
+
```js
|
|
48
|
+
const PageContextUrlComputed = getPageContextUrlComputed(pageContext)
|
|
49
|
+
|
|
50
|
+
// ❌ Breaks the property descriptors/getters of pageContext defined by getPageContextUrlComputed() such as pageContext.urlPathname
|
|
51
|
+
Object.assign(pageContext, pageContextUrlComputed)
|
|
52
|
+
|
|
53
|
+
// ❌ Also breaks property descriptors/getters
|
|
54
|
+
const pageContext = { ...pageContextUrlComputed }
|
|
55
|
+
|
|
56
|
+
// ✅ Preserves property descriptors/getters (see objectAssign() implementation)
|
|
57
|
+
objectAssign(pageContext, pageContextUrlComputed)
|
|
58
|
+
```
|
|
59
|
+
*/
|
|
60
|
+
;
|
|
61
|
+
[
|
|
62
|
+
'urlPathname',
|
|
63
|
+
// TODO/v1-release: remove
|
|
64
|
+
'urlParsed',
|
|
65
|
+
// TODO/v1-release: remove
|
|
66
|
+
'url',
|
|
67
|
+
// TODO/v1-release: remove
|
|
68
|
+
'pageExports'
|
|
69
|
+
].forEach((prop) => {
|
|
70
|
+
if (pageContext.prop)
|
|
71
|
+
assert(isPropertyGetter(pageContext, prop));
|
|
72
|
+
});
|
|
73
|
+
}
|
|
@@ -7,7 +7,7 @@ export { logAbortErrorHandled };
|
|
|
7
7
|
export { getPageContextFromAllRewrites };
|
|
8
8
|
export { AbortRender };
|
|
9
9
|
export { assertNoInfiniteAbortLoop };
|
|
10
|
-
import { isUserHookError } from '../hooks/
|
|
10
|
+
import { isUserHookError } from '../hooks/execHook.js';
|
|
11
11
|
import { assert, assertInfo, assertUsage, assertUsageUrlPathnameAbsolute, assertUsageUrlRedirectTarget, assertWarning, checkType, hasProp, joinEnglish, objectAssign, truncateString } from './utils.js';
|
|
12
12
|
import pc from '@brillout/picocolors';
|
|
13
13
|
/**
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
export { executeGuardHook };
|
|
2
|
-
import type {
|
|
2
|
+
import type { PageFile } from '../getPageFiles.js';
|
|
3
3
|
import type { PageConfigRuntime } from '../page-configs/PageConfig.js';
|
|
4
|
-
|
|
4
|
+
import { type PageContextExecuteHook } from '../hooks/execHook.js';
|
|
5
|
+
declare function executeGuardHook<PageContext extends {
|
|
5
6
|
pageId: string;
|
|
6
7
|
_pageFilesAll: PageFile[];
|
|
7
8
|
_pageConfigs: PageConfigRuntime[];
|
|
8
|
-
}>(pageContext:
|
|
9
|
+
} & PageContextExecuteHook>(pageContext: PageContext, prepareForPublicUsage: (pageConfig: PageContext) => PageContext): Promise<void>;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export { executeGuardHook };
|
|
2
2
|
import { getHookFromPageContext, getHookTimeoutDefault } from '../hooks/getHook.js';
|
|
3
3
|
import { assert, assertUsage, isCallable } from './utils.js';
|
|
4
|
-
import {
|
|
4
|
+
import { execHookSingle } from '../hooks/execHook.js';
|
|
5
5
|
const errIntro = 'The guard() hook defined by';
|
|
6
|
-
async function executeGuardHook(pageContext,
|
|
6
|
+
async function executeGuardHook(pageContext, prepareForPublicUsage) {
|
|
7
7
|
let hook;
|
|
8
8
|
if (pageContext._pageFilesAll.length > 0) {
|
|
9
|
+
// TODO/v1-release: remove
|
|
9
10
|
// V0.4 design
|
|
10
11
|
assert(pageContext._pageConfigs.length === 0);
|
|
11
12
|
hook = findPageGuard(pageContext.pageId, pageContext._pageFilesAll);
|
|
@@ -16,13 +17,7 @@ async function executeGuardHook(pageContext, prepareForUserConsumption) {
|
|
|
16
17
|
}
|
|
17
18
|
if (!hook)
|
|
18
19
|
return;
|
|
19
|
-
|
|
20
|
-
let pageContextForUserConsumption = pageContext;
|
|
21
|
-
const res = prepareForUserConsumption(pageContext);
|
|
22
|
-
if (res)
|
|
23
|
-
pageContextForUserConsumption = res;
|
|
24
|
-
const hookResult = await executeHook(() => guard(pageContextForUserConsumption), hook, pageContext);
|
|
25
|
-
assertUsage(hookResult === undefined, `${errIntro} ${hook.hookFilePath} returns a value, but guard() shouldn't return any value`);
|
|
20
|
+
await execHookSingle(hook, pageContext, prepareForPublicUsage);
|
|
26
21
|
}
|
|
27
22
|
function findPageGuard(pageId, pageFilesAll) {
|
|
28
23
|
const pageRouteFile = pageFilesAll.find((p) => p.pageId === pageId && p.fileType === '.page.route');
|
|
@@ -3,7 +3,8 @@ import { assertPageContextProvidedByUser } from '../assertPageContextProvidedByU
|
|
|
3
3
|
import { assertUsage, hasProp, isObjectWithKeys, objectAssign, assertWarning, assertUsageUrlPathnameAbsolute, joinEnglish, assert } from './utils.js';
|
|
4
4
|
import { assertRouteParams, assertSyncRouting } from './resolveRouteFunction.js';
|
|
5
5
|
import pc from '@brillout/picocolors';
|
|
6
|
-
import {
|
|
6
|
+
import { execHookSync } from '../hooks/execHook.js';
|
|
7
|
+
import { preparePageContextForPublicUsage } from '../preparePageContextForPublicUsage.js';
|
|
7
8
|
async function executeOnBeforeRouteHook(pageContext) {
|
|
8
9
|
const pageContextFromOnBeforeRouteHook = {};
|
|
9
10
|
if (!pageContext._onBeforeRouteHook)
|
|
@@ -33,10 +34,10 @@ async function executeOnBeforeRouteHook(pageContext) {
|
|
|
33
34
|
return pageContextFromOnBeforeRouteHook;
|
|
34
35
|
}
|
|
35
36
|
async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
|
|
36
|
-
let hookReturn = onBeforeRouteHook
|
|
37
|
+
let { hookReturn } = execHookSync(onBeforeRouteHook, pageContext, preparePageContextForPublicUsage);
|
|
37
38
|
assertSyncRouting(hookReturn, `The onBeforeRoute() hook ${onBeforeRouteHook.hookFilePath}`);
|
|
38
39
|
// TODO/v1-release: make executeOnBeforeRouteHook() and route() sync
|
|
39
|
-
hookReturn = await
|
|
40
|
+
hookReturn = await hookReturn;
|
|
40
41
|
const errPrefix = `The onBeforeRoute() hook defined by ${onBeforeRouteHook.hookFilePath}`;
|
|
41
42
|
assertUsage(hookReturn === null ||
|
|
42
43
|
hookReturn === undefined ||
|
|
@@ -6,7 +6,6 @@ if (isBrowser()) {
|
|
|
6
6
|
assertClientRouting();
|
|
7
7
|
}
|
|
8
8
|
import { assert, assertUsage, isPlainObject, objectAssign } from './utils.js';
|
|
9
|
-
import { assertPageContextUrl } from '../getPageContextUrlComputed.js';
|
|
10
9
|
import { resolvePrecendence } from './resolvePrecedence.js';
|
|
11
10
|
import { resolveRouteString } from './resolveRouteString.js';
|
|
12
11
|
import { resolveRouteFunction } from './resolveRouteFunction.js';
|
|
@@ -15,7 +14,6 @@ import { debug } from './debug.js';
|
|
|
15
14
|
import pc from '@brillout/picocolors';
|
|
16
15
|
async function route(pageContext, skipOnBeforeRouteHook) {
|
|
17
16
|
debug('Pages routes:', pageContext._pageRoutes);
|
|
18
|
-
assertPageContextUrl(pageContext);
|
|
19
17
|
const pageContextFromRoute = {};
|
|
20
18
|
// onBeforeRoute()
|
|
21
19
|
if (!skipOnBeforeRouteHook) {
|
|
@@ -69,8 +67,8 @@ async function route(pageContext, skipOnBeforeRouteHook) {
|
|
|
69
67
|
}
|
|
70
68
|
// Route Function defined in `.page.route.js`
|
|
71
69
|
if (pageRoute.routeType === 'FUNCTION') {
|
|
72
|
-
const { routeFunction,
|
|
73
|
-
const match = await resolveRouteFunction(routeFunction, pageContext,
|
|
70
|
+
const { routeFunction, routeFunctionFilePath } = pageRoute;
|
|
71
|
+
const match = await resolveRouteFunction(routeFunction, pageContext, routeFunctionFilePath);
|
|
74
72
|
if (match) {
|
|
75
73
|
const { routeParams, precedence } = match;
|
|
76
74
|
routeMatches.push({ pageId, precedence, routeParams, routeType });
|
|
@@ -2,7 +2,7 @@ export { loadPageRoutes };
|
|
|
2
2
|
import { isErrorPageId } from '../error-page.js';
|
|
3
3
|
import { assert, assertUsage, hasProp, slice } from './utils.js';
|
|
4
4
|
import { deduceRouteStringFromFilesystemPath } from './deduceRouteStringFromFilesystemPath.js';
|
|
5
|
-
import { isCallable } from '../utils.js';
|
|
5
|
+
import { isArray, isCallable } from '../utils.js';
|
|
6
6
|
import { getConfigValueRuntime } from '../page-configs/getConfigValueRuntime.js';
|
|
7
7
|
import { getDefinedAtString } from '../page-configs/getConfigDefinedAt.js';
|
|
8
8
|
import { warnDeprecatedAllowKey } from './resolveRouteFunction.js';
|
|
@@ -44,6 +44,10 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
46
|
else {
|
|
47
|
+
const { definedAtData } = configValue;
|
|
48
|
+
assert(!isArray(definedAtData) && !definedAtData.definedBy);
|
|
49
|
+
const { filePathToShowToUser } = definedAtData;
|
|
50
|
+
assert(filePathToShowToUser);
|
|
47
51
|
assert(isCallable(route));
|
|
48
52
|
// TODO/next-major: remove
|
|
49
53
|
if (getConfigValueRuntime(pageConfig, 'iKnowThePerformanceRisksOfAsyncRouteFunctions', 'boolean'))
|
|
@@ -52,6 +56,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
52
56
|
pageId,
|
|
53
57
|
comesFromV1PageConfig,
|
|
54
58
|
routeFunction: route,
|
|
59
|
+
routeFunctionFilePath: filePathToShowToUser,
|
|
55
60
|
routeDefinedAtString: definedAtString,
|
|
56
61
|
routeType: 'FUNCTION'
|
|
57
62
|
};
|
|
@@ -125,6 +130,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
125
130
|
pageId,
|
|
126
131
|
comesFromV1PageConfig,
|
|
127
132
|
routeFunction,
|
|
133
|
+
routeFunctionFilePath: filePath,
|
|
128
134
|
routeDefinedAtString: filePath,
|
|
129
135
|
routeType: 'FUNCTION'
|
|
130
136
|
});
|
|
@@ -2,8 +2,8 @@ export { resolveRouteFunction };
|
|
|
2
2
|
export { assertRouteParams };
|
|
3
3
|
export { assertSyncRouting };
|
|
4
4
|
export { warnDeprecatedAllowKey };
|
|
5
|
-
import { PageContextUrlInternal } from '../getPageContextUrlComputed.js';
|
|
6
|
-
declare function resolveRouteFunction(routeFunction:
|
|
5
|
+
import type { PageContextUrlInternal } from '../getPageContextUrlComputed.js';
|
|
6
|
+
declare function resolveRouteFunction(routeFunction: (arg: unknown) => unknown, pageContext: PageContextUrlInternal, routeFunctionFilePath: string): Promise<null | {
|
|
7
7
|
precedence: number | null;
|
|
8
8
|
routeParams: Record<string, string>;
|
|
9
9
|
}>;
|
|
@@ -2,13 +2,17 @@ export { resolveRouteFunction };
|
|
|
2
2
|
export { assertRouteParams };
|
|
3
3
|
export { assertSyncRouting };
|
|
4
4
|
export { warnDeprecatedAllowKey };
|
|
5
|
-
import {
|
|
5
|
+
import { execHookSync } from '../hooks/execHook.js';
|
|
6
|
+
import { preparePageContextForPublicUsage } from '../preparePageContextForPublicUsage.js';
|
|
6
7
|
import { assert, assertUsage, assertWarning, hasProp, isPlainObject, isPromise } from './utils.js';
|
|
7
8
|
import pc from '@brillout/picocolors';
|
|
8
|
-
async function resolveRouteFunction(routeFunction, pageContext,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
async function resolveRouteFunction(routeFunction, pageContext, routeFunctionFilePath) {
|
|
10
|
+
let { hookReturn: result } = execHookSync({
|
|
11
|
+
hookFn: routeFunction,
|
|
12
|
+
hookFilePath: routeFunctionFilePath,
|
|
13
|
+
hookName: 'route'
|
|
14
|
+
}, pageContext, preparePageContextForPublicUsage);
|
|
15
|
+
assertSyncRouting(result, `The Route Function ${routeFunctionFilePath}`);
|
|
12
16
|
// TODO/v1-release: make resolveRouteFunction() and route() sync
|
|
13
17
|
//* We disallow asynchronous routing, because we need to check whether a link is a Vike link in a synchronous fashion before calling ev.preventDefault() in the 'click' event listener
|
|
14
18
|
result = await result;
|
|
@@ -19,11 +23,11 @@ async function resolveRouteFunction(routeFunction, pageContext, routeDefinedAtSt
|
|
|
19
23
|
if (result === true) {
|
|
20
24
|
result = {};
|
|
21
25
|
}
|
|
22
|
-
assertUsage(isPlainObject(result), `The Route Function ${
|
|
26
|
+
assertUsage(isPlainObject(result), `The Route Function ${routeFunctionFilePath} should return a boolean or a plain JavaScript object (but it's ${pc.cyan(`typeof result === ${JSON.stringify(typeof result)}`)} instead)`);
|
|
23
27
|
// AFAICT this return interface is superfluous. Should we soft-deprecate it and remove it?
|
|
24
28
|
if ('match' in result) {
|
|
25
29
|
const { match } = result;
|
|
26
|
-
assertUsage(typeof match === 'boolean', `The ${pc.cyan('match')} value returned by the Route Function ${
|
|
30
|
+
assertUsage(typeof match === 'boolean', `The ${pc.cyan('match')} value returned by the Route Function ${routeFunctionFilePath} should be a boolean.`);
|
|
27
31
|
if (!match) {
|
|
28
32
|
return null;
|
|
29
33
|
}
|
|
@@ -31,14 +35,14 @@ async function resolveRouteFunction(routeFunction, pageContext, routeDefinedAtSt
|
|
|
31
35
|
let precedence = null;
|
|
32
36
|
if ('precedence' in result) {
|
|
33
37
|
precedence = result.precedence;
|
|
34
|
-
assertUsage(typeof precedence === 'number', `The ${pc.cyan('precedence')} value returned by the Route Function ${
|
|
38
|
+
assertUsage(typeof precedence === 'number', `The ${pc.cyan('precedence')} value returned by the Route Function ${routeFunctionFilePath} should be a number.`);
|
|
35
39
|
}
|
|
36
|
-
assertRouteParams(result, `The ${pc.cyan('routeParams')} object returned by the Route Function ${
|
|
40
|
+
assertRouteParams(result, `The ${pc.cyan('routeParams')} object returned by the Route Function ${routeFunctionFilePath} should`);
|
|
37
41
|
const routeParams = result.routeParams || {};
|
|
38
42
|
assertUsage(!('pageContext' in result), `Providing ${pc.cyan('pageContext')} in Route Functions is prohibited, see https://vike.dev/route-function#cannot-provide-pagecontext`);
|
|
39
43
|
assert(isPlainObject(routeParams));
|
|
40
44
|
Object.keys(result).forEach((key) => {
|
|
41
|
-
assertUsage(key === 'match' || key === 'routeParams' || key === 'precedence', `The Route Function ${
|
|
45
|
+
assertUsage(key === 'match' || key === 'routeParams' || key === 'precedence', `The Route Function ${routeFunctionFilePath} returned an object with an unknown property ${pc.cyan(key)} (the known properties are ${pc.cyan('match')}, ${pc.cyan('routeParams')}, and ${pc.cyan('precedence')})`);
|
|
42
46
|
});
|
|
43
47
|
return {
|
|
44
48
|
precedence,
|
|
@@ -7,7 +7,10 @@ export type { GlobalContextClient };
|
|
|
7
7
|
export type { PageContextWithServerRouting };
|
|
8
8
|
export type { PageContextClientWithServerRouting };
|
|
9
9
|
export type { GlobalContextClientWithServerRouting };
|
|
10
|
-
export type {
|
|
10
|
+
export type { PageContextInternalServer };
|
|
11
|
+
export type { PageContextInternalClient };
|
|
12
|
+
export type { PageContextInternalClient_ServerRouting };
|
|
13
|
+
export type { PageContextInternalClient_ClientRouting };
|
|
11
14
|
export type { PageContextBuiltInServer_deprecated as PageContextBuiltInServer };
|
|
12
15
|
export type { PageContextBuiltInClientWithClientRouting_deprecated as PageContextBuiltInClientWithClientRouting };
|
|
13
16
|
export type { PageContextBuiltInClientWithServerRouting_deprecated as PageContextBuiltInClientWithServerRouting };
|
|
@@ -235,8 +238,15 @@ type PageContextClientCommon = {
|
|
|
235
238
|
*/
|
|
236
239
|
isPrerendering: false;
|
|
237
240
|
};
|
|
238
|
-
|
|
239
|
-
type
|
|
241
|
+
type PageContextInternalServer = Omit<PageContextBuiltInCommon<unknown> & PageContextUrlInternal, 'data' | 'globalContext'>;
|
|
242
|
+
type OnlyUsers = 'data' | 'Page' | 'globalContext';
|
|
243
|
+
type PageContextInternalClient = Omit<PageContextInternalClient_ClientRouting | PageContextInternalClient_ServerRouting, OnlyUsers>;
|
|
244
|
+
type PageContextInternalClient_ClientRouting = Omit<PageContextBuiltInClientWithClientRouting<unknown>, OnlyUsers | 'previousPageContext'> & {
|
|
245
|
+
previousPageContext: {
|
|
246
|
+
pageId: string;
|
|
247
|
+
} | null;
|
|
248
|
+
};
|
|
249
|
+
type PageContextInternalClient_ServerRouting = Omit<PageContextBuiltInClientWithServerRouting<unknown>, OnlyUsers>;
|
|
240
250
|
/** @deprecated
|
|
241
251
|
* Replace:
|
|
242
252
|
* ```
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.229-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.229-commit-e27d672";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.229-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.229-commit-e27d672';
|