vike 0.4.143-commit-f03b42d → 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 (49) hide show
  1. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +30 -27
  2. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
  3. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +119 -64
  4. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -10
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +11 -11
  6. package/dist/cjs/node/prerender/runPrerender.js +9 -8
  7. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  8. package/dist/cjs/node/runtime/renderPage/log404/index.js +10 -5
  9. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
  10. package/dist/cjs/node/shared/getClientEntryFilePath.js +1 -7
  11. package/dist/cjs/shared/getPageFiles/getExports.js +2 -5
  12. package/dist/cjs/shared/getPageFiles/parsePageConfigsSerialized.js +9 -6
  13. package/dist/cjs/shared/hooks/getHook.js +3 -1
  14. package/dist/cjs/shared/page-configs/getExportPath.js +2 -2
  15. package/dist/cjs/shared/page-configs/parseConfigValuesImported.js +8 -5
  16. package/dist/cjs/shared/page-configs/utils.js +66 -42
  17. package/dist/cjs/shared/route/loadPageRoutes.js +5 -6
  18. package/dist/cjs/utils/projectInfo.js +1 -1
  19. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +30 -27
  20. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +11 -2
  21. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
  22. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +3 -2
  23. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +119 -64
  24. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -10
  25. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +2 -2
  26. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +11 -11
  27. package/dist/esm/node/prerender/runPrerender.js +10 -9
  28. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  29. package/dist/esm/node/runtime/renderPage/log404/index.js +10 -5
  30. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
  31. package/dist/esm/node/shared/getClientEntryFilePath.js +2 -8
  32. package/dist/esm/shared/addUrlComputedProps.d.ts +4 -2
  33. package/dist/esm/shared/getPageFiles/getExports.d.ts +1 -2
  34. package/dist/esm/shared/getPageFiles/getExports.js +3 -6
  35. package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.js +9 -6
  36. package/dist/esm/shared/hooks/getHook.js +3 -1
  37. package/dist/esm/shared/page-configs/Config.d.ts +1 -3
  38. package/dist/esm/shared/page-configs/PageConfig.d.ts +35 -10
  39. package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
  40. package/dist/esm/shared/page-configs/getExportPath.js +2 -2
  41. package/dist/esm/shared/page-configs/parseConfigValuesImported.js +8 -5
  42. package/dist/esm/shared/page-configs/utils.d.ts +19 -13
  43. package/dist/esm/shared/page-configs/utils.js +65 -41
  44. package/dist/esm/shared/route/loadPageRoutes.js +6 -7
  45. package/dist/esm/shared/types.d.ts +1 -0
  46. package/dist/esm/types/index.d.ts +1 -0
  47. package/dist/esm/utils/projectInfo.d.ts +1 -1
  48. package/dist/esm/utils/projectInfo.js +1 -1
  49. 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
  });
@@ -2,6 +2,12 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getFilePathToShowToUser = void 0;
4
4
  const utils_js_1 = require("../../../utils.js");
