vike 0.4.213 → 0.4.215

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 (69) hide show
  1. package/dist/cjs/node/api/build.js +9 -3
  2. package/dist/cjs/node/api/context.js +18 -0
  3. package/dist/cjs/node/api/dev.js +6 -3
  4. package/dist/cjs/node/api/onLoad.js +9 -0
  5. package/dist/cjs/node/api/{enhanceViteConfig.js → prepareApiCall.js} +11 -6
  6. package/dist/cjs/node/api/prerender.js +6 -3
  7. package/dist/cjs/node/api/preview.js +6 -3
  8. package/dist/cjs/node/api/utils.js +21 -0
  9. package/dist/cjs/node/cli/entry.js +8 -8
  10. package/dist/cjs/node/cli/onLoad.js +2 -0
  11. package/dist/cjs/node/cli/parseCli.js +2 -2
  12. package/dist/cjs/node/plugin/index.js +3 -1
  13. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +0 -3
  14. package/dist/cjs/node/plugin/plugins/commonConfig/pluginName.js +1 -1
  15. package/dist/cjs/node/plugin/plugins/commonConfig.js +5 -1
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -15
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -7
  18. package/dist/cjs/node/plugin/plugins/vite6HmrRegressionWorkaround.js +35 -0
  19. package/dist/cjs/node/prerender/runPrerender.js +4 -3
  20. package/dist/cjs/shared/page-configs/getConfigValue.js +2 -31
  21. package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +2 -2
  22. package/dist/cjs/shared/page-configs/getConfigValueTyped.js +32 -0
  23. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  24. package/dist/esm/node/api/build.d.ts +5 -3
  25. package/dist/esm/node/api/build.js +9 -3
  26. package/dist/esm/node/api/context.d.ts +5 -0
  27. package/dist/esm/node/api/context.js +17 -0
  28. package/dist/esm/node/api/dev.d.ts +6 -2
  29. package/dist/esm/node/api/dev.js +6 -3
  30. package/dist/esm/node/api/onLoad.d.ts +2 -0
  31. package/dist/esm/node/api/onLoad.js +7 -0
  32. package/dist/esm/node/api/prepareApiCall.d.ts +7 -0
  33. package/dist/esm/node/api/{enhanceViteConfig.js → prepareApiCall.js} +11 -6
  34. package/dist/esm/node/api/prerender.d.ts +4 -1
  35. package/dist/esm/node/api/prerender.js +6 -3
  36. package/dist/esm/node/api/preview.d.ts +6 -2
  37. package/dist/esm/node/api/preview.js +6 -3
  38. package/dist/esm/node/api/{APIOptions.d.ts → types.d.ts} +3 -1
  39. package/dist/esm/node/api/utils.d.ts +1 -0
  40. package/dist/esm/node/api/utils.js +5 -0
  41. package/dist/esm/node/cli/entry.js +8 -8
  42. package/dist/esm/node/cli/onLoad.js +2 -0
  43. package/dist/esm/node/cli/parseCli.js +2 -2
  44. package/dist/esm/node/plugin/index.js +3 -1
  45. package/dist/esm/node/plugin/plugins/autoFullBuild.js +0 -3
  46. package/dist/esm/node/plugin/plugins/commonConfig/pluginName.d.ts +1 -1
  47. package/dist/esm/node/plugin/plugins/commonConfig/pluginName.js +1 -1
  48. package/dist/esm/node/plugin/plugins/commonConfig.js +5 -1
  49. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
  50. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +2 -16
  51. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -7
  52. package/dist/esm/node/plugin/plugins/vite6HmrRegressionWorkaround.d.ts +3 -0
  53. package/dist/esm/node/plugin/plugins/vite6HmrRegressionWorkaround.js +33 -0
  54. package/dist/esm/node/prerender/runPrerender.d.ts +5 -3
  55. package/dist/esm/node/prerender/runPrerender.js +4 -3
  56. package/dist/esm/shared/ConfigVike.d.ts +1 -1
  57. package/dist/esm/shared/page-configs/getConfigValue.d.ts +2 -8
  58. package/dist/esm/shared/page-configs/getConfigValue.js +1 -27
  59. package/dist/esm/shared/page-configs/getConfigValueBuildTime.d.ts +2 -3
  60. package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +1 -1
  61. package/dist/esm/shared/page-configs/getConfigValueTyped.d.ts +9 -0
  62. package/dist/esm/shared/page-configs/getConfigValueTyped.js +27 -0
  63. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  64. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  65. package/dist/esm/utils/projectInfo.d.ts +1 -1
  66. package/package.json +13 -6
  67. package/dist/esm/node/api/enhanceViteConfig.d.ts +0 -6
  68. /package/dist/cjs/node/api/{APIOptions.js → types.js} +0 -0
  69. /package/dist/esm/node/api/{APIOptions.js → types.js} +0 -0
