vike 0.4.143-commit-dc6fea0 → 0.4.143-commit-fa295e1

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 (37) hide show
  1. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +30 -27
  2. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +107 -54
  3. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -10
  4. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +11 -11
  5. package/dist/cjs/node/prerender/runPrerender.js +9 -8
  6. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
  7. package/dist/cjs/node/shared/getClientEntryFilePath.js +1 -7
  8. package/dist/cjs/shared/getPageFiles/getExports.js +2 -5
  9. package/dist/cjs/shared/getPageFiles/parsePageConfigsSerialized.js +9 -6
  10. package/dist/cjs/shared/hooks/getHook.js +3 -1
  11. package/dist/cjs/shared/page-configs/getExportPath.js +2 -2
  12. package/dist/cjs/shared/page-configs/parseConfigValuesImported.js +8 -5
  13. package/dist/cjs/shared/page-configs/utils.js +66 -42
  14. package/dist/cjs/shared/route/loadPageRoutes.js +5 -6
  15. package/dist/cjs/utils/projectInfo.js +1 -1
  16. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +30 -27
  17. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +107 -54
  18. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -10
  19. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +2 -2
  20. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +11 -11
  21. package/dist/esm/node/prerender/runPrerender.js +10 -9
  22. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
  23. package/dist/esm/node/shared/getClientEntryFilePath.js +2 -8
  24. package/dist/esm/shared/getPageFiles/getExports.d.ts +1 -2
  25. package/dist/esm/shared/getPageFiles/getExports.js +3 -6
  26. package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.js +9 -6
  27. package/dist/esm/shared/hooks/getHook.js +3 -1
  28. package/dist/esm/shared/page-configs/PageConfig.d.ts +34 -10
  29. package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
  30. package/dist/esm/shared/page-configs/getExportPath.js +2 -2
  31. package/dist/esm/shared/page-configs/parseConfigValuesImported.js +8 -5
  32. package/dist/esm/shared/page-configs/utils.d.ts +19 -13
  33. package/dist/esm/shared/page-configs/utils.js +65 -41
  34. package/dist/esm/shared/route/loadPageRoutes.js +6 -7
  35. package/dist/esm/utils/projectInfo.d.ts +1 -1
  36. package/dist/esm/utils/projectInfo.js +1 -1
  37. package/package.json +1 -1
@@ -24,7 +24,7 @@ async function determineOptimizeDeps(config, configVike, isDev) {
24
24
  */
25
25
  config.optimizeDeps.include = [...include, ...normalizeInclude(config.optimizeDeps.include)];
26
26
  config.optimizeDeps.entries = [...entries, ...normalizeEntries(config.optimizeDeps.entries)];
27
- // console.log('config.optimizeDeps', config.optimizeDeps)
27
+ console.log('config.optimizeDeps', config.optimizeDeps);
28
28
  }
29
29
  exports.determineOptimizeDeps = determineOptimizeDeps;
