vike 0.4.237-commit-92dc549 → 0.4.237-commit-2d6f480

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 (89) hide show
  1. package/dist/cjs/client/runtime-server-routing/utils.js +1 -1
  2. package/dist/cjs/node/api/build.js +4 -30
  3. package/dist/cjs/node/api/prepareViteApiCall.js +0 -1
  4. package/dist/cjs/node/prerender/runPrerender.js +5 -6
  5. package/dist/cjs/node/runtime/renderPage/analyzePage.js +3 -1
  6. package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +1 -1
  7. package/dist/cjs/node/runtime/renderPage/execHookOnRenderHtml.js +1 -11
  8. package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +42 -46
  9. package/dist/cjs/node/runtime/renderPage/{renderPageAlreadyRouted.js → renderPageAfterRoute.js} +3 -4
  10. package/dist/cjs/node/runtime/renderPage.js +6 -9
  11. package/dist/cjs/node/runtime/utils.js +1 -1
  12. package/dist/cjs/node/vite/plugins/pluginBuild/handleAssetsManifest.js +3 -5
  13. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildApp.js +4 -11
  14. package/dist/cjs/node/vite/plugins/pluginBuild/pluginBuildConfig.js +120 -14
  15. package/dist/cjs/node/vite/plugins/pluginBuild.js +1 -2
  16. package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +3 -2
  17. package/dist/cjs/node/vite/plugins/pluginFileEnv.js +4 -3
  18. package/dist/cjs/node/vite/plugins/pluginPreview.js +1 -11
  19. package/dist/cjs/node/vite/shared/getOutDirs.js +5 -11
  20. package/dist/cjs/node/vite/shared/isViteServerSide.js +46 -19
  21. package/dist/cjs/shared/page-configs/{loadPageEntry.js → loadAndParseVirtualFilePageEntry.js} +2 -2
  22. package/dist/cjs/shared/page-configs/resolveVikeConfigPublic.js +5 -0
  23. package/dist/cjs/shared/route/execHookOnBeforeRoute.js +0 -1
  24. package/dist/cjs/shared/route/index.js +0 -1
  25. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  26. package/dist/cjs/utils/{augmentType.js → updateType.js} +3 -3
  27. package/dist/esm/__internal/index.d.ts +1 -1
  28. package/dist/esm/client/runtime-client-routing/createPageContextClientSide.js +2 -2
  29. package/dist/esm/client/runtime-client-routing/renderPageClientSide.js +6 -6
  30. package/dist/esm/client/runtime-client-routing/utils.d.ts +1 -1
  31. package/dist/esm/client/runtime-client-routing/utils.js +1 -1
  32. package/dist/esm/client/runtime-server-routing/createPageContextClientSide.js +3 -3
  33. package/dist/esm/client/runtime-server-routing/utils.d.ts +1 -1
  34. package/dist/esm/client/runtime-server-routing/utils.js +1 -1
  35. package/dist/esm/client/shared/loadPageConfigsLazyClientSide.js +2 -2
  36. package/dist/esm/node/api/build.js +5 -31
  37. package/dist/esm/node/api/prepareViteApiCall.d.ts +0 -2
  38. package/dist/esm/node/api/prepareViteApiCall.js +0 -1
  39. package/dist/esm/node/prerender/runPrerender.d.ts +9 -300
  40. package/dist/esm/node/prerender/runPrerender.js +6 -7
  41. package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +4 -3
  42. package/dist/esm/node/runtime/renderPage/analyzePage.js +3 -1
  43. package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +2 -2
  44. package/dist/esm/node/runtime/renderPage/execHookOnRenderHtml.d.ts +0 -1
  45. package/dist/esm/node/runtime/renderPage/execHookOnRenderHtml.js +1 -11
  46. package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -4
  47. package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +1 -1
  48. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.d.ts +105 -19
  49. package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +44 -48
  50. package/dist/esm/node/runtime/renderPage/{renderPageAlreadyRouted.d.ts → renderPageAfterRoute.d.ts} +20 -4
  51. package/dist/esm/node/runtime/renderPage/{renderPageAlreadyRouted.js → renderPageAfterRoute.js} +5 -6
  52. package/dist/esm/node/runtime/renderPage.js +8 -11
  53. package/dist/esm/node/runtime/utils.d.ts +1 -1
  54. package/dist/esm/node/runtime/utils.js +1 -1
  55. package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.d.ts +0 -1
  56. package/dist/esm/node/vite/plugins/pluginBuild/handleAssetsManifest.js +5 -7
  57. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildApp.js +3 -10
  58. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.d.ts +4 -0
  59. package/dist/esm/node/vite/plugins/pluginBuild/pluginBuildConfig.js +120 -17
  60. package/dist/esm/node/vite/plugins/pluginBuild.js +1 -2
  61. package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +3 -2
  62. package/dist/esm/node/vite/plugins/pluginFileEnv.js +4 -3
  63. package/dist/esm/node/vite/plugins/pluginPreview.js +3 -13
  64. package/dist/esm/node/vite/shared/getOutDirs.d.ts +1 -3
  65. package/dist/esm/node/vite/shared/getOutDirs.js +6 -12
  66. package/dist/esm/node/vite/shared/isViteServerSide.d.ts +1 -1
  67. package/dist/esm/node/vite/shared/isViteServerSide.js +46 -19
  68. package/dist/esm/shared/page-configs/loadAndParseVirtualFilePageEntry.d.ts +3 -0
  69. package/dist/esm/shared/page-configs/{loadPageEntry.js → loadAndParseVirtualFilePageEntry.js} +2 -2
  70. package/dist/esm/shared/page-configs/resolveVikeConfigPublic.js +5 -0
  71. package/dist/esm/shared/route/execHookOnBeforeRoute.d.ts +3 -3
  72. package/dist/esm/shared/route/execHookOnBeforeRoute.js +0 -1
  73. package/dist/esm/shared/route/index.d.ts +5 -6
  74. package/dist/esm/shared/route/index.js +0 -1
  75. package/dist/esm/types/Config.d.ts +2 -4
  76. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  77. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  78. package/dist/esm/utils/updateType.d.ts +3 -0
  79. package/dist/esm/utils/updateType.js +7 -0
  80. package/package.json +3 -3
  81. package/dist/cjs/node/runtime/renderPage/debugPageFiles.js +0 -52
  82. package/dist/cjs/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +0 -150
  83. package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +0 -23
  84. package/dist/esm/node/runtime/renderPage/debugPageFiles.js +0 -47
  85. package/dist/esm/node/vite/plugins/pluginBuild/pluginAutoFullBuild.d.ts +0 -5
  86. package/dist/esm/node/vite/plugins/pluginBuild/pluginAutoFullBuild.js +0 -145
  87. package/dist/esm/shared/page-configs/loadPageEntry.d.ts +0 -3
  88. package/dist/esm/utils/augmentType.d.ts +0 -3
  89. package/dist/esm/utils/augmentType.js +0 -7