@@ -0,0 +1,7 @@
1
+ export { onLoad };
2
+ import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
3
+ import { assertIsNotProductionRuntime } from '../runtime/utils.js';
4
+ function onLoad() {
5
+ assertIsNotBrowser();
6
+ assertIsNotProductionRuntime();
7
+ }
@@ -0,0 +1,7 @@
1
+ export { prepareApiCall };
2
+ import type { InlineConfig } from 'vite';
3
+ import type { Operation } from './types.js';
4
+ declare function prepareApiCall(viteConfig: InlineConfig | undefined, operation: Operation): Promise<{
5
+ viteConfigEnhanced: InlineConfig;
6
+ configVike: import("../../shared/ConfigVike.js").ConfigVikeResolved;
7
+ }>;
@@ -1,9 +1,14 @@
1
- export { enhanceViteConfig };
1
+ export { prepareApiCall };
2
2
  import { resolveConfig } from 'vite';
3
3
  import { getConfigVike } from '../shared/getConfigVike.js';
4
4
  import { pluginName } from '../plugin/plugins/commonConfig/pluginName.js';
5
- async function enhanceViteConfig(viteConfig = {}, command) {
6
- let viteConfigResolved = await resolveViteConfig(viteConfig, command);
5
+ import { setOperation } from './context.js';
6
+ async function prepareApiCall(viteConfig = {}, operation) {
7
+ setOperation(operation);
8
+ return enhanceViteConfig(viteConfig, operation);
9
+ }
10
+ async function enhanceViteConfig(viteConfig = {}, operation) {
11
+ let viteConfigResolved = await resolveViteConfig(viteConfig, operation);
7
12
  let viteConfigEnhanced = viteConfig;
8
13
  // Add vike to plugins if not present
9
14
  if (!viteConfigResolved.plugins.some((p) => p.name === pluginName)) {
@@ -13,7 +18,7 @@ async function enhanceViteConfig(viteConfig = {}, command) {
13
18
  ...viteConfig,
14
19
  plugins: [...(viteConfig.plugins ?? []), vikePlugin()]
15
20
  };
16
- viteConfigResolved = await resolveViteConfig(viteConfigEnhanced, command);
21
+ viteConfigResolved = await resolveViteConfig(viteConfigEnhanced, operation);
17
22
  }
18
23
  const configVike = await getConfigVike(viteConfigResolved);
19
24
  // TODO: enable Vike extensions to add Vite plugins
@@ -22,6 +27,6 @@ async function enhanceViteConfig(viteConfig = {}, command) {
22
27
  configVike
23
28
  };
24
29
  }
25
- async function resolveViteConfig(viteConfig, command) {
26
- return await resolveConfig(viteConfig, command === 'build' || command === 'prerender' ? 'build' : 'serve', 'custom', command === 'dev' ? 'development' : 'production', command === 'preview');
30
+ async function resolveViteConfig(viteConfig, operation) {
31
+ return await resolveConfig(viteConfig, operation === 'build' || operation === 'prerender' ? 'build' : 'serve', 'custom', operation === 'dev' ? 'development' : 'production', operation === 'preview');
27
32
  }
@@ -1,3 +1,6 @@
1
1
  export { prerender };
2
2
  import { type PrerenderOptions } from '../prerender/runPrerender.js';
3
- declare function prerender(options?: PrerenderOptions): Promise<void>;
3
+ import type { ResolvedConfig } from 'vite';
4
+ declare function prerender(options?: PrerenderOptions): Promise<{
5
+ viteConfig: ResolvedConfig;
6
+ }>;
@@ -1,8 +1,11 @@
1
1
  export { prerender };
2
2
  import { runPrerenderFromAPI } from '../prerender/runPrerender.js';
3
- import { enhanceViteConfig } from './enhanceViteConfig.js';
3
+ import { prepareApiCall } from './prepareApiCall.js';
4
4
  async function prerender(options = {}) {
5
- const { viteConfigEnhanced } = await enhanceViteConfig(options.viteConfig, 'prerender');
5
+ const { viteConfigEnhanced } = await prepareApiCall(options.viteConfig, 'prerender');
6
6
  options.viteConfig = viteConfigEnhanced;
7
- await runPrerenderFromAPI(options);
7
+ const { viteConfig } = await runPrerenderFromAPI(options);
8
+ return {
9
+ viteConfig
10
+ };
8
11
  }
@@ -1,3 +1,7 @@
1
1
  export { preview };
2
- import type { APIOptions } from './APIOptions.js';
3
- declare function preview(options?: APIOptions): Promise<import("vite").PreviewServer>;
2
+ import { type ResolvedConfig, type PreviewServer } from 'vite';
3
+ import type { APIOptions } from './types.js';
4
+ declare function preview(options?: APIOptions): Promise<{
5
+ viteServer: PreviewServer;
6
+ viteConfig: ResolvedConfig;
7
+ }>;
@@ -1,8 +1,11 @@
1
1
  export { preview };
2
- import { enhanceViteConfig } from './enhanceViteConfig.js';
2
+ import { prepareApiCall } from './prepareApiCall.js';
3
3
  import { preview as previewVite } from 'vite';
4
4
  async function preview(options = {}) {
5
- const { viteConfigEnhanced } = await enhanceViteConfig(options.viteConfig, 'preview');
5
+ const { viteConfigEnhanced } = await prepareApiCall(options.viteConfig, 'preview');
6
6
  const server = await previewVite(viteConfigEnhanced);
7
- return server;
7
+ return {
8
+ viteServer: server,
9
+ viteConfig: server.config
10
+ };
8
11
  }
@@ -1,4 +1,5 @@
1
- export { APIOptions };
1
+ export type { APIOptions };
2
+ export type { Operation };
2
3
  import type { InlineConfig } from 'vite';
3
4
  type APIOptions = {
4
5
  /**
@@ -8,3 +9,4 @@ type APIOptions = {
8
9
  */
9
10
  viteConfig?: InlineConfig;
10
11
  };
12
+ type Operation = 'build' | 'dev' | 'preview' | 'prerender';
@@ -0,0 +1 @@
1
+ export * from '../../utils/assert.js';
@@ -0,0 +1,5 @@
1
+ // Utils needed by Vike's API
2
+ // We call onLoad() here so that it's called even when only a subset of the API is loaded. (Making the assert() calls inside onLoad() a lot stronger.)
3
+ import { onLoad } from './onLoad.js';
4
+ onLoad();
5
+ export * from '../../utils/assert.js';
@@ -21,16 +21,16 @@ async function cli() {
21
21
  async function cmdDev() {
22
22
  const startTime = performance.now();
23
23
  try {
24
- const server = await dev();
25
- await server.listen();
26
- const info = server.config.logger.info;
24
+ const { viteServer } = await dev();
25
+ await viteServer.listen();
26
+ const info = viteServer.config.logger.info;
27
27
  const startupDurationString = pc.dim(`ready in ${pc.reset(pc.bold(String(Math.ceil(performance.now() - startTime))))} ms`);
28
28
  const hasExistingLogs = process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0;
29
29
  info(` ${pc.yellow(`${pc.bold(projectInfo.projectName)} v${projectInfo.projectVersion}`)} ${startupDurationString}\n`, {
30
30
  clear: !hasExistingLogs
31
31
  });
32
- server.printUrls();
33
- server.bindCLIShortcuts({ print: true });
32
+ viteServer.printUrls();
33
+ viteServer.bindCLIShortcuts({ print: true });
34
34
  }
35
35
  catch (err) {
36
36
  console.error(pc.red(`Error while starting dev server:`));
@@ -52,9 +52,9 @@ async function cmdBuild() {
52
52
  }
53
53
  async function cmdPreview() {
54
54
  try {
55
- const server = await preview();
56
- server.printUrls();
57
- server.bindCLIShortcuts({ print: true });
55
+ const { viteServer } = await preview();
56
+ viteServer.printUrls();
57
+ viteServer.bindCLIShortcuts({ print: true });
58
58
  }
59
59
  catch (err) {
60
60
  console.error(pc.red(`Error while starting preview server:`));
@@ -1,5 +1,7 @@
1
1
  export { onLoad };
2
2
  import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
3
+ import { assertIsNotProductionRuntime } from '../runtime/utils.js';
3
4
  function onLoad() {
4
5
  assertIsNotBrowser();
6
+ assertIsNotProductionRuntime();
5
7
  }
@@ -4,8 +4,8 @@ import { projectInfo, includes } from './utils.js';
4
4
  const commands = [
5
5
  { name: 'dev', desc: 'Start development server' },
6
6
  { name: 'build', desc: 'Build for production' },
7
- { name: 'preview', desc: 'Start preview server using production build' },
8
- { name: 'prerender', desc: 'Pre-render pages' }
7
+ { name: 'preview', desc: 'Start preview server using production build (only works for SSG apps)' },
8
+ { name: 'prerender', desc: 'Pre-render pages (only needed when partial.disableAutoRun is true)' }
9
9
  ];
10
10
  function parseCli() {
11
11
  const command = (() => {
@@ -27,6 +27,7 @@ import { fileEnv } from './plugins/fileEnv.js';
27
27
  import { setResolveClientEntriesDev } from '../runtime/renderPage/getPageAssets.js';
28
28
  import { resolveClientEntriesDev } from './resolveClientEntriesDev.js';
29
29
  import { workaroundCssModuleHmr } from './plugins/workaroundCssModuleHmr.js';
30
+ import { vite6HmrRegressionWorkaround } from './plugins/vite6HmrRegressionWorkaround.js';
30
31
  assertNodeEnv_onVikePluginLoad();
31
32
  markEnvAsVikePluginLoaded();
32
33
  assertViteVersion();
@@ -52,7 +53,8 @@ function plugin(vikeConfig) {
52
53
  baseUrls(vikeConfig),
53
54
  envVarsPlugin(),
54
55
  fileEnv(),
55
- workaroundCssModuleHmr()
56
+ workaroundCssModuleHmr(),
57
+ vite6HmrRegressionWorkaround()
56
58
  ];
57
59
  return plugins;
58
60
  }
@@ -9,9 +9,6 @@ import pc from '@brillout/picocolors';
9
9
  import { logErrorHint } from '../../runtime/renderPage/logErrorHint.js';
10
10
  import { manifestTempFile } from './buildConfig.js';
11
11
  let forceExit = false;
12
- assertWarning(!isViteCliCall(), `Vite's CLI is deprecated ${pc.underline('https://vike.dev/migration/cli')}`, {
13
- onlyOnce: true
14
- });
15
12
  function autoFullBuild() {
16
13
  let config;
17
14
  let configVike;
@@ -1 +1 @@
1
- export declare const pluginName = "vike:commonConfig-1";
1
+ export declare const pluginName = "vike:commonConfig";
@@ -1 +1 @@
1
- export const pluginName = 'vike:commonConfig-1';
1
+ export const pluginName = 'vike:commonConfig';
@@ -8,6 +8,10 @@ import path from 'path';
8
8
  import { assertResolveAlias } from './commonConfig/assertResolveAlias.js';
9
9
  import { pluginName } from './commonConfig/pluginName.js';
10
10
  import { getEnvVarObject } from '../shared/getEnvVarObject.js';
11
+ import { isViteCliCall } from '../shared/isViteCliCall.js';
12
+ assertWarning(!isViteCliCall(), `Vite's CLI is deprecated ${pc.underline('https://vike.dev/migration/cli')}`, {
13
+ onlyOnce: true
14
+ });
11
15
  function commonConfig() {
12
16
  return [
13
17
  {
@@ -18,7 +22,7 @@ function commonConfig() {
18
22
  }
19
23
  },
20
24
  {
21
- name: 'vike:commonConfig-2',
25
+ name: `${pluginName}:post`,
22
26
  enforce: 'post',
23
27
  configResolved: {
24
28
  order: 'post',
@@ -1,4 +1,4 @@
1
1
  export { crawlPlusFiles };
2
- declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: string, isDev: boolean, crawlWithGit: null | boolean): Promise<{
2
+ declare function crawlPlusFiles(userRootDir: string, outDirAbsoluteFilesystem: string, crawlWithGit: null | boolean): Promise<{
3
3
  filePathAbsoluteUserRootDir: string;
4
4
  }[]>;
@@ -1,18 +1,17 @@
1
1
  export { crawlPlusFiles };
2
- import { assertPosixPath, assert, assertWarning, scriptFileExtensions, humanizeTime, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove, isScriptFile } from '../../../../utils.js';
2
+ import { assertPosixPath, assert, scriptFileExtensions, assertIsSingleModuleInstance, assertIsNotProductionRuntime, isVersionOrAbove, isScriptFile } from '../../../../utils.js';
3
3
  import path from 'path';
4
4
  import fs from 'fs/promises';
5
5
  import glob from 'fast-glob';
6
6
  import { exec } from 'child_process';
7
7
  import { promisify } from 'util';
8
- import pc from '@brillout/picocolors';
9
8
  import { isTemporaryBuildFile } from './transpileAndExecuteFile.js';
10
9
  const execA = promisify(exec);
11
10
  const TOO_MANY_UNTRACKED_FILES = 5;
12
11
  assertIsNotProductionRuntime();
13
12
  assertIsSingleModuleInstance('crawlPlusFiles.ts');
14
13
  let gitIsNotUsable = false;
15
- async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, crawlWithGit) {
14
+ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, crawlWithGit) {
16
15
  assertPosixPath(userRootDir);
17
16
  assertPosixPath(outDirAbsoluteFilesystem);
18
17
  let outDirRelativeFromUserRootDir = path.posix.relative(userRootDir, outDirAbsoluteFilesystem);
@@ -27,7 +26,6 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, craw
27
26
  (!outDirRelativeFromUserRootDir.startsWith('./') &&
28
27
  //
29
28
  !outDirRelativeFromUserRootDir.startsWith('../')));
30
- const timeBefore = new Date().getTime();
31
29
  // Crawl
32
30
  let files = [];
33
31
  const res = crawlWithGit !== false && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
@@ -43,18 +41,6 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem, isDev, craw
43
41
  }
44
42
  // Filter build files
45
43
  files = files.filter((filePath) => !isTemporaryBuildFile(filePath));
46
- // Check performance
47
- {
48
- const timeAfter = new Date().getTime();
49
- const timeSpent = timeAfter - timeBefore;
50
- if (isDev) {
51
- // We only warn in dev, because while building it's expected to take a long time as crawling is competing for resources with other tasks.
52
- // Although, in dev, it's also competing for resources e.g. with Vite's `optimizeDeps`.
53
- assertWarning(timeSpent < 3 * 1000, `Crawling your ${pc.cyan('+')} files took an unexpected long time (${humanizeTime(timeSpent)}). If you consistently get this warning, then consider reaching out on GitHub.`, {
54
- onlyOnce: 'slow-crawling'
55
- });
56
- }
57
- }
58
44
  // Normalize
59
45
  const plusFiles = files.map((filePath) => {
60
46
  // Both `$ git-ls files` and fast-glob return posix paths
@@ -80,8 +80,8 @@ async function isV1Design(config, isDev) {
80
80
  const isV1Design = pageConfigs.length > 0;
81
81
  return isV1Design;
82
82
  }
83
- async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit) {
84
- const plusFiles = await findPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
83
+ async function loadInterfaceFiles(userRootDir, outDirRoot, crawlWithGit) {
84
+ const plusFiles = await findPlusFiles(userRootDir, outDirRoot, crawlWithGit);
85
85
  const configFiles = [];
86
86
  const valueFiles = [];
87
87
  plusFiles.forEach((f) => {
@@ -195,7 +195,7 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
195
195
  let ret;
196
196
  let err;
197
197
  try {
198
- ret = await loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit);
198
+ ret = await loadVikeConfig(userRootDir, outDirRoot, crawlWithGit);
199
199
  }
200
200
  catch (err_) {
201
201
  hasError = true;
@@ -232,8 +232,8 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
232
232
  }
233
233
  }
234
234
  }
235
- async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
236
- const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
235
+ async function loadVikeConfig(userRootDir, outDirRoot, crawlWithGit) {
236
+ const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, crawlWithGit);
237
237
  const importedFilesLoaded = {};
238
238
  const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
239
239
  const pageConfigs = await Promise.all(objectEntries(interfaceFilesByLocationId)
@@ -779,8 +779,8 @@ function getComputed(configValueSources, configDefinitions) {
779
779
  });
780
780
  return configValuesComputed;
781
781
  }
782
- async function findPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit) {
783
- const files = await crawlPlusFiles(userRootDir, outDirRoot, isDev, crawlWithGit);
782
+ async function findPlusFiles(userRootDir, outDirRoot, crawlWithGit) {
783
+ const files = await crawlPlusFiles(userRootDir, outDirRoot, crawlWithGit);
784
784
  const plusFiles = files.map(({ filePathAbsoluteUserRootDir }) => getFilePathResolved({ filePathAbsoluteUserRootDir, userRootDir }));
785
785
  return plusFiles;
786
786
  }
@@ -0,0 +1,3 @@
1
+ export { vite6HmrRegressionWorkaround };
2
+ import type { Plugin } from 'vite';
3
+ declare function vite6HmrRegressionWorkaround(): Plugin;
@@ -0,0 +1,33 @@
1
+ export { vite6HmrRegressionWorkaround };
2
+ // https://vite.dev/guide/migration (will be 404 after vite@7 release) > search for `hmrReload()`
3
+ // https://v6.vite.dev/guide/migration (will exist after vite@7 release) > search for `hmrReload()`
4
+ // Workaround seems to work for docs page /banner (which is HTML-only)
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() {
7
+ return {
8
+ name: 'vike:vite6HmrRegressionWorkaround',
9
+ enforce: 'post',
10
+ hotUpdate: {
11
+ order: 'post',
12
+ handler({ modules, server, timestamp }) {
13
+ if (this.environment.name !== 'ssr')
14
+ return;
15
+ let hasSsrOnlyModules = false;
16
+ const invalidatedModules = new Set();
17
+ for (const mod of modules) {
18
+ if (mod.id == null)
19
+ continue;
20
+ const clientModule = server.environments.client.moduleGraph.getModuleById(mod.id);
21
+ if (clientModule != null)
22
+ continue;
23
+ this.environment.moduleGraph.invalidateModule(mod, invalidatedModules, timestamp, true);
24
+ hasSsrOnlyModules = true;
25
+ }
26
+ if (hasSsrOnlyModules) {
27
+ server.ws.send({ type: 'full-reload' });
28
+ return [];
29
+ }
30
+ }
31
+ }
32
+ };
33
+ }
@@ -4,8 +4,8 @@ export { runPrerenderFromAutoRun };
4
4
  export { runPrerender_forceExit };
5
5
  export type { PrerenderOptions };
6
6
  import '../runtime/page-files/setup.js';
7
- import type { InlineConfig } from 'vite';
8
- import type { APIOptions } from '../api/APIOptions.js';
7
+ import type { InlineConfig, ResolvedConfig } from 'vite';
8
+ import type { APIOptions } from '../api/types.js';
9
9
  type PrerenderOptions = APIOptions & {
10
10
  /** Initial `pageContext` values */
11
11
  pageContextInit?: Record<string, unknown>;
@@ -26,7 +26,9 @@ type PrerenderOptions = APIOptions & {
26
26
  /** @deprecated */
27
27
  base?: string;
28
28
  };
29
- declare function runPrerenderFromAPI(options?: PrerenderOptions): Promise<void>;
29
+ declare function runPrerenderFromAPI(options?: PrerenderOptions): Promise<{
30
+ viteConfig: ResolvedConfig;
31
+ }>;
30
32
  declare function runPrerenderFromCLIPrerenderCommand(): Promise<void>;
31
33
  declare function runPrerenderFromAutoRun(viteConfig: InlineConfig, forceExit: boolean): Promise<void>;
32
34
  declare function runPrerender_forceExit(): void;
@@ -28,15 +28,15 @@ import { getVikeConfig } from '../plugin/plugins/importUserCode/v1-design/getVik
28
28
  import { logErrorHint } from '../runtime/renderPage/logErrorHint.js';
29
29
  import { executeHook, isUserHookError } from '../../shared/hooks/executeHook.js';
30
30
  import { getConfigValueBuildTime } from '../../shared/page-configs/getConfigValueBuildTime.js';
31
- import { enhanceViteConfig } from '../api/enhanceViteConfig.js';
31
+ import { prepareApiCall } from '../api/prepareApiCall.js';
32
32
  async function runPrerenderFromAPI(options = {}) {
33
- await runPrerender(options, 'prerender()');
33
+ return await runPrerender(options, 'prerender()');
34
34
  // - We purposely propagate the error to the user land, so that the error interrupts the user land. It's also, I guess, a nice-to-have that the user has control over the error.
35
35
  // - We don't use logErrorHint() because we don't have control over what happens with the error. For example, if the user land purposely swallows the error then the hint shouldn't be logged. Also, it's best if the hint is shown to the user *after* the error, but we cannot do/guarentee that.
36
36
  }
37
37
  async function runPrerenderFromCLIPrerenderCommand() {
38
38
  try {
39
- const { viteConfigEnhanced } = await enhanceViteConfig(undefined, 'prerender');
39
+ const { viteConfigEnhanced } = await prepareApiCall(undefined, 'prerender');
40
40
  await runPrerender({ viteConfig: viteConfigEnhanced }, '$ vike prerender');
41
41
  }
42
42
  catch (err) {
@@ -115,6 +115,7 @@ async function runPrerender(options = {}, standaloneTrigger) {
115
115
  console.log(`${pc.green(`✓`)} ${prerenderedCount} HTML documents pre-rendered.`);
116
116
  }
117
117
  warnMissingPages(prerenderedPageContexts, doNotPrerenderList, renderContext, partial);
118
+ return { viteConfig };
118
119
  }
119
120
  async function collectDoNoPrerenderList(renderContext, pageConfigs, doNotPrerenderList, concurrencyLimit) {
120
121
  // V1 design
@@ -56,7 +56,7 @@ type ConfigVikeUserProvided = {
56
56
  *
57
57
  * Use this if you want to programmatically initiate the pre-rendering process instead.
58
58
  *
59
- * https://vike.dev/prerender-programmatic
59
+ * https://vike.dev/api#prerender
60
60
  *
61
61
  * @default false
62
62
  */
@@ -1,14 +1,8 @@
1
1
  export { getConfigValueRuntime };
2
- export { getConfigValueTyped };
3
- export type { TypeAsString };
4
2
  import { type ResolveTypeAsString } from '../utils.js';
5
3
  import type { PageConfigRuntime, ConfigValue } from './PageConfig.js';
6
4
  import type { ConfigNameBuiltIn } from './Config.js';
7
- type ConfigName = ConfigNameBuiltIn;
8
- type TypeAsString = 'string' | 'boolean' | undefined;
9
- declare function getConfigValueTyped<Type extends TypeAsString = undefined>(configValue: ConfigValue, configName: ConfigName, type?: Type): null | (ConfigValue & {
10
- value: ResolveTypeAsString<Type>;
11
- });
12
- declare function getConfigValueRuntime<Type extends TypeAsString = undefined>(pageConfig: PageConfigRuntime, configName: ConfigName, type?: Type): null | (ConfigValue & {
5
+ import { type TypeAsString } from './getConfigValueTyped.js';
6
+ declare function getConfigValueRuntime<Type extends TypeAsString = undefined>(pageConfig: PageConfigRuntime, configName: ConfigNameBuiltIn, type?: Type): null | (ConfigValue & {
13
7
  value: ResolveTypeAsString<Type>;
14
8
  });
@@ -1,34 +1,8 @@
1
1
  export { getConfigValueRuntime };
2
- export { getConfigValueTyped };
3
- import { assert, assertUsage, getValuePrintable } from '../utils.js';
4
- import pc from '@brillout/picocolors';
5
- import { getConfigDefinedAtOptional } from './getConfigDefinedAt.js';
6
- function getConfigValueTyped(configValue, configName, type) {
7
- /* [NULL_HANDLING] Do we really need this? This doesn't seem to make sense, let's eventually (re)move this.
8
- // Enable users to suppress global config values by setting the local config value to null
9
- if (configValue.value === null) return null
10
- */
11
- const { value, definedAtData } = configValue;
12
- if (type)
13
- assertConfigValueType(value, type, configName, definedAtData);
14
- return configValue;
15
- }
2
+ import { getConfigValueTyped } from './getConfigValueTyped.js';
16
3
  function getConfigValueRuntime(pageConfig, configName, type) {
17
4
  const configValue = pageConfig.configValues[configName];
18
5
  if (!configValue)
19
6
  return null;
20
7
  return getConfigValueTyped(configValue, configName, type);
21
8
  }
22
- function assertConfigValueType(value, type, configName, definedAtData) {
23
- assert(value !== null);
24
- const typeActual = typeof value;
25
- if (typeActual === type)
26
- return;
27
- const valuePrintable = getValuePrintable(value);
28
- const problem = valuePrintable !== null
29
- ? `value ${pc.cyan(valuePrintable)}`
30
- : `type ${pc.cyan(typeActual)}`;
31
- const configDefinedAt = getConfigDefinedAtOptional('Config', configName, definedAtData);
32
- const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${pc.cyan(type)} instead`;
33
- assertUsage(false, errMsg);
34
- }
@@ -2,8 +2,7 @@ export { getConfigValueBuildTime };
2
2
  import { type ResolveTypeAsString } from '../utils.js';
3
3
  import type { PageConfigBuildTime, ConfigValue } from './PageConfig.js';
4
4
  import type { ConfigNameBuiltIn } from './Config.js';
5
- import { type TypeAsString } from './getConfigValue.js';
6
- type ConfigName = ConfigNameBuiltIn;
7
- declare function getConfigValueBuildTime<Type extends TypeAsString = undefined>(pageConfig: PageConfigBuildTime, configName: ConfigName, type?: Type): null | (ConfigValue & {
5
+ import { type TypeAsString } from './getConfigValueTyped.js';
6
+ declare function getConfigValueBuildTime<Type extends TypeAsString = undefined>(pageConfig: PageConfigBuildTime, configName: ConfigNameBuiltIn, type?: Type): null | (ConfigValue & {
8
7
  value: ResolveTypeAsString<Type>;
9
8
  });
@@ -1,7 +1,7 @@
1
1
  export { getConfigValueBuildTime };
2
2
  import { assert } from '../utils.js';
3
- import { getConfigValueTyped } from './getConfigValue.js';
4
3
  import { assertIsNotProductionRuntime } from '../../utils/assertIsNotProductionRuntime.js';
4
+ import { getConfigValueTyped } from './getConfigValueTyped.js';
5
5
  assertIsNotProductionRuntime();
6
6
  function getConfigValueBuildTime(pageConfig, configName, type) {
7
7
  const configValue = getConfigValue(pageConfig, configName);
@@ -0,0 +1,9 @@
1
+ export { getConfigValueTyped };
2
+ export type { TypeAsString };
3
+ import { type ResolveTypeAsString } from '../utils.js';
4
+ import type { ConfigValue } from './PageConfig.js';
5
+ import type { ConfigNameBuiltIn } from './Config.js';
6
+ type TypeAsString = 'string' | 'boolean' | undefined;
7
+ declare function getConfigValueTyped<Type extends TypeAsString = undefined>(configValue: ConfigValue, configName: ConfigNameBuiltIn, type?: Type): null | (ConfigValue & {
8
+ value: ResolveTypeAsString<Type>;
9
+ });
@@ -0,0 +1,27 @@
1
+ export { getConfigValueTyped };
2
+ import { assert, assertUsage, getValuePrintable } from '../utils.js';
3
+ import pc from '@brillout/picocolors';
4
+ import { getConfigDefinedAtOptional } from './getConfigDefinedAt.js';
5
+ function getConfigValueTyped(configValue, configName, type) {
6
+ /* [NULL_HANDLING] Do we really need this? This doesn't seem to make sense, let's eventually (re)move this.
7
+ // Enable users to suppress global config values by setting the local config value to null
8
+ if (configValue.value === null) return null
9
+ */
10
+ const { value, definedAtData } = configValue;
11
+ if (type)
12
+ assertConfigValueType(value, type, configName, definedAtData);
13
+ return configValue;
14
+ }
15
+ function assertConfigValueType(value, type, configName, definedAtData) {
16
+ assert(value !== null);
17
+ const typeActual = typeof value;
18
+ if (typeActual === type)
19
+ return;
20
+ const valuePrintable = getValuePrintable(value);
21
+ const problem = valuePrintable !== null
22
+ ? `value ${pc.cyan(valuePrintable)}`
23
+ : `type ${pc.cyan(typeActual)}`;
24
+ const configDefinedAt = getConfigDefinedAtOptional('Config', configName, definedAtData);
25
+ const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${pc.cyan(type)} instead`;
26
+ assertUsage(false, errMsg);
27
+ }
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.213";
1
+ export declare const PROJECT_VERSION: "0.4.215";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.213';
2
+ export const PROJECT_VERSION = '0.4.215';
@@ -1,4 +1,4 @@
1
1
  export declare const projectInfo: {
2
2
  projectName: "Vike";
3
- projectVersion: "0.4.213";
3
+ projectVersion: "0.4.215";
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.213",
3
+ "version": "0.4.215",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {
@@ -139,7 +139,8 @@
139
139
  "fast-glob": "^3.0.0",
140
140
  "json5": "^2.0.0",
141
141
  "semver": "^7.0.0",
142
- "source-map-support": "^0.5.0"
142
+ "source-map-support": "^0.5.0",
143
+ "vite": ">=5.1.0"
143
144
  },
144
145
  "peerDependencies": {
145
146
  "react-streaming": ">=0.3.42",
@@ -148,20 +149,26 @@
148
149
  "peerDependenciesMeta": {
149
150
  "react-streaming": {
150
151
  "optional": true
152
+ },
153
+ "vite": {
154
+ "optional": true
151
155
  }
152
156
  },
153
157
  "engines": {
154
158
  "node": ">=18.0.0"
155
159
  },
156
160
  "license": "MIT",
157
- "description": "Flexible, lean, community-driven, dependable, fast Vite-based frontend framework.",
161
+ "description": "The Framework *You* Control - Next.js & Nuxt alternative for unprecedented flexibility and dependability.",
158
162
  "keywords": [
163
+ "vite-plugin",
164
+ "ssr",
165
+ "vite",
159
166
  "react",
160
167
  "vue",
161
168
  "solid",
162
- "vite",
163
- "vite-plugin",
164
- "ssr"
169
+ "next",
170
+ "remix",
171
+ "vike"
165
172
  ],
166
173
  "typesVersions": {
167
174
  "*": {
@@ -1,6 +0,0 @@
1
- export { enhanceViteConfig };
2
- import type { InlineConfig } from 'vite';
3
- declare function enhanceViteConfig(viteConfig: InlineConfig | undefined, command: 'build' | 'dev' | 'preview' | 'prerender'): Promise<{
4
- viteConfigEnhanced: InlineConfig;
5
- configVike: import("../../shared/ConfigVike.js").ConfigVikeResolved;
6
- }>;