vike 0.4.238 → 0.4.239-commit-33e55d4

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 (197) hide show
  1. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +3 -2
  2. package/dist/cjs/node/prerender/runPrerender.js +1 -0
  3. package/dist/cjs/node/runtime/globalContext.js +10 -0
  4. package/dist/cjs/node/runtime/index.js +3 -3
  5. package/dist/cjs/node/runtime/page-files/setup.js +3 -1
  6. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +2 -9
  7. package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +2 -2
  8. package/dist/cjs/node/runtime/renderPage/csp.js +47 -0
  9. package/dist/cjs/node/runtime/renderPage/execHookOnRenderHtml.js +2 -2
  10. package/dist/cjs/node/runtime/renderPage/getEarlyHints.js +1 -1
  11. package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +2 -2
  12. package/dist/cjs/node/runtime/renderPage/headersResponse.js +48 -0
  13. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/getHtmlTags.js +16 -13
  14. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/getViteDevScript.js +1 -1
  15. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/inferHtmlTags.js +8 -6
  16. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/injectAssets__public.js +1 -1
  17. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/injectHtmlTags.js +1 -1
  18. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/mergeScriptTags.js +5 -3
  19. package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets.js +2 -2
  20. package/dist/cjs/node/runtime/{html → renderPage/html}/propKeys.js +1 -1
  21. package/dist/cjs/node/runtime/{html → renderPage/html}/renderHtml.js +1 -1
  22. package/dist/cjs/node/runtime/{html → renderPage/html}/serializeContext.js +6 -6
  23. package/dist/cjs/node/runtime/{html → renderPage/html}/stream/react-streaming.js +1 -1
  24. package/dist/cjs/node/runtime/{html → renderPage/html}/stream.js +1 -1
  25. package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +17 -38
  26. package/dist/cjs/node/runtime/renderPage/renderPageAfterRoute.js +2 -2
  27. package/dist/cjs/node/runtime/renderPage.js +1 -1
  28. package/dist/cjs/node/vite/onLoad.js +1 -1
  29. package/dist/cjs/node/vite/plugins/pluginBaseUrls.js +32 -28
  30. package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +1 -1
  31. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
  32. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
  33. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
  34. package/dist/cjs/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
  35. package/dist/cjs/node/vite/plugins/pluginBuild/pluginModuleBanner.js +17 -9
  36. package/dist/cjs/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
  37. package/dist/cjs/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
  38. package/dist/cjs/node/vite/plugins/pluginCommon.js +7 -21
  39. package/dist/cjs/node/vite/plugins/pluginDev.js +51 -47
  40. package/dist/cjs/node/vite/plugins/pluginEnvVars.js +62 -57
  41. package/dist/cjs/node/vite/plugins/pluginExtractAssets.js +107 -93
  42. package/dist/cjs/node/vite/plugins/pluginExtractExportNames.js +27 -13
  43. package/dist/cjs/node/vite/plugins/pluginFileEnv.js +107 -84
  44. package/dist/cjs/node/vite/plugins/pluginNonRunnableDev.js +40 -21
  45. package/dist/cjs/node/vite/plugins/pluginPreview.js +30 -24
  46. package/dist/cjs/node/vite/plugins/pluginReplaceConstants.js +59 -33
  47. package/dist/cjs/node/vite/plugins/pluginSetGlobalContext.js +4 -2
  48. package/dist/cjs/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +1 -1
  49. package/dist/cjs/node/vite/plugins/pluginVirtualFiles.js +54 -36
  50. package/dist/cjs/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
  51. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +3 -0
  52. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +1 -1
  53. package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +20 -22
  54. package/dist/cjs/shared/createGlobalContextShared.js +4 -22
  55. package/dist/cjs/shared/createPageContextShared.js +2 -2
  56. package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +62 -43
  57. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  58. package/dist/cjs/utils/assert.js +16 -1
  59. package/dist/cjs/utils/assertNodeVersion.js +3 -1
  60. package/dist/cjs/utils/assertVersion.js +26 -5
  61. package/dist/cjs/utils/joinEnglish.js +2 -1
  62. package/dist/cjs/utils/virtualFileId.js +15 -11
  63. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.d.ts +40 -17
  64. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.js +1 -1
  65. package/dist/esm/client/runtime-client-routing/getPageContextCurrent.d.ts +2 -2
  66. package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.d.ts +99 -85
  67. package/dist/esm/client/runtime-client-routing/globalContext.d.ts +39 -11
  68. package/dist/esm/client/runtime-client-routing/prefetch/getPrefetchSettings.d.ts +2 -2
  69. package/dist/esm/client/runtime-client-routing/prefetch.d.ts +2 -2
  70. package/dist/esm/client/runtime-client-routing/prefetch.js +2 -2
  71. package/dist/esm/client/runtime-client-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
  72. package/dist/esm/client/runtime-client-routing/renderPageClientSide.d.ts +44 -29
  73. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.d.ts +40 -17
  74. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +1 -1
  75. package/dist/esm/client/runtime-server-routing/globalContext.d.ts +39 -11
  76. package/dist/esm/client/runtime-server-routing/preparePageContextForPublicUsageClient.d.ts +2 -2
  77. package/dist/esm/client/shared/createGetGlobalContextClient.d.ts +39 -11
  78. package/dist/esm/client/shared/execHookOnRenderClient.d.ts +2 -2
  79. package/dist/esm/client/shared/loadPageConfigsLazyClientSide.d.ts +1 -1
  80. package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +2 -3
  81. package/dist/esm/client/shared/preparePageContextForPublicUsageClientShared.d.ts +2 -2
  82. package/dist/esm/node/prerender/resolvePrerenderConfig.js +4 -3
  83. package/dist/esm/node/prerender/runPrerender.d.ts +61 -16
  84. package/dist/esm/node/prerender/runPrerender.js +2 -1
  85. package/dist/esm/node/runtime/globalContext.d.ts +167 -42
  86. package/dist/esm/node/runtime/globalContext.js +11 -1
  87. package/dist/esm/node/runtime/index.d.ts +3 -3
  88. package/dist/esm/node/runtime/index.js +3 -3
  89. package/dist/esm/node/runtime/page-files/setup.js +3 -1
  90. package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +1 -1
  91. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +2 -9
  92. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +56 -12
  93. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +2 -2
  94. package/dist/esm/node/runtime/renderPage/csp.d.ts +12 -0
  95. package/dist/esm/node/runtime/renderPage/csp.js +45 -0
  96. package/dist/esm/node/runtime/renderPage/execHookOnRenderHtml.d.ts +2 -2
  97. package/dist/esm/node/runtime/renderPage/execHookOnRenderHtml.js +2 -2
  98. package/dist/esm/node/runtime/renderPage/execHookServer.d.ts +2 -2
  99. package/dist/esm/node/runtime/renderPage/getEarlyHints.js +1 -1
  100. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.d.ts +2 -2
  101. package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +2 -2
  102. package/dist/esm/node/runtime/renderPage/headersResponse.d.ts +10 -0
  103. package/dist/esm/node/runtime/renderPage/headersResponse.js +46 -0
  104. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getHtmlTags.d.ts +1 -1
  105. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getHtmlTags.js +16 -13
  106. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getViteDevScript.d.ts +1 -1
  107. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/getViteDevScript.js +1 -1
  108. package/dist/esm/node/runtime/renderPage/html/injectAssets/inferHtmlTags.d.ts +10 -0
  109. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/inferHtmlTags.js +7 -5
  110. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectAssets__public.js +1 -1
  111. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectHtmlTags.js +1 -1
  112. package/dist/esm/node/runtime/renderPage/html/injectAssets/mergeScriptTags.d.ts +3 -0
  113. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/mergeScriptTags.js +6 -4
  114. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets.d.ts +2 -2
  115. package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets.js +2 -2
  116. package/dist/esm/node/runtime/{html → renderPage/html}/propKeys.js +1 -1
  117. package/dist/esm/node/runtime/{html → renderPage/html}/renderHtml.d.ts +1 -1
  118. package/dist/esm/node/runtime/{html → renderPage/html}/renderHtml.js +1 -1
  119. package/dist/esm/node/runtime/{html → renderPage/html}/serializeContext.d.ts +6 -5
  120. package/dist/esm/node/runtime/{html → renderPage/html}/serializeContext.js +6 -6
  121. package/dist/esm/node/runtime/{html → renderPage/html}/stream/react-streaming.js +1 -1
  122. package/dist/esm/node/runtime/{html → renderPage/html}/stream.js +1 -1
  123. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +66 -17
  124. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +18 -39
  125. package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +2 -2
  126. package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.d.ts +122 -32
  127. package/dist/esm/node/runtime/renderPage/renderPageAfterRoute.js +2 -2
  128. package/dist/esm/node/runtime/renderPage.d.ts +56 -12
  129. package/dist/esm/node/runtime/renderPage.js +1 -1
  130. package/dist/esm/node/vite/onLoad.js +1 -1
  131. package/dist/esm/node/vite/plugins/pluginBaseUrls.js +32 -28
  132. package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +1 -1
  133. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +24 -20
  134. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +4 -2
  135. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistFileNames.js +76 -74
  136. package/dist/esm/node/vite/plugins/pluginBuild/pluginDistPackageJsonFile.js +18 -14
  137. package/dist/esm/node/vite/plugins/pluginBuild/pluginModuleBanner.js +18 -10
  138. package/dist/esm/node/vite/plugins/pluginBuild/pluginProdBuildEntry.js +4 -2
  139. package/dist/esm/node/vite/plugins/pluginBuild/pluginSuppressRollupWarning.js +20 -18
  140. package/dist/esm/node/vite/plugins/pluginCommon.js +8 -22
  141. package/dist/esm/node/vite/plugins/pluginDev.js +51 -47
  142. package/dist/esm/node/vite/plugins/pluginEnvVars.js +62 -57
  143. package/dist/esm/node/vite/plugins/pluginExtractAssets.js +107 -91
  144. package/dist/esm/node/vite/plugins/pluginExtractExportNames.js +27 -13
  145. package/dist/esm/node/vite/plugins/pluginFileEnv.js +107 -84
  146. package/dist/esm/node/vite/plugins/pluginNonRunnableDev.js +41 -22
  147. package/dist/esm/node/vite/plugins/pluginPreview.js +30 -24
  148. package/dist/esm/node/vite/plugins/pluginReplaceConstants.d.ts +11 -0
  149. package/dist/esm/node/vite/plugins/pluginReplaceConstants.js +58 -33
  150. package/dist/esm/node/vite/plugins/pluginSetGlobalContext.js +4 -2
  151. package/dist/esm/node/vite/plugins/pluginVirtualFiles/generateVirtualFileGlobalEntryWithOldDesign.js +2 -2
  152. package/dist/esm/node/vite/plugins/pluginVirtualFiles.js +56 -38
  153. package/dist/esm/node/vite/plugins/pluginWorkaroundCssModuleHmr.js +8 -6
  154. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +3 -0
  155. package/dist/esm/node/vite/shared/resolveVikeConfigInternal/crawlPlusFiles.js +2 -2
  156. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +4 -8
  157. package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +22 -24
  158. package/dist/esm/shared/createGlobalContextShared.d.ts +75 -19
  159. package/dist/esm/shared/createGlobalContextShared.js +5 -23
  160. package/dist/esm/shared/createPageContextShared.d.ts +2 -7
  161. package/dist/esm/shared/createPageContextShared.js +2 -2
  162. package/dist/esm/shared/getPageFiles.d.ts +1 -1
  163. package/dist/esm/shared/hooks/execHook.d.ts +2 -2
  164. package/dist/esm/shared/hooks/getHook.d.ts +3 -3
  165. package/dist/esm/shared/page-configs/resolveVikeConfigPublic.d.ts +91 -31
  166. package/dist/esm/shared/page-configs/resolveVikeConfigPublic.js +62 -43
  167. package/dist/esm/types/Config/ConfigResolved.d.ts +8 -0
  168. package/dist/esm/types/Config.d.ts +14 -6
  169. package/dist/esm/types/PageContext.d.ts +8 -25
  170. package/dist/esm/types/VikeNamespace.d.ts +0 -27
  171. package/dist/esm/types/index.d.ts +2 -2
  172. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  173. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  174. package/dist/esm/utils/assert.js +16 -1
  175. package/dist/esm/utils/assertNodeVersion.js +3 -1
  176. package/dist/esm/utils/assertVersion.d.ts +4 -3
  177. package/dist/esm/utils/assertVersion.js +23 -5
  178. package/dist/esm/utils/joinEnglish.js +2 -1
  179. package/dist/esm/utils/virtualFileId.d.ts +4 -0
  180. package/dist/esm/utils/virtualFileId.js +14 -11
  181. package/package.json +5 -5
  182. package/dist/cjs/types/Config/helpers.js +0 -2
  183. package/dist/esm/node/runtime/html/injectAssets/inferHtmlTags.d.ts +0 -9
  184. package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.d.ts +0 -2
  185. package/dist/esm/types/Config/PageContextConfig.d.ts +0 -15
  186. package/dist/esm/types/Config/helpers.d.ts +0 -10
  187. package/dist/esm/types/Config/helpers.js +0 -1
  188. /package/dist/cjs/node/runtime/{html → renderPage/html}/injectAssets/sanitizeJson.js +0 -0
  189. /package/dist/cjs/types/Config/{PageContextConfig.js → ConfigResolved.js} +0 -0
  190. /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectAssets__public.d.ts +0 -0
  191. /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/injectHtmlTags.d.ts +0 -0
  192. /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/sanitizeJson.d.ts +0 -0
  193. /package/dist/esm/node/runtime/{html → renderPage/html}/injectAssets/sanitizeJson.js +0 -0
  194. /package/dist/esm/node/runtime/{html → renderPage/html}/propKeys.d.ts +0 -0
  195. /package/dist/esm/node/runtime/{html → renderPage/html}/stream/react-streaming.d.ts +0 -0
  196. /package/dist/esm/node/runtime/{html → renderPage/html}/stream.d.ts +0 -0
  197. /package/dist/esm/types/Config/{PageContextConfig.js → ConfigResolved.js} +0 -0
