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.
Files changed (198) hide show
  1. package/dist/cjs/__internal/index.js +6 -2
  2. package/dist/cjs/node/plugin/plugins/buildConfig.js +3 -3
  3. package/dist/cjs/node/plugin/plugins/commonConfig.js +0 -3
  4. package/dist/cjs/node/plugin/plugins/config/index.js +3 -3
  5. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +8 -8
  6. package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -0
  7. package/dist/cjs/node/plugin/plugins/envVars.js +34 -20
  8. package/dist/cjs/node/plugin/plugins/importBuild/index.js +3 -3
  9. package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
  10. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +3 -3
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -4
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +249 -228
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +8 -6
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +36 -14
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +18 -0
  18. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +15 -17
  19. package/dist/cjs/node/plugin/plugins/previewConfig.js +11 -2
  20. package/dist/cjs/node/prerender/runPrerender.js +34 -26
  21. package/dist/cjs/node/prerender/utils.js +1 -1
  22. package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +20 -6
  23. package/dist/cjs/node/runtime/renderPage/debugPageFiles.js +5 -5
  24. package/dist/cjs/node/runtime/renderPage/log404/index.js +28 -17
  25. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -3
  26. package/dist/cjs/node/runtime/renderPage.js +3 -3
  27. package/dist/cjs/node/runtime/utils.js +1 -1
  28. package/dist/cjs/node/shared/getClientEntryFilePath.js +2 -2
  29. package/dist/cjs/node/shared/getConfigVike.js +4 -1
  30. package/dist/cjs/shared/addUrlComputedProps.js +24 -12
  31. package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +4 -6
  32. package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
  33. package/dist/cjs/shared/hooks/getHook.js +1 -1
  34. package/dist/cjs/shared/page-configs/getExportPath.js +3 -3
  35. package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +43 -0
  36. package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +44 -0
  37. package/dist/cjs/shared/page-configs/helpers.js +33 -0
  38. package/dist/cjs/shared/page-configs/loadConfigValues.js +2 -2
  39. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +14 -13
  40. package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -2
  41. package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +9 -10
  42. package/dist/cjs/shared/route/abort.js +1 -1
  43. package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +41 -15
  44. package/dist/cjs/shared/route/index.js +22 -32
  45. package/dist/cjs/shared/route/loadPageRoutes.js +11 -10
  46. package/dist/cjs/shared/route/noRouteMatch.js +4 -0
  47. package/dist/cjs/shared/route/resolveRouteFunction.js +1 -1
  48. package/dist/cjs/shared/utils.js +1 -1
  49. package/dist/cjs/utils/getFilePathAbsolute.js +11 -11
  50. package/dist/cjs/utils/isExternalLink.js +7 -0
  51. package/dist/cjs/utils/{hasPropertyGetter.js → isPropertyGetter.js} +3 -3
  52. package/dist/cjs/utils/onPageVisibilityChange.js +19 -0
  53. package/dist/cjs/utils/parseUrl.js +1 -1
  54. package/dist/cjs/utils/projectInfo.js +1 -1
  55. package/dist/cjs/utils/truncateString.js +12 -7
  56. package/dist/esm/__internal/index.d.ts +6 -3
  57. package/dist/esm/__internal/index.js +8 -3
  58. package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -3
  59. package/dist/esm/client/client-routing-runtime/createPageContext.js +3 -4
  60. package/dist/esm/client/client-routing-runtime/entry.js +2 -2
  61. package/dist/esm/client/client-routing-runtime/getBaseServer.d.ts +2 -1
  62. package/dist/esm/client/client-routing-runtime/getBaseServer.js +2 -1
  63. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +39 -0
  64. package/dist/esm/client/client-routing-runtime/{getPageContext.js → getPageContextFromHooks.js} +50 -79
  65. package/dist/esm/client/client-routing-runtime/history.d.ts +3 -1
  66. package/dist/esm/client/client-routing-runtime/history.js +31 -9
  67. package/dist/esm/client/client-routing-runtime/installClientRouter.d.ts +2 -0
  68. package/dist/esm/client/client-routing-runtime/installClientRouter.js +22 -0
  69. package/dist/esm/client/client-routing-runtime/isClientSideRoutable.d.ts +8 -0
  70. package/dist/esm/client/client-routing-runtime/isClientSideRoutable.js +12 -0
  71. package/dist/esm/client/client-routing-runtime/navigate.d.ts +0 -2
  72. package/dist/esm/client/client-routing-runtime/navigate.js +9 -8
  73. package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.d.ts +4 -0
  74. package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +63 -0
  75. package/dist/esm/client/client-routing-runtime/onLinkClick.d.ts +2 -0
  76. package/dist/esm/client/client-routing-runtime/onLinkClick.js +40 -0
  77. package/dist/esm/client/client-routing-runtime/prefetch.js +54 -29
  78. package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +19 -0
  79. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +347 -0
  80. package/dist/esm/client/client-routing-runtime/scrollRestoration.d.ts +6 -0
  81. package/dist/esm/client/client-routing-runtime/scrollRestoration.js +25 -0
  82. package/dist/esm/client/client-routing-runtime/setScrollPosition.d.ts +7 -0
  83. package/dist/esm/client/client-routing-runtime/setScrollPosition.js +77 -0
  84. package/dist/esm/client/client-routing-runtime/skipLink.d.ts +0 -1
  85. package/dist/esm/client/client-routing-runtime/skipLink.js +9 -5
  86. package/dist/esm/client/client-routing-runtime/utils.d.ts +2 -0
  87. package/dist/esm/client/client-routing-runtime/utils.js +2 -0
  88. package/dist/esm/client/server-routing-runtime/getPageContext.js +1 -1
  89. package/dist/esm/client/shared/executeOnRenderClientHook.js +6 -5
  90. package/dist/esm/client/shared/getPageContextProxyForUser.js +13 -7
  91. package/dist/esm/client/shared/loadPageFilesClientSide.d.ts +8 -3
  92. package/dist/esm/client/shared/loadPageFilesClientSide.js +5 -5
  93. package/dist/esm/node/plugin/plugins/buildConfig.js +3 -3
  94. package/dist/esm/node/plugin/plugins/commonConfig.js +0 -3
  95. package/dist/esm/node/plugin/plugins/config/index.js +4 -4
  96. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +9 -9
  97. package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -0
  98. package/dist/esm/node/plugin/plugins/envVars.d.ts +2 -0
  99. package/dist/esm/node/plugin/plugins/envVars.js +35 -20
  100. package/dist/esm/node/plugin/plugins/importBuild/index.js +3 -3
  101. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
  102. package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -3
  103. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
  104. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -4
  105. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
  106. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
  107. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -1
  108. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +250 -229
  109. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +2 -2
  110. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +7 -5
  111. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +2 -2
  112. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +37 -15
  113. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
  114. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +7 -0
  115. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +15 -0
  116. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
  117. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +16 -18
  118. package/dist/esm/node/plugin/plugins/previewConfig.js +11 -2
  119. package/dist/esm/node/prerender/runPrerender.js +29 -21
  120. package/dist/esm/node/prerender/utils.d.ts +1 -1
  121. package/dist/esm/node/prerender/utils.js +1 -1
  122. package/dist/esm/node/runtime/html/serializePageContextClientSide.js +21 -7
  123. package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +5 -5
  124. package/dist/esm/node/runtime/renderPage/debugPageFiles.js +5 -5
  125. package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.d.ts +2 -2
  126. package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
  127. package/dist/esm/node/runtime/renderPage/log404/index.js +28 -16
  128. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
  129. package/dist/esm/node/runtime/renderPage.js +3 -3
  130. package/dist/esm/node/runtime/utils.d.ts +1 -1
  131. package/dist/esm/node/runtime/utils.js +1 -1
  132. package/dist/esm/node/shared/getClientEntryFilePath.js +1 -1
  133. package/dist/esm/node/shared/getConfigVike.d.ts +2 -1
  134. package/dist/esm/node/shared/getConfigVike.js +4 -1
  135. package/dist/esm/shared/addUrlComputedProps.d.ts +1 -0
  136. package/dist/esm/shared/addUrlComputedProps.js +25 -13
  137. package/dist/esm/shared/getPageFiles/analyzeClientSide.js +2 -4
  138. package/dist/esm/shared/getPageFiles/getExports.js +2 -2
  139. package/dist/esm/shared/hooks/getHook.js +1 -1
  140. package/dist/esm/shared/page-configs/PageConfig.d.ts +55 -31
  141. package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
  142. package/dist/esm/shared/page-configs/getExportPath.js +3 -3
  143. package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +7 -0
  144. package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +37 -0
  145. package/dist/esm/shared/page-configs/helpers/getConfigValue.d.ts +14 -0
  146. package/dist/esm/shared/page-configs/helpers/getConfigValue.js +38 -0
  147. package/dist/esm/shared/page-configs/helpers.d.ts +13 -0
  148. package/dist/esm/shared/page-configs/helpers.js +27 -0
  149. package/dist/esm/shared/page-configs/loadConfigValues.js +2 -2
  150. package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +4 -4
  151. package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +15 -11
  152. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -2
  153. package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +9 -10
  154. package/dist/esm/shared/route/abort.js +1 -1
  155. package/dist/esm/shared/route/executeOnBeforeRouteHook.d.ts +5 -8
  156. package/dist/esm/shared/route/executeOnBeforeRouteHook.js +41 -15
  157. package/dist/esm/shared/route/index.d.ts +12 -10
  158. package/dist/esm/shared/route/index.js +23 -33
  159. package/dist/esm/shared/route/loadPageRoutes.js +8 -7
  160. package/dist/esm/shared/route/noRouteMatch.d.ts +1 -0
  161. package/dist/esm/shared/route/noRouteMatch.js +1 -0
  162. package/dist/esm/shared/route/resolveRouteFunction.js +1 -1
  163. package/dist/esm/shared/utils.d.ts +1 -1
  164. package/dist/esm/shared/utils.js +1 -1
  165. package/dist/esm/utils/getFilePathAbsolute.d.ts +1 -1
  166. package/dist/esm/utils/getFilePathAbsolute.js +11 -11
  167. package/dist/esm/utils/isPropertyGetter.d.ts +1 -0
  168. package/dist/esm/utils/{hasPropertyGetter.js → isPropertyGetter.js} +1 -1
  169. package/dist/esm/utils/onPageVisibilityChange.d.ts +4 -0
  170. package/dist/esm/utils/onPageVisibilityChange.js +16 -0
  171. package/dist/esm/utils/parseUrl.js +1 -1
  172. package/dist/esm/utils/projectInfo.d.ts +1 -1
  173. package/dist/esm/utils/projectInfo.js +1 -1
  174. package/dist/esm/utils/truncateString.d.ts +2 -1
  175. package/dist/esm/utils/truncateString.js +10 -7
  176. package/node/cli/bin-entry.js +1 -1
  177. package/package.json +2 -3
  178. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -16
  179. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -13
  180. package/dist/cjs/shared/page-configs/utils.js +0 -103
  181. package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +0 -29
  182. package/dist/esm/client/client-routing-runtime/getPageId.d.ts +0 -10
  183. package/dist/esm/client/client-routing-runtime/getPageId.js +0 -17
  184. package/dist/esm/client/client-routing-runtime/navigationState.d.ts +0 -5
  185. package/dist/esm/client/client-routing-runtime/navigationState.js +0 -14
  186. package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.d.ts +0 -2
  187. package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.js +0 -15
  188. package/dist/esm/client/client-routing-runtime/useClientRouter.d.ts +0 -6
  189. package/dist/esm/client/client-routing-runtime/useClientRouter.js +0 -493
  190. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +0 -24
  191. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -13
  192. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.d.ts +0 -3
  193. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -10
  194. package/dist/esm/shared/page-configs/utils.d.ts +0 -35
  195. package/dist/esm/shared/page-configs/utils.js +0 -97
  196. package/dist/esm/utils/hasPropertyGetter.d.ts +0 -1
  197. /package/dist/esm/{client/client-routing-runtime → utils}/isExternalLink.d.ts +0 -0
  198. /package/dist/esm/{client/client-routing-runtime → utils}/isExternalLink.js +0 -0
