vike 0.4.171 → 0.4.172
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/devConfig/index.js +2 -1
- package/dist/cjs/node/plugin/plugins/envVars.js +2 -1
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/{generateEagerImport.js → addImportStatement.js} +8 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +0 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +31 -75
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +4 -43
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +9 -50
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +6 -0
- package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +17 -2
- package/dist/cjs/node/prerender/runPrerender.js +35 -15
- package/dist/cjs/node/prerender/utils.js +1 -0
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +3 -3
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScripts.js +2 -1
- package/dist/cjs/node/runtime/html/injectAssets/mergeScriptTags.js +2 -8
- package/dist/cjs/node/runtime/html/renderHtml.js +19 -20
- package/dist/cjs/node/runtime/html/stream.js +9 -9
- 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/executeOnBeforeRenderAndDataHooks.js +2 -2
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -8
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +2 -2
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +4 -5
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +91 -282
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +2 -2
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +30 -10
- package/dist/cjs/node/runtime/renderPage.js +17 -13
- package/dist/cjs/node/runtime/utils.js +2 -0
- package/dist/cjs/node/shared/assertV1Design.js +3 -4
- package/dist/cjs/shared/getPageContext.js +5 -0
- package/dist/cjs/shared/{addUrlComputedProps.js → getPageContextUrlComputed.js} +52 -42
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +2 -2
- package/dist/cjs/shared/getPageFiles/getExports.js +49 -1
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +15 -8
- package/dist/cjs/shared/hooks/executeHook.js +22 -3
- 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 +0 -18
- 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/executeGuardHook.js +1 -1
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +1 -1
- package/dist/cjs/shared/route/index.js +2 -2
- package/dist/cjs/shared/route/loadPageRoutes.js +2 -2
- package/dist/cjs/shared/route/resolveRouteFunction.js +2 -2
- package/dist/cjs/shared/sortPageContext.js +4 -8
- package/dist/cjs/shared/utils.js +2 -0
- package/dist/cjs/utils/assert.js +1 -1
- package/dist/cjs/utils/assertNodeVersion.js +1 -1
- package/dist/cjs/utils/changeEnumerable.js +9 -0
- package/dist/cjs/utils/escapeHtml.js +14 -0
- package/dist/cjs/utils/getPropAccessNotation.js +1 -4
- package/dist/cjs/utils/hasProp.js +5 -7
- package/dist/cjs/utils/normalizeHeaders.js +13 -0
- package/dist/cjs/utils/objectAssign.js +1 -1
- package/dist/cjs/utils/objectDefineProperty.js +8 -0
- package/dist/cjs/utils/objectKeys.js +8 -4
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +6 -4
- package/dist/esm/client/client-routing-runtime/createPageContext.js +4 -3
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +16 -12
- package/dist/esm/client/client-routing-runtime/installClientRouter.js +18 -10
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +3 -3
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +4 -4
- package/dist/esm/client/server-routing-runtime/utils.d.ts +1 -0
- package/dist/esm/client/server-routing-runtime/utils.js +1 -0
- package/dist/esm/client/shared/executeOnRenderClientHook.js +1 -1
- package/dist/esm/client/shared/getPageContextProxyForUser.d.ts +3 -2
- package/dist/esm/client/shared/getPageContextProxyForUser.js +35 -48
- package/dist/esm/client/shared/loadUserFilesClientSide.js +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/devConfig/index.js +2 -1
- package/dist/esm/node/plugin/plugins/envVars.js +2 -1
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/addImportStatement.d.ts +14 -0
- package/dist/esm/node/plugin/plugins/importUserCode/{generateEagerImport.js → addImportStatement.js} +7 -9
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +0 -1
- 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/loadFileAtConfigTime.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +31 -75
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +4 -43
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +9 -50
- 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/plugin/shared/addSsrMiddleware.js +14 -2
- package/dist/esm/node/prerender/runPrerender.js +37 -17
- package/dist/esm/node/prerender/utils.d.ts +1 -0
- package/dist/esm/node/prerender/utils.js +1 -0
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +3 -3
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScripts.js +3 -2
- package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.d.ts +1 -1
- package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.js +2 -8
- package/dist/esm/node/runtime/html/renderHtml.js +19 -20
- package/dist/esm/node/runtime/html/stream.d.ts +1 -1
- package/dist/esm/node/runtime/html/stream.js +9 -9
- 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/executeOnBeforeRenderAndDataHooks.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -8
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +1 -6
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +4 -5
- package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +2 -6
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +92 -283
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +65 -39
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +31 -11
- package/dist/esm/node/runtime/renderPage.js +17 -13
- package/dist/esm/node/runtime/utils.d.ts +2 -0
- package/dist/esm/node/runtime/utils.js +2 -0
- package/dist/esm/node/shared/assertV1Design.d.ts +2 -2
- package/dist/esm/node/shared/assertV1Design.js +3 -4
- package/dist/esm/shared/VikeNamespace.d.ts +9 -0
- package/dist/esm/shared/getPageContext.d.ts +1 -0
- package/dist/esm/shared/getPageContext.js +1 -0
- package/dist/esm/shared/{addUrlComputedProps.d.ts → getPageContextUrlComputed.d.ts} +23 -21
- package/dist/esm/shared/{addUrlComputedProps.js → getPageContextUrlComputed.js} +52 -42
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +3 -3
- package/dist/esm/shared/getPageFiles/getExports.d.ts +36 -0
- package/dist/esm/shared/getPageFiles/getExports.js +50 -2
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +14 -7
- package/dist/esm/shared/hooks/executeHook.d.ts +10 -1
- package/dist/esm/shared/hooks/executeHook.js +21 -2
- 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/Config/PageContextConfig.d.ts +2 -2
- package/dist/esm/shared/page-configs/PageConfig.d.ts +14 -8
- 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 +17 -21
- package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.d.ts +1 -5
- package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.js +1 -16
- 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/executeGuardHook.js +1 -1
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +1 -1
- package/dist/esm/shared/route/index.d.ts +3 -3
- package/dist/esm/shared/route/index.js +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +3 -3
- package/dist/esm/shared/route/resolveRouteFunction.d.ts +2 -2
- package/dist/esm/shared/route/resolveRouteFunction.js +2 -2
- package/dist/esm/shared/sortPageContext.js +4 -8
- package/dist/esm/shared/types.d.ts +32 -6
- package/dist/esm/shared/utils.d.ts +2 -0
- package/dist/esm/shared/utils.js +2 -0
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/assert.js +1 -1
- package/dist/esm/utils/assertNodeVersion.js +1 -1
- package/dist/esm/utils/changeEnumerable.d.ts +2 -0
- package/dist/esm/utils/changeEnumerable.js +5 -0
- package/dist/esm/utils/escapeHtml.d.ts +1 -0
- package/dist/esm/utils/escapeHtml.js +10 -0
- package/dist/esm/utils/getPropAccessNotation.d.ts +1 -2
- package/dist/esm/utils/getPropAccessNotation.js +2 -6
- package/dist/esm/utils/hasProp.d.ts +4 -13
- package/dist/esm/utils/hasProp.js +5 -7
- package/dist/esm/utils/normalizeHeaders.d.ts +1 -0
- package/dist/esm/utils/normalizeHeaders.js +9 -0
- package/dist/esm/utils/objectAssign.js +1 -1
- package/dist/esm/utils/objectDefineProperty.d.ts +4 -0
- package/dist/esm/utils/objectDefineProperty.js +4 -0
- package/dist/esm/utils/objectKeys.d.ts +1 -3
- package/dist/esm/utils/objectKeys.js +8 -4
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +21 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +0 -76
- 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 -50
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.d.ts +0 -16
- 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 -70
- 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 -8
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +0 -47
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
export { executeHook };
|
|
2
|
+
export { getPageContext };
|
|
2
3
|
export { isUserHookError };
|
|
3
4
|
import { getProjectError, assertWarning } from '../../utils/assert.js';
|
|
4
5
|
import { getGlobalObject } from '../../utils/getGlobalObject.js';
|
|
5
6
|
import { humanizeTime } from '../../utils/humanizeTime.js';
|
|
6
7
|
import { isObject } from '../../utils/isObject.js';
|
|
7
8
|
const globalObject = getGlobalObject('utils/executeHook.ts', {
|
|
8
|
-
userHookErrors: new WeakMap()
|
|
9
|
+
userHookErrors: new WeakMap(),
|
|
10
|
+
pageContext: null
|
|
9
11
|
});
|
|
10
12
|
function isUserHookError(err) {
|
|
11
13
|
if (!isObject(err))
|
|
12
14
|
return false;
|
|
13
15
|
return globalObject.userHookErrors.get(err) ?? false;
|
|
14
16
|
}
|
|
15
|
-
function executeHook(hookFnCaller, hook) {
|
|
17
|
+
function executeHook(hookFnCaller, hook, pageContext) {
|
|
16
18
|
const { hookName, hookFilePath, hookTimeout: { error: timeoutErr, warning: timeoutWarn } } = hook;
|
|
17
19
|
let resolve;
|
|
18
20
|
let reject;
|
|
@@ -43,6 +45,7 @@ function executeHook(hookFnCaller, hook) {
|
|
|
43
45
|
}, timeoutErr);
|
|
44
46
|
(async () => {
|
|
45
47
|
try {
|
|
48
|
+
providePageContext(pageContext);
|
|
46
49
|
const ret = await hookFnCaller();
|
|
47
50
|
resolve(ret);
|
|
48
51
|
}
|
|
@@ -58,3 +61,19 @@ function executeHook(hookFnCaller, hook) {
|
|
|
58
61
|
function isNotDisabled(timeout) {
|
|
59
62
|
return !!timeout && timeout !== Infinity;
|
|
60
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Access `pageContext` object inside Vike hooks, in order to create universal hooks.
|
|
66
|
+
*
|
|
67
|
+
* https://vike.dev/getPageContext
|
|
68
|
+
*/
|
|
69
|
+
function getPageContext() {
|
|
70
|
+
return globalObject.pageContext;
|
|
71
|
+
}
|
|
72
|
+
function providePageContext(pageContext) {
|
|
73
|
+
globalObject.pageContext = pageContext;
|
|
74
|
+
// Promise.resolve() is quicker than process.nextTick() and setImmediate()
|
|
75
|
+
// https://stackoverflow.com/questions/67949576/process-nexttick-before-promise-resolve-then
|
|
76
|
+
Promise.resolve().then(() => {
|
|
77
|
+
globalObject.pageContext = null;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
@@ -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;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export type { PageContextConfig };
|
|
2
2
|
import type { VikePackages } from '../../VikeNamespace.js';
|
|
3
3
|
import type { ConfigBuiltIn } from '../Config.js';
|
|
4
|
-
import type { Combine, IsNotEmpty, XOR5 } from './helpers.
|
|
5
|
-
type PageContextConfig = ConfigBuiltIn & Vike.Config & (ConfigVikePackagesNotEmptyXor extends true ? ConfigVikePackagesIntersection : ConfigVikePackagesCombined);
|
|
4
|
+
import type { Combine, IsNotEmpty, XOR5 } from './helpers.js';
|
|
5
|
+
type PageContextConfig = ConfigBuiltIn & Vike.ConfigResolved & Omit<Vike.Config, keyof Vike.ConfigResolved> & (ConfigVikePackagesNotEmptyXor extends true ? ConfigVikePackagesIntersection : ConfigVikePackagesCombined);
|
|
6
6
|
type ConfigVikePackagesIntersection = VikePackages.ConfigVikeReact & VikePackages.ConfigVikeVue & VikePackages.ConfigVikeSolid & VikePackages.ConfigVikeSvelte & VikePackages.ConfigVikeAngular;
|
|
7
7
|
type ConfigVikePackagesCombined = Combine<VikePackages.ConfigVikeReact, Combine<VikePackages.ConfigVikeVue, Combine<VikePackages.ConfigVikeSolid, Combine<VikePackages.ConfigVikeSvelte, VikePackages.ConfigVikeAngular>>>>;
|
|
8
8
|
type ConfigVikePackagesNotEmptyXor = XOR5<IsNotEmpty<VikePackages.ConfigVikeReact>, IsNotEmpty<VikePackages.ConfigVikeVue>, IsNotEmpty<VikePackages.ConfigVikeSolid>, IsNotEmpty<VikePackages.ConfigVikeSvelte>, IsNotEmpty<VikePackages.ConfigVikeAngular>>;
|
|
@@ -6,7 +6,7 @@ export type { ConfigEnvInternal };
|
|
|
6
6
|
export type { PageConfigGlobalRuntime };
|
|
7
7
|
export type { PageConfigGlobalBuildTime };
|
|
8
8
|
export type { ConfigValue };
|
|
9
|
-
export type {
|
|
9
|
+
export type { ConfigValueStandard };
|
|
10
10
|
export type { ConfigValueCumulative };
|
|
11
11
|
export type { ConfigValueComputed };
|
|
12
12
|
export type { ConfigValues };
|
|
@@ -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;
|
|
@@ -86,10 +92,10 @@ type ConfigValuesComputed = Record<string, {
|
|
|
86
92
|
configEnv: ConfigEnvInternal;
|
|
87
93
|
value: unknown;
|
|
88
94
|
}>;
|
|
89
|
-
type ConfigValue =
|
|
95
|
+
type ConfigValue = ConfigValueStandard | ConfigValueCumulative | ConfigValueComputed;
|
|
90
96
|
/** Defined by a unique source (thus unique file path). */
|
|
91
|
-
type
|
|
92
|
-
type: '
|
|
97
|
+
type ConfigValueStandard = {
|
|
98
|
+
type: 'standard';
|
|
93
99
|
value: unknown;
|
|
94
100
|
definedAtData: DefinedAtFile;
|
|
95
101
|
};
|
|
@@ -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 {
|
|
5
|
-
import type {
|
|
4
|
+
export type { ValueSerialized };
|
|
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
|
-
type ConfigValueSerialized = (Omit<
|
|
18
|
-
valueSerialized:
|
|
25
|
+
type ConfigValueSerialized = (Omit<ConfigValueStandard, 'value'> & {
|
|
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
|
});
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { assertPageConfigGlobalSerialized };
|
|
3
|
-
import type { PageConfigGlobalRuntimeSerialized, PageConfigRuntimeSerialized } from './PageConfigSerialized.js';
|
|
4
|
-
declare function assertPageConfigsSerialized(pageConfigsSerialized: unknown): asserts pageConfigsSerialized is PageConfigRuntimeSerialized[];
|
|
5
|
-
declare function assertPageConfigGlobalSerialized(pageConfigGlobalSerialized: unknown): asserts pageConfigGlobalSerialized is PageConfigGlobalRuntimeSerialized;
|
|
1
|
+
export {};
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { assertPageConfigGlobalSerialized };
|
|
3
|
-
import { assert, isObject, hasProp, isArray } from '../../utils.js';
|
|
4
|
-
function assertPageConfigsSerialized(pageConfigsSerialized) {
|
|
5
|
-
assert(isArray(pageConfigsSerialized));
|
|
6
|
-
pageConfigsSerialized.forEach((pageConfigSerialized) => {
|
|
7
|
-
assert(isObject(pageConfigSerialized));
|
|
8
|
-
assert(hasProp(pageConfigSerialized, 'pageId', 'string'));
|
|
9
|
-
assert(hasProp(pageConfigSerialized, 'routeFilesystem'));
|
|
10
|
-
assert(hasProp(pageConfigSerialized, 'configValuesSerialized'));
|
|
11
|
-
assert(hasProp(pageConfigSerialized, 'configValuesImported'));
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
function assertPageConfigGlobalSerialized(pageConfigGlobalSerialized) {
|
|
15
|
-
assert(hasProp(pageConfigGlobalSerialized, 'configValuesImported'));
|
|
16
|
-
}
|
|
1
|
+
export {};
|
|
@@ -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;
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
export { parsePageConfigs };
|
|
2
|
-
|
|
2
|
+
export { parseConfigValuesSerialized };
|
|
3
3
|
import { assert, assertUsage, isCallable } from '../../utils.js';
|
|
4
4
|
import { getConfigDefinedAt } from '../getConfigDefinedAt.js';
|
|
5
|
-
import {
|
|
5
|
+
import { parseTransform } from '@brillout/json-serializer/parse';
|
|
6
|
+
import { assertPlusFileExport } from '../assertPlusFileExport.js';
|
|
7
|
+
function parseConfigValuesSerialized(configValuesSerialized) {
|
|
8
|
+
const configValues = parseConfigValuesSerialized_tmp(configValuesSerialized);
|
|
9
|
+
return configValues;
|
|
10
|
+
}
|
|
6
11
|
function parsePageConfigs(pageConfigsSerialized, pageConfigGlobalSerialized) {
|
|
12
|
+
// pageConfigs
|
|
7
13
|
const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
|
|
8
|
-
const configValues =
|
|
9
|
-
{
|
|
10
|
-
const { configValuesSerialized } = pageConfigSerialized;
|
|
11
|
-
const configValuesAddendum = parseConfigValuesSerialized(configValuesSerialized);
|
|
12
|
-
Object.assign(configValues, configValuesAddendum);
|
|
13
|
-
}
|
|
14
|
-
{
|
|
15
|
-
const { configValuesImported } = pageConfigSerialized;
|
|
16
|
-
const configValuesAddendum = parseConfigValuesImported(configValuesImported);
|
|
17
|
-
Object.assign(configValues, configValuesAddendum);
|
|
18
|
-
}
|
|
14
|
+
const configValues = parseConfigValuesSerialized(pageConfigSerialized.configValuesSerialized);
|
|
19
15
|
const { pageId, isErrorPage, routeFilesystem, loadConfigValuesAll } = pageConfigSerialized;
|
|
20
16
|
assertRouteConfigValue(configValues);
|
|
21
17
|
return {
|
|
@@ -26,10 +22,11 @@ function parsePageConfigs(pageConfigsSerialized, pageConfigGlobalSerialized) {
|
|
|
26
22
|
loadConfigValuesAll
|
|
27
23
|
};
|
|
28
24
|
});
|
|
25
|
+
// pageConfigsGlobal
|
|
29
26
|
const pageConfigGlobal = { configValues: {} };
|
|
30
27
|
{
|
|
31
|
-
const
|
|
32
|
-
Object.assign(pageConfigGlobal.configValues,
|
|
28
|
+
const configValues = parseConfigValuesSerialized(pageConfigGlobalSerialized.configValuesSerialized);
|
|
29
|
+
Object.assign(pageConfigGlobal.configValues, configValues);
|
|
33
30
|
}
|
|
34
31
|
return { pageConfigs, pageConfigGlobal };
|
|
35
32
|
}
|
|
@@ -52,3 +49,100 @@ function assertRouteConfigValue(configValues) {
|
|
|
52
49
|
}
|
|
53
50
|
*/
|
|
54
51
|
}
|
|
52
|
+
function parseConfigValuesSerialized_tmp(configValuesSerialized) {
|
|
53
|
+
const configValues = {};
|
|
54
|
+
Object.entries(configValuesSerialized).forEach(([configName, configValueSeriliazed]) => {
|
|
55
|
+
let configValue;
|
|
56
|
+
if (configValueSeriliazed.type === 'cumulative') {
|
|
57
|
+
const { valueSerialized, ...common } = configValueSeriliazed;
|
|
58
|
+
const value = valueSerialized.map((valueSerializedElement, i) => {
|
|
59
|
+
const { value, sideExports } = parseValueSerialized(valueSerializedElement, configName, () => {
|
|
60
|
+
const definedAtFile = configValueSeriliazed.definedAtData[i];
|
|
61
|
+
assert(definedAtFile);
|
|
62
|
+
return definedAtFile;
|
|
63
|
+
});
|
|
64
|
+
addSideExports(sideExports);
|
|
65
|
+
return value;
|
|
66
|
+
});
|
|
67
|
+
configValue = { value, ...common };
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const { valueSerialized, ...common } = configValueSeriliazed;
|
|
71
|
+
const { value, sideExports } = parseValueSerialized(valueSerialized, configName, () => {
|
|
72
|
+
assert(configValueSeriliazed.type !== 'computed');
|
|
73
|
+
return configValueSeriliazed.definedAtData;
|
|
74
|
+
});
|
|
75
|
+
addSideExports(sideExports);
|
|
76
|
+
configValue = { value, ...common };
|
|
77
|
+
}
|
|
78
|
+
configValues[configName] = configValue;
|
|
79
|
+
});
|
|
80
|
+
return configValues;
|
|
81
|
+
function addSideExports(sideExports) {
|
|
82
|
+
sideExports.forEach((sideExport) => {
|
|
83
|
+
const { configName, configValue } = sideExport;
|
|
84
|
+
if (!configValues[configName]) {
|
|
85
|
+
configValues[configName] = configValue;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// Side-exports have lower precedence.
|
|
89
|
+
// We can't avoid side-export conflicts upstream. (We cannot know about side-exports at build-time.)
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function parseValueSerialized(valueSerialized, configName, getDefinedAtFile) {
|
|
95
|
+
if (valueSerialized.type === 'js-serialized') {
|
|
96
|
+
let { value } = valueSerialized;
|
|
97
|
+
value = parseTransform(value);
|
|
98
|
+
return { value, sideExports: [] };
|
|
99
|
+
}
|
|
100
|
+
if (valueSerialized.type === 'pointer-import') {
|
|
101
|
+
const { value } = valueSerialized;
|
|
102
|
+
return { value, sideExports: [] };
|
|
103
|
+
}
|
|
104
|
+
if (valueSerialized.type === 'plus-file') {
|
|
105
|
+
const definedAtFile = getDefinedAtFile();
|
|
106
|
+
const { exportValues } = valueSerialized;
|
|
107
|
+
assertPlusFileExport(exportValues, definedAtFile.filePathToShowToUser, configName);
|
|
108
|
+
let value;
|
|
109
|
+
let valueWasFound = false;
|
|
110
|
+
const sideExports = [];
|
|
111
|
+
Object.entries(exportValues).forEach(([exportName, exportValue]) => {
|
|
112
|
+
const isSideExport = exportName !== 'default' && exportName !== configName;
|
|
113
|
+
if (!isSideExport) {
|
|
114
|
+
value = exportValue;
|
|
115
|
+
assert(!valueWasFound);
|
|
116
|
+
valueWasFound = true;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
sideExports.push({
|
|
120
|
+
configName: exportName,
|
|
121
|
+
configValue: {
|
|
122
|
+
type: 'standard', // We don't support side exports for cumulative values. We could support it but it isn't trivial.
|
|
123
|
+
value: exportValue,
|
|
124
|
+
definedAtData: {
|
|
125
|
+
filePathToShowToUser: definedAtFile.filePathToShowToUser,
|
|
126
|
+
fileExportPathToShowToUser: [exportName]
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
assert(valueWasFound);
|
|
133
|
+
return { value, sideExports };
|
|
134
|
+
}
|
|
135
|
+
assert(false);
|
|
136
|
+
}
|
|
137
|
+
/* [NULL_HANDLING] Do we really need this?
|
|
138
|
+
function assertIsNotNull(configValue: unknown, configName: string, filePathToShowToUser: string) {
|
|
139
|
+
assert(!filePathToShowToUser.includes('+config.'))
|
|
140
|
+
// Re-use this for:
|
|
141
|
+
// - upcoming config.requestPageContextOnNavigation
|
|
142
|
+
// - for cumulative values in the future: we don't need this for now because, currently, cumulative values are never imported.
|
|
143
|
+
assertUsage(
|
|
144
|
+
configValue !== null,
|
|
145
|
+
`Set ${pc.cyan(configName)} to ${pc.cyan('null')} in a +config.js file instead of ${filePathToShowToUser}`
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
*/
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { serializeConfigValues };
|
|
2
|
+
import type { ConfigEnvInternal, PageConfigBuildTime, PageConfigGlobalBuildTime } from '../PageConfig.js';
|
|
3
|
+
declare function serializeConfigValues(pageConfig: PageConfigBuildTime | (PageConfigGlobalBuildTime & {
|
|
4
|
+
configValuesComputed?: undefined;
|
|
5
|
+
}), importStatements: string[], isEnvMatch: (configEnv: ConfigEnvInternal) => boolean, tabspace: string): string[];
|