5
+ /*
6
+ const f: FilePath = 1 as any
7
+ if (f.filePathRelativeToUserRootDir === null) {
8
+ f.importPathAbsolute
9
+ }
10
+ //*/
5
11
  function getFilePathToShowToUser(filePath) {
6
12
  const filePathToShowToUser = filePath.filePathRelativeToUserRootDir ?? filePath.filePathAbsolute;
7
13
  (0, utils_js_1.assert)(filePathToShowToUser);
@@ -89,7 +89,8 @@ async function loadInterfaceFiles(userRootDir, isDev, extensions) {
89
89
  await Promise.all(configFiles.map(async ({ filePathAbsolute, filePathRelativeToUserRootDir }) => {
90
90
  const configFilePath = {
91
91
  filePathAbsolute: filePathAbsolute,
92
- filePathRelativeToUserRootDir: filePathRelativeToUserRootDir
92
+ filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
93
+ importPathAbsolute: null
93
94
  };
94
95
  const { configFile, extendsConfigs } = await loadConfigFile(configFilePath, userRootDir, []);
95
96
  const interfaceFile = getInterfaceFileFromConfigFile(configFile, false);
@@ -108,7 +109,8 @@ async function loadInterfaceFiles(userRootDir, isDev, extensions) {
108
109
  const interfaceFile = {
109
110
  filePath: {
110
111
  filePathRelativeToUserRootDir,
111
- filePathAbsolute
112
+ filePathAbsolute,
113
+ importPathAbsolute: null
112
114
  },
113
115
  configMap: {
114
116
  [configName]: {}
@@ -343,7 +345,9 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
343
345
  if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
344
346
  return;
345
347
  (0, utils_js_1.assert)(!configValueSource.isComputed);
346
- (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 });
347
351
  globalVikeConfig[configName] = configValueSource.value;
348
352
  }
349
353
  });
@@ -426,48 +430,48 @@ function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden,
426
430
  interfaceFilesOverriden.forEach((interfaceFileLoser) => {
427
431
  const configValueSourceWinner = getConfigValueSource(configName, interfaceFileWinner, configDef, userRootDir);
428
432
  const configValueSourceLoser = getConfigValueSource(configName, interfaceFileLoser, configDef, userRootDir);
429
- (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 });
430
436
  });
431
437
  }
432
438
  function isInterfaceFileUserLand(interfaceFile) {
433
439
  return (interfaceFile.isConfigFile && !interfaceFile.isConfigExtend) || interfaceFile.isValueFile;
434
440
  }
435
441
  function getConfigValueSource(configName, interfaceFile, configDef, userRootDir) {
436
- // TODO: rethink file paths of ConfigElement
437
- const filePathToShowToUser = interfaceFile.filePath.filePathRelativeToUserRootDir ?? interfaceFile.filePath.filePathAbsolute;
438
442
  const conf = interfaceFile.configMap[configName];
439
443
  (0, utils_js_1.assert)(conf);
440
444
  const configEnv = configDef.env;
441
- const definedAtInfoConfigFile = {
442
- filePath: filePathToShowToUser,
445
+ const definedAtConfigFile = {
446
+ ...interfaceFile.filePath,
443
447
  fileExportPath: ['default', configName]
444
448
  };
445
449
  if (configDef._valueIsFilePath) {
446
- let filePath;
450
+ let definedAtInfo;
451
+ let valueFilePath;
447
452
  if (interfaceFile.isConfigFile) {
448
453
  const { configValue } = conf;
449
454
  const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
450
- const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, { definedAtInfo: definedAtInfoConfigFile }, true);
455
+ const configDefinedAt = getConfigSourceDefinedAtString(configName, { definedAtInfo: definedAtConfigFile });
451
456
  (0, utils_js_1.assertUsage)(import_, `${configDefinedAt} should be an import`);
452
- filePath = import_.filePathToShowToUser;
457
+ valueFilePath = import_.filePathRelativeToUserRootDir ?? import_.importPathAbsolute;
458
+ definedAtInfo = import_;
453
459
  }
454
460
  else {
455
461
  (0, utils_js_1.assert)(interfaceFile.isValueFile);
456
- filePath =
457
- interfaceFile.filePath.filePathRelativeToUserRootDir ??
458
- // Experimental: is this needed? Would it work?
459
- interfaceFile.filePath.filePathAbsolute;
462
+ valueFilePath = interfaceFile.filePath.filePathRelativeToUserRootDir;
463
+ definedAtInfo = {
464
+ ...interfaceFile.filePath,
465
+ fileExportPath: []
466
+ };
460
467
  }
461
468
  const configValueSource = {
462
- value: filePath,
469
+ value: valueFilePath,
463
470
  valueIsFilePath: true,
464
471
  configEnv,
465
472
  valueIsImportedAtRuntime: true,
466
473
  isComputed: false,
467
- definedAtInfo: {
468
- filePath,
469
- fileExportPath: []
470
- }
474
+ definedAtInfo
471
475
  };
472
476
  return configValueSource;
473
477
  }
@@ -476,15 +480,11 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
476
480
  const { configValue } = conf;
477
481
  const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
478
482
  if (import_) {
479
- const { filePathToShowToUser, fileExportName: exportName } = import_;
480
483
  const configValueSource = {
481
484
  configEnv,
482
485
  valueIsImportedAtRuntime: true,
483
486
  isComputed: false,
484
- definedAtInfo: {
485
- filePath: filePathToShowToUser,
486
- fileExportPath: [exportName]
487
- }
487
+ definedAtInfo: import_
488
488
  };
489
489
  return configValueSource;
490
490
  }
@@ -494,23 +494,21 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
494
494
  configEnv,
495
495
  valueIsImportedAtRuntime: false,
496
496
  isComputed: false,
497
- definedAtInfo: definedAtInfoConfigFile
497
+ definedAtInfo: definedAtConfigFile
498
498
  };
499
499
  return configValueSource;
500
500
  }
501
501
  }
