vike 0.4.228 → 0.4.229-commit-a19745d

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 (248) hide show
  1. package/dist/cjs/__internal/index.js +2 -2
  2. package/dist/cjs/client/client-routing-runtime/globalContext.js +49 -0
  3. package/dist/cjs/client/server-routing-runtime/globalContext.js +41 -0
  4. package/dist/cjs/client/server-routing-runtime/utils.js +1 -1
  5. package/dist/cjs/client/shared/createGetGlobalContextClient.js +58 -0
  6. package/dist/cjs/client/shared/getJsonSerializedInHtml.js +31 -0
  7. package/dist/cjs/client/shared/utils.js +22 -0
  8. package/dist/cjs/node/plugin/index.js +3 -1
  9. package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
  10. package/dist/cjs/node/plugin/plugins/build/handleAssetsManifest.js +10 -5
  11. package/dist/cjs/node/plugin/plugins/build/pluginBuildApp.js +1 -1
  12. package/dist/cjs/node/plugin/plugins/build/pluginBuildConfig.js +3 -10
  13. package/dist/cjs/node/plugin/plugins/build/pluginBuildEntry.js +9 -5
  14. package/dist/cjs/node/plugin/plugins/build/pluginModuleBanner.js +9 -5
  15. package/dist/cjs/node/plugin/plugins/commonConfig/assertResolveAlias.js +1 -1
  16. package/dist/cjs/node/plugin/plugins/commonConfig.js +14 -3
  17. package/dist/cjs/node/plugin/plugins/devConfig/determineFsAllowList.js +2 -7
  18. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +6 -1
  19. package/dist/cjs/node/plugin/plugins/envVars.js +17 -19
  20. package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +3 -1
  21. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +11 -0
  22. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.js +2 -0
  23. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -1
  24. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
  25. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.js → pointerImports.js} +13 -0
  26. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +20 -19
  27. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +15 -12
  28. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +11 -11
  29. package/dist/cjs/node/plugin/plugins/replaceConstants.js +76 -0
  30. package/dist/cjs/node/plugin/shared/applyRegExWithMagicString.js +10 -0
  31. package/dist/cjs/node/plugin/shared/findPageFiles.js +1 -1
  32. package/dist/cjs/node/plugin/shared/getFilePath.js +2 -2
  33. package/dist/cjs/node/plugin/shared/resolveClientEntriesDev.js +8 -20
  34. package/dist/cjs/node/plugin/utils.js +1 -0
  35. package/dist/cjs/node/prerender/runPrerender.js +44 -41
  36. package/dist/cjs/node/prerender/utils.js +1 -1
  37. package/dist/cjs/node/runtime/globalContext.js +102 -125
  38. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +18 -5
  39. package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +2 -2
  40. package/dist/cjs/node/runtime/html/propKeys.js +47 -0
  41. package/dist/cjs/node/runtime/html/renderHtml.js +13 -3
  42. package/dist/cjs/node/runtime/html/{serializePageContextClientSide.js → serializeContext.js} +37 -67
  43. package/dist/cjs/node/runtime/index-deprecated.js +9 -38
  44. package/dist/cjs/node/runtime/index.js +56 -2
  45. package/dist/cjs/node/runtime/renderPage/analyzePage.js +1 -1
  46. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +8 -3
  47. package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +73 -0
  48. package/dist/cjs/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +2 -2
  49. package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
  50. package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +1 -1
  51. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +1 -17
  52. package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +1 -1
  53. package/dist/cjs/node/runtime/renderPage/getPageAssets.js +3 -3
  54. package/dist/cjs/node/runtime/renderPage/handleErrorWithoutErrorPage.js +1 -1
  55. package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
  56. package/dist/cjs/node/runtime/renderPage/log404/index.js +1 -1
  57. package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +1 -1
  58. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -68
  59. package/dist/cjs/node/runtime/renderPage.js +102 -81
  60. package/dist/cjs/node/runtime/universal-middleware.js +7 -1
  61. package/dist/cjs/node/runtime/utils.js +3 -2
  62. package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -1
  63. package/dist/cjs/shared/createGlobalContextShared.js +54 -0
  64. package/dist/cjs/shared/createPageContextShared.js +17 -0
  65. package/dist/cjs/shared/getPageFiles/fileTypes.js +1 -1
  66. package/dist/cjs/shared/hooks/executeHookGeneric.js +18 -0
  67. package/dist/cjs/shared/hooks/getHook.js +45 -27
  68. package/dist/cjs/shared/htmlElementIds.js +5 -0
  69. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +3 -7
  70. package/dist/cjs/shared/route/executeGuardHook.js +1 -1
  71. package/dist/cjs/shared/route/loadPageRoutes.js +2 -1
  72. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  73. package/dist/cjs/utils/catchInfiniteLoop.js +3 -3
  74. package/dist/cjs/utils/debug.js +1 -0
  75. package/dist/cjs/utils/getPublicProxy.js +27 -0
  76. package/dist/cjs/utils/isImportPath.js +21 -0
  77. package/dist/cjs/utils/isScriptFile.js +24 -21
  78. package/dist/cjs/utils/objectAssign.js +6 -10
  79. package/dist/cjs/utils/objectReplace.js +4 -4
  80. package/dist/cjs/utils/{isNpmPackage.js → parseNpmPackage.js} +24 -23
  81. package/dist/cjs/utils/path.js +12 -2
  82. package/dist/cjs/utils/requireResolve.js +148 -53
  83. package/dist/esm/__internal/index.js +3 -3
  84. package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +29 -10
  85. package/dist/esm/client/client-routing-runtime/createPageContext.js +23 -22
  86. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +5 -4
  87. package/dist/esm/client/client-routing-runtime/globalContext.d.ts +20 -0
  88. package/dist/esm/client/client-routing-runtime/globalContext.js +13 -0
  89. package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +2 -2
  90. package/dist/esm/client/client-routing-runtime/prefetch.js +2 -2
  91. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +8 -7
  92. package/dist/esm/client/client-routing-runtime/utils.d.ts +0 -1
  93. package/dist/esm/client/client-routing-runtime/utils.js +0 -1
  94. package/dist/esm/client/index.d.ts +1 -0
  95. package/dist/esm/client/index.js +4 -0
  96. package/dist/esm/client/node.js +1 -3
  97. package/dist/esm/client/server-routing-runtime/createPageContextClientSide.d.ts +36 -0
  98. package/dist/esm/client/server-routing-runtime/createPageContextClientSide.js +47 -0
  99. package/dist/esm/client/server-routing-runtime/entry.js +2 -2
  100. package/dist/esm/client/server-routing-runtime/globalContext.d.ts +17 -0
  101. package/dist/esm/client/server-routing-runtime/globalContext.js +5 -0
  102. package/dist/esm/client/server-routing-runtime/utils.d.ts +1 -1
  103. package/dist/esm/client/server-routing-runtime/utils.js +1 -1
  104. package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +23 -0
  105. package/dist/esm/client/shared/createGetGlobalContextClient.js +58 -0
  106. package/dist/esm/client/shared/executeOnRenderClientHook.js +5 -4
  107. package/dist/esm/client/shared/{getPageContextSerializedInHtml.d.ts → getJsonSerializedInHtml.d.ts} +2 -0
  108. package/dist/esm/client/shared/getJsonSerializedInHtml.js +29 -0
  109. package/dist/esm/client/shared/removeFoucBuster.js +1 -0
  110. package/dist/esm/client/shared/utils.d.ts +4 -0
  111. package/dist/esm/client/shared/utils.js +4 -0
  112. package/dist/esm/node/plugin/index.js +3 -1
  113. package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
  114. package/dist/esm/node/plugin/plugins/build/handleAssetsManifest.js +11 -6
  115. package/dist/esm/node/plugin/plugins/build/pluginBuildApp.js +2 -2
  116. package/dist/esm/node/plugin/plugins/build/pluginBuildConfig.js +4 -11
  117. package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.d.ts +1 -1
  118. package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.js +10 -6
  119. package/dist/esm/node/plugin/plugins/build/pluginModuleBanner.js +9 -5
  120. package/dist/esm/node/plugin/plugins/commonConfig/assertResolveAlias.js +2 -2
  121. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +2 -0
  122. package/dist/esm/node/plugin/plugins/commonConfig.js +15 -4
  123. package/dist/esm/node/plugin/plugins/devConfig/determineFsAllowList.js +3 -8
  124. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +7 -2
  125. package/dist/esm/node/plugin/plugins/envVars.js +18 -20
  126. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +4 -2
  127. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +11 -0
  128. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.d.ts +1 -1
  129. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles/ignorePatternsBuiltIn.js +2 -0
  130. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +2 -2
  131. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +1 -1
  132. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.d.ts → pointerImports.d.ts} +2 -0
  133. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformPointerImports.js → pointerImports.js} +14 -1
  134. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.d.ts +1 -1
  135. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolvePointerImport.js +20 -19
  136. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +15 -12
  137. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +11 -11
  138. package/dist/esm/node/plugin/plugins/replaceConstants.d.ts +3 -0
  139. package/dist/esm/node/plugin/plugins/replaceConstants.js +71 -0
  140. package/dist/esm/node/plugin/shared/applyRegExWithMagicString.d.ts +3 -0
  141. package/dist/esm/node/plugin/shared/applyRegExWithMagicString.js +8 -0
  142. package/dist/esm/node/plugin/shared/findPageFiles.js +2 -2
  143. package/dist/esm/node/plugin/shared/getFilePath.js +3 -3
  144. package/dist/esm/node/plugin/shared/resolveClientEntriesDev.d.ts +1 -1
  145. package/dist/esm/node/plugin/shared/resolveClientEntriesDev.js +9 -21
  146. package/dist/esm/node/plugin/utils.d.ts +1 -0
  147. package/dist/esm/node/plugin/utils.js +1 -0
  148. package/dist/esm/node/prerender/runPrerender.d.ts +314 -5
  149. package/dist/esm/node/prerender/runPrerender.js +48 -45
  150. package/dist/esm/node/prerender/utils.d.ts +1 -1
  151. package/dist/esm/node/prerender/utils.js +1 -1
  152. package/dist/esm/node/runtime/globalContext.d.ts +425 -47
  153. package/dist/esm/node/runtime/globalContext.js +103 -126
  154. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +18 -5
  155. package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.d.ts +2 -2
  156. package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +2 -2
  157. package/dist/esm/node/runtime/html/injectAssets.d.ts +3 -3
  158. package/dist/esm/node/runtime/html/propKeys.d.ts +8 -0
  159. package/dist/esm/node/runtime/html/propKeys.js +45 -0
  160. package/dist/esm/node/runtime/html/renderHtml.js +13 -3
  161. package/dist/esm/node/runtime/html/{serializePageContextClientSide.d.ts → serializeContext.d.ts} +7 -6
  162. package/dist/esm/node/runtime/html/{serializePageContextClientSide.js → serializeContext.js} +36 -67
  163. package/dist/esm/node/runtime/index-deprecated.d.ts +1 -16
  164. package/dist/esm/node/runtime/index-deprecated.js +9 -36
  165. package/dist/esm/node/runtime/index.d.ts +23 -1
  166. package/dist/esm/node/runtime/index.js +38 -3
  167. package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
  168. package/dist/esm/node/runtime/renderPage/analyzePage.js +1 -1
  169. package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +5 -4
  170. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +8 -3
  171. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +155 -0
  172. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +71 -0
  173. package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.js +3 -3
  174. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +1 -1
  175. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +3 -3
  176. package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +2 -2
  177. package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js +1 -17
  178. package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
  179. package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -2
  180. package/dist/esm/node/runtime/renderPage/getPageAssets.js +3 -3
  181. package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
  182. package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.js +1 -1
  183. package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +2 -2
  184. package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
  185. package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
  186. package/dist/esm/node/runtime/renderPage/log404/index.js +1 -1
  187. package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +3 -3
  188. package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +1 -1
  189. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +225 -179
  190. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +4 -69
  191. package/dist/esm/node/runtime/renderPage.d.ts +146 -7
  192. package/dist/esm/node/runtime/renderPage.js +105 -84
  193. package/dist/esm/node/runtime/universal-middleware.js +7 -1
  194. package/dist/esm/node/runtime/utils.d.ts +3 -2
  195. package/dist/esm/node/runtime/utils.js +3 -2
  196. package/dist/esm/shared/VikeNamespace.d.ts +35 -13
  197. package/dist/esm/shared/assertPageContextProvidedByUser.js +1 -1
  198. package/dist/esm/shared/createGlobalContextShared.d.ts +39 -0
  199. package/dist/esm/shared/createGlobalContextShared.js +51 -0
  200. package/dist/esm/shared/createPageContextShared.d.ts +9 -0
  201. package/dist/esm/shared/createPageContextShared.js +15 -0
  202. package/dist/esm/shared/getPageFiles/fileTypes.js +1 -1
  203. package/dist/esm/shared/hooks/executeHookGeneric.d.ts +8 -0
  204. package/dist/esm/shared/hooks/executeHookGeneric.js +16 -0
  205. package/dist/esm/shared/hooks/getHook.d.ts +5 -3
  206. package/dist/esm/shared/hooks/getHook.js +47 -29
  207. package/dist/esm/shared/htmlElementIds.d.ts +2 -0
  208. package/dist/esm/shared/htmlElementIds.js +2 -0
  209. package/dist/esm/shared/page-configs/Config.d.ts +12 -2
  210. package/dist/esm/shared/page-configs/getConfigDefinedAt.d.ts +1 -1
  211. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +3 -7
  212. package/dist/esm/shared/route/executeGuardHook.js +2 -2
  213. package/dist/esm/shared/route/loadPageRoutes.js +2 -1
  214. package/dist/esm/shared/types.d.ts +64 -32
  215. package/dist/esm/types/index.d.ts +1 -5
  216. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  217. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  218. package/dist/esm/utils/catchInfiniteLoop.js +4 -4
  219. package/dist/esm/utils/debug.d.ts +1 -1
  220. package/dist/esm/utils/debug.js +1 -0
  221. package/dist/esm/utils/getGlobalObject.d.ts +1 -1
  222. package/dist/esm/utils/getPublicProxy.d.ts +2 -0
  223. package/dist/esm/utils/getPublicProxy.js +25 -0
  224. package/dist/esm/utils/isImportPath.d.ts +4 -0
  225. package/dist/esm/utils/isImportPath.js +19 -0
  226. package/dist/esm/utils/isScriptFile.d.ts +5 -5
  227. package/dist/esm/utils/isScriptFile.js +23 -20
  228. package/dist/esm/utils/objectAssign.d.ts +1 -1
  229. package/dist/esm/utils/objectAssign.js +6 -10
  230. package/dist/esm/utils/objectReplace.d.ts +1 -1
  231. package/dist/esm/utils/objectReplace.js +4 -4
  232. package/dist/esm/utils/parseNpmPackage.d.ts +19 -0
  233. package/dist/esm/utils/{isNpmPackage.js → parseNpmPackage.js} +24 -24
  234. package/dist/esm/utils/path.d.ts +1 -1
  235. package/dist/esm/utils/path.js +12 -2
  236. package/dist/esm/utils/requireResolve.d.ts +20 -7
  237. package/dist/esm/utils/requireResolve.js +148 -53
  238. package/package.json +14 -13
  239. package/dist/cjs/node/runtime/index-common.js +0 -27
  240. package/dist/cjs/utils/makePublicCopy.js +0 -32
  241. package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +0 -19
  242. package/dist/esm/client/server-routing-runtime/getPageContext.js +0 -44
  243. package/dist/esm/client/shared/getPageContextSerializedInHtml.js +0 -20
  244. package/dist/esm/node/runtime/index-common.d.ts +0 -8
  245. package/dist/esm/node/runtime/index-common.js +0 -10
  246. package/dist/esm/utils/isNpmPackage.d.ts +0 -17
  247. package/dist/esm/utils/makePublicCopy.d.ts +0 -3
  248. package/dist/esm/utils/makePublicCopy.js +0 -30
