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
@@ -20,5 +20,5 @@ const onLoad_js_1 = require("./onLoad.js");
20
20
  (0, onLoad_js_1.onLoad)();
21
21
  __exportStar(require("../../utils/assert.js"), exports);
22
22
  __exportStar(require("../../utils/getGlobalObject.js"), exports);
23
- __exportStar(require("../../utils/filesystemPathHandling.js"), exports);
23
+ __exportStar(require("../../utils/toPosixPath.js"), exports);
24
24
  __exportStar(require("../../utils/isObject.js"), exports);
@@ -5,12 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getOutDirs = getOutDirs;
7
7
  exports.resolveOutDir = resolveOutDir;
8
- const viteIsSSR_js_1 = require("./viteIsSSR.js");
9
- const assert_js_1 = require("./assert.js");
10
- const path_shim_js_1 = require("./path-shim.js");
11
- const filesystemPathHandling_js_1 = require("./filesystemPathHandling.js");
8
+ const viteIsSSR_js_1 = require("../../utils/viteIsSSR.js");
9
+ const assert_js_1 = require("../../utils/assert.js");
10
+ const path_shim_js_1 = require("../../utils/path-shim.js");
11
+ const toPosixPath_js_1 = require("../../utils/toPosixPath.js");
12
12
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
13
- const debug_js_1 = require("./debug.js");
13
+ const debug_js_1 = require("../../utils/debug.js");
14
14
  const debug = (0, debug_js_1.createDebugger)('vike:outDir');
15
15
  function getOutDirs(config) {
16
16
  debug('getOutDirs()', new Error().stack);
@@ -55,7 +55,7 @@ function resolveOutDir(config) {
55
55
  }
56
56
  }
