vike 0.4.224 → 0.4.225-commit-37a36a5

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 (139) hide show
  1. package/dist/cjs/node/api/build.js +1 -1
  2. package/dist/cjs/node/api/context.js +4 -4
  3. package/dist/cjs/node/api/dev.js +1 -1
  4. package/dist/cjs/node/api/prepareViteApiCall.js +3 -2
  5. package/dist/cjs/node/api/prerender.js +1 -1
  6. package/dist/cjs/node/api/preview.js +1 -1
  7. package/dist/cjs/node/cli/context.js +5 -4
  8. package/dist/cjs/node/cli/entry.js +3 -3
  9. package/dist/cjs/node/cli/parseCli.js +43 -15
  10. package/dist/cjs/node/cli/utils.js +1 -1
  11. package/dist/cjs/node/plugin/plugins/build/pluginBuildEntry.js +1 -1
  12. package/dist/cjs/node/plugin/plugins/commonConfig.js +16 -5
  13. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +6 -4
  14. package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -1
  15. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +14 -10
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -2
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -12
  18. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +138 -83
  19. package/dist/cjs/node/plugin/plugins/previewConfig.js +12 -7
  20. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +10 -1
  21. package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +5 -1
  22. package/dist/cjs/node/plugin/shared/getEnvVarObject.js +9 -8
  23. package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +1 -1
  24. package/dist/cjs/node/prerender/context.js +1 -1
  25. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +33 -18
  26. package/dist/cjs/node/prerender/runPrerender.js +6 -8
  27. package/dist/cjs/node/prerender/utils.js +1 -1
  28. package/dist/cjs/node/runtime/globalContext.js +9 -5
  29. package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +6 -3
  30. package/dist/cjs/node/runtime/html/stream.js +7 -0
  31. package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +14 -5
  32. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +2 -4
  33. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +6 -1
  34. package/dist/cjs/node/runtime/renderPage.js +6 -10
  35. package/dist/cjs/node/runtime/utils.js +0 -1
  36. package/dist/cjs/node/runtime-dev/createDevMiddleware.js +10 -8
  37. package/dist/cjs/node/shared/assertV1Design.js +2 -1
  38. package/dist/cjs/node/shared/utils.js +0 -1
  39. package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +19 -2
  40. package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +8 -5
  41. package/dist/cjs/shared/page-configs/helpers.js +1 -1
  42. package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -5
  43. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +9 -5
  44. package/dist/cjs/shared/route/loadPageRoutes.js +2 -2
  45. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  46. package/dist/cjs/utils/assert.js +11 -4
  47. package/dist/cjs/utils/assertSingleInstance.js +11 -17
  48. package/dist/cjs/utils/debug.js +2 -1
  49. package/dist/cjs/utils/getRandomId.js +1 -1
  50. package/dist/cjs/utils/normalizeHeaders.js +1 -1
  51. package/dist/cjs/utils/parseUrl-extras.js +1 -0
  52. package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +1 -1
  53. package/dist/esm/client/client-routing-runtime/createPageContext.js +2 -2
  54. package/dist/esm/node/api/build.js +1 -1
  55. package/dist/esm/node/api/context.d.ts +8 -2
  56. package/dist/esm/node/api/context.js +4 -4
  57. package/dist/esm/node/api/dev.js +1 -1
  58. package/dist/esm/node/api/prepareViteApiCall.d.ts +2 -2
  59. package/dist/esm/node/api/prepareViteApiCall.js +3 -2
  60. package/dist/esm/node/api/prerender.js +1 -1
  61. package/dist/esm/node/api/preview.js +1 -1
  62. package/dist/esm/node/api/types.d.ts +7 -0
  63. package/dist/esm/node/cli/context.d.ts +4 -2
  64. package/dist/esm/node/cli/context.js +5 -4
  65. package/dist/esm/node/cli/entry.js +4 -4
  66. package/dist/esm/node/cli/parseCli.d.ts +3 -0
  67. package/dist/esm/node/cli/parseCli.js +44 -16
  68. package/dist/esm/node/cli/utils.d.ts +1 -1
  69. package/dist/esm/node/cli/utils.js +1 -1
  70. package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.js +2 -2
  71. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +1 -0
  72. package/dist/esm/node/plugin/plugins/commonConfig.js +16 -5
  73. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +6 -4
  74. package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -1
  75. package/dist/esm/node/plugin/plugins/importUserCode/index.js +15 -11
  76. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +3 -1
  77. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -2
  78. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +5 -2
  79. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -12
  80. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
  81. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +140 -84
  82. package/dist/esm/node/plugin/plugins/previewConfig.js +12 -7
  83. package/dist/esm/node/plugin/plugins/setGlobalContext.js +11 -2
  84. package/dist/esm/node/plugin/shared/addSsrMiddleware.d.ts +1 -1
  85. package/dist/esm/node/plugin/shared/addSsrMiddleware.js +5 -1
  86. package/dist/esm/node/plugin/shared/getEnvVarObject.d.ts +3 -1
  87. package/dist/esm/node/plugin/shared/getEnvVarObject.js +9 -8
  88. package/dist/esm/node/plugin/shared/loggerNotProd/log.js +2 -2
  89. package/dist/esm/node/prerender/context.js +1 -1
  90. package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +2 -1
  91. package/dist/esm/node/prerender/resolvePrerenderConfig.js +34 -19
  92. package/dist/esm/node/prerender/runPrerender.js +7 -9
  93. package/dist/esm/node/prerender/utils.d.ts +1 -1
  94. package/dist/esm/node/prerender/utils.js +1 -1
  95. package/dist/esm/node/runtime/globalContext.d.ts +1 -1
  96. package/dist/esm/node/runtime/globalContext.js +10 -6
  97. package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +6 -3
  98. package/dist/esm/node/runtime/html/stream.js +7 -0
  99. package/dist/esm/node/runtime/index-deprecated.d.ts +1 -3
  100. package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.d.ts +3 -1
  101. package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +15 -6
  102. package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +3 -1
  103. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +2 -4
  104. package/dist/esm/node/runtime/renderPage/logErrorHint.js +6 -1
  105. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +5 -5
  106. package/dist/esm/node/runtime/renderPage.js +7 -11
  107. package/dist/esm/node/runtime/utils.d.ts +0 -1
  108. package/dist/esm/node/runtime/utils.js +0 -1
  109. package/dist/esm/node/runtime-dev/createDevMiddleware.js +10 -8
  110. package/dist/esm/node/shared/assertV1Design.js +2 -1
  111. package/dist/esm/node/shared/utils.d.ts +0 -1
  112. package/dist/esm/node/shared/utils.js +0 -1
  113. package/dist/esm/shared/page-configs/Config.d.ts +19 -1
  114. package/dist/esm/shared/page-configs/PageConfig.d.ts +16 -5
  115. package/dist/esm/shared/page-configs/getConfigDefinedAt.d.ts +5 -3
  116. package/dist/esm/shared/page-configs/getConfigDefinedAt.js +20 -3
  117. package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +8 -5
  118. package/dist/esm/shared/page-configs/helpers.js +1 -1
  119. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +1 -1
  120. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -5
  121. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -3
  122. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +9 -5
  123. package/dist/esm/shared/route/loadPageRoutes.js +2 -2
  124. package/dist/esm/shared/types.d.ts +5 -1
  125. package/dist/esm/types/index.d.ts +2 -0
  126. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  127. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  128. package/dist/esm/utils/assert.d.ts +2 -1
  129. package/dist/esm/utils/assert.js +11 -4
  130. package/dist/esm/utils/assertSingleInstance.js +11 -17
  131. package/dist/esm/utils/debug.js +2 -1
  132. package/dist/esm/utils/getRandomId.d.ts +1 -1
  133. package/dist/esm/utils/getRandomId.js +1 -1
  134. package/dist/esm/utils/normalizeHeaders.js +1 -1
  135. package/dist/esm/utils/parseUrl-extras.js +1 -0
  136. package/package.json +6 -3
  137. package/dist/cjs/utils/projectInfo.js +0 -8
  138. package/dist/esm/utils/projectInfo.d.ts +0 -4
  139. package/dist/esm/utils/projectInfo.js +0 -5
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.assertSingleInstance_onClientEntryServerRouting = assertSingleInstance_onClientEntryServerRouting;
7
7
  exports.assertSingleInstance_onClientEntryClientRouting = assertSingleInstance_onClientEntryClientRouting;
