vike 0.4.229 → 0.4.230-commit-dd11364

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 +6 -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 +7 -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
@@ -1,9 +1,11 @@
1
1
  export { createGlobalContextShared };
2
2
  export { getGlobalContextSyncErrMsg };
3
+ import { changeEnumerable, objectAssign, unique } from './utils.js';
4
+ import { parseGlobResults } from './getPageFiles/parseGlobResults.js';
5
+ import { getUserFriendlyConfigsGlobal, getUserFriendlyConfigsPageEager } from './page-configs/getUserFriendlyConfigs.js';
6
+ import { execHookGlobal } from './hooks/execHook.js';
7
+ import { prepareGlobalContextForPublicUsage } from './prepareGlobalContextForPublicUsage.js';
3
8
  const getGlobalContextSyncErrMsg = "The global context isn't set yet, call getGlobalContextSync() later or use getGlobalContext() instead.";
4
- import { getPageConfigsRuntime } from './getPageConfigsRuntime.js';
5
- import { executeHookGenericGlobalCumulative } from './hooks/executeHookGeneric.js';
6
- import { objectAssign } from './utils.js';
7
9
  async function createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext) {
8
10
  const globalContext = createGlobalContextBase(virtualFileExports);
9
11
  const globalContextAddendum = await addGlobalContext?.(globalContext);
@@ -21,17 +23,17 @@ async function createGlobalContextShared(virtualFileExports, globalObject, addGl
21
23
  // - globalContext._viteDevServer.hot.send()
22
24
  // - Send 'full-server-reload' signal whenever a onCreateGlobalContext() function is modified => we need a globalObject to track all hooks and see if one of them is new/modified.
23
25
  // - Seems less idiomatic
24
- await executeHookGenericGlobalCumulative('onCreateGlobalContext', globalContext._pageConfigGlobal, null, globalContext);
26
+ await execHookGlobal('onCreateGlobalContext', globalContext._pageConfigGlobal, null, globalContext, prepareGlobalContextForPublicUsage);
25
27
  }
26
28
  else {
27
29
  // Singleton: ensure all `globalContext` user-land references are preserved & updated.
28
30
  // We don't use objectReplace() in order to keep user-land properties.
29
- objectAssign(globalObject.globalContext, globalContext);
31
+ objectAssign(globalObject.globalContext, globalContext, true);
30
32
  }
31
33
  return globalObject.globalContext;
32
34
  }
33
35
  function createGlobalContextBase(virtualFileExports) {
34
- const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, globalConfig, pageConfigsUserFriendly } = getPageConfigsRuntime(virtualFileExports);
36
+ const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, userFriendlyConfigsGlobal, userFriendlyConfigsPageEager } = getConfigsAll(virtualFileExports);
35
37
  const globalContext = {
36
38
  /**
37
39
  * Useful for distinguishing `globalContext` from other objects and narrowing down TypeScript unions.
@@ -39,13 +41,40 @@ function createGlobalContextBase(virtualFileExports) {
39
41
  * https://vike.dev/globalContext#typescript
40
42
  */
41
43
  isGlobalContext: true,
44
+ _isOriginalObject: true,
42
45
  _virtualFileExports: virtualFileExports,
43
46
  _pageFilesAll: pageFilesAll,
44
47
  _pageConfigs: pageConfigs,
45
48
  _pageConfigGlobal: pageConfigGlobal,
46
49
  _allPageIds: allPageIds,
47
- config: globalConfig.config,
48
- pages: pageConfigsUserFriendly
50
+ _userFriendlyConfigsGlobal: userFriendlyConfigsGlobal,
51
+ config: userFriendlyConfigsGlobal.config,
52
+ pages: userFriendlyConfigsPageEager
49
53
  };
54
+ changeEnumerable(globalContext, '_isOriginalObject', false);
50
55
  return globalContext;
51
56
  }
57
+ function getConfigsAll(virtualFileExports) {
58
+ const { pageFilesAll, pageConfigs, pageConfigGlobal } = parseGlobResults(virtualFileExports);
59
+ const allPageIds = getAllPageIds(pageFilesAll, pageConfigs);
60
+ const userFriendlyConfigsGlobal = getUserFriendlyConfigsGlobal({
61
+ pageConfigGlobalValues: pageConfigGlobal.configValues
62
+ });
63
+ const userFriendlyConfigsPageEager = Object.fromEntries(pageConfigs.map((pageConfig) => {
64
+ return getUserFriendlyConfigsPageEager(pageConfigGlobal.configValues, pageConfig, pageConfig.configValues);
65
+ }));
66
+ return {
67
+ pageFilesAll,
68
+ allPageIds,
69
+ pageConfigs,
70
+ pageConfigGlobal,
71
+ userFriendlyConfigsGlobal,
72
+ userFriendlyConfigsPageEager
73
+ };
74
+ }
75
+ function getAllPageIds(pageFilesAll, pageConfigs) {
76
+ const fileIds = pageFilesAll.filter(({ isDefaultPageFile }) => !isDefaultPageFile).map(({ pageId }) => pageId);
77
+ const allPageIds = unique(fileIds);
78
+ const allPageIds2 = pageConfigs.map((p) => p.pageId);
79
+ return [...allPageIds, ...allPageIds2];
80
+ }
@@ -1,9 +1,10 @@
1
1
  export { createPageContextShared };
