vike 0.4.220-commit-a9f46b8 → 0.4.220-commit-5c7810f

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 (110) 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 +18 -13
  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/loadFileAtConfigTime.js +29 -3
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +216 -233
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -1
  18. package/dist/cjs/node/plugin/plugins/previewConfig.js +3 -4
  19. package/dist/cjs/node/plugin/utils.js +1 -1
  20. package/dist/cjs/node/prerender/context.js +6 -4
  21. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +25 -0
  22. package/dist/cjs/node/prerender/runPrerender.js +9 -4
  23. package/dist/cjs/node/prerender/utils.js +2 -2
  24. package/dist/cjs/node/runtime/globalContext.js +42 -36
  25. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -3
  26. package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +6 -5
  27. package/dist/cjs/node/runtime/renderPage.js +10 -5
  28. package/dist/cjs/node/runtime/utils.js +2 -2
  29. package/dist/cjs/node/shared/resolveBase.js +9 -0
  30. package/dist/cjs/shared/getPageContextUrlComputed.js +6 -1
  31. package/dist/cjs/shared/page-configs/getPageConfigUserFriendly.js +2 -2
  32. package/dist/cjs/shared/utils.js +1 -1
  33. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  34. package/dist/cjs/utils/findFile.js +3 -3
  35. package/dist/cjs/utils/isDev.js +3 -2
  36. package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +2 -2
  37. package/dist/cjs/utils/requireResolve.js +3 -3
  38. package/dist/esm/node/api/utils.d.ts +1 -1
  39. package/dist/esm/node/api/utils.js +1 -1
  40. package/dist/esm/{utils → node/plugin}/getOutDirs.js +5 -5
  41. package/dist/esm/node/plugin/index.d.ts +29 -1
  42. package/dist/esm/node/plugin/index.js +2 -8
  43. package/dist/esm/node/plugin/onLoad.js +7 -2
  44. package/dist/esm/node/plugin/plugins/autoFullBuild.js +12 -13
  45. package/dist/esm/node/plugin/plugins/baseUrls.js +2 -2
  46. package/dist/esm/node/plugin/plugins/buildConfig.js +7 -4
  47. package/dist/esm/node/plugin/plugins/buildEntry/index.d.ts +3 -3
  48. package/dist/esm/node/plugin/plugins/buildEntry/index.js +25 -22
  49. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +1 -1
  50. package/dist/esm/node/plugin/plugins/commonConfig.js +4 -3
  51. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +4 -2
  52. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +2 -2
  53. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +10 -7
  54. package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -4
  55. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.d.ts +3 -2
  56. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +19 -14
  57. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +8 -3
  58. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +5 -2
  59. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +30 -4
  60. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +23 -101
  61. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +219 -236
  62. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -1
  63. package/dist/esm/node/plugin/plugins/previewConfig.js +3 -4
  64. package/dist/esm/node/plugin/utils.js +1 -1
  65. package/dist/esm/node/prerender/context.d.ts +2 -2
  66. package/dist/esm/node/prerender/context.js +6 -4
  67. package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +5 -0
  68. package/dist/esm/node/prerender/resolvePrerenderConfig.js +23 -0
  69. package/dist/esm/node/prerender/runPrerender.js +9 -4
  70. package/dist/esm/node/prerender/utils.d.ts +2 -2
  71. package/dist/esm/node/prerender/utils.js +2 -2
  72. package/dist/esm/node/runtime/globalContext.d.ts +15 -9
  73. package/dist/esm/node/runtime/globalContext.js +43 -37
  74. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +5 -5
  75. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -3
  76. package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +2 -0
  77. package/dist/esm/node/runtime/renderPage/resolveRedirects.js +5 -5
  78. package/dist/esm/node/runtime/renderPage.js +10 -5
  79. package/dist/esm/node/runtime/utils.d.ts +2 -2
  80. package/dist/esm/node/runtime/utils.js +2 -2
  81. package/dist/esm/node/shared/resolveBase.d.ts +4 -1
  82. package/dist/esm/node/shared/resolveBase.js +9 -0
  83. package/dist/esm/shared/getPageContextUrlComputed.js +6 -1
  84. package/dist/esm/shared/page-configs/Config.d.ts +76 -3
  85. package/dist/esm/shared/page-configs/PageConfig.d.ts +25 -19
  86. package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +1 -1
  87. package/dist/esm/shared/page-configs/getPageConfigUserFriendly.js +2 -2
  88. package/dist/esm/shared/utils.d.ts +1 -1
  89. package/dist/esm/shared/utils.js +1 -1
  90. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  91. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  92. package/dist/esm/utils/findFile.js +1 -1
  93. package/dist/esm/utils/isDev.js +3 -2
  94. package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +1 -1
  95. package/dist/esm/utils/projectInfo.d.ts +1 -1
  96. package/dist/esm/utils/requireResolve.js +1 -1
  97. package/package.json +1 -1
  98. package/dist/cjs/node/plugin/plugins/buildEntry/getVikeManifest.js +0 -17
  99. package/dist/cjs/node/shared/assertPluginManifest.js +0 -20
  100. package/dist/cjs/node/shared/assertRuntimeManifest.js +0 -16
  101. package/dist/esm/node/plugin/plugins/buildEntry/getVikeManifest.d.ts +0 -5
  102. package/dist/esm/node/plugin/plugins/buildEntry/getVikeManifest.js +0 -15
  103. package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -12
  104. package/dist/esm/node/shared/assertPluginManifest.js +0 -18
  105. package/dist/esm/node/shared/assertRuntimeManifest.d.ts +0 -10
  106. package/dist/esm/node/shared/assertRuntimeManifest.js +0 -14
  107. /package/dist/cjs/utils/{filesystemPathHandling.js → toPosixPath.js} +0 -0
  108. /package/dist/esm/{utils → node/plugin}/getOutDirs.d.ts +0 -0
  109. /package/dist/esm/utils/{filesystemPathHandling.d.ts → toPosixPath.d.ts} +0 -0
  110. /package/dist/esm/utils/{filesystemPathHandling.js → toPosixPath.js} +0 -0