@@ -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 utils_js_2 = require("../../../../../shared/page-configs/utils.js");
9
+ const helpers_js_1 = require("../../../../../shared/page-configs/helpers.js");
10
10
  const getConfigValueSourcesRelevant_js_1 = require("../../../shared/getConfigValueSourcesRelevant.js");
11
- const isConfigEnvMatch_js_1 = require("./isConfigEnvMatch.js");
11
+ const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
12
12
  const serializeConfigValue_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValue.js");
13
- async function getVirtualFilePageConfigValuesAll(id, userRootDir, outDirRoot, isDev, configVike) {
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)(userRootDir, outDirRoot, isDev, configVike.extensions, true);
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, utils_js_2.getConfigValue)(pageConfig, 'clientRouting', 'boolean');
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, isConfigEnvMatch_js_1.isConfigEnvMatch)(configEnv, isForClientSide, isClientRouting))
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 isConfigEnvMatch_js_1 = require("./isConfigEnvMatch.js");
15
- const utils_js_2 = require("../../../../../shared/page-configs/utils.js");
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(userRootDir, outDirRoot, isForClientSide, isDev, id, configVike, isClientRouting) {
18
- const { pageConfigs, pageConfigGlobal } = await (0, getVikeConfig_js_1.getVikeConfig)(userRootDir, outDirRoot, isDev, configVike.extensions, true);
19
- return getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
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 getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting) {
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, isConfigEnvMatch_js_1.isConfigEnvMatch)(configEnv, isForClientSide, isClientRouting))
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
- if (!(0, isConfigEnvMatch_js_1.isConfigEnvMatch)(configEnv, isForClientSide, isClientRouting))
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 = [...importStatements, ...lines].join('\n');
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
- (0, utils_js_1.assert)((0, utils_js_1.hasProp)(err, 'messageCore', 'string'));
116
- const configValueFilePathToShowToUser = (0, utils_js_2.getConfigValueFilePathToShowToUser)({ definedAt });
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 the value isn't serializable: ${err.messageCore}.)`,
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
- if (configValueSource) {
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 { filePathAbsolute } = filePath;
27
- (0, utils_js_1.assertPosixPath)(filePathAbsolute);
28
- getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsolute);
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 { filePathAbsolute } = filePath;
43
- (0, utils_js_1.assertPosixPath)(filePathAbsolute);
44
- const isHeader = isHeaderFile(filePathAbsolute);
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.filePathAbsolute;
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 filePathAbsolute = path_1.default.posix.join(userRootDir, filePathRelative);
132
- getVikeConfig_js_1.vikeConfigDependencies.add(filePathAbsolute);
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 { filePathAbsolute, filePathRelativeToUserRootDir } = filePath;
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(filePathAbsolute);
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 ?? filePathAbsolute;
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.assertUsage)(fileImportsUnused.length === 0, [
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((0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(filePath))),
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
- if (!configVike.prerender) {
35
- (0, addSsrMiddleware_js_1.addSsrMiddleware)(server.middlewares);
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 utils_js_2 = require("../../shared/page-configs/utils.js");
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 collectDoNoPrerenderList(renderContext, doNotPrerenderList, concurrencyLimit);
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
- renderContext.pageConfigs.forEach((pageConfig) => {
116
+ async function collectDoNoPrerenderList(renderContext, pageConfigs, doNotPrerenderList, concurrencyLimit) {
117
+ // V1 design
118
+ pageConfigs.forEach((pageConfig) => {
115
119
  const configName = 'prerender';
116
- const configValue = (0, utils_js_2.getConfigValue)(pageConfig, configName, 'boolean');
120
+ const configValue = (0, helpers_js_1.getConfigValue)(pageConfig, configName, 'boolean');
117
121
  if (configValue?.value === false) {
118
- const configValueFilePathToShowToUser = (0, utils_js_2.getConfigValueFilePathToShowToUser)(configValue);
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, utils_js_2.getConfigValue)(pageConfigLoaded, hookName);
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, utils_js_2.getHookFilePathToShowToUser)(configValue);
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
- _routeMatches: [
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 => definedAtInfo should always be defined
317
- const hookFilePath = (0, utils_js_2.getHookFilePathToShowToUser)(configValue);
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.hasPropertyGetter)(pageContext, 'url'));
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.hasPropertyGetter)(pageContext, 'url') && pageContext.url) {
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 routeResult = await (0, index_js_1.route)(pageContext);
439
- (0, utils_js_1.assert)((0, utils_js_1.hasProp)(routeResult.pageContextAddendum, '_pageId', 'null') ||
440
- (0, utils_js_1.hasProp)(routeResult.pageContextAddendum, '_pageId', 'string'));
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 doesn't match any of your page routes. Make sure that the URLs returned by ${hookName}() always match the route of a page.`);
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)(routeResult.pageContextAddendum._routingProvidedByOnBeforeRouteHook);
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)(routeResult.pageContextAddendum._pageId);
464
- (0, utils_js_1.objectAssign)(pageContext, routeResult.pageContextAddendum);
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, utils_js_2.getConfigValue)(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
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 ? 'prerender' : 'onBeforePrerenderStart';
519
- const getPageAt = isV1 ? (pageId) => `defined at ${pageId}` : (pageId) => `\`${pageId}.page.*\``;
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 = getPageAt(pageId);
526
- (0, utils_js_1.assertWarning)(partial, `Cannot pre-render page ${pageAt} because it has a non-static route, and no ${hookName}() hook returned (an) URL(s) matching the page's route. Either use a ${hookName}() hook to pre-render the page, or use the option ${picocolors_1.default.cyan('prerender.partial')} to suppress this warning, see https://vike.dev/prerender-config`, { onlyOnce: true });
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/hasPropertyGetter.js"), exports);
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
- (0, utils_js_1.assert)((0, utils_js_1.hasProp)(err, 'messageCore', 'string'));
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
- `Serialization error: ${err.messageCore}.`
58
- ].join(' '), { onlyOnce: false });
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
- pageContextSerialized = serialize(pageContextClient);
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._routeMatches));
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(routeMatches) {
25
- if (routeMatches === 'ROUTE_ERROR') {
24
+ function printRouteMatches(debugRouteMatches) {
25
+ if (debugRouteMatches === 'ROUTING_ERROR') {
26
26
  return 'Routing Failed';
27
27
  }
28
- if (routeMatches === 'CUSTOM_ROUTE') {
28
+ if (debugRouteMatches === 'CUSTOM_ROUTING') {
29
29
  return 'Custom Routing';
30
30
  }
31
- return routeMatches;
31
+ return debugRouteMatches;
32
32
  }
33
33
  function printPageFiles(pageFiles, genericPageFilesLast = false) {
34
34
  if (pageFiles.length === 0) {