2
+ export { createPageContextObject };
3
+ import type { PageConfigUserFriendly } from './page-configs/getUserFriendlyConfigs.js';
2
4
  import type { PageConfigGlobalRuntime } from './page-configs/PageConfig.js';
3
- declare function createPageContextShared<T extends object>(pageContextCreated: T, pageConfigGlobal: PageConfigGlobalRuntime): Promise<T & {
4
- config: import("./page-configs/Config/PageContextConfig.js").ConfigResolved;
5
- _source: import("./page-configs/getPageConfigUserFriendly.js").Source;
6
- _sources: import("./page-configs/getPageConfigUserFriendly.js").Sources;
7
- _from: import("./page-configs/getPageConfigUserFriendly.js").From;
5
+ import { type PageContextPrepareMinimum } from './preparePageContextForPublicUsage.js';
6
+ declare function createPageContextShared<T extends PageContextPrepareMinimum>(pageContextCreated: T, pageConfigGlobal: PageConfigGlobalRuntime, userFriendlyConfigsGlobal: PageConfigUserFriendly): Promise<T & PageConfigUserFriendly>;
7
+ declare function createPageContextObject(): {
8
+ _isOriginalObject: true;
8
9
  isPageContext: true;
9
- }>;
10
+ };
@@ -1,15 +1,18 @@
1
1
  export { createPageContextShared };
