vike 0.4.220-commit-a9f46b8 → 0.4.220-commit-9a798ce

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 (105) hide show
  1. package/dist/cjs/node/api/utils.js +1 -1
  2. package/dist/cjs/{utils → node/plugin}/getOutDirs.js +11 -11
  3. package/dist/cjs/node/plugin/index.js +1 -7
  4. package/dist/cjs/node/plugin/onLoad.js +6 -1
  5. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +12 -13
  6. package/dist/cjs/node/plugin/plugins/baseUrls.js +2 -2
  7. package/dist/cjs/node/plugin/plugins/buildConfig.js +6 -3
  8. package/dist/cjs/node/plugin/plugins/buildEntry/index.js +24 -21
  9. package/dist/cjs/node/plugin/plugins/commonConfig.js +4 -3
  10. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +4 -2
  11. package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +10 -7
  12. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +3 -4
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +10 -9
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +8 -3
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +158 -176
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -1
  17. package/dist/cjs/node/plugin/plugins/previewConfig.js +3 -4
  18. package/dist/cjs/node/plugin/utils.js +1 -1
  19. package/dist/cjs/node/prerender/context.js +6 -4
  20. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +25 -0
  21. package/dist/cjs/node/prerender/runPrerender.js +9 -4
  22. package/dist/cjs/node/prerender/utils.js +2 -2
  23. package/dist/cjs/node/runtime/globalContext.js +42 -36
  24. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -3
  25. package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +6 -5
  26. package/dist/cjs/node/runtime/renderPage.js +10 -5
  27. package/dist/cjs/node/runtime/utils.js +2 -2
  28. package/dist/cjs/node/shared/resolveBase.js +9 -0
  29. package/dist/cjs/shared/page-configs/getPageConfigUserFriendly.js +2 -2
  30. package/dist/cjs/shared/utils.js +1 -1
  31. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  32. package/dist/cjs/utils/findFile.js +3 -3
  33. package/dist/cjs/utils/isDev.js +2 -1
  34. package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +2 -2
  35. package/dist/cjs/utils/requireResolve.js +3 -3
  36. package/dist/esm/node/api/utils.d.ts +1 -1
  37. package/dist/esm/node/api/utils.js +1 -1
  38. package/dist/esm/{utils → node/plugin}/getOutDirs.js +5 -5
  39. package/dist/esm/node/plugin/index.d.ts +29 -1
  40. package/dist/esm/node/plugin/index.js +2 -8
  41. package/dist/esm/node/plugin/onLoad.js +7 -2
  42. package/dist/esm/node/plugin/plugins/autoFullBuild.js +12 -13
  43. package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
  44. package/dist/esm/node/plugin/plugins/buildConfig.js +7 -4
  45. package/dist/esm/node/plugin/plugins/buildEntry/index.d.ts +3 -3
  46. package/dist/esm/node/plugin/plugins/buildEntry/index.js +25 -22
  47. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +1 -1
  48. package/dist/esm/node/plugin/plugins/commonConfig.js +4 -3
  49. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +4 -2
  50. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +2 -2
  51. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +10 -7
  52. package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -4
  53. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.d.ts +3 -2
  54. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +10 -9
  55. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +8 -3
  56. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -95
  57. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +159 -177
  58. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -1
  59. package/dist/esm/node/plugin/plugins/previewConfig.js +3 -4
  60. package/dist/esm/node/plugin/utils.js +1 -1
  61. package/dist/esm/node/prerender/context.d.ts +2 -2
  62. package/dist/esm/node/prerender/context.js +6 -4
  63. package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +5 -0
  64. package/dist/esm/node/prerender/resolvePrerenderConfig.js +23 -0
  65. package/dist/esm/node/prerender/runPrerender.js +9 -4
  66. package/dist/esm/node/prerender/utils.d.ts +2 -2
  67. package/dist/esm/node/prerender/utils.js +2 -2
  68. package/dist/esm/node/runtime/globalContext.d.ts +15 -9
  69. package/dist/esm/node/runtime/globalContext.js +43 -37
  70. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +5 -5
  71. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -3
  72. package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +2 -0
  73. package/dist/esm/node/runtime/renderPage/resolveRedirects.js +5 -5
  74. package/dist/esm/node/runtime/renderPage.js +10 -5
  75. package/dist/esm/node/runtime/utils.d.ts +2 -2
  76. package/dist/esm/node/runtime/utils.js +2 -2
  77. package/dist/esm/node/shared/resolveBase.d.ts +4 -1
  78. package/dist/esm/node/shared/resolveBase.js +9 -0
  79. package/dist/esm/shared/page-configs/Config.d.ts +76 -3
  80. package/dist/esm/shared/page-configs/PageConfig.d.ts +25 -19
  81. package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +1 -1
  82. package/dist/esm/shared/page-configs/getPageConfigUserFriendly.js +2 -2
  83. package/dist/esm/shared/utils.d.ts +1 -1
  84. package/dist/esm/shared/utils.js +1 -1
  85. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  86. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  87. package/dist/esm/utils/findFile.js +1 -1
  88. package/dist/esm/utils/isDev.js +2 -1
  89. package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -1
  90. package/dist/esm/utils/projectInfo.d.ts +1 -1
  91. package/dist/esm/utils/requireResolve.js +1 -1
  92. package/package.json +1 -1
  93. package/dist/cjs/node/plugin/plugins/buildEntry/getVikeManifest.js +0 -17
  94. package/dist/cjs/node/shared/assertPluginManifest.js +0 -20
  95. package/dist/cjs/node/shared/assertRuntimeManifest.js +0 -16
  96. package/dist/esm/node/plugin/plugins/buildEntry/getVikeManifest.d.ts +0 -5
  97. package/dist/esm/node/plugin/plugins/buildEntry/getVikeManifest.js +0 -15
  98. package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -12
  99. package/dist/esm/node/shared/assertPluginManifest.js +0 -18
  100. package/dist/esm/node/shared/assertRuntimeManifest.d.ts +0 -10
  101. package/dist/esm/node/shared/assertRuntimeManifest.js +0 -14
  102. /package/dist/cjs/utils/{filesystemPathHandling.js → toPosixPath.js} +0 -0
  103. /package/dist/esm/{utils → node/plugin}/getOutDirs.d.ts +0 -0
  104. /package/dist/esm/utils/{filesystemPathHandling.d.ts → toPosixPath.d.ts} +0 -0
  105. /package/dist/esm/utils/{filesystemPathHandling.js → toPosixPath.js} +0 -0
