vike 0.4.229 → 0.4.230
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/index.js +3 -1
- 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/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/transpileAndExecuteFile.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +12 -6
- 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 +1 -1
- 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/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/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 +1 -2
- package/dist/esm/node/plugin/index.js +3 -1
- 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/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/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 -6
- 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 +1 -1
- 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/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/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
package/dist/cjs/shared/page-configs/{getPageConfigUserFriendly.js → getUserFriendlyConfigs.js}
RENAMED
|
@@ -3,16 +3,16 @@ 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.
|
|
7
|
-
exports.
|
|
8
|
-
exports.
|
|
6
|
+
exports.getUserFriendlyConfigsGlobal = getUserFriendlyConfigsGlobal;
|
|
7
|
+
exports.getUserFriendlyConfigsPageEager = getUserFriendlyConfigsPageEager;
|
|
8
|
+
exports.getUserFriendlyConfigsPageLazy = getUserFriendlyConfigsPageLazy;
|
|
9
9
|
const assert_exports_old_design_js_1 = require("../getPageFiles/assert_exports_old_design.js");
|
|
10
10
|
const getConfigDefinedAt_js_1 = require("./getConfigDefinedAt.js");
|
|
11
11
|
const helpers_js_1 = require("./helpers.js");
|
|
12
12
|
const utils_js_1 = require("../utils.js");
|
|
13
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
|
-
function
|
|
15
|
-
const pageConfigUserFriendly =
|
|
14
|
+
function getUserFriendlyConfigsPageEager(pageConfigGlobalValues, pageConfig, pageConfigValues) {
|
|
15
|
+
const pageConfigUserFriendly = getUserFriendlyConfigs_public({ pageConfigGlobalValues, pageConfigValues });
|
|
16
16
|
let page;
|
|
17
17
|
if (!pageConfig.isErrorPage) {
|
|
18
18
|
const route = pageConfigUserFriendly.config.route ?? pageConfig.routeFilesystem.routeString;
|
|
@@ -29,8 +29,8 @@ function getPageConfigUserFriendly(pageConfigGlobalValues, pageConfig, pageConfi
|
|
|
29
29
|
}
|
|
30
30
|
return [pageConfig.pageId, page];
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
const pageConfigUserFriendly =
|
|
32
|
+
function getUserFriendlyConfigs_public({ pageConfigGlobalValues, pageConfigValues }) {
|
|
33
|
+
const pageConfigUserFriendly = getUserFriendlyConfigs_base({ pageConfigGlobalValues, pageConfigValues });
|
|
34
34
|
return getPublicCopy(pageConfigUserFriendly);
|
|
35
35
|
}
|
|
36
36
|
function getPublicCopy(pageConfigUserFriendly) {
|
|
@@ -42,15 +42,17 @@ function getPublicCopy(pageConfigUserFriendly) {
|
|
|
42
42
|
_from: p.from
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function getUserFriendlyConfigs_base({ pageConfigGlobalValues, pageConfigValues }) {
|
|
46
46
|
const configValues = { ...pageConfigGlobalValues, ...pageConfigValues };
|
|
47
|
-
return
|
|
47
|
+
return getUserFriendlyConfigs_V1Design({ configValues });
|
|
48
48
|
}
|
|
49
|
-
function
|
|
50
|
-
const pageConfigGlobalUserFriendly =
|
|
49
|
+
function getUserFriendlyConfigsGlobal({ pageConfigGlobalValues }) {
|
|
50
|
+
const pageConfigGlobalUserFriendly = getUserFriendlyConfigs_V1Design({ configValues: pageConfigGlobalValues });
|
|
51
51
|
return getPublicCopy(pageConfigGlobalUserFriendly);
|
|
52
52
|
}
|
|
53
|
-
function
|
|
53
|
+
function getUserFriendlyConfigsPageLazy(pageFiles, // V0.4 design
|
|
54
|
+
pageConfig, // V1 design
|
|
55
|
+
pageConfigGlobal) {
|
|
54
56
|
const config = {};
|
|
55
57
|
const configEntries = {}; // TODO/v1-release: remove
|
|
56
58
|
const exportsAll = {}; // TODO/v1-release: remove
|
|
@@ -75,7 +77,7 @@ function getPageConfigUserFriendly_oldDesign(pageFiles, pageConfig, pageConfigGl
|
|
|
75
77
|
let sources;
|
|
76
78
|
let from;
|
|
77
79
|
if (pageConfig) {
|
|
78
|
-
const res =
|
|
80
|
+
const res = getUserFriendlyConfigs_base({
|
|
79
81
|
pageConfigGlobalValues: pageConfigGlobal.configValues,
|
|
80
82
|
pageConfigValues: pageConfig.configValues
|
|
81
83
|
});
|
|
@@ -95,7 +97,7 @@ function getPageConfigUserFriendly_oldDesign(pageFiles, pageConfig, pageConfigGl
|
|
|
95
97
|
configsComputed: {}
|
|
96
98
|
};
|
|
97
99
|
}
|
|
98
|
-
const pageExports =
|
|
100
|
+
const pageExports = {};
|
|
99
101
|
const exports = {};
|
|
100
102
|
Object.entries(exportsAll).forEach(([exportName, values]) => {
|
|
101
103
|
values.forEach(({ exportValue, _fileType, _isFromDefaultExport }) => {
|
|
@@ -118,13 +120,27 @@ function getPageConfigUserFriendly_oldDesign(pageFiles, pageConfig, pageConfigGl
|
|
|
118
120
|
// TODO/eventually: deprecate/remove every prop below
|
|
119
121
|
configEntries,
|
|
120
122
|
exports,
|
|
121
|
-
exportsAll
|
|
122
|
-
pageExports
|
|
123
|
+
exportsAll
|
|
123
124
|
};
|
|
125
|
+
// TODO/v1-release: remove
|
|
126
|
+
(0, utils_js_1.objectDefineProperty)(pageContextExports, 'pageExports', {
|
|
127
|
+
get: () => {
|
|
128
|
+
// 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.
|
|
129
|
+
if (!(0, utils_js_1.isBrowser)()) {
|
|
130
|
+
(0, utils_js_1.assertWarning)(false, 'pageContext.pageExports is outdated, use pageContext.exports instead', {
|
|
131
|
+
onlyOnce: true,
|
|
132
|
+
showStackTrace: true
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return pageExports;
|
|
136
|
+
},
|
|
137
|
+
enumerable: false,
|
|
138
|
+
configurable: true
|
|
139
|
+
});
|
|
124
140
|
return pageContextExports;
|
|
125
141
|
}
|
|
126
142
|
// V1 design
|
|
127
|
-
function
|
|
143
|
+
function getUserFriendlyConfigs_V1Design(pageConfig) {
|
|
128
144
|
const config = {};
|
|
129
145
|
const configEntries = {};
|
|
130
146
|
const exportsAll = {};
|
|
@@ -140,19 +156,30 @@ function getPageConfigUserFriendly_V1Design(pageConfig) {
|
|
|
140
156
|
sources[configName] ?? (sources[configName] = []);
|
|
141
157
|
sources[configName].push(src);
|
|
142
158
|
};
|
|
143
|
-
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAtOptional)('Config', configName, configValue.definedAtData);
|
|
147
|
-
config[configName] = config[configName] ?? value;
|
|
159
|
+
const addLegacy = (configName, value, definedAtData) => {
|
|
160
|
+
const configValueFilePathToShowToUser = (0, helpers_js_1.getConfigValueFilePathToShowToUser)(definedAtData);
|
|
161
|
+
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAtOptional)('Config', configName, definedAtData);
|
|
148
162
|
configEntries[configName] = configEntries[configName] ?? [];
|
|
149
|
-
// Currently each configName has only one entry. Adding an entry for each overriden config value isn't implemented yet. (This is an isomorphic file and it isn't clear whether this can/should be implemented on the client-side. We should load a minimum amount of code on the client-side.)
|
|
150
|
-
(0, utils_js_1.assert)(configEntries[configName].length === 0);
|
|
151
163
|
configEntries[configName].push({
|
|
152
164
|
configValue: value,
|
|
153
165
|
configDefinedAt,
|
|
154
166
|
configDefinedByFile: configValueFilePathToShowToUser
|
|
155
167
|
});
|
|
168
|
+
// TODO/v1-release: remove
|
|
169
|
+
const exportName = configName;
|
|
170
|
+
exportsAll[exportName] = exportsAll[exportName] ?? [];
|
|
171
|
+
exportsAll[exportName].push({
|
|
172
|
+
exportValue: value,
|
|
173
|
+
exportSource: configDefinedAt,
|
|
174
|
+
filePath: configValueFilePathToShowToUser,
|
|
175
|
+
_filePath: configValueFilePathToShowToUser,
|
|
176
|
+
_fileType: null,
|
|
177
|
+
_isFromDefaultExport: null
|
|
178
|
+
});
|
|
179
|
+
};
|
|
180
|
+
Object.entries(pageConfig.configValues).forEach(([configName, configValue]) => {
|
|
181
|
+
const { value } = configValue;
|
|
182
|
+
config[configName] = config[configName] ?? value;
|
|
156
183
|
if (configValue.type === 'standard') {
|
|
157
184
|
const src = {
|
|
158
185
|
type: 'configsStandard',
|
|
@@ -161,6 +188,7 @@ function getPageConfigUserFriendly_V1Design(pageConfig) {
|
|
|
161
188
|
};
|
|
162
189
|
addSrc(src, configName);
|
|
163
190
|
from.configsStandard[configName] = src;
|
|
191
|
+
addLegacy(configName, value, configValue.definedAtData);
|
|
164
192
|
}
|
|
165
193
|
if (configValue.type === 'cumulative') {
|
|
166
194
|
const src = {
|
|
@@ -169,6 +197,7 @@ function getPageConfigUserFriendly_V1Design(pageConfig) {
|
|
|
169
197
|
const definedAtFile = configValue.definedAtData[i];
|
|
170
198
|
(0, utils_js_1.assert)(definedAtFile);
|
|
171
199
|
const definedAt = (0, getConfigDefinedAt_js_1.getDefinedAtString)(definedAtFile, configName);
|
|
200
|
+
addLegacy(configName, value, definedAtFile);
|
|
172
201
|
return {
|
|
173
202
|
value,
|
|
174
203
|
definedAt
|
|
@@ -185,18 +214,8 @@ function getPageConfigUserFriendly_V1Design(pageConfig) {
|
|
|
185
214
|
};
|
|
186
215
|
addSrc(src, configName);
|
|
187
216
|
from.configsComputed[configName] = src;
|
|
217
|
+
addLegacy(configName, value, configValue.definedAtData);
|
|
188
218
|
}
|
|
189
|
-
// TODO/v1-release: remove
|
|
190
|
-
const exportName = configName;
|
|
191
|
-
exportsAll[exportName] = exportsAll[exportName] ?? [];
|
|
192
|
-
exportsAll[exportName].push({
|
|
193
|
-
exportValue: value,
|
|
194
|
-
exportSource: configDefinedAt,
|
|
195
|
-
filePath: configValueFilePathToShowToUser,
|
|
196
|
-
_filePath: configValueFilePathToShowToUser,
|
|
197
|
-
_fileType: null,
|
|
198
|
-
_isFromDefaultExport: null
|
|
199
|
-
});
|
|
200
219
|
});
|
|
201
220
|
return {
|
|
202
221
|
config: config,
|
|
@@ -244,15 +263,3 @@ function getExportValues(pageFile) {
|
|
|
244
263
|
});
|
|
245
264
|
return exportValues;
|
|
246
265
|
}
|
|
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 (!(0, utils_js_1.isBrowser)()) {
|
|
253
|
-
(0, utils_js_1.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,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prepareGlobalContextForPublicUsage = prepareGlobalContextForPublicUsage;
|
|
4
|
+
const getProxyForPublicUsage_js_1 = require("./getProxyForPublicUsage.js");
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
function prepareGlobalContextForPublicUsage(globalContext) {
|
|
7
|
+
(0, utils_js_1.assert)(globalContext._isOriginalObject); // ensure we preserve the original object reference
|
|
8
|
+
const globalContextPublic = (0, getProxyForPublicUsage_js_1.getProxyForPublicUsage)(globalContext, 'globalContext');
|
|
9
|
+
return globalContextPublic;
|
|
10
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.preparePageContextForPublicUsage = preparePageContextForPublicUsage;
|
|
4
|
+
exports.assertPropertyGetters = assertPropertyGetters;
|
|
5
|
+
const utils_js_1 = require("./utils.js");
|
|
6
|
+
const addIs404ToPageProps_js_1 = require("./addIs404ToPageProps.js");
|
|
7
|
+
const prepareGlobalContextForPublicUsage_js_1 = require("./prepareGlobalContextForPublicUsage.js");
|
|
8
|
+
const getProxyForPublicUsage_js_1 = require("./getProxyForPublicUsage.js");
|
|
9
|
+
function preparePageContextForPublicUsage(pageContext) {
|
|
10
|
+
(0, utils_js_1.assert)(!pageContext._isProxyObject);
|
|
11
|
+
(0, utils_js_1.assert)(!pageContext.globalContext); // pageContext.globalContext should only be available to users — Vike itself should use pageContext._globalContext instead
|
|
12
|
+
(0, utils_js_1.assert)(pageContext._isOriginalObject); // ensure we preserve the original object reference
|
|
13
|
+
(0, addIs404ToPageProps_js_1.addIs404ToPageProps)(pageContext);
|
|
14
|
+
// TODO/next-major-release: remove
|
|
15
|
+
if (!('_pageId' in pageContext)) {
|
|
16
|
+
Object.defineProperty(pageContext, '_pageId', {
|
|
17
|
+
get() {
|
|
18
|
+
(0, utils_js_1.assertWarning)(false, 'pageContext._pageId has been renamed to pageContext.pageId', {
|
|
19
|
+
showStackTrace: true,
|
|
20
|
+
onlyOnce: true
|
|
21
|
+
});
|
|
22
|
+
return pageContext.pageId;
|
|
23
|
+
},
|
|
24
|
+
enumerable: false
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// For a more readable `console.log(pageContext)` output
|
|
28
|
+
sortPageContext(pageContext);
|
|
29
|
+
const globalContextPublic = (0, prepareGlobalContextForPublicUsage_js_1.prepareGlobalContextForPublicUsage)(pageContext._globalContext);
|
|
30
|
+
const pageContextPublic = (0, getProxyForPublicUsage_js_1.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, (prop) => {
|
|
34
|
+
if (prop === 'globalContext') {
|
|
35
|
+
return globalContextPublic;
|
|
36
|
+
}
|
|
37
|
+
if (prop in globalContextPublic) {
|
|
38
|
+
return globalContextPublic[prop];
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
return pageContextPublic;
|
|
42
|
+
}
|
|
43
|
+
// Sort `pageContext` keys alphabetically, in order to make reading the `console.log(pageContext)` output easier
|
|
44
|
+
function sortPageContext(pageContext) {
|
|
45
|
+
let descriptors = Object.getOwnPropertyDescriptors(pageContext);
|
|
46
|
+
for (const key of Object.keys(pageContext))
|
|
47
|
+
delete pageContext[key];
|
|
48
|
+
descriptors = Object.fromEntries(Object.entries(descriptors).sort(([key1], [key2]) => (0, utils_js_1.compareString)(key1, key2)));
|
|
49
|
+
Object.defineProperties(pageContext, descriptors);
|
|
50
|
+
}
|
|
51
|
+
function assertPropertyGetters(pageContext) {
|
|
52
|
+
/*
|
|
53
|
+
If the isPropertyGetter() assertions fail then it's most likely because Object.assign() was used instead of `objectAssign()`:
|
|
54
|
+
```js
|
|
55
|
+
const PageContextUrlComputed = getPageContextUrlComputed(pageContext)
|
|
56
|
+
|
|
57
|
+
// ❌ Breaks the property descriptors/getters of pageContext defined by getPageContextUrlComputed() such as pageContext.urlPathname
|
|
58
|
+
Object.assign(pageContext, pageContextUrlComputed)
|
|
59
|
+
|
|
60
|
+
// ❌ Also breaks property descriptors/getters
|
|
61
|
+
const pageContext = { ...pageContextUrlComputed }
|
|
62
|
+
|
|
63
|
+
// ✅ Preserves property descriptors/getters (see objectAssign() implementation)
|
|
64
|
+
objectAssign(pageContext, pageContextUrlComputed)
|
|
65
|
+
```
|
|
66
|
+
*/
|
|
67
|
+
;
|
|
68
|
+
[
|
|
69
|
+
'urlPathname',
|
|
70
|
+
// TODO/v1-release: remove
|
|
71
|
+
'urlParsed',
|
|
72
|
+
// TODO/v1-release: remove
|
|
73
|
+
'url',
|
|
74
|
+
// TODO/v1-release: remove
|
|
75
|
+
'pageExports'
|
|
76
|
+
].forEach((prop) => {
|
|
77
|
+
if (pageContext.prop)
|
|
78
|
+
(0, utils_js_1.assert)((0, utils_js_1.isPropertyGetter)(pageContext, prop));
|
|
79
|
+
});
|
|
80
|
+
}
|
|
@@ -12,7 +12,7 @@ exports.logAbortErrorHandled = logAbortErrorHandled;
|
|
|
12
12
|
exports.getPageContextFromAllRewrites = getPageContextFromAllRewrites;
|
|
13
13
|
exports.AbortRender = AbortRender;
|
|
14
14
|
exports.assertNoInfiniteAbortLoop = assertNoInfiniteAbortLoop;
|
|
15
|
-
const
|
|
15
|
+
const execHook_js_1 = require("../hooks/execHook.js");
|
|
16
16
|
const utils_js_1 = require("./utils.js");
|
|
17
17
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
18
18
|
/**
|
|
@@ -124,7 +124,7 @@ function logAbortErrorHandled(err, isProduction, pageContext) {
|
|
|
124
124
|
(0, utils_js_1.assert)(urlCurrent);
|
|
125
125
|
const abortCall = err._pageContextAbort._abortCall;
|
|
126
126
|
(0, utils_js_1.assert)(abortCall);
|
|
127
|
-
const hookLoc = (0,
|
|
127
|
+
const hookLoc = (0, execHook_js_1.isUserHookError)(err);
|
|
128
128
|
let thrownBy = '';
|
|
129
129
|
if (hookLoc) {
|
|
130
130
|
thrownBy = ` by ${picocolors_1.default.cyan(`${hookLoc.hookName}()`)} hook defined at ${hookLoc.hookFilePath}`;
|
|
@@ -1,13 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.debug = debug;
|
|
4
|
-
|
|
4
|
+
exports.setCreateDebugger = setCreateDebugger;
|
|
5
|
+
// Using createDebugger() for isomorphic code without bloating the client-side.
|
|
6
|
+
// On the server-side, this is just a transparent proxy.
|
|
7
|
+
// On the client-side, this is an emtpy shell.
|
|
8
|
+
const getGlobalObject_js_1 = require("../../utils/getGlobalObject.js");
|
|
9
|
+
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('route/debug.ts', {});
|
|
5
10
|
function debug(...args) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (
|
|
11
|
-
|
|
11
|
+
// Client-side => does nothing
|
|
12
|
+
if (!globalObject.createDebugger)
|
|
13
|
+
return;
|
|
14
|
+
// Server-side => just a proxy
|
|
15
|
+
if (!globalObject.debug) {
|
|
16
|
+
globalObject.debug = globalObject.createDebugger('vike:routing');
|
|
12
17
|
}
|
|
18
|
+
globalObject.debug(...args);
|
|
19
|
+
}
|
|
20
|
+
// Called only on the server-side
|
|
21
|
+
function setCreateDebugger(createDebugger) {
|
|
22
|
+
globalObject.createDebugger = createDebugger;
|
|
13
23
|
}
|
|
@@ -3,11 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.executeGuardHook = executeGuardHook;
|
|
4
4
|
const getHook_js_1 = require("../hooks/getHook.js");
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
|
-
const
|
|
6
|
+
const execHook_js_1 = require("../hooks/execHook.js");
|
|
7
7
|
const errIntro = 'The guard() hook defined by';
|
|
8
|
-
async function executeGuardHook(pageContext,
|
|
8
|
+
async function executeGuardHook(pageContext, prepareForPublicUsage) {
|
|
9
9
|
let hook;
|
|
10
10
|
if (pageContext._pageFilesAll.length > 0) {
|
|
11
|
+
// TODO/v1-release: remove
|
|
11
12
|
// V0.4 design
|
|
12
13
|
(0, utils_js_1.assert)(pageContext._pageConfigs.length === 0);
|
|
13
14
|
hook = findPageGuard(pageContext.pageId, pageContext._pageFilesAll);
|
|
@@ -18,13 +19,7 @@ async function executeGuardHook(pageContext, prepareForUserConsumption) {
|
|
|
18
19
|
}
|
|
19
20
|
if (!hook)
|
|
20
21
|
return;
|
|
21
|
-
|
|
22
|
-
let pageContextForUserConsumption = pageContext;
|
|
23
|
-
const res = prepareForUserConsumption(pageContext);
|
|
24
|
-
if (res)
|
|
25
|
-
pageContextForUserConsumption = res;
|
|
26
|
-
const hookResult = await (0, executeHook_js_1.executeHook)(() => guard(pageContextForUserConsumption), hook, pageContext);
|
|
27
|
-
(0, utils_js_1.assertUsage)(hookResult === undefined, `${errIntro} ${hook.hookFilePath} returns a value, but guard() shouldn't return any value`);
|
|
22
|
+
await (0, execHook_js_1.execHookSingle)(hook, pageContext, prepareForPublicUsage);
|
|
28
23
|
}
|
|
29
24
|
function findPageGuard(pageId, pageFilesAll) {
|
|
30
25
|
const pageRouteFile = pageFilesAll.find((p) => p.pageId === pageId && p.fileType === '.page.route');
|
|
@@ -8,7 +8,8 @@ const assertPageContextProvidedByUser_js_1 = require("../assertPageContextProvid
|
|
|
8
8
|
const utils_js_1 = require("./utils.js");
|
|
9
9
|
const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
|
|
10
10
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
|
-
const
|
|
11
|
+
const execHook_js_1 = require("../hooks/execHook.js");
|
|
12
|
+
const preparePageContextForPublicUsage_js_1 = require("../preparePageContextForPublicUsage.js");
|
|
12
13
|
async function executeOnBeforeRouteHook(pageContext) {
|
|
13
14
|
const pageContextFromOnBeforeRouteHook = {};
|
|
14
15
|
if (!pageContext._onBeforeRouteHook)
|
|
@@ -38,10 +39,10 @@ async function executeOnBeforeRouteHook(pageContext) {
|
|
|
38
39
|
return pageContextFromOnBeforeRouteHook;
|
|
39
40
|
}
|
|
40
41
|
async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
|
|
41
|
-
let hookReturn =
|
|
42
|
+
let { hookReturn } = (0, execHook_js_1.execHookSync)(onBeforeRouteHook, pageContext, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage);
|
|
42
43
|
(0, resolveRouteFunction_js_1.assertSyncRouting)(hookReturn, `The onBeforeRoute() hook ${onBeforeRouteHook.hookFilePath}`);
|
|
43
44
|
// TODO/v1-release: make executeOnBeforeRouteHook() and route() sync
|
|
44
|
-
hookReturn = await
|
|
45
|
+
hookReturn = await hookReturn;
|
|
45
46
|
const errPrefix = `The onBeforeRoute() hook defined by ${onBeforeRouteHook.hookFilePath}`;
|
|
46
47
|
(0, utils_js_1.assertUsage)(hookReturn === null ||
|
|
47
48
|
hookReturn === undefined ||
|
|
@@ -11,7 +11,6 @@ if ((0, isBrowser_js_1.isBrowser)()) {
|
|
|
11
11
|
(0, assertRoutingType_js_1.assertClientRouting)();
|
|
12
12
|
}
|
|
13
13
|
const utils_js_1 = require("./utils.js");
|
|
14
|
-
const getPageContextUrlComputed_js_1 = require("../getPageContextUrlComputed.js");
|
|
15
14
|
const resolvePrecedence_js_1 = require("./resolvePrecedence.js");
|
|
16
15
|
const resolveRouteString_js_1 = require("./resolveRouteString.js");
|
|
17
16
|
const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
|
|
@@ -20,7 +19,6 @@ const debug_js_1 = require("./debug.js");
|
|
|
20
19
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
21
20
|
async function route(pageContext, skipOnBeforeRouteHook) {
|
|
22
21
|
(0, debug_js_1.debug)('Pages routes:', pageContext._pageRoutes);
|
|
23
|
-
(0, getPageContextUrlComputed_js_1.assertPageContextUrl)(pageContext);
|
|
24
22
|
const pageContextFromRoute = {};
|
|
25
23
|
// onBeforeRoute()
|
|
26
24
|
if (!skipOnBeforeRouteHook) {
|
|
@@ -74,8 +72,8 @@ async function route(pageContext, skipOnBeforeRouteHook) {
|
|
|
74
72
|
}
|
|
75
73
|
// Route Function defined in `.page.route.js`
|
|
76
74
|
if (pageRoute.routeType === 'FUNCTION') {
|
|
77
|
-
const { routeFunction,
|
|
78
|
-
const match = await (0, resolveRouteFunction_js_1.resolveRouteFunction)(routeFunction, pageContext,
|
|
75
|
+
const { routeFunction, routeFunctionFilePath } = pageRoute;
|
|
76
|
+
const match = await (0, resolveRouteFunction_js_1.resolveRouteFunction)(routeFunction, pageContext, routeFunctionFilePath);
|
|
79
77
|
if (match) {
|
|
80
78
|
const { routeParams, precedence } = match;
|
|
81
79
|
routeMatches.push({ pageId, precedence, routeParams, routeType });
|
|
@@ -46,6 +46,10 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
else {
|
|
49
|
+
const { definedAtData } = configValue;
|
|
50
|
+
(0, utils_js_1.assert)(!(0, utils_js_2.isArray)(definedAtData) && !definedAtData.definedBy);
|
|
51
|
+
const { filePathToShowToUser } = definedAtData;
|
|
52
|
+
(0, utils_js_1.assert)(filePathToShowToUser);
|
|
49
53
|
(0, utils_js_1.assert)((0, utils_js_2.isCallable)(route));
|
|
50
54
|
// TODO/next-major: remove
|
|
51
55
|
if ((0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, 'iKnowThePerformanceRisksOfAsyncRouteFunctions', 'boolean'))
|
|
@@ -54,6 +58,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
54
58
|
pageId,
|
|
55
59
|
comesFromV1PageConfig,
|
|
56
60
|
routeFunction: route,
|
|
61
|
+
routeFunctionFilePath: filePathToShowToUser,
|
|
57
62
|
routeDefinedAtString: definedAtString,
|
|
58
63
|
routeType: 'FUNCTION'
|
|
59
64
|
};
|
|
@@ -127,6 +132,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
127
132
|
pageId,
|
|
128
133
|
comesFromV1PageConfig,
|
|
129
134
|
routeFunction,
|
|
135
|
+
routeFunctionFilePath: filePath,
|
|
130
136
|
routeDefinedAtString: filePath,
|
|
131
137
|
routeType: 'FUNCTION'
|
|
132
138
|
});
|
|
@@ -7,13 +7,17 @@ exports.resolveRouteFunction = resolveRouteFunction;
|
|
|
7
7
|
exports.assertRouteParams = assertRouteParams;
|
|
8
8
|
exports.assertSyncRouting = assertSyncRouting;
|
|
9
9
|
exports.warnDeprecatedAllowKey = warnDeprecatedAllowKey;
|
|
10
|
-
const
|
|
10
|
+
const execHook_js_1 = require("../hooks/execHook.js");
|
|
11
|
+
const preparePageContextForPublicUsage_js_1 = require("../preparePageContextForPublicUsage.js");
|
|
11
12
|
const utils_js_1 = require("./utils.js");
|
|
12
13
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
|
-
async function resolveRouteFunction(routeFunction, pageContext,
|
|
14
|
-
(0,
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
async function resolveRouteFunction(routeFunction, pageContext, routeFunctionFilePath) {
|
|
15
|
+
let { hookReturn: result } = (0, execHook_js_1.execHookSync)({
|
|
16
|
+
hookFn: routeFunction,
|
|
17
|
+
hookFilePath: routeFunctionFilePath,
|
|
18
|
+
hookName: 'route'
|
|
19
|
+
}, pageContext, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage);
|
|
20
|
+
assertSyncRouting(result, `The Route Function ${routeFunctionFilePath}`);
|
|
17
21
|
// TODO/v1-release: make resolveRouteFunction() and route() sync
|
|
18
22
|
//* 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
|
|
19
23
|
result = await result;
|
|
@@ -24,11 +28,11 @@ async function resolveRouteFunction(routeFunction, pageContext, routeDefinedAtSt
|
|
|
24
28
|
if (result === true) {
|
|
25
29
|
result = {};
|
|
26
30
|
}
|
|
27
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.isPlainObject)(result), `The Route Function ${
|
|
31
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isPlainObject)(result), `The Route Function ${routeFunctionFilePath} should return a boolean or a plain JavaScript object (but it's ${picocolors_1.default.cyan(`typeof result === ${JSON.stringify(typeof result)}`)} instead)`);
|
|
28
32
|
// AFAICT this return interface is superfluous. Should we soft-deprecate it and remove it?
|
|
29
33
|
if ('match' in result) {
|
|
30
34
|
const { match } = result;
|
|
31
|
-
(0, utils_js_1.assertUsage)(typeof match === 'boolean', `The ${picocolors_1.default.cyan('match')} value returned by the Route Function ${
|
|
35
|
+
(0, utils_js_1.assertUsage)(typeof match === 'boolean', `The ${picocolors_1.default.cyan('match')} value returned by the Route Function ${routeFunctionFilePath} should be a boolean.`);
|
|
32
36
|
if (!match) {
|
|
33
37
|
return null;
|
|
34
38
|
}
|
|
@@ -36,14 +40,14 @@ async function resolveRouteFunction(routeFunction, pageContext, routeDefinedAtSt
|
|
|
36
40
|
let precedence = null;
|
|
37
41
|
if ('precedence' in result) {
|
|
38
42
|
precedence = result.precedence;
|
|
39
|
-
(0, utils_js_1.assertUsage)(typeof precedence === 'number', `The ${picocolors_1.default.cyan('precedence')} value returned by the Route Function ${
|
|
43
|
+
(0, utils_js_1.assertUsage)(typeof precedence === 'number', `The ${picocolors_1.default.cyan('precedence')} value returned by the Route Function ${routeFunctionFilePath} should be a number.`);
|
|
40
44
|
}
|
|
41
|
-
assertRouteParams(result, `The ${picocolors_1.default.cyan('routeParams')} object returned by the Route Function ${
|
|
45
|
+
assertRouteParams(result, `The ${picocolors_1.default.cyan('routeParams')} object returned by the Route Function ${routeFunctionFilePath} should`);
|
|
42
46
|
const routeParams = result.routeParams || {};
|
|
43
47
|
(0, utils_js_1.assertUsage)(!('pageContext' in result), `Providing ${picocolors_1.default.cyan('pageContext')} in Route Functions is prohibited, see https://vike.dev/route-function#cannot-provide-pagecontext`);
|
|
44
48
|
(0, utils_js_1.assert)((0, utils_js_1.isPlainObject)(routeParams));
|
|
45
49
|
Object.keys(result).forEach((key) => {
|
|
46
|
-
(0, utils_js_1.assertUsage)(key === 'match' || key === 'routeParams' || key === 'precedence', `The Route Function ${
|
|
50
|
+
(0, utils_js_1.assertUsage)(key === 'match' || key === 'routeParams' || key === 'precedence', `The Route Function ${routeFunctionFilePath} returned an object with an unknown property ${picocolors_1.default.cyan(key)} (the known properties are ${picocolors_1.default.cyan('match')}, ${picocolors_1.default.cyan('routeParams')}, and ${picocolors_1.default.cyan('precedence')})`);
|
|
47
51
|
});
|
|
48
52
|
return {
|
|
49
53
|
precedence,
|
package/dist/cjs/shared/utils.js
CHANGED
|
@@ -43,3 +43,4 @@ __exportStar(require("../utils/changeEnumerable.js"), exports);
|
|
|
43
43
|
__exportStar(require("../utils/objectDefineProperty.js"), exports);
|
|
44
44
|
__exportStar(require("../utils/isScriptFile.js"), exports);
|
|
45
45
|
__exportStar(require("../utils/objectFilter.js"), exports);
|
|
46
|
+
__exportStar(require("../utils/getPropAccessNotation.js"), exports);
|
package/dist/cjs/utils/debug.js
CHANGED
|
@@ -13,11 +13,10 @@ const checkType_js_1 = require("./checkType.js");
|
|
|
13
13
|
const getTerminWidth_js_1 = require("./getTerminWidth.js");
|
|
14
14
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
15
15
|
const isArray_js_1 = require("./isArray.js");
|
|
16
|
-
|
|
16
|
+
const isObject_js_1 = require("./isObject.js");
|
|
17
|
+
const debug_js_1 = require("../shared/route/debug.js");
|
|
17
18
|
(0, assert_js_1.assert)(!(0, isBrowser_js_1.isBrowser)());
|
|
18
|
-
|
|
19
|
-
// We purposely read process.env.DEBUG early, in order to avoid users from the temptation to set process.env.DEBUG with JavaScript, since reading & writing process.env.DEBUG dynamically leads to inconsistencies: for example https://github.com/vikejs/vike/issues/2239
|
|
20
|
-
const DEBUG = getDEBUG() ?? '';
|
|
19
|
+
(0, debug_js_1.setCreateDebugger)(createDebugger); // for isomorphic code
|
|
21
20
|
const flags = [
|
|
22
21
|
'vike:crawl',
|
|
23
22
|
'vike:error',
|
|
@@ -31,6 +30,7 @@ const flags = [
|
|
|
31
30
|
'vike:outDir',
|
|
32
31
|
'vike:pageFiles',
|
|
33
32
|
'vike:pointer-imports',
|
|
33
|
+
'vike:resolve',
|
|
34
34
|
'vike:routing',
|
|
35
35
|
'vike:setup',
|
|
36
36
|
'vike:stream',
|
|
@@ -38,6 +38,10 @@ const flags = [
|
|
|
38
38
|
];
|
|
39
39
|
const flagsSkipWildcard = ['vike:log'];
|
|
40
40
|
const flagRegex = /\bvike:[a-zA-Z-]+/g;
|
|
41
|
+
// We purposely read process.env.DEBUG early, in order to avoid users from the temptation to set process.env.DEBUG with JavaScript, since reading & writing process.env.DEBUG dynamically leads to inconsistencies such as https://github.com/vikejs/vike/issues/2239
|
|
42
|
+
const DEBUG = getDEBUG() ?? '';
|
|
43
|
+
if (isDebug())
|
|
44
|
+
Error.stackTraceLimit = Infinity;
|
|
41
45
|
assertFlagsActivated();
|
|
42
46
|
function createDebugger(flag, optionsGlobal) {
|
|
43
47
|
(0, checkType_js_1.checkType)(flag);
|
|
@@ -64,9 +68,10 @@ function debug_(flag, options, ...msgs) {
|
|
|
64
68
|
});
|
|
65
69
|
let logFirst;
|
|
66
70
|
let logsRest;
|
|
67
|
-
const noNewLine = msgsRest.length <= 1 &&
|
|
71
|
+
const noNewLine = msgsRest.length <= 1 &&
|
|
72
|
+
[msgFirst, ...msgsRest].every((m) => (typeof m === 'string' ? !m.includes('\n') : !(0, isObject_js_1.isObject)(m)));
|
|
68
73
|
if (noNewLine) {
|
|
69
|
-
logFirst = [msgFirst, ...msgsRest].map((m) =>
|
|
74
|
+
logFirst = [msgFirst, ...msgsRest].map((m) => (typeof m !== 'string' ? m : m.trim()));
|
|
70
75
|
logsRest = [];
|
|
71
76
|
}
|
|
72
77
|
else {
|
|
@@ -156,6 +161,10 @@ function getFlagsActivated() {
|
|
|
156
161
|
const all = DEBUG.includes('vike:*');
|
|
157
162
|
return { flagsActivated, all };
|
|
158
163
|
}
|
|
164
|
+
function isDebug() {
|
|
165
|
+
const { flagsActivated, all } = getFlagsActivated();
|
|
166
|
+
return all || flagsActivated.length > 0;
|
|
167
|
+
}
|
|
159
168
|
function getDEBUG() {
|
|
160
169
|
let DEBUG;
|
|
161
170
|
// - `process` can be undefined in edge workers
|