vike 0.4.229 → 0.4.230-commit-8b60b8c

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 (235) hide show
  1. package/dist/cjs/client/server-routing-runtime/utils.js +1 -0
  2. package/dist/cjs/client/shared/{preparePageContextForUserConsumptionClientSide.js → preparePageContextForPublicUsageClientShared.js} +14 -19
  3. package/dist/cjs/node/api/build.js +2 -5
  4. package/dist/cjs/node/plugin/index.js +3 -1
  5. package/dist/cjs/node/plugin/onLoad.js +2 -0
  6. package/dist/cjs/node/plugin/plugins/build/pluginDistFileNames.js +1 -0
  7. package/dist/cjs/node/plugin/plugins/build/pluginModuleBanner.js +4 -4
  8. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -0
  9. package/dist/cjs/node/plugin/plugins/envVars.js +17 -19
  10. package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +3 -1
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js +2 -2
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -0
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -1
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +5 -0
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +2 -2
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +12 -8
  17. package/dist/cjs/node/plugin/plugins/replaceConstants.js +76 -0
  18. package/dist/cjs/node/plugin/shared/applyRegExWithMagicString.js +10 -0
  19. package/dist/cjs/node/plugin/shared/findPageFiles.js +1 -1
  20. package/dist/cjs/node/plugin/shared/loggerNotProd.js +2 -2
  21. package/dist/cjs/node/plugin/shared/resolveClientEntriesDev.js +1 -1
  22. package/dist/cjs/node/prerender/runPrerender.js +42 -38
  23. package/dist/cjs/node/prerender/utils.js +1 -1
  24. package/dist/cjs/node/runtime/globalContext.js +13 -27
  25. package/dist/cjs/node/runtime/html/renderHtml.js +12 -2
  26. package/dist/cjs/node/runtime/html/serializeContext.js +4 -2
  27. package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +7 -5
  28. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +3 -4
  29. package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +6 -9
  30. package/dist/cjs/node/runtime/renderPage/execHookServer.js +11 -0
  31. package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +14 -15
  32. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -12
  33. package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +1 -1
  34. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +1 -1
  35. package/dist/cjs/node/runtime/renderPage/{loadUserFilesServerSide.js → loadPageConfigsLazyServerSide.js} +4 -4
  36. package/dist/cjs/node/runtime/renderPage/preparePageContextForPublicUsageServer.js +10 -0
  37. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -5
  38. package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +0 -2
  39. package/dist/cjs/node/runtime/renderPage.js +21 -12
  40. package/dist/cjs/node/runtime/utils.js +1 -1
  41. package/dist/cjs/shared/NOT_SERIALIZABLE.js +0 -1
  42. package/dist/cjs/shared/addIs404ToPageProps.js +0 -7
  43. package/dist/cjs/shared/createGlobalContextShared.js +37 -8
  44. package/dist/cjs/shared/createPageContextShared.js +14 -11
  45. package/dist/cjs/shared/getPageContext.js +3 -3
  46. package/dist/cjs/shared/getPageContextUrlComputed.js +2 -36
  47. package/dist/cjs/shared/getProxyForPublicUsage.js +56 -0
  48. package/dist/cjs/shared/hooks/execHook.js +170 -0
  49. package/dist/cjs/shared/hooks/getHook.js +23 -4
  50. package/dist/cjs/shared/page-configs/{getPageConfigUserFriendly.js → getUserFriendlyConfigs.js} +54 -47
  51. package/dist/cjs/shared/prepareGlobalContextForPublicUsage.js +10 -0
  52. package/dist/cjs/shared/preparePageContextForPublicUsage.js +80 -0
  53. package/dist/cjs/shared/route/abort.js +2 -2
  54. package/dist/cjs/shared/route/debug.js +17 -7
  55. package/dist/cjs/shared/route/executeGuardHook.js +4 -9
  56. package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +4 -3
  57. package/dist/cjs/shared/route/index.js +2 -4
  58. package/dist/cjs/shared/route/loadPageRoutes.js +6 -0
  59. package/dist/cjs/shared/route/resolveRouteFunction.js +14 -10
  60. package/dist/cjs/shared/utils.js +1 -0
  61. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  62. package/dist/cjs/utils/debug.js +15 -6
  63. package/dist/cjs/utils/isDev.js +3 -1
  64. package/dist/cjs/utils/isScriptFile.js +24 -21
  65. package/dist/cjs/utils/objectAssign.js +3 -3
  66. package/dist/cjs/utils/objectDefineProperty.js +1 -1
  67. package/dist/cjs/utils/parseNpmPackage.js +1 -0
  68. package/dist/cjs/utils/parseUrl-extras.js +0 -1
  69. package/dist/cjs/utils/requireResolve.js +39 -19
  70. package/dist/esm/client/client-routing-runtime/{createPageContext.d.ts → createPageContextClientSide.d.ts} +21 -13
  71. package/dist/esm/client/client-routing-runtime/{createPageContext.js → createPageContextClientSide.js} +9 -11
  72. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +400 -15
  73. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +56 -54
  74. package/dist/esm/client/client-routing-runtime/globalContext.d.ts +11 -1
  75. package/dist/esm/client/client-routing-runtime/prefetch.d.ts +3 -8
  76. package/dist/esm/client/client-routing-runtime/prefetch.js +3 -3
  77. package/dist/esm/client/client-routing-runtime/preparePageContextForPublicUsageClient.d.ts +11 -0
  78. package/dist/esm/client/client-routing-runtime/preparePageContextForPublicUsageClient.js +5 -0
  79. package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +135 -0
  80. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +72 -81
  81. package/dist/esm/client/client-routing-runtime/utils.d.ts +1 -0
  82. package/dist/esm/client/client-routing-runtime/utils.js +1 -0
  83. package/dist/esm/client/server-routing-runtime/createPageContextClientSide.d.ts +19 -13
  84. package/dist/esm/client/server-routing-runtime/createPageContextClientSide.js +15 -26
  85. package/dist/esm/client/server-routing-runtime/entry.js +4 -4
  86. package/dist/esm/client/server-routing-runtime/globalContext.d.ts +11 -1
  87. package/dist/esm/client/server-routing-runtime/preparePageContextForPublicUsageClient.d.ts +9 -0
  88. package/dist/esm/client/server-routing-runtime/preparePageContextForPublicUsageClient.js +5 -0
  89. package/dist/esm/client/server-routing-runtime/utils.d.ts +1 -0
  90. package/dist/esm/client/server-routing-runtime/utils.js +1 -0
  91. package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +11 -1
  92. package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +3 -3
  93. package/dist/esm/client/shared/executeOnRenderClientHook.js +4 -13
  94. package/dist/esm/client/shared/{loadUserFilesClientSide.d.ts → loadPageConfigsLazyClientSide.d.ts} +2 -2
  95. package/dist/esm/client/shared/{loadUserFilesClientSide.js → loadPageConfigsLazyClientSide.js} +4 -4
  96. package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +11 -0
  97. package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.js +39 -0
  98. package/dist/esm/node/api/build.js +2 -2
  99. package/dist/esm/node/plugin/index.js +3 -1
  100. package/dist/esm/node/plugin/onLoad.js +2 -0
  101. package/dist/esm/node/plugin/plugins/build/pluginDistFileNames.js +1 -0
  102. package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +4 -4
  103. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +6 -1
  104. package/dist/esm/node/plugin/plugins/envVars.js +18 -20
  105. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +4 -2
  106. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.d.ts +1 -2
  107. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/assertExtensions.js +2 -2
  108. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -0
  109. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +2 -2
  110. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +6 -1
  111. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +3 -3
  112. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +1 -1
  113. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +12 -8
  114. package/dist/esm/node/plugin/plugins/replaceConstants.d.ts +3 -0
  115. package/dist/esm/node/plugin/plugins/replaceConstants.js +71 -0
  116. package/dist/esm/node/plugin/shared/applyRegExWithMagicString.d.ts +3 -0
  117. package/dist/esm/node/plugin/shared/applyRegExWithMagicString.js +8 -0
  118. package/dist/esm/node/plugin/shared/findPageFiles.js +2 -2
  119. package/dist/esm/node/plugin/shared/loggerNotProd.js +1 -1
  120. package/dist/esm/node/plugin/shared/resolveClientEntriesDev.d.ts +1 -1
  121. package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +1 -1
  122. package/dist/esm/node/prerender/runPrerender.d.ts +37 -73
  123. package/dist/esm/node/prerender/runPrerender.js +42 -38
  124. package/dist/esm/node/prerender/utils.d.ts +1 -1
  125. package/dist/esm/node/prerender/utils.js +1 -1
  126. package/dist/esm/node/runtime/globalContext.d.ts +46 -251
  127. package/dist/esm/node/runtime/globalContext.js +14 -28
  128. package/dist/esm/node/runtime/html/renderHtml.js +12 -2
  129. package/dist/esm/node/runtime/html/serializeContext.d.ts +1 -1
  130. package/dist/esm/node/runtime/html/serializeContext.js +4 -2
  131. package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.d.ts +1 -1
  132. package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.js +7 -5
  133. package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +2 -2
  134. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +3 -4
  135. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +26 -41
  136. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +7 -10
  137. package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +12 -0
  138. package/dist/esm/node/runtime/renderPage/execHookServer.js +9 -0
  139. package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.d.ts +2 -3
  140. package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +14 -15
  141. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +4 -2
  142. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -12
  143. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +1 -1
  144. package/dist/esm/node/runtime/renderPage/getPageAssets.js +1 -1
  145. package/dist/esm/node/runtime/renderPage/{loadUserFilesServerSide.d.ts → loadPageConfigsLazyServerSide.d.ts} +6 -6
  146. package/dist/esm/node/runtime/renderPage/{loadUserFilesServerSide.js → loadPageConfigsLazyServerSide.js} +4 -4
  147. package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +20 -0
  148. package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.js +8 -0
  149. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +38 -74
  150. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +5 -5
  151. package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +0 -2
  152. package/dist/esm/node/runtime/renderPage/resolveRedirects.js +0 -1
  153. package/dist/esm/node/runtime/renderPage.d.ts +21 -39
  154. package/dist/esm/node/runtime/renderPage.js +22 -13
  155. package/dist/esm/node/runtime/utils.d.ts +1 -1
  156. package/dist/esm/node/runtime/utils.js +1 -1
  157. package/dist/esm/shared/NOT_SERIALIZABLE.js +0 -1
  158. package/dist/esm/shared/addIs404ToPageProps.d.ts +1 -6
  159. package/dist/esm/shared/addIs404ToPageProps.js +1 -8
  160. package/dist/esm/shared/createGlobalContextShared.d.ts +28 -6
  161. package/dist/esm/shared/createGlobalContextShared.js +37 -8
  162. package/dist/esm/shared/createPageContextShared.d.ts +7 -6
  163. package/dist/esm/shared/createPageContextShared.js +15 -12
  164. package/dist/esm/shared/getPageContext.d.ts +1 -1
  165. package/dist/esm/shared/getPageContext.js +1 -1
  166. package/dist/esm/shared/getPageContextUrlComputed.d.ts +2 -5
  167. package/dist/esm/shared/getPageContextUrlComputed.js +3 -37
  168. package/dist/esm/shared/getPageFiles.d.ts +1 -1
  169. package/dist/esm/shared/getProxyForPublicUsage.d.ts +4 -0
  170. package/dist/esm/shared/getProxyForPublicUsage.js +54 -0
  171. package/dist/esm/shared/hooks/execHook.d.ts +63 -0
  172. package/dist/esm/shared/hooks/execHook.js +168 -0
  173. package/dist/esm/shared/hooks/getHook.d.ts +10 -11
  174. package/dist/esm/shared/hooks/getHook.js +23 -4
  175. package/dist/esm/shared/page-configs/Config.d.ts +11 -4
  176. package/dist/esm/shared/page-configs/{getPageConfigUserFriendly.d.ts → getUserFriendlyConfigs.d.ts} +8 -6
  177. package/dist/esm/shared/page-configs/{getPageConfigUserFriendly.js → getUserFriendlyConfigs.js} +55 -48
  178. package/dist/esm/shared/prepareGlobalContextForPublicUsage.d.ts +7 -0
  179. package/dist/esm/shared/prepareGlobalContextForPublicUsage.js +8 -0
  180. package/dist/esm/shared/preparePageContextForPublicUsage.d.ts +11 -0
  181. package/dist/esm/shared/preparePageContextForPublicUsage.js +78 -0
  182. package/dist/esm/shared/route/abort.js +1 -1
  183. package/dist/esm/shared/route/debug.d.ts +4 -1
  184. package/dist/esm/shared/route/debug.js +17 -7
  185. package/dist/esm/shared/route/executeGuardHook.d.ts +4 -3
  186. package/dist/esm/shared/route/executeGuardHook.js +4 -9
  187. package/dist/esm/shared/route/executeOnBeforeRouteHook.js +4 -3
  188. package/dist/esm/shared/route/index.js +2 -4
  189. package/dist/esm/shared/route/loadPageRoutes.d.ts +2 -1
  190. package/dist/esm/shared/route/loadPageRoutes.js +7 -1
  191. package/dist/esm/shared/route/resolveRouteFunction.d.ts +2 -2
  192. package/dist/esm/shared/route/resolveRouteFunction.js +14 -10
  193. package/dist/esm/shared/types.d.ts +14 -4
  194. package/dist/esm/shared/utils.d.ts +1 -0
  195. package/dist/esm/shared/utils.js +1 -0
  196. package/dist/esm/types/index.d.ts +1 -1
  197. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  198. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  199. package/dist/esm/utils/debug.d.ts +1 -1
  200. package/dist/esm/utils/debug.js +15 -6
  201. package/dist/esm/utils/isDev.js +3 -1
  202. package/dist/esm/utils/isScriptFile.d.ts +5 -5
  203. package/dist/esm/utils/isScriptFile.js +23 -20
  204. package/dist/esm/utils/objectAssign.d.ts +1 -1
  205. package/dist/esm/utils/objectAssign.js +3 -3
  206. package/dist/esm/utils/objectDefineProperty.d.ts +0 -1
  207. package/dist/esm/utils/objectDefineProperty.js +1 -1
  208. package/dist/esm/utils/parseNpmPackage.d.ts +2 -0
  209. package/dist/esm/utils/parseNpmPackage.js +1 -1
  210. package/dist/esm/utils/parseUrl-extras.js +0 -1
  211. package/dist/esm/utils/requireResolve.js +39 -19
  212. package/package.json +2 -2
  213. package/dist/cjs/client/shared/getPageContextProxyForUser.js +0 -16
  214. package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +0 -16
  215. package/dist/cjs/shared/getPageConfigsRuntime.js +0 -23
  216. package/dist/cjs/shared/hooks/executeHook.js +0 -87
  217. package/dist/cjs/shared/hooks/executeHookGeneric.js +0 -18
  218. package/dist/cjs/shared/preparePageContextForUserConsumption.js +0 -34
  219. package/dist/cjs/utils/getPublicProxy.js +0 -27
  220. package/dist/esm/client/shared/getPageContextProxyForUser.d.ts +0 -2
  221. package/dist/esm/client/shared/getPageContextProxyForUser.js +0 -14
  222. package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +0 -12
  223. package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.js +0 -44
  224. package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +0 -24
  225. package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +0 -14
  226. package/dist/esm/shared/getPageConfigsRuntime.d.ts +0 -14
  227. package/dist/esm/shared/getPageConfigsRuntime.js +0 -21
  228. package/dist/esm/shared/hooks/executeHook.d.ts +0 -21
  229. package/dist/esm/shared/hooks/executeHook.js +0 -85
  230. package/dist/esm/shared/hooks/executeHookGeneric.d.ts +0 -8
  231. package/dist/esm/shared/hooks/executeHookGeneric.js +0 -16
  232. package/dist/esm/shared/preparePageContextForUserConsumption.d.ts +0 -5
  233. package/dist/esm/shared/preparePageContextForUserConsumption.js +0 -32
  234. package/dist/esm/utils/getPublicProxy.d.ts +0 -2
  235. package/dist/esm/utils/getPublicProxy.js +0 -25
