vike 0.4.143 → 0.4.144-commit-e40e9b1

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 (182) hide show
  1. package/dist/cjs/node/plugin/index.js +2 -2
  2. package/dist/cjs/node/plugin/plugins/buildConfig.js +1 -1
  3. package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
  4. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +31 -30
  5. package/dist/cjs/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
  6. package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +19 -10
  7. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +2 -2
  8. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
  9. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -4
  10. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +228 -186
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -35
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +60 -95
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +12 -5
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +18 -0
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +14 -13
  17. package/dist/cjs/node/plugin/shared/findPageFiles.js +2 -1
  18. package/dist/cjs/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +1 -12
  19. package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
  20. package/dist/cjs/node/plugin/utils.js +2 -3
  21. package/dist/cjs/node/prerender/runPrerender.js +18 -20
  22. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  23. package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
  24. package/dist/cjs/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
  25. package/dist/cjs/node/runtime/renderPage/log404/index.js +10 -5
  26. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
  27. package/dist/cjs/node/runtime/renderPage.js +1 -1
  28. package/dist/cjs/node/shared/getClientEntryFilePath.js +1 -7
  29. package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -1
  30. package/dist/cjs/shared/error-page.js +1 -1
  31. package/dist/cjs/shared/getPageFiles/getExports.js +8 -11
  32. package/dist/cjs/shared/getPageFiles/parseGlobResults.js +10 -44
  33. package/dist/cjs/shared/hooks/getHook.js +3 -1
  34. package/dist/cjs/shared/page-configs/assertExports.js +60 -0
  35. package/dist/cjs/shared/page-configs/getExportPath.js +9 -10
  36. package/dist/cjs/shared/page-configs/loadConfigValues.js +18 -0
  37. package/dist/cjs/shared/page-configs/serialize/PageConfigSerialized.js +2 -0
  38. package/dist/cjs/shared/page-configs/serialize/assertPageConfigs.js +19 -0
  39. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +56 -0
  40. package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +65 -0
  41. package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +58 -0
  42. package/dist/cjs/shared/page-configs/utils.js +65 -42
  43. package/dist/cjs/shared/route/loadPageRoutes.js +12 -15
  44. package/dist/cjs/shared/route/resolveRedirects.js +1 -1
  45. package/dist/cjs/shared/route/resolveRouteFunction.js +1 -0
  46. package/dist/cjs/shared/utils.js +0 -1
  47. package/dist/cjs/utils/getOutDirs.js +25 -18
  48. package/dist/cjs/utils/getValuePrintable.js +1 -1
  49. package/dist/cjs/utils/objectAssign.js +3 -1
  50. package/dist/cjs/utils/projectInfo.js +1 -1
  51. package/dist/cjs/utils/{resolve.js → requireResolve.js} +3 -3
  52. package/dist/cjs/utils/warnIfErrorIsNotObject.js +1 -1
  53. package/dist/esm/__internal/index.d.ts +3 -3
  54. package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -2
  55. package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +2 -2
  56. package/dist/esm/client/client-routing-runtime/getPageId.d.ts +2 -2
  57. package/dist/esm/client/client-routing-runtime/useClientRouter.js +3 -3
  58. package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
  59. package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
  60. package/dist/esm/client/shared/loadPageFilesClientSide.d.ts +2 -2
  61. package/dist/esm/client/shared/loadPageFilesClientSide.js +2 -2
  62. package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
  63. package/dist/esm/node/plugin/index.js +3 -2
  64. package/dist/esm/node/plugin/plugins/buildConfig.js +2 -2
  65. package/dist/esm/node/plugin/plugins/config/index.js +2 -2
  66. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +31 -30
  67. package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.d.ts +13 -2
  68. package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
  69. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +20 -11
  70. package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -3
  71. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +19 -2
  72. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
  73. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +5 -4
  74. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -4
  75. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +4 -4
  76. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +229 -187
  77. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +1 -1
  78. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -32
  79. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +3 -3
  80. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +60 -95
  81. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.d.ts +3 -3
  82. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +12 -5
  83. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +7 -0
  84. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +15 -0
  85. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.d.ts +18 -6
  86. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
  87. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
  88. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +14 -13
  89. package/dist/esm/node/plugin/shared/findPageFiles.js +3 -2
  90. package/dist/esm/node/plugin/shared/{getConfigValueSource.d.ts → getConfigValueSourcesRelevant.d.ts} +0 -2
  91. package/dist/esm/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +0 -11
  92. package/dist/esm/node/plugin/shared/loggerNotProd.js +2 -2
  93. package/dist/esm/node/plugin/utils.d.ts +1 -2
  94. package/dist/esm/node/plugin/utils.js +2 -3
  95. package/dist/esm/node/prerender/runPrerender.js +20 -22
  96. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  97. package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
  98. package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +2 -2
  99. package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
  100. package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
  101. package/dist/esm/node/runtime/renderPage/createHttpResponseObject.d.ts +2 -2
  102. package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +2 -2
  103. package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +2 -2
  104. package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
  105. package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.d.ts +2 -2
  106. package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
  107. package/dist/esm/node/runtime/renderPage/log404/index.js +10 -5
  108. package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
  109. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +13 -13
  110. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
  111. package/dist/esm/node/runtime/renderPage.js +1 -1
  112. package/dist/esm/node/shared/getClientEntryFilePath.d.ts +2 -2
  113. package/dist/esm/node/shared/getClientEntryFilePath.js +2 -8
  114. package/dist/esm/shared/addIs404ToPageProps.d.ts +2 -2
  115. package/dist/esm/shared/addUrlComputedProps.d.ts +4 -2
  116. package/dist/esm/shared/assertPageContextProvidedByUser.js +1 -1
  117. package/dist/esm/shared/error-page.d.ts +3 -3
  118. package/dist/esm/shared/error-page.js +1 -1
  119. package/dist/esm/shared/getPageFiles/analyzeClientSide.d.ts +2 -2
  120. package/dist/esm/shared/getPageFiles/getExports.d.ts +3 -4
  121. package/dist/esm/shared/getPageFiles/getExports.js +7 -10
  122. package/dist/esm/shared/getPageFiles/parseGlobResults.d.ts +3 -3
  123. package/dist/esm/shared/getPageFiles/parseGlobResults.js +9 -43
  124. package/dist/esm/shared/getPageFiles/setPageFiles.d.ts +3 -3
  125. package/dist/esm/shared/hooks/getHook.js +3 -1
  126. package/dist/esm/shared/page-configs/Config.d.ts +201 -14
  127. package/dist/esm/shared/page-configs/PageConfig.d.ts +80 -73
  128. package/dist/esm/shared/page-configs/assertExports.d.ts +6 -0
  129. package/dist/esm/shared/page-configs/assertExports.js +54 -0
  130. package/dist/esm/shared/page-configs/findPageConfig.d.ts +2 -2
  131. package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
  132. package/dist/esm/shared/page-configs/getExportPath.js +9 -10
  133. package/dist/esm/shared/page-configs/loadConfigValues.d.ts +3 -0
  134. package/dist/esm/shared/page-configs/loadConfigValues.js +15 -0
  135. package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +32 -0
  136. package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.js +1 -0
  137. package/dist/esm/shared/page-configs/serialize/assertPageConfigs.d.ts +5 -0
  138. package/dist/esm/shared/page-configs/serialize/assertPageConfigs.js +16 -0
  139. package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.d.ts +4 -0
  140. package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +50 -0
  141. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +7 -0
  142. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +62 -0
  143. package/dist/esm/shared/page-configs/serialize/serializeConfigValue.d.ts +8 -0
  144. package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +52 -0
  145. package/dist/esm/shared/page-configs/utils.d.ts +21 -14
  146. package/dist/esm/shared/page-configs/utils.js +64 -41
  147. package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
  148. package/dist/esm/shared/route/index.d.ts +3 -3
  149. package/dist/esm/shared/route/loadPageRoutes.d.ts +2 -2
  150. package/dist/esm/shared/route/loadPageRoutes.js +13 -16
  151. package/dist/esm/shared/route/resolveRedirects.js +1 -1
  152. package/dist/esm/shared/route/resolveRouteFunction.js +1 -0
  153. package/dist/esm/shared/types.d.ts +8 -6
  154. package/dist/esm/shared/utils.d.ts +0 -1
  155. package/dist/esm/shared/utils.js +0 -1
  156. package/dist/esm/types/index.d.ts +2 -1
  157. package/dist/esm/utils/getOutDirs.d.ts +0 -2
  158. package/dist/esm/utils/getOutDirs.js +24 -17
  159. package/dist/esm/utils/getValuePrintable.js +1 -1
  160. package/dist/esm/utils/objectAssign.js +3 -1
  161. package/dist/esm/utils/projectInfo.d.ts +1 -1
  162. package/dist/esm/utils/projectInfo.js +1 -1
  163. package/dist/esm/utils/requireResolve.d.ts +2 -0
  164. package/dist/esm/utils/{resolve.js → requireResolve.js} +2 -2
  165. package/dist/esm/utils/warnIfErrorIsNotObject.js +1 -1
  166. package/package.json +2 -2
  167. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -13
  168. package/dist/cjs/shared/getPageFiles/assertPageConfigs.js +0 -19
  169. package/dist/cjs/shared/page-configs/loadPageCode.js +0 -63
  170. package/dist/cjs/utils/assertDefaultExport.js +0 -53
  171. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.d.ts +0 -3
  172. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -10
  173. package/dist/esm/shared/getPageFiles/assertPageConfigs.d.ts +0 -5
  174. package/dist/esm/shared/getPageFiles/assertPageConfigs.js +0 -16
  175. package/dist/esm/shared/page-configs/loadPageCode.d.ts +0 -3
  176. package/dist/esm/shared/page-configs/loadPageCode.js +0 -57
  177. package/dist/esm/utils/assertDefaultExport.d.ts +0 -8
  178. package/dist/esm/utils/assertDefaultExport.js +0 -47
  179. package/dist/esm/utils/resolve.d.ts +0 -2
  180. /package/dist/cjs/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
  181. /package/dist/esm/shared/getPageFiles/{assertExports.d.ts → assert_exports_old_design.d.ts} +0 -0
  182. /package/dist/esm/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
