vike 0.4.144 → 0.4.145-commit-2520555

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 (198) hide show
  1. package/dist/cjs/__internal/index.js +6 -2
  2. package/dist/cjs/node/plugin/plugins/buildConfig.js +3 -3
  3. package/dist/cjs/node/plugin/plugins/commonConfig.js +0 -3
  4. package/dist/cjs/node/plugin/plugins/config/index.js +3 -3
  5. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +8 -8
  6. package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -0
  7. package/dist/cjs/node/plugin/plugins/envVars.js +34 -20
  8. package/dist/cjs/node/plugin/plugins/importBuild/index.js +3 -3
  9. package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
  10. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +3 -3
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -4
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +249 -228
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +8 -6
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +36 -14
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +18 -0
  18. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +15 -17
  19. package/dist/cjs/node/plugin/plugins/previewConfig.js +11 -2
  20. package/dist/cjs/node/prerender/runPrerender.js +34 -26
  21. package/dist/cjs/node/prerender/utils.js +1 -1
  22. package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +20 -6
  23. package/dist/cjs/node/runtime/renderPage/debugPageFiles.js +5 -5
  24. package/dist/cjs/node/runtime/renderPage/log404/index.js +28 -17
  25. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -3
  26. package/dist/cjs/node/runtime/renderPage.js +3 -3
  27. package/dist/cjs/node/runtime/utils.js +1 -1
  28. package/dist/cjs/node/shared/getClientEntryFilePath.js +2 -2
  29. package/dist/cjs/node/shared/getConfigVike.js +4 -1
  30. package/dist/cjs/shared/addUrlComputedProps.js +24 -12
  31. package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +4 -6
  32. package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
  33. package/dist/cjs/shared/hooks/getHook.js +1 -1
  34. package/dist/cjs/shared/page-configs/getExportPath.js +3 -3
  35. package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +43 -0
  36. package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +44 -0
  37. package/dist/cjs/shared/page-configs/helpers.js +33 -0
  38. package/dist/cjs/shared/page-configs/loadConfigValues.js +2 -2
  39. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +14 -13
  40. package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -2
  41. package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +9 -10
  42. package/dist/cjs/shared/route/abort.js +1 -1
  43. package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +41 -15
  44. package/dist/cjs/shared/route/index.js +22 -32
  45. package/dist/cjs/shared/route/loadPageRoutes.js +11 -10
  46. package/dist/cjs/shared/route/noRouteMatch.js +4 -0
  47. package/dist/cjs/shared/route/resolveRouteFunction.js +1 -1
  48. package/dist/cjs/shared/utils.js +1 -1
  49. package/dist/cjs/utils/getFilePathAbsolute.js +11 -11
  50. package/dist/cjs/utils/isExternalLink.js +7 -0
  51. package/dist/cjs/utils/{hasPropertyGetter.js → isPropertyGetter.js} +3 -3
  52. package/dist/cjs/utils/onPageVisibilityChange.js +19 -0
  53. package/dist/cjs/utils/parseUrl.js +1 -1
  54. package/dist/cjs/utils/projectInfo.js +1 -1
  55. package/dist/cjs/utils/truncateString.js +12 -7
  56. package/dist/esm/__internal/index.d.ts +6 -3
  57. package/dist/esm/__internal/index.js +8 -3
  58. package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -3
  59. package/dist/esm/client/client-routing-runtime/createPageContext.js +3 -4
  60. package/dist/esm/client/client-routing-runtime/entry.js +2 -2
  61. package/dist/esm/client/client-routing-runtime/getBaseServer.d.ts +2 -1
  62. package/dist/esm/client/client-routing-runtime/getBaseServer.js +2 -1
  63. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +39 -0
  64. package/dist/esm/client/client-routing-runtime/{getPageContext.js → getPageContextFromHooks.js} +50 -79
  65. package/dist/esm/client/client-routing-runtime/history.d.ts +3 -1
  66. package/dist/esm/client/client-routing-runtime/history.js +31 -9
  67. package/dist/esm/client/client-routing-runtime/installClientRouter.d.ts +2 -0
  68. package/dist/esm/client/client-routing-runtime/installClientRouter.js +22 -0
  69. package/dist/esm/client/client-routing-runtime/isClientSideRoutable.d.ts +8 -0
  70. package/dist/esm/client/client-routing-runtime/isClientSideRoutable.js +12 -0
  71. package/dist/esm/client/client-routing-runtime/navigate.d.ts +0 -2
  72. package/dist/esm/client/client-routing-runtime/navigate.js +9 -8
  73. package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.d.ts +4 -0
  74. package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +63 -0
  75. package/dist/esm/client/client-routing-runtime/onLinkClick.d.ts +2 -0
  76. package/dist/esm/client/client-routing-runtime/onLinkClick.js +40 -0
  77. package/dist/esm/client/client-routing-runtime/prefetch.js +54 -29
  78. package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +19 -0
  79. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +347 -0
  80. package/dist/esm/client/client-routing-runtime/scrollRestoration.d.ts +6 -0
  81. package/dist/esm/client/client-routing-runtime/scrollRestoration.js +25 -0
  82. package/dist/esm/client/client-routing-runtime/setScrollPosition.d.ts +7 -0
  83. package/dist/esm/client/client-routing-runtime/setScrollPosition.js +77 -0
  84. package/dist/esm/client/client-routing-runtime/skipLink.d.ts +0 -1
  85. package/dist/esm/client/client-routing-runtime/skipLink.js +9 -5
  86. package/dist/esm/client/client-routing-runtime/utils.d.ts +2 -0
  87. package/dist/esm/client/client-routing-runtime/utils.js +2 -0
  88. package/dist/esm/client/server-routing-runtime/getPageContext.js +1 -1
  89. package/dist/esm/client/shared/executeOnRenderClientHook.js +6 -5
  90. package/dist/esm/client/shared/getPageContextProxyForUser.js +13 -7
  91. package/dist/esm/client/shared/loadPageFilesClientSide.d.ts +8 -3
  92. package/dist/esm/client/shared/loadPageFilesClientSide.js +5 -5
  93. package/dist/esm/node/plugin/plugins/buildConfig.js +3 -3
  94. package/dist/esm/node/plugin/plugins/commonConfig.js +0 -3
  95. package/dist/esm/node/plugin/plugins/config/index.js +4 -4
  96. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +9 -9
  97. package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -0
  98. package/dist/esm/node/plugin/plugins/envVars.d.ts +2 -0
  99. package/dist/esm/node/plugin/plugins/envVars.js +35 -20
  100. package/dist/esm/node/plugin/plugins/importBuild/index.js +3 -3
  101. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
  102. package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -3
  103. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
  104. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -4
  105. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
  106. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
  107. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -1
  108. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +250 -229
  109. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +2 -2
  110. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +7 -5
  111. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +2 -2
  112. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +37 -15
  113. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
  114. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +7 -0
  115. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +15 -0
  116. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
  117. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +16 -18
  118. package/dist/esm/node/plugin/plugins/previewConfig.js +11 -2
  119. package/dist/esm/node/prerender/runPrerender.js +29 -21
  120. package/dist/esm/node/prerender/utils.d.ts +1 -1
  121. package/dist/esm/node/prerender/utils.js +1 -1
  122. package/dist/esm/node/runtime/html/serializePageContextClientSide.js +21 -7
  123. package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +5 -5
  124. package/dist/esm/node/runtime/renderPage/debugPageFiles.js +5 -5
  125. package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.d.ts +2 -2
  126. package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
  127. package/dist/esm/node/runtime/renderPage/log404/index.js +28 -16
  128. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
  129. package/dist/esm/node/runtime/renderPage.js +3 -3
  130. package/dist/esm/node/runtime/utils.d.ts +1 -1
  131. package/dist/esm/node/runtime/utils.js +1 -1
  132. package/dist/esm/node/shared/getClientEntryFilePath.js +1 -1
  133. package/dist/esm/node/shared/getConfigVike.d.ts +2 -1
  134. package/dist/esm/node/shared/getConfigVike.js +4 -1
  135. package/dist/esm/shared/addUrlComputedProps.d.ts +1 -0
  136. package/dist/esm/shared/addUrlComputedProps.js +25 -13
  137. package/dist/esm/shared/getPageFiles/analyzeClientSide.js +2 -4
  138. package/dist/esm/shared/getPageFiles/getExports.js +2 -2
  139. package/dist/esm/shared/hooks/getHook.js +1 -1
  140. package/dist/esm/shared/page-configs/PageConfig.d.ts +55 -31
  141. package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
  142. package/dist/esm/shared/page-configs/getExportPath.js +3 -3
  143. package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +7 -0
  144. package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +37 -0
  145. package/dist/esm/shared/page-configs/helpers/getConfigValue.d.ts +14 -0
  146. package/dist/esm/shared/page-configs/helpers/getConfigValue.js +38 -0
  147. package/dist/esm/shared/page-configs/helpers.d.ts +13 -0
  148. package/dist/esm/shared/page-configs/helpers.js +27 -0
  149. package/dist/esm/shared/page-configs/loadConfigValues.js +2 -2
  150. package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +4 -4
  151. package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +15 -11
  152. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -2
  153. package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +9 -10
  154. package/dist/esm/shared/route/abort.js +1 -1
  155. package/dist/esm/shared/route/executeOnBeforeRouteHook.d.ts +5 -8
  156. package/dist/esm/shared/route/executeOnBeforeRouteHook.js +41 -15
  157. package/dist/esm/shared/route/index.d.ts +12 -10
  158. package/dist/esm/shared/route/index.js +23 -33
  159. package/dist/esm/shared/route/loadPageRoutes.js +8 -7
  160. package/dist/esm/shared/route/noRouteMatch.d.ts +1 -0
  161. package/dist/esm/shared/route/noRouteMatch.js +1 -0
  162. package/dist/esm/shared/route/resolveRouteFunction.js +1 -1
  163. package/dist/esm/shared/utils.d.ts +1 -1
  164. package/dist/esm/shared/utils.js +1 -1
  165. package/dist/esm/utils/getFilePathAbsolute.d.ts +1 -1
  166. package/dist/esm/utils/getFilePathAbsolute.js +11 -11
  167. package/dist/esm/utils/isPropertyGetter.d.ts +1 -0
  168. package/dist/esm/utils/{hasPropertyGetter.js → isPropertyGetter.js} +1 -1
  169. package/dist/esm/utils/onPageVisibilityChange.d.ts +4 -0
  170. package/dist/esm/utils/onPageVisibilityChange.js +16 -0
  171. package/dist/esm/utils/parseUrl.js +1 -1
  172. package/dist/esm/utils/projectInfo.d.ts +1 -1
  173. package/dist/esm/utils/projectInfo.js +1 -1
  174. package/dist/esm/utils/truncateString.d.ts +2 -1
  175. package/dist/esm/utils/truncateString.js +10 -7
  176. package/node/cli/bin-entry.js +1 -1
  177. package/package.json +2 -3
  178. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -16
  179. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -13
  180. package/dist/cjs/shared/page-configs/utils.js +0 -103
  181. package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +0 -29
  182. package/dist/esm/client/client-routing-runtime/getPageId.d.ts +0 -10
  183. package/dist/esm/client/client-routing-runtime/getPageId.js +0 -17
  184. package/dist/esm/client/client-routing-runtime/navigationState.d.ts +0 -5
  185. package/dist/esm/client/client-routing-runtime/navigationState.js +0 -14
  186. package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.d.ts +0 -2
  187. package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.js +0 -15
  188. package/dist/esm/client/client-routing-runtime/useClientRouter.d.ts +0 -6
  189. package/dist/esm/client/client-routing-runtime/useClientRouter.js +0 -493
  190. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +0 -24
  191. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -13
  192. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.d.ts +0 -3
  193. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -10
  194. package/dist/esm/shared/page-configs/utils.d.ts +0 -35
  195. package/dist/esm/shared/page-configs/utils.js +0 -97
  196. package/dist/esm/utils/hasPropertyGetter.d.ts +0 -1
  197. /package/dist/esm/{client/client-routing-runtime → utils}/isExternalLink.d.ts +0 -0
  198. /package/dist/esm/{client/client-routing-runtime → utils}/isExternalLink.js +0 -0
