vike 0.4.218 → 0.4.219

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 (178) hide show
  1. package/dist/cjs/__internal/index.js +11 -11
  2. package/dist/cjs/node/api/build.js +20 -11
  3. package/dist/cjs/node/api/context.js +5 -1
  4. package/dist/cjs/node/api/index.js +17 -7
  5. package/dist/cjs/node/api/prepareViteApiCall.js +39 -11
  6. package/dist/cjs/node/cli/entry.js +19 -7
  7. package/dist/cjs/node/plugin/index.js +5 -5
  8. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +3 -4
  9. package/dist/cjs/node/plugin/plugins/baseUrls.js +3 -10
  10. package/dist/cjs/node/plugin/plugins/buildConfig.js +2 -2
  11. package/dist/cjs/node/plugin/plugins/{importBuild → buildEntry}/index.js +16 -17
  12. package/dist/cjs/node/plugin/plugins/commonConfig.js +38 -3
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +26 -23
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +171 -68
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +4 -3
  17. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +1 -1
  18. package/dist/cjs/node/plugin/plugins/{vite6HmrRegressionWorkaround.js → workaroundVite6HmrRegression.js} +3 -3
  19. package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +17 -7
  20. package/dist/cjs/node/prerender/isPrerenderAutoRunEnabled.js +16 -0
  21. package/dist/cjs/node/prerender/runPrerender.js +94 -66
  22. package/dist/cjs/node/prerender/utils.js +1 -0
  23. package/dist/cjs/node/runtime/globalContext.js +108 -34
  24. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
  25. package/dist/cjs/node/runtime/index-common.js +0 -15
  26. package/dist/cjs/node/runtime/onLoad.js +17 -3
  27. package/dist/cjs/node/runtime/page-files/setup.js +2 -4
  28. package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
  29. package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +2 -2
  30. package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
  31. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +11 -33
  32. package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +9 -1
  33. package/dist/cjs/node/runtime/renderPage.js +21 -22
  34. package/dist/cjs/node/runtime/utils.js +1 -0
  35. package/dist/cjs/node/runtime-dev/index.js +17 -7
  36. package/dist/cjs/node/shared/assertRuntimeManifest.js +0 -2
  37. package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +3 -3
  38. package/dist/cjs/shared/getPageFiles/{setPageFiles.js → getPageFiles.js} +8 -6
  39. package/dist/cjs/shared/getPageFiles.js +3 -9
  40. package/dist/cjs/shared/hooks/getHook.js +3 -3
  41. package/dist/cjs/shared/{getPageFiles/getExports.js → page-configs/getPageConfigUserFriendly.js} +113 -81
  42. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +80 -55
  43. package/dist/cjs/shared/route/loadPageRoutes.js +3 -3
  44. package/dist/cjs/shared/utils.js +1 -0
  45. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  46. package/dist/cjs/utils/assert.js +4 -3
  47. package/dist/cjs/utils/assertSetup.js +33 -16
  48. package/dist/cjs/utils/debug.js +11 -6
  49. package/dist/cjs/utils/getGlobalObject.js +1 -2
  50. package/dist/cjs/utils/objectReplace.js +9 -0
  51. package/dist/esm/__internal/index.d.ts +3 -5
  52. package/dist/esm/__internal/index.js +6 -8
  53. package/dist/esm/client/client-routing-runtime/createPageContext.js +4 -1
  54. package/dist/esm/client/client-routing-runtime/entry.d.ts +1 -1
  55. package/dist/esm/client/client-routing-runtime/entry.js +0 -1
  56. package/dist/esm/client/client-routing-runtime/getPageContextCurrent.d.ts +2 -2
  57. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +4 -4
  58. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +1 -1
  59. package/dist/esm/client/client-routing-runtime/prefetch/getPrefetchSettings.d.ts +2 -2
  60. package/dist/esm/client/client-routing-runtime/prefetch.d.ts +2 -2
  61. package/dist/esm/client/client-routing-runtime/prefetch.js +2 -2
  62. package/dist/esm/client/server-routing-runtime/entry.d.ts +1 -1
  63. package/dist/esm/client/server-routing-runtime/entry.js +0 -1
  64. package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
  65. package/dist/esm/client/server-routing-runtime/getPageContext.js +5 -2
  66. package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
  67. package/dist/esm/client/shared/loadUserFilesClientSide.d.ts +2 -2
  68. package/dist/esm/client/shared/loadUserFilesClientSide.js +2 -2
  69. package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
  70. package/dist/esm/node/api/build.js +3 -4
  71. package/dist/esm/node/api/context.d.ts +3 -1
  72. package/dist/esm/node/api/context.js +6 -2
  73. package/dist/esm/node/api/prepareViteApiCall.d.ts +1 -1
  74. package/dist/esm/node/api/prepareViteApiCall.js +25 -7
  75. package/dist/esm/node/cli/entry.js +2 -0
  76. package/dist/esm/node/cli/parseCli.d.ts +1 -1
  77. package/dist/esm/node/plugin/index.d.ts +1 -1
  78. package/dist/esm/node/plugin/index.js +5 -5
  79. package/dist/esm/node/plugin/plugins/autoFullBuild.js +3 -4
  80. package/dist/esm/node/plugin/plugins/baseUrls.d.ts +1 -1
  81. package/dist/esm/node/plugin/plugins/baseUrls.js +4 -11
  82. package/dist/esm/node/plugin/plugins/buildConfig.js +2 -2
  83. package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/getVikeManifest.d.ts +1 -1
  84. package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/index.d.ts +2 -2
  85. package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/index.js +16 -17
  86. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +3 -0
  87. package/dist/esm/node/plugin/plugins/commonConfig.js +39 -4
  88. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +1 -1
  89. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +6 -9
  90. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +25 -22
  91. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +96 -1
  92. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +167 -64
  93. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
  94. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +4 -3
  95. package/dist/esm/node/plugin/plugins/setGlobalContext.js +1 -1
  96. package/dist/esm/node/plugin/plugins/workaroundVite6HmrRegression.d.ts +3 -0
  97. package/dist/esm/node/plugin/plugins/{vite6HmrRegressionWorkaround.js → workaroundVite6HmrRegression.js} +3 -3
  98. package/dist/esm/node/prerender/isPrerenderAutoRunEnabled.d.ts +5 -0
  99. package/dist/esm/node/prerender/isPrerenderAutoRunEnabled.js +14 -0
  100. package/dist/esm/node/prerender/runPrerender.d.ts +1 -2
  101. package/dist/esm/node/prerender/runPrerender.js +78 -60
  102. package/dist/esm/node/prerender/utils.d.ts +1 -0
  103. package/dist/esm/node/prerender/utils.js +1 -0
  104. package/dist/esm/node/runtime/globalContext.d.ts +23 -7
  105. package/dist/esm/node/runtime/globalContext.js +108 -34
  106. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  107. package/dist/esm/node/runtime/index-common.d.ts +0 -1
  108. package/dist/esm/node/runtime/index-common.js +0 -15
  109. package/dist/esm/node/runtime/index-deprecated.d.ts +1 -0
  110. package/dist/esm/node/runtime/onLoad.js +16 -2
  111. package/dist/esm/node/runtime/page-files/setup.js +3 -3
  112. package/dist/esm/node/runtime/renderPage/analyzePage.js +1 -1
  113. package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.js +1 -1
  114. package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.d.ts +2 -2
  115. package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +1 -1
  116. package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +2 -2
  117. package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
  118. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +31 -46
  119. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +11 -33
  120. package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +1 -1
  121. package/dist/esm/node/runtime/renderPage/resolveRedirects.js +9 -1
  122. package/dist/esm/node/runtime/renderPage.js +22 -23
  123. package/dist/esm/node/runtime/utils.d.ts +1 -0
  124. package/dist/esm/node/runtime/utils.js +1 -0
  125. package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -1
  126. package/dist/esm/node/shared/assertRuntimeManifest.d.ts +0 -1
  127. package/dist/esm/node/shared/assertRuntimeManifest.js +1 -3
  128. package/dist/esm/shared/getPageFiles/analyzeClientSide.js +1 -1
  129. package/dist/esm/shared/getPageFiles/{setPageFiles.d.ts → getPageFiles.d.ts} +3 -1
  130. package/dist/esm/shared/getPageFiles/{setPageFiles.js → getPageFiles.js} +8 -6
  131. package/dist/esm/shared/getPageFiles.d.ts +2 -5
  132. package/dist/esm/shared/getPageFiles.js +1 -4
  133. package/dist/esm/shared/hooks/getHook.d.ts +3 -3
  134. package/dist/esm/shared/hooks/getHook.js +1 -1
  135. package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +9 -5
  136. package/dist/esm/shared/page-configs/Config.d.ts +20 -2
  137. package/dist/esm/shared/page-configs/PageConfig.d.ts +7 -3
  138. package/dist/esm/shared/{getPageFiles/getExports.d.ts → page-configs/getPageConfigUserFriendly.d.ts} +26 -12
  139. package/dist/esm/shared/{getPageFiles/getExports.js → page-configs/getPageConfigUserFriendly.js} +112 -80
  140. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +26 -6
  141. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +80 -55
  142. package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
  143. package/dist/esm/shared/route/loadPageRoutes.js +1 -1
  144. package/dist/esm/shared/types.d.ts +1 -1
  145. package/dist/esm/shared/utils.d.ts +1 -0
  146. package/dist/esm/shared/utils.js +1 -0
  147. package/dist/esm/types/index.d.ts +1 -1
  148. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  149. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  150. package/dist/esm/utils/assert.js +4 -3
  151. package/dist/esm/utils/assertSetup.js +33 -16
  152. package/dist/esm/utils/debug.d.ts +1 -1
  153. package/dist/esm/utils/debug.js +11 -6
  154. package/dist/esm/utils/getGlobalObject.js +1 -2
  155. package/dist/esm/utils/objectReplace.d.ts +1 -0
  156. package/dist/esm/utils/objectReplace.js +6 -0
  157. package/dist/esm/utils/projectInfo.d.ts +1 -1
  158. package/package.json +4 -13
  159. package/__internal/loadImportBuild.js +0 -3
  160. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +0 -128
  161. package/dist/cjs/node/runtime/globalContext/loadImportBuild.js +0 -25
  162. package/dist/cjs/node/runtime/page-files/getPageFilesExports.js +0 -22
  163. package/dist/esm/client/client-routing-runtime/pageFiles.d.ts +0 -1
  164. package/dist/esm/client/client-routing-runtime/pageFiles.js +0 -4
  165. package/dist/esm/client/server-routing-runtime/pageFiles.d.ts +0 -1
  166. package/dist/esm/client/server-routing-runtime/pageFiles.js +0 -4
  167. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.d.ts +0 -104
  168. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +0 -123
  169. package/dist/esm/node/plugin/plugins/vite6HmrRegressionWorkaround.d.ts +0 -3
  170. package/dist/esm/node/runtime/globalContext/loadImportBuild.d.ts +0 -18
  171. package/dist/esm/node/runtime/globalContext/loadImportBuild.js +0 -23
  172. package/dist/esm/node/runtime/page-files/getPageFilesExports.d.ts +0 -2
  173. package/dist/esm/node/runtime/page-files/getPageFilesExports.js +0 -20
  174. /package/dist/cjs/node/plugin/plugins/{importBuild → buildEntry}/getVikeManifest.js +0 -0
  175. /package/dist/cjs/shared/page-configs/{getConfigValue.js → getConfigValueRuntime.js} +0 -0
  176. /package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/getVikeManifest.js +0 -0
  177. /package/dist/esm/shared/page-configs/{getConfigValue.d.ts → getConfigValueRuntime.d.ts} +0 -0
  178. /package/dist/esm/shared/page-configs/{getConfigValue.js → getConfigValueRuntime.js} +0 -0
