vike 0.4.143-commit-f03b42d → 0.4.143-commit-fa295e1

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 (49) hide show
  1. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +30 -27
  2. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
  3. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +119 -64
  4. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -10
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +11 -11
  6. package/dist/cjs/node/prerender/runPrerender.js +9 -8
  7. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  8. package/dist/cjs/node/runtime/renderPage/log404/index.js +10 -5
  9. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
  10. package/dist/cjs/node/shared/getClientEntryFilePath.js +1 -7
  11. package/dist/cjs/shared/getPageFiles/getExports.js +2 -5
  12. package/dist/cjs/shared/getPageFiles/parsePageConfigsSerialized.js +9 -6
  13. package/dist/cjs/shared/hooks/getHook.js +3 -1
  14. package/dist/cjs/shared/page-configs/getExportPath.js +2 -2
  15. package/dist/cjs/shared/page-configs/parseConfigValuesImported.js +8 -5
  16. package/dist/cjs/shared/page-configs/utils.js +66 -42
  17. package/dist/cjs/shared/route/loadPageRoutes.js +5 -6
  18. package/dist/cjs/utils/projectInfo.js +1 -1
  19. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +30 -27
  20. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +11 -2
  21. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
  22. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +3 -2
  23. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +119 -64
  24. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -10
  25. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +2 -2
  26. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +11 -11
  27. package/dist/esm/node/prerender/runPrerender.js +10 -9
  28. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  29. package/dist/esm/node/runtime/renderPage/log404/index.js +10 -5
  30. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
  31. package/dist/esm/node/shared/getClientEntryFilePath.js +2 -8
  32. package/dist/esm/shared/addUrlComputedProps.d.ts +4 -2
  33. package/dist/esm/shared/getPageFiles/getExports.d.ts +1 -2
  34. package/dist/esm/shared/getPageFiles/getExports.js +3 -6
  35. package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.js +9 -6
  36. package/dist/esm/shared/hooks/getHook.js +3 -1
  37. package/dist/esm/shared/page-configs/Config.d.ts +1 -3
  38. package/dist/esm/shared/page-configs/PageConfig.d.ts +35 -10
  39. package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
  40. package/dist/esm/shared/page-configs/getExportPath.js +2 -2
  41. package/dist/esm/shared/page-configs/parseConfigValuesImported.js +8 -5
  42. package/dist/esm/shared/page-configs/utils.d.ts +19 -13
  43. package/dist/esm/shared/page-configs/utils.js +65 -41
  44. package/dist/esm/shared/route/loadPageRoutes.js +6 -7
  45. package/dist/esm/shared/types.d.ts +1 -0
  46. package/dist/esm/types/index.d.ts +1 -0
  47. package/dist/esm/utils/projectInfo.d.ts +1 -1
  48. package/dist/esm/utils/projectInfo.js +1 -1
  49. package/package.json +1 -1
@@ -9,13 +9,12 @@ import type { PageFile } from './getPageFileObject.js';
9
9
  type ExportsAll = Record<string, {
10
10
  exportValue: unknown;
11
11
  exportSource: string;
12
+ filePath: string | null;
12
13
  /** @deprecated */
13
14
  _fileType: FileType | null;
14
15
  /** @deprecated */
15
16
  _isFromDefaultExport: boolean | null;
16
17
  /** @deprecated */
17
- filePath: string | null;
18
- /** @deprecated */
19
18
  _filePath: string | null;
20
19
  }[]>;
