vike 0.4.215 → 0.4.217-commit-99ea561

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 (144) hide show
  1. package/dist/cjs/__internal/index.js +2 -2
  2. package/dist/cjs/node/api/build.js +10 -3
  3. package/dist/cjs/node/api/context.js +8 -6
  4. package/dist/cjs/node/api/dev.js +7 -2
  5. package/dist/cjs/node/api/{prepareApiCall.js → prepareViteApiCall.js} +16 -6
  6. package/dist/cjs/node/api/prerender.js +7 -2
  7. package/dist/cjs/node/api/preview.js +7 -2
  8. package/dist/cjs/node/api/utils.js +1 -0
  9. package/dist/cjs/node/plugin/index.js +7 -10
  10. package/dist/cjs/node/plugin/onLoad.js +2 -2
  11. package/dist/cjs/node/plugin/plugins/autoFullBuild.js +15 -12
  12. package/dist/cjs/node/plugin/plugins/baseUrls.js +17 -12
  13. package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +1 -1
  14. package/dist/cjs/node/plugin/plugins/buildConfig.js +10 -10
  15. package/dist/cjs/node/plugin/plugins/commonConfig.js +35 -4
  16. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
  17. package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -4
  18. package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +4 -7
  19. package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +2 -2
  20. package/dist/cjs/node/plugin/plugins/importBuild/index.js +8 -6
  21. package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +8 -8
  22. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +9 -13
  23. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +23 -106
  24. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +128 -0
  25. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +42 -28
  26. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -4
  27. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
  28. package/dist/cjs/node/plugin/plugins/previewConfig.js +4 -4
  29. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +35 -17
  30. package/dist/cjs/node/prerender/runPrerender.js +5 -7
  31. package/dist/cjs/node/prerender/utils.js +1 -1
  32. package/dist/cjs/node/runtime/globalContext.js +21 -13
  33. package/dist/cjs/node/runtime/index-common.js +3 -1
  34. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
  35. package/dist/cjs/node/runtime/renderPage.js +4 -2
  36. package/dist/cjs/node/runtime/utils.js +1 -2
  37. package/dist/cjs/node/runtime-dev/createDevMiddleware.js +25 -0
  38. package/dist/cjs/node/runtime-dev/index.js +32 -0
  39. package/dist/cjs/node/shared/resolveBase.js +41 -0
  40. package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +2 -2
  41. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +2 -2
  42. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  43. package/dist/cjs/utils/assertSetup.js +135 -0
  44. package/dist/cjs/utils/isDocker.js +2 -2
  45. package/dist/cjs/utils/requireResolve.js +2 -2
  46. package/dist/esm/__internal/index.js +2 -2
  47. package/dist/esm/node/api/build.d.ts +5 -0
  48. package/dist/esm/node/api/build.js +10 -3
  49. package/dist/esm/node/api/context.js +9 -7
  50. package/dist/esm/node/api/dev.d.ts +5 -0
  51. package/dist/esm/node/api/dev.js +7 -2
  52. package/dist/esm/node/api/prepareViteApiCall.d.ts +7 -0
  53. package/dist/esm/node/api/{prepareApiCall.js → prepareViteApiCall.js} +16 -6
  54. package/dist/esm/node/api/prerender.d.ts +5 -0
  55. package/dist/esm/node/api/prerender.js +7 -2
  56. package/dist/esm/node/api/preview.d.ts +5 -0
  57. package/dist/esm/node/api/preview.js +7 -2
  58. package/dist/esm/node/api/utils.d.ts +1 -0
  59. package/dist/esm/node/api/utils.js +1 -0
  60. package/dist/esm/node/cli/parseCli.d.ts +1 -1
  61. package/dist/esm/node/plugin/index.d.ts +3 -3
  62. package/dist/esm/node/plugin/index.js +6 -9
  63. package/dist/esm/node/plugin/onLoad.js +1 -1
  64. package/dist/esm/node/plugin/plugins/autoFullBuild.js +15 -12
  65. package/dist/esm/node/plugin/plugins/baseUrls.d.ts +2 -2
  66. package/dist/esm/node/plugin/plugins/baseUrls.js +17 -12
  67. package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +1 -1
  68. package/dist/esm/node/plugin/plugins/buildConfig.js +11 -11
  69. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +7 -1
  70. package/dist/esm/node/plugin/plugins/commonConfig.js +36 -5
  71. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.d.ts +1 -1
  72. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
  73. package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -5
  74. package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +4 -7
  75. package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +3 -2
  76. package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +2 -2
  77. package/dist/esm/node/plugin/plugins/importBuild/index.js +8 -6
  78. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +2 -2
  79. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +8 -8
  80. package/dist/esm/node/plugin/plugins/importUserCode/index.js +11 -15
  81. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +1 -1
  82. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +23 -106
  83. package/dist/esm/{shared/ConfigVike.d.ts → node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.d.ts} +14 -12
  84. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +123 -0
  85. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +8 -6
  86. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +43 -29
  87. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +3 -4
  88. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +1 -1
  89. package/dist/esm/node/plugin/plugins/previewConfig.js +5 -5
  90. package/dist/esm/node/plugin/plugins/setGlobalContext.d.ts +1 -1
  91. package/dist/esm/node/plugin/plugins/setGlobalContext.js +37 -19
  92. package/dist/esm/node/plugin/shared/getEnvVarObject.d.ts +1 -1
  93. package/dist/esm/node/prerender/runPrerender.js +6 -8
  94. package/dist/esm/node/prerender/utils.d.ts +1 -1
  95. package/dist/esm/node/prerender/utils.js +1 -1
  96. package/dist/esm/node/runtime/globalContext.d.ts +8 -4
  97. package/dist/esm/node/runtime/globalContext.js +22 -14
  98. package/dist/esm/node/runtime/index-common.d.ts +1 -0
  99. package/dist/esm/node/runtime/index-common.js +1 -0
  100. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
  101. package/dist/esm/node/runtime/renderPage.js +5 -3
  102. package/dist/esm/node/runtime/utils.d.ts +1 -2
  103. package/dist/esm/node/runtime/utils.js +1 -2
  104. package/dist/esm/node/runtime-dev/createDevMiddleware.d.ts +10 -0
  105. package/dist/esm/node/runtime-dev/createDevMiddleware.js +23 -0
  106. package/dist/esm/node/runtime-dev/index.d.ts +3 -0
  107. package/dist/esm/node/runtime-dev/index.js +6 -0
  108. package/dist/esm/node/shared/resolveBase.d.ts +11 -0
  109. package/dist/esm/node/shared/resolveBase.js +36 -0
  110. package/dist/esm/shared/page-configs/Config.d.ts +2 -2
  111. package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +1 -1
  112. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +1 -1
  113. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  114. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  115. package/dist/esm/utils/assertSetup.d.ts +20 -0
  116. package/dist/esm/utils/assertSetup.js +130 -0
  117. package/dist/esm/utils/isDocker.js +1 -1
  118. package/dist/esm/utils/projectInfo.d.ts +1 -1
  119. package/dist/esm/utils/requireResolve.js +1 -1
  120. package/package.json +1 -1
  121. package/dist/cjs/node/plugin/plugins/config/assertVikeConfig.js +0 -75
  122. package/dist/cjs/node/plugin/plugins/config/index.js +0 -81
  123. package/dist/cjs/node/plugin/plugins/config/pickFirst.js +0 -6
  124. package/dist/cjs/node/plugin/plugins/config/resolveBase.js +0 -47
  125. package/dist/cjs/node/shared/getConfigVike.js +0 -10
  126. package/dist/cjs/shared/ConfigVike.js +0 -2
  127. package/dist/cjs/utils/assertIsNotProductionRuntime.js +0 -62
  128. package/dist/cjs/utils/assertNodeEnv.js +0 -106
  129. package/dist/esm/node/api/prepareApiCall.d.ts +0 -7
  130. package/dist/esm/node/plugin/plugins/config/assertVikeConfig.d.ts +0 -7
  131. package/dist/esm/node/plugin/plugins/config/assertVikeConfig.js +0 -73
  132. package/dist/esm/node/plugin/plugins/config/index.d.ts +0 -3
  133. package/dist/esm/node/plugin/plugins/config/index.js +0 -76
  134. package/dist/esm/node/plugin/plugins/config/pickFirst.d.ts +0 -1
  135. package/dist/esm/node/plugin/plugins/config/pickFirst.js +0 -3
  136. package/dist/esm/node/plugin/plugins/config/resolveBase.d.ts +0 -10
  137. package/dist/esm/node/plugin/plugins/config/resolveBase.js +0 -42
  138. package/dist/esm/node/shared/getConfigVike.d.ts +0 -4
  139. package/dist/esm/node/shared/getConfigVike.js +0 -8
  140. package/dist/esm/shared/ConfigVike.js +0 -1
  141. package/dist/esm/utils/assertIsNotProductionRuntime.d.ts +0 -12
  142. package/dist/esm/utils/assertIsNotProductionRuntime.js +0 -59
  143. package/dist/esm/utils/assertNodeEnv.d.ts +0 -10
  144. package/dist/esm/utils/assertNodeEnv.js +0 -103
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getConfigValueBuildTime = getConfigValueBuildTime;
4
4
  const utils_js_1 = require("../utils.js");