@@ -7,7 +7,7 @@ export { isV1Design };
7
7
  export { getConfigValueInterfaceFile };
8
8
  import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEntries, hasProp, includes, assertIsNotProductionRuntime, getMostSimilar, joinEnglish, lowerFirst, assertKeys, objectKeys, objectFromEntries, makeFirst, isNpmPackageImport, reverse } from '../../../utils.js';
9
9
  import path from 'path';
10
- import { configDefinitionsBuiltIn, configDefinitionsBuiltInGlobal } from './getVikeConfig/configDefinitionsBuiltIn.js';
10
+ import { configDefinitionsBuiltInAll } from './getVikeConfig/configDefinitionsBuiltIn.js';
11
11
  import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, isGlobalLocation, applyFilesystemRoutingRootEffect } from './getVikeConfig/filesystemRouting.js';
12
12
  import { isTemporaryBuildFile } from './getVikeConfig/transpileAndExecuteFile.js';
13
13
  import { isConfigInvalid, isConfigInvalid_set } from '../../../../runtime/renderPage/isConfigInvalid.js';
@@ -23,7 +23,10 @@ import { clearFilesEnvMap, resolveConfigEnvWithFileName, resolvePointerImportOfC
23
23
  import { getFilePathResolved } from '../../../shared/getFilePath.js';
24
24
  import { getConfigValueBuildTime } from '../../../../../shared/page-configs/getConfigValueBuildTime.js';
25
25
  import { assertExtensionsPeerDependencies, assertExtensionsConventions } from './assertExtensions.js';
26
- import { resolveVikeConfigGlobal } from './getVikeConfig/resolveVikeConfigGlobal.js';
26
+ import { getPageConfigUserFriendlyNew } from '../../../../../shared/page-configs/getPageConfigUserFriendly.js';
27
+ import { getConfigValuesBase } from '../../../../../shared/page-configs/serialize/serializeConfigValues.js';
28
+ const configDefinitionsBuiltIn = getConfigDefinitionsBuiltIn();
29
+ const configDefinitionsBuiltInGlobal = getConfigDefinitionsBuiltInGlobal();
27
30
  assertIsNotProductionRuntime();
28
31
  let restartVite = false;
29
32
  let wasConfigInvalid = null;
@@ -239,7 +242,8 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, vikeVitePlug
239
242
  configDefinitions: {},
240
243
  configValueSources: {}
241
244
  },
