vike 0.4.224 → 0.4.225

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 (120) 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 +2 -0
  14. package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -1
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +9 -1
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +75 -21
  17. package/dist/cjs/node/plugin/plugins/previewConfig.js +12 -7
  18. package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +5 -1
  19. package/dist/cjs/node/plugin/shared/getEnvVarObject.js +9 -8
  20. package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +1 -1
  21. package/dist/cjs/node/prerender/context.js +1 -1
  22. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +33 -18
  23. package/dist/cjs/node/prerender/runPrerender.js +6 -8
  24. package/dist/cjs/node/prerender/utils.js +1 -1
  25. package/dist/cjs/node/runtime/globalContext.js +9 -5
  26. package/dist/cjs/node/runtime/html/stream.js +7 -0
  27. package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +13 -5
  28. package/dist/cjs/node/runtime/renderPage/createHttpResponse.js +2 -4
  29. package/dist/cjs/node/runtime/renderPage/logErrorHint.js +6 -1
  30. package/dist/cjs/node/runtime/renderPage.js +6 -10
  31. package/dist/cjs/node/runtime/utils.js +0 -1
  32. package/dist/cjs/node/runtime-dev/createDevMiddleware.js +10 -8
  33. package/dist/cjs/node/shared/assertV1Design.js +2 -1
  34. package/dist/cjs/node/shared/utils.js +0 -1
  35. package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +18 -2
  36. package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +8 -5
  37. package/dist/cjs/shared/page-configs/helpers.js +1 -1
  38. package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -5
  39. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +6 -2
  40. package/dist/cjs/shared/route/loadPageRoutes.js +2 -2
  41. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  42. package/dist/cjs/utils/assert.js +2 -2
  43. package/dist/cjs/utils/assertSingleInstance.js +11 -17
  44. package/dist/cjs/utils/debug.js +2 -1
  45. package/dist/cjs/utils/parseUrl-extras.js +1 -0
  46. package/dist/esm/node/api/build.js +1 -1
  47. package/dist/esm/node/api/context.d.ts +8 -2
  48. package/dist/esm/node/api/context.js +4 -4
  49. package/dist/esm/node/api/dev.js +1 -1
  50. package/dist/esm/node/api/prepareViteApiCall.d.ts +2 -2
  51. package/dist/esm/node/api/prepareViteApiCall.js +3 -2
  52. package/dist/esm/node/api/prerender.js +1 -1
  53. package/dist/esm/node/api/preview.js +1 -1
  54. package/dist/esm/node/api/types.d.ts +7 -0
  55. package/dist/esm/node/cli/context.d.ts +4 -2
  56. package/dist/esm/node/cli/context.js +5 -4
  57. package/dist/esm/node/cli/entry.js +4 -4
  58. package/dist/esm/node/cli/parseCli.d.ts +3 -0
  59. package/dist/esm/node/cli/parseCli.js +44 -16
  60. package/dist/esm/node/cli/utils.d.ts +1 -1
  61. package/dist/esm/node/cli/utils.js +1 -1
  62. package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.js +2 -2
  63. package/dist/esm/node/plugin/plugins/commonConfig.d.ts +1 -0
  64. package/dist/esm/node/plugin/plugins/commonConfig.js +16 -5
  65. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -0
  66. package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -1
  67. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +3 -1
  68. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +9 -1
  69. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +75 -21
  70. package/dist/esm/node/plugin/plugins/previewConfig.js +12 -7
  71. package/dist/esm/node/plugin/shared/addSsrMiddleware.d.ts +1 -1
  72. package/dist/esm/node/plugin/shared/addSsrMiddleware.js +5 -1
  73. package/dist/esm/node/plugin/shared/getEnvVarObject.d.ts +3 -1
  74. package/dist/esm/node/plugin/shared/getEnvVarObject.js +9 -8
  75. package/dist/esm/node/plugin/shared/loggerNotProd/log.js +2 -2
  76. package/dist/esm/node/prerender/context.js +1 -1
  77. package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +2 -1
  78. package/dist/esm/node/prerender/resolvePrerenderConfig.js +34 -19
  79. package/dist/esm/node/prerender/runPrerender.js +7 -9
  80. package/dist/esm/node/prerender/utils.d.ts +1 -1
  81. package/dist/esm/node/prerender/utils.js +1 -1
  82. package/dist/esm/node/runtime/globalContext.d.ts +1 -1
  83. package/dist/esm/node/runtime/globalContext.js +10 -6
  84. package/dist/esm/node/runtime/html/stream.js +7 -0
  85. package/dist/esm/node/runtime/index-deprecated.d.ts +1 -3
  86. package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.d.ts +3 -1
  87. package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +14 -6
  88. package/dist/esm/node/runtime/renderPage/createHttpResponse.d.ts +3 -1
  89. package/dist/esm/node/runtime/renderPage/createHttpResponse.js +2 -4
  90. package/dist/esm/node/runtime/renderPage/logErrorHint.js +6 -1
  91. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +5 -5
  92. package/dist/esm/node/runtime/renderPage.js +7 -11
  93. package/dist/esm/node/runtime/utils.d.ts +0 -1
  94. package/dist/esm/node/runtime/utils.js +0 -1
  95. package/dist/esm/node/runtime-dev/createDevMiddleware.js +10 -8
  96. package/dist/esm/node/shared/assertV1Design.js +2 -1
  97. package/dist/esm/node/shared/utils.d.ts +0 -1
  98. package/dist/esm/node/shared/utils.js +0 -1
  99. package/dist/esm/shared/page-configs/Config.d.ts +19 -1
  100. package/dist/esm/shared/page-configs/PageConfig.d.ts +16 -5
  101. package/dist/esm/shared/page-configs/getConfigDefinedAt.d.ts +3 -3
  102. package/dist/esm/shared/page-configs/getConfigDefinedAt.js +19 -3
  103. package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +8 -5
  104. package/dist/esm/shared/page-configs/helpers.js +1 -1
  105. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +1 -1
  106. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -5
  107. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -3
  108. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +6 -2
  109. package/dist/esm/shared/route/loadPageRoutes.js +2 -2
  110. package/dist/esm/types/index.d.ts +2 -0
  111. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  112. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  113. package/dist/esm/utils/assert.js +2 -2
  114. package/dist/esm/utils/assertSingleInstance.js +11 -17
  115. package/dist/esm/utils/debug.js +2 -1
  116. package/dist/esm/utils/parseUrl-extras.js +1 -0
  117. package/package.json +4 -3
  118. package/dist/cjs/utils/projectInfo.js +0 -8
  119. package/dist/esm/utils/projectInfo.d.ts +0 -4
  120. 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 };