@@ -0,0 +1,47 @@
1
+ export { createPageContextClientSide };
2
+ import { assertUsage, assertWarning, augmentType, objectAssign } from './utils.js';
3
+ import { getPageContextSerializedInHtml } from '../shared/getJsonSerializedInHtml.js';
4
+ import { loadUserFilesClientSide } from '../shared/loadUserFilesClientSide.js';
5
+ import { getCurrentUrl } from '../shared/getCurrentUrl.js';
6
+ import { createPageContextShared } from '../../shared/createPageContextShared.js';
7
+ import { getGlobalContextClientInternal } from './globalContext.js';
8
+ const urlFirst = getCurrentUrl({ withoutHash: true });
9
+ async function createPageContextClientSide() {
10
+ const globalContext = await getGlobalContextClientInternal();
11
+ const pageContextCreated = {
12
+ /* Don't spread globalContext for now? Or never spread it as it leads to confusion? The convenience isn't worth the added confusion?
13
+ ...globalContext, // least precedence
14
+ */
15
+ globalContext,
16
+ _pageFilesAll: globalContext._pageFilesAll,
17
+ _pageConfigs: globalContext._pageConfigs,
18
+ _pageConfigGlobal: globalContext._pageConfigGlobal,
19
+ _allPageIds: globalContext._allPageIds,
20
+ isPrerendering: false,
21
+ isClientSide: true,
22
+ isHydration: true,
23
+ isBackwardNavigation: null,
24
+ _hasPageContextFromServer: true,
25
+ _hasPageContextFromClient: false
26
+ };
27
+ objectAssign(pageContextCreated, getPageContextSerializedInHtml());
28
+ objectAssign(pageContextCreated, await loadPageUserFiles(pageContextCreated.pageId, pageContextCreated));
29
+ const pageContextAugmented = await createPageContextShared(pageContextCreated, globalContext._pageConfigGlobal);
30
+ augmentType(pageContextCreated, pageContextAugmented);
31
+ assertPristineUrl();
32
+ return pageContextCreated;
33
+ }
34
+ function assertPristineUrl() {
35
+ const urlCurrent = getCurrentUrl({ withoutHash: true });
36
+ assertUsage(urlFirst === urlCurrent, `The URL was manipulated before the hydration finished ('${urlFirst}' to '${urlCurrent}'). Ensure the hydration has finished before manipulating the URL. Consider using the onHydrationEnd() hook.`);
37
+ }
38
+ async function loadPageUserFiles(pageId, pageContext) {
39
+ const pageContextAddendum = {};
40
+ objectAssign(pageContextAddendum, await loadUserFilesClientSide(pageId, pageContext._pageFilesAll, pageContext._pageConfigs, pageContext._pageConfigGlobal));
41
+ pageContext._pageFilesAll
42
+ .filter((p) => p.fileType !== '.page.server')
43
+ .forEach((p) => {
44
+ assertWarning(!p.fileExports?.onBeforeRender, `export { onBeforeRender } of ${p.filePath} is loaded in the browser but never executed (because you are using Server-side Routing). In order to reduce the size of you browser-side JavaScript, define onBeforeRender() in a .page.server.js file instead, see https://vike.dev/onBeforeRender-isomorphic#server-routing`, { onlyOnce: true });
45
+ });
46
+ return pageContextAddendum;
47
+ }
@@ -1,6 +1,6 @@
1
1
  import { assertServerRouting } from '../../utils/assertRoutingType.js';