@@ -18,7 +18,7 @@ const isNewError_js_1 = require("./renderPage/isNewError.js");
18
18
  const assertArguments_js_1 = require("./renderPage/assertArguments.js");
19
19
  const index_js_2 = require("./renderPage/log404/index.js");
20
20
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
21
- const serializeContext_js_1 = require("./html/serializeContext.js");
21
+ const serializeContext_js_1 = require("./renderPage/html/serializeContext.js");
22
22
  const error_page_js_1 = require("../../shared/error-page.js");
23
23
  const handleErrorWithoutErrorPage_js_1 = require("./renderPage/handleErrorWithoutErrorPage.js");
24
24
  const loadPageConfigsLazyServerSide_js_1 = require("./renderPage/loadPageConfigsLazyServerSide.js");
@@ -15,7 +15,7 @@ function onLoad() {
15
15
  // TO-DO/eventually: let's also use this.meta.viteVersion
16
16
  // - https://github.com/vitejs/vite/pull/20088
17
17
  // - https://github.com/vitejs/vite/blob/main/packages/vite/CHANGELOG.md#700-2025-06-24
18
- (0, assertVersion_js_1.assertVersion)('Vite', vite_1.version, '6.0.0');
18
+ (0, assertVersion_js_1.assertVersion)('Vite', vite_1.version, ['6.3.0']);
19
19
  // Ensure we don't bloat the server runtime with heavy dependencies such Vite and esbuild
20
20
  (0, assertSetup_js_1.assertIsNotProductionRuntime)();
21
21
  }
