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/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigValuesAll };
|
|
2
|
-
import type {
|
|
3
|
-
declare function getVirtualFilePageConfigValuesAll(id: string,
|
|
2
|
+
import type { ResolvedConfig } from 'vite';
|
|
3
|
+
declare function getVirtualFilePageConfigValuesAll(id: string, isDev: boolean, config: ResolvedConfig): Promise<string>;
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -4,11 +4,12 @@ import { getVirtualFileIdPageConfigValuesAll, isVirtualFileIdPageConfigValuesAll
|
|
|
4
4
|
import { getVikeConfig } from './getVikeConfig.js';
|
|
5
5
|
import { extractAssetsAddQuery } from '../../../../shared/extractAssetsQuery.js';
|
|
6
6
|
import { debug } from './debug.js';
|
|
7
|
-
import { getConfigValue } from '../../../../../shared/page-configs/
|
|
7
|
+
import { getConfigValue } from '../../../../../shared/page-configs/helpers.js';
|
|
8
8
|
import { getConfigValueSourcesRelevant } from '../../../shared/getConfigValueSourcesRelevant.js';
|
|
9
|
-
import {
|
|
9
|
+
import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
|
|
10
10
|
import { serializeConfigValueImported } from '../../../../../shared/page-configs/serialize/serializeConfigValue.js';
|
|
11
|
-
|
|
11
|
+
import { getConfigVike } from '../../../../shared/getConfigVike.js';
|
|
12
|
+
async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
|
|
12
13
|
const result = isVirtualFileIdPageConfigValuesAll(id);
|
|
13
14
|
assert(result);
|
|
14
15
|
/* This assertion fails when using includeAssetsImportedByServer
|
|
@@ -18,9 +19,10 @@ async function getVirtualFilePageConfigValuesAll(id, userRootDir, outDirRoot, is
|
|
|
18
19
|
}
|
|
19
20
|
*/
|
|
20
21
|
const { pageId, isForClientSide } = result;
|
|
21
|
-
const { pageConfigs } = await getVikeConfig(
|
|
22
|
+
const { pageConfigs } = await getVikeConfig(config, isDev, true);
|
|
22
23
|
const pageConfig = pageConfigs.find((pageConfig) => pageConfig.pageId === pageId);
|
|
23
24
|
assert(pageConfig);
|
|
25
|
+
const configVike = await getConfigVike(config);
|
|
24
26
|
const code = getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, configVike.includeAssetsImportedByServer, isDev);
|
|
25
27
|
debug(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
26
28
|
return code;
|
|
@@ -38,7 +40,7 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
38
40
|
return;
|
|
39
41
|
if (configValueSource.valueIsFilePath)
|
|
40
42
|
return;
|
|
41
|
-
if (!
|
|
43
|
+
if (!isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: false }))
|
|
42
44
|
return;
|
|
43
45
|
const whitespace = ' ';
|
|
44
46
|
lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigs };
|
|
2
2
|
export { getConfigValueSerialized };
|
|
3
3
|
import type { DefinedAt } from '../../../../../shared/page-configs/PageConfig.js';
|
|
4
|
-
import type {
|
|
5
|
-
declare function getVirtualFilePageConfigs(
|
|
4
|
+
import type { ResolvedConfig } from 'vite';
|
|
5
|
+
declare function getVirtualFilePageConfigs(isForClientSide: boolean, isDev: boolean, id: string, isClientRouting: boolean, config: ResolvedConfig): Promise<string>;
|
|
6
6
|
declare function getConfigValueSerialized(value: unknown, configName: string, definedAt: DefinedAt): string;
|
|
@@ -1,23 +1,31 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigs };
|
|
2
2
|
export { getConfigValueSerialized };
|
|
3
|
-
import { assert, assertUsage, getPropAccessNotation,
|
|
3
|
+
import { assert, assertUsage, getPropAccessNotation, objectEntries } from '../../../utils.js';
|
|
4
4
|
import { getVirtualFileIdPageConfigValuesAll } from '../../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
5
5
|
import { debug } from './debug.js';
|
|
6
|
-
import { stringify } from '@brillout/json-serializer/stringify';
|
|
6
|
+
import { isJsonSerializerError, stringify } from '@brillout/json-serializer/stringify';
|
|
7
7
|
import { getConfigEnv } from './helpers.js';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { getVikeConfig } from './getVikeConfig.js';
|
|
10
|
-
import {
|
|
11
|
-
import { getConfigValueFilePathToShowToUser } from '../../../../../shared/page-configs/
|
|
10
|
+
import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
|
|
11
|
+
import { getConfigValueFilePathToShowToUser } from '../../../../../shared/page-configs/helpers.js';
|
|
12
12
|
import { serializeConfigValue, serializeConfigValueImported } from '../../../../../shared/page-configs/serialize/serializeConfigValue.js';
|
|
13
|
-
async function getVirtualFilePageConfigs(
|
|
14
|
-
const { pageConfigs, pageConfigGlobal } = await getVikeConfig(
|
|
15
|
-
return
|
|
13
|
+
async function getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, config) {
|
|
14
|
+
const { pageConfigs, pageConfigGlobal } = await getVikeConfig(config, isDev, true);
|
|
15
|
+
return getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting) {
|
|
18
18
|
const lines = [];
|
|
19
19
|
const importStatements = [];
|
|
20
20
|
const varCounterContainer = { varCounter: 0 };
|
|
21
|
+
lines.push(getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements, varCounterContainer));
|
|
22
|
+
lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements, varCounterContainer));
|
|
23
|
+
const code = [...importStatements, ...lines].join('\n');
|
|
24
|
+
debug(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
25
|
+
return code;
|
|
26
|
+
}
|
|
27
|
+
function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements, varCounterContainer) {
|
|
28
|
+
const lines = [];
|
|
21
29
|
lines.push('export const pageConfigsSerialized = [');
|
|
22
30
|
pageConfigs.forEach((pageConfig) => {
|
|
23
31
|
const { pageId, routeFilesystem, isErrorPage } = pageConfig;
|
|
@@ -30,7 +38,7 @@ function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, i
|
|
|
30
38
|
lines.push(` configValuesSerialized: {`);
|
|
31
39
|
Object.entries(pageConfig.configValuesComputed).forEach(([configName, configValuesComputed]) => {
|
|
32
40
|
const { value, configEnv } = configValuesComputed;
|
|
33
|
-
if (!
|
|
41
|
+
if (!isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: true }))
|
|
34
42
|
return;
|
|
35
43
|
if (pageConfig.configValueSources[configName])
|
|
36
44
|
return;
|
|
@@ -45,7 +53,8 @@ function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, i
|
|
|
45
53
|
if (configValue) {
|
|
46
54
|
const configEnv = getConfigEnv(pageConfig.configValueSources, configName);
|
|
47
55
|
assert(configEnv, configName);
|
|
48
|
-
|
|
56
|
+
const isEnvMatch = isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: true });
|
|
57
|
+
if (!isEnvMatch)
|
|
49
58
|
return;
|
|
50
59
|
const { value, definedAt } = configValue;
|
|
51
60
|
const valueSerialized = getConfigValueSerialized(value, configName, definedAt);
|
|
@@ -70,6 +79,11 @@ function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, i
|
|
|
70
79
|
lines.push(` },`);
|
|
71
80
|
});
|
|
72
81
|
lines.push('];');
|
|
82
|
+
const code = lines.join('\n');
|
|
83
|
+
return code;
|
|
84
|
+
}
|
|
85
|
+
function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements, varCounterContainer) {
|
|
86
|
+
const lines = [];
|
|
73
87
|
lines.push('export const pageConfigGlobalSerialized = {');
|
|
74
88
|
/* Nothing (yet)
|
|
75
89
|
lines.push(` configValuesSerialized: {`)
|
|
@@ -96,23 +110,31 @@ function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, i
|
|
|
96
110
|
});
|
|
97
111
|
lines.push(` ],`);
|
|
98
112
|
lines.push('};');
|
|
99
|
-
const code =
|
|
100
|
-
debug(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
113
|
+
const code = lines.join('\n');
|
|
101
114
|
return code;
|
|
102
115
|
}
|
|
103
116
|
function getConfigValueSerialized(value, configName, definedAt) {
|
|
104
117
|
const valueName = `config${getPropAccessNotation(configName)}`;
|
|
105
118
|
let configValueSerialized;
|
|
106
119
|
try {
|
|
107
|
-
configValueSerialized = stringify(value, { valueName });
|
|
120
|
+
configValueSerialized = stringify(value, { valueName, forbidReactElements: true });
|
|
108
121
|
}
|
|
109
122
|
catch (err) {
|
|
110
|
-
|
|
123
|
+
let serializationErrMsg = '';
|
|
124
|
+
if (isJsonSerializerError(err)) {
|
|
125
|
+
serializationErrMsg = err.messageCore;
|
|
126
|
+
}
|
|
127
|
+
else {
|
|
128
|
+
// When a property getter throws an error
|
|
129
|
+
console.error('Serialization error:');
|
|
130
|
+
console.error(err);
|
|
131
|
+
serializationErrMsg = 'see serialization error printed above';
|
|
132
|
+
}
|
|
111
133
|
const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
|
|
112
134
|
assert(configValueFilePathToShowToUser);
|
|
113
135
|
assertUsage(false, [
|
|
114
136
|
`The value of the config ${pc.cyan(configName)} cannot be defined inside the file ${configValueFilePathToShowToUser}:`,
|
|
115
|
-
`its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because
|
|
137
|
+
`its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because its value isn't serializable: ${serializationErrMsg}.)`,
|
|
116
138
|
`Only serializable config values can be defined inside +config.h.js files, see https://vike.dev/header-file.`
|
|
117
139
|
].join(' '));
|
|
118
140
|
}
|
|
@@ -6,20 +6,7 @@ function getConfigEnv(configValueSources, configName) {
|
|
|
6
6
|
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
7
7
|
if (!configValueSource)
|
|
8
8
|
return null;
|
|
9
|
-
|
|
10
|
-
return configValueSource.configEnv;
|
|
11
|
-
}
|
|
12
|
-
else {
|
|
13
|
-
// In case of effect/computed config values, there isn't any configValueSource
|
|
14
|
-
// TODO: make it work for custom config definitions
|
|
15
|
-
// - Ideally set configValueSource also for effect/computed config values?
|
|
16
|
-
assert(false, 'TODO');
|
|
17
|
-
/*
|
|
18
|
-
const configDef = configDefinitionsBuiltIn[configName as keyof typeof configDefinitionsBuiltIn]
|
|
19
|
-
if (!configDef) return null
|
|
20
|
-
return configDef.env
|
|
21
|
-
*/
|
|
22
|
-
}
|
|
9
|
+
return configValueSource.configEnv;
|
|
23
10
|
}
|
|
24
11
|
function isConfigSet(configValueSources, configName) {
|
|
25
12
|
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { isRuntimeEnvMatch };
|
|
2
|
+
import type { ConfigEnvInternal } from '../../../../../shared/page-configs/PageConfig.js';
|
|
3
|
+
declare function isRuntimeEnvMatch(configEnv: ConfigEnvInternal, runtime: {
|
|
4
|
+
isForClientSide: boolean;
|
|
5
|
+
isClientRouting: boolean;
|
|
6
|
+
isEager: boolean;
|
|
7
|
+
}): boolean;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { isRuntimeEnvMatch };
|
|
2
|
+
function isRuntimeEnvMatch(configEnv, runtime) {
|
|
3
|
+
const { isForClientSide, isClientRouting, isEager } = runtime;
|
|
4
|
+
if (configEnv === 'config-only')
|
|
5
|
+
return false;
|
|
6
|
+
if (configEnv === (isForClientSide ? 'server-only' : 'client-only'))
|
|
7
|
+
return false;
|
|
8
|
+
if (configEnv === '_routing-eager' || configEnv === '_routing-lazy') {
|
|
9
|
+
if (isForClientSide && !isClientRouting)
|
|
10
|
+
return false;
|
|
11
|
+
if (isEager !== (configEnv === '_routing-eager'))
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
@@ -3,8 +3,8 @@ export { getConfigBuildErrorFormatted };
|
|
|
3
3
|
export { getConfigExecutionErrorIntroMsg as getConfigExecutionErrorIntroMsg };
|
|
4
4
|
export { isTmpFile };
|
|
5
5
|
import 'source-map-support/register.js';
|
|
6
|
-
import {
|
|
7
|
-
declare function transpileAndExecuteFile(filePath:
|
|
6
|
+
import type { FilePathResolved } from '../../../../../shared/page-configs/PageConfig.js';
|
|
7
|
+
declare function transpileAndExecuteFile(filePath: FilePathResolved, isValueFile: boolean, userRootDir: string): Promise<{
|
|
8
8
|
fileExports: Record<string, unknown>;
|
|
9
9
|
}>;
|
|
10
10
|
declare function getConfigBuildErrorFormatted(err: unknown): null | string;
|
|
@@ -7,11 +7,10 @@ import fs from 'fs';
|
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import pc from '@brillout/picocolors';
|
|
9
9
|
import { import_ } from '@brillout/import';
|
|
10
|
-
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, unique, assertWarning, isObject, toPosixPath
|
|
10
|
+
import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, unique, assertWarning, isObject, toPosixPath } from '../../../utils.js';
|
|
11
11
|
import { isImportData, replaceImportStatements } from './replaceImportStatements.js';
|
|
12
12
|
import { vikeConfigDependencies } from './getVikeConfig.js';
|
|
13
13
|
import 'source-map-support/register.js';
|
|
14
|
-
import { getFilePathToShowToUser } from './getFilePathToShowToUser.js';
|
|
15
14
|
import { assertExportsOfConfigFile } from '../../../../../shared/page-configs/assertExports.js';
|
|
16
15
|
assertIsNotProductionRuntime();
|
|
17
16
|
async function transpileAndExecuteFile(filePath, isValueFile, userRootDir) {
|
|
@@ -20,9 +19,9 @@ async function transpileAndExecuteFile(filePath, isValueFile, userRootDir) {
|
|
|
20
19
|
return { fileExports };
|
|
21
20
|
}
|
|
22
21
|
async function transpileFile(filePath, isValueFile, userRootDir) {
|
|
23
|
-
const {
|
|
24
|
-
assertPosixPath(
|
|
25
|
-
vikeConfigDependencies.add(
|
|
22
|
+
const { filePathAbsoluteFilesystem } = filePath;
|
|
23
|
+
assertPosixPath(filePathAbsoluteFilesystem);
|
|
24
|
+
vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
26
25
|
let code = await transpileWithEsbuild(filePath, isValueFile, userRootDir);
|
|
27
26
|
let fileImports = null;
|
|
28
27
|
{
|
|
@@ -36,14 +35,13 @@ async function transpileFile(filePath, isValueFile, userRootDir) {
|
|
|
36
35
|
}
|
|
37
36
|
function transpileImports(codeOriginal, filePath, isValueFile) {
|
|
38
37
|
// Do we need to remove the imports?
|
|
39
|
-
const {
|
|
40
|
-
assertPosixPath(
|
|
41
|
-
const isHeader = isHeaderFile(
|
|
38
|
+
const { filePathAbsoluteFilesystem, filePathToShowToUser } = filePath;
|
|
39
|
+
assertPosixPath(filePathAbsoluteFilesystem);
|
|
40
|
+
const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
|
|
42
41
|
const isPageConfigFile = !isValueFile;
|
|
43
42
|
if (!isHeader && !isPageConfigFile) {
|
|
44
43
|
return null;
|
|
45
44
|
}
|
|
46
|
-
const filePathToShowToUser = getFilePathToShowToUser(filePath);
|
|
47
45
|
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 });
|
|
48
46
|
// Remove the imports
|
|
49
47
|
const res = replaceImportStatements(codeOriginal, filePathToShowToUser);
|
|
@@ -60,7 +58,7 @@ function transpileImports(codeOriginal, filePath, isValueFile) {
|
|
|
60
58
|
return { code, fileImports };
|
|
61
59
|
}
|
|
62
60
|
async function transpileWithEsbuild(filePath, bundle, userRootDir) {
|
|
63
|
-
const entryFilePath = filePath.
|
|
61
|
+
const entryFilePath = filePath.filePathAbsoluteFilesystem;
|
|
64
62
|
const entryFileDir = path.posix.dirname(entryFilePath);
|
|
65
63
|
const options = {
|
|
66
64
|
platform: 'node',
|
|
@@ -125,8 +123,8 @@ async function transpileWithEsbuild(filePath, bundle, userRootDir) {
|
|
|
125
123
|
Object.keys(result.metafile.inputs).forEach((filePathRelative) => {
|
|
126
124
|
filePathRelative = toPosixPath(filePathRelative);
|
|
127
125
|
assertPosixPath(userRootDir);
|
|
128
|
-
const
|
|
129
|
-
vikeConfigDependencies.add(
|
|
126
|
+
const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathRelative);
|
|
127
|
+
vikeConfigDependencies.add(filePathAbsoluteFilesystem);
|
|
130
128
|
});
|
|
131
129
|
}
|
|
132
130
|
const code = result.outputFiles[0].text;
|
|
@@ -134,10 +132,10 @@ async function transpileWithEsbuild(filePath, bundle, userRootDir) {
|
|
|
134
132
|
return code;
|
|
135
133
|
}
|
|
136
134
|
async function executeFile(filePath, code, fileImports, isValueFile) {
|
|
137
|
-
const {
|
|
135
|
+
const { filePathAbsoluteFilesystem, filePathRelativeToUserRootDir } = filePath;
|
|
138
136
|
// Alternative to using a temporary file: https://github.com/vitejs/vite/pull/13269
|
|
139
137
|
// - But seems to break source maps, so I don't think it's worth it
|
|
140
|
-
const filePathTmp = getFilePathTmp(
|
|
138
|
+
const filePathTmp = getFilePathTmp(filePathAbsoluteFilesystem);
|
|
141
139
|
fs.writeFileSync(filePathTmp, code);
|
|
142
140
|
const clean = () => fs.unlinkSync(filePathTmp);
|
|
143
141
|
let fileExports = {};
|
|
@@ -160,7 +158,7 @@ async function executeFile(filePath, code, fileImports, isValueFile) {
|
|
|
160
158
|
fileExports = { ...fileExports };
|
|
161
159
|
if (fileImports && !isValueFile) {
|
|
162
160
|
assert(filePathRelativeToUserRootDir !== undefined);
|
|
163
|
-
const filePathToShowToUser = filePathRelativeToUserRootDir ??
|
|
161
|
+
const filePathToShowToUser = filePathRelativeToUserRootDir ?? filePathAbsoluteFilesystem;
|
|
164
162
|
assertImportsAreReExported(fileImports, fileExports, filePathToShowToUser);
|
|
165
163
|
}
|
|
166
164
|
return { fileExports };
|
|
@@ -228,11 +226,11 @@ function assertImportsAreReExported(fileImports, fileExports, filePathToShowToUs
|
|
|
228
226
|
const importStatements = unique(fileImportsUnused.map((fi) => fi.importStatementCode));
|
|
229
227
|
const importNamesUnused = fileImportsUnused.map((fi) => pc.cyan(fi.importLocalName)).join(', ');
|
|
230
228
|
const singular = fileImportsUnused.length === 1;
|
|
231
|
-
|
|
229
|
+
assertWarning(fileImportsUnused.length === 0, [
|
|
232
230
|
`${filePathToShowToUser} imports the following:`,
|
|
233
231
|
...importStatements.map((s) => pc.cyan(` ${s}`)),
|
|
234
232
|
`But the import${singular ? '' : 's'} ${importNamesUnused} ${singular ? "isn't" : "aren't"} re-exported at ${pc.cyan('export default { ... }')} and therefore ${singular ? 'has' : 'have'} no effect, see explanation at https://vike.dev/header-file`
|
|
235
|
-
].join('\n'));
|
|
233
|
+
].join('\n'), { onlyOnce: true });
|
|
236
234
|
}
|
|
237
235
|
function getExportedStrings(obj) {
|
|
238
236
|
const exportedStrings = [];
|
|
@@ -273,7 +271,7 @@ function triggerPrepareStackTrace(err) {
|
|
|
273
271
|
function getErrIntroMsg(operation, filePath) {
|
|
274
272
|
const msg = [
|
|
275
273
|
pc.red(`Failed to ${operation}`),
|
|
276
|
-
pc.bold(pc.red(
|
|
274
|
+
pc.bold(pc.red(filePath.filePathToShowToUser)),
|
|
277
275
|
pc.red(`because:`)
|
|
278
276
|
].join(' ');
|
|
279
277
|
return msg;
|
|
@@ -13,6 +13,7 @@ function previewConfig() {
|
|
|
13
13
|
apply: 'serve',
|
|
14
14
|
config(config) {
|
|
15
15
|
return {
|
|
16
|
+
appType: 'custom',
|
|
16
17
|
build: {
|
|
17
18
|
outDir: resolveOutDir(config)
|
|
18
19
|
}
|
|
@@ -23,12 +24,20 @@ function previewConfig() {
|
|
|
23
24
|
configVike = await getConfigVike(config);
|
|
24
25
|
},
|
|
25
26
|
configurePreviewServer(server) {
|
|
27
|
+
/* - Couldn't make `appType: 'mpa'` work as of npm:@brillout/vite@5.0.0-beta.14.0426910c
|
|
28
|
+
- This ugly hack to set appType for preview won't be need once https://github.com/vitejs/vite/pull/14855 is merged.
|
|
29
|
+
config.appType = 'mpa'
|
|
30
|
+
*/
|
|
26
31
|
markEnvAsPreview();
|
|
27
32
|
return () => {
|
|
28
33
|
assertDist();
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
/* 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'`.
|
|
35
|
+
if (!configVike.prerender || configVike.prerender.partial) {
|
|
36
|
+
addSsrMiddleware(server.middlewares)
|
|
31
37
|
}
|
|
38
|
+
/*/
|
|
39
|
+
addSsrMiddleware(server.middlewares);
|
|
40
|
+
//*/
|
|
32
41
|
addStatic404Middleware(server.middlewares);
|
|
33
42
|
};
|
|
34
43
|
}
|
|
@@ -5,7 +5,7 @@ export { prerenderForceExit };
|
|
|
5
5
|
import '../runtime/page-files/setup.js';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { route } from '../../shared/route/index.js';
|
|
8
|
-
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs,
|
|
8
|
+
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, executeHook, isPlainObject, setNodeEnvToProduction } from './utils.js';
|
|
9
9
|
import { pLimit } from '../../utils/pLimit.js';
|
|
10
10
|
import { prerenderPage, prerender404Page, getRenderContext, getPageContextInitEnhanced } from '../runtime/renderPage/renderPageAlreadyRouted.js';
|
|
11
11
|
import pc from '@brillout/picocolors';
|
|
@@ -16,7 +16,7 @@ import { getConfigVike } from '../shared/getConfigVike.js';
|
|
|
16
16
|
import { getPageFilesServerSide } from '../../shared/getPageFiles.js';
|
|
17
17
|
import { getPageContextRequestUrl } from '../../shared/getPageContextRequestUrl.js';
|
|
18
18
|
import { getUrlFromRouteString } from '../../shared/route/resolveRouteString.js';
|
|
19
|
-
import { getConfigValue, getConfigValueFilePathToShowToUser, getHookFilePathToShowToUser } from '../../shared/page-configs/
|
|
19
|
+
import { getConfigValue, getConfigValueFilePathToShowToUser, getHookFilePathToShowToUser } from '../../shared/page-configs/helpers.js';
|
|
20
20
|
import { loadConfigValues } from '../../shared/page-configs/loadConfigValues.js';
|
|
21
21
|
import { isErrorPage } from '../../shared/error-page.js';
|
|
22
22
|
import { addUrlComputedProps } from '../../shared/addUrlComputedProps.js';
|
|
@@ -24,6 +24,8 @@ import { assertPathIsFilesystemAbsolute } from '../../utils/assertPathIsFilesyst
|
|
|
24
24
|
import { isAbortError } from '../../shared/route/abort.js';
|
|
25
25
|
import { loadPageFilesServerSide } from '../runtime/renderPage/loadPageFilesServerSide.js';
|
|
26
26
|
import { assertHookFn } from '../../shared/hooks/getHook.js';
|
|
27
|
+
import { noRouteMatch } from '../../shared/route/noRouteMatch.js';
|
|
28
|
+
import { getVikeConfig } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
|
|
27
29
|
async function prerenderFromAPI(options = {}) {
|
|
28
30
|
await runPrerender(options, 'prerender()');
|
|
29
31
|
}
|
|
@@ -67,7 +69,8 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
67
69
|
pageContextInit: options.pageContextInit ?? null
|
|
68
70
|
});
|
|
69
71
|
const doNotPrerenderList = [];
|
|
70
|
-
await
|
|
72
|
+
const vikeConfig = await getVikeConfig(viteConfig, false);
|
|
73
|
+
await collectDoNoPrerenderList(renderContext, vikeConfig.pageConfigs, doNotPrerenderList, concurrencyLimit);
|
|
71
74
|
await callOnBeforePrerenderStartHooks(prerenderContext, renderContext, concurrencyLimit);
|
|
72
75
|
await handlePagesWithStaticRoutes(prerenderContext, renderContext, doNotPrerenderList, concurrencyLimit);
|
|
73
76
|
await callOnPrerenderStartHook(prerenderContext, renderContext);
|
|
@@ -82,8 +85,9 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
82
85
|
await Promise.all(htmlFiles.map((htmlFile) => writeHtmlFile(htmlFile, root, outDirClient, concurrencyLimit, options.onPagePrerender, logLevel)));
|
|
83
86
|
warnMissingPages(prerenderPageIds, doNotPrerenderList, renderContext, partial);
|
|
84
87
|
}
|
|
85
|
-
async function collectDoNoPrerenderList(renderContext, doNotPrerenderList, concurrencyLimit) {
|
|
86
|
-
|
|
88
|
+
async function collectDoNoPrerenderList(renderContext, pageConfigs, doNotPrerenderList, concurrencyLimit) {
|
|
89
|
+
// V1 design
|
|
90
|
+
pageConfigs.forEach((pageConfig) => {
|
|
87
91
|
const configName = 'prerender';
|
|
88
92
|
const configValue = getConfigValue(pageConfig, configName, 'boolean');
|
|
89
93
|
if (configValue?.value === false) {
|
|
@@ -97,6 +101,8 @@ async function collectDoNoPrerenderList(renderContext, doNotPrerenderList, concu
|
|
|
97
101
|
});
|
|
98
102
|
}
|
|
99
103
|
});
|
|
104
|
+
// Old design
|
|
105
|
+
// TODO/v1-release: remove
|
|
100
106
|
await Promise.all(renderContext.pageFilesAll
|
|
101
107
|
.filter((p) => {
|
|
102
108
|
assertExportNames(p);
|
|
@@ -244,7 +250,7 @@ async function handlePagesWithStaticRoutes(prerenderContext, renderContext, doNo
|
|
|
244
250
|
_providedByHook: null,
|
|
245
251
|
routeParams,
|
|
246
252
|
_pageId: pageId,
|
|
247
|
-
|
|
253
|
+
_debugRouteMatches: [
|
|
248
254
|
{
|
|
249
255
|
pageId,
|
|
250
256
|
routeType: pageRoute.routeType,
|
|
@@ -285,7 +291,7 @@ async function callOnPrerenderStartHook(prerenderContext, renderContext) {
|
|
|
285
291
|
const configValue = pageConfigGlobal.configValues.onPrerenderStart;
|
|
286
292
|
if (configValue?.value) {
|
|
287
293
|
const { value: hookFn } = configValue;
|
|
288
|
-
// config.onPrerenderStart isn't a computed nor a cumulative config =>
|
|
294
|
+
// config.onPrerenderStart isn't a computed nor a cumulative config => definedAt should always be defined
|
|
289
295
|
const hookFilePath = getHookFilePathToShowToUser(configValue);
|
|
290
296
|
assert(hookFilePath);
|
|
291
297
|
onPrerenderStartHook = {
|
|
@@ -343,7 +349,7 @@ async function callOnPrerenderStartHook(prerenderContext, renderContext) {
|
|
|
343
349
|
enumerable: false,
|
|
344
350
|
configurable: true
|
|
345
351
|
});
|
|
346
|
-
assert(
|
|
352
|
+
assert(isPropertyGetter(pageContext, 'url'));
|
|
347
353
|
assert(pageContext.urlOriginal);
|
|
348
354
|
pageContext._urlOriginalBeforeHook = pageContext.urlOriginal;
|
|
349
355
|
});
|
|
@@ -382,7 +388,7 @@ async function callOnPrerenderStartHook(prerenderContext, renderContext) {
|
|
|
382
388
|
prerenderContext.pageContexts = result.prerenderContext.pageContexts;
|
|
383
389
|
prerenderContext.pageContexts.forEach((pageContext) => {
|
|
384
390
|
// TODO/v1-release: remove
|
|
385
|
-
if (!
|
|
391
|
+
if (pageContext.url && !isPropertyGetter(pageContext, 'url')) {
|
|
386
392
|
assertWarning(false, msgPrefix +
|
|
387
393
|
' provided pageContext.url but it should provide pageContext.urlOriginal instead, see https://vike.dev/migration/0.4.23', { onlyOnce: true });
|
|
388
394
|
pageContext.urlOriginal = pageContext.url;
|
|
@@ -407,10 +413,9 @@ async function routeAndPrerender(prerenderContext, htmlFiles, prerenderPageIds,
|
|
|
407
413
|
await Promise.all(prerenderContext.pageContexts.map((pageContext) => concurrencyLimit(async () => {
|
|
408
414
|
const { urlOriginal } = pageContext;
|
|
409
415
|
assert(urlOriginal);
|
|
410
|
-
const
|
|
411
|
-
assert(hasProp(
|
|
412
|
-
|
|
413
|
-
if (routeResult.pageContextAddendum._pageId === null) {
|
|
416
|
+
const pageContextFromRoute = await route(pageContext);
|
|
417
|
+
assert(hasProp(pageContextFromRoute, '_pageId', 'null') || hasProp(pageContextFromRoute, '_pageId', 'string'));
|
|
418
|
+
if (pageContextFromRoute._pageId === null) {
|
|
414
419
|
let hookName;
|
|
415
420
|
let hookFilePath;
|
|
416
421
|
if (pageContext._providedByHook) {
|
|
@@ -423,17 +428,17 @@ async function routeAndPrerender(prerenderContext, htmlFiles, prerenderPageIds,
|
|
|
423
428
|
}
|
|
424
429
|
if (hookName) {
|
|
425
430
|
assert(hookFilePath);
|
|
426
|
-
assertUsage(false, `The ${hookName}() hook defined by ${hookFilePath} returns a URL ${pc.cyan(urlOriginal)} that
|
|
431
|
+
assertUsage(false, `The ${hookName}() hook defined by ${hookFilePath} returns a URL ${pc.cyan(urlOriginal)} that ${noRouteMatch}. Make sure that the URLs returned by ${hookName}() always match the route of a page.`);
|
|
427
432
|
}
|
|
428
433
|
else {
|
|
429
434
|
// `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.
|
|
430
|
-
assert(
|
|
435
|
+
assert(pageContextFromRoute._routingProvidedByOnBeforeRouteHook);
|
|
431
436
|
// Abort since the URL doesn't correspond to any page
|
|
432
437
|
return;
|
|
433
438
|
}
|
|
434
439
|
}
|
|
435
|
-
assert(
|
|
436
|
-
objectAssign(pageContext,
|
|
440
|
+
assert(pageContextFromRoute._pageId);
|
|
441
|
+
objectAssign(pageContext, pageContextFromRoute);
|
|
437
442
|
const { _pageId: pageId } = pageContext;
|
|
438
443
|
objectAssign(pageContext, await loadPageFilesServerSide(pageContext));
|
|
439
444
|
let usesClientRouter;
|
|
@@ -487,15 +492,18 @@ function warnContradictoryNoPrerenderList(prerenderPageIds, doNotPrerenderList)
|
|
|
487
492
|
}
|
|
488
493
|
function warnMissingPages(prerenderPageIds, doNotPrerenderList, renderContext, partial) {
|
|
489
494
|
const isV1 = renderContext.pageConfigs.length > 0;
|
|
490
|
-
const hookName = isV1 ? '
|
|
491
|
-
|
|
495
|
+
const hookName = isV1 ? 'onBeforePrerenderStart' : 'prerender';
|
|
496
|
+
/* TODO/after-v1-design-release: document setting `prerender: false` as an alternative to using prerender.partial (both in the warnings and the docs)
|
|
497
|
+
const optOutName = isV1 ? 'prerender' : 'doNotPrerender'
|
|
498
|
+
const msgAddendum = `Explicitly opt-out by setting the config ${optOutName} to ${isV1 ? 'false' : 'true'} or use the option prerender.partial`
|
|
499
|
+
*/
|
|
492
500
|
renderContext.allPageIds
|
|
493
501
|
.filter((pageId) => !prerenderPageIds[pageId])
|
|
494
502
|
.filter((pageId) => !doNotPrerenderList.find((p) => p.pageId === pageId))
|
|
495
503
|
.filter((pageId) => !isErrorPage(pageId, renderContext.pageConfigs))
|
|
496
504
|
.forEach((pageId) => {
|
|
497
|
-
const pageAt =
|
|
498
|
-
assertWarning(partial, `Cannot pre-render page ${pageAt} because it has a non-static route,
|
|
505
|
+
const pageAt = isV1 ? pageId : `\`${pageId}.page.*\``;
|
|
506
|
+
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 });
|
|
499
507
|
});
|
|
500
508
|
}
|
|
501
509
|
async function prerender404(htmlFiles, renderContext, prerenderContext) {
|
|
@@ -5,7 +5,7 @@ export * from '../../utils/objectAssign.js';
|
|
|
5
5
|
export * from '../../utils/isObjectWithKeys.js';
|
|
6
6
|
export * from '../../utils/isCallable.js';
|
|
7
7
|
export * from '../../utils/getOutDirs.js';
|
|
8
|
-
export * from '../../utils/
|
|
8
|
+
export * from '../../utils/isPropertyGetter.js';
|
|
9
9
|
export * from '../../utils/filesystemPathHandling.js';
|
|
10
10
|
export * from '../../utils/urlToFile.js';
|
|
11
11
|
export * from '../../shared/hooks/executeHook.js';
|
|
@@ -7,7 +7,7 @@ export * from '../../utils/objectAssign.js';
|
|
|
7
7
|
export * from '../../utils/isObjectWithKeys.js';
|
|
8
8
|
export * from '../../utils/isCallable.js';
|
|
9
9
|
export * from '../../utils/getOutDirs.js';
|
|
10
|
-
export * from '../../utils/
|
|
10
|
+
export * from '../../utils/isPropertyGetter.js';
|
|
11
11
|
export * from '../../utils/filesystemPathHandling.js';
|
|
12
12
|
export * from '../../utils/urlToFile.js';
|
|
13
13
|
export * from '../../shared/hooks/executeHook.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { serializePageContextClientSide };
|
|
2
2
|
export { serializePageContextAbort };
|
|
3
|
-
import { stringify } from '@brillout/json-serializer/stringify';
|
|
3
|
+
import { stringify, isJsonSerializerError } from '@brillout/json-serializer/stringify';
|
|
4
4
|
import { assert, assertWarning, hasProp, unique } from '../utils.js';
|
|
5
5
|
import { isErrorPage } from '../../../shared/error-page.js';
|
|
6
6
|
import { addIs404ToPageProps } from '../../../shared/addIs404ToPageProps.js';
|
|
@@ -46,19 +46,33 @@ function serializePageContextClientSide(pageContext) {
|
|
|
46
46
|
catch (err) {
|
|
47
47
|
hasWarned = true;
|
|
48
48
|
propsNonSerializable.push(prop);
|
|
49
|
-
|
|
50
|
-
assertWarning(false, [
|
|
49
|
+
let msg = [
|
|
51
50
|
`${varName} cannot be serialized and, therefore, cannot be passed to the client.`,
|
|
52
|
-
`Make sure that ${varName} is serializable, or remove ${h(propName)} from ${h('passToClient')}
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
`Make sure that ${varName} is serializable, or remove ${h(propName)} from ${h('passToClient')}.`
|
|
52
|
+
].join(' ');
|
|
53
|
+
if (isJsonSerializerError(err)) {
|
|
54
|
+
msg = `${msg} Serialization error: ${err.messageCore}.`;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// When a property getter throws an error
|
|
58
|
+
console.warn('Serialization error:');
|
|
59
|
+
console.warn(err);
|
|
60
|
+
msg = `${msg} The serialization failed because of the error printed above.`;
|
|
61
|
+
}
|
|
62
|
+
// 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
|
|
63
|
+
assertWarning(false, msg, { onlyOnce: false });
|
|
55
64
|
}
|
|
56
65
|
});
|
|
57
66
|
assert(hasWarned);
|
|
58
67
|
propsNonSerializable.forEach((prop) => {
|
|
59
68
|
pageContextClient[prop] = notSerializable;
|
|
60
69
|
});
|
|
61
|
-
|
|
70
|
+
try {
|
|
71
|
+
pageContextSerialized = serialize(pageContextClient);
|
|
72
|
+
}
|
|
73
|
+
catch (err) {
|
|
74
|
+
assert(false);
|
|
75
|
+
}
|
|
62
76
|
}
|
|
63
77
|
return pageContextSerialized;
|
|
64
78
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { debugPageFiles };
|
|
2
|
-
export type {
|
|
3
|
-
import { RouteMatches } from '../../../shared/route/index.js';
|
|
2
|
+
export type { PageContextDebugRouteMatches };
|
|
3
|
+
import type { RouteMatches } from '../../../shared/route/index.js';
|
|
4
4
|
import type { ClientDependency } from '../../../shared/getPageFiles/analyzePageClientSide/ClientDependency.js';
|
|
5
5
|
import type { PageFile } from '../../../shared/getPageFiles.js';
|
|
6
6
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
7
|
-
type
|
|
8
|
-
|
|
7
|
+
type PageContextDebugRouteMatches = {
|
|
8
|
+
_debugRouteMatches: 'ROUTING_ERROR' | RouteMatches;
|
|
9
9
|
};
|
|
10
10
|
declare function debugPageFiles({ pageContext, isHtmlOnly, isClientRouting, pageFilesLoaded, pageFilesServerSide, pageFilesClientSide, clientEntries, clientDependencies }: {
|
|
11
11
|
pageContext: {
|
|
@@ -13,7 +13,7 @@ declare function debugPageFiles({ pageContext, isHtmlOnly, isClientRouting, page
|
|
|
13
13
|
_pageId: string;
|
|
14
14
|
_pageFilesAll: PageFile[];
|
|
15
15
|
_pageConfigs: PageConfigRuntime[];
|
|
16
|
-
} &
|
|
16
|
+
} & PageContextDebugRouteMatches;
|
|
17
17
|
isHtmlOnly: boolean;
|
|
18
18
|
isClientRouting: boolean;
|
|
19
19
|
pageFilesLoaded: PageFile[];
|