@@ -5,6 +5,7 @@ export type { ConfigNameBuiltIn };
5
5
  export type { ConfigNameGlobal };
6
6
  export type { ConfigMeta };
7
7
  export type { HookName };
8
+ export type { HookNameOld };
8
9
  export type { HookNamePage };
9
10
  export type { HookNameGlobal };
10
11
  export type { ImportString };
@@ -43,10 +44,11 @@ import type { Vike, VikePackages } from '../VikeNamespace.js';
43
44
  import type { HooksTimeoutProvidedByUser } from '../hooks/getHook.js';
44
45
  import type { GlobalContext, PageContextClient, PageContextServer } from '../types.js';
45
46
  import type { InlineConfig } from 'vite';
46
- type HookName = HookNamePage | HookNameGlobal | HookNameOldDesign;
47
- type HookNamePage = 'onHydrationEnd' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onRenderHtml' | 'onRenderClient' | 'guard' | 'data';
48
- type HookNameGlobal = 'onBeforePrerender' | 'onBeforeRoute' | 'onPrerenderStart' | 'onCreatePageContext' | 'onCreateGlobalContext';
49
- type HookNameOldDesign = 'render' | 'prerender';
47
+ type HookNameOld = HookName | HookNameOldDesign;
48
+ type HookName = HookNamePage | HookNameGlobal;
49
+ type HookNamePage = 'onHydrationEnd' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onRenderHtml' | 'onRenderClient' | 'guard' | 'data' | 'onData' | 'route';
50
+ type HookNameGlobal = 'onBeforeRoute' | 'onPrerenderStart' | 'onCreatePageContext' | 'onCreateGlobalContext';
51
+ type HookNameOldDesign = 'render' | 'prerender' | 'onBeforePrerender';
50
52
  type ConfigNameBuiltIn = Exclude<keyof Config, keyof VikeVitePluginOptions | 'onBeforeRoute' | 'onPrerenderStart' | 'vite' | 'redirects'> | 'prerender' | 'isClientRuntimeLoaded' | 'onBeforeRenderEnv' | 'dataEnv' | 'hooksTimeout' | 'clientHooks' | 'middleware';