57
57
  function determineOutDirs(outDirRoot) {
58
- (0, filesystemPathHandling_js_1.assertPosixPath)(outDirRoot);
58
+ (0, toPosixPath_js_1.assertPosixPath)(outDirRoot);
59
59
  (0, assert_js_1.assert)(!outDirRoot.endsWith('/'));
60
60
  (0, assert_js_1.assert)(isOutDirRoot(outDirRoot));
61
61
  const outDirClient = (0, path_shim_js_1.pathJoin)(outDirRoot, 'client');
@@ -66,8 +66,8 @@ function determineOutDirs(outDirRoot) {
66
66
  }
67
67
  function getOutDirsAll(outDirRoot, root) {
68
68
  if (!outDirIsAbsolutePath(outDirRoot)) {
69
- (0, filesystemPathHandling_js_1.assertPosixPath)(outDirRoot);
70
- (0, filesystemPathHandling_js_1.assertPosixPath)(root);
69
+ (0, toPosixPath_js_1.assertPosixPath)(outDirRoot);
70
+ (0, toPosixPath_js_1.assertPosixPath)(root);
71
71
  outDirRoot = (0, path_shim_js_1.pathJoin)(root, outDirRoot);
72
72
  }
73
73
  let { outDirClient, outDirServer } = determineOutDirs(outDirRoot);
@@ -80,7 +80,7 @@ function getOutDirsAll(outDirRoot, root) {
80
80
  return { outDirRoot, outDirClient, outDirServer };
81
81
  }
82
82
  function assertNormalization(outDirAny) {
83
- (0, filesystemPathHandling_js_1.assertPosixPath)(outDirAny);
83
+ (0, toPosixPath_js_1.assertPosixPath)(outDirAny);
84
84
  (0, assert_js_1.assert)(outDirIsAbsolutePath(outDirAny));
85
85
  (0, assert_js_1.assert)(outDirAny.endsWith('/'));
86
86
  (0, assert_js_1.assert)(!outDirAny.endsWith('//'));
@@ -95,7 +95,7 @@ function assertIsNotOutDirRoot(outDir) {
95
95
  }
96
96
  /** `outDir` ends with `/server` or `/client` */
97
97
  function assertOutDirResolved(outDir, config) {
98
- (0, filesystemPathHandling_js_1.assertPosixPath)(outDir);
98
+ (0, toPosixPath_js_1.assertPosixPath)(outDir);
99
99
  assertIsNotOutDirRoot(outDir);
100
100
  (0, assert_js_1.assert)('/client'.length === '/server'.length);
101
101
  const outDirCorrected = outDir.slice(0, -1 * '/client'.length);
@@ -121,7 +121,7 @@ function getOutDirFromViteResolvedConfig(config) {
121
121
  return outDir;
122
122
  }
123
123
  function normalize(outDir) {
124
- outDir = (0, filesystemPathHandling_js_1.toPosixPath)(outDir);
124
+ outDir = (0, toPosixPath_js_1.toPosixPath)(outDir);
125
125
  outDir = outDir.replace(/\/+$/, ''); // remove trailing slashes
126
126
  return outDir;
127
127
  }
@@ -9,7 +9,6 @@ exports.ssr = plugin;
9
9
  exports.default = plugin;
10
10
  var utils_js_1 = require("./utils.js");
11
11
  Object.defineProperty(exports, "version", { enumerable: true, get: function () { return utils_js_1.PROJECT_VERSION; } });
12
- const vite_1 = require("vite");
13
12
  const utils_js_2 = require("./utils.js");
14
13
  const buildConfig_js_1 = require("./plugins/buildConfig.js");
15
14
  const previewConfig_js_1 = require("./plugins/previewConfig.js");
@@ -33,8 +32,7 @@ const getPageAssets_js_1 = require("../runtime/renderPage/getPageAssets.js");
33
32
  const resolveClientEntriesDev_js_1 = require("./resolveClientEntriesDev.js");
34
33
  const workaroundCssModuleHmr_js_1 = require("./plugins/workaroundCssModuleHmr.js");
35
34
  const workaroundVite6HmrRegression_js_1 = require("./plugins/workaroundVite6HmrRegression.js");
36
- (0, utils_js_2.markSetup_vikeVitePlugin)();
37
- assertViteVersion();
35
+ // We don't call this in ./onLoad.ts to avoid a cyclic dependency with utils.ts
38
36
  (0, getPageAssets_js_1.setResolveClientEntriesDev)(resolveClientEntriesDev_js_1.resolveClientEntriesDev);
39
37
  // Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
40
38
  function plugin(vikeVitePluginOptions = {}) {
@@ -69,10 +67,6 @@ Object.defineProperty(plugin, 'apply', {
69
67
  (0, utils_js_2.assertUsage)(false, `Add ${picocolors_1.default.cyan('vike()')} instead of ${picocolors_1.default.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 });
70
68
  }
71
69
  });
72
- // package.json#peerDependencies isn't enough as users can ignore it
73
- function assertViteVersion() {
74
- (0, utils_js_2.assertVersion)('Vite', vite_1.version, '5.1.0');
75
- }
76
70
  // Ensures following works: `const vike = require('vike/plugin')` / `import vike from 'vike/plugin'`
77
71
  // - It needs to live at the end of this file, in order to ensure we do it after all assignments to `exports`.
78
72
  try {
@@ -4,9 +4,14 @@ exports.onLoad = onLoad;
4
4
  const assertIsNotBrowser_js_1 = require("../../utils/assertIsNotBrowser.js");
5
5
  const assertSetup_js_1 = require("../../utils/assertSetup.js");
6
6
  const assertNodeVersion_js_1 = require("../../utils/assertNodeVersion.js");
7
+ const assertVersion_js_1 = require("../../utils/assertVersion.js");
8
+ const vite_1 = require("vite");
7
9
  function onLoad() {
10
+ (0, assertSetup_js_1.markSetup_vikeVitePlugin)();
8
11
  (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
9
12
  (0, assertNodeVersion_js_1.assertNodeVersion)();
10
- // Ensure we don't bloat the server runtime with heavy plugin dependencies such as esbuild
13
+ // package.json#peerDependencies isn't enough as users can ignore it
14
+ (0, assertVersion_js_1.assertVersion)('Vite', vite_1.version, '5.1.0');
15
+ // Ensure we don't bloat the server runtime with heavy dependencies such Vite and esbuild
11
16
  (0, assertSetup_js_1.assertIsNotProductionRuntime)();
12
17
  }
@@ -19,17 +19,16 @@ const context_js_3 = require("../../cli/context.js");
19
19
  let forceExit = false;
20
20
  function autoFullBuild() {
21
21
  let config;
22
- let vikeConfigGlobal;
22
+ let vikeConfig;
23
23
  return [
24
24
  {
25
25
  name: 'vike:autoFullBuild',
26
26
  apply: 'build',
27
27
  enforce: 'pre',
28
28
  async configResolved(config_) {
29
- const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config_);
30
- vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
29
+ vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config_);
31
30
  config = config_;
32
- abortViteBuildSsr(vikeConfigGlobal);
31
+ abortViteBuildSsr(vikeConfig);
33
32
  },
34
33
  writeBundle: {
35
34
  /* We can't use this because it breaks Vite's logging. TODO: try again with latest Vite version.
@@ -38,7 +37,7 @@ function autoFullBuild() {
38
37
  */
39
38
  async handler(_options, bundle) {
40
39
  try {
41
- await triggerFullBuild(config, vikeConfigGlobal, bundle);
40
+ await triggerFullBuild(config, vikeConfig, bundle);
42
41
  }
43
42
  catch (err) {
44
43
  // Avoid Rollup prefixing the error with [vike:autoFullBuild], for example see https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
@@ -64,10 +63,10 @@ function autoFullBuild() {
64
63
  }
65
64
  ];
66
65
  }
67
- async function triggerFullBuild(config, vikeConfigGlobal, bundle) {
66
+ async function triggerFullBuild(config, vikeConfig, bundle) {
68
67
  if (config.build.ssr)
69
68
  return; // already triggered
70
- if (isDisabled(vikeConfigGlobal))
69
+ if (isDisabled(vikeConfig))
71
70
  return;
72
71
  // Workaround for @vitejs/plugin-legacy
73
72
  // - The legacy plugin triggers its own Rollup build for the client-side.
@@ -98,7 +97,7 @@ async function triggerFullBuild(config, vikeConfigGlobal, bundle) {
98
97
  (0, logErrorHint_js_1.logErrorHint)(err);
99
98
  process.exit(1);
100
99
  }
101
- if ((0, context_js_1.isPrerenderAutoRunEnabled)(vikeConfigGlobal)) {
100
+ if ((0, context_js_1.isPrerenderAutoRunEnabled)(vikeConfig)) {
102
101
  const { prerenderContextPublic } = await (0, runPrerender_js_1.runPrerenderFromAutoRun)(configInline);
103
102
  config.vike.prerenderContext = prerenderContextPublic;
104
103
  forceExit = (0, context_js_3.isVikeCli)() || (0, isViteCliCall_js_1.isViteCliCall)();
@@ -113,15 +112,15 @@ function setSSR(configInline) {
113
112
  }
114
113
  };
115
114
  }
116
- function abortViteBuildSsr(vikeConfigGlobal) {
117
- if (vikeConfigGlobal.disableAutoFullBuild !== true && (0, isViteCliCall_js_1.isViteCliCall)() && (0, isViteCliCall_js_1.getViteConfigFromCli)()?.build.ssr) {
115
+ function abortViteBuildSsr(vikeConfig) {
116
+ if (vikeConfig.global.config.disableAutoFullBuild !== true && (0, isViteCliCall_js_1.isViteCliCall)() && (0, isViteCliCall_js_1.getViteConfigFromCli)()?.build.ssr) {
118
117
  (0, utils_js_1.assertWarning)(false, `The CLI call ${picocolors_1.default.cyan('$ vite build --ssr')} is superfluous since ${picocolors_1.default.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 ${picocolors_1.default.cyan('build()')} API.`, { onlyOnce: true });
119
118
  process.exit(0);
120
119
  }
121
120
  }
122
- function isDisabled(vikeConfigGlobal) {
123
- const { disableAutoFullBuild } = vikeConfigGlobal;
124
- if (disableAutoFullBuild === null || disableAutoFullBuild === 'prerender') {
121
+ function isDisabled(vikeConfig) {
122
+ const { disableAutoFullBuild } = vikeConfig.global.config;
123
+ if (disableAutoFullBuild === undefined || disableAutoFullBuild === 'prerender') {
125
124
  const isViteApi = !(0, isViteCliCall_js_1.isViteCliCall)() && !(0, context_js_2.isVikeCliOrApi)();
126
125
  return isViteApi;
127
126
  }
@@ -13,7 +13,7 @@ function baseUrls() {
13
13
  const isDev = config._isDev;
14
14
  (0, utils_js_1.assert)(typeof isDev === 'boolean');
15
15
  const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
16
- basesResolved = (0, resolveBase_js_1.resolveBase)(baseViteOriginal, config._vikeConfigGlobal.baseServer, config._vikeConfigGlobal.baseAssets);
16
+ basesResolved = (0, resolveBase_js_1.resolveBase)(baseViteOriginal, config.vike.global.config.baseServer ?? null, config.vike.global.config.baseAssets ?? null);
17
17
  // We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
18
18
  process.env.BASE_SERVER = basesResolved.baseServer;
19
19
  process.env.BASE_ASSETS = basesResolved.baseAssets;
@@ -29,7 +29,7 @@ function baseUrls() {
29
29
  },
30
30
  async configResolved(config) {
31
31
  const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config);
32
- const basesResolved2 = (0, resolveBase_js_1.resolveBaseFromResolvedConfig)(vikeConfig.vikeConfigGlobal.baseServer, vikeConfig.vikeConfigGlobal.baseAssets, config);
32
+ const basesResolved2 = (0, resolveBase_js_1.resolveBaseFromResolvedConfig)(vikeConfig.global.config.baseServer ?? null, vikeConfig.global.config.baseAssets ?? null, config);
33
33
  (0, utils_js_1.assert)(basesResolved2.baseServer === basesResolved.baseServer);
34
34
  (0, utils_js_1.assert)(basesResolved2.baseAssets === basesResolved.baseAssets);
35
35
  /* In dev, Vite seems buggy around setting vite.config.js#base to an absolute URL (e.g. http://localhost:8080/cdn/)
@@ -85,7 +85,7 @@ function buildConfig() {
85
85
  name: 'vike:buildConfig:pre',
86
86
  apply: 'build',
87
87
  // Make sure other writeBundle() hooks are called after this writeBundle() hook.
88
- // - set_ASSETS_MAP() needs to be called before dist/server/ code is executed.
88
+ // - set_ASSETS_MANIFEST() needs to be called before dist/server/ code is executed.
89
89
  // - 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
90
90
  enforce: 'pre',
91
91
  writeBundle: {
@@ -108,7 +108,7 @@ function buildConfig() {
108
108
  }
109
109
  await promises_1.default.rm(clientManifestFilePath);
110
110
  await promises_1.default.rm(serverManifestFilePath);
111
- await (0, index_js_1.set_ASSETS_MAP)(options, bundle);
111
+ await (0, index_js_1.set_ASSETS_MANIFEST)(options, bundle);
112
112
  }
113
113
  }
114
114
  }
@@ -118,7 +118,10 @@ function buildConfig() {
118
118
  async function getEntries(config) {
119
119
  const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config);
120
120
  const { pageConfigs } = vikeConfig;
121
- const pageFileEntries = await getPageFileEntries(config, vikeConfig.vikeConfigGlobal.includeAssetsImportedByServer); // TODO/v1-release: remove
121
+ // TODO/v1-release: remove
122
+ const pageFileEntries = await getPageFileEntries(config,
123
+ // TODO/now: add meta.default
124
+ vikeConfig.global.config.includeAssetsImportedByServer ?? true);
122
125
  (0, utils_js_1.assertUsage)(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
123
126
  if ((0, utils_js_1.viteIsSSR)(config)) {
124
127
  const pageEntries = getPageEntries(pageConfigs);
@@ -4,11 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.buildEntry = buildEntry;
7
- exports.set_ASSETS_MAP = set_ASSETS_MAP;
7
+ exports.set_ASSETS_MANIFEST = set_ASSETS_MANIFEST;
8
8
  const plugin_1 = require("@brillout/vite-plugin-server-entry/plugin");
9
9
  const virtualFileImportUserCode_js_1 = require("../../../shared/virtual-files/virtualFileImportUserCode.js");
10
- const getVikeManifest_js_1 = require("./getVikeManifest.js");
11
- const getVikeConfig_js_1 = require("../importUserCode/v1-design/getVikeConfig.js");
12
10
  const utils_js_1 = require("../../utils.js");
13
11
  const promises_1 = __importDefault(require("fs/promises"));
14
12
  const path_1 = __importDefault(require("path"));
@@ -16,69 +14,74 @@ const module_1 = require("module");
16
14
  // @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
17
15
  const importMetaUrl = `file://${__filename}`;
18
16
  const require_ = (0, module_1.createRequire)(importMetaUrl);
19
- const ASSETS_MAP = '__VITE_ASSETS_MAP__';
17
+ const extractExportNamesPlugin_js_1 = require("../extractExportNamesPlugin.js");
18
+ const globalContext_js_1 = require("../../../runtime/globalContext.js");
19
+ const ASSETS_MANIFEST = '__VITE_ASSETS_MANIFEST__';
20
20
  function buildEntry() {
21
21
  let config;
22
- let vikeConfigGlobal;
23
22
  return [
24
23
  {
25
24
  name: 'vike:buildEntry',
26
25
  enforce: 'post',
27
26
  async configResolved(config_) {
28
27
  config = config_;
29
- const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config);
30
- vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
31
28
  }
32
29
  },
33
30
  ...(0, plugin_1.serverProductionEntryPlugin)({
34
31
  getServerProductionEntry: () => {
35
- return getServerProductionEntryCode(config, vikeConfigGlobal);
32
+ return getServerProductionEntryCode(config);
36
33
  },
37
34
  libraryName: 'Vike'
38
35
  })
39
36
  ];
40
37
  }
41
- function getServerProductionEntryCode(config, vikeConfigGlobal) {
38
+ function getServerProductionEntryCode(config) {
42
39
  const importPath = getImportPath(config);
43
- const vikeManifest = (0, getVikeManifest_js_1.getVikeManifest)(vikeConfigGlobal, config);
44
- // Let's eventually simplify and move everything to a single virtual module
40
+ const buildInfo = {
41
+ versionAtBuildTime: utils_js_1.projectInfo.projectVersion,
42
+ usesClientRouter: (0, extractExportNamesPlugin_js_1.isUsingClientRouter)(), // TODO/v1-release: remove
43
+ viteConfigRuntime: (0, globalContext_js_1.getViteConfigRuntime)(config)
44
+ };
45
+ (0, globalContext_js_1.assertBuildInfo)(buildInfo);
46
+ // After the old design is removed, let's maybe simplify and move everything into a single virtual module
45
47
  const importerCode = [
46
48
  ` import { setGlobalContext_buildEntry } from '${importPath}';`,
47
49
  ` import * as pageFiles from '${virtualFileImportUserCode_js_1.virtualFileIdImportUserCodeServer}';`,
48
50
  ` {`,
49
- // 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
50
- ` const assetsManifest = ${ASSETS_MAP};`,
51
- ` const pluginManifest = ${JSON.stringify(vikeManifest, null, 2)};`,
51
+ // Because of a Rollup bug, we have to assign ASSETS_MANIFEST to a variable before passing it to setGlobalContext_buildEntry()
52
+ // - This workaround doesn't work: https://github.com/vikejs/vike/commit/d5f3a4f7aae5a8bc44192e6cbb2bcb9007be188d
53
+ ` const assetsManifest = ${ASSETS_MANIFEST};`,
54
+ ` const buildInfo = ${JSON.stringify(buildInfo, null, 2)};`,
52
55
  ' setGlobalContext_buildEntry({',
53
56
  ` pageFiles,`,
54
57
  ` assetsManifest,`,
55
- ` pluginManifest,`,
58
+ ` buildInfo,`,
56
59
  ' });',
57
60
  ` }`,
58
61
  ''
59
62
  ].join('\n');
60
63
  return importerCode;
61
64
  }
62
- /** Set the value of the ASSETS_MAP constant inside dist/server/entry.js (or dist/server/index.js) */
63
- async function set_ASSETS_MAP(options, bundle) {
65
+ /** Set the value of the ASSETS_MANIFEST constant inside dist/server/entry.js (or dist/server/index.js) */
66
+ async function set_ASSETS_MANIFEST(options, bundle) {
64
67
  const { dir } = options;
65
68
  (0, utils_js_1.assert)(dir);
66
- const chunkPath = find_ASSETS_MAP(bundle);
69
+ const chunkPath = find_ASSETS_MANIFEST(bundle);
67
70
  const chunkFilePath = path_1.default.join(dir, chunkPath);
68
71
  const assetsJsonFilePath = path_1.default.join(dir, '..', 'assets.json');
69
72
  const [assetsJsonString, chunkFileContent] = await Promise.all([
70
73
  await promises_1.default.readFile(assetsJsonFilePath, 'utf8'),
71
74
  await promises_1.default.readFile(chunkFilePath, 'utf8')
72
75
  ]);
73
- const serverEntryFileContentPatched = chunkFileContent.replace(ASSETS_MAP, assetsJsonString);
76
+ const serverEntryFileContentPatched = chunkFileContent.replace(ASSETS_MANIFEST, assetsJsonString);
74
77
  (0, utils_js_1.assert)(serverEntryFileContentPatched !== chunkFileContent);
75
78
  await promises_1.default.writeFile(chunkFilePath, serverEntryFileContentPatched);
76
79
  }
77
- function find_ASSETS_MAP(bundle) {
80
+ function find_ASSETS_MANIFEST(bundle) {
78
81
  let chunkPath;
79
82
  for (const filePath in bundle) {
80
83
  const chunk = bundle[filePath];
81
- if ('code' in chunk && chunk.code.includes(ASSETS_MAP)) {
84
+ if ('code' in chunk && chunk.code.includes(ASSETS_MANIFEST)) {
82
85
  (0, utils_js_1.assert)(!chunkPath);
83
86
  chunkPath = filePath;
84
87
  }
@@ -17,6 +17,7 @@ const context_js_1 = require("../../api/context.js");
17
17
  const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
18
18
  const prepareViteApiCall_js_1 = require("../../api/prepareViteApiCall.js");
19
19
  const context_js_2 = require("../../prerender/context.js");
20
+ const resolvePrerenderConfig_js_1 = require("../../prerender/resolvePrerenderConfig.js");
20
21
  const pluginName = 'vike:commonConfig';
21
22
  function commonConfig(vikeVitePluginOptions) {
22
23
  return [
@@ -36,10 +37,10 @@ function commonConfig(vikeVitePluginOptions) {
36
37
  _root: root,
37
38
  _vikeVitePluginOptions: vikeVitePluginOptions,
38
39
  vike: { global: vikeConfig.global },
39
- // TODO/now: remove
40
- _vikeConfigGlobal: vikeConfig.vikeConfigGlobal,
41
40
  // TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
42
- configVikePromise: Promise.resolve({ prerender: !!vikeConfig.vikeConfigGlobal.prerender })
41
+ configVikePromise: Promise.resolve({
42
+ prerender: !!(0, resolvePrerenderConfig_js_1.resolvePrerenderConfig)(vikeConfig.global.config.prerender)
43
+ })
43
44
  };
44
45
  }
45
46
  }
@@ -45,7 +45,8 @@ function extractAssetsPlugin() {
45
45
  (0, assertV1Design_js_1.assertV1Design)(vikeConfig.pageConfigs, true);
46
46
  (0, utils_js_1.assert)(false);
47
47
  }
48
- (0, utils_js_1.assert)(vikeConfig.vikeConfigGlobal.includeAssetsImportedByServer);
48
+ // TODO/now: add meta.default
49
+ (0, utils_js_1.assert)(vikeConfig.global.config.includeAssetsImportedByServer ?? true);
49
50
  (0, utils_js_1.assert)(!(0, utils_js_1.viteIsSSR_options)(options));
50
51
  const importStatements = await (0, parseEsModule_js_1.getImportStatements)(src);
51
52
  const moduleNames = getImportedModules(importStatements);
@@ -78,7 +79,8 @@ function extractAssetsPlugin() {
78
79
  if (!extractAssetsRE.test(importer)) {
79
80
  return;
80
81
  }
81
- (0, utils_js_1.assert)(vikeConfig.vikeConfigGlobal.includeAssetsImportedByServer);
82
+ // TODO/now: add meta.default
83
+ (0, utils_js_1.assert)(vikeConfig.global.config.includeAssetsImportedByServer ?? true);
82
84
  let resolution = null;
83
85
  try {
84
86
  resolution = await this.resolve(source, importer, { skipSelf: true, ...options });
@@ -11,16 +11,17 @@ const fileTypes_js_1 = require("../../../../shared/getPageFiles/fileTypes.js");
11
11
  const path_1 = __importDefault(require("path"));
12
12
  const getVirtualFilePageConfigs_js_1 = require("./v1-design/getVirtualFilePageConfigs.js");
13
13
  const getVikeConfig_js_1 = require("./v1-design/getVikeConfig.js");
14
- async function getVirtualFileImportUserCode(id, options, vikeConfigGlobal, config, isDev) {
14
+ const resolvePrerenderConfig_js_1 = require("../../../prerender/resolvePrerenderConfig.js");
15
+ async function getVirtualFileImportUserCode(id, options, vikeConfig, config, isDev) {
15
16
  const idParsed = (0, virtualFileImportUserCode_js_1.isVirtualFileIdImportUserCode)(id);
16
17
  (0, utils_js_1.assert)(idParsed);
17
18
  const { isForClientSide, isClientRouting } = idParsed;
18
19
  (0, utils_js_1.assert)(isForClientSide === !(0, utils_js_1.viteIsSSR_options)(options));
19
- const isPrerendering = !!vikeConfigGlobal.prerender;
20
- const code = await getCode(config, vikeConfigGlobal, isForClientSide, isClientRouting, isPrerendering, isDev, id);
20
+ const isPrerendering = !!(0, resolvePrerenderConfig_js_1.resolvePrerenderConfig)(vikeConfig.global.config.prerender);
21
+ const code = await getCode(config, vikeConfig, isForClientSide, isClientRouting, isPrerendering, isDev, id);
21
22
  return code;
22
23
  }
23
- async function getCode(config, vikeConfigGlobal, isForClientSide, isClientRouting, isPrerendering, isDev, id) {
24
+ async function getCode(config, vikeConfig, isForClientSide, isClientRouting, isPrerendering, isDev, id) {
24
25
  const { command } = config;
25
26
  (0, utils_js_1.assert)(command === 'serve' || command === 'build');
26
27
  const isBuild = command === 'build';
@@ -29,7 +30,7 @@ async function getCode(config, vikeConfigGlobal, isForClientSide, isClientRoutin
29
30
  {
30
31
  const globRoots = getGlobRoots(config);
31
32
  (0, utils_js_1.debugGlob)('Glob roots: ', globRoots);
32
- content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfigGlobal, isPrerendering, config, isDev, id);
33
+ content += await generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfig, isPrerendering, config, isDev, id);
33
34
  }
34
35
  (0, utils_js_1.debugGlob)(`Glob imports for ${isForClientSide ? 'client' : 'server'}:\n`, content);
35
36
  return content;
@@ -59,7 +60,7 @@ function determineInjection({ fileType, isForClientSide, isClientRouting, isPrer
59
60
  }
60
61
  }
61
62
  }
62
- async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfigGlobal, isPrerendering, config, isDev, id) {
63
+ async function generateGlobImports(globRoots, isBuild, isForClientSide, isClientRouting, vikeConfig, isPrerendering, config, isDev, id) {
63
64
  let fileContent = `// Generated by https://github.com/vikejs/vike/blob/main/vike/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.ts
64
65
 
65
66
  export const pageFilesLazy = {};
@@ -91,7 +92,9 @@ ${await (0, getVirtualFilePageConfigs_js_1.getVirtualFilePageConfigs)(isForClien
91
92
  fileContent += getGlobs(globRoots, isBuild, fileType, 'extractExportNames', isV1Design);
92
93
  }
93
94
  });
94
- if (vikeConfigGlobal.includeAssetsImportedByServer && isForClientSide) {
95
+ // TODO/now: add meta.default
96
+ const includeAssetsImportedByServer = vikeConfig.global.config.includeAssetsImportedByServer ?? true;
97
+ if (includeAssetsImportedByServer && isForClientSide) {
95
98
  fileContent += getGlobs(globRoots, isBuild, '.page.server', 'extractAssets', isV1Design);
96
99
  }
97
100
  return fileContent;
@@ -17,12 +17,11 @@ const loggerNotProd_js_1 = require("../../shared/loggerNotProd.js");
17
17
  const getFilePath_js_1 = require("../../shared/getFilePath.js");
18
18
  function importUserCode() {
19
19
  let config;
20
- let vikeConfigGlobal;
20
+ let vikeConfig;
21
21
  return {
22
22
  name: 'vike:importUserCode',
23
23
  async configResolved(config_) {
24
- const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config_);
25
- vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
24
+ vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(config_);
26
25
  config = config_;
27
26
  // TODO/v1-release: remove
28
27
  {
@@ -57,7 +56,7 @@ function importUserCode() {
57
56
  return code;
58
57
  }
59
58
  if ((0, virtualFileImportUserCode_js_1.isVirtualFileIdImportUserCode)(id)) {
60
- const code = await (0, getVirtualFileImportUserCode_js_1.getVirtualFileImportUserCode)(id, options, vikeConfigGlobal, config, isDev);
59
+ const code = await (0, getVirtualFileImportUserCode_js_1.getVirtualFileImportUserCode)(id, options, vikeConfig, config, isDev);
61
60
  return code;
62
61
  }
63
62
  },
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.assertExtensionsConventions = assertExtensionsConventions;
7
- exports.assertExtensionsPeerDependencies = assertExtensionsPeerDependencies;
7
+ exports.assertExtensionsRequire = assertExtensionsRequire;
8
8
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
9
9
  const isObjectOfStrings_js_1 = require("../../../../../utils/isObjectOfStrings.js");
10
10
  const utils_js_1 = require("../../../utils.js");
@@ -23,32 +23,33 @@ function assertConfigExportPath(interfaceFile) {
23
23
  (0, utils_js_1.assert)(!p.includes('node_modules'));
24
24
  return;
25
25
  }
26
- const name = getConfigNameValue(interfaceFile);
26
+ const name = getNameValue(interfaceFile);
27
27
  (0, utils_js_1.assert)(name); // already asserted in assertExtensionName()
28
28
  const importPathAbsoluteExpected = `${name}/config`;
29
29
  (0, utils_js_1.assertWarning)(importPathAbsolute === importPathAbsoluteExpected, `The Vike configuration of ${picocolors_1.default.bold(name)} is exported at ${picocolors_1.default.bold(importPathAbsolute)}, but it should be exported at ${picocolors_1.default.bold(importPathAbsoluteExpected)} instead.`, { onlyOnce: true });
30
30
  }
31
31
  function assertExtensionName(interfaceFile) {
32
32
  const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
33
- const name = getConfigNameValue(interfaceFile);
33
+ const name = getNameValue(interfaceFile);
34
34
  (0, utils_js_1.assertUsage)(name, `Vike extension name missing: the config ${filePathToShowToUser} must define the setting ${picocolors_1.default.cyan('name')}`);
35
35
  }
36
- function assertExtensionsPeerDependencies(interfaceFilesRelevantList) {
37
- // Get installed extensions
36
+ function assertExtensionsRequire(pageConfig) {
37
+ const interfaceFilesRelevantList = Object.values(pageConfig.interfaceFiles).flat(1);
38
+ // Collect extensions
38
39
  const extensions = {};
39
40
  interfaceFilesRelevantList.forEach((interfaceFile) => {
40
- const name = getConfigNameValue(interfaceFile);
41
+ const name = getNameValue(interfaceFile);
41
42
  if (name) {
42
43
  const version = getExtensionVersion(name, interfaceFile);
43
44
  extensions[name] = version;
44
45
  }
45
46
  });
46
- // Enforce peer dependencies
47
+ // Enforce `require`
47
48
  interfaceFilesRelevantList.forEach((interfaceFile) => {
48
49
  const require = getConfigRequireValue(interfaceFile);
49
50
  if (!require)
50
51
  return;
51
- const name = getConfigNameValue(interfaceFile);
52
+ const name = getNameValue(interfaceFile);
52
53
  const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
53
54
  (0, utils_js_1.assertUsage)(name, `Setting ${picocolors_1.default.bold('name')} is required for being able to use setting ${picocolors_1.default.bold('require')} in ${filePathToShowToUser}.`);
54
55
  Object.entries(require).forEach(([reqName, reqVersion]) => {
@@ -72,7 +73,7 @@ function getConfigRequireValue(interfaceFile) {
72
73
  (0, utils_js_1.assertUsage)((0, isObjectOfStrings_js_1.isObjectOfStrings)(require), `The setting ${picocolors_1.default.bold('require')} defined at ${filePathToShowToUserResolved} should be an object with string values (${picocolors_1.default.bold('Record<string, string>')}).`);
73
74
  return require;
74
75
  }
75
- function getConfigNameValue(interfaceFile) {
76
+ function getNameValue(interfaceFile) {
76
77
  const name = (0, getVikeConfig_js_1.getConfigValueInterfaceFile)(interfaceFile, 'name');
77
78
  if (!name)
78
79
  return null;
@@ -141,7 +141,12 @@ const configDefinitionsBuiltInAll = {
141
141
  eager: true,
142
142
  global: true
143
143
  },
144
- prerender: { env: { config: true }, global: (value) => typeof value !== 'object', type: ['boolean', 'object'] },
144
+ prerender: {
145
+ env: { config: true },
146
+ global: (value) => typeof value === 'object',
147
+ type: ['boolean', 'object'],
148
+ cumulative: true
149
+ },
145
150
  vite: { env: { config: true }, global: true, cumulative: true, type: 'object' },
146
151
  disableAutoFullBuild: {
147
152
  env: { config: true },
@@ -153,8 +158,8 @@ const configDefinitionsBuiltInAll = {
153
158
  ]
154
159
  },
155
160
  includeAssetsImportedByServer: { env: { config: true }, global: true, type: 'boolean' },
156
- baseAssets: { env: { config: true }, global: true, type: 'string' },
157
- baseServer: { env: { config: true }, global: true, type: 'string' },
161
+ baseAssets: { env: { config: true, server: true }, global: true, type: 'string' },
162
+ baseServer: { env: { config: true, server: true }, global: true, type: 'string' },
158
163
  redirects: { env: { server: true }, global: true, type: 'string{}', cumulative: true },
159
164
  trailingSlash: { env: { server: true }, global: true, type: 'boolean' },
160
165
  disableUrlNormalization: { env: { server: true }, global: true, type: 'boolean' }