@@ -1,7 +1,9 @@
1
1
  export { pluginBuildConfig };
2
2
  export { assertRollupInput };
3
3
  export { analyzeClientEntries };
4
- import { assert, addOnBeforeLogHook, removeFileExtension, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsImportPathNpmPackage, requireResolveDistFile, } from '../../utils.js';
4
+ export { pluginAutoFullBuild };
5
+ export { isPrerenderForceExit };
6
+ import { assert, addOnBeforeLogHook, removeFileExtension, unique, assertUsage, injectRollupInputs, normalizeRollupInput, onSetupBuild, assertIsImportPathNpmPackage, requireResolveDistFile, assertWarning, getGlobalObject, } from '../../utils.js';
5
7
  import { getVikeConfigInternal } from '../../shared/resolveVikeConfigInternal.js';
6
8
  import { findPageFiles } from '../../shared/findPageFiles.js';
7
9
  import { generateVirtualFileId } from '../../../shared/virtualFileId.js';
@@ -9,13 +11,21 @@ import { extractAssetsAddQuery } from '../../../shared/extractAssetsQuery.js';
9
11
  import { prependEntriesDir } from '../../../shared/prependEntriesDir.js';
10
12
  import { getFilePathResolved } from '../../shared/getFilePath.js';
11
13
  import { getConfigValueBuildTime } from '../../../../shared/page-configs/getConfigValueBuildTime.js';
12
- import { isViteServerSide_withoutEnv } from '../../shared/isViteServerSide.js';
13
- import { resolveOutDir_configEnvironment } from '../../shared/getOutDirs.js';
14
- import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig, } from './handleAssetsManifest.js';
14
+ import { isViteServerSide_withoutEnv, isViteServerSide_onlySsrEnv } from '../../shared/isViteServerSide.js';
15
+ import { handleAssetsManifest_assertUsageCssCodeSplit, handleAssetsManifest_getBuildConfig, handleAssetsManifest, handleAssetsManifest_assertUsageCssTarget, } from './handleAssetsManifest.js';
15
16
  import { resolveIncludeAssetsImportedByServer } from '../../../runtime/renderPage/getPageAssets/retrievePageAssetsProd.js';