@@ -18,6 +18,7 @@ const removeSuperfluousViteLog_js_1 = require("../../../shared/loggerVite/remove
18
18
  const getFilePathToShowToUser_js_1 = require("./getFilePathToShowToUser.js");
19
19
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
20
20
  const utils_js_2 = require("../../../../../shared/page-configs/utils.js");
21
+ const assertExports_js_1 = require("../../../../../shared/page-configs/assertExports.js");
21
22
  const getVirtualFilePageConfigs_js_1 = require("./getVirtualFilePageConfigs.js");
22
23
  (0, utils_js_1.assertIsNotProductionRuntime)();
23
24
  let devServerIsCorrupt = false;
@@ -25,11 +26,11 @@ let wasConfigInvalid = null;
25
26
  let vikeConfigPromise = null;
26
27
  const vikeConfigDependencies = new Set();
27
28
  exports.vikeConfigDependencies = vikeConfigDependencies;
28
- const codeFilesEnv = new Map();
29
- function reloadVikeConfig(userRootDir, extensions) {
29
+ const filesEnv = new Map();
30
+ function reloadVikeConfig(userRootDir, outDirRoot, extensions) {
30
31
  vikeConfigDependencies.clear();
31
- codeFilesEnv.clear();
32
- vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, true, extensions, true);
32
+ filesEnv.clear();
33
+ vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, true, extensions, true);
33
34
  handleReloadSideEffects();
34
35
  }
35
36
  exports.reloadVikeConfig = reloadVikeConfig;
@@ -64,15 +65,15 @@ async function handleReloadSideEffects() {
64
65
  }
65
66
  }
66
67
  }
67
- async function getVikeConfig(userRootDir, isDev, extensions, tolerateInvalidConfig = false) {
68
+ async function getVikeConfig(userRootDir, outDirRoot, isDev, extensions, tolerateInvalidConfig = false) {
68
69
  if (!vikeConfigPromise) {
69
- vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, isDev, extensions, tolerateInvalidConfig);
70
+ vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, extensions, tolerateInvalidConfig);
70
71
  }
71
72
  return await vikeConfigPromise;
72
73
  }
73
74
  exports.getVikeConfig = getVikeConfig;
