vike 0.4.144-commit-6aef8a6 → 0.4.144-commit-f7ab002
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/plugin/plugins/buildConfig.js +2 -2
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +29 -42
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +13 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/cjs/node/plugin/plugins/previewConfig.js +6 -2
- package/dist/cjs/node/prerender/runPrerender.js +8 -8
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +19 -6
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
- package/dist/cjs/node/shared/getClientEntryFilePath.js +2 -2
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +4 -6
- package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
- package/dist/cjs/shared/hooks/getHook.js +1 -1
- package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +43 -0
- package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +44 -0
- package/dist/cjs/shared/page-configs/helpers.js +33 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +6 -8
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +2 -2
- package/dist/cjs/shared/route/loadPageRoutes.js +11 -10
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/getPageContext.js +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig.js +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +29 -42
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +14 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/esm/node/plugin/plugins/previewConfig.js +6 -2
- package/dist/esm/node/prerender/runPrerender.js +2 -2
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +20 -7
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
- package/dist/esm/node/shared/getClientEntryFilePath.js +1 -1
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +2 -4
- package/dist/esm/shared/getPageFiles/getExports.js +2 -2
- package/dist/esm/shared/hooks/getHook.js +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +4 -12
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +7 -0
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +37 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.d.ts +14 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.js +38 -0
- package/dist/esm/shared/page-configs/helpers.d.ts +13 -0
- package/dist/esm/shared/page-configs/helpers.js +27 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +6 -8
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +7 -6
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/shared/page-configs/utils.js +0 -96
- package/dist/esm/shared/page-configs/utils.d.ts +0 -35
- package/dist/esm/shared/page-configs/utils.js +0 -90
|
@@ -7,7 +7,7 @@ exports.analyzeClientEntries = exports.assertRollupInput = exports.buildConfig =
|
|
|
7
7
|
const utils_js_1 = require("../utils.js");
|
|
8
8
|
const virtualFileImportUserCode_js_1 = require("../../shared/virtual-files/virtualFileImportUserCode.js");
|
|
9
9
|
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
10
|
-
const
|
|
10
|
+
const helpers_js_1 = require("../../../shared/page-configs/helpers.js");
|
|
11
11
|
const findPageFiles_js_1 = require("../shared/findPageFiles.js");
|
|
12
12
|
const getConfigVike_js_1 = require("../../shared/getConfigVike.js");
|
|
13
13
|
const virtualFilePageConfigValuesAll_js_1 = require("../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
@@ -112,7 +112,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
112
112
|
let clientEntries = {};
|
|
113
113
|
let clientFilePaths = [];
|
|
114
114
|
pageConfigs.forEach((pageConfig) => {
|
|
115
|
-
const configValue = (0,
|
|
115
|
+
const configValue = (0, helpers_js_1.getConfigValue)(pageConfig, 'clientRouting', 'boolean');
|
|
116
116
|
if (configValue?.value) {
|
|
117
117
|
hasClientRouting = true;
|
|
118
118
|
}
|
|
@@ -37,18 +37,18 @@ async function getPageDeps(config, pageConfigs, isDev) {
|
|
|
37
37
|
configValueSourcesRelevant.forEach((configValueSource) => {
|
|
38
38
|
if (!configValueSource.valueIsImportedAtRuntime)
|
|
39
39
|
return;
|
|
40
|
-
const {
|
|
40
|
+
const { definedAt, configEnv } = configValueSource;
|
|
41
41
|
if (configEnv !== 'client-only' && configEnv !== 'server-and-client')
|
|
42
42
|
return;
|
|
43
|
-
if (
|
|
44
|
-
const { filePathAbsoluteFilesystem } =
|
|
43
|
+
if (definedAt.filePathRelativeToUserRootDir !== null) {
|
|
44
|
+
const { filePathAbsoluteFilesystem } = definedAt;
|
|
45
45
|
(0, utils_js_1.assert)(filePathAbsoluteFilesystem);
|
|
46
46
|
// Surprisingly Vite expects entries to be absolute paths
|
|
47
47
|
entries.push(filePathAbsoluteFilesystem);
|
|
48
48
|
}
|
|
49
49
|
else {
|
|
50
|
-
// Adding
|
|
51
|
-
const { importPathAbsolute } =
|
|
50
|
+
// Adding definedAt.filePathAbsoluteFilesystem doesn't work for npm packages, I guess because of Vite's config.server.fs.allow
|
|
51
|
+
const { importPathAbsolute } = definedAt;
|
|
52
52
|
(0, utils_js_1.assert)(importPathAbsolute);
|
|
53
53
|
// We need to differentiate between npm package imports and path aliases.
|
|
54
54
|
// There are path aliases that cannot be distinguished from npm package names.
|
|
@@ -49,16 +49,17 @@ const configDefinitionsBuiltIn = {
|
|
|
49
49
|
_valueIsFilePath: true
|
|
50
50
|
},
|
|
51
51
|
clientRouting: {
|
|
52
|
-
|
|
52
|
+
// We could make it 'server-only' (we don't yet because of some legacy V0.4 design code)
|
|
53
|
+
env: 'server-and-client'
|
|
53
54
|
},
|
|
54
55
|
prerender: {
|
|
55
56
|
env: 'server-only'
|
|
56
57
|
},
|
|
57
58
|
hydrationCanBeAborted: {
|
|
58
|
-
env: 'client-only'
|
|
59
|
+
env: 'client-only'
|
|
59
60
|
},
|
|
60
61
|
prefetchStaticAssets: {
|
|
61
|
-
env: 'client-only'
|
|
62
|
+
env: 'client-only'
|
|
62
63
|
},
|
|
63
64
|
extends: {
|
|
64
65
|
env: 'config-only'
|
|
@@ -16,7 +16,7 @@ const globalContext_js_1 = require("../../../../runtime/globalContext.js");
|
|
|
16
16
|
const loggerNotProd_js_1 = require("../../../shared/loggerNotProd.js");
|
|
17
17
|
const removeSuperfluousViteLog_js_1 = require("../../../shared/loggerVite/removeSuperfluousViteLog.js");
|
|
18
18
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
19
|
-
const
|
|
19
|
+
const helpers_js_1 = require("../../../../../shared/page-configs/helpers.js");
|
|
20
20
|
const assertExports_js_1 = require("../../../../../shared/page-configs/assertExports.js");
|
|
21
21
|
const getVirtualFilePageConfigs_js_1 = require("./getVirtualFilePageConfigs.js");
|
|
22
22
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
@@ -334,7 +334,7 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
|
334
334
|
(0, utils_js_1.assert)('value' in configValueSource);
|
|
335
335
|
if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
|
|
336
336
|
return;
|
|
337
|
-
const { filePathToShowToUser } = configValueSource.
|
|
337
|
+
const { filePathToShowToUser } = configValueSource.definedAt;
|
|
338
338
|
(0, utils_js_1.assertWarning)(false, `Being able to define config ${picocolors_1.default.cyan(configName)} in ${filePathToShowToUser} is experimental and will likely be removed. Define the config ${picocolors_1.default.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
|
|
339
339
|
globalVikeConfig[configName] = configValueSource.value;
|
|
340
340
|
}
|
|
@@ -416,9 +416,14 @@ function makeOrderDeterministic(interfaceFile1, interfaceFile2) {
|
|
|
416
416
|
}
|
|
417
417
|
function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden, configName, configDef, userRootDir) {
|
|
418
418
|
interfaceFilesOverriden.forEach((interfaceFileLoser) => {
|
|
419
|
+
const configValueSourceLoser_ = getConfigValueSource(configName, interfaceFileLoser, configDef, userRootDir);
|
|
419
420
|
const configValueSourceWinner = getConfigValueSource(configName, interfaceFileWinner, configDef, userRootDir);
|
|
420
|
-
|
|
421
|
-
(0,
|
|
421
|
+
// prettier-ignore
|
|
422
|
+
const configLoser_DefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configValueSourceLoser_);
|
|
423
|
+
// prettier-ignore
|
|
424
|
+
const configWinnerDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('config', configName, configValueSourceWinner);
|
|
425
|
+
const errMsg = `${configLoser_DefinedAt} is overriden by another ${configWinnerDefinedAt}, remove one of the two`;
|
|
426
|
+
(0, utils_js_1.assertWarning)(false, errMsg, { onlyOnce: false });
|
|
422
427
|
});
|
|
423
428
|
}
|
|
424
429
|
function isInterfaceFileUserLand(interfaceFile) {
|
|
@@ -433,20 +438,20 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
433
438
|
fileExportPathToShowToUser: ['default', configName]
|
|
434
439
|
};
|
|
435
440
|
if (configDef._valueIsFilePath) {
|
|
436
|
-
let
|
|
441
|
+
let definedAt;
|
|
437
442
|
let valueFilePath;
|
|
438
443
|
if (interfaceFile.isConfigFile) {
|
|
439
444
|
const { configValue } = conf;
|
|
440
445
|
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
441
|
-
const configDefinedAt =
|
|
446
|
+
const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, { definedAt: definedAtConfigFile });
|
|
442
447
|
(0, utils_js_1.assertUsage)(import_, `${configDefinedAt} should be an import`);
|
|
443
448
|
valueFilePath = import_.filePathAbsoluteVite;
|
|
444
|
-
|
|
449
|
+
definedAt = import_;
|
|
445
450
|
}
|
|
446
451
|
else {
|
|
447
452
|
(0, utils_js_1.assert)(interfaceFile.isValueFile);
|
|
448
453
|
valueFilePath = interfaceFile.filePath.filePathAbsoluteVite;
|
|
449
|
-
|
|
454
|
+
definedAt = {
|
|
450
455
|
...interfaceFile.filePath,
|
|
451
456
|
fileExportPathToShowToUser: []
|
|
452
457
|
};
|
|
@@ -456,7 +461,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
456
461
|
valueIsFilePath: true,
|
|
457
462
|
configEnv,
|
|
458
463
|
valueIsImportedAtRuntime: true,
|
|
459
|
-
|
|
464
|
+
definedAt
|
|
460
465
|
};
|
|
461
466
|
return configValueSource;
|
|
462
467
|
}
|
|
@@ -468,7 +473,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
468
473
|
const configValueSource = {
|
|
469
474
|
configEnv,
|
|
470
475
|
valueIsImportedAtRuntime: true,
|
|
471
|
-
|
|
476
|
+
definedAt: import_
|
|
472
477
|
};
|
|
473
478
|
return configValueSource;
|
|
474
479
|
}
|
|
@@ -477,7 +482,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
477
482
|
value: configValue,
|
|
478
483
|
configEnv,
|
|
479
484
|
valueIsImportedAtRuntime: false,
|
|
480
|
-
|
|
485
|
+
definedAt: definedAtConfigFile
|
|
481
486
|
};
|
|
482
487
|
return configValueSource;
|
|
483
488
|
}
|
|
@@ -487,7 +492,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
487
492
|
const configValueSource = {
|
|
488
493
|
configEnv,
|
|
489
494
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
490
|
-
|
|
495
|
+
definedAt: {
|
|
491
496
|
...interfaceFile.filePath,
|
|
492
497
|
fileExportPathToShowToUser: configName === interfaceFile.configName
|
|
493
498
|
? []
|
|
@@ -620,9 +625,7 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
620
625
|
if (!configMeta)
|
|
621
626
|
return;
|
|
622
627
|
const meta = configMeta.configValue;
|
|
623
|
-
assertMetaValue(meta,
|
|
624
|
-
// TODO: Maybe we should use the getConfigDefinedAtString() helper?
|
|
625
|
-
`Config ${picocolors_1.default.cyan('meta')} defined at ${interfaceFile.filePath.filePathToShowToUser}`);
|
|
628
|
+
assertMetaValue(meta, `Config ${picocolors_1.default.cyan('meta')} defined at ${interfaceFile.filePath.filePathToShowToUser}`);
|
|
626
629
|
// Set configDef._userEffectDefinedAt
|
|
627
630
|
Object.entries(meta).forEach(([configName, configDef]) => {
|
|
628
631
|
if (!configDef.effect)
|
|
@@ -710,7 +713,7 @@ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
|
|
|
710
713
|
// Call effect
|
|
711
714
|
const configModFromEffect = configDef.effect({
|
|
712
715
|
configValue: source.value,
|
|
713
|
-
configDefinedAt:
|
|
716
|
+
configDefinedAt: (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, source)
|
|
714
717
|
});
|
|
715
718
|
if (!configModFromEffect)
|
|
716
719
|
return;
|
|
@@ -724,8 +727,8 @@ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
|
724
727
|
if (configName === 'meta') {
|
|
725
728
|
let configDefinedAtString;
|
|
726
729
|
if (configDefEffect._userEffectDefinedAt) {
|
|
727
|
-
configDefinedAtString =
|
|
728
|
-
|
|
730
|
+
configDefinedAtString = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, {
|
|
731
|
+
definedAt: configDefEffect._userEffectDefinedAt
|
|
729
732
|
});
|
|
730
733
|
}
|
|
731
734
|
else {
|
|
@@ -749,7 +752,7 @@ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
|
749
752
|
else {
|
|
750
753
|
(0, utils_js_1.assertUsage)(false, notSupported);
|
|
751
754
|
// If we do end implementing being able to set the value of a config:
|
|
752
|
-
// - For setting
|
|
755
|
+
// - For setting definedAt: we could take the definedAt of the effect config while appending '(effect)' to definedAt.fileExportPathToShowToUser
|
|
753
756
|
}
|
|
754
757
|
});
|
|
755
758
|
}
|
|
@@ -879,8 +882,6 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
879
882
|
const extendsConfigFiles = [];
|
|
880
883
|
extendsImportData.map((importData) => {
|
|
881
884
|
const { importPath: importPath } = importData;
|
|
882
|
-
// TODO
|
|
883
|
-
// - validate extends configs
|
|
884
885
|
const filePathAbsoluteFilesystem = resolveImportPath(importData, configFilePath);
|
|
885
886
|
assertImportPath(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
886
887
|
assertExtendsImportPath(importPath, filePathAbsoluteFilesystem, configFilePath);
|
|
@@ -1024,10 +1025,10 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
|
|
|
1024
1025
|
// Eagerly loaded since it's config-only
|
|
1025
1026
|
(0, utils_js_1.assert)('value' in configFilesystemRoutingRoot);
|
|
1026
1027
|
const { value } = configFilesystemRoutingRoot;
|
|
1027
|
-
const configDefinedAt =
|
|
1028
|
+
const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configFilesystemRoutingRoot);
|
|
1028
1029
|
(0, utils_js_1.assertUsage)(typeof value === 'string', `${configDefinedAt} should be a string`);
|
|
1029
1030
|
(0, utils_js_1.assertUsage)(value.startsWith('/'), `${configDefinedAt} is ${picocolors_1.default.cyan(value)} but it should start with a leading slash ${picocolors_1.default.cyan('/')}`);
|
|
1030
|
-
const { filePathRelativeToUserRootDir } = configFilesystemRoutingRoot.
|
|
1031
|
+
const { filePathRelativeToUserRootDir } = configFilesystemRoutingRoot.definedAt;
|
|
1031
1032
|
(0, utils_js_1.assert)(filePathRelativeToUserRootDir);
|
|
1032
1033
|
const before = (0, filesystemRouting_js_1.getFilesystemRouteString)((0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir));
|
|
1033
1034
|
const after = value;
|
|
@@ -1092,7 +1093,6 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
1092
1093
|
configValues[configName] = {
|
|
1093
1094
|
value,
|
|
1094
1095
|
definedAt: {
|
|
1095
|
-
isCumulative: true,
|
|
1096
1096
|
files: sources.map((source) => getDefinedAtFile(source))
|
|
1097
1097
|
}
|
|
1098
1098
|
};
|
|
@@ -1102,21 +1102,19 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
1102
1102
|
}
|
|
1103
1103
|
function getDefinedAtFile(configValueSource) {
|
|
1104
1104
|
return {
|
|
1105
|
-
filePathToShowToUser: configValueSource.
|
|
1106
|
-
fileExportPathToShowToUser: configValueSource.
|
|
1105
|
+
filePathToShowToUser: configValueSource.definedAt.filePathToShowToUser,
|
|
1106
|
+
fileExportPathToShowToUser: configValueSource.definedAt.fileExportPathToShowToUser
|
|
1107
1107
|
};
|
|
1108
1108
|
}
|
|
1109
1109
|
function getDefinedAt(configValueSource) {
|
|
1110
|
-
return
|
|
1111
|
-
file: getDefinedAtFile(configValueSource)
|
|
1112
|
-
};
|
|
1110
|
+
return getDefinedAtFile(configValueSource);
|
|
1113
1111
|
}
|
|
1114
1112
|
function mergeCumulative(configName, configValueSources) {
|
|
1115
1113
|
const valuesArr = [];
|
|
1116
1114
|
const valuesSet = [];
|
|
1117
1115
|
let configValueSourcePrevious = null;
|
|
1118
1116
|
configValueSources.forEach((configValueSource) => {
|
|
1119
|
-
const configDefinedAt =
|
|
1117
|
+
const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configValueSource);
|
|
1120
1118
|
const configNameColored = picocolors_1.default.cyan(configName);
|
|
1121
1119
|
// We could, in principle, also support cumulative values to be defined in +${configName}.js but it ins't completely trivial to implement
|
|
1122
1120
|
(0, utils_js_1.assertUsage)('value' in configValueSource, `${configDefinedAt} is only allowed to be defined in a +config.h.js file. (Because the values of ${configNameColored} are cumulative.)`);
|
|
@@ -1134,7 +1132,7 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1134
1132
|
if (vals2.length === 0)
|
|
1135
1133
|
return;
|
|
1136
1134
|
(0, utils_js_1.assert)(configValueSourcePrevious);
|
|
1137
|
-
const configPreviousDefinedAt =
|
|
1135
|
+
const configPreviousDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configValueSourcePrevious);
|
|
1138
1136
|
(0, utils_js_1.assertUsage)(false, `${configDefinedAt} sets ${t1} but another ${configPreviousDefinedAt} sets ${t2} which is forbidden: the values must be all arrays or all sets (you cannot mix).`);
|
|
1139
1137
|
};
|
|
1140
1138
|
const { value } = configValueSource;
|
|
@@ -1165,14 +1163,3 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1165
1163
|
}
|
|
1166
1164
|
(0, utils_js_1.assert)(false);
|
|
1167
1165
|
}
|
|
1168
|
-
// TODO: rename and/or refactor
|
|
1169
|
-
function getConfigSourceDefinedAtString(configName, { definedAtInfo }, sentenceBegin = true) {
|
|
1170
|
-
return (0, utils_js_2.getConfigDefinedAtString)(configName, {
|
|
1171
|
-
definedAt: {
|
|
1172
|
-
file: {
|
|
1173
|
-
filePathToShowToUser: definedAtInfo.filePathToShowToUser,
|
|
1174
|
-
fileExportPathToShowToUser: definedAtInfo.fileExportPathToShowToUser
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
}, sentenceBegin);
|
|
1178
|
-
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -6,7 +6,7 @@ const virtualFilePageConfigValuesAll_js_1 = require("../../../../shared/virtual-
|
|
|
6
6
|
const getVikeConfig_js_1 = require("./getVikeConfig.js");
|
|
7
7
|
const extractAssetsQuery_js_1 = require("../../../../shared/extractAssetsQuery.js");
|
|
8
8
|
const debug_js_1 = require("./debug.js");
|
|
9
|
-
const
|
|
9
|
+
const helpers_js_1 = require("../../../../../shared/page-configs/helpers.js");
|
|
10
10
|
const getConfigValueSourcesRelevant_js_1 = require("../../../shared/getConfigValueSourcesRelevant.js");
|
|
11
11
|
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
12
12
|
const serializeConfigValue_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValue.js");
|
|
@@ -29,7 +29,7 @@ async function getVirtualFilePageConfigValuesAll(id, userRootDir, outDirRoot, is
|
|
|
29
29
|
}
|
|
30
30
|
exports.getVirtualFilePageConfigValuesAll = getVirtualFilePageConfigValuesAll;
|
|
31
31
|
function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAssetsImportedByServer, isDev) {
|
|
32
|
-
const configValue = (0,
|
|
32
|
+
const configValue = (0, helpers_js_1.getConfigValue)(pageConfig, 'clientRouting', 'boolean');
|
|
33
33
|
const isClientRouting = configValue?.value ?? false;
|
|
34
34
|
const lines = [];
|
|
35
35
|
const importStatements = [];
|
|
@@ -12,7 +12,7 @@ const helpers_js_1 = require("./helpers.js");
|
|
|
12
12
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
13
|
const getVikeConfig_js_1 = require("./getVikeConfig.js");
|
|
14
14
|
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
15
|
-
const
|
|
15
|
+
const helpers_js_2 = require("../../../../../shared/page-configs/helpers.js");
|
|
16
16
|
const serializeConfigValue_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValue.js");
|
|
17
17
|
async function getVirtualFilePageConfigs(userRootDir, outDirRoot, isForClientSide, isDev, id, configVike, isClientRouting) {
|
|
18
18
|
const { pageConfigs, pageConfigGlobal } = await (0, getVikeConfig_js_1.getVikeConfig)(userRootDir, outDirRoot, isDev, configVike.extensions, true);
|
|
@@ -110,15 +110,23 @@ function getConfigValueSerialized(value, configName, definedAt) {
|
|
|
110
110
|
const valueName = `config${(0, utils_js_1.getPropAccessNotation)(configName)}`;
|
|
111
111
|
let configValueSerialized;
|
|
112
112
|
try {
|
|
113
|
-
configValueSerialized = (0, stringify_1.stringify)(value, { valueName });
|
|
113
|
+
configValueSerialized = (0, stringify_1.stringify)(value, { valueName, forbidReactElements: true });
|
|
114
114
|
}
|
|
115
115
|
catch (err) {
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
let serializationErrMsg = '';
|
|
117
|
+
if ((0, stringify_1.isJsonSerializerError)(err)) {
|
|
118
|
+
serializationErrMsg = err.messageCore;
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
console.error('Serialization error:');
|
|
122
|
+
console.error(err);
|
|
123
|
+
serializationErrMsg = 'see serialization error printed above';
|
|
124
|
+
}
|
|
125
|
+
const configValueFilePathToShowToUser = (0, helpers_js_2.getConfigValueFilePathToShowToUser)({ definedAt });
|
|
118
126
|
(0, utils_js_1.assert)(configValueFilePathToShowToUser);
|
|
119
127
|
(0, utils_js_1.assertUsage)(false, [
|
|
120
128
|
`The value of the config ${picocolors_1.default.cyan(configName)} cannot be defined inside the file ${configValueFilePathToShowToUser}:`,
|
|
121
|
-
`its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because
|
|
129
|
+
`its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because its value isn't serializable: ${serializationErrMsg}.)`,
|
|
122
130
|
`Only serializable config values can be defined inside +config.h.js files, see https://vike.dev/header-file.`
|
|
123
131
|
].join(' '));
|
|
124
132
|
}
|
|
@@ -7,20 +7,7 @@ function getConfigEnv(configValueSources, configName) {
|
|
|
7
7
|
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
8
8
|
if (!configValueSource)
|
|
9
9
|
return null;
|
|
10
|
-
|
|
11
|
-
return configValueSource.configEnv;
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
// In case of effect/computed config values, there isn't any configValueSource
|
|
15
|
-
// TODO: make it work for custom config definitions
|
|
16
|
-
// - Ideally set configValueSource also for effect/computed config values?
|
|
17
|
-
(0, utils_js_1.assert)(false, 'TODO');
|
|
18
|
-
/*
|
|
19
|
-
const configDef = configDefinitionsBuiltIn[configName as keyof typeof configDefinitionsBuiltIn]
|
|
20
|
-
if (!configDef) return null
|
|
21
|
-
return configDef.env
|
|
22
|
-
*/
|
|
23
|
-
}
|
|
10
|
+
return configValueSource.configEnv;
|
|
24
11
|
}
|
|
25
12
|
exports.getConfigEnv = getConfigEnv;
|
|
26
13
|
function isConfigSet(configValueSources, configName) {
|
|
@@ -31,9 +31,13 @@ function previewConfig() {
|
|
|
31
31
|
(0, utils_js_1.markEnvAsPreview)();
|
|
32
32
|
return () => {
|
|
33
33
|
assertDist();
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
/* We don't use this condition (we wrongfully always use the SSR middleware) because of the regression introduced by https://github.com/vitejs/vite/pull/14756 which stops servering .html files when `appType: 'custom'`.
|
|
35
|
+
if (!configVike.prerender || configVike.prerender.partial) {
|
|
36
|
+
addSsrMiddleware(server.middlewares)
|
|
36
37
|
}
|
|
38
|
+
/*/
|
|
39
|
+
(0, addSsrMiddleware_js_1.addSsrMiddleware)(server.middlewares);
|
|
40
|
+
//*/
|
|
37
41
|
addStatic404Middleware(server.middlewares);
|
|
38
42
|
};
|
|
39
43
|
}
|
|
@@ -41,7 +41,7 @@ const getConfigVike_js_1 = require("../shared/getConfigVike.js");
|
|
|
41
41
|
const getPageFiles_js_1 = require("../../shared/getPageFiles.js");
|
|
42
42
|
const getPageContextRequestUrl_js_1 = require("../../shared/getPageContextRequestUrl.js");
|
|
43
43
|
const resolveRouteString_js_1 = require("../../shared/route/resolveRouteString.js");
|
|
44
|
-
const
|
|
44
|
+
const helpers_js_1 = require("../../shared/page-configs/helpers.js");
|
|
45
45
|
const loadConfigValues_js_1 = require("../../shared/page-configs/loadConfigValues.js");
|
|
46
46
|
const error_page_js_1 = require("../../shared/error-page.js");
|
|
47
47
|
const addUrlComputedProps_js_1 = require("../../shared/addUrlComputedProps.js");
|
|
@@ -113,9 +113,9 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
113
113
|
async function collectDoNoPrerenderList(renderContext, doNotPrerenderList, concurrencyLimit) {
|
|
114
114
|
renderContext.pageConfigs.forEach((pageConfig) => {
|
|
115
115
|
const configName = 'prerender';
|
|
116
|
-
const configValue = (0,
|
|
116
|
+
const configValue = (0, helpers_js_1.getConfigValue)(pageConfig, configName, 'boolean');
|
|
117
117
|
if (configValue?.value === false) {
|
|
118
|
-
const configValueFilePathToShowToUser = (0,
|
|
118
|
+
const configValueFilePathToShowToUser = (0, helpers_js_1.getConfigValueFilePathToShowToUser)(configValue);
|
|
119
119
|
(0, utils_js_1.assert)(configValueFilePathToShowToUser);
|
|
120
120
|
doNotPrerenderList.push({
|
|
121
121
|
pageId: pageConfig.pageId,
|
|
@@ -173,11 +173,11 @@ async function callOnBeforePrerenderStartHooks(prerenderContext, renderContext,
|
|
|
173
173
|
await Promise.all(renderContext.pageConfigs.map((pageConfig) => concurrencyLimit(async () => {
|
|
174
174
|
const hookName = 'onBeforePrerenderStart';
|
|
175
175
|
const pageConfigLoaded = await (0, loadConfigValues_js_1.loadConfigValues)(pageConfig, false);
|
|
176
|
-
const configValue = (0,
|
|
176
|
+
const configValue = (0, helpers_js_1.getConfigValue)(pageConfigLoaded, hookName);
|
|
177
177
|
if (!configValue)
|
|
178
178
|
return;
|
|
179
179
|
const hookFn = configValue.value;
|
|
180
|
-
const hookFilePath = (0,
|
|
180
|
+
const hookFilePath = (0, helpers_js_1.getHookFilePathToShowToUser)(configValue);
|
|
181
181
|
(0, utils_js_1.assert)(hookFilePath);
|
|
182
182
|
(0, getHook_js_1.assertHookFn)(hookFn, { hookName, hookFilePath });
|
|
183
183
|
onBeforePrerenderStartHooks.push({
|
|
@@ -313,8 +313,8 @@ async function callOnPrerenderStartHook(prerenderContext, renderContext) {
|
|
|
313
313
|
const configValue = pageConfigGlobal.configValues.onPrerenderStart;
|
|
314
314
|
if (configValue?.value) {
|
|
315
315
|
const { value: hookFn } = configValue;
|
|
316
|
-
// config.onPrerenderStart isn't a computed nor a cumulative config =>
|
|
317
|
-
const hookFilePath = (0,
|
|
316
|
+
// config.onPrerenderStart isn't a computed nor a cumulative config => definedAt should always be defined
|
|
317
|
+
const hookFilePath = (0, helpers_js_1.getHookFilePathToShowToUser)(configValue);
|
|
318
318
|
(0, utils_js_1.assert)(hookFilePath);
|
|
319
319
|
onPrerenderStartHook = {
|
|
320
320
|
hookFn,
|
|
@@ -469,7 +469,7 @@ async function routeAndPrerender(prerenderContext, htmlFiles, prerenderPageIds,
|
|
|
469
469
|
if (pageContext._pageConfigs.length > 0) {
|
|
470
470
|
const pageConfig = pageContext._pageConfigs.find((p) => p.pageId === pageId);
|
|
471
471
|
(0, utils_js_1.assert)(pageConfig);
|
|
472
|
-
usesClientRouter = (0,
|
|
472
|
+
usesClientRouter = (0, helpers_js_1.getConfigValue)(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
473
473
|
}
|
|
474
474
|
else {
|
|
475
475
|
usesClientRouter = globalContext.pluginManifest.usesClientRouter;
|
|
@@ -50,19 +50,32 @@ function serializePageContextClientSide(pageContext) {
|
|
|
50
50
|
catch (err) {
|
|
51
51
|
hasWarned = true;
|
|
52
52
|
propsNonSerializable.push(prop);
|
|
53
|
-
|
|
54
|
-
(0, utils_js_1.assertWarning)(false, [
|
|
53
|
+
let msg = [
|
|
55
54
|
`${varName} cannot be serialized and, therefore, cannot be passed to the client.`,
|
|
56
|
-
`Make sure that ${varName} is serializable, or remove ${h(propName)} from ${h('passToClient')}
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
`Make sure that ${varName} is serializable, or remove ${h(propName)} from ${h('passToClient')}.`
|
|
56
|
+
].join(' ');
|
|
57
|
+
if ((0, stringify_1.isJsonSerializerError)(err)) {
|
|
58
|
+
msg = `${msg} Serialization error: ${err.messageCore}.`;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
console.warn('Serialization error:');
|
|
62
|
+
console.warn(err);
|
|
63
|
+
msg = `${msg} The serialization failed because of the error printed above.`;
|
|
64
|
+
}
|
|
65
|
+
// We warn (instead of throwing an error) since Vike's client runtime throws an error (with `assertUsage()`) if the user's client code tries to access the property that cannot be serialized
|
|
66
|
+
(0, utils_js_1.assertWarning)(false, msg, { onlyOnce: false });
|
|
59
67
|
}
|
|
60
68
|
});
|
|
61
69
|
(0, utils_js_1.assert)(hasWarned);
|
|
62
70
|
propsNonSerializable.forEach((prop) => {
|
|
63
71
|
pageContextClient[prop] = notSerializable_js_1.notSerializable;
|
|
64
72
|
});
|
|
65
|
-
|
|
73
|
+
try {
|
|
74
|
+
pageContextSerialized = serialize(pageContextClient);
|
|
75
|
+
}
|
|
76
|
+
catch (err) {
|
|
77
|
+
(0, utils_js_1.assert)(false);
|
|
78
|
+
}
|
|
66
79
|
}
|
|
67
80
|
return pageContextSerialized;
|
|
68
81
|
}
|
|
@@ -21,7 +21,7 @@ const preparePageContextForUserConsumptionServerSide_js_1 = require("./preparePa
|
|
|
21
21
|
const executeGuardHook_js_1 = require("../../../shared/route/executeGuardHook.js");
|
|
22
22
|
const loadPageRoutes_js_1 = require("../../../shared/route/loadPageRoutes.js");
|
|
23
23
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
24
|
-
const
|
|
24
|
+
const helpers_js_1 = require("../../../shared/page-configs/helpers.js");
|
|
25
25
|
async function renderPageAlreadyRouted(pageContext) {
|
|
26
26
|
// pageContext._pageId can either be the:
|
|
27
27
|
// - ID of the page matching the routing, or the
|
|
@@ -173,7 +173,7 @@ function assertNonMixedDesign(pageFilesAll, pageConfigs) {
|
|
|
173
173
|
const indent = '- ';
|
|
174
174
|
const v1Files = (0, utils_js_1.unique)(pageConfigs
|
|
175
175
|
.map((p) => Object.values(p.configValues)
|
|
176
|
-
.map(
|
|
176
|
+
.map(helpers_js_1.getConfigValueFilePathToShowToUser)
|
|
177
177
|
.filter(utils_js_1.isNotNullish)
|
|
178
178
|
.map((filePathToShowToUser) => indent + filePathToShowToUser))
|
|
179
179
|
.flat(2));
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getClientEntryFilePath = void 0;
|
|
4
|
-
const
|
|
4
|
+
const helpers_js_1 = require("../../shared/page-configs/helpers.js");
|
|
5
5
|
function getClientEntryFilePath(pageConfig) {
|
|
6
6
|
const configName = 'client';
|
|
7
|
-
const configValue = (0,
|
|
7
|
+
const configValue = (0, helpers_js_1.getConfigValue)(pageConfig, configName, 'string');
|
|
8
8
|
if (!configValue)
|
|
9
9
|
return null;
|
|
10
10
|
return configValue.value;
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.analyzeClientSide = void 0;
|
|
4
|
-
const
|
|
4
|
+
const helpers_js_1 = require("../page-configs/helpers.js");
|
|
5
5
|
const analyzePageClientSide_js_1 = require("./analyzePageClientSide.js");
|
|
6
6
|
function analyzeClientSide(pageConfig, pageFilesAll, pageId) {
|
|
7
7
|
// V1 design
|
|
8
8
|
if (pageConfig) {
|
|
9
|
-
const isClientRouting = (0,
|
|
10
|
-
const isClientSideRenderable = (0,
|
|
9
|
+
const isClientRouting = (0, helpers_js_1.getConfigValue)(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
10
|
+
const isClientSideRenderable = (0, helpers_js_1.getConfigValue)(pageConfig, 'isClientSideRenderable', 'boolean')?.value ?? false;
|
|
11
11
|
return { isClientSideRenderable, isClientRouting };
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
14
|
-
// TODO/v1-release:
|
|
15
|
-
// - remove V0.4 implementation
|
|
16
|
-
// - globally rename isHtmlOnly to !isClientSideRenderable
|
|
14
|
+
// TODO/v1-release: remove
|
|
17
15
|
// V0.4 design
|
|
18
16
|
const { isHtmlOnly, isClientRouting } = (0, analyzePageClientSide_js_1.analyzePageClientSide)(pageFilesAll, pageId);
|
|
19
17
|
return { isClientSideRenderable: !isHtmlOnly, isClientRouting };
|
|
@@ -7,7 +7,7 @@ exports.getExports = exports.getExportUnion = void 0;
|
|
|
7
7
|
const isScriptFile_js_1 = require("../../utils/isScriptFile.js");
|
|
8
8
|
const utils_js_1 = require("../utils.js");
|
|
9
9
|
const assert_exports_old_design_js_1 = require("./assert_exports_old_design.js");
|
|
10
|
-
const
|
|
10
|
+
const helpers_js_1 = require("../page-configs/helpers.js");
|
|
11
11
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
12
12
|
function getExports(pageFiles, pageConfig) {
|
|
13
13
|
const configEntries = {};
|
|
@@ -34,8 +34,8 @@ function getExports(pageFiles, pageConfig) {
|
|
|
34
34
|
if (pageConfig) {
|
|
35
35
|
Object.entries(pageConfig.configValues).forEach(([configName, configValue]) => {
|
|
36
36
|
const { value } = configValue;
|
|
37
|
-
const configValueFilePathToShowToUser = (0,
|
|
38
|
-
const configDefinedAt = (0,
|
|
37
|
+
const configValueFilePathToShowToUser = (0, helpers_js_1.getConfigValueFilePathToShowToUser)(configValue);
|
|
38
|
+
const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configValue);
|
|
39
39
|
config[configName] = config[configName] ?? value;
|
|
40
40
|
configEntries[configName] = configEntries[configName] ?? [];
|
|
41
41
|
// 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.)
|
|
@@ -25,7 +25,7 @@ exports.assertHook = assertHook;
|
|
|
25
25
|
function assertHookFn(hookFn, { hookName, hookFilePath }) {
|
|
26
26
|
(0, utils_js_1.assert)(hookName && hookFilePath);
|
|
27
27
|
(0, utils_js_1.assert)(!hookName.endsWith(')'));
|
|
28
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.isCallable)(hookFn), `
|
|
28
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isCallable)(hookFn), `Hook ${hookName}() defined by ${hookFilePath} should be a function`);
|
|
29
29
|
(0, utils_js_1.checkType)(hookFn);
|
|
30
30
|
}
|
|
31
31
|
exports.assertHookFn = assertHookFn;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getDefinedAtString = exports.getConfigDefinedAtString = void 0;
|
|
7
|
+
const utils_js_1 = require("../../utils.js");
|
|
8
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
|
+
const getExportPath_js_1 = require("../getExportPath.js");
|
|
10
|
+
function getConfigDefinedAtString(sentenceBegin, configName, { definedAt }) {
|
|
11
|
+
const definedAtString = getDefinedAtString(definedAt, configName);
|
|
12
|
+
const definedAtStr = definedAtString === 'internally' ? definedAtString : `at ${definedAtString}`;
|
|
13
|
+
let configNameStr = `${configName}${sentenceBegin === 'Hook' ? '()' : ''}`;
|
|
14
|
+
const configDefinedAt = `${sentenceBegin} ${picocolors_1.default.cyan(configNameStr)} defined ${definedAtStr}`;
|
|
15
|
+
return configDefinedAt;
|
|
16
|
+
}
|
|
17
|
+
exports.getConfigDefinedAtString = getConfigDefinedAtString;
|
|
18
|
+
function getDefinedAtString(definedAt, configName) {
|
|
19
|
+
if ('isComputed' in definedAt) {
|
|
20
|
+
return 'internally';
|
|
21
|
+
}
|
|
22
|
+
let files;
|
|
23
|
+
if ('files' in definedAt) {
|
|
24
|
+
files = definedAt.files;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
files = [definedAt];
|
|
28
|
+
}
|
|
29
|
+
(0, utils_js_1.assert)(files.length >= 1);
|
|
30
|
+
const definedAtString = files
|
|
31
|
+
.map((source) => {
|
|
32
|
+
const { filePathToShowToUser, fileExportPathToShowToUser } = source;
|
|
33
|
+
let s = filePathToShowToUser;
|
|
34
|
+
const exportPath = (0, getExportPath_js_1.getExportPath)(fileExportPathToShowToUser, configName);
|
|
35
|
+
if (exportPath) {
|
|
36
|
+
s = `${s} > ${picocolors_1.default.cyan(exportPath)}`;
|
|
37
|
+
}
|
|
38
|
+
return s;
|
|
39
|
+
})
|
|
40
|
+
.join(' / ');
|
|
41
|
+
return definedAtString;
|
|
42
|
+
}
|
|
43
|
+
exports.getDefinedAtString = getDefinedAtString;
|