vike 0.4.237 → 0.4.238-commit-5762291

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 (299) hide show
  1. package/dist/cjs/__internal/index.js +3 -3
  2. package/dist/cjs/client/runtime-client-routing/globalContext.js +2 -2
  3. package/dist/cjs/client/runtime-server-routing/globalContext.js +2 -2
  4. package/dist/cjs/client/runtime-server-routing/utils.js +1 -1
  5. package/dist/cjs/client/shared/createGetGlobalContextClient.js +5 -5
  6. package/dist/cjs/node/api/build.js +5 -31
  7. package/dist/cjs/node/api/context.js +13 -12
  8. package/dist/cjs/node/api/dev.js +0 -2
  9. package/dist/cjs/node/api/index.js +0 -2
  10. package/dist/cjs/node/api/onLoad.js +2 -2
  11. package/dist/cjs/node/api/prepareViteApiCall.js +2 -3
  12. package/dist/cjs/node/api/preview.js +2 -3
  13. package/dist/cjs/node/api/utils.js +1 -0
  14. package/dist/cjs/node/cli/index.js +2 -2
  15. package/dist/cjs/node/cli/onLoad.js +2 -2
  16. package/dist/cjs/node/prerender/runPrerender.js +7 -8
  17. package/dist/cjs/node/prerender/runPrerenderEntry.js +1 -1
  18. package/dist/cjs/node/runtime/csp.js +46 -0
  19. package/dist/cjs/node/runtime/globalContext.js +128 -112
  20. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +11 -8
  21. package/dist/cjs/node/runtime/html/injectAssets/inferHtmlTags.js +5 -2
  22. package/dist/cjs/node/runtime/html/injectAssets/mergeScriptTags.js +4 -2
  23. package/dist/cjs/node/runtime/renderPage/analyzePage.js +6 -4
  24. package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +1 -1
  25. package/dist/cjs/node/runtime/renderPage/execHookOnRenderHtml.js +1 -11
  26. package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +5 -4
  27. package/dist/cjs/node/runtime/renderPage/getPageAssets/{retrieveAssetsDev.js → retrievePageAssetsDev.js} +21 -6
  28. package/dist/cjs/node/runtime/renderPage/getPageAssets/{retrieveAssetsProd.js → retrievePageAssetsProd.js} +19 -2
  29. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +5 -34
  30. package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +46 -46
  31. package/dist/cjs/node/runtime/renderPage/{renderPageAlreadyRouted.js → renderPageAfterRoute.js} +3 -4
  32. package/dist/cjs/node/runtime/renderPage.js +18 -16
  33. package/dist/cjs/node/runtime/utils.js +3 -2
  34. package/dist/cjs/node/runtime-dev/createDevMiddleware.js +0 -2
  35. package/dist/cjs/node/shared/virtualFileId.js +110 -0
  36. package/dist/cjs/node/vite/index.js +3 -3
  37. package/dist/cjs/node/vite/onLoad.js +5 -3
  38. package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +29 -30
  39. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +122 -10
  40. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +12 -17
  41. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +2 -10
  42. package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +5 -11
  43. package/dist/cjs/node/vite/plugins/pluginBuild/{pluginBuildEntry.js → pluginProdBuildEntry.js} +11 -11
  44. package/dist/cjs/node/vite/plugins/pluginBuild.js +2 -4
  45. package/dist/cjs/node/vite/plugins/pluginDev/determineFsAllowList.js +2 -2
  46. package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +6 -5
  47. package/dist/cjs/node/vite/plugins/pluginEnvVars.js +6 -13
  48. package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +7 -7
  49. package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +6 -2
  50. package/dist/cjs/node/vite/plugins/pluginFileEnv.js +4 -3
  51. package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +11 -11
  52. package/dist/cjs/node/vite/plugins/pluginPreview.js +4 -7
  53. package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +6 -13
  54. package/dist/cjs/node/vite/plugins/pluginSetGlobalContext.js +1 -1
  55. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigsEager.js → generateVirtualFileGlobalEntry.js} +5 -6
  56. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/{getVirtualFileEntry.js → generateVirtualFileGlobalEntryWithOldDesign.js} +12 -12
  57. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigLazy.js → generateVirtualFilePageEntry.js} +10 -11
  58. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +51 -21
  59. package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +14 -12
  60. package/dist/cjs/node/vite/shared/findPageFiles.js +1 -1
  61. package/dist/cjs/node/vite/shared/{resolveClientEntriesDev.js → getClientEntrySrcDev.js} +3 -3
  62. package/dist/cjs/node/vite/shared/getHttpRequestAsyncStore.js +8 -6
  63. package/dist/cjs/node/vite/shared/getMagicString.js +1 -1
  64. package/dist/cjs/node/vite/shared/getOutDirs.js +21 -22
  65. package/dist/cjs/node/vite/shared/getViteConfigRuntime.js +1 -1
  66. package/dist/cjs/node/vite/shared/isViteServerSide.js +68 -0
  67. package/dist/cjs/node/vite/shared/loggerVite/removeSuperfluousViteLog.js +6 -4
  68. package/dist/cjs/node/vite/shared/loggerVite.js +1 -1
  69. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +23 -36
  70. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +5 -4
  71. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +46 -48
  72. package/dist/cjs/shared/createGlobalContextShared.js +16 -14
  73. package/dist/cjs/shared/getPageFiles/{parseVirtualFileExports.js → parseVirtualFileExportsGlobalEntry.js} +20 -26
  74. package/dist/cjs/shared/page-configs/loadAndParseVirtualFilePageEntry.js +25 -0
  75. package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +10 -4
  76. package/dist/cjs/shared/page-configs/serialize/{parsePageConfigs.js → parsePageConfigsSerialized.js} +2 -2
  77. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +3 -3
  78. package/dist/cjs/shared/route/execHookOnBeforeRoute.js +0 -1
  79. package/dist/cjs/shared/route/index.js +0 -1
  80. package/dist/cjs/types/VikeGlobalInternal.js +2 -0
  81. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  82. package/dist/cjs/utils/assertSetup.js +2 -3
  83. package/dist/cjs/utils/assertVersion.js +2 -0
  84. package/dist/cjs/utils/debug.js +4 -4
  85. package/dist/cjs/utils/getGlobalObject.js +8 -15
  86. package/dist/cjs/utils/isNonRunnableDev.js +12 -0
  87. package/dist/cjs/utils/isScriptFile.js +1 -1
  88. package/dist/cjs/utils/path.js +5 -5
  89. package/dist/cjs/utils/requireResolve.js +13 -12
  90. package/dist/cjs/utils/{augmentType.js → updateType.js} +3 -3
  91. package/dist/esm/__internal/index.d.ts +2 -2
  92. package/dist/esm/__internal/index.js +3 -3
  93. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +2 -2
  94. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.js +2 -2
  95. package/dist/esm/client/runtime-client-routing/getPageContextCurrent.d.ts +2 -2
  96. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +12 -12
  97. package/dist/esm/client/runtime-client-routing/globalContext.d.ts +2 -2
  98. package/dist/esm/client/runtime-client-routing/globalContext.js +2 -2
  99. package/dist/esm/client/runtime-client-routing/prefetch/getPrefetchSettings.d.ts +2 -2
  100. package/dist/esm/client/runtime-client-routing/prefetch.d.ts +2 -2
  101. package/dist/esm/client/runtime-client-routing/prefetch.js +2 -2
  102. package/dist/esm/client/runtime-client-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
  103. package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +6 -7
  104. package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +6 -6
  105. package/dist/esm/client/runtime-client-routing/utils.d.ts +1 -1
  106. package/dist/esm/client/runtime-client-routing/utils.js +1 -1
  107. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +3 -3
  108. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +3 -3
  109. package/dist/esm/client/runtime-server-routing/globalContext.d.ts +2 -2
  110. package/dist/esm/client/runtime-server-routing/globalContext.js +2 -2
  111. package/dist/esm/client/runtime-server-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
  112. package/dist/esm/client/runtime-server-routing/utils.d.ts +1 -1
  113. package/dist/esm/client/runtime-server-routing/utils.js +1 -1
  114. package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +3 -3
  115. package/dist/esm/client/shared/createGetGlobalContextClient.js +5 -5
  116. package/dist/esm/client/shared/execHookOnRenderClient.d.ts +2 -2
  117. package/dist/esm/client/shared/loadPageConfigsLazyClientSide.d.ts +1 -1
  118. package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +4 -4
  119. package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +2 -2
  120. package/dist/esm/node/api/build.d.ts +2 -2
  121. package/dist/esm/node/api/build.js +6 -32
  122. package/dist/esm/node/api/context.d.ts +10 -10
  123. package/dist/esm/node/api/context.js +13 -12
  124. package/dist/esm/node/api/dev.d.ts +2 -2
  125. package/dist/esm/node/api/dev.js +0 -2
  126. package/dist/esm/node/api/index.js +0 -2
  127. package/dist/esm/node/api/onLoad.js +1 -1
  128. package/dist/esm/node/api/prepareViteApiCall.d.ts +3 -5
  129. package/dist/esm/node/api/prepareViteApiCall.js +3 -4
  130. package/dist/esm/node/api/preview.d.ts +2 -2
  131. package/dist/esm/node/api/preview.js +2 -3
  132. package/dist/esm/node/api/types.d.ts +4 -4
  133. package/dist/esm/node/api/utils.d.ts +1 -0
  134. package/dist/esm/node/api/utils.js +1 -0
  135. package/dist/esm/node/cli/index.js +1 -1
  136. package/dist/esm/node/cli/onLoad.js +1 -1
  137. package/dist/esm/node/prerender/runPrerender.d.ts +14 -303
  138. package/dist/esm/node/prerender/runPrerender.js +8 -9
  139. package/dist/esm/node/prerender/runPrerenderEntry.js +1 -1
  140. package/dist/esm/node/runtime/csp.d.ts +12 -0
  141. package/dist/esm/node/runtime/csp.js +44 -0
  142. package/dist/esm/node/runtime/globalContext.d.ts +13 -13
  143. package/dist/esm/node/runtime/globalContext.js +125 -109
  144. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +11 -8
  145. package/dist/esm/node/runtime/html/injectAssets/inferHtmlTags.d.ts +2 -1
  146. package/dist/esm/node/runtime/html/injectAssets/inferHtmlTags.js +5 -2
  147. package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.d.ts +2 -1
  148. package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.js +4 -2
  149. package/dist/esm/node/runtime/html/serializeContext.d.ts +2 -1
  150. package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +4 -3
  151. package/dist/esm/node/runtime/renderPage/analyzePage.js +6 -4
  152. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +2 -2
  153. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +2 -2
  154. package/dist/esm/node/runtime/renderPage/execHookOnRenderHtml.d.ts +0 -1
  155. package/dist/esm/node/runtime/renderPage/execHookOnRenderHtml.js +1 -11
  156. package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +2 -2
  157. package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +5 -4
  158. package/dist/esm/node/runtime/renderPage/getPageAssets/retrievePageAssetsDev.d.ts +10 -0
  159. package/dist/esm/node/runtime/renderPage/getPageAssets/{retrieveAssetsDev.js → retrievePageAssetsDev.js} +22 -7
  160. package/dist/esm/node/runtime/renderPage/getPageAssets/retrievePageAssetsProd.d.ts +10 -0
  161. package/dist/esm/node/runtime/renderPage/getPageAssets/{retrieveAssetsProd.js → retrievePageAssetsProd.js} +19 -2
  162. package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -10
  163. package/dist/esm/node/runtime/renderPage/getPageAssets.js +4 -33
  164. package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +1 -1
  165. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +108 -20
  166. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +48 -48
  167. package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +2 -2
  168. package/dist/esm/node/runtime/renderPage/{renderPageAlreadyRouted.d.ts → renderPageAfterRoute.d.ts} +30 -10
  169. package/dist/esm/node/runtime/renderPage/{renderPageAlreadyRouted.js → renderPageAfterRoute.js} +5 -6
  170. package/dist/esm/node/runtime/renderPage.d.ts +9 -6
  171. package/dist/esm/node/runtime/renderPage.js +20 -18
  172. package/dist/esm/node/runtime/utils.d.ts +3 -2
  173. package/dist/esm/node/runtime/utils.js +3 -2
  174. package/dist/esm/node/runtime-dev/createDevMiddleware.d.ts +2 -2
  175. package/dist/esm/node/runtime-dev/createDevMiddleware.js +0 -2
  176. package/dist/esm/node/shared/virtualFileId.d.ts +28 -0
  177. package/dist/esm/node/shared/virtualFileId.js +107 -0
  178. package/dist/esm/node/vite/index.js +3 -3
  179. package/dist/esm/node/vite/onLoad.js +5 -3
  180. package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +5 -6
  181. package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +31 -32
  182. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +119 -10
  183. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +12 -17
  184. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +2 -10
  185. package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +5 -8
  186. package/dist/esm/node/vite/plugins/pluginBuild/{pluginBuildEntry.d.ts → pluginProdBuildEntry.d.ts} +2 -2
  187. package/dist/esm/node/vite/plugins/pluginBuild/{pluginBuildEntry.js → pluginProdBuildEntry.js} +12 -12
  188. package/dist/esm/node/vite/plugins/pluginBuild.js +2 -4
  189. package/dist/esm/node/vite/plugins/pluginDev/determineFsAllowList.js +3 -3
  190. package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +6 -5
  191. package/dist/esm/node/vite/plugins/pluginEnvVars.js +6 -10
  192. package/dist/esm/node/vite/plugins/pluginExtractAssets.js +5 -5
  193. package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +6 -2
  194. package/dist/esm/node/vite/plugins/pluginFileEnv.js +4 -3
  195. package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +12 -12
  196. package/dist/esm/node/vite/plugins/pluginPreview.js +5 -8
  197. package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +6 -10
  198. package/dist/esm/node/vite/plugins/pluginSetGlobalContext.js +2 -2
  199. package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntry.d.ts +2 -0
  200. package/dist/esm/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigsEager.js → generateVirtualFileGlobalEntry.js} +5 -6
  201. package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.d.ts +6 -0
  202. package/dist/esm/node/vite/plugins/pluginVirtualFiles/{getVirtualFileEntry.js → generateVirtualFileGlobalEntryWithOldDesign.js} +11 -11
  203. package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFilePageEntry.d.ts +2 -0
  204. package/dist/esm/node/vite/plugins/pluginVirtualFiles/{getVirtualFilePageConfigLazy.js → generateVirtualFilePageEntry.js} +10 -11
  205. package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.d.ts +5 -1
  206. package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +52 -22
  207. package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +14 -12
  208. package/dist/esm/node/vite/shared/findPageFiles.js +1 -1
  209. package/dist/esm/node/vite/shared/getClientEntrySrcDev.d.ts +4 -0
  210. package/dist/esm/node/vite/shared/{resolveClientEntriesDev.js → getClientEntrySrcDev.js} +4 -4
  211. package/dist/esm/node/vite/shared/getHttpRequestAsyncStore.js +9 -7
  212. package/dist/esm/node/vite/shared/getMagicString.js +1 -1
  213. package/dist/esm/node/vite/shared/getOutDirs.d.ts +4 -3
  214. package/dist/esm/node/vite/shared/getOutDirs.js +21 -22
  215. package/dist/esm/node/vite/shared/getViteConfigRuntime.js +1 -1
  216. package/dist/esm/node/vite/shared/isViteServerSide.d.ts +18 -0
  217. package/dist/esm/node/vite/shared/isViteServerSide.js +66 -0
  218. package/dist/esm/node/vite/shared/loggerVite/removeSuperfluousViteLog.js +7 -5
  219. package/dist/esm/node/vite/shared/loggerVite.js +1 -1
  220. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.d.ts +3 -2
  221. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +24 -37
  222. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +6 -5
  223. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +4 -2
  224. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +49 -51
  225. package/dist/esm/shared/createGlobalContextShared.d.ts +7 -6
  226. package/dist/esm/shared/createGlobalContextShared.js +18 -16
  227. package/dist/esm/shared/getPageFiles/{parseVirtualFileExports.d.ts → parseVirtualFileExportsGlobalEntry.d.ts} +2 -2
  228. package/dist/esm/shared/getPageFiles/{parseVirtualFileExports.js → parseVirtualFileExportsGlobalEntry.js} +20 -26
  229. package/dist/esm/shared/getPageFiles.d.ts +1 -1
  230. package/dist/esm/shared/hooks/execHook.d.ts +2 -2
  231. package/dist/esm/shared/hooks/getHook.d.ts +3 -3
  232. package/dist/esm/shared/page-configs/loadAndParseVirtualFilePageEntry.d.ts +3 -0
  233. package/dist/esm/shared/page-configs/loadAndParseVirtualFilePageEntry.js +23 -0
  234. package/dist/esm/shared/page-configs/resolveVikeConfigPublic.d.ts +9 -9
  235. package/dist/esm/shared/page-configs/resolveVikeConfigPublic.js +10 -4
  236. package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +1 -1
  237. package/dist/esm/shared/page-configs/serialize/{parsePageConfigs.d.ts → parsePageConfigsSerialized.d.ts} +2 -2
  238. package/dist/esm/shared/page-configs/serialize/{parsePageConfigs.js → parsePageConfigsSerialized.js} +2 -2
  239. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +3 -3
  240. package/dist/esm/shared/route/execHookOnBeforeRoute.d.ts +3 -3
  241. package/dist/esm/shared/route/execHookOnBeforeRoute.js +0 -1
  242. package/dist/esm/shared/route/index.d.ts +5 -6
  243. package/dist/esm/shared/route/index.js +0 -1
  244. package/dist/esm/types/Config.d.ts +11 -7
  245. package/dist/esm/types/PageConfig.d.ts +11 -9
  246. package/dist/esm/types/PageContext.d.ts +6 -0
  247. package/dist/esm/types/VikeGlobalInternal.d.ts +4 -0
  248. package/dist/esm/types/VikeGlobalInternal.js +1 -0
  249. package/dist/esm/types/VikeNamespace.d.ts +13 -0
  250. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  251. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  252. package/dist/esm/utils/assertSetup.js +2 -3
  253. package/dist/esm/utils/assertVersion.js +2 -0
  254. package/dist/esm/utils/debug.js +3 -3
  255. package/dist/esm/utils/getGlobalObject.d.ts +6 -5
  256. package/dist/esm/utils/getGlobalObject.js +8 -15
  257. package/dist/esm/utils/isNonRunnableDev.d.ts +2 -0
  258. package/dist/esm/utils/isNonRunnableDev.js +10 -0
  259. package/dist/esm/utils/isScriptFile.d.ts +1 -1
  260. package/dist/esm/utils/isScriptFile.js +1 -1
  261. package/dist/esm/utils/path.d.ts +2 -0
  262. package/dist/esm/utils/path.js +5 -5
  263. package/dist/esm/utils/requireResolve.d.ts +4 -4
  264. package/dist/esm/utils/requireResolve.js +13 -12
  265. package/dist/esm/utils/updateType.d.ts +3 -0
  266. package/dist/esm/utils/updateType.js +7 -0
  267. package/package.json +6 -6
  268. package/dist/cjs/node/runtime/renderPage/debugPageFiles.js +0 -52
  269. package/dist/cjs/node/shared/virtualFiles/virtualFileEntry.js +0 -31
  270. package/dist/cjs/node/shared/virtualFiles/virtualFilePageConfigLazy.js +0 -45
  271. package/dist/cjs/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +0 -149
  272. package/dist/cjs/node/vite/shared/applyRegExWithMagicString.js +0 -11
  273. package/dist/cjs/node/vite/shared/isViteServerBuild.js +0 -47
  274. package/dist/cjs/shared/page-configs/loadConfigValues.js +0 -21
  275. package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +0 -23
  276. package/dist/esm/node/runtime/renderPage/debugPageFiles.js +0 -47
  277. package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.d.ts +0 -4
  278. package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.d.ts +0 -4
  279. package/dist/esm/node/shared/virtualFiles/virtualFileEntry.d.ts +0 -11
  280. package/dist/esm/node/shared/virtualFiles/virtualFileEntry.js +0 -28
  281. package/dist/esm/node/shared/virtualFiles/virtualFilePageConfigLazy.d.ts +0 -9
  282. package/dist/esm/node/shared/virtualFiles/virtualFilePageConfigLazy.js +0 -43
  283. package/dist/esm/node/vite/plugins/pluginBuild/pluginAutoFullBuild.d.ts +0 -5
  284. package/dist/esm/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +0 -144
  285. package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFileEntry.d.ts +0 -5
  286. package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.d.ts +0 -3
  287. package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.d.ts +0 -2
  288. package/dist/esm/node/vite/shared/applyRegExWithMagicString.d.ts +0 -3
  289. package/dist/esm/node/vite/shared/applyRegExWithMagicString.js +0 -9
  290. package/dist/esm/node/vite/shared/isViteServerBuild.d.ts +0 -15
  291. package/dist/esm/node/vite/shared/isViteServerBuild.js +0 -45
  292. package/dist/esm/node/vite/shared/resolveClientEntriesDev.d.ts +0 -4
  293. package/dist/esm/shared/page-configs/loadConfigValues.d.ts +0 -3
  294. package/dist/esm/shared/page-configs/loadConfigValues.js +0 -19
  295. package/dist/esm/utils/augmentType.d.ts +0 -3
  296. package/dist/esm/utils/augmentType.js +0 -7
  297. /package/dist/cjs/utils/{getTerminWidth.js → getTerminalWidth.js} +0 -0
  298. /package/dist/esm/utils/{getTerminWidth.d.ts → getTerminalWidth.d.ts} +0 -0
  299. /package/dist/esm/utils/{getTerminWidth.js → getTerminalWidth.js} +0 -0