30
30
  async function getPageDeps(config, pageConfigs, isDev) {
@@ -35,37 +35,40 @@ async function getPageDeps(config, pageConfigs, isDev) {
35
35
  pageConfigs.forEach((pageConfig) => {
36
36
  const configValueSourcesRelevant = (0, getConfigValueSourcesRelevant_js_1.getConfigValueSourcesRelevant)(pageConfig);
37
37
  configValueSourcesRelevant.forEach((configValueSource) => {
38
- const { valueIsImportedAtRuntime, configEnv, definedAtInfo } = configValueSource;
39
- if (!valueIsImportedAtRuntime)
38
+ if (!configValueSource.valueIsImportedAtRuntime)
40
39
  return;
41
- const { filePath } = definedAtInfo;
42
- (0, utils_js_1.assert)(filePath);
43
- if (configEnv !== 'client-only' && configEnv !== 'server-and-client')
40
+ if (configValueSource.isComputed)
44
41
  return;
45
- if (filePath.startsWith('/')) {
46
- // Is getFilePathAbsolute() really needed? This contradicts the code below that doesn't need getFilePathAbsolute().
47
- entries.push((0, utils_js_1.getFilePathAbsolute)(filePath, config));
42
+ const { definedAtInfo, configEnv } = configValueSource;
43
+ if (configEnv !== 'client-only' && configEnv !== 'server-and-client')
48
44
  return;
49
- }
50
- // getVikeConfig() resolves relative import paths
51
- (0, utils_js_1.assert)(!filePath.startsWith('.'));
52
- // We need to differentiate between npm package imports and path aliases.
53
- // There are path aliases that cannot be distinguished from npm package names.
54
- // We recommend users to use the '#' prefix convention for path aliases, see https://vike.dev/path-aliases#vite and assertResolveAlias()
55
- if ((0, utils_js_1.isNpmPackageImport)(filePath)) {
56
- // isNpmPackageImport() returns false for a path alias like #root/renderer/onRenderClient
57
- (0, utils_js_1.assert)(!filePath.startsWith('#'));
58
- include.push(filePath);
45
+ if (definedAtInfo.filePathRelativeToUserRootDir !== null) {
46
+ const { filePathAbsolute } = definedAtInfo;
47
+ (0, utils_js_1.assert)(filePathAbsolute);
48
+ // Surpsingly Vite expects entries to be absolute paths
49
+ entries.push(filePathAbsolute);
59
50
  }
60
51
  else {
61
- /* Path aliases, e.g.:
62
- * ```js
63
- * // /renderer/+config.js
64
- * import onRenderClient from '#root/renderer/onRenderClient'
65
- * ```
66
- * Does Vite resolve the path aliases or is getFilePathAbsolute() needed?
67
- */
68
- entries.push(filePath);
52
+ // Adding definedAtInfo.filePathAbsolute doesn't work for npm packages, I guess because of Vite's config.server.fs.allow
53
+ const { importPathAbsolute } = definedAtInfo;
54
+ (0, utils_js_1.assert)(importPathAbsolute);
55
+ // We need to differentiate between npm package imports and path aliases.
56
+ // There are path aliases that cannot be distinguished from npm package names.
57
+ // We recommend users to use the '#' prefix convention for path aliases, see https://vike.dev/path-aliases#vite and assertResolveAlias()
58
+ if ((0, utils_js_1.isNpmPackageImport)(importPathAbsolute)) {
59
+ // isNpmPackageImport() returns false for a path alias like #root/renderer/onRenderClient
60
+ (0, utils_js_1.assert)(!importPathAbsolute.startsWith('#'));
61
+ include.push(importPathAbsolute);
62
+ }
63
+ else {
64
+ /* Path aliases, e.g.:
65
+ * ```js
66
+ * // /renderer/+config.js
67
+ * import onRenderClient from '#root/renderer/onRenderClient'
68
+ * ```
69
+ */
70
+ entries.push(importPathAbsolute);
71
+ }
69
72
  }
70
73
  });
71
74
  });
@@ -345,7 +345,9 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
345
345
  if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
346
346
  return;
347
347
  (0, utils_js_1.assert)(!configValueSource.isComputed);
348
- (0, utils_js_1.assertWarning)(false, `Being able to define config ${picocolors_1.default.cyan(configName)} in ${configValueSource.definedAtInfo.filePath} is experimental and will likely be removed. Define the config ${picocolors_1.default.cyan(configName)} in vike's Vite plugin options instead.`, { onlyOnce: true });
348
+ const sourceFilePath = getFilePathToShowToUser2(configValueSource.definedAtInfo);
349
+ (0, utils_js_1.assert)(sourceFilePath);
350
+ (0, utils_js_1.assertWarning)(false, `Being able to define config ${picocolors_1.default.cyan(configName)} in ${sourceFilePath} is experimental and will likely be removed. Define the config ${picocolors_1.default.cyan(configName)} in vike's Vite plugin options instead.`, { onlyOnce: true });
349
351
  globalVikeConfig[configName] = configValueSource.value;
350
352
  }
351
353
  });
@@ -428,48 +430,48 @@ function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden,
428
430
  interfaceFilesOverriden.forEach((interfaceFileLoser) => {
429
431
  const configValueSourceWinner = getConfigValueSource(configName, interfaceFileWinner, configDef, userRootDir);
430
432
  const configValueSourceLoser = getConfigValueSource(configName, interfaceFileLoser, configDef, userRootDir);
431
- (0, utils_js_1.assertWarning)(false, `${(0, utils_js_2.getConfigDefinedAtString)(configName, configValueSourceLoser, true)} overriden by another ${(0, utils_js_2.getConfigDefinedAtString)(configName, configValueSourceWinner, false)}, remove one of the two`, { onlyOnce: false });
433
+ (0, utils_js_1.assert)(!configValueSourceLoser.isComputed);
434
+ (0, utils_js_1.assert)(!configValueSourceWinner.isComputed);
435
+ (0, utils_js_1.assertWarning)(false, `${getConfigSourceDefinedAtString(configName, configValueSourceLoser, undefined, true)} overriden by another ${getConfigSourceDefinedAtString(configName, configValueSourceWinner, undefined, false)}, remove one of the two`, { onlyOnce: false });
432
436
  });
433
437
  }
434
438
  function isInterfaceFileUserLand(interfaceFile) {
435
439
  return (interfaceFile.isConfigFile && !interfaceFile.isConfigExtend) || interfaceFile.isValueFile;
436
440
  }