74
- async function loadInterfaceFiles(userRootDir, isDev, extensions) {
75
- const plusFiles = await findPlusFiles(userRootDir, isDev, extensions);
75
+ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
76
+ const plusFiles = await findPlusFiles(userRootDir, [outDirRoot], isDev, extensions);
76
77
  const configFiles = [];
77
78
  const valueFiles = [];
78
79
  plusFiles.forEach((f) => {
@@ -88,7 +89,8 @@ async function loadInterfaceFiles(userRootDir, isDev, extensions) {
88
89
  await Promise.all(configFiles.map(async ({ filePathAbsolute, filePathRelativeToUserRootDir }) => {
89
90
  const configFilePath = {
90
91
  filePathAbsolute: filePathAbsolute,
91
- filePathRelativeToUserRootDir: filePathRelativeToUserRootDir
92
+ filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
93
+ importPathAbsolute: null
92
94
  };
93
95
  const { configFile, extendsConfigs } = await loadConfigFile(configFilePath, userRootDir, []);
94
96
  const interfaceFile = getInterfaceFileFromConfigFile(configFile, false);
@@ -102,27 +104,28 @@ async function loadInterfaceFiles(userRootDir, isDev, extensions) {
102
104
  }));
103
105
  // Value files
104
106
  await Promise.all(valueFiles.map(async ({ filePathAbsolute, filePathRelativeToUserRootDir }) => {
105
- const configNameDefault = getConfigName(filePathRelativeToUserRootDir);
106
- (0, utils_js_1.assert)(configNameDefault);
107
+ const configName = getConfigName(filePathRelativeToUserRootDir);
108
+ (0, utils_js_1.assert)(configName);
107
109
  const interfaceFile = {
108
110
  filePath: {
109
111
  filePathRelativeToUserRootDir,
110
- filePathAbsolute
112
+ filePathAbsolute,
113
+ importPathAbsolute: null
111
114
  },
112
115
  configMap: {
113
- [configNameDefault]: {}
116
+ [configName]: {}
114
117
  },
115
118
  isConfigFile: false,
116
119
  isValueFile: true,
117
- configNameDefault
120
+ configName
118
121
  };
119
122
  {
120
123
  // We don't have access to custom config definitions yet
121
- // - We load +someCustomConifg.js later
124
+ // - We load +{configName}.js later
122
125
  // - But we do need to eagerly load +meta.js (to get all the custom config definitions)
123
- const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn, configNameDefault);
126
+ const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn, configName);
124
127
  if (configDef?.env === 'config-only') {
125
- await loadValueFile(interfaceFile, configNameDefault, userRootDir);
128
+ await loadValueFile(interfaceFile, configName, userRootDir);
126
129
  }
127
130
  }
128
131
  {
@@ -142,14 +145,13 @@ function getConfigDefinition(configDefinitionsRelevant, configName, definedByFil
142
145
  function getConfigDefinitionOptional(configDefinitions, configName) {
143
146
  return configDefinitions[configName] ?? null;
144
147
  }
145
- async function loadValueFile(interfaceValueFile, configNameDefault, userRootDir) {
148
+ async function loadValueFile(interfaceValueFile, configName, userRootDir) {
146
149
  const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath, true, userRootDir);
147
- (0, utils_js_1.assertDefaultExportUnknown)(fileExports, (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceValueFile.filePath));
148
- Object.entries(fileExports).forEach(([configName, configValue]) => {
149
- if (configName === 'default') {
150
- configName = configNameDefault;
151
- }
152
- interfaceValueFile.configMap[configName] = { configValue };
150
+ const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceValueFile.filePath);
151
+ (0, assertExports_js_1.assertExportsOfValueFile)(fileExports, filePathToShowToUser, configName);
152
+ Object.entries(fileExports).forEach(([exportName, configValue]) => {
153
+ const configName_ = exportName === 'default' ? configName : exportName;
154
+ interfaceValueFile.configMap[configName_] = { configValue };
153
155
  });
154
156
  }
155
157
  function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
@@ -162,19 +164,19 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
162
164
  isConfigExtend,
163
165
  extendsFilePaths
164
166
  };
165
- const interfaceFilePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(filePath);
166
- (0, utils_js_1.assertDefaultExportObject)(fileExports, interfaceFilePathToShowToUser);
167
+ const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(filePath);
168
+ (0, assertExports_js_1.assertExportsOfConfigFile)(fileExports, filePathToShowToUser);
167
169
  Object.entries(fileExports.default).forEach(([configName, configValue]) => {
168
170
  interfaceFile.configMap[configName] = { configValue };
169
171
  });
170
172
  return interfaceFile;
171
173
  }
172
- async function loadVikeConfig_withErrorHandling(userRootDir, isDev, extensions, tolerateInvalidConfig) {
174
+ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, extensions, tolerateInvalidConfig) {
173
175
  let hasError = false;
174
176
  let ret;
175
177
  let err;
176
178
  try {
177
- ret = await loadVikeConfig(userRootDir, isDev, extensions);
179
+ ret = await loadVikeConfig(userRootDir, outDirRoot, isDev, extensions);
178
180
  }
179
181
  catch (err_) {
180
182
  hasError = true;
@@ -202,8 +204,7 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, extensions,
202
204
  const dummyData = {
203
205
  pageConfigs: [],
204
206
  pageConfigGlobal: {
205
- onPrerenderStart: null,
206
- onBeforeRoute: null
207
+ configValueSources: {}
207
208
  },
208
209
  globalVikeConfig: {}
209
210
  };
@@ -211,8 +212,8 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, extensions,
211
212
  }
212
213
  }
213
214
  }
214
- async function loadVikeConfig(userRootDir, isDev, extensions) {
215
- const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, isDev, extensions);
215
+ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
216
+ const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions);
216
217
  const { globalVikeConfig, pageConfigGlobal } = getGlobalConfigs(interfaceFilesByLocationId, userRootDir);
217
218
  const pageConfigs = await Promise.all(Object.entries(interfaceFilesByLocationId)
218
219
  .filter(([_pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
@@ -223,18 +224,18 @@ async function loadVikeConfig(userRootDir, isDev, extensions) {
223
224
  await Promise.all(getInterfaceFileList(interfaceFilesRelevant).map(async (interfaceFile) => {
224
225
  if (!interfaceFile.isValueFile)
225
226
  return;
226
- const { configNameDefault } = interfaceFile;
227
- if (isGlobalConfig(configNameDefault))
227
+ const { configName } = interfaceFile;
228
+ if (isGlobalConfig(configName))
228
229
  return;
229
- const configDef = getConfigDefinition(configDefinitionsRelevant, configNameDefault, (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceFile.filePath));
230
+ const configDef = getConfigDefinition(configDefinitionsRelevant, configName, (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceFile.filePath));
230
231
  if (configDef.env !== 'config-only')
231
232
  return;
232
233
  const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
233
234
  if (isAlreadyLoaded)
234
235
  return;
235
236
  // Value files for built-in confg-only configs should have already been loaded at loadInterfaceFiles()
236
- (0, utils_js_1.assert)(!(configNameDefault in configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn));
237
- await loadValueFile(interfaceFile, configNameDefault, userRootDir);
237
+ (0, utils_js_1.assert)(!(configName in configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn));
238
+ await loadValueFile(interfaceFile, configName, userRootDir);
238
239
  }));
239
240
  const configValueSources = {};
240
241
  (0, utils_js_1.objectEntries)(configDefinitionsRelevant)
@@ -246,17 +247,17 @@ async function loadVikeConfig(userRootDir, isDev, extensions) {
246
247
  configValueSources[configName] = sources;
247
248
  });
248
249
  const { routeFilesystem, isErrorPage } = determineRouteFilesystem(locationId, configValueSources);
250
+ applyEffectsAll(configValueSources, configDefinitionsRelevant);
251
+ const configValuesComputed = getComputed(configValueSources, configDefinitionsRelevant);
252
+ const configValues = getConfigValues(configValueSources, configValuesComputed, configDefinitionsRelevant);
249
253
  const pageConfig = {
250
254
  pageId: locationId,
251
255
  isErrorPage,
252
256
  routeFilesystem,
253
257
  configValueSources,
254
- configValues: getConfigValues(configValueSources, configDefinitionsRelevant)
258
+ configValuesComputed,
259
+ configValues
255
260
  };
256
- applyEffects(pageConfig, configDefinitionsRelevant);
257
- pageConfig.configValues = getConfigValues(configValueSources, configDefinitionsRelevant);
258
- applyComputed(pageConfig, configDefinitionsRelevant);
259
- pageConfig.configValues = getConfigValues(configValueSources, configDefinitionsRelevant);
260
261
  return pageConfig;
261
262
  }));
262
263
  // Show error message upon unknown config
@@ -328,24 +329,24 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
328
329
  }
329
330
  const globalVikeConfig = {};
330
331
  const pageConfigGlobal = {
331
- onBeforeRoute: null,
332
- onPrerenderStart: null
332
+ configValueSources: {}
333
333
  };
334
334
  (0, utils_js_1.objectEntries)(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal).forEach(([configName, configDef]) => {
335
335
  const sources = resolveConfigValueSources(configName, configDef, interfaceFilesGlobal, userRootDir);
336
336
  const configValueSource = sources?.[0];
337
337
  if (!configValueSource)
338
338
  return;
339
- if ((0, utils_js_1.arrayIncludes)((0, utils_js_1.objectKeys)(pageConfigGlobal), configName)) {
339
+ if (configName === 'onBeforeRoute' || configName === 'onPrerenderStart') {
340
340
  (0, utils_js_1.assert)(!('value' in configValueSource));
341
- pageConfigGlobal[configName] = configValueSource;
341
+ pageConfigGlobal.configValueSources[configName] = [configValueSource];
342
342
  }
343
343
  else {
344
344
  (0, utils_js_1.assert)('value' in configValueSource);
345
345
  if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
346
346
  return;
347
- (0, utils_js_1.assert)(!configValueSource.isComputed);
348
- (0, utils_js_1.assertWarning)(false, `Being able to define config ${picocolors_1.default.cyan(configName)} in ${configValueSource.definedAtInfo.filePath} is experimental and will likely be removed. Define the config ${picocolors_1.default.cyan(configName)} in vike's Vite plugin options instead.`, { onlyOnce: true });
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 });
349
350
  globalVikeConfig[configName] = configValueSource.value;
350
351
  }
351
352
  });
@@ -370,8 +371,8 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
370
371
  {
371
372
  const interfaceValueFiles = interfaceFilesDefiningConfig
372
373
  .filter((interfaceFile) => interfaceFile.isValueFile &&
373
- // We consider side-effect exports (e.g. `export { frontmatter }` of .mdx files) later (i.e. with less priority)
374
- interfaceFile.configNameDefault === configName)
374
+ // We consider side-effect configs (e.g. `export { frontmatter }` of .mdx files) later (i.e. with less priority)
375
+ interfaceFile.configName === configName)
375
376
  .sort(makeOrderDeterministic);
376
377
  const interfaceConfigFiles = interfaceFilesDefiningConfig
377
378
  .filter((interfaceFile) => interfaceFile.isConfigFile &&
@@ -381,9 +382,9 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
381
382
  const interfaceValueFile = interfaceValueFiles[0];
382
383
  const interfaceConfigFile = interfaceConfigFiles[0];
383
384
  // Make this value:
384
- // /pages/some-page/+someConfig.js > `export default`
385
+ // /pages/some-page/+{configName}.js > `export default`
385
386
  // override that value:
386
- // /pages/some-page/+config > `export default { someConfig }`
387
+ // /pages/some-page/+config.h.js > `export default { someConfig }`
387
388
  const interfaceFileWinner = interfaceValueFile ?? interfaceConfigFile;
388
389
  if (interfaceFileWinner) {
389
390
  const interfaceFilesOverriden = [...interfaceValueFiles, ...interfaceConfigFiles].filter((f) => f !== interfaceFileWinner);
@@ -397,8 +398,8 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
397
398
  // Side-effect configs such as `export { frontmatter }` in .mdx files
398
399
  interfaceFilesDefiningConfig
399
400
  .filter((interfaceFile) => interfaceFile.isValueFile &&
400
- // Is side-effect export
401
- interfaceFile.configNameDefault !== configName)
401
+ // Is side-effect config
402
+ interfaceFile.configName !== configName)
402
403
  .forEach((interfaceValueFileSideEffect) => {
403
404
  add(interfaceValueFileSideEffect);
404
405
  });
@@ -428,66 +429,57 @@ function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden,
428
429
  interfaceFilesOverriden.forEach((interfaceFileLoser) => {
429
430
  const configValueSourceWinner = getConfigValueSource(configName, interfaceFileWinner, configDef, userRootDir);
430
431
  const configValueSourceLoser = getConfigValueSource(configName, interfaceFileLoser, configDef, userRootDir);
431
- (0, utils_js_1.assertWarning)(false, `${(0, utils_js_2.getConfigDefinedAtString)(configName, configValueSourceLoser, true)} overriden by another ${(0, utils_js_2.getConfigDefinedAtString)(configName, configValueSourceWinner, false)}, remove one of the two`, { onlyOnce: false });
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 });
432
433
  });
433
434
  }
434
435
  function isInterfaceFileUserLand(interfaceFile) {
435
436
  return (interfaceFile.isConfigFile && !interfaceFile.isConfigExtend) || interfaceFile.isValueFile;
436
437
  }
437
438
  function getConfigValueSource(configName, interfaceFile, configDef, userRootDir) {
438
- // TODO: rethink file paths of ConfigElement
439
- const configFilePath = interfaceFile.filePath.filePathRelativeToUserRootDir ?? interfaceFile.filePath.filePathAbsolute;
440
439
  const conf = interfaceFile.configMap[configName];
441
440
  (0, utils_js_1.assert)(conf);
442
441
  const configEnv = configDef.env;
443
- const definedAtInfoConfigFile = {
444
- filePath: configFilePath,
442
+ const definedAtConfigFile = {
443
+ ...interfaceFile.filePath,
445
444
  fileExportPath: ['default', configName]
446
445
  };
447
446
  if (configDef._valueIsFilePath) {
448
- let filePath;
447
+ let definedAtInfo;
448
+ let valueFilePath;
449
449
  if (interfaceFile.isConfigFile) {
450
450
  const { configValue } = conf;
451
- const import_ = getImport(configValue, interfaceFile.filePath, userRootDir);
452
- const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, { definedAtInfo: definedAtInfoConfigFile }, true);
451
+ const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
452
+ const configDefinedAt = getConfigSourceDefinedAtString(configName, { definedAtInfo: definedAtConfigFile });
453
453
  (0, utils_js_1.assertUsage)(import_, `${configDefinedAt} should be an import`);
454
- filePath = import_.importFilePath;
454
+ valueFilePath = import_.filePathRelativeToUserRootDir ?? import_.importPathAbsolute;
455
+ definedAtInfo = import_;
455
456
  }
456
457
  else {
457
458
  (0, utils_js_1.assert)(interfaceFile.isValueFile);
458
- filePath =
459
- interfaceFile.filePath.filePathRelativeToUserRootDir ??
460
- // Experimental: is this needed? Would it work?
461
- interfaceFile.filePath.filePathAbsolute;
459
+ valueFilePath = interfaceFile.filePath.filePathRelativeToUserRootDir;
460
+ definedAtInfo = {
461
+ ...interfaceFile.filePath,
462
+ fileExportPath: []
463
+ };
462
464
  }
463
465
  const configValueSource = {
464
- value: filePath,
466
+ value: valueFilePath,
465
467
  valueIsFilePath: true,
466
468
  configEnv,
467
469
  valueIsImportedAtRuntime: true,
468
- isComputed: false,
469
- definedAtInfo: {
470
- filePath,
471
- fileExportPath: []
472
- }
470
+ definedAtInfo
473
471
  };
474
472
  return configValueSource;
475
473
  }
476
474
  if (interfaceFile.isConfigFile) {
477
475
  (0, utils_js_1.assert)('configValue' in conf);
478
476
  const { configValue } = conf;
479
- const import_ = getImport(configValue, interfaceFile.filePath, userRootDir);
477
+ const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
480
478
  if (import_) {
481
- const { importFilePath, importFileExportName } = import_;
482
- assertCodeFileEnv(importFilePath, configEnv, configName);
483
479
  const configValueSource = {
484
480
  configEnv,
485
481
  valueIsImportedAtRuntime: true,
486
- isComputed: false,
487
- definedAtInfo: {
488
- filePath: importFilePath,
489
- fileExportPath: [importFileExportName]
490
- }
482
+ definedAtInfo: import_
491
483
  };
492
484
  return configValueSource;
493
485
  }
@@ -496,24 +488,22 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
496
488
  value: configValue,
497
489
  configEnv,
498
490
  valueIsImportedAtRuntime: false,
499
- isComputed: false,
500
- definedAtInfo: definedAtInfoConfigFile
491
+ definedAtInfo: definedAtConfigFile
501
492
  };
502
493
  return configValueSource;
503
494
  }
504
495
  }
505
496
  else if (interfaceFile.isValueFile) {
506
- // TODO: rethink file paths of ConfigElement
507
- const importFilePath = interfaceFile.filePath.filePathRelativeToUserRootDir ?? interfaceFile.filePath.filePathAbsolute;
508
- const importFileExportName = configName === interfaceFile.configNameDefault ? 'default' : configName;
509
497
  const valueAlreadyLoaded = 'configValue' in conf;
510
498
  const configValueSource = {
511
499
  configEnv,
512
500
  valueIsImportedAtRuntime: !valueAlreadyLoaded,
513
- isComputed: false,
514
501
  definedAtInfo: {
515
- filePath: importFilePath,
516
- fileExportPath: [importFileExportName]
502
+ ...interfaceFile.filePath,
503
+ fileExportPath: configName === interfaceFile.configName
504
+ ? []
505
+ : // Side-effect config (e.g. `export { frontmatter }` of .md files)
506
+ [configName]
517
507
  }
518
508
  };
519
509
  if (valueAlreadyLoaded) {
@@ -526,16 +516,17 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
526
516
  }
527
517
  (0, utils_js_1.assert)(false);
528
518
  }
529
- function assertCodeFileEnv(importFilePath, configEnv, configName) {
530
- if (!codeFilesEnv.has(importFilePath)) {
531
- codeFilesEnv.set(importFilePath, []);
519
+ function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
520
+ (0, utils_js_1.assertPosixPath)(filePathForEnvCheck);
521
+ if (!filesEnv.has(filePathForEnvCheck)) {
522
+ filesEnv.set(filePathForEnvCheck, []);
532
523
  }
533
- const codeFileEnv = codeFilesEnv.get(importFilePath);
534
- codeFileEnv.push({ configEnv, configName });
535
- const configDifferentEnv = codeFileEnv.filter((c) => c.configEnv !== configEnv)[0];
524
+ const fileEnv = filesEnv.get(filePathForEnvCheck);
525
+ fileEnv.push({ configEnv, configName });
526
+ const configDifferentEnv = fileEnv.filter((c) => c.configEnv !== configEnv)[0];
536
527
  if (configDifferentEnv) {
537
528
  (0, utils_js_1.assertUsage)(false, [
538
- `${importFilePath} defines the value of configs living in different environments:`,
529
+ `${filePathForEnvCheck} defines the value of configs living in different environments:`,
539
530
  ...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${picocolors_1.default.cyan(c.configName)} which value lives in environment ${picocolors_1.default.cyan(c.configEnv)}`),
540
531
  'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/header-file/import-from-same-file'
541
532
  ].join('\n'));
@@ -553,53 +544,65 @@ function isDefiningPage(interfaceFiles) {
553
544
  function isDefiningPageConfig(configName) {
554
545
  return ['Page', 'route'].includes(configName);
555
546
  }
556
- function getImport(configValue, configFilePath, userRootDir) {
547
+ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
557
548
  if (typeof configValue !== 'string')
558
549
  return null;
559
550
  const importData = (0, replaceImportStatements_js_1.parseImportData)(configValue);
560
551
  if (!importData)
561
552
  return null;
562
- let { importFilePath, importFileExportName } = importData;
563
- if (importFilePath.startsWith('.')) {
553
+ const { importPath, exportName } = importData;
554
+ const filePathAbsolute = resolveImportPath(importData, importerFilePath);
555
+ assertFileEnv(filePathAbsolute ?? importPath, configEnv, configName);
556
+ const fileExportPath = exportName === 'default' || exportName === configName ? [] : [exportName];
557
+ if (importPath.startsWith('.')) {
564
558
  // We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
565
559
  // ```
566
560
  // [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
567
561
  // ```
568
- importFilePath = resolveRelativeCodeFilePath(importData, configFilePath, userRootDir);
562
+ assertImportPath(filePathAbsolute, importData, importerFilePath);
563
+ const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, importerFilePath, userRootDir);
564
+ return {
565
+ exportName,
566
+ fileExportPath,
567
+ filePathAbsolute,
568
+ filePathRelativeToUserRootDir,
569
+ importPathAbsolute: null
570
+ };
569
571
  }
570
572
  else {
571
- // importFilePath can be:
573
+ // importPath can be:
572
574
  // - an npm package import
573
575
  // - a path alias
576
+ return {
577
+ exportName,
578
+ fileExportPath,
579
+ filePathAbsolute,
580
+ filePathRelativeToUserRootDir: null,
581
+ importPathAbsolute: importPath
582
+ };
574
583
  }
575
- return {
576
- importFilePath,
577
- importFileExportName
578
- };
579
584
  }
580
- function resolveRelativeCodeFilePath(importData, configFilePath, userRootDir) {
581
- let importFilePath = resolveImport(importData, configFilePath);
582
- // Make it a Vite path
585
+ function resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, configFilePath, userRootDir) {
583
586
  (0, utils_js_1.assertPosixPath)(userRootDir);
584
- (0, utils_js_1.assertPosixPath)(importFilePath);
585
- if (importFilePath.startsWith(userRootDir)) {
586
- importFilePath = getVitePathFromAbsolutePath(importFilePath, userRootDir);
587
+ let filePathRelativeToUserRootDir;
588
+ if (filePathAbsolute.startsWith(userRootDir)) {
589
+ filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsolute, userRootDir);
587
590
  }
588
591
  else {
589
- (0, utils_js_1.assertUsage)(false, `${(0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(configFilePath)} imports from a relative path ${picocolors_1.default.cyan(importData.importFilePath)} outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
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`);
590
593
  // None of the following works. Seems to be a Vite bug?
591
594
  // /*
592
- // assert(importFilePath.startsWith('/'))
593
- // importFilePath = `/@fs${importFilePath}`
595
+ // assert(filePathAbsolute.startsWith('/'))
596
+ // filePath = `/@fs${filePathAbsolute}`
594
597
  // /*/
595
- // importFilePath = path.posix.relative(userRootDir, importFilePath)
596
- // assert(importFilePath.startsWith('../'))
597
- // importFilePath = '/' + importFilePath
598
+ // filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsolute)
599
+ // assert(filePathRelativeToUserRootDir.startsWith('../'))
600
+ // filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir
598
601
  // //*/
599
602
  }
600
- (0, utils_js_1.assertPosixPath)(importFilePath);
601
- (0, utils_js_1.assert)(importFilePath.startsWith('/'));
602
- return importFilePath;
603
+ (0, utils_js_1.assertPosixPath)(filePathRelativeToUserRootDir);
604
+ (0, utils_js_1.assert)(filePathRelativeToUserRootDir.startsWith('/'));
605
+ return filePathRelativeToUserRootDir;
603
606
  }
604
607
  function getVitePathFromAbsolutePath(filePathAbsolute, root) {
605
608
  (0, utils_js_1.assertPosixPath)(filePathAbsolute);
@@ -660,34 +663,36 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
660
663
  }
661
664
  });
662
665
  }