@@ -12,29 +12,23 @@ export { initGlobalContext_getPagesAndRoutes };
12
12
  export { setGlobalContext_viteDevServer };
13
13
  export { setGlobalContext_viteConfig };
14
14
  export { setGlobalContext_isPrerendering };
15
- export { setGlobalContext_isProduction };
16
- export { setGlobalContext_buildEntry }; // production entry
15
+ export { setGlobalContext_isProductionAccordingToVite };
16
+ export { setGlobalContext_prodBuildEntry }; // production entry
17
17
  export { clearGlobalContext };
18
18
  export { assertBuildInfo };
19
19
  export { updateUserFiles };
20
20
  export { vikeConfigErrorRecoverMsg };
21
- // TODO/now: use isProductionEnvironment() instead of globalObject.isProduction
22
- // TODO/now: rename:
23
- // - isProduction => isProductionEnvironment
24
- // - setIsProduction => setIsProductionEnvironment
25
- // - setGlobalContext_isProduction => setGlobalContext_isProductionEnvironment
26
- // - sProductionEnvironment => sDevEnv
27
21
  // The core logic revolves around:
28
- // - virtualFileExports is the main requirement
29
- // - In production: globalObject.buildEntry which is the production entry set by @brillout/vite-plugin-server-entry
30
- // - loadBuildEntry() sets globalObject.buildEntry and then sets virtualFileExports
31
- // - With vike-server it's set at server start: @brillout/vite-plugin-server-entry injects `import './entry.mjs'` (the production entry generated by @brillout/vite-plugin-server-entry) as first line of code of dist/server/index.mjs while dist/server/entry.mjs calls setGlobalContext_buildEntry()
22
+ // - virtualFileExportsGlobalEntry is the main requirement
23
+ // - In production: globalObject.prodBuildEntry which is the production entry set by @brillout/vite-plugin-server-entry
24
+ // - loadProdBuildEntry() sets globalObject.prodBuildEntry and then sets virtualFileExportsGlobalEntry
25
+ // - With vike-server it's set at server start: @brillout/vite-plugin-server-entry injects `import './entry.mjs'` (the production entry generated by @brillout/vite-plugin-server-entry) as first line of code of dist/server/index.mjs while dist/server/entry.mjs calls setGlobalContext_prodBuildEntry()
32
26
  // - Without vike-server it's manually loaded here using importServerProductionEntry() which uses @brillout/vite-plugin-server-entry's autoImporter or crawler
