vike 0.4.229 → 0.4.230-commit-dd11364
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 +2 -5
- package/dist/cjs/node/plugin/index.js +3 -1
- package/dist/cjs/node/plugin/onLoad.js +2 -0
- package/dist/cjs/node/plugin/plugins/build/pluginDistFileNames.js +1 -0
- package/dist/cjs/node/plugin/plugins/build/pluginModuleBanner.js +4 -4
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -0
- package/dist/cjs/node/plugin/plugins/envVars.js +17 -19
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +3 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +6 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +12 -8
- package/dist/cjs/node/plugin/plugins/replaceConstants.js +76 -0
- package/dist/cjs/node/plugin/shared/applyRegExWithMagicString.js +10 -0
- package/dist/cjs/node/plugin/shared/findPageFiles.js +1 -1
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +2 -2
- package/dist/cjs/node/plugin/shared/resolveClientEntriesDev.js +1 -1
- package/dist/cjs/node/prerender/runPrerender.js +42 -38
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +13 -27
- package/dist/cjs/node/runtime/html/renderHtml.js +12 -2
- package/dist/cjs/node/runtime/html/serializeContext.js +4 -2
- package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +7 -5
- package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +3 -4
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +6 -9
- package/dist/cjs/node/runtime/renderPage/execHookServer.js +11 -0
- package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +14 -15
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -12
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +1 -1
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +1 -1
- package/dist/cjs/node/runtime/renderPage/{loadUserFilesServerSide.js → loadPageConfigsLazyServerSide.js} +4 -4
- package/dist/cjs/node/runtime/renderPage/preparePageContextForPublicUsageServer.js +10 -0
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -5
- package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +0 -2
- package/dist/cjs/node/runtime/renderPage.js +21 -12
- 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 +37 -8
- package/dist/cjs/shared/createPageContextShared.js +14 -11
- package/dist/cjs/shared/getPageContext.js +3 -3
- package/dist/cjs/shared/getPageContextUrlComputed.js +2 -36
- package/dist/cjs/shared/getProxyForPublicUsage.js +56 -0
- package/dist/cjs/shared/hooks/execHook.js +170 -0
- package/dist/cjs/shared/hooks/getHook.js +23 -4
- package/dist/cjs/shared/page-configs/{getPageConfigUserFriendly.js → getUserFriendlyConfigs.js} +54 -47
- package/dist/cjs/shared/prepareGlobalContextForPublicUsage.js +10 -0
- package/dist/cjs/shared/preparePageContextForPublicUsage.js +80 -0
- package/dist/cjs/shared/route/abort.js +2 -2
- package/dist/cjs/shared/route/debug.js +17 -7
- 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/debug.js +15 -6
- package/dist/cjs/utils/isDev.js +3 -1
- package/dist/cjs/utils/isScriptFile.js +24 -21
- package/dist/cjs/utils/objectAssign.js +3 -3
- package/dist/cjs/utils/objectDefineProperty.js +1 -1
- package/dist/cjs/utils/parseNpmPackage.js +1 -0
- package/dist/cjs/utils/parseUrl-extras.js +0 -1
- package/dist/cjs/utils/requireResolve.js +39 -19
- package/dist/esm/client/client-routing-runtime/{createPageContext.d.ts → createPageContextClientSide.d.ts} +21 -13
- package/dist/esm/client/client-routing-runtime/{createPageContext.js → createPageContextClientSide.js} +9 -11
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +400 -15
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +56 -54
- package/dist/esm/client/client-routing-runtime/globalContext.d.ts +11 -1
- package/dist/esm/client/client-routing-runtime/prefetch.d.ts +3 -8
- package/dist/esm/client/client-routing-runtime/prefetch.js +3 -3
- 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 +72 -81
- 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 +19 -13
- package/dist/esm/client/server-routing-runtime/createPageContextClientSide.js +15 -26
- package/dist/esm/client/server-routing-runtime/entry.js +4 -4
- package/dist/esm/client/server-routing-runtime/globalContext.d.ts +11 -1
- 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 +11 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +3 -3
- package/dist/esm/client/shared/executeOnRenderClientHook.js +4 -13
- package/dist/esm/client/shared/{loadUserFilesClientSide.d.ts → loadPageConfigsLazyClientSide.d.ts} +2 -2
- package/dist/esm/client/shared/{loadUserFilesClientSide.js → loadPageConfigsLazyClientSide.js} +4 -4
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +11 -0
- package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.js +39 -0
- package/dist/esm/node/api/build.js +2 -2
- package/dist/esm/node/plugin/index.js +3 -1
- package/dist/esm/node/plugin/onLoad.js +2 -0
- package/dist/esm/node/plugin/plugins/build/pluginDistFileNames.js +1 -0
- package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +4 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +6 -1
- package/dist/esm/node/plugin/plugins/envVars.js +18 -20
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +4 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +7 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +12 -8
- package/dist/esm/node/plugin/plugins/replaceConstants.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/replaceConstants.js +71 -0
- package/dist/esm/node/plugin/shared/applyRegExWithMagicString.d.ts +3 -0
- package/dist/esm/node/plugin/shared/applyRegExWithMagicString.js +8 -0
- package/dist/esm/node/plugin/shared/findPageFiles.js +2 -2
- package/dist/esm/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/esm/node/plugin/shared/resolveClientEntriesDev.d.ts +1 -1
- package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +1 -1
- package/dist/esm/node/prerender/runPrerender.d.ts +37 -73
- package/dist/esm/node/prerender/runPrerender.js +42 -38
- 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 +46 -251
- package/dist/esm/node/runtime/globalContext.js +14 -28
- package/dist/esm/node/runtime/html/renderHtml.js +12 -2
- package/dist/esm/node/runtime/html/serializeContext.d.ts +1 -1
- package/dist/esm/node/runtime/html/serializeContext.js +4 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.js +7 -5
- package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponse.js +3 -4
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +26 -41
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +7 -10
- 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 +2 -3
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +14 -15
- 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/getHttpResponseBody.js +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +1 -1
- package/dist/esm/node/runtime/renderPage/{loadUserFilesServerSide.d.ts → loadPageConfigsLazyServerSide.d.ts} +6 -6
- package/dist/esm/node/runtime/renderPage/{loadUserFilesServerSide.js → loadPageConfigsLazyServerSide.js} +4 -4
- 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 +38 -74
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -5
- package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +0 -2
- package/dist/esm/node/runtime/renderPage/resolveRedirects.js +0 -1
- package/dist/esm/node/runtime/renderPage.d.ts +21 -39
- package/dist/esm/node/runtime/renderPage.js +22 -13
- 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 +28 -6
- package/dist/esm/shared/createGlobalContextShared.js +37 -8
- package/dist/esm/shared/createPageContextShared.d.ts +7 -6
- package/dist/esm/shared/createPageContextShared.js +15 -12
- 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/getPageFiles.d.ts +1 -1
- package/dist/esm/shared/getProxyForPublicUsage.d.ts +4 -0
- package/dist/esm/shared/getProxyForPublicUsage.js +54 -0
- package/dist/esm/shared/hooks/execHook.d.ts +63 -0
- package/dist/esm/shared/hooks/execHook.js +168 -0
- package/dist/esm/shared/hooks/getHook.d.ts +10 -11
- package/dist/esm/shared/hooks/getHook.js +23 -4
- package/dist/esm/shared/page-configs/Config.d.ts +11 -4
- package/dist/esm/shared/page-configs/{getPageConfigUserFriendly.d.ts → getUserFriendlyConfigs.d.ts} +8 -6
- package/dist/esm/shared/page-configs/{getPageConfigUserFriendly.js → getUserFriendlyConfigs.js} +55 -48
- package/dist/esm/shared/prepareGlobalContextForPublicUsage.d.ts +7 -0
- package/dist/esm/shared/prepareGlobalContextForPublicUsage.js +8 -0
- package/dist/esm/shared/preparePageContextForPublicUsage.d.ts +11 -0
- package/dist/esm/shared/preparePageContextForPublicUsage.js +78 -0
- package/dist/esm/shared/route/abort.js +1 -1
- package/dist/esm/shared/route/debug.d.ts +4 -1
- package/dist/esm/shared/route/debug.js +17 -7
- 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 +14 -4
- package/dist/esm/shared/utils.d.ts +1 -0
- package/dist/esm/shared/utils.js +1 -0
- 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/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +15 -6
- package/dist/esm/utils/isDev.js +3 -1
- package/dist/esm/utils/isScriptFile.d.ts +5 -5
- package/dist/esm/utils/isScriptFile.js +23 -20
- 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/dist/esm/utils/parseNpmPackage.d.ts +2 -0
- package/dist/esm/utils/parseNpmPackage.js +1 -1
- package/dist/esm/utils/parseUrl-extras.js +0 -1
- package/dist/esm/utils/requireResolve.js +39 -19
- package/package.json +2 -2
- package/dist/cjs/client/shared/getPageContextProxyForUser.js +0 -16
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +0 -16
- package/dist/cjs/shared/getPageConfigsRuntime.js +0 -23
- package/dist/cjs/shared/hooks/executeHook.js +0 -87
- package/dist/cjs/shared/hooks/executeHookGeneric.js +0 -18
- 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/preparePageContextForUserConsumptionServerSide.d.ts +0 -24
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +0 -14
- package/dist/esm/shared/getPageConfigsRuntime.d.ts +0 -14
- package/dist/esm/shared/getPageConfigsRuntime.js +0 -21
- package/dist/esm/shared/hooks/executeHook.d.ts +0 -21
- package/dist/esm/shared/hooks/executeHook.js +0 -85
- package/dist/esm/shared/hooks/executeHookGeneric.d.ts +0 -8
- package/dist/esm/shared/hooks/executeHookGeneric.js +0 -16
- 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
|
@@ -10,12 +10,12 @@ const renderHtml_js_1 = require("../html/renderHtml.js");
|
|
|
10
10
|
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
|
-
const
|
|
13
|
+
const loadPageConfigsLazyServerSide_js_1 = require("./loadPageConfigsLazyServerSide.js");
|
|
14
14
|
const executeOnRenderHtmlHook_js_1 = require("./executeOnRenderHtmlHook.js");
|
|
15
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
|
-
const
|
|
18
|
+
const preparePageContextForPublicUsageServer_js_1 = require("./preparePageContextForPublicUsageServer.js");
|
|
19
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");
|
|
@@ -26,9 +26,9 @@ async function renderPageAlreadyRouted(pageContext) {
|
|
|
26
26
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContext, 'pageId', 'string'));
|
|
27
27
|
const isError = pageContext.is404 || !!pageContext.errorWhileRendering;
|
|
28
28
|
(0, utils_js_1.assert)(isError === (pageContext.pageId === (0, error_page_js_1.getErrorPageId)(pageContext._pageFilesAll, pageContext._pageConfigs)));
|
|
29
|
-
(0, utils_js_1.objectAssign)(pageContext, await (0,
|
|
29
|
+
(0, utils_js_1.objectAssign)(pageContext, await (0, loadPageConfigsLazyServerSide_js_1.loadPageConfigsLazyServerSide)(pageContext));
|
|
30
30
|
if (!isError) {
|
|
31
|
-
await (0, executeGuardHook_js_1.executeGuardHook)(pageContext, (pageContext) => (0,
|
|
31
|
+
await (0, executeGuardHook_js_1.executeGuardHook)(pageContext, (pageContext) => (0, preparePageContextForPublicUsageServer_js_1.preparePageContextForPublicUsageServer)(pageContext));
|
|
32
32
|
}
|
|
33
33
|
if (!isError) {
|
|
34
34
|
await (0, executeOnBeforeRenderAndDataHooks_js_1.executeOnBeforeRenderAndDataHooks)(pageContext);
|
|
@@ -65,7 +65,7 @@ async function prerenderPage(pageContext) {
|
|
|
65
65
|
});
|
|
66
66
|
/* Should we execute the guard() hook upon pre-rendering? Is there a use case for this?
|
|
67
67
|
* - It isn't trivial to implement, as it requires to duplicate / factor out the isAbortError() handling
|
|
68
|
-
await executeGuardHook(pageContext, (pageContext) =>
|
|
68
|
+
await executeGuardHook(pageContext, (pageContext) => preparePageContextForPublicUsageServer(pageContext))
|
|
69
69
|
*/
|
|
70
70
|
await (0, executeOnBeforeRenderAndDataHooks_js_1.executeOnBeforeRenderAndDataHooks)(pageContext);
|
|
71
71
|
const { htmlRender, renderHook } = await (0, executeOnRenderHtmlHook_js_1.executeOnRenderHtmlHook)(pageContext);
|
|
@@ -3,7 +3,6 @@ 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.redirectsErrPrefix = void 0;
|
|
7
6
|
exports.resolveRedirects = resolveRedirects;
|
|
8
7
|
exports.resolveRouteStringRedirect = resolveRouteStringRedirect;
|
|
9
8
|
const assertIsNotBrowser_js_1 = require("../../../utils/assertIsNotBrowser.js");
|
|
@@ -13,7 +12,6 @@ const resolveRouteString_js_1 = require("../../../shared/route/resolveRouteStrin
|
|
|
13
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
13
|
(0, assertIsNotBrowser_js_1.assertIsNotBrowser)(); // Don't bloat the client
|
|
15
14
|
const redirectsErrPrefix = '[+redirects]';
|
|
16
|
-
exports.redirectsErrPrefix = redirectsErrPrefix;
|
|
17
15
|
function resolveRedirects(redirectsAll, urlPathname) {
|
|
18
16
|
const redirects = merge(redirectsAll);
|
|
19
17
|
for (const [urlSource, urlTarget] of Object.entries(redirects)) {
|
|
@@ -22,7 +22,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
22
22
|
const serializeContext_js_1 = require("./html/serializeContext.js");
|
|
23
23
|
const error_page_js_1 = require("../../shared/error-page.js");
|
|
24
24
|
const handleErrorWithoutErrorPage_js_1 = require("./renderPage/handleErrorWithoutErrorPage.js");
|
|
25
|
-
const
|
|
25
|
+
const loadPageConfigsLazyServerSide_js_1 = require("./renderPage/loadPageConfigsLazyServerSide.js");
|
|
26
26
|
const resolveRedirects_js_1 = require("./renderPage/resolveRedirects.js");
|
|
27
27
|
const globalObject = (0, utils_js_1.getGlobalObject)('runtime/renderPage.ts', {
|
|
28
28
|
httpRequestsCount: 0
|
|
@@ -33,9 +33,9 @@ async function renderPage(pageContextInit) {
|
|
|
33
33
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextInit, 'urlOriginal', 'string')); // assertUsage() already implemented at assertArguments()
|
|
34
34
|
assertIsUrl(pageContextInit.urlOriginal);
|
|
35
35
|
(0, utils_js_1.onSetupRuntime)();
|
|
36
|
-
const
|
|
37
|
-
if (
|
|
38
|
-
return
|
|
36
|
+
const pageContextSkipRequest = getPageContextSkipRequest(pageContextInit);
|
|
37
|
+
if (pageContextSkipRequest)
|
|
38
|
+
return pageContextSkipRequest;
|
|
39
39
|
const httpRequestId = getRequestId();
|
|
40
40
|
const urlOriginalPretty = (0, utils_js_1.getUrlPretty)(pageContextInit.urlOriginal);
|
|
41
41
|
logHttpRequest(urlOriginalPretty, httpRequestId);
|
|
@@ -81,8 +81,8 @@ async function renderPagePrepare(pageContextInit, httpRequestId) {
|
|
|
81
81
|
else {
|
|
82
82
|
// `globalContext` now contains the entire Vike config and getVikeConfig() isn't called anymore for this request.
|
|
83
83
|
}
|
|
84
|
-
const { globalContext
|
|
85
|
-
const pageContextBegin = await getPageContextBegin(pageContextInit, globalContext,
|
|
84
|
+
const { globalContext } = await (0, globalContext_js_1.getGlobalContextServerInternal)();
|
|
85
|
+
const pageContextBegin = await getPageContextBegin(pageContextInit, globalContext, httpRequestId);
|
|
86
86
|
// Check Base URL
|
|
87
87
|
{
|
|
88
88
|
const pageContextHttpResponse = await checkBaseUrl(pageContextBegin, globalContext);
|
|
@@ -304,9 +304,9 @@ async function getPageContextErrorPageInit(pageContextBegin, errNominalPage, pag
|
|
|
304
304
|
(0, utils_js_1.assert)(pageContext.errorWhileRendering);
|
|
305
305
|
return pageContext;
|
|
306
306
|
}
|
|
307
|
-
async function getPageContextBegin(pageContextInit, globalContext,
|
|
307
|
+
async function getPageContextBegin(pageContextInit, globalContext, httpRequestId) {
|
|
308
308
|
const { isClientSideNavigation, _urlHandler } = handlePageContextUrl(pageContextInit.urlOriginal);
|
|
309
|
-
const pageContextBegin = await (0, createPageContextServerSide_js_1.createPageContextServerSide)(pageContextInit, globalContext,
|
|
309
|
+
const pageContextBegin = await (0, createPageContextServerSide_js_1.createPageContextServerSide)(pageContextInit, globalContext, {
|
|
310
310
|
isPrerendering: false,
|
|
311
311
|
ssr: {
|
|
312
312
|
urlHandler: _urlHandler,
|
|
@@ -415,7 +415,7 @@ pageContextNominalPageBegin, httpRequestId, pageContextErrorPageInit, globalCont
|
|
|
415
415
|
(0, utils_js_1.objectAssign)(pageContext, { pageId: errorPageId });
|
|
416
416
|
(0, utils_js_1.objectAssign)(pageContext, pageContextAbort);
|
|
417
417
|
(0, utils_js_1.objectAssign)(pageContext, pageContextErrorPageInit, true);
|
|
418
|
-
(0, utils_js_1.objectAssign)(pageContext, await (0,
|
|
418
|
+
(0, utils_js_1.objectAssign)(pageContext, await (0, loadPageConfigsLazyServerSide_js_1.loadPageConfigsLazyServerSide)(pageContext));
|
|
419
419
|
// We include pageContextInit: we don't only serialize pageContextAbort because the error page may need to access pageContextInit
|
|
420
420
|
pageContextSerialized = (0, serializeContext_js_1.getPageContextClientSerialized)(pageContext);
|
|
421
421
|
}
|
|
@@ -459,13 +459,22 @@ async function checkBaseUrl(pageContextBegin, globalContext) {
|
|
|
459
459
|
(0, utils_js_1.checkType)(pageContext);
|
|
460
460
|
return pageContext;
|
|
461
461
|
}
|
|
462
|
-
function
|
|
462
|
+
function getPageContextSkipRequest(pageContextInit) {
|
|
463
463
|
const urlPathnameWithBase = (0, utils_js_1.parseUrl)(pageContextInit.urlOriginal, '/').pathname;
|
|
464
464
|
assertIsNotViteRequest(urlPathnameWithBase, pageContextInit.urlOriginal);
|
|
465
|
-
|
|
465
|
+
let errMsg404;
|
|
466
|
+
if (urlPathnameWithBase.endsWith('/favicon.ico')) {
|
|
467
|
+
errMsg404 = 'No favicon.ico found';
|
|
468
|
+
}
|
|
469
|
+
if (urlPathnameWithBase.endsWith('.well-known/appspecific/com.chrome.devtools.json')) {
|
|
470
|
+
// https://chromium.googlesource.com/devtools/devtools-frontend/+/main/docs/ecosystem/automatic_workspace_folders.md
|
|
471
|
+
// https://www.reddit.com/r/node/comments/1kcr0wh/odd_request_coming_into_my_localhost_server_from/
|
|
472
|
+
errMsg404 = 'Not spported';
|
|
473
|
+
}
|
|
474
|
+
if (!errMsg404)
|
|
466
475
|
return;
|
|
467
476
|
const pageContext = (0, createPageContextServerSide_js_1.createPageContextServerSideWithoutGlobalContext)(pageContextInit);
|
|
468
|
-
const httpResponse = (0, createHttpResponse_js_1.
|
|
477
|
+
const httpResponse = (0, createHttpResponse_js_1.createHttpResponse404)(errMsg404);
|
|
469
478
|
(0, utils_js_1.objectAssign)(pageContext, { httpResponse });
|
|
470
479
|
(0, utils_js_1.checkType)(pageContext);
|
|
471
480
|
return pageContext;
|
|
@@ -74,5 +74,5 @@ __exportStar(require("../../utils/isVikeReactApp.js"), exports);
|
|
|
74
74
|
__exportStar(require("../../utils/getPropAccessNotation.js"), exports);
|
|
75
75
|
__exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
|
|
76
76
|
__exportStar(require("../../utils/genPromise.js"), exports);
|
|
77
|
-
__exportStar(require("../../utils/getPublicProxy.js"), exports);
|
|
78
77
|
__exportStar(require("../../utils/augmentType.js"), exports);
|
|
78
|
+
__exportStar(require("../../utils/changeEnumerable.js"), exports);
|
|
@@ -2,16 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.addIs404ToPageProps = addIs404ToPageProps;
|
|
4
4
|
const utils_js_1 = require("./utils.js");
|
|
5
|
-
const error_page_js_1 = require("./error-page.js");
|
|
6
5
|
function addIs404ToPageProps(pageContext) {
|
|
7
|
-
assertIs404(pageContext);
|
|
8
6
|
addIs404(pageContext);
|
|
9
7
|
}
|
|
10
|
-
function assertIs404(pageContext) {
|
|
11
|
-
if ((0, error_page_js_1.isErrorPage)(pageContext.pageId, pageContext._pageConfigs)) {
|
|
12
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContext, 'is404', 'boolean'));
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
8
|
function addIs404(pageContext) {
|
|
16
9
|
if (pageContext.is404 === undefined || pageContext.is404 === null)
|
|
17
10
|
return;
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getGlobalContextSyncErrMsg = void 0;
|
|
4
4
|
exports.createGlobalContextShared = createGlobalContextShared;
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
const parseGlobResults_js_1 = require("./getPageFiles/parseGlobResults.js");
|
|
7
|
+
const getUserFriendlyConfigs_js_1 = require("./page-configs/getUserFriendlyConfigs.js");
|
|
8
|
+
const execHook_js_1 = require("./hooks/execHook.js");
|
|
9
|
+
const prepareGlobalContextForPublicUsage_js_1 = require("./prepareGlobalContextForPublicUsage.js");
|
|
5
10
|
const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
|
|
6
11
|
exports.getGlobalContextSyncErrMsg = getGlobalContextSyncErrMsg;
|
|
7
|
-
const getPageConfigsRuntime_js_1 = require("./getPageConfigsRuntime.js");
|
|
8
|
-
const executeHookGeneric_js_1 = require("./hooks/executeHookGeneric.js");
|
|
9
|
-
const utils_js_1 = require("./utils.js");
|
|
10
12
|
async function createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext) {
|
|
11
13
|
const globalContext = createGlobalContextBase(virtualFileExports);
|
|
12
14
|
const globalContextAddendum = await addGlobalContext?.(globalContext);
|
|
@@ -24,17 +26,17 @@ async function createGlobalContextShared(virtualFileExports, globalObject, addGl
|
|
|
24
26
|
// - globalContext._viteDevServer.hot.send()
|
|
25
27
|
// - Send 'full-server-reload' signal whenever a onCreateGlobalContext() function is modified => we need a globalObject to track all hooks and see if one of them is new/modified.
|
|
26
28
|
// - Seems less idiomatic
|
|
27
|
-
await (0,
|
|
29
|
+
await (0, execHook_js_1.execHookGlobal)('onCreateGlobalContext', globalContext._pageConfigGlobal, null, globalContext, prepareGlobalContextForPublicUsage_js_1.prepareGlobalContextForPublicUsage);
|
|
28
30
|
}
|
|
29
31
|
else {
|
|
30
32
|
// Singleton: ensure all `globalContext` user-land references are preserved & updated.
|
|
31
33
|
// We don't use objectReplace() in order to keep user-land properties.
|
|
32
|
-
(0, utils_js_1.objectAssign)(globalObject.globalContext, globalContext);
|
|
34
|
+
(0, utils_js_1.objectAssign)(globalObject.globalContext, globalContext, true);
|
|
33
35
|
}
|
|
34
36
|
return globalObject.globalContext;
|
|
35
37
|
}
|
|
36
38
|
function createGlobalContextBase(virtualFileExports) {
|
|
37
|
-
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal,
|
|
39
|
+
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, userFriendlyConfigsGlobal, userFriendlyConfigsPageEager } = getConfigsAll(virtualFileExports);
|
|
38
40
|
const globalContext = {
|
|
39
41
|
/**
|
|
40
42
|
* Useful for distinguishing `globalContext` from other objects and narrowing down TypeScript unions.
|
|
@@ -42,13 +44,40 @@ function createGlobalContextBase(virtualFileExports) {
|
|
|
42
44
|
* https://vike.dev/globalContext#typescript
|
|
43
45
|
*/
|
|
44
46
|
isGlobalContext: true,
|
|
47
|
+
_isOriginalObject: true,
|
|
45
48
|
_virtualFileExports: virtualFileExports,
|
|
46
49
|
_pageFilesAll: pageFilesAll,
|
|
47
50
|
_pageConfigs: pageConfigs,
|
|
48
51
|
_pageConfigGlobal: pageConfigGlobal,
|
|
49
52
|
_allPageIds: allPageIds,
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
_userFriendlyConfigsGlobal: userFriendlyConfigsGlobal,
|
|
54
|
+
config: userFriendlyConfigsGlobal.config,
|
|
55
|
+
pages: userFriendlyConfigsPageEager
|
|
52
56
|
};
|
|
57
|
+
(0, utils_js_1.changeEnumerable)(globalContext, '_isOriginalObject', false);
|
|
53
58
|
return globalContext;
|
|
54
59
|
}
|
|
60
|
+
function getConfigsAll(virtualFileExports) {
|
|
61
|
+
const { pageFilesAll, pageConfigs, pageConfigGlobal } = (0, parseGlobResults_js_1.parseGlobResults)(virtualFileExports);
|
|
62
|
+
const allPageIds = getAllPageIds(pageFilesAll, pageConfigs);
|
|
63
|
+
const userFriendlyConfigsGlobal = (0, getUserFriendlyConfigs_js_1.getUserFriendlyConfigsGlobal)({
|
|
64
|
+
pageConfigGlobalValues: pageConfigGlobal.configValues
|
|
65
|
+
});
|
|
66
|
+
const userFriendlyConfigsPageEager = Object.fromEntries(pageConfigs.map((pageConfig) => {
|
|
67
|
+
return (0, getUserFriendlyConfigs_js_1.getUserFriendlyConfigsPageEager)(pageConfigGlobal.configValues, pageConfig, pageConfig.configValues);
|
|
68
|
+
}));
|
|
69
|
+
return {
|
|
70
|
+
pageFilesAll,
|
|
71
|
+
allPageIds,
|
|
72
|
+
pageConfigs,
|
|
73
|
+
pageConfigGlobal,
|
|
74
|
+
userFriendlyConfigsGlobal,
|
|
75
|
+
userFriendlyConfigsPageEager
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
function getAllPageIds(pageFilesAll, pageConfigs) {
|
|
79
|
+
const fileIds = pageFilesAll.filter(({ isDefaultPageFile }) => !isDefaultPageFile).map(({ pageId }) => pageId);
|
|
80
|
+
const allPageIds = (0, utils_js_1.unique)(fileIds);
|
|
81
|
+
const allPageIds2 = pageConfigs.map((p) => p.pageId);
|
|
82
|
+
return [...allPageIds, ...allPageIds2];
|
|
83
|
+
}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPageContextShared = createPageContextShared;
|
|
4
|
-
|
|
5
|
-
const
|
|
4
|
+
exports.createPageContextObject = createPageContextObject;
|
|
5
|
+
const execHook_js_1 = require("./hooks/execHook.js");
|
|
6
|
+
const preparePageContextForPublicUsage_js_1 = require("./preparePageContextForPublicUsage.js");
|
|
6
7
|
const utils_js_1 = require("./utils.js");
|
|
7
|
-
async function createPageContextShared(pageContextCreated, pageConfigGlobal) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
});
|
|
11
|
-
(0, utils_js_1.objectAssign)(pageContextCreated, {
|
|
12
|
-
isPageContext: true,
|
|
13
|
-
...pageConfigGlobalUserFriendly
|
|
14
|
-
}, true);
|
|
15
|
-
await (0, executeHookGeneric_js_1.executeHookGenericGlobalCumulative)('onCreatePageContext', pageConfigGlobal, pageContextCreated, pageContextCreated);
|
|
8
|
+
async function createPageContextShared(pageContextCreated, pageConfigGlobal, userFriendlyConfigsGlobal) {
|
|
9
|
+
(0, utils_js_1.objectAssign)(pageContextCreated, userFriendlyConfigsGlobal);
|
|
10
|
+
await (0, execHook_js_1.execHookGlobal)('onCreatePageContext', pageConfigGlobal, pageContextCreated, pageContextCreated, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage);
|
|
16
11
|
return pageContextCreated;
|
|
17
12
|
}
|
|
13
|
+
function createPageContextObject() {
|
|
14
|
+
const pageContext = {
|
|
15
|
+
_isOriginalObject: true,
|
|
16
|
+
isPageContext: true
|
|
17
|
+
};
|
|
18
|
+
(0, utils_js_1.changeEnumerable)(pageContext, '_isOriginalObject', false);
|
|
19
|
+
return pageContext;
|
|
20
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.providePageContext = exports.getPageContext = void 0;
|
|
4
|
-
var
|
|
5
|
-
Object.defineProperty(exports, "getPageContext", { enumerable: true, get: function () { return
|
|
6
|
-
Object.defineProperty(exports, "providePageContext", { enumerable: true, get: function () { return
|
|
4
|
+
var execHook_js_1 = require("./hooks/execHook.js");
|
|
5
|
+
Object.defineProperty(exports, "getPageContext", { enumerable: true, get: function () { return execHook_js_1.getPageContext; } });
|
|
6
|
+
Object.defineProperty(exports, "providePageContext", { enumerable: true, get: function () { return execHook_js_1.providePageContext; } });
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getPageContextUrlComputed = getPageContextUrlComputed;
|
|
4
|
-
exports.assertPageContextUrl = assertPageContextUrl;
|
|
5
4
|
// =====================
|
|
6
5
|
// File determining the URL logic.
|
|
7
6
|
// URLs need to be computed, because the user can modify the URL e.g. with onBeforeRoute() for i18n.
|
|
8
7
|
// =====================
|
|
9
8
|
const objectDefineProperty_js_1 = require("../utils/objectDefineProperty.js");
|
|
9
|
+
const preparePageContextForPublicUsage_js_1 = require("./preparePageContextForPublicUsage.js");
|
|
10
10
|
const utils_js_1 = require("./utils.js");
|
|
11
11
|
function getPageContextUrlComputed(pageContext) {
|
|
12
12
|
(0, utils_js_1.assert)(typeof pageContext.urlOriginal === 'string');
|
|
13
|
-
|
|
13
|
+
(0, preparePageContextForPublicUsage_js_1.assertPropertyGetters)(pageContext);
|
|
14
14
|
const pageContextUrlComputed = {};
|
|
15
15
|
(0, objectDefineProperty_js_1.objectDefineProperty)(pageContextUrlComputed, 'urlPathname', {
|
|
16
16
|
get: urlPathnameGetter,
|
|
@@ -130,37 +130,3 @@ function urlParsedGetter() {
|
|
|
130
130
|
}
|
|
131
131
|
return urlParsedEnhanced;
|
|
132
132
|
}
|
|
133
|
-
function assertPageContextUrl(pageContext) {
|
|
134
|
-
(0, utils_js_1.assert)(typeof pageContext.urlOriginal === 'string');
|
|
135
|
-
(0, utils_js_1.assert)(typeof pageContext.urlPathname === 'string');
|
|
136
|
-
(0, utils_js_1.assert)((0, utils_js_1.isPlainObject)(pageContext.urlParsed));
|
|
137
|
-
(0, utils_js_1.assert)(pageContext.urlPathname === pageContext.urlParsed.pathname);
|
|
138
|
-
assertPageContextUrlComputed(pageContext);
|
|
139
|
-
}
|
|
140
|
-
function assertPageContextUrlComputed(pageContext) {
|
|
141
|
-
/*
|
|
142
|
-
If the isPropertyGetter() assertions fail then it's most likely because Object.assign() was used instead of `objectAssign()`:
|
|
143
|
-
```js
|
|
144
|
-
const PageContextUrlComputed = getPageContextUrlComputed(pageContext)
|
|
145
|
-
|
|
146
|
-
// ❌ Breaks the property descriptors/getters of pageContext defined by getPageContextUrlComputed() such as pageContext.urlPathname
|
|
147
|
-
Object.assign(pageContext, pageContextUrlComputed)
|
|
148
|
-
|
|
149
|
-
// ❌ Also breaks property descriptors/getters
|
|
150
|
-
const pageContext = { ...pageContextUrlComputed }
|
|
151
|
-
|
|
152
|
-
// ✅ Preserves property descriptors/getters (see objectAssign() implementation)
|
|
153
|
-
objectAssign(pageContext, pageContextUrlComputed)
|
|
154
|
-
```
|
|
155
|
-
*/
|
|
156
|
-
if ('urlPathname' in pageContext) {
|
|
157
|
-
(0, utils_js_1.assert)(typeof pageContext.urlPathname === 'string');
|
|
158
|
-
(0, utils_js_1.assert)((0, utils_js_1.isPropertyGetter)(pageContext, 'urlPathname'));
|
|
159
|
-
(0, utils_js_1.assert)((0, utils_js_1.isPropertyGetter)(pageContext, 'urlParsed'));
|
|
160
|
-
(0, utils_js_1.assert)((0, utils_js_1.isPropertyGetter)(pageContext, 'url'));
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
(0, utils_js_1.assert)(!('urlParsed' in pageContext));
|
|
164
|
-
(0, utils_js_1.assert)(!('url' in pageContext));
|
|
165
|
-
}
|
|
166
|
-
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getProxyForPublicUsage = getProxyForPublicUsage;
|
|
4
|
+
// We use a proxy instead of property getters.
|
|
5
|
+
// - The issue with property getters is that they can't be `writable: true` but we do want the user to be able to modify the value of internal properties.
|
|
6
|
+
// ```console
|
|
7
|
+
// TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #<Object>
|
|
8
|
+
// ```
|
|
9
|
+
// - Previous implementation using property getters: https://github.com/vikejs/vike/blob/main/vike/utils/makePublicCopy.ts
|
|
10
|
+
// Show warning when user is accessing internal `_` properties.
|
|
11
|
+
const NOT_SERIALIZABLE_js_1 = require("./NOT_SERIALIZABLE.js");
|
|
12
|
+
const utils_js_1 = require("./utils.js");
|
|
13
|
+
function getProxyForPublicUsage(obj, objName, skipOnInternalProp, fallback) {
|
|
14
|
+
return new Proxy(obj, {
|
|
15
|
+
get: getTrapGet(obj, objName, skipOnInternalProp, fallback)
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function getTrapGet(obj, objName, skipOnInternalProp, fallback) {
|
|
19
|
+
return function (_, prop) {
|
|
20
|
+
const propStr = String(prop);
|
|
21
|
+
if (prop === '_isProxyObject')
|
|
22
|
+
return true;
|
|
23
|
+
if (!skipOnInternalProp)
|
|
24
|
+
onInternalProp(propStr, objName);
|
|
25
|
+
if (fallback && !(prop in obj)) {
|
|
26
|
+
// Rudimentary flat pageContext implementation https://github.com/vikejs/vike/issues/1268
|
|
27
|
+
// Failed full-fledged implementation: https://github.com/vikejs/vike/pull/2458
|
|
28
|
+
return fallback(prop);
|
|
29
|
+
}
|
|
30
|
+
const val = obj[prop];
|
|
31
|
+
onNotSerializable(propStr, val, objName);
|
|
32
|
+
return val;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function onNotSerializable(propStr, val, objName) {
|
|
36
|
+
if (val !== NOT_SERIALIZABLE_js_1.NOT_SERIALIZABLE)
|
|
37
|
+
return;
|
|
38
|
+
const propName = (0, utils_js_1.getPropAccessNotation)(propStr);
|
|
39
|
+
(0, utils_js_1.assert)((0, utils_js_1.isBrowser)());
|
|
40
|
+
(0, utils_js_1.assertUsage)(false, `Can't access ${objName}${propName} on the client side. Because it can't be serialized, see server logs.`);
|
|
41
|
+
}
|
|
42
|
+
function onInternalProp(propStr, objName) {
|
|
43
|
+
// - We must skip it in the client-side because of the reactivity mechanism of UI frameworks like Solid.
|
|
44
|
+
// - TO-DO/eventually: use import.meta.CLIENT instead of isBrowser()
|
|
45
|
+
// - Where import.meta.CLIENT is defined by Vike
|
|
46
|
+
// - Using import.meta.env.CLIENT (note `.env.`) doesn't seem possible: https://github.com/brillout/playground_node_import.meta.env
|
|
47
|
+
// - If Rolldown Vite + Rolldowns always transpiles node_modules/ then we can simply use import.meta.env.SSR
|
|
48
|
+
if ((0, utils_js_1.isBrowser)())
|
|
49
|
+
return;
|
|
50
|
+
// TODO/now remove this and only warn on built-in access instead
|
|
51
|
+
if (propStr === '_configFromHook')
|
|
52
|
+
return;
|
|
53
|
+
if (propStr.startsWith('_')) {
|
|
54
|
+
(0, utils_js_1.assertWarning)(false, `Using internal ${objName}.${propStr} which may break in any minor version update. Reach out on GitHub to request official support for your use case.`, { onlyOnce: true, showStackTrace: true });
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.execHook = execHook;
|
|
4
|
+
exports.execHookSingle = execHookSingle;
|
|
5
|
+
exports.execHookSingleWithReturn = execHookSingleWithReturn;
|
|
6
|
+
exports.execHookErrorHandling = execHookErrorHandling;
|
|
7
|
+
exports.execHooksErrorHandling = execHooksErrorHandling;
|
|
8
|
+
exports.execHookWithoutPageContext = execHookWithoutPageContext;
|
|
9
|
+
exports.execHookGlobal = execHookGlobal;
|
|
10
|
+
exports.execHookSync = execHookSync;
|
|
11
|
+
exports.getPageContext = getPageContext;
|
|
12
|
+
exports.providePageContext = providePageContext;
|
|
13
|
+
exports.isUserHookError = isUserHookError;
|
|
14
|
+
const assert_js_1 = require("../../utils/assert.js");
|
|
15
|
+
const getGlobalObject_js_1 = require("../../utils/getGlobalObject.js");
|
|
16
|
+
const humanizeTime_js_1 = require("../../utils/humanizeTime.js");
|
|
17
|
+
const isObject_js_1 = require("../../utils/isObject.js");
|
|
18
|
+
const getHook_js_1 = require("./getHook.js");
|
|
19
|
+
const preparePageContextForPublicUsage_js_1 = require("../preparePageContextForPublicUsage.js");
|
|
20
|
+
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/execHook.ts', {
|
|
21
|
+
userHookErrors: new WeakMap(),
|
|
22
|
+
pageContext: null
|
|
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
|
+
}
|
|
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) {
|
|
45
|
+
const hooks = (0, getHook_js_1.getHookFromPageContextNew)(hookName, pageContext);
|
|
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
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async function execHookGlobal(hookName, pageConfigGlobal, pageContext, hookArg, prepareForPublicUsage) {
|
|
71
|
+
const hooks = (0, getHook_js_1.getHookFromPageConfigGlobalCumulative)(pageConfigGlobal, hookName);
|
|
72
|
+
const hookArgForPublicUsage = prepareForPublicUsage(hookArg);
|
|
73
|
+
await Promise.all(hooks.map(async (hook) => {
|
|
74
|
+
await execHookAsync(() => hook.hookFn(hookArgForPublicUsage), hook, pageContext);
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
function isUserHookError(err) {
|
|
78
|
+
if (!(0, isObject_js_1.isObject)(err))
|
|
79
|
+
return false;
|
|
80
|
+
return globalObject.userHookErrors.get(err) ?? false;
|
|
81
|
+
}
|
|
82
|
+
async function execHookWithoutPageContext(hookFnCaller, hook) {
|
|
83
|
+
const { hookName, hookFilePath, hookTimeout } = hook;
|
|
84
|
+
const hookReturn = await execHookAsync(hookFnCaller, { hookName, hookFilePath, hookTimeout }, null);
|
|
85
|
+
return hookReturn;
|
|
86
|
+
}
|
|
87
|
+
function execHookAsync(hookFnCaller, hook, pageContextForPublicUsage) {
|
|
88
|
+
const { hookName, hookFilePath, hookTimeout: { error: timeoutErr, warning: timeoutWarn } } = hook;
|
|
89
|
+
let resolve;
|
|
90
|
+
let reject;
|
|
91
|
+
const promise = new Promise((resolve_, reject_) => {
|
|
92
|
+
resolve = (ret) => {
|
|
93
|
+
clearTimeouts();
|
|
94
|
+
resolve_(ret);
|
|
95
|
+
};
|
|
96
|
+
reject = (err) => {
|
|
97
|
+
clearTimeouts();
|
|
98
|
+
reject_(err);
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
const clearTimeouts = () => {
|
|
102
|
+
if (currentTimeoutWarn)
|
|
103
|
+
clearTimeout(currentTimeoutWarn);
|
|
104
|
+
if (currentTimeoutErr)
|
|
105
|
+
clearTimeout(currentTimeoutErr);
|
|
106
|
+
};
|
|
107
|
+
const currentTimeoutWarn = isNotDisabled(timeoutWarn) &&
|
|
108
|
+
setTimeout(() => {
|
|
109
|
+
(0, assert_js_1.assertWarning)(false, `The ${hookName}() hook defined by ${hookFilePath} is slow: it's taking more than ${(0, humanizeTime_js_1.humanizeTime)(timeoutWarn)} (https://vike.dev/hooksTimeout)`, { onlyOnce: false });
|
|
110
|
+
}, timeoutWarn);
|
|
111
|
+
const currentTimeoutErr = isNotDisabled(timeoutErr) &&
|
|
112
|
+
setTimeout(() => {
|
|
113
|
+
const err = (0, assert_js_1.getProjectError)(`The ${hookName}() hook defined by ${hookFilePath} timed out: it didn't finish after ${(0, humanizeTime_js_1.humanizeTime)(timeoutErr)} (https://vike.dev/hooksTimeout)`);
|
|
114
|
+
reject(err);
|
|
115
|
+
}, timeoutErr);
|
|
116
|
+
(async () => {
|
|
117
|
+
try {
|
|
118
|
+
providePageContextInternal(pageContextForPublicUsage);
|
|
119
|
+
const ret = await hookFnCaller();
|
|
120
|
+
resolve(ret);
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
if ((0, isObject_js_1.isObject)(err)) {
|
|
124
|
+
globalObject.userHookErrors.set(err, { hookName, hookFilePath });
|
|
125
|
+
}
|
|
126
|
+
reject(err);
|
|
127
|
+
}
|
|
128
|
+
})();
|
|
129
|
+
return promise;
|
|
130
|
+
}
|
|
131
|
+
function execHookSync(hook, pageContext, preparePageContextForPublicUsage) {
|
|
132
|
+
const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
|
|
133
|
+
providePageContextInternal(pageContextForPublicUsage);
|
|
134
|
+
const hookReturn = hook.hookFn(pageContextForPublicUsage);
|
|
135
|
+
return { hookReturn };
|
|
136
|
+
}
|
|
137
|
+
function isNotDisabled(timeout) {
|
|
138
|
+
return !!timeout && timeout !== Infinity;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Access `pageContext` object inside Vike hooks, in order to create universal hooks.
|
|
142
|
+
*
|
|
143
|
+
* https://vike.dev/getPageContext
|
|
144
|
+
*/
|
|
145
|
+
function getPageContext() {
|
|
146
|
+
const { pageContext } = globalObject;
|
|
147
|
+
if (!pageContext)
|
|
148
|
+
return null;
|
|
149
|
+
const pageContextForPublicUsage = pageContext._isProxyObject
|
|
150
|
+
? // providePageContext() is called on the user-land (e.g. it's called by `vike-{react,vue,solid}`) thus it's already a proxy
|
|
151
|
+
pageContext
|
|
152
|
+
: (0, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage)(pageContext);
|
|
153
|
+
return pageContextForPublicUsage;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Provide `pageContext` for universal hooks.
|
|
157
|
+
*
|
|
158
|
+
* https://vike.dev/getPageContext
|
|
159
|
+
*/
|
|
160
|
+
function providePageContext(pageContext) {
|
|
161
|
+
providePageContextInternal(pageContext);
|
|
162
|
+
}
|
|
163
|
+
function providePageContextInternal(pageContext) {
|
|
164
|
+
globalObject.pageContext = pageContext;
|
|
165
|
+
// Promise.resolve() is quicker than process.nextTick() and setImmediate()
|
|
166
|
+
// https://stackoverflow.com/questions/67949576/process-nexttick-before-promise-resolve-then
|
|
167
|
+
Promise.resolve().then(() => {
|
|
168
|
+
globalObject.pageContext = null;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
@@ -4,10 +4,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getHookFromPageContext = getHookFromPageContext;
|
|
7
|
+
exports.getHookFromPageContextNew = getHookFromPageContextNew;
|
|
7
8
|
exports.getHookFromPageConfig = getHookFromPageConfig;
|
|
8
9
|
exports.getHookFromPageConfigGlobal = getHookFromPageConfigGlobal;
|
|
9
10
|
exports.getHookFromPageConfigGlobalCumulative = getHookFromPageConfigGlobalCumulative;
|
|
10
|
-
exports.assertHook = assertHook;
|
|
11
11
|
exports.getHook_setIsPrerenderering = getHook_setIsPrerenderering;
|
|
12
12
|
exports.getHookTimeoutDefault = getHookTimeoutDefault;
|
|
13
13
|
const getGlobalObject_js_1 = require("../../utils/getGlobalObject.js");
|
|
@@ -25,12 +25,34 @@ function getHookFromPageContext(pageContext, hookName) {
|
|
|
25
25
|
const hookFn = pageContext.exports[hookName];
|
|
26
26
|
if (hookFn === null)
|
|
27
27
|
return null;
|
|
28
|
+
// TO-DO/eventually: use pageContext.configEntries in favor of pageContext.exportsAll once V0.4 is removed
|
|
28
29
|
const file = pageContext.exportsAll[hookName][0];
|
|
29
30
|
(0, utils_js_1.assert)(file.exportValue === hookFn);
|
|
30
31
|
const hookFilePath = file.filePath;
|
|
31
32
|
(0, utils_js_1.assert)(hookFilePath);
|
|
32
33
|
return getHook(hookFn, hookName, hookFilePath, hookTimeout);
|
|
33
34
|
}
|
|
35
|
+
// TO-DO/eventually: remove getHookFromPageContext() in favor of getHookFromPageContextNew()
|
|
36
|
+
function getHookFromPageContextNew(hookName, pageContext) {
|
|
37
|
+
const { hooksTimeout } = pageContext.config;
|
|
38
|
+
const hookTimeout = getHookTimeout(hooksTimeout, hookName);
|
|
39
|
+
const hooks = [];
|
|
40
|
+
/* TO-DO/eventually: use pageContext.configEntries in favor of pageContext.exportsAll once V0.4 is removed
|
|
41
|
+
pageContext.configEntries[hookName]?.forEach((val) => {
|
|
42
|
+
const hookFn = val.configValue
|
|
43
|
+
if (hookFn === null) return
|
|
44
|
+
const hookFilePath = val.configDefinedByFile
|
|
45
|
+
*/
|
|
46
|
+
pageContext.exportsAll[hookName]?.forEach((val) => {
|
|
47
|
+
const hookFn = val.exportValue;
|
|
48
|
+
if (hookFn === null)
|
|
49
|
+
return;
|
|
50
|
+
const hookFilePath = val.filePath;
|
|
51
|
+
(0, utils_js_1.assert)(hookFilePath);
|
|
52
|
+
hooks.push(getHook(hookFn, hookName, hookFilePath, hookTimeout));
|
|
53
|
+
});
|
|
54
|
+
return hooks;
|
|
55
|
+
}
|
|
34
56
|
function getHookFromPageConfig(pageConfig, hookName) {
|
|
35
57
|
const configValue = (0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, hookName);
|
|
36
58
|
if (!configValue?.value)
|
|
@@ -79,9 +101,6 @@ function getHookFromConfigValue(configValue) {
|
|
|
79
101
|
const hookFilePath = (0, helpers_js_1.getHookFilePathToShowToUser)(configValue.definedAtData);
|
|
80
102
|
return { hookFn, hookFilePath };
|
|
81
103
|
}
|
|
82
|
-
function assertHook(pageContext, hookName) {
|
|
83
|
-
getHookFromPageContext(pageContext, hookName);
|
|
84
|
-
}
|
|
85
104
|
function assertHookFn(hookFn, { hookName, hookFilePath }) {
|
|
86
105
|
(0, utils_js_1.assert)(hookName && hookFilePath);
|
|
87
106
|
(0, utils_js_1.assert)(!hookName.endsWith(')'));
|