vike 0.4.144 → 0.4.145-commit-2520555
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/__internal/index.js +6 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +3 -3
- package/dist/cjs/node/plugin/plugins/commonConfig.js +0 -3
- package/dist/cjs/node/plugin/plugins/config/index.js +3 -3
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +8 -8
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -0
- package/dist/cjs/node/plugin/plugins/envVars.js +34 -20
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +249 -228
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +8 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +36 -14
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +18 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +15 -17
- package/dist/cjs/node/plugin/plugins/previewConfig.js +11 -2
- package/dist/cjs/node/prerender/runPrerender.js +34 -26
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +20 -6
- package/dist/cjs/node/runtime/renderPage/debugPageFiles.js +5 -5
- package/dist/cjs/node/runtime/renderPage/log404/index.js +28 -17
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -3
- package/dist/cjs/node/runtime/renderPage.js +3 -3
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/node/shared/getClientEntryFilePath.js +2 -2
- package/dist/cjs/node/shared/getConfigVike.js +4 -1
- package/dist/cjs/shared/addUrlComputedProps.js +24 -12
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +4 -6
- package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
- package/dist/cjs/shared/hooks/getHook.js +1 -1
- package/dist/cjs/shared/page-configs/getExportPath.js +3 -3
- package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +43 -0
- package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +44 -0
- package/dist/cjs/shared/page-configs/helpers.js +33 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +14 -13
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +9 -10
- package/dist/cjs/shared/route/abort.js +1 -1
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +41 -15
- package/dist/cjs/shared/route/index.js +22 -32
- package/dist/cjs/shared/route/loadPageRoutes.js +11 -10
- package/dist/cjs/shared/route/noRouteMatch.js +4 -0
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -1
- package/dist/cjs/shared/utils.js +1 -1
- package/dist/cjs/utils/getFilePathAbsolute.js +11 -11
- package/dist/cjs/utils/isExternalLink.js +7 -0
- package/dist/cjs/utils/{hasPropertyGetter.js → isPropertyGetter.js} +3 -3
- package/dist/cjs/utils/onPageVisibilityChange.js +19 -0
- package/dist/cjs/utils/parseUrl.js +1 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/truncateString.js +12 -7
- package/dist/esm/__internal/index.d.ts +6 -3
- package/dist/esm/__internal/index.js +8 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.js +3 -4
- package/dist/esm/client/client-routing-runtime/entry.js +2 -2
- package/dist/esm/client/client-routing-runtime/getBaseServer.d.ts +2 -1
- package/dist/esm/client/client-routing-runtime/getBaseServer.js +2 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +39 -0
- package/dist/esm/client/client-routing-runtime/{getPageContext.js → getPageContextFromHooks.js} +50 -79
- package/dist/esm/client/client-routing-runtime/history.d.ts +3 -1
- package/dist/esm/client/client-routing-runtime/history.js +31 -9
- package/dist/esm/client/client-routing-runtime/installClientRouter.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/installClientRouter.js +22 -0
- package/dist/esm/client/client-routing-runtime/isClientSideRoutable.d.ts +8 -0
- package/dist/esm/client/client-routing-runtime/isClientSideRoutable.js +12 -0
- package/dist/esm/client/client-routing-runtime/navigate.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/navigate.js +9 -8
- package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.d.ts +4 -0
- package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +63 -0
- package/dist/esm/client/client-routing-runtime/onLinkClick.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/onLinkClick.js +40 -0
- package/dist/esm/client/client-routing-runtime/prefetch.js +54 -29
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +19 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +347 -0
- package/dist/esm/client/client-routing-runtime/scrollRestoration.d.ts +6 -0
- package/dist/esm/client/client-routing-runtime/scrollRestoration.js +25 -0
- package/dist/esm/client/client-routing-runtime/setScrollPosition.d.ts +7 -0
- package/dist/esm/client/client-routing-runtime/setScrollPosition.js +77 -0
- package/dist/esm/client/client-routing-runtime/skipLink.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/skipLink.js +9 -5
- package/dist/esm/client/client-routing-runtime/utils.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/utils.js +2 -0
- package/dist/esm/client/server-routing-runtime/getPageContext.js +1 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.js +6 -5
- package/dist/esm/client/shared/getPageContextProxyForUser.js +13 -7
- package/dist/esm/client/shared/loadPageFilesClientSide.d.ts +8 -3
- package/dist/esm/client/shared/loadPageFilesClientSide.js +5 -5
- package/dist/esm/node/plugin/plugins/buildConfig.js +3 -3
- package/dist/esm/node/plugin/plugins/commonConfig.js +0 -3
- package/dist/esm/node/plugin/plugins/config/index.js +4 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +9 -9
- package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -0
- package/dist/esm/node/plugin/plugins/envVars.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/envVars.js +35 -20
- package/dist/esm/node/plugin/plugins/importBuild/index.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +250 -229
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +7 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +37 -15
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +7 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +15 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +16 -18
- package/dist/esm/node/plugin/plugins/previewConfig.js +11 -2
- package/dist/esm/node/prerender/runPrerender.js +29 -21
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +21 -7
- package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +5 -5
- package/dist/esm/node/runtime/renderPage/debugPageFiles.js +5 -5
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.js +28 -16
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
- package/dist/esm/node/runtime/renderPage.js +3 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/node/shared/getClientEntryFilePath.js +1 -1
- package/dist/esm/node/shared/getConfigVike.d.ts +2 -1
- package/dist/esm/node/shared/getConfigVike.js +4 -1
- package/dist/esm/shared/addUrlComputedProps.d.ts +1 -0
- package/dist/esm/shared/addUrlComputedProps.js +25 -13
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +2 -4
- package/dist/esm/shared/getPageFiles/getExports.js +2 -2
- package/dist/esm/shared/hooks/getHook.js +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +55 -31
- package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
- package/dist/esm/shared/page-configs/getExportPath.js +3 -3
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +7 -0
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +37 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.d.ts +14 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.js +38 -0
- package/dist/esm/shared/page-configs/helpers.d.ts +13 -0
- package/dist/esm/shared/page-configs/helpers.js +27 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +2 -2
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +4 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +15 -11
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +9 -10
- package/dist/esm/shared/route/abort.js +1 -1
- package/dist/esm/shared/route/executeOnBeforeRouteHook.d.ts +5 -8
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +41 -15
- package/dist/esm/shared/route/index.d.ts +12 -10
- package/dist/esm/shared/route/index.js +23 -33
- package/dist/esm/shared/route/loadPageRoutes.js +8 -7
- package/dist/esm/shared/route/noRouteMatch.d.ts +1 -0
- package/dist/esm/shared/route/noRouteMatch.js +1 -0
- package/dist/esm/shared/route/resolveRouteFunction.js +1 -1
- package/dist/esm/shared/utils.d.ts +1 -1
- package/dist/esm/shared/utils.js +1 -1
- package/dist/esm/utils/getFilePathAbsolute.d.ts +1 -1
- package/dist/esm/utils/getFilePathAbsolute.js +11 -11
- package/dist/esm/utils/isPropertyGetter.d.ts +1 -0
- package/dist/esm/utils/{hasPropertyGetter.js → isPropertyGetter.js} +1 -1
- package/dist/esm/utils/onPageVisibilityChange.d.ts +4 -0
- package/dist/esm/utils/onPageVisibilityChange.js +16 -0
- package/dist/esm/utils/parseUrl.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/truncateString.d.ts +2 -1
- package/dist/esm/utils/truncateString.js +10 -7
- package/node/cli/bin-entry.js +1 -1
- package/package.json +2 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -16
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -13
- package/dist/cjs/shared/page-configs/utils.js +0 -103
- package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +0 -29
- package/dist/esm/client/client-routing-runtime/getPageId.d.ts +0 -10
- package/dist/esm/client/client-routing-runtime/getPageId.js +0 -17
- package/dist/esm/client/client-routing-runtime/navigationState.d.ts +0 -5
- package/dist/esm/client/client-routing-runtime/navigationState.js +0 -14
- package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.js +0 -15
- package/dist/esm/client/client-routing-runtime/useClientRouter.d.ts +0 -6
- package/dist/esm/client/client-routing-runtime/useClientRouter.js +0 -493
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +0 -24
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -13
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -10
- package/dist/esm/shared/page-configs/utils.d.ts +0 -35
- package/dist/esm/shared/page-configs/utils.js +0 -97
- package/dist/esm/utils/hasPropertyGetter.d.ts +0 -1
- /package/dist/esm/{client/client-routing-runtime → utils}/isExternalLink.d.ts +0 -0
- /package/dist/esm/{client/client-routing-runtime → utils}/isExternalLink.js +0 -0
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -6,11 +6,12 @@ const virtualFilePageConfigValuesAll_js_1 = require("../../../../shared/virtual-
|
|
|
6
6
|
const getVikeConfig_js_1 = require("./getVikeConfig.js");
|
|
7
7
|
const extractAssetsQuery_js_1 = require("../../../../shared/extractAssetsQuery.js");
|
|
8
8
|
const debug_js_1 = require("./debug.js");
|
|
9
|
-
const
|
|
9
|
+
const helpers_js_1 = require("../../../../../shared/page-configs/helpers.js");
|
|
10
10
|
const getConfigValueSourcesRelevant_js_1 = require("../../../shared/getConfigValueSourcesRelevant.js");
|
|
11
|
-
const
|
|
11
|
+
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
12
12
|
const serializeConfigValue_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValue.js");
|
|
13
|
-
|
|
13
|
+
const getConfigVike_js_1 = require("../../../../shared/getConfigVike.js");
|
|
14
|
+
async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
|
|
14
15
|
const result = (0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(id);
|
|
15
16
|
(0, utils_js_1.assert)(result);
|
|
16
17
|
/* This assertion fails when using includeAssetsImportedByServer
|
|
@@ -20,16 +21,17 @@ async function getVirtualFilePageConfigValuesAll(id, userRootDir, outDirRoot, is
|
|
|
20
21
|
}
|
|
21
22
|
*/
|
|
22
23
|
const { pageId, isForClientSide } = result;
|
|
23
|
-
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(
|
|
24
|
+
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(config, isDev, true);
|
|
24
25
|
const pageConfig = pageConfigs.find((pageConfig) => pageConfig.pageId === pageId);
|
|
25
26
|
(0, utils_js_1.assert)(pageConfig);
|
|
27
|
+
const configVike = await (0, getConfigVike_js_1.getConfigVike)(config);
|
|
26
28
|
const code = getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, configVike.includeAssetsImportedByServer, isDev);
|
|
27
29
|
(0, debug_js_1.debug)(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
28
30
|
return code;
|
|
29
31
|
}
|
|
30
32
|
exports.getVirtualFilePageConfigValuesAll = getVirtualFilePageConfigValuesAll;
|
|
31
33
|
function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAssetsImportedByServer, isDev) {
|
|
32
|
-
const configValue = (0,
|
|
34
|
+
const configValue = (0, helpers_js_1.getConfigValue)(pageConfig, 'clientRouting', 'boolean');
|
|
33
35
|
const isClientRouting = configValue?.value ?? false;
|
|
34
36
|
const lines = [];
|
|
35
37
|
const importStatements = [];
|
|
@@ -41,7 +43,7 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
41
43
|
return;
|
|
42
44
|
if (configValueSource.valueIsFilePath)
|
|
43
45
|
return;
|
|
44
|
-
if (!(0,
|
|
46
|
+
if (!(0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: false }))
|
|
45
47
|
return;
|
|
46
48
|
const whitespace = ' ';
|
|
47
49
|
lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
@@ -11,18 +11,26 @@ const stringify_1 = require("@brillout/json-serializer/stringify");
|
|
|
11
11
|
const helpers_js_1 = require("./helpers.js");
|
|
12
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
13
|
const getVikeConfig_js_1 = require("./getVikeConfig.js");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
15
|
+
const helpers_js_2 = require("../../../../../shared/page-configs/helpers.js");
|
|
16
16
|
const serializeConfigValue_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValue.js");
|
|
17
|
-
async function getVirtualFilePageConfigs(
|
|
18
|
-
const { pageConfigs, pageConfigGlobal } = await (0, getVikeConfig_js_1.getVikeConfig)(
|
|
19
|
-
return
|
|
17
|
+
async function getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, config) {
|
|
18
|
+
const { pageConfigs, pageConfigGlobal } = await (0, getVikeConfig_js_1.getVikeConfig)(config, isDev, true);
|
|
19
|
+
return getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
|
|
20
20
|
}
|
|
21
21
|
exports.getVirtualFilePageConfigs = getVirtualFilePageConfigs;
|
|
22
|
-
function
|
|
22
|
+
function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting) {
|
|
23
23
|
const lines = [];
|
|
24
24
|
const importStatements = [];
|
|
25
25
|
const varCounterContainer = { varCounter: 0 };
|
|
26
|
+
lines.push(getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements, varCounterContainer));
|
|
27
|
+
lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements, varCounterContainer));
|
|
28
|
+
const code = [...importStatements, ...lines].join('\n');
|
|
29
|
+
(0, debug_js_1.debug)(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
30
|
+
return code;
|
|
31
|
+
}
|
|
32
|
+
function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements, varCounterContainer) {
|
|
33
|
+
const lines = [];
|
|
26
34
|
lines.push('export const pageConfigsSerialized = [');
|
|
27
35
|
pageConfigs.forEach((pageConfig) => {
|
|
28
36
|
const { pageId, routeFilesystem, isErrorPage } = pageConfig;
|
|
@@ -35,7 +43,7 @@ function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, i
|
|
|
35
43
|
lines.push(` configValuesSerialized: {`);
|
|
36
44
|
Object.entries(pageConfig.configValuesComputed).forEach(([configName, configValuesComputed]) => {
|
|
37
45
|
const { value, configEnv } = configValuesComputed;
|
|
38
|
-
if (!(0,
|
|
46
|
+
if (!(0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: true }))
|
|
39
47
|
return;
|
|
40
48
|
if (pageConfig.configValueSources[configName])
|
|
41
49
|
return;
|
|
@@ -50,7 +58,8 @@ function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, i
|
|
|
50
58
|
if (configValue) {
|
|
51
59
|
const configEnv = (0, helpers_js_1.getConfigEnv)(pageConfig.configValueSources, configName);
|
|
52
60
|
(0, utils_js_1.assert)(configEnv, configName);
|
|
53
|
-
|
|
61
|
+
const isEnvMatch = (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: true });
|
|
62
|
+
if (!isEnvMatch)
|
|
54
63
|
return;
|
|
55
64
|
const { value, definedAt } = configValue;
|
|
56
65
|
const valueSerialized = getConfigValueSerialized(value, configName, definedAt);
|
|
@@ -75,6 +84,11 @@ function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, i
|
|
|
75
84
|
lines.push(` },`);
|
|
76
85
|
});
|
|
77
86
|
lines.push('];');
|
|
87
|
+
const code = lines.join('\n');
|
|
88
|
+
return code;
|
|
89
|
+
}
|
|
90
|
+
function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements, varCounterContainer) {
|
|
91
|
+
const lines = [];
|
|
78
92
|
lines.push('export const pageConfigGlobalSerialized = {');
|
|
79
93
|
/* Nothing (yet)
|
|
80
94
|
lines.push(` configValuesSerialized: {`)
|
|
@@ -101,23 +115,31 @@ function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, i
|
|
|
101
115
|
});
|
|
102
116
|
lines.push(` ],`);
|
|
103
117
|
lines.push('};');
|
|
104
|
-
const code =
|
|
105
|
-
(0, debug_js_1.debug)(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
118
|
+
const code = lines.join('\n');
|
|
106
119
|
return code;
|
|
107
120
|
}
|
|
108
121
|
function getConfigValueSerialized(value, configName, definedAt) {
|
|
109
122
|
const valueName = `config${(0, utils_js_1.getPropAccessNotation)(configName)}`;
|
|
110
123
|
let configValueSerialized;
|
|
111
124
|
try {
|
|
112
|
-
configValueSerialized = (0, stringify_1.stringify)(value, { valueName });
|
|
125
|
+
configValueSerialized = (0, stringify_1.stringify)(value, { valueName, forbidReactElements: true });
|
|
113
126
|
}
|
|
114
127
|
catch (err) {
|
|
115
|
-
|
|
116
|
-
|
|
128
|
+
let serializationErrMsg = '';
|
|
129
|
+
if ((0, stringify_1.isJsonSerializerError)(err)) {
|
|
130
|
+
serializationErrMsg = err.messageCore;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
// When a property getter throws an error
|
|
134
|
+
console.error('Serialization error:');
|
|
135
|
+
console.error(err);
|
|
136
|
+
serializationErrMsg = 'see serialization error printed above';
|
|
137
|
+
}
|
|
138
|
+
const configValueFilePathToShowToUser = (0, helpers_js_2.getConfigValueFilePathToShowToUser)({ definedAt });
|
|
117
139
|
(0, utils_js_1.assert)(configValueFilePathToShowToUser);
|
|
118
140
|
(0, utils_js_1.assertUsage)(false, [
|
|
119
141
|
`The value of the config ${picocolors_1.default.cyan(configName)} cannot be defined inside the file ${configValueFilePathToShowToUser}:`,
|
|
120
|
-
`its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because
|
|
142
|
+
`its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because its value isn't serializable: ${serializationErrMsg}.)`,
|
|
121
143
|
`Only serializable config values can be defined inside +config.h.js files, see https://vike.dev/header-file.`
|
|
122
144
|
].join(' '));
|
|
123
145
|
}
|
|
@@ -7,20 +7,7 @@ function getConfigEnv(configValueSources, configName) {
|
|
|
7
7
|
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
8
8
|
if (!configValueSource)
|
|
9
9
|
return null;
|
|
10
|
-
|
|
11
|
-
return configValueSource.configEnv;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
// In case of effect/computed config values, there isn't any configValueSource
|
|
15
|
-
// TODO: make it work for custom config definitions
|
|
16
|
-
// - Ideally set configValueSource also for effect/computed config values?
|
|
17
|
-
(0, utils_js_1.assert)(false, 'TODO');
|
|
18
|
-
/*
|
|
19
|
-
const configDef = configDefinitionsBuiltIn[configName as keyof typeof configDefinitionsBuiltIn]
|
|
20
|
-
if (!configDef) return null
|
|
21
|
-
return configDef.env
|
|
22
|
-
*/
|
|
23
|
-
}
|
|
10
|
+
return configValueSource.configEnv;
|
|
24
11
|
}
|
|
25
12
|
exports.getConfigEnv = getConfigEnv;
|
|
26
13
|
function isConfigSet(configValueSources, configName) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isRuntimeEnvMatch = void 0;
|
|
4
|
+
function isRuntimeEnvMatch(configEnv, runtime) {
|
|
5
|
+
const { isForClientSide, isClientRouting, isEager } = runtime;
|
|
6
|
+
if (configEnv === 'config-only')
|
|
7
|
+
return false;
|
|
8
|
+
if (configEnv === (isForClientSide ? 'server-only' : 'client-only'))
|
|
9
|
+
return false;
|
|
10
|
+
if (configEnv === '_routing-eager' || configEnv === '_routing-lazy') {
|
|
11
|
+
if (isForClientSide && !isClientRouting)
|
|
12
|
+
return false;
|
|
13
|
+
if (isEager !== (configEnv === '_routing-eager'))
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
exports.isRuntimeEnvMatch = isRuntimeEnvMatch;
|
|
@@ -13,7 +13,6 @@ const utils_js_1 = require("../../../utils.js");
|
|
|
13
13
|
const replaceImportStatements_js_1 = require("./replaceImportStatements.js");
|
|
14
14
|
const getVikeConfig_js_1 = require("./getVikeConfig.js");
|
|
15
15
|
require("source-map-support/register.js");
|
|
16
|
-
const getFilePathToShowToUser_js_1 = require("./getFilePathToShowToUser.js");
|
|
17
16
|
const assertExports_js_1 = require("../../../../../shared/page-configs/assertExports.js");
|
|
18
17
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
19
18
|
async function transpileAndExecuteFile(filePath, isValueFile, userRootDir) {
|
|
@@ -23,9 +22,9 @@ async function transpileAndExecuteFile(filePath, isValueFile, userRootDir) {
|
|
|
23
22
|
}
|
|
24
23
|
exports.transpileAndExecuteFile = transpileAndExecuteFile;
|
|
25
24
|
async function transpileFile(filePath, isValueFile, userRootDir) {
|
|
26
|
-
const {
|
|
27
|
-
(0, utils_js_1.assertPosixPath)(
|
|
28
|
-
getVikeConfig_js_1.vikeConfigDependencies.add(
|
|
25
|
+
const { filePathAbsoluteFilesystem } = filePath;
|
|
26
|
+
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
27
|
+
getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
29
28
|
let code = await transpileWithEsbuild(filePath, isValueFile, userRootDir);
|
|
30
29
|
let fileImports = null;
|
|
31
30
|
{
|
|
@@ -39,14 +38,13 @@ async function transpileFile(filePath, isValueFile, userRootDir) {
|
|
|
39
38
|
}
|
|
40
39
|
function transpileImports(codeOriginal, filePath, isValueFile) {
|
|
41
40
|
// Do we need to remove the imports?
|
|
42
|
-
const {
|
|
43
|
-
(0, utils_js_1.assertPosixPath)(
|
|
44
|
-
const isHeader = isHeaderFile(
|
|
41
|
+
const { filePathAbsoluteFilesystem, filePathToShowToUser } = filePath;
|
|
42
|
+
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
43
|
+
const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
|
|
45
44
|
const isPageConfigFile = !isValueFile;
|
|
46
45
|
if (!isHeader && !isPageConfigFile) {
|
|
47
46
|
return null;
|
|
48
47
|
}
|
|
49
|
-
const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(filePath);
|
|
50
48
|
(0, utils_js_1.assertWarning)(isPageConfigFile, `${filePathToShowToUser} is a JavaScript header file (.h.js), but JavaScript header files should only be used for +config.h.js, see https://vike.dev/header-file`, { onlyOnce: true });
|
|
51
49
|
// Remove the imports
|
|
52
50
|
const res = (0, replaceImportStatements_js_1.replaceImportStatements)(codeOriginal, filePathToShowToUser);
|
|
@@ -63,7 +61,7 @@ function transpileImports(codeOriginal, filePath, isValueFile) {
|
|
|
63
61
|
return { code, fileImports };
|
|
64
62
|
}
|
|
65
63
|
async function transpileWithEsbuild(filePath, bundle, userRootDir) {
|
|
66
|
-
const entryFilePath = filePath.
|
|
64
|
+
const entryFilePath = filePath.filePathAbsoluteFilesystem;
|
|
67
65
|
const entryFileDir = path_1.default.posix.dirname(entryFilePath);
|
|
68
66
|
const options = {
|
|
69
67
|
platform: 'node',
|
|
@@ -128,8 +126,8 @@ async function transpileWithEsbuild(filePath, bundle, userRootDir) {
|
|
|
128
126
|
Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
|
|
129
127
|
filePathRelative = (0, utils_js_1.toPosixPath)(filePathRelative);
|
|
130
128
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
131
|
-
const
|
|
132
|
-
getVikeConfig_js_1.vikeConfigDependencies.add(
|
|
129
|
+
const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, filePathRelative);
|
|
130
|
+
getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
133
131
|
});
|
|
134
132
|
}
|
|
135
133
|
const code = result.outputFiles[0].text;
|
|
@@ -137,10 +135,10 @@ async function transpileWithEsbuild(filePath, bundle, userRootDir) {
|
|
|
137
135
|
return code;
|
|
138
136
|
}
|
|
139
137
|
async function executeFile(filePath, code, fileImports, isValueFile) {
|
|
140
|
-
const {
|
|
138
|
+
const { filePathAbsoluteFilesystem, filePathRelativeToUserRootDir } = filePath;
|
|
141
139
|
// Alternative to using a temporary file: https://github.com/vitejs/vite/pull/13269
|
|
142
140
|
// - But seems to break source maps, so I don't think it's worth it
|
|
143
|
-
const filePathTmp = getFilePathTmp(
|
|
141
|
+
const filePathTmp = getFilePathTmp(filePathAbsoluteFilesystem);
|
|
144
142
|
fs_1.default.writeFileSync(filePathTmp, code);
|
|
145
143
|
const clean = () => fs_1.default.unlinkSync(filePathTmp);
|
|
146
144
|
let fileExports = {};
|
|
@@ -163,7 +161,7 @@ async function executeFile(filePath, code, fileImports, isValueFile) {
|
|
|
163
161
|
fileExports = { ...fileExports };
|
|
164
162
|
if (fileImports && !isValueFile) {
|
|
165
163
|
(0, utils_js_1.assert)(filePathRelativeToUserRootDir !== undefined);
|
|
166
|
-
const filePathToShowToUser = filePathRelativeToUserRootDir ??
|
|
164
|
+
const filePathToShowToUser = filePathRelativeToUserRootDir ?? filePathAbsoluteFilesystem;
|
|
167
165
|
assertImportsAreReExported(fileImports, fileExports, filePathToShowToUser);
|
|
168
166
|
}
|
|
169
167
|
return { fileExports };
|
|
@@ -234,11 +232,11 @@ function assertImportsAreReExported(fileImports, fileExports, filePathToShowToUs
|
|
|
234
232
|
const importStatements = (0, utils_js_1.unique)(fileImportsUnused.map((fi) => fi.importStatementCode));
|
|
235
233
|
const importNamesUnused = fileImportsUnused.map((fi) => picocolors_1.default.cyan(fi.importLocalName)).join(', ');
|
|
236
234
|
const singular = fileImportsUnused.length === 1;
|
|
237
|
-
(0, utils_js_1.
|
|
235
|
+
(0, utils_js_1.assertWarning)(fileImportsUnused.length === 0, [
|
|
238
236
|
`${filePathToShowToUser} imports the following:`,
|
|
239
237
|
...importStatements.map((s) => picocolors_1.default.cyan(` ${s}`)),
|
|
240
238
|
`But the import${singular ? '' : 's'} ${importNamesUnused} ${singular ? "isn't" : "aren't"} re-exported at ${picocolors_1.default.cyan('export default { ... }')} and therefore ${singular ? 'has' : 'have'} no effect, see explanation at https://vike.dev/header-file`
|
|
241
|
-
].join('\n'));
|
|
239
|
+
].join('\n'), { onlyOnce: true });
|
|
242
240
|
}
|
|
243
241
|
function getExportedStrings(obj) {
|
|
244
242
|
const exportedStrings = [];
|
|
@@ -279,7 +277,7 @@ function triggerPrepareStackTrace(err) {
|
|
|
279
277
|
function getErrIntroMsg(operation, filePath) {
|
|
280
278
|
const msg = [
|
|
281
279
|
picocolors_1.default.red(`Failed to ${operation}`),
|
|
282
|
-
picocolors_1.default.bold(picocolors_1.default.red(
|
|
280
|
+
picocolors_1.default.bold(picocolors_1.default.red(filePath.filePathToShowToUser)),
|
|
283
281
|
picocolors_1.default.red(`because:`)
|
|
284
282
|
].join(' ');
|
|
285
283
|
return msg;
|
|
@@ -18,6 +18,7 @@ function previewConfig() {
|
|
|
18
18
|
apply: 'serve',
|
|
19
19
|
config(config) {
|
|
20
20
|
return {
|
|
21
|
+
appType: 'custom',
|
|
21
22
|
build: {
|
|
22
23
|
outDir: (0, utils_js_1.resolveOutDir)(config)
|
|
23
24
|
}
|
|
@@ -28,12 +29,20 @@ function previewConfig() {
|
|
|
28
29
|
configVike = await (0, getConfigVike_js_1.getConfigVike)(config);
|
|
29
30
|
},
|
|
30
31
|
configurePreviewServer(server) {
|
|
32
|
+
/* - Couldn't make `appType: 'mpa'` work as of npm:@brillout/vite@5.0.0-beta.14.0426910c
|
|
33
|
+
- This ugly hack to set appType for preview won't be need once https://github.com/vitejs/vite/pull/14855 is merged.
|
|
34
|
+
config.appType = 'mpa'
|
|
35
|
+
*/
|
|
31
36
|
(0, utils_js_1.markEnvAsPreview)();
|
|
32
37
|
return () => {
|
|
33
38
|
assertDist();
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
/* We don't use this condition (we wrongfully always use the SSR middleware) because of the regression introduced by https://github.com/vitejs/vite/pull/14756 which stops servering .html files when `appType: 'custom'`.
|
|
40
|
+
if (!configVike.prerender || configVike.prerender.partial) {
|
|
41
|
+
addSsrMiddleware(server.middlewares)
|
|
36
42
|
}
|
|
43
|
+
/*/
|
|
44
|
+
(0, addSsrMiddleware_js_1.addSsrMiddleware)(server.middlewares);
|
|
45
|
+
//*/
|
|
37
46
|
addStatic404Middleware(server.middlewares);
|
|
38
47
|
};
|
|
39
48
|
}
|
|
@@ -41,7 +41,7 @@ const getConfigVike_js_1 = require("../shared/getConfigVike.js");
|
|
|
41
41
|
const getPageFiles_js_1 = require("../../shared/getPageFiles.js");
|
|
42
42
|
const getPageContextRequestUrl_js_1 = require("../../shared/getPageContextRequestUrl.js");
|
|
43
43
|
const resolveRouteString_js_1 = require("../../shared/route/resolveRouteString.js");
|
|
44
|
-
const
|
|
44
|
+
const helpers_js_1 = require("../../shared/page-configs/helpers.js");
|
|
45
45
|
const loadConfigValues_js_1 = require("../../shared/page-configs/loadConfigValues.js");
|
|
46
46
|
const error_page_js_1 = require("../../shared/error-page.js");
|
|
47
47
|
const addUrlComputedProps_js_1 = require("../../shared/addUrlComputedProps.js");
|
|
@@ -49,6 +49,8 @@ const assertPathIsFilesystemAbsolute_js_1 = require("../../utils/assertPathIsFil
|
|
|
49
49
|
const abort_js_1 = require("../../shared/route/abort.js");
|
|
50
50
|
const loadPageFilesServerSide_js_1 = require("../runtime/renderPage/loadPageFilesServerSide.js");
|
|
51
51
|
const getHook_js_1 = require("../../shared/hooks/getHook.js");
|
|
52
|
+
const noRouteMatch_js_1 = require("../../shared/route/noRouteMatch.js");
|
|
53
|
+
const getVikeConfig_js_1 = require("../plugin/plugins/importUserCode/v1-design/getVikeConfig.js");
|
|
52
54
|
async function prerenderFromAPI(options = {}) {
|
|
53
55
|
await runPrerender(options, 'prerender()');
|
|
54
56
|
}
|
|
@@ -95,7 +97,8 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
95
97
|
pageContextInit: options.pageContextInit ?? null
|
|
96
98
|
});
|
|
97
99
|
const doNotPrerenderList = [];
|
|
98
|
-
await
|
|
100
|
+
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(viteConfig, false);
|
|
101
|
+
await collectDoNoPrerenderList(renderContext, vikeConfig.pageConfigs, doNotPrerenderList, concurrencyLimit);
|
|
99
102
|
await callOnBeforePrerenderStartHooks(prerenderContext, renderContext, concurrencyLimit);
|
|
100
103
|
await handlePagesWithStaticRoutes(prerenderContext, renderContext, doNotPrerenderList, concurrencyLimit);
|
|
101
104
|
await callOnPrerenderStartHook(prerenderContext, renderContext);
|
|
@@ -110,12 +113,13 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
110
113
|
await Promise.all(htmlFiles.map((htmlFile) => writeHtmlFile(htmlFile, root, outDirClient, concurrencyLimit, options.onPagePrerender, logLevel)));
|
|
111
114
|
warnMissingPages(prerenderPageIds, doNotPrerenderList, renderContext, partial);
|
|
112
115
|
}
|
|
113
|
-
async function collectDoNoPrerenderList(renderContext, doNotPrerenderList, concurrencyLimit) {
|
|
114
|
-
|
|
116
|
+
async function collectDoNoPrerenderList(renderContext, pageConfigs, doNotPrerenderList, concurrencyLimit) {
|
|
117
|
+
// V1 design
|
|
118
|
+
pageConfigs.forEach((pageConfig) => {
|
|
115
119
|
const configName = 'prerender';
|
|
116
|
-
const configValue = (0,
|
|
120
|
+
const configValue = (0, helpers_js_1.getConfigValue)(pageConfig, configName, 'boolean');
|
|
117
121
|
if (configValue?.value === false) {
|
|
118
|
-
const configValueFilePathToShowToUser = (0,
|
|
122
|
+
const configValueFilePathToShowToUser = (0, helpers_js_1.getConfigValueFilePathToShowToUser)(configValue);
|
|
119
123
|
(0, utils_js_1.assert)(configValueFilePathToShowToUser);
|
|
120
124
|
doNotPrerenderList.push({
|
|
121
125
|
pageId: pageConfig.pageId,
|
|
@@ -125,6 +129,8 @@ async function collectDoNoPrerenderList(renderContext, doNotPrerenderList, concu
|
|
|
125
129
|
});
|
|
126
130
|
}
|
|
127
131
|
});
|
|
132
|
+
// Old design
|
|
133
|
+
// TODO/v1-release: remove
|
|
128
134
|
await Promise.all(renderContext.pageFilesAll
|
|
129
135
|
.filter((p) => {
|
|
130
136
|
assertExportNames(p);
|
|
@@ -173,11 +179,11 @@ async function callOnBeforePrerenderStartHooks(prerenderContext, renderContext,
|
|
|
173
179
|
await Promise.all(renderContext.pageConfigs.map((pageConfig) => concurrencyLimit(async () => {
|
|
174
180
|
const hookName = 'onBeforePrerenderStart';
|
|
175
181
|
const pageConfigLoaded = await (0, loadConfigValues_js_1.loadConfigValues)(pageConfig, false);
|
|
176
|
-
const configValue = (0,
|
|
182
|
+
const configValue = (0, helpers_js_1.getConfigValue)(pageConfigLoaded, hookName);
|
|
177
183
|
if (!configValue)
|
|
178
184
|
return;
|
|
179
185
|
const hookFn = configValue.value;
|
|
180
|
-
const hookFilePath = (0,
|
|
186
|
+
const hookFilePath = (0, helpers_js_1.getHookFilePathToShowToUser)(configValue);
|
|
181
187
|
(0, utils_js_1.assert)(hookFilePath);
|
|
182
188
|
(0, getHook_js_1.assertHookFn)(hookFn, { hookName, hookFilePath });
|
|
183
189
|
onBeforePrerenderStartHooks.push({
|
|
@@ -272,7 +278,7 @@ async function handlePagesWithStaticRoutes(prerenderContext, renderContext, doNo
|
|
|
272
278
|
_providedByHook: null,
|
|
273
279
|
routeParams,
|
|
274
280
|
_pageId: pageId,
|
|
275
|
-
|
|
281
|
+
_debugRouteMatches: [
|
|
276
282
|
{
|
|
277
283
|
pageId,
|
|
278
284
|
routeType: pageRoute.routeType,
|
|
@@ -313,8 +319,8 @@ async function callOnPrerenderStartHook(prerenderContext, renderContext) {
|
|
|
313
319
|
const configValue = pageConfigGlobal.configValues.onPrerenderStart;
|
|
314
320
|
if (configValue?.value) {
|
|
315
321
|
const { value: hookFn } = configValue;
|
|
316
|
-
// config.onPrerenderStart isn't a computed nor a cumulative config =>
|
|
317
|
-
const hookFilePath = (0,
|
|
322
|
+
// config.onPrerenderStart isn't a computed nor a cumulative config => definedAt should always be defined
|
|
323
|
+
const hookFilePath = (0, helpers_js_1.getHookFilePathToShowToUser)(configValue);
|
|
318
324
|
(0, utils_js_1.assert)(hookFilePath);
|
|
319
325
|
onPrerenderStartHook = {
|
|
320
326
|
hookFn,
|
|
@@ -371,7 +377,7 @@ async function callOnPrerenderStartHook(prerenderContext, renderContext) {
|
|
|
371
377
|
enumerable: false,
|
|
372
378
|
configurable: true
|
|
373
379
|
});
|
|
374
|
-
(0, utils_js_1.assert)((0, utils_js_1.
|
|
380
|
+
(0, utils_js_1.assert)((0, utils_js_1.isPropertyGetter)(pageContext, 'url'));
|
|
375
381
|
(0, utils_js_1.assert)(pageContext.urlOriginal);
|
|
376
382
|
pageContext._urlOriginalBeforeHook = pageContext.urlOriginal;
|
|
377
383
|
});
|
|
@@ -410,7 +416,7 @@ async function callOnPrerenderStartHook(prerenderContext, renderContext) {
|
|
|
410
416
|
prerenderContext.pageContexts = result.prerenderContext.pageContexts;
|
|
411
417
|
prerenderContext.pageContexts.forEach((pageContext) => {
|
|
412
418
|
// TODO/v1-release: remove
|
|
413
|
-
if (!(0, utils_js_1.
|
|
419
|
+
if (pageContext.url && !(0, utils_js_1.isPropertyGetter)(pageContext, 'url')) {
|
|
414
420
|
(0, utils_js_1.assertWarning)(false, msgPrefix +
|
|
415
421
|
' provided pageContext.url but it should provide pageContext.urlOriginal instead, see https://vike.dev/migration/0.4.23', { onlyOnce: true });
|
|
416
422
|
pageContext.urlOriginal = pageContext.url;
|
|
@@ -435,10 +441,9 @@ async function routeAndPrerender(prerenderContext, htmlFiles, prerenderPageIds,
|
|
|
435
441
|
await Promise.all(prerenderContext.pageContexts.map((pageContext) => concurrencyLimit(async () => {
|
|
436
442
|
const { urlOriginal } = pageContext;
|
|
437
443
|
(0, utils_js_1.assert)(urlOriginal);
|
|
438
|
-
const
|
|
439
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(
|
|
440
|
-
|
|
441
|
-
if (routeResult.pageContextAddendum._pageId === null) {
|
|
444
|
+
const pageContextFromRoute = await (0, index_js_1.route)(pageContext);
|
|
445
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextFromRoute, '_pageId', 'null') || (0, utils_js_1.hasProp)(pageContextFromRoute, '_pageId', 'string'));
|
|
446
|
+
if (pageContextFromRoute._pageId === null) {
|
|
442
447
|
let hookName;
|
|
443
448
|
let hookFilePath;
|
|
444
449
|
if (pageContext._providedByHook) {
|
|
@@ -451,17 +456,17 @@ async function routeAndPrerender(prerenderContext, htmlFiles, prerenderPageIds,
|
|
|
451
456
|
}
|
|
452
457
|
if (hookName) {
|
|
453
458
|
(0, utils_js_1.assert)(hookFilePath);
|
|
454
|
-
(0, utils_js_1.assertUsage)(false, `The ${hookName}() hook defined by ${hookFilePath} returns a URL ${picocolors_1.default.cyan(urlOriginal)} that
|
|
459
|
+
(0, utils_js_1.assertUsage)(false, `The ${hookName}() hook defined by ${hookFilePath} returns a URL ${picocolors_1.default.cyan(urlOriginal)} that ${noRouteMatch_js_1.noRouteMatch}. Make sure that the URLs returned by ${hookName}() always match the route of a page.`);
|
|
455
460
|
}
|
|
456
461
|
else {
|
|
457
462
|
// `prerenderHookFile` is `null` when the URL was deduced by the Filesytem Routing of `.page.js` files. The `onBeforeRoute()` can override Filesystem Routing; it is therefore expected that the deduced URL may not match any page.
|
|
458
|
-
(0, utils_js_1.assert)(
|
|
463
|
+
(0, utils_js_1.assert)(pageContextFromRoute._routingProvidedByOnBeforeRouteHook);
|
|
459
464
|
// Abort since the URL doesn't correspond to any page
|
|
460
465
|
return;
|
|
461
466
|
}
|
|
462
467
|
}
|
|
463
|
-
(0, utils_js_1.assert)(
|
|
464
|
-
(0, utils_js_1.objectAssign)(pageContext,
|
|
468
|
+
(0, utils_js_1.assert)(pageContextFromRoute._pageId);
|
|
469
|
+
(0, utils_js_1.objectAssign)(pageContext, pageContextFromRoute);
|
|
465
470
|
const { _pageId: pageId } = pageContext;
|
|
466
471
|
(0, utils_js_1.objectAssign)(pageContext, await (0, loadPageFilesServerSide_js_1.loadPageFilesServerSide)(pageContext));
|
|
467
472
|
let usesClientRouter;
|
|
@@ -469,7 +474,7 @@ async function routeAndPrerender(prerenderContext, htmlFiles, prerenderPageIds,
|
|
|
469
474
|
if (pageContext._pageConfigs.length > 0) {
|
|
470
475
|
const pageConfig = pageContext._pageConfigs.find((p) => p.pageId === pageId);
|
|
471
476
|
(0, utils_js_1.assert)(pageConfig);
|
|
472
|
-
usesClientRouter = (0,
|
|
477
|
+
usesClientRouter = (0, helpers_js_1.getConfigValue)(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
473
478
|
}
|
|
474
479
|
else {
|
|
475
480
|
usesClientRouter = globalContext.pluginManifest.usesClientRouter;
|
|
@@ -515,15 +520,18 @@ function warnContradictoryNoPrerenderList(prerenderPageIds, doNotPrerenderList)
|
|
|
515
520
|
}
|
|
516
521
|
function warnMissingPages(prerenderPageIds, doNotPrerenderList, renderContext, partial) {
|
|
517
522
|
const isV1 = renderContext.pageConfigs.length > 0;
|
|
518
|
-
const hookName = isV1 ? '
|
|
519
|
-
|
|
523
|
+
const hookName = isV1 ? 'onBeforePrerenderStart' : 'prerender';
|
|
524
|
+
/* TODO/after-v1-design-release: document setting `prerender: false` as an alternative to using prerender.partial (both in the warnings and the docs)
|
|
525
|
+
const optOutName = isV1 ? 'prerender' : 'doNotPrerender'
|
|
526
|
+
const msgAddendum = `Explicitly opt-out by setting the config ${optOutName} to ${isV1 ? 'false' : 'true'} or use the option prerender.partial`
|
|
527
|
+
*/
|
|
520
528
|
renderContext.allPageIds
|
|
521
529
|
.filter((pageId) => !prerenderPageIds[pageId])
|
|
522
530
|
.filter((pageId) => !doNotPrerenderList.find((p) => p.pageId === pageId))
|
|
523
531
|
.filter((pageId) => !(0, error_page_js_1.isErrorPage)(pageId, renderContext.pageConfigs))
|
|
524
532
|
.forEach((pageId) => {
|
|
525
|
-
const pageAt =
|
|
526
|
-
(0, utils_js_1.assertWarning)(partial, `Cannot pre-render page ${pageAt} because it has a non-static route,
|
|
533
|
+
const pageAt = isV1 ? pageId : `\`${pageId}.page.*\``;
|
|
534
|
+
(0, utils_js_1.assertWarning)(partial, `Cannot pre-render page ${pageAt} because it has a non-static route, while no ${hookName}() hook returned any URL matching the page's route. You need to use a ${hookName}() hook (https://vike.dev/${hookName}) providing a list of URLs for ${pageAt} that should be pre-rendered. If you don't want to pre-render ${pageAt} then use the option prerender.partial (https://vike.dev/prerender-config#partial) to suppress this warning.`, { onlyOnce: true });
|
|
527
535
|
});
|
|
528
536
|
}
|
|
529
537
|
async function prerender404(htmlFiles, renderContext, prerenderContext) {
|
|
@@ -23,7 +23,7 @@ __exportStar(require("../../utils/objectAssign.js"), exports);
|
|
|
23
23
|
__exportStar(require("../../utils/isObjectWithKeys.js"), exports);
|
|
24
24
|
__exportStar(require("../../utils/isCallable.js"), exports);
|
|
25
25
|
__exportStar(require("../../utils/getOutDirs.js"), exports);
|
|
26
|
-
__exportStar(require("../../utils/
|
|
26
|
+
__exportStar(require("../../utils/isPropertyGetter.js"), exports);
|
|
27
27
|
__exportStar(require("../../utils/filesystemPathHandling.js"), exports);
|
|
28
28
|
__exportStar(require("../../utils/urlToFile.js"), exports);
|
|
29
29
|
__exportStar(require("../../shared/hooks/executeHook.js"), exports);
|
|
@@ -50,19 +50,33 @@ function serializePageContextClientSide(pageContext) {
|
|
|
50
50
|
catch (err) {
|
|
51
51
|
hasWarned = true;
|
|
52
52
|
propsNonSerializable.push(prop);
|
|
53
|
-
|
|
54
|
-
(0, utils_js_1.assertWarning)(false, [
|
|
53
|
+
let msg = [
|
|
55
54
|
`${varName} cannot be serialized and, therefore, cannot be passed to the client.`,
|
|
56
|
-
`Make sure that ${varName} is serializable, or remove ${h(propName)} from ${h('passToClient')}
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
`Make sure that ${varName} is serializable, or remove ${h(propName)} from ${h('passToClient')}.`
|
|
56
|
+
].join(' ');
|
|
57
|
+
if ((0, stringify_1.isJsonSerializerError)(err)) {
|
|
58
|
+
msg = `${msg} Serialization error: ${err.messageCore}.`;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
// When a property getter throws an error
|
|
62
|
+
console.warn('Serialization error:');
|
|
63
|
+
console.warn(err);
|
|
64
|
+
msg = `${msg} The serialization failed because of the error printed above.`;
|
|
65
|
+
}
|
|
66
|
+
// We warn (instead of throwing an error) since Vike's client runtime throws an error (with `assertUsage()`) if the user's client code tries to access the property that cannot be serialized
|
|
67
|
+
(0, utils_js_1.assertWarning)(false, msg, { onlyOnce: false });
|
|
59
68
|
}
|
|
60
69
|
});
|
|
61
70
|
(0, utils_js_1.assert)(hasWarned);
|
|
62
71
|
propsNonSerializable.forEach((prop) => {
|
|
63
72
|
pageContextClient[prop] = notSerializable_js_1.notSerializable;
|
|
64
73
|
});
|
|
65
|
-
|
|
74
|
+
try {
|
|
75
|
+
pageContextSerialized = serialize(pageContextClient);
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
(0, utils_js_1.assert)(false);
|
|
79
|
+
}
|
|
66
80
|
}
|
|
67
81
|
return pageContextSerialized;
|
|
68
82
|
}
|
|
@@ -11,7 +11,7 @@ function debugPageFiles({ pageContext, isHtmlOnly, isClientRouting, pageFilesLoa
|
|
|
11
11
|
const padding = ' - ';
|
|
12
12
|
debug('All page files:', printPageFiles(pageContext._pageFilesAll, true)); // TODO
|
|
13
13
|
debug(`URL:`, pageContext.urlOriginal);
|
|
14
|
-
debug.options({ serialization: { emptyArray: 'No match' } })(`Routing:`, printRouteMatches(pageContext.
|
|
14
|
+
debug.options({ serialization: { emptyArray: 'No match' } })(`Routing:`, printRouteMatches(pageContext._debugRouteMatches));
|
|
15
15
|
debug(`pageId:`, pageContext._pageId);
|
|
16
16
|
debug('Page type:', isHtmlOnly ? 'HTML-only' : 'SSR/SPA');
|
|
17
17
|
debug(`Routing type:`, !isHtmlOnly && isClientRouting ? 'Client Routing' : 'Server Routing');
|
|
@@ -21,14 +21,14 @@ function debugPageFiles({ pageContext, isHtmlOnly, isClientRouting, pageFilesLoa
|
|
|
21
21
|
debug('Client-side entries:', clientEntries);
|
|
22
22
|
debug('Client-side dependencies:', clientDependencies);
|
|
23
23
|
return;
|
|
24
|
-
function printRouteMatches(
|
|
25
|
-
if (
|
|
24
|
+
function printRouteMatches(debugRouteMatches) {
|
|
25
|
+
if (debugRouteMatches === 'ROUTING_ERROR') {
|
|
26
26
|
return 'Routing Failed';
|
|
27
27
|
}
|
|
28
|
-
if (
|
|
28
|
+
if (debugRouteMatches === 'CUSTOM_ROUTING') {
|
|
29
29
|
return 'Custom Routing';
|
|
30
30
|
}
|
|
31
|
-
return
|
|
31
|
+
return debugRouteMatches;
|
|
32
32
|
}
|
|
33
33
|
function printPageFiles(pageFiles, genericPageFilesLast = false) {
|
|
34
34
|
if (pageFiles.length === 0) {
|