663
- function applyEffects(pageConfig, configDefinitionsRelevant) {
666
+ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
664
667
  (0, utils_js_1.objectEntries)(configDefinitionsRelevant).forEach(([configName, configDef]) => {
665
668
  if (!configDef.effect)
666
669
  return;
667
670
  // The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
668
671
  // (We could support effect for non config-only by always loading its value at config time, regardless of the config's `env` value.)
669
- (0, utils_js_1.assertWarning)(configDef.env === 'config-only', [
670
- `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)}).`,
671
- 'Reach out to a maintainer if you want to use this in production.'
672
- ].join(' '), { onlyOnce: true });
673
- const configValue = pageConfig.configValueSources[configName]?.[0];
674
- if (!configValue)
672
+ (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')}.`
674
+ ].join(' '));
675
+ const source = configValueSources[configName]?.[0];
676
+ if (!source)
675
677
  return;
678
+ // The config value is eagerly loaded since `configDef.env === 'config-only``
679
+ (0, utils_js_1.assert)('value' in source);
680
+ // Call effect
676
681
  const configModFromEffect = configDef.effect({
677
- configValue: configValue.value,
678
- configDefinedAt: (0, utils_js_2.getConfigDefinedAtString)(configName, configValue, true)
682
+ configValue: source.value,
683
+ configDefinedAt: getConfigSourceDefinedAtString(configName, source)
679
684
  });
680
685
  if (!configModFromEffect)
681
686
  return;
682
- (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
683
- applyEffect(configModFromEffect, configValue, pageConfig.configValueSources);
687
+ (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);
684
689
  });
685
690
  }