@@ -9,35 +9,39 @@ function pluginBaseUrls() {
9
9
  return {
10
10
  name: 'vike:pluginBaseUrls',
11
11
  enforce: 'post',
12
- async config(config) {
13
- const isDev = config._isDev;
14
- (0, utils_js_1.assert)(typeof isDev === 'boolean');
15
- const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
16
- const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
17
- basesResolved = (0, resolveBase_js_1.resolveBase)(baseViteOriginal, vikeConfig.config.baseServer ?? null, vikeConfig.config.baseAssets ?? null);
18
- // We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
19
- process.env.BASE_SERVER = basesResolved.baseServer;
20
- process.env.BASE_ASSETS = basesResolved.baseAssets;
21
- return {
22
- envPrefix: [
23
- 'VITE_', // Vite doesn't seem to merge in its default, see https://github.com/vikejs/vike/issues/554
24
- 'BASE_SERVER',
25
- 'BASE_ASSETS',
26
- ],
27
- base: basesResolved.baseAssets, // Make Vite inject baseAssets to imports e.g. `import logoUrl from './logo.svg.js'`
28
- _baseViteOriginal: baseViteOriginal,
29
- };
12
+ config: {
13
+ async handler(config) {
14
+ const isDev = config._isDev;
15
+ (0, utils_js_1.assert)(typeof isDev === 'boolean');
16
+ const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
17
+ const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
18
+ basesResolved = (0, resolveBase_js_1.resolveBase)(baseViteOriginal, vikeConfig.config.baseServer ?? null, vikeConfig.config.baseAssets ?? null);
19
+ // We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
20
+ process.env.BASE_SERVER = basesResolved.baseServer;
21
+ process.env.BASE_ASSETS = basesResolved.baseAssets;
22
+ return {
23
+ envPrefix: [
24
+ 'VITE_', // Vite doesn't seem to merge in its default, see https://github.com/vikejs/vike/issues/554
25
+ 'BASE_SERVER',
26
+ 'BASE_ASSETS',
27
+ ],
28
+ base: basesResolved.baseAssets, // Make Vite inject baseAssets to imports e.g. `import logoUrl from './logo.svg.js'`
29
+ _baseViteOriginal: baseViteOriginal,
30
+ };
31
+ },
30
32
  },
31
- async configResolved(config) {
32
- const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
33
- const basesResolved2 = resolveBaseFromResolvedConfig(vikeConfig.config.baseServer ?? null, vikeConfig.config.baseAssets ?? null, config);
34
- (0, utils_js_1.assert)(basesResolved2.baseServer === basesResolved.baseServer);
35
- (0, utils_js_1.assert)(basesResolved2.baseAssets === basesResolved.baseAssets);
36
- /* In dev, Vite seems buggy around setting vite.config.js#base to an absolute URL (e.g. http://localhost:8080/cdn/)
37
- * - In dev, Vite removes the URL origin. (I.e. it resolves the user config `vite.config.js#base: 'http://localhost:8080/cdn/'` to resolved config `config.base === '/cdn/'`.)
38
- * - Instead of having an internal Vike assertion fail, we let the user discover Vite's buggy behavior.
39
- assert(config.base === baseAssets)
40
- */
33
+ configResolved: {
34
+ async handler(config) {
35
+ const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
36
+ const basesResolved2 = resolveBaseFromResolvedConfig(vikeConfig.config.baseServer ?? null, vikeConfig.config.baseAssets ?? null, config);
37
+ (0, utils_js_1.assert)(basesResolved2.baseServer === basesResolved.baseServer);
38
+ (0, utils_js_1.assert)(basesResolved2.baseAssets === basesResolved.baseAssets);
39
+ /* In dev, Vite seems buggy around setting vite.config.js#base to an absolute URL (e.g. http://localhost:8080/cdn/)
40
+ * - In dev, Vite removes the URL origin. (I.e. it resolves the user config `vite.config.js#base: 'http://localhost:8080/cdn/'` to resolved config `config.base === '/cdn/'`.)
41
+ * - Instead of having an internal Vike assertion fail, we let the user discover Vite's buggy behavior.
42
+ assert(config.base === baseAssets)
43
+ */
44
+ },
41
45
  },
42
46
  };
43
47
  }
@@ -24,7 +24,7 @@ const getManifestFilePathRelative_js_1 = require("../../shared/getManifestFilePa
24
24
  const globalObject = (0, utils_js_1.getGlobalObject)('build/handleAssetsManifest.ts', {
25
25
  assetsJsonFilePath: undefined,
26
26
  });
27
- // true => use workaround config.build.ssrEmitAssets
27
+ // yes => use workaround config.build.ssrEmitAssets
28
28
  // false => use workaround extractAssets plugin
29
29
  function handleAssetsManifest_isFixEnabled() {
30
30
  // Allow user to toggle between the two workarounds? E.g. based on https://vike.dev/includeAssetsImportedByServer.
@@ -51,35 +51,39 @@ function pluginBuildApp() {
51
51
  {
52
52
  name: 'vike:build:pluginBuildApp',
53
53
  apply: 'build',
54
- config(config) {
55
- return {
56
- environments: {
57
- ssr: {
58
- consumer: 'server',
59
- build: {
60
- outDir: (0, getOutDirs_js_1.resolveOutDir)(config, true),
61
- ssr: true,
54
+ config: {
55
+ handler(config) {
56
+ return {
57
+ environments: {
58
+ ssr: {
59
+ consumer: 'server',
60
+ build: {
61
+ outDir: (0, getOutDirs_js_1.resolveOutDir)(config, true),
62
+ ssr: true,
63
+ },
62
64
  },
63
- },
64
- client: {
65
- consumer: 'client',
66
- build: {
67
- outDir: (0, getOutDirs_js_1.resolveOutDir)(config, false),
68
- copyPublicDir: true,
69
- ssr: false,
65
+ client: {
66
+ consumer: 'client',
67
+ build: {
68
+ outDir: (0, getOutDirs_js_1.resolveOutDir)(config, false),
69
+ copyPublicDir: true,
70
+ ssr: false,
71
+ },
70
72
  },
71
73
  },
72
- },
73
- };
74
+ };
75
+ },
74
76
  },
75
77
  },
76
78
  {
77
79
  name: 'vike:build:pluginBuildApp:autoFullBuild:pre',
78
80
  apply: 'build',
79
81
  enforce: 'pre',
80
- async configResolved(config_) {
81
- config = config_;
82
- await abortViteBuildSsr();
82
+ configResolved: {
83
+ async handler(config_) {
84
+ config = config_;
85
+ await abortViteBuildSsr();
86
+ },
83
87
  },
84
88
  // TO-DO/eventually: stop using this writeBundle() hack and, instead, use the buildApp() implementation above.
85
89
  // - Could it cause issues if a tool uses the writeBundle() hack together with getVikeConfig() ?
@@ -42,8 +42,10 @@ function pluginBuildConfig() {
42
42
  return { build };
43
43
  },
44
44
  },
45
- buildStart() {
46
- (0, utils_js_1.onSetupBuild)();
45
+ buildStart: {
46
+ handler() {
47
+ (0, utils_js_1.onSetupBuild)();
48
+ },
47
49
  },
48
50
  },
49
51
  ];
@@ -17,88 +17,90 @@ function pluginDistFileNames() {
17
17
  name: 'vike:build:pluginDistFileNames',
18
18
  apply: 'build',
19
19
  enforce: 'post',
20
- configResolved(config) {
21
- const rollupOutputs = getRollupOutputs(config);
22
- // We need to support multiple outputs: @vite/plugin-legacy adds an output, see https://github.com/vikejs/vike/issues/477#issuecomment-1406434802
23
- rollupOutputs.forEach((rollupOutput) => {
24
- if (!('entryFileNames' in rollupOutput)) {
25
- rollupOutput.entryFileNames = (chunkInfo) => getEntryFileName(chunkInfo, config, true);
26
- }
27
- if (!('chunkFileNames' in rollupOutput)) {
28
- rollupOutput.chunkFileNames = (chunkInfo) => getChunkFileName(chunkInfo, config);
29
- }
30
- if (!('assetFileNames' in rollupOutput)) {
31
- rollupOutput.assetFileNames = (chunkInfo) => getAssetFileName(chunkInfo, config);
32
- rollupOutput.assetFileNames.isTheOneSetByVike = true;
33
- (0, utils_js_1.assert)(rollupOutput.assetFileNames.isTheOneSetByVike);
34
- }
35
- else {
36
- // If a user needs this:
37
- // - assertUsage() that the naming provided by the user ends with `.[hash][extname]`
38
- // - It's needed for getHash() of handleAssetsManifest()
39
- // - Asset URLs should always contain a hash: it's paramount for caching assets.
40
- // - If rollupOutput.assetFileNames is a function then use a wrapper function to apply the assertUsage()
41
- (0, utils_js_1.assertUsage)(rollupOutput.assetFileNames.isTheOneSetByVike, "Setting Vite's configuration build.rollupOptions.output.assetFileNames is currently forbidden. Reach out if you need to use it.");
42
- }
43
- {
44
- const manualChunksOriginal = rollupOutput.manualChunks;
45
- rollupOutput.manualChunks = function (id, ...args) {
46
- if (manualChunksOriginal) {
47
- if ((0, utils_js_1.isCallable)(manualChunksOriginal)) {
48
- const result = manualChunksOriginal.call(this, id, ...args);
49
- if (result !== undefined)
50
- return result;
51
- }
52
- else {
53
- (0, utils_js_1.assertUsage)(false, "The Vite's configuration build.rollupOptions.output.manualChunks must be a function. Reach out if you need to set it to another value.");
54
- }
55
- }
56
- // Disable CSS bundling to workaround https://github.com/vikejs/vike/issues/1815
57
- // TO-DO/eventually: let's bundle CSS again once Rolldown replaces Rollup
58
- if (id.endsWith('.css')) {
59
- const userRootDir = config.root;
60
- if (id.startsWith(userRootDir)) {
61
- (0, utils_js_1.assertPosixPath)(id);
62
- (0, getFilePath_js_1.assertModuleId)(id);
63
- let name;
64
- const isNodeModules = id.match(/node_modules\/([^\/]+)\/(?!.*node_modules)/);
65
- if (isNodeModules) {
66
- name = isNodeModules[1];
20
+ configResolved: {
21
+ handler(config) {
22
+ const rollupOutputs = getRollupOutputs(config);
23
+ // We need to support multiple outputs: @vite/plugin-legacy adds an output, see https://github.com/vikejs/vike/issues/477#issuecomment-1406434802
24
+ rollupOutputs.forEach((rollupOutput) => {
25
+ if (!('entryFileNames' in rollupOutput)) {
26
+ rollupOutput.entryFileNames = (chunkInfo) => getEntryFileName(chunkInfo, config, true);
27
+ }
28
+ if (!('chunkFileNames' in rollupOutput)) {
29
+ rollupOutput.chunkFileNames = (chunkInfo) => getChunkFileName(chunkInfo, config);
30
+ }
31
+ if (!('assetFileNames' in rollupOutput)) {
32
+ rollupOutput.assetFileNames = (chunkInfo) => getAssetFileName(chunkInfo, config);
33
+ rollupOutput.assetFileNames.isTheOneSetByVike = true;
34
+ (0, utils_js_1.assert)(rollupOutput.assetFileNames.isTheOneSetByVike);
35
+ }
36
+ else {
37
+ // If a user needs this:
38
+ // - assertUsage() that the naming provided by the user ends with `.[hash][extname]`
39
+ // - It's needed for getHash() of handleAssetsManifest()
40
+ // - Asset URLs should always contain a hash: it's paramount for caching assets.
41
+ // - If rollupOutput.assetFileNames is a function then use a wrapper function to apply the assertUsage()
42
+ (0, utils_js_1.assertUsage)(rollupOutput.assetFileNames.isTheOneSetByVike, "Setting Vite's configuration build.rollupOptions.output.assetFileNames is currently forbidden. Reach out if you need to use it.");
43
+ }
44
+ {
45
+ const manualChunksOriginal = rollupOutput.manualChunks;
46
+ rollupOutput.manualChunks = function (id, ...args) {
47
+ if (manualChunksOriginal) {
48
+ if ((0, utils_js_1.isCallable)(manualChunksOriginal)) {
49
+ const result = manualChunksOriginal.call(this, id, ...args);
50
+ if (result !== undefined)
51
+ return result;
67
52
  }
68
53
  else {
69
- const filePath = (0, getFilePath_js_1.getModuleFilePathAbsolute)(id, config);
70
- name = filePath;
71
- name = name.split('.').slice(0, -1).join('.'); // remove file extension
72
- name = name.split('/').filter(Boolean).join('_');
54
+ (0, utils_js_1.assertUsage)(false, "The Vite's configuration build.rollupOptions.output.manualChunks must be a function. Reach out if you need to set it to another value.");
73
55
  }
74
- // Make fileHash the same between local development and CI
75
- const idStable = node_path_1.default.posix.relative(userRootDir, id);
76
- // Don't remove `?` queries because each `id` should belong to a unique bundle.
77
- const hash = getIdHash(idStable);
78
- return `${name}-${hash}`;
79
56
  }
80
- else {
81
- let name;
82
- const isVirtualModule = id.match(/virtual:([^:]+):/);
83
- if (isVirtualModule) {
84
- name = isVirtualModule[1];
85
- (0, utils_js_1.assert)(name);
86
- }
87
- else if (
88
- // https://github.com/vikejs/vike/issues/1818#issuecomment-2298478321
89
- id.startsWith('/__uno')) {
90
- name = 'uno';
57
+ // Disable CSS bundling to workaround https://github.com/vikejs/vike/issues/1815
58
+ // TO-DO/eventually: let's bundle CSS again once Rolldown replaces Rollup
59
+ if (id.endsWith('.css')) {
60
+ const userRootDir = config.root;
61
+ if (id.startsWith(userRootDir)) {
62
+ (0, utils_js_1.assertPosixPath)(id);
63
+ (0, getFilePath_js_1.assertModuleId)(id);
64
+ let name;
65
+ const isNodeModules = id.match(/node_modules\/([^\/]+)\/(?!.*node_modules)/);
66
+ if (isNodeModules) {
67
+ name = isNodeModules[1];
68
+ }
69
+ else {
70
+ const filePath = (0, getFilePath_js_1.getModuleFilePathAbsolute)(id, config);
71
+ name = filePath;
72
+ name = name.split('.').slice(0, -1).join('.'); // remove file extension
73
+ name = name.split('/').filter(Boolean).join('_');
74
+ }
75
+ // Make fileHash the same between local development and CI
76
+ const idStable = node_path_1.default.posix.relative(userRootDir, id);
77
+ // Don't remove `?` queries because each `id` should belong to a unique bundle.
78
+ const hash = getIdHash(idStable);
79
+ return `${name}-${hash}`;
91
80
  }
92
81
  else {
93
- name = 'style';
82
+ let name;
83
+ const isVirtualModule = id.match(/virtual:([^:]+):/);
84
+ if (isVirtualModule) {
85
+ name = isVirtualModule[1];
86
+ (0, utils_js_1.assert)(name);
87
+ }
88
+ else if (
89
+ // https://github.com/vikejs/vike/issues/1818#issuecomment-2298478321
90
+ id.startsWith('/__uno')) {
91
+ name = 'uno';
92
+ }
93
+ else {
94
+ name = 'style';
95
+ }
96
+ const hash = getIdHash(id);
97
+ return `${name}-${hash}`;
94
98
  }
95
- const hash = getIdHash(id);
96
- return `${name}-${hash}`;
97
99
  }
98
- }
99
- };
100
- }
101
- });
100
+ };
101
+ }
102
+ });
103
+ },
102
104
  },
103
105
  };
104
106
  }
@@ -8,21 +8,25 @@ function pluginDistPackageJsonFile() {
8
8
  return {
9
9
  name: 'vike:build:pluginDistPackageJsonFile',
10
10
  apply: 'build',
11
- configResolved(config_) {
12
- config = config_;
11
+ configResolved: {
12
+ handler(config_) {
13
+ config = config_;
14
+ },
13
15
  },
14
- generateBundle(options, bundle) {
15
- if (!(0, isViteServerSide_js_1.isViteServerSide)(config, this.environment))
16
- return;
17
- const isEsm = (0, rollupIsEsm_js_1.rollupIsEsm)(options);
18
- const fileName = 'package.json';
19
- if (bundle[fileName])
20
- return; // E.g. already generated by Telefunc / vike
21
- this.emitFile({
22
- fileName,
23
- type: 'asset',
24
- source: getPackageJsonContent(isEsm),
25
- });
16
+ generateBundle: {
17
+ handler(options, bundle) {
18
+ if (!(0, isViteServerSide_js_1.isViteServerSide)(config, this.environment))
19
+ return;
20
+ const isEsm = (0, rollupIsEsm_js_1.rollupIsEsm)(options);
21
+ const fileName = 'package.json';
22
+ if (bundle[fileName])
23
+ return; // E.g. already generated by Telefunc / vike
24
+ this.emitFile({
25
+ fileName,
26
+ type: 'asset',
27
+ source: getPackageJsonContent(isEsm),
28
+ });
29
+ },
26
30
  },
27
31
  };
28
32
  }
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.pluginModuleBanner = pluginModuleBanner;
4
4
  const utils_js_1 = require("../../utils.js");
5
5
  const getMagicString_js_1 = require("../../shared/getMagicString.js");
6
- const isViteServerSide_js_1 = require("../../shared/isViteServerSide.js");
7
6
  // Rollup's banner feature doesn't work with Vite: https://github.com/vitejs/vite/issues/8412
8
7
  // But, anyways, we want to prepend the banner at the beginning of each module, not at the beginning of each file (I believe that's what Rollup's banner feature does).
9
8
  function pluginModuleBanner() {
@@ -12,17 +11,26 @@ function pluginModuleBanner() {
12
11
  name: 'vike:build:pluginModuleBanner',
13
12
  enforce: 'post',
14
13
  apply: 'build',
15
- configResolved(config_) {
16
- config = config_;
14
+ applyToEnvironment(environment) {
15
+ const { config } = environment;
16
+ const { consumer } = config;
17
+ const { minify } = config.build;
18
+ (0, utils_js_1.assert)(minify === false || minify, { minify, consumer });
19
+ return !minify;
20
+ },
21
+ configResolved: {
22
+ handler(config_) {
23
+ config = config_;
24
+ },
17
25
  },
18
26
  transform: {
19
27
  order: 'post',
20
- handler(code, id, options) {
21
- if (!(0, isViteServerSide_js_1.isViteServerSide_extraSafe)(config, this.environment, options) &&
22
- // Inject module banners if user sets `build.minify` to `false` for inspecting dist/client/
23
- config.build.minify) {
24
- return;
25
- }
28
+ /* Using a Rolldown hook filter doesn't make sense here — we use applyToEnvironment() to conditionally apply this plugin.
29
+ filter: {},
30
+ */
31
+ handler(code, id) {
32
+ const { minify } = this.environment.config.build;
33
+ (0, utils_js_1.assert)(minify === false, { minify });
26
34
  if (id.startsWith('\0'))
27
35
  id = id;
28
36
  id = (0, utils_js_1.removeVirtualFileIdPrefix)(id);
@@ -22,8 +22,10 @@ function pluginProdBuildEntry() {
22
22
  name: 'vike:build:pluginProdBuildEntry',
23
23
  apply: 'build',
24
24
  enforce: 'post',
25
- async configResolved(config_) {
26
- config = config_;
25
+ configResolved: {
26
+ async handler(config_) {
27
+ config = config_;
28
+ },
27
29
  },
28
30
  },
29
31
  ...(0, plugin_1.serverProductionEntryPlugin)({
@@ -7,24 +7,26 @@ function pluginSuppressRollupWarning() {
7
7
  name: 'vike:build:pluginSuppressRollupWarning',
8
8
  apply: 'build',
9
9
  enforce: 'post',
10
- async configResolved(config) {
11
- const onWarnOriginal = config.build.rollupOptions.onwarn;
12
- config.build.rollupOptions.onwarn = function (warning, warn) {
13
- // Suppress
14
- if (suppressUnusedImport(warning))
15
- return;
16
- if (suppressEmptyBundle(warning))
17
- return;
18
- if (suppressUseClientDirective(warning))
19
- return;
20
- // Pass through
21
- if (onWarnOriginal) {
22
- onWarnOriginal.apply(this, arguments);
23
- }
24
- else {
25
- warn(warning);
26
- }
27
- };
10
+ configResolved: {
11
+ async handler(config) {
12
+ const onWarnOriginal = config.build.rollupOptions.onwarn;
13
+ config.build.rollupOptions.onwarn = function (warning, warn) {
14
+ // Suppress
15
+ if (suppressUnusedImport(warning))
16
+ return;
17
+ if (suppressEmptyBundle(warning))
18
+ return;
19
+ if (suppressUseClientDirective(warning))
20
+ return;
21
+ // Pass through
22
+ if (onWarnOriginal) {
23
+ onWarnOriginal.apply(this, arguments);
24
+ }
25
+ else {
26
+ warn(warning);
27
+ }
28
+ };
29
+ },
28
30
  },
29
31
  };
30
32
  }
@@ -8,7 +8,6 @@ const utils_js_1 = require("../utils.js");
8
8
  const pluginBuildConfig_js_1 = require("./pluginBuild/pluginBuildConfig.js");
9
9
  const require_shim_1 = require("@brillout/require-shim");
10
10
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
11
- const node_path_1 = __importDefault(require("node:path"));
12
11
  const assertResolveAlias_js_1 = require("./pluginCommon/assertResolveAlias.js");
13
12
  const isViteCliCall_js_1 = require("../shared/isViteCliCall.js");
14
13
  const context_js_1 = require("../../api/context.js");
@@ -47,10 +46,12 @@ function pluginCommon(vikeVitePluginOptions) {
47
46
  },
48
47
  {
49
48
  name: pluginName,
50
- configResolved(config) {
51
- (0, prepareViteApiCall_js_1.assertViteRoot)(config._rootResolvedEarly, config);
52
- assertSingleInstance(config);
53
- (0, require_shim_1.installRequireShim_setUserRootDir)(config.root);
49
+ configResolved: {
50
+ handler(config) {
51
+ (0, prepareViteApiCall_js_1.assertViteRoot)(config._rootResolvedEarly, config);
52
+ assertSingleInstance(config);
53
+ (0, require_shim_1.installRequireShim_setUserRootDir)(config.root);
54
+ },
54
55
  },
55
56
  },
56
57
  {
@@ -69,7 +70,6 @@ function pluginCommon(vikeVitePluginOptions) {
69
70
  workaroundCI(config);
70
71
  (0, pluginBuildConfig_js_1.assertRollupInput)(config);
71
72
  (0, assertResolveAlias_js_1.assertResolveAlias)(config);
72
- assertEsm(config.root);
73
73
  assertVikeCliOrApi(config);
74
74
  temp_supportOldInterface(config);
75
75
  await emitServerEntryOnlyIfNeeded(config);
@@ -112,7 +112,7 @@ function setDefault(setting, value, configFromUser, configFromVike) {
112
112
  /*
113
113
  import { version } from 'vite'
114
114
  function overrideViteDefaultSsrExternal(config: ResolvedConfig) {
115
- if (!isVersionOrAbove(version, '5.0.12')) return
115
+ if (!isVersionMatch(version, ['5.0.12'])) return
116
116
  // @ts-ignore Not released yet: https://github.com/vitejs/vite/pull/10939/files#diff-5a3d42620df2c6b17e25f440ffdb67683dee7ef57317674d19f41d5f30502310L5
117
117
  config.ssr.external ??= true
118
118
  }
@@ -125,20 +125,6 @@ function workaroundCI(config) {
125
125
  (_b = config.preview).host ?? (_b.host = true);
126
126
  }
127
127
  }
128
- function assertEsm(userViteRoot) {
129
- const found = (0, utils_js_1.findPackageJson)(userViteRoot);
130
- if (!found)
131
- return;
132
- const { packageJson, packageJsonPath } = found;
133
- let dir = node_path_1.default.posix.dirname(packageJsonPath);
134
- if (dir !== '/') {
135
- (0, utils_js_1.assert)(!dir.endsWith('/'));
136
- dir = dir + '/';
137
- }
138
- (0, utils_js_1.assert)(dir.endsWith('/'));
139
- dir = picocolors_1.default.dim(dir);
140
- (0, utils_js_1.assertWarning)(packageJson.type === 'module', `We recommend setting ${dir}package.json#type to "module", see https://vike.dev/CJS`, { onlyOnce: true });
141
- }
142
128
  function assertSingleInstance(config) {
143
129
  const numberOfInstances = config.plugins.filter((o) => o.name === pluginName).length;
144
130
  (0, utils_js_1.assertUsage)(numberOfInstances === 1, `Vike's Vite plugin (${picocolors_1.default.cyan("import vike from 'vike/plugin'")}) is being added ${numberOfInstances} times to the list of Vite plugins. Make sure to add it only once instead.`);