vike 0.4.239 → 0.4.240-commit-bac5dee

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 (479) hide show
  1. package/dist/esm/client/index.d.ts +1 -1
  2. package/dist/esm/client/index.js +1 -1
  3. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +1 -1
  4. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.js +1 -1
  5. package/dist/esm/client/runtime-client-routing/entry.js +5 -3
  6. package/dist/esm/client/runtime-client-routing/getBaseServer.js +0 -1
  7. package/dist/esm/client/runtime-client-routing/{globalContext.d.ts → getGlobalContextClientInternal.d.ts} +2 -2
  8. package/dist/esm/client/runtime-client-routing/{globalContext.js → getGlobalContextClientInternal.js} +8 -4
  9. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +6 -6
  10. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +1 -1
  11. package/dist/esm/client/runtime-client-routing/isClientSideRoutable.d.ts +1 -1
  12. package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +4 -4
  13. package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +15 -4
  14. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +1 -1
  15. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +1 -1
  16. package/dist/esm/client/runtime-server-routing/entry.js +5 -3
  17. package/dist/esm/client/runtime-server-routing/{globalContext.d.ts → getGlobalContextClientInternal.d.ts} +2 -2
  18. package/dist/esm/client/runtime-server-routing/getGlobalContextClientInternal.js +6 -0
  19. package/dist/esm/client/shared/execHookOnRenderClient.d.ts +1 -1
  20. package/dist/esm/client/shared/{createGetGlobalContextClient.d.ts → getGlobalContextClientInternalShared.d.ts} +11 -8
  21. package/dist/esm/client/shared/getGlobalContextClientInternalShared.js +66 -0
  22. package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +1 -3
  23. package/dist/esm/node/prerender/runPrerender.d.ts +4 -2
  24. package/dist/esm/node/prerender/runPrerender.js +5 -2
  25. package/dist/esm/node/runtime/globalContext.d.ts +15 -2
  26. package/dist/esm/node/runtime/globalContext.js +46 -32
  27. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +4 -2
  28. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +4 -2
  29. package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.d.ts +8 -4
  30. package/dist/esm/node/runtime/renderPage.d.ts +4 -2
  31. package/dist/esm/node/vite/index.js +42 -18
  32. package/dist/esm/node/vite/onLoad.js +1 -1
  33. package/dist/esm/node/vite/plugins/{pluginBuild → build}/handleAssetsManifest.d.ts +4 -0
  34. package/dist/esm/node/vite/plugins/{pluginBuild → build}/handleAssetsManifest.js +21 -6
  35. package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginBuildApp.js +24 -20
  36. package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginBuildConfig.js +20 -6
  37. package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginDistFileNames.d.ts +1 -1
  38. package/dist/esm/node/vite/plugins/build/pluginDistFileNames.js +253 -0
  39. package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginDistPackageJsonFile.d.ts +1 -1
  40. package/dist/esm/node/vite/plugins/build/pluginDistPackageJsonFile.js +40 -0
  41. package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginModuleBanner.d.ts +1 -1
  42. package/dist/esm/node/vite/plugins/build/pluginModuleBanner.js +49 -0
  43. package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginProdBuildEntry.js +4 -2
  44. package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginSuppressRollupWarning.d.ts +1 -1
  45. package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginSuppressRollupWarning.js +27 -23
  46. package/dist/esm/node/vite/plugins/non-runnable-dev/pluginReplaceConstantsNonRunnableDev.d.ts +7 -0
  47. package/dist/esm/node/vite/plugins/non-runnable-dev/pluginReplaceConstantsNonRunnableDev.js +47 -0
  48. package/dist/esm/node/vite/plugins/{pluginNonRunnableDev.d.ts → non-runnable-dev/pluginViteRPC.d.ts} +3 -7
  49. package/dist/esm/node/vite/plugins/non-runnable-dev/pluginViteRPC.js +30 -0
  50. package/dist/esm/node/vite/plugins/pluginBaseUrls.d.ts +1 -1
  51. package/dist/esm/node/vite/plugins/pluginBaseUrls.js +39 -33
  52. package/dist/esm/node/vite/plugins/pluginCommon.js +8 -28
  53. package/dist/esm/node/vite/plugins/pluginDev/determineFsAllowList.js +0 -1
  54. package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +1 -1
  55. package/dist/esm/node/vite/plugins/pluginDev.js +51 -47
  56. package/dist/esm/node/vite/plugins/pluginExtractAssets.js +108 -92
  57. package/dist/esm/node/vite/plugins/pluginExtractExportNames.d.ts +1 -1
  58. package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +39 -23
  59. package/dist/esm/node/vite/plugins/pluginFileEnv.d.ts +1 -1
  60. package/dist/esm/node/vite/plugins/pluginFileEnv.js +117 -92
  61. package/dist/esm/node/vite/plugins/pluginPreview.d.ts +1 -1
  62. package/dist/esm/node/vite/plugins/pluginPreview.js +38 -30
  63. package/dist/esm/node/vite/plugins/pluginReplaceConstantsEnvVars.d.ts +3 -0
  64. package/dist/esm/node/vite/plugins/pluginReplaceConstantsEnvVars.js +127 -0
  65. package/dist/esm/node/vite/plugins/pluginReplaceConstantsGlobalThis.d.ts +17 -0
  66. package/dist/esm/node/vite/plugins/pluginReplaceConstantsGlobalThis.js +52 -0
  67. package/dist/esm/node/vite/plugins/pluginReplaceConstantsPageContext.d.ts +3 -0
  68. package/dist/esm/node/vite/plugins/pluginReplaceConstantsPageContext.js +89 -0
  69. package/dist/esm/node/vite/plugins/pluginSetGlobalContext.js +4 -2
  70. package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.js +1 -1
  71. package/dist/esm/node/vite/plugins/pluginVirtualFiles.d.ts +1 -1
  72. package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +67 -47
  73. package/dist/esm/node/vite/plugins/pluginWorkaroundCssModuleHmr.d.ts +1 -1
  74. package/dist/esm/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +13 -9
  75. package/dist/esm/node/vite/plugins/pluginWorkaroundVite6HmrRegression.d.ts +1 -1
  76. package/dist/esm/node/vite/plugins/pluginWorkaroundVite6HmrRegression.js +26 -24
  77. package/dist/esm/node/vite/shared/getMagicString.d.ts +1 -1
  78. package/dist/esm/node/vite/shared/getMagicString.js +2 -0
  79. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +2 -2
  80. package/dist/esm/shared/createGlobalContextShared.d.ts +4 -4
  81. package/dist/esm/shared/route/abort.d.ts +22 -11
  82. package/dist/esm/shared/route/abort.js +45 -5
  83. package/dist/esm/shared/route/index.js +13 -4
  84. package/dist/esm/shared/route/utils.d.ts +1 -0
  85. package/dist/esm/shared/route/utils.js +1 -0
  86. package/dist/esm/types/Config.d.ts +1 -1
  87. package/dist/esm/types/PageContext.d.ts +8 -8
  88. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  89. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  90. package/dist/esm/utils/assert.js +1 -0
  91. package/dist/esm/utils/debug.d.ts +5 -3
  92. package/dist/esm/utils/debug.js +28 -11
  93. package/dist/esm/utils/findPackageJson.js +0 -1
  94. package/dist/esm/utils/getGlobalObject.d.ts +5 -1
  95. package/dist/esm/utils/getGlobalObject.js +5 -1
  96. package/dist/esm/utils/getViteRPC.js +0 -2
  97. package/dist/esm/utils/isDev.js +3 -1
  98. package/dist/esm/utils/isNonRunnableDev.js +2 -2
  99. package/dist/esm/utils/requireResolve.js +1 -2
  100. package/dist/esm/utils/virtualFileId.d.ts +4 -0
  101. package/dist/esm/utils/virtualFileId.js +14 -11
  102. package/package.json +7 -26
  103. package/dist/cjs/__internal/index.js +0 -35
  104. package/dist/cjs/client/runtime-client-routing/globalContext.js +0 -49
  105. package/dist/cjs/client/runtime-client-routing/prefetch/PrefetchSetting.js +0 -2
  106. package/dist/cjs/client/runtime-server-routing/globalContext.js +0 -41
  107. package/dist/cjs/client/runtime-server-routing/onLoad.js +0 -7
  108. package/dist/cjs/client/runtime-server-routing/utils.js +0 -34
  109. package/dist/cjs/client/shared/createGetGlobalContextClient.js +0 -65
  110. package/dist/cjs/client/shared/getJsonSerializedInHtml.js +0 -40
  111. package/dist/cjs/client/shared/preparePageContextForPublicUsageClientShared.js +0 -41
  112. package/dist/cjs/client/shared/utils.js +0 -23
  113. package/dist/cjs/node/api/build.js +0 -24
  114. package/dist/cjs/node/api/context.js +0 -23
  115. package/dist/cjs/node/api/dev.js +0 -18
  116. package/dist/cjs/node/api/index.js +0 -44
  117. package/dist/cjs/node/api/onLoad.js +0 -9
  118. package/dist/cjs/node/api/prepareViteApiCall.js +0 -206
  119. package/dist/cjs/node/api/prerender.js +0 -18
  120. package/dist/cjs/node/api/preview.js +0 -38
  121. package/dist/cjs/node/api/types.js +0 -2
  122. package/dist/cjs/node/api/utils.js +0 -27
  123. package/dist/cjs/node/cli/context.js +0 -17
  124. package/dist/cjs/node/cli/entry.js +0 -121
  125. package/dist/cjs/node/cli/index.js +0 -12
  126. package/dist/cjs/node/cli/onLoad.js +0 -9
  127. package/dist/cjs/node/cli/parseCli.js +0 -95
  128. package/dist/cjs/node/cli/utils.js +0 -24
  129. package/dist/cjs/node/client/router.js +0 -19
  130. package/dist/cjs/node/createPageRenderer.js +0 -132
  131. package/dist/cjs/node/importBuild.js +0 -3
  132. package/dist/cjs/node/prerender/context.js +0 -26
  133. package/dist/cjs/node/prerender/index.js +0 -12
  134. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +0 -66
  135. package/dist/cjs/node/prerender/runPrerender.js +0 -777
  136. package/dist/cjs/node/prerender/runPrerenderEntry.js +0 -55
  137. package/dist/cjs/node/prerender/utils.js +0 -37
  138. package/dist/cjs/node/runtime/globalContext.js +0 -572
  139. package/dist/cjs/node/runtime/index-deprecated.js +0 -33
  140. package/dist/cjs/node/runtime/index.js +0 -74
  141. package/dist/cjs/node/runtime/loggerRuntime.js +0 -17
  142. package/dist/cjs/node/runtime/onLoad.js +0 -29
  143. package/dist/cjs/node/runtime/page-files/setup.js +0 -5
  144. package/dist/cjs/node/runtime/renderPage/analyzePage.js +0 -71
  145. package/dist/cjs/node/runtime/renderPage/assertArguments.js +0 -42
  146. package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +0 -51
  147. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +0 -114
  148. package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +0 -59
  149. package/dist/cjs/node/runtime/renderPage/csp.js +0 -47
  150. package/dist/cjs/node/runtime/renderPage/execHookDataAndOnBeforeRender.js +0 -31
  151. package/dist/cjs/node/runtime/renderPage/execHookOnRenderHtml.js +0 -120
  152. package/dist/cjs/node/runtime/renderPage/execHookServer.js +0 -8
  153. package/dist/cjs/node/runtime/renderPage/getCacheControl.js +0 -24
  154. package/dist/cjs/node/runtime/renderPage/getEarlyHints.js +0 -20
  155. package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +0 -137
  156. package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +0 -125
  157. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrievePageAssetsDev.js +0 -86
  158. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrievePageAssetsProd.js +0 -77
  159. package/dist/cjs/node/runtime/renderPage/getPageAssets/sortPageAssetsForEarlyHintsHeader.js +0 -36
  160. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +0 -50
  161. package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +0 -41
  162. package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +0 -68
  163. package/dist/cjs/node/runtime/renderPage/headersResponse.js +0 -48
  164. package/dist/cjs/node/runtime/renderPage/html/injectAssets/getHtmlTags.js +0 -269
  165. package/dist/cjs/node/runtime/renderPage/html/injectAssets/getViteDevScript.js +0 -32
  166. package/dist/cjs/node/runtime/renderPage/html/injectAssets/inferHtmlTags.js +0 -55
  167. package/dist/cjs/node/runtime/renderPage/html/injectAssets/injectAssets__public.js +0 -31
  168. package/dist/cjs/node/runtime/renderPage/html/injectAssets/injectHtmlTags.js +0 -161
  169. package/dist/cjs/node/runtime/renderPage/html/injectAssets/mergeScriptTags.js +0 -73
  170. package/dist/cjs/node/runtime/renderPage/html/injectAssets/sanitizeJson.js +0 -8
  171. package/dist/cjs/node/runtime/renderPage/html/injectAssets.js +0 -93
  172. package/dist/cjs/node/runtime/renderPage/html/propKeys.js +0 -47
  173. package/dist/cjs/node/runtime/renderPage/html/renderHtml.js +0 -245
  174. package/dist/cjs/node/runtime/renderPage/html/serializeContext.js +0 -189
  175. package/dist/cjs/node/runtime/renderPage/html/stream/react-streaming.js +0 -36
  176. package/dist/cjs/node/runtime/renderPage/html/stream.js +0 -829
  177. package/dist/cjs/node/runtime/renderPage/inferMediaType.js +0 -81
  178. package/dist/cjs/node/runtime/renderPage/isFontFallback.js +0 -29
  179. package/dist/cjs/node/runtime/renderPage/isNewError.js +0 -25
  180. package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +0 -124
  181. package/dist/cjs/node/runtime/renderPage/log404/index.js +0 -154
  182. package/dist/cjs/node/runtime/renderPage/logErrorHint/errors.js +0 -20
  183. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +0 -200
  184. package/dist/cjs/node/runtime/renderPage/loggerProd.js +0 -34
  185. package/dist/cjs/node/runtime/renderPage/preparePageContextForPublicUsageServer.js +0 -10
  186. package/dist/cjs/node/runtime/renderPage/renderPageAfterRoute.js +0 -83
  187. package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +0 -71
  188. package/dist/cjs/node/runtime/renderPage.js +0 -502
  189. package/dist/cjs/node/runtime/universal-middleware.js +0 -20
  190. package/dist/cjs/node/runtime/utils.js +0 -83
  191. package/dist/cjs/node/runtime-dev/createDevMiddleware.js +0 -27
  192. package/dist/cjs/node/runtime-dev/index.js +0 -42
  193. package/dist/cjs/node/shared/assertV1Design.js +0 -30
  194. package/dist/cjs/node/shared/extractAssetsQuery.js +0 -29
  195. package/dist/cjs/node/shared/getVikeConfigError.js +0 -22
  196. package/dist/cjs/node/shared/isErrorDebug.js +0 -7
  197. package/dist/cjs/node/shared/prependEntriesDir.js +0 -13
  198. package/dist/cjs/node/shared/resolveBase.js +0 -35
  199. package/dist/cjs/node/shared/utils.js +0 -35
  200. package/dist/cjs/node/shared/virtualFileId.js +0 -110
  201. package/dist/cjs/node/vite/index.js +0 -69
  202. package/dist/cjs/node/vite/onLoad.js +0 -21
  203. package/dist/cjs/node/vite/plugins/pluginBaseUrls.js +0 -48
  204. package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +0 -342
  205. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +0 -179
  206. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +0 -220
  207. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +0 -254
  208. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +0 -36
  209. package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +0 -41
  210. package/dist/cjs/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +0 -109
  211. package/dist/cjs/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +0 -63
  212. package/dist/cjs/node/vite/plugins/pluginBuild.js +0 -21
  213. package/dist/cjs/node/vite/plugins/pluginCommon/assertResolveAlias.js +0 -88
  214. package/dist/cjs/node/vite/plugins/pluginCommon.js +0 -197
  215. package/dist/cjs/node/vite/plugins/pluginDev/determineFsAllowList.js +0 -28
  216. package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +0 -163
  217. package/dist/cjs/node/vite/plugins/pluginDev.js +0 -107
  218. package/dist/cjs/node/vite/plugins/pluginEnvVars.js +0 -87
  219. package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +0 -227
  220. package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +0 -99
  221. package/dist/cjs/node/vite/plugins/pluginFileEnv.js +0 -149
  222. package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +0 -52
  223. package/dist/cjs/node/vite/plugins/pluginPreview.js +0 -76
  224. package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +0 -69
  225. package/dist/cjs/node/vite/plugins/pluginSetGlobalContext.js +0 -49
  226. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/debug.js +0 -5
  227. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.js +0 -56
  228. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +0 -190
  229. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.js +0 -54
  230. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +0 -97
  231. package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +0 -215
  232. package/dist/cjs/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +0 -15
  233. package/dist/cjs/node/vite/plugins/pluginWorkaroundVite6HmrRegression.js +0 -35
  234. package/dist/cjs/node/vite/shared/addSsrMiddleware.js +0 -60
  235. package/dist/cjs/node/vite/shared/findPageFiles.js +0 -25
  236. package/dist/cjs/node/vite/shared/getAssetsDir.js +0 -10
  237. package/dist/cjs/node/vite/shared/getClientEntrySrcDev.js +0 -42
  238. package/dist/cjs/node/vite/shared/getEnvVarObject.js +0 -37
  239. package/dist/cjs/node/vite/shared/getFilePath.js +0 -172
  240. package/dist/cjs/node/vite/shared/getHttpRequestAsyncStore.js +0 -125
  241. package/dist/cjs/node/vite/shared/getMagicString.js +0 -18
  242. package/dist/cjs/node/vite/shared/getManifestFilePathRelative.js +0 -10
  243. package/dist/cjs/node/vite/shared/getOutDirs.js +0 -146
  244. package/dist/cjs/node/vite/shared/getViteConfigRuntime.js +0 -21
  245. package/dist/cjs/node/vite/shared/isAsset.js +0 -40
  246. package/dist/cjs/node/vite/shared/isViteCliCall.js +0 -83
  247. package/dist/cjs/node/vite/shared/isViteServerSide.js +0 -68
  248. package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errBabelReact.js +0 -15
  249. package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errBabelSolid.js +0 -15
  250. package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errEsbuild.js +0 -38
  251. package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errMdx1.js +0 -26
  252. package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errMdx2.js +0 -85
  253. package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errPostcss.js +0 -30
  254. package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwc.js +0 -19
  255. package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errSwcBig.js +0 -19
  256. package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueCss.js +0 -29
  257. package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueHtml.js +0 -13
  258. package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet/fixture-errors/errVueJavascript.js +0 -15
  259. package/dist/cjs/node/vite/shared/loggerNotProd/errorWithCodeSnippet.js +0 -162
  260. package/dist/cjs/node/vite/shared/loggerNotProd/log.js +0 -102
  261. package/dist/cjs/node/vite/shared/loggerNotProd.js +0 -208
  262. package/dist/cjs/node/vite/shared/loggerVite/removeSuperfluousViteLog.js +0 -26
  263. package/dist/cjs/node/vite/shared/loggerVite.js +0 -54
  264. package/dist/cjs/node/vite/shared/normalizeId.js +0 -9
  265. package/dist/cjs/node/vite/shared/parseEsModule.js +0 -33
  266. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/assertExtensions.js +0 -136
  267. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +0 -262
  268. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles/ignorePatternsBuiltIn.js +0 -18
  269. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +0 -252
  270. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/filesystemRouting.js +0 -190
  271. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/getConfigFileExport.js +0 -17
  272. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/getPlusFilesAll.js +0 -127
  273. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/loadFileAtConfigTime.js +0 -129
  274. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/pointerImports.js +0 -195
  275. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/resolvePointerImport.js +0 -102
  276. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/transpileAndExecuteFile.js +0 -425
  277. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +0 -1151
  278. package/dist/cjs/node/vite/shared/rollupIsEsm.js +0 -15
  279. package/dist/cjs/node/vite/utils.js +0 -45
  280. package/dist/cjs/package.json +0 -1
  281. package/dist/cjs/shared/NOT_SERIALIZABLE.js +0 -4
  282. package/dist/cjs/shared/RenderErrorPage.js +0 -6
  283. package/dist/cjs/shared/abort.js +0 -16
  284. package/dist/cjs/shared/addIs404ToPageProps.js +0 -18
  285. package/dist/cjs/shared/assertHookReturnedObject.js +0 -21
  286. package/dist/cjs/shared/assertOnBeforeRenderHookReturn.js +0 -21
  287. package/dist/cjs/shared/assertPageContextProvidedByUser.js +0 -20
  288. package/dist/cjs/shared/createGlobalContextShared.js +0 -109
  289. package/dist/cjs/shared/createPageContextShared.js +0 -17
  290. package/dist/cjs/shared/determinePageIdOld.js +0 -11
  291. package/dist/cjs/shared/error-page.js +0 -40
  292. package/dist/cjs/shared/getPageContext.js +0 -6
  293. package/dist/cjs/shared/getPageContextRequestUrl.js +0 -16
  294. package/dist/cjs/shared/getPageContextUrlComputed.js +0 -132
  295. package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +0 -19
  296. package/dist/cjs/shared/getPageFiles/analyzePageClientSide/ClientDependency.js +0 -2
  297. package/dist/cjs/shared/getPageFiles/analyzePageClientSide/analyzeExports.js +0 -50
  298. package/dist/cjs/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +0 -30
  299. package/dist/cjs/shared/getPageFiles/analyzePageClientSide/getExportNames.js +0 -15
  300. package/dist/cjs/shared/getPageFiles/analyzePageClientSide.js +0 -59
  301. package/dist/cjs/shared/getPageFiles/analyzePageServerSide.js +0 -22
  302. package/dist/cjs/shared/getPageFiles/assert_exports_old_design.js +0 -24
  303. package/dist/cjs/shared/getPageFiles/fileTypes.js +0 -52
  304. package/dist/cjs/shared/getPageFiles/getAllPageIdFiles.js +0 -102
  305. package/dist/cjs/shared/getPageFiles/getPageFileObject.js +0 -56
  306. package/dist/cjs/shared/getPageFiles/parseVirtualFileExportsGlobalEntry.js +0 -100
  307. package/dist/cjs/shared/getPageFiles.js +0 -7
  308. package/dist/cjs/shared/getProxyForPublicUsage.js +0 -56
  309. package/dist/cjs/shared/hooks/execHook.js +0 -147
  310. package/dist/cjs/shared/hooks/getHook.js +0 -173
  311. package/dist/cjs/shared/htmlElementIds.js +0 -5
  312. package/dist/cjs/shared/misc/isServerSideError.js +0 -4
  313. package/dist/cjs/shared/misc/pageContextInitIsPassedToClient.js +0 -4
  314. package/dist/cjs/shared/modifyUrl.js +0 -28
  315. package/dist/cjs/shared/modifyUrlSameOrigin.js +0 -47
  316. package/dist/cjs/shared/page-configs/assertPlusFileExport.js +0 -42
  317. package/dist/cjs/shared/page-configs/findPageConfig.js +0 -10
  318. package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +0 -65
  319. package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +0 -68
  320. package/dist/cjs/shared/page-configs/getConfigValueRuntime.js +0 -10
  321. package/dist/cjs/shared/page-configs/getConfigValueTyped.js +0 -32
  322. package/dist/cjs/shared/page-configs/getExportPath.js +0 -29
  323. package/dist/cjs/shared/page-configs/helpers.js +0 -27
  324. package/dist/cjs/shared/page-configs/loadAndParseVirtualFilePageEntry.js +0 -25
  325. package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +0 -287
  326. package/dist/cjs/shared/page-configs/serialize/PageConfigSerialized.js +0 -2
  327. package/dist/cjs/shared/page-configs/serialize/assertPageConfigsSerialized.js +0 -1
  328. package/dist/cjs/shared/page-configs/serialize/parsePageConfigsSerialized.js +0 -145
  329. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +0 -290
  330. package/dist/cjs/shared/prepareGlobalContextForPublicUsage.js +0 -10
  331. package/dist/cjs/shared/preparePageContextForPublicUsage.js +0 -80
  332. package/dist/cjs/shared/route/abort.js +0 -178
  333. package/dist/cjs/shared/route/debug.js +0 -23
  334. package/dist/cjs/shared/route/deduceRouteStringFromFilesystemPath.js +0 -52
  335. package/dist/cjs/shared/route/execHookGuard.js +0 -37
  336. package/dist/cjs/shared/route/execHookOnBeforeRoute.js +0 -84
  337. package/dist/cjs/shared/route/index.js +0 -107
  338. package/dist/cjs/shared/route/loadPageRoutes.js +0 -197
  339. package/dist/cjs/shared/route/noRouteMatch.js +0 -4
  340. package/dist/cjs/shared/route/resolvePrecedence.js +0 -93
  341. package/dist/cjs/shared/route/resolveRoute.js +0 -20
  342. package/dist/cjs/shared/route/resolveRouteFunction.js +0 -73
  343. package/dist/cjs/shared/route/resolveRouteString.js +0 -153
  344. package/dist/cjs/shared/route/resolveUrlPathname.js +0 -47
  345. package/dist/cjs/shared/route/routing.js +0 -9
  346. package/dist/cjs/shared/route/utils.js +0 -40
  347. package/dist/cjs/shared/utils.js +0 -49
  348. package/dist/cjs/types/Config/ConfigResolved.js +0 -2
  349. package/dist/cjs/types/Config.js +0 -2
  350. package/dist/cjs/types/FilePath.js +0 -2
  351. package/dist/cjs/types/PageConfig.js +0 -2
  352. package/dist/cjs/types/PageContext.js +0 -2
  353. package/dist/cjs/types/VikeGlobalInternal.js +0 -2
  354. package/dist/cjs/types/VikeNamespace.js +0 -2
  355. package/dist/cjs/types/ViteManifest.js +0 -2
  356. package/dist/cjs/types/defineConfig.js +0 -6
  357. package/dist/cjs/types/index-dreprecated.js +0 -3
  358. package/dist/cjs/types/index.js +0 -5
  359. package/dist/cjs/utils/PROJECT_VERSION.js +0 -5
  360. package/dist/cjs/utils/PromiseType.js +0 -2
  361. package/dist/cjs/utils/assert.js +0 -211
  362. package/dist/cjs/utils/assertIsBrowser.js +0 -8
  363. package/dist/cjs/utils/assertIsNotBrowser.js +0 -9
  364. package/dist/cjs/utils/assertKeys.js +0 -27
  365. package/dist/cjs/utils/assertNodeVersion.js +0 -14
  366. package/dist/cjs/utils/assertRoutingType.js +0 -29
  367. package/dist/cjs/utils/assertSetup.js +0 -171
  368. package/dist/cjs/utils/assertSingleInstance.js +0 -110
  369. package/dist/cjs/utils/assertVersion.js +0 -60
  370. package/dist/cjs/utils/capitalizeFirstLetter.js +0 -9
  371. package/dist/cjs/utils/cast.js +0 -6
  372. package/dist/cjs/utils/catchInfiniteLoop.js +0 -34
  373. package/dist/cjs/utils/changeEnumerable.js +0 -8
  374. package/dist/cjs/utils/checkType.js +0 -6
  375. package/dist/cjs/utils/compareString.js +0 -10
  376. package/dist/cjs/utils/createErrorWithCleanStackTrace.js +0 -39
  377. package/dist/cjs/utils/debug.js +0 -178
  378. package/dist/cjs/utils/debugGlob.js +0 -6
  379. package/dist/cjs/utils/deepEqual.js +0 -10
  380. package/dist/cjs/utils/escapeHtml.js +0 -13
  381. package/dist/cjs/utils/escapeRegex.js +0 -7
  382. package/dist/cjs/utils/findFile.js +0 -30
  383. package/dist/cjs/utils/findPackageJson.js +0 -18
  384. package/dist/cjs/utils/formatHintLog.js +0 -17
  385. package/dist/cjs/utils/freezePartial.js +0 -35
  386. package/dist/cjs/utils/genPromise.js +0 -51
  387. package/dist/cjs/utils/getFileExtension.js +0 -16
  388. package/dist/cjs/utils/getGlobalObject.js +0 -15
  389. package/dist/cjs/utils/getMostSimilar.js +0 -68
  390. package/dist/cjs/utils/getPropAccessNotation.js +0 -9
  391. package/dist/cjs/utils/getRandomId.js +0 -14
  392. package/dist/cjs/utils/getTerminalWidth.js +0 -7
  393. package/dist/cjs/utils/getValuePrintable.js +0 -10
  394. package/dist/cjs/utils/getViteRPC.js +0 -79
  395. package/dist/cjs/utils/hasProp.js +0 -50
  396. package/dist/cjs/utils/humanizeTime.js +0 -24
  397. package/dist/cjs/utils/includes.js +0 -13
  398. package/dist/cjs/utils/injectRollupInputs.js +0 -29
  399. package/dist/cjs/utils/isArray.js +0 -7
  400. package/dist/cjs/utils/isArrayOfStrings.js +0 -7
  401. package/dist/cjs/utils/isBrowser.js +0 -8
  402. package/dist/cjs/utils/isCallable.js +0 -6
  403. package/dist/cjs/utils/isDev.js +0 -20
  404. package/dist/cjs/utils/isDocker.js +0 -45
  405. package/dist/cjs/utils/isEqualStringList.js +0 -13
  406. package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +0 -66
  407. package/dist/cjs/utils/isHtml.js +0 -9
  408. package/dist/cjs/utils/isImportPath.js +0 -21
  409. package/dist/cjs/utils/isNodeJS.js +0 -16
  410. package/dist/cjs/utils/isNonRunnableDev.js +0 -12
  411. package/dist/cjs/utils/isNullish.js +0 -16
  412. package/dist/cjs/utils/isObject.js +0 -6
  413. package/dist/cjs/utils/isObjectOfStrings.js +0 -7
  414. package/dist/cjs/utils/isObjectWithKeys.js +0 -15
  415. package/dist/cjs/utils/isPlainObject.js +0 -19
  416. package/dist/cjs/utils/isPromise.js +0 -7
  417. package/dist/cjs/utils/isPropertyGetter.js +0 -7
  418. package/dist/cjs/utils/isReact.js +0 -23
  419. package/dist/cjs/utils/isRunnableDevEnvironment.js +0 -9
  420. package/dist/cjs/utils/isSameErrorMessage.js +0 -9
  421. package/dist/cjs/utils/isScriptFile.js +0 -67
  422. package/dist/cjs/utils/isVikeReactApp.js +0 -8
  423. package/dist/cjs/utils/isVitest.js +0 -6
  424. package/dist/cjs/utils/joinEnglish.js +0 -14
  425. package/dist/cjs/utils/normalizeHeaders.js +0 -17
  426. package/dist/cjs/utils/objectAssign.js +0 -14
  427. package/dist/cjs/utils/objectAssignSafe.js +0 -7
  428. package/dist/cjs/utils/objectDefineProperty.js +0 -7
  429. package/dist/cjs/utils/objectEntries.js +0 -8
  430. package/dist/cjs/utils/objectEntriesForEach.js +0 -7
  431. package/dist/cjs/utils/objectFilter.js +0 -10
  432. package/dist/cjs/utils/objectFromEntries.js +0 -7
  433. package/dist/cjs/utils/objectKeys.js +0 -9
  434. package/dist/cjs/utils/objectReplace.js +0 -9
  435. package/dist/cjs/utils/onPageVisibilityChange.js +0 -18
  436. package/dist/cjs/utils/pLimit.js +0 -134
  437. package/dist/cjs/utils/parseNpmPackage.js +0 -106
  438. package/dist/cjs/utils/parseUrl-extras.js +0 -110
  439. package/dist/cjs/utils/parseUrl.js +0 -338
  440. package/dist/cjs/utils/path.js +0 -59
  441. package/dist/cjs/utils/pick.js +0 -12
  442. package/dist/cjs/utils/preservePropertyGetters.js +0 -30
  443. package/dist/cjs/utils/redirectHard.js +0 -6
  444. package/dist/cjs/utils/removeEmptyLines.js +0 -9
  445. package/dist/cjs/utils/removeFileExtension.js +0 -6
  446. package/dist/cjs/utils/requireResolve.js +0 -214
  447. package/dist/cjs/utils/rollupSourceMap.js +0 -19
  448. package/dist/cjs/utils/sleep.js +0 -6
  449. package/dist/cjs/utils/slice.js +0 -35
  450. package/dist/cjs/utils/sorter.js +0 -117
  451. package/dist/cjs/utils/stringifyStringArray.js +0 -6
  452. package/dist/cjs/utils/stripAnsi.js +0 -21
  453. package/dist/cjs/utils/styleFileRE.js +0 -6
  454. package/dist/cjs/utils/throttle.js +0 -15
  455. package/dist/cjs/utils/trackLogs.js +0 -31
  456. package/dist/cjs/utils/trimWithAnsi.js +0 -40
  457. package/dist/cjs/utils/truncateString.js +0 -23
  458. package/dist/cjs/utils/unique.js +0 -6
  459. package/dist/cjs/utils/updateType.js +0 -9
  460. package/dist/cjs/utils/urlToFile.js +0 -36
  461. package/dist/cjs/utils/virtualFileId.js +0 -39
  462. package/dist/cjs/utils/warnIfErrorIsNotObject.js +0 -23
  463. package/dist/esm/client/runtime-server-routing/globalContext.js +0 -5
  464. package/dist/esm/client/shared/createGetGlobalContextClient.js +0 -65
  465. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +0 -249
  466. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +0 -34
  467. package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +0 -39
  468. package/dist/esm/node/vite/plugins/pluginBuild.d.ts +0 -3
  469. package/dist/esm/node/vite/plugins/pluginBuild.js +0 -19
  470. package/dist/esm/node/vite/plugins/pluginEnvVars.d.ts +0 -3
  471. package/dist/esm/node/vite/plugins/pluginEnvVars.js +0 -85
  472. package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +0 -50
  473. package/dist/esm/node/vite/plugins/pluginReplaceConstants.d.ts +0 -3
  474. package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +0 -67
  475. package/dist/esm/shared/route/debug.d.ts +0 -6
  476. package/dist/esm/shared/route/debug.js +0 -21
  477. /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginBuildApp.d.ts +0 -0
  478. /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginBuildConfig.d.ts +0 -0
  479. /package/dist/esm/node/vite/plugins/{pluginBuild → build}/pluginProdBuildEntry.d.ts +0 -0
