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.
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +30 -27
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +119 -64
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +11 -11
- package/dist/cjs/node/prerender/runPrerender.js +9 -8
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/renderPage/log404/index.js +10 -5
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
- package/dist/cjs/node/shared/getClientEntryFilePath.js +1 -7
- package/dist/cjs/shared/getPageFiles/getExports.js +2 -5
- package/dist/cjs/shared/getPageFiles/parsePageConfigsSerialized.js +9 -6
- package/dist/cjs/shared/hooks/getHook.js +3 -1
- package/dist/cjs/shared/page-configs/getExportPath.js +2 -2
- package/dist/cjs/shared/page-configs/parseConfigValuesImported.js +8 -5
- package/dist/cjs/shared/page-configs/utils.js +66 -42
- package/dist/cjs/shared/route/loadPageRoutes.js +5 -6
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +30 -27
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +11 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +3 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +119 -64
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -10
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +11 -11
- package/dist/esm/node/prerender/runPrerender.js +10 -9
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/esm/node/runtime/renderPage/log404/index.js +10 -5
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
- package/dist/esm/node/shared/getClientEntryFilePath.js +2 -8
- package/dist/esm/shared/addUrlComputedProps.d.ts +4 -2
- package/dist/esm/shared/getPageFiles/getExports.d.ts +1 -2
- package/dist/esm/shared/getPageFiles/getExports.js +3 -6
- package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.js +9 -6
- package/dist/esm/shared/hooks/getHook.js +3 -1
- package/dist/esm/shared/page-configs/Config.d.ts +1 -3
- package/dist/esm/shared/page-configs/PageConfig.d.ts +35 -10
- package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
- package/dist/esm/shared/page-configs/getExportPath.js +2 -2
- package/dist/esm/shared/page-configs/parseConfigValuesImported.js +8 -5
- package/dist/esm/shared/page-configs/utils.d.ts +19 -13
- package/dist/esm/shared/page-configs/utils.js +65 -41
- package/dist/esm/shared/route/loadPageRoutes.js +6 -7
- package/dist/esm/shared/types.d.ts +1 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- 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
|
|
33
|
-
|
|
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,
|
|
13
|
+
const { valueSerialized, definedAt } = configValueSeriliazed;
|
|
13
14
|
assert(valueSerialized);
|
|
14
15
|
assert(!configValues[configName]);
|
|
15
16
|
configValues[configName] = {
|
|
16
17
|
value: parse(valueSerialized),
|
|
17
|
-
|
|
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
|
-
|
|
46
|
+
const configName = 'route';
|
|
47
|
+
const configValue = configValues[configName];
|
|
48
|
+
if (!configValue)
|
|
46
49
|
return;
|
|
47
|
-
const { value
|
|
50
|
+
const { value } = configValue;
|
|
48
51
|
const configValueType = typeof value;
|
|
49
|
-
|
|
50
|
-
assertUsage(configValueType === 'string' || isCallable(value), `${
|
|
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.
|
|
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
|
|
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 {
|
|
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:
|
|
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
|
-
|
|
84
|
+
definedAt: DefinedAt;
|
|
82
85
|
};
|
|
83
86
|
type ConfigValueSerialized = {
|
|
84
87
|
valueSerialized: string;
|
|
85
|
-
|
|
88
|
+
definedAt: DefinedAt;
|
|
86
89
|
};
|
|
87
90
|
type ConfigValues = Record<string, ConfigValue>;
|
|
88
|
-
type
|
|
89
|
-
|
|
90
|
-
|
|
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
|
|
93
|
-
|
|
106
|
+
type DefinedAtInfoNew = {
|
|
107
|
+
filePathToShowToUser: string;
|
|
108
|
+
fileExportPath: null | string[];
|
|
109
|
+
};
|
|
110
|
+
type DefinedAtInfoFull = ({
|
|
111
|
+
filePathRelativeToUserRootDir: string;
|
|
94
112
|
filePathAbsolute: string;
|
|
95
|
-
|
|
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,
|
|
7
|
+
const addConfigValue = (configName, value, importPath, exportName) => {
|
|
8
8
|
configValues[configName] = {
|
|
9
9
|
value,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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,
|
|
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
|
-
|
|
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, {
|
|
24
|
-
|
|
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, {
|
|
27
|
-
|
|
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(
|
|
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,
|
|
15
|
+
const { value, definedAt } = configValue;
|
|
15
16
|
if (type)
|
|
16
|
-
assertConfigValueType(value, type, configName,
|
|
17
|
-
return
|
|
17
|
+
assertConfigValueType(value, type, configName, definedAt);
|
|
18
|
+
return configValue;
|
|
18
19
|
}
|
|
19
|
-
function
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
|
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
|
|
47
|
-
|
|
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
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
71
|
-
|
|
53
|
+
let sources;
|
|
54
|
+
if (definedAt.isCumulative) {
|
|
55
|
+
sources = definedAt.sources;
|
|
72
56
|
}
|
|
73
|
-
|
|
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 {
|
|
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(
|
|
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
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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-
|
|
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-
|
|
3
|
+
const PROJECT_VERSION = '0.4.143-commit-fa295e1';
|
|
4
4
|
const projectInfo = {
|
|
5
5
|
projectName: 'Vike',
|
|
6
6
|
projectVersion: PROJECT_VERSION,
|