437
441
  function getConfigValueSource(configName, interfaceFile, configDef, userRootDir) {
438
- // TODO: rethink file paths of ConfigElement
439
- const filePathToShowToUser = interfaceFile.filePath.filePathRelativeToUserRootDir ?? interfaceFile.filePath.filePathAbsolute;
440
442
  const conf = interfaceFile.configMap[configName];
441
443
  (0, utils_js_1.assert)(conf);
442
444
  const configEnv = configDef.env;
443
- const definedAtInfoConfigFile = {
444
- filePath: filePathToShowToUser,
445
+ const definedAtConfigFile = {
446
+ ...interfaceFile.filePath,
445
447
  fileExportPath: ['default', configName]
446
448
  };
447
449
  if (configDef._valueIsFilePath) {
448
- let filePath;
450
+ let definedAtInfo;
451
+ let valueFilePath;
449
452
  if (interfaceFile.isConfigFile) {
450
453
  const { configValue } = conf;
451
454
  const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
452
- const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, { definedAtInfo: definedAtInfoConfigFile }, true);
455
+ const configDefinedAt = getConfigSourceDefinedAtString(configName, { definedAtInfo: definedAtConfigFile });
453
456
  (0, utils_js_1.assertUsage)(import_, `${configDefinedAt} should be an import`);
454
- filePath = import_.filePathToShowToUser;
457
+ valueFilePath = import_.filePathRelativeToUserRootDir ?? import_.importPathAbsolute;
458
+ definedAtInfo = import_;
455
459
  }
456
460
  else {
457
461
  (0, utils_js_1.assert)(interfaceFile.isValueFile);
458
- filePath =
459
- interfaceFile.filePath.filePathRelativeToUserRootDir ??
460
- // Experimental: is this needed? Would it work?
461
- interfaceFile.filePath.filePathAbsolute;
462
+ valueFilePath = interfaceFile.filePath.filePathRelativeToUserRootDir;
463
+ definedAtInfo = {
464
+ ...interfaceFile.filePath,
465
+ fileExportPath: []
466
+ };
462
467
  }
463
468
  const configValueSource = {
464
- value: filePath,
469
+ value: valueFilePath,
465
470
  valueIsFilePath: true,
466
471
  configEnv,
467
472
  valueIsImportedAtRuntime: true,
468
473
  isComputed: false,
469
- definedAtInfo: {
470
- filePath,
471
- fileExportPath: []
472
- }
474
+ definedAtInfo
473
475
  };
474
476
  return configValueSource;
475
477
  }
@@ -478,15 +480,11 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
478
480
  const { configValue } = conf;
479
481
  const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
480
482
  if (import_) {
481
- const { filePathToShowToUser, fileExportName: exportName } = import_;
482
483
  const configValueSource = {
483
484
  configEnv,
484
485
  valueIsImportedAtRuntime: true,
485
486
  isComputed: false,
486
- definedAtInfo: {
487
- filePath: filePathToShowToUser,
488
- fileExportPath: [exportName]
489
- }
487
+ definedAtInfo: import_
490
488
  };
491
489
  return configValueSource;
492
490
  }
@@ -496,23 +494,21 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
496
494
  configEnv,
497
495
  valueIsImportedAtRuntime: false,
498
496
  isComputed: false,
499
- definedAtInfo: definedAtInfoConfigFile
497
+ definedAtInfo: definedAtConfigFile
500
498
  };
501
499
  return configValueSource;
502
500
  }
503
501
  }
504
502
  else if (interfaceFile.isValueFile) {
505
503
  // TODO: rethink file paths of ConfigElement
506
- const importPath = interfaceFile.filePath.filePathRelativeToUserRootDir ?? interfaceFile.filePath.filePathAbsolute;
507
- const exportName = configName === interfaceFile.configName ? 'default' : configName;
508
504
  const valueAlreadyLoaded = 'configValue' in conf;
509
505
  const configValueSource = {
510
506
  configEnv,
511
507
  valueIsImportedAtRuntime: !valueAlreadyLoaded,
512
508
  isComputed: false,
513
509
  definedAtInfo: {
514
- filePath: importPath,
515
- fileExportPath: [exportName]
510
+ ...interfaceFile.filePath,
511
+ fileExportPath: configName === interfaceFile.configName ? [] : [configName]
516
512
  }
517
513
  };
518
514
  if (valueAlreadyLoaded) {
@@ -561,7 +557,8 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
561
557
  return null;
562
558
  const { importPath, exportName } = importData;
563
559
  const filePathAbsolute = resolveImportPath(importData, importerFilePath);
564
- let filePathToShowToUser;
560
+ assertFileEnv(filePathAbsolute ?? importPath, configEnv, configName);
561
+ const fileExportPath = exportName === 'default' || exportName === configName ? [] : [exportName];
565
562
  if (importPath.startsWith('.')) {
566
563
  // We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
567
564
  // ```
@@ -569,22 +566,26 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
569
566
  // ```
570
567
  assertImportPath(filePathAbsolute, importData, importerFilePath);
571
568
  const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, importerFilePath, userRootDir);
572
- filePathToShowToUser = filePathRelativeToUserRootDir;
569
+ return {
570
+ exportName,
571
+ fileExportPath,
572
+ filePathAbsolute,
573
+ filePathRelativeToUserRootDir,
574
+ importPathAbsolute: null
575
+ };
573
576
  }
574
577
  else {
575
578
  // importPath can be:
576
579
  // - an npm package import
577
580
  // - a path alias
578
- filePathToShowToUser = importPath;
579
- }
580
- {
581
- const filePathForEnvCheck = filePathAbsolute ?? importPath;
582
- assertFileEnv(filePathForEnvCheck, configEnv, configName);
581
+ return {
582
+ exportName,
583
+ fileExportPath,
584
+ filePathAbsolute,
585
+ filePathRelativeToUserRootDir: null,
586
+ importPathAbsolute: importPath
587
+ };
583
588
  }
584
- return {
585
- filePathToShowToUser,
586
- fileExportName: exportName
587
- };
588
589
  }