@@ -15,11 +15,11 @@ const isConfigInvalid_js_1 = require("../../../../runtime/renderPage/isConfigInv
15
15
  const globalContext_js_1 = require("../../../../runtime/globalContext.js");
16
16
  const loggerNotProd_js_1 = require("../../../shared/loggerNotProd.js");
17
17
  const removeSuperfluousViteLog_js_1 = require("../../../shared/loggerVite/removeSuperfluousViteLog.js");
18
- const getFilePathToShowToUser_js_1 = require("./getFilePathToShowToUser.js");
19
18
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
20
- const utils_js_2 = require("../../../../../shared/page-configs/utils.js");
19
+ const helpers_js_1 = require("../../../../../shared/page-configs/helpers.js");
21
20
  const assertExports_js_1 = require("../../../../../shared/page-configs/assertExports.js");
22
21
  const getVirtualFilePageConfigs_js_1 = require("./getVirtualFilePageConfigs.js");
22
+ const getConfigVike_js_1 = require("../../../../shared/getConfigVike.js");
23
23
  (0, utils_js_1.assertIsNotProductionRuntime)();
24
24
  let devServerIsCorrupt = false;
25
25
  let wasConfigInvalid = null;
@@ -65,9 +65,11 @@ async function handleReloadSideEffects() {
65
65
  }
66
66
  }
67
67
  }
68
- async function getVikeConfig(userRootDir, outDirRoot, isDev, extensions, tolerateInvalidConfig = false) {
68
+ async function getVikeConfig(config, isDev, tolerateInvalidConfig = false, extensions) {
69
+ const { outDirRoot } = (0, utils_js_1.getOutDirs)(config);
70
+ const userRootDir = config.root;
69
71
  if (!vikeConfigPromise) {
70
- vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, extensions, tolerateInvalidConfig);
72
+ vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, extensions ?? (await (0, getConfigVike_js_1.getConfigVike)(config)).extensions, tolerateInvalidConfig);
71
73
  }
72
74
  return await vikeConfigPromise;
73
75
  }
@@ -77,7 +79,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
77
79
  const configFiles = [];
78
80
  const valueFiles = [];