51
53
  type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | 'disableAutoFullBuild' | 'includeAssetsImportedByServer' | 'baseAssets' | 'baseServer' | 'redirects' | 'trailingSlash' | 'disableUrlNormalization' | 'vite';
52
54
  type Config = ConfigBuiltIn & Vike.Config & (VikePackages.ConfigVikeReact | VikePackages.ConfigVikeVue | VikePackages.ConfigVikeSolid | VikePackages.ConfigVikeSvelte | VikePackages.ConfigVikeAngular);
@@ -345,6 +347,11 @@ type ConfigBuiltIn = {
345
347
  * https://vike.dev/data
346
348
  */
347
349
  data?: DataAsync<unknown> | DataSync<unknown> | ImportString | null;
350
+ /** Hook called as soon as `pageContext.data` is available.
351
+ *
352
+ * https://vike.dev/onData
353
+ */
354
+ onData?: Function;
348
355
  /** Determines what pageContext properties are sent to the client-side.
349
356
  *
350
357
  * https://vike.dev/passToClient
@@ -1,6 +1,6 @@
1
- export { getPageConfigUserFriendly };
2
- export { getPageConfigUserFriendly_oldDesign };
3
- export { getPageConfigGlobalUserFriendly };
1
+ export { getUserFriendlyConfigsGlobal };
2
+ export { getUserFriendlyConfigsPageEager };
3
+ export { getUserFriendlyConfigsPageLazy };
4
4
  export type { PageConfigsUserFriendly };
5
5
  export type { PageConfigUserFriendly };
6
6
  export type { PageConfigUserFriendlyOld };
@@ -92,8 +92,10 @@ type WithRoute = {
92
92
  isErrorPage: true;
93
93
  };
94
94
  type PageConfigUserFriendlyWithRoute = PageConfigUserFriendly & WithRoute;
95
- declare function getPageConfigUserFriendly(pageConfigGlobalValues: ConfigValues, pageConfig: PageConfigRuntime | PageConfigBuildTime, pageConfigValues: ConfigValues): [string, PageConfigUserFriendlyWithRoute];
96
- declare function getPageConfigGlobalUserFriendly({ pageConfigGlobalValues }: {
95
+ declare function getUserFriendlyConfigsPageEager(pageConfigGlobalValues: ConfigValues, pageConfig: PageConfigRuntime | PageConfigBuildTime, pageConfigValues: ConfigValues): [string, PageConfigUserFriendlyWithRoute];
96
+ declare function getUserFriendlyConfigsGlobal({ pageConfigGlobalValues }: {
97
97
  pageConfigGlobalValues: ConfigValues;
98
98
  }): PageConfigUserFriendly;
99
- declare function getPageConfigUserFriendly_oldDesign(pageFiles: PageFile[], pageConfig: PageConfigRuntimeLoaded | null, pageConfigGlobal: PageConfigGlobalRuntime): PageConfigUserFriendlyOld;
99
+ declare function getUserFriendlyConfigsPageLazy(pageFiles: PageFile[], // V0.4 design
100
+ pageConfig: PageConfigRuntimeLoaded | null, // V1 design
101
+ pageConfigGlobal: PageConfigGlobalRuntime): PageConfigUserFriendlyOld;
@@ -1,13 +1,13 @@
1
- export { getPageConfigUserFriendly };
2
- export { getPageConfigUserFriendly_oldDesign };
3
- export { getPageConfigGlobalUserFriendly };
1
+ export { getUserFriendlyConfigsGlobal };
2
+ export { getUserFriendlyConfigsPageEager };
3
+ export { getUserFriendlyConfigsPageLazy };
4
4
  import { assertDefaultExports, forbiddenDefaultExports } from '../getPageFiles/assert_exports_old_design.js';
5
5
  import { getConfigDefinedAtOptional, getDefinedAtString } from './getConfigDefinedAt.js';
6
6
  import { getConfigValueFilePathToShowToUser } from './helpers.js';
7
- import { assert, isObject, assertWarning, assertUsage, makeLast, isBrowser, isScriptFile, isTemplateFile } from '../utils.js';
7
+ import { assert, isObject, assertWarning, assertUsage, makeLast, isBrowser, isScriptFile, isTemplateFile, objectDefineProperty } from '../utils.js';
8
8
  import pc from '@brillout/picocolors';
9
- function getPageConfigUserFriendly(pageConfigGlobalValues, pageConfig, pageConfigValues) {
10
- const pageConfigUserFriendly = getPageConfigUserFriendly_public({ pageConfigGlobalValues, pageConfigValues });
9
+ function getUserFriendlyConfigsPageEager(pageConfigGlobalValues, pageConfig, pageConfigValues) {
10
+ const pageConfigUserFriendly = getUserFriendlyConfigs_public({ pageConfigGlobalValues, pageConfigValues });
11
11
  let page;
12
12
  if (!pageConfig.isErrorPage) {
13
13
  const route = pageConfigUserFriendly.config.route ?? pageConfig.routeFilesystem.routeString;
@@ -24,8 +24,8 @@ function getPageConfigUserFriendly(pageConfigGlobalValues, pageConfig, pageConfi
24
24
  }
25
25
  return [pageConfig.pageId, page];
26
26
  }
27
- function getPageConfigUserFriendly_public({ pageConfigGlobalValues, pageConfigValues }) {
28
- const pageConfigUserFriendly = getPageConfigUserFriendly_base({ pageConfigGlobalValues, pageConfigValues });
27
+ function getUserFriendlyConfigs_public({ pageConfigGlobalValues, pageConfigValues }) {
28
+ const pageConfigUserFriendly = getUserFriendlyConfigs_base({ pageConfigGlobalValues, pageConfigValues });
29
29
  return getPublicCopy(pageConfigUserFriendly);
30
30
  }
31
31
  function getPublicCopy(pageConfigUserFriendly) {
@@ -37,15 +37,17 @@ function getPublicCopy(pageConfigUserFriendly) {
37
37
  _from: p.from
38
38
  };
39
39
  }
40
- function getPageConfigUserFriendly_base({ pageConfigGlobalValues, pageConfigValues }) {
40
+ function getUserFriendlyConfigs_base({ pageConfigGlobalValues, pageConfigValues }) {
41
41
  const configValues = { ...pageConfigGlobalValues, ...pageConfigValues };
42
- return getPageConfigUserFriendly_V1Design({ configValues });
42
+ return getUserFriendlyConfigs_V1Design({ configValues });
43
43
  }
44
- function getPageConfigGlobalUserFriendly({ pageConfigGlobalValues }) {
45
- const pageConfigGlobalUserFriendly = getPageConfigUserFriendly_V1Design({ configValues: pageConfigGlobalValues });
44
+ function getUserFriendlyConfigsGlobal({ pageConfigGlobalValues }) {
45
+ const pageConfigGlobalUserFriendly = getUserFriendlyConfigs_V1Design({ configValues: pageConfigGlobalValues });
46
46
  return getPublicCopy(pageConfigGlobalUserFriendly);
47
47
  }
48
- function getPageConfigUserFriendly_oldDesign(pageFiles, pageConfig, pageConfigGlobal) {
48
+ function getUserFriendlyConfigsPageLazy(pageFiles, // V0.4 design
49
+ pageConfig, // V1 design
50
+ pageConfigGlobal) {
49
51
  const config = {};
50
52
  const configEntries = {}; // TODO/v1-release: remove
51
53
  const exportsAll = {}; // TODO/v1-release: remove
@@ -70,7 +72,7 @@ function getPageConfigUserFriendly_oldDesign(pageFiles, pageConfig, pageConfigGl
70
72
  let sources;
71
73
  let from;
72
74
  if (pageConfig) {
73
- const res = getPageConfigUserFriendly_base({
75
+ const res = getUserFriendlyConfigs_base({
74
76
  pageConfigGlobalValues: pageConfigGlobal.configValues,
75
77
  pageConfigValues: pageConfig.configValues
76
78
  });
@@ -90,7 +92,7 @@ function getPageConfigUserFriendly_oldDesign(pageFiles, pageConfig, pageConfigGl
90
92
  configsComputed: {}
91
93
  };
92
94
  }
93
- const pageExports = createObjectWithDeprecationWarning();
95
+ const pageExports = {};
94
96
  const exports = {};
95
97
  Object.entries(exportsAll).forEach(([exportName, values]) => {
96
98
  values.forEach(({ exportValue, _fileType, _isFromDefaultExport }) => {
@@ -113,13 +115,27 @@ function getPageConfigUserFriendly_oldDesign(pageFiles, pageConfig, pageConfigGl
113
115
  // TODO/eventually: deprecate/remove every prop below
114
116
  configEntries,
115
117
  exports,
116
- exportsAll,
117
- pageExports
118
+ exportsAll
118
119
  };
120
+ // TODO/v1-release: remove
121
+ objectDefineProperty(pageContextExports, 'pageExports', {
122
+ get: () => {
123
+ // We only show the warning in Node.js because when using Client Routing Vue integration uses `Object.assign(pageContextReactive, pageContext)` which will wrongully trigger the warning. There is no cross-browser way to catch whether the property accessor was initiated by an `Object.assign()` call.
124
+ if (!isBrowser()) {
125
+ assertWarning(false, 'pageContext.pageExports is outdated, use pageContext.exports instead', {
126
+ onlyOnce: true,
127
+ showStackTrace: true
128
+ });
129
+ }
130
+ return pageExports;
131
+ },
132
+ enumerable: false,
133
+ configurable: true
134
+ });
119
135
  return pageContextExports;
120
136
  }
121
137
  // V1 design
122
- function getPageConfigUserFriendly_V1Design(pageConfig) {
138
+ function getUserFriendlyConfigs_V1Design(pageConfig) {
123
139
  const config = {};
124
140
  const configEntries = {};
125
141
  const exportsAll = {};
@@ -135,19 +151,30 @@ function getPageConfigUserFriendly_V1Design(pageConfig) {
135
151
  sources[configName] ?? (sources[configName] = []);
136
152
  sources[configName].push(src);
137
153
  };
138
- Object.entries(pageConfig.configValues).forEach(([configName, configValue]) => {
139
- const { value } = configValue;
140
- const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser(configValue.definedAtData);
141
- const configDefinedAt = getConfigDefinedAtOptional('Config', configName, configValue.definedAtData);
142
- config[configName] = config[configName] ?? value;
154
+ const addLegacy = (configName, value, definedAtData) => {
155
+ const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser(definedAtData);
156
+ const configDefinedAt = getConfigDefinedAtOptional('Config', configName, definedAtData);
143
157
  configEntries[configName] = configEntries[configName] ?? [];
144
- // Currently each configName has only one entry. Adding an entry for each overriden config value isn't implemented yet. (This is an isomorphic file and it isn't clear whether this can/should be implemented on the client-side. We should load a minimum amount of code on the client-side.)
145
- assert(configEntries[configName].length === 0);
146
158
  configEntries[configName].push({
147
159
  configValue: value,
148
160
  configDefinedAt,
149
161
  configDefinedByFile: configValueFilePathToShowToUser
150
162
  });
163
+ // TODO/v1-release: remove
164
+ const exportName = configName;
165
+ exportsAll[exportName] = exportsAll[exportName] ?? [];
166
+ exportsAll[exportName].push({
167
+ exportValue: value,
168
+ exportSource: configDefinedAt,
169
+ filePath: configValueFilePathToShowToUser,
170
+ _filePath: configValueFilePathToShowToUser,
171
+ _fileType: null,
172
+ _isFromDefaultExport: null
173
+ });
174
+ };
175
+ Object.entries(pageConfig.configValues).forEach(([configName, configValue]) => {
176
+ const { value } = configValue;
177
+ config[configName] = config[configName] ?? value;
151
178
  if (configValue.type === 'standard') {
152
179
  const src = {
153
180
  type: 'configsStandard',
@@ -156,6 +183,7 @@ function getPageConfigUserFriendly_V1Design(pageConfig) {
156
183
  };
157
184
  addSrc(src, configName);
158
185
  from.configsStandard[configName] = src;
186
+ addLegacy(configName, value, configValue.definedAtData);
159
187
  }
160
188
  if (configValue.type === 'cumulative') {
161
189
  const src = {
@@ -164,6 +192,7 @@ function getPageConfigUserFriendly_V1Design(pageConfig) {
164
192
  const definedAtFile = configValue.definedAtData[i];
165
193
  assert(definedAtFile);
166
194
  const definedAt = getDefinedAtString(definedAtFile, configName);
195
+ addLegacy(configName, value, definedAtFile);
167
196
  return {
168
197
  value,
169
198
  definedAt
@@ -180,18 +209,8 @@ function getPageConfigUserFriendly_V1Design(pageConfig) {
180
209
  };
181
210
  addSrc(src, configName);
182
211
  from.configsComputed[configName] = src;
212
+ addLegacy(configName, value, configValue.definedAtData);
183
213
  }
184
- // TODO/v1-release: remove
185
- const exportName = configName;
186
- exportsAll[exportName] = exportsAll[exportName] ?? [];
187
- exportsAll[exportName].push({
188
- exportValue: value,
189
- exportSource: configDefinedAt,
190
- filePath: configValueFilePathToShowToUser,
191
- _filePath: configValueFilePathToShowToUser,
192
- _fileType: null,
193
- _isFromDefaultExport: null
194
- });
195
214
  });
196
215
  return {
197
216
  config: config,
@@ -239,15 +258,3 @@ function getExportValues(pageFile) {
239
258
  });
240
259
  return exportValues;
241
260
  }
242
- // TODO/v1-release: remove
243
- function createObjectWithDeprecationWarning() {
244
- return new Proxy({}, {
245
- get(...args) {
246
- // We only show the warning in Node.js because when using Client Routing Vue integration uses `Object.assign(pageContextReactive, pageContext)` which will wrongully trigger the warning. There is no cross-browser way to catch whether the property accessor was initiated by an `Object.assign()` call.
247
- if (!isBrowser()) {
248
- assertWarning(false, '`pageContext.pageExports` is outdated. Use `pageContext.exports` instead, see https://vike.dev/exports', { onlyOnce: true, showStackTrace: true });
249
- }
250
- return Reflect.get(...args);
251
- }
252
- });
253
- }
@@ -0,0 +1,7 @@
1
+ export { prepareGlobalContextForPublicUsage };
2
+ export type { GlobalContextPrepareMinimum };
3
+ type GlobalContextPrepareMinimum = {
4
+ _isOriginalObject: true;
5
+ isGlobalContext: true;
6
+ };
7
+ declare function prepareGlobalContextForPublicUsage<GlobalContext extends GlobalContextPrepareMinimum>(globalContext: GlobalContext): GlobalContext;
@@ -0,0 +1,8 @@
1
+ export { prepareGlobalContextForPublicUsage };
2
+ import { getProxyForPublicUsage } from './getProxyForPublicUsage.js';
3
+ import { assert } from './utils.js';
4
+ function prepareGlobalContextForPublicUsage(globalContext) {
5
+ assert(globalContext._isOriginalObject); // ensure we preserve the original object reference
6
+ const globalContextPublic = getProxyForPublicUsage(globalContext, 'globalContext');
7
+ return globalContextPublic;
8
+ }
@@ -0,0 +1,11 @@
1
+ export { preparePageContextForPublicUsage };
2
+ export { assertPropertyGetters };
3
+ export type { PageContextPrepareMinimum };
4
+ import { type GlobalContextPrepareMinimum } from './prepareGlobalContextForPublicUsage.js';
5
+ type PageContextPrepareMinimum = {
6
+ _isOriginalObject: true;
7
+ isPageContext: true;
8
+ _globalContext: GlobalContextPrepareMinimum;
9
+ };
10
+ declare function preparePageContextForPublicUsage<PageContext extends PageContextPrepareMinimum>(pageContext: PageContext): PageContext;
11
+ declare function assertPropertyGetters(pageContext: Record<string, unknown>): void;
@@ -0,0 +1,78 @@
1
+ export { preparePageContextForPublicUsage };
2
+ export { assertPropertyGetters };
3
+ import { assert, assertWarning, compareString, isPropertyGetter } from './utils.js';
4
+ import { addIs404ToPageProps } from './addIs404ToPageProps.js';
5
+ import { prepareGlobalContextForPublicUsage } from './prepareGlobalContextForPublicUsage.js';
6
+ import { getProxyForPublicUsage } from './getProxyForPublicUsage.js';
7
+ function preparePageContextForPublicUsage(pageContext) {
8
+ assert(!pageContext._isProxyObject);
9
+ assert(!pageContext.globalContext); // pageContext.globalContext should only be available to users — Vike itself should use pageContext._globalContext instead
10
+ assert(pageContext._isOriginalObject); // ensure we preserve the original object reference
11
+ addIs404ToPageProps(pageContext);
12
+ // TODO/next-major-release: remove
13
+ if (!('_pageId' in pageContext)) {
14
+ Object.defineProperty(pageContext, '_pageId', {
15
+ get() {
16
+ assertWarning(false, 'pageContext._pageId has been renamed to pageContext.pageId', {
17
+ showStackTrace: true,
18
+ onlyOnce: true
19
+ });
20
+ return pageContext.pageId;
21
+ },
22
+ enumerable: false
23
+ });
24
+ }
25
+ // For a more readable `console.log(pageContext)` output
26
+ sortPageContext(pageContext);
27
+ const globalContextPublic = prepareGlobalContextForPublicUsage(pageContext._globalContext);
28
+ const pageContextPublic = getProxyForPublicUsage(pageContext, 'pageContext',
29
+ // We must skip it in the client-side because of the reactivity mechanism of UI frameworks like Solid.
30
+ // - TODO/now: double check whether that's true
31
+ true, (prop) => {
32
+ if (prop === 'globalContext') {
33
+ return globalContextPublic;
34
+ }
35
+ if (prop in globalContextPublic) {
36
+ return globalContextPublic[prop];
37
+ }
38
+ });
39
+ return pageContextPublic;
40
+ }
41
+ // Sort `pageContext` keys alphabetically, in order to make reading the `console.log(pageContext)` output easier
42
+ function sortPageContext(pageContext) {
43
+ let descriptors = Object.getOwnPropertyDescriptors(pageContext);
44
+ for (const key of Object.keys(pageContext))
45
+ delete pageContext[key];
46
+ descriptors = Object.fromEntries(Object.entries(descriptors).sort(([key1], [key2]) => compareString(key1, key2)));
47
+ Object.defineProperties(pageContext, descriptors);
48
+ }
49
+ function assertPropertyGetters(pageContext) {
50
+ /*
51
+ If the isPropertyGetter() assertions fail then it's most likely because Object.assign() was used instead of `objectAssign()`:
52
+ ```js
53
+ const PageContextUrlComputed = getPageContextUrlComputed(pageContext)
54
+
55
+ // ❌ Breaks the property descriptors/getters of pageContext defined by getPageContextUrlComputed() such as pageContext.urlPathname
56
+ Object.assign(pageContext, pageContextUrlComputed)
57
+
58
+ // ❌ Also breaks property descriptors/getters
59
+ const pageContext = { ...pageContextUrlComputed }
60
+
61
+ // ✅ Preserves property descriptors/getters (see objectAssign() implementation)
62
+ objectAssign(pageContext, pageContextUrlComputed)
63
+ ```
64
+ */
65
+ ;
66
+ [
67
+ 'urlPathname',
68
+ // TODO/v1-release: remove
69
+ 'urlParsed',
70
+ // TODO/v1-release: remove
71
+ 'url',
72
+ // TODO/v1-release: remove
73
+ 'pageExports'
74
+ ].forEach((prop) => {
75
+ if (pageContext.prop)
76
+ assert(isPropertyGetter(pageContext, prop));
77
+ });
78
+ }
@@ -7,7 +7,7 @@ export { logAbortErrorHandled };
7
7
  export { getPageContextFromAllRewrites };