242
- vikeConfigGlobal: resolveVikeConfigGlobal({}, {})
245
+ vikeConfigGlobal: resolveVikeConfigGlobal({}, {}),
246
+ global: getPageConfigUserFriendlyNew({ configValues: {} })
243
247
  };
244
248
  return dummyData;
245
249
  }
@@ -248,8 +252,97 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, vikeVitePlug
248
252
  async function loadVikeConfig(userRootDir, vikeVitePluginOptions) {
249
253
  const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir);
250
254
  const importedFilesLoaded = {};
251
- const { pageConfigGlobal, pageConfigGlobalValues } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
255
+ const [globalConfigs, pageConfigs] = await Promise.all([
256
+ getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded, vikeVitePluginOptions),
257
+ getPageConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded)
258
+ ]);
259
+ return { pageConfigs, ...globalConfigs };
260
+ }
261
+ async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded, vikeVitePluginOptions) {
262
+ const locationIds = objectKeys(interfaceFilesByLocationId);
263
+ const interfaceFilesGlobal = objectFromEntries(objectEntries(interfaceFilesByLocationId).filter(([locationId]) => {
264
+ return isGlobalLocation(locationId, locationIds);
265
+ }));
266
+ // Validate that global configs live in global interface files
267
+ {
268
+ const interfaceFilesGlobalPaths = [];
269
+ objectEntries(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
270
+ assert(isGlobalLocation(locationId, locationIds));
271
+ interfaceFiles.forEach(({ filePath: { filePathAbsoluteUserRootDir } }) => {
272
+ if (filePathAbsoluteUserRootDir) {
273
+ interfaceFilesGlobalPaths.push(filePathAbsoluteUserRootDir);
274
+ }
275
+ });
276
+ });
277
+ const globalPaths = Array.from(new Set(interfaceFilesGlobalPaths.map((p) => path.posix.dirname(p))));
278
+ objectEntries(interfaceFilesByLocationId).forEach(([locationId, interfaceFiles]) => {
279
+ interfaceFiles.forEach((interfaceFile) => {
280
+ Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
281
+ if (!isGlobalLocation(locationId, locationIds) && isGlobalConfig(configName)) {
282
+ assertUsage(false, [
283
+ `${interfaceFile.filePath.filePathToShowToUser} defines the config ${pc.cyan(configName)} which is global:`,
284
+ globalPaths.length
285
+ ? `define ${pc.cyan(configName)} in ${joinEnglish(globalPaths, 'or')} instead`
286
+ : `create a global config (e.g. /pages/+config.js) and define ${pc.cyan(configName)} there instead`
287
+ ].join(' '));
288
+ }
289
+ });
290
+ });
291
+ });
292
+ }
293
+ const pageConfigGlobalValues = {};
294
+ const pageConfigGlobal = {
295
+ configDefinitions: configDefinitionsBuiltInGlobal,
296
+ configValueSources: {}
297
+ };
298
+ await Promise.all(objectEntries(configDefinitionsBuiltInGlobal).map(async ([configName, configDef]) => {
299
+ const sources = await resolveConfigValueSources(configName, configDef, interfaceFilesGlobal, userRootDir, importedFilesLoaded);
300
+ const configValueSource = sources[0];
301
+ if (!configValueSource)
302
+ return;
303
+ pageConfigGlobal.configValueSources[configName] = sources;
304
+ // TODO/now
305
+ if (configName === 'onBeforeRoute' || configName === 'onPrerenderStart') {
306
+ assert(!('value' in configValueSource));
307
+ }
308
+ else {
309
+ assert('value' in configValueSource);
310
+ // TODO/now
311
+ if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
312
+ return;
313
+ pageConfigGlobalValues[configName] = configValueSource.value;
314
+ }
315
+ }));
252
316
  const vikeConfigGlobal = resolveVikeConfigGlobal(vikeVitePluginOptions, pageConfigGlobalValues);