21
20
  /** All the config's values (including overriden ones) and where they come from.
@@ -3,7 +3,7 @@ export { getExports };
3
3
  import { isScriptFile, isTemplateFile } from '../../utils/isScriptFile.js';
4
4
  import { assert, hasProp, isObject, assertWarning, assertUsage, makeLast, isBrowser } from '../utils.js';
5
5
  import { assertDefaultExports, forbiddenDefaultExports } from './assert_exports_old_design.js';
6
- import { getConfigDefinedAtString } from '../page-configs/utils.js';
6
+ import { getConfigDefinedAtString, getConfigValueFilePathToShowToUser } from '../page-configs/utils.js';
7
7
  import pc from '@brillout/picocolors';
8
8
  function getExports(pageFiles, pageConfig) {
9
9
  const configEntries = {};
@@ -29,11 +29,8 @@ function getExports(pageFiles, pageConfig) {
29
29
  // V1 design
30
30
  if (pageConfig) {
31
31
  Object.entries(pageConfig.configValues).forEach(([configName, configValue]) => {
32
- const { value, definedAtInfo } = configValue;
33
- let filePath = null;
34
- if (definedAtInfo) {
35
- filePath = definedAtInfo.filePath;
36
- }
32
+ const { value } = configValue;
33
+ const filePath = getConfigValueFilePathToShowToUser(configValue);
37
34
  const configDefinedAt = getConfigDefinedAtString(configName, configValue, true);
38
35
  config[configName] = config[configName] ?? value;
39
36
  configEntries[configName] = configEntries[configName] ?? [];
@@ -2,6 +2,7 @@ export { parsePageConfigsSerialized };
2
2
  import { parse } from '@brillout/json-serializer/parse';
3
3
  import { parseConfigValuesImported } from '../page-configs/parseConfigValuesImported.js';
4
4
  import { assert, assertUsage, isCallable } from '../utils.js';
5
+ import { getConfigDefinedAtString } from '../page-configs/utils.js';
5
6
  function parsePageConfigsSerialized(pageConfigsSerialized, pageConfigGlobalSerialized) {
6
7
  const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
7
8
  const configValues = {};
@@ -9,12 +10,12 @@ function parsePageConfigsSerialized(pageConfigsSerialized, pageConfigGlobalSeria
9
10
  const { configValuesSerialized } = pageConfigSerialized;
10
11
  Object.entries(configValuesSerialized).forEach(([configName, configValueSeriliazed]) => {
11
12
  {
12
- const { valueSerialized, definedAtInfo } = configValueSeriliazed;
13
+ const { valueSerialized, definedAt } = configValueSeriliazed;
13
14
  assert(valueSerialized);
14
15
  assert(!configValues[configName]);
15
16
  configValues[configName] = {
16
17
  value: parse(valueSerialized),
17
- definedAtInfo
18
+ definedAt
18
19
  };
19
20
  }
20
21
  });
@@ -42,12 +43,14 @@ function parsePageConfigsSerialized(pageConfigsSerialized, pageConfigGlobalSeria
42
43
  return { pageConfigs, pageConfigGlobal };
43
44
  }
44
45
  function assertRouteConfigValue(configValues) {
45
- if (!configValues.route)
46
+ const configName = 'route';
47
+ const configValue = configValues[configName];
48
+ if (!configValue)
46
49
  return;
47
- const { value, definedAtInfo } = configValues.route;
50
+ const { value } = configValue;
48
51
  const configValueType = typeof value;
49
- assert(definedAtInfo);
50
- assertUsage(configValueType === 'string' || isCallable(value), `${definedAtInfo.filePath} has an invalid type '${configValueType}': it should be a string or a function instead, see https://vike.dev/route`);
52
+ const configDefinedAt = getConfigDefinedAtString(configName, configValue, true);
53
+ assertUsage(configValueType === 'string' || isCallable(value), `${configDefinedAt} has an invalid type '${configValueType}': it should be a string or a function instead, see https://vike.dev/route`);
51
54
  /* We don't use assertRouteString() in order to avoid unnecessarily bloating the client-side bundle when using Server Routing:
52
55
  * - When using Server Routing, this file is loaded => loading assertRouteString() would bloat the client bundle.
53
56
  * - assertRouteString() is already called on the server-side
@@ -11,7 +11,9 @@ function getHook(pageContext, hookName) {
11
11
  assert(file.exportValue === hookFn);
12
12
  if (hookFn === null)
13
13
  return null;
14
- const hookFilePath = file.exportSource;
14
+ const hookFilePath = file.filePath;
15
+ assert(hookFilePath);
16
+ assert(!hookFilePath.endsWith(' '));
15
17
  assertHookFn(hookFn, { hookName, hookFilePath });
16
18
  return { hookFn, hookName, hookFilePath };
17
19
  }
@@ -32,9 +32,7 @@ import type { ConfigVikeUserProvided } from '../ConfigVike.js';
32
32
  import type { Vike, VikePackages } from '../VikeNamespace.js';
33
33
  import type { PageContextClient, PageContextServer } from '../types.js';
34
34
  type HookName = 'onHydrationEnd' | 'onBeforePrerender' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onBeforeRoute' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onPrerenderStart' | 'onRenderHtml' | 'onRenderClient' | 'guard' | 'render';
35
- type ConfigNameBuiltInPublic = Exclude<keyof Config, keyof ConfigVikeUserProvided | 'onBeforeRoute' | 'onPrerenderStart'> | 'prerender';
36
- type ConfigNameBuiltInInternal = 'isClientSideRenderable' | 'onBeforeRenderEnv';
37
- type ConfigNameBuiltIn = ConfigNameBuiltInPublic | ConfigNameBuiltInInternal;
35
+ type ConfigNameBuiltIn = Exclude<keyof Config, keyof ConfigVikeUserProvided | 'onBeforeRoute' | 'onPrerenderStart'> | 'prerender' | 'isClientSideRenderable' | 'onBeforeRenderEnv';
38
36
  type Config = ConfigBuiltIn & Vike.Config & (VikePackages.ConfigVikeReact | VikePackages.ConfigVikeVue | VikePackages.ConfigVikeSolid | VikePackages.ConfigVikeSvelte);
39
37
  /** Protect page(s), e.g. forbid unauthorized access.
40
38
  *
@@ -14,8 +14,10 @@ export type { ConfigValueImported };
14
14
  export type { ConfigValues };
15
15
  export type { ConfigValueSource };
16
16
  export type { ConfigValueSources };
17
- export type { DefinedAtInfo };
17
+ export type { DefinedAt };
18
+ export type { DefinedAtInfoNew };
18
19
  export type { DefinedAtInfoFull };
20
+ export type { DefinedAtInfoFull as DefinedAtInfo };
19
21
  type PageConfigBase = {
20
22
  pageId: string;
21
23
  isErrorPage?: true;
@@ -61,6 +63,7 @@ type PageConfigGlobalBuildTime = {
61
63
  configValueSources: ConfigValueSources;
62
64
  };
63
65
  type ConfigEnv = 'client-only' | 'server-only' | 'server-and-client' | 'config-only';
66
+ /** For Vike internal use */
64
67
  type ConfigEnvInternal = ConfigEnv | '_routing-eager' | '_routing-lazy';