8
8
  exports.assertSingleInstance_onAssertModuleLoad = assertSingleInstance_onAssertModuleLoad;
9
- // - Throw error if there are two different versions of vike loaded
9
+ // - Show warning if there are two different Vike versions loaded
10
10
  // - Show warning if entry of Client Routing and entry of Server Routing are both loaded
11
- // - Show warning if vike is loaded twice
11
+ // - Show warning if Vike is loaded twice
12
12
  const unique_js_1 = require("./unique.js");
13
13
  const getGlobalObject_js_1 = require("./getGlobalObject.js");
14
- const projectInfo_js_1 = require("./projectInfo.js");
15
14
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
16
- /* Use original assertUsage() & assertWarning() after all CJS is removed from node_modules/vike/dist/
17
- import { assertUsage, assertWarning } from './assert.js'
15
+ const PROJECT_VERSION_js_1 = require("./PROJECT_VERSION.js");
16
+ /* Use original assertWarning() after all CJS is removed from node_modules/vike/dist/
17
+ import { assertWarning } from './assert.js'
18
18
  */
19
19
  const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/assertSingleInstance.ts', {
20
20
  instances: [],
@@ -25,9 +25,10 @@ const clientNotSingleInstance = 'Client runtime loaded twice https://vike.dev/cl
25
25
  function assertSingleInstance() {
26
26
  {
27
27
  const versions = (0, unique_js_1.unique)(globalObject.instances);
28
- assertUsage(versions.length <= 1,
29
- // DO *NOT* patch vike to remove this error: because of multiple conflicting versions, you *will* eventually encounter insidious issues that hard to debug and potentially a security hazard, see for example https://github.com/vikejs/vike/issues/1108
30
- `vike@${picocolors_1.default.bold(versions[0])} and vike@${picocolors_1.default.bold(versions[1])} loaded but it's forbidden to load different versions`);
28
+ assertWarning(versions.length <= 1,
29
+ // Do *NOT* patch Vike to remove this warning: you *will* eventually encounter the issues listed at https://vike.dev/warning/version-mismatch
30
+ // - This happened before: https://github.com/vikejs/vike/issues/1108#issuecomment-1719061509
31
+ `vike@${picocolors_1.default.bold(versions[0])} and vike@${picocolors_1.default.bold(versions[1])} loaded which is highly discouraged, see ${picocolors_1.default.underline('https://vike.dev/warning/version-mismatch')}`, { onlyOnce: true, showStackTrace: false });
31
32
  }
32
33
  if (globalObject.checkSingleInstance && globalObject.instances.length > 1) {
33
34
  /*/ Not sure whether circular dependency can cause problems? In principle not since client-side code is ESM.
@@ -67,21 +68,14 @@ function assertSingleInstance_onClientEntryClientRouting(isProduction) {
67
68
  }
68
69
  // Called by utils/assert.ts which is (most certainly) loaded by all entries. That way we don't have to call a callback for every entry. (There are a lot of entries: `client/router/`, `client/`, `node/runtime/`, `node/plugin/`, `node/cli`.)
69
70
  function assertSingleInstance_onAssertModuleLoad() {
70
- globalObject.instances.push(projectInfo_js_1.projectInfo.projectVersion);
71
+ globalObject.instances.push(PROJECT_VERSION_js_1.PROJECT_VERSION);
71
72
  assertSingleInstance();
72
73
  }
73
- function assertUsage(condition, errorMessage) {
74
- if (condition) {
75
- return;
76
- }
77
- const errMsg = `[vike][Wrong Usage] ${errorMessage}`;
78
- throw new Error(errMsg);
79
- }
80
74
  function assertWarning(condition, errorMessage, { onlyOnce, showStackTrace }) {
81
75
  if (condition) {
82
76
  return;
83
77
  }
84
- const msg = `[vike][Warning] ${errorMessage}`;
78
+ const msg = `[Vike][Warning] ${errorMessage}`;
85
79
  if (onlyOnce) {
86
80
  const { alreadyLogged } = globalObject;
87
81
  const key = onlyOnce === true ? msg : onlyOnce;
@@ -16,6 +16,8 @@ const isArray_js_1 = require("./isArray.js");
16
16
  // Avoid this to be loaded in the browser. For isomorphic code: instead of `import { createDebugger } from './utils.js'`, use `globalThis.createDebugger()`.
17
17
  (0, assert_js_1.assert)(!(0, isBrowser_js_1.isBrowser)());
18
18
  globalThis.__brillout_debug_createDebugger = createDebugger;
19
+ // We purposely read process.env.DEBUG early, in order to avoid users from the temptation to set process.env.DEBUG with JavaScript, since reading & writing process.env.DEBUG dynamically leads to inconsistencies: for example https://github.com/vikejs/vike/issues/2239
20
+ const DEBUG = getDEBUG() ?? '';
19
21
  const flags = [
20
22
  'vike:crawl',
21
23
  'vike:error',
@@ -150,7 +152,6 @@ function assertFlagsActivated() {
150
152
  });
151
153
  }
152
154
  function getFlagsActivated() {
153
- const DEBUG = getDEBUG() ?? '';
154
155
  const flagsActivated = DEBUG.match(flagRegex) ?? [];
155
156
  const all = DEBUG.includes('vike:*');
156
157
  return { flagsActivated, all };
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getRandomId = getRandomId;
4
4
  const assert_js_1 = require("./assert.js");
5
5
  // https://stackoverflow.com/questions/1349404/generate-random-string-characters-in-javascript
6
- function getRandomId(length) {
6
+ function getRandomId(length = 12) {
7
7
  let randomId = '';
8
8
  while (randomId.length < length) {
9
9
  randomId += Math.random().toString(36).slice(2);
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeHeaders = normalizeHeaders;
4
4
  const isObject_js_1 = require("./isObject.js");
5
5
  function normalizeHeaders(
6
- /* This type is precise, too precise which can be annoying: e.g. cannot pass a string[][] argument because it doesn't match the more precise [string,string][] type.
6
+ /* This type is too strict which is annoying: cannot pass `string[][]` because it doesn't match the more precise type `[string,string][]`.
7
7
  headersOriginal ConstructorParameters<typeof Headers>[0]
8
8
  */
9
9
  headersOriginal) {
@@ -94,6 +94,7 @@ function modifyUrlPathname(url, modifier) {
94
94
  function removeUrlOrigin(url) {
95
95
  const { origin, pathnameOriginal, searchOriginal, hashOriginal } = (0, parseUrl_js_1.parseUrl)(url, '/');
96
96
  const urlModified = (0, parseUrl_js_1.createUrlFromComponents)(null, pathnameOriginal, searchOriginal, hashOriginal);
97
+ (0, assert_js_1.assert)(urlModified.startsWith('/'));
97
98
  return { urlModified, origin };
98
99
  }
99
100
  function setUrlOrigin(url, origin) {
@@ -1,5 +1,6 @@
1
1
  export { createPageContext };
2
2
  declare function createPageContext(urlOriginal: string): Promise<{
3
+ _isPageContextObject: boolean;
3
4
  urlOriginal: string;
4
5
  _objectCreatedByVike: boolean;
5
6
  _urlHandler: null;
@@ -11,7 +12,6 @@ declare function createPageContext(urlOriginal: string): Promise<{
11
12
  _allPageIds: string[];
12
13
  _pageRoutes: import("../../shared/route/loadPageRoutes.js").PageRoutes;
13
14
  _onBeforeRouteHook: import("../../shared/hooks/getHook.js").Hook | null;
14
- _isPageContextObject: boolean;
15
15
  } & {
16
16
  urlParsed: import("./utils.js").UrlPublic;
17
17
  urlPathname: string;
@@ -13,6 +13,7 @@ async function createPageContext(urlOriginal) {
13
13
  const baseServer = getBaseServer();
14
14
  assert(isBaseServer(baseServer));
15
15
  const pageContext = {
16
+ _isPageContextObject: true,
16
17
  urlOriginal,
17
18
  _objectCreatedByVike: true,
18
19
  _urlHandler: null,
@@ -23,8 +24,7 @@ async function createPageContext(urlOriginal) {
23
24
  _pageConfigGlobal: pageConfigGlobal,
24
25
  _allPageIds: allPageIds,
25
26
  _pageRoutes: pageRoutes,
26
- _onBeforeRouteHook: onBeforeRouteHook,
27
- _isPageContextObject: true
27
+ _onBeforeRouteHook: onBeforeRouteHook
28
28
  };
29
29
  const pageContextUrlComputed = getPageContextUrlComputed(pageContext);
30
30
  objectAssign(pageContext, pageContextUrlComputed);
@@ -11,7 +11,7 @@ import { assertVersion } from './utils.js';
11
11
  * https://vike.dev/api#build
12
12
  */
13
13
  async function build(options = {}) {
14
- const { viteConfigEnhanced, vikeConfig } = await prepareViteApiCall(options.viteConfig, 'build');
14
+ const { viteConfigEnhanced, vikeConfig } = await prepareViteApiCall(options, 'build');
15
15
  // Pass it to pluginAutoFullBuild()
16
16
  if (viteConfigEnhanced)
17
17
  viteConfigEnhanced._viteConfigEnhanced = viteConfigEnhanced;
@@ -1,7 +1,13 @@
1
1
  export { isVikeCliOrApi };
2
2
  export { setContextApiOperation };
3
3
  export { clearContextApiOperation };
4
- import type { Operation } from './types.js';
4
+ export { getApiOperation };
5
+ import type { APIOptions, Operation } from './types.js';
6
+ type ApiOperation = {
7
+ operation: Operation;
8
+ options: APIOptions;
9
+ };
10
+ declare function getApiOperation(): ApiOperation | null;
5
11
  declare function isVikeCliOrApi(): boolean;
6
- declare function setContextApiOperation(operation: Operation): void;
12
+ declare function setContextApiOperation(operation: Operation, options: APIOptions): void;
7
13
  declare function clearContextApiOperation(): void;
@@ -1,19 +1,19 @@
1
1
  export { isVikeCliOrApi };
2
2
  export { setContextApiOperation };
3
3
  export { clearContextApiOperation };
4
+ export { getApiOperation };
4
5
  import { assert, getGlobalObject } from './utils.js';
5
6
  const globalObject = getGlobalObject('api/context.ts', {});
6
7
  function getApiOperation() {
7
- assert(globalObject.apiOperation);
8
- return globalObject.apiOperation;
8
+ return globalObject.apiOperation ?? null;
9
9
  }
10
10
  function isVikeCliOrApi() {
11
11
  // The CLI uses the API
12
12
  return !!globalObject.apiOperation;
13
13
  }
14
- function setContextApiOperation(operation) {
14
+ function setContextApiOperation(operation, options) {
15
15
  assert(!globalObject.apiOperation);
16
- globalObject.apiOperation = operation;
16
+ globalObject.apiOperation = { operation, options };
17
17
  }
18
18
  function clearContextApiOperation() {
19
19
  globalObject.apiOperation = undefined;
@@ -7,7 +7,7 @@ import { createServer } from 'vite';
7
7
  * https://vike.dev/api#dev
8
8
  */
9
9
  async function dev(options = {}) {
10
- const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'dev');
10
+ const { viteConfigEnhanced } = await prepareViteApiCall(options, 'dev');
11
11
  const server = await createServer(viteConfigEnhanced);
12
12
  return {
13
13
  viteServer: server,
@@ -3,9 +3,9 @@ export { getViteRoot };
3
3
  export { assertViteRoot };
4
4
  export { normalizeViteRoot };
5
5
  import type { InlineConfig, ResolvedConfig } from 'vite';
6
- import type { Operation } from './types.js';
6
+ import type { APIOptions, Operation } from './types.js';
7
7
  import { type VikeConfigObject } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
8
- declare function prepareViteApiCall(viteConfigFromOptions: InlineConfig | undefined, operation: Operation): Promise<{
8
+ declare function prepareViteApiCall(options: APIOptions, operation: Operation): Promise<{
9
9
  vikeConfig: VikeConfigObject;
10
10
  viteConfigEnhanced: InlineConfig | undefined;
11
11
  }>;
@@ -10,9 +10,10 @@ import { assert, assertUsage, getGlobalObject, isObject, toPosixPath } from './u
10
10
  import pc from '@brillout/picocolors';
11
11
  import { clearGlobalContext } from '../runtime/globalContext.js';
12
12
  const globalObject = getGlobalObject('api/prepareViteApiCall.ts', {});
13
- async function prepareViteApiCall(viteConfigFromOptions, operation) {
13
+ async function prepareViteApiCall(options, operation) {
14
14
  clear();
15
- setContextApiOperation(operation);
15
+ setContextApiOperation(operation, options);
16
+ const viteConfigFromOptions = options.viteConfig;
16
17
  return enhanceViteConfig(viteConfigFromOptions, operation);
17
18
  }
18
19
  // For subsequent API calls, e.g. calling prerender() after build()
@@ -8,7 +8,7 @@ import { prepareViteApiCall } from './prepareViteApiCall.js';
8
8
  * https://vike.dev/api#prerender
9
9
  */
10
10
  async function prerender(options = {}) {
11
- const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'prerender');
11
+ const { viteConfigEnhanced } = await prepareViteApiCall(options, 'prerender');
12
12
  options.viteConfig = viteConfigEnhanced;
13
13
  const { viteConfig } = await runPrerenderFromAPI(options);
14
14
  return {
@@ -7,7 +7,7 @@ import { preview as previewVite } from 'vite';
7
7
  * https://vike.dev/api#preview
8
8
  */
9
9
  async function preview(options = {}) {
10
- const { viteConfigEnhanced } = await prepareViteApiCall(options.viteConfig, 'preview');
10
+ const { viteConfigEnhanced } = await prepareViteApiCall(options, 'preview');
11
11
  const server = await previewVite(viteConfigEnhanced);
12
12
  return {
13
13
  viteServer: server,
@@ -1,6 +1,7 @@
1
1
  export type { APIOptions };
2
2
  export type { Operation };
3
3
  import type { InlineConfig } from 'vite';
4
+ import type { Config } from '../../shared/page-configs/Config.js';
4
5
  type APIOptions = {
5
6
  /**
6
7
  * Vite config.
@@ -8,5 +9,11 @@ type APIOptions = {
8
9
  * https://vike.dev/api
9
10
  */
10
11
  viteConfig?: InlineConfig;
12
+ /**
13
+ * Vike config.
14
+ *
15
+ * https://vike.dev/api
16
+ */
17
+ vikeConfig?: Config;
11
18
  };
12
19
  type Operation = 'build' | 'dev' | 'preview' | 'prerender';
@@ -1,5 +1,7 @@
1
1
  export { isVikeCli };
2
2
  export { setContextCliCommand };
3
- import type { Command } from './parseCli.js';
3
+ export { getCliOptions };
4
+ import type { CliOptions, Command } from './parseCli.js';
5
+ declare function getCliOptions(): CliOptions | null;
4
6
  declare function isVikeCli(): boolean;
5
- declare function setContextCliCommand(command: Command): void;
7
+ declare function setContextCliCommand(command: Command, cliOptions: CliOptions): void;
@@ -1,14 +1,15 @@
1
1
  export { isVikeCli };
2
2
  export { setContextCliCommand };
3
+ export { getCliOptions };
3
4
  import { assert, getGlobalObject } from './utils.js';
4
5
  const globalObject = getGlobalObject('cli/context.ts', {});
5
- function getCliCommand() {
6
- return globalObject.cliCommand;
6
+ function getCliOptions() {
7
+ return globalObject.cliCommand?.cliOptions ?? null;
7
8
  }
8
9
  function isVikeCli() {
9
10
  return !!globalObject.cliCommand;
10
11
  }
11
- function setContextCliCommand(command) {
12
+ function setContextCliCommand(command, cliOptions) {
12
13
  assert(!globalObject.cliCommand);
13
- globalObject.cliCommand = command;
14
+ globalObject.cliCommand = { command, cliOptions };
14
15
  }
@@ -1,12 +1,12 @@
1
- import { projectInfo } from './utils.js';
1
+ import { PROJECT_VERSION } from './utils.js';
2
2
  import { dev, build, preview } from '../api/index.js';
3
3
  import pc from '@brillout/picocolors';
4
4
  import { parseCli } from './parseCli.js';
5
5
  import { setContextCliCommand } from './context.js';
6
6
  cli();
7
7
  async function cli() {
8
- const { command } = parseCli();
9
- setContextCliCommand(command);
8
+ const { command, cliOptions } = parseCli();
9
+ setContextCliCommand(command, cliOptions);
10
10
  if (command === 'dev') {
11
11
  await cmdDev();
12
12
  }
@@ -28,7 +28,7 @@ async function cmdDev() {
28
28
  const info = viteServer.config.logger.info;
29
29
  const startupDurationString = pc.dim(`ready in ${pc.reset(pc.bold(String(Math.ceil(performance.now() - startTime))))} ms`);
30
30
  const hasExistingLogs = process.stdout.bytesWritten > 0 || process.stderr.bytesWritten > 0;
31
- info(` ${pc.yellow(`${pc.bold(projectInfo.projectName)} v${projectInfo.projectVersion}`)} ${startupDurationString}\n`, {
31
+ info(` ${pc.yellow(`${pc.bold('Vike')} v${PROJECT_VERSION}`)} ${startupDurationString}\n`, {
32
32
  clear: !hasExistingLogs
33
33
  });
34
34
  viteServer.printUrls();
@@ -1,6 +1,9 @@
1
1
  export { parseCli };
2
2
  export type { Command };
3
+ export type { CliOptions };
4
+ type CliOptions = Record<string, unknown>;
3
5
  type Command = 'dev' | 'build' | 'preview' | 'prerender';
4
6
  declare function parseCli(): {
5
7
  command: Command;
8
+ cliOptions: CliOptions;
6
9
  };
@@ -1,6 +1,7 @@
1
1
  export { parseCli };
2
2
  import pc from '@brillout/picocolors';
3
- import { projectInfo, includes } from './utils.js';
3
+ import { assert, includes, PROJECT_VERSION } from './utils.js';
4
+ import { parseJson5 } from '../plugin/shared/getEnvVarObject.js';
4
5
  const commands = [
5
6
  { name: 'dev', desc: 'Start development server' },
6
7
  { name: 'build', desc: 'Build for production' },
@@ -8,32 +9,59 @@ const commands = [
8
9
  { name: 'prerender', desc: 'Pre-render pages (only needed when partial.disableAutoRun is true)' }
9
10
  ];
10
11
  function parseCli() {
11
- const command = (() => {
12
- const firstArg = process.argv[2];
13
- if (!firstArg) {
14
- showHelp();
15
- }
16
- showHelpOrVersion(firstArg);
17
- if (includes(commands.map((c) => c.name), firstArg))
18
- return firstArg;
19
- wrongUsage(`Unknown command ${pc.bold(firstArg)}`);
20
- })();
12
+ const command = getCommand();
13
+ const cliOptions = getCliOptions();
14
+ return { command, cliOptions };
15
+ }
16
+ function getCommand() {
17
+ const firstArg = process.argv[2];
18
+ if (includes(commands.map((c) => c.name), firstArg)) {
19
+ return firstArg;
20
+ }
21
+ if (!firstArg)
22
+ showHelp();
23
+ showHelpOrVersion(firstArg);
24
+ wrongUsage(`Unknown command ${pc.bold(firstArg)}`);
25
+ }
26
+ function getCliOptions() {
27
+ let cliOptions = {};
28
+ let configNameCurrent;
29
+ const commitIfDefinedWithoutValue = () => {
30
+ if (configNameCurrent)
31
+ commit(true);
32
+ };
33
+ const commit = (val) => {
34
+ assert(configNameCurrent);
35
+ cliOptions[configNameCurrent] = val;
36
+ configNameCurrent = undefined;
37
+ };
21
38
  for (const arg of process.argv.slice(3)) {
22
39
  showHelpOrVersion(arg);
23
- wrongUsage(`Unknown option ${pc.bold(arg)}`);
40
+ if (arg.startsWith('--')) {
41
+ commitIfDefinedWithoutValue();
42
+ configNameCurrent = arg.slice('--'.length);
43
+ }
44
+ else {
45
+ if (!configNameCurrent)
46
+ wrongUsage(`Unknown option ${pc.bold(arg)}`);
47
+ commit(parseJson5(arg, `CLI option --${configNameCurrent}`));
48
+ }
24
49
  }
25
- return { command };
50
+ commitIfDefinedWithoutValue();
51
+ return cliOptions;
26
52
  }
27
53
  function showHelp() {
28
54
  const TAB = ' '.repeat(3);
29
55
  const nameMaxLength = Math.max(...commands.map((c) => c.name.length));
30
56
  console.log([
31
- `vike@${projectInfo.projectVersion}`,
57
+ `vike@${PROJECT_VERSION}`,
32
58
  '',
33
59
  'Usage:',
34
60
  ...[...commands, { name: '-v', desc: "Print Vike's installed version" }].map((c) => ` ${pc.dim('$')} ${pc.bold(`vike ${c.name}`)}${' '.repeat(nameMaxLength - c.name.length)}${TAB}${pc.dim(`# ${c.desc}`)}`),
35
61
  '',
36
- `More infos at ${pc.underline('https://vike.dev/cli')}`
62
+ `Vike settings can be passed over the ${pc.cyan('VIKE_CONFIG')} environment variable or as ${pc.cyan('CLI options')} such as --host.`,
63
+ `Vite settings can be passed over the ${pc.cyan('VITE_CONFIG')} environment variable.`,
64
+ `See ${pc.underline('https://vike.dev/cli')} for more information.`
37
65
  ].join('\n'));
38
66
  process.exit(1);
39
67
  }
@@ -46,7 +74,7 @@ function showHelpOrVersion(arg) {
46
74
  }
47
75
  }
48
76
  function showVersion() {
49
- console.log(projectInfo.projectVersion);
77
+ console.log(PROJECT_VERSION);
50
78
  process.exit(1);
51
79
  }
52
80
  function wrongUsage(msg) {
@@ -1,4 +1,4 @@
1
1
  export * from '../../utils/assert.js';
2
- export * from '../../utils/projectInfo.js';
2
+ export * from '../../utils/PROJECT_VERSION.js';
3
3
  export * from '../../utils/includes.js';
4
4
  export * from '../../utils/getGlobalObject.js';
@@ -3,6 +3,6 @@
3
3
  import { onLoad } from './onLoad.js';
4
4
  onLoad();
5
5
  export * from '../../utils/assert.js';
6
- export * from '../../utils/projectInfo.js';
6
+ export * from '../../utils/PROJECT_VERSION.js';
7
7
  export * from '../../utils/includes.js';
8
8
  export * from '../../utils/getGlobalObject.js';
@@ -2,7 +2,7 @@ export { pluginBuildEntry };
2
2
  export { set_macro_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 { assert, projectInfo, toPosixPath } from '../../utils.js';
5
+ import { assert, PROJECT_VERSION, toPosixPath } from '../../utils.js';
6
6
  import fs from 'fs/promises';
7
7
  import path from 'path';
8
8
  import { createRequire } from 'module';
@@ -35,7 +35,7 @@ function pluginBuildEntry() {
35
35
  function getServerProductionEntryCode(config) {
36
36
  const importPath = getImportPath(config);
37
37
  const buildInfo = {
38
- versionAtBuildTime: projectInfo.projectVersion,
38
+ versionAtBuildTime: PROJECT_VERSION,
39
39
  usesClientRouter: isUsingClientRouter(), // TODO/v1-release: remove
40
40
  viteConfigRuntime: getViteConfigRuntime(config)
41
41
  };
@@ -1,5 +1,6 @@
1
1
  export { commonConfig };
2
2
  export { getVikeConfigPublic };
3
+ export type { VikeConfigPublic };
3
4
  import { type InlineConfig, type Plugin, type ResolvedConfig, type UserConfig } from 'vite';
4
5
  import { type VikeConfigObject } from './importUserCode/v1-design/getVikeConfig.js';
5
6
  import type { PrerenderContextPublic } from '../../prerender/runPrerender.js';
@@ -39,7 +39,7 @@ function commonConfig(vikeVitePluginOptions) {
39
39
  },
40
40
  // TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
41
41
  configVikePromise: Promise.resolve({
42
- prerender: resolvePrerenderConfigGlobal(vikeConfig).isEnabled
42
+ prerender: resolvePrerenderConfigGlobal(vikeConfig).isPrerenderingEnabled
43
43
  })
44
44
  };
45
45
  }
@@ -73,11 +73,22 @@ function commonConfig(vikeVitePluginOptions) {
73
73
  config: {
74
74
  order: 'post',
75
75
  handler(configFromUser) {
76
- // Change default port
77
76
  let configFromVike = { server: {}, preview: {} };
78
- setDefault('port', 3000, configFromUser, configFromVike);
79
- // Set `--host` for Docker/Podman
80
- if (isDocker()) {
77
+ const vike = getVikeConfigPublic(configFromUser);
78
+ if (vike.config.port !== undefined) {
79
+ // https://vike.dev/port
80
+ setDefault('port', vike.config.port, configFromUser, configFromVike);
81
+ }
82
+ else {
83
+ // Change Vite's default port
84
+ setDefault('port', 3000, configFromUser, configFromVike);
85
+ }
86
+ if (vike.config.host) {
87
+ // https://vike.dev/host
88
+ setDefault('host', vike.config.host, configFromUser, configFromVike);
89
+ }
90
+ else if (isDocker()) {
91
+ // Set `--host` for Docker/Podman
81
92
  setDefault('host', true, configFromUser, configFromVike);
82
93
  }
83
94
  // VITE_CONFIG
@@ -50,16 +50,18 @@ async function getPageDeps(config, pageConfigs) {
50
50
  .forEach((configValueSource) => {
51
51
  if (!configValueSource.valueIsLoadedWithImport && !configValueSource.valueIsFilePath)
52
52
  return;
53
- const { definedAtFilePath, configEnv } = configValueSource;
53
+ const { definedAt, configEnv } = configValueSource;
54
54
  if (!configEnv.client)
55
55
  return;
56
- if (definedAtFilePath.filePathAbsoluteUserRootDir !== null) {
56
+ if (definedAt.definedBy)
57
+ return;
58
+ if (definedAt.filePathAbsoluteUserRootDir !== null) {
57
59
  // Vite expects entries to be filesystem absolute paths (surprisingly so).
58
- addEntry(definedAtFilePath.filePathAbsoluteFilesystem);
60
+ addEntry(definedAt.filePathAbsoluteFilesystem);
59
61
  }
60
62
  else {
61
63
  // Adding definedAtFilePath.filePathAbsoluteFilesystem doesn't work for npm packages, I guess because of Vite's config.server.fs.allow
62
- addInclude(definedAtFilePath.importPathAbsolute);
64
+ addInclude(definedAt.importPathAbsolute);
63
65
  }
64
66
  });
65
67
  });
@@ -79,7 +79,7 @@ function devConfig() {
79
79
  if (config.server.middlewareMode || hasHonoViteDevServer)
80
80
  return;
81
81
  return () => {
82
- addSsrMiddleware(server.middlewares, config, false);
82
+ addSsrMiddleware(server.middlewares, config, false, null);
83
83
  };
84
84
  }
85
85
  },
@@ -6,7 +6,7 @@ import { assert, assertPosixPath } from '../../utils.js';
6
6
  import { resolveVirtualFileId, isVirtualFileId, getVirtualFileId } from '../../../shared/virtual-files.js';
7
7
  import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
8
8
  import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
9
- import { vikeConfigDependencies, reloadVikeConfig, isV1Design, getVikeConfig } from './v1-design/getVikeConfig.js';
9
+ import { reloadVikeConfig, isV1Design, getVikeConfig, getVikeConfigOptional } from './v1-design/getVikeConfig.js';
10
10
  import pc from '@brillout/picocolors';
11
11
  import { logConfigInfo } from '../../shared/loggerNotProd.js';
12
12
  import { getModuleFilePathAbsolute } from '../../shared/getFilePath.js';
@@ -29,9 +29,9 @@ function importUserCode() {
29
29
  return resolveVirtualFileId(id);
30
30
  }
31
31
  },
32
- handleHotUpdate(ctx) {
32
+ async handleHotUpdate(ctx) {
33
33
  try {
34
- return handleHotUpdate(ctx, config);
34
+ return await handleHotUpdate(ctx, config);
35
35
  }
36
36
  catch (err) {
37
37
  // Vite swallows errors thrown by handleHotUpdate()
@@ -63,9 +63,9 @@ function handleFileAddRemove(server, config) {
63
63
  server.watcher.prependListener('add', (f) => listener(f, false));
64
64
  server.watcher.prependListener('unlink', (f) => listener(f, true));
65
65
  return;
66
- function listener(file, isRemove) {
66
+ async function listener(file, isRemove) {
67
67
  file = normalizePath(file);
68
- if (isPlusFile(file) || isVikeConfigDependency(file, server.moduleGraph)?.modifiesVikeVirtualFiles) {
68
+ if (isPlusFile(file) || (await isVikeConfigDependency(file, server.moduleGraph))?.modifiesVikeVirtualFiles) {
69
69
  invalidateVikeVirtualFiles(server);
70
70
  reloadConfig(file, config, isRemove ? 'removed' : 'created');
71
71
  }
@@ -77,9 +77,9 @@ function invalidateVikeVirtualFiles(server) {
77
77
  server.moduleGraph.invalidateModule(mod);
78
78
  });
79
79
  }
80
- function handleHotUpdate(ctx, config) {
80
+ async function handleHotUpdate(ctx, config) {
81
81
  const { file, server } = ctx;
82
- const isVikeConfig = isVikeConfigDependency(ctx.file, ctx.server.moduleGraph);
82
+ const isVikeConfig = await isVikeConfigDependency(ctx.file, ctx.server.moduleGraph);
83
83
  if (isVikeConfig) {
84
84
  if (isVikeConfig.modifiesVikeVirtualFiles) {
85
85
  /* Tailwind breaks this assertion, see https://github.com/vikejs/vike/discussions/1330#discussioncomment-7787238
@@ -101,12 +101,16 @@ function handleHotUpdate(ctx, config) {
101
101
  }
102
102
  }
103
103
  }
104
- function isVikeConfigDependency(filePathAbsoluteFilesystem, moduleGraph) {
104
+ async function isVikeConfigDependency(filePathAbsoluteFilesystem, moduleGraph) {
105
105
  // Check config-only files, for example all pages/+config.js dependencies. (There aren't part of Vite's module graph.)
106
106
  assertPosixPath(filePathAbsoluteFilesystem);
107
- vikeConfigDependencies.forEach((f) => assertPosixPath(f));
108
- if (vikeConfigDependencies.has(filePathAbsoluteFilesystem))
109
- return { modifiesVikeVirtualFiles: true };
107
+ const vikeConfigObject = await getVikeConfigOptional();
108
+ if (vikeConfigObject) {
109
+ const { vikeConfigDependencies } = vikeConfigObject;
110
+ vikeConfigDependencies.forEach((f) => assertPosixPath(f));
111
+ if (vikeConfigDependencies.has(filePathAbsoluteFilesystem))
112
+ return { modifiesVikeVirtualFiles: true };
113
+ }
110
114
  // Check using Vite's module graph, for example all +htmlAttributes dependencies.
111
115
  // Alternatively, simply call updateUserFiles() on every handleHotUpdate() call.
112
116
  const importers = getImporters(filePathAbsoluteFilesystem, moduleGraph);
@@ -44,7 +44,9 @@ type ConfigDefinition = {
44
44
  *
45
45
  * https://vike.dev/extends#inheritance
46
46
  */
47
- global?: boolean | ((value: unknown) => boolean);
47
+ global?: boolean | ((value: unknown, moreInfo: {
48
+ isGlobalLocation: boolean;
49
+ }) => boolean);
48
50
  type?: string | string[];
49
51
  };
50
52
  /**