17
+ import { isPrerenderAutoRunEnabled, wasPrerenderRun } from '../../../prerender/context.js';
18
+ import { isViteCliCall, getViteConfigFromCli } from '../../shared/isViteCliCall.js';
19
+ import pc from '@brillout/picocolors';
20
+ import { logErrorHint } from '../../../runtime/renderPage/logErrorHint.js';
21
+ import { isVikeCliOrApi } from '../../../api/context.js';
22
+ import { runPrerenderFromAutoRun } from '../../../prerender/runPrerenderEntry.js';
23
+ import { getManifestFilePathRelative } from '../../shared/getManifestFilePathRelative.js';
24
+ const globalObject = getGlobalObject('build/pluginAutoFullBuild.ts', {
25
+ forceExit: false,
26
+ });
16
27
  function pluginBuildConfig() {
17
28
  let config;
18
- let configUnresolved;
19
29
  return [
20
30
  {
21
31
  name: 'vike:build:pluginBuildConfig',
@@ -34,21 +44,9 @@ function pluginBuildConfig() {
34
44
  handleAssetsManifest_assertUsageCssCodeSplit(config);
35
45
  },
36
46
  },
37
- configEnvironment: {
38
- order: 'post',
39
- async handler(envName, configEnv) {
40
- assert(configUnresolved);
41
- return {
42
- build: {
43
- outDir: resolveOutDir_configEnvironment(configUnresolved, envName, configEnv),
44
- },
45
- };
46
- },
47
- },
48
47
  config: {
49
48
  order: 'post',
50
49
  async handler(config) {
51
- configUnresolved = config;
52
50
  onSetupBuild();
53
51
  const build = await handleAssetsManifest_getBuildConfig(config);
54
52
  return { build };
@@ -230,3 +228,108 @@ function assertRollupInput(config) {
230
228
  const htmlInput = htmlInputs[0];
231
229
  assertUsage(htmlInput === undefined, `The entry ${htmlInput} of config build.rollupOptions.input is an HTML entry which is forbidden when using Vike, instead follow https://vike.dev/add`);
232
230
  }
231
+ function pluginAutoFullBuild() {
232
+ let config;
233
+ return [
234
+ {
235
+ name: 'vike:build:pluginAutoFullBuild',
236
+ apply: 'build',
237
+ enforce: 'pre',
238
+ async configResolved(config_) {
239
+ config = config_;
240
+ await abortViteBuildSsr();
241
+ },
242
+ writeBundle: {
243
+ /* We can't use this because it breaks Vite's logging. TO-DO/eventually: try again with latest Vite version.
244
+ sequential: true,
245
+ order: 'pre',
246
+ */
247
+ async handler(options, bundle) {
248
+ try {
249
+ await handleAssetsManifest(config, this.environment, options, bundle);
250
+ await triggerPrerendering(config, this.environment, bundle);
251
+ }
252
+ catch (err) {
253
+ // We use try-catch also because:
254
+ // - Vite/Rollup swallows errors thrown inside the writeBundle() hook. (It doesn't swallow errors thrown inside the first writeBundle() hook while building the client-side, but it does swallow errors thrown inside the second writeBundle() while building the server-side triggered after Vike calls Vite's `build()` API.)
255
+ // - Avoid Rollup prefixing the error with [vike:build:pluginAutoFullBuild], see for example https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
256
+ console.error(err);
257
+ logErrorHint(err);
258
+ process.exit(1);
259
+ }
260
+ },
261
+ },
262
+ },
263
+ {
264
+ name: 'vike:build:pluginAutoFullBuild:post',
265
+ apply: 'build',
266
+ enforce: 'post',
267
+ closeBundle: {
268
+ sequential: true,
269
+ order: 'post',
270
+ handler() {
271
+ onSetupBuild();
272
+ handleAssetsManifest_assertUsageCssTarget(config, this.environment);
273
+ /* Let vike:build:pluginBuildApp force exit
274
+ runPrerender_forceExit()
275
+ */
276
+ },
277
+ },
278
+ },
279
+ ];
280
+ }
281
+ async function triggerPrerendering(config, viteEnv, bundle) {
282
+ const vikeConfig = await getVikeConfigInternal();
283
+ if (!isViteServerSide_onlySsrEnv(config, viteEnv))
284
+ return;
285
+ if (isDisabled(vikeConfig))
286
+ return;
287
+ // Workaround for @vitejs/plugin-legacy
288
+ // - The legacy plugin triggers its own Rollup build for the client-side.
289
+ // - The legacy plugin doesn't generate a manifest => we can use that to detect the legacy plugin build.
290
+ // - Issue & reproduction: https://github.com/vikejs/vike/issues/1154#issuecomment-1965954636
291
+ if (!bundle[getManifestFilePathRelative(config.build.manifest)])
292
+ return;
293
+ const configInline = getFullBuildInlineConfig(config);
294
+ if (isPrerenderAutoRunEnabled(vikeConfig)) {
295
+ const res = await runPrerenderFromAutoRun(configInline);
296
+ globalObject.forceExit = res.forceExit;
297
+ assert(wasPrerenderRun());
298
+ }
299
+ }
300
+ async function abortViteBuildSsr() {
301
+ const vikeConfig = await getVikeConfigInternal();
302
+ if (vikeConfig.config.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
303
+ assertWarning(false, `The CLI call ${pc.cyan('$ vite build --ssr')} is superfluous since ${pc.cyan('$ vite build')} also builds the server-side. If you want two separate build steps then use https://vike.dev/disableAutoFullBuild or use Vite's ${pc.cyan('build()')} API.`, { onlyOnce: true });
304
+ process.exit(0);
305
+ }
306
+ }
307
+ function isDisabled(vikeConfig) {
308
+ const { disableAutoFullBuild } = vikeConfig.config;
309
+ if (disableAutoFullBuild === undefined || disableAutoFullBuild === 'prerender') {
310
+ const isUserUsingViteApi = !isViteCliCall() && !isVikeCliOrApi();
311
+ return isUserUsingViteApi;
312
+ }
313
+ else {
314
+ return disableAutoFullBuild;
315
+ }
316
+ }
317
+ function isPrerenderForceExit() {
318
+ return globalObject.forceExit;
319
+ }
320
+ function getFullBuildInlineConfig(config) {
321
+ const configFromCli = !isViteCliCall() ? null : getViteConfigFromCli();
322
+ if (config._viteConfigFromUserEnhanced) {
323
+ return config._viteConfigFromUserEnhanced;
324
+ }
325
+ else {
326
+ return {
327
+ ...configFromCli,
328
+ configFile: configFromCli?.configFile || config.configFile,
329
+ root: config.root,
330
+ build: {
331
+ ...configFromCli?.build,
332
+ },
333
+ };
334
+ }
335
+ }
@@ -3,9 +3,8 @@ import { pluginBuildApp } from './pluginBuild/pluginBuildApp.js';
3
3
  import { pluginDistPackageJsonFile } from './pluginBuild/pluginDistPackageJsonFile.js';
4
4
  import { pluginSuppressRollupWarning } from './pluginBuild/pluginSuppressRollupWarning.js';
5
5
  import { pluginDistFileNames } from './pluginBuild/pluginDistFileNames.js';
6
- import { pluginAutoFullBuild } from './pluginBuild/pluginAutoFullBuild.js';
7
6
  import { pluginBuildEntry } from './pluginBuild/pluginBuildEntry.js';
8
- import { pluginBuildConfig } from './pluginBuild/pluginBuildConfig.js';
7
+ import { pluginBuildConfig, pluginAutoFullBuild } from './pluginBuild/pluginBuildConfig.js';
9
8
  import { pluginModuleBanner } from './pluginBuild/pluginModuleBanner.js';
10
9
  function pluginBuild() {
11
10
  return [
@@ -13,8 +13,9 @@ async function determineOptimizeDeps(config) {
13
13
  const { entriesClient, entriesServer, includeClient, includeServer } = await getPageDeps(config, pageConfigs);
14
14
  config.optimizeDeps.include = add(config.optimizeDeps.include, includeClient);
15
15
  config.optimizeDeps.entries = add(config.optimizeDeps.entries, entriesClient);
16
- // Workaround until https://github.com/vitejs/vite-plugin-react/issues/650
17
- // - TODO/soon: remove workaround once https://github.com/vitejs/vite/pull/20495 is released
16
+ // Workaround for https://github.com/vitejs/vite-plugin-react/issues/650
17
+ // - The issue was closed as completed with https://github.com/vitejs/vite/pull/20495 but it doesn't fix the issue and the workaround is still needed.
18
+ // - TO-DO/eventually: try removing the workaround and see if the CI fails (at test/@cloudflare_vite-plugin/) — maybe the issue will get fixed at some point.
18
19
  includeServer.push('react/jsx-dev-runtime');
19
20
  for (const envName in config.environments) {
20
21
  const env = config.environments[envName];
@@ -7,6 +7,7 @@ import { getModuleFilePathAbsolute } from '../shared/getFilePath.js';
7
7
  import { getExportNames } from '../shared/parseEsModule.js';
8
8
  import { normalizeId } from '../shared/normalizeId.js';
9
9
  import { isV1Design } from '../shared/resolveVikeConfigInternal.js';
10
+ import { isViteServerSide, isViteServerSide_extraSafe } from '../shared/isViteServerSide.js';
10
11
  function pluginFileEnv() {
11
12
  let config;
12
13
  let viteDevServer;
@@ -28,7 +29,7 @@ function pluginFileEnv() {
28
29
  const importers = Array.from(moduleInfo.importers)
29
30
  .map((m) => m.id)
30
31
  .filter((id) => id !== null);
31
- assertFileEnv(id, !!options?.ssr, importers,
32
+ assertFileEnv(id, isViteServerSide_extraSafe(config, options, this.environment), importers,
32
33
  // In dev, we only show a warning because we don't want to disrupt when the user plays with settings such as [ssr](https://vike.dev/ssr).
33
34
  true);
34
35
  },
@@ -40,7 +41,7 @@ function pluginFileEnv() {
40
41
  return;
41
42
  if (skip(id))
42
43
  return;
43
- const isServerSide = !!options?.ssr;
44
+ const isServerSide = isViteServerSide_extraSafe(config, options, this.environment);
44
45
  if (!isWrongEnv(id, isServerSide))
45
46
  return;
46
47
  const { importers } = this.getModuleInfo(id);
@@ -66,7 +67,7 @@ function pluginFileEnv() {
66
67
  */
67
68
  return;
68
69
  }
69
- assertFileEnv(moduleId, !!config.build.ssr, importers, false);
70
+ assertFileEnv(moduleId, isViteServerSide(config, this.environment), importers, false);
70
71
  });
71
72
  },
72
73
  configResolved(config_) {
@@ -1,34 +1,24 @@
1
1
  export { pluginPreview };
2
- import { assertUsage, applyPreview, assert } from '../utils.js';
2
+ import { assertUsage, applyPreview } from '../utils.js';
3
3
  import fs from 'node:fs';
4
4
  import path from 'node:path';
5
5
  import { addSsrMiddleware } from '../shared/addSsrMiddleware.js';
6
6
  import pc from '@brillout/picocolors';
7
7
  import { logDockerHint } from './pluginDev.js';
8
- import { getOutDirs, resolveOutDir_configEnvironment } from '../shared/getOutDirs.js';
8
+ import { getOutDirs } from '../shared/getOutDirs.js';
9
9
  import sirv from 'sirv';
10
10
  import { getVikeConfigInternal } from '../shared/resolveVikeConfigInternal.js';
11
11
  function pluginPreview() {
12
12
  let config;
13
- let configUnresolved;
14
13
  let vikeConfig;
15
14
  return {
16
15
  name: 'vike:pluginPreview',
17
16
  apply: applyPreview,
18
- config(config) {
19
- configUnresolved = config;
17
+ config() {
20
18
  return {
21
19
  appType: 'custom',
22
20
  };
23
21
  },
24
- configEnvironment(envName, configEnv) {
25
- assert(configUnresolved);
26
- return {
27
- build: {
28
- outDir: resolveOutDir_configEnvironment(configUnresolved, envName, configEnv),
29
- },
30
- };
31
- },
32
22
  async configResolved(config_) {
33
23
  config = config_;
34
24
  vikeConfig = await getVikeConfigInternal();
@@ -1,8 +1,7 @@
1
1
  export { getOutDirs };
2
2
  export { resolveOutDir };
3
- export { resolveOutDir_configEnvironment };
4
3
  export type { OutDirs };
5
- import type { UserConfig, ResolvedConfig, EnvironmentOptions } from 'vite';
4
+ import type { UserConfig, ResolvedConfig } from 'vite';
6
5
  import { ViteEnv } from './isViteServerSide.js';
7
6
  type OutDirs = {
8
7
  /** Absolute path to `outDir` */
@@ -13,6 +12,5 @@ type OutDirs = {
13
12
  outDirServer: string;
14
13
  };
15
14
  declare function getOutDirs(configGlobal: ResolvedConfig, viteEnv: ViteEnv | undefined): OutDirs;
16
- declare function resolveOutDir_configEnvironment(configGlobal: UserConfig, envName: string, configEnv: EnvironmentOptions): string;
17
15
  /** Appends `client/` or `server/` to `config.build.outDir` */
18
16
  declare function resolveOutDir(config: UserConfig, isServerSide: boolean): string;
@@ -1,13 +1,12 @@
1
1
  export { getOutDirs };
2
2
  export { resolveOutDir };
3
- export { resolveOutDir_configEnvironment };
4
3
  import pc from '@brillout/picocolors';
5
4
  import { assert, assertPosixPath, assertUsage, createDebugger, pathJoin, toPosixPath } from '../utils.js';
6
- import { isViteServerSide, isViteServerSide_withoutEnv } from './isViteServerSide.js';
5
+ import { isViteServerSide_withoutEnv } from './isViteServerSide.js';
7
6
  const debug = createDebugger('vike:outDir');
8
7
  function getOutDirs(configGlobal, viteEnv) {
9
8
  debug('getOutDirs()', new Error().stack);
10
- const outDir = getOutDirFromResolvedConfig(configGlobal);
9
+ const outDir = getOutDirFromResolvedConfig(configGlobal, viteEnv);
11
10
  assertOutDirResolved(outDir, configGlobal, viteEnv);
12
11
  const outDirs = getOutDirsAll(outDir, configGlobal.root);
13
12
  assertNormalization(outDirs.outDirRoot);
@@ -15,12 +14,6 @@ function getOutDirs(configGlobal, viteEnv) {
15
14
  assertNormalization(outDirs.outDirServer);
16
15
  return outDirs;
17
16
  }
18
- function resolveOutDir_configEnvironment(configGlobal, envName, configEnv) {
19
- assert(configGlobal && envName && configEnv);
20
- const viteEnv = { name: envName, config: configEnv };
21
- const isServerSide = isViteServerSide(configGlobal, viteEnv);
22
- return resolveOutDir(configEnv, isServerSide);
23
- }
24
17
  /** Appends `client/` or `server/` to `config.build.outDir` */
25
18
  function resolveOutDir(config, isServerSide) {
26
19
  debug('resolveOutDir()', new Error().stack);
@@ -114,7 +107,8 @@ function assertOutDirResolved(outDir, configGlobal, viteEnv) {
114
107
  assert('/client'.length === '/server'.length);
115
108
  const outDirCorrected = outDir.slice(0, -1 * '/client'.length);
116
109
  const wrongUsage = `You've set Vite's config.build.outDir to ${pc.cyan(outDir)} but you should set it to ${pc.cyan(outDirCorrected)} instead.`;
117
- if (isViteServerSide_withoutEnv(configGlobal, viteEnv)) {
110
+ const isServerSide = isViteServerSide_withoutEnv(configGlobal, viteEnv);
111
+ if (isServerSide) {
118
112
  assertUsage(outDir.endsWith('/server'), wrongUsage);
119
113
  }
120
114
  else {
@@ -128,8 +122,8 @@ function getOutDirFromViteUserConfig(config) {
128
122
  outDir = normalizeOutDir(outDir);
129
123
  return outDir;
130
124
  }
131
- function getOutDirFromResolvedConfig(config) {
132
- let outDir = config.build.outDir;
125
+ function getOutDirFromResolvedConfig(config, viteEnv) {
126
+ let outDir = viteEnv?.config.build?.outDir ?? config.build.outDir;
133
127
  assert(outDir);
134
128
  outDir = normalizeOutDir(outDir);
135
129
  return outDir;
@@ -9,8 +9,8 @@ type ViteEnv = {
9
9
  name?: string;
10
10
  config: EnvironmentOptions | Environment['config'];
11
11
  };
12
- declare function isViteServerSide_withoutEnv(configGlobal: ResolvedConfig | UserConfig, viteEnv?: ViteEnv): boolean;
13
12
  declare function isViteServerSide(configGlobal: ResolvedConfig | UserConfig, viteEnv: ViteEnv): boolean;
13
+ declare function isViteServerSide_withoutEnv(configGlobal: ResolvedConfig | UserConfig, viteEnv?: ViteEnv | undefined): boolean;
14
14
  declare function isViteClientSide(configGlobal: ResolvedConfig, viteEnv: ViteEnv): boolean;
15
15
  declare function isViteServerSide_onlySsrEnv(configGlobal: ResolvedConfig, viteEnv: ViteEnv): boolean;
16
16
  declare function isViteServerSide_extraSafe(config: ResolvedConfig, options: {
@@ -4,16 +4,16 @@ export { isViteServerSide_withoutEnv };
4
4
  export { isViteServerSide_onlySsrEnv };
5
5
  export { isViteServerSide_extraSafe };
6
6
  import { assert } from '../../../utils/assert.js';
7
- function isViteServerSide_withoutEnv(configGlobal, viteEnv) {
7
+ function isViteServerSide_impl(configGlobal, viteEnv) {
8
8
  assert(!('consumer' in configGlobal)); // make sure configGlobal isn't viteEnv.config
9
9
  const isServerSide1 = !viteEnv?.config.consumer ? null : viteEnv.config.consumer !== 'client';
10
- const isServerSide2 = !viteEnv?.name ? null : viteEnv.name !== 'client'; // I can't think of a use case for creating another client-side environment
11
- const isServerSide3 = !viteEnv ? null : !!viteEnv.config.build?.ssr;
12
- const isServerSide4 = !!configGlobal.build?.ssr;
10
+ const isServerSide2 = !viteEnv?.config.build ? null : getBuildSsrValue(viteEnv.config.build.ssr);
11
+ const isServerSide3 = !configGlobal.build ? null : getBuildSsrValue(configGlobal.build.ssr);
12
+ const isServerSide4 = viteEnv?.name === 'ssr' ? true : viteEnv?.name === 'client' ? false : null;
13
13
  const debug = {
14
- envIsUndefined: !viteEnv,
15
- envName: viteEnv?.name ?? null,
16
- envConsumer: viteEnv?.config.consumer ?? null,
14
+ viteEnvIsUndefined: !viteEnv,
15
+ viteEnvName: viteEnv?.name ?? null,
16
+ viteEnvConsumer: viteEnv?.config.consumer ?? null,
17
17
  configEnvBuildSsr: viteEnv?.config.build?.ssr ?? null,
18
18
  configGlobalBuildSsr: configGlobal.build?.ssr ?? null,
19
19
  isServerSide1,
@@ -22,25 +22,36 @@ function isViteServerSide_withoutEnv(configGlobal, viteEnv) {
22
22
  isServerSide4,
23
23
  };
24
24
  if (isServerSide1 !== null) {
25
- assert(isServerSide1 === isServerSide2 || isServerSide2 === null, debug);
25
+ // assert(isServerSide1 === isServerSide4 || isServerSide4 === null, debug)
26
26
  /* This assertion can fail, seems to be a Vite bug?
27
- assert(isServerSide1 === isServerSide3, debug)
27
+ assert(isServerSide1 === isServerSide2, debug)
28
28
  */
29
29
  return isServerSide1;
30
30
  }
31
31
  if (isServerSide2 !== null) {
32
- /* This assertion can fail, seems to be a Vite bug?
33
- assert(isServerSide2 === isServerSide3, debug)
34
- */
32
+ // assert(isServerSide2 === isServerSide4 || isServerSide4 === null, debug)
35
33
  return isServerSide2;
36
34
  }
37
35
  if (isServerSide3 !== null) {
36
+ // assert(isServerSide3 === isServerSide4 || isServerSide4 === null, debug)
38
37
  return isServerSide3;
39
38
  }
40
- return isServerSide4;
39
+ if (isServerSide4 !== null) {
40
+ return isServerSide4;
41
+ }
42
+ assert(!viteEnv);
43
+ return !!configGlobal.build?.ssr;
44
+ }
45
+ function getBuildSsrValue(buildSsr) {
46
+ if (buildSsr === undefined)
47
+ return null;
48
+ return !!buildSsr;
41
49
  }
42
50
  function isViteServerSide(configGlobal, viteEnv) {
43
- return isViteServerSide_withoutEnv(configGlobal, viteEnv);
51
+ return isViteServerSide_impl(configGlobal, viteEnv);
52
+ }
53
+ function isViteServerSide_withoutEnv(configGlobal, viteEnv) {
54
+ return isViteServerSide_impl(configGlobal, viteEnv);
44
55
  }
45
56
  function isViteClientSide(configGlobal, viteEnv) {
46
57
  return !isViteServerSide(configGlobal, viteEnv);
@@ -51,20 +62,36 @@ function isViteServerSide_onlySsrEnv(configGlobal, viteEnv) {
51
62
  }
52
63
  // Vite is quite messy about setting config.build.ssr — for security purposes, we use an extra safe implementation with lots of assertions, which is needed for the .client.js and .server.js guarantee.
53
64
  function isViteServerSide_extraSafe(config, options, viteEnv) {
65
+ const isServerSide = isViteServerSide(config, viteEnv);
66
+ const debug = {
67
+ configCommand: config.command,
68
+ configBuildSsr: config.build.ssr,
69
+ optionsIsUndefined: options === undefined,
70
+ optionsSsr: options?.ssr,
71
+ isServerSide,
72
+ };
73
+ if (true) {
74
+ const res = options?.ssr;
75
+ if (typeof res === 'boolean') {
76
+ assert(res === isServerSide, debug);
77
+ return res;
78
+ }
79
+ return isServerSide;
80
+ }
54
81
  if (config.command === 'build') {
55
82
  const res = config.build.ssr;
56
- assert(typeof res === 'boolean');
57
- assert(res === options?.ssr || options?.ssr === undefined);
58
- assert(res === isViteServerSide(config, viteEnv));
83
+ assert(typeof res === 'boolean', debug);
84
+ assert(res === options?.ssr || options?.ssr === undefined, debug);
85
+ assert(res === isServerSide, debug);
59
86
  return res;
60
87
  }
61
88
  else {
62
89
  const res = options?.ssr;
63
- assert(typeof res === 'boolean');
90
+ assert(typeof res === 'boolean', debug);
64
91
  /* This assertion can fail, seems to be a Vite bug? It's very unexpected.
65
92
  if (typeof config.build.ssr === 'boolean') assert(res === config.build.ssr)
66
93
  */
67
- assert(res === isViteServerSide(config, viteEnv));
94
+ assert(res === isServerSide, debug);
68
95
  return res;
69
96
  }
70
97
  }
@@ -0,0 +1,3 @@
1
+ export { loadAndParseVirtualFilePageEntry };
2
+ import type { PageConfigRuntime, PageConfigRuntimeLoaded } from '../../types/PageConfig.js';
3
+ declare function loadAndParseVirtualFilePageEntry(pageConfig: PageConfigRuntime, isDev: boolean): Promise<PageConfigRuntimeLoaded>;
@@ -1,7 +1,7 @@
1
- export { loadPageEntry };
1
+ export { loadAndParseVirtualFilePageEntry };
2
2
  import { assert, objectAssign } from '../utils.js';
3
3
  import { parseConfigValuesSerialized } from './serialize/parsePageConfigsSerialized.js';
4
- async function loadPageEntry(pageConfig, isDev) {
4
+ async function loadAndParseVirtualFilePageEntry(pageConfig, isDev) {
5
5
  if ('isPageEntryLoaded' in pageConfig &&
6
6
  // We don't need to cache in dev, since Vite already caches the virtual module
7
7
  !isDev) {
@@ -1,3 +1,8 @@
1
+ // TO-DO/soon: rename PageConfig names
2
+ // - Use `Internal` suffix, i.e. {Page,Global}ConfigInternal
3
+ // - While keeping {Page,Global}ConfigPublic or remove Public suffix and rename it to {Page,Global}Config ?
4
+ // - rename EagerLoaded EagerlyLoaded
5
+ // - remove `LazyLoaded` suffix
1
6
  // TO-DO/soon/same-api: use public API internally?
2
7
  // TO-DO/soon/flat-pageContext: rename definedAt => definedBy
3
8
  export { resolveVikeConfigPublicGlobal };
@@ -1,7 +1,7 @@
1
1
  export { execHookOnBeforeRoute };
2
- import type { PageContextForRoute, PageContextFromRoute } from './index.js';
3
- declare function execHookOnBeforeRoute(pageContext: PageContextForRoute): Promise<null | ({
2
+ import type { PageContextBeforeRoute, PageContextAfterRoute } from './index.js';
3
+ declare function execHookOnBeforeRoute(pageContext: PageContextBeforeRoute): Promise<null | ({
4
4
  _routingProvidedByOnBeforeRouteHook: true;
5
- } & PageContextFromRoute) | {
5
+ } & PageContextAfterRoute) | {
6
6
  _routingProvidedByOnBeforeRouteHook: false;
7
7
  }>;
@@ -23,7 +23,6 @@ async function execHookOnBeforeRoute(pageContext) {
23
23
  }
24
24
  objectAssign(pageContextFromOnBeforeRouteHook, {
25
25
  _routingProvidedByOnBeforeRouteHook: true,
26
- _debugRouteMatches: 'CUSTOM_ROUTING',
27
26
  });
28
27
  return pageContextFromOnBeforeRouteHook;
29
28
  }
@@ -1,19 +1,18 @@
1
1
  export { route };
2
- export type { PageContextForRoute };
3
- export type { PageContextFromRoute };
2
+ export type { PageContextBeforeRoute };
3
+ export type { PageContextAfterRoute };
4
4
  export type { PageRoutes };
5
5
  export type { RouteMatches };
6
6
  import { type PageContextUrlInternal, type PageContextUrlSource } from '../getPageContextUrlComputed.js';
7
7
  import type { PageRoutes, RouteType } from './loadPageRoutes.js';
8
8
  import type { GlobalContextInternal } from '../createGlobalContextShared.js';
9
- type PageContextForRoute = PageContextUrlInternal & {
9
+ type PageContextBeforeRoute = PageContextUrlInternal & {
10
10
  _globalContext: GlobalContextInternal;
11
11
  } & PageContextUrlSource;
12
- type PageContextFromRoute = {
12
+ type PageContextAfterRoute = {
13
13
  pageId: string | null;
14
14
  routeParams: Record<string, string>;
15
15
  _routingProvidedByOnBeforeRouteHook?: boolean;
16
- _debugRouteMatches: RouteMatches;
17
16
  };
18
17
  type RouteMatch = {
19
18
  pageId: string;
@@ -23,4 +22,4 @@ type RouteMatch = {
23
22
  routeParams: Record<string, string>;
24
23
  };
25
24
  type RouteMatches = 'CUSTOM_ROUTING' | RouteMatch[];
26
- declare function route(pageContext: PageContextForRoute, skipOnBeforeRouteHook?: true): Promise<PageContextFromRoute>;
25
+ declare function route(pageContext: PageContextBeforeRoute, skipOnBeforeRouteHook?: true): Promise<PageContextAfterRoute>;
@@ -81,7 +81,6 @@ async function route(pageContext, skipOnBeforeRouteHook) {
81
81
  resolvePrecedence(routeMatches);
82
82
  const winner = routeMatches[0] ?? null;
83
83
  debug(`Route matches for URL ${pc.cyan(urlPathname)} (in precedence order):`, routeMatches);
84
- objectAssign(pageContextFromRoute, { _debugRouteMatches: routeMatches });
85
84
  // For vite-plugin-vercel https://github.com/magne4000/vite-plugin-vercel/blob/main/packages/vike-integration/vike.ts#L173
86
85
  objectAssign(pageContextFromRoute, { _routeMatch: winner });
87
86
  if (!winner) {
@@ -404,11 +404,9 @@ type ConfigBuiltIn = {
404
404
  /** @deprecated See https://vike.dev/disableAutoFullBuild */
405
405
  disableAutoFullBuild?: boolean | 'prerender';
406
406
  /**
407
- * Use builder.buildApp() to orchestrate the build process.
408
- *
409
- * @experimental
407
+ * @deprecated It's value is now always true.
410
408
  */
411
- vite6BuilderApp?: boolean;
409
+ vite6BuilderApp?: true;
412
410
  /** The Base URL of your server.
413
411
  *
414
412
  * https://vike.dev/base-url
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.237-commit-92dc549";
1
+ export declare const PROJECT_VERSION: "0.4.237-commit-2d6f480";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.237-commit-92dc549';
2
+ export const PROJECT_VERSION = '0.4.237-commit-2d6f480';
@@ -0,0 +1,3 @@
1
+ export { updateType };
2
+ /** Help TypeScript update the type of dynamically modified objects. */
3
+ declare function updateType<Thing, Clone>(thing: Thing, clone: Clone): asserts thing is Thing & Clone;
@@ -0,0 +1,7 @@
1
+ export { updateType };
2
+ import { assert } from './assert.js';
3
+ /** Help TypeScript update the type of dynamically modified objects. */
4
+ function updateType(thing, clone) {
5
+ // @ts-ignore
6
+ assert(thing === clone);
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.237-commit-92dc549",
3
+ "version": "0.4.237-commit-2d6f480",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -132,7 +132,7 @@
132
132
  "@brillout/json-serializer": "^0.5.20",
133
133
  "@brillout/picocolors": "^1.0.26",
134
134
  "@brillout/require-shim": "^0.1.2",
135
- "@brillout/vite-plugin-server-entry": "^0.7.12",
135
+ "@brillout/vite-plugin-server-entry": "^0.7.13",
136
136
  "acorn": "^8.0.0",
137
137
  "cac": "^6.0.0",
138
138
  "es-module-lexer": "^1.0.0",
@@ -263,7 +263,7 @@
263
263
  "react-streaming": "^0.4.3",
264
264
  "rimraf": "^5.0.5",
265
265
  "typescript": "^5.8.3",
266
- "vite": "^7.0.6"
266
+ "vite": "^7.1.3"
267
267
  },
268
268
  "scripts": {
269
269
  "dev": "tsc --watch",