vike 0.4.224-commit-00ed9fe → 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 (112) 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 +15 -4
  13. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +6 -4
  14. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +14 -10
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -2
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -12
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +138 -83
  18. package/dist/cjs/node/plugin/plugins/setGlobalContext.js +10 -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/resolvePrerenderConfig.js +25 -17
  22. package/dist/cjs/node/prerender/runPrerender.js +2 -2
  23. package/dist/cjs/node/prerender/utils.js +1 -1
  24. package/dist/cjs/node/runtime/globalContext.js +9 -5
  25. package/dist/cjs/node/runtime/html/injectAssets/getViteDevScript.js +6 -3
  26. package/dist/cjs/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +3 -2
  27. package/dist/cjs/node/runtime/utils.js +0 -1
  28. package/dist/cjs/node/runtime-dev/createDevMiddleware.js +10 -8
  29. package/dist/cjs/node/shared/assertV1Design.js +2 -1
  30. package/dist/cjs/node/shared/utils.js +0 -1
  31. package/dist/cjs/shared/page-configs/getConfigDefinedAt.js +19 -2
  32. package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +8 -5
  33. package/dist/cjs/shared/page-configs/helpers.js +1 -1
  34. package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -5
  35. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +9 -5
  36. package/dist/cjs/shared/route/loadPageRoutes.js +2 -2
  37. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  38. package/dist/cjs/utils/assert.js +11 -4
  39. package/dist/cjs/utils/assertSingleInstance.js +11 -17
  40. package/dist/cjs/utils/getRandomId.js +1 -1
  41. package/dist/cjs/utils/normalizeHeaders.js +1 -1
  42. package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +1 -1
  43. package/dist/esm/client/client-routing-runtime/createPageContext.js +2 -2
  44. package/dist/esm/node/api/build.js +1 -1
  45. package/dist/esm/node/api/context.d.ts +8 -2
  46. package/dist/esm/node/api/context.js +4 -4
  47. package/dist/esm/node/api/dev.js +1 -1
  48. package/dist/esm/node/api/prepareViteApiCall.d.ts +2 -2
  49. package/dist/esm/node/api/prepareViteApiCall.js +3 -2
  50. package/dist/esm/node/api/prerender.js +1 -1
  51. package/dist/esm/node/api/preview.js +1 -1
  52. package/dist/esm/node/api/types.d.ts +7 -0
  53. package/dist/esm/node/cli/context.d.ts +4 -2
  54. package/dist/esm/node/cli/context.js +5 -4
  55. package/dist/esm/node/cli/entry.js +4 -4
  56. package/dist/esm/node/cli/parseCli.d.ts +3 -0
  57. package/dist/esm/node/cli/parseCli.js +44 -16
  58. package/dist/esm/node/cli/utils.d.ts +1 -1
  59. package/dist/esm/node/cli/utils.js +1 -1
  60. package/dist/esm/node/plugin/plugins/build/pluginBuildEntry.js +2 -2
  61. package/dist/esm/node/plugin/plugins/commonConfig.js +15 -4
  62. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +6 -4
  63. package/dist/esm/node/plugin/plugins/importUserCode/index.js +15 -11
  64. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +3 -1
  65. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +10 -2
  66. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +5 -2
  67. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -12
  68. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
  69. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +140 -84
  70. package/dist/esm/node/plugin/plugins/setGlobalContext.js +11 -2
  71. package/dist/esm/node/plugin/shared/getEnvVarObject.d.ts +3 -1
  72. package/dist/esm/node/plugin/shared/getEnvVarObject.js +9 -8
  73. package/dist/esm/node/plugin/shared/loggerNotProd/log.js +2 -2
  74. package/dist/esm/node/prerender/resolvePrerenderConfig.js +26 -18
  75. package/dist/esm/node/prerender/runPrerender.js +3 -3
  76. package/dist/esm/node/prerender/utils.d.ts +1 -1
  77. package/dist/esm/node/prerender/utils.js +1 -1
  78. package/dist/esm/node/runtime/globalContext.js +10 -6
  79. package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.js +6 -3
  80. package/dist/esm/node/runtime/index-deprecated.d.ts +1 -3
  81. package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.d.ts +1 -1
  82. package/dist/esm/node/runtime/renderPage/createHttpResponse/assertNoInfiniteHttpRedirect.js +3 -2
  83. package/dist/esm/node/runtime/utils.d.ts +0 -1
  84. package/dist/esm/node/runtime/utils.js +0 -1
  85. package/dist/esm/node/runtime-dev/createDevMiddleware.js +10 -8
  86. package/dist/esm/node/shared/assertV1Design.js +2 -1
  87. package/dist/esm/node/shared/utils.d.ts +0 -1
  88. package/dist/esm/node/shared/utils.js +0 -1
  89. package/dist/esm/shared/page-configs/Config.d.ts +19 -1
  90. package/dist/esm/shared/page-configs/PageConfig.d.ts +16 -5
  91. package/dist/esm/shared/page-configs/getConfigDefinedAt.d.ts +5 -3
  92. package/dist/esm/shared/page-configs/getConfigDefinedAt.js +20 -3
  93. package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +8 -5
  94. package/dist/esm/shared/page-configs/helpers.js +1 -1
  95. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +1 -1
  96. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -5
  97. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -3
  98. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +9 -5
  99. package/dist/esm/shared/route/loadPageRoutes.js +2 -2
  100. package/dist/esm/shared/types.d.ts +5 -1
  101. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  102. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  103. package/dist/esm/utils/assert.d.ts +2 -1
  104. package/dist/esm/utils/assert.js +11 -4
  105. package/dist/esm/utils/assertSingleInstance.js +11 -17
  106. package/dist/esm/utils/getRandomId.d.ts +1 -1
  107. package/dist/esm/utils/getRandomId.js +1 -1
  108. package/dist/esm/utils/normalizeHeaders.js +1 -1
  109. package/package.json +5 -3
  110. package/dist/cjs/utils/projectInfo.js +0 -8
  111. package/dist/esm/utils/projectInfo.d.ts +0 -4
  112. package/dist/esm/utils/projectInfo.js +0 -5
