vike 0.4.146 → 0.4.147-commit-f9a91f3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/plugin/index.js +6 -4
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +76 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +61 -40
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +104 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +62 -75
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +43 -17
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +12 -70
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +11 -8
- package/dist/cjs/node/plugin/shared/{getConfigValueSourcesRelevant.js → getConfigValueSourcesNotOverriden.js} +3 -3
- package/dist/cjs/node/plugin/utils.js +2 -0
- package/dist/cjs/node/prerender/runPrerender.js +75 -67
- package/dist/cjs/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
- package/dist/cjs/node/runtime/index-common.js +3 -1
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.js +12 -12
- package/dist/cjs/node/runtime/renderPage/createHttpResponseObject.js +3 -3
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +1 -2
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +1 -1
- package/dist/cjs/node/runtime/renderPage.js +75 -51
- package/dist/cjs/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +1 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +12 -3
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesSerialized.js +19 -0
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +3 -12
- package/dist/cjs/shared/route/resolveRedirects.js +8 -5
- package/dist/cjs/utils/assertKeys.js +28 -0
- package/dist/cjs/utils/joinEnglish.js +3 -3
- package/dist/cjs/utils/parseUrl-extras.js +22 -8
- package/dist/cjs/utils/parseUrl.js +24 -16
- package/dist/cjs/utils/projectInfo.js +3 -2
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +25 -11
- package/dist/esm/client/client-routing-runtime/index.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/index.js +1 -0
- package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +2 -2
- package/dist/esm/client/shared/getPageContextSerializedInHtml.js +1 -1
- package/dist/esm/node/plugin/index.d.ts +1 -0
- package/dist/esm/node/plugin/index.js +1 -0
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +70 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +58 -37
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +98 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +63 -76
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +43 -17
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +13 -68
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +11 -8
- package/dist/esm/node/plugin/shared/getConfigValueSourcesNotOverriden.d.ts +5 -0
- package/dist/esm/node/plugin/shared/{getConfigValueSourcesRelevant.js → getConfigValueSourcesNotOverriden.js} +2 -2
- package/dist/esm/node/plugin/utils.d.ts +2 -0
- package/dist/esm/node/plugin/utils.js +2 -0
- package/dist/esm/node/prerender/runPrerender.js +75 -67
- package/dist/esm/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
- package/dist/esm/node/runtime/index-common.d.ts +1 -0
- package/dist/esm/node/runtime/index-common.js +1 -0
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.js +13 -13
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject.js +3 -3
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +1 -2
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +1 -1
- package/dist/esm/node/runtime/renderPage.js +76 -52
- package/dist/esm/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +1 -0
- package/dist/esm/shared/page-configs/PageConfig.d.ts +14 -4
- package/dist/esm/shared/page-configs/loadConfigValues.js +12 -3
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.d.ts +4 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.js +16 -0
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +4 -13
- package/dist/esm/shared/route/resolveRedirects.js +8 -5
- package/dist/esm/utils/assertKeys.d.ts +4 -0
- package/dist/esm/utils/assertKeys.js +22 -0
- package/dist/esm/utils/joinEnglish.d.ts +1 -1
- package/dist/esm/utils/joinEnglish.js +3 -3
- package/dist/esm/utils/parseUrl-extras.d.ts +3 -1
- package/dist/esm/utils/parseUrl-extras.js +21 -7
- package/dist/esm/utils/parseUrl.js +24 -16
- package/dist/esm/utils/projectInfo.d.ts +3 -1
- package/dist/esm/utils/projectInfo.js +2 -1
- package/package.json +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +0 -28
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.d.ts +0 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +0 -25
- package/dist/esm/node/plugin/shared/getConfigValueSourcesRelevant.d.ts +0 -5
|
@@ -2,10 +2,9 @@ export { getVikeConfig };
|
|
|
2
2
|
export { reloadVikeConfig };
|
|
3
3
|
export { vikeConfigDependencies };
|
|
4
4
|
export { isVikeConfigFile };
|
|
5
|
-
import { assertPosixPath, assert, isObject, assertUsage,
|
|
5
|
+
import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEntries, hasProp, arrayIncludes, assertIsNotProductionRuntime, getMostSimilar, isNpmPackageImport, joinEnglish, lowerFirst, mergeCumulativeValues, requireResolve, getOutDirs, deepEqual, assertKeys } from '../../../utils.js';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { configDefinitionsBuiltIn, configDefinitionsBuiltInGlobal } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
8
|
-
import glob from 'fast-glob';
|
|
9
8
|
import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, isGlobalLocation, applyFilesystemRoutingRootEffect } from './getVikeConfig/filesystemRouting.js';
|
|
10
9
|
import { isTmpFile, transpileAndExecuteFile } from './transpileAndExecuteFile.js';
|
|
11
10
|
import { parseImportData } from './replaceImportStatements.js';
|
|
@@ -16,8 +15,9 @@ import { removeSuperfluousViteLog_enable, removeSuperfluousViteLog_disable } fro
|
|
|
16
15
|
import pc from '@brillout/picocolors';
|
|
17
16
|
import { getConfigDefinedAtString } from '../../../../../shared/page-configs/helpers.js';
|
|
18
17
|
import { assertExportsOfConfigFile, assertExportsOfValueFile } from '../../../../../shared/page-configs/assertExports.js';
|
|
19
|
-
import { getConfigValueSerialized } from './getVirtualFilePageConfigs.js';
|
|
20
18
|
import { getConfigVike } from '../../../../shared/getConfigVike.js';
|
|
19
|
+
import { assertConfigValueIsSerializable } from './getConfigValuesSerialized.js';
|
|
20
|
+
import { crawlPlusFiles } from './getVikeConfig/crawlPlusFiles.js';
|
|
21
21
|
assertIsNotProductionRuntime();
|
|
22
22
|
let devServerIsCorrupt = false;
|
|
23
23
|
let wasConfigInvalid = null;
|
|
@@ -70,7 +70,7 @@ async function getVikeConfig(config, isDev, tolerateInvalidConfig = false, exten
|
|
|
70
70
|
return await vikeConfigPromise;
|
|
71
71
|
}
|
|
72
72
|
async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
73
|
-
const plusFiles = await findPlusFiles(userRootDir,
|
|
73
|
+
const plusFiles = await findPlusFiles(userRootDir, outDirRoot, isDev, extensions);
|
|
74
74
|
const configFiles = [];
|
|
75
75
|
const valueFiles = [];
|
|
76
76
|
plusFiles.forEach((f) => {
|
|
@@ -151,12 +151,12 @@ async function loadImportedFile(filePath, userRootDir, importedFilesLoaded) {
|
|
|
151
151
|
return fileExports;
|
|
152
152
|
}
|
|
153
153
|
function isConfigEnv(configDef, configName) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
return
|
|
154
|
+
const configEnv = configDef.env;
|
|
155
|
+
if (configDef.cumulative) {
|
|
156
|
+
// In principle we could lift that requirement (but it requires non-trivial modifications)
|
|
157
|
+
assertUsage(configEnv.config, `Config ${pc.cyan(configName)} needs its ${pc.cyan('env')} to have ${pc.cyan('{ config: true }')} (because ${pc.cyan(configName)} is a ${pc.cyan('cumulative')} config)`);
|
|
158
|
+
}
|
|
159
|
+
return !!configEnv.config;
|
|
160
160
|
}
|
|
161
161
|
function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
162
162
|
const { fileExports, filePath, extendsFilePaths } = configFile;
|
|
@@ -509,6 +509,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
509
509
|
}
|
|
510
510
|
else if (interfaceFile.isValueFile) {
|
|
511
511
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
512
|
+
assert(valueAlreadyLoaded === !!configEnv.config);
|
|
512
513
|
const configValueSource = {
|
|
513
514
|
configEnv,
|
|
514
515
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
@@ -523,9 +524,6 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
523
524
|
if (valueAlreadyLoaded) {
|
|
524
525
|
configValueSource.value = conf.configValue;
|
|
525
526
|
}
|
|
526
|
-
else {
|
|
527
|
-
assert(configEnv !== 'config-only');
|
|
528
|
-
}
|
|
529
527
|
return configValueSource;
|
|
530
528
|
}
|
|
531
529
|
assert(false);
|
|
@@ -537,12 +535,12 @@ function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
|
|
|
537
535
|
}
|
|
538
536
|
const fileEnv = filesEnv.get(filePathForEnvCheck);
|
|
539
537
|
fileEnv.push({ configEnv, configName });
|
|
540
|
-
const configDifferentEnv = fileEnv.filter((c) => c.configEnv
|
|
538
|
+
const configDifferentEnv = fileEnv.filter((c) => !deepEqual(c.configEnv, configEnv))[0];
|
|
541
539
|
if (configDifferentEnv) {
|
|
542
540
|
assertUsage(false, [
|
|
543
541
|
`${filePathForEnvCheck} defines the value of configs living in different environments:`,
|
|
544
|
-
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${pc.cyan(c.configName)} which value lives in environment ${pc.cyan(c.configEnv)}`),
|
|
545
|
-
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/header-file
|
|
542
|
+
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${pc.cyan(c.configName)} which value lives in environment ${pc.cyan(JSON.stringify(c.configEnv))}`),
|
|
543
|
+
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/header-file'
|
|
546
544
|
].join('\n'));
|
|
547
545
|
}
|
|
548
546
|
}
|
|
@@ -678,30 +676,17 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
678
676
|
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}`)} to a value with an invalid type ${pc.cyan(typeof def)}: it should be an object instead.`);
|
|
679
677
|
}
|
|
680
678
|
// env
|
|
679
|
+
let configEnv;
|
|
681
680
|
{
|
|
682
|
-
|
|
683
|
-
'client-only',
|
|
684
|
-
'server-only',
|
|
685
|
-
'server-and-client',
|
|
686
|
-
'config-only'
|
|
687
|
-
];
|
|
688
|
-
const fix = [
|
|
689
|
-
`Set the value of ${pc.cyan(`meta.${configName}.env`)} to `,
|
|
690
|
-
joinEnglish(envValues.map((s) => pc.cyan(`'${s}'`)), 'or'),
|
|
691
|
-
'.'
|
|
692
|
-
].join('');
|
|
681
|
+
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
693
682
|
if (!('env' in def)) {
|
|
694
|
-
|
|
695
|
-
assertUsage(false, `${configMetaDefinedAt} doesn't set ${pc.cyan(`meta.${configName}.env`)} but it's required. ${fix}`);
|
|
696
|
-
}
|
|
697
|
-
if (!hasProp(def, 'env', 'string')) {
|
|
698
|
-
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
699
|
-
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}.env`)} to an invalid type ${pc.cyan(typeof def.env)}. ${fix}`);
|
|
700
|
-
}
|
|
701
|
-
if (!envValues.includes(def.env)) {
|
|
702
|
-
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
703
|
-
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}.env`)} to an unknown value ${pc.cyan(`'${def.env}'`)}. ${fix}`);
|
|
683
|
+
assertUsage(false, `${configMetaDefinedAt} doesn't set ${pc.cyan(`meta.${configName}.env`)} but it's required.`);
|
|
704
684
|
}
|
|
685
|
+
configEnv = getConfigEnvValue(def.env, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}.env`)} to`);
|
|
686
|
+
// Overwrite deprecated value with valid value
|
|
687
|
+
// TODO/v1-release: remove once support for the deprecated values is removed
|
|
688
|
+
if (typeof def.env === 'string')
|
|
689
|
+
def.env = configEnv;
|
|
705
690
|
}
|
|
706
691
|
// effect
|
|
707
692
|
if ('effect' in def) {
|
|
@@ -709,9 +694,9 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
709
694
|
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
710
695
|
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}.effect`)} to an invalid type ${pc.cyan(typeof def.effect)}: it should be a function instead`);
|
|
711
696
|
}
|
|
712
|
-
if (
|
|
697
|
+
if (!configEnv.config) {
|
|
713
698
|
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
714
|
-
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}.effect`)} but it's only supported if meta.${configName}.env
|
|
699
|
+
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}.effect`)} but it's only supported if meta.${configName}.env has ${pc.cyan('{ config: true }')} (but it's ${pc.cyan(JSON.stringify(configEnv))} instead)`);
|
|
715
700
|
}
|
|
716
701
|
}
|
|
717
702
|
});
|
|
@@ -722,8 +707,8 @@ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
|
|
|
722
707
|
return;
|
|
723
708
|
// The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
|
|
724
709
|
// (We could support effect for non config-only by always loading its value at config time, regardless of the config's `env` value.)
|
|
725
|
-
assertUsage(configDef.env
|
|
726
|
-
`Cannot add effect to ${pc.cyan(configName)} because its ${pc.cyan('env')} is ${pc.cyan(configDef.env)}: effects can only be added to configs with an ${pc.cyan('env')}
|
|
710
|
+
assertUsage(configDef.env.config, [
|
|
711
|
+
`Cannot add effect to ${pc.cyan(configName)} because its ${pc.cyan('env')} is ${pc.cyan(JSON.stringify(configDef.env))}: effects can only be added to configs with an ${pc.cyan('env')} with ${pc.cyan('{ config: true }')}.`
|
|
727
712
|
].join(' '));
|
|
728
713
|
const source = configValueSources[configName]?.[0];
|
|
729
714
|
if (!source)
|
|
@@ -791,39 +776,9 @@ function getComputed(configValueSources, configDefinitionsRelevant) {
|
|
|
791
776
|
});
|
|
792
777
|
return configValuesComputed;
|
|
793
778
|
}
|
|
794
|
-
async function findPlusFiles(userRootDir,
|
|
795
|
-
const
|
|
796
|
-
|
|
797
|
-
const ignorePatterns = [];
|
|
798
|
-
for (const dir of ignoreDirs) {
|
|
799
|
-
assertPosixPath(dir);
|
|
800
|
-
ignorePatterns.push(`${path.posix.relative(userRootDir, dir)}/**`);
|
|
801
|
-
}
|
|
802
|
-
const result = await glob(`**/+*.${scriptFileExtensions}`, {
|
|
803
|
-
ignore: [
|
|
804
|
-
'**/node_modules/**',
|
|
805
|
-
// Allow:
|
|
806
|
-
// ```
|
|
807
|
-
// +Page.js
|
|
808
|
-
// +Page.telefunc.js
|
|
809
|
-
// ```
|
|
810
|
-
'**/*.telefunc.*',
|
|
811
|
-
...ignorePatterns
|
|
812
|
-
],
|
|
813
|
-
cwd: userRootDir,
|
|
814
|
-
dot: false
|
|
815
|
-
});
|
|
816
|
-
const time = new Date().getTime() - timeBase;
|
|
817
|
-
if (isDev) {
|
|
818
|
-
// We only warn in dev, because while building it's expected to take a long time as fast-glob is competing for resources with other tasks
|
|
819
|
-
assertWarning(time < 2 * 1000, `Crawling your user files took an unexpected long time (${time}ms). Create a new issue on Vike's GitHub.`, {
|
|
820
|
-
onlyOnce: 'slow-page-files-search'
|
|
821
|
-
});
|
|
822
|
-
}
|
|
823
|
-
const plusFiles = result.map((p) => {
|
|
824
|
-
p = toPosixPath(p);
|
|
825
|
-
const filePathRelativeToUserRootDir = path.posix.join('/', p);
|
|
826
|
-
const filePathAbsoluteFilesystem = path.posix.join(userRootDir, p);
|
|
779
|
+
async function findPlusFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
780
|
+
const files = await crawlPlusFiles(userRootDir, outDirRoot, isDev);
|
|
781
|
+
const plusFiles = files.map(({ filePathRelativeToUserRootDir, filePathAbsoluteFilesystem }) => {
|
|
827
782
|
return {
|
|
828
783
|
filePathRelativeToUserRootDir,
|
|
829
784
|
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
@@ -1041,7 +996,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
1041
996
|
return { routeFilesystem, isErrorPage: undefined };
|
|
1042
997
|
}
|
|
1043
998
|
function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName) {
|
|
1044
|
-
assert(configFilesystemRoutingRoot.configEnv
|
|
999
|
+
assert(configFilesystemRoutingRoot.configEnv.config);
|
|
1045
1000
|
// Eagerly loaded since it's config-only
|
|
1046
1001
|
assert('value' in configFilesystemRoutingRoot);
|
|
1047
1002
|
const { value } = configFilesystemRoutingRoot;
|
|
@@ -1137,7 +1092,7 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1137
1092
|
// We could, in principle, also support cumulative for values that aren't loaded at config-time but it isn't completely trivial to implement.
|
|
1138
1093
|
assert('value' in configValueSource);
|
|
1139
1094
|
// Make sure configValueSource.value is serializable
|
|
1140
|
-
|
|
1095
|
+
assertConfigValueIsSerializable(configValueSource.value, configName, getDefinedAt(configValueSource));
|
|
1141
1096
|
const assertNoMixing = (isSet) => {
|
|
1142
1097
|
const vals1 = isSet ? valuesSet : valuesArr;
|
|
1143
1098
|
const t1 = isSet ? 'a Set' : 'an array';
|
|
@@ -1178,3 +1133,35 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1178
1133
|
}
|
|
1179
1134
|
assert(false);
|
|
1180
1135
|
}
|
|
1136
|
+
function getConfigEnvValue(val, errMsgIntro) {
|
|
1137
|
+
const errInvalidValue = `${errMsgIntro} an invalid value ${pc.cyan(JSON.stringify(val))}`;
|
|
1138
|
+
// Legacy outdated values
|
|
1139
|
+
if (typeof val === 'string') {
|
|
1140
|
+
const valConverted = (() => {
|
|
1141
|
+
if (val === 'client-only')
|
|
1142
|
+
return { client: true };
|
|
1143
|
+
if (val === 'server-only')
|
|
1144
|
+
return { server: true };
|
|
1145
|
+
if (val === 'server-and-client')
|
|
1146
|
+
return { server: true, client: true };
|
|
1147
|
+
if (val === 'config-only')
|
|
1148
|
+
return { config: true };
|
|
1149
|
+
if (val === '_routing-lazy')
|
|
1150
|
+
return { server: true, client: 'if-client-routing' };
|
|
1151
|
+
if (val === '_routing-eager')
|
|
1152
|
+
return { server: true, client: 'if-client-routing', eager: true };
|
|
1153
|
+
assertUsage(false, errInvalidValue);
|
|
1154
|
+
})();
|
|
1155
|
+
assertWarning(false, `${errMsgIntro} ${pc.cyan(val)} which is deprecated and will be removed in the next major release`, { onlyOnce: true });
|
|
1156
|
+
return valConverted;
|
|
1157
|
+
}
|
|
1158
|
+
assertUsage(isObject(val), `${errMsgIntro} an invalid type ${pc.cyan(typeof val)}`);
|
|
1159
|
+
assertKeys(val, ['config', 'server', 'client'], `${errInvalidValue}:`);
|
|
1160
|
+
assertUsage(hasProp(val, 'config', 'undefined') || hasProp(val, 'config', 'boolean'), errInvalidValue);
|
|
1161
|
+
assertUsage(hasProp(val, 'server', 'undefined') || hasProp(val, 'server', 'boolean'), errInvalidValue);
|
|
1162
|
+
assertUsage(hasProp(val, 'client', 'undefined') || hasProp(val, 'client', 'boolean'), errInvalidValue);
|
|
1163
|
+
/* Uncomment to allow users to set an eager config. Same for `{ client: 'if-client-routing' }`.
|
|
1164
|
+
assertUsage(hasProp(val, 'eager', 'undefined') || hasProp(val, 'eager', 'boolean'), errInvalidValue)
|
|
1165
|
+
*/
|
|
1166
|
+
return val;
|
|
1167
|
+
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -5,10 +5,11 @@ import { getVikeConfig } from './getVikeConfig.js';
|
|
|
5
5
|
import { extractAssetsAddQuery } from '../../../../shared/extractAssetsQuery.js';
|
|
6
6
|
import { debug } from './debug.js';
|
|
7
7
|
import { getConfigValue } from '../../../../../shared/page-configs/helpers.js';
|
|
8
|
-
import {
|
|
8
|
+
import { getConfigValueSourcesNotOverriden } from '../../../shared/getConfigValueSourcesNotOverriden.js';
|
|
9
9
|
import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
|
|
10
10
|
import { serializeConfigValueImported } from '../../../../../shared/page-configs/serialize/serializeConfigValue.js';
|
|
11
11
|
import { getConfigVike } from '../../../../shared/getConfigVike.js';
|
|
12
|
+
import { getConfigValuesSerialized } from './getConfigValuesSerialized.js';
|
|
12
13
|
async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
|
|
13
14
|
const result = isVirtualFileIdPageConfigValuesAll(id);
|
|
14
15
|
assert(result);
|
|
@@ -28,27 +29,52 @@ async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
|
|
|
28
29
|
return code;
|
|
29
30
|
}
|
|
30
31
|
function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAssetsImportedByServer, isDev) {
|
|
31
|
-
const configValue = getConfigValue(pageConfig, 'clientRouting', 'boolean');
|
|
32
|
-
const isClientRouting = configValue?.value ?? false;
|
|
33
32
|
const lines = [];
|
|
34
33
|
const importStatements = [];
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
const { valueIsImportedAtRuntime, configEnv, configName } = configValueSource;
|
|
39
|
-
if (!valueIsImportedAtRuntime)
|
|
40
|
-
return;
|
|
41
|
-
if (configValueSource.valueIsFilePath)
|
|
42
|
-
return;
|
|
43
|
-
if (!isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: false }))
|
|
44
|
-
return;
|
|
45
|
-
const whitespace = ' ';
|
|
46
|
-
lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
47
|
-
});
|
|
34
|
+
const isClientRouting = getConfigValue(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
35
|
+
lines.push('export const configValuesImported = [');
|
|
36
|
+
lines.push(getConfigValuesImported(pageConfig, isForClientSide, isClientRouting, importStatements));
|
|
48
37
|
lines.push('];');
|
|
38
|
+
lines.push('export const configValuesSerialized = {');
|
|
39
|
+
lines.push(getConfigValuesSerialized(pageConfig, (configEnv, configValueSource) => isEnvMatch(configEnv, !configValueSource ? false : checkWhetherIsImport(configValueSource), {
|
|
40
|
+
isImport: false,
|
|
41
|
+
isForClientSide,
|
|
42
|
+
isClientRouting
|
|
43
|
+
})));
|
|
44
|
+
lines.push('};');
|
|
49
45
|
if (includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
50
|
-
|
|
46
|
+
importStatements.push(`import '${extractAssetsAddQuery(getVirtualFileIdPageConfigValuesAll(pageId, false))}'`);
|
|
51
47
|
}
|
|
52
48
|
const code = [...importStatements, ...lines].join('\n');
|
|
53
49
|
return code;
|
|
54
50
|
}
|
|
51
|
+
function getConfigValuesImported(pageConfig, isForClientSide, isClientRouting, importStatements) {
|
|
52
|
+
const lines = [];
|
|
53
|
+
const varCounterContainer = { varCounter: 0 };
|
|
54
|
+
getConfigValueSourcesNotOverriden(pageConfig).forEach((configValueSource) => {
|
|
55
|
+
if (!isEnvMatch(configValueSource.configEnv, checkWhetherIsImport(configValueSource), {
|
|
56
|
+
isImport: true,
|
|
57
|
+
isForClientSide,
|
|
58
|
+
isClientRouting
|
|
59
|
+
}))
|
|
60
|
+
return;
|
|
61
|
+
const whitespace = ' ';
|
|
62
|
+
lines.push(...serializeConfigValueImported(configValueSource, configValueSource.configName, whitespace, varCounterContainer, importStatements));
|
|
63
|
+
});
|
|
64
|
+
const code = lines.join('\n');
|
|
65
|
+
return code;
|
|
66
|
+
}
|
|
67
|
+
function checkWhetherIsImport(configValueSource) {
|
|
68
|
+
const { valueIsImportedAtRuntime, valueIsFilePath } = configValueSource;
|
|
69
|
+
return valueIsImportedAtRuntime && !valueIsFilePath;
|
|
70
|
+
}
|
|
71
|
+
function isEnvMatch(configEnv, isImport, runtime) {
|
|
72
|
+
// Whether config value is imported or serialized
|
|
73
|
+
if (isImport !== runtime.isImport)
|
|
74
|
+
return false;
|
|
75
|
+
// Runtime match
|
|
76
|
+
const { isForClientSide, isClientRouting } = runtime;
|
|
77
|
+
if (!isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: false }))
|
|
78
|
+
return false;
|
|
79
|
+
return true;
|
|
80
|
+
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigs };
|
|
2
|
-
export { getConfigValueSerialized };
|
|
3
|
-
import type { DefinedAt } from '../../../../../shared/page-configs/PageConfig.js';
|
|
4
2
|
import type { ResolvedConfig } from 'vite';
|
|
5
3
|
declare function getVirtualFilePageConfigs(isForClientSide: boolean, isDev: boolean, id: string, isClientRouting: boolean, config: ResolvedConfig): Promise<string>;
|
|
6
|
-
declare function getConfigValueSerialized(value: unknown, configName: string, definedAt: DefinedAt): string;
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigs };
|
|
2
|
-
|
|
3
|
-
import { assert, assertUsage, getPropAccessNotation, objectEntries } from '../../../utils.js';
|
|
2
|
+
import { assert, objectEntries } from '../../../utils.js';
|
|
4
3
|
import { getVirtualFileIdPageConfigValuesAll } from '../../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
5
4
|
import { debug } from './debug.js';
|
|
6
|
-
import { isJsonSerializerError, stringify } from '@brillout/json-serializer/stringify';
|
|
7
|
-
import { getConfigEnv } from './helpers.js';
|
|
8
|
-
import pc from '@brillout/picocolors';
|
|
9
5
|
import { getVikeConfig } from './getVikeConfig.js';
|
|
10
6
|
import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
7
|
+
import { serializeConfigValueImported } from '../../../../../shared/page-configs/serialize/serializeConfigValue.js';
|
|
8
|
+
import { getConfigValuesSerialized } from './getConfigValuesSerialized.js';
|
|
13
9
|
async function getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, config) {
|
|
14
10
|
const { pageConfigs, pageConfigGlobal } = await getVikeConfig(config, isDev, true);
|
|
15
11
|
return getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
|
|
@@ -18,15 +14,18 @@ function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isCl
|
|
|
18
14
|
const lines = [];
|
|
19
15
|
const importStatements = [];
|
|
20
16
|
const varCounterContainer = { varCounter: 0 };
|
|
17
|
+
lines.push('export const pageConfigsSerialized = [');
|
|
21
18
|
lines.push(getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements, varCounterContainer));
|
|
19
|
+
lines.push('];');
|
|
20
|
+
lines.push('export const pageConfigGlobalSerialized = {');
|
|
22
21
|
lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements, varCounterContainer));
|
|
22
|
+
lines.push('};');
|
|
23
23
|
const code = [...importStatements, ...lines].join('\n');
|
|
24
24
|
debug(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
25
25
|
return code;
|
|
26
26
|
}
|
|
27
27
|
function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements, varCounterContainer) {
|
|
28
28
|
const lines = [];
|
|
29
|
-
lines.push('export const pageConfigsSerialized = [');
|
|
30
29
|
pageConfigs.forEach((pageConfig) => {
|
|
31
30
|
const { pageId, routeFilesystem, isErrorPage } = pageConfig;
|
|
32
31
|
const virtualFileIdPageConfigValuesAll = getVirtualFileIdPageConfigValuesAll(pageId, isForClientSide);
|
|
@@ -34,35 +33,13 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
|
|
|
34
33
|
lines.push(` pageId: ${JSON.stringify(pageId)},`);
|
|
35
34
|
lines.push(` isErrorPage: ${JSON.stringify(isErrorPage)},`);
|
|
36
35
|
lines.push(` routeFilesystem: ${JSON.stringify(routeFilesystem)},`);
|
|
37
|
-
lines.push(` loadConfigValuesAll:
|
|
36
|
+
lines.push(` loadConfigValuesAll: () => import(${JSON.stringify(virtualFileIdPageConfigValuesAll)}),`);
|
|
37
|
+
// Serialized config values
|
|
38
38
|
lines.push(` configValuesSerialized: {`);
|
|
39
|
-
|
|
40
|
-
const { value, configEnv } = configValuesComputed;
|
|
41
|
-
if (!isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: true }))
|
|
42
|
-
return;
|
|
43
|
-
if (pageConfig.configValueSources[configName])
|
|
44
|
-
return;
|
|
45
|
-
const configValue = pageConfig.configValues[configName];
|
|
46
|
-
assert(configValue);
|
|
47
|
-
const { definedAt } = configValue;
|
|
48
|
-
const valueSerialized = getConfigValueSerialized(value, configName, definedAt);
|
|
49
|
-
serializeConfigValue(lines, configName, { definedAt, valueSerialized });
|
|
50
|
-
});
|
|
51
|
-
Object.entries(pageConfig.configValueSources).forEach(([configName]) => {
|
|
52
|
-
const configValue = pageConfig.configValues[configName];
|
|
53
|
-
if (configValue) {
|
|
54
|
-
const configEnv = getConfigEnv(pageConfig.configValueSources, configName);
|
|
55
|
-
assert(configEnv, configName);
|
|
56
|
-
const isEnvMatch = isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: true });
|
|
57
|
-
if (!isEnvMatch)
|
|
58
|
-
return;
|
|
59
|
-
const { value, definedAt } = configValue;
|
|
60
|
-
const valueSerialized = getConfigValueSerialized(value, configName, definedAt);
|
|
61
|
-
serializeConfigValue(lines, configName, { definedAt, valueSerialized });
|
|
62
|
-
}
|
|
63
|
-
});
|
|
39
|
+
lines.push(getConfigValuesSerialized(pageConfig, (configEnv) => isRuntimeEnvMatch(configEnv, { isForClientSide, isClientRouting, isEager: true })));
|
|
64
40
|
lines.push(` },`);
|
|
65
|
-
|
|
41
|
+
// Imported config values
|
|
42
|
+
const whitespace = ' ';
|
|
66
43
|
lines.push(`${whitespace}configValuesImported: [`);
|
|
67
44
|
Object.entries(pageConfig.configValueSources).forEach(([configName, sources]) => {
|
|
68
45
|
const configValue = pageConfig.configValues[configName];
|
|
@@ -70,21 +47,18 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
|
|
|
70
47
|
return;
|
|
71
48
|
const configValueSource = sources[0];
|
|
72
49
|
assert(configValueSource);
|
|
73
|
-
if (configValueSource.configEnv
|
|
50
|
+
if (!configValueSource.configEnv.eager)
|
|
74
51
|
return;
|
|
75
52
|
lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
76
53
|
});
|
|
77
54
|
lines.push(`${whitespace}],`);
|
|
78
|
-
// pageConfig end
|
|
79
55
|
lines.push(` },`);
|
|
80
56
|
});
|
|
81
|
-
lines.push('];');
|
|
82
57
|
const code = lines.join('\n');
|
|
83
58
|
return code;
|
|
84
59
|
}
|
|
85
60
|
function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements, varCounterContainer) {
|
|
86
61
|
const lines = [];
|
|
87
|
-
lines.push('export const pageConfigGlobalSerialized = {');
|
|
88
62
|
/* Nothing (yet)
|
|
89
63
|
lines.push(` configValuesSerialized: {`)
|
|
90
64
|
lines.push(` },`)
|
|
@@ -109,35 +83,6 @@ function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, is
|
|
|
109
83
|
lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
110
84
|
});
|
|
111
85
|
lines.push(` ],`);
|
|
112
|
-
lines.push('};');
|
|
113
86
|
const code = lines.join('\n');
|
|
114
87
|
return code;
|
|
115
88
|
}
|
|
116
|
-
function getConfigValueSerialized(value, configName, definedAt) {
|
|
117
|
-
const valueName = `config${getPropAccessNotation(configName)}`;
|
|
118
|
-
let configValueSerialized;
|
|
119
|
-
try {
|
|
120
|
-
configValueSerialized = stringify(value, { valueName, forbidReactElements: true });
|
|
121
|
-
}
|
|
122
|
-
catch (err) {
|
|
123
|
-
let serializationErrMsg = '';
|
|
124
|
-
if (isJsonSerializerError(err)) {
|
|
125
|
-
serializationErrMsg = err.messageCore;
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
// When a property getter throws an error
|
|
129
|
-
console.error('Serialization error:');
|
|
130
|
-
console.error(err);
|
|
131
|
-
serializationErrMsg = 'see serialization error printed above';
|
|
132
|
-
}
|
|
133
|
-
const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
|
|
134
|
-
assert(configValueFilePathToShowToUser);
|
|
135
|
-
assertUsage(false, [
|
|
136
|
-
`The value of the config ${pc.cyan(configName)} cannot be defined inside the file ${configValueFilePathToShowToUser}:`,
|
|
137
|
-
`its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because its value isn't serializable: ${serializationErrMsg}.)`,
|
|
138
|
-
`Only serializable config values can be defined inside +config.h.js files, see https://vike.dev/header-file.`
|
|
139
|
-
].join(' '));
|
|
140
|
-
}
|
|
141
|
-
configValueSerialized = JSON.stringify(configValueSerialized);
|
|
142
|
-
return configValueSerialized;
|
|
143
|
-
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
export { isRuntimeEnvMatch };
|
|
2
2
|
function isRuntimeEnvMatch(configEnv, runtime) {
|
|
3
|
-
|
|
4
|
-
if (
|
|
5
|
-
|
|
6
|
-
if (configEnv === (isForClientSide ? 'server-only' : 'client-only'))
|
|
7
|
-
return false;
|
|
8
|
-
if (configEnv === '_routing-eager' || configEnv === '_routing-lazy') {
|
|
9
|
-
if (isForClientSide && !isClientRouting)
|
|
3
|
+
// Runtime
|
|
4
|
+
if (!runtime.isForClientSide) {
|
|
5
|
+
if (!configEnv.server)
|
|
10
6
|
return false;
|
|
11
|
-
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
if (!configEnv.client)
|
|
10
|
+
return false;
|
|
11
|
+
if (configEnv.client === 'if-client-routing' && !runtime.isClientRouting)
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
|
+
// Eager
|
|
15
|
+
if (runtime.isEager !== !!configEnv.eager)
|
|
16
|
+
return false;
|
|
14
17
|
return true;
|
|
15
18
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { getConfigValueSourcesNotOverriden };
|
|
2
|
+
import type { ConfigValueSource, PageConfigBuildTime } from '../../../shared/page-configs/PageConfig.js';
|
|
3
|
+
declare function getConfigValueSourcesNotOverriden(pageConfig: PageConfigBuildTime): (ConfigValueSource & {
|
|
4
|
+
configName: string;
|
|
5
|
+
})[];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { getConfigValueSourcesNotOverriden };
|
|
2
2
|
import { assert, assertIsNotBrowser } from '../../shared/utils.js';
|
|
3
3
|
assertIsNotBrowser();
|
|
4
|
-
function
|
|
4
|
+
function getConfigValueSourcesNotOverriden(pageConfig) {
|
|
5
5
|
const configValueSourcesRelevant = Object.entries(pageConfig.configValueSources).map(([configName, sources]) => {
|
|
6
6
|
const configValueSource = sources[0];
|
|
7
7
|
assert(configValueSource);
|
|
@@ -16,3 +16,5 @@ export * from '../../utils/removeEmptyLines.js';
|
|
|
16
16
|
export * from '../../utils/findUserPackageJsonPath.js';
|
|
17
17
|
export * from '../../utils/getPropAccessNotation.js';
|
|
18
18
|
export * from '../../utils/mergeCumulativeValues.js';
|
|
19
|
+
export * from '../../utils/deepEqual.js';
|
|
20
|
+
export * from '../../utils/assertKeys.js';
|
|
@@ -22,3 +22,5 @@ export * from '../../utils/removeEmptyLines.js';
|
|
|
22
22
|
export * from '../../utils/findUserPackageJsonPath.js';
|
|
23
23
|
export * from '../../utils/getPropAccessNotation.js';
|
|
24
24
|
export * from '../../utils/mergeCumulativeValues.js';
|
|
25
|
+
export * from '../../utils/deepEqual.js';
|
|
26
|
+
export * from '../../utils/assertKeys.js';
|