vike 0.4.223-commit-59f3966 → 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.
Files changed (34) hide show
  1. package/dist/cjs/node/api/prepareViteApiCall.js +0 -1
  2. package/dist/cjs/node/plugin/plugins/commonConfig.js +2 -1
  3. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +2 -1
  4. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +113 -71
  5. package/dist/cjs/node/prerender/context.js +3 -8
  6. package/dist/cjs/node/prerender/resolvePrerenderConfig.js +23 -21
  7. package/dist/cjs/node/prerender/runPrerender.js +24 -28
  8. package/dist/cjs/node/prerender/utils.js +1 -0
  9. package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +2 -2
  10. package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +3 -1
  11. package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +1 -1
  12. package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
  13. package/dist/esm/node/api/prepareViteApiCall.js +0 -1
  14. package/dist/esm/node/plugin/plugins/commonConfig.js +3 -2
  15. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +2 -1
  16. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +113 -71
  17. package/dist/esm/node/prerender/context.d.ts +0 -2
  18. package/dist/esm/node/prerender/context.js +4 -9
  19. package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +10 -6
  20. package/dist/esm/node/prerender/resolvePrerenderConfig.js +24 -22
  21. package/dist/esm/node/prerender/runPrerender.d.ts +7 -25
  22. package/dist/esm/node/prerender/runPrerender.js +25 -29
  23. package/dist/esm/node/prerender/utils.d.ts +1 -0
  24. package/dist/esm/node/prerender/utils.js +1 -0
  25. package/dist/esm/node/runtime/globalContext.d.ts +2 -1
  26. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +165 -5
  27. package/dist/esm/shared/page-configs/Config.d.ts +8 -0
  28. package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +2 -2
  29. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +3 -1
  30. package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +1 -1
  31. package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
  32. package/dist/esm/utils/PROJECT_VERSION.js +1 -1
  33. package/dist/esm/utils/projectInfo.d.ts +1 -1
  34. package/package.json +2 -2
@@ -40,7 +40,6 @@ exports.prepareViteApiCall = prepareViteApiCall;
40
40
  exports.getViteRoot = getViteRoot;
41
41
  exports.assertViteRoot = assertViteRoot;
42
42
  exports.normalizeViteRoot = normalizeViteRoot;
43
- // TODO: enable Vike extensions to add Vite plugins
44
43
  const vite_1 = require("vite");
45
44
  const context_js_1 = require("./context.js");
46
45
  const getVikeConfig_js_1 = require("../plugin/plugins/importUserCode/v1-design/getVikeConfig.js");
@@ -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, context_js_2.isPrerenderEnabled)(vikeConfig)
47
+ prerender: (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(vikeConfig).isEnabled
47
48
  })
48
49
  };
49
50
  }
@@ -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
- // sortAfterInheritanceOrder() only works if both locationId1 and locationId2 are inherited by the same page
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
- // interop vike(options) in vite.config.js
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,13 +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
  });
205
+ applyEffectsMetaEnv(pageConfigGlobal.configValueSources, configDefinitionsResolved.configDefinitionsGlobal);
206
+ applyEffectsConfVal(pageConfigGlobal.configValueSources, configDefinitionsResolved.configDefinitionsGlobal);
209
207
  assertPageConfigGlobal(pageConfigGlobal, plusFilesAll);
210
208
  const pageConfigs = (0, utils_js_1.objectEntries)(configDefinitionsResolved.configDefinitionsLocal)
211
209
  .filter(([_locationId, { plusFiles }]) => isDefiningPage(plusFiles))
@@ -222,7 +220,8 @@ function getPageConfigsBuildTime(configDefinitionsResolved, plusFilesAll, userRo
222
220
  configValueSources[configName] = sources;
223
221
  });
224
222
  const pageConfigRoute = determineRouteFilesystem(locationId, configValueSources);
225
- applyEffectsAll(configValueSources, configDefinitionsLocal);
223
+ applyEffectsMetaEnv(configValueSources, configDefinitionsLocal);
224
+ applyEffectsConfVal(configValueSources, configDefinitionsLocal);
226
225
  const configValuesComputed = getComputed(configValueSources, configDefinitionsLocal);
