vike 0.4.219 → 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 (157) hide show
  1. package/dist/cjs/node/api/build.js +23 -58
  2. package/dist/cjs/node/api/context.js +6 -8
  3. package/dist/cjs/node/api/prepareViteApiCall.js +6 -7
  4. package/dist/cjs/node/api/utils.js +1 -1
  5. package/dist/cjs/node/cli/context.js +16 -0
  6. package/dist/cjs/node/cli/entry.js +2 -0
  7. package/dist/cjs/node/cli/utils.js +1 -0
  8. package/dist/cjs/{utils → node/plugin}/getOutDirs.js +11 -11
  9. package/dist/cjs/node/plugin/index.js +1 -7
  10. package/dist/cjs/node/plugin/onLoad.js +6 -1
  11. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +43 -31
  12. package/dist/cjs/node/plugin/plugins/baseUrls.js +2 -2
  13. package/dist/cjs/node/plugin/plugins/buildConfig.js +6 -3
  14. package/dist/cjs/node/plugin/plugins/buildEntry/index.js +24 -21
  15. package/dist/cjs/node/plugin/plugins/commonConfig.js +11 -8
  16. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +4 -2
  17. package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +10 -7
  18. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +3 -4
  19. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +10 -9
  20. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +8 -3
  21. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +158 -176
  22. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -1
  23. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +3 -2
  24. package/dist/cjs/node/plugin/plugins/previewConfig.js +3 -4
  25. package/dist/cjs/node/plugin/utils.js +1 -1
  26. package/dist/cjs/node/prerender/context.js +26 -0
  27. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +25 -0
  28. package/dist/cjs/node/prerender/runPrerender.js +64 -37
  29. package/dist/cjs/node/prerender/utils.js +3 -2
  30. package/dist/cjs/node/runtime/globalContext.js +44 -58
  31. package/dist/cjs/node/runtime/page-files/setup.js +1 -1
  32. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -3
  33. package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +6 -5
  34. package/dist/cjs/node/runtime/renderPage.js +10 -5
  35. package/dist/cjs/node/runtime/utils.js +3 -2
  36. package/dist/cjs/node/shared/resolveBase.js +9 -0
  37. package/dist/cjs/shared/page-configs/getPageConfigUserFriendly.js +2 -2
  38. package/dist/cjs/shared/page-configs/loadConfigValues.js +5 -1
  39. package/dist/cjs/shared/utils.js +1 -1
  40. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  41. package/dist/cjs/utils/assertSetup.js +15 -1
  42. package/dist/cjs/utils/catchInfiniteLoop.js +34 -0
  43. package/dist/cjs/utils/findFile.js +3 -3
  44. package/dist/cjs/utils/isDev.js +4 -1
  45. package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +2 -2
  46. package/dist/cjs/utils/makePublicCopy.js +32 -0
  47. package/dist/cjs/utils/requireResolve.js +3 -3
  48. package/dist/esm/client/client-routing-runtime/history.d.ts +3 -1
  49. package/dist/esm/client/client-routing-runtime/history.js +23 -18
  50. package/dist/esm/client/client-routing-runtime/index.d.ts +0 -1
  51. package/dist/esm/client/client-routing-runtime/index.js +0 -1
  52. package/dist/esm/client/client-routing-runtime/initClientRouter.js +2 -2
  53. package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +3 -4
  54. package/dist/esm/client/client-routing-runtime/initOnPopState.d.ts +0 -10
  55. package/dist/esm/client/client-routing-runtime/initOnPopState.js +50 -62
  56. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +15 -15
  57. package/dist/esm/client/client-routing-runtime/scrollRestoration.d.ts +4 -6
  58. package/dist/esm/client/client-routing-runtime/scrollRestoration.js +17 -12
  59. package/dist/esm/client/client-routing-runtime/setScrollPosition.d.ts +1 -1
  60. package/dist/esm/client/client-routing-runtime/setScrollPosition.js +29 -5
  61. package/dist/esm/client/client-routing-runtime/utils.d.ts +1 -0
  62. package/dist/esm/client/client-routing-runtime/utils.js +1 -0
  63. package/dist/esm/client/shared/normalizeClientSideUrl.js +2 -3
  64. package/dist/esm/node/api/build.d.ts +1 -6
  65. package/dist/esm/node/api/build.js +20 -25
  66. package/dist/esm/node/api/context.d.ts +4 -4
  67. package/dist/esm/node/api/context.js +6 -9
  68. package/dist/esm/node/api/prepareViteApiCall.d.ts +0 -1
  69. package/dist/esm/node/api/prepareViteApiCall.js +7 -8
  70. package/dist/esm/node/api/utils.d.ts +1 -1
  71. package/dist/esm/node/api/utils.js +1 -1
  72. package/dist/esm/node/cli/context.d.ts +5 -0
  73. package/dist/esm/node/cli/context.js +14 -0
  74. package/dist/esm/node/cli/entry.js +2 -0
  75. package/dist/esm/node/cli/parseCli.d.ts +3 -1
  76. package/dist/esm/node/cli/utils.d.ts +1 -0
  77. package/dist/esm/node/cli/utils.js +1 -0
  78. package/dist/esm/{utils → node/plugin}/getOutDirs.js +5 -5
  79. package/dist/esm/node/plugin/index.d.ts +29 -1
  80. package/dist/esm/node/plugin/index.js +2 -8
  81. package/dist/esm/node/plugin/onLoad.js +7 -2
  82. package/dist/esm/node/plugin/plugins/autoFullBuild.js +43 -31
  83. package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
  84. package/dist/esm/node/plugin/plugins/buildConfig.js +7 -4
  85. package/dist/esm/node/plugin/plugins/buildEntry/index.d.ts +3 -3
  86. package/dist/esm/node/plugin/plugins/buildEntry/index.js +25 -22
  87. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +8 -2
  88. package/dist/esm/node/plugin/plugins/commonConfig.js +9 -6
  89. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +4 -2
  90. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +2 -2
  91. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +10 -7
  92. package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -4
  93. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.d.ts +3 -2
  94. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +10 -9
  95. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +8 -3
  96. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -95
  97. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +159 -177
  98. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -1
  99. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +3 -2
  100. package/dist/esm/node/plugin/plugins/previewConfig.js +3 -4
  101. package/dist/esm/node/plugin/utils.js +1 -1
  102. package/dist/esm/node/prerender/context.d.ts +9 -0
  103. package/dist/esm/node/prerender/context.js +24 -0
  104. package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +5 -0
  105. package/dist/esm/node/prerender/resolvePrerenderConfig.js +23 -0
  106. package/dist/esm/node/prerender/runPrerender.d.ts +42 -1
  107. package/dist/esm/node/prerender/runPrerender.js +65 -38
  108. package/dist/esm/node/prerender/utils.d.ts +3 -2
  109. package/dist/esm/node/prerender/utils.js +3 -2
  110. package/dist/esm/node/runtime/globalContext.d.ts +15 -9
  111. package/dist/esm/node/runtime/globalContext.js +45 -59
  112. package/dist/esm/node/runtime/page-files/setup.js +1 -1
  113. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +5 -5
  114. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -3
  115. package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +2 -0
  116. package/dist/esm/node/runtime/renderPage/resolveRedirects.js +5 -5
  117. package/dist/esm/node/runtime/renderPage.js +10 -5
  118. package/dist/esm/node/runtime/utils.d.ts +3 -2
  119. package/dist/esm/node/runtime/utils.js +3 -2
  120. package/dist/esm/node/shared/resolveBase.d.ts +4 -1
  121. package/dist/esm/node/shared/resolveBase.js +9 -0
  122. package/dist/esm/shared/page-configs/Config.d.ts +76 -3
  123. package/dist/esm/shared/page-configs/PageConfig.d.ts +25 -16
  124. package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +1 -1
  125. package/dist/esm/shared/page-configs/getPageConfigUserFriendly.js +2 -2
  126. package/dist/esm/shared/page-configs/loadConfigValues.js +6 -2
  127. package/dist/esm/shared/utils.d.ts +1 -1
  128. package/dist/esm/shared/utils.js +1 -1
  129. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  130. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  131. package/dist/esm/utils/assertSetup.js +15 -1
  132. package/dist/esm/utils/catchInfiniteLoop.d.ts +2 -0
  133. package/dist/esm/utils/catchInfiniteLoop.js +32 -0
  134. package/dist/esm/utils/findFile.js +1 -1
  135. package/dist/esm/utils/isDev.js +4 -1
  136. package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -1
  137. package/dist/esm/utils/makePublicCopy.d.ts +3 -0
  138. package/dist/esm/utils/makePublicCopy.js +30 -0
  139. package/dist/esm/utils/projectInfo.d.ts +1 -1
  140. package/dist/esm/utils/requireResolve.js +1 -1
  141. package/package.json +1 -1
  142. package/dist/cjs/node/plugin/plugins/buildEntry/getVikeManifest.js +0 -17
  143. package/dist/cjs/node/prerender/isPrerenderAutoRunEnabled.js +0 -16
  144. package/dist/cjs/node/shared/assertPluginManifest.js +0 -20
  145. package/dist/cjs/node/shared/assertRuntimeManifest.js +0 -16
  146. package/dist/esm/node/plugin/plugins/buildEntry/getVikeManifest.d.ts +0 -5
  147. package/dist/esm/node/plugin/plugins/buildEntry/getVikeManifest.js +0 -15
  148. package/dist/esm/node/prerender/isPrerenderAutoRunEnabled.d.ts +0 -5
  149. package/dist/esm/node/prerender/isPrerenderAutoRunEnabled.js +0 -14
  150. package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -12
  151. package/dist/esm/node/shared/assertPluginManifest.js +0 -18
  152. package/dist/esm/node/shared/assertRuntimeManifest.d.ts +0 -10
  153. package/dist/esm/node/shared/assertRuntimeManifest.js +0 -14
  154. /package/dist/cjs/utils/{filesystemPathHandling.js → toPosixPath.js} +0 -0
  155. /package/dist/esm/{utils → node/plugin}/getOutDirs.d.ts +0 -0
  156. /package/dist/esm/utils/{filesystemPathHandling.d.ts → toPosixPath.d.ts} +0 -0
  157. /package/dist/esm/utils/{filesystemPathHandling.js → toPosixPath.js} +0 -0