686
691
  function applyEffect(configModFromEffect, configValueEffectSource, configValueSources) {
687
- 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.`;
692
+ const notSupported = `Effects currently only supports modifying the the ${picocolors_1.default.cyan('env')} of a config.`;
688
693
  (0, utils_js_1.objectEntries)(configModFromEffect).forEach(([configName, configValue]) => {
689
694
  if (configName === 'meta') {
690
- assertMetaValue(configValue, (0, utils_js_2.getConfigDefinedAtString)(configName, configValueEffectSource, true, 'effect'));
695
+ assertMetaValue(configValue, getConfigSourceDefinedAtString(configName, configValueEffectSource, true));
691
696
  (0, utils_js_1.objectEntries)(configValue).forEach(([configTargetName, configTargetDef]) => {
692
697
  {
693
698
  const keys = Object.keys(configTargetDef);
@@ -697,6 +702,7 @@ function applyEffect(configModFromEffect, configValueEffectSource, configValueSo
697
702
  const envOverriden = configTargetDef.env;
698
703
  const sources = configValueSources[configTargetName];
699
704
  sources?.forEach((configValueSource) => {
705
+ // Apply effect
700
706
  configValueSource.configEnv = envOverriden;
701
707
  });
702
708
  });
@@ -708,30 +714,29 @@ function applyEffect(configModFromEffect, configValueEffectSource, configValueSo
708
714
  }
709
715
  });
710
716
  }
711
- function applyComputed(pageConfig, configDefinitionsRelevant) {
717
+ function getComputed(configValueSources, configDefinitionsRelevant) {
718
+ const configValuesComputed = {};
712
719
  (0, utils_js_1.objectEntries)(configDefinitionsRelevant).forEach(([configName, configDef]) => {
713
- var _a;
714
- const computed = configDef._computed;
715
- if (!computed)
720
+ if (!configDef._computed)
716
721
  return;
717
- const value = computed(pageConfig);
722
+ const value = configDef._computed(configValueSources);
718
723
  if (value === undefined)
719
724
  return;
720
- const configValueSource = {
725
+ configValuesComputed[configName] = {
721
726
  value,
722
- configEnv: configDef.env,
723
- definedAtInfo: null,
724
- isComputed: true,
725
- valueIsImportedAtRuntime: false
727
+ configEnv: configDef.env
726
728
  };
727
- (_a = pageConfig.configValueSources)[configName] ?? (_a[configName] = []);
728
- // Computed values are inserted last: they have the least priority (i.e. computed can be overriden)
729
- pageConfig.configValueSources[configName].push(configValueSource);
730
729
  });
730
+ return configValuesComputed;
731
731
  }
732
- async function findPlusFiles(userRootDir, isDev, extensions) {
732
+ async function findPlusFiles(userRootDir, ignoreDirs, isDev, extensions) {
733
733
  const timeBase = new Date().getTime();
734
734
  (0, utils_js_1.assertPosixPath)(userRootDir);
735
+ const ignorePatterns = [];
736
+ for (const dir of ignoreDirs) {
737
+ (0, utils_js_1.assertPosixPath)(dir);
738
+ ignorePatterns.push(`${path_1.default.posix.relative(userRootDir, dir)}/**`);
739
+ }
735
740
  const result = await (0, fast_glob_1.default)(`**/+*.${utils_js_1.scriptFileExtensions}`, {
736
741
  ignore: [
737
742
  '**/node_modules/**',
@@ -740,7 +745,8 @@ async function findPlusFiles(userRootDir, isDev, extensions) {
740
745
  // +Page.js
741
746
  // +Page.telefunc.js
742
747
  // ```
743
- '**/*.telefunc.*'
748
+ '**/*.telefunc.*',
749
+ ...ignorePatterns
744
750
  ],