@@ -1,11 +1,11 @@
1
1
  export { getOutDirs };
2
2
  export { resolveOutDir };
3
- import { viteIsSSR } from './viteIsSSR.js';
4
- import { assert, assertUsage } from './assert.js';
5
- import { pathJoin } from './path-shim.js';
6
- import { assertPosixPath, toPosixPath } from './filesystemPathHandling.js';
3
+ import { viteIsSSR } from '../../utils/viteIsSSR.js';
4
+ import { assert, assertUsage } from '../../utils/assert.js';
5
+ import { pathJoin } from '../../utils/path-shim.js';
6
+ import { assertPosixPath, toPosixPath } from '../../utils/toPosixPath.js';
7
7
  import pc from '@brillout/picocolors';
8
- import { createDebugger } from './debug.js';
8
+ import { createDebugger } from '../../utils/debug.js';
9
9
  const debug = createDebugger('vike:outDir');
10
10
  function getOutDirs(config) {
11
11
  debug('getOutDirs()', new Error().stack);
@@ -2,6 +2,34 @@ export default plugin;
2
2
  export { plugin };
3
3
  export { plugin as ssr };
4
4
  export type { VikeVitePluginOptions as UserConfig };
5
+ export type { VikeVitePluginOptions };
5
6
  export { PROJECT_VERSION as version } from './utils.js';
6
- import type { VikeVitePluginOptions } from './plugins/importUserCode/v1-design/getVikeConfig.js';
7
7
  declare function plugin(vikeVitePluginOptions?: VikeVitePluginOptions): any;
8
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
9
+ type VikeVitePluginOptions = {
10
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
11
+ prerender?: boolean | {
12
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
13
+ noExtraDir?: boolean;
14
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
15
+ parallel?: boolean | number;
16
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
17
+ partial?: boolean;
18
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
19
+ disableAutoRun?: boolean;
20
+ };
21
+ /** @deprecated See https://vike.dev/disableAutoFullBuild */
22
+ disableAutoFullBuild?: boolean | 'prerender';
23
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
24
+ baseServer?: string;
25
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
26
+ baseAssets?: string;
27
+ /** @deprecated It's now `true` by default. You can remove this option. */
28
+ includeAssetsImportedByServer?: boolean;
29
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
30
+ redirects?: Record<string, string>;
31
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
32
+ trailingSlash?: boolean;
33
+ /** @deprecated Define Vike settings in +config.js instead of vite.config.js */
34
+ disableUrlNormalization?: boolean;
35
+ };
@@ -3,8 +3,7 @@ export { plugin };
3
3
  // TODO/v1-release: remove
4
4
  export { plugin as ssr };
5
5
  export { PROJECT_VERSION as version } from './utils.js';
6
- import { version } from 'vite';
7
- import { assertUsage, assertVersion, markSetup_vikeVitePlugin } from './utils.js';
6
+ import { assertUsage } from './utils.js';
8
7
  import { buildConfig } from './plugins/buildConfig.js';
9
8
  import { previewConfig } from './plugins/previewConfig.js';
10
9
  import { autoFullBuild } from './plugins/autoFullBuild.js';
@@ -27,8 +26,7 @@ import { setResolveClientEntriesDev } from '../runtime/renderPage/getPageAssets.
27
26
  import { resolveClientEntriesDev } from './resolveClientEntriesDev.js';
28
27
  import { workaroundCssModuleHmr } from './plugins/workaroundCssModuleHmr.js';
29
28
  import { workaroundVite6HmrRegression } from './plugins/workaroundVite6HmrRegression.js';
30
- markSetup_vikeVitePlugin();
31
- assertViteVersion();
29
+ // We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
32
30
  setResolveClientEntriesDev(resolveClientEntriesDev);
33
31
  // Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
34
32
  function plugin(vikeVitePluginOptions = {}) {
@@ -63,10 +61,6 @@ Object.defineProperty(plugin, 'apply', {
63
61
  assertUsage(false, `Add ${pc.cyan('vike()')} instead of ${pc.cyan('vike')} to vite.config.js#plugins (i.e. call the function and add the return value instead of adding the function itself)`, { showStackTrace: true });
64
62
  }
65
63
  });
66
- // package.json#peerDependencies isn't enough as users can ignore it
67
- function assertViteVersion() {
68
- assertVersion('Vite', version, '5.1.0');
69
- }
70
64
  // Ensures following works: `const vike = require('vike/plugin')` / `import vike from 'vike/plugin'`
71
65
  // - It needs to live at the end of this file, in order to ensure we do it after all assignments to `exports`.
72
66
  try {
@@ -1,10 +1,15 @@
1
1
  export { onLoad };
2
2
  import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
3
- import { assertIsNotProductionRuntime } from '../../utils/assertSetup.js';
3
+ import { assertIsNotProductionRuntime, markSetup_vikeVitePlugin } from '../../utils/assertSetup.js';
4
4
  import { assertNodeVersion } from '../../utils/assertNodeVersion.js';
5
+ import { assertVersion } from '../../utils/assertVersion.js';
6
+ import { version } from 'vite';
5
7
  function onLoad() {
8
+ markSetup_vikeVitePlugin();
6
9
  assertIsNotBrowser();
7
10
  assertNodeVersion();
8
- // Ensure we don't bloat the server runtime with heavy plugin dependencies such as esbuild
11
+ // package.json#peerDependencies isn't enough as users can ignore it
12
+ assertVersion('Vite', version, '5.1.0');
13
+ // Ensure we don't bloat the server runtime with heavy dependencies such Vite and esbuild
9
14
  assertIsNotProductionRuntime();
10
15
  }
@@ -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,9 +1,9 @@
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';
6
- import { getConfigValueInterfaceFile } from './getVikeConfig.js';
6
+ import { getConfVal } from './getVikeConfig.js';
7
7
  import path from 'path';
8
8
  import semver from 'semver';
9
9
  function assertExtensionsConventions(interfaceFile) {
@@ -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]) => {
@@ -59,18 +60,22 @@ function assertExtensionsPeerDependencies(interfaceFilesRelevantList) {
59
60
  });
60
61
  }
