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,6 +1,6 @@
|
|
|
1
1
|
export { commonConfig };
|
|
2
2
|
import { mergeConfig } from 'vite';
|
|
3
|
-
import { assert, assertUsage, assertWarning, findPackageJson, isDevCheck, isDocker } from '../utils.js';
|
|
3
|
+
import { assert, assertUsage, assertWarning, findPackageJson, hasProp, isDevCheck, isDocker, isObject } from '../utils.js';
|
|
4
4
|
import { assertRollupInput } from './buildConfig.js';
|
|
5
5
|
import { installRequireShim_setUserRootDir } from '@brillout/require-shim';
|
|
6
6
|
import pc from '@brillout/picocolors';
|
|
@@ -9,6 +9,9 @@ import { assertResolveAlias } from './commonConfig/assertResolveAlias.js';
|
|
|
9
9
|
import { getEnvVarObject } from '../shared/getEnvVarObject.js';
|
|
10
10
|
import { isViteCliCall } from '../shared/isViteCliCall.js';
|
|
11
11
|
import { isVikeCliOrApi } from '../../api/context.js';
|
|
12
|
+
import { getVikeConfig2 } from './importUserCode/v1-design/getVikeConfig.js';
|
|
13
|
+
import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/prepareViteApiCall.js';
|
|
14
|
+
import { temp_disablePrerenderAutoRun } from '../../prerender/context.js';
|
|
12
15
|
const pluginName = 'vike:commonConfig';
|
|
13
16
|
function commonConfig(vikeVitePluginOptions) {
|
|
14
17
|
return [
|
|
@@ -17,10 +20,21 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
17
20
|
enforce: 'pre',
|
|
18
21
|
config: {
|
|
19
22
|
order: 'pre',
|
|
20
|
-
handler(
|
|
23
|
+
async handler(configFromUser, env) {
|
|
24
|
+
const isDev = isDevCheck(env);
|
|
25
|
+
const operation = env.command === 'build' ? 'build' : env.isPreview ? 'preview' : 'dev';
|
|
26
|
+
const root = configFromUser.root ? normalizeViteRoot(configFromUser.root) : await getViteRoot(operation);
|
|
27
|
+
assert(root);
|
|
28
|
+
const vikeConfig = await getVikeConfig2(root, isDev, vikeVitePluginOptions);
|
|
21
29
|
return {
|
|
22
|
-
_isDev:
|
|
23
|
-
|
|
30
|
+
_isDev: isDev,
|
|
31
|
+
_root: root,
|
|
32
|
+
_vikeVitePluginOptions: vikeVitePluginOptions,
|
|
33
|
+
vike: { global: vikeConfig.global },
|
|
34
|
+
// TODO/now: remove
|
|
35
|
+
_vikeConfigGlobal: vikeConfig.vikeConfigGlobal,
|
|
36
|
+
// TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
|
|
37
|
+
configVikePromise: Promise.resolve({ prerender: !!vikeConfig.vikeConfigGlobal.prerender })
|
|
24
38
|
};
|
|
25
39
|
}
|
|
26
40
|
}
|
|
@@ -28,6 +42,7 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
28
42
|
{
|
|
29
43
|
name: pluginName,
|
|
30
44
|
configResolved(config) {
|
|
45
|
+
assertViteRoot(config._root, config);
|
|
31
46
|
assertSingleInstance(config);
|
|
32
47
|
installRequireShim_setUserRootDir(config.root);
|
|
33
48
|
}
|
|
@@ -46,6 +61,7 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
46
61
|
assertResolveAlias(config);
|
|
47
62
|
assertEsm(config.root);
|
|
48
63
|
assertVikeCliOrApi(config);
|
|
64
|
+
temp_supportOldInterface(config);
|
|
49
65
|
}
|
|
50
66
|
},
|
|
51
67
|
config: {
|
|
@@ -61,7 +77,7 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
61
77
|
// VITE_CONFIG
|
|
62
78
|
const configFromEnvVar = getEnvVarObject('VITE_CONFIG');
|
|
63
79
|
if (configFromEnvVar)
|
|
64
|
-
configFromVike = mergeConfig(
|
|
80
|
+
configFromVike = mergeConfig(configFromVike, configFromEnvVar);
|
|
65
81
|
return configFromVike;
|
|
66
82
|
}
|
|
67
83
|
}
|
|
@@ -128,3 +144,24 @@ function assertVikeCliOrApi(config) {
|
|
|
128
144
|
onlyOnce: true
|
|
129
145
|
});
|
|
130
146
|
}
|
|
147
|
+
// TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
|
|
148
|
+
function temp_supportOldInterface(config) {
|
|
149
|
+
if (!('vitePluginSsr' in config))
|
|
150
|
+
return;
|
|
151
|
+
assert(isObject(config.vitePluginSsr));
|
|
152
|
+
if (hasProp(config.vitePluginSsr, 'prerender', 'object')) {
|
|
153
|
+
assert(hasProp(config.vitePluginSsr.prerender, 'disableAutoRun', 'boolean'));
|
|
154
|
+
if (config.vitePluginSsr.prerender.disableAutoRun) {
|
|
155
|
+
temp_disablePrerenderAutoRun();
|
|
156
|
+
}
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (hasProp(config.vitePluginSsr, 'disableAutoFullBuild')) {
|
|
160
|
+
if (config.vitePluginSsr.disableAutoFullBuild) {
|
|
161
|
+
assert(config.vitePluginSsr.disableAutoFullBuild === 'prerender');
|
|
162
|
+
temp_disablePrerenderAutoRun();
|
|
163
|
+
}
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
assert(false);
|
|
167
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { getVirtualFileImportUserCode };
|
|
2
2
|
import type { ResolvedConfig } from 'vite';
|
|
3
|
-
import type { VikeConfigGlobal } from './v1-design/getVikeConfig
|
|
3
|
+
import type { VikeConfigGlobal } from './v1-design/getVikeConfig.js';
|
|
4
4
|
declare function getVirtualFileImportUserCode(id: string, options: {
|
|
5
5
|
ssr?: boolean;
|
|
6
6
|
} | undefined, vikeConfigGlobal: VikeConfigGlobal, config: ResolvedConfig, isDev: boolean): Promise<string>;
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { configDefinitionsBuiltInGlobal };
|
|
1
|
+
export { configDefinitionsBuiltInAll };
|
|
3
2
|
export type { ConfigDefinition };
|
|
4
3
|
export type { ConfigDefinitions };
|
|
5
4
|
export type { ConfigDefinitionInternal };
|
|
6
|
-
export type { ConfigNameGlobal };
|
|
7
5
|
export type { ConfigEffect };
|
|
8
6
|
import type { ConfigEnvInternal, ConfigEnv, ConfigValueSources, DefinedAtFilePath } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
9
|
-
import type { Config, ConfigNameBuiltIn } from '../../../../../../shared/page-configs/Config.js';
|
|
7
|
+
import type { Config, ConfigNameBuiltIn, ConfigNameGlobal } from '../../../../../../shared/page-configs/Config.js';
|
|
10
8
|
import { type ConfigDefinedAt } from '../../../../../../shared/page-configs/getConfigDefinedAt.js';
|
|
11
9
|
/** The meta definition of a config.
|
|
12
10
|
*
|
|
@@ -46,7 +44,8 @@ type ConfigDefinition = {
|
|
|
46
44
|
*
|
|
47
45
|
* https://vike.dev/extends#inheritance
|
|
48
46
|
*/
|
|
49
|
-
global?: boolean;
|
|
47
|
+
global?: boolean | ((value: unknown) => boolean);
|
|
48
|
+
type?: string | string[];
|
|
50
49
|
};
|
|
51
50
|
/**
|
|
52
51
|
* Function called when the config value is defined.
|
|
@@ -74,7 +73,5 @@ type ConfigDefinitionInternal = Omit<ConfigDefinition, 'env'> & {
|
|
|
74
73
|
};
|
|
75
74
|
type ConfigDefinitions = Record<string, // configName
|
|
76
75
|
ConfigDefinitionInternal>;
|
|
77
|
-
type ConfigDefinitionsBuiltIn = Record<ConfigNameBuiltIn, ConfigDefinitionInternal>;
|
|
78
|
-
declare const
|
|
79
|
-
type ConfigNameGlobal = 'onPrerenderStart' | 'onBeforeRoute' | 'prerender' | 'disableAutoFullBuild' | 'includeAssetsImportedByServer' | 'baseAssets' | 'baseServer' | 'redirects' | 'trailingSlash' | 'disableUrlNormalization';
|
|
80
|
-
declare const configDefinitionsBuiltInGlobal: Record<ConfigNameGlobal, ConfigDefinitionInternal>;
|
|
76
|
+
type ConfigDefinitionsBuiltIn = Record<ConfigNameBuiltIn | ConfigNameGlobal, ConfigDefinitionInternal>;
|
|
77
|
+
declare const configDefinitionsBuiltInAll: ConfigDefinitionsBuiltIn;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { configDefinitionsBuiltInGlobal };
|
|
1
|
+
export { configDefinitionsBuiltInAll };
|
|
3
2
|
import { assert, assertUsage } from '../../../../utils.js';
|
|
4
3
|
import { getConfigDefinedAt } from '../../../../../../shared/page-configs/getConfigDefinedAt.js';
|
|
5
|
-
const
|
|
4
|
+
const configDefinitionsBuiltInAll = {
|
|
6
5
|
onRenderHtml: {
|
|
7
6
|
env: { server: true }
|
|
8
7
|
},
|
|
@@ -61,9 +60,6 @@ const configDefinitionsBuiltIn = {
|
|
|
61
60
|
clientHooks: {
|
|
62
61
|
env: { config: true }
|
|
63
62
|
},
|
|
64
|
-
prerender: {
|
|
65
|
-
env: { config: true }
|
|
66
|
-
},
|
|
67
63
|
hydrationCanBeAborted: {
|
|
68
64
|
env: { client: true }
|
|
69
65
|
},
|
|
@@ -132,27 +128,34 @@ const configDefinitionsBuiltIn = {
|
|
|
132
128
|
env: { client: true }
|
|
133
129
|
},
|
|
134
130
|
// TODO/eventually: define it as a global config.
|
|
135
|
-
middleware: { env: { server: true }, cumulative: true, eager: true }
|
|
136
|
-
};
|
|
137
|
-
const configDefinitionsBuiltInGlobal = {
|
|
131
|
+
middleware: { env: { server: true }, cumulative: true, eager: true },
|
|
138
132
|
onPrerenderStart: {
|
|
139
133
|
env: { server: true, production: true },
|
|
140
|
-
eager: true
|
|
134
|
+
eager: true,
|
|
135
|
+
global: true
|
|
141
136
|
},
|
|
142
137
|
onBeforeRoute: {
|
|
143
138
|
env: { server: true, client: 'if-client-routing' },
|
|
144
|
-
eager: true
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
},
|
|
149
|
-
disableAutoFullBuild: {
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
139
|
+
eager: true,
|
|
140
|
+
global: true
|
|
141
|
+
},
|
|
142
|
+
prerender: { env: { config: true }, global: (value) => typeof value !== 'object', type: ['boolean', 'object'] },
|
|
143
|
+
vite: { env: { config: true }, global: true, cumulative: true, type: 'object' },
|
|
144
|
+
disableAutoFullBuild: {
|
|
145
|
+
env: { config: true },
|
|
146
|
+
global: true,
|
|
147
|
+
type: [
|
|
148
|
+
'boolean',
|
|
149
|
+
// Can be 'prerender'
|
|
150
|
+
'string'
|
|
151
|
+
]
|
|
152
|
+
},
|
|
153
|
+
includeAssetsImportedByServer: { env: { config: true }, global: true, type: 'boolean' },
|
|
154
|
+
baseAssets: { env: { config: true }, global: true, type: 'string' },
|
|
155
|
+
baseServer: { env: { config: true }, global: true, type: 'string' },
|
|
156
|
+
redirects: { env: { server: true }, global: true, type: 'string{}', cumulative: true },
|
|
157
|
+
trailingSlash: { env: { server: true }, global: true, type: 'boolean' },
|
|
158
|
+
disableUrlNormalization: { env: { server: true }, global: true, type: 'boolean' }
|
|
156
159
|
};
|
|
157
160
|
function getConfigEnv(configValueSources, configName) {
|
|
158
161
|
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
@@ -8,11 +8,13 @@ export { getConfigValueInterfaceFile };
|
|
|
8
8
|
export type { VikeConfigObject };
|
|
9
9
|
export type { InterfaceValueFile };
|
|
10
10
|
export type { InterfaceFile };
|
|
11
|
+
export type { VikeConfigGlobal };
|
|
12
|
+
export type { VikeVitePluginOptions };
|
|
11
13
|
import type { PageConfigGlobalBuildTime, PageConfigBuildTime } from '../../../../../shared/page-configs/PageConfig.js';
|
|
12
14
|
import { type LocationId } from './getVikeConfig/filesystemRouting.js';
|
|
13
15
|
import type { ResolvedConfig } from 'vite';
|
|
14
16
|
import type { FilePathResolved } from '../../../../../shared/page-configs/FilePath.js';
|
|
15
|
-
import
|
|
17
|
+
import { getPageConfigUserFriendlyNew } from '../../../../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
16
18
|
type InterfaceFile = InterfaceConfigFile | InterfaceValueFile;
|
|
17
19
|
type InterfaceFileCommons = {
|
|
18
20
|
locationId: LocationId;
|
|
@@ -37,6 +39,7 @@ type VikeConfigObject = {
|
|
|
37
39
|
pageConfigs: PageConfigBuildTime[];
|
|
38
40
|
pageConfigGlobal: PageConfigGlobalBuildTime;
|
|
39
41
|
vikeConfigGlobal: VikeConfigGlobal;
|
|
42
|
+
global: ReturnType<typeof getPageConfigUserFriendlyNew>;
|
|
40
43
|
};
|
|
41
44
|
declare const vikeConfigDependencies: Set<string>;
|
|
42
45
|
declare function reloadVikeConfig(config: ResolvedConfig): void;
|
|
@@ -47,3 +50,95 @@ declare function getVikeConfig2(userRootDir: string, isDev: boolean, vikeVitePlu
|
|
|
47
50
|
declare function isV1Design(config: ResolvedConfig): Promise<boolean>;
|
|
48
51
|
declare function isVikeConfigFile(filePath: string): boolean;
|
|
49
52
|
declare function getConfigValueInterfaceFile(interfaceFile: InterfaceFile, configName: string): unknown;
|
|
53
|
+
type VikeConfigGlobal = {
|
|
54
|
+
prerender: false | {
|
|
55
|
+
noExtraDir: boolean;
|
|
56
|
+
parallel: boolean | number;
|
|
57
|
+
partial: boolean;
|
|
58
|
+
disableAutoRun: boolean;
|
|
59
|
+
};
|
|
60
|
+
disableAutoFullBuild: boolean | 'prerender' | null;
|
|
61
|
+
includeAssetsImportedByServer: boolean;
|
|
62
|
+
baseAssets: string | null;
|
|
63
|
+
baseServer: string | null;
|
|
64
|
+
trailingSlash: boolean;
|
|
65
|
+
disableUrlNormalization: boolean;
|
|
66
|
+
};
|
|
67
|
+
type VikeVitePluginOptions = {
|
|
68
|
+
/**
|
|
69
|
+
* Enable pre-rendering.
|
|
70
|
+
*
|
|
71
|
+
* https://vike.dev/pre-rendering
|
|
72
|
+
*
|
|
73
|
+
* @default false
|
|
74
|
+
*/
|
|
75
|
+
prerender?: boolean | {
|
|
76
|
+
/**
|
|
77
|
+
* Don't create a new directory for each HTML file.
|
|
78
|
+
*
|
|
79
|
+
* For example, generate `dist/client/about.html` instead of `dist/client/about/index.html`.
|
|
80
|
+
*
|
|
81
|
+
* @default false
|
|
82
|
+
*/
|
|
83
|
+
noExtraDir?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Number of concurrent pre-render jobs.
|
|
86
|
+
*
|
|
87
|
+
* Set to `false` to disable concurrency.
|
|
88
|
+
*
|
|
89
|
+
* @default os.cpus().length
|
|
90
|
+
*/
|
|
91
|
+
parallel?: boolean | number;
|
|
92
|
+
/**
|
|
93
|
+
* Allow only some of your pages to be pre-rendered.
|
|
94
|
+
*
|
|
95
|
+
* This setting doesn't affect the pre-rendering process: it merely suppresses the warnings when some of your pages cannot be pre-rendered.
|
|
96
|
+
|
|
97
|
+
* @default false
|
|
98
|
+
*/
|
|
99
|
+
partial?: boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Disable the automatic initiation of the pre-rendering process when running `$ vike build`.
|
|
102
|
+
*
|
|
103
|
+
* Use this if you want to programmatically initiate the pre-rendering process instead.
|
|
104
|
+
*
|
|
105
|
+
* https://vike.dev/api#prerender
|
|
106
|
+
*
|
|
107
|
+
* @default false
|
|
108
|
+
*/
|
|
109
|
+
disableAutoRun?: boolean;
|
|
110
|
+
};
|
|
111
|
+
/** @deprecated See https://vike.dev/disableAutoFullBuild */
|
|
112
|
+
disableAutoFullBuild?: boolean | 'prerender';
|
|
113
|
+
/** The Base URL of your server.
|
|
114
|
+
*
|
|
115
|
+
* https://vike.dev/base-url
|
|
116
|
+
*/
|
|
117
|
+
baseServer?: string;
|
|
118
|
+
/** The Base URL of your static assets.
|
|
119
|
+
*
|
|
120
|
+
* https://vike.dev/base-url
|
|
121
|
+
*/
|
|
122
|
+
baseAssets?: string;
|
|
123
|
+
/** @deprecated It's now `true` by default. You can remove this option. */
|
|
124
|
+
includeAssetsImportedByServer?: boolean;
|
|
125
|
+
/** Permanent redirections (HTTP status code 301)
|
|
126
|
+
*
|
|
127
|
+
* https://vike.dev/redirects
|
|
128
|
+
*/
|
|
129
|
+
redirects?: Record<string, string>;
|
|
130
|
+
/** Whether URLs should end with a trailing slash.
|
|
131
|
+
*
|
|
132
|
+
* https://vike.dev/url-normalization
|
|
133
|
+
*
|
|
134
|
+
* @default false
|
|
135
|
+
*/
|
|
136
|
+
trailingSlash?: boolean;
|
|
137
|
+
/** Disable automatic URL normalization.
|
|
138
|
+
*
|
|
139
|
+
* https://vike.dev/url-normalization
|
|
140
|
+
*
|
|
141
|
+
* @default false
|
|
142
|
+
*/
|
|
143
|
+
disableUrlNormalization?: boolean;
|
|
144
|
+
};
|
|
@@ -7,7 +7,7 @@ export { isV1Design };
|
|
|
7
7
|
export { getConfigValueInterfaceFile };
|
|
8
8
|
import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEntries, hasProp, includes, assertIsNotProductionRuntime, getMostSimilar, joinEnglish, lowerFirst, assertKeys, objectKeys, objectFromEntries, makeFirst, isNpmPackageImport, reverse } from '../../../utils.js';
|
|
9
9
|
import path from 'path';
|
|
10
|
-
import {
|
|
10
|
+
import { configDefinitionsBuiltInAll } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
11
11
|
import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, isGlobalLocation, applyFilesystemRoutingRootEffect } from './getVikeConfig/filesystemRouting.js';
|
|
12
12
|
import { isTemporaryBuildFile } from './getVikeConfig/transpileAndExecuteFile.js';
|
|
13
13
|
import { isConfigInvalid, isConfigInvalid_set } from '../../../../runtime/renderPage/isConfigInvalid.js';
|
|
@@ -23,7 +23,10 @@ import { clearFilesEnvMap, resolveConfigEnvWithFileName, resolvePointerImportOfC
|
|
|
23
23
|
import { getFilePathResolved } from '../../../shared/getFilePath.js';
|
|
24
24
|
import { getConfigValueBuildTime } from '../../../../../shared/page-configs/getConfigValueBuildTime.js';
|
|
25
25
|
import { assertExtensionsPeerDependencies, assertExtensionsConventions } from './assertExtensions.js';
|
|
26
|
-
import {
|
|
26
|
+
import { getPageConfigUserFriendlyNew } from '../../../../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
27
|
+
import { getConfigValuesBase } from '../../../../../shared/page-configs/serialize/serializeConfigValues.js';
|
|
28
|
+
const configDefinitionsBuiltIn = getConfigDefinitionsBuiltIn();
|
|
29
|
+
const configDefinitionsBuiltInGlobal = getConfigDefinitionsBuiltInGlobal();
|
|
27
30
|
assertIsNotProductionRuntime();
|
|
28
31
|
let restartVite = false;
|
|
29
32
|
let wasConfigInvalid = null;
|
|
@@ -239,7 +242,8 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, vikeVitePlug
|
|
|
239
242
|
configDefinitions: {},
|
|
240
243
|
configValueSources: {}
|
|
241
244
|
},
|
|
242
|
-
vikeConfigGlobal: resolveVikeConfigGlobal({}, {})
|
|
245
|
+
vikeConfigGlobal: resolveVikeConfigGlobal({}, {}),
|
|
246
|
+
global: getPageConfigUserFriendlyNew({ configValues: {} })
|
|
243
247
|
};
|
|
244
248
|
return dummyData;
|
|
245
249
|
}
|
|
@@ -248,8 +252,97 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, vikeVitePlug
|
|
|
248
252
|
async function loadVikeConfig(userRootDir, vikeVitePluginOptions) {
|
|
249
253
|
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir);
|
|
250
254
|
const importedFilesLoaded = {};
|
|
251
|
-
const
|
|
255
|
+
const [globalConfigs, pageConfigs] = await Promise.all([
|
|
256
|
+
getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded, vikeVitePluginOptions),
|
|
257
|
+
getPageConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded)
|
|
258
|
+
]);
|
|
259
|
+
return { pageConfigs, ...globalConfigs };
|
|
260
|
+
}
|
|
261
|
+
async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded, vikeVitePluginOptions) {
|
|
262
|
+
const locationIds = objectKeys(interfaceFilesByLocationId);
|
|
263
|
+
const interfaceFilesGlobal = objectFromEntries(objectEntries(interfaceFilesByLocationId).filter(([locationId]) => {
|
|
264
|
+
return isGlobalLocation(locationId, locationIds);
|
|
265
|
+
}));
|
|
266
|
+
// Validate that global configs live in global interface files
|
|
267
|
+
{
|
|
268
|
+
const interfaceFilesGlobalPaths = [];
|
|
269
|
+
objectEntries(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
|
|
270
|
+
assert(isGlobalLocation(locationId, locationIds));
|
|
271
|
+
interfaceFiles.forEach(({ filePath: { filePathAbsoluteUserRootDir } }) => {
|
|
272
|
+
if (filePathAbsoluteUserRootDir) {
|
|
273
|
+
interfaceFilesGlobalPaths.push(filePathAbsoluteUserRootDir);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
});
|
|
277
|
+
const globalPaths = Array.from(new Set(interfaceFilesGlobalPaths.map((p) => path.posix.dirname(p))));
|
|
278
|
+
objectEntries(interfaceFilesByLocationId).forEach(([locationId, interfaceFiles]) => {
|
|
279
|
+
interfaceFiles.forEach((interfaceFile) => {
|
|
280
|
+
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
281
|
+
if (!isGlobalLocation(locationId, locationIds) && isGlobalConfig(configName)) {
|
|
282
|
+
assertUsage(false, [
|
|
283
|
+
`${interfaceFile.filePath.filePathToShowToUser} defines the config ${pc.cyan(configName)} which is global:`,
|
|
284
|
+
globalPaths.length
|
|
285
|
+
? `define ${pc.cyan(configName)} in ${joinEnglish(globalPaths, 'or')} instead`
|
|
286
|
+
: `create a global config (e.g. /pages/+config.js) and define ${pc.cyan(configName)} there instead`
|
|
287
|
+
].join(' '));
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
const pageConfigGlobalValues = {};
|
|
294
|
+
const pageConfigGlobal = {
|
|
295
|
+
configDefinitions: configDefinitionsBuiltInGlobal,
|
|
296
|
+
configValueSources: {}
|
|
297
|
+
};
|
|
298
|
+
await Promise.all(objectEntries(configDefinitionsBuiltInGlobal).map(async ([configName, configDef]) => {
|
|
299
|
+
const sources = await resolveConfigValueSources(configName, configDef, interfaceFilesGlobal, userRootDir, importedFilesLoaded);
|
|
300
|
+
const configValueSource = sources[0];
|
|
301
|
+
if (!configValueSource)
|
|
302
|
+
return;
|
|
303
|
+
pageConfigGlobal.configValueSources[configName] = sources;
|
|
304
|
+
// TODO/now
|
|
305
|
+
if (configName === 'onBeforeRoute' || configName === 'onPrerenderStart') {
|
|
306
|
+
assert(!('value' in configValueSource));
|
|
307
|
+
}
|
|
308
|
+
else {
|
|
309
|
+
assert('value' in configValueSource);
|
|
310
|
+
// TODO/now
|
|
311
|
+
if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
|
|
312
|
+
return;
|
|
313
|
+
pageConfigGlobalValues[configName] = configValueSource.value;
|
|
314
|
+
}
|
|
315
|
+
}));
|
|
252
316
|
const vikeConfigGlobal = resolveVikeConfigGlobal(vikeVitePluginOptions, pageConfigGlobalValues);
|
|
317
|
+
{
|
|
318
|
+
assert(isObject(vikeVitePluginOptions));
|
|
319
|
+
Object.entries(vikeVitePluginOptions).forEach(([configName, value]) => {
|
|
320
|
+
var _a;
|
|
321
|
+
assert(includes(objectKeys(configDefinitionsBuiltInGlobal), configName));
|
|
322
|
+
const configDef = configDefinitionsBuiltInGlobal[configName];
|
|
323
|
+
const sources = ((_a = pageConfigGlobal.configValueSources)[configName] ?? (_a[configName] = []));
|
|
324
|
+
sources.push({
|
|
325
|
+
value,
|
|
326
|
+
configEnv: configDef.env,
|
|
327
|
+
definedAtFilePath: {
|
|
328
|
+
...getFilePathResolved({
|
|
329
|
+
userRootDir,
|
|
330
|
+
filePathAbsoluteUserRootDir: '/vite.config.js'
|
|
331
|
+
}),
|
|
332
|
+
fileExportPathToShowToUser: null
|
|
333
|
+
},
|
|
334
|
+
locationId: '/',
|
|
335
|
+
isOverriden: configDef.cumulative ? false : sources.length > 0,
|
|
336
|
+
valueIsImportedAtRuntime: false,
|
|
337
|
+
valueIsDefinedByPlusFile: false
|
|
338
|
+
});
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
const configValues = getConfigValues(pageConfigGlobal);
|
|
342
|
+
const global = getPageConfigUserFriendlyNew({ configValues });
|
|
343
|
+
return { pageConfigGlobal, vikeConfigGlobal, global };
|
|
344
|
+
}
|
|
345
|
+
async function getPageConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded) {
|
|
253
346
|
const pageConfigs = await Promise.all(objectEntries(interfaceFilesByLocationId)
|
|
254
347
|
.filter(([_pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
255
348
|
.map(async ([locationId]) => {
|
|
@@ -299,9 +392,37 @@ async function loadVikeConfig(userRootDir, vikeVitePluginOptions) {
|
|
|
299
392
|
return pageConfig;
|
|
300
393
|
}));
|
|
301
394
|
assertPageConfigs(pageConfigs);
|
|
302
|
-
return
|
|
395
|
+
return pageConfigs;
|
|
303
396
|
}
|
|
304
|
-
|
|
397
|
+
function getConfigValues(pageConfig) {
|
|
398
|
+
const configValues = {};
|
|
399
|
+
getConfigValuesBase(pageConfig, (configEnv) => !!configEnv.config, null).forEach((entry) => {
|
|
400
|
+
if (entry.configValueBase.type === 'computed') {
|
|
401
|
+
assert('value' in entry); // Help TS
|
|
402
|
+
const { configValueBase, value, configName } = entry;
|
|
403
|
+
configValues[configName] = { ...configValueBase, value };
|
|
404
|
+
}
|
|
405
|
+
if (entry.configValueBase.type === 'standard') {
|
|
406
|
+
assert('sourceRelevant' in entry); // Help TS
|
|
407
|
+
const { configValueBase, sourceRelevant, configName } = entry;
|
|
408
|
+
assert('value' in sourceRelevant);
|
|
409
|
+
const { value } = sourceRelevant;
|
|
410
|
+
configValues[configName] = { ...configValueBase, value };
|
|
411
|
+
}
|
|
412
|
+
if (entry.configValueBase.type === 'cumulative') {
|
|
413
|
+
assert('sourcesRelevant' in entry); // Help TS
|
|
414
|
+
const { configValueBase, sourcesRelevant, configName } = entry;
|
|
415
|
+
const values = [];
|
|
416
|
+
sourcesRelevant.forEach((source) => {
|
|
417
|
+
assert('value' in source);
|
|
418
|
+
values.push(source.value);
|
|
419
|
+
});
|
|
420
|
+
configValues[configName] = { ...configValueBase, value: values };
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
return configValues;
|
|
424
|
+
}
|
|
425
|
+
// TODO/now: refactor
|
|
305
426
|
// - Dedupe: most of the assertUsageGlobalConfigs() code below is a copy-paste of the assertUsage() logic inside getGlobalConfigs()
|
|
306
427
|
// - This assertUsage() message is slightly better: use this one for getGlobalConfigs()
|
|
307
428
|
// Global configs should be defined at global locations
|
|
@@ -318,7 +439,7 @@ function assertUsageGlobalConfigs(interfaceFilesRelevantList, configDefinitions,
|
|
|
318
439
|
if (isGlobalConfig(configName))
|
|
319
440
|
return;
|
|
320
441
|
const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
321
|
-
if (configDef.global) {
|
|
442
|
+
if (configDef.global === true) {
|
|
322
443
|
const locationIds = objectKeys(interfaceFilesByLocationId);
|
|
323
444
|
if (!isGlobalLocation(interfaceFile.locationId, locationIds)) {
|
|
324
445
|
const interfaceFilesGlobal = objectFromEntries(objectEntries(interfaceFilesByLocationId).filter(([locationId]) => {
|
|
@@ -377,63 +498,6 @@ function getInterfaceFilesRelevant(interfaceFilesByLocationId, locationIdPage) {
|
|
|
377
498
|
.sort(([locationId1], [locationId2]) => sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage)));
|
|
378
499
|
return interfaceFilesRelevant;
|
|
379
500
|
}
|
|
380
|
-
async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded) {
|
|
381
|
-
const locationIds = objectKeys(interfaceFilesByLocationId);
|
|
382
|
-
const interfaceFilesGlobal = objectFromEntries(objectEntries(interfaceFilesByLocationId).filter(([locationId]) => {
|
|
383
|
-
return isGlobalLocation(locationId, locationIds);
|
|
384
|
-
}));
|
|
385
|
-
// Validate that global configs live in global interface files
|
|
386
|
-
{
|
|
387
|
-
const interfaceFilesGlobalPaths = [];
|
|
388
|
-
objectEntries(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
|
|
389
|
-
assert(isGlobalLocation(locationId, locationIds));
|
|
390
|
-
interfaceFiles.forEach(({ filePath: { filePathAbsoluteUserRootDir } }) => {
|
|
391
|
-
if (filePathAbsoluteUserRootDir) {
|
|
392
|
-
interfaceFilesGlobalPaths.push(filePathAbsoluteUserRootDir);
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
});
|
|
396
|
-
const globalPaths = Array.from(new Set(interfaceFilesGlobalPaths.map((p) => path.posix.dirname(p))));
|
|
397
|
-
objectEntries(interfaceFilesByLocationId).forEach(([locationId, interfaceFiles]) => {
|
|
398
|
-
interfaceFiles.forEach((interfaceFile) => {
|
|
399
|
-
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
400
|
-
if (!isGlobalLocation(locationId, locationIds) && isGlobalConfig(configName)) {
|
|
401
|
-
assertUsage(false, [
|
|
402
|
-
`${interfaceFile.filePath.filePathToShowToUser} defines the config ${pc.cyan(configName)} which is global:`,
|
|
403
|
-
globalPaths.length
|
|
404
|
-
? `define ${pc.cyan(configName)} in ${joinEnglish(globalPaths, 'or')} instead`
|
|
405
|
-
: `create a global config (e.g. /pages/+config.js) and define ${pc.cyan(configName)} there instead`
|
|
406
|
-
].join(' '));
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
});
|
|
410
|
-
});
|
|
411
|
-
}
|
|
412
|
-
const pageConfigGlobalValues = {};
|
|
413
|
-
const pageConfigGlobal = {
|
|
414
|
-
configDefinitions: configDefinitionsBuiltInGlobal,
|
|
415
|
-
configValueSources: {}
|
|
416
|
-
};
|
|
417
|
-
await Promise.all(objectEntries(configDefinitionsBuiltInGlobal).map(async ([configName, configDef]) => {
|
|
418
|
-
const sources = await resolveConfigValueSources(configName, configDef, interfaceFilesGlobal, userRootDir, importedFilesLoaded);
|
|
419
|
-
const configValueSource = sources[0];
|
|
420
|
-
if (!configValueSource)
|
|
421
|
-
return;
|
|
422
|
-
if (configName === 'onBeforeRoute' || configName === 'onPrerenderStart') {
|
|
423
|
-
assert(!('value' in configValueSource));
|
|
424
|
-
pageConfigGlobal.configValueSources[configName] = [configValueSource];
|
|
425
|
-
}
|
|
426
|
-
else {
|
|
427
|
-
assert('value' in configValueSource);
|
|
428
|
-
if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
|
|
429
|
-
return;
|
|
430
|
-
const { filePathToShowToUser } = configValueSource.definedAtFilePath;
|
|
431
|
-
assertWarning(false, `Being able to define config ${pc.cyan(configName)} in ${filePathToShowToUser} is experimental and will likely be removed. Define the config ${pc.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
|
|
432
|
-
pageConfigGlobalValues[configName] = configValueSource.value;
|
|
433
|
-
}
|
|
434
|
-
}));
|
|
435
|
-
return { pageConfigGlobal, pageConfigGlobalValues };
|
|
436
|
-
}
|
|
437
501
|
async function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir, importedFilesLoaded) {
|
|
438
502
|
const sourcesInfo = [];
|
|
439
503
|
// interfaceFilesRelevant is sorted by sortAfterInheritanceOrder()
|
|
@@ -976,6 +1040,7 @@ function isLoadableAtBuildTime(configDef) {
|
|
|
976
1040
|
return !!configDef.env.config && !configDef._valueIsFilePath;
|
|
977
1041
|
}
|
|
978
1042
|
function isGlobalConfig(configName) {
|
|
1043
|
+
// TODO/now
|
|
979
1044
|
if (configName === 'prerender')
|
|
980
1045
|
return false;
|
|
981
1046
|
const configNamesGlobal = getConfigNamesGlobal();
|
|
@@ -984,6 +1049,12 @@ function isGlobalConfig(configName) {
|
|
|
984
1049
|
function getConfigNamesGlobal() {
|
|
985
1050
|
return Object.keys(configDefinitionsBuiltInGlobal);
|
|
986
1051
|
}
|
|
1052
|
+
function getConfigDefinitionsBuiltInGlobal() {
|
|
1053
|
+
return objectFromEntries(objectEntries(configDefinitionsBuiltInAll).filter(([_configName, configDef]) => configDef.global !== undefined));
|
|
1054
|
+
}
|
|
1055
|
+
function getConfigDefinitionsBuiltIn() {
|
|
1056
|
+
return objectFromEntries(objectEntries(configDefinitionsBuiltInAll).filter(([_configName, configDef]) => configDef.global !== true));
|
|
1057
|
+
}
|
|
987
1058
|
function assertConfigExists(configName, configNamesRelevant, filePathToShowToUser) {
|
|
988
1059
|
const configNames = [...configNamesRelevant, ...getConfigNamesGlobal()];
|
|
989
1060
|
if (configNames.includes(configName))
|
|
@@ -1010,3 +1081,35 @@ function sortConfigValueSources(configValueSources, locationIdPage) {
|
|
|
1010
1081
|
function getConfigValueInterfaceFile(interfaceFile, configName) {
|
|
1011
1082
|
return interfaceFile.fileExportsByConfigName[configName]?.configValue;
|
|
1012
1083
|
}
|
|
1084
|
+
// TODO/now: refactor code below
|
|
1085
|
+
function resolveVikeConfigGlobal(vikeVitePluginOptions, pageConfigGlobalValues) {
|
|
1086
|
+
const configs = [vikeVitePluginOptions, pageConfigGlobalValues];
|
|
1087
|
+
const vikeConfigGlobal = {
|
|
1088
|
+
disableAutoFullBuild: pickFirst(configs.map((c) => c.disableAutoFullBuild)) ?? null,
|
|
1089
|
+
prerender: resolvePrerenderOptions(configs),
|
|
1090
|
+
includeAssetsImportedByServer: pickFirst(configs.map((c) => c.includeAssetsImportedByServer)) ?? true,
|
|
1091
|
+
baseServer: pickFirst(configs.map((c) => c.baseServer)) ?? null,
|
|
1092
|
+
baseAssets: pickFirst(configs.map((c) => c.baseAssets)) ?? null,
|
|
1093
|
+
disableUrlNormalization: pickFirst(configs.map((c) => c.disableUrlNormalization)) ?? false,
|
|
1094
|
+
trailingSlash: pickFirst(configs.map((c) => c.trailingSlash)) ?? false
|
|
1095
|
+
};
|
|
1096
|
+
return vikeConfigGlobal;
|
|
1097
|
+
}
|
|
1098
|
+
function resolvePrerenderOptions(configs) {
|
|
1099
|
+
if (!configs.some((c) => c.prerender)) {
|
|
1100
|
+
return false;
|
|
1101
|
+
}
|
|
1102
|
+
const configsPrerender = configs.map((c) => c.prerender).filter(isObject2);
|
|
1103
|
+
return {
|
|
1104
|
+
partial: pickFirst(configsPrerender.map((c) => c.partial)) ?? false,
|
|
1105
|
+
noExtraDir: pickFirst(configsPrerender.map((c) => c.noExtraDir)) ?? false,
|
|
1106
|
+
parallel: pickFirst(configsPrerender.map((c) => c.parallel)) ?? true,
|
|
1107
|
+
disableAutoRun: pickFirst(configsPrerender.map((c) => c.disableAutoRun)) ?? false
|
|
1108
|
+
};
|
|
1109
|
+
}
|
|
1110
|
+
function isObject2(p) {
|
|
1111
|
+
return typeof p === 'object';
|
|
1112
|
+
}
|
|
1113
|
+
function pickFirst(arr) {
|
|
1114
|
+
return arr.filter((v) => v !== undefined)[0];
|
|
1115
|
+
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -31,7 +31,7 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
31
31
|
const importStatements = [];
|
|
32
32
|
const isClientRouting = getConfigValueBuildTime(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
33
33
|
lines.push('export const configValuesSerialized = {');
|
|
34
|
-
lines.push(...serializeConfigValues(pageConfig, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }),
|
|
34
|
+
lines.push(...serializeConfigValues(pageConfig, importStatements, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isDev }), '', false));
|
|
35
35
|
lines.push('};');
|
|
36
36
|
if (!fixServerAssets_isEnabled() && includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
37
37
|
importStatements.push(`import '${extractAssetsAddQuery(getVirtualFileIdPageConfigValuesAll(pageId, false))}'`);
|