502
502
  else if (interfaceFile.isValueFile) {
503
503
  // TODO: rethink file paths of ConfigElement
504
- const importPath = interfaceFile.filePath.filePathRelativeToUserRootDir ?? interfaceFile.filePath.filePathAbsolute;
505
- const exportName = configName === interfaceFile.configName ? 'default' : configName;
506
504
  const valueAlreadyLoaded = 'configValue' in conf;
507
505
  const configValueSource = {
508
506
  configEnv,
509
507
  valueIsImportedAtRuntime: !valueAlreadyLoaded,
510
508
  isComputed: false,
511
509
  definedAtInfo: {
512
- filePath: importPath,
513
- fileExportPath: [exportName]
510
+ ...interfaceFile.filePath,
511
+ fileExportPath: configName === interfaceFile.configName ? [] : [configName]
514
512
  }
515
513
  };
516
514
  if (valueAlreadyLoaded) {
@@ -559,7 +557,8 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
559
557
  return null;
560
558
  const { importPath, exportName } = importData;
561
559
  const filePathAbsolute = resolveImportPath(importData, importerFilePath);
562
- let filePathToShowToUser;
560
+ assertFileEnv(filePathAbsolute ?? importPath, configEnv, configName);
561
+ const fileExportPath = exportName === 'default' || exportName === configName ? [] : [exportName];
563
562
  if (importPath.startsWith('.')) {
564
563
  // We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
565
564
  // ```
@@ -567,22 +566,26 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
567
566
  // ```
568
567
  assertImportPath(filePathAbsolute, importData, importerFilePath);
569
568
  const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, importerFilePath, userRootDir);
570
- filePathToShowToUser = filePathRelativeToUserRootDir;
569
+ return {
570
+ exportName,
571
+ fileExportPath,
572
+ filePathAbsolute,
573
+ filePathRelativeToUserRootDir,
574
+ importPathAbsolute: null
575
+ };
571
576
  }
572
577
  else {
573
578
  // importPath can be:
574
579
  // - an npm package import
575
580
  // - a path alias
576
- filePathToShowToUser = importPath;
577
- }
578
- {
579
- const filePathForEnvCheck = filePathAbsolute ?? importPath;
580
- assertFileEnv(filePathForEnvCheck, configEnv, configName);
581
+ return {
582
+ exportName,
583
+ fileExportPath,
584
+ filePathAbsolute,
585
+ filePathRelativeToUserRootDir: null,
586
+ importPathAbsolute: importPath
587
+ };
581
588
  }
582
- return {
583
- filePathToShowToUser,
584
- fileExportName: exportName
585
- };
586
589
  }