2
2
  assertServerRouting();
3
- import { getPageContext } from './getPageContext.js';
3
+ import { createPageContextClientSide } from './createPageContextClientSide.js';
4
4
  import { executeOnRenderClientHook } from '../shared/executeOnRenderClientHook.js';
5
5
  import { assertHook } from '../../shared/hooks/getHook.js';
6
6
  import { assertSingleInstance_onClientEntryServerRouting } from './utils.js';
@@ -12,7 +12,7 @@ if (import.meta.env.DEV)
12
12
  removeFoucBuster();
13
13
  hydrate();
14
14
  async function hydrate() {
15
- const pageContext = await getPageContext();
15
+ const pageContext = await createPageContextClientSide();
16
16
  await executeOnRenderClientHook(pageContext, false);
17
17
  assertHook(pageContext, 'onHydrationEnd');
18
18
  await pageContext.exports.onHydrationEnd?.(pageContext);
@@ -0,0 +1,17 @@
1
+ export { getGlobalContextClientInternal };
2
+ export type { GlobalContextClientWithServerRouting };
3
+ import type { GlobalContextSharedPublic } from '../../shared/createGlobalContextShared.js';
4
+ type GlobalContextClientWithServerRouting = GlobalContextSharedPublic & Pick<GlobalContextClientInternal, 'isClientSide'> & Vike.GlobalContext & Vike.GlobalContextClient & {};
5
+ type GlobalContextClientInternal = Awaited<ReturnType<typeof getGlobalContextClientInternal>>;
6
+ declare const getGlobalContextClientInternal: () => Promise<{
7
+ isGlobalContext: true;
8
+ _virtualFileExports: unknown;
9
+ _pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
10
+ _pageConfigs: import("../../__internal/index.js").PageConfig[];
11
+ _pageConfigGlobal: import("../../shared/page-configs/PageConfig.js").PageConfigGlobalRuntime;
12
+ _allPageIds: string[];
13
+ config: import("../../types/index.js").ConfigResolved;
14
+ pages: import("../../shared/page-configs/getPageConfigUserFriendly.js").PageConfigsUserFriendly;
15
+ } & {
16
+ isClientSide: true;
17
+ } & object>;
@@ -0,0 +1,5 @@
1
+ export { getGlobalContextClientInternal };
2
+ import { createGetGlobalContextClient } from '../shared/createGetGlobalContextClient.js';
3
+ // @ts-ignore
4
+ import * as virtualFileExports from 'virtual:vike:importUserCode:client:server-routing';
5
+ const getGlobalContextClientInternal = createGetGlobalContextClient(virtualFileExports, false);
@@ -1,6 +1,5 @@
1
1
  export * from '../../utils/assert.js';
2
2
  export * from '../../utils/assertSingleInstance.js';
3
- export * from '../../shared/hooks/executeHook.js';
4
3
  export * from '../../utils/checkType.js';
5
4
  export * from '../../utils/getGlobalObject.js';
6
5
  export * from '../../utils/hasProp.js';
@@ -11,3 +10,4 @@ export * from '../../utils/parseUrl.js';
11
10
  export * from '../../utils/slice.js';
12
11
  export * from '../../utils/unique.js';
13
12
  export * from '../../utils/getPropAccessNotation.js';
13
+ export * from '../../utils/augmentType.js';
@@ -4,7 +4,6 @@ import { onLoad } from './onLoad.js';
4
4
  onLoad();
5
5
  export * from '../../utils/assert.js';
6
6
  export * from '../../utils/assertSingleInstance.js';
7
- export * from '../../shared/hooks/executeHook.js';
8
7
  export * from '../../utils/checkType.js'; // Only used by Server Routing (not needed for Client Routing)
9
8
  export * from '../../utils/getGlobalObject.js';
10
9
  export * from '../../utils/hasProp.js';
@@ -15,3 +14,4 @@ export * from '../../utils/parseUrl.js';
15
14
  export * from '../../utils/slice.js';
16
15
  export * from '../../utils/unique.js'; // Only used by Server Routing (not needed for Client Routing)
17
16
  export * from '../../utils/getPropAccessNotation.js';
17
+ export * from '../../utils/augmentType.js';
@@ -0,0 +1,23 @@
1
+ export { getGlobalContext };
2
+ export { getGlobalContextSync };
3
+ export { createGetGlobalContextClient };
4
+ import { type GlobalContextShared } from '../../shared/createGlobalContextShared.js';
5
+ declare function createGetGlobalContextClient<GlobalContextAddendum extends object>(virtualFileExports: unknown, isClientRouting: boolean, addGlobalContext?: (globalContext: GlobalContextShared) => Promise<GlobalContextAddendum>): () => Promise<{
6
+ isGlobalContext: true;
7
+ _virtualFileExports: unknown;
8
+ _pageFilesAll: import("../../shared/getPageFiles.js").PageFile[];
9
+ _pageConfigs: import("../../__internal/index.js").PageConfig[];
10
+ _pageConfigGlobal: import("../../shared/page-configs/PageConfig.js").PageConfigGlobalRuntime;
11
+ _allPageIds: string[];
12
+ config: import("../../types/index.js").ConfigResolved;
13
+ pages: import("../../shared/page-configs/getPageConfigUserFriendly.js").PageConfigsUserFriendly;
14
+ } & Awaited<{
15
+ /**
16
+ * Whether the environment is client-side or server-side / pre-rendering.
17
+ *
18
+ * We recommend using `import.meta.env.SSR` instead, see https://vike.dev/globalContext
19
+ */
20
+ isClientSide: true;
21
+ } & Awaited<GlobalContextAddendum>>>;
22
+ declare function getGlobalContext(): Promise<never>;
23
+ declare function getGlobalContextSync(): never;
@@ -0,0 +1,58 @@
1
+ // Public usage
2
+ export { getGlobalContext };
3
+ export { getGlobalContextSync };
4
+ // Internal usage
5
+ export { createGetGlobalContextClient };
6
+ import { createGlobalContextShared, getGlobalContextSyncErrMsg } from '../../shared/createGlobalContextShared.js';
7
+ import { getGlobalContextSerializedInHtml } from './getJsonSerializedInHtml.js';
8
+ import { assert, assertUsage, genPromise, getGlobalObject, objectAssign } from './utils.js';
9
+ const globalObject = getGlobalObject('createGetGlobalContextClient.ts', (() => {
10
+ const { promise: globalContextPromise, resolve: globalContextPromiseResolve } = genPromise();
11
+ return {
12
+ globalContextPromise,
13
+ globalContextPromiseResolve
14
+ };
15
+ })());
16
+ function createGetGlobalContextClient(virtualFileExports, isClientRouting, addGlobalContext) {
17
+ assert(globalObject.isClientRouting === undefined || globalObject.isClientRouting === isClientRouting);
18
+ globalObject.isClientRouting = isClientRouting;
19
+ // Eagerly call onCreateGlobalContext() hook
20
+ getGlobalContext();
21
+ return getGlobalContext;
22
+ async function getGlobalContext() {
23
+ // Cache
24
+ if (globalObject.globalContext &&
25
+ // Don't break HMR
26
+ globalObject.globalContext._virtualFileExports !== virtualFileExports) {
27
+ return globalObject.globalContext;
28
+ }
29
+ // Create
30
+ const globalContext = await createGlobalContextShared(virtualFileExports, globalObject, async (globalContext) => {
31
+ const globalContextAddendum = {
32
+ /**
33
+ * Whether the environment is client-side or server-side / pre-rendering.
34
+ *
35
+ * We recommend using `import.meta.env.SSR` instead, see https://vike.dev/globalContext
36
+ */
37
+ isClientSide: true
38
+ };
39
+ objectAssign(globalContextAddendum, getGlobalContextSerializedInHtml());
40
+ objectAssign(globalContextAddendum, await addGlobalContext?.(globalContext));
41
+ return globalContextAddendum;
42
+ });
43
+ assert(globalObject.globalContext);
44
+ globalObject.globalContextPromiseResolve(globalObject.globalContext);
45
+ // Return
46
+ return globalContext;
47
+ }
48
+ }
49
+ // The type is never used: it's the type of the server-side getGlobalContext() that is used.
50
+ async function getGlobalContext() {
51
+ const globalContext = await globalObject.globalContextPromise;
52
+ return globalContext;
53
+ }
54
+ function getGlobalContextSync() {
55
+ const { globalContext } = globalObject;
56
+ assertUsage(globalContext, getGlobalContextSyncErrMsg);
57
+ return globalContext;
58
+ }
@@ -1,18 +1,19 @@
1
1
  export { executeOnRenderClientHook };
2
- import { assert, assertUsage, executeHook } from '../server-routing-runtime/utils.js';
3
- import { getHook } from '../../shared/hooks/getHook.js';
2
+ import { assert, assertUsage } from '../server-routing-runtime/utils.js';
3
+ import { getHookFromPageContext } from '../../shared/hooks/getHook.js';
4
4
  import { preparePageContextForUserConsumptionClientSide } from './preparePageContextForUserConsumptionClientSide.js';
5
+ import { executeHook } from '../../shared/hooks/executeHook.js';
5
6
  async function executeOnRenderClientHook(pageContext, isClientRouting) {
6
7
  const pageContextForUserConsumption = preparePageContextForUserConsumptionClientSide(pageContext, isClientRouting);
7
8
  let hook = null;
8
9
  let hookName;
9
10
  {
10
- const renderHook = getHook(pageContext, 'render');
11
+ const renderHook = getHookFromPageContext(pageContext, 'render');
11
12
  hook = renderHook;
12
13
  hookName = 'render';
13
14
  }
14
15
  {
15
- const renderHook = getHook(pageContext, 'onRenderClient');
16
+ const renderHook = getHookFromPageContext(pageContext, 'onRenderClient');
16
17
  if (renderHook) {
17
18
  hook = renderHook;
18
19
  hookName = 'onRenderClient';
@@ -1,5 +1,7 @@
1
1
  export { getPageContextSerializedInHtml };
2
+ export { getGlobalContextSerializedInHtml };
2
3
  declare function getPageContextSerializedInHtml(): {
3
4
  pageId: string;
4
5
  routeParams: Record<string, string>;
5
6
  };
7
+ declare function getGlobalContextSerializedInHtml(): object;
@@ -0,0 +1,29 @@
1
+ export { getPageContextSerializedInHtml };
2
+ export { getGlobalContextSerializedInHtml };
3
+ import { parse } from '@brillout/json-serializer/parse';
4
+ import { hasProp, assert, assertUsage } from './utils.js';
5
+ import { htmlElementId_globalContext, htmlElementId_pageContext } from '../../shared/htmlElementIds.js';
6
+ // elements should exist because:
7
+ // 1. <script id="vike_pageContext" type="application/json"> appears before the <script> that loads Vike's client runtime (which includes this file)
8
+ // 2. <script id="vike_pageContext" type="application/json"> is neither async nor defer
9
+ // See https://github.com/vikejs/vike/pull/1271
10
+ function getPageContextSerializedInHtml() {
11
+ const pageContextSerializedInHtml = findAndParseJson(htmlElementId_pageContext);
12
+ assert(hasProp(pageContextSerializedInHtml, 'pageId', 'string'));
13
+ assert(hasProp(pageContextSerializedInHtml, 'routeParams', 'string{}'));
14
+ return pageContextSerializedInHtml;
15
+ }
16
+ function getGlobalContextSerializedInHtml() {
17
+ const globalContextSerializedInHtml = findAndParseJson(htmlElementId_globalContext);
18
+ return globalContextSerializedInHtml;
19
+ }
20
+ function findAndParseJson(id) {
21
+ const elem = document.getElementById(id);
22
+ assertUsage(elem,
23
+ // It seems like it can be missing when HTML is malformed: https://github.com/vikejs/vike/issues/913
24
+ `Couldn't find #${id} (which Vike automatically injects in the HTML): make sure it exists (i.e. don't remove it and make sure your HTML isn't malformed)`);
25
+ const jsonStr = elem.textContent;
26
+ assert(jsonStr);
27
+ const json = parse(jsonStr);
28
+ return json;
29
+ }
@@ -6,6 +6,7 @@ import { assert } from './utils.js';
6
6
  // - https://github.com/rakkasjs/rakkasjs/blob/7d75ccc915e93bca04e6bab37dc6abdb68a85e4a/packages/rakkasjs/src/features/pages/middleware.tsx#L701
7
7
  // - https://github.com/remix-run/remix/issues/8830
8
8
  function removeFoucBuster() {
9
+ // In production removeFoucBuster() is expected to be have been removed by tree shaking
9
10
  assert(import.meta.env.DEV);
10
11
  let sleep = 2;
11
12
  setTimeout(runClean, sleep);
@@ -1,2 +1,6 @@
1
1
  export * from '../../utils/assert.js';
2
2
  export * from '../../utils/parseUrl.js';
3
+ export * from '../../utils/getGlobalObject.js';
4
+ export * from '../../utils/objectAssign.js';
5
+ export * from '../../utils/hasProp.js';
6
+ export * from '../../utils/genPromise.js';
@@ -1,2 +1,6 @@
1
1
  export * from '../../utils/assert.js';
2
2
  export * from '../../utils/parseUrl.js';
3
+ export * from '../../utils/getGlobalObject.js';
4
+ export * from '../../utils/objectAssign.js';
5
+ export * from '../../utils/hasProp.js';
6
+ export * from '../../utils/genPromise.js';
@@ -21,6 +21,7 @@ import { setResolveClientEntriesDev } from '../runtime/renderPage/getPageAssets.
21
21
  import { resolveClientEntriesDev } from './shared/resolveClientEntriesDev.js';
22
22
  import { workaroundCssModuleHmr } from './plugins/workaroundCssModuleHmr.js';
23
23
  import { workaroundVite6HmrRegression } from './plugins/workaroundVite6HmrRegression.js';
24
+ import { replaceConstants } from './plugins/replaceConstants.js';
24
25
  // We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
25
26
  setResolveClientEntriesDev(resolveClientEntriesDev);
26
27
  // Return `PluginInterop` instead of `Plugin` to avoid type mismatch upon different Vite versions
@@ -38,7 +39,8 @@ function plugin(vikeVitePluginOptions = {}) {
38
39
  envVarsPlugin(),
39
40
  fileEnv(),
40
41
  workaroundCssModuleHmr(),
41
- workaroundVite6HmrRegression()
42
+ workaroundVite6HmrRegression(),
43
+ replaceConstants()
42
44
  ];
43
45
  Object.assign(plugins, { __vikeVitePluginOptions: vikeVitePluginOptions });
44
46
  return plugins;
@@ -2,7 +2,7 @@ export { baseUrls };
2
2
  import { resolveBase } from '../../shared/resolveBase.js';
3
3
  import { assert } from '../utils.js';
4
4
  import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
5
- import { getVikeConfigPublic } from './commonConfig.js';
5
+ import { getVikeConfigInternal } from './commonConfig.js';
6
6
  function baseUrls() {
7
7
  let basesResolved;
8
8
  return {
@@ -12,7 +12,7 @@ function baseUrls() {
12
12
  const isDev = config._isDev;
13
13
  assert(typeof isDev === 'boolean');
14
14
  const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
15
- const vike = getVikeConfigPublic(config);
15
+ const vike = getVikeConfigInternal(config);
16
16
  basesResolved = resolveBase(baseViteOriginal, vike.config.baseServer ?? null, vike.config.baseAssets ?? null);
17
17
  // We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
18
18
  process.env.BASE_SERVER = basesResolved.baseServer;
@@ -15,7 +15,7 @@ import pc from '@brillout/picocolors';
15
15
  import { isV1Design } from '../importUserCode/v1-design/getVikeConfig.js';
16
16
  import { getOutDirs } from '../../shared/getOutDirs.js';
17
17
  import { isViteServerBuild_onlySsrEnv, isViteServerBuild } from '../../shared/isViteServerBuild.js';
18
- import { getVikeConfigPublic } from '../commonConfig.js';
18
+ import { getVikeConfigInternal } from '../commonConfig.js';
19
19
  import { set_macro_ASSETS_MANIFEST } from './pluginBuildEntry.js';
20
20
  assertIsSingleModuleInstance('build/handleAssetsManifest.ts');
21
21
  let assetsJsonFilePath;
@@ -281,7 +281,7 @@ async function writeManifestFile(manifest, manifestFilePath) {
281
281
  await fs.writeFile(manifestFilePath, manifestFileContent, 'utf-8');
282
282
  }
283
283
  function handleAssetsManifest_getBuildConfig(config) {
284
- const vike = getVikeConfigPublic(config);
284
+ const vike = getVikeConfigInternal(config);
285
285
  const isFixEnabled = handleAssetsManifest_isFixEnabled(config);
286
286
  return {
287
287
  // https://github.com/vikejs/vike/issues/1339
@@ -296,16 +296,21 @@ function handleAssetsManifest_getBuildConfig(config) {
296
296
  };
297
297
  }
298
298
  async function handleAssetsManifest(config, viteEnv, options, bundle) {
299
- if (isViteServerBuild_onlySsrEnv(config, viteEnv)) {
299
+ const isSsREnv = isViteServerBuild_onlySsrEnv(config, viteEnv);
300
+ if (isSsREnv) {
300
301
  assert(!assetsJsonFilePath);
301
302
  const outDirs = getOutDirs(config, viteEnv);
302
303
  assetsJsonFilePath = path.posix.join(outDirs.outDirRoot, 'assets.json');
303
304
  await writeAssetsManifestFile(outDirs, assetsJsonFilePath, config);
304
305
  }
305
306
  if (isViteServerBuild(config, viteEnv)) {
306
- assert(assetsJsonFilePath);
307
- // Replace __VITE_ASSETS_MANIFEST__ in all server-side bundles
308
- await set_macro_ASSETS_MANIFEST(options, bundle, assetsJsonFilePath);
307
+ // Replace __VITE_ASSETS_MANIFEST__ in server builds
308
+ // - Always replace it in dist/server/
309
+ // - Also in some other server builds such as dist/vercel/ from vike-vercel
310
+ // - Don't replace it in dist/rsc/ from vike-react-rsc since __VITE_ASSETS_MANIFEST__ doesn't exist there
311
+ const noop = await set_macro_ASSETS_MANIFEST(options, bundle, assetsJsonFilePath);
312
+ if (isSsREnv)
313
+ assert(!noop); // dist/server should always contain __VITE_ASSETS_MANIFEST__
309
314
  }
310
315
  }
311
316
  async function writeAssetsManifestFile(outDirs, assetsJsonFilePath, config) {
@@ -2,7 +2,7 @@ export { pluginBuildApp };
2
2
  import { runPrerender_forceExit } from '../../../prerender/runPrerender.js';
3
3
  import { resolveOutDir } from '../../shared/getOutDirs.js';
4
4
  import { assert } from '../../utils.js';
5
- import { getVikeConfigPublic } from '../commonConfig.js';
5
+ import { getVikeConfigInternal } from '../commonConfig.js';
6
6
  import { isPrerenderForceExit } from './pluginAutoFullBuild.js';
7
7
  function pluginBuildApp() {
8
8
  return [
@@ -10,7 +10,7 @@ function pluginBuildApp() {
10
10
  name: 'vike:build:pluginBuildApp',
11
11
  apply: 'build',
12
12
  config(config) {
13
- const vike = getVikeConfigPublic(config);
13
+ const vike = getVikeConfigInternal(config);
14
14
  if (!vike.config.vite6BuilderApp)
15
15
  return;
16
16
  return {
@@ -2,7 +2,7 @@ export { pluginBuildConfig };
2
2
  export { assertRollupInput };
3
3
  export { analyzeClientEntries };
4
4
  export { manifestTempFile };
5
- import { assert, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsNpmPackageImport, requireResolveNonUserFile } from '../../utils.js';
5
+ import { assert, addOnBeforeLogHook, removeFileExtention, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsImportPathNpmPackage, requireResolveVikeDistFile } from '../../utils.js';
6
6
  import { getVikeConfig } from '../importUserCode/v1-design/getVikeConfig.js';
7
7
  import { findPageFiles } from '../../shared/findPageFiles.js';
8
8
  import { getVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
@@ -13,8 +13,6 @@ import { getConfigValueBuildTime } from '../../../../shared/page-configs/getConf
13
13
  import { isViteServerBuild } from '../../shared/isViteServerBuild.js';
14
14
  import { resolveOutDir } from '../../shared/getOutDirs.js';
15
15
  import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig } from './handleAssetsManifest.js';
16
- // @ts-ignore import.meta.url is shimmed at dist/cjs by dist-cjs-fixup.js.
17
- const importMetaUrl = import.meta.url;
18
16
  const manifestTempFile = '_temp_manifest.json';
19
17
  function pluginBuildConfig() {
20
18
  let config;
@@ -81,8 +79,8 @@ async function getEntries(config) {
81
79
  ...clientEntries,
82
80
  ...pageFileEntries
83
81
  };
84
- const clientRoutingEntry = resolve(`dist/esm/client/client-routing-runtime/entry.js`);
85
- const serverRoutingEntry = resolve(`dist/esm/client/server-routing-runtime/entry.js`);
82
+ const clientRoutingEntry = requireResolveVikeDistFile('dist/esm/client/client-routing-runtime/entry.js');
83
+ const serverRoutingEntry = requireResolveVikeDistFile('dist/esm/client/server-routing-runtime/entry.js');
86
84
  if (hasClientRouting) {
87
85
  entries['entries/entry-client-routing'] = clientRoutingEntry;
88
86
  }
@@ -156,7 +154,7 @@ async function getPageFileEntries(config, includeAssetsImportedByServer) {
156
154
  }
157
155
  function getEntryFromClientEntry(clientEntry, config, addExtractAssetsQuery) {
158
156
  if (!clientEntry.startsWith('/')) {
159
- assertIsNpmPackageImport(clientEntry);
157
+ assertIsImportPathNpmPackage(clientEntry);
160
158
  const entryTarget = clientEntry;
161
159
  const entryName = prependEntriesDir(clientEntry);
162
160
  return { entryName, entryTarget };
@@ -192,11 +190,6 @@ function getEntryFromPageConfig(pageConfig, isForClientSide) {
192
190
  assert(!entryName.endsWith('/'));
193
191
  return { entryName, entryTarget };
194
192
  }
195
- function resolve(filePath) {
196
- assert(filePath.startsWith('dist/'));
197
- // [RELATIVE_PATH_FROM_DIST] Current directory: node_modules/vike/dist/esm/node/plugin/plugins/build/
198
- return requireResolveNonUserFile(`../../../../../../${filePath}`, importMetaUrl);
199
- }
200
193
  function addLogHook() {
201
194
  const tty = process.stdout.isTTY && !process.env.CI; // Equals https://github.com/vitejs/vite/blob/193d55c7b9cbfec5b79ebfca276d4a721e7de14d/packages/vite/src/node/plugins/reporter.ts#L27
202
195
  if (!tty)
@@ -4,4 +4,4 @@ import type { Plugin, Rollup } from 'vite';
4
4
  type Bundle = Rollup.OutputBundle;
5
5
  type Options = Rollup.NormalizedOutputOptions;
6
6
  declare function pluginBuildEntry(): Plugin[];
7
- declare function set_macro_ASSETS_MANIFEST(options: Options, bundle: Bundle, assetsJsonFilePath: string): Promise<void>;
7
+ declare function set_macro_ASSETS_MANIFEST(options: Options, bundle: Bundle, assetsJsonFilePath: string | undefined): Promise<boolean>;
@@ -2,11 +2,9 @@ export { pluginBuildEntry };
2
2
  export { set_macro_ASSETS_MANIFEST };
3
3
  import { serverProductionEntryPlugin } from '@brillout/vite-plugin-server-entry/plugin';
4
4
  import { virtualFileIdImportUserCodeServer } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
5
- import { assert, PROJECT_VERSION, requireResolveNonUserFile } from '../../utils.js';
5
+ import { assert, PROJECT_VERSION, requireResolveVikeDistFile } from '../../utils.js';
6
6
  import fs from 'fs/promises';
7
7
  import path from 'path';
8
- // @ts-ignore import.meta.url is shimmed at dist/cjs by dist-cjs-fixup.js.
9
- const importMetaUrl = import.meta.url;
10
8
  import { isUsingClientRouter } from '../extractExportNamesPlugin.js';
11
9
  import { assertBuildInfo } from '../../../runtime/globalContext.js';
12
10
  import { getOutDirs } from '../../shared/getOutDirs.js';
@@ -63,6 +61,12 @@ async function set_macro_ASSETS_MANIFEST(options, bundle, assetsJsonFilePath) {
63
61
  const { dir } = options;
64
62
  assert(dir);
65
63
  const chunkPath = find_ASSETS_MANIFEST(bundle);
64
+ // Some server builds don't contain __VITE_ASSETS_MANIFEST__ such as dist/rsc/ from vike-react-rsc
65
+ if (!chunkPath) {
66
+ const noop = true; // no operation
67
+ return noop;
68
+ }
69
+ assert(assetsJsonFilePath);
66
70
  const chunkFilePath = path.join(dir, chunkPath);
67
71
  const [assetsJsonString, chunkFileContent] = await Promise.all([
68
72
  await fs.readFile(assetsJsonFilePath, 'utf8'),
@@ -71,6 +75,8 @@ async function set_macro_ASSETS_MANIFEST(options, bundle, assetsJsonFilePath) {
71
75
  const serverEntryFileContentPatched = chunkFileContent.replace(ASSETS_MANIFEST, assetsJsonString);
72
76
  assert(serverEntryFileContentPatched !== chunkFileContent);
73
77
  await fs.writeFile(chunkFilePath, serverEntryFileContentPatched);
78
+ const noop = false;
79
+ return noop;
74
80
  }
75
81
  function find_ASSETS_MANIFEST(bundle) {
76
82
  let chunkPath;
@@ -81,13 +87,11 @@ function find_ASSETS_MANIFEST(bundle) {
81
87
  chunkPath = filePath;
82
88
  }
83
89
  }
84
- assert(chunkPath);
85
90
  return chunkPath;
86
91
  }
87
92
  function getImportPath(config) {
88
93
  // We resolve filePathAbsolute even if we don't use it: we use require.resolve() as an assertion that the relative path is correct
89
- // [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/plugins/pluginBuildEntry/index.js
90
- const filePathAbsolute = requireResolveNonUserFile(`../../../../../../dist/esm/__internal/index.js`, importMetaUrl);
94
+ const filePathAbsolute = requireResolveVikeDistFile('dist/esm/__internal/index.js');
91
95
  if (
92
96
  // Let's implement a new config if a user needs the import to be a relative path instead of 'vike/__internal' (AFAIK a relative path is needed only if a framework has npm package 'vike' as direct dependency instead of a peer dependency and if the user of that framework uses pnpm)
93
97
  true) {
@@ -16,21 +16,25 @@ function pluginModuleBanner() {
16
16
  transform: {
17
17
  order: 'post',
18
18
  handler(code, id, options) {
19
- if (!isViteServerBuild_safe(config, options))
19
+ if (!isViteServerBuild_safe(config, options) &&
20
+ // Inject module banners if user sets `build.minify` to `false` for inspecting dist/client/
21
+ config.build.minify) {
20
22
  return;
23
+ }
21
24
  if (id.startsWith('\0'))
22
25
  id = id;
23
26
  id = removeVirtualIdTag(id);
24
27
  if (id.startsWith(config.root))
25
28
  id = id.slice(config.root.length + 1);
26
- const s = new MagicString(code);
29
+ id = id.replaceAll('*/', '*\\/'); // https://github.com/vikejs/vike/issues/2377
30
+ const magicString = new MagicString(code);
27
31
  // Use legal comment so that esbuild doesn't remove it.
28
32
  // - Terser still removes the comment, but I guess users use terser to minify JavaScript so I guess it's a good thing that comment is removed.
29
33
  // - https://esbuild.github.io/api/#legal-comments
30
- s.prepend(`/*! ${id} [vike:pluginModuleBanner] */\n`);
34
+ magicString.prepend(`/*! ${id} [vike:pluginModuleBanner] */\n`);
31
35
  return {
32
- code: s.toString(),
33
- map: s.generateMap({ hires: true, source: id })
36
+ code: magicString.toString(),
37
+ map: magicString.generateMap({ hires: true, source: id })
34
38
  };
35
39
  }
36
40
  }
@@ -1,5 +1,5 @@
1
1
  export { assertResolveAlias };
2
- import { assert, assertUsage, assertWarning, isArray, isValidPathAlias } from '../../utils.js';
2
+ import { assert, assertUsage, assertWarning, isArray, isPathAliasRecommended } from '../../utils.js';
3
3
  import pc from '@brillout/picocolors';
4
4
  // Recommend users to avoid un-distinguishable path aliases.
5
5
  // There are a lot of libraries that don't or cannot follow that recommendation, for example:
@@ -59,7 +59,7 @@ function assertResolveAlias(config) {
59
59
  // - determineOptimizeDeps()
60
60
  // - extractAssets
61
61
  // - in general: using un-distinguishable path aliases is asking for trouble
62
- if (!isValidPathAlias(find)) {
62
+ if (!isPathAliasRecommended(find)) {
63
63
  if (find.startsWith('@')) {
64
64
  const msg = `${errPrefix} defines an invalid resolve.alias ${deprecation}: a path alias cannot start with ${pc.cyan('@')}, ${errSuffix1}`;
65
65
  assertWarning(false, msg, { onlyOnce: true });
@@ -1,5 +1,6 @@
1
1
  export { commonConfig };
2
2
  export { getVikeConfigPublic };
3
+ export { getVikeConfigInternal };
3
4
  export type { VikeConfigPublic };
4
5
  import { type InlineConfig, type Plugin, type ResolvedConfig, type UserConfig } from 'vite';
5
6
  import { type VikeConfigObject } from './importUserCode/v1-design/getVikeConfig.js';
@@ -34,4 +35,5 @@ declare function commonConfig(vikeVitePluginOptions: unknown): Plugin[];
34
35
  *
35
36
  * https://vike.dev/getVikeConfig
36
37
  */
38
+ declare function getVikeConfigInternal(config: ResolvedConfig | UserConfig): VikeConfigPublic;
37
39
  declare function getVikeConfigPublic(config: ResolvedConfig | UserConfig): VikeConfigPublic;
@@ -1,6 +1,7 @@
1
1
  export { commonConfig };
2
2
  export { getVikeConfigPublic };
3
- import { assert, assertUsage, assertWarning, findPackageJson, hasProp, isDevCheck, isDocker, isObject } from '../utils.js';
3
+ export { getVikeConfigInternal };
4
+ import { assert, assertUsage, assertWarning, findPackageJson, hasProp, isDevCheck, isDocker, isObject, isVitest } from '../utils.js';
4
5
  import { assertRollupInput } from './build/pluginBuildConfig.js';
5
6
  import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
6
7
  import pc from '@brillout/picocolors';
@@ -85,7 +86,7 @@ function commonConfig(vikeVitePluginOptions) {
85
86
  order: 'post',
86
87
  handler(configFromUser) {
87
88
  let configFromVike = { server: {}, preview: {} };
88
- const vike = getVikeConfigPublic(configFromUser);
89
+ const vike = getVikeConfigInternal(configFromUser);
89
90
  if (vike.config.port !== undefined) {
90
91
  // https://vike.dev/port
91
92
  setDefault('port', vike.config.port, configFromUser, configFromVike);
@@ -153,11 +154,16 @@ function assertVikeCliOrApi(config) {
153
154
  if (isVikeCliOrApi())
154
155
  return;
155
156
  if (isViteCliCall()) {
157
+ assert(!isVitest());
156
158
  assertWarning(false, `Vite's CLI is deprecated ${pc.underline('https://vike.dev/migration/cli')}`, {
157
159
  onlyOnce: true
158
160
  });
159
161
  return;
160
162
  }
163
+ if (isVitest()) {
164
+ assertWarning(false, `Unexpected Vitest setup: you seem to be using Vitest together with Vike's Vite plugin but without using Vike's JavaScript API which is unexpected, see ${pc.underline('https://vike.dev/vitest')}`, { onlyOnce: true });
165
+ return;
166
+ }
161
167
  if (config.server.middlewareMode) {
162
168
  assertWarning(false, `${pc.cyan('vite.createServer()')} is deprecated ${pc.underline('https://vike.dev/migration/cli#api')}`, {
163
169
  onlyOnce: true
@@ -191,7 +197,7 @@ function temp_supportOldInterface(config) {
191
197
  }
192
198
  // TODO/soon rename:
193
199
  // - `getVikeConfig()` => `resolveVikeConfig()` ?
194
- // - `getVikeConfigPublic()` => `getVikeConfig()`
200
+ // - `getVikeConfigInternal()` => `getVikeConfig()`
195
201
  // - `VikeConfigPublic` => `VikeConfig` ?
196
202
  // - `VikeConfigObject` => `VikeConfigInternal` ?
197
203
  /**
@@ -199,11 +205,16 @@ function temp_supportOldInterface(config) {
199
205
  *
200
206
  * https://vike.dev/getVikeConfig
201
207
  */
202
- function getVikeConfigPublic(config) {
208
+ function getVikeConfigInternal(config) {
203
209
  const vikeConfig = config._vike;
204
210
  assert(vikeConfig);
205
211
  return vikeConfig;
206
212
  }
213
+ function getVikeConfigPublic(config) {
214
+ const vikeConfig = config._vike;
215
+ assertUsage(vikeConfig, "getVikeConfig() can only be used when Vite is running with Vike's Vite plugin");
216
+ return vikeConfig;
217
+ }
207
218
  // Only emit dist/server/entry.mjs if necessary
208
219
  function emitServerEntryOnlyIfNeeded(config) {
209
220
  if (config.vitePluginServerEntry?.inject &&