@@ -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
  }
@@ -1,12 +1,18 @@
1
1
  export { commonConfig };
2
- import { type Plugin } from 'vite';
2
+ import { type InlineConfig, type Plugin } from 'vite';
3
3
  import { type VikeConfigObject } from './importUserCode/v1-design/getVikeConfig.js';
4
+ import type { PrerenderContextPublic } from '../../prerender/runPrerender.js';
4
5
  declare module 'vite' {
5
6
  interface UserConfig {
6
7
  _isDev?: boolean;
7
8
  _vikeVitePluginOptions?: unknown;
8
9
  _root?: string;
9
- vike?: VikeConfigObject;
10
+ _baseViteOriginal?: string;
11
+ _viteConfigEnhanced?: InlineConfig;
12
+ vike?: {
13
+ global: VikeConfigObject['global'];
14
+ prerenderContext?: PrerenderContextPublic;
15
+ };
10
16
  }
11
17
  }
12
18
  declare function commonConfig(vikeVitePluginOptions: unknown): Plugin[];
@@ -11,7 +11,8 @@ import { isViteCliCall } from '../shared/isViteCliCall.js';
11
11
  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
- import { temp_disablePrerenderAutoRun } from '../../prerender/isPrerenderAutoRunEnabled.js';
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 [
@@ -30,9 +31,11 @@ function commonConfig(vikeVitePluginOptions) {
30
31
  _isDev: isDev,
31
32
  _root: root,
32
33
  _vikeVitePluginOptions: vikeVitePluginOptions,
33
- vike: vikeConfig,
34
- // TODO/v1-release: remove
35
- configVikePromise: Promise.resolve(vikeConfig.vikeConfigGlobal)
34
+ vike: { global: vikeConfig.global },
35
+ // TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
36
+ configVikePromise: Promise.resolve({
37
+ prerender: !!resolvePrerenderConfig(vikeConfig.global.config.prerender)
38
+ })
36
39
  };
37
40
  }
38
41
  }
@@ -75,7 +78,7 @@ function commonConfig(vikeVitePluginOptions) {
75
78
  // VITE_CONFIG
76
79
  const configFromEnvVar = getEnvVarObject('VITE_CONFIG');
77
80
  if (configFromEnvVar)
78
- configFromVike = mergeConfig(configFromEnvVar, configFromVike);
81
+ configFromVike = mergeConfig(configFromVike, configFromEnvVar);
79
82
  return configFromVike;
80
83
  }
81
84
  }
@@ -142,7 +145,7 @@ function assertVikeCliOrApi(config) {
142
145
  onlyOnce: true
143
146
  });
144
147
  }
145
- // TODO/v1-release: remove
148
+ // TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
146
149
  function temp_supportOldInterface(config) {
147
150
  if (!('vitePluginSsr' in config))
148
151
  return;
@@ -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
- };