79
81
  plusFiles.forEach((f) => {
80
- if (getConfigName(f.filePathRelativeToUserRootDir) === 'config') {
82
+ if (getConfigName(f.filePathAbsoluteFilesystem) === 'config') {
81
83
  configFiles.push(f);
82
84
  }
83
85
  else {
@@ -86,15 +88,10 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
86
88
  });
87
89
  let interfaceFilesByLocationId = {};
88
90
  // Config files
89
- await Promise.all(configFiles.map(async ({ filePathAbsolute, filePathRelativeToUserRootDir }) => {
90
- const configFilePath = {
91
- filePathAbsolute: filePathAbsolute,
92
- filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
93
- importPathAbsolute: null
94
- };
95
- const { configFile, extendsConfigs } = await loadConfigFile(configFilePath, userRootDir, []);
91
+ await Promise.all(configFiles.map(async (filePath) => {
92
+ const { configFile, extendsConfigs } = await loadConfigFile(filePath, userRootDir, []);
96
93
  const interfaceFile = getInterfaceFileFromConfigFile(configFile, false);
97
- const locationId = (0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir);
94
+ const locationId = (0, filesystemRouting_js_1.getLocationId)(filePath.filePathAbsoluteVite);
98
95
  interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
99
96
  interfaceFilesByLocationId[locationId].push(interfaceFile);
100
97
  extendsConfigs.forEach((extendsConfig) => {
@@ -103,15 +100,11 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
103
100
  });
104
101
  }));
105
102
  // Value files
106
- await Promise.all(valueFiles.map(async ({ filePathAbsolute, filePathRelativeToUserRootDir }) => {
107
- const configName = getConfigName(filePathRelativeToUserRootDir);
103
+ await Promise.all(valueFiles.map(async (filePath) => {
104
+ const configName = getConfigName(filePath.filePathAbsoluteVite);
108
105
  (0, utils_js_1.assert)(configName);
109
106
  const interfaceFile = {
110
- filePath: {
111
- filePathRelativeToUserRootDir,
112
- filePathAbsolute,
113
- importPathAbsolute: null
114
- },
107
+ filePath,
115
108
  configMap: {
116
109
  [configName]: {}
117
110
  },
@@ -120,25 +113,25 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
120
113
  configName
121
114
  };
122
115
  {
123
- // We don't have access to custom config definitions yet
124
- // - We load +{configName}.js later
125
- // - But we do need to eagerly load +meta.js (to get all the custom config definitions)
116
+ // We don't have access to the custom config definitions defined by the user yet.
117
+ // - If `configDef` is `undefined` => we load the file +{configName}.js later.
118
+ // - We already need to load +meta.js here (to get the custom config definitions defined by the user)
126
119
  const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn, configName);
127
- if (configDef?.env === 'config-only') {
120
+ if (configDef && isConfigEnv(configDef, configName)) {
128
121
  await loadValueFile(interfaceFile, configName, userRootDir);
129
122
  }
130
123
  }
131
124
  {
132
- const locationId = (0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir);
125
+ const locationId = (0, filesystemRouting_js_1.getLocationId)(filePath.filePathAbsoluteVite);
133
126
  interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
134
127
  interfaceFilesByLocationId[locationId].push(interfaceFile);
135
128
  }
136
129
  }));
137
130
  return interfaceFilesByLocationId;
138
131
  }
139
- function getConfigDefinition(configDefinitionsRelevant, configName, definedByFile) {
132
+ function getConfigDefinition(configDefinitionsRelevant, configName, filePathToShowToUser) {
140
133
  const configDef = configDefinitionsRelevant[configName];
141
- assertConfigExists(configName, Object.keys(configDefinitionsRelevant), definedByFile);
134
+ assertConfigExists(configName, Object.keys(configDefinitionsRelevant), filePathToShowToUser);
142
135
  (0, utils_js_1.assert)(configDef);
143
136
  return configDef;
144
137
  }
@@ -147,13 +140,29 @@ function getConfigDefinitionOptional(configDefinitions, configName) {
147
140
  }
148
141
  async function loadValueFile(interfaceValueFile, configName, userRootDir) {
149
142
  const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath, true, userRootDir);
150
- const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceValueFile.filePath);
143
+ const { filePathToShowToUser } = interfaceValueFile.filePath;
151
144
  (0, assertExports_js_1.assertExportsOfValueFile)(fileExports, filePathToShowToUser, configName);
152
145
  Object.entries(fileExports).forEach(([exportName, configValue]) => {
153
146
  const configName_ = exportName === 'default' ? configName : exportName;
154
147
  interfaceValueFile.configMap[configName_] = { configValue };
155
148
  });
156
149
  }
150
+ async function loadImportedFile(filePath, userRootDir, importedFilesLoaded) {
151
+ const f = filePath.filePathAbsoluteFilesystem;
152
+ if (!importedFilesLoaded[f]) {
153
+ importedFilesLoaded[f] = (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(filePath, true, userRootDir).then((r) => r.fileExports);
154
+ }
155
+ const fileExports = await importedFilesLoaded[f];
156
+ return fileExports;
157
+ }
158
+ function isConfigEnv(configDef, configName) {
159
+ if (configDef.cumulative)
160
+ return true;
161
+ if (configDef.env === 'config-only')
162
+ return true;
163
+ // TODO: replace with proper `env: { config: boolean }` implementation
164
+ return configName === 'clientRouting';
165
+ }
157
166
  function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
158
167
  const { fileExports, filePath, extendsFilePaths } = configFile;
159
168
  const interfaceFile = {
@@ -164,7 +173,7 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
164
173
  isConfigExtend,
165
174
  extendsFilePaths
166
175
  };
167
- const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(filePath);
176
+ const { filePathToShowToUser } = filePath;
168
177
  (0, assertExports_js_1.assertExportsOfConfigFile)(fileExports, filePathToShowToUser);
169
178
  Object.entries(fileExports.default).forEach(([configName, configValue]) => {
170
179
  interfaceFile.configMap[configName] = { configValue };
@@ -214,7 +223,8 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
214
223
  }
215
224
  async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
216
225
  const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions);
217
- const { globalVikeConfig, pageConfigGlobal } = getGlobalConfigs(interfaceFilesByLocationId, userRootDir);
226
+ const importedFilesLoaded = {};
227
+ const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
218
228
  const pageConfigs = await Promise.all(Object.entries(interfaceFilesByLocationId)
219
229
  .filter(([_pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
220
230
  .map(async ([locationId]) => {
@@ -227,25 +237,25 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
227
237
  const { configName } = interfaceFile;
228
238
  if (isGlobalConfig(configName))
229
239
  return;
230
- const configDef = getConfigDefinition(configDefinitionsRelevant, configName, (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceFile.filePath));
231
- if (configDef.env !== 'config-only')
240
+ const configDef = getConfigDefinition(configDefinitionsRelevant, configName, interfaceFile.filePath.filePathToShowToUser);
241
+ if (!isConfigEnv(configDef, configName))
232
242
  return;
233
243
  const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
234
244
  if (isAlreadyLoaded)
235
245
  return;
236
- // Value files for built-in confg-only configs should have already been loaded at loadInterfaceFiles()
246
+ // Value files of built-in configs should have already been loaded at loadInterfaceFiles()
237
247
  (0, utils_js_1.assert)(!(configName in configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn));
238
248
  await loadValueFile(interfaceFile, configName, userRootDir);
239
249
  }));
240
250
  const configValueSources = {};
241
- (0, utils_js_1.objectEntries)(configDefinitionsRelevant)
251
+ await Promise.all((0, utils_js_1.objectEntries)(configDefinitionsRelevant)
242
252
  .filter(([configName]) => !isGlobalConfig(configName))
243
- .forEach(([configName, configDef]) => {
244
- const sources = resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir);
245
- if (!sources)
253
+ .map(async ([configName, configDef]) => {
254
+ const sources = await resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir, importedFilesLoaded);
255
+ if (sources.length === 0)
246
256
  return;
247
257
  configValueSources[configName] = sources;
248
- });
258
+ }));
249
259
  const { routeFilesystem, isErrorPage } = determineRouteFilesystem(locationId, configValueSources);
250
260
  applyEffectsAll(configValueSources, configDefinitionsRelevant);
251
261
  const configValuesComputed = getComputed(configValueSources, configDefinitionsRelevant);
@@ -266,7 +276,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
266
276
  const configDefinitionsRelevant = getConfigDefinitions(interfaceFilesRelevant);
267
277
  interfaceFiles.forEach((interfaceFile) => {
268
278
  Object.keys(interfaceFile.configMap).forEach((configName) => {
269
- assertConfigExists(configName, Object.keys(configDefinitionsRelevant), (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceFile.filePath));
279
+ assertConfigExists(configName, Object.keys(configDefinitionsRelevant), interfaceFile.filePath.filePathToShowToUser);
270
280
  });
271
281
  });
272
282
  });
@@ -295,7 +305,7 @@ function getInterfaceFileList(interfaceFilesByLocationId) {
295
305
  });
296
306
  return interfaceFiles;
297
307
  }
298
- function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
308
+ async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded) {
299
309
  const locationIds = Object.keys(interfaceFilesByLocationId);
300
310
  const interfaceFilesGlobal = Object.fromEntries(Object.entries(interfaceFilesByLocationId).filter(([locationId]) => {
301
311
  return (0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds);
@@ -317,7 +327,7 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
317
327
  Object.keys(interfaceFile.configMap).forEach((configName) => {
318
328
  if (!(0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds) && isGlobalConfig(configName)) {
319
329
  (0, utils_js_1.assertUsage)(false, [
320
- `${(0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceFile.filePath)} defines the config ${picocolors_1.default.cyan(configName)} which is global:`,
330
+ `${interfaceFile.filePath.filePathToShowToUser} defines the config ${picocolors_1.default.cyan(configName)} which is global:`,
321
331
  globalPaths.length
322
332
  ? `define ${picocolors_1.default.cyan(configName)} in ${(0, utils_js_1.joinEnglish)(globalPaths, 'or')} instead`
323
333
  : `create a global config (e.g. /pages/+config.js) and define ${picocolors_1.default.cyan(configName)} there instead`
@@ -331,9 +341,9 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
331
341
  const pageConfigGlobal = {
332
342
  configValueSources: {}
333
343
  };
334
- (0, utils_js_1.objectEntries)(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal).forEach(([configName, configDef]) => {
335
- const sources = resolveConfigValueSources(configName, configDef, interfaceFilesGlobal, userRootDir);
336
- const configValueSource = sources?.[0];
344
+ await Promise.all((0, utils_js_1.objectEntries)(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal).map(async ([configName, configDef]) => {
345
+ const sources = await resolveConfigValueSources(configName, configDef, interfaceFilesGlobal, userRootDir, importedFilesLoaded);
346
+ const configValueSource = sources[0];
337
347
  if (!configValueSource)
338
348
  return;
339
349
  if (configName === 'onBeforeRoute' || configName === 'onPrerenderStart') {
@@ -344,28 +354,25 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
344
354
  (0, utils_js_1.assert)('value' in configValueSource);
345
355
  if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
346
356
  return;
347
- const sourceFilePath = getDefinedAtFilePathToShowToUser(configValueSource.definedAtInfo);
348
- (0, utils_js_1.assert)(sourceFilePath);
349
- (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 });
357
+ const { filePathToShowToUser } = configValueSource.definedAt;
358
+ (0, utils_js_1.assertWarning)(false, `Being able to define config ${picocolors_1.default.cyan(configName)} in ${filePathToShowToUser} is experimental and will likely be removed. Define the config ${picocolors_1.default.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
350
359
  globalVikeConfig[configName] = configValueSource.value;
351
360
  }
352
- });
361
+ }));
353
362
  return { pageConfigGlobal, globalVikeConfig };
354
363
  }
355
- function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir) {
356
- let sources = null;
364
+ async function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir, importedFilesLoaded) {
365
+ const sourcesInfo = [];
357
366
  // interfaceFilesRelevant is sorted by sortAfterInheritanceOrder()
358
367
  for (const interfaceFiles of Object.values(interfaceFilesRelevant)) {
359
368
  const interfaceFilesDefiningConfig = interfaceFiles.filter((interfaceFile) => interfaceFile.configMap[configName]);
360
369
  if (interfaceFilesDefiningConfig.length === 0)
361
370
  continue;
362
- sources = sources ?? [];
363
371
  const visited = new WeakSet();
364
372
  const add = (interfaceFile) => {
365
373
  (0, utils_js_1.assert)(!visited.has(interfaceFile));
366
374
  visited.add(interfaceFile);
367
- const configValueSource = getConfigValueSource(configName, interfaceFile, configDef, userRootDir);
368
- sources.push(configValueSource);
375
+ sourcesInfo.push([configName, interfaceFile, configDef, userRootDir, importedFilesLoaded]);
369
376
  };
370
377
  // Main resolution logic
371
378
  {
@@ -389,7 +396,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
389
396
  if (interfaceFileWinner) {
390
397
  const interfaceFilesOverriden = [...interfaceValueFiles, ...interfaceConfigFiles].filter((f) => f !== interfaceFileWinner);
391
398
  // A user-land conflict of interfaceFiles with the same locationId means that the user has superfluously defined the config twice; the user should remove such redundancy making things unnecessarily ambiguous
392
- warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden, configName, configDef, userRootDir);
399
+ warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden, configName);
393
400
  [interfaceFileWinner, ...interfaceFilesOverriden].forEach((interfaceFile) => {
394
401
  add(interfaceFile);
395
402
  });
@@ -414,7 +421,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
414
421
  (0, utils_js_1.assert)(visited.has(interfaceFile));
415
422
  });
416
423
  }
417
- (0, utils_js_1.assert)(sources === null || sources.length > 0);
424
+ const sources = await Promise.all(sourcesInfo.map(async (args) => await getConfigValueSource(...args)));
418
425
  return sources;
419
426
  }
420
427
  function makeOrderDeterministic(interfaceFile1, interfaceFile2) {
@@ -425,41 +432,41 @@ function makeOrderDeterministic(interfaceFile1, interfaceFile2) {
425
432
  return filePathRelativeToUserRootDir.length;
426
433
  })(interfaceFile1, interfaceFile2);
427
434
  }
428
- function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden, configName, configDef, userRootDir) {
435
+ function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden, configName) {
429
436
  interfaceFilesOverriden.forEach((interfaceFileLoser) => {
430
- const configValueSourceWinner = getConfigValueSource(configName, interfaceFileWinner, configDef, userRootDir);
431
- const configValueSourceLoser = getConfigValueSource(configName, interfaceFileLoser, configDef, userRootDir);
432
- (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 });
437
+ const loserFilePath = interfaceFileLoser.filePath.filePathToShowToUser;
438
+ const winnerFilePath = interfaceFileWinner.filePath.filePathToShowToUser;
439
+ (0, utils_js_1.assertWarning)(false, `Config ${configName} defined at ${loserFilePath} is always overwritten by ${configName} defined at ${winnerFilePath}, remove the superfluous ${configName} value defined at ${interfaceFileLoser}`, { onlyOnce: false });
433
440
  });
434
441
  }
435
442
  function isInterfaceFileUserLand(interfaceFile) {
436
443
  return (interfaceFile.isConfigFile && !interfaceFile.isConfigExtend) || interfaceFile.isValueFile;
437
444
  }
438
- function getConfigValueSource(configName, interfaceFile, configDef, userRootDir) {
445
+ async function getConfigValueSource(configName, interfaceFile, configDef, userRootDir, importedFilesLoaded) {
439
446
  const conf = interfaceFile.configMap[configName];
440
447
  (0, utils_js_1.assert)(conf);
441
448
  const configEnv = configDef.env;
442
449
  const definedAtConfigFile = {
443
450
  ...interfaceFile.filePath,
444
- fileExportPath: ['default', configName]
451
+ fileExportPathToShowToUser: ['default', configName]
445
452
  };
446
453
  if (configDef._valueIsFilePath) {
447
- let definedAtInfo;
454
+ let definedAt;
448
455
  let valueFilePath;
449
456
  if (interfaceFile.isConfigFile) {
450
457
  const { configValue } = conf;
451
458
  const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
452
- const configDefinedAt = getConfigSourceDefinedAtString(configName, { definedAtInfo: definedAtConfigFile });
459
+ const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, { definedAt: definedAtConfigFile });
453
460
  (0, utils_js_1.assertUsage)(import_, `${configDefinedAt} should be an import`);
454
- valueFilePath = import_.filePathRelativeToUserRootDir ?? import_.importPathAbsolute;
455
- definedAtInfo = import_;
461
+ valueFilePath = import_.filePathAbsoluteVite;
462
+ definedAt = import_;
456
463
  }
457
464
  else {
458
465
  (0, utils_js_1.assert)(interfaceFile.isValueFile);
459
- valueFilePath = interfaceFile.filePath.filePathRelativeToUserRootDir;
460
- definedAtInfo = {
466
+ valueFilePath = interfaceFile.filePath.filePathAbsoluteVite;
467
+ definedAt = {
461
468
  ...interfaceFile.filePath,
462
- fileExportPath: []
469
+ fileExportPathToShowToUser: []
463
470
  };
464
471
  }
465
472
  const configValueSource = {
@@ -467,7 +474,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
467
474
  valueIsFilePath: true,
468
475
  configEnv,
469
476
  valueIsImportedAtRuntime: true,
470
- definedAtInfo
477
+ definedAt
471
478
  };
472
479
  return configValueSource;
473
480
  }
@@ -479,8 +486,20 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
479
486
  const configValueSource = {
480
487
  configEnv,
481
488
  valueIsImportedAtRuntime: true,
482
- definedAtInfo: import_
489
+ definedAt: import_
483
490
  };
491
+ // Load config value
492
+ if (isConfigEnv(configDef, configName)) {
493
+ if (import_.filePathAbsoluteFilesystem) {
494
+ (0, utils_js_1.assert)((0, utils_js_1.hasProp)(import_, 'filePathAbsoluteFilesystem', 'string')); // Help TS
495
+ const fileExports = await loadImportedFile(import_, userRootDir, importedFilesLoaded);
496
+ configValueSource.value = fileExports[import_.fileExportName];
497
+ }
498
+ else {
499
+ const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configValueSource);
500
+ (0, utils_js_1.assertUsage)(!configDef.cumulative, `${configDefinedAt} cannot be defined over an aliased import`);
501
+ }
502
+ }
484
503
  return configValueSource;
485
504
  }
486
505
  else {
@@ -488,7 +507,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
488
507
  value: configValue,
489
508
  configEnv,
490
509
  valueIsImportedAtRuntime: false,
491
- definedAtInfo: definedAtConfigFile
510
+ definedAt: definedAtConfigFile
492
511
  };
493
512
  return configValueSource;
494
513
  }
@@ -498,9 +517,9 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
498
517
  const configValueSource = {
499
518
  configEnv,
500
519
  valueIsImportedAtRuntime: !valueAlreadyLoaded,
501
- definedAtInfo: {
520
+ definedAt: {
502
521
  ...interfaceFile.filePath,
503
- fileExportPath: configName === interfaceFile.configName
522
+ fileExportPathToShowToUser: configName === interfaceFile.configName
504
523
  ? []
505
524
  : // Side-effect config (e.g. `export { frontmatter }` of .md files)
506
525
  [configName]
@@ -551,51 +570,61 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
551
570
  if (!importData)
552
571
  return null;
553
572
  const { importPath, exportName } = importData;
554
- const filePathAbsolute = resolveImportPath(importData, importerFilePath);
555
- assertFileEnv(filePathAbsolute ?? importPath, configEnv, configName);
556
- const fileExportPath = exportName === 'default' || exportName === configName ? [] : [exportName];
573
+ const filePathAbsoluteFilesystem = resolveImportPath(importData, importerFilePath);
574
+ assertFileEnv(filePathAbsoluteFilesystem ?? importPath, configEnv, configName);
575
+ const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
557
576
  if (importPath.startsWith('.')) {
558
577
  // We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
559
578
  // ```
560
579
  // [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
561
580
  // ```
562
- assertImportPath(filePathAbsolute, importData, importerFilePath);
563
- const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, importerFilePath, userRootDir);
564
- return {
565
- exportName,
566
- fileExportPath,
567
- filePathAbsolute,
581
+ assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
582
+ const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, importerFilePath, userRootDir);
583
+ const filePath = {
584
+ filePathAbsoluteFilesystem,
568
585
  filePathRelativeToUserRootDir,
586
+ filePathAbsoluteVite: filePathRelativeToUserRootDir,
587
+ filePathToShowToUser: filePathRelativeToUserRootDir,
569
588
  importPathAbsolute: null
570
589
  };
590
+ return {
591
+ ...filePath,
592
+ fileExportName: exportName,
593
+ fileExportPathToShowToUser
594
+ };
571
595
  }
572
596
  else {
573
597
  // importPath can be:
574
598
  // - an npm package import
575
599
  // - a path alias
576
- return {
577
- exportName,
578
- fileExportPath,
579
- filePathAbsolute,
600
+ const filePath = {
601
+ filePathAbsoluteFilesystem,
580
602
  filePathRelativeToUserRootDir: null,
603
+ filePathAbsoluteVite: importPath,
604
+ filePathToShowToUser: importPath,
581
605
  importPathAbsolute: importPath
582
606
  };
607
+ return {
608
+ ...filePath,
609
+ fileExportName: exportName,
610
+ fileExportPathToShowToUser
611
+ };
583
612
  }
584
613
  }
585
- function resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, configFilePath, userRootDir) {
614
+ function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
586
615
  (0, utils_js_1.assertPosixPath)(userRootDir);
587
616
  let filePathRelativeToUserRootDir;
588
- if (filePathAbsolute.startsWith(userRootDir)) {
589
- filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsolute, userRootDir);
617
+ if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
618
+ filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, userRootDir);
590
619
  }
591
620
  else {
592
- (0, utils_js_1.assertUsage)(false, `${(0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(configFilePath)} imports from a relative path ${picocolors_1.default.cyan(importData.importPath)} outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
621
+ (0, utils_js_1.assertUsage)(false, `${configFilePath.filePathToShowToUser} imports from a relative path ${picocolors_1.default.cyan(importData.importPath)} outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
593
622
  // None of the following works. Seems to be a Vite bug?
594
623
  // /*
595
- // assert(filePathAbsolute.startsWith('/'))
596
- // filePath = `/@fs${filePathAbsolute}`
624
+ // assert(filePathAbsoluteFilesystem.startsWith('/'))
625
+ // filePath = `/@fs${filePathAbsoluteFilesystem}`
597
626
  // /*/
598
- // filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsolute)
627
+ // filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem)
599
628
  // assert(filePathRelativeToUserRootDir.startsWith('../'))
600
629
  // filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir
601
630
  // //*/
@@ -604,11 +633,11 @@ function resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, c
604
633
  (0, utils_js_1.assert)(filePathRelativeToUserRootDir.startsWith('/'));
605
634
  return filePathRelativeToUserRootDir;
606
635
  }
607
- function getVitePathFromAbsolutePath(filePathAbsolute, root) {
608
- (0, utils_js_1.assertPosixPath)(filePathAbsolute);
636
+ function getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, root) {
637
+ (0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
609
638
  (0, utils_js_1.assertPosixPath)(root);
610
- (0, utils_js_1.assert)(filePathAbsolute.startsWith(root));
611
- let vitePath = path_1.default.posix.relative(root, filePathAbsolute);
639
+ (0, utils_js_1.assert)(filePathAbsoluteFilesystem.startsWith(root));
640
+ let vitePath = path_1.default.posix.relative(root, filePathAbsoluteFilesystem);
612
641
  (0, utils_js_1.assert)(!vitePath.startsWith('/') && !vitePath.startsWith('.'));
613
642
  vitePath = '/' + vitePath;
614
643
  return vitePath;
@@ -621,9 +650,17 @@ function getConfigDefinitions(interfaceFilesRelevant) {
621
650
  if (!configMeta)
622
651
  return;
623
652
  const meta = configMeta.configValue;
624
- assertMetaValue(meta,
625
- // Maybe we should use the getConfigDefinedAtString() helper?
626
- `Config ${picocolors_1.default.cyan('meta')} defined at ${(0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceFile.filePath)}`);
653
+ assertMetaValue(meta, `Config ${picocolors_1.default.cyan('meta')} defined at ${interfaceFile.filePath.filePathToShowToUser}`);
654
+ // Set configDef._userEffectDefinedAt
655
+ Object.entries(meta).forEach(([configName, configDef]) => {
656
+ if (!configDef.effect)
657
+ return;
658
+ (0, utils_js_1.assert)(interfaceFile.isConfigFile);
659
+ configDef._userEffectDefinedAt = {
660
+ ...interfaceFile.filePath,
661
+ fileExportPathToShowToUser: ['default', 'meta', configName, 'effect']
662
+ };
663
+ });
627
664
  (0, utils_js_1.objectEntries)(meta).forEach(([configName, configDefinition]) => {
628
665
  // User can override an existing config definition
629
666
  configDefinitions[configName] = {
@@ -636,9 +673,15 @@ function getConfigDefinitions(interfaceFilesRelevant) {
636
673
  return configDefinitions;
637
674
  }
638
675
  function assertMetaValue(metaVal, configMetaDefinedAt) {
639
- (0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(metaVal), `${configMetaDefinedAt} has an invalid type ${picocolors_1.default.cyan(typeof metaVal)}: it should be an object instead.`);
676
+ if (!(0, utils_js_1.isObject)(metaVal)) {
677
+ (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
678
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} has an invalid type ${picocolors_1.default.cyan(typeof metaVal)}: it should be an object instead.`);
679
+ }
640
680
  (0, utils_js_1.objectEntries)(metaVal).forEach(([configName, def]) => {
641
- (0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(def), `${configMetaDefinedAt} sets meta.${configName} to a value with an invalid type ${picocolors_1.default.cyan(typeof def)}: it should be an object instead.`);
681
+ if (!(0, utils_js_1.isObject)(def)) {
682
+ (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
683
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}`)} to a value with an invalid type ${picocolors_1.default.cyan(typeof def)}: it should be an object instead.`);
684
+ }
642
685
  // env
643
686
  {
644
687
  const envValues = [
@@ -647,19 +690,34 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
647
690
  'server-and-client',
648
691
  'config-only'
649
692
  ];
650
- const hint = [
651
- `Set the value of ${picocolors_1.default.cyan('env')} to `,
693
+ const fix = [
694
+ `Set the value of ${picocolors_1.default.cyan(`meta.${configName}.env`)} to `,
652
695
  (0, utils_js_1.joinEnglish)(envValues.map((s) => picocolors_1.default.cyan(`'${s}'`)), 'or'),
653
696
  '.'
654
697
  ].join('');
655
- (0, utils_js_1.assertUsage)('env' in def, `${configMetaDefinedAt} doesn't set meta.${configName}.env but it's required. ${hint}`);
656
- (0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(def, 'env', 'string'), `${configMetaDefinedAt} sets meta.${configName}.env to an invalid type ${picocolors_1.default.cyan(typeof def.env)}. ${hint}`);
657
- (0, utils_js_1.assertUsage)(envValues.includes(def.env), `${configMetaDefinedAt} sets meta.${configName}.env to an invalid value ${picocolors_1.default.cyan(`'${def.env}'`)}. ${hint}`);
698
+ if (!('env' in def)) {
699
+ (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
700
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} doesn't set ${picocolors_1.default.cyan(`meta.${configName}.env`)} but it's required. ${fix}`);
701
+ }
702
+ if (!(0, utils_js_1.hasProp)(def, 'env', 'string')) {
703
+ (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
704
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.env`)} to an invalid type ${picocolors_1.default.cyan(typeof def.env)}. ${fix}`);
705
+ }
706
+ if (!envValues.includes(def.env)) {
707
+ (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
708
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.env`)} to an unknown value ${picocolors_1.default.cyan(`'${def.env}'`)}. ${fix}`);
709
+ }
658
710
  }
659
711
  // effect
660
712
  if ('effect' in def) {
661
- (0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(def, 'effect', 'function'), `${configMetaDefinedAt} sets meta.${configName}.effect to an invalid type ${picocolors_1.default.cyan(typeof def.effect)}: it should be a function instead`);
662
- (0, utils_js_1.assertUsage)(def.env === 'config-only', `${configMetaDefinedAt} sets meta.${configName}.effect but it's only supported if meta.${configName}.env is ${picocolors_1.default.cyan('config-only')} (but it's ${picocolors_1.default.cyan(def.env)} instead)`);
713
+ if (!(0, utils_js_1.hasProp)(def, 'effect', 'function')) {
714
+ (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
715
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.effect`)} to an invalid type ${picocolors_1.default.cyan(typeof def.effect)}: it should be a function instead`);
716
+ }
717
+ if (def.env !== 'config-only') {
718
+ (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
719
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.effect`)} but it's only supported if meta.${configName}.env is ${picocolors_1.default.cyan('config-only')} (but it's ${picocolors_1.default.cyan(def.env)} instead)`);
720
+ }
663
721
  }
664
722
  });
665
723
  }
@@ -670,7 +728,7 @@ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
670
728
  // The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
671
729
  // (We could support effect for non config-only by always loading its value at config time, regardless of the config's `env` value.)
672
730
  (0, utils_js_1.assertUsage)(configDef.env === 'config-only', [
673
- `Cannot add effect to ${picocolors_1.default.cyan(configName)} because its ${picocolors_1.default.cyan('env')} is ${picocolors_1.default.cyan(configDef.env)}: effects can only be added to configs with an env that is ${picocolors_1.default.cyan('config-only')}.`
731
+ `Cannot add effect to ${picocolors_1.default.cyan(configName)} because its ${picocolors_1.default.cyan('env')} is ${picocolors_1.default.cyan(configDef.env)}: effects can only be added to configs with an ${picocolors_1.default.cyan('env')} value of ${picocolors_1.default.cyan('config-only')}.`
674
732
  ].join(' '));
675
733
  const source = configValueSources[configName]?.[0];
676
734
  if (!source)
@@ -680,19 +738,28 @@ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
680
738
  // Call effect
681
739
  const configModFromEffect = configDef.effect({
682
740
  configValue: source.value,
683
- configDefinedAt: getConfigSourceDefinedAtString(configName, source)
741
+ configDefinedAt: (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, source)
684
742
  });
685
743
  if (!configModFromEffect)
686
744
  return;
687
745
  (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
688
- applyEffect(configModFromEffect, source, configValueSources);
746
+ applyEffect(configModFromEffect, configValueSources, configDef);
689
747
  });
690
748
  }
691
- function applyEffect(configModFromEffect, configValueEffectSource, configValueSources) {
749
+ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
692
750
  const notSupported = `Effects currently only supports modifying the the ${picocolors_1.default.cyan('env')} of a config.`;
693
751
  (0, utils_js_1.objectEntries)(configModFromEffect).forEach(([configName, configValue]) => {
694
752
  if (configName === 'meta') {
695
- assertMetaValue(configValue, getConfigSourceDefinedAtString(configName, configValueEffectSource, true));
753
+ let configDefinedAtString;
754
+ if (configDefEffect._userEffectDefinedAt) {
755
+ configDefinedAtString = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, {
756
+ definedAt: configDefEffect._userEffectDefinedAt
757
+ });
758
+ }
759
+ else {
760
+ configDefinedAtString = null;
761
+ }
762
+ assertMetaValue(configValue, configDefinedAtString);
696
763
  (0, utils_js_1.objectEntries)(configValue).forEach(([configTargetName, configTargetDef]) => {
697
764
  {
698
765
  const keys = Object.keys(configTargetDef);
@@ -710,7 +777,7 @@ function applyEffect(configModFromEffect, configValueEffectSource, configValueSo
710
777
  else {
711
778
  (0, utils_js_1.assertUsage)(false, notSupported);
712
779
  // If we do end implementing being able to set the value of a config:
713
- // - For setting definedAtInfo: we could take the definedAtInfo of the effect config while appending '(effect)' to definedAtInfo.fileExportPath
780
+ // - For setting definedAt: we could take the definedAt of the effect config while appending '(effect)' to definedAt.fileExportPathToShowToUser
714
781
  }
715
782
  });
716
783
  }
@@ -761,20 +828,29 @@ async function findPlusFiles(userRootDir, ignoreDirs, isDev, extensions) {
761
828
  const plusFiles = result.map((p) => {
762
829
  p = (0, utils_js_1.toPosixPath)(p);
763
830
  const filePathRelativeToUserRootDir = path_1.default.posix.join('/', p);
764
- const filePathAbsolute = path_1.default.posix.join(userRootDir, p);
765
- return { filePathRelativeToUserRootDir, filePathAbsolute };
831
+ const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, p);
832
+ return {
833
+ filePathRelativeToUserRootDir,
834
+ filePathAbsoluteVite: filePathRelativeToUserRootDir,
835
+ filePathAbsoluteFilesystem,
836
+ filePathToShowToUser: filePathRelativeToUserRootDir,
837
+ importPathAbsolute: null
838
+ };
766
839
  });
840
+ // TODO/v1-release: remove
767
841
  extensions.forEach((extension) => {
768
842
  extension.pageConfigsDistFiles?.forEach((pageConfigDistFile) => {
769
- // TODO/v1-release: remove
770
843
  if (!pageConfigDistFile.importPath.includes('+'))
771
844
  return;
772
845
  (0, utils_js_1.assert)(pageConfigDistFile.importPath.includes('+'));
773
846
  (0, utils_js_1.assert)(path_1.default.posix.basename(pageConfigDistFile.importPath).startsWith('+'));
774
847
  const { importPath, filePath } = pageConfigDistFile;
775
848
  plusFiles.push({
776
- filePathRelativeToUserRootDir: importPath,
777
- filePathAbsolute: filePath
849
+ filePathRelativeToUserRootDir: null,
850
+ filePathAbsoluteVite: importPath,
851
+ filePathAbsoluteFilesystem: filePath,
852
+ filePathToShowToUser: importPath,
853
+ importPathAbsolute: importPath
778
854
  });
779
855
  });
780
856
  });
@@ -804,12 +880,12 @@ function assertNoUnexpectedPlusSign(filePath, fileName) {
804
880
  (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`);
805
881
  }
806
882
  async function loadConfigFile(configFilePath, userRootDir, visited) {
807
- const { filePathAbsolute } = configFilePath;
808
- assertNoInfiniteLoop(visited, filePathAbsolute);
883
+ const { filePathAbsoluteFilesystem } = configFilePath;
884
+ assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
809
885
  const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(configFilePath, false, userRootDir);
810
886
  const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
811
887
  ...visited,
812
- filePathAbsolute
888
+ filePathAbsoluteFilesystem
813
889
  ]);
814
890
  const configFile = {
815
891
  fileExports,
@@ -818,31 +894,31 @@ async function loadConfigFile(configFilePath, userRootDir, visited) {
818
894
  };
819
895
  return { configFile, extendsConfigs };
820
896
  }
821
- function assertNoInfiniteLoop(visited, filePathAbsolute) {
822
- const idx = visited.indexOf(filePathAbsolute);
897
+ function assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem) {
898
+ const idx = visited.indexOf(filePathAbsoluteFilesystem);
823
899
  if (idx === -1)
824
900
  return;
825
901
  const loop = visited.slice(idx);
826
- (0, utils_js_1.assert)(loop[0] === filePathAbsolute);
827
- (0, utils_js_1.assertUsage)(idx === -1, `Infinite extends loop ${[...loop, filePathAbsolute].join('>')}`);
902
+ (0, utils_js_1.assert)(loop[0] === filePathAbsoluteFilesystem);
903
+ (0, utils_js_1.assertUsage)(idx === -1, `Infinite extends loop ${[...loop, filePathAbsoluteFilesystem].join('>')}`);
828
904
  }
829
905
  async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir, visited) {
830
906
  const extendsImportData = getExtendsImportData(configFileExports, configFilePath);
831
907
  const extendsConfigFiles = [];
832
908
  extendsImportData.map((importData) => {
833
909
  const { importPath: importPath } = importData;
834
- // TODO
835
- // - validate extends configs
836
- const filePathAbsolute = resolveImportPath(importData, configFilePath);
837
- assertImportPath(filePathAbsolute, importData, configFilePath);
838
- assertExtendsImportPath(importPath, filePathAbsolute, configFilePath);
910
+ const filePathAbsoluteFilesystem = resolveImportPath(importData, configFilePath);
911
+ assertImportPath(filePathAbsoluteFilesystem, importData, configFilePath);
912
+ assertExtendsImportPath(importPath, filePathAbsoluteFilesystem, configFilePath);
839
913
  // - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
840
- // - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsolute for added clarity
841
- const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsolute, userRootDir);
914
+ // - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsoluteFilesystem for added clarity
915
+ const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir);
916
+ const filePathAbsoluteVite = filePathRelativeToUserRootDir ?? importPath;
842
917
  extendsConfigFiles.push({
843
- filePathAbsolute,
844
- // TODO: fix type cast
845
- filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
918
+ filePathAbsoluteFilesystem,
919
+ filePathAbsoluteVite,
920
+ filePathRelativeToUserRootDir,
921
+ filePathToShowToUser: filePathAbsoluteVite,
846
922
  importPathAbsolute: importPath
847
923
  });
848
924
  });
@@ -852,16 +928,16 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
852
928
  extendsConfigs.push(result.configFile);
853
929
  extendsConfigs.push(...result.extendsConfigs);
854
930
  }));
855
- const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsolute);
931
+ const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
856
932
  return { extendsConfigs, extendsFilePaths };
857
933
  }
858
- function determineFilePathRelativeToUserDir(filePathAbsolute, userRootDir) {
859
- (0, utils_js_1.assertPosixPath)(filePathAbsolute);
934
+ function determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir) {
935
+ (0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
860
936
  (0, utils_js_1.assertPosixPath)(userRootDir);
861
- if (!filePathAbsolute.startsWith(userRootDir)) {
937
+ if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
862
938
  return null;
863
939
  }
864
- let filePathRelativeToUserRootDir = filePathAbsolute.slice(userRootDir.length);
940
+ let filePathRelativeToUserRootDir = filePathAbsoluteFilesystem.slice(userRootDir.length);
865
941
  if (!filePathRelativeToUserRootDir.startsWith('/'))
866
942
  filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
867
943
  return filePathRelativeToUserRootDir;
@@ -878,14 +954,14 @@ function assertExtendsImportPath(importPath, filePath, configFilePath) {
878
954
  });
879
955
  }
880
956
  else {
881
- (0, utils_js_1.assertWarning)(false, `${(0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(configFilePath)} uses ${picocolors_1.default.cyan('extends')} to inherit from ${picocolors_1.default.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this feature.`, { onlyOnce: true });
957
+ (0, utils_js_1.assertWarning)(false, `${configFilePath.filePathToShowToUser} uses ${picocolors_1.default.cyan('extends')} to inherit from ${picocolors_1.default.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this feature.`, { onlyOnce: true });
882
958
  }
883
959
  }
884
960
  function getExtendsImportData(configFileExports, configFilePath) {
885
- const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(configFilePath);
961
+ const { filePathToShowToUser } = configFilePath;
886
962
  (0, assertExports_js_1.assertExportsOfConfigFile)(configFileExports, filePathToShowToUser);
887
963
  const defaultExports = configFileExports.default;
888
- const wrongUsage = `${filePathToShowToUser} sets the config 'extends' to an invalid value, see https://vike.dev/extends`;
964
+ const wrongUsage = `${filePathToShowToUser} sets the config ${picocolors_1.default.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
889
965
  let extendList;
890
966
  if (!('extends' in defaultExports)) {
891
967
  return [];
@@ -906,38 +982,6 @@ function getExtendsImportData(configFileExports, configFilePath) {
906
982
  });
907
983
  return extendsImportData;
908
984
  }
909
- // TODO: re-use this
910
- function handleUserFileError(err, isDev) {
911
- // Properly handle error during transpilation so that we can use assertUsage() during transpilation
912
- if (isDev) {
913
- throw err;
914
- }
915
- else {
916
- // Avoid ugly error format:
917
- // ```
918
- // [vike:importUserCode] Could not load virtual:vike:importUserCode:server: [vike@0.4.70][Wrong Usage] /pages/+config.ts sets the config 'onRenderHtml' to the value './+config/onRenderHtml-i-dont-exist.js' but no file was found at /home/rom/code/vike/examples/v1/pages/+config/onRenderHtml-i-dont-exist.js
919
- // Error: [vike@0.4.70][Wrong Usage] /pages/+config.ts sets the config 'onRenderHtml' to the value './+config/onRenderHtml-i-dont-exist.js' but no file was found at /home/rom/code/vike/examples/v1/pages/+config/onRenderHtml-i-dont-exist.js
920
- // at ...
921
- // at ...
922
- // at ...
923
- // at ...
924
- // at ...
925
- // at ...
926
- // code: 'PLUGIN_ERROR',
927
- // plugin: 'vike:importUserCode',
928
- // hook: 'load',
929
- // watchFiles: [
930
- // '/home/rom/code/vike/vike/dist/esm/node/importBuild.js',
931
- // '\x00virtual:vike:importUserCode:server'
932
- // ]
933
- // }
934
- //  ELIFECYCLE  Command failed with exit code 1.
935
- // ```
936
- console.log('');
937
- console.error(err);
938
- process.exit(1);
939
- }
940
- }
941
985
  function isGlobalConfig(configName) {
942
986
  if (configName === 'prerender')
943
987
  return false;
@@ -947,15 +991,15 @@ function isGlobalConfig(configName) {
947
991
  function getConfigNamesGlobal() {
948
992
  return Object.keys(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal);
949
993
  }
950
- function assertConfigExists(configName, configNamesRelevant, definedByFile) {
994
+ function assertConfigExists(configName, configNamesRelevant, filePathToShowToUser) {
951
995
  const configNames = [...configNamesRelevant, ...getConfigNamesGlobal()];
952
996
  if (configNames.includes(configName))
953
997
  return;
954
- handleUnknownConfig(configName, configNames, definedByFile);
998
+ handleUnknownConfig(configName, configNames, filePathToShowToUser);
955
999
  (0, utils_js_1.assert)(false);
956
1000
  }
957
- function handleUnknownConfig(configName, configNames, definedByFile) {
958
- let errMsg = `${definedByFile} defines an unknown config ${picocolors_1.default.cyan(configName)}`;
1001
+ function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
1002
+ let errMsg = `${filePathToShowToUser} defines an unknown config ${picocolors_1.default.cyan(configName)}`;
959
1003
  let configNameSimilar = null;
960
1004
  if (configName === 'page') {
961
1005
  configNameSimilar = 'Page';
@@ -987,11 +1031,11 @@ function determineRouteFilesystem(locationId, configValueSources) {
987
1031
  if (configFilesystemRoutingRoot) {
988
1032
  const routingRoot = getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName);
989
1033
  if (routingRoot) {
990
- const { filesystemRoutingRootEffect, filesystemRoutingRootDefinedAt } = routingRoot;
1034
+ const { filesystemRoutingRootEffect /*, filesystemRoutingRootDefinedAt*/ } = routingRoot;
991
1035
  const debugInfo = { locationId, routeFilesystem: filesystemRouteString, configFilesystemRoutingRoot };
992
1036
  (0, utils_js_1.assert)(filesystemRouteString.startsWith(filesystemRoutingRootEffect.before), debugInfo);
993
1037
  filesystemRouteString = (0, filesystemRouting_js_1.applyFilesystemRoutingRootEffect)(filesystemRouteString, filesystemRoutingRootEffect);
994
- filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${filesystemRoutingRootDefinedAt})`;
1038
+ // filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${filesystemRoutingRootDefinedAt})`
995
1039
  }
996
1040
  }
997
1041
  (0, utils_js_1.assert)(filesystemRouteString.startsWith('/'));
@@ -1006,10 +1050,10 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
1006
1050
  // Eagerly loaded since it's config-only
1007
1051
  (0, utils_js_1.assert)('value' in configFilesystemRoutingRoot);
1008
1052
  const { value } = configFilesystemRoutingRoot;
1009
- const configDefinedAt = getConfigSourceDefinedAtString(configName, configFilesystemRoutingRoot);
1053
+ const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configFilesystemRoutingRoot);
1010
1054
  (0, utils_js_1.assertUsage)(typeof value === 'string', `${configDefinedAt} should be a string`);
1011
1055
  (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
- const { filePathRelativeToUserRootDir } = configFilesystemRoutingRoot.definedAtInfo;
1056
+ const { filePathRelativeToUserRootDir } = configFilesystemRoutingRoot.definedAt;
1013
1057
  (0, utils_js_1.assert)(filePathRelativeToUserRootDir);
1014
1058
  const before = (0, filesystemRouting_js_1.getFilesystemRouteString)((0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir));
1015
1059
  const after = value;
@@ -1021,17 +1065,17 @@ function determineIsErrorPage(routeFilesystem) {
1021
1065
  return routeFilesystem.split('/').includes('_error');
1022
1066
  }
1023
1067
  function resolveImportPath(importData, importerFilePath) {
1024
- const importerFilePathAbsolute = importerFilePath.filePathAbsolute;
1068
+ const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
1025
1069
  (0, utils_js_1.assertPosixPath)(importerFilePathAbsolute);
1026
1070
  const cwd = path_1.default.posix.dirname(importerFilePathAbsolute);
1027
- // filePathAbsolute is expected to be null when importData.importPath is a Vite path alias
1028
- const filePathAbsolute = (0, utils_js_1.requireResolve)(importData.importPath, cwd);
1029
- return filePathAbsolute;
1071
+ // filePathAbsoluteFilesystem is expected to be null when importData.importPath is a Vite path alias
1072
+ const filePathAbsoluteFilesystem = (0, utils_js_1.requireResolve)(importData.importPath, cwd);
1073
+ return filePathAbsoluteFilesystem;
1030
1074
  }
1031
- function assertImportPath(filePathAbsolute, importData, importerFilePath) {
1075
+ function assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath) {
1032
1076
  const { importPath: importPath, importStringWasGenerated, importString } = importData;
1033
- const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(importerFilePath);
1034
- if (!filePathAbsolute) {
1077
+ const { filePathToShowToUser } = importerFilePath;
1078
+ if (!filePathAbsoluteFilesystem) {
1035
1079
  const importPathString = picocolors_1.default.cyan(`'${importPath}'`);
1036
1080
  const errIntro = importStringWasGenerated
1037
1081
  ? `The import path ${importPathString} in ${filePathToShowToUser}`
@@ -1074,7 +1118,6 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
1074
1118
  configValues[configName] = {
1075
1119
  value,
1076
1120
  definedAt: {
1077
- isCumulative: true,
1078
1121
  files: sources.map((source) => getDefinedAtFile(source))
1079
1122
  }
1080
1123
  };
@@ -1082,18 +1125,23 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
1082
1125
  });
1083
1126
  return configValues;
1084
1127
  }
1128
+ function getDefinedAtFile(configValueSource) {
1129
+ return {
1130
+ filePathToShowToUser: configValueSource.definedAt.filePathToShowToUser,
1131
+ fileExportPathToShowToUser: configValueSource.definedAt.fileExportPathToShowToUser
1132
+ };
1133
+ }
1134
+ function getDefinedAt(configValueSource) {
1135
+ return getDefinedAtFile(configValueSource);
1136
+ }
1085
1137
  function mergeCumulative(configName, configValueSources) {
1086
1138
  const valuesArr = [];
1087
1139
  const valuesSet = [];
1088
1140
  let configValueSourcePrevious = null;
1089
1141
  configValueSources.forEach((configValueSource) => {
1090
- const configDefinedAt = getConfigSourceDefinedAtString(configName, configValueSource);
1091
- const configNameColored = picocolors_1.default.cyan(configName);
1092
- // We could, in principle, also support cumulative values to be defined in +${configName}.js but it ins't completely trivial to implement
1093
- (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.)`);
1094
- /* This is more confusing than adding value. For example, this explanation shouldn't be shown for the passToClient config.
1095
- const explanation = `(Because the values of ${configNameColored} are cumulative and therefore merged together.)` as const
1096
- */
1142
+ const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configValueSource);
1143
+ // We could, in principle, also support cumulative for values that aren't loaded at config-time but it isn't completely trivial to implement.
1144
+ (0, utils_js_1.assert)('value' in configValueSource);
1097
1145
  // Make sure configValueSource.value is serializable
1098
1146
  (0, getVirtualFilePageConfigs_js_1.getConfigValueSerialized)(configValueSource.value, configName, getDefinedAt(configValueSource));
1099
1147
  const assertNoMixing = (isSet) => {
@@ -1105,7 +1153,7 @@ function mergeCumulative(configName, configValueSources) {
1105
1153
  if (vals2.length === 0)
1106
1154
  return;
1107
1155
  (0, utils_js_1.assert)(configValueSourcePrevious);
1108
- const configPreviousDefinedAt = getConfigSourceDefinedAtString(configName, configValueSourcePrevious, undefined, false);
1156
+ const configPreviousDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configValueSourcePrevious);
1109
1157
  (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).`);
1110
1158
  };
1111
1159
  const { value } = configValueSource;
@@ -1136,30 +1184,3 @@ function mergeCumulative(configName, configValueSources) {
1136
1184
  }
1137
1185
  (0, utils_js_1.assert)(false);
1138
1186
  }
1139
- // TODO: rename
1140
- // TODO: refactor
1141
- function getConfigSourceDefinedAtString(configName, { definedAtInfo }, isEffect = undefined, sentenceBegin = true) {
1142
- return (0, utils_js_2.getConfigDefinedAtString)(configName, {
1143
- definedAt: {
1144
- isEffect,
1145
- file: {
1146
- filePathToShowToUser: getDefinedAtFilePathToShowToUser(definedAtInfo),
1147
- fileExportPath: definedAtInfo.fileExportPath
1148
- }
1149
- }
1150
- }, sentenceBegin);
1151
- }
1152
- function getDefinedAtFilePathToShowToUser(definedAtInfo) {
1153
- return definedAtInfo.filePathRelativeToUserRootDir ?? definedAtInfo.importPathAbsolute;
1154
- }
1155
- function getDefinedAtFile(source) {
1156
- return {
1157
- filePathToShowToUser: getDefinedAtFilePathToShowToUser(source.definedAtInfo),
1158
- fileExportPath: source.definedAtInfo.fileExportPath
1159
- };
1160
- }
1161
- function getDefinedAt(configValueSource) {
1162
- return {
1163
- file: getDefinedAtFile(configValueSource)
1164
- };
1165
- }