@@ -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
  };
@@ -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
  });
@@ -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
  /**
@@ -96,7 +96,7 @@ const configDefinitionsBuiltIn = {
96
96
  assert(source.valueIsLoaded);
97
97
  if (source.value !== null) {
98
98
  const { value } = source;
99
- const definedAt = getConfigDefinedAt('Config', 'clientHooks', source.definedAtFilePath);
99
+ const definedAt = getConfigDefinedAt('Config', 'clientHooks', source.definedAt);
100
100
  assertUsage(typeof value === 'boolean', `${definedAt} should be a boolean`);
101
101
  return value;
102
102
  }
@@ -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
  },
@@ -7,8 +7,11 @@ import type { FilePathResolved } from '../../../../../../shared/page-configs/Fil
7
7
  type FileExports = {
8
8
  fileExports: Record<string, unknown>;
9
9
  };
10
- type EsbuildCache = Record<string, // filePathAbsoluteFilesystem
11
- Promise<FileExports>>;
10
+ type EsbuildCache = {
11
+ transpileCache: Record<string, // filePathAbsoluteFilesystem
12
+ Promise<FileExports>>;
13
+ vikeConfigDependencies: Set<string>;
14
+ };
12
15
  declare function transpileAndExecuteFile(filePath: FilePathResolved, userRootDir: string, isExtensionConfig: boolean, esbuildCache: EsbuildCache): Promise<FileExports>;
13
16
  declare function getConfigBuildErrorFormatted(err: unknown): null | string;
14
17
  declare function getConfigExecutionErrorIntroMsg(err: unknown): string | null;
@@ -9,7 +9,6 @@ import pc from '@brillout/picocolors';
9
9
  import { import_ } from '@brillout/import';
10
10
  import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, assertWarning, isObject, toPosixPath, assertUsage, isPlainJavaScriptFile, createDebugger, assertFilePathAbsoluteFilesystem, assertIsNpmPackageImport, genPromise, isVitest } from '../../../../utils.js';
11
11
  import { transformPointerImports } from './transformPointerImports.js';
12
- import { vikeConfigDependencies } from '../getVikeConfig.js';
13
12
  import sourceMapSupport from 'source-map-support';
14
13
  import { getFilePathAbsoluteUserRootDir } from '../../../../shared/getFilePath.js';
15
14
  import { createRequire } from 'module';
@@ -26,11 +25,11 @@ async function transpileAndExecuteFile(filePath, userRootDir, isExtensionConfig,
26
25
  const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
27
26
  assert(filePathAbsoluteFilesystem);
28
27
  const fileExtension = getFileExtension(filePathAbsoluteFilesystem);
29
- if (esbuildCache[filePathAbsoluteFilesystem]) {
30
- return await esbuildCache[filePathAbsoluteFilesystem];
28
+ if (esbuildCache.transpileCache[filePathAbsoluteFilesystem]) {
29
+ return await esbuildCache.transpileCache[filePathAbsoluteFilesystem];
31
30
  }
32
31
  const { promise, resolve } = genPromise();
33
- esbuildCache[filePathAbsoluteFilesystem] = promise;
32
+ esbuildCache.transpileCache[filePathAbsoluteFilesystem] = promise;
34
33
  assertUsage(isPlainJavaScriptFile(filePathAbsoluteFilesystem), `${filePathToShowToUserResolved} has file extension .${fileExtension} but a config file can only be a JavaScript/TypeScript file`);
35
34
  const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
36
35
  if (isHeader) {
@@ -43,20 +42,20 @@ async function transpileAndExecuteFile(filePath, userRootDir, isExtensionConfig,
43
42
  }
44
43
  else {
45
44
  const transformImports = isHeader ? 'all' : true;
46
- const code = await transpileFile(filePath, transformImports, userRootDir);
45
+ const code = await transpileFile(filePath, transformImports, userRootDir, esbuildCache);
47
46
  fileExports = await executeTranspiledFile(filePath, code);
48
47
  }
49
48
  resolve({ fileExports });
50
49
  return { fileExports };
51
50
  }
52
- async function transpileFile(filePath, transformImports, userRootDir) {
51
+ async function transpileFile(filePath, transformImports, userRootDir, esbuildCache) {
53
52
  const { filePathAbsoluteFilesystem, filePathToShowToUserResolved } = filePath;
54
53
  assert(filePathAbsoluteFilesystem);
55
54
  assertPosixPath(filePathAbsoluteFilesystem);
56
- vikeConfigDependencies.add(filePathAbsoluteFilesystem);
55
+ esbuildCache.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
57
56
  if (debug.isActivated)
58
57
  debug('transpile', filePathToShowToUserResolved);
59
- let { code, pointerImports } = await transpileWithEsbuild(filePath, userRootDir, transformImports);
58
+ let { code, pointerImports } = await transpileWithEsbuild(filePath, userRootDir, transformImports, esbuildCache);
60
59
  if (debug.isActivated)
61
60
  debug(`code, post esbuild (${filePathToShowToUserResolved})`, code);
62
61
  let isImportTransformed = false;
@@ -75,7 +74,7 @@ async function transpileFile(filePath, transformImports, userRootDir) {
75
74
  }
76
75
  return code;
77
76
  }
78
- async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
77
+ async function transpileWithEsbuild(filePath, userRootDir, transformImports, esbuildCache) {
79
78
  const entryFilePath = filePath.filePathAbsoluteFilesystem;
80
79
  const entryFileDir = path.posix.dirname(entryFilePath);
81
80
  const options = {
@@ -229,7 +228,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
229
228
  // We collect the dependency `args.path` in case the bulid fails (upon build error => error is thrown => no metafile)
230
229
  let { path } = args;
231
230
  path = toPosixPath(path);
232
- vikeConfigDependencies.add(path);
231
+ esbuildCache.vikeConfigDependencies.add(path);
233
232
  return undefined;
234
233
  });
235
234
  /* To exhaustively collect all dependencies upon build failure, we would also need to use onResolve().
@@ -258,7 +257,7 @@ async function transpileWithEsbuild(filePath, userRootDir, transformImports) {
258
257
  filePathRelative = toPosixPath(filePathRelative);
259
258
  assertPosixPath(userRootDir);
260
259
  const filePathAbsoluteFilesystem = path.posix.join(userRootDir, filePathRelative);
261
- vikeConfigDependencies.add(filePathAbsoluteFilesystem);
260
+ esbuildCache.vikeConfigDependencies.add(filePathAbsoluteFilesystem);
262
261
  });
263
262
  const code = result.outputFiles[0].text;
264
263
  assert(typeof code === 'string');
@@ -330,7 +329,7 @@ function getTemporaryBuildFilePath(filePathAbsoluteFilesystem) {
330
329
  const dirname = path.posix.dirname(filePathAbsoluteFilesystem);
331
330
  const filename = path.posix.basename(filePathAbsoluteFilesystem);
332
331
  // Syntax with semicolon `build:${/*...*/}` doesn't work on Windows: https://github.com/vikejs/vike/issues/800#issuecomment-1517329455
333
- const filePathTmp = path.posix.join(dirname, `${filename}.build-${getRandomId(12)}.mjs`);
332
+ const filePathTmp = path.posix.join(dirname, `${filename}.build-${getRandomId()}.mjs`);
334
333
  assert(isTemporaryBuildFile(filePathTmp));
335
334
  return filePathTmp;
336
335
  }
@@ -1,7 +1,7 @@
1
1
  export { getVikeConfig };
2
+ export { getVikeConfigOptional };
2
3
  export { getVikeConfig2 };
3
4
  export { reloadVikeConfig };
4
- export { vikeConfigDependencies };
5
5
  export { isV1Design };
6
6
  export { getConfVal };
7
7
  export { getConfigDefinitionOptional };
@@ -17,13 +17,14 @@ type VikeConfigObject = {
17
17
  pageConfigGlobal: PageConfigGlobalBuildTime;
18
18
  global: PageConfigUserFriendly;
19
19
  pages: PageConfigsUserFriendly;
20
+ vikeConfigDependencies: Set<string>;
20
21
  };
21
- declare const vikeConfigDependencies: Set<string>;
22
22
  declare function reloadVikeConfig(config: ResolvedConfig): void;
23
23
  declare function getVikeConfig(config: ResolvedConfig, { doNotRestartViteOnError }?: {
24
24
  doNotRestartViteOnError?: true;
25
25
  }): Promise<VikeConfigObject>;
26
26
  declare function getVikeConfig2(userRootDir: string, isDev: boolean, vikeVitePluginOptions: unknown): Promise<VikeConfigObject>;
27
+ declare function getVikeConfigOptional(): Promise<null | VikeConfigObject>;
27
28
  declare function isV1Design(config: ResolvedConfig | UserConfig): boolean;
28
29
  declare function getConfigDefinitionOptional(configDefinitions: ConfigDefinitions, configName: string): ConfigDefinitionInternal | null;
29
30
  declare function getConfVal(plusFile: PlusFile, configName: string): null | {