vike 0.4.144-commit-6aef8a6 → 0.4.144-commit-f7ab002
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/buildConfig.js +2 -2
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +29 -42
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +13 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/cjs/node/plugin/plugins/previewConfig.js +6 -2
- package/dist/cjs/node/prerender/runPrerender.js +8 -8
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +19 -6
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
- package/dist/cjs/node/shared/getClientEntryFilePath.js +2 -2
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +4 -6
- package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
- package/dist/cjs/shared/hooks/getHook.js +1 -1
- package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +43 -0
- package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +44 -0
- package/dist/cjs/shared/page-configs/helpers.js +33 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +6 -8
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +2 -2
- package/dist/cjs/shared/route/loadPageRoutes.js +11 -10
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/getPageContext.js +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig.js +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +29 -42
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +14 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/esm/node/plugin/plugins/previewConfig.js +6 -2
- package/dist/esm/node/prerender/runPrerender.js +2 -2
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +20 -7
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
- package/dist/esm/node/shared/getClientEntryFilePath.js +1 -1
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +2 -4
- package/dist/esm/shared/getPageFiles/getExports.js +2 -2
- package/dist/esm/shared/hooks/getHook.js +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +4 -12
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +7 -0
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +37 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.d.ts +14 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.js +38 -0
- package/dist/esm/shared/page-configs/helpers.d.ts +13 -0
- package/dist/esm/shared/page-configs/helpers.js +27 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +6 -8
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +7 -6
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/shared/page-configs/utils.js +0 -96
- package/dist/esm/shared/page-configs/utils.d.ts +0 -35
- package/dist/esm/shared/page-configs/utils.js +0 -90
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { serializePageContextClientSide };
|
|
2
2
|
export { serializePageContextAbort };
|
|
3
|
-
import { stringify } from '@brillout/json-serializer/stringify';
|
|
3
|
+
import { stringify, isJsonSerializerError } from '@brillout/json-serializer/stringify';
|
|
4
4
|
import { assert, assertWarning, hasProp, unique } from '../utils.js';
|
|
5
5
|
import { isErrorPage } from '../../../shared/error-page.js';
|
|
6
6
|
import { addIs404ToPageProps } from '../../../shared/addIs404ToPageProps.js';
|
|
@@ -46,19 +46,32 @@ function serializePageContextClientSide(pageContext) {
|
|
|
46
46
|
catch (err) {
|
|
47
47
|
hasWarned = true;
|
|
48
48
|
propsNonSerializable.push(prop);
|
|
49
|
-
|
|
50
|
-
assertWarning(false, [
|
|
49
|
+
let msg = [
|
|
51
50
|
`${varName} cannot be serialized and, therefore, cannot be passed to the client.`,
|
|
52
|
-
`Make sure that ${varName} is serializable, or remove ${h(propName)} from ${h('passToClient')}
|
|
53
|
-
|
|
54
|
-
|
|
51
|
+
`Make sure that ${varName} is serializable, or remove ${h(propName)} from ${h('passToClient')}.`
|
|
52
|
+
].join(' ');
|
|
53
|
+
if (isJsonSerializerError(err)) {
|
|
54
|
+
msg = `${msg} Serialization error: ${err.messageCore}.`;
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
console.warn('Serialization error:');
|
|
58
|
+
console.warn(err);
|
|
59
|
+
msg = `${msg} The serialization failed because of the error printed above.`;
|
|
60
|
+
}
|
|
61
|
+
// We warn (instead of throwing an error) since Vike's client runtime throws an error (with `assertUsage()`) if the user's client code tries to access the property that cannot be serialized
|
|
62
|
+
assertWarning(false, msg, { onlyOnce: false });
|
|
55
63
|
}
|
|
56
64
|
});
|
|
57
65
|
assert(hasWarned);
|
|
58
66
|
propsNonSerializable.forEach((prop) => {
|
|
59
67
|
pageContextClient[prop] = notSerializable;
|
|
60
68
|
});
|
|
61
|
-
|
|
69
|
+
try {
|
|
70
|
+
pageContextSerialized = serialize(pageContextClient);
|
|
71
|
+
}
|
|
72
|
+
catch (err) {
|
|
73
|
+
assert(false);
|
|
74
|
+
}
|
|
62
75
|
}
|
|
63
76
|
return pageContextSerialized;
|
|
64
77
|
}
|
|
@@ -20,7 +20,7 @@ import { preparePageContextForUserConsumptionServerSide } from './preparePageCon
|
|
|
20
20
|
import { executeGuardHook } from '../../../shared/route/executeGuardHook.js';
|
|
21
21
|
import { loadPageRoutes } from '../../../shared/route/loadPageRoutes.js';
|
|
22
22
|
import pc from '@brillout/picocolors';
|
|
23
|
-
import { getConfigValueFilePathToShowToUser } from '../../../shared/page-configs/
|
|
23
|
+
import { getConfigValueFilePathToShowToUser } from '../../../shared/page-configs/helpers.js';
|
|
24
24
|
async function renderPageAlreadyRouted(pageContext) {
|
|
25
25
|
// pageContext._pageId can either be the:
|
|
26
26
|
// - ID of the page matching the routing, or the
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getClientEntryFilePath };
|
|
2
|
-
import { getConfigValue } from '../../shared/page-configs/
|
|
2
|
+
import { getConfigValue } from '../../shared/page-configs/helpers.js';
|
|
3
3
|
function getClientEntryFilePath(pageConfig) {
|
|
4
4
|
const configName = 'client';
|
|
5
5
|
const configValue = getConfigValue(pageConfig, configName, 'string');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { analyzeClientSide };
|
|
2
|
-
import { getConfigValue } from '../page-configs/
|
|
2
|
+
import { getConfigValue } from '../page-configs/helpers.js';
|
|
3
3
|
import { analyzePageClientSide } from './analyzePageClientSide.js';
|
|
4
4
|
function analyzeClientSide(pageConfig, pageFilesAll, pageId) {
|
|
5
5
|
// V1 design
|
|
@@ -9,9 +9,7 @@ function analyzeClientSide(pageConfig, pageFilesAll, pageId) {
|
|
|
9
9
|
return { isClientSideRenderable, isClientRouting };
|
|
10
10
|
}
|
|
11
11
|
else {
|
|
12
|
-
// TODO/v1-release:
|
|
13
|
-
// - remove V0.4 implementation
|
|
14
|
-
// - globally rename isHtmlOnly to !isClientSideRenderable
|
|
12
|
+
// TODO/v1-release: remove
|
|
15
13
|
// V0.4 design
|
|
16
14
|
const { isHtmlOnly, isClientRouting } = analyzePageClientSide(pageFilesAll, pageId);
|
|
17
15
|
return { isClientSideRenderable: !isHtmlOnly, isClientRouting };
|
|
@@ -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, getConfigValueFilePathToShowToUser } from '../page-configs/
|
|
6
|
+
import { getConfigDefinedAtString, getConfigValueFilePathToShowToUser } from '../page-configs/helpers.js';
|
|
7
7
|
import pc from '@brillout/picocolors';
|
|
8
8
|
function getExports(pageFiles, pageConfig) {
|
|
9
9
|
const configEntries = {};
|
|
@@ -31,7 +31,7 @@ function getExports(pageFiles, pageConfig) {
|
|
|
31
31
|
Object.entries(pageConfig.configValues).forEach(([configName, configValue]) => {
|
|
32
32
|
const { value } = configValue;
|
|
33
33
|
const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser(configValue);
|
|
34
|
-
const configDefinedAt = getConfigDefinedAtString(configName, configValue
|
|
34
|
+
const configDefinedAt = getConfigDefinedAtString('Config', configName, configValue);
|
|
35
35
|
config[configName] = config[configName] ?? value;
|
|
36
36
|
configEntries[configName] = configEntries[configName] ?? [];
|
|
37
37
|
// Currently each configName has only one entry. Adding an entry for each overriden config value isn't implemented yet. (This is an isomorphic file and it isn't clear whether this can/should be implemented on the client-side. We should load a minimum amount of code on the client-side.)
|
|
@@ -23,6 +23,6 @@ function assertHook(pageContext, hookName) {
|
|
|
23
23
|
function assertHookFn(hookFn, { hookName, hookFilePath }) {
|
|
24
24
|
assert(hookName && hookFilePath);
|
|
25
25
|
assert(!hookName.endsWith(')'));
|
|
26
|
-
assertUsage(isCallable(hookFn), `
|
|
26
|
+
assertUsage(isCallable(hookFn), `Hook ${hookName}() defined by ${hookFilePath} should be a function`);
|
|
27
27
|
checkType(hookFn);
|
|
28
28
|
}
|
|
@@ -13,7 +13,7 @@ export type { ConfigValueComputed };
|
|
|
13
13
|
export type { ConfigValuesComputed };
|
|
14
14
|
export type { DefinedAt };
|
|
15
15
|
export type { DefinedAtFile };
|
|
16
|
-
export type {
|
|
16
|
+
export type { DefinedAtFileFullInfo };
|
|
17
17
|
export type { FilePathResolved };
|
|
18
18
|
export type { FilePath };
|
|
19
19
|
import type { ConfigValueImported } from './serialize/PageConfigSerialized.js';
|
|
@@ -56,15 +56,14 @@ type ConfigEnvInternal = ConfigEnv | '_routing-eager' | '_routing-lazy';
|
|
|
56
56
|
type ConfigValueSource = {
|
|
57
57
|
value?: unknown;
|
|
58
58
|
configEnv: ConfigEnvInternal;
|
|
59
|
-
|
|
59
|
+
definedAt: DefinedAtFileFullInfo;
|
|
60
60
|
/** Wether the config value is loaded at runtime, for example config.Page or config.onBeforeRender */
|
|
61
61
|
valueIsImportedAtRuntime: boolean;
|
|
62
62
|
/** Whether the config value is a file path, for example config.client */
|
|
63
63
|
valueIsFilePath?: true;
|
|
64
64
|
};
|
|
65
|
-
type
|
|
65
|
+
type DefinedAtFileFullInfo = DefinedAtFile & FilePath & {
|
|
66
66
|
fileExportName?: string;
|
|
67
|
-
fileExportPathToShowToUser: null | string[];
|
|
68
67
|
};
|
|
69
68
|
type ConfigValueSources = Record<string, ConfigValueSource[]>;
|
|
70
69
|
type ConfigValueComputed = {
|
|
@@ -76,17 +75,10 @@ type ConfigValue = {
|
|
|
76
75
|
value: unknown;
|
|
77
76
|
definedAt: DefinedAt;
|
|
78
77
|
};
|
|
79
|
-
type DefinedAt = {
|
|
80
|
-
file: DefinedAtFile;
|
|
81
|
-
isComputed?: undefined;
|
|
82
|
-
isCumulative?: undefined;
|
|
83
|
-
} | {
|
|
84
|
-
isCumulative: true;
|
|
78
|
+
type DefinedAt = DefinedAtFile | {
|
|
85
79
|
files: DefinedAtFile[];
|
|
86
|
-
isComputed?: undefined;
|
|
87
80
|
} | {
|
|
88
81
|
isComputed: true;
|
|
89
|
-
isCumulative?: undefined;
|
|
90
82
|
};
|
|
91
83
|
type DefinedAtFile = {
|
|
92
84
|
filePathToShowToUser: string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { getConfigDefinedAtString };
|
|
2
|
+
export { getDefinedAtString };
|
|
3
|
+
import type { DefinedAt } from '../PageConfig.js';
|
|
4
|
+
declare function getConfigDefinedAtString<ConfigName extends string, SentenceBegin extends 'Config' | 'config' | 'Hook'>(sentenceBegin: SentenceBegin, configName: ConfigName, { definedAt }: {
|
|
5
|
+
definedAt: DefinedAt;
|
|
6
|
+
}): `${SentenceBegin} ${ConfigName}${string} defined ${'internally' | `at ${string}`}`;
|
|
7
|
+
declare function getDefinedAtString(definedAt: DefinedAt, configName: string): string;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export { getConfigDefinedAtString };
|
|
2
|
+
export { getDefinedAtString };
|
|
3
|
+
import { assert } from '../../utils.js';
|
|
4
|
+
import pc from '@brillout/picocolors';
|
|
5
|
+
import { getExportPath } from '../getExportPath.js';
|
|
6
|
+
function getConfigDefinedAtString(sentenceBegin, configName, { definedAt }) {
|
|
7
|
+
const definedAtString = getDefinedAtString(definedAt, configName);
|
|
8
|
+
const definedAtStr = definedAtString === 'internally' ? definedAtString : `at ${definedAtString}`;
|
|
9
|
+
let configNameStr = `${configName}${sentenceBegin === 'Hook' ? '()' : ''}`;
|
|
10
|
+
const configDefinedAt = `${sentenceBegin} ${pc.cyan(configNameStr)} defined ${definedAtStr}`;
|
|
11
|
+
return configDefinedAt;
|
|
12
|
+
}
|
|
13
|
+
function getDefinedAtString(definedAt, configName) {
|
|
14
|
+
if ('isComputed' in definedAt) {
|
|
15
|
+
return 'internally';
|
|
16
|
+
}
|
|
17
|
+
let files;
|
|
18
|
+
if ('files' in definedAt) {
|
|
19
|
+
files = definedAt.files;
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
files = [definedAt];
|
|
23
|
+
}
|
|
24
|
+
assert(files.length >= 1);
|
|
25
|
+
const definedAtString = files
|
|
26
|
+
.map((source) => {
|
|
27
|
+
const { filePathToShowToUser, fileExportPathToShowToUser } = source;
|
|
28
|
+
let s = filePathToShowToUser;
|
|
29
|
+
const exportPath = getExportPath(fileExportPathToShowToUser, configName);
|
|
30
|
+
if (exportPath) {
|
|
31
|
+
s = `${s} > ${pc.cyan(exportPath)}`;
|
|
32
|
+
}
|
|
33
|
+
return s;
|
|
34
|
+
})
|
|
35
|
+
.join(' / ');
|
|
36
|
+
return definedAtString;
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { getConfigValue };
|
|
2
|
+
import type { PageConfigRuntime, PageConfigBuildTime, ConfigValue } from '../PageConfig.js';
|
|
3
|
+
import type { ConfigNameBuiltIn } from '../Config.js';
|
|
4
|
+
type PageConfigCommon = PageConfigRuntime | PageConfigBuildTime;
|
|
5
|
+
type ConfigName = ConfigNameBuiltIn;
|
|
6
|
+
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'string'): null | ConfigValue & {
|
|
7
|
+
value: string;
|
|
8
|
+
};
|
|
9
|
+
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'boolean'): null | ConfigValue & {
|
|
10
|
+
value: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName): null | ConfigValue & {
|
|
13
|
+
value: unknown;
|
|
14
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export { getConfigValue };
|
|
2
|
+
import { assert, assertUsage, getValuePrintable } from '../../utils.js';
|
|
3
|
+
import pc from '@brillout/picocolors';
|
|
4
|
+
import { getConfigDefinedAtString } from './getConfigDefinedAtString.js';
|
|
5
|
+
// prettier-ignore
|
|
6
|
+
function getConfigValue(pageConfig, configName, type) {
|
|
7
|
+
const configValue = getConfigValueEntry(pageConfig, configName);
|
|
8
|
+
if (configValue === null)
|
|
9
|
+
return null;
|
|
10
|
+
const { value, definedAt } = configValue;
|
|
11
|
+
if (type)
|
|
12
|
+
assertConfigValueType(value, type, configName, definedAt);
|
|
13
|
+
return configValue;
|
|
14
|
+
}
|
|
15
|
+
function assertConfigValueType(value, type, configName, definedAt) {
|
|
16
|
+
assert(value !== null);
|
|
17
|
+
const typeActual = typeof value;
|
|
18
|
+
if (typeActual === type)
|
|
19
|
+
return;
|
|
20
|
+
const valuePrintable = getValuePrintable(value);
|
|
21
|
+
const problem = valuePrintable !== null
|
|
22
|
+
? `value ${pc.cyan(valuePrintable)}`
|
|
23
|
+
: `type ${pc.cyan(typeActual)}`;
|
|
24
|
+
const configDefinedAt = getConfigDefinedAtString('Config', configName, {
|
|
25
|
+
definedAt
|
|
26
|
+
});
|
|
27
|
+
const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${pc.cyan(type)} instead`;
|
|
28
|
+
assertUsage(false, errMsg);
|
|
29
|
+
}
|
|
30
|
+
function getConfigValueEntry(pageConfig, configName) {
|
|
31
|
+
const configValue = pageConfig.configValues[configName];
|
|
32
|
+
if (!configValue)
|
|
33
|
+
return null;
|
|
34
|
+
// Enable users to suppress global config values by setting the local config value to null
|
|
35
|
+
if (configValue.value === null)
|
|
36
|
+
return null;
|
|
37
|
+
return configValue;
|
|
38
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { getPageConfig };
|
|
2
|
+
export { getConfigValueFilePathToShowToUser };
|
|
3
|
+
export { getHookFilePathToShowToUser };
|
|
4
|
+
export { getConfigDefinedAtString, getDefinedAtString } from './helpers/getConfigDefinedAtString.js';
|
|
5
|
+
export { getConfigValue } from './helpers/getConfigValue.js';
|
|
6
|
+
import type { PageConfigRuntime, DefinedAt } from './PageConfig.js';
|
|
7
|
+
declare function getPageConfig(pageId: string, pageConfigs: PageConfigRuntime[]): PageConfigRuntime;
|
|
8
|
+
declare function getConfigValueFilePathToShowToUser({ definedAt }: {
|
|
9
|
+
definedAt: DefinedAt;
|
|
10
|
+
}): null | string;
|
|
11
|
+
declare function getHookFilePathToShowToUser({ definedAt }: {
|
|
12
|
+
definedAt: DefinedAt;
|
|
13
|
+
}): string;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export { getPageConfig };
|
|
2
|
+
export { getConfigValueFilePathToShowToUser };
|
|
3
|
+
export { getHookFilePathToShowToUser };
|
|
4
|
+
export { getConfigDefinedAtString, getDefinedAtString } from './helpers/getConfigDefinedAtString.js';
|
|
5
|
+
export { getConfigValue } from './helpers/getConfigValue.js';
|
|
6
|
+
import { assert } from '../utils.js';
|
|
7
|
+
function getPageConfig(pageId, pageConfigs) {
|
|
8
|
+
const pageConfig = pageConfigs.find((p) => p.pageId === pageId);
|
|
9
|
+
assert(pageConfigs.length > 0);
|
|
10
|
+
assert(pageConfig);
|
|
11
|
+
return pageConfig;
|
|
12
|
+
}
|
|
13
|
+
function getConfigValueFilePathToShowToUser({ definedAt }) {
|
|
14
|
+
// A unique file path only exists if the config value isn't cumulative nor computed:
|
|
15
|
+
// - cumulative config values have multiple file paths
|
|
16
|
+
// - computed values don't have any file path
|
|
17
|
+
if ('isComputed' in definedAt || 'files' in definedAt)
|
|
18
|
+
return null;
|
|
19
|
+
const { filePathToShowToUser } = definedAt;
|
|
20
|
+
assert(filePathToShowToUser);
|
|
21
|
+
return filePathToShowToUser;
|
|
22
|
+
}
|
|
23
|
+
function getHookFilePathToShowToUser({ definedAt }) {
|
|
24
|
+
const filePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
|
|
25
|
+
assert(filePathToShowToUser);
|
|
26
|
+
return filePathToShowToUser;
|
|
27
|
+
}
|
|
@@ -8,14 +8,12 @@ function parseConfigValuesImported(configValuesImported) {
|
|
|
8
8
|
configValues[configName] = {
|
|
9
9
|
value,
|
|
10
10
|
definedAt: {
|
|
11
|
-
file
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
[exportName]
|
|
18
|
-
}
|
|
11
|
+
// importPath cannot be relative to the current file, since the current file is a virtual file
|
|
12
|
+
filePathToShowToUser: importPath,
|
|
13
|
+
fileExportPathToShowToUser: [configName, 'default'].includes(exportName)
|
|
14
|
+
? []
|
|
15
|
+
: // Side-effect config
|
|
16
|
+
[exportName]
|
|
19
17
|
}
|
|
20
18
|
};
|
|
21
19
|
assertIsNotNull(value, configName, importPath);
|
|
@@ -2,7 +2,7 @@ export { parsePageConfigs };
|
|
|
2
2
|
import { parse } from '@brillout/json-serializer/parse';
|
|
3
3
|
import { parseConfigValuesImported } from './parseConfigValuesImported.js';
|
|
4
4
|
import { assert, assertUsage, isCallable } from '../../utils.js';
|
|
5
|
-
import { getConfigDefinedAtString } from '../
|
|
5
|
+
import { getConfigDefinedAtString } from '../helpers.js';
|
|
6
6
|
function parsePageConfigs(pageConfigsSerialized, pageConfigGlobalSerialized) {
|
|
7
7
|
const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
|
|
8
8
|
const configValues = {};
|
|
@@ -49,7 +49,7 @@ function assertRouteConfigValue(configValues) {
|
|
|
49
49
|
return;
|
|
50
50
|
const { value } = configValue;
|
|
51
51
|
const configValueType = typeof value;
|
|
52
|
-
const configDefinedAt = getConfigDefinedAtString(configName, configValue
|
|
52
|
+
const configDefinedAt = getConfigDefinedAtString('Config', configName, configValue);
|
|
53
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`);
|
|
54
54
|
/* We don't use assertRouteString() in order to avoid unnecessarily bloating the client-side bundle when using Server Routing:
|
|
55
55
|
* - When using Server Routing, this file is loaded => loading assertRouteString() would bloat the client bundle.
|
|
@@ -23,9 +23,9 @@ function serializeConfigValue(lines, configName, configValueSerialized) {
|
|
|
23
23
|
function serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements) {
|
|
24
24
|
assert(!configValueSource.valueIsFilePath);
|
|
25
25
|
assert(whitespace.replaceAll(' ', '').length === 0);
|
|
26
|
-
const { valueIsImportedAtRuntime,
|
|
26
|
+
const { valueIsImportedAtRuntime, definedAt } = configValueSource;
|
|
27
27
|
assert(valueIsImportedAtRuntime);
|
|
28
|
-
const { filePathAbsoluteVite, fileExportName } =
|
|
28
|
+
const { filePathAbsoluteVite, fileExportName } = definedAt;
|
|
29
29
|
assertPosixPath(filePathAbsoluteVite);
|
|
30
30
|
const fileName = path.posix.basename(filePathAbsoluteVite);
|
|
31
31
|
const isValueFile = fileName.startsWith('+');
|
|
@@ -3,10 +3,10 @@ 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 { getConfigValue, getDefinedAtString, getHookFilePathToShowToUser } from '../page-configs/
|
|
6
|
+
import { getConfigDefinedAtString, getConfigValue, getDefinedAtString, getHookFilePathToShowToUser } from '../page-configs/helpers.js';
|
|
7
7
|
import { warnDeprecatedAllowKey } from './resolveRouteFunction.js';
|
|
8
8
|
async function loadPageRoutes(
|
|
9
|
-
//
|
|
9
|
+
// Remove all arguments and use GlobalContext instead?
|
|
10
10
|
pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
|
|
11
11
|
await Promise.all(pageFilesAll.filter((p) => p.fileType === '.page.route').map((p) => p.loadFile?.()));
|
|
12
12
|
const { onBeforeRouteHook, filesystemRoots } = getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal);
|
|
@@ -136,12 +136,13 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
136
136
|
function getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal) {
|
|
137
137
|
// V1 Design
|
|
138
138
|
if (pageConfigs.length > 0) {
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
const hookName = 'onBeforeRoute';
|
|
140
|
+
if (pageConfigGlobal.configValues[hookName]?.value) {
|
|
141
|
+
const configValue = pageConfigGlobal.configValues[hookName];
|
|
141
142
|
const { value: hookFn } = configValue;
|
|
142
143
|
const hookFilePath = getHookFilePathToShowToUser(configValue);
|
|
143
|
-
|
|
144
|
-
assertUsage(isCallable(hookFn),
|
|
144
|
+
const hookDefinedAt = getConfigDefinedAtString('Hook', hookName, configValue);
|
|
145
|
+
assertUsage(isCallable(hookFn), `${hookDefinedAt} should be a function.`);
|
|
145
146
|
const onBeforeRouteHook = {
|
|
146
147
|
hookFilePath: hookFilePath,
|
|
147
148
|
onBeforeRoute: hookFn
|
|
@@ -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.144-commit-
|
|
8
|
+
projectVersion: "0.4.144-commit-f7ab002";
|
|
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.144-commit-
|
|
3
|
+
const PROJECT_VERSION = '0.4.144-commit-f7ab002';
|
|
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.144-commit-
|
|
3
|
+
"version": "0.4.144-commit-f7ab002",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "tsc --watch",
|
|
6
6
|
"build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@brillout/import": "0.2.3",
|
|
16
|
-
"@brillout/json-serializer": "^0.5.
|
|
16
|
+
"@brillout/json-serializer": "^0.5.8",
|
|
17
17
|
"@brillout/picocolors": "^1.0.9",
|
|
18
18
|
"@brillout/require-shim": "^0.1.2",
|
|
19
19
|
"@brillout/vite-plugin-import-build": "^0.2.20",
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getHookFilePathToShowToUser = exports.getConfigValueFilePathToShowToUser = exports.getDefinedAtString = exports.getConfigDefinedAtString = exports.getPageConfig = exports.getConfigValue = void 0;
|
|
7
|
-
const utils_js_1 = require("../utils.js");
|
|
8
|
-
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
|
-
const getExportPath_js_1 = require("./getExportPath.js");
|
|
10
|
-
// prettier-ignore
|
|
11
|
-
function getConfigValue(pageConfig, configName, type) {
|
|
12
|
-
const configValue = getConfigValueEntry(pageConfig, configName);
|
|
13
|
-
if (configValue === null)
|
|
14
|
-
return null;
|
|
15
|
-
const { value, definedAt } = configValue;
|
|
16
|
-
if (type)
|
|
17
|
-
assertConfigValueType(value, type, configName, definedAt);
|
|
18
|
-
return configValue;
|
|
19
|
-
}
|
|
20
|
-
exports.getConfigValue = getConfigValue;
|
|
21
|
-
function assertConfigValueType(value, type, configName, definedAt) {
|
|
22
|
-
(0, utils_js_1.assert)(value !== null);
|
|
23
|
-
const typeActual = typeof value;
|
|
24
|
-
if (typeActual === type)
|
|
25
|
-
return;
|
|
26
|
-
const valuePrintable = (0, utils_js_1.getValuePrintable)(value);
|
|
27
|
-
const problem = valuePrintable !== null ? `value ${picocolors_1.default.cyan(valuePrintable)}` : `type ${picocolors_1.default.cyan(typeActual)}`;
|
|
28
|
-
const configDefinedAt = getConfigDefinedAtString(configName, { definedAt }, true);
|
|
29
|
-
(0, utils_js_1.assertUsage)(false, `${configDefinedAt} has an invalid ${problem}: it should be a ${picocolors_1.default.cyan(type)} instead`);
|
|
30
|
-
}
|
|
31
|
-
function getConfigValueEntry(pageConfig, configName) {
|
|
32
|
-
const configValue = pageConfig.configValues[configName];
|
|
33
|
-
if (!configValue)
|
|
34
|
-
return null;
|
|
35
|
-
// Enable users to suppress global config values by setting the local config value to null
|
|
36
|
-
if (configValue.value === null)
|
|
37
|
-
return null;
|
|
38
|
-
return configValue;
|
|
39
|
-
}
|
|
40
|
-
function getPageConfig(pageId, pageConfigs) {
|
|
41
|
-
const pageConfig = pageConfigs.find((p) => p.pageId === pageId);
|
|
42
|
-
(0, utils_js_1.assert)(pageConfigs.length > 0);
|
|
43
|
-
(0, utils_js_1.assert)(pageConfig);
|
|
44
|
-
return pageConfig;
|
|
45
|
-
}
|
|
46
|
-
exports.getPageConfig = getPageConfig;
|
|
47
|
-
function getConfigDefinedAtString(configName, { definedAt }, sentenceBegin) {
|
|
48
|
-
const definedAtString = getDefinedAtString(definedAt, configName);
|
|
49
|
-
const definedAtStr = definedAtString === 'internally' ? definedAtString : `at ${definedAtString}`;
|
|
50
|
-
const configDefinedAt = `${sentenceBegin ? `Config` : `config`} ${picocolors_1.default.cyan(configName)} defined ${definedAtStr}`;
|
|
51
|
-
return configDefinedAt;
|
|
52
|
-
}
|
|
53
|
-
exports.getConfigDefinedAtString = getConfigDefinedAtString;
|
|
54
|
-
function getDefinedAtString(definedAt, configName) {
|
|
55
|
-
if (definedAt.isComputed) {
|
|
56
|
-
return 'internally';
|
|
57
|
-
}
|
|
58
|
-
let files;
|
|
59
|
-
if (definedAt.isCumulative) {
|
|
60
|
-
files = definedAt.files;
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
files = [definedAt.file];
|
|
64
|
-
}
|
|
65
|
-
(0, utils_js_1.assert)(files.length >= 1);
|
|
66
|
-
const definedAtString = files
|
|
67
|
-
.map((source) => {
|
|
68
|
-
const { filePathToShowToUser, fileExportPathToShowToUser } = source;
|
|
69
|
-
let s = filePathToShowToUser;
|
|
70
|
-
const exportPath = (0, getExportPath_js_1.getExportPath)(fileExportPathToShowToUser, configName);
|
|
71
|
-
if (exportPath) {
|
|
72
|
-
s = `${s} > ${picocolors_1.default.cyan(exportPath)}`;
|
|
73
|
-
}
|
|
74
|
-
return s;
|
|
75
|
-
})
|
|
76
|
-
.join(' / ');
|
|
77
|
-
return definedAtString;
|
|
78
|
-
}
|
|
79
|
-
exports.getDefinedAtString = getDefinedAtString;
|
|
80
|
-
function getConfigValueFilePathToShowToUser({ definedAt }) {
|
|
81
|
-
// A unique file path only exists if the config value isn't cumulative nor computed:
|
|
82
|
-
// - cumulative config values have multiple file paths
|
|
83
|
-
// - computed values don't have any file path
|
|
84
|
-
if (definedAt.isComputed || definedAt.isCumulative)
|
|
85
|
-
return null;
|
|
86
|
-
const { filePathToShowToUser } = definedAt.file;
|
|
87
|
-
(0, utils_js_1.assert)(filePathToShowToUser);
|
|
88
|
-
return filePathToShowToUser;
|
|
89
|
-
}
|
|
90
|
-
exports.getConfigValueFilePathToShowToUser = getConfigValueFilePathToShowToUser;
|
|
91
|
-
function getHookFilePathToShowToUser({ definedAt }) {
|
|
92
|
-
const filePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
|
|
93
|
-
(0, utils_js_1.assert)(filePathToShowToUser);
|
|
94
|
-
return filePathToShowToUser;
|
|
95
|
-
}
|
|
96
|
-
exports.getHookFilePathToShowToUser = getHookFilePathToShowToUser;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export { getConfigValue };
|
|
2
|
-
export { getPageConfig };
|
|
3
|
-
export { getConfigDefinedAtString };
|
|
4
|
-
export { getDefinedAtString };
|
|
5
|
-
export { getConfigValueFilePathToShowToUser };
|
|
6
|
-
export { getHookFilePathToShowToUser };
|
|
7
|
-
import type { PageConfigRuntime, PageConfigBuildTime, ConfigValue, DefinedAt } from './PageConfig.js';
|
|
8
|
-
import type { ConfigNameBuiltIn } from './Config.js';
|
|
9
|
-
type PageConfigCommon = PageConfigRuntime | PageConfigBuildTime;
|
|
10
|
-
type ConfigName = ConfigNameBuiltIn;
|
|
11
|
-
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'string'): null | ConfigValue & {
|
|
12
|
-
value: string;
|
|
13
|
-
};
|
|
14
|
-
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'boolean'): null | ConfigValue & {
|
|
15
|
-
value: boolean;
|
|
16
|
-
};
|
|
17
|
-
declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName): null | ConfigValue & {
|
|
18
|
-
value: unknown;
|
|
19
|
-
};
|
|
20
|
-
declare function getPageConfig(pageId: string, pageConfigs: PageConfigRuntime[]): PageConfigRuntime;
|
|
21
|
-
type ConfigDefinedAtUppercase<ConfigName extends string> = `Config ${ConfigName} defined ${'internally' | `at ${string}`}`;
|
|
22
|
-
type ConfigDefinedAtLowercase<ConfigName extends string> = `config ${ConfigName} defined ${'internally' | `at ${string}`}`;
|
|
23
|
-
declare function getConfigDefinedAtString<ConfigName extends string>(configName: ConfigName, { definedAt }: {
|
|
24
|
-
definedAt: DefinedAt;
|
|
25
|
-
}, sentenceBegin: true): ConfigDefinedAtUppercase<ConfigName>;
|
|
26
|
-
declare function getConfigDefinedAtString<ConfigName extends string>(configName: ConfigName, { definedAt }: {
|
|
27
|
-
definedAt: DefinedAt;
|
|
28
|
-
}, sentenceBegin: false): ConfigDefinedAtLowercase<ConfigName>;
|
|
29
|
-
declare function getDefinedAtString(definedAt: DefinedAt, configName: string): string;
|
|
30
|
-
declare function getConfigValueFilePathToShowToUser({ definedAt }: {
|
|
31
|
-
definedAt: DefinedAt;
|
|
32
|
-
}): null | string;
|
|
33
|
-
declare function getHookFilePathToShowToUser({ definedAt }: {
|
|
34
|
-
definedAt: DefinedAt;
|
|
35
|
-
}): string;
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
export { getConfigValue };
|
|
2
|
-
export { getPageConfig };
|
|
3
|
-
export { getConfigDefinedAtString };
|
|
4
|
-
export { getDefinedAtString };
|
|
5
|
-
export { getConfigValueFilePathToShowToUser };
|
|
6
|
-
export { getHookFilePathToShowToUser };
|
|
7
|
-
import { assert, assertUsage, getValuePrintable } from '../utils.js';
|
|
8
|
-
import pc from '@brillout/picocolors';
|
|
9
|
-
import { getExportPath } from './getExportPath.js';
|
|
10
|
-
// prettier-ignore
|
|
11
|
-
function getConfigValue(pageConfig, configName, type) {
|
|
12
|
-
const configValue = getConfigValueEntry(pageConfig, configName);
|
|
13
|
-
if (configValue === null)
|
|
14
|
-
return null;
|
|
15
|
-
const { value, definedAt } = configValue;
|
|
16
|
-
if (type)
|
|
17
|
-
assertConfigValueType(value, type, configName, definedAt);
|
|
18
|
-
return configValue;
|
|
19
|
-
}
|
|
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
|
-
}
|
|
30
|
-
function getConfigValueEntry(pageConfig, configName) {
|
|
31
|
-
const configValue = pageConfig.configValues[configName];
|
|
32
|
-
if (!configValue)
|
|
33
|
-
return null;
|
|
34
|
-
// Enable users to suppress global config values by setting the local config value to null
|
|
35
|
-
if (configValue.value === null)
|
|
36
|
-
return null;
|
|
37
|
-
return configValue;
|
|
38
|
-
}
|
|
39
|
-
function getPageConfig(pageId, pageConfigs) {
|
|
40
|
-
const pageConfig = pageConfigs.find((p) => p.pageId === pageId);
|
|
41
|
-
assert(pageConfigs.length > 0);
|
|
42
|
-
assert(pageConfig);
|
|
43
|
-
return pageConfig;
|
|
44
|
-
}
|
|
45
|
-
function getConfigDefinedAtString(configName, { definedAt }, sentenceBegin) {
|
|
46
|
-
const definedAtString = getDefinedAtString(definedAt, configName);
|
|
47
|
-
const definedAtStr = definedAtString === 'internally' ? definedAtString : `at ${definedAtString}`;
|
|
48
|
-
const configDefinedAt = `${sentenceBegin ? `Config` : `config`} ${pc.cyan(configName)} defined ${definedAtStr}`;
|
|
49
|
-
return configDefinedAt;
|
|
50
|
-
}
|
|
51
|
-
function getDefinedAtString(definedAt, configName) {
|
|
52
|
-
if (definedAt.isComputed) {
|
|
53
|
-
return 'internally';
|
|
54
|
-
}
|
|
55
|
-
let files;
|
|
56
|
-
if (definedAt.isCumulative) {
|
|
57
|
-
files = definedAt.files;
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
files = [definedAt.file];
|
|
61
|
-
}
|
|
62
|
-
assert(files.length >= 1);
|
|
63
|
-
const definedAtString = files
|
|
64
|
-
.map((source) => {
|
|
65
|
-
const { filePathToShowToUser, fileExportPathToShowToUser } = source;
|
|
66
|
-
let s = filePathToShowToUser;
|
|
67
|
-
const exportPath = getExportPath(fileExportPathToShowToUser, configName);
|
|
68
|
-
if (exportPath) {
|
|
69
|
-
s = `${s} > ${pc.cyan(exportPath)}`;
|
|
70
|
-
}
|
|
71
|
-
return s;
|
|
72
|
-
})
|
|
73
|
-
.join(' / ');
|
|
74
|
-
return definedAtString;
|
|
75
|
-
}
|
|
76
|
-
function getConfigValueFilePathToShowToUser({ definedAt }) {
|
|
77
|
-
// A unique file path only exists if the config value isn't cumulative nor computed:
|
|
78
|
-
// - cumulative config values have multiple file paths
|
|
79
|
-
// - computed values don't have any file path
|
|
80
|
-
if (definedAt.isComputed || definedAt.isCumulative)
|
|
81
|
-
return null;
|
|
82
|
-
const { filePathToShowToUser } = definedAt.file;
|
|
83
|
-
assert(filePathToShowToUser);
|
|
84
|
-
return filePathToShowToUser;
|
|
85
|
-
}
|
|
86
|
-
function getHookFilePathToShowToUser({ definedAt }) {
|
|
87
|
-
const filePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
|
|
88
|
-
assert(filePathToShowToUser);
|
|
89
|
-
return filePathToShowToUser;
|
|
90
|
-
}
|