vike 0.4.218 → 0.4.220-commit-a9f46b8
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/__internal/index.js +11 -11
- package/dist/cjs/node/api/build.js +22 -48
- package/dist/cjs/node/api/context.js +8 -6
- package/dist/cjs/node/api/index.js +17 -7
- package/dist/cjs/node/api/prepareViteApiCall.js +40 -13
- package/dist/cjs/node/cli/context.js +16 -0
- package/dist/cjs/node/cli/entry.js +21 -7
- package/dist/cjs/node/cli/utils.js +1 -0
- package/dist/cjs/node/plugin/index.js +5 -5
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +32 -20
- package/dist/cjs/node/plugin/plugins/baseUrls.js +3 -10
- package/dist/cjs/node/plugin/plugins/buildConfig.js +2 -2
- package/dist/cjs/node/plugin/plugins/{importBuild → buildEntry}/index.js +16 -17
- package/dist/cjs/node/plugin/plugins/commonConfig.js +41 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +26 -23
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +171 -68
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +7 -5
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +1 -1
- package/dist/cjs/node/plugin/plugins/{vite6HmrRegressionWorkaround.js → workaroundVite6HmrRegression.js} +3 -3
- package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +17 -7
- package/dist/cjs/node/prerender/context.js +24 -0
- package/dist/cjs/node/prerender/runPrerender.js +146 -96
- package/dist/cjs/node/prerender/utils.js +2 -0
- package/dist/cjs/node/runtime/globalContext.js +109 -55
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/cjs/node/runtime/index-common.js +0 -15
- package/dist/cjs/node/runtime/onLoad.js +17 -3
- package/dist/cjs/node/runtime/page-files/setup.js +2 -4
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/createHttpResponse/getCacheControl.js +2 -2
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +11 -33
- package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +9 -1
- package/dist/cjs/node/runtime/renderPage.js +21 -22
- package/dist/cjs/node/runtime/utils.js +2 -0
- package/dist/cjs/node/runtime-dev/index.js +17 -7
- package/dist/cjs/node/shared/assertRuntimeManifest.js +0 -2
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +3 -3
- package/dist/cjs/shared/getPageFiles/{setPageFiles.js → getPageFiles.js} +8 -6
- package/dist/cjs/shared/getPageFiles.js +3 -9
- package/dist/cjs/shared/hooks/getHook.js +3 -3
- package/dist/cjs/shared/{getPageFiles/getExports.js → page-configs/getPageConfigUserFriendly.js} +113 -81
- package/dist/cjs/shared/page-configs/loadConfigValues.js +5 -1
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +80 -55
- package/dist/cjs/shared/route/loadPageRoutes.js +3 -3
- package/dist/cjs/shared/utils.js +1 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assert.js +4 -3
- package/dist/cjs/utils/assertSetup.js +47 -16
- package/dist/cjs/utils/catchInfiniteLoop.js +34 -0
- package/dist/cjs/utils/debug.js +11 -6
- package/dist/cjs/utils/getGlobalObject.js +1 -2
- package/dist/cjs/utils/isDev.js +2 -0
- package/dist/cjs/utils/makePublicCopy.js +32 -0
- package/dist/cjs/utils/objectReplace.js +9 -0
- package/dist/esm/__internal/index.d.ts +3 -5
- package/dist/esm/__internal/index.js +6 -8
- package/dist/esm/client/client-routing-runtime/createPageContext.js +4 -1
- package/dist/esm/client/client-routing-runtime/entry.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/entry.js +0 -1
- package/dist/esm/client/client-routing-runtime/getPageContextCurrent.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +4 -4
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +1 -1
- package/dist/esm/client/client-routing-runtime/history.d.ts +3 -1
- package/dist/esm/client/client-routing-runtime/history.js +23 -18
- package/dist/esm/client/client-routing-runtime/index.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/index.js +0 -1
- package/dist/esm/client/client-routing-runtime/initClientRouter.js +2 -2
- package/dist/esm/client/client-routing-runtime/initOnLinkClick.js +3 -4
- package/dist/esm/client/client-routing-runtime/initOnPopState.d.ts +0 -10
- package/dist/esm/client/client-routing-runtime/initOnPopState.js +50 -62
- package/dist/esm/client/client-routing-runtime/prefetch/getPrefetchSettings.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.js +2 -2
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +15 -15
- package/dist/esm/client/client-routing-runtime/scrollRestoration.d.ts +4 -6
- package/dist/esm/client/client-routing-runtime/scrollRestoration.js +17 -12
- package/dist/esm/client/client-routing-runtime/setScrollPosition.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/setScrollPosition.js +29 -5
- package/dist/esm/client/client-routing-runtime/utils.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/utils.js +1 -0
- package/dist/esm/client/server-routing-runtime/entry.d.ts +1 -1
- package/dist/esm/client/server-routing-runtime/entry.js +0 -1
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
- package/dist/esm/client/server-routing-runtime/getPageContext.js +5 -2
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
- package/dist/esm/client/shared/loadUserFilesClientSide.d.ts +2 -2
- package/dist/esm/client/shared/loadUserFilesClientSide.js +2 -2
- package/dist/esm/client/shared/normalizeClientSideUrl.js +2 -3
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/api/build.d.ts +1 -6
- package/dist/esm/node/api/build.js +20 -26
- package/dist/esm/node/api/context.d.ts +4 -2
- package/dist/esm/node/api/context.js +8 -7
- package/dist/esm/node/api/prepareViteApiCall.d.ts +0 -1
- package/dist/esm/node/api/prepareViteApiCall.js +26 -9
- package/dist/esm/node/cli/context.d.ts +5 -0
- package/dist/esm/node/cli/context.js +14 -0
- package/dist/esm/node/cli/entry.js +4 -0
- package/dist/esm/node/cli/parseCli.d.ts +3 -1
- package/dist/esm/node/cli/utils.d.ts +1 -0
- package/dist/esm/node/cli/utils.js +1 -0
- package/dist/esm/node/plugin/index.d.ts +1 -1
- package/dist/esm/node/plugin/index.js +5 -5
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +32 -20
- package/dist/esm/node/plugin/plugins/baseUrls.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/baseUrls.js +4 -11
- package/dist/esm/node/plugin/plugins/buildConfig.js +2 -2
- package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/getVikeManifest.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/index.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/index.js +16 -17
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +10 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +42 -5
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +6 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +25 -22
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +96 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +167 -64
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +7 -5
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +1 -1
- package/dist/esm/node/plugin/plugins/workaroundVite6HmrRegression.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/{vite6HmrRegressionWorkaround.js → workaroundVite6HmrRegression.js} +3 -3
- package/dist/esm/node/prerender/context.d.ts +9 -0
- package/dist/esm/node/prerender/context.js +22 -0
- package/dist/esm/node/prerender/runPrerender.d.ts +42 -2
- package/dist/esm/node/prerender/runPrerender.js +130 -90
- package/dist/esm/node/prerender/utils.d.ts +2 -0
- package/dist/esm/node/prerender/utils.js +2 -0
- package/dist/esm/node/runtime/globalContext.d.ts +23 -7
- package/dist/esm/node/runtime/globalContext.js +109 -55
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/esm/node/runtime/index-common.d.ts +0 -1
- package/dist/esm/node/runtime/index-common.js +0 -15
- package/dist/esm/node/runtime/index-deprecated.d.ts +1 -0
- package/dist/esm/node/runtime/onLoad.js +16 -2
- package/dist/esm/node/runtime/page-files/setup.js +3 -3
- package/dist/esm/node/runtime/renderPage/analyzePage.js +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponse/getCacheControl.js +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +31 -46
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +11 -33
- package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/resolveRedirects.js +9 -1
- package/dist/esm/node/runtime/renderPage.js +22 -23
- package/dist/esm/node/runtime/utils.d.ts +2 -0
- package/dist/esm/node/runtime/utils.js +2 -0
- package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertRuntimeManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertRuntimeManifest.js +1 -3
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +1 -1
- package/dist/esm/shared/getPageFiles/{setPageFiles.d.ts → getPageFiles.d.ts} +3 -1
- package/dist/esm/shared/getPageFiles/{setPageFiles.js → getPageFiles.js} +8 -6
- package/dist/esm/shared/getPageFiles.d.ts +2 -5
- package/dist/esm/shared/getPageFiles.js +1 -4
- package/dist/esm/shared/hooks/getHook.d.ts +3 -3
- package/dist/esm/shared/hooks/getHook.js +1 -1
- package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +9 -5
- package/dist/esm/shared/page-configs/Config.d.ts +20 -2
- package/dist/esm/shared/page-configs/PageConfig.d.ts +13 -6
- package/dist/esm/shared/{getPageFiles/getExports.d.ts → page-configs/getPageConfigUserFriendly.d.ts} +26 -12
- package/dist/esm/shared/{getPageFiles/getExports.js → page-configs/getPageConfigUserFriendly.js} +112 -80
- package/dist/esm/shared/page-configs/loadConfigValues.js +6 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +26 -6
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +80 -55
- package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +1 -1
- package/dist/esm/shared/types.d.ts +1 -1
- package/dist/esm/shared/utils.d.ts +1 -0
- package/dist/esm/shared/utils.js +1 -0
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assert.js +4 -3
- package/dist/esm/utils/assertSetup.js +47 -16
- package/dist/esm/utils/catchInfiniteLoop.d.ts +2 -0
- package/dist/esm/utils/catchInfiniteLoop.js +32 -0
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/debug.js +11 -6
- package/dist/esm/utils/getGlobalObject.js +1 -2
- package/dist/esm/utils/isDev.js +2 -0
- package/dist/esm/utils/makePublicCopy.d.ts +3 -0
- package/dist/esm/utils/makePublicCopy.js +30 -0
- package/dist/esm/utils/objectReplace.d.ts +1 -0
- package/dist/esm/utils/objectReplace.js +6 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +4 -13
- package/__internal/loadImportBuild.js +0 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +0 -128
- package/dist/cjs/node/runtime/globalContext/loadImportBuild.js +0 -25
- package/dist/cjs/node/runtime/page-files/getPageFilesExports.js +0 -22
- package/dist/esm/client/client-routing-runtime/pageFiles.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/pageFiles.js +0 -4
- package/dist/esm/client/server-routing-runtime/pageFiles.d.ts +0 -1
- package/dist/esm/client/server-routing-runtime/pageFiles.js +0 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.d.ts +0 -104
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveVikeConfigGlobal.js +0 -123
- package/dist/esm/node/plugin/plugins/vite6HmrRegressionWorkaround.d.ts +0 -3
- package/dist/esm/node/runtime/globalContext/loadImportBuild.d.ts +0 -18
- package/dist/esm/node/runtime/globalContext/loadImportBuild.js +0 -23
- package/dist/esm/node/runtime/page-files/getPageFilesExports.d.ts +0 -2
- package/dist/esm/node/runtime/page-files/getPageFilesExports.js +0 -20
- /package/dist/cjs/node/plugin/plugins/{importBuild → buildEntry}/getVikeManifest.js +0 -0
- /package/dist/cjs/shared/page-configs/{getConfigValue.js → getConfigValueRuntime.js} +0 -0
- /package/dist/esm/node/plugin/plugins/{importBuild → buildEntry}/getVikeManifest.js +0 -0
- /package/dist/esm/shared/page-configs/{getConfigValue.d.ts → getConfigValueRuntime.d.ts} +0 -0
- /package/dist/esm/shared/page-configs/{getConfigValue.js → getConfigValueRuntime.js} +0 -0
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
export type { PageContextConfig };
|
|
2
|
+
export type { ConfigResolved };
|
|
2
3
|
import type { VikePackages } from '../../VikeNamespace.js';
|
|
3
|
-
import type { ConfigBuiltIn, ImportString } from '../Config.js';
|
|
4
|
+
import type { ConfigBuiltIn, ConfigBuiltInResolved, ImportString } from '../Config.js';
|
|
4
5
|
import type { Combine, IsNotEmpty, XOR5 } from './helpers.js';
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
type
|
|
6
|
+
type PageContextConfig = ConfigResolved & (ConfigVikePackagesNotEmptyXor extends true ? ConfigVikePackagesIntersection : ConfigVikePackagesCombined);
|
|
7
|
+
type ConfigUnresolved = WithoutImportString<ConfigBuiltIn & Vike.Config>;
|
|
8
|
+
type ConfigResolvedOnly = ConfigBuiltInResolved & Vike.ConfigResolved;
|
|
9
|
+
type ConfigResolved = ConfigResolvedOnly & Omit<ConfigUnresolved, keyof ConfigResolvedOnly>;
|
|
9
10
|
type ConfigVikePackagesIntersection = VikePackages.ConfigVikeReact & VikePackages.ConfigVikeVue & VikePackages.ConfigVikeSolid & VikePackages.ConfigVikeSvelte & VikePackages.ConfigVikeAngular;
|
|
10
11
|
type ConfigVikePackagesCombined = Combine<VikePackages.ConfigVikeReact, Combine<VikePackages.ConfigVikeVue, Combine<VikePackages.ConfigVikeSolid, Combine<VikePackages.ConfigVikeSvelte, VikePackages.ConfigVikeAngular>>>>;
|
|
11
12
|
type ConfigVikePackagesNotEmptyXor = XOR5<IsNotEmpty<VikePackages.ConfigVikeReact>, IsNotEmpty<VikePackages.ConfigVikeVue>, IsNotEmpty<VikePackages.ConfigVikeSolid>, IsNotEmpty<VikePackages.ConfigVikeSvelte>, IsNotEmpty<VikePackages.ConfigVikeAngular>>;
|
|
13
|
+
type WithoutImportString<T> = {
|
|
14
|
+
[K in keyof T]: Exclude<T[K], ImportString>;
|
|
15
|
+
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export type { Config };
|
|
2
2
|
export type { ConfigBuiltIn };
|
|
3
|
+
export type { ConfigBuiltInResolved };
|
|
3
4
|
export type { ConfigNameBuiltIn };
|
|
5
|
+
export type { ConfigNameGlobal };
|
|
4
6
|
export type { ConfigMeta };
|
|
5
7
|
export type { HookName };
|
|
6
8
|
export type { HookNamePage };
|
|
@@ -35,15 +37,17 @@ import type { PrefetchSetting, PrefetchStaticAssets } from '../../client/client-
|
|
|
35
37
|
import type { ConfigDefinition } from '../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js';
|
|
36
38
|
import type { DocumentHtml } from '../../node/runtime/html/renderHtml.js';
|
|
37
39
|
import type { InjectFilterEntry } from '../../types/index.js';
|
|
38
|
-
import type { VikeVitePluginOptions } from '../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig
|
|
40
|
+
import type { VikeVitePluginOptions } from '../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
|
|
39
41
|
import type { Vike, VikePackages } from '../VikeNamespace.js';
|
|
40
42
|
import type { HooksTimeoutProvidedByUser } from '../hooks/getHook.js';
|
|
41
43
|
import type { PageContextClient, PageContextServer } from '../types.js';
|
|
44
|
+
import type { InlineConfig } from 'vite';
|
|
42
45
|
type HookName = HookNamePage | HookNameGlobal | HookNameOldDesign;
|
|
43
46
|
type HookNamePage = 'onHydrationEnd' | 'onBeforePrerenderStart' | 'onBeforeRender' | 'onPageTransitionStart' | 'onPageTransitionEnd' | 'onRenderHtml' | 'onRenderClient' | 'guard' | 'data';
|
|
44
47
|
type HookNameGlobal = 'onBeforePrerender' | 'onBeforeRoute' | 'onPrerenderStart';
|
|
45
48
|
type HookNameOldDesign = 'render' | 'prerender';
|
|
46
|
-
type ConfigNameBuiltIn = Exclude<keyof Config, keyof VikeVitePluginOptions | 'onBeforeRoute' | 'onPrerenderStart'> | 'prerender' | 'isClientRuntimeLoaded' | 'onBeforeRenderEnv' | 'dataEnv' | 'hooksTimeout' | 'clientHooks' | 'middleware';
|
|
49
|
+
type ConfigNameBuiltIn = Exclude<keyof Config, keyof VikeVitePluginOptions | 'onBeforeRoute' | 'onPrerenderStart' | 'vite' | 'redirects'> | 'prerender' | 'isClientRuntimeLoaded' | 'onBeforeRenderEnv' | 'dataEnv' | 'hooksTimeout' | 'clientHooks' | 'middleware';
|
|
50
|
+
type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | 'disableAutoFullBuild' | 'includeAssetsImportedByServer' | 'baseAssets' | 'baseServer' | 'redirects' | 'trailingSlash' | 'disableUrlNormalization' | 'vite';
|
|
47
51
|
type Config = ConfigBuiltIn & Vike.Config & (VikePackages.ConfigVikeReact | VikePackages.ConfigVikeVue | VikePackages.ConfigVikeSolid | VikePackages.ConfigVikeSvelte | VikePackages.ConfigVikeAngular);
|
|
48
52
|
/** Hook for fetching data.
|
|
49
53
|
*
|
|
@@ -344,6 +348,16 @@ type ConfigBuiltIn = {
|
|
|
344
348
|
* https://vike.dev/meta
|
|
345
349
|
*/
|
|
346
350
|
meta?: ConfigMeta | ImportString;
|
|
351
|
+
/** Vite configuration.
|
|
352
|
+
*
|
|
353
|
+
* https://vite.dev/config/
|
|
354
|
+
*/
|
|
355
|
+
vite?: InlineConfig;
|
|
356
|
+
/** Permanent redirections (HTTP status code 301)
|
|
357
|
+
*
|
|
358
|
+
* https://vike.dev/redirects
|
|
359
|
+
*/
|
|
360
|
+
redirects?: Record<string, string>;
|
|
347
361
|
/**
|
|
348
362
|
* @experimental DON'T USE: the API *will* have breaking changes upon any minor version release.
|
|
349
363
|
*
|
|
@@ -390,5 +404,9 @@ type ConfigBuiltIn = {
|
|
|
390
404
|
*/
|
|
391
405
|
keepScrollPosition?: KeepScrollPosition;
|
|
392
406
|
};
|
|
407
|
+
type ConfigBuiltInResolved = {
|
|
408
|
+
passToClient?: string[][];
|
|
409
|
+
redirects?: Record<string, string>[];
|
|
410
|
+
};
|
|
393
411
|
type ConfigMeta = Record<string, ConfigDefinition>;
|
|
394
412
|
type ImportString = `import:${string}`;
|
|
@@ -32,9 +32,12 @@ type PageConfigBase = {
|
|
|
32
32
|
type PageConfigRuntime = PageConfigBase & {
|
|
33
33
|
configValues: ConfigValues;
|
|
34
34
|
/** Load config values that are lazily loaded such as config.Page */
|
|
35
|
-
loadConfigValuesAll: () =>
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
loadConfigValuesAll: () => {
|
|
36
|
+
moduleId: string;
|
|
37
|
+
moduleExports: Promise<{
|
|
38
|
+
configValuesSerialized: Record<string, ConfigValueSerialized>;
|
|
39
|
+
}>;
|
|
40
|
+
};
|
|
38
41
|
};
|
|
39
42
|
/** Same as PageConfigRuntime but also contains all lazily loaded config values such as config.Page */
|
|
40
43
|
type PageConfigRuntimeLoaded = PageConfigRuntime & {
|
|
@@ -54,6 +57,7 @@ type PageConfigGlobalRuntime = {
|
|
|
54
57
|
type PageConfigGlobalBuildTime = {
|
|
55
58
|
configValueSources: ConfigValueSources;
|
|
56
59
|
configDefinitions: ConfigDefinitions;
|
|
60
|
+
configValuesComputed?: undefined;
|
|
57
61
|
};
|
|
58
62
|
/** In what environment(s) the config value is loaded.
|
|
59
63
|
*
|
|
@@ -70,6 +74,8 @@ type ConfigEnvInternal = Omit<ConfigEnv, 'client'> & {
|
|
|
70
74
|
/** Load value only in production, or only in development. */
|
|
71
75
|
production?: boolean;
|
|
72
76
|
};
|
|
77
|
+
type ConfigValueSources = Record<string, // configName
|
|
78
|
+
ConfigValueSource[]>;
|
|
73
79
|
type ConfigValueSource = {
|
|
74
80
|
value?: unknown;
|
|
75
81
|
configEnv: ConfigEnvInternal;
|
|
@@ -85,11 +91,13 @@ type ConfigValueSource = {
|
|
|
85
91
|
type DefinedAtFilePath = DefinedAtFile & FilePath & {
|
|
86
92
|
fileExportName?: string;
|
|
87
93
|
};
|
|
88
|
-
type
|
|
89
|
-
|
|
94
|
+
type ConfigValuesComputed = Record<string, // configName
|
|
95
|
+
{
|
|
90
96
|
configEnv: ConfigEnvInternal;
|
|
91
97
|
value: unknown;
|
|
92
98
|
}>;
|
|
99
|
+
type ConfigValues = Record<string, // configName
|
|
100
|
+
ConfigValue>;
|
|
93
101
|
type ConfigValue = ConfigValueStandard | ConfigValueCumulative | ConfigValueComputed;
|
|
94
102
|
/** Defined by a unique source (thus unique file path). */
|
|
95
103
|
type ConfigValueStandard = {
|
|
@@ -109,7 +117,6 @@ type ConfigValueComputed = {
|
|
|
109
117
|
value: unknown;
|
|
110
118
|
definedAtData: null;
|
|
111
119
|
};
|
|
112
|
-
type ConfigValues = Record<string, ConfigValue>;
|
|
113
120
|
type DefinedAtData = DefinedAtFile | DefinedAtFile[] | null;
|
|
114
121
|
type DefinedAtFile = {
|
|
115
122
|
filePathToShowToUser: string;
|
package/dist/esm/shared/{getPageFiles/getExports.d.ts → page-configs/getPageConfigUserFriendly.d.ts}
RENAMED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getPageConfigUserFriendly };
|
|
2
|
+
export { getPageConfigUserFriendlyNew };
|
|
3
|
+
export type { ConfigUserFriendly };
|
|
4
|
+
export type { PageConfigUserFriendly };
|
|
5
|
+
export type { Source };
|
|
6
|
+
export type { Sources };
|
|
7
|
+
export type { From };
|
|
2
8
|
export type { ExportsAll };
|
|
3
|
-
export type { PageContextExports };
|
|
4
9
|
export type { ConfigEntries };
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import type
|
|
9
|
-
import type {
|
|
10
|
-
import type { PageFile } from './getPageFileObject.js';
|
|
11
|
-
import { type ConfigDefinedAtOptional } from '../page-configs/getConfigDefinedAt.js';
|
|
10
|
+
import type { FileType } from '../getPageFiles/fileTypes.js';
|
|
11
|
+
import type { PageFile } from '../getPageFiles/getPageFileObject.js';
|
|
12
|
+
import type { ConfigValues, PageConfigRuntimeLoaded } from './PageConfig.js';
|
|
13
|
+
import { type ConfigDefinedAtOptional } from './getConfigDefinedAt.js';
|
|
14
|
+
import type { ConfigResolved } from './Config/PageContextConfig.js';
|
|
12
15
|
type ExportsAll = Record<string, {
|
|
13
16
|
exportValue: unknown;
|
|
14
17
|
exportSource: string;
|
|
@@ -29,11 +32,11 @@ type ConfigEntries = Record<string, {
|
|
|
29
32
|
configDefinedAt: ConfigDefinedAtOptional;
|
|
30
33
|
configDefinedByFile: string | null;
|
|
31
34
|
}[]>;
|
|
32
|
-
type
|
|
35
|
+
type PageConfigUserFriendly = {
|
|
36
|
+
config: Record<string, unknown>;
|
|
33
37
|
source: Source;
|
|
34
38
|
sources: Sources;
|
|
35
39
|
from: From;
|
|
36
|
-
config: Record<string, unknown>;
|
|
37
40
|
configEntries: ConfigEntries;
|
|
38
41
|
exports: Record<string, unknown>;
|
|
39
42
|
exportsAll: ExportsAll;
|
|
@@ -70,4 +73,15 @@ type SourceConfigsComputed = {
|
|
|
70
73
|
type: 'configsComputed';
|
|
71
74
|
value: unknown;
|
|
72
75
|
};
|
|
73
|
-
declare function
|
|
76
|
+
declare function getPageConfigUserFriendly(pageFiles: PageFile[], pageConfig: PageConfigRuntimeLoaded | null): PageConfigUserFriendly;
|
|
77
|
+
type ConfigUserFriendly = {
|
|
78
|
+
config: ConfigResolved;
|
|
79
|
+
configEntries: ConfigEntries;
|
|
80
|
+
exportsAll: ExportsAll;
|
|
81
|
+
source: Source;
|
|
82
|
+
sources: Sources;
|
|
83
|
+
from: From;
|
|
84
|
+
};
|
|
85
|
+
declare function getPageConfigUserFriendlyNew(pageConfig: {
|
|
86
|
+
configValues: ConfigValues;
|
|
87
|
+
}): ConfigUserFriendly;
|
package/dist/esm/shared/{getPageFiles/getExports.js → page-configs/getPageConfigUserFriendly.js}
RENAMED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
1
|
+
export { getPageConfigUserFriendly };
|
|
2
|
+
export { getPageConfigUserFriendlyNew };
|
|
3
|
+
import { assertDefaultExports, forbiddenDefaultExports } from '../getPageFiles/assert_exports_old_design.js';
|
|
4
|
+
import { getConfigDefinedAtOptional, getDefinedAtString } from './getConfigDefinedAt.js';
|
|
5
|
+
import { getConfigValueFilePathToShowToUser } from './helpers.js';
|
|
6
|
+
import { assert, isObject, assertWarning, assertUsage, makeLast, isBrowser, isScriptFile, isTemplateFile } from '../utils.js';
|
|
7
7
|
import pc from '@brillout/picocolors';
|
|
8
|
-
function
|
|
9
|
-
const configEntries = {};
|
|
8
|
+
function getPageConfigUserFriendly(pageFiles, pageConfig) {
|
|
10
9
|
const config = {};
|
|
11
|
-
const
|
|
10
|
+
const configEntries = {}; // TODO/v1-release: remove
|
|
11
|
+
const exportsAll = {}; // TODO/v1-release: remove
|
|
12
12
|
// V0.4 design
|
|
13
13
|
// TODO/v1-release: remove
|
|
14
14
|
pageFiles.forEach((pageFile) => {
|
|
@@ -26,78 +26,26 @@ function getPageContextExports(pageFiles, pageConfig) {
|
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const addSrc = (src, configName) => {
|
|
33
|
-
source[configName] = src;
|
|
34
|
-
sources[configName] ?? (sources[configName] = []);
|
|
35
|
-
sources[configName].push(src);
|
|
36
|
-
};
|
|
37
|
-
const from = {
|
|
38
|
-
configsStandard: {},
|
|
39
|
-
configsCumulative: {},
|
|
40
|
-
configsComputed: {}
|
|
41
|
-
};
|
|
29
|
+
let source;
|
|
30
|
+
let sources;
|
|
31
|
+
let from;
|
|
42
32
|
if (pageConfig) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
value: configValue.value,
|
|
60
|
-
definedAt: getDefinedAtString(configValue.definedAtData, configName)
|
|
61
|
-
};
|
|
62
|
-
addSrc(src, configName);
|
|
63
|
-
from.configsStandard[configName] = src;
|
|
64
|
-
}
|
|
65
|
-
if (configValue.type === 'cumulative') {
|
|
66
|
-
const src = {
|
|
67
|
-
type: 'configsCumulative',
|
|
68
|
-
values: configValue.value.map((value, i) => {
|
|
69
|
-
const definedAtFile = configValue.definedAtData[i];
|
|
70
|
-
assert(definedAtFile);
|
|
71
|
-
const definedAt = getDefinedAtString(definedAtFile, configName);
|
|
72
|
-
return {
|
|
73
|
-
value,
|
|
74
|
-
definedAt
|
|
75
|
-
};
|
|
76
|
-
})
|
|
77
|
-
};
|
|
78
|
-
addSrc(src, configName);
|
|
79
|
-
from.configsCumulative[configName] = src;
|
|
80
|
-
}
|
|
81
|
-
if (configValue.type === 'computed') {
|
|
82
|
-
const src = {
|
|
83
|
-
type: 'configsComputed',
|
|
84
|
-
value: configValue.value
|
|
85
|
-
};
|
|
86
|
-
addSrc(src, configName);
|
|
87
|
-
from.configsComputed[configName] = src;
|
|
88
|
-
}
|
|
89
|
-
// TODO/v1-release: remove
|
|
90
|
-
const exportName = configName;
|
|
91
|
-
exportsAll[exportName] = exportsAll[exportName] ?? [];
|
|
92
|
-
exportsAll[exportName].push({
|
|
93
|
-
exportValue: value,
|
|
94
|
-
exportSource: configDefinedAt,
|
|
95
|
-
filePath: configValueFilePathToShowToUser,
|
|
96
|
-
_filePath: configValueFilePathToShowToUser,
|
|
97
|
-
_fileType: null,
|
|
98
|
-
_isFromDefaultExport: null
|
|
99
|
-
});
|
|
100
|
-
});
|
|
33
|
+
const res = getPageConfigUserFriendlyNew(pageConfig);
|
|
34
|
+
source = res.source;
|
|
35
|
+
sources = res.sources;
|
|
36
|
+
from = res.from;
|
|
37
|
+
Object.assign(config, res.config);
|
|
38
|
+
Object.assign(configEntries, res.configEntries);
|
|
39
|
+
Object.assign(exportsAll, res.exportsAll);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
source = {};
|
|
43
|
+
sources = {};
|
|
44
|
+
from = {
|
|
45
|
+
configsStandard: {},
|
|
46
|
+
configsCumulative: {},
|
|
47
|
+
configsComputed: {}
|
|
48
|
+
};
|
|
101
49
|
}
|
|
102
50
|
const pageExports = createObjectWithDeprecationWarning();
|
|
103
51
|
const exports = {};
|
|
@@ -127,6 +75,90 @@ function getPageContextExports(pageFiles, pageConfig) {
|
|
|
127
75
|
};
|
|
128
76
|
return pageContextExports;
|
|
129
77
|
}
|
|
78
|
+
// V1 design
|
|
79
|
+
function getPageConfigUserFriendlyNew(pageConfig) {
|
|
80
|
+
const config = {};
|
|
81
|
+
const configEntries = {};
|
|
82
|
+
const exportsAll = {};
|
|
83
|
+
const source = {};
|
|
84
|
+
const sources = {};
|
|
85
|
+
const from = {
|
|
86
|
+
configsStandard: {},
|
|
87
|
+
configsCumulative: {},
|
|
88
|
+
configsComputed: {}
|
|
89
|
+
};
|
|
90
|
+
const addSrc = (src, configName) => {
|
|
91
|
+
source[configName] = src;
|
|
92
|
+
sources[configName] ?? (sources[configName] = []);
|
|
93
|
+
sources[configName].push(src);
|
|
94
|
+
};
|
|
95
|
+
Object.entries(pageConfig.configValues).forEach(([configName, configValue]) => {
|
|
96
|
+
const { value } = configValue;
|
|
97
|
+
const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser(configValue.definedAtData);
|
|
98
|
+
const configDefinedAt = getConfigDefinedAtOptional('Config', configName, configValue.definedAtData);
|
|
99
|
+
config[configName] = config[configName] ?? value;
|
|
100
|
+
configEntries[configName] = configEntries[configName] ?? [];
|
|
101
|
+
// 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.)
|
|
102
|
+
assert(configEntries[configName].length === 0);
|
|
103
|
+
configEntries[configName].push({
|
|
104
|
+
configValue: value,
|
|
105
|
+
configDefinedAt,
|
|
106
|
+
configDefinedByFile: configValueFilePathToShowToUser
|
|
107
|
+
});
|
|
108
|
+
if (configValue.type === 'standard') {
|
|
109
|
+
const src = {
|
|
110
|
+
type: 'configsStandard',
|
|
111
|
+
value: configValue.value,
|
|
112
|
+
definedAt: getDefinedAtString(configValue.definedAtData, configName)
|
|
113
|
+
};
|
|
114
|
+
addSrc(src, configName);
|
|
115
|
+
from.configsStandard[configName] = src;
|
|
116
|
+
}
|
|
117
|
+
if (configValue.type === 'cumulative') {
|
|
118
|
+
const src = {
|
|
119
|
+
type: 'configsCumulative',
|
|
120
|
+
values: configValue.value.map((value, i) => {
|
|
121
|
+
const definedAtFile = configValue.definedAtData[i];
|
|
122
|
+
assert(definedAtFile);
|
|
123
|
+
const definedAt = getDefinedAtString(definedAtFile, configName);
|
|
124
|
+
return {
|
|
125
|
+
value,
|
|
126
|
+
definedAt
|
|
127
|
+
};
|
|
128
|
+
})
|
|
129
|
+
};
|
|
130
|
+
addSrc(src, configName);
|
|
131
|
+
from.configsCumulative[configName] = src;
|
|
132
|
+
}
|
|
133
|
+
if (configValue.type === 'computed') {
|
|
134
|
+
const src = {
|
|
135
|
+
type: 'configsComputed',
|
|
136
|
+
value: configValue.value
|
|
137
|
+
};
|
|
138
|
+
addSrc(src, configName);
|
|
139
|
+
from.configsComputed[configName] = src;
|
|
140
|
+
}
|
|
141
|
+
// TODO/v1-release: remove
|
|
142
|
+
const exportName = configName;
|
|
143
|
+
exportsAll[exportName] = exportsAll[exportName] ?? [];
|
|
144
|
+
exportsAll[exportName].push({
|
|
145
|
+
exportValue: value,
|
|
146
|
+
exportSource: configDefinedAt,
|
|
147
|
+
filePath: configValueFilePathToShowToUser,
|
|
148
|
+
_filePath: configValueFilePathToShowToUser,
|
|
149
|
+
_fileType: null,
|
|
150
|
+
_isFromDefaultExport: null
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
return {
|
|
154
|
+
config,
|
|
155
|
+
configEntries,
|
|
156
|
+
exportsAll,
|
|
157
|
+
source,
|
|
158
|
+
sources,
|
|
159
|
+
from
|
|
160
|
+
};
|
|
161
|
+
}
|
|
130
162
|
function getExportValues(pageFile) {
|
|
131
163
|
const { filePath, fileExports } = pageFile;
|
|
132
164
|
assert(fileExports); // assume pageFile.loadFile() was called
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { loadConfigValues };
|
|
2
|
-
import { objectAssign } from '../utils.js';
|
|
2
|
+
import { assert, objectAssign } from '../utils.js';
|
|
3
3
|
import { parseConfigValuesSerialized } from './serialize/parsePageConfigs.js';
|
|
4
4
|
async function loadConfigValues(pageConfig, isDev) {
|
|
5
5
|
if ('isAllLoaded' in pageConfig &&
|
|
@@ -7,7 +7,11 @@ async function loadConfigValues(pageConfig, isDev) {
|
|
|
7
7
|
!isDev) {
|
|
8
8
|
return pageConfig;
|
|
9
9
|
}
|
|
10
|
-
const
|
|
10
|
+
const { moduleId, moduleExports } = pageConfig.loadConfigValuesAll();
|
|
11
|
+
const configValuesLoaded = await moduleExports;
|
|
12
|
+
// `configValuesLoaded` is sometimes `undefined` https://github.com/vikejs/vike/discussions/2092
|
|
13
|
+
if (!configValuesLoaded)
|
|
14
|
+
assert(false, { moduleExports, configValuesLoaded, moduleId });
|
|
11
15
|
const configValues = parseConfigValuesSerialized(configValuesLoaded.configValuesSerialized);
|
|
12
16
|
Object.assign(pageConfig.configValues, configValues);
|
|
13
17
|
objectAssign(pageConfig, { isAllLoaded: true });
|
|
@@ -1,7 +1,27 @@
|
|
|
1
1
|
export { serializeConfigValues };
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
export { getConfigValuesBase };
|
|
3
|
+
import type { ConfigEnvInternal, ConfigValueSource, DefinedAtFile, PageConfigBuildTime, PageConfigGlobalBuildTime } from '../PageConfig.js';
|
|
4
|
+
declare function serializeConfigValues(pageConfig: PageConfigBuildTime | PageConfigGlobalBuildTime, importStatements: string[], isEnvMatch: (configEnv: ConfigEnvInternal) => boolean, tabspace: string, isEager: boolean | null): string[];
|
|
5
|
+
declare function getConfigValuesBase(pageConfig: PageConfigBuildTime | PageConfigGlobalBuildTime, isEnvMatch: (configEnv: ConfigEnvInternal) => boolean, isEager: boolean | null): ConfigValuesBase;
|
|
6
|
+
type ConfigValuesBase = ({
|
|
7
|
+
configValueBase: {
|
|
8
|
+
type: 'computed';
|
|
9
|
+
definedAtData: null;
|
|
10
|
+
};
|
|
11
|
+
value: unknown;
|
|
12
|
+
configName: string;
|
|
13
|
+
} | {
|
|
14
|
+
configValueBase: {
|
|
15
|
+
type: 'standard';
|
|
16
|
+
definedAtData: DefinedAtFile;
|
|
17
|
+
};
|
|
18
|
+
sourceRelevant: ConfigValueSource;
|
|
19
|
+
configName: string;
|
|
20
|
+
} | {
|
|
21
|
+
configValueBase: {
|
|
22
|
+
type: 'cumulative';
|
|
23
|
+
definedAtData: DefinedAtFile[];
|
|
24
|
+
};
|
|
25
|
+
sourcesRelevant: ConfigValueSource[];
|
|
26
|
+
configName: string;
|
|
27
|
+
})[];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { serializeConfigValues };
|
|
2
|
+
export { getConfigValuesBase };
|
|
2
3
|
import { assertIsNotProductionRuntime } from '../../../utils/assertSetup.js';
|
|
3
4
|
import { assert, assertUsage, getPropAccessNotation } from '../../../node/plugin/utils.js';
|
|
4
5
|
import { addImportStatement } from '../../../node/plugin/plugins/importUserCode/addImportStatement.js';
|
|
@@ -12,77 +13,45 @@ const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
|
|
|
12
13
|
// - vike/shared/page-configs/serialize/parsePageConfigs.ts
|
|
13
14
|
// - parsePageConfigs() is loaded on both the client- and server-side.
|
|
14
15
|
assertIsNotProductionRuntime();
|
|
15
|
-
function serializeConfigValues(pageConfig, importStatements, isEnvMatch,
|
|
16
|
+
function serializeConfigValues(pageConfig, importStatements, isEnvMatch, tabspace, isEager) {
|
|
16
17
|
const lines = [];
|
|
17
18
|
tabspace += ' ';
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return;
|
|
24
|
-
const valueData = serializeWithJson(configValuesComputed.value, configName, null, importStatements);
|
|
25
|
-
const configValueBase = {
|
|
26
|
-
type: 'computed',
|
|
27
|
-
definedAtData: null
|
|
28
|
-
};
|
|
29
|
-
serializeConfigValue(configValueBase, valueData, configName, lines, tabspace);
|
|
30
|
-
});
|
|
31
|
-
Object.entries(pageConfig.configValueSources).forEach(([configName, sources]) => {
|
|
32
|
-
const configDef = pageConfig.configDefinitions[configName];
|
|
33
|
-
assert(configDef);
|
|
34
|
-
if (isEager !== !!configDef.eager)
|
|
35
|
-
return;
|
|
36
|
-
if (!configDef.cumulative) {
|
|
37
|
-
const configValueSource = sources[0];
|
|
38
|
-
assert(configValueSource);
|
|
39
|
-
assert(sources.slice(1).every((s) => s.isOverriden === true));
|
|
40
|
-
if (!isEnvMatch(configValueSource.configEnv))
|
|
41
|
-
return;
|
|
42
|
-
const { valueData, definedAtFile } = serializeConfigValueSource(configValueSource, configName, importStatements);
|
|
43
|
-
const configValueBase = {
|
|
44
|
-
type: 'standard',
|
|
45
|
-
definedAtData: definedAtFile
|
|
46
|
-
};
|
|
19
|
+
getConfigValuesBase(pageConfig, isEnvMatch, isEager).forEach((entry) => {
|
|
20
|
+
if (entry.configValueBase.type === 'computed') {
|
|
21
|
+
assert('value' in entry); // Help TS
|
|
22
|
+
const { configValueBase, value, configName } = entry;
|
|
23
|
+
const valueData = getValueSerializedWithJson(value, configName, configValueBase.definedAtData, importStatements);
|
|
47
24
|
serializeConfigValue(configValueBase, valueData, configName, lines, tabspace);
|
|
48
25
|
}
|
|
49
|
-
|
|
26
|
+
if (entry.configValueBase.type === 'standard') {
|
|
27
|
+
assert('sourceRelevant' in entry); // Help TS
|
|
28
|
+
const { configValueBase, sourceRelevant, configName } = entry;
|
|
29
|
+
const valueData = getValueSerializedFromSource(sourceRelevant, configName, importStatements);
|
|
30
|
+
serializeConfigValue(configValueBase, valueData, configName, lines, tabspace);
|
|
31
|
+
}
|
|
32
|
+
if (entry.configValueBase.type === 'cumulative') {
|
|
33
|
+
assert('sourcesRelevant' in entry); // Help TS
|
|
34
|
+
const { configValueBase, sourcesRelevant, configName } = entry;
|
|
50
35
|
const valueDataList = [];
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
.filter((s) => !s.isOverriden)
|
|
54
|
-
.forEach((configValueSource) => {
|
|
55
|
-
if (!isEnvMatch(configValueSource.configEnv))
|
|
56
|
-
return;
|
|
57
|
-
const { valueData, definedAtFile } = serializeConfigValueSource(configValueSource, configName, importStatements);
|
|
36
|
+
sourcesRelevant.forEach((source) => {
|
|
37
|
+
const valueData = getValueSerializedFromSource(source, configName, importStatements);
|
|
58
38
|
valueDataList.push(valueData);
|
|
59
|
-
definedAtData.push(definedAtFile);
|
|
60
39
|
});
|
|
61
|
-
if (valueDataList.length === 0)
|
|
62
|
-
return;
|
|
63
|
-
const configValueBase = {
|
|
64
|
-
type: 'cumulative',
|
|
65
|
-
definedAtData
|
|
66
|
-
};
|
|
67
40
|
serializeConfigValue(configValueBase, valueDataList, configName, lines, tabspace);
|
|
68
41
|
}
|
|
69
42
|
});
|
|
70
43
|
return lines;
|
|
71
44
|
}
|
|
72
|
-
function
|
|
45
|
+
function getValueSerializedFromSource(configValueSource, configName, importStatements) {
|
|
73
46
|
assert(configValueSource.isOverriden === false);
|
|
74
47
|
let valueData;
|
|
75
48
|
if ('value' in configValueSource) {
|
|
76
|
-
valueData =
|
|
49
|
+
valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.definedAtFilePath, importStatements);
|
|
77
50
|
}
|
|
78
51
|
else {
|
|
79
|
-
valueData =
|
|
52
|
+
valueData = getValueSerializedWithImport(configValueSource, importStatements);
|
|
80
53
|
}
|
|
81
|
-
|
|
82
|
-
filePathToShowToUser: configValueSource.definedAtFilePath.filePathToShowToUser,
|
|
83
|
-
fileExportPathToShowToUser: configValueSource.definedAtFilePath.fileExportPathToShowToUser
|
|
84
|
-
};
|
|
85
|
-
return { valueData, definedAtFile };
|
|
54
|
+
return valueData;
|
|
86
55
|
}
|
|
87
56
|
function serializeConfigValue(configValueBase, valueData, configName, lines, tabspace) {
|
|
88
57
|
lineAdd(`[${JSON.stringify(configName)}]: {`);
|
|
@@ -126,7 +95,7 @@ function serializeConfigValue(configValueBase, valueData, configName, lines, tab
|
|
|
126
95
|
tabspace = tabspace.slice(2);
|
|
127
96
|
}
|
|
128
97
|
}
|
|
129
|
-
function
|
|
98
|
+
function getValueSerializedWithImport(configValueSource, importStatements) {
|
|
130
99
|
assert(!configValueSource.valueIsFilePath);
|
|
131
100
|
const { valueIsImportedAtRuntime, valueIsDefinedByPlusFile, definedAtFilePath } = configValueSource;
|
|
132
101
|
assert(valueIsImportedAtRuntime);
|
|
@@ -139,7 +108,7 @@ function serializeWithImport(configValueSource, importStatements) {
|
|
|
139
108
|
valueAsJsCode: importName
|
|
140
109
|
};
|
|
141
110
|
}
|
|
142
|
-
function
|
|
111
|
+
function getValueSerializedWithJson(value, configName, definedAtData, importStatements) {
|
|
143
112
|
const valueAsJsCode = valueToJson(value, configName, definedAtData, importStatements);
|
|
144
113
|
return {
|
|
145
114
|
type: 'js-serialized',
|
|
@@ -196,3 +165,59 @@ function logJsonSerializeError(err, configName, definedAtData) {
|
|
|
196
165
|
assert(configValueFilePathToShowToUser);
|
|
197
166
|
assertUsage(false, `${pc.cyan(configName)} defined by ${configValueFilePathToShowToUser} must be defined over a so-called "pointer import", see https://vike.dev/config#pointer-imports`);
|
|
198
167
|
}
|
|
168
|
+
function getConfigValuesBase(pageConfig, isEnvMatch, isEager) {
|
|
169
|
+
const fromComputed = Object.entries(pageConfig.configValuesComputed ?? {}).map(([configName, valueInfo]) => {
|
|
170
|
+
if (!isEnvMatch(valueInfo.configEnv))
|
|
171
|
+
return 'SKIP';
|
|
172
|
+
// Is there a use case for overriding computed values? If yes, then configValeSources has higher precedence
|
|
173
|
+
if (pageConfig.configValueSources[configName])
|
|
174
|
+
return 'SKIP';
|
|
175
|
+
const configValueBase = {
|
|
176
|
+
type: 'computed',
|
|
177
|
+
definedAtData: null
|
|
178
|
+
};
|
|
179
|
+
return { configValueBase, value: valueInfo.value, configName };
|
|
180
|
+
});
|
|
181
|
+
const fromSources = Object.entries(pageConfig.configValueSources).map(([configName, sources]) => {
|
|
182
|
+
const configDef = pageConfig.configDefinitions[configName];
|
|
183
|
+
assert(configDef);
|
|
184
|
+
if (isEager !== null && isEager !== !!configDef.eager)
|
|
185
|
+
return 'SKIP';
|
|
186
|
+
if (!configDef.cumulative) {
|
|
187
|
+
const source = sources[0];
|
|
188
|
+
assert(source);
|
|
189
|
+
assert(sources.slice(1).every((s) => s.isOverriden === true));
|
|
190
|
+
if (!isEnvMatch(source.configEnv))
|
|
191
|
+
return 'SKIP';
|
|
192
|
+
const definedAtFile = getDefinedAtFileSource(source);
|
|
193
|
+
const configValueBase = {
|
|
194
|
+
type: 'standard',
|
|
195
|
+
definedAtData: definedAtFile
|
|
196
|
+
};
|
|
197
|
+
return { configValueBase, sourceRelevant: source, configName };
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
const sourcesRelevant = sources.filter((source) => !source.isOverriden && isEnvMatch(source.configEnv));
|
|
201
|
+
if (sourcesRelevant.length === 0)
|
|
202
|
+
return 'SKIP';
|
|
203
|
+
const definedAtData = [];
|
|
204
|
+
sourcesRelevant.forEach((source) => {
|
|
205
|
+
const definedAtFile = getDefinedAtFileSource(source);
|
|
206
|
+
definedAtData.push(definedAtFile);
|
|
207
|
+
});
|
|
208
|
+
const configValueBase = {
|
|
209
|
+
type: 'cumulative',
|
|
210
|
+
definedAtData
|
|
211
|
+
};
|
|
212
|
+
return { configValueBase, sourcesRelevant, configName };
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
return [...fromComputed, ...fromSources].filter((r) => r !== 'SKIP');
|
|
216
|
+
}
|
|
217
|
+
function getDefinedAtFileSource(source) {
|
|
218
|
+
const definedAtFile = {
|
|
219
|
+
filePathToShowToUser: source.definedAtFilePath.filePathToShowToUser,
|
|
220
|
+
fileExportPathToShowToUser: source.definedAtFilePath.fileExportPathToShowToUser
|
|
221
|
+
};
|
|
222
|
+
return definedAtFile;
|
|
223
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { executeGuardHook };
|
|
2
|
-
import type {
|
|
2
|
+
import type { PageConfigUserFriendly, PageFile } from '../getPageFiles.js';
|
|
3
3
|
import type { PageConfigRuntime } from '../page-configs/PageConfig.js';
|
|
4
|
-
declare function executeGuardHook<T extends
|
|
4
|
+
declare function executeGuardHook<T extends PageConfigUserFriendly & {
|
|
5
5
|
pageId: string;
|
|
6
6
|
_pageFilesAll: PageFile[];
|
|
7
7
|
_pageConfigs: PageConfigRuntime[];
|