vike 0.4.228 → 0.4.229

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 (225) hide show
  1. package/dist/cjs/__internal/index.js +2 -2
  2. package/dist/cjs/client/client-routing-runtime/globalContext.js +49 -0
  3. package/dist/cjs/client/server-routing-runtime/globalContext.js +41 -0
  4. package/dist/cjs/client/server-routing-runtime/utils.js +1 -1
  5. package/dist/cjs/client/shared/createGetGlobalContextClient.js +58 -0
  6. package/dist/cjs/client/shared/getJsonSerializedInHtml.js +31 -0
  7. package/dist/cjs/client/shared/utils.js +22 -0
  8. package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
  9. package/dist/cjs/node/plugin/plugins/build/handleAssetsManifest.js +10 -5
  10. package/dist/cjs/node/plugin/plugins/build/pluginBuildApp.js +1 -1
  11. package/dist/cjs/node/plugin/plugins/build/pluginBuildConfig.js +3 -10
  12. package/dist/cjs/node/plugin/plugins/build/pluginBuildEntry.js +9 -5
  13. package/dist/cjs/node/plugin/plugins/build/pluginModuleBanner.js +5 -1
  14. package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +1 -1
  15. package/dist/cjs/node/plugin/plugins/commonConfig.js +14 -3
  16. package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +2 -7
  17. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
  18. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -0
  19. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.js +2 -0
  20. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
  21. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.js → pointerImports.js} +13 -0
  22. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +20 -19
  23. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +13 -10
  24. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +11 -11
  25. package/dist/cjs/node/plugin/shared/getFilePath.js +2 -2
  26. package/dist/cjs/node/plugin/shared/resolveClientEntriesDev.js +7 -19
  27. package/dist/cjs/node/plugin/utils.js +1 -0
  28. package/dist/cjs/node/prerender/runPrerender.js +44 -41
  29. package/dist/cjs/node/prerender/utils.js +1 -1
  30. package/dist/cjs/node/runtime/globalContext.js +102 -125
  31. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +18 -5
  32. package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +2 -2
  33. package/dist/cjs/node/runtime/html/propKeys.js +47 -0
  34. package/dist/cjs/node/runtime/html/renderHtml.js +1 -1
  35. package/dist/cjs/node/runtime/html/{serializePageContextClientSide.js → serializeContext.js} +37 -67
  36. package/dist/cjs/node/runtime/index-deprecated.js +9 -38
  37. package/dist/cjs/node/runtime/index.js +56 -2
  38. package/dist/cjs/node/runtime/renderPage/analyzePage.js +1 -1
  39. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +8 -3
  40. package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +73 -0
  41. package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +2 -2
  42. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
  43. package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +1 -1
  44. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +1 -17
  45. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +1 -1
  46. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +2 -2
  47. package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +1 -1
  48. package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
  49. package/dist/cjs/node/runtime/renderPage/log404/index.js +1 -1
  50. package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +1 -1
  51. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -68
  52. package/dist/cjs/node/runtime/renderPage.js +102 -81
  53. package/dist/cjs/node/runtime/universal-middleware.js +7 -1
  54. package/dist/cjs/node/runtime/utils.js +3 -2
  55. package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -1
  56. package/dist/cjs/shared/createGlobalContextShared.js +54 -0
  57. package/dist/cjs/shared/createPageContextShared.js +17 -0
  58. package/dist/cjs/shared/getPageFiles/fileTypes.js +1 -1
  59. package/dist/cjs/shared/hooks/executeHookGeneric.js +18 -0
  60. package/dist/cjs/shared/hooks/getHook.js +45 -27
  61. package/dist/cjs/shared/htmlElementIds.js +5 -0
  62. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +3 -7
  63. package/dist/cjs/shared/route/executeGuardHook.js +1 -1
  64. package/dist/cjs/shared/route/loadPageRoutes.js +2 -1
  65. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  66. package/dist/cjs/utils/catchInfiniteLoop.js +3 -3
  67. package/dist/cjs/utils/getPublicProxy.js +27 -0
  68. package/dist/cjs/utils/isImportPath.js +21 -0
  69. package/dist/cjs/utils/objectAssign.js +6 -10
  70. package/dist/cjs/utils/objectReplace.js +4 -4
  71. package/dist/cjs/utils/{isNpmPackage.js → parseNpmPackage.js} +23 -23
  72. package/dist/cjs/utils/path.js +12 -2
  73. package/dist/cjs/utils/requireResolve.js +134 -53
  74. package/dist/esm/__internal/index.js +3 -3
  75. package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +29 -10
  76. package/dist/esm/client/client-routing-runtime/createPageContext.js +23 -22
  77. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +5 -4
  78. package/dist/esm/client/client-routing-runtime/globalContext.d.ts +20 -0
  79. package/dist/esm/client/client-routing-runtime/globalContext.js +13 -0
  80. package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +2 -2
  81. package/dist/esm/client/client-routing-runtime/prefetch.js +2 -2
  82. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +8 -7
  83. package/dist/esm/client/client-routing-runtime/utils.d.ts +0 -1
  84. package/dist/esm/client/client-routing-runtime/utils.js +0 -1
  85. package/dist/esm/client/index.d.ts +1 -0
  86. package/dist/esm/client/index.js +4 -0
  87. package/dist/esm/client/node.js +1 -3
  88. package/dist/esm/client/server-routing-runtime/createPageContextClientSide.d.ts +36 -0
  89. package/dist/esm/client/server-routing-runtime/createPageContextClientSide.js +47 -0
  90. package/dist/esm/client/server-routing-runtime/entry.js +2 -2
  91. package/dist/esm/client/server-routing-runtime/globalContext.d.ts +17 -0
  92. package/dist/esm/client/server-routing-runtime/globalContext.js +5 -0
  93. package/dist/esm/client/server-routing-runtime/utils.d.ts +1 -1
  94. package/dist/esm/client/server-routing-runtime/utils.js +1 -1
  95. package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +23 -0
  96. package/dist/esm/client/shared/createGetGlobalContextClient.js +58 -0
  97. package/dist/esm/client/shared/executeOnRenderClientHook.js +5 -4
  98. package/dist/esm/client/shared/{getPageContextSerializedInHtml.d.ts → getJsonSerializedInHtml.d.ts} +2 -0
  99. package/dist/esm/client/shared/getJsonSerializedInHtml.js +29 -0
  100. package/dist/esm/client/shared/removeFoucBuster.js +1 -0
  101. package/dist/esm/client/shared/utils.d.ts +4 -0
  102. package/dist/esm/client/shared/utils.js +4 -0
  103. package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
  104. package/dist/esm/node/plugin/plugins/build/handleAssetsManifest.js +11 -6
  105. package/dist/esm/node/plugin/plugins/build/pluginBuildApp.js +2 -2
  106. package/dist/esm/node/plugin/plugins/build/pluginBuildConfig.js +4 -11
  107. package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.d.ts +1 -1
  108. package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.js +10 -6
  109. package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +5 -1
  110. package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +2 -2
  111. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +2 -0
  112. package/dist/esm/node/plugin/plugins/commonConfig.js +15 -4
  113. package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +3 -8
  114. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
  115. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -0
  116. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.d.ts +1 -1
  117. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.js +2 -0
  118. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -1
  119. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.d.ts → pointerImports.d.ts} +2 -0
  120. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.js → pointerImports.js} +14 -1
  121. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +1 -1
  122. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +20 -19
  123. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +13 -10
  124. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +11 -11
  125. package/dist/esm/node/plugin/shared/getFilePath.js +3 -3
  126. package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +8 -20
  127. package/dist/esm/node/plugin/utils.d.ts +1 -0
  128. package/dist/esm/node/plugin/utils.js +1 -0
  129. package/dist/esm/node/prerender/runPrerender.d.ts +314 -5
  130. package/dist/esm/node/prerender/runPrerender.js +48 -45
  131. package/dist/esm/node/prerender/utils.d.ts +1 -1
  132. package/dist/esm/node/prerender/utils.js +1 -1
  133. package/dist/esm/node/runtime/globalContext.d.ts +425 -47
  134. package/dist/esm/node/runtime/globalContext.js +103 -126
  135. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +18 -5
  136. package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.d.ts +2 -2
  137. package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +2 -2
  138. package/dist/esm/node/runtime/html/injectAssets.d.ts +3 -3
  139. package/dist/esm/node/runtime/html/propKeys.d.ts +8 -0
  140. package/dist/esm/node/runtime/html/propKeys.js +45 -0
  141. package/dist/esm/node/runtime/html/renderHtml.js +1 -1
  142. package/dist/esm/node/runtime/html/{serializePageContextClientSide.d.ts → serializeContext.d.ts} +7 -6
  143. package/dist/esm/node/runtime/html/{serializePageContextClientSide.js → serializeContext.js} +36 -67
  144. package/dist/esm/node/runtime/index-deprecated.d.ts +1 -16
  145. package/dist/esm/node/runtime/index-deprecated.js +9 -36
  146. package/dist/esm/node/runtime/index.d.ts +23 -1
  147. package/dist/esm/node/runtime/index.js +38 -3
  148. package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
  149. package/dist/esm/node/runtime/renderPage/analyzePage.js +1 -1
  150. package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +5 -4
  151. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +8 -3
  152. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +155 -0
  153. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +71 -0
  154. package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +3 -3
  155. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +1 -1
  156. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +3 -3
  157. package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +2 -2
  158. package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +1 -17
  159. package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
  160. package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -2
  161. package/dist/esm/node/runtime/renderPage/getPageAssets.js +2 -2
  162. package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
  163. package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.js +1 -1
  164. package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +2 -2
  165. package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
  166. package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
  167. package/dist/esm/node/runtime/renderPage/log404/index.js +1 -1
  168. package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +3 -3
  169. package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +1 -1
  170. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +225 -179
  171. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +4 -69
  172. package/dist/esm/node/runtime/renderPage.d.ts +146 -7
  173. package/dist/esm/node/runtime/renderPage.js +105 -84
  174. package/dist/esm/node/runtime/universal-middleware.js +7 -1
  175. package/dist/esm/node/runtime/utils.d.ts +3 -2
  176. package/dist/esm/node/runtime/utils.js +3 -2
  177. package/dist/esm/shared/VikeNamespace.d.ts +35 -13
  178. package/dist/esm/shared/assertPageContextProvidedByUser.js +1 -1
  179. package/dist/esm/shared/createGlobalContextShared.d.ts +39 -0
  180. package/dist/esm/shared/createGlobalContextShared.js +51 -0
  181. package/dist/esm/shared/createPageContextShared.d.ts +9 -0
  182. package/dist/esm/shared/createPageContextShared.js +15 -0
  183. package/dist/esm/shared/getPageFiles/fileTypes.js +1 -1
  184. package/dist/esm/shared/hooks/executeHookGeneric.d.ts +8 -0
  185. package/dist/esm/shared/hooks/executeHookGeneric.js +16 -0
  186. package/dist/esm/shared/hooks/getHook.d.ts +5 -3
  187. package/dist/esm/shared/hooks/getHook.js +47 -29
  188. package/dist/esm/shared/htmlElementIds.d.ts +2 -0
  189. package/dist/esm/shared/htmlElementIds.js +2 -0
  190. package/dist/esm/shared/page-configs/Config.d.ts +12 -2
  191. package/dist/esm/shared/page-configs/getConfigDefinedAt.d.ts +1 -1
  192. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +3 -7
  193. package/dist/esm/shared/route/executeGuardHook.js +2 -2
  194. package/dist/esm/shared/route/loadPageRoutes.js +2 -1
  195. package/dist/esm/shared/types.d.ts +64 -32
  196. package/dist/esm/types/index.d.ts +1 -5
  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/catchInfiniteLoop.js +4 -4
  200. package/dist/esm/utils/getGlobalObject.d.ts +1 -1
  201. package/dist/esm/utils/getPublicProxy.d.ts +2 -0
  202. package/dist/esm/utils/getPublicProxy.js +25 -0
  203. package/dist/esm/utils/isImportPath.d.ts +4 -0
  204. package/dist/esm/utils/isImportPath.js +19 -0
  205. package/dist/esm/utils/objectAssign.d.ts +1 -1
  206. package/dist/esm/utils/objectAssign.js +6 -10
  207. package/dist/esm/utils/objectReplace.d.ts +1 -1
  208. package/dist/esm/utils/objectReplace.js +4 -4
  209. package/dist/esm/utils/parseNpmPackage.d.ts +17 -0
  210. package/dist/esm/utils/{isNpmPackage.js → parseNpmPackage.js} +23 -23
  211. package/dist/esm/utils/path.d.ts +1 -1
  212. package/dist/esm/utils/path.js +12 -2
  213. package/dist/esm/utils/requireResolve.d.ts +20 -7
  214. package/dist/esm/utils/requireResolve.js +134 -53
  215. package/package.json +14 -13
  216. package/dist/cjs/node/runtime/index-common.js +0 -27
  217. package/dist/cjs/utils/makePublicCopy.js +0 -32
  218. package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +0 -19
  219. package/dist/esm/client/server-routing-runtime/getPageContext.js +0 -44
  220. package/dist/esm/client/shared/getPageContextSerializedInHtml.js +0 -20
  221. package/dist/esm/node/runtime/index-common.d.ts +0 -8
  222. package/dist/esm/node/runtime/index-common.js +0 -10
  223. package/dist/esm/utils/isNpmPackage.d.ts +0 -17
  224. package/dist/esm/utils/makePublicCopy.d.ts +0 -3
  225. package/dist/esm/utils/makePublicCopy.js +0 -30