589
590
  function resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, configFilePath, userRootDir) {
590
591
  (0, utils_js_1.assertPosixPath)(userRootDir);
@@ -677,24 +678,26 @@ function applyEffects(pageConfig, configDefinitionsRelevant) {
677
678
  `Adding an effect to ${picocolors_1.default.cyan(configName)} may not work as expected because ${picocolors_1.default.cyan(configName)} has an ${picocolors_1.default.cyan('env')} that is different than ${picocolors_1.default.cyan('config-only')} (its env is ${picocolors_1.default.cyan(configDef.env)}).`,
678
679
  'Reach out to a maintainer if you want to use this in production.'
679
680
  ].join(' '), { onlyOnce: true });
680
- const configValue = pageConfig.configValueSources[configName]?.[0];
681
- if (!configValue)
681
+ const source = pageConfig.configValueSources[configName]?.[0];
682
+ if (!source)
682
683
  return;
684
+ (0, utils_js_1.assert)(!source.isComputed);
683
685
  const configModFromEffect = configDef.effect({
684
- configValue: configValue.value,
685
- configDefinedAt: (0, utils_js_2.getConfigDefinedAtString)(configName, configValue, true)
686
+ configValue: source.value,
687
+ configDefinedAt: getConfigSourceDefinedAtString(configName, source)
686
688
  });
687
689
  if (!configModFromEffect)
688
690
  return;
689
- (0, utils_js_1.assert)((0, utils_js_1.hasProp)(configValue, 'value')); // We need to assume that the config value is loaded at build-time
690
- applyEffect(configModFromEffect, configValue, pageConfig.configValueSources);
691
+ (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
692
+ applyEffect(configModFromEffect, source, pageConfig.configValueSources);
691
693
  });
692
694
  }