61
62
  function getConfigRequireValue(interfaceFile) {
62
- const require = getConfigValueInterfaceFile(interfaceFile, 'require');
63
- if (!require)
63
+ const confVal = getConfVal(interfaceFile, 'require');
64
+ if (!confVal)
64
65
  return null;
66
+ assert(confVal.configValueLoaded);
67
+ const require = confVal.configValue;
65
68
  const { filePathToShowToUserResolved } = interfaceFile.filePath;
66
69
  assert(filePathToShowToUserResolved);
67
70
  assertUsage(isObjectOfStrings(require), `The setting ${pc.bold('require')} defined at ${filePathToShowToUserResolved} should be an object with string values (${pc.bold('Record<string, string>')}).`);
68
71
  return require;
69
72
  }
70
- function getConfigNameValue(interfaceFile) {
71
- const name = getConfigValueInterfaceFile(interfaceFile, 'name');
72
- if (!name)
73
+ function getNameValue(interfaceFile) {
74
+ const confVal = getConfVal(interfaceFile, 'name');
75
+ if (!confVal)
73
76
  return null;
77
+ assert(confVal.configValueLoaded);
78
+ const name = confVal.configValue;
74
79
  const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
75
80
  assertUsage(typeof name === 'string', `The setting ${pc.bold('name')} defined at ${filePathToShowToUser} should be a string.`);
76
81
  return name;
@@ -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' }