317
+ {
318
+ assert(isObject(vikeVitePluginOptions));
319
+ Object.entries(vikeVitePluginOptions).forEach(([configName, value]) => {
320
+ var _a;
321
+ assert(includes(objectKeys(configDefinitionsBuiltInGlobal), configName));
322
+ const configDef = configDefinitionsBuiltInGlobal[configName];
323
+ const sources = ((_a = pageConfigGlobal.configValueSources)[configName] ?? (_a[configName] = []));
324
+ sources.push({
325
+ value,
326
+ configEnv: configDef.env,
327
+ definedAtFilePath: {
328
+ ...getFilePathResolved({
329
+ userRootDir,
330
+ filePathAbsoluteUserRootDir: '/vite.config.js'
331
+ }),
332
+ fileExportPathToShowToUser: null
333
+ },
334
+ locationId: '/',
335
+ isOverriden: configDef.cumulative ? false : sources.length > 0,
336
+ valueIsImportedAtRuntime: false,
337
+ valueIsDefinedByPlusFile: false
338
+ });
339
+ });
340
+ }
341
+ const configValues = getConfigValues(pageConfigGlobal);
342
+ const global = getPageConfigUserFriendlyNew({ configValues });
343
+ return { pageConfigGlobal, vikeConfigGlobal, global };
344
+ }
345
+ async function getPageConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded) {
253
346
  const pageConfigs = await Promise.all(objectEntries(interfaceFilesByLocationId)
254
347
  .filter(([_pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
255
348
  .map(async ([locationId]) => {
@@ -299,9 +392,37 @@ async function loadVikeConfig(userRootDir, vikeVitePluginOptions) {
299
392
  return pageConfig;
300
393
  }));
301
394
  assertPageConfigs(pageConfigs);
302
- return { pageConfigs, pageConfigGlobal, vikeConfigGlobal };
395
+ return pageConfigs;
303
396
  }
304
- // TODO/soon: refactor
397
+ function getConfigValues(pageConfig) {
398
+ const configValues = {};
399
+ getConfigValuesBase(pageConfig, (configEnv) => !!configEnv.config, null).forEach((entry) => {
400
+ if (entry.configValueBase.type === 'computed') {
401
+ assert('value' in entry); // Help TS
402
+ const { configValueBase, value, configName } = entry;
403
+ configValues[configName] = { ...configValueBase, value };
404
+ }
405
+ if (entry.configValueBase.type === 'standard') {
406
+ assert('sourceRelevant' in entry); // Help TS
407
+ const { configValueBase, sourceRelevant, configName } = entry;
408
+ assert('value' in sourceRelevant);
409
+ const { value } = sourceRelevant;
410
+ configValues[configName] = { ...configValueBase, value };
411
+ }
412
+ if (entry.configValueBase.type === 'cumulative') {
413
+ assert('sourcesRelevant' in entry); // Help TS
414
+ const { configValueBase, sourcesRelevant, configName } = entry;
415
+ const values = [];
416
+ sourcesRelevant.forEach((source) => {
417
+ assert('value' in source);
418
+ values.push(source.value);
419
+ });
420
+ configValues[configName] = { ...configValueBase, value: values };
421
+ }
422
+ });
423
+ return configValues;
424
+ }
425
+ // TODO/now: refactor
305
426
  // - Dedupe: most of the assertUsageGlobalConfigs() code below is a copy-paste of the assertUsage() logic inside getGlobalConfigs()
306
427
  // - This assertUsage() message is slightly better: use this one for getGlobalConfigs()
307
428
  // Global configs should be defined at global locations
@@ -318,7 +439,7 @@ function assertUsageGlobalConfigs(interfaceFilesRelevantList, configDefinitions,
318
439
  if (isGlobalConfig(configName))
319
440
  return;
320
441
  const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
321
- if (configDef.global) {
442
+ if (configDef.global === true) {
322
443
  const locationIds = objectKeys(interfaceFilesByLocationId);
323
444
  if (!isGlobalLocation(interfaceFile.locationId, locationIds)) {
324
445
  const interfaceFilesGlobal = objectFromEntries(objectEntries(interfaceFilesByLocationId).filter(([locationId]) => {
@@ -377,63 +498,6 @@ function getInterfaceFilesRelevant(interfaceFilesByLocationId, locationIdPage) {
377
498
  .sort(([locationId1], [locationId2]) => sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage)));
378
499
  return interfaceFilesRelevant;
379
500
  }
380
- async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded) {
381
- const locationIds = objectKeys(interfaceFilesByLocationId);
382
- const interfaceFilesGlobal = objectFromEntries(objectEntries(interfaceFilesByLocationId).filter(([locationId]) => {
383
- return isGlobalLocation(locationId, locationIds);
384
- }));
385
- // Validate that global configs live in global interface files
386
- {
387
- const interfaceFilesGlobalPaths = [];
388
- objectEntries(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
389
- assert(isGlobalLocation(locationId, locationIds));
390
- interfaceFiles.forEach(({ filePath: { filePathAbsoluteUserRootDir } }) => {
391
- if (filePathAbsoluteUserRootDir) {
392
- interfaceFilesGlobalPaths.push(filePathAbsoluteUserRootDir);
393
- }
394
- });
395
- });
396
- const globalPaths = Array.from(new Set(interfaceFilesGlobalPaths.map((p) => path.posix.dirname(p))));
397
- objectEntries(interfaceFilesByLocationId).forEach(([locationId, interfaceFiles]) => {
398
- interfaceFiles.forEach((interfaceFile) => {
399
- Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
400
- if (!isGlobalLocation(locationId, locationIds) && isGlobalConfig(configName)) {
401
- assertUsage(false, [
402
- `${interfaceFile.filePath.filePathToShowToUser} defines the config ${pc.cyan(configName)} which is global:`,
403
- globalPaths.length
404
- ? `define ${pc.cyan(configName)} in ${joinEnglish(globalPaths, 'or')} instead`
405
- : `create a global config (e.g. /pages/+config.js) and define ${pc.cyan(configName)} there instead`
406
- ].join(' '));
407
- }
408
- });
409
- });
410
- });
411
- }
412
- const pageConfigGlobalValues = {};
413
- const pageConfigGlobal = {
414
- configDefinitions: configDefinitionsBuiltInGlobal,
415
- configValueSources: {}
416
- };
417
- await Promise.all(objectEntries(configDefinitionsBuiltInGlobal).map(async ([configName, configDef]) => {
418
- const sources = await resolveConfigValueSources(configName, configDef, interfaceFilesGlobal, userRootDir, importedFilesLoaded);
419
- const configValueSource = sources[0];
420
- if (!configValueSource)
421
- return;
422
- if (configName === 'onBeforeRoute' || configName === 'onPrerenderStart') {
423
- assert(!('value' in configValueSource));
424
- pageConfigGlobal.configValueSources[configName] = [configValueSource];
425
- }
426
- else {
427
- assert('value' in configValueSource);
428
- if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
429
- return;
430
- const { filePathToShowToUser } = configValueSource.definedAtFilePath;
431
- assertWarning(false, `Being able to define config ${pc.cyan(configName)} in ${filePathToShowToUser} is experimental and will likely be removed. Define the config ${pc.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
432
- pageConfigGlobalValues[configName] = configValueSource.value;
433
- }
434
- }));
435
- return { pageConfigGlobal, pageConfigGlobalValues };
436
- }
437
501
  async function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir, importedFilesLoaded) {
438
502
  const sourcesInfo = [];
439
503
  // interfaceFilesRelevant is sorted by sortAfterInheritanceOrder()
@@ -976,6 +1040,7 @@ function isLoadableAtBuildTime(configDef) {
976
1040
  return !!configDef.env.config && !configDef._valueIsFilePath;
977
1041
  }
978
1042
  function isGlobalConfig(configName) {
1043
+ // TODO/now
979
1044
  if (configName === 'prerender')
980
1045
  return false;
981
1046
  const configNamesGlobal = getConfigNamesGlobal();
@@ -984,6 +1049,12 @@ function isGlobalConfig(configName) {
984
1049
  function getConfigNamesGlobal() {
985
1050
  return Object.keys(configDefinitionsBuiltInGlobal);
986
1051
  }
1052
+ function getConfigDefinitionsBuiltInGlobal() {
1053
+ return objectFromEntries(objectEntries(configDefinitionsBuiltInAll).filter(([_configName, configDef]) => configDef.global !== undefined));
1054
+ }
1055
+ function getConfigDefinitionsBuiltIn() {
1056
+ return objectFromEntries(objectEntries(configDefinitionsBuiltInAll).filter(([_configName, configDef]) => configDef.global !== true));
1057
+ }
987
1058
  function assertConfigExists(configName, configNamesRelevant, filePathToShowToUser) {
988
1059
  const configNames = [...configNamesRelevant, ...getConfigNamesGlobal()];
989
1060
  if (configNames.includes(configName))
@@ -1010,3 +1081,35 @@ function sortConfigValueSources(configValueSources, locationIdPage) {
1010
1081
  function getConfigValueInterfaceFile(interfaceFile, configName) {
1011
1082
  return interfaceFile.fileExportsByConfigName[configName]?.configValue;
1012
1083
  }
1084
+ // TODO/now: refactor code below
1085
+ function resolveVikeConfigGlobal(vikeVitePluginOptions, pageConfigGlobalValues) {
1086
+ const configs = [vikeVitePluginOptions, pageConfigGlobalValues];
1087
+ const vikeConfigGlobal = {
1088
+ disableAutoFullBuild: pickFirst(configs.map((c) => c.disableAutoFullBuild)) ?? null,
1089
+ prerender: resolvePrerenderOptions(configs),
1090
+ includeAssetsImportedByServer: pickFirst(configs.map((c) => c.includeAssetsImportedByServer)) ?? true,
1091
+ baseServer: pickFirst(configs.map((c) => c.baseServer)) ?? null,
1092
+ baseAssets: pickFirst(configs.map((c) => c.baseAssets)) ?? null,
1093
+ disableUrlNormalization: pickFirst(configs.map((c) => c.disableUrlNormalization)) ?? false,
1094
+ trailingSlash: pickFirst(configs.map((c) => c.trailingSlash)) ?? false
1095
+ };
1096
+ return vikeConfigGlobal;
1097
+ }
1098
+ function resolvePrerenderOptions(configs) {
1099
+ if (!configs.some((c) => c.prerender)) {
1100
+ return false;
1101
+ }
1102
+ const configsPrerender = configs.map((c) => c.prerender).filter(isObject2);
1103
+ return {
1104
+ partial: pickFirst(configsPrerender.map((c) => c.partial)) ?? false,
1105
+ noExtraDir: pickFirst(configsPrerender.map((c) => c.noExtraDir)) ?? false,
1106
+ parallel: pickFirst(configsPrerender.map((c) => c.parallel)) ?? true,
1107
+ disableAutoRun: pickFirst(configsPrerender.map((c) => c.disableAutoRun)) ?? false
1108
+ };
1109
+ }
1110
+ function isObject2(p) {
1111
+ return typeof p === 'object';
1112
+ }
1113
+ function pickFirst(arr) {
1114
+ return arr.filter((v) => v !== undefined)[0];
1115
+ }
@@ -31,7 +31,7 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
31
31
  const importStatements = [];
32
32
  const isClientRouting = getConfigValueBuildTime(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
33
33
  lines.push('export const configValuesSerialized = {');
34
- lines.push(...serializeConfigValues(pageConfig, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), { isEager: false }, ''));
34
+ lines.push(...serializeConfigValues(pageConfig, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), '', false));
35
35
  lines.push('};');
36
36
  if (!fixServerAssets_isEnabled() && includeAssetsImportedByServer && isForClientSide && !isDev) {
37
37
  importStatements.push(`import '${extractAssetsAddQuery(getVirtualFileIdPageConfigValuesAll(pageId, false))}'`);
@@ -5,7 +5,8 @@ import { getVikeConfig } from './getVikeConfig.js';
5
5
  import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
6
6
  import { serializeConfigValues } from '../../../../../shared/page-configs/serialize/serializeConfigValues.js';
7
7
  async function getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, config) {
8
- const { pageConfigs, pageConfigGlobal } = await getVikeConfig(config, { doNotRestartViteOnError: true });
8
+ const vikeConfig = await getVikeConfig(config, { doNotRestartViteOnError: true });
9
+ const { pageConfigs, pageConfigGlobal } = vikeConfig;
9
10
  return getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
10
11
  }
11
12
  function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting) {
@@ -32,7 +33,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
32
33
  lines.push(` routeFilesystem: ${JSON.stringify(routeFilesystem)},`);
33
34
  lines.push(` loadConfigValuesAll: () => import(${JSON.stringify(virtualFileIdPageConfigValuesAll)}),`);
34
35
  lines.push(` configValuesSerialized: {`);
35
- lines.push(...serializeConfigValues(pageConfig, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), { isEager: true }, ' '));
36
+ lines.push(...serializeConfigValues(pageConfig, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), ' ', true));
36
37
  lines.push(` },`);
37
38
  lines.push(` },`);
38
39
  });
@@ -42,7 +43,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
42
43
  function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements) {
43
44
  const lines = [];
44
45
  lines.push(` configValuesSerialized: {`);
45
- lines.push(...serializeConfigValues(pageConfigGlobal, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), { isEager: true }, ' '));
46
+ lines.push(...serializeConfigValues(pageConfigGlobal, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), ' ', null));
46
47
  lines.push(` },`);
47
48
  const code = lines.join('\n');
48
49
  return code;
@@ -33,7 +33,7 @@ function setGlobalContext() {
33
33
  order: 'post',
34
34
  async handler(config) {
35
35
  const { outDirRoot } = getOutDirs(config);
36
- assertFilePathAbsoluteFilesystem(outDirRoot); // Needed for loadImportBuild(outDir) of @brillout/vite-plugin-server-entry
36
+ assertFilePathAbsoluteFilesystem(outDirRoot); // Needed for `importServerProductionEntry({ outDir })` of @brillout/vite-plugin-server-entry
37
37
  setGlobalContext_viteConfig(config, outDirRoot);
38
38
  const vikeConfig = await getVikeConfig(config);
39
39
  setGlobalContext_vikeConfig(vikeConfig);
@@ -0,0 +1,3 @@
1
+ export { workaroundVite6HmrRegression };
2
+ import type { Plugin } from 'vite';
3
+ declare function workaroundVite6HmrRegression(): Plugin;
@@ -1,11 +1,11 @@
1
- export { vite6HmrRegressionWorkaround };
1
+ export { workaroundVite6HmrRegression };
2
2
  // https://vite.dev/guide/migration (will be 404 after vite@7 release) > search for `hmrReload()`
3
3
  // https://v6.vite.dev/guide/migration (will exist after vite@7 release) > search for `hmrReload()`
4
4
  // Workaround seems to work for docs page /banner (which is HTML-only)
5
5
  // But doesn't seem to work for /examples/render-modes/ (see https://github.com/vikejs/vike/pull/2069 commit `renable HMR test for HTML-only`)
6
- function vite6HmrRegressionWorkaround() {
6
+ function workaroundVite6HmrRegression() {
7
7
  return {
8
- name: 'vike:vite6HmrRegressionWorkaround',
8
+ name: 'vike:workaroundVite6HmrRegression',
9
9
  enforce: 'post',
10
10
  hotUpdate: {
11
11
  order: 'post',
@@ -0,0 +1,5 @@
1
+ export { isPrerenderAutoRunEnabled };
2
+ export { temp_disablePrerenderAutoRun };
3
+ import type { VikeConfigGlobal } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
4
+ declare function isPrerenderAutoRunEnabled(vikeConfigGlobal: VikeConfigGlobal): boolean;
5
+ declare function temp_disablePrerenderAutoRun(): void;
@@ -0,0 +1,14 @@
1
+ export { isPrerenderAutoRunEnabled };
2
+ export { temp_disablePrerenderAutoRun };
3
+ import { getGlobalObject } from '../../utils/getGlobalObject.js';
4
+ const globalObject = getGlobalObject('isPrerenderAutoRunEnabled.ts', {});
5
+ function isPrerenderAutoRunEnabled(vikeConfigGlobal) {
6
+ return (vikeConfigGlobal.prerender &&
7
+ !vikeConfigGlobal.prerender.disableAutoRun &&
8
+ !globalObject.isDisabled &&
9
+ vikeConfigGlobal.disableAutoFullBuild !== 'prerender');
10
+ }
11
+ // TODO/v1-release: remove
12
+ function temp_disablePrerenderAutoRun() {
13
+ globalObject.isDisabled = true;
14
+ }
@@ -3,7 +3,6 @@ export { runPrerenderFromCLIPrerenderCommand };
3
3
  export { runPrerenderFromAutoRun };
4
4
  export { runPrerender_forceExit };
5
5
  export type { PrerenderOptions };
6
- import '../runtime/page-files/setup.js';
7
6
  import type { InlineConfig, ResolvedConfig } from 'vite';
8
7
  import type { APIOptions } from '../api/types.js';
9
8
  type PrerenderOptions = APIOptions & {
@@ -30,5 +29,5 @@ declare function runPrerenderFromAPI(options?: PrerenderOptions): Promise<{
30
29
  viteConfig: ResolvedConfig;
31
30
  }>;
32
31
  declare function runPrerenderFromCLIPrerenderCommand(): Promise<void>;
33
- declare function runPrerenderFromAutoRun(viteConfig: InlineConfig | undefined, forceExit: boolean): Promise<void>;
32
+ declare function runPrerenderFromAutoRun(viteConfig: InlineConfig | undefined): Promise<void>;
34
33
  declare function runPrerender_forceExit(): void;