8
8
  export { AbortRender };
9
9
  export { assertNoInfiniteAbortLoop };
10
- import { isUserHookError } from '../hooks/executeHook.js';
10
+ import { isUserHookError } from '../hooks/execHook.js';
11
11
  import { assert, assertInfo, assertUsage, assertUsageUrlPathnameAbsolute, assertUsageUrlRedirectTarget, assertWarning, checkType, hasProp, joinEnglish, objectAssign, truncateString } from './utils.js';
12
12
  import pc from '@brillout/picocolors';
13
13
  /**
@@ -1,3 +1,6 @@
1
1
  export { debug };
2
- import type { Debug } from '../../utils/debug.js';
2
+ export { setCreateDebugger };
3
+ import type { createDebugger, Debug } from '../../utils/debug.js';
4
+ type CreateDebugger = typeof createDebugger;
3
5
  declare function debug(...args: Parameters<Debug>): void;
6
+ declare function setCreateDebugger(createDebugger: CreateDebugger): void;
@@ -1,11 +1,21 @@
1
1
  export { debug };
2
- var _debug;
2
+ export { setCreateDebugger };
3
+ // Using createDebugger() for isomorphic code without bloating the client-side.
4
+ // On the server-side, this is just a transparent proxy.
5
+ // On the client-side, this is an emtpy shell.
6
+ import { getGlobalObject } from '../../utils/getGlobalObject.js';
7
+ const globalObject = getGlobalObject('route/debug.ts', {});
3
8
  function debug(...args) {
4
- if (!_debug) {
5
- // We use this trick instead of `import { createDebugger } from '../../utils/debug` in order to ensure that the `debug` mechanism is only loaded on the server-side
6
- _debug = globalThis.__brillout_debug_createDebugger?.('vike:routing');
7
- }
8
- if (_debug) {
9
- _debug(...args);
9
+ // Client-side => does nothing
10
+ if (!globalObject.createDebugger)
11
+ return;
12
+ // Server-side => just a proxy
13
+ if (!globalObject.debug) {
14
+ globalObject.debug = globalObject.createDebugger('vike:routing');
10
15
  }
16
+ globalObject.debug(...args);
17
+ }
18
+ // Called only on the server-side
19
+ function setCreateDebugger(createDebugger) {
20
+ globalObject.createDebugger = createDebugger;
11
21
  }
@@ -1,8 +1,9 @@
1
1
  export { executeGuardHook };
2
- import type { PageConfigUserFriendlyOld, PageFile } from '../getPageFiles.js';
2
+ import type { PageFile } from '../getPageFiles.js';
3
3
  import type { PageConfigRuntime } from '../page-configs/PageConfig.js';
4
- declare function executeGuardHook<T extends PageConfigUserFriendlyOld & {
4
+ import { type PageContextExecuteHook } from '../hooks/execHook.js';
5
+ declare function executeGuardHook<PageContext extends {
5
6
  pageId: string;
6
7
  _pageFilesAll: PageFile[];
7
8
  _pageConfigs: PageConfigRuntime[];
8
- }>(pageContext: T, prepareForUserConsumption: (pageConfig: T) => T | void): Promise<void>;
9
+ } & PageContextExecuteHook>(pageContext: PageContext, prepareForPublicUsage: (pageConfig: PageContext) => PageContext): Promise<void>;
@@ -1,11 +1,12 @@
1
1
  export { executeGuardHook };
2
2
  import { getHookFromPageContext, getHookTimeoutDefault } from '../hooks/getHook.js';
3
3
  import { assert, assertUsage, isCallable } from './utils.js';
4
- import { executeHook } from '../hooks/executeHook.js';
4
+ import { execHookSingle } from '../hooks/execHook.js';
5
5
  const errIntro = 'The guard() hook defined by';
6
- async function executeGuardHook(pageContext, prepareForUserConsumption) {
6
+ async function executeGuardHook(pageContext, prepareForPublicUsage) {
7
7
  let hook;
8
8
  if (pageContext._pageFilesAll.length > 0) {
9
+ // TODO/v1-release: remove
9
10
  // V0.4 design
10
11
  assert(pageContext._pageConfigs.length === 0);
11
12
  hook = findPageGuard(pageContext.pageId, pageContext._pageFilesAll);
@@ -16,13 +17,7 @@ async function executeGuardHook(pageContext, prepareForUserConsumption) {
16
17
  }
17
18
  if (!hook)
18
19
  return;
19
- const guard = hook.hookFn;
20
- let pageContextForUserConsumption = pageContext;
21
- const res = prepareForUserConsumption(pageContext);
22
- if (res)
23
- pageContextForUserConsumption = res;
24
- const hookResult = await executeHook(() => guard(pageContextForUserConsumption), hook, pageContext);
25
- assertUsage(hookResult === undefined, `${errIntro} ${hook.hookFilePath} returns a value, but guard() shouldn't return any value`);
20
+ await execHookSingle(hook, pageContext, prepareForPublicUsage);
26
21
  }
27
22
  function findPageGuard(pageId, pageFilesAll) {
28
23
  const pageRouteFile = pageFilesAll.find((p) => p.pageId === pageId && p.fileType === '.page.route');
@@ -3,7 +3,8 @@ import { assertPageContextProvidedByUser } from '../assertPageContextProvidedByU
3
3
  import { assertUsage, hasProp, isObjectWithKeys, objectAssign, assertWarning, assertUsageUrlPathnameAbsolute, joinEnglish, assert } from './utils.js';
4
4
  import { assertRouteParams, assertSyncRouting } from './resolveRouteFunction.js';
5
5
  import pc from '@brillout/picocolors';
6
- import { executeHook } from '../hooks/executeHook.js';
6
+ import { execHookSync } from '../hooks/execHook.js';
7
+ import { preparePageContextForPublicUsage } from '../preparePageContextForPublicUsage.js';
7
8
  async function executeOnBeforeRouteHook(pageContext) {
8
9
  const pageContextFromOnBeforeRouteHook = {};
9
10
  if (!pageContext._onBeforeRouteHook)
@@ -33,10 +34,10 @@ async function executeOnBeforeRouteHook(pageContext) {
33
34
  return pageContextFromOnBeforeRouteHook;
34
35
  }
35
36
  async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
36
- let hookReturn = onBeforeRouteHook.hookFn(pageContext);
37
+ let { hookReturn } = execHookSync(onBeforeRouteHook, pageContext, preparePageContextForPublicUsage);
37
38
  assertSyncRouting(hookReturn, `The onBeforeRoute() hook ${onBeforeRouteHook.hookFilePath}`);
38
39
  // TODO/v1-release: make executeOnBeforeRouteHook() and route() sync
39
- hookReturn = await executeHook(() => hookReturn, onBeforeRouteHook, pageContext);
40
+ hookReturn = await hookReturn;
40
41
  const errPrefix = `The onBeforeRoute() hook defined by ${onBeforeRouteHook.hookFilePath}`;
41
42
  assertUsage(hookReturn === null ||
42
43
  hookReturn === undefined ||
@@ -6,7 +6,6 @@ if (isBrowser()) {
6
6
  assertClientRouting();
7
7
  }
8
8
  import { assert, assertUsage, isPlainObject, objectAssign } from './utils.js';
9
- import { assertPageContextUrl } from '../getPageContextUrlComputed.js';
10
9
  import { resolvePrecendence } from './resolvePrecedence.js';
11
10
  import { resolveRouteString } from './resolveRouteString.js';
12
11
  import { resolveRouteFunction } from './resolveRouteFunction.js';
@@ -15,7 +14,6 @@ import { debug } from './debug.js';
15
14
  import pc from '@brillout/picocolors';
16
15
  async function route(pageContext, skipOnBeforeRouteHook) {
17
16
  debug('Pages routes:', pageContext._pageRoutes);
18
- assertPageContextUrl(pageContext);
19
17
  const pageContextFromRoute = {};
20
18
  // onBeforeRoute()
21
19
  if (!skipOnBeforeRouteHook) {
@@ -69,8 +67,8 @@ async function route(pageContext, skipOnBeforeRouteHook) {
69
67
  }
70
68
  // Route Function defined in `.page.route.js`
71
69
  if (pageRoute.routeType === 'FUNCTION') {
72
- const { routeFunction, routeDefinedAtString } = pageRoute;
73
- const match = await resolveRouteFunction(routeFunction, pageContext, routeDefinedAtString);
70
+ const { routeFunction, routeFunctionFilePath } = pageRoute;
71
+ const match = await resolveRouteFunction(routeFunction, pageContext, routeFunctionFilePath);
74
72
  if (match) {
75
73
  const { routeParams, precedence } = match;
76
74
  routeMatches.push({ pageId, precedence, routeParams, routeType });
@@ -17,7 +17,8 @@ type PageRoute = {
17
17
  routeDefinedAtString: string;
18
18
  routeType: 'STRING';
19
19
  } | {
20
- routeFunction: Function;
20
+ routeFunction: (arg: unknown) => unknown;
21
+ routeFunctionFilePath: string;
21
22
  routeDefinedAtString: string;
22
23
  routeType: 'FUNCTION';
23
24
  });
@@ -2,7 +2,7 @@ export { loadPageRoutes };
2
2
  import { isErrorPageId } from '../error-page.js';
3
3
  import { assert, assertUsage, hasProp, slice } from './utils.js';
4
4
  import { deduceRouteStringFromFilesystemPath } from './deduceRouteStringFromFilesystemPath.js';
5
- import { isCallable } from '../utils.js';
5
+ import { isArray, isCallable } from '../utils.js';
6
6
  import { getConfigValueRuntime } from '../page-configs/getConfigValueRuntime.js';
7
7
  import { getDefinedAtString } from '../page-configs/getConfigDefinedAt.js';
8
8
  import { warnDeprecatedAllowKey } from './resolveRouteFunction.js';
@@ -44,6 +44,10 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
44
44
  };
45
45
  }
46
46
  else {
47
+ const { definedAtData } = configValue;
48
+ assert(!isArray(definedAtData) && !definedAtData.definedBy);
49
+ const { filePathToShowToUser } = definedAtData;
50
+ assert(filePathToShowToUser);
47
51
  assert(isCallable(route));
48
52
  // TODO/next-major: remove
49
53
  if (getConfigValueRuntime(pageConfig, 'iKnowThePerformanceRisksOfAsyncRouteFunctions', 'boolean'))
@@ -52,6 +56,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
52
56
  pageId,
53
57
  comesFromV1PageConfig,
54
58
  routeFunction: route,
59
+ routeFunctionFilePath: filePathToShowToUser,
55
60
  routeDefinedAtString: definedAtString,
56
61
  routeType: 'FUNCTION'
57
62
  };
@@ -125,6 +130,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
125
130
  pageId,
126
131
  comesFromV1PageConfig,
127
132
  routeFunction,
133
+ routeFunctionFilePath: filePath,
128
134
  routeDefinedAtString: filePath,
129
135
  routeType: 'FUNCTION'
130
136
  });
@@ -2,8 +2,8 @@ export { resolveRouteFunction };
2
2
  export { assertRouteParams };
3
3
  export { assertSyncRouting };
4
4
  export { warnDeprecatedAllowKey };
5
- import { PageContextUrlInternal } from '../getPageContextUrlComputed.js';
6
- declare function resolveRouteFunction(routeFunction: Function, pageContext: PageContextUrlInternal, routeDefinedAtString: string): Promise<null | {
5
+ import type { PageContextUrlInternal } from '../getPageContextUrlComputed.js';
6
+ declare function resolveRouteFunction(routeFunction: (arg: unknown) => unknown, pageContext: PageContextUrlInternal, routeFunctionFilePath: string): Promise<null | {
7
7
  precedence: number | null;
8
8
  routeParams: Record<string, string>;
9
9
  }>;
@@ -2,13 +2,17 @@ export { resolveRouteFunction };
2
2
  export { assertRouteParams };
3
3
  export { assertSyncRouting };
4
4
  export { warnDeprecatedAllowKey };
5
- import { assertPageContextUrl } from '../getPageContextUrlComputed.js';
5
+ import { execHookSync } from '../hooks/execHook.js';
6
+ import { preparePageContextForPublicUsage } from '../preparePageContextForPublicUsage.js';
6
7
  import { assert, assertUsage, assertWarning, hasProp, isPlainObject, isPromise } from './utils.js';
7
8
  import pc from '@brillout/picocolors';
8
- async function resolveRouteFunction(routeFunction, pageContext, routeDefinedAtString) {
9
- assertPageContextUrl(pageContext);
10
- let result = routeFunction(pageContext);
11
- assertSyncRouting(result, `The Route Function ${routeDefinedAtString}`);
9
+ async function resolveRouteFunction(routeFunction, pageContext, routeFunctionFilePath) {
10
+ let { hookReturn: result } = execHookSync({
11
+ hookFn: routeFunction,
12
+ hookFilePath: routeFunctionFilePath,
13
+ hookName: 'route'
14
+ }, pageContext, preparePageContextForPublicUsage);
15
+ assertSyncRouting(result, `The Route Function ${routeFunctionFilePath}`);
12
16
  // TODO/v1-release: make resolveRouteFunction() and route() sync
13
17
  //* We disallow asynchronous routing, because we need to check whether a link is a Vike link in a synchronous fashion before calling ev.preventDefault() in the 'click' event listener
14
18
  result = await result;
@@ -19,11 +23,11 @@ async function resolveRouteFunction(routeFunction, pageContext, routeDefinedAtSt
19
23
  if (result === true) {
20
24
  result = {};
21
25
  }
22
- assertUsage(isPlainObject(result), `The Route Function ${routeDefinedAtString} should return a boolean or a plain JavaScript object (but it's ${pc.cyan(`typeof result === ${JSON.stringify(typeof result)}`)} instead)`);
26
+ assertUsage(isPlainObject(result), `The Route Function ${routeFunctionFilePath} should return a boolean or a plain JavaScript object (but it's ${pc.cyan(`typeof result === ${JSON.stringify(typeof result)}`)} instead)`);
23
27
  // AFAICT this return interface is superfluous. Should we soft-deprecate it and remove it?
24
28
  if ('match' in result) {
25
29
  const { match } = result;
26
- assertUsage(typeof match === 'boolean', `The ${pc.cyan('match')} value returned by the Route Function ${routeDefinedAtString} should be a boolean.`);
30
+ assertUsage(typeof match === 'boolean', `The ${pc.cyan('match')} value returned by the Route Function ${routeFunctionFilePath} should be a boolean.`);
27
31
  if (!match) {
28
32
  return null;
29
33
  }
@@ -31,14 +35,14 @@ async function resolveRouteFunction(routeFunction, pageContext, routeDefinedAtSt
31
35
  let precedence = null;
32
36
  if ('precedence' in result) {
33
37
  precedence = result.precedence;
34
- assertUsage(typeof precedence === 'number', `The ${pc.cyan('precedence')} value returned by the Route Function ${routeDefinedAtString} should be a number.`);
38
+ assertUsage(typeof precedence === 'number', `The ${pc.cyan('precedence')} value returned by the Route Function ${routeFunctionFilePath} should be a number.`);
35
39
  }
36
- assertRouteParams(result, `The ${pc.cyan('routeParams')} object returned by the Route Function ${routeDefinedAtString} should`);
40
+ assertRouteParams(result, `The ${pc.cyan('routeParams')} object returned by the Route Function ${routeFunctionFilePath} should`);
37
41
  const routeParams = result.routeParams || {};
38
42
  assertUsage(!('pageContext' in result), `Providing ${pc.cyan('pageContext')} in Route Functions is prohibited, see https://vike.dev/route-function#cannot-provide-pagecontext`);
39
43
  assert(isPlainObject(routeParams));
40
44
  Object.keys(result).forEach((key) => {
41
- assertUsage(key === 'match' || key === 'routeParams' || key === 'precedence', `The Route Function ${routeDefinedAtString} returned an object with an unknown property ${pc.cyan(key)} (the known properties are ${pc.cyan('match')}, ${pc.cyan('routeParams')}, and ${pc.cyan('precedence')})`);
45
+ assertUsage(key === 'match' || key === 'routeParams' || key === 'precedence', `The Route Function ${routeFunctionFilePath} returned an object with an unknown property ${pc.cyan(key)} (the known properties are ${pc.cyan('match')}, ${pc.cyan('routeParams')}, and ${pc.cyan('precedence')})`);
42
46
  });
43
47
  return {
44
48
  precedence,