vike 0.4.171-commit-f9548df → 0.4.171-commit-6e37128
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 +3 -4
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -15
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +30 -74
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +4 -42
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +9 -49
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +6 -0
- package/dist/cjs/node/prerender/runPrerender.js +3 -2
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +9 -7
- package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +1 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
- package/dist/cjs/node/shared/assertV1Design.js +3 -4
- package/dist/cjs/shared/getPageContextUrlComputed.js +8 -6
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +2 -2
- package/dist/cjs/shared/hooks/getHook.js +2 -2
- package/dist/cjs/shared/page-configs/getConfigValue.js +14 -17
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +70 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +3 -12
- package/dist/cjs/shared/page-configs/serialize/assertPageConfigsSerialized.js +1 -2
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +110 -16
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +198 -0
- package/dist/cjs/shared/route/loadPageRoutes.js +2 -2
- package/dist/cjs/utils/hasProp.js +5 -7
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +3 -3
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +4 -4
- package/dist/esm/node/plugin/plugins/buildConfig.js +3 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -15
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +30 -74
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +4 -42
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +9 -49
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +1 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +6 -0
- package/dist/esm/node/prerender/runPrerender.js +4 -3
- package/dist/esm/node/runtime/renderPage/analyzePage.js +9 -7
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +4 -4
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
- package/dist/esm/node/shared/assertV1Design.d.ts +2 -2
- package/dist/esm/node/shared/assertV1Design.js +3 -4
- package/dist/esm/shared/getPageContextUrlComputed.js +8 -6
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +3 -3
- package/dist/esm/shared/hooks/getHook.d.ts +2 -2
- package/dist/esm/shared/hooks/getHook.js +3 -3
- package/dist/esm/shared/page-configs/PageConfig.d.ts +10 -4
- package/dist/esm/shared/page-configs/getConfigValue.d.ts +12 -12
- package/dist/esm/shared/page-configs/getConfigValue.js +13 -16
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.d.ts +9 -0
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +67 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +3 -12
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +15 -19
- package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.js +1 -2
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +4 -1
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +109 -15
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +5 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +192 -0
- package/dist/esm/shared/route/loadPageRoutes.js +3 -3
- package/dist/esm/utils/hasProp.d.ts +4 -13
- package/dist/esm/utils/hasProp.js +5 -7
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +0 -101
- package/dist/cjs/node/plugin/shared/getConfigValueSourcesNotOverriden.js +0 -14
- package/dist/cjs/node/shared/getClientEntry.js +0 -12
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +0 -85
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesSerialized.js +0 -24
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +0 -49
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.d.ts +0 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +0 -95
- package/dist/esm/node/plugin/shared/getConfigValueSourcesNotOverriden.d.ts +0 -5
- package/dist/esm/node/plugin/shared/getConfigValueSourcesNotOverriden.js +0 -11
- package/dist/esm/node/shared/getClientEntry.d.ts +0 -3
- package/dist/esm/node/shared/getClientEntry.js +0 -9
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.d.ts +0 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +0 -82
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.d.ts +0 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.js +0 -21
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.d.ts +0 -6
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +0 -46
|
@@ -4,12 +4,16 @@ import { analyzePageClientSide } from '../../../shared/getPageFiles/analyzePageC
|
|
|
4
4
|
import { getVirtualFileIdPageConfigValuesAll } from '../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
5
5
|
import { analyzeClientSide } from '../../../shared/getPageFiles/analyzeClientSide.js';
|
|
6
6
|
import { getGlobalContext } from '../globalContext.js';
|
|
7
|
-
import {
|
|
7
|
+
import { getConfigValueRuntime } from '../../../shared/page-configs/getConfigValue.js';
|
|
8
8
|
function analyzePage(pageFilesAll, pageConfig, pageId) {
|
|
9
9
|
if (pageConfig) {
|
|
10
10
|
const { isClientSideRenderable, isClientRouting } = analyzeClientSide(pageConfig, pageFilesAll, pageId);
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const clientEntries = [];
|
|
12
|
+
const clientFilePath = getConfigValueRuntime(pageConfig, 'client', 'string')?.value ?? null;
|
|
13
|
+
if (clientFilePath)
|
|
14
|
+
clientEntries.push(clientFilePath);
|
|
15
|
+
if (isClientSideRenderable)
|
|
16
|
+
clientEntries.push(getVikeClientEntry(isClientRouting));
|
|
13
17
|
const clientDependencies = [];
|
|
14
18
|
clientDependencies.push({
|
|
15
19
|
id: getVirtualFileIdPageConfigValuesAll(pageConfig.pageId, true),
|
|
@@ -41,15 +45,13 @@ function analyzePage(pageFilesAll, pageConfig, pageId) {
|
|
|
41
45
|
}
|
|
42
46
|
})
|
|
43
47
|
*/
|
|
44
|
-
|
|
45
|
-
if (clientEntry) {
|
|
48
|
+
clientEntries.forEach((clientEntry) => {
|
|
46
49
|
clientDependencies.push({
|
|
47
50
|
id: clientEntry,
|
|
48
51
|
onlyAssets: false,
|
|
49
52
|
eagerlyImported: false
|
|
50
53
|
});
|
|
51
|
-
|
|
52
|
-
}
|
|
54
|
+
});
|
|
53
55
|
return {
|
|
54
56
|
isHtmlOnly: !isClientSideRenderable,
|
|
55
57
|
isClientRouting,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
export { getCacheControl };
|
|
2
2
|
import { getPageConfig } from '../../../../shared/page-configs/helpers.js';
|
|
3
|
-
import {
|
|
3
|
+
import { getConfigValueRuntime } from '../../../../shared/page-configs/getConfigValue.js';
|
|
4
4
|
const defaultValue = 'no-store, max-age=0';
|
|
5
5
|
function getCacheControl(pageId, pageConfigs) {
|
|
6
6
|
// TODO/v1-release: remove
|
|
7
7
|
if (pageConfigs.length === 0)
|
|
8
8
|
return defaultValue;
|
|
9
9
|
const pageConfig = getPageConfig(pageId, pageConfigs);
|
|
10
|
-
const configValue =
|
|
10
|
+
const configValue = getConfigValueRuntime(pageConfig, 'cacheControl', 'string');
|
|
11
11
|
const value = configValue?.value;
|
|
12
12
|
if (value)
|
|
13
13
|
return value;
|
|
@@ -14,7 +14,7 @@ type PageContext_loadUserFilesServerSide = PageContextGetPageAssets & PageContex
|
|
|
14
14
|
type PageFiles = PromiseType<ReturnType<typeof loadUserFilesServerSide>>;
|
|
15
15
|
declare function loadUserFilesServerSide(pageContext: {
|
|
16
16
|
_pageId: string;
|
|
17
|
-
} & PageContext_loadUserFilesServerSide): Promise<import("../../../shared/getPageFiles
|
|
17
|
+
} & PageContext_loadUserFilesServerSide): Promise<import("../../../shared/getPageFiles.js").PageContextExports & {
|
|
18
18
|
Page: unknown;
|
|
19
19
|
_isHtmlOnly: boolean;
|
|
20
20
|
_passToClient: string[];
|
|
@@ -65,7 +65,7 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
|
|
|
65
65
|
url: string;
|
|
66
66
|
} & {
|
|
67
67
|
headers: Record<string, string> | null;
|
|
68
|
-
} & import("../../../shared/getPageFiles
|
|
68
|
+
} & import("../../../shared/getPageFiles.js").PageContextExports & {
|
|
69
69
|
Page: unknown;
|
|
70
70
|
_isHtmlOnly: boolean;
|
|
71
71
|
_passToClient: string[];
|
|
@@ -116,7 +116,7 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
|
|
|
116
116
|
url: string;
|
|
117
117
|
} & {
|
|
118
118
|
headers: Record<string, string> | null;
|
|
119
|
-
} & import("../../../shared/getPageFiles
|
|
119
|
+
} & import("../../../shared/getPageFiles.js").PageContextExports & {
|
|
120
120
|
Page: unknown;
|
|
121
121
|
_isHtmlOnly: boolean;
|
|
122
122
|
_passToClient: string[];
|
|
@@ -168,7 +168,7 @@ declare function prerender404Page(renderContext: RenderContext, pageContextInit_
|
|
|
168
168
|
url: string;
|
|
169
169
|
} & {
|
|
170
170
|
headers: Record<string, string> | null;
|
|
171
|
-
} & import("../../../shared/getPageFiles
|
|
171
|
+
} & import("../../../shared/getPageFiles.js").PageContextExports & {
|
|
172
172
|
Page: unknown;
|
|
173
173
|
_isHtmlOnly: boolean;
|
|
174
174
|
_passToClient: string[];
|
|
@@ -219,7 +219,7 @@ declare function prerender404Page(renderContext: RenderContext, pageContextInit_
|
|
|
219
219
|
url: string;
|
|
220
220
|
} & {
|
|
221
221
|
headers: Record<string, string> | null;
|
|
222
|
-
} & import("../../../shared/getPageFiles
|
|
222
|
+
} & import("../../../shared/getPageFiles.js").PageContextExports & {
|
|
223
223
|
Page: unknown;
|
|
224
224
|
_isHtmlOnly: boolean;
|
|
225
225
|
_passToClient: string[];
|
|
@@ -21,7 +21,6 @@ import { executeGuardHook } from '../../../shared/route/executeGuardHook.js';
|
|
|
21
21
|
import { loadPageRoutes } from '../../../shared/route/loadPageRoutes.js';
|
|
22
22
|
import pc from '@brillout/picocolors';
|
|
23
23
|
import { isServerSideError } from '../../../shared/misc/isServerSideError.js';
|
|
24
|
-
import { assertV1Design } from '../../shared/assertV1Design.js';
|
|
25
24
|
async function renderPageAlreadyRouted(pageContext) {
|
|
26
25
|
// pageContext._pageId can either be the:
|
|
27
26
|
// - ID of the page matching the routing, or the
|
|
@@ -171,7 +170,8 @@ async function getRenderContext() {
|
|
|
171
170
|
const globalContext = getGlobalContext();
|
|
172
171
|
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal } = await getPageFilesAll(false, globalContext.isProduction);
|
|
173
172
|
const { pageRoutes, onBeforeRouteHook } = await loadPageRoutes(pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds);
|
|
174
|
-
assertV1Design(
|
|
173
|
+
// We assume assertV1Design() was already called at build-time
|
|
174
|
+
assert(pageFilesAll.length === 0 || pageConfigs.length === 0);
|
|
175
175
|
const renderContext = {
|
|
176
176
|
pageFilesAll: pageFilesAll,
|
|
177
177
|
pageConfigs,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { assertV1Design };
|
|
2
2
|
import { PageFile } from '../../shared/getPageFiles.js';
|
|
3
|
-
import type { PageConfigBuildTime
|
|
4
|
-
declare function assertV1Design(isOldDesign: boolean, pageConfigs:
|
|
3
|
+
import type { PageConfigBuildTime } from '../../shared/page-configs/PageConfig.js';
|
|
4
|
+
declare function assertV1Design(isOldDesign: boolean, pageConfigs: PageConfigBuildTime[], pageFilesAll?: PageFile[]): void;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export { assertV1Design };
|
|
2
|
-
import { getConfigValueFilePathToShowToUser } from '../../shared/page-configs/helpers.js';
|
|
3
2
|
import { assert, assertUsage, assertWarning, isNotNullish, unique } from './utils.js';
|
|
4
3
|
function assertV1Design(isOldDesign, pageConfigs, pageFilesAll) {
|
|
5
4
|
const isV1Design = pageConfigs.length > 0;
|
|
@@ -9,10 +8,10 @@ function assertV1Design(isOldDesign, pageConfigs, pageFilesAll) {
|
|
|
9
8
|
assert(pageFilesAll.length > 0);
|
|
10
9
|
const indent = '- ';
|
|
11
10
|
const filesV1 = unique(pageConfigs
|
|
12
|
-
.map((p) => Object.values(p.
|
|
13
|
-
.map((c) =>
|
|
11
|
+
.map((p) => Object.values(p.configValueSources).map((sources) => sources
|
|
12
|
+
.map((c) => c.definedAtFilePath.filePathAbsoluteUserRootDir)
|
|
14
13
|
.filter(isNotNullish)
|
|
15
|
-
.map((filePathToShowToUser) => indent + filePathToShowToUser))
|
|
14
|
+
.map((filePathToShowToUser) => indent + filePathToShowToUser)))
|
|
16
15
|
.flat(2));
|
|
17
16
|
const filesOld = pageFilesAll.map((p) => indent + p.filePath);
|
|
18
17
|
lines.push(...['V1 design files:', ...filesV1, 'Old design files:', ...filesOld]);
|
|
@@ -127,22 +127,24 @@ function assertPageContextUrlComputed(pageContext) {
|
|
|
127
127
|
```js
|
|
128
128
|
const PageContextUrlComputed = getPageContextUrlComputed(pageContext)
|
|
129
129
|
|
|
130
|
-
// ❌ Breaks the property getters of pageContext
|
|
130
|
+
// ❌ Breaks the property descriptors/getters of pageContext defined by getPageContextUrlComputed() such as pageContext.urlPathname
|
|
131
131
|
Object.assign(pageContext, pageContextUrlComputed)
|
|
132
132
|
|
|
133
|
-
// ❌ Also breaks property getters
|
|
133
|
+
// ❌ Also breaks property descriptors/getters
|
|
134
134
|
const pageContext = { ...pageContextUrlComputed }
|
|
135
135
|
|
|
136
|
-
// ✅ Preserves property getters
|
|
136
|
+
// ✅ Preserves property descriptors/getters (see objectAssign() implementation)
|
|
137
137
|
objectAssign(pageContext, pageContextUrlComputed)
|
|
138
138
|
```
|
|
139
139
|
*/
|
|
140
140
|
if ('urlPathname' in pageContext) {
|
|
141
141
|
assert(typeof pageContext.urlPathname === 'string');
|
|
142
142
|
assert(isPropertyGetter(pageContext, 'urlPathname'));
|
|
143
|
-
}
|
|
144
|
-
if ('urlParsed' in pageContext)
|
|
145
143
|
assert(isPropertyGetter(pageContext, 'urlParsed'));
|
|
146
|
-
if ('url' in pageContext)
|
|
147
144
|
assert(isPropertyGetter(pageContext, 'url'));
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
assert(!('urlParsed' in pageContext));
|
|
148
|
+
assert(!('url' in pageContext));
|
|
149
|
+
}
|
|
148
150
|
}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export { analyzeClientSide };
|
|
2
|
-
import {
|
|
2
|
+
import { getConfigValueRuntime } from '../page-configs/getConfigValue.js';
|
|
3
3
|
import { analyzePageClientSide } from './analyzePageClientSide.js';
|
|
4
4
|
function analyzeClientSide(pageConfig, pageFilesAll, pageId) {
|
|
5
5
|
// V1 design
|
|
6
6
|
if (pageConfig) {
|
|
7
|
-
const isClientRouting =
|
|
8
|
-
const isClientSideRenderable =
|
|
7
|
+
const isClientRouting = getConfigValueRuntime(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
8
|
+
const isClientSideRenderable = getConfigValueRuntime(pageConfig, 'isClientSideRenderable', 'boolean')?.value ?? false;
|
|
9
9
|
return { isClientSideRenderable, isClientRouting };
|
|
10
10
|
}
|
|
11
11
|
else {
|
|
@@ -11,7 +11,7 @@ export type { HooksTimeoutProvidedByUser };
|
|
|
11
11
|
export { getHookTimeoutDefault };
|
|
12
12
|
import type { PageContextExports } from '../getPageFiles.js';
|
|
13
13
|
import type { HookName, HookNamePage, HookNameGlobal } from '../page-configs/Config.js';
|
|
14
|
-
import type {
|
|
14
|
+
import type { PageConfigGlobalRuntime, PageConfigRuntime } from '../page-configs/PageConfig.js';
|
|
15
15
|
type Hook = HookLoc & {
|
|
16
16
|
hookFn: HookFn;
|
|
17
17
|
hookTimeout: HookTimeout;
|
|
@@ -27,7 +27,7 @@ type HookTimeout = {
|
|
|
27
27
|
};
|
|
28
28
|
type HooksTimeoutProvidedByUser = false | Partial<Record<HookName, false | Partial<HookTimeout>>>;
|
|
29
29
|
declare function getHook(pageContext: PageContextExports, hookName: HookName): null | Hook;
|
|
30
|
-
declare function getHookFromPageConfig(pageConfig: PageConfigRuntime
|
|
30
|
+
declare function getHookFromPageConfig(pageConfig: PageConfigRuntime, hookName: HookNamePage): null | Hook;
|
|
31
31
|
declare function getHookFromPageConfigGlobal(pageConfigGlobal: PageConfigGlobalRuntime, hookName: HookNameGlobal): null | Hook;
|
|
32
32
|
declare function assertHook<TPageContext extends PageContextExports, THookName extends PropertyKey & HookName>(pageContext: TPageContext, hookName: THookName): asserts pageContext is TPageContext & {
|
|
33
33
|
exports: Record<THookName, Function | undefined>;
|
|
@@ -8,7 +8,7 @@ export { setIsPrerenderering };
|
|
|
8
8
|
export { getHookTimeoutDefault };
|
|
9
9
|
import { getGlobalObject } from '../../utils/getGlobalObject.js';
|
|
10
10
|
import { getHookFilePathToShowToUser } from '../page-configs/helpers.js';
|
|
11
|
-
import {
|
|
11
|
+
import { getConfigValueRuntime } from '../page-configs/getConfigValue.js';
|
|
12
12
|
import { assert, assertUsage, checkType, isCallable, isObject } from '../utils.js';
|
|
13
13
|
import pc from '@brillout/picocolors';
|
|
14
14
|
const globalObject = getGlobalObject('getHook.ts', {
|
|
@@ -32,8 +32,8 @@ function getHook(pageContext, hookName) {
|
|
|
32
32
|
return { hookFn, hookName, hookFilePath, hookTimeout };
|
|
33
33
|
}
|
|
34
34
|
function getHookFromPageConfig(pageConfig, hookName) {
|
|
35
|
-
const configValue =
|
|
36
|
-
const hooksTimeout =
|
|
35
|
+
const configValue = getConfigValueRuntime(pageConfig, hookName);
|
|
36
|
+
const hooksTimeout = getConfigValueRuntime(pageConfig, 'hooksTimeout')?.value;
|
|
37
37
|
if (!configValue)
|
|
38
38
|
return null;
|
|
39
39
|
const hookFn = configValue.value;
|
|
@@ -16,9 +16,10 @@ export type { ConfigValuesComputed };
|
|
|
16
16
|
export type { DefinedAtData };
|
|
17
17
|
export type { DefinedAtFile };
|
|
18
18
|
export type { DefinedAtFilePath };
|
|
19
|
-
import type {
|
|
19
|
+
import type { ConfigValueSerialized } from './serialize/PageConfigSerialized.js';
|
|
20
20
|
import type { LocationId } from '../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js';
|
|
21
21
|
import type { FilePath } from './FilePath.js';
|
|
22
|
+
import type { ConfigDefinitions } from '../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js';
|
|
22
23
|
type PageConfigBase = {
|
|
23
24
|
pageId: string;
|
|
24
25
|
isErrorPage?: true;
|
|
@@ -26,13 +27,12 @@ type PageConfigBase = {
|
|
|
26
27
|
routeString: string;
|
|
27
28
|
definedBy: string;
|
|
28
29
|
};
|
|
29
|
-
configValues: ConfigValues;
|
|
30
30
|
};
|
|
31
31
|
/** Page config data structure available at runtime */
|
|
32
32
|
type PageConfigRuntime = PageConfigBase & {
|
|
33
|
+
configValues: ConfigValues;
|
|
33
34
|
/** Load config values that are lazily loaded such as config.Page */
|
|
34
35
|
loadConfigValuesAll: () => Promise<{
|
|
35
|
-
configValuesImported: ConfigValueImported[];
|
|
36
36
|
configValuesSerialized: Record<string, ConfigValueSerialized>;
|
|
37
37
|
}>;
|
|
38
38
|
};
|
|
@@ -43,6 +43,7 @@ type PageConfigRuntimeLoaded = PageConfigRuntime & {
|
|
|
43
43
|
};
|
|
44
44
|
/** Page config data structure available at build-time */
|
|
45
45
|
type PageConfigBuildTime = PageConfigBase & {
|
|
46
|
+
configDefinitions: ConfigDefinitions;
|
|
46
47
|
configValueSources: ConfigValueSources;
|
|
47
48
|
configValuesComputed: ConfigValuesComputed;
|
|
48
49
|
};
|
|
@@ -52,6 +53,7 @@ type PageConfigGlobalRuntime = {
|
|
|
52
53
|
};
|
|
53
54
|
type PageConfigGlobalBuildTime = {
|
|
54
55
|
configValueSources: ConfigValueSources;
|
|
56
|
+
configDefinitions: ConfigDefinitions;
|
|
55
57
|
};
|
|
56
58
|
/** In what environment(s) the config value is loaded.
|
|
57
59
|
*
|
|
@@ -65,18 +67,22 @@ type ConfigEnv = {
|
|
|
65
67
|
/** For Vike internal use */
|
|
66
68
|
type ConfigEnvInternal = Omit<ConfigEnv, 'client'> & {
|
|
67
69
|
client?: boolean | 'if-client-routing';
|
|
70
|
+
/** Always load value, not matter what page is loaded. */
|
|
68
71
|
eager?: boolean;
|
|
72
|
+
/** Load value only in production or only in development. */
|
|
73
|
+
production?: boolean;
|
|
69
74
|
};
|
|
70
75
|
type ConfigValueSource = {
|
|
71
76
|
value?: unknown;
|
|
72
77
|
configEnv: ConfigEnvInternal;
|
|
73
78
|
definedAtFilePath: DefinedAtFilePath;
|
|
74
79
|
locationId: LocationId;
|
|
80
|
+
isOverriden: boolean;
|
|
75
81
|
/** Wether the config value is loaded at runtime, for example config.Page or config.onBeforeRender */
|
|
76
82
|
valueIsImportedAtRuntime: boolean;
|
|
77
83
|
/** Whether the config value is a file path, for example config.client */
|
|
78
84
|
valueIsFilePath?: true;
|
|
79
|
-
|
|
85
|
+
valueIsDefinedByPlusFile: boolean;
|
|
80
86
|
};
|
|
81
87
|
type DefinedAtFilePath = DefinedAtFile & FilePath & {
|
|
82
88
|
fileExportName?: string;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export { getConfigValueRuntime };
|
|
2
|
+
export { getConfigValueTyped };
|
|
3
|
+
export type { TypeAsString };
|
|
4
|
+
import { type ResolveTypeAsString } from '../utils.js';
|
|
5
|
+
import type { PageConfigRuntime, ConfigValue } from './PageConfig.js';
|
|
3
6
|
import type { ConfigNameBuiltIn } from './Config.js';
|
|
4
|
-
type PageConfigCommon = PageConfigRuntime | PageConfigBuildTime;
|
|
5
7
|
type ConfigName = ConfigNameBuiltIn;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
value: unknown;
|
|
14
|
-
};
|
|
8
|
+
type TypeAsString = 'string' | 'boolean' | undefined;
|
|
9
|
+
declare function getConfigValueTyped<Type extends TypeAsString = undefined>(configValue: ConfigValue, configName: ConfigName, type?: Type): null | (ConfigValue & {
|
|
10
|
+
value: ResolveTypeAsString<Type>;
|
|
11
|
+
});
|
|
12
|
+
declare function getConfigValueRuntime<Type extends TypeAsString = undefined>(pageConfig: PageConfigRuntime, configName: ConfigName, type?: Type): null | (ConfigValue & {
|
|
13
|
+
value: ResolveTypeAsString<Type>;
|
|
14
|
+
});
|
|
@@ -1,18 +1,24 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getConfigValueRuntime };
|
|
2
|
+
export { getConfigValueTyped };
|
|
2
3
|
import { assert, assertUsage, getValuePrintable } from '../utils.js';
|
|
3
4
|
import pc from '@brillout/picocolors';
|
|
4
5
|
import { getConfigDefinedAtOptional } from './getConfigDefinedAt.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return null;
|
|
6
|
+
function getConfigValueTyped(configValue, configName, type) {
|
|
7
|
+
/* [NULL_HANDLING] Do we really need this? This doesn't seem to make sense, let's eventually (re)move this.
|
|
8
|
+
// Enable users to suppress global config values by setting the local config value to null
|
|
9
|
+
if (configValue.value === null) return null
|
|
10
|
+
*/
|
|
11
11
|
const { value, definedAtData } = configValue;
|
|
12
12
|
if (type)
|
|
13
13
|
assertConfigValueType(value, type, configName, definedAtData);
|
|
14
14
|
return configValue;
|
|
15
15
|
}
|
|
16
|
+
function getConfigValueRuntime(pageConfig, configName, type) {
|
|
17
|
+
const configValue = pageConfig.configValues[configName];
|
|
18
|
+
if (!configValue)
|
|
19
|
+
return null;
|
|
20
|
+
return getConfigValueTyped(configValue, configName, type);
|
|
21
|
+
}
|
|
16
22
|
function assertConfigValueType(value, type, configName, definedAtData) {
|
|
17
23
|
assert(value !== null);
|
|
18
24
|
const typeActual = typeof value;
|
|
@@ -26,12 +32,3 @@ function assertConfigValueType(value, type, configName, definedAtData) {
|
|
|
26
32
|
const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${pc.cyan(type)} instead`;
|
|
27
33
|
assertUsage(false, errMsg);
|
|
28
34
|
}
|
|
29
|
-
function getConfigValueEntry(pageConfig, configName) {
|
|
30
|
-
const configValue = pageConfig.configValues[configName];
|
|
31
|
-
if (!configValue)
|
|
32
|
-
return null;
|
|
33
|
-
// Enable users to suppress global config values by setting the local config value to null
|
|
34
|
-
if (configValue.value === null)
|
|
35
|
-
return null;
|
|
36
|
-
return configValue;
|
|
37
|
-
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { getConfigValueBuildTime };
|
|
2
|
+
import { type ResolveTypeAsString } from '../utils.js';
|
|
3
|
+
import type { PageConfigBuildTime, ConfigValue } from './PageConfig.js';
|
|
4
|
+
import type { ConfigNameBuiltIn } from './Config.js';
|
|
5
|
+
import { type TypeAsString } from './getConfigValue.js';
|
|
6
|
+
type ConfigName = ConfigNameBuiltIn;
|
|
7
|
+
declare function getConfigValueBuildTime<Type extends TypeAsString = undefined>(pageConfig: PageConfigBuildTime, configName: ConfigName, type?: Type): null | (ConfigValue & {
|
|
8
|
+
value: ResolveTypeAsString<Type>;
|
|
9
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
export { getConfigValueBuildTime };
|
|
2
|
+
import { assert } from '../utils.js';
|
|
3
|
+
import { getConfigValueTyped } from './getConfigValue.js';
|
|
4
|
+
import { assertIsNotProductionRuntime } from '../../utils/assertIsNotProductionRuntime.js';
|
|
5
|
+
assertIsNotProductionRuntime();
|
|
6
|
+
function getConfigValueBuildTime(pageConfig, configName, type) {
|
|
7
|
+
const configValue = getConfigValue(pageConfig, configName);
|
|
8
|
+
if (!configValue)
|
|
9
|
+
return null;
|
|
10
|
+
return getConfigValueTyped(configValue, configName, type);
|
|
11
|
+
}
|
|
12
|
+
function getConfigValue(pageConfig, configName) {
|
|
13
|
+
const { configValueSources, configValuesComputed, configDefinitions } = pageConfig;
|
|
14
|
+
const configValueComputed = configValuesComputed[configName];
|
|
15
|
+
if (configValueComputed) {
|
|
16
|
+
return {
|
|
17
|
+
type: 'computed',
|
|
18
|
+
value: configValueComputed.value,
|
|
19
|
+
definedAtData: null
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
const sources = configValueSources[configName];
|
|
23
|
+
if (!sources)
|
|
24
|
+
return null;
|
|
25
|
+
assert(sources.every((s) => s.configEnv.config === true));
|
|
26
|
+
const configDef = configDefinitions[configName];
|
|
27
|
+
assert(configDef);
|
|
28
|
+
if (!configDef.cumulative) {
|
|
29
|
+
const configValueSource = sources[0];
|
|
30
|
+
assert(configValueSource);
|
|
31
|
+
assert(configValueSource.isOverriden === false);
|
|
32
|
+
assert(sources.slice(1).every((s) => s.isOverriden === true));
|
|
33
|
+
assert('value' in configValueSource);
|
|
34
|
+
return {
|
|
35
|
+
type: 'standard',
|
|
36
|
+
value: configValueSource.value,
|
|
37
|
+
definedAtData: getDefinedAtFile(configValueSource)
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const { value, definedAtData } = mergeCumulative(sources);
|
|
42
|
+
assert(value.length === definedAtData.length);
|
|
43
|
+
return {
|
|
44
|
+
type: 'cumulative',
|
|
45
|
+
value,
|
|
46
|
+
definedAtData
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function mergeCumulative(configValueSources) {
|
|
51
|
+
const value = [];
|
|
52
|
+
const definedAtData = [];
|
|
53
|
+
configValueSources.forEach((configValueSource) => {
|
|
54
|
+
assert(configValueSource.isOverriden === false);
|
|
55
|
+
assert(configValueSource.configEnv.config === true);
|
|
56
|
+
assert('value' in configValueSource);
|
|
57
|
+
value.push(configValueSource.value);
|
|
58
|
+
definedAtData.push(getDefinedAtFile(configValueSource));
|
|
59
|
+
});
|
|
60
|
+
return { value, definedAtData };
|
|
61
|
+
}
|
|
62
|
+
function getDefinedAtFile(configValueSource) {
|
|
63
|
+
return {
|
|
64
|
+
filePathToShowToUser: configValueSource.definedAtFilePath.filePathToShowToUser,
|
|
65
|
+
fileExportPathToShowToUser: configValueSource.definedAtFilePath.fileExportPathToShowToUser
|
|
66
|
+
};
|
|
67
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
export { loadConfigValues };
|
|
2
2
|
import { objectAssign } from '../utils.js';
|
|
3
|
-
import {
|
|
4
|
-
import { parseConfigValuesSerialized } from './serialize/parseConfigValuesSerialized.js';
|
|
3
|
+
import { parseConfigValuesSerialized } from './serialize/parsePageConfigs.js';
|
|
5
4
|
async function loadConfigValues(pageConfig, isDev) {
|
|
6
5
|
if ('isAllLoaded' in pageConfig &&
|
|
7
6
|
// We don't need to cache in dev, since Vite already caches the virtual module
|
|
@@ -9,16 +8,8 @@ async function loadConfigValues(pageConfig, isDev) {
|
|
|
9
8
|
return pageConfig;
|
|
10
9
|
}
|
|
11
10
|
const configValuesLoaded = await pageConfig.loadConfigValuesAll();
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const configValuesAddendum = parseConfigValuesImported(configValuesImported);
|
|
15
|
-
Object.assign(pageConfig.configValues, configValuesAddendum);
|
|
16
|
-
}
|
|
17
|
-
{
|
|
18
|
-
const { configValuesSerialized } = configValuesLoaded;
|
|
19
|
-
const configValuesAddendum = parseConfigValuesSerialized(configValuesSerialized);
|
|
20
|
-
Object.assign(pageConfig.configValues, configValuesAddendum);
|
|
21
|
-
}
|
|
11
|
+
const configValues = parseConfigValuesSerialized(configValuesLoaded.configValuesSerialized);
|
|
12
|
+
Object.assign(pageConfig.configValues, configValues);
|
|
22
13
|
objectAssign(pageConfig, { isAllLoaded: true });
|
|
23
14
|
return pageConfig;
|
|
24
15
|
}
|
|
@@ -1,35 +1,31 @@
|
|
|
1
1
|
export type { PageConfigRuntimeSerialized };
|
|
2
2
|
export type { PageConfigGlobalRuntimeSerialized };
|
|
3
3
|
export type { ConfigValueSerialized };
|
|
4
|
-
export type {
|
|
4
|
+
export type { ValueSerialized };
|
|
5
5
|
import type { ConfigValueStandard, ConfigValueComputed, ConfigValueCumulative, PageConfigRuntime } from '../PageConfig.js';
|
|
6
6
|
/** Page config data structure serialized in virtual files: parsing it results in PageConfigRuntime */
|
|
7
7
|
type PageConfigRuntimeSerialized = Omit<PageConfigRuntime, 'configValues'> & {
|
|
8
8
|
/** Config values that are serializable and loaded eagerly such as config.passToClient */
|
|
9
9
|
configValuesSerialized: Record<string, ConfigValueSerialized>;
|
|
10
|
-
/** Config values imported eagerly such as config.route */
|
|
11
|
-
configValuesImported: ConfigValueImported[];
|
|
12
10
|
};
|
|
13
11
|
type PageConfigGlobalRuntimeSerialized = {
|
|
14
|
-
|
|
12
|
+
configValuesSerialized: Record<string, ConfigValueSerialized>;
|
|
13
|
+
};
|
|
14
|
+
type ValueSerialized = {
|
|
15
|
+
type: 'js-serialized';
|
|
16
|
+
value: unknown;
|
|
17
|
+
} | {
|
|
18
|
+
type: 'plus-file';
|
|
19
|
+
exportValues: Record<string, unknown>;
|
|
20
|
+
} | {
|
|
21
|
+
type: 'pointer-import';
|
|
22
|
+
value: unknown;
|
|
15
23
|
};
|
|
16
24
|
/** Value is serialized */
|
|
17
25
|
type ConfigValueSerialized = (Omit<ConfigValueStandard, 'value'> & {
|
|
18
|
-
valueSerialized:
|
|
26
|
+
valueSerialized: ValueSerialized;
|
|
19
27
|
}) | (Omit<ConfigValueCumulative, 'value'> & {
|
|
20
|
-
valueSerialized:
|
|
28
|
+
valueSerialized: ValueSerialized[];
|
|
21
29
|
}) | (Omit<ConfigValueComputed, 'value'> & {
|
|
22
|
-
valueSerialized:
|
|
23
|
-
});
|
|
24
|
-
/** Value is imported */
|
|
25
|
-
type ConfigValueImported = {
|
|
26
|
-
configName: string;
|
|
27
|
-
importPath: string;
|
|
28
|
-
} & ({
|
|
29
|
-
isValueFile: true;
|
|
30
|
-
exportValues: Record<string, unknown>;
|
|
31
|
-
} | {
|
|
32
|
-
isValueFile: false;
|
|
33
|
-
exportName: string;
|
|
34
|
-
exportValue: unknown;
|
|
30
|
+
valueSerialized: ValueSerialized;
|
|
35
31
|
});
|
|
@@ -8,9 +8,8 @@ function assertPageConfigsSerialized(pageConfigsSerialized) {
|
|
|
8
8
|
assert(hasProp(pageConfigSerialized, 'pageId', 'string'));
|
|
9
9
|
assert(hasProp(pageConfigSerialized, 'routeFilesystem'));
|
|
10
10
|
assert(hasProp(pageConfigSerialized, 'configValuesSerialized'));
|
|
11
|
-
assert(hasProp(pageConfigSerialized, 'configValuesImported'));
|
|
12
11
|
});
|
|
13
12
|
}
|
|
14
13
|
function assertPageConfigGlobalSerialized(pageConfigGlobalSerialized) {
|
|
15
|
-
assert(hasProp(pageConfigGlobalSerialized, '
|
|
14
|
+
assert(hasProp(pageConfigGlobalSerialized, 'configValuesSerialized'));
|
|
16
15
|
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export { parsePageConfigs };
|
|
2
|
-
|
|
2
|
+
export { parseConfigValuesSerialized };
|
|
3
|
+
import type { ConfigValues, PageConfigRuntime, PageConfigGlobalRuntime } from '../PageConfig.js';
|
|
3
4
|
import type { PageConfigGlobalRuntimeSerialized, PageConfigRuntimeSerialized } from './PageConfigSerialized.js';
|
|
5
|
+
import type { ConfigValueSerialized } from './PageConfigSerialized.js';
|
|
6
|
+
declare function parseConfigValuesSerialized(configValuesSerialized: Record<string, ConfigValueSerialized>): ConfigValues;
|
|
4
7
|
declare function parsePageConfigs(pageConfigsSerialized: PageConfigRuntimeSerialized[], pageConfigGlobalSerialized: PageConfigGlobalRuntimeSerialized): {
|
|
5
8
|
pageConfigs: PageConfigRuntime[];
|
|
6
9
|
pageConfigGlobal: PageConfigGlobalRuntime;
|