693
695
  function applyEffect(configModFromEffect, configValueEffectSource, configValueSources) {
694
696
  const notSupported = `config.meta[configName].effect currently only supports modifying the the ${picocolors_1.default.cyan('env')} of a config. Reach out to a maintainer if you need more capabilities.`;
695
697
  (0, utils_js_1.objectEntries)(configModFromEffect).forEach(([configName, configValue]) => {
696
698
  if (configName === 'meta') {
697
- assertMetaValue(configValue, (0, utils_js_2.getConfigDefinedAtString)(configName, configValueEffectSource, true, 'effect'));
699
+ (0, utils_js_1.assert)(!configValueEffectSource.isComputed);
700
+ assertMetaValue(configValue, getConfigSourceDefinedAtString(configName, configValueEffectSource, true));
698
701
  (0, utils_js_1.objectEntries)(configValue).forEach(([configTargetName, configTargetDef]) => {
699
702
  {
700
703
  const keys = Object.keys(configTargetDef);
@@ -1006,11 +1009,13 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
1006
1009
  // Eagerly loaded since it's config-only
1007
1010
  (0, utils_js_1.assert)('value' in configFilesystemRoutingRoot);
1008
1011
  const { value } = configFilesystemRoutingRoot;
1009
- const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, configFilesystemRoutingRoot, false);
1012
+ (0, utils_js_1.assert)(!configFilesystemRoutingRoot.isComputed);
1013
+ const configDefinedAt = getConfigSourceDefinedAtString(configName, configFilesystemRoutingRoot);
1010
1014
  (0, utils_js_1.assertUsage)(typeof value === 'string', `${configDefinedAt} should be a string`);
1011
1015
  (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('/')}`);
1012
1016
  (0, utils_js_1.assert)(!configFilesystemRoutingRoot.isComputed);
1013
- const before = (0, filesystemRouting_js_1.getFilesystemRouteString)((0, filesystemRouting_js_1.getLocationId)(configFilesystemRoutingRoot.definedAtInfo.filePath));
1017
+ (0, utils_js_1.assert)(configFilesystemRoutingRoot.definedAtInfo.filePathRelativeToUserRootDir);
1018
+ const before = (0, filesystemRouting_js_1.getFilesystemRouteString)((0, filesystemRouting_js_1.getLocationId)(configFilesystemRoutingRoot.definedAtInfo.filePathRelativeToUserRootDir));
1014
1019
  const after = value;
1015
1020
  const filesystemRoutingRootEffect = { before, after };
1016
1021
  return { filesystemRoutingRootEffect, filesystemRoutingRootDefinedAt: configDefinedAt };
@@ -1056,10 +1061,11 @@ function getConfigValues(configValueSources, configDefinitionsRelevant) {
1056
1061
  if (!configDef.cumulative) {
1057
1062
  const configValueSource = sources[0];
1058
1063
  if ('value' in configValueSource) {
1059
- const { value, definedAtInfo } = configValueSource;
1064
+ const { value } = configValueSource;
1065
+ const definedAt = configValueSource.isComputed ? { isComputed: true } : getDefinedAt(configValueSource);
1060
1066
  configValues[configName] = {
1061
1067
  value,
1062
- definedAtInfo
1068
+ definedAt
1063
1069
  };
1064
1070
  }
1065
1071
  }
@@ -1067,7 +1073,10 @@ function getConfigValues(configValueSources, configDefinitionsRelevant) {
1067
1073
  const value = mergeCumulative(configName, sources);
1068
1074
  configValues[configName] = {
1069
1075
  value,
1070
- definedAtInfo: null
1076
+ definedAt: {
1077
+ isCumulative: true,
1078
+ sources: sources.map((source) => getSourceDefinedAt(source))
1079
+ }
1071
1080
  };
1072
1081
  }
1073
1082
  });
@@ -1079,7 +1088,7 @@ function mergeCumulative(configName, configValueSources) {
1079
1088
  let configValueSourcePrevious = null;
1080
1089
  configValueSources.forEach((configValueSource) => {
1081
1090
  (0, utils_js_1.assert)(!configValueSource.isComputed);
1082
- const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, configValueSource, true);
1091
+ const configDefinedAt = getConfigSourceDefinedAtString(configName, configValueSource);
1083
1092
  const configNameColored = picocolors_1.default.cyan(configName);
1084
1093
  // We could, in principle, also support cumulative values to be defined in +${configName}.js but it ins't completely trivial to implement
1085
1094
  (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.)`);
@@ -1087,7 +1096,7 @@ function mergeCumulative(configName, configValueSources) {
1087
1096
  const explanation = `(Because the values of ${configNameColored} are cumulative and therefore merged together.)` as const
1088
1097
  */
1089
1098
  // Make sure configValueSource.value is serializable
1090
- (0, getVirtualFilePageConfigs_js_1.getConfigValueSerialized)(configValueSource.value, configName, configValueSource.definedAtInfo);
1099
+ (0, getVirtualFilePageConfigs_js_1.getConfigValueSerialized)(configValueSource.value, configName, getDefinedAt(configValueSource));
1091
1100
  const assertNoMixing = (isSet) => {
1092
1101
  const vals1 = isSet ? valuesSet : valuesArr;
1093
1102
  const t1 = isSet ? 'a Set' : 'an array';
@@ -1097,7 +1106,8 @@ function mergeCumulative(configName, configValueSources) {
1097
1106
  if (vals2.length === 0)
1098
1107
  return;
1099
1108
  (0, utils_js_1.assert)(configValueSourcePrevious);
1100
- const configPreviousDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, configValueSourcePrevious, false);
1109
+ (0, utils_js_1.assert)(!configValueSourcePrevious.isComputed);
1110
+ const configPreviousDefinedAt = getConfigSourceDefinedAtString(configName, configValueSourcePrevious, undefined, true);
1101
1111
  (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).`);
1102
1112
  };
1103
1113
  const { value } = configValueSource;
@@ -1128,3 +1138,46 @@ function mergeCumulative(configName, configValueSources) {
1128
1138
  }
1129
1139
  (0, utils_js_1.assert)(false);
1130
1140
  }
1141
+ // TODO: rename
1142
+ // TODO: refactor
1143
+ function getConfigSourceDefinedAtString(configName, { definedAtInfo }, isEffect = undefined, sentenceBegin = true) {
1144
+ return (0, utils_js_2.getConfigDefinedAtString)(configName, {
1145
+ definedAt: {
1146
+ isEffect,
1147
+ source: {
1148
+ filePathToShowToUser: getFilePathToShowToUser2(definedAtInfo),
1149
+ fileExportPath: definedAtInfo.fileExportPath
1150
+ }
1151
+ }
1152
+ }, sentenceBegin);
1153
+ }
1154
+ // TODO: rename
1155
+ function getFilePathToShowToUser2(definedAtInfo) {
1156
+ return definedAtInfo.filePathRelativeToUserRootDir ?? definedAtInfo.importPathAbsolute;
1157
+ /*
1158
+ if (definedAtInfo.filePathRelativeToUserRootDir !== null) {
1159
+ return definedAtInfo.filePathRelativeToUserRootDir
1160
+ }
1161
+ if (definedAtInfo.importPathAbsolute !== null) {
1162
+ return definedAtInfo.importPathAbsolute
1163
+ } else {
1164
+ const filePathToShowToUser = definedAtInfo.filePathAbsolute
1165
+ // TypeScript failes to infer that definedAtInfo.filePathAbsolute cannot be null
1166
+ assert(filePathToShowToUser)
1167
+ return filePathToShowToUser
1168
+ }
1169
+ */
1170
+ }
1171
+ // TODO: rename
1172
+ function getSourceDefinedAt(source) {
1173
+ (0, utils_js_1.assert)(!source.isComputed);
1174
+ return {
1175
+ filePathToShowToUser: getFilePathToShowToUser2(source.definedAtInfo),
1176
+ fileExportPath: source.definedAtInfo.fileExportPath
1177
+ };
1178
+ }
1179
+ function getDefinedAt(configValueSource) {
1180
+ return {
1181
+ source: getSourceDefinedAt(configValueSource)
1182
+ };
1183
+ }
@@ -58,30 +58,31 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
58
58
  return code;
59
59
  }
60
60
  function serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements) {
61
+ (0, utils_js_1.assert)(!configValueSource.valueIsFilePath);
61
62
  (0, utils_js_1.assert)(whitespace.replaceAll(' ', '').length === 0);
62
63
  const { valueIsImportedAtRuntime, definedAtInfo } = configValueSource;
63
64
  (0, utils_js_1.assert)(valueIsImportedAtRuntime);
64
- const { filePath, fileExportPath } = definedAtInfo;
65
- (0, utils_js_1.assertPosixPath)(filePath);
66
- const fileName = path_1.default.posix.basename(filePath);
65
+ const { filePathRelativeToUserRootDir, importPathAbsolute, exportName } = definedAtInfo;
66
+ const importPath = filePathRelativeToUserRootDir ?? importPathAbsolute;
67
+ (0, utils_js_1.assertPosixPath)(importPath);
68
+ const fileName = path_1.default.posix.basename(importPath);
67
69
  const isValueFile = fileName.startsWith('+');
68
- const fileExportName = fileExportPath[0];
69
- (0, utils_js_1.assert)(!configValueSource.valueIsFilePath);
70
- (0, utils_js_1.assert)(fileExportName);
71
- const { importName, importStatement } = (0, generateEagerImport_js_1.generateEagerImport)(filePath, varCounterContainer.varCounter++, isValueFile ? undefined : fileExportName);
70
+ if (isValueFile)
71
+ (0, utils_js_1.assert)(exportName === undefined);
72
+ const { importName, importStatement } = (0, generateEagerImport_js_1.generateEagerImport)(importPath, varCounterContainer.varCounter++, exportName);
72
73
  importStatements.push(importStatement);
73
74
  const lines = [];
74
75
  lines.push(` {`);
75
76
  lines.push(` configName: '${configName}',`);
76
- lines.push(` importPath: '${filePath}',`);
77
+ lines.push(` importPath: '${importPath}',`);
77
78
  lines.push(` isValueFile: ${JSON.stringify(isValueFile)},`);
78
79
  if (isValueFile) {
79
80
  lines.push(` importFileExports: ${importName},`);
80
81
  }
81
82
  else {
82
83
  lines.push(` importFileExportValue: ${importName},`);
83
- (0, utils_js_1.assert)(fileExportName);
84
- lines.push(` exportName: ${JSON.stringify(fileExportName)},`);
84
+ (0, utils_js_1.assert)(exportName);
85
+ lines.push(` exportName: ${JSON.stringify(exportName)},`);
85
86
  }
86
87
  lines.push(` },`);
87
88
  return lines;
@@ -13,6 +13,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
13
13
  const getVikeConfig_js_1 = require("./getVikeConfig.js");
14
14
  const isConfigEnvMatch_js_1 = require("./isConfigEnvMatch.js");
15
15
  const getVirtualFilePageConfigValuesAll_js_1 = require("./getVirtualFilePageConfigValuesAll.js");
16
+ const utils_js_2 = require("../../../../../shared/page-configs/utils.js");
16
17
  async function getVirtualFilePageConfigs(userRootDir, isForClientSide, isDev, id, configVike, isClientRouting) {
17
18
  const { pageConfigs, pageConfigGlobal } = await (0, getVikeConfig_js_1.getVikeConfig)(userRootDir, isDev, configVike.extensions, true);
18
19
  return getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
@@ -39,9 +40,9 @@ function getContent(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, i
39
40
  (0, utils_js_1.assert)(configEnv, configName);
40
41
  if (!(0, isConfigEnvMatch_js_1.isConfigEnvMatch)(configEnv, isForClientSide, isClientRouting))
41
42
  return;
42
- const { value, definedAtInfo } = configValue;
43
- const valueSerialized = getConfigValueSerialized(value, configName, definedAtInfo);
44
- serializeConfigValue(lines, configName, { definedAtInfo, valueSerialized });
43
+ const { value, definedAt } = configValue;
44
+ const valueSerialized = getConfigValueSerialized(value, configName, definedAt);
45
+ serializeConfigValue(lines, configName, { definedAt, valueSerialized });
45
46
  }
46
47
  });
47
48
  lines.push(` },`);
@@ -98,13 +99,13 @@ function serializeConfigValue(lines, configName, configValueSerialized) {
98
99
  lines.push(`${whitespace}['${configName}']: {`);
99
100
  whitespace += ' ';
100
101
  Object.entries(configValueSerialized).forEach(([key, val]) => {
101
- const valSerialized = key === 'definedAtInfo' ? JSON.stringify(val) : val;
102
+ const valSerialized = key === 'definedAt' ? JSON.stringify(val) : val;
102
103
  lines.push(`${whitespace} ${key}: ${valSerialized},`);
103
104
  });
104
105
  whitespace = whitespace.slice(2);
105
106
  lines.push(`${whitespace}},`);
106
107
  }
107
- function getConfigValueSerialized(value, configName, definedAtInfo) {
108
+ function getConfigValueSerialized(value, configName, definedAt) {
108
109
  let configValueSerialized;
109
110
  const valueName = `config${(0, utils_js_1.getPropAccessNotation)(configName)}`;
110
111
  try {
@@ -112,15 +113,14 @@ function getConfigValueSerialized(value, configName, definedAtInfo) {
112
113
  }
113
114
  catch (err) {
114
115
  (0, utils_js_1.assert)((0, utils_js_1.hasProp)(err, 'messageCore', 'string'));
115
- // definedAtInfo is null when config value is:
116
+ const configValueFilePathToShowToUser = (0, utils_js_2.getConfigValueFilePathToShowToUser)({ definedAt });
117
+ // definedAt is null when config value is:
116
118
  // - computed => all computed values defined by Vike can are serializable
117
119
  // - cumulative => the values are already ensured to be serializable
118
- (0, utils_js_1.assert)(definedAtInfo);
119
- const configDefinedByFile = definedAtInfo.filePath;
120
- (0, utils_js_1.assert)(configDefinedByFile);
120
+ (0, utils_js_1.assert)(configValueFilePathToShowToUser);
121
121
  (0, utils_js_1.assertUsage)(false, [
122
- `The value of the config ${picocolors_1.default.cyan(configName)} cannot be defined inside the file ${configDefinedByFile}:`,
123
- `its value must be defined in an another file and then imported by ${configDefinedByFile}. (Because the value isn't serializable: ${err.messageCore}.)`,
122
+ `The value of the config ${picocolors_1.default.cyan(configName)} cannot be defined inside the file ${configValueFilePathToShowToUser}:`,
123
+ `its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because the value isn't serializable: ${err.messageCore}.)`,
124
124
  `Only serializable config values can be defined inside +config.h.js files, see https://vike.dev/header-file.`
125
125
  ].join(' '));
126
126
  }
@@ -115,12 +115,13 @@ async function collectDoNoPrerenderList(renderContext, doNotPrerenderList, concu
115
115
  const configName = 'prerender';
116
116
  const configValue = (0, utils_js_2.getConfigValue)(pageConfig, configName, 'boolean');
117
117
  if (configValue?.value === false) {
118
- const definedAtInfo = (0, utils_js_2.getConfigDefinedAtInfo)(pageConfig, configName);
118
+ const filePath = (0, utils_js_2.getConfigValueFilePathToShowToUser)(configValue);
119
+ (0, utils_js_1.assert)(filePath);
119
120
  doNotPrerenderList.push({
120
121
  pageId: pageConfig.pageId,
121
122
  setByConfigName: 'prerender',
122
123
  setByConfigValue: false,
123
- setByConfigFile: definedAtInfo.filePath
124
+ setByConfigFile: filePath
124
125
  });
125
126
  }
126
127
  });
@@ -176,8 +177,7 @@ async function callOnBeforePrerenderStartHooks(prerenderContext, renderContext,
176
177
  if (!configValue)
177
178
  return;
178
179
  const hookFn = configValue.value;
179
- const definedAtInfo = (0, utils_js_2.getConfigDefinedAtInfo)(pageConfigLoaded, hookName);
180
- const hookFilePath = definedAtInfo.filePath;
180
+ const hookFilePath = (0, utils_js_2.getHookFilePathToShowToUser)(configValue);
181
181
  (0, utils_js_1.assert)(hookFilePath);
182
182
  (0, getHook_js_1.assertHookFn)(hookFn, { hookName, hookFilePath });
183
183
  onBeforePrerenderStartHooks.push({
@@ -310,11 +310,12 @@ async function callOnPrerenderStartHook(prerenderContext, renderContext) {
310
310
  // V1 design
311
311
  if (renderContext.pageConfigs.length > 0) {
312
312
  const { pageConfigGlobal } = renderContext;
313
- if (pageConfigGlobal.configValues.onPrerenderStart?.value) {
314
- const { value: hookFn, definedAtInfo } = pageConfigGlobal.configValues.onPrerenderStart;
313
+ const configValue = pageConfigGlobal.configValues.onPrerenderStart;
314
+ if (configValue?.value) {
315
+ const { value: hookFn } = configValue;
315
316
  // config.onPrerenderStart isn't a computed nor a cumulative config => definedAtInfo should always be defined
316
- (0, utils_js_1.assert)(definedAtInfo);
317
- const hookFilePath = definedAtInfo.filePath;
317
+ const hookFilePath = (0, utils_js_2.getHookFilePathToShowToUser)(configValue);
318
+ (0, utils_js_1.assert)(hookFilePath);
318
319
  onPrerenderStartHook = {
319
320
  hookFn,
320
321
  hookName: 'onPrerenderStart',
@@ -21,6 +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 utils_js_2 = require("../../../shared/page-configs/utils.js");
24
25
  async function renderPageAlreadyRouted(pageContext) {
25
26
  // pageContext._pageId can either be the:
26
27
  // - ID of the page matching the routing, or the
@@ -172,9 +173,9 @@ function assertNonMixedDesign(pageFilesAll, pageConfigs) {
172
173
  const indent = '- ';
173
174
  const v1Files = (0, utils_js_1.unique)(pageConfigs
174
175
  .map((p) => Object.values(p.configValues)
175
- .map(({ definedAtInfo }) => definedAtInfo)
176
+ .map(utils_js_2.getConfigValueFilePathToShowToUser)
176
177
  .filter(utils_js_1.isNotNullish)
177
- .map((definedAtInfo) => indent + definedAtInfo.filePath))
178
+ .map((filePathToShowToUser) => indent + filePathToShowToUser))
178
179
  .flat(2));
179
180
  (0, utils_js_1.assertUsage)(false, [
180
181
  'Mixing the new V1 design with the old V0.4 design is forbidden.',
@@ -2,17 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getClientEntryFilePath = void 0;
4
4
  const utils_js_1 = require("../../shared/page-configs/utils.js");
5
- const utils_js_2 = require("./utils.js");
6
5
  function getClientEntryFilePath(pageConfig) {
7
6
  const configName = 'client';
8
7
  const configValue = (0, utils_js_1.getConfigValue)(pageConfig, configName, 'string');
9
8
  if (!configValue)
10
9
  return null;
11
- const definedAtInfo = (0, utils_js_1.getConfigDefinedAtInfo)(pageConfig, configName);
12
- const { value } = configValue;
13
- // Users should be able to suppress client entry by setting its value to null
14
- (0, utils_js_2.assert)(value !== null);
15
- const clientEntryFilePath = definedAtInfo.filePath;
16
- return clientEntryFilePath;
10
+ return configValue.value;
17
11
  }
18
12
  exports.getClientEntryFilePath = getClientEntryFilePath;
@@ -33,11 +33,8 @@ function getExports(pageFiles, pageConfig) {
33
33
  // V1 design
34
34
  if (pageConfig) {
35
35
  Object.entries(pageConfig.configValues).forEach(([configName, configValue]) => {
36
- const { value, definedAtInfo } = configValue;
37
- let filePath = null;
38
- if (definedAtInfo) {
39
- filePath = definedAtInfo.filePath;
40
- }
36
+ const { value } = configValue;
37
+ const filePath = (0, utils_js_2.getConfigValueFilePathToShowToUser)(configValue);
41
38
  const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, configValue, true);
42
39
  config[configName] = config[configName] ?? value;
43
40
  configEntries[configName] = configEntries[configName] ?? [];
@@ -4,6 +4,7 @@ exports.parsePageConfigsSerialized = void 0;
4
4
  const parse_1 = require("@brillout/json-serializer/parse");
5
5
  const parseConfigValuesImported_js_1 = require("../page-configs/parseConfigValuesImported.js");
6
6
  const utils_js_1 = require("../utils.js");
7
+ const utils_js_2 = require("../page-configs/utils.js");
7
8
  function parsePageConfigsSerialized(pageConfigsSerialized, pageConfigGlobalSerialized) {
8
9
  const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
9
10
  const configValues = {};
@@ -11,12 +12,12 @@ function parsePageConfigsSerialized(pageConfigsSerialized, pageConfigGlobalSeria
11
12
  const { configValuesSerialized } = pageConfigSerialized;
12
13
  Object.entries(configValuesSerialized).forEach(([configName, configValueSeriliazed]) => {
13
14
  {
14
- const { valueSerialized, definedAtInfo } = configValueSeriliazed;
15
+ const { valueSerialized, definedAt } = configValueSeriliazed;
15
16
  (0, utils_js_1.assert)(valueSerialized);
16
17
  (0, utils_js_1.assert)(!configValues[configName]);
17
18
  configValues[configName] = {
18
19
  value: (0, parse_1.parse)(valueSerialized),
19
- definedAtInfo
20
+ definedAt
20
21
  };
21
22
  }
22
23
  });
@@ -45,12 +46,14 @@ function parsePageConfigsSerialized(pageConfigsSerialized, pageConfigGlobalSeria
45
46
  }
46
47
  exports.parsePageConfigsSerialized = parsePageConfigsSerialized;
47
48
  function assertRouteConfigValue(configValues) {
48
- if (!configValues.route)
49
+ const configName = 'route';
50
+ const configValue = configValues[configName];
51
+ if (!configValue)
49
52
  return;
50
- const { value, definedAtInfo } = configValues.route;
53
+ const { value } = configValue;
51
54
  const configValueType = typeof value;
52
- (0, utils_js_1.assert)(definedAtInfo);
53
- (0, utils_js_1.assertUsage)(configValueType === 'string' || (0, utils_js_1.isCallable)(value), `${definedAtInfo.filePath} has an invalid type '${configValueType}': it should be a string or a function instead, see https://vike.dev/route`);
55
+ const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, configValue, true);
56
+ (0, utils_js_1.assertUsage)(configValueType === 'string' || (0, utils_js_1.isCallable)(value), `${configDefinedAt} has an invalid type '${configValueType}': it should be a string or a function instead, see https://vike.dev/route`);
54
57
  /* We don't use assertRouteString() in order to avoid unnecessarily bloating the client-side bundle when using Server Routing:
55
58
  * - When using Server Routing, this file is loaded => loading assertRouteString() would bloat the client bundle.
56
59
  * - assertRouteString() is already called on the server-side