227
226
  const pageConfig = {
228
227
  pageId: locationId,
@@ -365,18 +364,18 @@ function temp_interopVikeVitePlugin(pageConfigGlobal, vikeVitePluginOptions, use
365
364
  });
366
365
  });
367
366
  }
367
+ // Together with getPlusFilesOrdered() this implements the whole config inheritance ordering for non-global configs. See sortAfterInheritanceOrderGlobal() for global configs.
368
368
  function getPlusFilesRelevant(plusFilesAll, locationIdPage) {
369
369
  const plusFilesRelevant = Object.fromEntries((0, utils_js_1.objectEntries)(plusFilesAll)
370
370
  .filter(([locationId]) => {
371
371
  return (0, filesystemRouting_js_1.isInherited)(locationId, locationIdPage);
372
372
  })
373
- // Sort after config inheritance.
374
- // - Together with getPlusFilesOrdered() this implements the whole order of config inheritance.
375
- // - See sortForGlobal() for global configs order.
376
373
  .sort(([locationId1], [locationId2]) => (0, filesystemRouting_js_1.sortAfterInheritanceOrder)(locationId1, locationId2, locationIdPage)));
377
374
  return plusFilesRelevant;
378
375
  }
379
- function sortForGlobal(plusFilesAll) {
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) {
380
379
  const plusFilesAllSorted = Object.fromEntries((0, utils_js_1.objectEntries)(plusFilesAll)
381
380
  .sort((0, utils_js_1.lowerFirst)(([locationId]) => locationId.split('/').length))
382
381
  .sort((0, utils_js_1.makeFirst)(([locationId]) => isGlobalLocation(locationId, plusFilesAll))));
@@ -390,22 +389,20 @@ function resolveConfigValueSources(configName, configDef, plusFilesRelevant, use
390
389
  return configValueSource;
391
390
  });
392
391
  if ((0, utils_js_1.isCallable)(configDef.global)) {
393
- const isGlobalValue = configDef.global;
394
392
  (0, utils_js_1.assert)(configDef.env.config);
395
393
  sources = sources.filter((source) => {
396
394
  (0, utils_js_1.assert)(source.configEnv.config);
397
395
  (0, utils_js_1.assert)(source.valueIsLoaded);
398
- const valueIsGlobal = isGlobalValue(source.value);
396
+ const valueIsGlobal = resolveIsGlobalValue(configDef.global, source.value);
399
397
  return isGlobal ? valueIsGlobal : !valueIsGlobal;
400
398
  });
401
399
  }
402
400
  return sources;
403
401
  }
404
- // Together with sortAfterInheritanceOrder() this implements the whole order of config inheritance.
402
+ // Together with getPlusFilesRelevant() this implements the whole config inheritance ordering.
405
403
  function getPlusFilesOrdered(configName, plusFilesRelevant) {
406
404
  const plusFilesOrdered = [];
407
- // `plusFilesRelevant` is already sorted by sortAfterInheritanceOrder() at getPlusFilesRelevant()
408
- // `plusFilesAtLocationId` is already sorted by sortMakeDeterministic() at getPlusFilesAll()
405
+ // `plusFilesRelevant` is already deterministic, see sortMakeDeterministic() at getPlusFilesAll()
409
406
  for (const plusFilesAtLocationId of Object.values(plusFilesRelevant)) {
410
407
  const plusFilesForConfigName = plusFilesAtLocationId.filter((plusFile) => getDefiningConfigNames(plusFile).includes(configName));
411
408
  // We populate `plusFilesOrdered` with inheritance order.
@@ -582,6 +579,15 @@ function isDefiningPage(plusFiles) {
582
579
  function isDefiningPageConfig(configName) {
583
580
  return ['Page', 'route'].includes(configName);
584
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
+ }
585
591
  function getDefiningConfigNames(plusFile) {
586
592
  let configNames = [];
587
593
  if (!plusFile.isConfigFile) {
@@ -666,67 +672,103 @@ function assertMetaUsage(metaVal, metaConfigDefinedAt) {
666
672
  }
667
673
  });
668
674
  }
669
- function applyEffectsAll(configValueSources, configDefinitions) {
670
- (0, utils_js_1.objectEntries)(configDefinitions).forEach(([configName, configDef]) => {
671
- if (!configDef.effect)
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)
672
680
  return;
673
- // The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
674
- // (We could support effect for non config-only by always loading its value at config time, regardless of the config's `env` value.)
675
- (0, utils_js_1.assertUsage)(configDef.env.config, [
676
- `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 }')}.`
677
- ].join(' '));
678
- const source = configValueSources[configName]?.[0];
679
- if (!source)
681
+ const effect = runEffect(configNameEffect, configDefEffect, sourceEffect);
682
+ if (!effect)
680
683
  return;
681
- // The config value is eagerly loaded since `configDef.env === 'config-only``
682
- (0, utils_js_1.assert)('value' in source);
683
- // Call effect
684
- const configModFromEffect = configDef.effect({
685
- configValue: source.value,
686
- configDefinedAt: (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, source.definedAtFilePath)
687
- });
688
- if (!configModFromEffect)
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)
689
696
  return;
690
- (0, utils_js_1.assert)((0, utils_js_1.hasProp)(source, 'value')); // We need to assume that the config value is loaded at build-time
691
- applyEffect(configModFromEffect, configValueSources, configDef);
697
+ const { configModFromEffect } = effect;
698
+ applyEffectMetaEnv(configModFromEffect, configValueSources, configDefEffect);
692
699
  });
693
700
  }