587
590
  function resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, configFilePath, userRootDir) {
588
591
  (0, utils_js_1.assertPosixPath)(userRootDir);
@@ -675,24 +678,26 @@ function applyEffects(pageConfig, configDefinitionsRelevant) {
675
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)}).`,
676
679
  'Reach out to a maintainer if you want to use this in production.'
677
680
  ].join(' '), { onlyOnce: true });
678
- const configValue = pageConfig.configValueSources[configName]?.[0];
679
- if (!configValue)
681
+ const source = pageConfig.configValueSources[configName]?.[0];
682
+ if (!source)
680
683
  return;
684
+ (0, utils_js_1.assert)(!source.isComputed);
681
685
  const configModFromEffect = configDef.effect({
682
- configValue: configValue.value,
683
- configDefinedAt: (0, utils_js_2.getConfigDefinedAtString)(configName, configValue, true)
686
+ configValue: source.value,
687
+ configDefinedAt: getConfigSourceDefinedAtString(configName, source)
684
688
  });
685
689
  if (!configModFromEffect)
686
690
  return;
687
- (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
688
- 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);
689
693
  });
690
694
  }
691
695
  function applyEffect(configModFromEffect, configValueEffectSource, configValueSources) {
692
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.`;
693
697
  (0, utils_js_1.objectEntries)(configModFromEffect).forEach(([configName, configValue]) => {
694
698
  if (configName === 'meta') {
695
- 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));
696
701
  (0, utils_js_1.objectEntries)(configValue).forEach(([configTargetName, configTargetDef]) => {
697
702
  {
698
703
  const keys = Object.keys(configTargetDef);
@@ -802,7 +807,7 @@ function assertNoUnexpectedPlusSign(filePath, fileName) {
802
807
  (0, utils_js_1.assertUsage)(!fileName.slice(1).includes('+'), `Character '+' is only allowed at the beginning of filenames: make sure ${filePath} doesn't contain any '+' in its filename other than its first letter`);
803
808
  }
804
809
  async function loadConfigFile(configFilePath, userRootDir, visited) {
805
- const { filePathAbsolute, filePathRelativeToUserRootDir } = configFilePath;
810
+ const { filePathAbsolute } = configFilePath;
806
811
  assertNoInfiniteLoop(visited, filePathAbsolute);
807
812
  const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(configFilePath, false, userRootDir);
808
813
  const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
@@ -811,10 +816,7 @@ async function loadConfigFile(configFilePath, userRootDir, visited) {
811
816
  ]);
812
817
  const configFile = {
813
818
  fileExports,
814
- filePath: {
815
- filePathRelativeToUserRootDir,
816
- filePathAbsolute
817
- },
819
+ filePath: configFilePath,
818
820
  extendsFilePaths
819
821
  };
820
822
  return { configFile, extendsConfigs };
@@ -837,11 +839,14 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
837
839
  const filePathAbsolute = resolveImportPath(importData, configFilePath);
838
840
  assertImportPath(filePathAbsolute, importData, configFilePath);
839
841
  assertExtendsImportPath(importPath, filePathAbsolute, configFilePath);
842
+ // - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
843
+ // - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsolute for added clarity
844
+ const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsolute, userRootDir);
840
845
  extendsConfigFiles.push({
841
846
  filePathAbsolute,
842
- // - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
843
- // - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsolute for added clarity
844
- filePathRelativeToUserRootDir: determineFilePathRelativeToUserDir(filePathAbsolute, userRootDir)
847
+ // TODO: fix type cast
848
+ filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
849
+ importPathAbsolute: importPath
845
850
  });
846
851
  });
847
852
  const extendsConfigs = [];
@@ -1004,11 +1009,13 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
1004
1009
  // Eagerly loaded since it's config-only
1005
1010
  (0, utils_js_1.assert)('value' in configFilesystemRoutingRoot);
1006
1011
  const { value } = configFilesystemRoutingRoot;
1007
- const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, configFilesystemRoutingRoot, false);
1012
+ (0, utils_js_1.assert)(!configFilesystemRoutingRoot.isComputed);
1013
+ const configDefinedAt = getConfigSourceDefinedAtString(configName, configFilesystemRoutingRoot);
1008
1014
  (0, utils_js_1.assertUsage)(typeof value === 'string', `${configDefinedAt} should be a string`);