@@ -1,84 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.execHookOnBeforeRoute = execHookOnBeforeRoute;
7
- const assertPageContextProvidedByUser_js_1 = require("../assertPageContextProvidedByUser.js");
8
- const utils_js_1 = require("./utils.js");
9
- const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
10
- const picocolors_1 = __importDefault(require("@brillout/picocolors"));
11
- const execHook_js_1 = require("../hooks/execHook.js");
12
- const preparePageContextForPublicUsage_js_1 = require("../preparePageContextForPublicUsage.js");
13
- async function execHookOnBeforeRoute(pageContext) {
14
- const pageContextFromOnBeforeRouteHook = {};
15
- if (!pageContext._globalContext._onBeforeRouteHook)
16
- return null;
17
- const pageContextFromHook = await getPageContextFromHook(pageContext._globalContext._onBeforeRouteHook, pageContext);
18
- if (pageContextFromHook) {
19
- (0, utils_js_1.objectAssign)(pageContextFromOnBeforeRouteHook, pageContextFromHook);
20
- if ((0, utils_js_1.hasProp)(pageContextFromOnBeforeRouteHook, 'pageId', 'string') ||
21
- (0, utils_js_1.hasProp)(pageContextFromOnBeforeRouteHook, 'pageId', 'null')) {
22
- // We bypass Vike's routing
23
- if (!(0, utils_js_1.hasProp)(pageContextFromOnBeforeRouteHook, 'routeParams')) {
24
- (0, utils_js_1.objectAssign)(pageContextFromOnBeforeRouteHook, { routeParams: {} });
25
- }
26
- else {
27
- (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageContextFromOnBeforeRouteHook, 'routeParams', 'object'));
28
- }
29
- (0, utils_js_1.objectAssign)(pageContextFromOnBeforeRouteHook, {
30
- _routingProvidedByOnBeforeRouteHook: true,
31
- });
32
- return pageContextFromOnBeforeRouteHook;
33
- }
34
- }
35
- (0, utils_js_1.objectAssign)(pageContextFromOnBeforeRouteHook, {
36
- _routingProvidedByOnBeforeRouteHook: false,
37
- });
38
- return pageContextFromOnBeforeRouteHook;
39
- }
40
- async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
41
- let { hookReturn } = (0, execHook_js_1.execHookDirectSync)(onBeforeRouteHook, pageContext, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage);
42
- (0, resolveRouteFunction_js_1.assertSyncRouting)(hookReturn, `The onBeforeRoute() hook ${onBeforeRouteHook.hookFilePath}`);
43
- // TO-DO/next-major-release: make execHookOnBeforeRoute() and route() sync
44
- hookReturn = await hookReturn;
45
- const errPrefix = `The onBeforeRoute() hook defined by ${onBeforeRouteHook.hookFilePath}`;
46
- (0, utils_js_1.assertUsage)(hookReturn === null ||
47
- hookReturn === undefined ||
48
- ((0, utils_js_1.isObjectWithKeys)(hookReturn, ['pageContext']) && (0, utils_js_1.hasProp)(hookReturn, 'pageContext')), `${errPrefix} should return ${picocolors_1.default.cyan('null')}, ${picocolors_1.default.cyan('undefined')}, or a plain JavaScript object ${picocolors_1.default.cyan('{ pageContext: { /* ... */ } }')}`);
49
- if (hookReturn === null || hookReturn === undefined) {
50
- return null;
51
- }
52
- (0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(hookReturn, 'pageContext', 'object'), `${errPrefix} returned ${picocolors_1.default.cyan('{ pageContext }')} but pageContext should be a plain JavaScript object.`);
53
- if ((0, utils_js_1.hasProp)(hookReturn.pageContext, 'pageId') && !(0, utils_js_1.hasProp)(hookReturn.pageContext, 'pageId', 'null')) {
54
- const errPrefix2 = `${errPrefix} returned ${picocolors_1.default.cyan('{ pageContext: { pageId } }')} but ${picocolors_1.default.cyan('pageId')} should be`;
55
- (0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(hookReturn.pageContext, 'pageId', 'string'), `${errPrefix2} a string or null`);
56
- (0, utils_js_1.assertUsage)(pageContext._globalContext._allPageIds.includes(hookReturn.pageContext.pageId), `${errPrefix2} ${(0, utils_js_1.joinEnglish)(pageContext._globalContext._allPageIds.map((s) => picocolors_1.default.cyan(s)), 'or')}`);
57
- }
58
- if ((0, utils_js_1.hasProp)(hookReturn.pageContext, 'routeParams')) {
59
- (0, resolveRouteFunction_js_1.assertRouteParams)(hookReturn.pageContext, `${errPrefix} returned ${picocolors_1.default.cyan('{ pageContext: { routeParams } }')} but routeParams should`);
60
- }
61
- const deprecatedReturn = (prop) => `${errPrefix} returned ${picocolors_1.default.cyan(`{ pageContext: { ${prop} } }`)} which is deprecated. Return ${picocolors_1.default.cyan('{ pageContext: { urlLogical } }')} instead.`;
62
- if ((0, utils_js_1.hasProp)(hookReturn.pageContext, 'url')) {
63
- (0, utils_js_1.assertWarning)(false, deprecatedReturn('url'), { onlyOnce: true });
64
- hookReturn.pageContext.urlLogical = hookReturn.pageContext.url;
65
- delete hookReturn.pageContext.url;
66
- }
67
- if ((0, utils_js_1.hasProp)(hookReturn.pageContext, 'urlOriginal')) {
68
- (0, utils_js_1.assertWarning)(false, deprecatedReturn('urlOriginal'), { onlyOnce: true });
69
- hookReturn.pageContext.urlLogical = hookReturn.pageContext.urlOriginal;
70
- delete hookReturn.pageContext.urlOriginal;
71
- }
72
- if ((0, utils_js_1.hasProp)(hookReturn.pageContext, 'urlLogical')) {
73
- (0, utils_js_1.assertUsageUrlPathnameAbsolute)(
74
- // We skip validation and type-cast instead of assertUsage() in order to save client-side KBs
75
- hookReturn.pageContext.urlLogical, `${errPrefix} returned ${picocolors_1.default.cyan('{ pageContext: { urlLogical } }')} and ${picocolors_1.default.cyan('urlLogical')}`);
76
- }
77
- (0, assertPageContextProvidedByUser_js_1.assertPageContextProvidedByUser)(hookReturn.pageContext, {
78
- hookFilePath: onBeforeRouteHook.hookFilePath,
79
- hookName: 'onBeforeRoute',
80
- });
81
- const pageContextAddendumHook = {};
82
- (0, utils_js_1.objectAssign)(pageContextAddendumHook, hookReturn.pageContext);
83
- return pageContextAddendumHook;
84
- }
@@ -1,107 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.route = route;
7
- // Ensure we don't bloat runtime of Server Routing
8
- const assertRoutingType_js_1 = require("../../utils/assertRoutingType.js");
9
- const isBrowser_js_1 = require("../../utils/isBrowser.js");
10
- if ((0, isBrowser_js_1.isBrowser)()) {
11
- (0, assertRoutingType_js_1.assertClientRouting)();
12
- }
13
- const utils_js_1 = require("./utils.js");
14
- const resolvePrecedence_js_1 = require("./resolvePrecedence.js");
15
- const resolveRouteString_js_1 = require("./resolveRouteString.js");
16
- const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
17
- const execHookOnBeforeRoute_js_1 = require("./execHookOnBeforeRoute.js");
18
- const debug_js_1 = require("./debug.js");
19
- const picocolors_1 = __importDefault(require("@brillout/picocolors"));
20
- // TO-DO/next-major-release: make it sync
21
- async function route(pageContext, skipOnBeforeRouteHook) {
22
- (0, debug_js_1.debug)('Pages routes:', pageContext._globalContext._pageRoutes);
23
- const pageContextFromRoute = {};
24
- // onBeforeRoute()
25
- if (!skipOnBeforeRouteHook) {
26
- const pageContextFromOnBeforeRouteHook = await (0, execHookOnBeforeRoute_js_1.execHookOnBeforeRoute)(pageContext);
27
- if (pageContextFromOnBeforeRouteHook) {
28
- if (pageContextFromOnBeforeRouteHook._routingProvidedByOnBeforeRouteHook) {
29
- (0, utils_js_1.assert)(pageContextFromOnBeforeRouteHook.pageId);
30
- return pageContextFromOnBeforeRouteHook;
31
- }
32
- else {
33
- (0, utils_js_1.objectAssign)(pageContextFromRoute, pageContextFromOnBeforeRouteHook);
34
- }
35
- }
36
- // We take into account pageContext.urlLogical set by onBeforeRoute()
37
- (0, utils_js_1.objectAssign)(pageContext, pageContextFromOnBeforeRouteHook);
38
- }
39
- // Vike's routing
40
- const allPageIds = pageContext._globalContext._allPageIds;
41
- (0, utils_js_1.assertUsage)(allPageIds.length > 0, 'No page found. You must create at least one page.');
42
- (0, utils_js_1.assert)(pageContext._globalContext._pageFilesAll.length > 0 || pageContext._globalContext._pageConfigs.length > 0);
43
- const { urlPathname } = pageContext;
44
- (0, utils_js_1.assert)(urlPathname.startsWith('/'));
45
- const routeMatches = [];
46
- await Promise.all(pageContext._globalContext._pageRoutes.map(async (pageRoute) => {
47
- const { pageId, routeType } = pageRoute;
48
- // Filesystem Routing
49
- if (pageRoute.routeType === 'FILESYSTEM') {
50
- const { routeString } = pageRoute;
51
- const match = (0, resolveRouteString_js_1.resolveRouteString)(routeString, urlPathname);
52
- if (match) {
53
- const { routeParams } = match;
54
- routeMatches.push({ pageId, routeParams, routeString, routeType });
55
- }
56
- return;
57
- }
58
- // Route String defined in `.page.route.js`
59
- if (pageRoute.routeType === 'STRING') {
60
- const { routeString } = pageRoute;
61
- const match = (0, resolveRouteString_js_1.resolveRouteString)(routeString, urlPathname);
62
- if (match) {
63
- const { routeParams } = match;
64
- (0, utils_js_1.assert)(routeType === 'STRING');
65
- routeMatches.push({
66
- pageId,
67
- routeString,
68
- routeParams,
69
- routeType,
70
- });
71
- }
72
- return;
73
- }
74
- // Route Function defined in `.page.route.js`
75
- if (pageRoute.routeType === 'FUNCTION') {
76
- const { routeFunction, routeFunctionFilePath } = pageRoute;
77
- const match = await (0, resolveRouteFunction_js_1.resolveRouteFunction)(routeFunction, pageContext, routeFunctionFilePath);
78
- if (match) {
79
- const { routeParams, precedence } = match;
80
- routeMatches.push({ pageId, precedence, routeParams, routeType });
81
- }
82
- return;
83
- }
84
- (0, utils_js_1.assert)(false);
85
- }));
86
- (0, resolvePrecedence_js_1.resolvePrecedence)(routeMatches);
87
- const winner = routeMatches[0] ?? null;
88
- (0, debug_js_1.debug)(`Route matches for URL ${picocolors_1.default.cyan(urlPathname)} (in precedence order):`, routeMatches);
89
- // For vite-plugin-vercel https://github.com/magne4000/vite-plugin-vercel/blob/main/packages/vike-integration/vike.ts#L173
90
- (0, utils_js_1.objectAssign)(pageContextFromRoute, { _routeMatch: winner });
91
- if (!winner) {
92
- (0, utils_js_1.objectAssign)(pageContextFromRoute, {
93
- pageId: null,
94
- routeParams: {},
95
- });
96
- return pageContextFromRoute;
97
- }
98
- {
99
- const { routeParams } = winner;
100
- (0, utils_js_1.assert)((0, utils_js_1.isPlainObject)(routeParams));
101
- (0, utils_js_1.objectAssign)(pageContextFromRoute, {
102
- pageId: winner.pageId,
103
- routeParams: winner.routeParams,
104
- });
105
- }
106
- return pageContextFromRoute;
107
- }
@@ -1,197 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.loadPageRoutes = loadPageRoutes;
4
- exports.loadPageRoutesSync = loadPageRoutesSync;
5
- const error_page_js_1 = require("../error-page.js");
6
- const utils_js_1 = require("./utils.js");
7
- const deduceRouteStringFromFilesystemPath_js_1 = require("./deduceRouteStringFromFilesystemPath.js");
8
- const utils_js_2 = require("../utils.js");
9
- const getConfigValueRuntime_js_1 = require("../page-configs/getConfigValueRuntime.js");
10
- const getConfigDefinedAt_js_1 = require("../page-configs/getConfigDefinedAt.js");
11
- const resolveRouteFunction_js_1 = require("./resolveRouteFunction.js");
12
- const getHook_js_1 = require("../hooks/getHook.js");
13
- async function loadPageRoutes(
14
- // Remove all arguments and use GlobalContextServerInternal instead?
15
- pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
16
- // TO-DO/next-major-release: remove this line, remove this function, rename loadPageRoutesSync() to loadPageRoutes()
17
- await Promise.all(pageFilesAll.filter((p) => p.fileType === '.page.route').map((p) => p.loadFile?.()));
18
- return loadPageRoutesSync(pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds);
19
- }
20
- function loadPageRoutesSync(
21
- // Remove all arguments and use GlobalContextServerInternal instead?
22
- pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
23
- const { onBeforeRouteHook, filesystemRoots } = getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal);
24
- const pageRoutes = getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds);
25
- return { pageRoutes, onBeforeRouteHook };
26
- }
27
- function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
28
- const pageRoutes = [];
29
- // V1 Design
30
- if (pageConfigs.length > 0) {
31
- (0, utils_js_1.assert)(filesystemRoots === null);
32
- const comesFromV1PageConfig = true;
33
- pageConfigs
34
- .filter((p) => !p.isErrorPage)
35
- .forEach((pageConfig) => {
36
- const pageId = pageConfig.pageId;
37
- let pageRoute = null;
38
- {
39
- const configName = 'route';
40
- const configValue = (0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, configName);
41
- if (configValue) {
42
- const route = configValue.value;
43
- (0, utils_js_1.assert)(configValue.definedAtData);
44
- const definedAtString = (0, getConfigDefinedAt_js_1.getDefinedAtString)(configValue.definedAtData, configName);
45
- if (typeof route === 'string') {
46
- pageRoute = {
47
- pageId,
48
- comesFromV1PageConfig,
49
- routeString: route,
50
- routeDefinedAtString: definedAtString,
51
- routeType: 'STRING',
52
- };
53
- }
54
- else {
55
- const { definedAtData } = configValue;
56
- (0, utils_js_1.assert)(!(0, utils_js_2.isArray)(definedAtData) && !definedAtData.definedBy);
57
- const { filePathToShowToUser } = definedAtData;
58
- (0, utils_js_1.assert)(filePathToShowToUser);
59
- (0, utils_js_1.assert)((0, utils_js_2.isCallable)(route));
60
- // TO-DO/next-major-release: remove
61
- if ((0, getConfigValueRuntime_js_1.getConfigValueRuntime)(pageConfig, 'iKnowThePerformanceRisksOfAsyncRouteFunctions', 'boolean'))
62
- (0, resolveRouteFunction_js_1.warnDeprecatedAllowKey)();
63
- pageRoute = {
64
- pageId,
65
- comesFromV1PageConfig,
66
- routeFunction: route,
67
- routeFunctionFilePath: filePathToShowToUser,
68
- routeDefinedAtString: definedAtString,
69
- routeType: 'FUNCTION',
70
- };
71
- }
72
- }
73
- }
74
- if (!pageRoute) {
75
- const { routeFilesystem } = pageConfig;
76
- (0, utils_js_1.assert)(routeFilesystem);
77
- const { routeString, definedAtLocation } = routeFilesystem;
78
- (0, utils_js_1.assert)(routeFilesystem.routeString.startsWith('/'));
79
- pageRoute = {
80
- pageId,
81
- routeFilesystemDefinedBy: definedAtLocation,
82
- comesFromV1PageConfig,
83
- routeString,
84
- routeDefinedAtString: null,
85
- routeType: 'FILESYSTEM',
86
- };
87
- }
88
- (0, utils_js_1.assert)(pageRoute);
89
- pageRoutes.push(pageRoute);
90
- });
91
- }
92
- // Old design
93
- // TO-DO/next-major-release: remove
94
- if (pageConfigs.length === 0) {
95
- (0, utils_js_1.assert)(filesystemRoots);
96
- const comesFromV1PageConfig = false;
97
- allPageIds
98
- .filter((pageId) => !(0, error_page_js_1.isErrorPageId)(pageId, false))
99
- .forEach((pageId) => {
100
- const pageRouteFile = pageFilesAll.find((p) => p.pageId === pageId && p.fileType === '.page.route');
101
- if (!pageRouteFile || !('default' in pageRouteFile.fileExports)) {
102
- const routeString = (0, deduceRouteStringFromFilesystemPath_js_1.deduceRouteStringFromFilesystemPath)(pageId, filesystemRoots);
103
- (0, utils_js_1.assert)(routeString.startsWith('/'));
104
- (0, utils_js_1.assert)(!routeString.endsWith('/') || routeString === '/');
105
- pageRoutes.push({
106
- pageId,
107
- comesFromV1PageConfig,
108
- routeString,
109
- routeDefinedAtString: null,
110
- routeFilesystemDefinedBy: `${pageId}.page.*`,
111
- routeType: 'FILESYSTEM',
112
- });
113
- }
114
- else {
115
- const { filePath, fileExports } = pageRouteFile;
116
- (0, utils_js_1.assert)(fileExports.default);
117
- if ((0, utils_js_1.hasProp)(fileExports, 'default', 'string')) {
118
- const routeString = fileExports.default;
119
- (0, utils_js_1.assertUsage)(routeString.startsWith('/'), `A Route String should start with a leading slash '/' but ${filePath} has \`export default '${routeString}'\`. Make sure to \`export default '/${routeString}'\` instead.`);
120
- pageRoutes.push({
121
- pageId,
122
- comesFromV1PageConfig,
123
- routeString,
124
- routeDefinedAtString: filePath,
125
- routeType: 'STRING',
126
- });
127
- return;
128
- }
129
- if ((0, utils_js_1.hasProp)(fileExports, 'default', 'function')) {
130
- const routeFunction = fileExports.default;
131
- {
132
- const allowKey = 'iKnowThePerformanceRisksOfAsyncRouteFunctions';
133
- if (allowKey in fileExports) {
134
- (0, resolveRouteFunction_js_1.warnDeprecatedAllowKey)();
135
- }
136
- }
137
- pageRoutes.push({
138
- pageId,
139
- comesFromV1PageConfig,
140
- routeFunction,
141
- routeFunctionFilePath: filePath,
142
- routeDefinedAtString: filePath,
143
- routeType: 'FUNCTION',
144
- });
145
- return;
146
- }
147
- (0, utils_js_1.assertUsage)(false, `The default export of ${filePath} should be a string or a function.`);
148
- }
149
- });
150
- }
151
- return pageRoutes;
152
- }
153
- function getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal) {
154
- // V1 Design
155
- if (pageConfigs.length > 0) {
156
- const hook = (0, getHook_js_1.getHookFromPageConfigGlobal)(pageConfigGlobal, 'onBeforeRoute');
157
- return { onBeforeRouteHook: hook, filesystemRoots: null };
158
- }
159
- // Old design
160
- // TO-DO/next-major-release: remove
161
- let onBeforeRouteHook = null;
162
- const filesystemRoots = [];
163
- pageFilesAll
164
- .filter((p) => p.fileType === '.page.route' && p.isDefaultPageFile)
165
- .forEach(({ filePath, fileExports }) => {
166
- (0, utils_js_1.assert)(fileExports);
167
- if ('onBeforeRoute' in fileExports) {
168
- (0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(fileExports, 'onBeforeRoute', 'function'), `\`export { onBeforeRoute }\` of ${filePath} should be a function.`);
169
- const { onBeforeRoute } = fileExports;
170
- const hookName = 'onBeforeRoute';
171
- onBeforeRouteHook = {
172
- hookFilePath: filePath,
173
- hookFn: onBeforeRoute,
174
- hookName,
175
- hookTimeout: (0, getHook_js_1.getHookTimeoutDefault)(hookName),
176
- };
177
- }
178
- if ('filesystemRoutingRoot' in fileExports) {
179
- (0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(fileExports, 'filesystemRoutingRoot', 'string'), `\`export { filesystemRoutingRoot }\` of ${filePath} should be a string.`);
180
- (0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(fileExports, 'filesystemRoutingRoot', 'string'), `\`export { filesystemRoutingRoot }\` of ${filePath} is \`'${fileExports.filesystemRoutingRoot}'\` but it should start with a leading slash \`/\`.`);
181
- filesystemRoots.push({
182
- filesystemRoot: dirname(filePath),
183
- urlRoot: fileExports.filesystemRoutingRoot,
184
- });
185
- }
186
- });
187
- return { onBeforeRouteHook, filesystemRoots };
188
- }
189
- function dirname(filePath) {
190
- (0, utils_js_1.assert)(filePath.startsWith('/'));
191
- (0, utils_js_1.assert)(!filePath.endsWith('/'));
192
- const paths = filePath.split('/');
193
- const dirPath = (0, utils_js_1.slice)(paths, 0, -1).join('/') || '/';
194
- (0, utils_js_1.assert)(dirPath.startsWith('/'));
195
- (0, utils_js_1.assert)(!dirPath.endsWith('/') || dirPath === '/');
196
- return dirPath;
197
- }
@@ -1,4 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.noRouteMatch = void 0;
4
- exports.noRouteMatch = "doesn't match the route of any of your pages";
@@ -1,93 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.resolvePrecedence = resolvePrecedence;
4
- // export type { RouteMatch }
5
- const resolveRouteString_js_1 = require("./resolveRouteString.js");
6
- const utils_js_1 = require("./utils.js");
7
- const utils_js_2 = require("./utils.js");
8
- const resolveRouteString_js_2 = require("./resolveRouteString.js");
9
- // See https://vike.dev/route-function#precedence
10
- function resolvePrecedence(routeMatches) {
11
- // prettier-ignore
12
- // biome-ignore format:
13
- routeMatches
14
- .sort(sortMatches)
15
- .sort((0, utils_js_2.makeFirst)((routeMatch) => routeMatch.routeType === 'FUNCTION' && !!routeMatch.precedence && routeMatch.precedence < 0))
16
- .sort((0, utils_js_2.makeFirst)((routeMatch) => routeMatch.routeType === 'STRING' && (0, resolveRouteString_js_2.isStaticRouteString)(routeMatch.routeString) === false))
17
- .sort((0, utils_js_2.makeFirst)((routeMatch) => routeMatch.routeType === 'FUNCTION' && !routeMatch.precedence))
18
- .sort((0, utils_js_2.makeFirst)((routeMatch) => routeMatch.routeType === 'STRING' && (0, resolveRouteString_js_2.isStaticRouteString)(routeMatch.routeString) === true))
19
- .sort((0, utils_js_2.makeFirst)((routeMatch) => routeMatch.routeType === 'FILESYSTEM'))
20
- .sort((0, utils_js_2.makeFirst)((routeMatch) => routeMatch.routeType === 'FUNCTION' && !!routeMatch.precedence && routeMatch.precedence > 0));
21
- }
22
- // -1 => routeMatch1 higher precedence
23
- // +1 => routeMatch2 higher precedence
24
- function sortMatches(routeMatch1, routeMatch2) {
25
- {
26
- const precedence1 = routeMatch1.precedence ?? 0;
27
- const precedence2 = routeMatch2.precedence ?? 0;
28
- if (precedence1 !== precedence2) {
29
- return precedence1 > precedence2 ? -1 : 1;
30
- }
31
- }
32
- if (!routeMatch2.routeString) {
33
- return 0;
34
- }
35
- if (!routeMatch1.routeString) {
36
- return 0;
37
- }
38
- /* DEBUG
39
- console.log('routeMatch1.routeString', routeMatch1.routeString)
40
- console.log('routeMatch2.routeString', routeMatch2.routeString)
41
- console.log('parseRouteString(routeMatch1.routeString)', parseRouteString(routeMatch1.routeString))
42
- console.log('parseRouteString(routeMatch2.routeString)', parseRouteString(routeMatch2.routeString))
43
- //*/
44
- // Return route with highest number of static path segments at beginning first
45
- {
46
- const getValue = (routeString) => (0, resolveRouteString_js_1.analyzeRouteString)(routeString).numberOfStaticPartsBeginning;
47
- const result = (0, utils_js_1.higherFirst)(getValue)(routeMatch1.routeString, routeMatch2.routeString);
48
- if (result !== 0) {
49
- /* DEBUG
50
- console.log('analyzeRouteString(routeMatch1.routeString).numberOfStaticPartsBeginning', getValue(routeMatch1.routeString))
51
- console.log('analyzeRouteString(routeMatch2.routeString).numberOfStaticPartsBeginning', getValue(routeMatch2.routeString))
52
- //*/
53
- return result;
54
- }
55
- }
56
- // Return route with highest number of static path segments in total first
57
- {
58
- const getValue = (routeString) => (0, resolveRouteString_js_1.analyzeRouteString)(routeString).numberOfStaticParts;
59
- const result = (0, utils_js_1.higherFirst)(getValue)(routeMatch1.routeString, routeMatch2.routeString);
60
- if (result !== 0) {
61
- /* DEBUG
62
- console.log('analyzeRouteString(routeMatch1.routeString).numberOfStaticParts', getValue(routeMatch1.routeString))
63
- console.log('analyzeRouteString(routeMatch2.routeString).numberOfStaticParts', getValue(routeMatch2.routeString))
64
- //*/
65
- return result;
66
- }
67
- }
68
- // Return route with least amount of globs first
69
- {
70
- const getValue = (routeString) => (0, resolveRouteString_js_1.analyzeRouteString)(routeString).numberOfGlobs;
71
- const result = (0, utils_js_1.lowerFirst)(getValue)(routeMatch1.routeString, routeMatch2.routeString);
72
- if (result !== 0) {
73
- /* DEBUG
74
- console.log('analyzeRouteString(routeMatch1.routeString).numberOfGlobs', getValue(routeMatch1.routeString))
75
- console.log('analyzeRouteString(routeMatch2.routeString).numberOfGlobs', getValue(routeMatch2.routeString))
76
- //*/
77
- return result;
78
- }
79
- }
80
- // Return route with highest number of parameters first
81
- {
82
- const getValue = (routeString) => (0, resolveRouteString_js_1.analyzeRouteString)(routeString).numberOfParams;
83
- const result = (0, utils_js_1.higherFirst)(getValue)(routeMatch1.routeString, routeMatch2.routeString);
84
- if (result !== 0) {
85
- /* DEBUG
86
- console.log('analyzeRouteString(routeMatch1.routeString).numberOfParams', getValue(routeMatch1.routeString))
87
- console.log('analyzeRouteString(routeMatch2.routeString).numberOfParams', getValue(routeMatch2.routeString))
88
- //*/
89
- return result;
90
- }
91
- }
92
- return 0;
93
- }
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.resolveRoute = resolveRoute;
7
- const utils_js_1 = require("./utils.js");
8
- const resolveRouteString_js_1 = require("./resolveRouteString.js");
9
- const picocolors_1 = __importDefault(require("@brillout/picocolors"));
10
- function resolveRoute(routeString, urlPathname) {
11
- const errMsg = (propName, msg = 'a non-empty string') => `[resolveRoute(routeString, urlPathname)] ${picocolors_1.default.cyan(propName)} should be ` + msg;
12
- (0, utils_js_1.assertUsage)(routeString, errMsg('routeString'), { showStackTrace: true });
13
- (0, utils_js_1.assertUsage)(urlPathname, errMsg('urlPathname'), { showStackTrace: true });
14
- (0, utils_js_1.assertUsage)(urlPathname.startsWith('/'), errMsg('urlPathname', 'pageContext.urlPathname'), { showStackTrace: true });
15
- const result = (0, resolveRouteString_js_1.resolveRouteString)(routeString, urlPathname);
16
- return {
17
- match: !!result,
18
- routeParams: result?.routeParams ?? {},
19
- };
20
- }
@@ -1,73 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.resolveRouteFunction = resolveRouteFunction;
7
- exports.assertRouteParams = assertRouteParams;
8
- exports.assertSyncRouting = assertSyncRouting;
9
- exports.warnDeprecatedAllowKey = warnDeprecatedAllowKey;
10
- const execHook_js_1 = require("../hooks/execHook.js");
11
- const preparePageContextForPublicUsage_js_1 = require("../preparePageContextForPublicUsage.js");
12
- const utils_js_1 = require("./utils.js");
13
- const picocolors_1 = __importDefault(require("@brillout/picocolors"));
14
- async function resolveRouteFunction(routeFunction, pageContext, routeFunctionFilePath) {
15
- let { hookReturn: result } = (0, execHook_js_1.execHookDirectSync)({
16
- hookFn: routeFunction,
17
- hookFilePath: routeFunctionFilePath,
18
- hookName: 'route',
19
- }, pageContext, preparePageContextForPublicUsage_js_1.preparePageContextForPublicUsage);
20
- assertSyncRouting(result, `The Route Function ${routeFunctionFilePath}`);
21
- // TO-DO/next-major-release: make resolveRouteFunction() and route() sync
22
- //* 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
23
- result = await result;
24
- //*/
25
- if (result === false) {
26
- return null;
27
- }
28
- if (result === true) {
29
- result = {};
30
- }
31
- (0, utils_js_1.assertUsage)((0, utils_js_1.isPlainObject)(result), `The Route Function ${routeFunctionFilePath} should return a boolean or a plain JavaScript object (but it's ${picocolors_1.default.cyan(`typeof result === ${JSON.stringify(typeof result)}`)} instead)`);
32
- // AFAICT this return interface is superfluous. Should we soft-deprecate it and remove it?
33
- if ('match' in result) {
34
- const { match } = result;
35
- (0, utils_js_1.assertUsage)(typeof match === 'boolean', `The ${picocolors_1.default.cyan('match')} value returned by the Route Function ${routeFunctionFilePath} should be a boolean.`);
36
- if (!match) {
37
- return null;
38
- }
39
- }
40
- let precedence = null;
41
- if ('precedence' in result) {
42
- precedence = result.precedence;
43
- (0, utils_js_1.assertUsage)(typeof precedence === 'number', `The ${picocolors_1.default.cyan('precedence')} value returned by the Route Function ${routeFunctionFilePath} should be a number.`);
44
- }
45
- assertRouteParams(result, `The ${picocolors_1.default.cyan('routeParams')} object returned by the Route Function ${routeFunctionFilePath} should`);
46
- const routeParams = result.routeParams || {};
47
- (0, utils_js_1.assertUsage)(!('pageContext' in result), `Providing ${picocolors_1.default.cyan('pageContext')} in Route Functions is prohibited, see https://vike.dev/route-function#cannot-provide-pagecontext`);
48
- (0, utils_js_1.assert)((0, utils_js_1.isPlainObject)(routeParams));
49
- Object.keys(result).forEach((key) => {
50
- (0, utils_js_1.assertUsage)(key === 'match' || key === 'routeParams' || key === 'precedence', `The Route Function ${routeFunctionFilePath} returned an object with an unknown property ${picocolors_1.default.cyan(key)} (the known properties are ${picocolors_1.default.cyan('match')}, ${picocolors_1.default.cyan('routeParams')}, and ${picocolors_1.default.cyan('precedence')})`);
51
- });
52
- return {
53
- precedence,
54
- routeParams,
55
- };
56
- }
57
- // TO-DO/next-major-release: remove, and make routing synchronous (enabling Vike to synchronously check whether a link is a Vike link before even calling ev.preventDefault())
58
- function assertSyncRouting(res, errPrefix) {
59
- (0, utils_js_1.assertWarning)(!(0, utils_js_1.isPromise)(res), `${errPrefix} returned a promise, but asynchronous routing is deprecated and will be removed in the next major release, see https://vike.dev/route-function#async`, { onlyOnce: true });
60
- }
61
- // TO-DO/next-major-release: remove
62
- function warnDeprecatedAllowKey() {
63
- const allowKey = picocolors_1.default.cyan('iKnowThePerformanceRisksOfAsyncRouteFunctions');
64
- (0, utils_js_1.assertWarning)(false, `${allowKey} is deprecated and will be removed in the next major release`, { onlyOnce: true });
65
- }
66
- function assertRouteParams(result, errPrefix) {
67
- (0, utils_js_1.assert)(errPrefix.endsWith(' should'));
68
- if (!(0, utils_js_1.hasProp)(result, 'routeParams')) {
69
- return;
70
- }
71
- (0, utils_js_1.assert)(errPrefix.endsWith(' should'));
72
- (0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(result, 'routeParams', 'string{}'), `${errPrefix} be an object holding string values.`);
73
- }