33
27
  // - In development: globalObject.viteDevServer which is Vite's development server
34
- // - globalObject.viteDevServer is used by updateUserFiles() which then sets virtualFileExports
35
- import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebugger, checkType, PROJECT_VERSION, getViteRPC, isRunnableDevEnvironment, assertIsNotBrowser, } from './utils.js';
28
+ // - globalObject.viteDevServer is used by updateUserFiles() which then sets virtualFileExportsGlobalEntry
29
+ import { assert, onSetupRuntime, assertUsage, assertWarning, isPlainObject, objectReplace, isObject, hasProp, getGlobalObject, genPromise, createDebugger, checkType, PROJECT_VERSION, getViteRPC, isRunnableDevEnvironment, assertIsNotBrowser, isNonRunnableDev, } from './utils.js';
36
30
  import { importServerProductionEntry } from '@brillout/vite-plugin-server-entry/runtime';
37
- import { virtualFileIdEntryServer } from '../shared/virtualFiles/virtualFileEntry.js';
31
+ import { virtualFileIdGlobalEntryServer } from '../shared/virtualFileId.js';
38
32
  import pc from '@brillout/picocolors';
39
33
  import { loadPageRoutes, loadPageRoutesSync } from '../../shared/route/loadPageRoutes.js';
40
34
  import { assertV1Design } from '../shared/assertV1Design.js';