745
751
  cwd: userRootDir,
746
752
  dot: false
@@ -748,7 +754,7 @@ async function findPlusFiles(userRootDir, isDev, extensions) {
748
754
  const time = new Date().getTime() - timeBase;
749
755
  if (isDev) {
750
756
  // We only warn in dev, because while building it's expected to take a long time as fast-glob is competing for resources with other tasks
751
- (0, utils_js_1.assertWarning)(time < 2 * 1000, `Crawling your user files took an unexpected long time (${time}ms). Create a new issue on vike's GitHub.`, {
757
+ (0, utils_js_1.assertWarning)(time < 2 * 1000, `Crawling your user files took an unexpected long time (${time}ms). Create a new issue on Vike's GitHub.`, {
752
758
  onlyOnce: 'slow-page-files-search'
753
759
  });
754
760
  }
@@ -798,7 +804,7 @@ function assertNoUnexpectedPlusSign(filePath, fileName) {
798
804
  (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`);
799
805
  }
800
806
  async function loadConfigFile(configFilePath, userRootDir, visited) {
801
- const { filePathAbsolute, filePathRelativeToUserRootDir } = configFilePath;
807
+ const { filePathAbsolute } = configFilePath;
802
808
  assertNoInfiniteLoop(visited, filePathAbsolute);
803
809
  const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(configFilePath, false, userRootDir);
804
810
  const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
@@ -807,10 +813,7 @@ async function loadConfigFile(configFilePath, userRootDir, visited) {
807
813
  ]);
808
814
  const configFile = {
809
815
  fileExports,
810
- filePath: {
811
- filePathRelativeToUserRootDir,
812
- filePathAbsolute
813
- },
816
+ filePath: configFilePath,
814
817
  extendsFilePaths
815
818
  };
816
819
  return { configFile, extendsConfigs };
@@ -827,16 +830,20 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
827
830
  const extendsImportData = getExtendsImportData(configFileExports, configFilePath);
828
831
  const extendsConfigFiles = [];
829
832
  extendsImportData.map((importData) => {
830
- const { importFilePath: importPath } = importData;
833
+ const { importPath: importPath } = importData;
831
834
  // TODO
832
835
  // - validate extends configs
833
- const filePathAbsolute = resolveImport(importData, configFilePath);
836
+ const filePathAbsolute = resolveImportPath(importData, configFilePath);
837
+ assertImportPath(filePathAbsolute, importData, configFilePath);
834
838
  assertExtendsImportPath(importPath, filePathAbsolute, configFilePath);
839
+ // - 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);
835
842
  extendsConfigFiles.push({
836
843
  filePathAbsolute,
837
- // - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
838
- // - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsolute for added clarity
839
- filePathRelativeToUserRootDir: determineFilePathRelativeToUserDir(filePathAbsolute, userRootDir)
844
+ // TODO: fix type cast
845
+ filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
846
+ importPathAbsolute: importPath
840
847
  });
841
848
  });
842
849
  const extendsConfigs = [];
@@ -876,7 +883,7 @@ function assertExtendsImportPath(importPath, filePath, configFilePath) {
876
883
  }
877
884
  function getExtendsImportData(configFileExports, configFilePath) {
878
885
  const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(configFilePath);
879
- (0, utils_js_1.assertDefaultExportObject)(configFileExports, filePathToShowToUser);
886
+ (0, assertExports_js_1.assertExportsOfConfigFile)(configFileExports, filePathToShowToUser);
880
887
  const defaultExports = configFileExports.default;
881
888
  const wrongUsage = `${filePathToShowToUser} sets the config 'extends' to an invalid value, see https://vike.dev/extends`;
882
889
  let extendList;
@@ -974,7 +981,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
974
981
  const configFilesystemRoutingRoot = configValueSources[configName]?.[0];
975
982
  let filesystemRouteString = (0, filesystemRouting_js_1.getFilesystemRouteString)(locationId);
976
983
  if (determineIsErrorPage(filesystemRouteString)) {
977
- return { isErrorPage: true, routeFilesystem: null };
984
+ return { isErrorPage: true, routeFilesystem: undefined };
978
985
  }
979
986
  let filesystemRouteDefinedBy = (0, filesystemRouting_js_1.getFilesystemRouteDefinedBy)(locationId); // for log404()
980
987
  if (configFilesystemRoutingRoot) {
@@ -992,18 +999,19 @@ function determineRouteFilesystem(locationId, configValueSources) {
992
999
  routeString: filesystemRouteString,
993
1000
  definedBy: filesystemRouteDefinedBy
994
1001
  };
995
- return { routeFilesystem, isErrorPage: false };
1002
+ return { routeFilesystem, isErrorPage: undefined };
996
1003
  }
997
1004
  function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName) {
998
1005
  (0, utils_js_1.assert)(configFilesystemRoutingRoot.configEnv === 'config-only');
999
1006
  // Eagerly loaded since it's config-only
1000
1007
  (0, utils_js_1.assert)('value' in configFilesystemRoutingRoot);
1001
1008
  const { value } = configFilesystemRoutingRoot;
1002
- const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, configFilesystemRoutingRoot, false);
1009
+ const configDefinedAt = getConfigSourceDefinedAtString(configName, configFilesystemRoutingRoot);
1003
1010
  (0, utils_js_1.assertUsage)(typeof value === 'string', `${configDefinedAt} should be a string`);
1004
1011
  (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('/')}`);
1005
- (0, utils_js_1.assert)(!configFilesystemRoutingRoot.isComputed);
1006
- const before = (0, filesystemRouting_js_1.getFilesystemRouteString)((0, filesystemRouting_js_1.getLocationId)(configFilesystemRoutingRoot.definedAtInfo.filePath));
1012
+ const { filePathRelativeToUserRootDir } = configFilesystemRoutingRoot.definedAtInfo;
1013
+ (0, utils_js_1.assert)(filePathRelativeToUserRootDir);
1014
+ const before = (0, filesystemRouting_js_1.getFilesystemRouteString)((0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir));
1007
1015
  const after = value;
1008
1016
  const filesystemRoutingRootEffect = { before, after };
1009
1017
  return { filesystemRoutingRootEffect, filesystemRoutingRootDefinedAt: configDefinedAt };
@@ -1012,22 +1020,22 @@ function determineIsErrorPage(routeFilesystem) {
1012
1020
  (0, utils_js_1.assertPosixPath)(routeFilesystem);
1013
1021
  return routeFilesystem.split('/').includes('_error');
1014
1022
  }
1015
- function resolveImport(importData, importerFilePath) {
1016
- const { filePathAbsolute } = importerFilePath;
1017
- (0, utils_js_1.assertPosixPath)(filePathAbsolute);
1018
- const plusConfigFilDirPathAbsolute = path_1.default.posix.dirname(filePathAbsolute);
1019
- const importedFile = (0, utils_js_1.resolve)(importData.importFilePath, plusConfigFilDirPathAbsolute);
1020
- assertImport(importedFile, importData, importerFilePath);
1021
- return importedFile;
1023
+ function resolveImportPath(importData, importerFilePath) {
1024
+ const importerFilePathAbsolute = importerFilePath.filePathAbsolute;
1025
+ (0, utils_js_1.assertPosixPath)(importerFilePathAbsolute);
1026
+ 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;
1022
1030
  }
1023
- function assertImport(importedFile, importData, importerFilePath) {
1024
- const { importFilePath: importPath, importWasGenerated, importDataString } = importData;
1031
+ function assertImportPath(filePathAbsolute, importData, importerFilePath) {
1032
+ const { importPath: importPath, importStringWasGenerated, importString } = importData;
1025
1033
  const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(importerFilePath);
1026
- if (!importedFile) {
1034
+ if (!filePathAbsolute) {
1027
1035
  const importPathString = picocolors_1.default.cyan(`'${importPath}'`);
1028
- const errIntro = importWasGenerated
1036
+ const errIntro = importStringWasGenerated
1029
1037
  ? `The import path ${importPathString} in ${filePathToShowToUser}`
1030
- : `The import ${picocolors_1.default.cyan(importDataString)} defined in ${filePathToShowToUser}`;
1038
+ : `The import ${picocolors_1.default.cyan(importString)} defined in ${filePathToShowToUser}`;
1031
1039
  const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
1032
1040
  if (importPath.startsWith('.')) {
1033
1041
  (0, utils_js_1.assertUsage)(false, `${errIntro2} point to an existing file?`);
@@ -1041,18 +1049,23 @@ function isVikeConfigFile(filePath) {
1041
1049
  return !!getConfigName(filePath);
1042
1050
  }
1043
1051
  exports.isVikeConfigFile = isVikeConfigFile;
1044
- function getConfigValues(configValueSources, configDefinitionsRelevant) {
1052
+ function getConfigValues(configValueSources, configValuesComputed, configDefinitionsRelevant) {
1045
1053
  const configValues = {};
1054
+ Object.entries(configValuesComputed).forEach(([configName, configValueComputed]) => {
1055
+ configValues[configName] = {
1056
+ value: configValueComputed.value,
1057
+ definedAt: { isComputed: true }
1058
+ };
1059
+ });
1046
1060
  Object.entries(configValueSources).forEach(([configName, sources]) => {
1047
1061
  const configDef = configDefinitionsRelevant[configName];
1048
1062
  (0, utils_js_1.assert)(configDef);
1049
1063
  if (!configDef.cumulative) {
1050
1064
  const configValueSource = sources[0];
1051
1065
  if ('value' in configValueSource) {
1052
- const { value, definedAtInfo } = configValueSource;
1053
1066
  configValues[configName] = {
1054
- value,
1055
- definedAtInfo
1067
+ value: configValueSource.value,
1068
+ definedAt: getDefinedAt(configValueSource)
1056
1069
  };
1057
1070
  }
1058
1071
  }
@@ -1060,7 +1073,10 @@ function getConfigValues(configValueSources, configDefinitionsRelevant) {
1060
1073
  const value = mergeCumulative(configName, sources);
1061
1074
  configValues[configName] = {
1062
1075
  value,
1063
- definedAtInfo: null
1076
+ definedAt: {
1077
+ isCumulative: true,
1078
+ files: sources.map((source) => getDefinedAtFile(source))
1079
+ }
1064
1080
  };
1065
1081
  }
1066
1082
  });
@@ -1071,8 +1087,7 @@ function mergeCumulative(configName, configValueSources) {
1071
1087
  const valuesSet = [];
1072
1088
  let configValueSourcePrevious = null;
1073
1089
  configValueSources.forEach((configValueSource) => {
1074
- (0, utils_js_1.assert)(!configValueSource.isComputed);
1075
- const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, configValueSource, true);
1090
+ const configDefinedAt = getConfigSourceDefinedAtString(configName, configValueSource);
1076
1091
  const configNameColored = picocolors_1.default.cyan(configName);
1077
1092
  // We could, in principle, also support cumulative values to be defined in +${configName}.js but it ins't completely trivial to implement
1078
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.)`);
@@ -1080,7 +1095,7 @@ function mergeCumulative(configName, configValueSources) {
1080
1095
  const explanation = `(Because the values of ${configNameColored} are cumulative and therefore merged together.)` as const
1081
1096
  */
1082
1097
  // Make sure configValueSource.value is serializable
1083
- (0, getVirtualFilePageConfigs_js_1.getConfigValueSerialized)(configValueSource.value, configName, configValueSource.definedAtInfo);
1098
+ (0, getVirtualFilePageConfigs_js_1.getConfigValueSerialized)(configValueSource.value, configName, getDefinedAt(configValueSource));
1084
1099
  const assertNoMixing = (isSet) => {
1085
1100
  const vals1 = isSet ? valuesSet : valuesArr;
1086
1101
  const t1 = isSet ? 'a Set' : 'an array';
@@ -1090,7 +1105,7 @@ function mergeCumulative(configName, configValueSources) {
1090
1105
  if (vals2.length === 0)
1091
1106
  return;
1092
1107
  (0, utils_js_1.assert)(configValueSourcePrevious);
1093
- const configPreviousDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, configValueSourcePrevious, false);
1108
+ const configPreviousDefinedAt = getConfigSourceDefinedAtString(configName, configValueSourcePrevious, undefined, false);
1094
1109
  (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).`);
1095
1110
  };
1096
1111
  const { value } = configValueSource;
@@ -1121,3 +1136,30 @@ function mergeCumulative(configName, configValueSources) {
1121
1136
  }
1122
1137
  (0, utils_js_1.assert)(false);
1123
1138
  }
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
+ }