5
- const assertIsNotProductionRuntime_js_1 = require("../../utils/assertIsNotProductionRuntime.js");
5
+ const assertSetup_js_1 = require("../../utils/assertSetup.js");
6
6
  const getConfigValueTyped_js_1 = require("./getConfigValueTyped.js");
7
- (0, assertIsNotProductionRuntime_js_1.assertIsNotProductionRuntime)();
7
+ (0, assertSetup_js_1.assertIsNotProductionRuntime)();
8
8
  function getConfigValueBuildTime(pageConfig, configName, type) {
9
9
  const configValue = getConfigValue(pageConfig, configName);
10
10
  if (!configValue)
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.serializeConfigValues = serializeConfigValues;
7
- const assertIsNotProductionRuntime_js_1 = require("../../../utils/assertIsNotProductionRuntime.js");
7
+ const assertSetup_js_1 = require("../../../utils/assertSetup.js");
8
8
  const utils_js_1 = require("../../../node/plugin/utils.js");
9
9
  const addImportStatement_js_1 = require("../../../node/plugin/plugins/importUserCode/addImportStatement.js");
10
10
  const transformPointerImports_js_1 = require("../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformPointerImports.js");
@@ -16,7 +16,7 @@ const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
16
16
  // This file is never loaded on the client-side but we save it under the vike/shared/ directory in order to collocate it with parsePageConfigs()
17
17
  // - vike/shared/page-configs/serialize/parsePageConfigs.ts
18
18
  // - parsePageConfigs() is loaded on both the client- and server-side.
19
- (0, assertIsNotProductionRuntime_js_1.assertIsNotProductionRuntime)();
19
+ (0, assertSetup_js_1.assertIsNotProductionRuntime)();
20
20
  function serializeConfigValues(pageConfig, importStatements, isEnvMatch, { isEager }, tabspace) {
21
21
  const lines = [];
22
22
  tabspace += ' ';
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.215';
5
+ exports.PROJECT_VERSION = '0.4.217-commit-99ea561';
@@ -0,0 +1,135 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.assertIsNotProductionRuntime = assertIsNotProductionRuntime;
7
+ exports.onSetupRuntime = onSetupRuntime;
8
+ exports.onSetupBuild = onSetupBuild;
9
+ exports.onSetupPrerender = onSetupPrerender;
10
+ exports.setNodeEnvProduction = setNodeEnvProduction;
11
+ exports.markSetup_viteDevServer = markSetup_viteDevServer;
12
+ exports.markSetup_vitePreviewServer = markSetup_vitePreviewServer;
13
+ exports.markSetup_vikeVitePlugin = markSetup_vikeVitePlugin;
14
+ exports.markSetup_isViteDev = markSetup_isViteDev;
15
+ exports.markSetup_isPrerendering = markSetup_isPrerendering;
16
+ const assert_js_1 = require("./assert.js");
17
+ const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
18
+ const debug_js_1 = require("./debug.js");
19
+ const getGlobalObject_js_1 = require("./getGlobalObject.js");
20
+ const isVitest_js_1 = require("./isVitest.js");
21
+ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
22
+ (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
23
+ const debug = (0, debug_js_1.createDebugger)('vike:setup');
24
+ const setup = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertIsNotProductionRuntime.ts', {});
25
+ // Called by Vike modules that want to ensure that they aren't loaded by the server runtime in production
26
+ function assertIsNotProductionRuntime() {
27
+ if (debug.isActivated)
28
+ debug('assertIsNotProductionRuntime()', new Error().stack);
29
+ setup.shouldNotBeProduction = true;
30
+ }
31
+ function onSetupRuntime() {
32
+ if (debug.isActivated)
33
+ debug('assertSetup()', new Error().stack);
34
+ if (isTest())
35
+ return;
36
+ if (!isViteLoaded()) {
37
+ // TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
38
+ (0, assert_js_1.assertWarning)(!isNodeEnvDev(), `The ${getEnvDescription()}, which seems contradictory because the environment seems to be a production environment (Vite isn't loaded), see https://vike.dev/NODE_ENV`, { onlyOnce: true });
39
+ (0, assert_js_1.assertUsage)(!setup.vikeVitePlugin, "Loading Vike's Vite plugin (the vike/plugin module) is prohibited in production.");
40
+ // This assert() one of the main goal of this file: it ensures assertIsNotProductionRuntime()
41
+ (0, assert_js_1.assert)(!setup.shouldNotBeProduction);
42
+ }
43
+ else {
44
+ // TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
45
+ (0, assert_js_1.assertWarning)(isNodeEnvDev() || setup.vitePreviewServer || setup.isPrerendering, `The ${getEnvDescription()}, but Vite is loaded which is prohibited in production, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
46
+ // These two assert() calls aren't that interesting
47
+ (0, assert_js_1.assert)(setup.vikeVitePlugin);
48
+ (0, assert_js_1.assert)(setup.shouldNotBeProduction);
49
+ }
50
+ }
51
+ // Ensure NODE_ENV is 'production' when building.
52
+ // - Used by both Vue and React for bundling minified version:
53
+ // - Vue: https://github.com/vuejs/core/blob/f66a75ea75c8aece065b61e2126b4c5b2338aa6e/packages/vue/index.js
54
+ // - React: https://github.com/facebook/react/blob/01ab35a9a731dec69995fbd28f3ac7eaad11e183/packages/react/npm/index.js
55
+ // - Required for React: setting NODE_ENV to a value other than 'production' triggers an error: https://github.com/vikejs/vike/issues/1469#issuecomment-1969301797
56
+ // - Not required for Vue: when building the app, NODE_ENV can be set to a value other than 'production', e.g. 'development'.
57
+ function onSetupBuild() {
58
+ assertUsageNodeEnvIsNotDev('building');
59
+ /* Not needed: Vite already sets `process.env.NODE_ENV = 'production'`
60
+ setNodeEnvProduction()
61
+ */
62
+ }
63
+ function onSetupPrerender() {
64
+ markSetup_isPrerendering();
65
+ if (getNodeEnvValue())
66
+ assertUsageNodeEnvIsNotDev('pre-rendering');
67
+ setNodeEnvProduction();
68
+ }
69
+ function isViteLoaded() {
70
+ // Do we need setup.viteDevServer or setup.vitePreviewServer ?
71
+ return setup.viteDevServer || setup.vitePreviewServer || setup.isViteDev !== undefined;
72
+ }
73
+ function isTest() {
74
+ return (0, isVitest_js_1.isVitest)() || getNodeEnvValue() === 'test';
75
+ }
76
+ // Called by Vite hook configureServer()
77
+ function markSetup_viteDevServer() {
78
+ if (debug.isActivated)
79
+ debug('markSetup_viteDevServer()', new Error().stack);
80
+ setup.viteDevServer = true;
81
+ }
82
+ // Called by Vite hook configurePreviewServer()
83
+ function markSetup_vitePreviewServer() {
84
+ if (debug.isActivated)
85
+ debug('markSetup_vitePreviewServer()', new Error().stack);
86
+ setup.vitePreviewServer = true;
87
+ }
88
+ // Called by ../node/plugin/index.ts
89
+ function markSetup_vikeVitePlugin() {
90
+ if (debug.isActivated)
91
+ debug('markSetup_vikeVitePlugin()', new Error().stack);
92
+ setup.vikeVitePlugin = true;
93
+ }
94
+ // Whether Vite is loaded and whether it's in dev mode (the value returned by `isDevCheck()`)
95
+ function markSetup_isViteDev(isViteDev) {
96
+ if (debug.isActivated)
97
+ debug('markSetup_isViteDev()', new Error().stack);
98
+ setup.isViteDev = isViteDev;
99
+ }
100
+ // Called by ../node/prerender/runPrerender.ts
101
+ function markSetup_isPrerendering() {
102
+ if (debug.isActivated)
103
+ debug('markSetup_isPrerendering()', new Error().stack);
104
+ setup.isPrerendering = true;
105
+ }
106
+ function assertUsageNodeEnvIsNotDev(operation) {
107
+ if (!isNodeEnvDev())
108
+ return;
109
+ // TODO: make it assertUsage() again once https://github.com/vikejs/vike/issues/1528 is implemented.
110
+ (0, assert_js_1.assertWarning)(false, `The ${getEnvDescription()} which is forbidden upon ${operation}, see https://vike.dev/NODE_ENV`, { onlyOnce: true });
111
+ }
112
+ function getEnvDescription() {
113
+ const nodeEnv = getNodeEnvValue();
114
+ const isDev = isNodeEnvDev();
115
+ const envType = `${(isDev ? 'development' : 'production')} environment`;
116
+ const nodeEnvDesc = `environment is set to be a ${picocolors_1.default.bold(envType)} by ${picocolors_1.default.cyan(`process.env.NODE_ENV===${JSON.stringify(nodeEnv)}`)}`;
117
+ return nodeEnvDesc;
118
+ }
119
+ function isNodeEnvDev() {
120
+ const nodeEnv = getNodeEnvValue();
121
+ // That's quite strict, let's see if some user complains
122
+ return !nodeEnv || ['development', 'dev'].includes(nodeEnv);
123
+ }
124
+ function getNodeEnvValue() {
125
+ if (typeof process === 'undefined')
126
+ return null;
127
+ return process.env.NODE_ENV?.toLowerCase();
128
+ }
129
+ function setNodeEnvProduction() {
130
+ // The statement `process.env['NODE_ENV'] = 'production'` chokes webpack v4
131
+ const proc = process;
132
+ const { env } = proc;
133
+ env.NODE_ENV = 'production';
134
+ (0, assert_js_1.assert)(getNodeEnvValue() === 'production');
135
+ }
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.isDocker = isDocker;
7
7
  const node_fs_1 = __importDefault(require("node:fs"));
8
- const assertIsNotProductionRuntime_js_1 = require("./assertIsNotProductionRuntime.js");
9
- (0, assertIsNotProductionRuntime_js_1.assertIsNotProductionRuntime)();
8
+ const assertSetup_js_1 = require("./assertSetup.js");
9
+ (0, assertSetup_js_1.assertIsNotProductionRuntime)();
10
10
  function isDocker() {
11
11
  return hasContainerEnv() || isDockerContainer();
12
12
  }
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.requireResolve = requireResolve;
4
4
  const assert_js_1 = require("./assert.js");
5
5
  const assertIsNotBrowser_js_1 = require("./assertIsNotBrowser.js");
6
- const assertIsNotProductionRuntime_js_1 = require("./assertIsNotProductionRuntime.js");
6
+ const assertSetup_js_1 = require("./assertSetup.js");
7
7
  const filesystemPathHandling_js_1 = require("./filesystemPathHandling.js");
8
8
  const isScriptFile_js_1 = require("./isScriptFile.js");
9
9
  const module_1 = require("module");
@@ -11,7 +11,7 @@ const module_1 = require("module");
11
11
  const importMetaUrl = `file://${__filename}`;
12
12
  const require_ = (0, module_1.createRequire)(importMetaUrl);
13
13
  (0, assertIsNotBrowser_js_1.assertIsNotBrowser)();
14
- (0, assertIsNotProductionRuntime_js_1.assertIsNotProductionRuntime)();
14
+ (0, assertSetup_js_1.assertIsNotProductionRuntime)();
15
15
  // We still can't use import.meta.resolve() as of 23.1.0 (November 2024) because `parent` argument requires an experimental flag.
16
16
  // - https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment139581675_62272600
17
17
  function requireResolve(importPath, cwd) {
@@ -5,7 +5,7 @@ export { getMiddlewares };
5
5
  import { route as routeInternal } from '../shared/route/index.js';
6
6
  import { getPageFilesAll } from '../shared/getPageFiles.js';
7
7
  import { getGlobalContext, initGlobalContext_getGlobalContextAsync } from '../node/runtime/globalContext.js';
8
- import { handleNodeEnv_vitePluginVercel } from '../utils/assertNodeEnv.js';
8
+ import { setNodeEnvProduction } from '../utils/assertSetup.js';
9
9
  import { getRenderContext } from '../node/runtime/renderPage/renderPageAlreadyRouted.js';
10
10
  /**
11
11
  * Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel}
@@ -14,7 +14,7 @@ import { getRenderContext } from '../node/runtime/renderPage/renderPageAlreadyRo
14
14
  * @param config
15
15
  */
16
16
  async function getPagesAndRoutes() {
17
- handleNodeEnv_vitePluginVercel();
17
+ setNodeEnvProduction();
18
18
  const renderContext = await getRenderContext();
19
19
  const {
20
20
  //
@@ -2,6 +2,11 @@ export { build };
2
2
  import { type Rollup } from 'vite';
3
3
  import type { APIOptions } from './types.js';
4
4
  type RollupOutput = Rollup.RollupOutput | Rollup.RollupOutput[] | Rollup.RollupWatcher;
5
+ /**
6
+ * Programmatically trigger `$ vike build`
7
+ *
8
+ * https://vike.dev/api#build
9
+ */
5
10
  declare function build(options?: APIOptions): Promise<{
6
11
  rollupOutputClient: RollupOutput;
7
12
  rollupOutputServer: RollupOutput;
@@ -1,14 +1,21 @@
1
1
  export { build };
2
- import { prepareApiCall } from './prepareApiCall.js';
2
+ import { prepareViteApiCall } from './prepareViteApiCall.js';
3
3
  import { build as buildVite } from 'vite';
4
+ /**
5
+ * Programmatically trigger `$ vike build`
6
+ *
7
+ * https://vike.dev/api#build
8
+ */
4
9
  async function build(options = {}) {
5
- const { viteConfigEnhanced, configVike } = await prepareApiCall(options.viteConfig, 'build');
10
+ const { viteConfigEnhanced, vikeConfigGlobal } = await prepareViteApiCall(options.viteConfig, 'build');
6
11
  // Build client-side
7
12
  const outputClient = await buildVite(viteConfigEnhanced);
8
13
  // Build server-side
9
14
  const outputServer = await buildVite(setSSR(viteConfigEnhanced));
10
15
  // Pre-render
11
- if (configVike.prerender && !configVike.prerender.disableAutoRun && configVike.disableAutoFullBuild !== 'prerender') {
16
+ if (vikeConfigGlobal.prerender &&
17
+ !vikeConfigGlobal.prerender.disableAutoRun &&
18
+ vikeConfigGlobal.disableAutoFullBuild !== 'prerender') {
12
19
  const { runPrerenderFromAutoRun } = await import('../prerender/runPrerender.js');
13
20
  await runPrerenderFromAutoRun(viteConfigEnhanced, true);
14
21
  }
@@ -1,17 +1,19 @@
1
1
  export { isVikeCliOrApi };
2
2
  // export { getOperation }
3
3
  export { setOperation as setOperation };
4
- import { assert } from './utils.js';
5
- let apiOperation;
4
+ import { assert, getGlobalObject } from './utils.js';
5
+ const globalObject = getGlobalObject('context.ts', {
6
+ apiOperation: undefined
7
+ });
6
8
  function getOperation() {
7
- assert(apiOperation);
8
- return apiOperation;
9
+ assert(globalObject.apiOperation);
10
+ return globalObject.apiOperation;
9
11
  }
10
12
  function isVikeCliOrApi() {
11
13
  // The CLI uses the API
12
- return !!apiOperation;
14
+ return !!globalObject.apiOperation;
13
15
  }
14
16
  function setOperation(operation) {
15
- assert(!apiOperation);
16
- apiOperation = operation;
17
+ assert(!globalObject.apiOperation);
18
+ globalObject.apiOperation = operation;
17
19
  }
@@ -1,6 +1,11 @@
1
1
  export { dev };
2
2
  import { type ResolvedConfig, type ViteDevServer } from 'vite';
3
3
  import type { APIOptions } from './types.js';
4
+ /**
5
+ * Programmatically trigger `$ vike dev`
6
+ *
7
+ * https://vike.dev/api#dev
8
+ */
4
9
  declare function dev(options?: APIOptions): Promise<{
5
10
  viteServer: ViteDevServer;
6
11
  viteConfig: ResolvedConfig;
@@ -1,8 +1,13 @@
1
1
  export { dev };
2
- import { prepareApiCall } from './prepareApiCall.js';
2
+ import { prepareViteApiCall } from './prepareViteApiCall.js';
3
3
  import { createServer } from 'vite';
4
+ /**
5
+ * Programmatically trigger `$ vike dev`
6
+ *
7
+ * https://vike.dev/api#dev
8
+ */
4
9
  async function dev(options = {}) {
5
- const { viteConfigEnhanced } = await prepareApiCall(options.viteConfig, 'dev');
10
+ const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'dev');
6
11
  const server = await createServer(viteConfigEnhanced);
7
12
  return {
8
13
  viteServer: server,
@@ -0,0 +1,7 @@
1
+ export { prepareViteApiCall };
2
+ import type { InlineConfig } from 'vite';
3
+ import type { Operation } from './types.js';
4
+ declare function prepareViteApiCall(viteConfig: InlineConfig | undefined, operation: Operation): Promise<{
5
+ viteConfigEnhanced: InlineConfig;
6
+ vikeConfigGlobal: import("../plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js").VikeConfigGlobal;
7
+ }>;
@@ -1,9 +1,9 @@
1
- export { prepareApiCall };
1
+ export { prepareViteApiCall };
2
2
  import { resolveConfig } from 'vite';
3
- import { getConfigVike } from '../shared/getConfigVike.js';
4
3
  import { pluginName } from '../plugin/plugins/commonConfig/pluginName.js';
5
4
  import { setOperation } from './context.js';
6
- async function prepareApiCall(viteConfig = {}, operation) {
5
+ import { getVikeConfig2 } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
6
+ async function prepareViteApiCall(viteConfig = {}, operation) {
7
7
  setOperation(operation);
8
8
  return enhanceViteConfig(viteConfig, operation);
9
9
  }
@@ -20,13 +20,23 @@ async function enhanceViteConfig(viteConfig = {}, operation) {
20
20
  };
21
21
  viteConfigResolved = await resolveViteConfig(viteConfigEnhanced, operation);
22
22
  }
23
- const configVike = await getConfigVike(viteConfigResolved);
23
+ // TODO: use loadConfigFromFile() instead of viteConfigResolved
24
+ const { vikeConfigGlobal } = await getVikeConfig2(viteConfigResolved.root, operation === 'dev', viteConfigResolved._vikeVitePluginOptions);
24
25
  // TODO: enable Vike extensions to add Vite plugins
25
26
  return {
26
27
  viteConfigEnhanced,
27
- configVike
28
+ vikeConfigGlobal
28
29
  };
29
30
  }
30
31
  async function resolveViteConfig(viteConfig, operation) {
31
- return await resolveConfig(viteConfig, operation === 'build' || operation === 'prerender' ? 'build' : 'serve', 'custom', operation === 'dev' ? 'development' : 'production', operation === 'preview');
32
+ const args = getResolveConfigArgs(viteConfig, operation);
33
+ return await resolveConfig(...args);
34
+ }
35
+ function getResolveConfigArgs(viteConfig, operation) {
36
+ const inlineConfig = viteConfig;
37
+ const command = operation === 'build' || operation === 'prerender' ? 'build' : 'serve';
38
+ const defaultMode = operation === 'dev' ? 'development' : 'production';
39
+ const defaultNodeEnv = defaultMode;
40
+ const isPreview = operation === 'preview';
41
+ return [inlineConfig, command, defaultMode, defaultNodeEnv, isPreview];
32
42
  }
@@ -1,6 +1,11 @@
1
1
  export { prerender };
2
2
  import { type PrerenderOptions } from '../prerender/runPrerender.js';
3
3
  import type { ResolvedConfig } from 'vite';
4
+ /**
5
+ * Programmatically trigger `$ vike prerender`
6
+ *
7
+ * https://vike.dev/api#prerender
8
+ */
4
9
  declare function prerender(options?: PrerenderOptions): Promise<{
5
10
  viteConfig: ResolvedConfig;
6
11
  }>;
@@ -1,8 +1,13 @@
1
1
  export { prerender };
2
2
  import { runPrerenderFromAPI } from '../prerender/runPrerender.js';
3
- import { prepareApiCall } from './prepareApiCall.js';
3
+ import { prepareViteApiCall } from './prepareViteApiCall.js';
4
+ /**
5
+ * Programmatically trigger `$ vike prerender`
6
+ *
7
+ * https://vike.dev/api#prerender
8
+ */
4
9
  async function prerender(options = {}) {
5
- const { viteConfigEnhanced } = await prepareApiCall(options.viteConfig, 'prerender');
10
+ const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'prerender');
6
11
  options.viteConfig = viteConfigEnhanced;
7
12
  const { viteConfig } = await runPrerenderFromAPI(options);
8
13
  return {
@@ -1,6 +1,11 @@
1
1
  export { preview };
2
2
  import { type ResolvedConfig, type PreviewServer } from 'vite';
3
3
  import type { APIOptions } from './types.js';
4
+ /**
5
+ * Programmatically trigger `$ vike preview`
6
+ *
7
+ * https://vike.dev/api#preview
8
+ */
4
9
  declare function preview(options?: APIOptions): Promise<{
5
10
  viteServer: PreviewServer;
6
11
  viteConfig: ResolvedConfig;
@@ -1,8 +1,13 @@
1
1
  export { preview };
2
- import { prepareApiCall } from './prepareApiCall.js';
2
+ import { prepareViteApiCall } from './prepareViteApiCall.js';
3
3
  import { preview as previewVite } from 'vite';
4
+ /**
5
+ * Programmatically trigger `$ vike preview`
6
+ *
7
+ * https://vike.dev/api#preview
8
+ */
4
9
  async function preview(options = {}) {
5
- const { viteConfigEnhanced } = await prepareApiCall(options.viteConfig, 'preview');
10
+ const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'preview');
6
11
  const server = await previewVite(viteConfigEnhanced);
7
12
  return {
8
13
  viteServer: server,
@@ -1 +1,2 @@
1
1
  export * from '../../utils/assert.js';
2
+ export * from '../../utils/getGlobalObject.js';
@@ -3,3 +3,4 @@
3
3
  import { onLoad } from './onLoad.js';
4
4
  onLoad();
5
5
  export * from '../../utils/assert.js';
6
+ export * from '../../utils/getGlobalObject.js';
@@ -1,4 +1,4 @@
1
1
  export { parseCli };
2
2
  declare function parseCli(): {
3
- command: "build" | "dev" | "preview" | "prerender";
3
+ command: "dev" | "build" | "preview" | "prerender";
4
4
  };
@@ -1,7 +1,7 @@
1
1
  export default plugin;
2
2
  export { plugin };
3
3
  export { plugin as ssr };
4
- export type { ConfigVikeUserProvided as UserConfig };
4
+ export type { VikeVitePluginOptions as UserConfig };
5
5
  export { PROJECT_VERSION as version } from './utils.js';
6
- import type { ConfigVikeUserProvided } from '../../shared/ConfigVike.js';
7
- declare function plugin(vikeConfig?: ConfigVikeUserProvided): any;
6
+ import type { VikeVitePluginOptions } from './plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js';
7
+ declare function plugin(vikeVitePluginOptions?: VikeVitePluginOptions): any;
@@ -4,7 +4,7 @@ export { plugin };
4
4
  export { plugin as ssr };
5
5
  export { PROJECT_VERSION as version } from './utils.js';
6
6
  import { version } from 'vite';
7
- import { assertNodeEnv_onVikePluginLoad, assertUsage, assertVersion, markEnvAsVikePluginLoaded } from './utils.js';
7
+ import { assertUsage, assertVersion, markSetup_vikeVitePlugin } from './utils.js';
8
8
  import { buildConfig } from './plugins/buildConfig.js';
9
9
  import { previewConfig } from './plugins/previewConfig.js';
10
10
  import { autoFullBuild } from './plugins/autoFullBuild.js';
@@ -12,7 +12,6 @@ import { devConfig } from './plugins/devConfig/index.js';
12
12
  import { packageJsonFile } from './plugins/packageJsonFile.js';
13
13
  import { removeRequireHookPlugin } from './plugins/removeRequireHookPlugin.js';
14
14
  import { importUserCode } from './plugins/importUserCode/index.js';
15
- import { resolveVikeConfig } from './plugins/config/index.js';
16
15
  import { distFileNames } from './plugins/distFileNames.js';
17
16
  import { extractAssetsPlugin } from './plugins/extractAssetsPlugin.js';
18
17
  import { extractExportNamesPlugin } from './plugins/extractExportNamesPlugin.js';
@@ -28,15 +27,13 @@ import { setResolveClientEntriesDev } from '../runtime/renderPage/getPageAssets.
28
27
  import { resolveClientEntriesDev } from './resolveClientEntriesDev.js';
29
28
  import { workaroundCssModuleHmr } from './plugins/workaroundCssModuleHmr.js';
30
29
  import { vite6HmrRegressionWorkaround } from './plugins/vite6HmrRegressionWorkaround.js';
31
- assertNodeEnv_onVikePluginLoad();
32
- markEnvAsVikePluginLoaded();
30
+ markSetup_vikeVitePlugin();
33
31
  assertViteVersion();
34
32
  setResolveClientEntriesDev(resolveClientEntriesDev);
35
33
  // Return as `any` to avoid Plugin type mismatches when there are multiple Vite versions installed
36
- function plugin(vikeConfig) {
34
+ function plugin(vikeVitePluginOptions) {
37
35
  const plugins = [
38
- resolveVikeConfig(vikeConfig), // The configResolved() hook of resolveVikeConfig() should be the first called
39
- ...commonConfig(),
36
+ ...commonConfig(vikeVitePluginOptions),
40
37
  importUserCode(),
41
38
  ...devConfig(),
42
39
  ...buildConfig(),
@@ -48,9 +45,9 @@ function plugin(vikeConfig) {
48
45
  ...extractAssetsPlugin(),
49
46
  extractExportNamesPlugin(),
50
47
  suppressRollupWarning(),
51
- setGlobalContext(),
48
+ ...setGlobalContext(),
52
49
  ...importBuild(),
53
- baseUrls(vikeConfig),
50
+ baseUrls(vikeVitePluginOptions),
54
51
  envVarsPlugin(),
55
52
  fileEnv(),
56
53
  workaroundCssModuleHmr(),
@@ -1,6 +1,6 @@
1
1
  export { onLoad };
2
2
  import { assertIsNotBrowser } from '../../utils/assertIsNotBrowser.js';
3
- import { assertIsNotProductionRuntime } from '../../utils/assertIsNotProductionRuntime.js';
3
+ import { assertIsNotProductionRuntime } from '../../utils/assertSetup.js';
4
4
  import { assertNodeVersion } from '../../utils/assertNodeVersion.js';
5
5
  function onLoad() {
6
6
  assertIsNotBrowser();
@@ -3,24 +3,25 @@ export { autoFullBuild };
3
3
  import { build } from 'vite';
4
4
  import { assertWarning } from '../utils.js';
5
5
  import { runPrerenderFromAutoRun, runPrerender_forceExit } from '../../prerender/runPrerender.js';
6
- import { getConfigVike } from '../../shared/getConfigVike.js';
7
6
  import { isViteCliCall, getViteConfigFromCli } from '../shared/isViteCliCall.js';
8
7
  import pc from '@brillout/picocolors';
9
8
  import { logErrorHint } from '../../runtime/renderPage/logErrorHint.js';
10
9
  import { manifestTempFile } from './buildConfig.js';
10
+ import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
11
11
  let forceExit = false;
12
12
  function autoFullBuild() {
13
13
  let config;
14
- let configVike;
14
+ let vikeConfigGlobal;
15
15
  return [
16
16
  {
17
17
  name: 'vike:autoFullBuild',
18
18
  apply: 'build',
19
19
  enforce: 'pre',
20
20
  async configResolved(config_) {
21
- configVike = await getConfigVike(config_);
21
+ const vikeConfig = await getVikeConfig(config_);
22
+ vikeConfigGlobal = vikeConfig.vikeConfigGlobal;
22
23
  config = config_;
23
- abortViteBuildSsr(configVike);
24
+ abortViteBuildSsr(vikeConfigGlobal);
24
25
  },
25
26
  writeBundle: {
26
27
  /* We can't use this because it breaks Vite's logging. TODO: try again with latest Vite version.
@@ -29,7 +30,7 @@ function autoFullBuild() {
29
30
  */
30
31
  async handler(_options, bundle) {
31
32
  try {
32
- await triggerFullBuild(config, configVike, bundle);
33
+ await triggerFullBuild(config, vikeConfigGlobal, bundle);
33
34
  }
34
35
  catch (err) {
35
36
  // Avoid Rollup prefixing the error with [vike:autoFullBuild], for example see https://github.com/vikejs/vike/issues/472#issuecomment-1276274203
@@ -55,10 +56,10 @@ function autoFullBuild() {
55
56
  }
56
57
  ];
57
58
  }
58
- async function triggerFullBuild(config, configVike, bundle) {
59
+ async function triggerFullBuild(config, vikeConfigGlobal, bundle) {
59
60
  if (config.build.ssr)
60
61
  return; // already triggered
61
- if (isDisabled(configVike))
62
+ if (isDisabled(vikeConfigGlobal))
62
63
  return;
63
64
  // Workaround for @vitejs/plugin-legacy
64
65
  // - The legacy plugin triggers its own Rollup build for the client-side.
@@ -89,19 +90,21 @@ async function triggerFullBuild(config, configVike, bundle) {
89
90
  logErrorHint(err);
90
91
  process.exit(1);
91
92
  }
92
- if (configVike.prerender && !configVike.prerender.disableAutoRun && configVike.disableAutoFullBuild !== 'prerender') {
93
+ if (vikeConfigGlobal.prerender &&
94
+ !vikeConfigGlobal.prerender.disableAutoRun &&
95
+ vikeConfigGlobal.disableAutoFullBuild !== 'prerender') {
93
96
  await runPrerenderFromAutoRun(configInline, false);
94
97
  forceExit = true;
95
98
  }
96
99
  }
97
- function abortViteBuildSsr(configVike) {
98
- if (configVike.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
100
+ function abortViteBuildSsr(vikeConfigGlobal) {
101
+ if (vikeConfigGlobal.disableAutoFullBuild !== true && isViteCliCall() && getViteConfigFromCli()?.build.ssr) {
99
102
  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 });
100
103
  process.exit(0);
101
104
  }
102
105
  }
103
- function isDisabled(configVike) {
104
- const { disableAutoFullBuild } = configVike;
106
+ function isDisabled(vikeConfigGlobal) {
107
+ const { disableAutoFullBuild } = vikeConfigGlobal;
105
108
  if (disableAutoFullBuild === null || disableAutoFullBuild === 'prerender') {
106
109
  return !isViteCliCall();
107
110
  }
@@ -1,4 +1,4 @@
1
1
  export { baseUrls };
2
2
  import type { Plugin } from 'vite';
3
- import type { ConfigVikeUserProvided } from '../../../shared/ConfigVike.js';
4
- declare function baseUrls(configVike?: ConfigVikeUserProvided): Plugin;
3
+ import type { VikeVitePluginOptions } from './importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js';
4
+ declare function baseUrls(vikeVitePluginOptions?: VikeVitePluginOptions): Plugin;