65
68
  type ConfigValueSource = {
66
69
  configEnv: ConfigEnvInternal;
@@ -69,7 +72,7 @@ type ConfigValueSource = {
69
72
  valueIsFilePath?: true;
70
73
  } & ({
71
74
  isComputed: false;
72
- definedAtInfo: DefinedAtInfo;
75
+ definedAtInfo: DefinedAtInfoFull;
73
76
  } | {
74
77
  isComputed: true;
75
78
  definedAtInfo: null;
@@ -78,21 +81,43 @@ type ConfigValueSource = {
78
81
  type ConfigValueSources = Record<string, ConfigValueSource[]>;
79
82
  type ConfigValue = {
80
83
  value: unknown;
81
- definedAtInfo: null | DefinedAtInfo;
84
+ definedAt: DefinedAt;
82
85
  };
83
86
  type ConfigValueSerialized = {
84
87
  valueSerialized: string;
85
- definedAtInfo: null | DefinedAtInfo;
88
+ definedAt: DefinedAt;
86
89
  };
87
90
  type ConfigValues = Record<string, ConfigValue>;
88
- type DefinedAtInfo = {
89
- filePath: string;
90
- fileExportPath: string[];
91
+ type DefinedAt = {
92
+ source: DefinedAtInfoNew;
93
+ isEffect?: true;
94
+ isComputed?: undefined;
95
+ isCumulative?: undefined;
96
+ } | {
97
+ isCumulative: true;
98
+ sources: DefinedAtInfoNew[];
99
+ isEffect?: undefined;
100
+ isComputed?: undefined;
101
+ } | {
102
+ isComputed: true;
103
+ isEffect?: undefined;
104
+ isCumulative?: undefined;
91
105
  };
92
- type DefinedAtInfoFull = {
93
- filePathRelativeToUserRootDir?: string;
106
+ type DefinedAtInfoNew = {
107
+ filePathToShowToUser: string;
108
+ fileExportPath: null | string[];
109
+ };
110
+ type DefinedAtInfoFull = ({
111
+ filePathRelativeToUserRootDir: string;
94
112
  filePathAbsolute: string;
95
- fileExportPath: string[];
113
+ importPathAbsolute: null;
114
+ } | {
115
+ filePathRelativeToUserRootDir: null;
116
+ filePathAbsolute: string | null;
117
+ importPathAbsolute: string;
118
+ }) & {
119
+ exportName?: string;
120
+ fileExportPath: null | string[];
96
121
  };
97
122
  type ConfigSource = {
98
123
  configSourceFile: string;
@@ -1,2 +1,2 @@
1
1
  export { getExportPath };
2
- declare function getExportPath(fileExportPath: string[]): null | string;
2
+ declare function getExportPath(fileExportPath: null | string[]): null | string;
@@ -1,8 +1,8 @@
1
1
  export { getExportPath };
2
2
  import { assert } from '../utils.js';
3
- // TODO: return null instead of 'export default'
4
- // - Also return null insead of 'export *'?
5
3
  function getExportPath(fileExportPath) {
4
+ if (!fileExportPath)
5
+ return null;
6
6
  let prefix = '';
7
7
  let suffix = '';
8
8
  let [exportName, ...exportObjectPath] = fileExportPath;
@@ -4,15 +4,18 @@ import { assertExportsOfValueFile } from './assertExports.js';
4
4
  import pc from '@brillout/picocolors';
5
5
  function parseConfigValuesImported(configValuesImported) {
6
6
  const configValues = {};
7
- const addConfigValue = (configName, value, filePath, exportName) => {
7
+ const addConfigValue = (configName, value, importPath, exportName) => {
8
8
  configValues[configName] = {
9
9
  value,
10
- definedAtInfo: {
11
- filePath,
12
- fileExportPath: [exportName]
10
+ definedAt: {
11
+ source: {
12
+ // importPath is always relative the user's root directory (it cannot be relative to the current file since the current file is a virtual file)
13
+ filePathToShowToUser: importPath,
14
+ fileExportPath: [exportName]
15
+ }
13
16
  }
14
17
  };
15
- assertIsNotNull(value, configName, filePath);
18
+ assertIsNotNull(value, configName, importPath);
16
19
  };
17
20
  configValuesImported.forEach((configValueLoaded) => {
18
21
  if (configValueLoaded.isValueFile) {
@@ -1,29 +1,35 @@
1
1
  export { getConfigValue };
2
2
  export { getPageConfig };
3
3
  export { getConfigDefinedAtString };
4
- export { getConfigDefinedAtInfo };
5
4
  export { getDefinedAtString };
6
- import type { DefinedAtInfo, PageConfigRuntime, PageConfigBuildTime } from './PageConfig.js';
5
+ export { getConfigValueFilePathToShowToUser };
6
+ export { getHookFilePathToShowToUser };
7
+ import type { PageConfigRuntime, PageConfigBuildTime, ConfigValue, DefinedAt } from './PageConfig.js';
7
8
  import type { ConfigNameBuiltIn } from './Config.js';
8
9
  type PageConfigCommon = PageConfigRuntime | PageConfigBuildTime;
9
10
  type ConfigName = ConfigNameBuiltIn;
10
- declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'string'): null | {
11
+ declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'string'): null | ConfigValue & {
11
12
  value: string;
12
13
  };
13
- declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'boolean'): null | {
14
+ declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'boolean'): null | ConfigValue & {
14
15
  value: boolean;
15
16
  };
16
- declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName): null | {
17
+ declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName): null | ConfigValue & {
17
18
  value: unknown;
18
19
  };
19
- declare function getConfigDefinedAtInfo(pageConfig: PageConfigCommon, configName: ConfigName): DefinedAtInfo;
20
20
  declare function getPageConfig(pageId: string, pageConfigs: PageConfigRuntime[]): PageConfigRuntime;
21
- type ConfigDefinedAtUppercase<ConfigName extends string> = `Config ${ConfigName}${string}`;
22
- type ConfigDefinedAtLowercase<ConfigName extends string> = `config ${ConfigName}${string}`;
23
- declare function getConfigDefinedAtString<ConfigName extends string>(configName: ConfigName, { definedAtInfo }: {
24
- definedAtInfo: null | DefinedAtInfo;
21
+ type ConfigDefinedAtUppercase<ConfigName extends string> = `Config ${ConfigName} defined ${string}`;
22
+ type ConfigDefinedAtLowercase<ConfigName extends string> = `config ${ConfigName} defined ${string}`;
23
+ declare function getConfigDefinedAtString<ConfigName extends string>(configName: ConfigName, { definedAt }: {
24
+ definedAt: DefinedAt;
25
25
  }, sentenceBegin: true, append?: 'effect'): ConfigDefinedAtUppercase<ConfigName>;
26
- declare function getConfigDefinedAtString<ConfigName extends string>(configName: ConfigName, { definedAtInfo }: {
27
- definedAtInfo: null | DefinedAtInfo;
26
+ declare function getConfigDefinedAtString<ConfigName extends string>(configName: ConfigName, { definedAt }: {
27
+ definedAt: DefinedAt;
28
28
  }, sentenceBegin: false, append?: 'effect'): ConfigDefinedAtLowercase<ConfigName>;
29
- declare function getDefinedAtString(definedAtInfo: DefinedAtInfo, append?: 'effect'): string;
29
+ declare function getDefinedAtString(configValue: ConfigValue): string;
30
+ declare function getConfigValueFilePathToShowToUser({ definedAt }: {
31
+ definedAt: DefinedAt;
32
+ }): null | string;
33
+ declare function getHookFilePathToShowToUser({ definedAt }: {
34
+ definedAt: DefinedAt;
35
+ }): string;
@@ -1,8 +1,9 @@
1
1
  export { getConfigValue };
2
2
  export { getPageConfig };
3
3
  export { getConfigDefinedAtString };
4
- export { getConfigDefinedAtInfo };
5
4
  export { getDefinedAtString };
5
+ export { getConfigValueFilePathToShowToUser };
6
+ export { getHookFilePathToShowToUser };
6
7
  import { assert, assertUsage, getValuePrintable } from '../utils.js';
7
8
  import pc from '@brillout/picocolors';
8
9
  import { getExportPath } from './getExportPath.js';
@@ -11,31 +12,29 @@ function getConfigValue(pageConfig, configName, type) {
11
12
  const configValue = getConfigValueEntry(pageConfig, configName);
12
13
  if (configValue === null)
13
14
  return null;
14
- const { value, definedAtInfo } = configValue;
15
+ const { value, definedAt } = configValue;
15
16
  if (type)
16
- assertConfigValueType(value, type, configName, definedAtInfo);
17
- return { value };
17
+ assertConfigValueType(value, type, configName, definedAt);
18
+ return configValue;
18
19
  }
19
- function getConfigDefinedAtInfo(pageConfig, configName) {
20
- const configValue = getConfigValueEntry(pageConfig, configName);
21
- // We assume the caller to have ensured that the config value exists prior to calling getConfigDefinedAtInfo()
22
- assert(configValue);
23
- const { definedAtInfo } = configValue;
24
- // definedAtInfo is available only for config values that aren't:
25
- // - computed, nor
26
- // - cumulative
27
- assert(definedAtInfo);
28
- return definedAtInfo;
20
+ function assertConfigValueType(value, type, configName, definedAt) {
21
+ assert(value !== null);
22
+ const typeActual = typeof value;
23
+ if (typeActual === type)
24
+ return;
25
+ const valuePrintable = getValuePrintable(value);
26
+ const problem = valuePrintable !== null ? `value ${pc.cyan(valuePrintable)}` : `type ${pc.cyan(typeActual)}`;
27
+ const configDefinedAt = getConfigDefinedAtString(configName, { definedAt }, true);
28
+ assertUsage(false, `${configDefinedAt} has an invalid ${problem}: it should be a ${pc.cyan(type)} instead`);
29
29
  }
30
30
  function getConfigValueEntry(pageConfig, configName) {
31
31
  const configValue = pageConfig.configValues[configName];
32
32
  if (!configValue)
33
33
  return null;
34
- const { value, definedAtInfo } = configValue;
35
34
  // Enable users to suppress global config values by setting the local config value to null
36
- if (value === null)
35
+ if (configValue.value === null)
37
36
  return null;
38
- return { value, definedAtInfo };
37
+ return configValue;
39
38
  }
40
39
  function getPageConfig(pageId, pageConfigs) {
41
40
  const pageConfig = pageConfigs.find((p) => p.pageId === pageId);
@@ -43,32 +42,57 @@ function getPageConfig(pageId, pageConfigs) {
43
42
  assert(pageConfig);
44
43
  return pageConfig;
45
44
  }
46
- function assertConfigValueType(value, type, configName, definedAtInfo) {
47
- assert(value !== null);
48
- const typeActual = typeof value;
49
- if (typeActual === type)
50
- return;
51
- const valuePrintable = getValuePrintable(value);
52
- const problem = valuePrintable !== null ? `value ${pc.cyan(valuePrintable)}` : `type ${pc.cyan(typeActual)}`;
53
- const configDefinedAt = getConfigDefinedAtString(configName, { definedAtInfo }, true);
54
- assertUsage(false, `${configDefinedAt} has an invalid ${problem}: it should be a ${pc.cyan(type)} instead`);
55
- }
56
- function getConfigDefinedAtString(configName, { definedAtInfo }, sentenceBegin, append) {
57
- let configDefinedAt = `${sentenceBegin ? `Config` : `config`} ${pc.cyan(configName)}`;
58
- if (definedAtInfo !== null) {
59
- configDefinedAt = `${configDefinedAt} defined at ${getDefinedAtString(definedAtInfo, append)}`;
60
- }
45
+ function getConfigDefinedAtString(configName, { definedAt }, sentenceBegin) {
46
+ const configDefinedAt = `${sentenceBegin ? `Config` : `config`} ${pc.cyan(configName)} defined ${getSourceString(definedAt)}`;
61
47
  return configDefinedAt;
62
48
  }
63
- function getDefinedAtString(definedAtInfo, append) {
64
- const { filePath, fileExportPath } = definedAtInfo;
65
- let definedAt = filePath;
66
- const exportPath = getExportPath(fileExportPath);
67
- if (exportPath) {
68
- definedAt = `${definedAt} > ${pc.cyan(exportPath)}`;
49
+ function getSourceString(definedAt) {
50
+ if (definedAt.isComputed) {
51
+ return 'internally';
69
52
  }
70
- if (append) {
71
- definedAt = `${definedAt} > (${pc.blue(append)})`;
53
+ let sources;
54
+ if (definedAt.isCumulative) {
55
+ sources = definedAt.sources;
72
56
  }
73
- return definedAt;
57
+ else {
58
+ sources = [definedAt.source];
59
+ }
60
+ assert(sources.length >= 1);
61
+ const sourceString = sources
62
+ .map((source) => {
63
+ const { filePathToShowToUser, fileExportPath } = source;
64
+ let s = filePathToShowToUser;
65
+ const exportPath = getExportPath(fileExportPath);
66
+ if (exportPath) {
67
+ s = `${s} > ${pc.cyan(exportPath)}`;
68
+ }
69
+ if (definedAt.isEffect) {
70
+ s = `${s} > (${pc.blue('effect')})`;
71
+ }
72
+ return s;
73
+ })
74
+ .join(' / ');
75
+ return `at ${sourceString}`;
76
+ }
77
+ function getDefinedAtString(configValue) {
78
+ let sourceString = getSourceString(configValue.definedAt);
79
+ if (sourceString.startsWith('at '))
80
+ sourceString = sourceString.slice('at '.length);
81
+ return sourceString;
82
+ }
83
+ function getConfigValueFilePathToShowToUser({ definedAt }) {
84
+ // A unique file path only exists if the config value isn't cumulative nor computed:
85
+ // - cumulative config values have multiple file paths
86
+ // - computed values don't have any file path
87
+ if (definedAt.isComputed || definedAt.isCumulative)
88
+ return null;
89
+ const { source } = definedAt;
90
+ const { filePathToShowToUser } = source;
91
+ assert(filePathToShowToUser);
92
+ return filePathToShowToUser;
93
+ }
94
+ function getHookFilePathToShowToUser({ definedAt }) {
95
+ const filePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
96
+ assert(filePathToShowToUser);
97
+ return filePathToShowToUser;
74
98
  }
@@ -3,7 +3,7 @@ import { isErrorPageId } from '../error-page.js';
3
3
  import { assert, assertUsage, hasProp, slice } from './utils.js';
4
4
  import { deduceRouteStringFromFilesystemPath } from './deduceRouteStringFromFilesystemPath.js';
5
5
  import { isCallable } from '../utils.js';
6
- import { getConfigDefinedAtInfo, getConfigValue, getDefinedAtString } from '../page-configs/utils.js';
6
+ import { getConfigValue, getDefinedAtString, getHookFilePathToShowToUser } from '../page-configs/utils.js';
7
7
  import { warnDeprecatedAllowKey } from './resolveRouteFunction.js';
8
8
  async function loadPageRoutes(
9
9
  // TODO: remove all arguments and use GlobalContext instead
@@ -30,9 +30,8 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
30
30
  const configName = 'route';
31
31
  const configValue = getConfigValue(pageConfig, configName);
32
32
  if (configValue) {
33
- const definedAtInfo = getConfigDefinedAtInfo(pageConfig, configName);
34
33
  const route = configValue.value;
35
- const definedAt = getDefinedAtString(definedAtInfo);
34
+ const definedAt = getDefinedAtString(configValue);
36
35
  if (typeof route === 'string') {
37
36
  pageRoute = {
38
37
  pageId,
@@ -138,10 +137,10 @@ function getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal) {
138
137
  // V1 Design
139
138
  if (pageConfigs.length > 0) {
140
139
  if (pageConfigGlobal.configValues.onBeforeRoute?.value) {
141
- const { value: hookFn, definedAtInfo } = pageConfigGlobal.configValues.onBeforeRoute;
142
- // config.onBeforeRoute isn't a computed nor a cumulative config => definedAtInfo should always be defined
143
- assert(definedAtInfo);
144
- const hookFilePath = definedAtInfo.filePath;
140
+ const configValue = pageConfigGlobal.configValues.onBeforeRoute;
141
+ const { value: hookFn } = configValue;
142
+ const hookFilePath = getHookFilePathToShowToUser(configValue);
143
+ // TODO: use getConfigDefinedAtString()
145
144
  assertUsage(isCallable(hookFn), `The hook onBeforeRoute() defined by ${hookFilePath} should be a function.`);
146
145
  const onBeforeRouteHook = {
147
146
  hookFilePath: hookFilePath,
@@ -22,6 +22,7 @@ type PageContextClientWithServerRouting = PageContextBuiltInClientWithServerRout
22
22
  * https://vike.dev/pageContext
23
23
  */
24
24
  type PageContextBuiltInServer<Page = [never]> = PageContextBuiltInCommon<Page> & PageContextUrlComputedPropsServer;
25
+ /** For Vike internal use */
25
26
  type PageContextBuiltInServerInternal<Page = [never]> = PageContextBuiltInCommon<Page> & PageContextUrlComputedPropsInternal;
26
27
  type PageContextBuiltInCommon<Page = [never]> = {
27
28
  /** The `export { Page }` of your `.page.js` file.
@@ -10,6 +10,7 @@ export type { Config, ConfigMeta as Meta, GuardAsync, GuardSync, OnBeforePrerend
10
10
  export type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
11
11
  export type { ConfigDefinition, ConfigEffect } from '../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js';
12
12
  export type { ConfigEntries } from '../shared/getPageFiles/getExports.js';
13
+ export type { Url } from '../shared/addUrlComputedProps.js';
13
14
  export type { InjectFilterEntry } from '../node/runtime/html/injectAssets/getHtmlTags.js';
14
15
  export { defineConfig } from './defineConfig.js';
15
16
  import type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
@@ -5,7 +5,7 @@ type ProjectVersion = typeof projectInfo.projectVersion;
5
5
  type ProjectTag = `[${PackageName}]` | `[${PackageName}@${ProjectVersion}]`;
6
6
  declare const projectInfo: {
7
7
  projectName: "Vike";
8
- projectVersion: "0.4.143-commit-f03b42d";
8
+ projectVersion: "0.4.143-commit-fa295e1";
9
9
  npmPackageName: "vike";
10
10
  githubRepository: "https://github.com/vikejs/vike";
11
11
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  import { onProjectInfo } from './assertSingleInstance.js';
3
- const PROJECT_VERSION = '0.4.143-commit-f03b42d';
3
+ const PROJECT_VERSION = '0.4.143-commit-fa295e1';
4
4
  const projectInfo = {
5
5
  projectName: 'Vike',
6
6
  projectVersion: PROJECT_VERSION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.143-commit-f03b42d",
3
+ "version": "0.4.143-commit-fa295e1",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",