@@ -14,17 +14,16 @@ import { isVikeCli } from '../../cli/context.js';
14
14
  let forceExit = false;
15
15
  function autoFullBuild() {
16
16
  let config;
17
- let vikeConfigGlobal;
17
+ let vikeConfig;
18
18
  return [
19
19
  {
20
20
  name: 'vike:autoFullBuild',
21
21
  apply: 'build',
22
22
  enforce: 'pre',
23
23
  async configResolved(config_) {
24
- const vikeConfig = await getVikeConfig(config_);
25
- vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
24
+ vikeConfig = await getVikeConfig(config_);
26
25
  config = config_;
27
- abortViteBuildSsr(vikeConfigGlobal);
26
+ abortViteBuildSsr(vikeConfig);
28
27
  },
29
28
  writeBundle: {
30
29
  /* We can't use this because it breaks Vite's logging. TODO: try again with latest Vite version.
@@ -33,7 +32,7 @@ function autoFullBuild() {
33
32
  */
34
33
  async handler(_options, bundle) {
35
34
  try {
36
- await triggerFullBuild(config, vikeConfigGlobal, bundle);
35
+ await triggerFullBuild(config, vikeConfig, bundle);
37
36
  }
38
37
  catch (err) {
39
38
  // Avoid Rollup prefixing the error with [vike:autoFullBuild], for example see https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
@@ -59,10 +58,10 @@ function autoFullBuild() {
59
58
  }
60
59
  ];
61
60
  }
62
- async function triggerFullBuild(config, vikeConfigGlobal, bundle) {
61
+ async function triggerFullBuild(config, vikeConfig, bundle) {
63
62
  if (config.build.ssr)
64
63
  return; // already triggered
65
- if (isDisabled(vikeConfigGlobal))
64
+ if (isDisabled(vikeConfig))
66
65
  return;
67
66
  // Workaround for @vitejs/plugin-legacy
68
67
  // - The legacy plugin triggers its own Rollup build for the client-side.
@@ -93,7 +92,7 @@ async function triggerFullBuild(config, vikeConfigGlobal, bundle) {
93
92
  logErrorHint(err);
94
93
  process.exit(1);
95
94
  }
96
- if (isPrerenderAutoRunEnabled(vikeConfigGlobal)) {
95
+ if (isPrerenderAutoRunEnabled(vikeConfig)) {
97
96
  const { prerenderContextPublic } = await runPrerenderFromAutoRun(configInline);
98
97
  config.vike.prerenderContext = prerenderContextPublic;
99
98
  forceExit = isVikeCli() || isViteCliCall();
@@ -108,15 +107,15 @@ function setSSR(configInline) {
108
107
  }
109
108
  };
110
109
  }
111
- function abortViteBuildSsr(vikeConfigGlobal) {
112
- if (vikeConfigGlobal.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
110
+ function abortViteBuildSsr(vikeConfig) {
111
+ if (vikeConfig.global.config.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
113
112
  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 });
114
113
  process.exit(0);
115
114
  }
116
115
  }
117
- function isDisabled(vikeConfigGlobal) {
118
- const { disableAutoFullBuild } = vikeConfigGlobal;
119
- if (disableAutoFullBuild === null || disableAutoFullBuild === 'prerender') {
116
+ function isDisabled(vikeConfig) {
117
+ const { disableAutoFullBuild } = vikeConfig.global.config;
118
+ if (disableAutoFullBuild === undefined || disableAutoFullBuild === 'prerender') {
120
119
  const isViteApi = !isViteCliCall() && !isVikeCliOrApi();
121
120
  return isViteApi;
122
121
  }
@@ -11,7 +11,7 @@ function baseUrls() {
11
11
  const isDev = config._isDev;
12
12
  assert(typeof isDev === 'boolean');
13
13
  const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
14
- basesResolved = resolveBase(baseViteOriginal, config._vikeConfigGlobal.baseServer, config._vikeConfigGlobal.baseAssets);
14
+ basesResolved = resolveBase(baseViteOriginal, config.vike.global.config.baseServer ?? null, config.vike.global.config.baseAssets ?? null);
15
15
  // We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
16
16
  process.env.BASE_SERVER = basesResolved.baseServer;
17
17
  process.env.BASE_ASSETS = basesResolved.baseAssets;
@@ -27,7 +27,7 @@ function baseUrls() {
27
27
  },
28
28
  async configResolved(config) {
29
29
  const vikeConfig = await getVikeConfig(config);
30
- const basesResolved2 = resolveBaseFromResolvedConfig(vikeConfig.vikeConfigGlobal.baseServer, vikeConfig.vikeConfigGlobal.baseAssets, config);
30
+ const basesResolved2 = resolveBaseFromResolvedConfig(vikeConfig.global.config.baseServer ?? null, vikeConfig.global.config.baseAssets ?? null, config);
31
31
  assert(basesResolved2.baseServer === basesResolved.baseServer);
32
32
  assert(basesResolved2.baseAssets === basesResolved.baseAssets);
33
33
  /* In dev, Vite seems buggy around setting vite.config.js#base to an absolute URL (e.g. http://localhost:8080/cdn/)
@@ -11,7 +11,7 @@ import { createRequire } from 'module';
11
11
  import fs from 'fs/promises';
12
12
  import path from 'path';
13
13
  import { fixServerAssets, fixServerAssets_assertCssCodeSplit, fixServerAssets_assertCssTarget, fixServerAssets_assertCssTarget_populate, fixServerAssets_isEnabled } from './buildConfig/fixServerAssets.js';
14
- import { set_ASSETS_MAP } from './buildEntry/index.js';
14
+ import { set_ASSETS_MANIFEST } from './buildEntry/index.js';
15
15
  import { prependEntriesDir } from '../../shared/prependEntriesDir.js';
16
16
  import { getFilePathResolved } from '../shared/getFilePath.js';
17
17
  import { getConfigValueBuildTime } from '../../../shared/page-configs/getConfigValueBuildTime.js';
@@ -79,7 +79,7 @@ function buildConfig() {
79
79
  name: 'vike:buildConfig:pre',
80
80
  apply: 'build',
81
81
  // Make sure other writeBundle() hooks are called after this writeBundle() hook.
82
- // - set_ASSETS_MAP() needs to be called before dist/server/ code is executed.
82
+ // - set_ASSETS_MANIFEST() needs to be called before dist/server/ code is executed.
83
83
  // - For example, the writeBundle() hook of vite-plugin-vercel needs to be called after this writeBundle() hook, otherwise: https://github.com/vikejs/vike/issues/1527
84
84
  enforce: 'pre',
85
85
  writeBundle: {
@@ -102,7 +102,7 @@ function buildConfig() {
102
102
  }
103
103
  await fs.rm(clientManifestFilePath);
104
104
  await fs.rm(serverManifestFilePath);
105
- await set_ASSETS_MAP(options, bundle);
105
+ await set_ASSETS_MANIFEST(options, bundle);
106
106
  }
107
107
  }
108
108
  }
@@ -112,7 +112,10 @@ function buildConfig() {
112
112
  async function getEntries(config) {
113
113
  const vikeConfig = await getVikeConfig(config);
114
114
  const { pageConfigs } = vikeConfig;
115
- const pageFileEntries = await getPageFileEntries(config, vikeConfig.vikeConfigGlobal.includeAssetsImportedByServer); // TODO/v1-release: remove
115
+ // TODO/v1-release: remove
116
+ const pageFileEntries = await getPageFileEntries(config,
117
+ // TODO/now: add meta.default
118
+ vikeConfig.global.config.includeAssetsImportedByServer ?? true);
116
119
  assertUsage(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
117
120
  if (viteIsSSR(config)) {
118
121
  const pageEntries = getPageEntries(pageConfigs);
@@ -1,8 +1,8 @@
1
1
  export { buildEntry };
2
- export { set_ASSETS_MAP };
2
+ export { set_ASSETS_MANIFEST };
3
3
  import type { Plugin, Rollup } from 'vite';
4
4
  type Bundle = Rollup.OutputBundle;
5
5
  type Options = Rollup.NormalizedOutputOptions;
6
6
  declare function buildEntry(): Plugin[];
7
- /** Set the value of the ASSETS_MAP constant inside dist/server/entry.js (or dist/server/index.js) */
8
- declare function set_ASSETS_MAP(options: Options, bundle: Bundle): Promise<void>;
7
+ /** Set the value of the ASSETS_MANIFEST constant inside dist/server/entry.js (or dist/server/index.js) */
8
+ declare function set_ASSETS_MANIFEST(options: Options, bundle: Bundle): Promise<void>;
@@ -1,79 +1,82 @@
1
1
  export { buildEntry };
2
- export { set_ASSETS_MAP };
2
+ export { set_ASSETS_MANIFEST };
3
3
  import { serverProductionEntryPlugin } from '@brillout/vite-plugin-server-entry/plugin';
4
4
  import { virtualFileIdImportUserCodeServer } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
5
- import { getVikeManifest } from './getVikeManifest.js';
6
- import { getVikeConfig } from '../importUserCode/v1-design/getVikeConfig.js';
7
- import { assert, getOutDirs, toPosixPath } from '../../utils.js';
5
+ import { assert, getOutDirs, projectInfo, toPosixPath } from '../../utils.js';
8
6
  import fs from 'fs/promises';
9
7
  import path from 'path';
10
8
  import { createRequire } from 'module';
11
9
  // @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
12
10
  const importMetaUrl = import.meta.url;
13
11
  const require_ = createRequire(importMetaUrl);
14
- const ASSETS_MAP = '__VITE_ASSETS_MAP__';
12
+ import { isUsingClientRouter } from '../extractExportNamesPlugin.js';
13
+ import { assertBuildInfo, getViteConfigRuntime } from '../../../runtime/globalContext.js';
14
+ const ASSETS_MANIFEST = '__VITE_ASSETS_MANIFEST__';
15
15
  function buildEntry() {
16
16
  let config;
17
- let vikeConfigGlobal;
18
17
  return [
19
18
  {
20
19
  name: 'vike:buildEntry',
21
20
  enforce: 'post',
22
21
  async configResolved(config_) {
23
22
  config = config_;
24
- const vikeConfig = await getVikeConfig(config);
25
- vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
26
23
  }
27
24
  },
28
25
  ...serverProductionEntryPlugin({
29
26
  getServerProductionEntry: () => {
30
- return getServerProductionEntryCode(config, vikeConfigGlobal);
27
+ return getServerProductionEntryCode(config);
31
28
  },
32
29
  libraryName: 'Vike'
33
30
  })
34
31
  ];
35
32
  }
36
- function getServerProductionEntryCode(config, vikeConfigGlobal) {
33
+ function getServerProductionEntryCode(config) {
37
34
  const importPath = getImportPath(config);
38
- const vikeManifest = getVikeManifest(vikeConfigGlobal, config);
39
- // Let's eventually simplify and move everything to a single virtual module
35
+ const buildInfo = {
36
+ versionAtBuildTime: projectInfo.projectVersion,
37
+ usesClientRouter: isUsingClientRouter(), // TODO/v1-release: remove
38
+ viteConfigRuntime: getViteConfigRuntime(config)
39
+ };
40
+ assertBuildInfo(buildInfo);
41
+ // After the old design is removed, let's maybe simplify and move everything into a single virtual module
40
42
  const importerCode = [
41
43
  ` import { setGlobalContext_buildEntry } from '${importPath}';`,
42
44
  ` import * as pageFiles from '${virtualFileIdImportUserCodeServer}';`,
43
45
  ` {`,
44
- // We first set the values to a variable because of a Rollup bug, and this workaround doesn't work: https://github.com/vikejs/vike/commit/d5f3a4f7aae5a8bc44192e6cbb2bcb9007be188d
45
- ` const assetsManifest = ${ASSETS_MAP};`,
46
- ` const pluginManifest = ${JSON.stringify(vikeManifest, null, 2)};`,
46
+ // Because of a Rollup bug, we have to assign ASSETS_MANIFEST to a variable before passing it to setGlobalContext_buildEntry()
47
+ // - This workaround doesn't work: https://github.com/vikejs/vike/commit/d5f3a4f7aae5a8bc44192e6cbb2bcb9007be188d
48
+ ` const assetsManifest = ${ASSETS_MANIFEST};`,
49
+ ` const buildInfo = ${JSON.stringify(buildInfo, null, 2)};`,
47
50
  ' setGlobalContext_buildEntry({',
48
51
  ` pageFiles,`,
49
52
  ` assetsManifest,`,
50
- ` pluginManifest,`,
53
+ ` buildInfo,`,
51
54
  ' });',
52
55
  ` }`,
53
56
  ''
54
57
  ].join('\n');
55
58
  return importerCode;
56
59
  }
57
- /** Set the value of the ASSETS_MAP constant inside dist/server/entry.js (or dist/server/index.js) */
58
- async function set_ASSETS_MAP(options, bundle) {
60
+ /** Set the value of the ASSETS_MANIFEST constant inside dist/server/entry.js (or dist/server/index.js) */
61
+ async function set_ASSETS_MANIFEST(options, bundle) {
59
62
  const { dir } = options;
60
63
  assert(dir);
61
- const chunkPath = find_ASSETS_MAP(bundle);
64
+ const chunkPath = find_ASSETS_MANIFEST(bundle);
62
65
  const chunkFilePath = path.join(dir, chunkPath);
63
66
  const assetsJsonFilePath = path.join(dir, '..', 'assets.json');
64
67
  const [assetsJsonString, chunkFileContent] = await Promise.all([
65
68
  await fs.readFile(assetsJsonFilePath, 'utf8'),
66
69
  await fs.readFile(chunkFilePath, 'utf8')
67
70
  ]);
68
- const serverEntryFileContentPatched = chunkFileContent.replace(ASSETS_MAP, assetsJsonString);
71
+ const serverEntryFileContentPatched = chunkFileContent.replace(ASSETS_MANIFEST, assetsJsonString);
69
72
  assert(serverEntryFileContentPatched !== chunkFileContent);
70
73
  await fs.writeFile(chunkFilePath, serverEntryFileContentPatched);
71
74
  }
72
- function find_ASSETS_MAP(bundle) {
75
+ function find_ASSETS_MANIFEST(bundle) {
73
76
  let chunkPath;
74
77
  for (const filePath in bundle) {
75
78
  const chunk = bundle[filePath];
76
- if ('code' in chunk && chunk.code.includes(ASSETS_MAP)) {
79
+ if ('code' in chunk && chunk.code.includes(ASSETS_MANIFEST)) {
77
80
  assert(!chunkPath);
78
81
  chunkPath = filePath;
79
82
  }
@@ -7,12 +7,12 @@ declare module 'vite' {
7
7
  _isDev?: boolean;
8
8
  _vikeVitePluginOptions?: unknown;
9
9
  _root?: string;
10
+ _baseViteOriginal?: string;
10
11
  _viteConfigEnhanced?: InlineConfig;
11
12
  vike?: {
12
13
  global: VikeConfigObject['global'];
13
14
  prerenderContext?: PrerenderContextPublic;
14
15
  };
15
- _vikeConfigGlobal?: VikeConfigObject['vikeConfigGlobal'];
16
16
  }
17
17
  }
18
18
  declare function commonConfig(vikeVitePluginOptions: unknown): Plugin[];
@@ -12,6 +12,7 @@ import { isVikeCliOrApi } from '../../api/context.js';
12
12
  import { getVikeConfig2 } from './importUserCode/v1-design/getVikeConfig.js';
13
13
  import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/prepareViteApiCall.js';
14
14
  import { temp_disablePrerenderAutoRun } from '../../prerender/context.js';
15
+ import { resolvePrerenderConfig } from '../../prerender/resolvePrerenderConfig.js';
15
16
  const pluginName = 'vike:commonConfig';
16
17
  function commonConfig(vikeVitePluginOptions) {
17
18
  return [
@@ -31,10 +32,10 @@ function commonConfig(vikeVitePluginOptions) {
31
32
  _root: root,
32
33
  _vikeVitePluginOptions: vikeVitePluginOptions,
33
34
  vike: { global: vikeConfig.global },
34
- // TODO/now: remove
35
- _vikeConfigGlobal: vikeConfig.vikeConfigGlobal,
36
35
  // TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
37
- configVikePromise: Promise.resolve({ prerender: !!vikeConfig.vikeConfigGlobal.prerender })
36
+ configVikePromise: Promise.resolve({
37
+ prerender: !!resolvePrerenderConfig(vikeConfig.global.config.prerender)
38
+ })
38
39
  };
39
40
  }
40
41
  }
@@ -43,7 +43,8 @@ function extractAssetsPlugin() {
43
43
  assertV1Design(vikeConfig.pageConfigs, true);
44
44
  assert(false);
45
45
  }
46
- assert(vikeConfig.vikeConfigGlobal.includeAssetsImportedByServer);
46
+ // TODO/now: add meta.default
47
+ assert(vikeConfig.global.config.includeAssetsImportedByServer ?? true);
47
48
  assert(!viteIsSSR_options(options));
48
49
  const importStatements = await getImportStatements(src);
49
50
  const moduleNames = getImportedModules(importStatements);
@@ -76,7 +77,8 @@ function extractAssetsPlugin() {
76
77
  if (!extractAssetsRE.test(importer)) {
77
78
  return;
78
79
  }
79
- assert(vikeConfig.vikeConfigGlobal.includeAssetsImportedByServer);
80
+ // TODO/now: add meta.default
81
+ assert(vikeConfig.global.config.includeAssetsImportedByServer ?? true);
80
82
  let resolution = null;
81
83
  try {
82
84
  resolution = await this.resolve(source, importer, { skipSelf: true, ...options });
@@ -1,6 +1,6 @@
1
1
  export { getVirtualFileImportUserCode };
2
2
  import type { ResolvedConfig } from 'vite';
3
- import type { VikeConfigGlobal } from './v1-design/getVikeConfig.js';
3
+ import type { VikeConfigObject } from './v1-design/getVikeConfig.js';
4
4
  declare function getVirtualFileImportUserCode(id: string, options: {
5
5
  ssr?: boolean;
6
- } | undefined, vikeConfigGlobal: VikeConfigGlobal, config: ResolvedConfig, isDev: boolean): Promise<string>;
6
+ } | undefined, vikeConfig: VikeConfigObject, config: ResolvedConfig, isDev: boolean): Promise<string>;
@@ -6,16 +6,17 @@ import { fileTypes } from '../../../../shared/getPageFiles/fileTypes.js';
6
6
  import path from 'path';
7
7
  import { getVirtualFilePageConfigs } from './v1-design/getVirtualFilePageConfigs.js';
8
8
  import { isV1Design as isV1Design_ } from './v1-design/getVikeConfig.js';
9
- async function getVirtualFileImportUserCode(id, options, vikeConfigGlobal, config, isDev) {
9
+ import { resolvePrerenderConfig } from '../../../prerender/resolvePrerenderConfig.js';
10
+ async function getVirtualFileImportUserCode(id, options, vikeConfig, config, isDev) {
10
11
  const idParsed = isVirtualFileIdImportUserCode(id);
11
12
  assert(idParsed);
12
13
  const { isForClientSide, isClientRouting } = idParsed;
13
14
  assert(isForClientSide === !viteIsSSR_options(options));
14
- const isPrerendering = !!vikeConfigGlobal.prerender;
15
- const code = await getCode(config, vikeConfigGlobal, isForClientSide, isClientRouting, isPrerendering, isDev, id);
15
+ const isPrerendering = !!resolvePrerenderConfig(vikeConfig.global.config.prerender);
16
+ const code = await getCode(config, vikeConfig, isForClientSide, isClientRouting, isPrerendering, isDev, id);
16
17
  return code;
17
18
  }
18
- async function getCode(config, vikeConfigGlobal, isForClientSide, isClientRouting, isPrerendering, isDev, id) {
19
+ async function getCode(config, vikeConfig, isForClientSide, isClientRouting, isPrerendering, isDev, id) {
19
20
  const { command } = config;
20
21
  assert(command === 'serve' || command === 'build');
21
22
  const isBuild = command === 'build';
@@ -24,7 +25,7 @@ async function getCode(config, vikeConfigGlobal, isForClientSide, isClientRoutin
24
25
  {
25
26
  const globRoots = getGlobRoots(config);
26
27
  debugGlob('Glob roots: ', globRoots);
27
- content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfigGlobal, isPrerendering, config, isDev, id);
28
+ content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfig, isPrerendering, config, isDev, id);
28
29
  }
29
30
  debugGlob(`Glob imports for ${isForClientSide ? 'client' : 'server'}:\n`, content);
30
31
  return content;
@@ -54,7 +55,7 @@ function determineInjection({ fileType, isForClientSide, isClientRouting, isPrer
54
55
  }
55
56
  }
56
57
  }
57
- async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfigGlobal, isPrerendering, config, isDev, id) {
58
+ async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfig, isPrerendering, config, isDev, id) {
58
59
  let fileContent = `// Generated by https://github.com/vikejs/vike/blob/main/vike/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.ts
59
60
 
60
61
  export const pageFilesLazy = {};
@@ -86,7 +87,9 @@ ${await getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, c
86
87
  fileContent += getGlobs(globRoots, isBuild, fileType, 'extractExportNames', isV1Design);
87
88
  }
88
89
  });
89
- if (vikeConfigGlobal.includeAssetsImportedByServer && isForClientSide) {
90
+ // TODO/now: add meta.default
91
+ const includeAssetsImportedByServer = vikeConfig.global.config.includeAssetsImportedByServer ?? true;
92
+ if (includeAssetsImportedByServer && isForClientSide) {
90
93
  fileContent += getGlobs(globRoots, isBuild, '.page.server', 'extractAssets', isV1Design);
91
94
  }
92
95
  return fileContent;
@@ -12,12 +12,11 @@ import { logConfigInfo } from '../../shared/loggerNotProd.js';
12
12
  import { getModuleFilePathAbsolute } from '../../shared/getFilePath.js';
13
13
  function importUserCode() {
14
14
  let config;
15
- let vikeConfigGlobal;
15
+ let vikeConfig;
16
16
  return {
17
17
  name: 'vike:importUserCode',
18
18
  async configResolved(config_) {
19
- const vikeConfig = await getVikeConfig(config_);
20
- vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
19
+ vikeConfig = await getVikeConfig(config_);
21
20
  config = config_;
22
21
  // TODO/v1-release: remove
23
22
  {
@@ -52,7 +51,7 @@ function importUserCode() {
52
51
  return code;
53
52
  }
54
53
  if (isVirtualFileIdImportUserCode(id)) {
55
- const code = await getVirtualFileImportUserCode(id, options, vikeConfigGlobal, config, isDev);
54
+ const code = await getVirtualFileImportUserCode(id, options, vikeConfig, config, isDev);
56
55
  return code;
57
56
  }
58
57
  },
@@ -1,5 +1,6 @@
1
1
  export { assertExtensionsConventions };
2
- export { assertExtensionsPeerDependencies };
2
+ export { assertExtensionsRequire };
3
3
  import { type InterfaceFile } from './getVikeConfig.js';
4
+ import { PageConfigBuildTime } from '../../../../../shared/page-configs/PageConfig.js';
4
5
  declare function assertExtensionsConventions(interfaceFile: InterfaceFile): void;
5
- declare function assertExtensionsPeerDependencies(interfaceFilesRelevantList: InterfaceFile[]): void;
6
+ declare function assertExtensionsRequire(pageConfig: PageConfigBuildTime): void;
@@ -1,5 +1,5 @@
1
1
  export { assertExtensionsConventions };
2
- export { assertExtensionsPeerDependencies };
2
+ export { assertExtensionsRequire };
3
3
  import pc from '@brillout/picocolors';
4
4
  import { isObjectOfStrings } from '../../../../../utils/isObjectOfStrings.js';
5
5
  import { PROJECT_VERSION, assert, assertUsage, assertWarning, findPackageJson } from '../../../utils.js';
@@ -18,32 +18,33 @@ function assertConfigExportPath(interfaceFile) {
18
18
  assert(!p.includes('node_modules'));
19
19
  return;
20
20
  }
21
- const name = getConfigNameValue(interfaceFile);
21
+ const name = getNameValue(interfaceFile);
22
22
  assert(name); // already asserted in assertExtensionName()
23
23
  const importPathAbsoluteExpected = `${name}/config`;
24
24
  assertWarning(importPathAbsolute === importPathAbsoluteExpected, `The Vike configuration of ${pc.bold(name)} is exported at ${pc.bold(importPathAbsolute)}, but it should be exported at ${pc.bold(importPathAbsoluteExpected)} instead.`, { onlyOnce: true });
25
25
  }
26
26
  function assertExtensionName(interfaceFile) {
27
27
  const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
28
- const name = getConfigNameValue(interfaceFile);
28
+ const name = getNameValue(interfaceFile);
29
29
  assertUsage(name, `Vike extension name missing: the config ${filePathToShowToUser} must define the setting ${pc.cyan('name')}`);
30
30
  }
31
- function assertExtensionsPeerDependencies(interfaceFilesRelevantList) {
32
- // Get installed extensions
31
+ function assertExtensionsRequire(pageConfig) {
32
+ const interfaceFilesRelevantList = Object.values(pageConfig.interfaceFiles).flat(1);
33
+ // Collect extensions
33
34
  const extensions = {};
34
35
  interfaceFilesRelevantList.forEach((interfaceFile) => {
35
- const name = getConfigNameValue(interfaceFile);
36
+ const name = getNameValue(interfaceFile);
36
37
  if (name) {
37
38
  const version = getExtensionVersion(name, interfaceFile);
38
39
  extensions[name] = version;
39
40
  }
40
41
  });
41
- // Enforce peer dependencies
42
+ // Enforce `require`
42
43
  interfaceFilesRelevantList.forEach((interfaceFile) => {
43
44
  const require = getConfigRequireValue(interfaceFile);
44
45
  if (!require)
45
46
  return;
46
- const name = getConfigNameValue(interfaceFile);
47
+ const name = getNameValue(interfaceFile);
47
48
  const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
48
49
  assertUsage(name, `Setting ${pc.bold('name')} is required for being able to use setting ${pc.bold('require')} in ${filePathToShowToUser}.`);
49
50
  Object.entries(require).forEach(([reqName, reqVersion]) => {
@@ -67,7 +68,7 @@ function getConfigRequireValue(interfaceFile) {
67
68
  assertUsage(isObjectOfStrings(require), `The setting ${pc.bold('require')} defined at ${filePathToShowToUserResolved} should be an object with string values (${pc.bold('Record<string, string>')}).`);
68
69
  return require;
69
70
  }
70
- function getConfigNameValue(interfaceFile) {
71
+ function getNameValue(interfaceFile) {
71
72
  const name = getConfigValueInterfaceFile(interfaceFile, 'name');
72
73
  if (!name)
73
74
  return null;
@@ -139,7 +139,12 @@ const configDefinitionsBuiltInAll = {
139
139
  eager: true,
140
140
  global: true
141
141
  },
142
- prerender: { env: { config: true }, global: (value) => typeof value !== 'object', type: ['boolean', 'object'] },
142
+ prerender: {
143
+ env: { config: true },
144
+ global: (value) => typeof value === 'object',
145
+ type: ['boolean', 'object'],
146
+ cumulative: true
147
+ },
143
148
  vite: { env: { config: true }, global: true, cumulative: true, type: 'object' },
144
149
  disableAutoFullBuild: {
145
150
  env: { config: true },
@@ -151,8 +156,8 @@ const configDefinitionsBuiltInAll = {
151
156
  ]
152
157
  },
153
158
  includeAssetsImportedByServer: { env: { config: true }, global: true, type: 'boolean' },
154
- baseAssets: { env: { config: true }, global: true, type: 'string' },
155
- baseServer: { env: { config: true }, global: true, type: 'string' },
159
+ baseAssets: { env: { config: true, server: true }, global: true, type: 'string' },
160
+ baseServer: { env: { config: true, server: true }, global: true, type: 'string' },
156
161
  redirects: { env: { server: true }, global: true, type: 'string{}', cumulative: true },
157
162
  trailingSlash: { env: { server: true }, global: true, type: 'boolean' },
158
163
  disableUrlNormalization: { env: { server: true }, global: true, type: 'boolean' }
@@ -8,8 +8,7 @@ export { getConfigValueInterfaceFile };
8
8
  export type { VikeConfigObject };
9
9
  export type { InterfaceValueFile };
10
10
  export type { InterfaceFile };
11
- export type { VikeConfigGlobal };
12
- export type { VikeVitePluginOptions };
11
+ export type { InterfaceFilesByLocationId };
13
12
  import type { PageConfigGlobalBuildTime, PageConfigBuildTime } from '../../../../../shared/page-configs/PageConfig.js';
14
13
  import { type LocationId } from './getVikeConfig/filesystemRouting.js';
15
14
  import type { ResolvedConfig } from 'vite';
@@ -35,10 +34,10 @@ type InterfaceValueFile = InterfaceFileCommons & {
35
34
  configName: string;
36
35
  };
37
36
  type ConfigName = string;
37
+ type InterfaceFilesByLocationId = Record<LocationId, InterfaceFile[]>;
38
38
  type VikeConfigObject = {
39
39
  pageConfigs: PageConfigBuildTime[];
40
40
  pageConfigGlobal: PageConfigGlobalBuildTime;
41
- vikeConfigGlobal: VikeConfigGlobal;
42
41
  global: ReturnType<typeof getPageConfigUserFriendlyNew>;
43
42
  };
44
43
  declare const vikeConfigDependencies: Set<string>;
@@ -50,95 +49,3 @@ declare function getVikeConfig2(userRootDir: string, isDev: boolean, vikeVitePlu
50
49
  declare function isV1Design(config: ResolvedConfig): Promise<boolean>;
51
50
  declare function isVikeConfigFile(filePath: string): boolean;
52
51
  declare function getConfigValueInterfaceFile(interfaceFile: InterfaceFile, configName: string): unknown;
53
- type VikeConfigGlobal = {
54
- prerender: false | {
55
- noExtraDir: boolean;
56
- parallel: boolean | number;
57
- partial: boolean;
58
- disableAutoRun: boolean;
59
- };
60
- disableAutoFullBuild: boolean | 'prerender' | null;
61
- includeAssetsImportedByServer: boolean;
62
- baseAssets: string | null;
63
- baseServer: string | null;
64
- trailingSlash: boolean;
65
- disableUrlNormalization: boolean;
66
- };
67
- type VikeVitePluginOptions = {
68
- /**
69
- * Enable pre-rendering.
70
- *
71
- * https://vike.dev/pre-rendering
72
- *
73
- * @default false
74
- */
75
- prerender?: boolean | {
76
- /**
77
- * Don't create a new directory for each HTML file.
78
- *
79
- * For example, generate `dist/client/about.html` instead of `dist/client/about/index.html`.
80
- *
81
- * @default false
82
- */
83
- noExtraDir?: boolean;
84
- /**
85
- * Number of concurrent pre-render jobs.
86
- *
87
- * Set to `false` to disable concurrency.
88
- *
89
- * @default os.cpus().length
90
- */
91
- parallel?: boolean | number;
92
- /**
93
- * Allow only some of your pages to be pre-rendered.
94
- *
95
- * This setting doesn't affect the pre-rendering process: it merely suppresses the warnings when some of your pages cannot be pre-rendered.
96
-
97
- * @default false
98
- */
99
- partial?: boolean;
100
- /**
101
- * Disable the automatic initiation of the pre-rendering process when running `$ vike build`.
102
- *
103
- * Use this if you want to programmatically initiate the pre-rendering process instead.
104
- *
105
- * https://vike.dev/api#prerender
106
- *
107
- * @default false
108
- */
109
- disableAutoRun?: boolean;
110
- };
111
- /** @deprecated See https://vike.dev/disableAutoFullBuild */
112
- disableAutoFullBuild?: boolean | 'prerender';
113
- /** The Base URL of your server.
114
- *
115
- * https://vike.dev/base-url
116
- */
117
- baseServer?: string;
118
- /** The Base URL of your static assets.
119
- *
120
- * https://vike.dev/base-url
121
- */
122
- baseAssets?: string;
123
- /** @deprecated It's now `true` by default. You can remove this option. */
124
- includeAssetsImportedByServer?: boolean;
125
- /** Permanent redirections (HTTP status code 301)
126
- *
127
- * https://vike.dev/redirects
128
- */
129
- redirects?: Record<string, string>;
130
- /** Whether URLs should end with a trailing slash.
131
- *
132
- * https://vike.dev/url-normalization
133
- *
134
- * @default false
135
- */
136
- trailingSlash?: boolean;
137
- /** Disable automatic URL normalization.
138
- *
139
- * https://vike.dev/url-normalization
140
- *
141
- * @default false
142
- */
143
- disableUrlNormalization?: boolean;
144
- };