@@ -44,6 +38,7 @@ import { prepareGlobalContextForPublicUsage } from '../../shared/prepareGlobalCo
44
38
  import { logRuntimeError, logRuntimeInfo } from './loggerRuntime.js';
45
39
  import { getVikeConfigErrorBuild, setVikeConfigError } from '../shared/getVikeConfigError.js';
46
40
  import { hasAlreadyLogged } from './renderPage/isNewError.js';
41
+ import { getVikeApiOperation } from '../api/context.js';
47
42
  const debug = createDebugger('vike:globalContext');
48
43
  const globalObject = getGlobalObject('runtime/globalContext.ts', getInitialGlobalObject());
49
44
  // Trick to break down TypeScript circular dependency
@@ -55,7 +50,7 @@ async function getGlobalContextServerInternal() {
55
50
  // getGlobalContextServerInternal() should always be called after initGlobalContext()
56
51
  assert(globalObject.isInitialized);
57
52
  assertGlobalContextIsDefined();
58
- if (globalObject.isProduction !== true)
53
+ if (!isProd())
59
54
  await globalObject.waitForUserFilesUpdate;
60
55
  const { globalContext } = globalObjectTyped;
61
56
  assertIsDefined(globalContext);
@@ -80,10 +75,9 @@ function assertGlobalContextIsDefined() {
80
75
  */
81
76
  async function getGlobalContext() {
82
77
  debug('getGlobalContext()');
83
- const { isProduction } = globalObject;
78
+ const isProduction = isProdOptional();
84
79
  // This assertion cannot fail for vike-server users (because when using vike-server it's guaranteed that globalObject.isProduction is set before executing any user-land code and any Vike extension code).
85
- assertUsage(isProduction !== undefined, "The global context isn't set yet, use getGlobalContextAsync() instead.");
86
- assert(typeof globalObject.isProduction === 'boolean');
80
+ assertUsage(isProduction !== null, "The global context isn't set yet, use getGlobalContextAsync() instead.");
87
81
  return await getGlobalContextAsync(isProduction);
88
82
  }
89
83
  /**
@@ -94,7 +88,7 @@ async function getGlobalContext() {
94
88
  async function getGlobalContextAsync(isProduction) {
95
89
  debug('getGlobalContextAsync()');
96
90
  assertUsage(typeof isProduction === 'boolean', `[getGlobalContextAsync(isProduction)] Argument ${pc.cyan('isProduction')} ${isProduction === undefined ? 'is missing' : `should be ${pc.cyan('true')} or ${pc.cyan('false')}`}`);
97
- setIsProduction(isProduction);
91
+ globalObject.isProductionAccordingToUser = isProduction;
98
92
  if (!globalObject.globalContext)
99
93
  await initGlobalContext_getGlobalContextAsync();
100
94
  if (!isProduction)
@@ -111,9 +105,7 @@ function getGlobalContextSync() {
111
105
  debug('getGlobalContextSync()');
112
106
  const { globalContext } = globalObjectTyped;
113
107
  assertUsage(globalContext, getGlobalContextSyncErrMsg);
114
- const isProd = globalContext._isProduction;
115
- assert(typeof isProd === 'boolean');
116
- assertWarning(isProd,
108
+ assertWarning(isProd(),
117
109
  // - We discourage users from using it in development because `pageContext.globalContext` is safer: I ain't sure but there could be race conditions when using `getGlobalContextSync()` inside React/Vue components upon HMR.
118
110
  // - I don't see any issues with getGlobalContextSync() in production.
119
111
  // - getGlobalContextSync() is used in production by vike-vercel
@@ -129,7 +121,6 @@ function getGlobalContextForPublicUsage() {
129
121
  }
130
122
  async function setGlobalContext_viteDevServer(viteDevServer) {
131
123
  debug('setGlobalContext_viteDevServer()');
132
- setIsProduction(false);
133
124
  // We cannot cache globalObject.viteDevServer because it's fully replaced when the user modifies vite.config.js => Vite's dev server is fully reloaded and a new viteDevServer replaces the previous one.
134
125
  if (!globalObject.viteDevServer) {
135
126
  assertIsNotInitializedYet();
@@ -157,18 +148,9 @@ function assertIsNotInitializedYet() {
157
148
  }
158
149
  function setGlobalContext_isPrerendering() {
159
150
  globalObject.isPrerendering = true;
160
- setIsProduction(true);
161
- }
162
- // TODO/now: `rename tolerateContraditction tolerateContradiction`
163
- function setGlobalContext_isProduction(isProduction, tolerateContraditction = false) {
164
- if (debug.isActivated)
165
- debug('setGlobalContext_isProduction()', { isProduction, tolerateContraditction });
166
- if (globalObject.isProduction === undefined) {
167
- setIsProduction(isProduction);
168
- }
169
- else {
170
- assert(globalObject.isProduction === isProduction || tolerateContraditction);
171
- }
151
+ }
152
+ function setGlobalContext_isProductionAccordingToVite(isProductionAccordingToVite) {
153
+ globalObject.isProductionAccordingToVite = isProductionAccordingToVite;
172
154
  }
173
155
  function getViteDevServer() {
174
156
  return globalObject.viteDevServer ?? null;
@@ -178,15 +160,13 @@ function getViteConfig() {
178
160
  }
179
161
  async function initGlobalContext_renderPage() {
180
162
  debug('initGlobalContext_renderPage()');
181
- // `globalObject.isProduction === undefined` when using production server without `vike-server`. (There isn't any reliable signal we can use to determine early whether the environment is production or development.)
182
- if (globalObject.isProduction === undefined)
183
- setIsProduction(true);
163
+ globalObject.isAfterFirstRenderPageCall = true;
184
164
  await initGlobalContext();
185
165
  }
186
166
  async function initGlobalContext_runPrerender() {
187
167
  debug('initGlobalContext_runPrerender()');
188
168
  assert(globalObject.isPrerendering === true);
189
- assert(globalObject.isProduction === true);
169
+ assert(isProd());
190
170
  if (globalObject.initGlobalContext_runPrerender_alreadyCalled)
191
171
  return;
192
172
  globalObject.initGlobalContext_runPrerender_alreadyCalled = true;
@@ -204,12 +184,11 @@ async function initGlobalContext_getGlobalContextAsync() {
204
184
  }
205
185
  async function initGlobalContext_getPagesAndRoutes() {
206
186
  debug('initGlobalContext_getPagesAndRoutes()');
207
- setIsProduction(true);
187
+ globalObject.isProductionAccordingToPhotonVercel = true;
208
188
  await initGlobalContext();
209
189
  }
210
190
  async function initGlobalContext() {
211
- const { isProduction } = globalObject;
212
- assert(typeof isProduction === 'boolean');
191
+ const isProduction = isProd();
213
192
  if (!isProduction) {
214
193
  if (isProcessSharedWithVite()) {
215
194
  await globalObject.viteDevServerPromise;
@@ -222,18 +201,11 @@ async function initGlobalContext() {
222
201
  await globalObject.waitForUserFilesUpdate;
223
202
  }
224
203
  else {
225
- await loadBuildEntry(globalObject.viteConfigRuntime?.build.outDir);
204
+ await loadProdBuildEntry(globalObject.viteConfigRuntime?.build.outDir);
226
205
  }
227
206
  assertGlobalContextIsDefined();
228
207
  globalObject.isInitialized = true;
229
208
  }
230
- function setIsProduction(isProduction) {
231
- debug('setIsProduction', isProduction);
232
- assert(typeof isProduction === 'boolean');
233
- if (globalObject.isProduction !== undefined)
234
- assert(globalObject.isProduction === isProduction);
235
- globalObject.isProduction = isProduction;
236
- }
237
209
  function assertViteManifest(manifest) {
238
210
  assert(isPlainObject(manifest));
239
211
  /* We should include these assertions but we don't as a workaround for PWA manifests: https://github.com/vikejs/vike/issues/769
@@ -247,59 +219,58 @@ function assertViteManifest(manifest) {
247
219
  })
248
220
  */
249
221
  }
250
- async function loadBuildEntry(outDir) {
251
- debug('loadBuildEntry()');
222
+ async function loadProdBuildEntry(outDir) {
223
+ debug('loadProdBuildEntry()');
252
224
  if (globalObject.globalContext) {
253
- debug('loadBuildEntry() - already done');
225
+ debug('loadProdBuildEntry() - already done');
254
226
  return;
255
227
  }
256
- if (!globalObject.buildEntry) {
228
+ if (!globalObject.prodBuildEntry) {
257
229
  debug('importServerProductionEntry()');
258
- // importServerProductionEntry() loads dist/server/entry.mjs which calls setGlobalContext_buildEntry()
230
+ // importServerProductionEntry() loads dist/server/entry.mjs which calls setGlobalContext_prodBuildEntry()
259
231
  await importServerProductionEntry({ outDir });
260
- if (!globalObject.buildEntry) {
261
- debug('globalObject.buildEntryPrevious');
232
+ if (!globalObject.prodBuildEntry) {
233
+ debug('globalObject.prodBuildEntryPrevious');
262
234
  // Needed, for example, when calling the API prerender() then preview() because both trigger a importServerProductionEntry() call but only the first only is applied because of the import() cache. (A proper implementation would be to clear the import() cache, but it probably isn't possible on platforms such as Cloudflare Workers.)
263
- globalObject.buildEntry = globalObject.buildEntryPrevious;
235
+ globalObject.prodBuildEntry = globalObject.prodBuildEntryPrevious;
264
236
  }
265
- assert(globalObject.buildEntry);
266
- // If using `inject` then dist/server/index.js imports dist/server/entry.js and loadBuildEntry() isn't needed.
237
+ assert(globalObject.prodBuildEntry);
238
+ // If using `inject` then dist/server/index.js imports dist/server/entry.js and loadProdBuildEntry() isn't needed.
267
239
  // If dist/server/entry.js isn't imported then this means the user is running the original server entry `$ ts-node server/index.ts`.
268
240
  assertWarning(
269
241
  // vike-server => `inject === true`
270
242
  // vike-node => `inject === [ 'index' ]` => we don't show the warning to vike-node users (I don't remember why).
271
243
  globalObject.buildInfo?.viteConfigRuntime.vitePluginServerEntry.inject !== true || globalObject.isPrerendering, `Run the built server entry (e.g. ${pc.cyan('$ node dist/server/index.mjs')}) instead of the original server entry (e.g. ${pc.cyan('$ ts-node server/index.ts')})`, { onlyOnce: true });
272
244
  }
273
- const { buildEntry } = globalObject;
274
- assertBuildEntry(buildEntry);
275
- globalObject.assetsManifest = buildEntry.assetsManifest;
276
- globalObject.buildInfo = buildEntry.buildInfo;
277
- await createGlobalContext(buildEntry.virtualFileExports);
245
+ const { prodBuildEntry } = globalObject;
246
+ assertProdBuildEntry(prodBuildEntry);
247
+ globalObject.assetsManifest = prodBuildEntry.assetsManifest;
248
+ globalObject.buildInfo = prodBuildEntry.buildInfo;
249
+ await createGlobalContext(prodBuildEntry.virtualFileExportsGlobalEntry);
278
250
  }
279
251
  // This is the production entry, see:
280
- // https://github.com/vikejs/vike/blob/798e5465dc3e3e6723b38b601a50350c0a006fb8/packages/vike/node/vite/plugins/pluginBuild/pluginBuildEntry.ts#L47
281
- async function setGlobalContext_buildEntry(buildEntry) {
282
- debug('setGlobalContext_buildEntry()');
283
- setIsProduction(true);
284
- assertBuildEntry(buildEntry);
285
- globalObject.buildEntry = buildEntry;
286
- globalObject.buildEntryPrevious = buildEntry;
287
- assert(globalObject.buildEntry); // ensure no infinite loop
288
- await loadBuildEntry();
252
+ // https://github.com/vikejs/vike/blob/8c350e8105a626469e87594d983090919e82099b/packages/vike/node/vite/plugins/pluginBuild/pluginProdBuildEntry.ts#L47
253
+ async function setGlobalContext_prodBuildEntry(prodBuildEntry) {
254
+ debug('setGlobalContext_prodBuildEntry()');
255
+ assertProdBuildEntry(prodBuildEntry);
256
+ globalObject.prodBuildEntry = prodBuildEntry;
257
+ globalObject.prodBuildEntryPrevious = prodBuildEntry;
258
+ assert(globalObject.prodBuildEntry); // ensure no infinite loop
259
+ await loadProdBuildEntry();
289
260
  assertGlobalContextIsDefined();
290
- debug('setGlobalContext_buildEntry() - done');
291
- }
292
- function assertBuildEntry(buildEntry) {
293
- assert(isObject(buildEntry));
294
- assert(hasProp(buildEntry, 'virtualFileExports', 'object'));
295
- const { virtualFileExports } = buildEntry;
296
- assert(hasProp(buildEntry, 'assetsManifest', 'object'));
297
- const { assetsManifest } = buildEntry;
261
+ debug('setGlobalContext_prodBuildEntry() - done');
262
+ }
263
+ function assertProdBuildEntry(prodBuildEntry) {
264
+ assert(isObject(prodBuildEntry));
265
+ assert(hasProp(prodBuildEntry, 'virtualFileExportsGlobalEntry', 'object'));
266
+ const { virtualFileExportsGlobalEntry } = prodBuildEntry;
267
+ assert(hasProp(prodBuildEntry, 'assetsManifest', 'object'));
268
+ const { assetsManifest } = prodBuildEntry;
298
269
  assertViteManifest(assetsManifest);
299
- assert(hasProp(buildEntry, 'buildInfo', 'object'));
300
- const { buildInfo } = buildEntry;
270
+ assert(hasProp(prodBuildEntry, 'buildInfo', 'object'));
271
+ const { buildInfo } = prodBuildEntry;
301
272
  assertBuildInfo(buildInfo);
302
- checkType({ virtualFileExports, assetsManifest, buildInfo });
273
+ checkType({ virtualFileExportsGlobalEntry, assetsManifest, buildInfo });
303
274
  }
304
275
  function assertBuildInfo(buildInfo) {
305
276
  assert(isObject(buildInfo));
@@ -320,7 +291,7 @@ function assertVersionAtBuildTime(versionAtBuildTime) {
320
291
  }
321
292
  async function updateUserFiles() {
322
293
  debug('updateUserFiles()');
323
- assert(!globalObject.isProduction);
294
+ assert(!isProd());
324
295
  const { promise, resolve } = genPromise();
325
296
  globalObject.waitForUserFilesUpdate = promise;
326
297
  globalObject.waitForUserFilesUpdateResolve ?? (globalObject.waitForUserFilesUpdateResolve = []);
@@ -353,15 +324,15 @@ async function updateUserFiles() {
353
324
  viteDevServer !== globalObject.viteDevServer;
354
325
  const { viteDevServer } = globalObject;
355
326
  let hasError = false;
356
- let virtualFileExports;
327
+ let virtualFileExportsGlobalEntry;
357
328
  let err;
358
329
  if (viteDevServer) {
359
330
  assert(isRunnable(viteDevServer));
360
331
  /* We don't use runner.import() yet, because as of vite@7.0.6 (July 2025) runner.import() unexpectedly invalidates the module graph, which is a unexpected behavior that doesn't happen with ssrLoadModule()
361
332
  // Vite 6
362
333
  try {
363
- virtualFileExports = await (viteDevServer.environments.ssr as RunnableDevEnvironment).runner.import(
364
- 'virtual:vike:entry:server',
334
+ virtualFileExportsGlobalEntry = await (viteDevServer.environments.ssr as RunnableDevEnvironment).runner.import(
335
+ 'virtual:vike:global-entry:server',
365
336
  )
366
337
  } catch (err_) {
367
338
  hasError = true
@@ -370,7 +341,7 @@ async function updateUserFiles() {
370
341
  */
371
342
  // Vite 5
372
343
  try {
373
- virtualFileExports = await viteDevServer.ssrLoadModule(virtualFileIdEntryServer);
344
+ virtualFileExportsGlobalEntry = await viteDevServer.ssrLoadModule(virtualFileIdGlobalEntryServer);
374
345
  }
375
346
  catch (err_) {
376
347
  hasError = true;
@@ -383,10 +354,10 @@ async function updateUserFiles() {
383
354
  ```js
384
355
  assert(false)
385
356
  // This line breaks the HMR of regular (runnable) apps, even though (as per the assert() above) it's never run. It seems to be a Vite bug: handleHotUpdate() receives an empty `modules` list.
386
- import('virtual:vike:entry:server')
357
+ import('virtual:vike:global-entry:server')
387
358
  ```
388
359
  */
389
- virtualFileExports = await __VIKE__DYNAMIC_IMPORT('virtual:vike:entry:server');
360
+ virtualFileExportsGlobalEntry = await __VIKE__DYNAMIC_IMPORT('virtual:vike:global-entry:server');
390
361
  }
391
362
  catch (err_) {
392
363
  hasError = true;
@@ -397,12 +368,12 @@ async function updateUserFiles() {
397
368
  return { success: false };
398
369
  if (hasError)
399
370
  return onError(err);
400
- virtualFileExports = virtualFileExports.default || virtualFileExports;
371
+ virtualFileExportsGlobalEntry = virtualFileExportsGlobalEntry.default || virtualFileExportsGlobalEntry;
401
372
  if (getVikeConfigErrorBuild()) {
402
373
  return { success: false };
403
374
  }
404
375
  try {
405
- await createGlobalContext(virtualFileExports);
376
+ await createGlobalContext(virtualFileExportsGlobalEntry);
406
377
  }
407
378
  catch (err_) {
408
379
  hasError = true;
@@ -414,16 +385,21 @@ async function updateUserFiles() {
414
385
  return onError(err);
415
386
  return onSuccess();
416
387
  }
417
- async function createGlobalContext(virtualFileExports) {
388
+ async function createGlobalContext(virtualFileExportsGlobalEntry) {
418
389
  debug('createGlobalContext()');
419
390
  assert(!getVikeConfigErrorBuild());
420
- const globalContext = await createGlobalContextShared(virtualFileExports, globalObject, addGlobalContext, addGlobalContextTmp, addGlobalContextAsync);
391
+ const globalContextPromise = createGlobalContextShared(virtualFileExportsGlobalEntry, globalObject, addGlobalContext, addGlobalContextTmp, addGlobalContextAsync);
392
+ debug('createGlobalContext() - done [sync]');
393
+ // We define an early globalContext version synchronously, so that getGlobalContextSync() can be called early.
394
+ // - Required by vike-vercel
395
+ assert(globalObject.globalContext);
396
+ const globalContext = await globalContextPromise;
397
+ debug('createGlobalContext() - done [async]');
421
398
  assertV1Design(
422
399
  // pageConfigs is PageConfigRuntime[] but assertV1Design() requires PageConfigBuildTime[]
423
400
  globalContext._pageConfigs.length > 0, globalContext._pageFilesAll);
424
401
  assertGlobalContextIsDefined();
425
402
  onSetupRuntime();
426
- debug('createGlobalContext() - done');
427
403
  // Never actually used, only used for TypeScript `ReturnType<typeof createGlobalContext>`
428
404
  return globalContext;
429
405
  }
@@ -443,8 +419,8 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
443
419
  _pageRoutes: pageRoutes,
444
420
  _onBeforeRouteHook: onBeforeRouteHook,
445
421
  };
446
- const { viteDevServer, viteConfig, isPrerendering, isProduction } = globalObject;
447
- assert(typeof isProduction === 'boolean');
422
+ const { viteDevServer, viteConfig, isPrerendering } = globalObject;
423
+ const isProduction = isProd();
448
424
  if (!isProduction) {
449
425
  assert(globalContext); // main common requirement
450
426
  assert(!isPrerendering);
@@ -458,7 +434,7 @@ function addGlobalContextCommon(globalContext, pageRoutes, onBeforeRouteHook) {
458
434
  };
459
435
  }
460
436
  else {
461
- assert(globalObject.buildEntry);
437
+ assert(globalObject.prodBuildEntry);
462
438
  assert(globalContext); // main common requiement
463
439
  const { buildInfo, assetsManifest } = globalObject;
464
440
  assert(buildInfo);
@@ -496,7 +472,7 @@ async function addGlobalContextAsync(globalContext) {
496
472
  }
497
473
  else {
498
474
  assert(!isProcessSharedWithVite()); // process shared with Vite => globalObject.viteConfigRuntime should be set
499
- assert(!globalObject.isProduction); // production => globalObject.buildInfo.viteConfigRuntime should be set
475
+ assert(!isProd()); // production => globalObject.buildInfo.viteConfigRuntime should be set
500
476
  assert(isNonRunnableDev());
501
477
  const rpc = getViteRPC();
502
478
  viteConfigRuntime = await rpc.getViteConfigRuntimeRPC();
@@ -510,13 +486,12 @@ async function addGlobalContextAsync(globalContext) {
510
486
  }
511
487
  function clearGlobalContext() {
512
488
  debug('clearGlobalContext()');
513
- objectReplace(globalObject, getInitialGlobalObject(), ['buildEntryPrevious']);
489
+ objectReplace(globalObject, getInitialGlobalObject(), ['prodBuildEntryPrevious']);
514
490
  }
515
491
  function getInitialGlobalObject() {
516
492
  debug('getInitialGlobalObject()');
517
493
  const { promise: viteDevServerPromise, resolve: viteDevServerPromiseResolve } = genPromise();
518
494
  return {
519
- isProduction: isNonRunnableDev() ? false : undefined,
520
495
  viteDevServerPromise,
521
496
  viteDevServerPromiseResolve,
522
497
  };
@@ -543,10 +518,51 @@ function isRunnable(viteDevServer) {
543
518
  assert(!isNonRunnableDev());
544
519
  return yes;
545
520
  }
546
- function isNonRunnableDev() {
547
- if (typeof __VIKE__IS_NON_RUNNABLE_DEV === 'undefined')
548
- return null;
549
- const yes = __VIKE__IS_NON_RUNNABLE_DEV;
521
+ function isProd() {
522
+ const isProduction = isProdOptional();
523
+ if (isProduction === null) {
524
+ if (globalObject.isAfterFirstRenderPageCall) {
525
+ // When using a production server without vike-server, there isn't any reliable signal we can use to determine early whether the environment is production or development. If renderPage() was called then some non-negligible amount of time passed — it's likely that, in dev, one of the Vite hooks should have already sent a signal we can use to determine prod/dev.
526
+ return true;
527
+ }
528
+ else {
529
+ assert(false);
530
+ }
531
+ }
532
+ return isProduction;
533
+ }
534
+ function isProdOptional() {
535
+ const vikeApiOperation = getVikeApiOperation()?.operation ?? null;
536
+ const yes =
537
+ // setGlobalContext_prodBuildEntry() was called
538
+ !!globalObject.prodBuildEntry ||
539
+ globalObject.isPrerendering === true ||
540
+ // Vike CLI & Vike API
541
+ (!!vikeApiOperation && vikeApiOperation !== 'dev') ||
542
+ // Vite command
543
+ globalObject.isProductionAccordingToVite === true ||
544
+ // getGlobalContextAsync(isProduction)
545
+ globalObject.isProductionAccordingToUser === true ||
546
+ // vite-plugin-vercel
547
+ globalObject.isProductionAccordingToPhotonVercel === true;
550
548
  assert(typeof yes === 'boolean');
551
- return yes;
549
+ const no = !!globalObject.viteDevServer ||
550
+ // Vike CLI & Vike API
551
+ vikeApiOperation === 'dev' ||
552
+ // Vite command
553
+ globalObject.isProductionAccordingToVite === false ||
554
+ // getGlobalContextAsync(isProduction)
555
+ globalObject.isProductionAccordingToUser === false ||
556
+ // @cloudflare/vite-plugin
557
+ isNonRunnableDev() === true;
558
+ assert(typeof no === 'boolean');
559
+ if (yes) {
560
+ assert(no === false);
561
+ return true;
562
+ }
563
+ if (no) {
564
+ assert(yes === false);
565
+ return false;
566
+ }
567
+ return null;
552
568
  }
@@ -1,4 +1,3 @@
1
- import { isFontFallback } from '../../renderPage/isFontFallback.js';
2
1
  export { getHtmlTags };
3
2
  import { assert, assertWarning, assertUsage, isObject, freezePartial } from '../../utils.js';
4
3
  import { getGlobalContextClientSerialized, getPageContextClientSerialized, } from '../serializeContext.js';
@@ -10,6 +9,8 @@ import { getConfigValueRuntime } from '../../../../shared/page-configs/getConfig
10
9
  import pc from '@brillout/picocolors';
11
10
  import { getConfigDefinedAt } from '../../../../shared/page-configs/getConfigDefinedAt.js';
12
11
  import { htmlElementId_globalContext, htmlElementId_pageContext } from '../../../../shared/htmlElementIds.js';
12
+ import { isFontFallback } from '../../renderPage/isFontFallback.js';
13
+ import { inferNonceAttr } from '../../csp.js';
13
14
  const stamp = '__injectFilterEntry';
14
15
  async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectFilter, pageAssets, viteDevScript, isStream) {
15
16
  assert([true, false].includes(pageContext._isHtmlOnly));
@@ -76,7 +77,7 @@ async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectF
76
77
  .forEach((asset) => {
77
78
  if (!asset.inject)
78
79
  return;
79
- const htmlTag = asset.isEntry ? inferAssetTag(asset) : inferPreloadTag(asset);
80
+ const htmlTag = asset.isEntry ? inferAssetTag(asset, pageContext) : inferPreloadTag(asset);
80
81
  htmlTags.push({ htmlTag, position: asset.inject });
81
82
  });
82
83
  // ==========
@@ -137,7 +138,7 @@ async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectF
137
138
  });
138
139
  }
139
140
  // The JavaScript entry <script> tag
140
- const scriptEntry = mergeScriptEntries(pageAssets, viteDevScript);
141
+ const scriptEntry = mergeScriptEntries(pageAssets, viteDevScript, pageContext);
141
142
  if (scriptEntry) {
142
143
  htmlTags.push({
143
144
  htmlTag: scriptEntry,
@@ -158,9 +159,9 @@ async function getHtmlTags(pageContext, streamFromReactStreamingPackage, injectF
158
159
  });
159
160
  return htmlTags;
160
161
  }
161
- function mergeScriptEntries(pageAssets, viteDevScript) {
162
+ function mergeScriptEntries(pageAssets, viteDevScript, pageContext) {
162
163
  const scriptEntries = pageAssets.filter((pageAsset) => pageAsset.isEntry && pageAsset.assetType === 'script');
163
- let scriptEntry = `${viteDevScript}${scriptEntries.map((asset) => inferAssetTag(asset)).join('')}`;
164
+ let scriptEntry = `${viteDevScript}${scriptEntries.map((asset) => inferAssetTag(asset, pageContext)).join('')}`;
164
165
  // We merge scripts to avoid the infamous HMR preamble error.
165
166
  // - Infamous HMR preamble error:
166
167
  // ```browser-console
@@ -178,12 +179,13 @@ function mergeScriptEntries(pageAssets, viteDevScript) {
178
179
  // ```
179
180
  // - Maybe an alternative would be to make Vike's client runtime entry <script> tag non-async. Would that work? Would it be a performance issue?
180
181
  // - The entry <script> shouldn't be `<script defer>` upon HTML streaming, otherwise progressive hydration while SSR streaming won't work.
181
- scriptEntry = mergeScriptTags(scriptEntry);
182
+ scriptEntry = mergeScriptTags(scriptEntry, pageContext);
182
183
  return scriptEntry;
183
184
  }
184
185
  function getPageContextJsonScriptTag(pageContext) {
185
186
  const pageContextClientSerialized = sanitizeJson(getPageContextClientSerialized(pageContext, true));
186
- const htmlTag = `<script id="${htmlElementId_pageContext}" type="application/json">${pageContextClientSerialized}</script>`;
187
+ const nonceAttr = inferNonceAttr(pageContext);
188
+ const htmlTag = `<script id="${htmlElementId_pageContext}" type="application/json"${nonceAttr}>${pageContextClientSerialized}</script>`;
187
189
  // Used by contra.com https://github.com/gajus
188
190
  // @ts-expect-error
189
191
  pageContext._pageContextHtmlTag = htmlTag;
@@ -191,7 +193,8 @@ function getPageContextJsonScriptTag(pageContext) {
191
193
  }
192
194
  function getGlobalContextJsonScriptTag(pageContext) {
193
195
  const globalContextClientSerialized = sanitizeJson(getGlobalContextClientSerialized(pageContext, true));
194
- const htmlTag = `<script id="${htmlElementId_globalContext}" type="application/json">${globalContextClientSerialized}</script>`;
196
+ const nonceAttr = inferNonceAttr(pageContext);
197
+ const htmlTag = `<script id="${htmlElementId_globalContext}" type="application/json"${nonceAttr}>${globalContextClientSerialized}</script>`;
195
198
  return htmlTag;
196
199
  }
197
200
  function assertInjectFilterEntries(injectFilterEntries) {
@@ -3,7 +3,8 @@ export { inferPreloadTag };
3
3
  export { inferEarlyHintLink };
4
4
  export { scriptAttrs };
5
5
  import type { PageAsset } from '../../renderPage/getPageAssets.js';
6
+ import { type PageContextCspNonce } from '../../csp.js';
6
7
  declare const scriptAttrs = "type=\"module\" async";
7
8
  declare function inferPreloadTag(pageAsset: PageAsset): string;
8
- declare function inferAssetTag(pageAsset: PageAsset): string;
9
+ declare function inferAssetTag(pageAsset: PageAsset, pageContext: PageContextCspNonce): string;
9
10
  declare function inferEarlyHintLink(pageAsset: PageAsset): string;
@@ -3,6 +3,8 @@ export { inferPreloadTag };
3
3
  export { inferEarlyHintLink };
4
4
  export { scriptAttrs };
5
5
  import { assert } from '../../utils.js';
6
+ import { inferNonceAttr } from '../../csp.js';
7
+ // TODO/now rename scriptAttrs scriptCommonAttrs
6
8
  // We can't use `defer` here. With `defer`, the entry script won't start before `</body>` has been parsed, preventing progressive hydration during SSR streaming, see https://github.com/vikejs/vike/pull/1271
7
9
  const scriptAttrs = 'type="module" async';
8
10
  function inferPreloadTag(pageAsset) {
@@ -20,11 +22,12 @@ function inferPreloadTag(pageAsset) {
20
22
  .join(' ');
21
23
  return `<link ${attributes}>`;
22
24
  }
23
- function inferAssetTag(pageAsset) {
25
+ function inferAssetTag(pageAsset, pageContext) {
24
26
  const { src, assetType, mediaType } = pageAsset;
25
27
  if (assetType === 'script') {
26
28
  assert(mediaType === 'text/javascript');
27
- return `<script src="${src}" ${scriptAttrs}></script>`;
29
+ const nonceAttr = inferNonceAttr(pageContext);
30
+ return `<script src="${src}" ${scriptAttrs}${nonceAttr}></script>`;
28
31
  }
29
32
  if (assetType === 'style') {
30
33
  // WARNING: if changing following line, then also update https://github.com/vikejs/vike/blob/fae90a15d88e5e87ca9fcbb54cf2dc8773d2f229/vike/client/shared/removeFoucBuster.ts#L29
@@ -1,2 +1,3 @@
1
1
  export { mergeScriptTags };
2
- declare function mergeScriptTags(scriptTagsHtml: string): string;
2
+ import { type PageContextCspNonce } from '../../csp.js';
3
+ declare function mergeScriptTags(scriptTagsHtml: string, pageContext: PageContextCspNonce): string;
@@ -1,10 +1,11 @@
1
1
  export { mergeScriptTags };
2
+ import { inferNonceAttr } from '../../csp.js';
2
3
  import { assert } from '../../utils.js';
3
4
  import { scriptAttrs } from './inferHtmlTags.js';
4
5
  const scriptRE = /(<script\b(?:\s[^>]*>|>))(.*?)<\/script>/gims;
5
6
  const srcRE = /\bsrc\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
6
7
  const typeRE = /\btype\s*=\s*(?:"([^"]+)"|'([^']+)'|([^\s'">]+))/im;
7
- function mergeScriptTags(scriptTagsHtml) {
8
+ function mergeScriptTags(scriptTagsHtml, pageContext) {
8
9
  let scriptTag = '';
9
10
  const scripts = parseScripts(scriptTagsHtml);
10
11
  // We need to merge module scripts to ensure execution order
@@ -33,7 +34,8 @@ function mergeScriptTags(scriptTagsHtml) {
33
34
  }
34
35
  });
35
36
  if (contents.length > 0) {
36
- scriptTag += `<script ${scriptAttrs}>\n${contents.join('\n')}\n</script>`;
37
+ const nonceAttr = inferNonceAttr(pageContext);
38
+ scriptTag += `<script ${scriptAttrs}${nonceAttr}>\n${contents.join('\n')}\n</script>`;
37
39
  }
38
40
  }
39
41
  }
@@ -8,6 +8,7 @@ import type { UrlRedirect } from '../../../shared/route/abort.js';
8
8
  import type { GlobalContextServerInternal } from '../globalContext.js';
9
9
  import type { PageContextCreated } from '../renderPage/createPageContextServerSide.js';
10
10
  import type { PageContextBegin } from '../renderPage.js';
11
+ import type { PageContextCspNonce } from '../csp.js';
11
12
  type PageContextSerialization = PageContextCreated & {
12
13
  pageId: string;
13
14
  routeParams: Record<string, string>;
@@ -17,7 +18,7 @@ type PageContextSerialization = PageContextCreated & {
17
18
  _pageContextInit: Record<string, unknown>;
18
19
  _globalContext: GlobalContextServerInternal;
19
20
  _isPageContextJsonRequest: null | PageContextBegin['_isPageContextJsonRequest'];
20
- };
21
+ } & PageContextCspNonce;
21
22
  declare function getPageContextClientSerialized(pageContext: PageContextSerialization, isHtmlJsonScript: boolean): string;
22
23
  declare function getGlobalContextClientSerialized(pageContext: PageContextSerialization, isHtmlJsonScript: boolean): string;
23
24
  type PassToClient = string[];
@@ -1,6 +1,7 @@
1
1
  export { analyzePage };
2
- import type { PageFile } from '../../../shared/getPageFiles/getPageFileObject.js';
3
2
  import type { PageConfigRuntime } from '../../../types/PageConfig.js';
4
3
  import { type AnalysisResult } from '../../../shared/getPageFiles/analyzePageClientSide.js';
5
- import type { GlobalContextServerInternal } from '../globalContext.js';
6
- declare function analyzePage(pageFilesAll: PageFile[], pageConfig: null | PageConfigRuntime, pageId: string, globalContext: GlobalContextServerInternal): Promise<AnalysisResult>;
4
+ import type { PageContext_loadPageConfigsLazyServerSide } from './loadPageConfigsLazyServerSide.js';
5
+ declare function analyzePage(pageContext: PageContext_loadPageConfigsLazyServerSide & {
6
+ _pageConfig: null | PageConfigRuntime;
7
+ }): AnalysisResult;