@@ -3,9 +3,10 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getHook = getHook;
6
+ exports.getHookFromPageContext = getHookFromPageContext;
7
7
  exports.getHookFromPageConfig = getHookFromPageConfig;
8
8
  exports.getHookFromPageConfigGlobal = getHookFromPageConfigGlobal;
9
+ exports.getHookFromPageConfigGlobalCumulative = getHookFromPageConfigGlobalCumulative;
9
10
  exports.assertHook = assertHook;
10
11
  exports.getHook_setIsPrerenderering = getHook_setIsPrerenderering;
11
12
  exports.getHookTimeoutDefault = getHookTimeoutDefault;
@@ -15,59 +16,76 @@ const getConfigValueRuntime_js_1 = require("../page-configs/getConfigValueRuntim
15
16
  const utils_js_1 = require("../utils.js");
16
17
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
17
18
  const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('hooks/getHook.ts', {});
18
- function getHook(pageContext, hookName) {
19
+ function getHookFromPageContext(pageContext, hookName) {
19
20
  if (!(hookName in pageContext.exports)) {
20
21
  return null;
21
22
  }
22
23
  const { hooksTimeout } = pageContext.config;
23
24
  const hookTimeout = getHookTimeout(hooksTimeout, hookName);
24
25
  const hookFn = pageContext.exports[hookName];
25
- const file = pageContext.exportsAll[hookName][0];
26
- (0, utils_js_1.assert)(file.exportValue === hookFn);
27
26
  if (hookFn === null)
28
27
  return null;
28
+ const file = pageContext.exportsAll[hookName][0];
29
+ (0, utils_js_1.assert)(file.exportValue === hookFn);
29
30
  const hookFilePath = file.filePath;
30
31
  (0, utils_js_1.assert)(hookFilePath);
31
- (0, utils_js_1.assert)(!hookFilePath.endsWith(' '));
32
- assertHookFn(hookFn, { hookName, hookFilePath });
33
- return { hookFn, hookName, hookFilePath, hookTimeout };
32
+ return getHook(hookFn, hookName, hookFilePath, hookTimeout);
34
33
  }
35
34
  function getHookFromPageConfig(pageConfig, hookName) {
36
35
  const configValue = (0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, hookName);
37
- const hooksTimeout = (0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, 'hooksTimeout')?.value;
38
- if (!configValue)
36
+ if (!configValue?.value)
39
37
  return null;
40
- const hookFn = configValue.value;
41
- if (!hookFn)
42
- return null;
43
- const hookFilePath = (0, helpers_js_1.getHookFilePathToShowToUser)(configValue.definedAtData);
44
- // hook isn't a computed nor a cumulative config => hookFilePath should always be defined
45
- (0, utils_js_1.assert)(hookFilePath);
46
- assertHookFn(hookFn, { hookName, hookFilePath });
38
+ const { hookFn, hookFilePath } = getHookFromConfigValue(configValue);
39
+ const hooksTimeout = (0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, 'hooksTimeout')?.value;
47
40
  const hookTimeout = getHookTimeout(hooksTimeout, hookName);
48
- return { hookFn, hookName, hookFilePath, hookTimeout };
41
+ return getHook(hookFn, hookName, hookFilePath, hookTimeout);
49
42
  }
50
43
  function getHookFromPageConfigGlobal(pageConfigGlobal, hookName) {
51
44
  const configValue = pageConfigGlobal.configValues[hookName];
52
- if (!configValue)
53
- return null;
54
- const hookFn = configValue.value;
55
- if (!hookFn)
45
+ if (!configValue?.value)
56
46
  return null;
57
- const hookFilePath = (0, helpers_js_1.getHookFilePathToShowToUser)(configValue.definedAtData);
58
- // hook isn't a computed nor a cumulative config => hookFilePath should always be defined
47
+ const { hookFn, hookFilePath } = getHookFromConfigValue(configValue);
48
+ const hookTimeout = getHookTimeoutGlobal(hookName);
49
+ return getHook(hookFn, hookName, hookFilePath, hookTimeout);
50
+ }
51
+ function getHookFromPageConfigGlobalCumulative(pageConfigGlobal, hookName) {
52
+ const configValue = pageConfigGlobal.configValues[hookName];
53
+ if (!configValue?.value)
54
+ return [];
55
+ const val = configValue.value;
56
+ (0, utils_js_1.assert)((0, utils_js_1.isArray)(val));
57
+ return val.map((v, i) => {
58
+ const hookFn = v;
59
+ const hookTimeout = getHookTimeoutGlobal(hookName);
60
+ (0, utils_js_1.assert)((0, utils_js_1.isArray)(configValue.definedAtData));
61
+ const hookFilePath = (0, helpers_js_1.getHookFilePathToShowToUser)(configValue.definedAtData[i]);
62
+ return getHook(hookFn, hookName, hookFilePath, hookTimeout);
63
+ });
64
+ }
65
+ function getHookTimeoutGlobal(hookName) {
66
+ // TO-DO/perfection: we could use the global value of configooksTimeout but it requires some non-trivial refactoring
67
+ const hookTimeout = getHookTimeoutDefault(hookName);
68
+ return hookTimeout;
69
+ }
70
+ function getHook(hookFn, hookName, hookFilePath, hookTimeout) {
59
71
  (0, utils_js_1.assert)(hookFilePath);
60
72
  assertHookFn(hookFn, { hookName, hookFilePath });
61
- // We could use the global value of configooksTimeout but it requires some non-trivial refactoring
62
- const hookTimeout = getHookTimeoutDefault(hookName);
63
- return { hookFn, hookName, hookFilePath, hookTimeout };
73
+ const hook = { hookFn, hookName, hookFilePath, hookTimeout };
74
+ return hook;
75
+ }
76
+ function getHookFromConfigValue(configValue) {
77
+ const hookFn = configValue.value;
78
+ (0, utils_js_1.assert)(hookFn);
79
+ const hookFilePath = (0, helpers_js_1.getHookFilePathToShowToUser)(configValue.definedAtData);
80
+ return { hookFn, hookFilePath };
64
81
  }
65
82
  function assertHook(pageContext, hookName) {
66
- getHook(pageContext, hookName);
83
+ getHookFromPageContext(pageContext, hookName);
67
84
  }
68
85
  function assertHookFn(hookFn, { hookName, hookFilePath }) {
69
86
  (0, utils_js_1.assert)(hookName && hookFilePath);
70
87
  (0, utils_js_1.assert)(!hookName.endsWith(')'));
88
+ (0, utils_js_1.assert)(!hookFilePath.endsWith(' '));
71
89
  (0, utils_js_1.assertUsage)((0, utils_js_1.isCallable)(hookFn), `Hook ${hookName}() defined by ${hookFilePath} should be a function`);
72
90
  (0, utils_js_1.checkType)(hookFn);
73
91
  }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.htmlElementId_globalContext = exports.htmlElementId_pageContext = void 0;
4
+ exports.htmlElementId_pageContext = 'vike_pageContext';
5
+ exports.htmlElementId_globalContext = 'vike_globalContext';
@@ -8,7 +8,7 @@ exports.getConfigValuesBase = getConfigValuesBase;
8
8
  exports.isJsonValue = isJsonValue;
9
9
  const assertSetup_js_1 = require("../../../utils/assertSetup.js");
10
10
  const utils_js_1 = require("../../../node/plugin/utils.js");
11
- const transformPointerImports_js_1 = require("../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformPointerImports.js");
11
+ const pointerImports_js_1 = require("../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/pointerImports.js");
12
12
  const helpers_js_1 = require("../helpers.js");
13
13
  const stringify_1 = require("@brillout/json-serializer/stringify");
14
14
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
@@ -134,7 +134,7 @@ function valueToJson(value, configName, definedAtData, importStatements, filesEn
134
134
  // - https://github.com/vikejs/vike-react/pull/113
135
135
  replacer(_, value) {
136
136
  if (typeof value === 'string') {
137
- const importData = (0, transformPointerImports_js_1.parsePointerImportData)(value);
137
+ const importData = (0, pointerImports_js_1.parsePointerImportData)(value);
138
138
  if (importData) {
139
139
  const { importName } = addImportStatement(importStatements, importData.importPath, importData.exportName, filesEnv, configEnv, configName);
140
140
  const replacement = [REPLACE_ME_BEFORE, importName, REPLACE_ME_AFTER].join('');
@@ -269,10 +269,10 @@ function addImportStatement(importStatements, importPath, exportName, filesEnv,
269
269
  return { importName };
270
270
  }
271
271
  function assertFileEnv(importPath, configEnv, configName, filesEnv) {
272
+ (0, utils_js_1.assert)(!(0, utils_js_1.isImportPathRelative)(importPath));
272
273
  const key = importPath;
273
274
  (0, utils_js_1.assert)(key);
274
275
  (0, utils_js_1.assertPosixPath)(key);
275
- (0, utils_js_1.assert)(!isRelativeImportPath(key));
276
276
  if (!filesEnv.has(key)) {
277
277
  filesEnv.set(key, []);
278
278
  }
@@ -288,7 +288,3 @@ function assertFileEnv(importPath, configEnv, configName, filesEnv) {
288
288
  ].join('\n'));
289
289
  }
290
290
  }
291
- // TODO/now dedupe
292
- function isRelativeImportPath(importPath) {
293
- return importPath.startsWith('./') || importPath.startsWith('../');
294
- }
@@ -14,7 +14,7 @@ async function executeGuardHook(pageContext, prepareForUserConsumption) {
14
14
  }
15
15
  else {
16
16
  // V1 design
17
- hook = (0, getHook_js_1.getHook)(pageContext, 'guard');
17
+ hook = (0, getHook_js_1.getHookFromPageContext)(pageContext, 'guard');
18
18
  }
19
19
  if (!hook)
20
20
  return;
@@ -10,7 +10,7 @@ const getConfigDefinedAt_js_1 = require("../page-configs/getConfigDefinedAt.js")
10
10
  const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
11
11
  const getHook_js_1 = require("../hooks/getHook.js");
12
12
  async function loadPageRoutes(
13
- // Remove all arguments and use GlobalContextInternal instead?
13
+ // Remove all arguments and use GlobalContextServerInternal instead?
14
14
  pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
15
15
  // TODO/next-major: remove & make this function sync
16
16
  await Promise.all(pageFilesAll.filter((p) => p.fileType === '.page.route').map((p) => p.loadFile?.()));
@@ -47,6 +47,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
47
47
  }
48
48
  else {
49
49
  (0, utils_js_1.assert)((0, utils_js_2.isCallable)(route));
50
+ // TODO/next-major: remove
50
51
  if ((0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, 'iKnowThePerformanceRisksOfAsyncRouteFunctions', 'boolean'))
51
52
  (0, resolveRouteFunction_js_1.warnDeprecatedAllowKey)();
52
53
  pageRoute = {
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.228';
5
+ exports.PROJECT_VERSION = '0.4.229';
@@ -14,14 +14,14 @@ function catchInfiniteLoop(functionName, maxNumberOfCalls = 100, withinSeconds =
14
14
  // Count
15
15
  tracker.count++;
16
16
  // Error
17
- const msg = `[Infinite Loop] ${functionName} called ${tracker.count} times within ${withinSeconds} seconds`;
17
+ const msg = `[Infinite Loop] Rendering ${tracker.count} times within ${withinSeconds} seconds [${functionName}]`;
18
18
  if (tracker.count > maxNumberOfCalls) {
19
- (0, assert_js_1.assert)(false, msg);
19
+ (0, assert_js_1.assertUsage)(false, msg);
20
20
  }
21
21
  // Warning, at 50% threshold
22
22
  if (!tracker.warned && tracker.count > maxNumberOfCalls * 0.5) {
23
23
  // Warning is shown upon 10 calls a second, on average during 5 seconds, given the default parameters
24
- (0, assert_js_1.assertWarning)(false, msg, { onlyOnce: false });
24
+ (0, assert_js_1.assertWarning)(false, msg, { onlyOnce: false, showStackTrace: true });
25
25
  tracker.warned = true;
26
26
  }
27
27
  }
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPublicProxy = getPublicProxy;
4
+ // We use a proxy instead of property getters.
5
+ // - 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.
6
+ // ```console
7
+ // TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #<Object>
8
+ // ```
9
+ // - Previous implementation using property getters: https://github.com/vikejs/vike/blob/main/vike/utils/makePublicCopy.ts
10
+ const assert_js_1 = require("./assert.js");
11
+ // Show warning when user is accessing internal `_` properties.
12
+ function getPublicProxy(obj, objName, propsPublic, expectCustomUserLandProps) {
13
+ if (!expectCustomUserLandProps) {
14
+ Object.keys(obj).forEach((key) => (0, assert_js_1.assert)(key.startsWith('_') || propsPublic.includes(key)));
15
+ propsPublic.forEach((prop) => prop in obj);
16
+ }
17
+ return new Proxy(obj, {
18
+ get(_, prop) {
19
+ const propStr = String(prop);
20
+ if (propStr.startsWith('_')) {
21
+ (0, assert_js_1.assertWarning)(false, `Using internal ${objName}.${propStr} which may break in any minor version update. Reach out on GitHub and elaborate your use case so that the Vike team can add official support for your use case.`, { onlyOnce: true });
22
+ }
23
+ // @ts-ignore Seems to be TypeScript bug
24
+ return Reflect.get(...arguments);
25
+ }
26
+ });
27
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isImportPath = isImportPath;
4
+ exports.isImportPathRelative = isImportPathRelative;
5
+ const path_js_1 = require("./path.js");
6
+ const assert_js_1 = require("./assert.js");
7
+ const parseNpmPackage_js_1 = require("./parseNpmPackage.js");
8
+ function isImportPath(importPath) {
9
+ return isImportPathRelative(importPath) || (0, parseNpmPackage_js_1.isImportPathNpmPackageOrPathAlias)(importPath);
10
+ }
11
+ // See also `import { pathIsRelative } from './path'`
12
+ function isImportPathRelative(importPath) {
13
+ (0, path_js_1.assertPosixPath)(importPath);
14
+ if (importPath.startsWith('./') || importPath.startsWith('../')) {
15
+ return true;
16
+ }
17
+ else {
18
+ (0, assert_js_1.assert)(!importPath.startsWith('.'));
19
+ return false;
20
+ }
21
+ }
@@ -4,15 +4,11 @@ exports.objectAssign = objectAssign;
4
4
  const assert_js_1 = require("./assert.js");
5
5
  // Same as Object.assign() but:
6
6
  // - With type inference
7
- // - Preserves property descriptors, which we need for preserving the getters added by getPageContextUrlComputed()
7
+ // - Preserves property descriptors, which we need for preserving the getters of getPageContextUrlComputed()
8
8
  function objectAssign(obj, objAddendum, objAddendumCanBePageContextObject) {
9
- if (objAddendum) {
10
- if (!objAddendumCanBePageContextObject) {
11
- // We only need this assert() in the rare case when the user is expected to mutate `pageContext` after the Vike hook was executed (and its promise resolved).
12
- // - The only use case I can think of is the user mutating `pageContext` after the onRenderClient() promise resolved (which can happen when client-side rendering finishes after onRenderClient() resolves). In that case, having Vike await async Vike hooks isn't enough.
13
- // - IIRC this assert() was mostly needed for preserving the getters added by getPageContextUrlComputed() but we don't need this anymore.
14
- (0, assert_js_1.assert)(!('_isPageContextObject' in objAddendum));
15
- }
16
- Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
17
- }
9
+ if (!objAddendum)
10
+ return;
11
+ if (!objAddendumCanBePageContextObject)
12
+ (0, assert_js_1.assert)(!('isPageContext' in objAddendum));
13
+ Object.defineProperties(obj, Object.getOwnPropertyDescriptors(objAddendum));
18
14
  }
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.objectReplace = objectReplace;
4
- function objectReplace(obj, objNew, except) {
5
- Object.keys(obj)
4
+ function objectReplace(objOld, objNew, except) {
5
+ Object.keys(objOld)
6
6
  .filter((key) => !except?.includes(key))
7
- .forEach((key) => delete obj[key]);
8
- Object.assign(obj, objNew);
7
+ .forEach((key) => delete objOld[key]);
8
+ Object.defineProperties(objOld, Object.getOwnPropertyDescriptors(objNew));
9
9
  }
@@ -1,46 +1,46 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isNpmPackageImport = isNpmPackageImport;
4
- exports.isNpmPackageImport_unreliable = isNpmPackageImport_unreliable;
5
- exports.assertIsNpmPackageImport = assertIsNpmPackageImport;
6
- exports.isValidPathAlias = isValidPathAlias;
7
- exports.parse = parse;
3
+ exports.isImportPathNpmPackage = isImportPathNpmPackage;
4
+ exports.isImportPathNpmPackageOrPathAlias = isImportPathNpmPackageOrPathAlias;
5
+ exports.assertIsImportPathNpmPackage = assertIsImportPathNpmPackage;
6
+ exports.isPathAliasRecommended = isPathAliasRecommended;
7
+ exports.parseNpmPackage = parseNpmPackage;
8
8
  exports.isDistinguishable = isDistinguishable;
9
9
  const assert_js_1 = require("./assert.js");
10
10
  const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
11
11
  (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
12
- function isNpmPackageImport(str, { cannotBePathAlias }) {
12
+ function isImportPathNpmPackage(str, { cannotBePathAlias }) {
13
13
  (0, assert_js_1.assert)(cannotBePathAlias);
14
- return isNpmPackageImport_unreliable(str);
14
+ return isImportPathNpmPackageOrPathAlias(str);
15
15
  }
16
16
  // We cannot distinguish path aliases that look like npm package imports
17
- function isNpmPackageImport_unreliable(str) {
18
- const res = parse(str);
17
+ function isImportPathNpmPackageOrPathAlias(str) {
18
+ const res = parseNpmPackage(str);
19
19
  return res !== null;
20
20
  }
21
- function assertIsNpmPackageImport(str) {
22
- (0, assert_js_1.assert)(isNpmPackageImport(str, {
23
- // If `str` is a path alias that looks like an npm package => assertIsNpmPackageImport() is erroneous but that's okay because the assertion will eventually fail for some other user using a disambiguated path alias.
21
+ function assertIsImportPathNpmPackage(str) {
22
+ (0, assert_js_1.assert)(isImportPathNpmPackage(str, {
23
+ // If `str` is a path alias that looks like an npm package => assertIsImportPathNpmPackage() is erroneous but that's okay because the assertion will eventually fail for some other user using a disambiguated path alias.
24
24
  cannotBePathAlias: true
25
25
  }), str);
26
26
  }
27
27
  function isNpmPackageName(str) {
28
- const res = parse(str);
28
+ const res = parseNpmPackage(str);
29
29
  return res !== null && res.importPath === null;
30
30
  }
31
31
  function getNpmPackageName(str) {
32
- const res = parse(str);
32
+ const res = parseNpmPackage(str);
33
33
  if (!res)
34
34
  return null;
35
35
  return res.pkgName;
36
36
  }
37
37
  function getNpmPackageImportPath(str) {
38
- const res = parse(str);
38
+ const res = parseNpmPackage(str);
39
39
  if (!res)
40
40
  return null;
41
41
  return res.importPath;
42
42
  }
43
- function isValidPathAlias(alias) {
43
+ function isPathAliasRecommended(alias) {
44
44
  // Cannot be distinguished from npm package names
45
45
  if (!isDistinguishable(alias))
46
46
  return false;
@@ -56,14 +56,14 @@ function isValidPathAlias(alias) {
56
56
  return true;
57
57
  }
58
58
  function isDistinguishable(alias) {
59
- return (parse(alias) === null &&
60
- parse(`${alias}fake-path`) === null &&
61
- parse(`${alias}/fake-path`) === null &&
62
- parse(`${alias}fake/deep/path`) === null &&
63
- parse(`${alias}/fake/deep/path`) === null &&
59
+ return (parseNpmPackage(alias) === null &&
60
+ parseNpmPackage(`${alias}fake-path`) === null &&
61
+ parseNpmPackage(`${alias}/fake-path`) === null &&
62
+ parseNpmPackage(`${alias}fake/deep/path`) === null &&
63
+ parseNpmPackage(`${alias}/fake/deep/path`) === null &&
64
64
  // See note about '-' in ./isNpmPackageName.spec.ts
65
65
  // ```ts
66
- // expect(parse('-')).toBe(null) // actually wrong: https://www.npmjs.com/package/-
66
+ // expect(parseNpmPackage('-')).toBe(null) // actually wrong: https://www.npmjs.com/package/-
67
67
  // ```
68
68
  !alias.startsWith('-'));
69
69
  }
@@ -71,7 +71,7 @@ function isDistinguishable(alias) {
71
71
  // - https://www.npmjs.com/package/-
72
72
  // The correct logic is complex, see https://github.com/npm/validate-npm-package-name
73
73
  // We don't need to be accurate: are there npm packages with weird names that are actually being used?
74
- function parse(str) {
74
+ function parseNpmPackage(str) {
75
75
  if (!str)
76
76
  return null;
77
77
  let scope = null;
@@ -44,6 +44,16 @@ function assertPosixPath(path) {
44
44
  (0, assert_js_1.assert)(path);
45
45
  (0, assert_js_1.assert)(!path.includes('\\'), errMsg(path));
46
46
  }
47
- function pathIsRelative(importPath) {
48
- return importPath.startsWith('./') || importPath.startsWith('../');
47
+ // See also `import { isImportPathRelative } from './isImportPath.js'`
48
+ function pathIsRelative(path) {
49
+ assertPosixPath(path);
50
+ if (path.startsWith('./') || path.startsWith('../')) {
51
+ return true;
52
+ }
53
+ else {
54
+ /* Not true if `path` starts with a hidden directory (i.e. a directory with a name that starts with `.`)
55
+ assert(!path.startsWith('.'))
56
+ */
57
+ return false;
58
+ }
49
59
  }