694
- function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
695
- const notSupported = `Effects currently only supports modifying the the ${picocolors_1.default.cyan('env')} of a config.`;
696
- (0, utils_js_1.objectEntries)(configModFromEffect).forEach(([configName, configValue]) => {
697
- if (configName === 'meta') {
698
- let configDefinedAt;
699
- if (configDefEffect._userEffectDefinedAtFilePath) {
700
- configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, configDefEffect._userEffectDefinedAtFilePath);
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
- });
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)
714
+ });
715
+ if (!configModFromEffect)
716
+ return null;
717
+ return { configModFromEffect, configValueEffectSource };
718
+ }
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) {
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.`;
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
- (0, utils_js_1.assertUsage)(false, notSupported);
722
- /* To implement being able to set a config value in an effect:
723
- * - Copy and append definedAtFile.fileExportPathToShowToUser with ['meta', configName, 'effect']
724
- * - Copying the definedAtFile of the config that defines the effect
725
- * - Same precedence as the config that sets the value triggering the effect (not the config defining the effect)
726
- * - Apply sortConfigValueSources() again?
727
- configValueSources.push()
728
- */
756
+ configDefinedAt = null;
729
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
+ });
730
772
  });
731
773
  }
732
774
  function getComputed(configValueSources, configDefinitions) {
@@ -840,7 +882,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
840
882
  function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName) {
841
883
  (0, utils_js_1.assert)(configFilesystemRoutingRoot.configEnv.config);
842
884
  // Eagerly loaded since it's config-only
843
- (0, utils_js_1.assert)('value' in configFilesystemRoutingRoot);
885
+ (0, utils_js_1.assert)(configFilesystemRoutingRoot.valueIsLoaded);
844
886
  const { value } = configFilesystemRoutingRoot;
845
887
  const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, configFilesystemRoutingRoot.definedAtFilePath);
846
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 prerenderConfig = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfig)(vikeConfig);
17
- return (isPrerenderEnabled(vikeConfig) &&
18
- !(prerenderConfig || {}).disableAutoRun &&
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.resolvePrerenderConfig = resolvePrerenderConfig;
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
- const helpers_js_1 = require("../../shared/page-configs/helpers.js");
8
- // TODO/now:
9
- // - prerender.value
10
- function resolvePrerenderConfig(vikeConfig) {
7
+ function resolvePrerenderConfigGlobal(vikeConfig) {
11
8
  const prerenderConfigs = vikeConfig.global.config.prerender;
12
- if (!prerenderConfigs &&
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
- prerenderSettings = prerenderSettings.filter(isObject2);
19
- (0, utils_js_1.assert)(prerenderSettings.every(isObject2));
20
- const prerenderConfig = {
21
- partial: pickFirst(prerenderSettings.map((c) => c.partial)) ?? false,
22
- noExtraDir: pickFirst(prerenderSettings.map((c) => c.noExtraDir)) ?? false,
23
- parallel: pickFirst(prerenderSettings.map((c) => c.parallel)) ?? true,
24
- disableAutoRun: pickFirst(prerenderSettings.map((c) => c.disableAutoRun)) ?? false
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
- return prerenderConfig;
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 configValueFilePathToShowToUser = (0, helpers_js_1.getConfigValueFilePathToShowToUser)(configValue.definedAtData[0]);
38
- (0, utils_js_1.assert)(configValueFilePathToShowToUser);
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 prerenderConfig = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfig)(vikeConfig);
124
- validatePrerenderConfig(prerenderConfig);
125
- if (!prerenderConfig) {
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
- (0, utils_js_1.assertWarning)(prerenderConfig, `You're executing ${picocolors_1.default.cyan(standaloneTrigger)} but the config ${picocolors_1.default.cyan('prerender')} isn't set to true`, {
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 configValue = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigLocal)(pageConfig);
171
- if (!configValue)
172
- return;
173
- const { value, configValueFilePathToShowToUser } = configValue;
174
- if (value === false) {
175
- doNotPrerenderList.push({
176
- pageId: pageConfig.pageId,
177
- setByConfigName: 'prerender',
178
- setByConfigValue: false,
179
- setByConfigFile: configValueFilePathToShowToUser
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
- const { setByConfigName, setByConfigValue, setByConfigFile } = doNotPrerenderListEntry;
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
- 'pageContexts',
820
- 'output'
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)('value' in configValueSource);
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)('value' in configValueSource);
57
+ (0, utils_js_1.assert)(configValueSource.valueIsLoaded);
58
58
  value.push(configValueSource.value);
59
59
  definedAtData.push(getDefinedAtFile(configValueSource));
60
60
  });
@@ -66,7 +66,9 @@ function parseConfigValuesSerialized_tmp(configValuesSerialized) {
66
66
  const { valueSerialized, ...common } = configValueSeriliazed;
67
67
  const { value, sideExports } = parseValueSerialized(valueSerialized, configName, () => {
68
68
  (0, utils_js_1.assert)(configValueSeriliazed.type !== 'computed');
69
- return configValueSeriliazed.definedAtData;
69
+ const { definedAtData } = configValueSeriliazed;
70
+ const definedAtFile = Array.isArray(definedAtData) ? definedAtData[0] : definedAtData;
71
+ return definedAtFile;
70
72
  });
71
73
  addSideExports(sideExports);
72
74
  configValue = { value, ...common };
@@ -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 ('value' in configValueSource && !configValueSource.valueIsLoadedWithImport) {
54
+ if (configValueSource.valueIsLoaded && !configValueSource.valueIsLoadedWithImport) {
55
55
  valueData = getValueSerializedWithJson(configValueSource.value, configName, configValueSource.definedAtFilePath, importStatements, filesEnv, configValueSource.configEnv);
56
56
  }
57
57
  else {
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.223-commit-59f3966';
5
+ exports.PROJECT_VERSION = '0.4.223-commit-535bde1';
@@ -2,7 +2,6 @@ export { prepareViteApiCall };
2
2
  export { getViteRoot };
3
3
  export { assertViteRoot };
4
4
  export { normalizeViteRoot };
5
- // TODO: enable Vike extensions to add Vite plugins
6
5
  import { loadConfigFromFile, mergeConfig, resolveConfig } from 'vite';
7
6
  import { clearContextApiOperation, setContextApiOperation } from './context.js';
8
7
  import { getVikeConfig2 } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
@@ -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 { isPrerenderEnabled, temp_disablePrerenderAutoRun } from '../../prerender/context.js';
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: isPrerenderEnabled(vikeConfig)
42
+ prerender: resolvePrerenderConfigGlobal(vikeConfig).isEnabled
42
43
  })
43
44
  };
44
45
  }
@@ -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
- // sortAfterInheritanceOrder() only works if both locationId1 and locationId2 are inherited by the same page
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)