1009
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('/')}`);
1010
1016
  (0, utils_js_1.assert)(!configFilesystemRoutingRoot.isComputed);
1011
- 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));
1012
1019
  const after = value;
1013
1020
  const filesystemRoutingRootEffect = { before, after };
1014
1021
  return { filesystemRoutingRootEffect, filesystemRoutingRootDefinedAt: configDefinedAt };
@@ -1054,10 +1061,11 @@ function getConfigValues(configValueSources, configDefinitionsRelevant) {
1054
1061
  if (!configDef.cumulative) {
1055
1062
  const configValueSource = sources[0];
1056
1063
  if ('value' in configValueSource) {
1057
- const { value, definedAtInfo } = configValueSource;
1064
+ const { value } = configValueSource;
1065
+ const definedAt = configValueSource.isComputed ? { isComputed: true } : getDefinedAt(configValueSource);
1058
1066
  configValues[configName] = {
1059
1067
  value,
1060
- definedAtInfo
1068
+ definedAt
1061
1069
  };
1062
1070
  }
1063
1071
  }
@@ -1065,7 +1073,10 @@ function getConfigValues(configValueSources, configDefinitionsRelevant) {
1065
1073
  const value = mergeCumulative(configName, sources);
1066
1074
  configValues[configName] = {
1067
1075
  value,
1068
- definedAtInfo: null
1076
+ definedAt: {
1077
+ isCumulative: true,
1078
+ sources: sources.map((source) => getSourceDefinedAt(source))
1079
+ }
1069
1080
  };
1070
1081
  }
1071
1082
  });
@@ -1077,7 +1088,7 @@ function mergeCumulative(configName, configValueSources) {
1077
1088
  let configValueSourcePrevious = null;
1078
1089
  configValueSources.forEach((configValueSource) => {
1079
1090
  (0, utils_js_1.assert)(!configValueSource.isComputed);
1080
- const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, configValueSource, true);
1091
+ const configDefinedAt = getConfigSourceDefinedAtString(configName, configValueSource);
1081
1092
  const configNameColored = picocolors_1.default.cyan(configName);
1082
1093
  // We could, in principle, also support cumulative values to be defined in +${configName}.js but it ins't completely trivial to implement
1083
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.)`);
@@ -1085,7 +1096,7 @@ function mergeCumulative(configName, configValueSources) {
1085
1096
  const explanation = `(Because the values of ${configNameColored} are cumulative and therefore merged together.)` as const
1086
1097
  */
1087
1098
  // Make sure configValueSource.value is serializable
1088
- (0, getVirtualFilePageConfigs_js_1.getConfigValueSerialized)(configValueSource.value, configName, configValueSource.definedAtInfo);
1099
+ (0, getVirtualFilePageConfigs_js_1.getConfigValueSerialized)(configValueSource.value, configName, getDefinedAt(configValueSource));
1089
1100
  const assertNoMixing = (isSet) => {
1090
1101
  const vals1 = isSet ? valuesSet : valuesArr;
1091
1102
  const t1 = isSet ? 'a Set' : 'an array';
@@ -1095,7 +1106,8 @@ function mergeCumulative(configName, configValueSources) {
1095
1106
  if (vals2.length === 0)
1096
1107
  return;
1097
1108
  (0, utils_js_1.assert)(configValueSourcePrevious);
1098
- 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);
1099
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).`);
1100
1112
  };
1101
1113
  const { value } = configValueSource;
@@ -1126,3 +1138,46 @@ function mergeCumulative(configName, configValueSources) {
1126
1138
  }
1127
1139
  (0, utils_js_1.assert)(false);
1128
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',
@@ -111,7 +111,7 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
111
111
  if (!isHtmlOnly) {
112
112
  // Don't allow the user to manipulate with injectFilter(): injecting <script type="application/json"> before the stream can break the app when:
113
113
  // - using https://vike.dev/stream#initial-data-after-stream-end
114
- // - `pageContext` is modified during the stream, e.g. /examples/vue-pinia which uses https://vuejs.org/api/composition-api-lifecycle.html#onserverprefetch
114
+ // - `pageContext` is modified during the stream, e.g. https://github.com/brillout/vike-with-pinia which uses https://vuejs.org/api/composition-api-lifecycle.html#onserverprefetch
115
115
  // The <script> tags are handled separately by vike down below.
116
116
  htmlTags.push({
117
117
  // Needs to be called after `resolvePageContextPromise()`