vike 0.4.223-commit-e239e2b → 0.4.223-commit-535bde1
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/commonConfig.js +2 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +2 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +112 -79
- package/dist/cjs/node/prerender/context.js +3 -8
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +23 -21
- package/dist/cjs/node/prerender/runPrerender.js +24 -28
- package/dist/cjs/node/prerender/utils.js +1 -0
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +3 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +112 -79
- package/dist/esm/node/prerender/context.d.ts +0 -2
- package/dist/esm/node/prerender/context.js +4 -9
- package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +10 -6
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +24 -22
- package/dist/esm/node/prerender/runPrerender.d.ts +7 -25
- package/dist/esm/node/prerender/runPrerender.js +25 -29
- package/dist/esm/node/prerender/utils.d.ts +1 -0
- package/dist/esm/node/prerender/utils.js +1 -0
- package/dist/esm/node/runtime/globalContext.d.ts +2 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +165 -5
- package/dist/esm/shared/page-configs/Config.d.ts +8 -0
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +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/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -18,6 +18,7 @@ const context_js_1 = require("../../api/context.js");
|
|
|
18
18
|
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
19
19
|
const prepareViteApiCall_js_1 = require("../../api/prepareViteApiCall.js");
|
|
20
20
|
const context_js_2 = require("../../prerender/context.js");
|
|
21
|
+
const resolvePrerenderConfig_js_1 = require("../../prerender/resolvePrerenderConfig.js");
|
|
21
22
|
const pluginName = 'vike:commonConfig';
|
|
22
23
|
function commonConfig(vikeVitePluginOptions) {
|
|
23
24
|
return [
|
|
@@ -43,7 +44,7 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
43
44
|
},
|
|
44
45
|
// TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
|
|
45
46
|
configVikePromise: Promise.resolve({
|
|
46
|
-
prerender: (0,
|
|
47
|
+
prerender: (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(vikeConfig).isEnabled
|
|
47
48
|
})
|
|
48
49
|
};
|
|
49
50
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -44,6 +44,7 @@ function getLogicalPath(locationId, ignoredDirs, removeParenthesesDirs) {
|
|
|
44
44
|
assertIsPath(logicalPath);
|
|
45
45
|
return logicalPath;
|
|
46
46
|
}
|
|
47
|
+
// See getPlusFilesRelevant() and getPlusFilesOrdered()
|
|
47
48
|
function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
48
49
|
assertLocationId(locationId1);
|
|
49
50
|
assertLocationId(locationId2);
|
|
@@ -52,7 +53,7 @@ function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
|
52
53
|
const inheritanceRoot1 = getInheritanceRoot(locationId1);
|
|
53
54
|
const inheritanceRoot2 = getInheritanceRoot(locationId2);
|
|
54
55
|
const inheritanceRootPage = getInheritanceRoot(locationIdPage);
|
|
55
|
-
//
|
|
56
|
+
// Only works if both locationId1 and locationId2 are inherited by the same page
|
|
56
57
|
(0, utils_js_1.assert)(isInherited(locationId1, locationIdPage));
|
|
57
58
|
(0, utils_js_1.assert)(isInherited(locationId2, locationIdPage));
|
|
58
59
|
// Equivalent assertion (see isInherited() implementation)
|
|
@@ -148,7 +148,7 @@ async function loadVikeConfig(userRootDir, vikeVitePluginOptions) {
|
|
|
148
148
|
const configDefinitionsResolved = await resolveConfigDefinitions(plusFilesAll, userRootDir, esbuildCache);
|
|
149
149
|
assertKnownConfigs(configDefinitionsResolved, plusFilesAll);
|
|
150
150
|
const { pageConfigGlobal, pageConfigs } = getPageConfigsBuildTime(configDefinitionsResolved, plusFilesAll, userRootDir);
|
|
151
|
-
//
|
|
151
|
+
// Backwards compatibility for vike(options) in vite.config.js
|
|
152
152
|
temp_interopVikeVitePlugin(pageConfigGlobal, vikeVitePluginOptions, userRootDir);
|
|
153
153
|
// global
|
|
154
154
|
const pageConfigGlobalValues = getConfigValues(pageConfigGlobal);
|
|
@@ -161,9 +161,7 @@ async function loadVikeConfig(userRootDir, vikeVitePluginOptions) {
|
|
|
161
161
|
return { pageConfigs, pageConfigGlobal, global, pages };
|
|
162
162
|
}
|
|
163
163
|
async function resolveConfigDefinitions(plusFilesAll, userRootDir, esbuildCache) {
|
|
164
|
-
const configDefinitionsGlobal = getConfigDefinitions(
|
|
165
|
-
// We use `plusFilesAll` in order to allow local Vike extensions to create global configs.
|
|
166
|
-
sortForGlobal(plusFilesAll), (configDef) => !!configDef.global);
|
|
164
|
+
const configDefinitionsGlobal = getConfigDefinitions(sortAfterInheritanceOrderGlobal(plusFilesAll), (configDef) => !!configDef.global);
|
|
167
165
|
await loadCustomConfigBuildTimeFiles(plusFilesAll, configDefinitionsGlobal, userRootDir, esbuildCache);
|
|
168
166
|
const configDefinitionsLocal = {};
|
|
169
167
|
await Promise.all((0, utils_js_1.objectEntries)(plusFilesAll).map(async ([locationId, plusFiles]) => {
|
|
@@ -199,14 +197,13 @@ function getPageConfigsBuildTime(configDefinitionsResolved, plusFilesAll, userRo
|
|
|
199
197
|
configValueSources: {}
|
|
200
198
|
};
|
|
201
199
|
(0, utils_js_1.objectEntries)(configDefinitionsResolved.configDefinitionsGlobal).forEach(([configName, configDef]) => {
|
|
202
|
-
const sources = resolveConfigValueSources(configName, configDef,
|
|
203
|
-
// We use `plusFilesAll` in order to allow local Vike extensions to set the value of global configs (e.g. `vite`).
|
|
204
|
-
sortForGlobal(plusFilesAll), userRootDir, true);
|
|
200
|
+
const sources = resolveConfigValueSources(configName, configDef, sortAfterInheritanceOrderGlobal(plusFilesAll), userRootDir, true);
|
|
205
201
|
if (sources.length === 0)
|
|
206
202
|
return;
|
|
207
203
|
pageConfigGlobal.configValueSources[configName] = sources;
|
|
208
204
|
});
|
|
209
|
-
|
|
205
|
+
applyEffectsMetaEnv(pageConfigGlobal.configValueSources, configDefinitionsResolved.configDefinitionsGlobal);
|
|
206
|
+
applyEffectsConfVal(pageConfigGlobal.configValueSources, configDefinitionsResolved.configDefinitionsGlobal);
|
|
210
207
|
assertPageConfigGlobal(pageConfigGlobal, plusFilesAll);
|
|
211
208
|
const pageConfigs = (0, utils_js_1.objectEntries)(configDefinitionsResolved.configDefinitionsLocal)
|
|
212
209
|
.filter(([_locationId, { plusFiles }]) => isDefiningPage(plusFiles))
|
|
@@ -223,7 +220,8 @@ function getPageConfigsBuildTime(configDefinitionsResolved, plusFilesAll, userRo
|
|
|
223
220
|
configValueSources[configName] = sources;
|
|
224
221
|
});
|
|
225
222
|
const pageConfigRoute = determineRouteFilesystem(locationId, configValueSources);
|
|
226
|
-
|
|
223
|
+
applyEffectsMetaEnv(configValueSources, configDefinitionsLocal);
|
|
224
|
+
applyEffectsConfVal(configValueSources, configDefinitionsLocal);
|
|
227
225
|
const configValuesComputed = getComputed(configValueSources, configDefinitionsLocal);
|
|
228
226
|
const pageConfig = {
|
|
229
227
|
pageId: locationId,
|
|
@@ -366,18 +364,18 @@ function temp_interopVikeVitePlugin(pageConfigGlobal, vikeVitePluginOptions, use
|
|
|
366
364
|
});
|
|
367
365
|
});
|
|
368
366
|
}
|
|
367
|
+
// Together with getPlusFilesOrdered() this implements the whole config inheritance ordering for non-global configs. See sortAfterInheritanceOrderGlobal() for global configs.
|
|
369
368
|
function getPlusFilesRelevant(plusFilesAll, locationIdPage) {
|
|
370
369
|
const plusFilesRelevant = Object.fromEntries((0, utils_js_1.objectEntries)(plusFilesAll)
|
|
371
370
|
.filter(([locationId]) => {
|
|
372
371
|
return (0, filesystemRouting_js_1.isInherited)(locationId, locationIdPage);
|
|
373
372
|
})
|
|
374
|
-
// Sort after config inheritance.
|
|
375
|
-
// - Together with getPlusFilesOrdered() this implements the whole order of config inheritance.
|
|
376
|
-
// - See sortForGlobal() for global configs order.
|
|
377
373
|
.sort(([locationId1], [locationId2]) => (0, filesystemRouting_js_1.sortAfterInheritanceOrder)(locationId1, locationId2, locationIdPage)));
|
|
378
374
|
return plusFilesRelevant;
|
|
379
375
|
}
|
|
380
|
-
|
|
376
|
+
// This implements the whole config inheritance ordering for global configs.
|
|
377
|
+
// We use `plusFilesAll` in order to allow local Vike extensions to create global configs, and to set the value of global configs such as `+vite` (enabling Vike extensions to add Vite plugins).
|
|
378
|
+
function sortAfterInheritanceOrderGlobal(plusFilesAll) {
|
|
381
379
|
const plusFilesAllSorted = Object.fromEntries((0, utils_js_1.objectEntries)(plusFilesAll)
|
|
382
380
|
.sort((0, utils_js_1.lowerFirst)(([locationId]) => locationId.split('/').length))
|
|
383
381
|
.sort((0, utils_js_1.makeFirst)(([locationId]) => isGlobalLocation(locationId, plusFilesAll))));
|
|
@@ -391,22 +389,20 @@ function resolveConfigValueSources(configName, configDef, plusFilesRelevant, use
|
|
|
391
389
|
return configValueSource;
|
|
392
390
|
});
|
|
393
391
|
if ((0, utils_js_1.isCallable)(configDef.global)) {
|
|
394
|
-
const isGlobalValue = configDef.global;
|
|
395
392
|
(0, utils_js_1.assert)(configDef.env.config);
|
|
396
393
|
sources = sources.filter((source) => {
|
|
397
394
|
(0, utils_js_1.assert)(source.configEnv.config);
|
|
398
395
|
(0, utils_js_1.assert)(source.valueIsLoaded);
|
|
399
|
-
const valueIsGlobal =
|
|
396
|
+
const valueIsGlobal = resolveIsGlobalValue(configDef.global, source.value);
|
|
400
397
|
return isGlobal ? valueIsGlobal : !valueIsGlobal;
|
|
401
398
|
});
|
|
402
399
|
}
|
|
403
400
|
return sources;
|
|
404
401
|
}
|
|
405
|
-
// Together with
|
|
402
|
+
// Together with getPlusFilesRelevant() this implements the whole config inheritance ordering.
|
|
406
403
|
function getPlusFilesOrdered(configName, plusFilesRelevant) {
|
|
407
404
|
const plusFilesOrdered = [];
|
|
408
|
-
// `plusFilesRelevant` is already
|
|
409
|
-
// `plusFilesAtLocationId` is already sorted by sortMakeDeterministic() at getPlusFilesAll()
|
|
405
|
+
// `plusFilesRelevant` is already deterministic, see sortMakeDeterministic() at getPlusFilesAll()
|
|
410
406
|
for (const plusFilesAtLocationId of Object.values(plusFilesRelevant)) {
|
|
411
407
|
const plusFilesForConfigName = plusFilesAtLocationId.filter((plusFile) => getDefiningConfigNames(plusFile).includes(configName));
|
|
412
408
|
// We populate `plusFilesOrdered` with inheritance order.
|
|
@@ -583,6 +579,15 @@ function isDefiningPage(plusFiles) {
|
|
|
583
579
|
function isDefiningPageConfig(configName) {
|
|
584
580
|
return ['Page', 'route'].includes(configName);
|
|
585
581
|
}
|
|
582
|
+
function resolveIsGlobalValue(configDefGlobal, configValue) {
|
|
583
|
+
let isGlobal;
|
|
584
|
+
if ((0, utils_js_1.isCallable)(configDefGlobal))
|
|
585
|
+
isGlobal = configDefGlobal(configValue);
|
|
586
|
+
else
|
|
587
|
+
isGlobal = configDefGlobal ?? false;
|
|
588
|
+
(0, utils_js_1.assert)(typeof isGlobal === 'boolean');
|
|
589
|
+
return isGlobal;
|
|
590
|
+
}
|
|
586
591
|
function getDefiningConfigNames(plusFile) {
|
|
587
592
|
let configNames = [];
|
|
588
593
|
if (!plusFile.isConfigFile) {
|
|
@@ -667,75 +672,103 @@ function assertMetaUsage(metaVal, metaConfigDefinedAt) {
|
|
|
667
672
|
}
|
|
668
673
|
});
|
|
669
674
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
675
|
+
// Test: https://github.com/vikejs/vike/blob/441a37c4c1a3b07bb8f6efb1d1f7be297a53974a/test/playground/vite.config.ts#L39
|
|
676
|
+
function applyEffectsConfVal(configValueSources, configDefinitions) {
|
|
677
|
+
(0, utils_js_1.objectEntries)(configDefinitions).forEach(([configNameEffect, configDefEffect]) => {
|
|
678
|
+
const sourceEffect = configValueSources[configNameEffect]?.[0];
|
|
679
|
+
if (!sourceEffect)
|
|
673
680
|
return;
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
(0, utils_js_1.assertUsage)(configDef.env.config, [
|
|
677
|
-
`Cannot add effect to ${picocolors_1.default.cyan(configName)} because its ${picocolors_1.default.cyan('env')} is ${picocolors_1.default.cyan(JSON.stringify(configDef.env))}: effects can only be added to configs with an ${picocolors_1.default.cyan('env')} with ${picocolors_1.default.cyan('{ config: true }')}.`
|
|
678
|
-
].join(' '));
|
|
679
|
-
const source = configValueSources[configName]?.[0];
|
|
680
|
-
if (!source)
|
|
681
|
+
const effect = runEffect(configNameEffect, configDefEffect, sourceEffect);
|
|
682
|
+
if (!effect)
|
|
681
683
|
return;
|
|
682
|
-
|
|
683
|
-
(
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
684
|
+
const { configModFromEffect, configValueEffectSource } = effect;
|
|
685
|
+
applyEffectConfVal(configModFromEffect, sourceEffect, configValueSources, configNameEffect, configDefEffect, configDefinitions, configValueEffectSource);
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
// Test: https://github.com/vikejs/vike/blob/441a37c4c1a3b07bb8f6efb1d1f7be297a53974a/test/playground/pages/config-meta/effect/e2e-test.ts#L16
|
|
689
|
+
function applyEffectsMetaEnv(configValueSources, configDefinitions) {
|
|
690
|
+
(0, utils_js_1.objectEntries)(configDefinitions).forEach(([configNameEffect, configDefEffect]) => {
|
|
691
|
+
const sourceEffect = configValueSources[configNameEffect]?.[0];
|
|
692
|
+
if (!sourceEffect)
|
|
693
|
+
return;
|
|
694
|
+
const effect = runEffect(configNameEffect, configDefEffect, sourceEffect);
|
|
695
|
+
if (!effect)
|
|
690
696
|
return;
|
|
691
|
-
|
|
697
|
+
const { configModFromEffect } = effect;
|
|
698
|
+
applyEffectMetaEnv(configModFromEffect, configValueSources, configDefEffect);
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
function runEffect(configName, configDef, source) {
|
|
702
|
+
if (!configDef.effect)
|
|
703
|
+
return null;
|
|
704
|
+
// The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
|
|
705
|
+
(0, utils_js_1.assertUsage)(configDef.env.config, [
|
|
706
|
+
`Cannot add meta.effect to ${picocolors_1.default.cyan(configName)} because its meta.env is ${picocolors_1.default.cyan(JSON.stringify(configDef.env))} but an effect can only be added to a config that has a meta.env with ${picocolors_1.default.cyan('{ config: true }')}.`
|
|
707
|
+
].join(' '));
|
|
708
|
+
(0, utils_js_1.assert)(source.valueIsLoaded);
|
|
709
|
+
const configValueEffectSource = source.value;
|
|
710
|
+
// Call effect
|
|
711
|
+
const configModFromEffect = configDef.effect({
|
|
712
|
+
configValue: configValueEffectSource,
|
|
713
|
+
configDefinedAt: (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, source.definedAtFilePath)
|
|
692
714
|
});
|
|
715
|
+
if (!configModFromEffect)
|
|
716
|
+
return null;
|
|
717
|
+
return { configModFromEffect, configValueEffectSource };
|
|
693
718
|
}
|
|
694
|
-
function
|
|
719
|
+
function applyEffectConfVal(configModFromEffect, sourceEffect, configValueSources, configNameEffect, configDefEffect, configDefinitions, configValueEffectSource) {
|
|
720
|
+
(0, utils_js_1.objectEntries)(configModFromEffect).forEach(([configNameTarget, configValue]) => {
|
|
721
|
+
if (configNameTarget === 'meta')
|
|
722
|
+
return;
|
|
723
|
+
const configDef = configDefinitions[configNameTarget];
|
|
724
|
+
(0, utils_js_1.assert)(configDef);
|
|
725
|
+
(0, utils_js_1.assert)(configDefEffect._userEffectDefinedAtFilePath);
|
|
726
|
+
const configValueSource = {
|
|
727
|
+
definedAtFilePath: configDefEffect._userEffectDefinedAtFilePath,
|
|
728
|
+
plusFile: sourceEffect.plusFile,
|
|
729
|
+
locationId: sourceEffect.locationId,
|
|
730
|
+
configEnv: configDef.env,
|
|
731
|
+
isOverriden: false, // TODO/now check
|
|
732
|
+
valueIsLoadedWithImport: false,
|
|
733
|
+
valueIsDefinedByPlusValueFile: false,
|
|
734
|
+
valueIsLoaded: true,
|
|
735
|
+
value: configValue
|
|
736
|
+
};
|
|
737
|
+
const isValueGlobalSource = resolveIsGlobalValue(configDefEffect.global, configValueEffectSource);
|
|
738
|
+
const isValueGlobalTarget = resolveIsGlobalValue(configDef.global, configValue);
|
|
739
|
+
const isGlobalHumanReadable = (isGlobal) => `${isGlobal ? 'non-' : ''}global`;
|
|
740
|
+
// The error message make it sound like it's an inherent limitation, it actually isn't (both ways can make senses).
|
|
741
|
+
(0, utils_js_1.assertUsage)(isValueGlobalSource === isValueGlobalTarget, `The configuration ${picocolors_1.default.cyan(configNameEffect)} is set to ${picocolors_1.default.cyan(JSON.stringify(configValueEffectSource))} which is considered ${isGlobalHumanReadable(isValueGlobalSource)}. However, it has a meta.effect that sets the configuration ${picocolors_1.default.cyan(configNameTarget)} to ${picocolors_1.default.cyan(JSON.stringify(configValue))} which is considered ${isGlobalHumanReadable(isValueGlobalTarget)}. This is contradictory: make sure the values are either both non-global or both global.`);
|
|
742
|
+
configValueSources[configNameTarget] ?? (configValueSources[configNameTarget] = []);
|
|
743
|
+
configValueSources[configNameTarget].push(configValueSource);
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
function applyEffectMetaEnv(configModFromEffect, configValueSources, configDefEffect) {
|
|
695
747
|
const notSupported = `${picocolors_1.default.cyan('meta.effect')} currently only supports setting the value of a config, or modifying the ${picocolors_1.default.cyan('meta.env')} of a config.`;
|
|
696
|
-
(0, utils_js_1.objectEntries)(configModFromEffect).forEach(([
|
|
697
|
-
if (
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
else {
|
|
703
|
-
configDefinedAt = null;
|
|
704
|
-
}
|
|
705
|
-
assertMetaUsage(configValue, configDefinedAt);
|
|
706
|
-
(0, utils_js_1.objectEntries)(configValue).forEach(([configTargetName, configTargetDef]) => {
|
|
707
|
-
{
|
|
708
|
-
const keys = Object.keys(configTargetDef);
|
|
709
|
-
(0, utils_js_1.assertUsage)(keys.includes('env'), notSupported);
|
|
710
|
-
(0, utils_js_1.assertUsage)(keys.length === 1, notSupported);
|
|
711
|
-
}
|
|
712
|
-
const envOverriden = configTargetDef.env;
|
|
713
|
-
const sources = configValueSources[configTargetName];
|
|
714
|
-
sources?.forEach((configValueSource) => {
|
|
715
|
-
// Apply effect
|
|
716
|
-
configValueSource.configEnv = envOverriden;
|
|
717
|
-
});
|
|
718
|
-
});
|
|
748
|
+
(0, utils_js_1.objectEntries)(configModFromEffect).forEach(([configNameTarget, configValue]) => {
|
|
749
|
+
if (configNameTarget !== 'meta')
|
|
750
|
+
return;
|
|
751
|
+
let configDefinedAt;
|
|
752
|
+
if (configDefEffect._userEffectDefinedAtFilePath) {
|
|
753
|
+
configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configNameTarget, configDefEffect._userEffectDefinedAtFilePath);
|
|
719
754
|
}
|
|
720
755
|
else {
|
|
721
|
-
|
|
722
|
-
(0, utils_js_1.assert)(configDef);
|
|
723
|
-
(0, utils_js_1.assert)(configDefEffect._userEffectDefinedAtFilePath);
|
|
724
|
-
const configValueSource = {
|
|
725
|
-
definedAtFilePath: configDefEffect._userEffectDefinedAtFilePath,
|
|
726
|
-
plusFile: source.plusFile,
|
|
727
|
-
locationId: source.locationId,
|
|
728
|
-
configEnv: configDef.env,
|
|
729
|
-
isOverriden: false, // TODO/now check
|
|
730
|
-
valueIsLoadedWithImport: false,
|
|
731
|
-
valueIsDefinedByPlusValueFile: false,
|
|
732
|
-
valueIsLoaded: true,
|
|
733
|
-
value: configValue
|
|
734
|
-
};
|
|
735
|
-
(0, utils_js_1.assertUsage)(!!configDef.global === !!configDefEffect.global, `The configuration ${picocolors_1.default.cyan(configNameEffect)} has a ${picocolors_1.default.cyan('meta.effect')} that changes the configuration ${picocolors_1.default.cyan(configName)} and, consequently, both ${picocolors_1.default.cyan(configNameEffect)} and ${picocolors_1.default.cyan(configName)} must have the same ${picocolors_1.default.cyan('meta.global')} value.`);
|
|
736
|
-
configValueSources[configName] ?? (configValueSources[configName] = []);
|
|
737
|
-
configValueSources[configName].push(configValueSource);
|
|
756
|
+
configDefinedAt = null;
|
|
738
757
|
}
|
|
758
|
+
assertMetaUsage(configValue, configDefinedAt);
|
|
759
|
+
(0, utils_js_1.objectEntries)(configValue).forEach(([configTargetName, configTargetDef]) => {
|
|
760
|
+
{
|
|
761
|
+
const keys = Object.keys(configTargetDef);
|
|
762
|
+
(0, utils_js_1.assertUsage)(keys.includes('env'), notSupported);
|
|
763
|
+
(0, utils_js_1.assertUsage)(keys.length === 1, notSupported);
|
|
764
|
+
}
|
|
765
|
+
const envOverriden = configTargetDef.env;
|
|
766
|
+
const sources = configValueSources[configTargetName];
|
|
767
|
+
sources?.forEach((configValueSource) => {
|
|
768
|
+
// Apply effect
|
|
769
|
+
configValueSource.configEnv = envOverriden;
|
|
770
|
+
});
|
|
771
|
+
});
|
|
739
772
|
});
|
|
740
773
|
}
|
|
741
774
|
function getComputed(configValueSources, configDefinitions) {
|
|
@@ -849,7 +882,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
849
882
|
function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName) {
|
|
850
883
|
(0, utils_js_1.assert)(configFilesystemRoutingRoot.configEnv.config);
|
|
851
884
|
// Eagerly loaded since it's config-only
|
|
852
|
-
(0, utils_js_1.assert)(
|
|
885
|
+
(0, utils_js_1.assert)(configFilesystemRoutingRoot.valueIsLoaded);
|
|
853
886
|
const { value } = configFilesystemRoutingRoot;
|
|
854
887
|
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, configFilesystemRoutingRoot.definedAtFilePath);
|
|
855
888
|
(0, utils_js_1.assertUsage)(typeof value === 'string', `${configDefinedAt} should be a string`);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPrerenderEnabled = isPrerenderEnabled;
|
|
4
3
|
exports.isPrerenderAutoRunEnabled = isPrerenderAutoRunEnabled;
|
|
5
4
|
exports.temp_disablePrerenderAutoRun = temp_disablePrerenderAutoRun;
|
|
6
5
|
exports.isPrerendering = isPrerendering;
|
|
@@ -8,14 +7,10 @@ exports.setContextIsPrerendering = setContextIsPrerendering;
|
|
|
8
7
|
const getGlobalObject_js_1 = require("../../utils/getGlobalObject.js");
|
|
9
8
|
const resolvePrerenderConfig_js_1 = require("./resolvePrerenderConfig.js");
|
|
10
9
|
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('prerender/context.ts', {});
|
|
11
|
-
function isPrerenderEnabled(vikeConfig) {
|
|
12
|
-
const prerenderConfig = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfig)(vikeConfig);
|
|
13
|
-
return !!prerenderConfig;
|
|
14
|
-
}
|
|
15
10
|
function isPrerenderAutoRunEnabled(vikeConfig) {
|
|
16
|
-
const
|
|
17
|
-
return (
|
|
18
|
-
!(
|
|
11
|
+
const prerenderConfigGlobal = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(vikeConfig);
|
|
12
|
+
return (prerenderConfigGlobal.isEnabled &&
|
|
13
|
+
!(prerenderConfigGlobal || {}).disableAutoRun &&
|
|
19
14
|
!globalObject.isDisabled &&
|
|
20
15
|
vikeConfig.global.config.disableAutoFullBuild !== 'prerender');
|
|
21
16
|
}
|
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.resolvePrerenderConfigGlobal = resolvePrerenderConfigGlobal;
|
|
4
4
|
exports.resolvePrerenderConfigLocal = resolvePrerenderConfigLocal;
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
6
|
const getConfigValueBuildTime_js_1 = require("../../shared/page-configs/getConfigValueBuildTime.js");
|
|
7
|
-
|
|
8
|
-
// TODO/now:
|
|
9
|
-
// - prerender.value
|
|
10
|
-
function resolvePrerenderConfig(vikeConfig) {
|
|
7
|
+
function resolvePrerenderConfigGlobal(vikeConfig) {
|
|
11
8
|
const prerenderConfigs = vikeConfig.global.config.prerender;
|
|
12
|
-
|
|
13
|
-
!vikeConfig.pageConfigs.some((pageConfig) => resolvePrerenderConfigLocal(pageConfig)?.value)) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
let prerenderSettings = prerenderConfigs || [];
|
|
9
|
+
let prerenderConfigList = prerenderConfigs || [];
|
|
17
10
|
// Needed because of backwards compatibility of `vike({prerender:true})` in `vite.config.js`; after we remove it we can remove this line.
|
|
18
|
-
|
|
19
|
-
(0, utils_js_1.assert)(
|
|
20
|
-
const
|
|
21
|
-
partial: pickFirst(
|
|
22
|
-
noExtraDir: pickFirst(
|
|
23
|
-
parallel: pickFirst(
|
|
24
|
-
disableAutoRun: pickFirst(
|
|
11
|
+
prerenderConfigList = prerenderConfigList.filter(isObject2);
|
|
12
|
+
(0, utils_js_1.assert)(prerenderConfigList.every(isObject2)); // Help TS
|
|
13
|
+
const prerenderConfigGlobal = {
|
|
14
|
+
partial: pickFirst(prerenderConfigList.map((c) => c.partial)) ?? false,
|
|
15
|
+
noExtraDir: pickFirst(prerenderConfigList.map((c) => c.noExtraDir)) ?? false,
|
|
16
|
+
parallel: pickFirst(prerenderConfigList.map((c) => c.parallel)) ?? true,
|
|
17
|
+
disableAutoRun: pickFirst(prerenderConfigList.map((c) => c.disableAutoRun)) ?? false
|
|
25
18
|
};
|
|
26
|
-
|
|
19
|
+
const prerenderConfigGlobalLocalValue = prerenderConfigList.map((c) => c.value).filter((v) => v !== null);
|
|
20
|
+
const defaultLocalValue = pickFirst(prerenderConfigGlobalLocalValue) ??
|
|
21
|
+
(prerenderConfigGlobalLocalValue.length > 0 ||
|
|
22
|
+
// Backwards compatibility for with vike({ prerender: true }) in vite.config.js
|
|
23
|
+
prerenderConfigs?.some((p) => p === true) ||
|
|
24
|
+
false);
|
|
25
|
+
(0, utils_js_1.objectAssign)(prerenderConfigGlobal, {
|
|
26
|
+
defaultLocalValue,
|
|
27
|
+
isEnabled: defaultLocalValue || vikeConfig.pageConfigs.some((pageConfig) => resolvePrerenderConfigLocal(pageConfig)?.value)
|
|
28
|
+
});
|
|
29
|
+
return prerenderConfigGlobal;
|
|
27
30
|
}
|
|
28
31
|
function resolvePrerenderConfigLocal(pageConfig) {
|
|
29
32
|
const configValue = (0, getConfigValueBuildTime_js_1.getConfigValueBuildTime)(pageConfig, 'prerender');
|
|
@@ -34,9 +37,8 @@ function resolvePrerenderConfigLocal(pageConfig) {
|
|
|
34
37
|
const value = values[0];
|
|
35
38
|
(0, utils_js_1.assert)(typeof value === 'boolean');
|
|
36
39
|
(0, utils_js_1.assert)((0, utils_js_1.isArray)(configValue.definedAtData));
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
return { value, configValueFilePathToShowToUser };
|
|
40
|
+
const prerenderConfigLocal = { value };
|
|
41
|
+
return prerenderConfigLocal;
|
|
40
42
|
}
|
|
41
43
|
function isObject2(p) {
|
|
42
44
|
return typeof p === 'object' && p !== null;
|
|
@@ -120,15 +120,16 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
120
120
|
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(viteConfig);
|
|
121
121
|
const { outDirClient } = (0, getOutDirs_js_1.getOutDirs)(viteConfig);
|
|
122
122
|
const { root } = viteConfig;
|
|
123
|
-
const
|
|
124
|
-
validatePrerenderConfig(
|
|
125
|
-
|
|
123
|
+
const prerenderConfigGlobal = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(vikeConfig);
|
|
124
|
+
validatePrerenderConfig(prerenderConfigGlobal);
|
|
125
|
+
const { partial, noExtraDir, parallel, defaultLocalValue, isEnabled } = prerenderConfigGlobal;
|
|
126
|
+
if (!isEnabled) {
|
|
126
127
|
(0, utils_js_1.assert)(standaloneTrigger);
|
|
127
|
-
|
|
128
|
+
// TODO/now: make it assertUsage() and remove dist/server/entry.mjs whenever possible
|
|
129
|
+
(0, utils_js_1.assertWarning)(prerenderConfigGlobal, `You're executing ${picocolors_1.default.cyan(standaloneTrigger)} but you didn't enable pre-rendering. Use the config ${picocolors_1.default.cyan('prerender')} (${picocolors_1.default.underline('https://vike.dev/prerender')}) to enable it.`, {
|
|
128
130
|
onlyOnce: true
|
|
129
131
|
});
|
|
130
132
|
}
|
|
131
|
-
const { partial = false, noExtraDir = false, parallel = true } = prerenderConfig || {};
|
|
132
133
|
const concurrencyLimit = (0, utils_js_1.pLimit)(parallel === false || parallel === 0 ? 1 : parallel === true || parallel === undefined ? (0, os_1.cpus)().length : parallel);
|
|
133
134
|
await (0, globalContext_js_1.initGlobalContext_runPrerender)();
|
|
134
135
|
const globalContext = await (0, globalContext_js_1.getGlobalContextInternal)();
|
|
@@ -141,7 +142,7 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
141
142
|
output: []
|
|
142
143
|
};
|
|
143
144
|
const doNotPrerenderList = [];
|
|
144
|
-
await collectDoNoPrerenderList(vikeConfig.pageConfigs, doNotPrerenderList, concurrencyLimit, globalContext);
|
|
145
|
+
await collectDoNoPrerenderList(vikeConfig.pageConfigs, doNotPrerenderList, defaultLocalValue, concurrencyLimit, globalContext);
|
|
145
146
|
await callOnBeforePrerenderStartHooks(prerenderContext, globalContext, concurrencyLimit, doNotPrerenderList);
|
|
146
147
|
await handlePagesWithStaticRoutes(prerenderContext, globalContext, doNotPrerenderList, concurrencyLimit);
|
|
147
148
|
await callOnPrerenderStartHook(prerenderContext, globalContext);
|
|
@@ -164,20 +165,21 @@ async function runPrerender(options = {}, standaloneTrigger) {
|
|
|
164
165
|
const prerenderContextPublic = makePublic(prerenderContext);
|
|
165
166
|
return { viteConfig, prerenderContextPublic };
|
|
166
167
|
}
|
|
167
|
-
async function collectDoNoPrerenderList(pageConfigs, doNotPrerenderList, concurrencyLimit, globalContext) {
|
|
168
|
+
async function collectDoNoPrerenderList(pageConfigs, doNotPrerenderList, defaultLocalValue, concurrencyLimit, globalContext) {
|
|
168
169
|
// V1 design
|
|
169
170
|
pageConfigs.forEach((pageConfig) => {
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
171
|
+
const prerenderConfigLocal = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigLocal)(pageConfig);
|
|
172
|
+
const { pageId } = pageConfig;
|
|
173
|
+
if (!prerenderConfigLocal) {
|
|
174
|
+
if (!defaultLocalValue) {
|
|
175
|
+
doNotPrerenderList.push({ pageId });
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
const { value } = prerenderConfigLocal;
|
|
180
|
+
if (value === false) {
|
|
181
|
+
doNotPrerenderList.push({ pageId });
|
|
182
|
+
}
|
|
181
183
|
}
|
|
182
184
|
});
|
|
183
185
|
// Old design
|
|
@@ -210,12 +212,7 @@ async function collectDoNoPrerenderList(pageConfigs, doNotPrerenderList, concurr
|
|
|
210
212
|
}
|
|
211
213
|
else {
|
|
212
214
|
// Don't pre-render `pageId`
|
|
213
|
-
doNotPrerenderList.push({
|
|
214
|
-
pageId,
|
|
215
|
-
setByConfigFile: p.filePath,
|
|
216
|
-
setByConfigName: 'doNotPrerender',
|
|
217
|
-
setByConfigValue: doNotPrerender
|
|
218
|
-
});
|
|
215
|
+
doNotPrerenderList.push({ pageId });
|
|
219
216
|
}
|
|
220
217
|
}
|
|
221
218
|
});
|
|
@@ -568,8 +565,7 @@ function warnContradictoryNoPrerenderList(prerenderedPageContexts, doNotPrerende
|
|
|
568
565
|
if (!isContradictory)
|
|
569
566
|
return;
|
|
570
567
|
}
|
|
571
|
-
|
|
572
|
-
(0, utils_js_1.assertWarning)(false, `The ${providedByHook.hookName}() hook defined by ${providedByHook.hookFilePath} returns the URL ${picocolors_1.default.cyan(urlOriginal)}, while ${setByConfigFile} sets the config ${picocolors_1.default.cyan(setByConfigName)} to ${picocolors_1.default.cyan(String(setByConfigValue))}. This is contradictory: either don't set the config ${picocolors_1.default.cyan(setByConfigName)} to ${picocolors_1.default.cyan(String(setByConfigValue))} or remove the URL ${picocolors_1.default.cyan(urlOriginal)} from the list of URLs to be pre-rendered.`, { onlyOnce: true });
|
|
568
|
+
(0, utils_js_1.assertWarning)(false, `The ${providedByHook.hookName}() hook defined by ${providedByHook.hookFilePath} returns the URL ${picocolors_1.default.cyan(urlOriginal)} matching the route of the page ${picocolors_1.default.cyan(pageId)} which isn't configured to be pre-rendered. This is contradictory: either enable pre-rendering for ${picocolors_1.default.cyan(pageId)} or remove the URL ${picocolors_1.default.cyan(urlOriginal)} from the list of URLs to be pre-rendered.`, { onlyOnce: true });
|
|
573
569
|
});
|
|
574
570
|
}
|
|
575
571
|
async function warnMissingPages(prerenderedPageContexts, globalContext, doNotPrerenderList, partial) {
|
|
@@ -816,8 +812,8 @@ prerenderConfig) {
|
|
|
816
812
|
}
|
|
817
813
|
function makePublic(prerenderContext) {
|
|
818
814
|
const prerenderContextPublic = (0, utils_js_1.makePublicCopy)(prerenderContext, 'prerenderContext', [
|
|
819
|
-
'
|
|
820
|
-
'
|
|
815
|
+
'output', // vite-plugin-vercel
|
|
816
|
+
'pageContexts' // https://vike.dev/i18n#pre-rendering
|
|
821
817
|
]);
|
|
822
818
|
return prerenderContextPublic;
|
|
823
819
|
}
|
|
@@ -33,3 +33,4 @@ __exportStar(require("../../utils/isArray.js"), exports);
|
|
|
33
33
|
__exportStar(require("../../utils/isObject.js"), exports);
|
|
34
34
|
__exportStar(require("../../utils/changeEnumerable.js"), exports);
|
|
35
35
|
__exportStar(require("../../utils/makePublicCopy.js"), exports);
|
|
36
|
+
__exportStar(require("../../utils/isNotNullish.js"), exports);
|
|
@@ -31,7 +31,7 @@ function getConfigValue(pageConfig, configName) {
|
|
|
31
31
|
(0, utils_js_1.assert)(configValueSource);
|
|
32
32
|
(0, utils_js_1.assert)(configValueSource.isOverriden === false);
|
|
33
33
|
(0, utils_js_1.assert)(sources.slice(1).every((s) => s.isOverriden === true));
|
|
34
|
-
(0, utils_js_1.assert)(
|
|
34
|
+
(0, utils_js_1.assert)(configValueSource.valueIsLoaded);
|
|
35
35
|
return {
|
|
36
36
|
type: 'standard',
|
|
37
37
|
value: configValueSource.value,
|
|
@@ -54,7 +54,7 @@ function mergeCumulative(configValueSources) {
|
|
|
54
54
|
configValueSources.forEach((configValueSource) => {
|
|
55
55
|
(0, utils_js_1.assert)(configValueSource.isOverriden === false);
|
|
56
56
|
(0, utils_js_1.assert)(configValueSource.configEnv.config === true);
|
|
57
|
-
(0, utils_js_1.assert)(
|
|
57
|
+
(0, utils_js_1.assert)(configValueSource.valueIsLoaded);
|
|
58
58
|
value.push(configValueSource.value);
|
|
59
59
|
definedAtData.push(getDefinedAtFile(configValueSource));
|
|
60
60
|
});
|
|
@@ -51,7 +51,7 @@ function serializeConfigValues(pageConfig, importStatements, filesEnv, isEnvMatc
|
|
|
51
51
|
function getValueSerializedFromSource(configValueSource, configName, importStatements, filesEnv) {
|
|
52
52
|
(0, utils_js_1.assert)(configValueSource.isOverriden === false);
|
|
53
53
|
let valueData;
|
|
54
|
-
if (
|
|
54
|
+
if (configValueSource.valueIsLoaded && !configValueSource.valueIsLoadedWithImport) {
|
|
55
55
|
valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.definedAtFilePath, importStatements, filesEnv, configValueSource.configEnv);
|
|
56
56
|
}
|
|
57
57
|
else {
|
|
@@ -12,7 +12,8 @@ import { isViteCliCall } from '../shared/isViteCliCall.js';
|
|
|
12
12
|
import { isVikeCliOrApi } from '../../api/context.js';
|
|
13
13
|
import { getVikeConfig2 } from './importUserCode/v1-design/getVikeConfig.js';
|
|
14
14
|
import { assertViteRoot, getViteRoot, normalizeViteRoot } from '../../api/prepareViteApiCall.js';
|
|
15
|
-
import {
|
|
15
|
+
import { temp_disablePrerenderAutoRun } from '../../prerender/context.js';
|
|
16
|
+
import { resolvePrerenderConfigGlobal } from '../../prerender/resolvePrerenderConfig.js';
|
|
16
17
|
const pluginName = 'vike:commonConfig';
|
|
17
18
|
function commonConfig(vikeVitePluginOptions) {
|
|
18
19
|
return [
|
|
@@ -38,7 +39,7 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
38
39
|
},
|
|
39
40
|
// TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
|
|
40
41
|
configVikePromise: Promise.resolve({
|
|
41
|
-
prerender:
|
|
42
|
+
prerender: resolvePrerenderConfigGlobal(vikeConfig).isEnabled
|
|
42
43
|
})
|
|
43
44
|
};
|
|
44
45
|
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -40,6 +40,7 @@ function getLogicalPath(locationId, ignoredDirs, removeParenthesesDirs) {
|
|
|
40
40
|
assertIsPath(logicalPath);
|
|
41
41
|
return logicalPath;
|
|
42
42
|
}
|
|
43
|
+
// See getPlusFilesRelevant() and getPlusFilesOrdered()
|
|
43
44
|
function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
44
45
|
assertLocationId(locationId1);
|
|
45
46
|
assertLocationId(locationId2);
|
|
@@ -48,7 +49,7 @@ function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
|
48
49
|
const inheritanceRoot1 = getInheritanceRoot(locationId1);
|
|
49
50
|
const inheritanceRoot2 = getInheritanceRoot(locationId2);
|
|
50
51
|
const inheritanceRootPage = getInheritanceRoot(locationIdPage);
|
|
51
|
-
//
|
|
52
|
+
// Only works if both locationId1 and locationId2 are inherited by the same page
|
|
52
53
|
assert(isInherited(locationId1, locationIdPage));
|
|
53
54
|
assert(isInherited(locationId2, locationIdPage));
|
|
54
55
|
// Equivalent assertion (see isInherited() implementation)
|