@@ -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) {
@@ -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
@@ -53,6 +53,8 @@ async function getPageDeps(config, pageConfigs) {
53
53
  const { definedAtFilePath, configEnv } = configValueSource;
54
54
  if (!configEnv.client)
55
55
  return;
56
+ if (definedAtFilePath.definedBy)
57
+ return;
56
58
  if (definedAtFilePath.filePathAbsoluteUserRootDir !== null) {
57
59
  // Vite expects entries to be filesystem absolute paths (surprisingly so).
58
60
  addEntry(definedAtFilePath.filePathAbsoluteFilesystem);
@@ -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
  },
@@ -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
  /**
@@ -123,6 +123,14 @@ const configDefinitionsBuiltIn = {
123
123
  cacheControl: {
124
124
  env: { server: true }
125
125
  },
126
+ host: {
127
+ env: { config: true },
128
+ global: true
129
+ },
130
+ port: {
131
+ env: { config: true },
132
+ global: true
133
+ },
126
134
  injectScriptsAt: {
127
135
  env: { server: true }
128
136
  },
@@ -148,7 +156,7 @@ const configDefinitionsBuiltIn = {
148
156
  },
149
157
  prerender: {
150
158
  env: { config: true },
151
- global: (value) => typeof value === 'object',
159
+ global: (value, { isGlobalLocation }) => typeof value === 'object' || isGlobalLocation,
152
160
  type: ['boolean', 'object'],
153
161
  cumulative: true
154
162
  },