2
- import { executeHookGenericGlobalCumulative } from './hooks/executeHookGeneric.js';
3
- import { getPageConfigGlobalUserFriendly } from './page-configs/getPageConfigUserFriendly.js';
4
- import { objectAssign } from './utils.js';
5
- async function createPageContextShared(pageContextCreated, pageConfigGlobal) {
6
- const pageConfigGlobalUserFriendly = getPageConfigGlobalUserFriendly({
7
- pageConfigGlobalValues: pageConfigGlobal.configValues
8
- });
9
- objectAssign(pageContextCreated, {
10
- isPageContext: true,
11
- ...pageConfigGlobalUserFriendly
12
- }, true);
13
- await executeHookGenericGlobalCumulative('onCreatePageContext', pageConfigGlobal, pageContextCreated, pageContextCreated);
2
+ export { createPageContextObject };
3
+ import { execHookGlobal } from './hooks/execHook.js';
4
+ import { preparePageContextForPublicUsage } from './preparePageContextForPublicUsage.js';
5
+ import { changeEnumerable, objectAssign } from './utils.js';
6
+ async function createPageContextShared(pageContextCreated, pageConfigGlobal, userFriendlyConfigsGlobal) {
7
+ objectAssign(pageContextCreated, userFriendlyConfigsGlobal);
8
+ await execHookGlobal('onCreatePageContext', pageConfigGlobal, pageContextCreated, pageContextCreated, preparePageContextForPublicUsage);
14
9
  return pageContextCreated;
15
10
  }
11
+ function createPageContextObject() {
12
+ const pageContext = {
13
+ _isOriginalObject: true,
14
+ isPageContext: true
15
+ };
16
+ changeEnumerable(pageContext, '_isOriginalObject', false);
17
+ return pageContext;
18
+ }
@@ -1 +1 @@
1
- export { getPageContext, providePageContext } from './hooks/executeHook.js';
1
+ export { getPageContext, providePageContext } from './hooks/execHook.js';
@@ -1 +1 @@
1
- export { getPageContext, providePageContext } from './hooks/executeHook.js';
1
+ export { getPageContext, providePageContext } from './hooks/execHook.js';
@@ -1,9 +1,9 @@
1
1
  export { getPageContextUrlComputed };
2
- export { assertPageContextUrl };
3
2
  export type { PageContextUrlInternal };
4
3
  export type { PageContextUrlClient };
5
4
  export type { PageContextUrlServer };
6
5
  export type { PageContextUrlSource };
6
+ import { type PageContextPrepareMinimum } from './preparePageContextForPublicUsage.js';
7
7
  import { type UrlPublic } from './utils.js';
8
8
  type PageContextUrlComputed = {
9
9
  /** Parsed information about the current URL */
@@ -17,7 +17,7 @@ type PageContextUrl = {
17
17
  /** The URL of the HTTP request */
18
18
  urlOriginal: string;
19
19
  } & PageContextUrlComputed;
20
- type PageContextUrlInternal = PageContextUrl & {
20
+ type PageContextUrlInternal = PageContextPrepareMinimum & PageContextUrl & {
21
21
  _urlRewrite: string | null;
22
22
  };
23
23
  type PageContextUrlClient = PageContextUrl;
@@ -40,6 +40,3 @@ type PageContextUrlSource = {
40
40
  _baseServer: string;
41
41
  _urlHandler: null | ((url: string) => string);
42
42
  };
43
- declare function assertPageContextUrl(pageContext: {
44
- urlOriginal: string;
45
- } & PageContextUrlClient): void;
@@ -1,14 +1,14 @@
1
1
  export { getPageContextUrlComputed };
2
- export { assertPageContextUrl };
3
2
  // =====================
4
3
  // File determining the URL logic.
5
4
  // URLs need to be computed, because the user can modify the URL e.g. with onBeforeRoute() for i18n.
6
5
  // =====================
7
6
  import { objectDefineProperty } from '../utils/objectDefineProperty.js';
8
- import { assert, parseUrl, assertWarning, isPlainObject, isPropertyGetter, isBrowser, changeEnumerable } from './utils.js';
7
+ import { assertPropertyGetters } from './preparePageContextForPublicUsage.js';
8
+ import { assert, parseUrl, assertWarning, isBrowser, changeEnumerable } from './utils.js';
9
9
  function getPageContextUrlComputed(pageContext) {
10
10
  assert(typeof pageContext.urlOriginal === 'string');
11
- assertPageContextUrlComputed(pageContext);
11
+ assertPropertyGetters(pageContext);
12
12
  const pageContextUrlComputed = {};
13
13
  objectDefineProperty(pageContextUrlComputed, 'urlPathname', {
14
14
  get: urlPathnameGetter,
@@ -128,37 +128,3 @@ function urlParsedGetter() {
128
128
  }
129
129
  return urlParsedEnhanced;
130
130
  }
131
- function assertPageContextUrl(pageContext) {
132
- assert(typeof pageContext.urlOriginal === 'string');
133
- assert(typeof pageContext.urlPathname === 'string');
134
- assert(isPlainObject(pageContext.urlParsed));
135
- assert(pageContext.urlPathname === pageContext.urlParsed.pathname);
136
- assertPageContextUrlComputed(pageContext);
137
- }
138
- function assertPageContextUrlComputed(pageContext) {
139
- /*
140
- If the isPropertyGetter() assertions fail then it's most likely because Object.assign() was used instead of `objectAssign()`:
141
- ```js
142
- const PageContextUrlComputed = getPageContextUrlComputed(pageContext)
143
-
144
- // ❌ Breaks the property descriptors/getters of pageContext defined by getPageContextUrlComputed() such as pageContext.urlPathname
145
- Object.assign(pageContext, pageContextUrlComputed)
146
-
147
- // ❌ Also breaks property descriptors/getters
148
- const pageContext = { ...pageContextUrlComputed }
149
-
150
- // ✅ Preserves property descriptors/getters (see objectAssign() implementation)
151
- objectAssign(pageContext, pageContextUrlComputed)
152
- ```
153
- */
154
- if ('urlPathname' in pageContext) {
155
- assert(typeof pageContext.urlPathname === 'string');
156
- assert(isPropertyGetter(pageContext, 'urlPathname'));
157
- assert(isPropertyGetter(pageContext, 'urlParsed'));
158
- assert(isPropertyGetter(pageContext, 'url'));
159
- }
160
- else {
161
- assert(!('urlParsed' in pageContext));
162
- assert(!('url' in pageContext));
163
- }
164
- }
@@ -1,4 +1,4 @@
1
1
  export type { PageFile } from './getPageFiles/getPageFileObject.js';
2
- export type { ExportsAll, PageConfigUserFriendlyOld } from './page-configs/getPageConfigUserFriendly.js';
2
+ export type { ExportsAll, PageConfigUserFriendlyOld } from './page-configs/getUserFriendlyConfigs.js';
3
3
  export { getPageFilesClientSide } from './getPageFiles/getAllPageIdFiles.js';
4
4
  export { getPageFilesServerSide } from './getPageFiles/getAllPageIdFiles.js';
@@ -0,0 +1,4 @@
1
+ export { getProxyForPublicUsage };
2
+ type Target = Record<string, unknown>;
3
+ type Fallback = (prop: string | symbol) => unknown;
4
+ declare function getProxyForPublicUsage<Obj extends Target>(obj: Obj, objName: string, skipOnInternalProp?: true, fallback?: Fallback): Obj;
@@ -0,0 +1,54 @@
1
+ export { getProxyForPublicUsage };
2
+ // We use a proxy instead of property getters.
3
+ // - The issue with property getters is that they can't be `writable: true` but we do want the user to be able to modify the value of internal properties.
4
+ // ```console
5
+ // TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #<Object>
6
+ // ```
7
+ // - Previous implementation using property getters: https://github.com/vikejs/vike/blob/main/vike/utils/makePublicCopy.ts
8
+ // Show warning when user is accessing internal `_` properties.
9
+ import { NOT_SERIALIZABLE } from './NOT_SERIALIZABLE.js';
10
+ import { assert, assertUsage, assertWarning, getPropAccessNotation, isBrowser } from './utils.js';
11
+ function getProxyForPublicUsage(obj, objName, skipOnInternalProp, fallback) {
12
+ return new Proxy(obj, {
13
+ get: getTrapGet(obj, objName, skipOnInternalProp, fallback)
14
+ });
15
+ }
16
+ function getTrapGet(obj, objName, skipOnInternalProp, fallback) {
17
+ return function (_, prop) {
18
+ const propStr = String(prop);
19
+ if (prop === '_isProxyObject')
20
+ return true;
21
+ if (!skipOnInternalProp)
22
+ onInternalProp(propStr, objName);
23
+ if (fallback && !(prop in obj)) {
24
+ // Rudimentary flat pageContext implementation https://github.com/vikejs/vike/issues/1268
25
+ // Failed full-fledged implementation: https://github.com/vikejs/vike/pull/2458
26
+ return fallback(prop);
27
+ }
28
+ const val = obj[prop];
29
+ onNotSerializable(propStr, val, objName);
30
+ return val;
31
+ };
32
+ }
33
+ function onNotSerializable(propStr, val, objName) {
34
+ if (val !== NOT_SERIALIZABLE)
35
+ return;
36
+ const propName = getPropAccessNotation(propStr);
37
+ assert(isBrowser());
38
+ assertUsage(false, `Can't access ${objName}${propName} on the client side. Because it can't be serialized, see server logs.`);
39
+ }
40
+ function onInternalProp(propStr, objName) {
41
+ // - We must skip it in the client-side because of the reactivity mechanism of UI frameworks like Solid.
42
+ // - TO-DO/eventually: use import.meta.CLIENT instead of isBrowser()
43
+ // - Where import.meta.CLIENT is defined by Vike
44
+ // - Using import.meta.env.CLIENT (note `.env.`) doesn't seem possible: https://github.com/brillout/playground_node_import.meta.env
45
+ // - If Rolldown Vite + Rolldowns always transpiles node_modules/ then we can simply use import.meta.env.SSR
46
+ if (isBrowser())
47
+ return;
48
+ // TODO/now remove this and only warn on built-in access instead
49
+ if (propStr === '_configFromHook')
50
+ return;
51
+ if (propStr.startsWith('_')) {
52
+ assertWarning(false, `Using internal ${objName}.${propStr} which may break in any minor version update. Reach out on GitHub to request official support for your use case.`, { onlyOnce: true, showStackTrace: true });
53
+ }
54
+ }
@@ -0,0 +1,63 @@
1
+ export { execHook };
2
+ export { execHookSingle };
3
+ export { execHookSingleWithReturn };
4
+ export { execHookErrorHandling };
5
+ export { execHooksErrorHandling };
6
+ export { execHookWithoutPageContext };
7
+ export { execHookGlobal };
8
+ export { execHookSync };
9
+ export { getPageContext };
10
+ export { providePageContext };
11
+ export { isUserHookError };
12
+ export type { PageContextExecuteHook };
13
+ import type { PageContextClient, PageContextServer } from '../types.js';
14
+ import type { Hook, HookLoc } from './getHook.js';
15
+ import type { PageConfigUserFriendlyOld } from '../getPageFiles.js';
16
+ import type { HookName, HookNameGlobal } from '../page-configs/Config.js';
17
+ import type { PageConfigGlobalRuntime } from '../page-configs/PageConfig.js';
18
+ import type { PageContextForPublicUsageServer } from '../../node/runtime/renderPage/preparePageContextForPublicUsageServer.js';
19
+ import type { PageContextForPublicUsageClientShared } from '../../client/shared/preparePageContextForPublicUsageClientShared.js';
20
+ import { type PageContextPrepareMinimum } from '../preparePageContextForPublicUsage.js';
21
+ import type { GlobalContextPrepareMinimum } from '../prepareGlobalContextForPublicUsage.js';
22
+ type PageContextExecuteHook = PageConfigUserFriendlyOld & PageContextForPublicUsage;
23
+ type PageContextForPublicUsage = PageContextForPublicUsageServer | PageContextForPublicUsageClientShared;
24
+ type HookWithResult = Hook & {
25
+ hookReturn: unknown;
26
+ };
27
+ declare function execHookSingle<PageContext extends PageContextExecuteHook>(hook: Hook, pageContext: PageContext, preparePageContextForPublicUsage: (pageContext: PageContext) => PageContext): Promise<void>;
28
+ declare function execHookSingleWithReturn<PageContext extends PageContextExecuteHook>(hook: Hook, pageContext: PageContext, preparePageContextForPublicUsage: (pageContext: PageContext) => PageContext): Promise<{
29
+ hookReturn: unknown;
30
+ }>;
31
+ declare function execHook<PageContext extends PageContextExecuteHook>(hookName: HookName, pageContext: PageContext, preparePageContextForPublicUsage: (pageContext: PageContext) => PageContext): Promise<HookWithResult[]>;
32
+ declare function execHookErrorHandling<PageContext extends PageContextExecuteHook>(hookName: HookName, pageContext: PageContext, preparePageContextForPublicUsage: (pageContext: PageContext) => PageContext): Promise<{
33
+ hooks: HookWithResult[];
34
+ err?: undefined;
35
+ } | {
36
+ hooks: Hook[];
37
+ err: unknown;
38
+ }>;
39
+ declare function execHooksErrorHandling<PageContext extends PageContextPrepareMinimum>(hooks: Hook[], pageContext: PageContext, preparePageContextForPublicUsage: (pageContext: PageContext) => PageContext): Promise<{
40
+ hooks: HookWithResult[];
41
+ err?: undefined;
42
+ } | {
43
+ hooks: Hook[];
44
+ err: unknown;
45
+ }>;
46
+ declare function execHookGlobal<HookArg extends PageContextPrepareMinimum | GlobalContextPrepareMinimum>(hookName: HookNameGlobal, pageConfigGlobal: PageConfigGlobalRuntime, pageContext: PageContextPrepareMinimum | null, hookArg: HookArg, prepareForPublicUsage: (hookArg: HookArg) => HookArg): Promise<void>;
47
+ declare function isUserHookError(err: unknown): false | HookLoc;
48
+ declare function execHookWithoutPageContext<HookReturn>(hookFnCaller: () => HookReturn, hook: Omit<Hook, 'hookFn'>): Promise<HookReturn>;
49
+ declare function execHookSync<PageContext extends PageContextPrepareMinimum>(hook: Omit<Hook, 'hookTimeout'>, pageContext: PageContext, preparePageContextForPublicUsage: (pageContext: PageContext) => PageContext): {
50
+ hookReturn: unknown;
51
+ };
52
+ /**
53
+ * Access `pageContext` object inside Vike hooks, in order to create universal hooks.
54
+ *
55
+ * https://vike.dev/getPageContext
56
+ */
57
+ declare function getPageContext<PageContext = PageContextClient | PageContextServer>(): null | PageContext;
58
+ /**
59
+ * Provide `pageContext` for universal hooks.
60
+ *
61
+ * https://vike.dev/getPageContext
62
+ */
63
+ declare function providePageContext(pageContext: null | PageContextClient | PageContextServer): void;
@@ -0,0 +1,168 @@
1
+ export { execHook };
2
+ export { execHookSingle };
3
+ export { execHookSingleWithReturn };
4
+ export { execHookErrorHandling };
5
+ export { execHooksErrorHandling };
6
+ export { execHookWithoutPageContext };
7
+ export { execHookGlobal };
8
+ export { execHookSync };
9
+ export { getPageContext };
10
+ export { providePageContext };
11
+ export { isUserHookError };
12
+ import { getProjectError, assertWarning, assertUsage } from '../../utils/assert.js';
13
+ import { getGlobalObject } from '../../utils/getGlobalObject.js';
14
+ import { humanizeTime } from '../../utils/humanizeTime.js';
15
+ import { isObject } from '../../utils/isObject.js';
16
+ import { getHookFromPageConfigGlobalCumulative, getHookFromPageContextNew } from './getHook.js';
17
+ import { preparePageContextForPublicUsage } from '../preparePageContextForPublicUsage.js';
18
+ const globalObject = getGlobalObject('utils/execHook.ts', {
19
+ userHookErrors: new WeakMap(),
20
+ pageContext: null
21
+ });
22
+ async function execHookSingle(hook, pageContext, preparePageContextForPublicUsage) {
23
+ const res = await execHooksErrorHandling([hook], pageContext, preparePageContextForPublicUsage);
24
+ if ('err' in res)
25
+ throw res.err;
26
+ const { hookReturn } = res.hooks[0];
27
+ assertUsage(hookReturn === undefined, `The ${hook.hookName}() hook defined by ${hook.hookFilePath} isn't allowed to return a value`);
28
+ }
29
+ async function execHookSingleWithReturn(hook, pageContext, preparePageContextForPublicUsage) {
30
+ const res = await execHooksErrorHandling([hook], pageContext, preparePageContextForPublicUsage);
31
+ if ('err' in res)
32
+ throw res.err;
33
+ const { hookReturn } = res.hooks[0];
34
+ return { hookReturn };
35
+ }
36
+ async function execHook(hookName, pageContext, preparePageContextForPublicUsage) {
37
+ const res = await execHookErrorHandling(hookName, pageContext, preparePageContextForPublicUsage);
38
+ if ('err' in res)
39
+ throw res.err;
40
+ return res.hooks;
41
+ }
42
+ async function execHookErrorHandling(hookName, pageContext, preparePageContextForPublicUsage) {
43
+ const hooks = getHookFromPageContextNew(hookName, pageContext);
44
+ return execHooksErrorHandling(hooks, pageContext, preparePageContextForPublicUsage);
45
+ }
46
+ async function execHooksErrorHandling(hooks, pageContext, preparePageContextForPublicUsage) {
47
+ if (!hooks.length)
48
+ return { hooks: [] };
49
+ const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
50
+ let hooksWithResult;
51
+ let err;
52
+ try {
53
+ hooksWithResult = await Promise.all(hooks.map(async (hook) => {
54
+ const hookReturn = await execHookAsync(() => hook.hookFn(pageContextForPublicUsage), hook, pageContextForPublicUsage);
55
+ return { ...hook, hookReturn };
56
+ }));
57
+ }
58
+ catch (err_) {
59
+ err = err_;
60
+ }
61
+ if (hooksWithResult) {
62
+ return { hooks: hooksWithResult };
63
+ }
64
+ else {
65
+ return { hooks, err };
66
+ }
67
+ }
68
+ async function execHookGlobal(hookName, pageConfigGlobal, pageContext, hookArg, prepareForPublicUsage) {
69
+ const hooks = getHookFromPageConfigGlobalCumulative(pageConfigGlobal, hookName);
70
+ const hookArgForPublicUsage = prepareForPublicUsage(hookArg);
71
+ await Promise.all(hooks.map(async (hook) => {
72
+ await execHookAsync(() => hook.hookFn(hookArgForPublicUsage), hook, pageContext);
73
+ }));
74
+ }
75
+ function isUserHookError(err) {
76
+ if (!isObject(err))
77
+ return false;
78
+ return globalObject.userHookErrors.get(err) ?? false;
79
+ }
80
+ async function execHookWithoutPageContext(hookFnCaller, hook) {
81
+ const { hookName, hookFilePath, hookTimeout } = hook;
82
+ const hookReturn = await execHookAsync(hookFnCaller, { hookName, hookFilePath, hookTimeout }, null);
83
+ return hookReturn;
84
+ }
85
+ function execHookAsync(hookFnCaller, hook, pageContextForPublicUsage) {
86
+ const { hookName, hookFilePath, hookTimeout: { error: timeoutErr, warning: timeoutWarn } } = hook;
87
+ let resolve;
88
+ let reject;
89
+ const promise = new Promise((resolve_, reject_) => {
90
+ resolve = (ret) => {
91
+ clearTimeouts();
92
+ resolve_(ret);
93
+ };
94
+ reject = (err) => {
95
+ clearTimeouts();
96
+ reject_(err);
97
+ };
98
+ });
99
+ const clearTimeouts = () => {
100
+ if (currentTimeoutWarn)
101
+ clearTimeout(currentTimeoutWarn);
102
+ if (currentTimeoutErr)
103
+ clearTimeout(currentTimeoutErr);
104
+ };
105
+ const currentTimeoutWarn = isNotDisabled(timeoutWarn) &&
106
+ setTimeout(() => {
107
+ assertWarning(false, `The ${hookName}() hook defined by ${hookFilePath} is slow: it's taking more than ${humanizeTime(timeoutWarn)} (https://vike.dev/hooksTimeout)`, { onlyOnce: false });
108
+ }, timeoutWarn);
109
+ const currentTimeoutErr = isNotDisabled(timeoutErr) &&
110
+ setTimeout(() => {
111
+ const err = getProjectError(`The ${hookName}() hook defined by ${hookFilePath} timed out: it didn't finish after ${humanizeTime(timeoutErr)} (https://vike.dev/hooksTimeout)`);
112
+ reject(err);
113
+ }, timeoutErr);
114
+ (async () => {
115
+ try {
116
+ providePageContextInternal(pageContextForPublicUsage);
117
+ const ret = await hookFnCaller();
118
+ resolve(ret);
119
+ }
120
+ catch (err) {
121
+ if (isObject(err)) {
122
+ globalObject.userHookErrors.set(err, { hookName, hookFilePath });
123
+ }
124
+ reject(err);
125
+ }
126
+ })();
127
+ return promise;
128
+ }
129
+ function execHookSync(hook, pageContext, preparePageContextForPublicUsage) {
130
+ const pageContextForPublicUsage = preparePageContextForPublicUsage(pageContext);
131
+ providePageContextInternal(pageContextForPublicUsage);
132
+ const hookReturn = hook.hookFn(pageContextForPublicUsage);
133
+ return { hookReturn };
134
+ }
135
+ function isNotDisabled(timeout) {
136
+ return !!timeout && timeout !== Infinity;
137
+ }
138
+ /**
139
+ * Access `pageContext` object inside Vike hooks, in order to create universal hooks.
140
+ *
141
+ * https://vike.dev/getPageContext
142
+ */
143
+ function getPageContext() {
144
+ const { pageContext } = globalObject;
145
+ if (!pageContext)
146
+ return null;
147
+ const pageContextForPublicUsage = pageContext._isProxyObject
148
+ ? // providePageContext() is called on the user-land (e.g. it's called by `vike-{react,vue,solid}`) thus it's already a proxy
149
+ pageContext
150
+ : preparePageContextForPublicUsage(pageContext);
151
+ return pageContextForPublicUsage;
152
+ }
153
+ /**
154
+ * Provide `pageContext` for universal hooks.
155
+ *
156
+ * https://vike.dev/getPageContext
157
+ */
158
+ function providePageContext(pageContext) {
159
+ providePageContextInternal(pageContext);
160
+ }
161
+ function providePageContextInternal(pageContext) {
162
+ globalObject.pageContext = pageContext;
163
+ // Promise.resolve() is quicker than process.nextTick() and setImmediate()
164
+ // https://stackoverflow.com/questions/67949576/process-nexttick-before-promise-resolve-then
165
+ Promise.resolve().then(() => {
166
+ globalObject.pageContext = null;
167
+ });
168
+ }
@@ -1,38 +1,37 @@
1
1
  export { getHookFromPageContext };
2
+ export { getHookFromPageContextNew };
2
3
  export { getHookFromPageConfig };
3
4
  export { getHookFromPageConfigGlobal };
4
5
  export { getHookFromPageConfigGlobalCumulative };
5
- export { assertHook };
6
6
  export { getHook_setIsPrerenderering };
7
7
  export type { Hook };
8
- export type { HookName };
9
8
  export type { HookLoc };
10
9
  export type { HookTimeout };
11
10
  export type { HooksTimeoutProvidedByUser };
12
11
  export { getHookTimeoutDefault };
13
12
  import type { PageConfigUserFriendlyOld } from '../getPageFiles.js';
14
- import type { HookName, HookNamePage, HookNameGlobal } from '../page-configs/Config.js';
13
+ import type { HookNameOld, HookNamePage, HookNameGlobal, HookName } from '../page-configs/Config.js';
15
14
  import type { PageConfigGlobalRuntime, PageConfigRuntime } from '../page-configs/PageConfig.js';
15
+ import type { GlobalContextPrepareMinimum } from '../prepareGlobalContextForPublicUsage.js';
16
+ import type { PageContextPrepareMinimum } from '../preparePageContextForPublicUsage.js';
16
17
  type Hook = HookLoc & {
17
18
  hookFn: HookFn;
18
19
  hookTimeout: HookTimeout;
19
20
  };
20
21
  type HookLoc = {
21
- hookName: HookName;
22
+ hookName: HookNameOld;
22
23
  hookFilePath: string;
23
24
  };
24
- type HookFn = (arg: object) => unknown;
25
+ type HookFn = (arg: PageContextPrepareMinimum | GlobalContextPrepareMinimum) => unknown;
25
26
  type HookTimeout = {
26
27
  error: number | false;
27
28
  warning: number | false;
28
29
  };
29
- type HooksTimeoutProvidedByUser = false | Partial<Record<HookName, false | Partial<HookTimeout>>>;
30
- declare function getHookFromPageContext(pageContext: PageConfigUserFriendlyOld, hookName: HookName): null | Hook;
30
+ type HooksTimeoutProvidedByUser = false | Partial<Record<HookNameOld, false | Partial<HookTimeout>>>;
31
+ declare function getHookFromPageContext(pageContext: PageConfigUserFriendlyOld, hookName: HookNameOld): null | Hook;
32
+ declare function getHookFromPageContextNew(hookName: HookName, pageContext: PageConfigUserFriendlyOld): Hook[];
31
33
  declare function getHookFromPageConfig(pageConfig: PageConfigRuntime, hookName: HookNamePage): null | Hook;
32
34
  declare function getHookFromPageConfigGlobal(pageConfigGlobal: PageConfigGlobalRuntime, hookName: HookNameGlobal): null | Hook;
33
35
  declare function getHookFromPageConfigGlobalCumulative(pageConfigGlobal: PageConfigGlobalRuntime, hookName: HookNameGlobal): Hook[];
34
- declare function assertHook<TPageContext extends PageConfigUserFriendlyOld, THookName extends PropertyKey & HookName>(pageContext: TPageContext, hookName: THookName): asserts pageContext is TPageContext & {
35
- exports: Record<THookName, Function | undefined>;
36
- };
37
- declare function getHookTimeoutDefault(hookName: HookName): HookTimeout;
36
+ declare function getHookTimeoutDefault(hookName: HookNameOld): HookTimeout;
38
37
  declare function getHook_setIsPrerenderering(): void;
@@ -1,8 +1,8 @@
1
1
  export { getHookFromPageContext };
2
+ export { getHookFromPageContextNew };
2
3
  export { getHookFromPageConfig };
3
4
  export { getHookFromPageConfigGlobal };
4
5
  export { getHookFromPageConfigGlobalCumulative };
5
- export { assertHook };
6
6
  export { getHook_setIsPrerenderering };
7
7
  // TODO/v1-release: remove
8
8
  // We export for old V0.4 design which doesn't support config.hooksTimeout
@@ -22,12 +22,34 @@ function getHookFromPageContext(pageContext, hookName) {
22
22
  const hookFn = pageContext.exports[hookName];
23
23
  if (hookFn === null)
24
24
  return null;
25
+ // TO-DO/eventually: use pageContext.configEntries in favor of pageContext.exportsAll once V0.4 is removed
25
26
  const file = pageContext.exportsAll[hookName][0];
26
27
  assert(file.exportValue === hookFn);
27
28
  const hookFilePath = file.filePath;
28
29
  assert(hookFilePath);
29
30
  return getHook(hookFn, hookName, hookFilePath, hookTimeout);
30
31
  }
32
+ // TO-DO/eventually: remove getHookFromPageContext() in favor of getHookFromPageContextNew()
33
+ function getHookFromPageContextNew(hookName, pageContext) {
34
+ const { hooksTimeout } = pageContext.config;
35
+ const hookTimeout = getHookTimeout(hooksTimeout, hookName);
36
+ const hooks = [];
37
+ /* TO-DO/eventually: use pageContext.configEntries in favor of pageContext.exportsAll once V0.4 is removed
38
+ pageContext.configEntries[hookName]?.forEach((val) => {
39
+ const hookFn = val.configValue
40
+ if (hookFn === null) return
41
+ const hookFilePath = val.configDefinedByFile
42
+ */
43
+ pageContext.exportsAll[hookName]?.forEach((val) => {
44
+ const hookFn = val.exportValue;
45
+ if (hookFn === null)
46
+ return;
47
+ const hookFilePath = val.filePath;
48
+ assert(hookFilePath);
49
+ hooks.push(getHook(hookFn, hookName, hookFilePath, hookTimeout));
50
+ });
51
+ return hooks;
52
+ }
31
53
  function getHookFromPageConfig(pageConfig, hookName) {
32
54
  const configValue = getConfigValueRuntime(pageConfig, hookName);
33
55
  if (!configValue?.value)
@@ -76,9 +98,6 @@ function getHookFromConfigValue(configValue) {
76
98
  const hookFilePath = getHookFilePathToShowToUser(configValue.definedAtData);
77
99
  return { hookFn, hookFilePath };
78
100
  }
79
- function assertHook(pageContext, hookName) {
80
- getHookFromPageContext(pageContext, hookName);
81
- }
82
101
  function assertHookFn(hookFn, { hookName, hookFilePath }) {
83
102
  assert(hookName && hookFilePath);
84
103
  assert(!hookName.endsWith(')'));