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
@@ -42,7 +42,7 @@ const getPageFiles_js_1 = require("../../shared/getPageFiles.js");
42
42
  const getPageContextRequestUrl_js_1 = require("../../shared/getPageContextRequestUrl.js");
43
43
  const resolveRouteString_js_1 = require("../../shared/route/resolveRouteString.js");
44
44
  const utils_js_2 = require("../../shared/page-configs/utils.js");
45
- const loadPageCode_js_1 = require("../../shared/page-configs/loadPageCode.js");
45
+ const loadConfigValues_js_1 = require("../../shared/page-configs/loadConfigValues.js");
46
46
  const error_page_js_1 = require("../../shared/error-page.js");
47
47
  const addUrlComputedProps_js_1 = require("../../shared/addUrlComputedProps.js");
48
48
  const assertPathIsFilesystemAbsolute_js_1 = require("../../utils/assertPathIsFilesystemAbsolute.js");
@@ -72,7 +72,7 @@ async function runPrerender(options, manuallyTriggered) {
72
72
  const viteConfig = await (0, vite_1.resolveConfig)(options.viteConfig || {}, 'vike pre-rendering', 'production');
73
73
  assertLoadedConfig(viteConfig, options);
74
74
  const configVike = await (0, getConfigVike_js_1.getConfigVike)(viteConfig);
75
- const { outDirClient, outDirRoot } = (0, utils_js_1.getOutDirs_prerender)(viteConfig);
75
+ const { outDirClient, outDirRoot } = (0, utils_js_1.getOutDirs)(viteConfig);
76
76
  const { root } = viteConfig;
77
77
  const prerenderConfig = configVike.prerender;
78
78
  if (!prerenderConfig) {
@@ -115,12 +115,13 @@ async function collectDoNoPrerenderList(renderContext, doNotPrerenderList, concu
115
115
  const configName = 'prerender';
116
116
  const configValue = (0, utils_js_2.getConfigValue)(pageConfig, configName, 'boolean');
117
117
  if (configValue?.value === false) {
118
- const definedAtInfo = (0, utils_js_2.getConfigDefinedAtInfo)(pageConfig, configName);
118
+ const configValueFilePathToShowToUser = (0, utils_js_2.getConfigValueFilePathToShowToUser)(configValue);
119
+ (0, utils_js_1.assert)(configValueFilePathToShowToUser);
119
120
  doNotPrerenderList.push({
120
121
  pageId: pageConfig.pageId,
121
122
  setByConfigName: 'prerender',
122
123
  setByConfigValue: false,
123
- setByConfigFile: definedAtInfo.filePath
124
+ setByConfigFile: configValueFilePathToShowToUser
124
125
  });
125
126
  }
126
127
  });
@@ -171,13 +172,12 @@ async function callOnBeforePrerenderStartHooks(prerenderContext, renderContext,
171
172
  // V1 design
172
173
  await Promise.all(renderContext.pageConfigs.map((pageConfig) => concurrencyLimit(async () => {
173
174
  const hookName = 'onBeforePrerenderStart';
174
- const pageConfigLoaded = await (0, loadPageCode_js_1.loadPageCode)(pageConfig, false);
175
+ const pageConfigLoaded = await (0, loadConfigValues_js_1.loadConfigValues)(pageConfig, false);
175
176
  const configValue = (0, utils_js_2.getConfigValue)(pageConfigLoaded, hookName);
176
177
  if (!configValue)
177
178
  return;
178
179
  const hookFn = configValue.value;
179
- const definedAtInfo = (0, utils_js_2.getConfigDefinedAtInfo)(pageConfigLoaded, hookName);
180
- const hookFilePath = definedAtInfo.filePath;
180
+ const hookFilePath = (0, utils_js_2.getHookFilePathToShowToUser)(configValue);
181
181
  (0, utils_js_1.assert)(hookFilePath);
182
182
  (0, getHook_js_1.assertHookFn)(hookFn, { hookName, hookFilePath });
183
183
  onBeforePrerenderStartHooks.push({
@@ -309,20 +309,18 @@ async function callOnPrerenderStartHook(prerenderContext, renderContext) {
309
309
  let onPrerenderStartHook;
310
310
  // V1 design
311
311
  if (renderContext.pageConfigs.length > 0) {
312
- const configValueSource = renderContext.pageConfigGlobal.onPrerenderStart;
313
- if (configValueSource) {
314
- const hookFn = configValueSource.value;
315
- (0, utils_js_1.assert)(!configValueSource.isComputed);
316
- const hookFilePath = configValueSource.definedAtInfo.filePath;
317
- (0, utils_js_1.assert)(hookFn);
312
+ const { pageConfigGlobal } = renderContext;
313
+ const configValue = pageConfigGlobal.configValues.onPrerenderStart;
314
+ if (configValue?.value) {
315
+ const { value: hookFn } = configValue;
316
+ // config.onPrerenderStart isn't a computed nor a cumulative config => definedAtInfo should always be defined
317
+ const hookFilePath = (0, utils_js_2.getHookFilePathToShowToUser)(configValue);
318
318
  (0, utils_js_1.assert)(hookFilePath);
319
- if (hookFn) {
320
- onPrerenderStartHook = {
321
- hookFn,
322
- hookName: 'onPrerenderStart',
323
- hookFilePath
324
- };
325
- }
319
+ onPrerenderStartHook = {
320
+ hookFn,
321
+ hookName: 'onPrerenderStart',
322
+ hookFilePath
323
+ };
326
324
  }
327
325
  }
328
326
  // Old design
@@ -111,7 +111,7 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
111
111
  if (!isHtmlOnly) {
112
112
  // Don't allow the user to manipulate with injectFilter(): injecting <script type="application/json"> before the stream can break the app when:
113
113
  // - using https://vike.dev/stream#initial-data-after-stream-end
114
- // - `pageContext` is modified during the stream, e.g. /examples/vue-pinia which uses https://vuejs.org/api/composition-api-lifecycle.html#onserverprefetch
114
+ // - `pageContext` is modified during the stream, e.g. https://github.com/brillout/vike-with-pinia which uses https://vuejs.org/api/composition-api-lifecycle.html#onserverprefetch
115
115
  // The <script> tags are handled separately by vike down below.
116
116
  htmlTags.push({
117
117
  // Needs to be called after `resolvePageContextPromise()`
@@ -28,14 +28,14 @@ function analyzePage(pageFilesAll, pageConfig, pageId) {
28
28
  }
29
29
  /* Remove?
30
30
  Object.values(pageConfig.configElements).forEach((configElement) => {
31
- if (configElement.importFilePath) {
31
+ if (configElement.importPath) {
32
32
  const { env } = configElement
33
33
  assert(env)
34
34
  const onlyAssets = env === 'server-only'
35
35
  const eagerlyImported = env === '_routing-eager'
36
36
  if (onlyAssets || eagerlyImported) {
37
37
  clientDependencies.push({
38
- id: configElement.importFilePath,
38
+ id: configElement.importPath,
39
39
  onlyAssets,
40
40
  eagerlyImported
41
41
  })
@@ -9,7 +9,7 @@ const debugPageFiles_js_1 = require("./debugPageFiles.js");
9
9
  const findPageConfig_js_1 = require("../../../shared/page-configs/findPageConfig.js");
10
10
  const analyzePage_js_1 = require("./analyzePage.js");
11
11
  const globalContext_js_1 = require("../globalContext.js");
12
- const loadPageCode_js_1 = require("../../../shared/page-configs/loadPageCode.js");
12
+ const loadConfigValues_js_1 = require("../../../shared/page-configs/loadConfigValues.js");
13
13
  async function loadPageFilesServerSide(pageContext) {
14
14
  const pageConfig = (0, findPageConfig_js_1.findPageConfig)(pageContext._pageConfigs, pageContext._pageId); // Make pageConfig globally available as pageContext._pageConfig?
15
15
  const [{ config, configEntries, exports, exportsAll, pageExports, pageFilesLoaded, pageConfigLoaded }] = await Promise.all([
@@ -85,7 +85,7 @@ async function loadPageFilesServerSide(pageContext) {
85
85
  exports.loadPageFilesServerSide = loadPageFilesServerSide;
86
86
  async function loadPageFiles(pageFilesAll, pageConfig, pageId, isDev) {
87
87
  const pageFilesServerSide = (0, getPageFiles_js_1.getPageFilesServerSide)(pageFilesAll, pageId);
88
- const pageConfigLoaded = !pageConfig ? null : await (0, loadPageCode_js_1.loadPageCode)(pageConfig, isDev);
88
+ const pageConfigLoaded = !pageConfig ? null : await (0, loadConfigValues_js_1.loadConfigValues)(pageConfig, isDev);
89
89
  await Promise.all(pageFilesServerSide.map((p) => p.loadFile?.()));
90
90
  const { config, configEntries, exports, exportsAll, pageExports } = (0, getPageFiles_js_1.getExports)(pageFilesServerSide, pageConfigLoaded);
91
91
  return {
@@ -72,8 +72,8 @@ function getPagesAndRoutesInfo(pageRoutes) {
72
72
  ...entries
73
73
  ];
74
74
  const terminalWidth = (0, utils_js_1.getTerminalWidth)() || 134;
75
- let width2 = Math.max(...linesContent.map(({ routeTypeSrc }) => routeTypeSrc.length));
76
- let width3 = Math.max(...linesContent.map(({ routeDefinedBy }) => routeDefinedBy.length));
75
+ let width2 = Math.max(...linesContent.map(({ routeTypeSrc }) => (0, utils_js_1.stripAnsi)(routeTypeSrc).length));
76
+ let width3 = Math.max(...linesContent.map(({ routeDefinedBy }) => (0, utils_js_1.stripAnsi)(routeDefinedBy).length));
77
77
  let width1 = terminalWidth - width3 - width2 - 10;
78
78
  linesContent.forEach((lineContent) => {
79
79
  let { routeStr } = lineContent;
@@ -88,9 +88,9 @@ function getPagesAndRoutesInfo(pageRoutes) {
88
88
  });
89
89
  width1 = Math.max(...linesContent.map(({ routeStr }) => (0, utils_js_1.stripAnsi)(routeStr).length));
90
90
  let lines = linesContent.map(({ routeStr, routeTypeSrc, routeDefinedBy }, i) => {
91
- let cell1 = routeStr.padEnd(width1 + (routeStr.length - (0, utils_js_1.stripAnsi)(routeStr).length), ' ');
92
- let cell2 = routeTypeSrc.padEnd(width2, ' ');
93
- let cell3 = routeDefinedBy.padEnd(width3, ' ');
91
+ let cell1 = padEnd(routeStr, width1 + ((0, utils_js_1.stripAnsi)(routeStr).length - (0, utils_js_1.stripAnsi)(routeStr).length));
92
+ let cell2 = padEnd(routeTypeSrc, width2);
93
+ let cell3 = padEnd(routeDefinedBy, width3);
94
94
  const isHeader = i === 0;
95
95
  if (isHeader) {
96
96
  cell1 = picocolors_1.default.dim(cell1);
@@ -125,6 +125,11 @@ function truncateRouteFunction(routeStr, lenMax) {
125
125
  routeStr = (0, utils_js_1.truncateString)(routeStr, lenMax, (s) => picocolors_1.default.dim(s));
126
126
  return routeStr;
127
127
  }
128
+ /** Same as String.prototype.padEnd but with stripAnsi() */
129
+ function padEnd(str, width) {
130
+ const padWidth = Math.max(0, width - (0, utils_js_1.stripAnsi)(str).length);
131
+ return str + ''.padEnd(padWidth, ' ');
132
+ }
128
133
  function removeNonAscii(str) {
129
134
  // https://stackoverflow.com/questions/20856197/remove-non-ascii-character-in-string/20856346#20856346
130
135
  return str.replace(/[^\x00-\x7F]/g, '');
@@ -21,6 +21,7 @@ const preparePageContextForUserConsumptionServerSide_js_1 = require("./preparePa
21
21
  const executeGuardHook_js_1 = require("../../../shared/route/executeGuardHook.js");
22
22
  const loadPageRoutes_js_1 = require("../../../shared/route/loadPageRoutes.js");
23
23
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
24
+ const utils_js_2 = require("../../../shared/page-configs/utils.js");
24
25
  async function renderPageAlreadyRouted(pageContext) {
25
26
  // pageContext._pageId can either be the:
26
27
  // - ID of the page matching the routing, or the
@@ -172,9 +173,9 @@ function assertNonMixedDesign(pageFilesAll, pageConfigs) {
172
173
  const indent = '- ';
173
174
  const v1Files = (0, utils_js_1.unique)(pageConfigs
174
175
  .map((p) => Object.values(p.configValues)
175
- .map(({ definedAtInfo }) => definedAtInfo)
176
+ .map(utils_js_2.getConfigValueFilePathToShowToUser)
176
177
  .filter(utils_js_1.isNotNullish)
177
- .map((definedAtInfo) => indent + definedAtInfo.filePath))
178
+ .map((filePathToShowToUser) => indent + filePathToShowToUser))
178
179
  .flat(2));
179
180
  (0, utils_js_1.assertUsage)(false, [
180
181
  'Mixing the new V1 design with the old V0.4 design is forbidden.',
@@ -311,7 +311,7 @@ function getRequestId() {
311
311
  }
312
312
  function skipRequest(urlOriginal) {
313
313
  const isViteClientRequest = urlOriginal.endsWith('/@vite/client') || urlOriginal.startsWith('/@fs/');
314
- (0, utils_js_1.assertWarning)(!isViteClientRequest, `The vike middleware renderPage() was called with the URL ${urlOriginal} which is unexpected because the HTTP request should have already been handled by Vite's development middleware. Make sure to 1. install Vite's development middleware and 2. add Vite's middleware *before* vike's middleware, see https://vike.dev/renderPage`, { onlyOnce: true });
314
+ (0, utils_js_1.assertWarning)(!isViteClientRequest, `The vike middleware renderPage() was called with the URL ${urlOriginal} which is unexpected because the HTTP request should have already been handled by Vite's development middleware. Make sure to 1. install Vite's development middleware and 2. add Vite's middleware *before* Vike's middleware, see https://vike.dev/renderPage`, { onlyOnce: true });
315
315
  return (urlOriginal.endsWith('/__vite_ping') ||
316
316
  urlOriginal.endsWith('/favicon.ico') ||
317
317
  !(0, utils_js_1.isParsable)(urlOriginal) ||
@@ -2,17 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getClientEntryFilePath = void 0;
4
4
  const utils_js_1 = require("../../shared/page-configs/utils.js");
5
- const utils_js_2 = require("./utils.js");
6
5
  function getClientEntryFilePath(pageConfig) {
7
6
  const configName = 'client';
8
7
  const configValue = (0, utils_js_1.getConfigValue)(pageConfig, configName, 'string');
9
8
  if (!configValue)
10
9
  return null;
11
- const definedAtInfo = (0, utils_js_1.getConfigDefinedAtInfo)(pageConfig, configName);
12
- const { value } = configValue;
13
- // Users should be able to suppress client entry by setting its value to null
14
- (0, utils_js_2.assert)(value !== null);
15
- const clientEntryFilePath = definedAtInfo.filePath;
16
- return clientEntryFilePath;
10
+ return configValue.value;
17
11
  }
18
12
  exports.getClientEntryFilePath = getClientEntryFilePath;
@@ -15,7 +15,7 @@ function assertPageContextProvidedByUser(pageContextProvidedByUser, { hookName,
15
15
  (0, utils_js_1.assertUsage)(!('_objectCreatedByVike' in pageContextProvidedByUser), `${errPrefix} shouldn't be the whole ${picocolors_1.default.cyan('pageContext')} object, see https://vike.dev/pageContext-manipulation#do-not-return-entire-pagecontext`);
16
16
  // In principle, it's possible to use onBeforeRoute()` to override and define the whole routing.
17
17
  // Is that a good idea to allow users to do this? Beyond deep integration with Vue Router or React Router, is there a use case for this?
18
- (0, utils_js_1.assertWarning)(!('_pageId' in pageContextProvidedByUser), `${errPrefix} sets ${picocolors_1.default.cyan('pageContext._pageId')} which means that vike's routing is overriden. This is an experimental feature: make sure to contact a vike maintainer before using this.`, { onlyOnce: true });
18
+ (0, utils_js_1.assertWarning)(!('_pageId' in pageContextProvidedByUser), `${errPrefix} sets ${picocolors_1.default.cyan('pageContext._pageId')} which means that Vike's routing is overriden. This is an experimental feature: make sure to contact a vike maintainer before using this.`, { onlyOnce: true });
19
19
  (0, utils_js_1.assertUsage)(!('is404' in pageContextProvidedByUser), `${errPrefix} sets ${picocolors_1.default.cyan('pageContext.is404')} which is forbidden, use ${picocolors_1.default.cyan('throw render()')} instead, see https://vike.dev/render`);
20
20
  }
21
21
  exports.assertPageContextProvidedByUser = assertPageContextProvidedByUser;
@@ -32,7 +32,7 @@ function isErrorPage(pageId, pageConfigs) {
32
32
  if (pageConfigs.length > 0) {
33
33
  const pageConfig = pageConfigs.find((p) => p.pageId === pageId);
34
34
  (0, utils_js_1.assert)(pageConfig);
35
- return pageConfig.isErrorPage;
35
+ return !!pageConfig.isErrorPage;
36
36
  }
37
37
  else {
38
38
  return isErrorPageId(pageId, false);
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getExports = exports.getExportUnion = void 0;
7
7
  const isScriptFile_js_1 = require("../../utils/isScriptFile.js");
8
8
  const utils_js_1 = require("../utils.js");
9
- const assertExports_js_1 = require("./assertExports.js");
9
+ const assert_exports_old_design_js_1 = require("./assert_exports_old_design.js");
10
10
  const utils_js_2 = require("../page-configs/utils.js");
11
11
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
12
12
  function getExports(pageFiles, pageConfig) {
@@ -33,11 +33,8 @@ function getExports(pageFiles, pageConfig) {
33
33
  // V1 design
34
34
  if (pageConfig) {
35
35
  Object.entries(pageConfig.configValues).forEach(([configName, configValue]) => {
36
- const { value, definedAtInfo } = configValue;
37
- let filePath = null;
38
- if (definedAtInfo) {
39
- filePath = definedAtInfo.filePath;
40
- }
36
+ const { value } = configValue;
37
+ const configValueFilePathToShowToUser = (0, utils_js_2.getConfigValueFilePathToShowToUser)(configValue);
41
38
  const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, configValue, true);
42
39
  config[configName] = config[configName] ?? value;
43
40
  configEntries[configName] = configEntries[configName] ?? [];
@@ -46,7 +43,7 @@ function getExports(pageFiles, pageConfig) {
46
43
  configEntries[configName].push({
47
44
  configValue: value,
48
45
  configDefinedAt,
49
- configDefinedByFile: filePath
46
+ configDefinedByFile: configValueFilePathToShowToUser
50
47
  });
51
48
  // TODO/v1-release: remove
52
49
  const exportName = configName;
@@ -54,8 +51,8 @@ function getExports(pageFiles, pageConfig) {
54
51
  exportsAll[exportName].push({
55
52
  exportValue: value,
56
53
  exportSource: configDefinedAt,
57
- filePath,
58
- _filePath: filePath,
54
+ filePath: configValueFilePathToShowToUser,
55
+ _filePath: configValueFilePathToShowToUser,
59
56
  _fileType: null,
60
57
  _isFromDefaultExport: null
61
58
  });
@@ -102,7 +99,7 @@ function getExportValues(pageFile) {
102
99
  else {
103
100
  (0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(exportValue), `The ${picocolors_1.default.cyan('export default')} of ${filePath} should be an object.`);
104
101
  Object.entries(exportValue).forEach(([defaultExportName, defaultExportValue]) => {
105
- (0, assertExports_js_1.assertDefaultExports)(defaultExportName, filePath);
102
+ (0, assert_exports_old_design_js_1.assertDefaultExports)(defaultExportName, filePath);
106
103
  exportValues.push({
107
104
  exportName: defaultExportName,
108
105
  exportValue: defaultExportValue,
@@ -119,7 +116,7 @@ function getExportValues(pageFile) {
119
116
  });
120
117
  });
121
118
  exportValues.forEach(({ exportName, isFromDefaultExport }) => {
122
- (0, utils_js_1.assert)(!(isFromDefaultExport && assertExports_js_1.forbiddenDefaultExports.includes(exportName)));
119
+ (0, utils_js_1.assert)(!(isFromDefaultExport && assert_exports_old_design_js_1.forbiddenDefaultExports.includes(exportName)));
123
120
  });
124
121
  return exportValues;
125
122
  }
@@ -2,11 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseGlobResults = void 0;
4
4
  const utils_js_1 = require("../utils.js");
5
- const assertExports_js_1 = require("./assertExports.js");
5
+ const assert_exports_old_design_js_1 = require("./assert_exports_old_design.js");
6
6
  const getPageFileObject_js_1 = require("./getPageFileObject.js");
7
7
  const fileTypes_js_1 = require("./fileTypes.js");
8
- const assertPageConfigs_js_1 = require("./assertPageConfigs.js");
9
- const parse_1 = require("@brillout/json-serializer/parse");
8
+ const assertPageConfigs_js_1 = require("../page-configs/serialize/assertPageConfigs.js");
9
+ const parsePageConfigs_js_1 = require("../page-configs/serialize/parsePageConfigs.js");
10
10
  function parseGlobResults(pageFilesExports) {
11
11
  (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'isGeneratedFile'));
12
12
  (0, utils_js_1.assert)(pageFilesExports.isGeneratedFile !== false, `vike was re-installed(/re-built). Restart your app.`);
@@ -18,12 +18,12 @@ function parseGlobResults(pageFilesExports) {
18
18
  (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports.pageFilesLazy, '.page'));
19
19
  (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports.pageFilesLazy, '.page.client') || (0, utils_js_1.hasProp)(pageFilesExports.pageFilesLazy, '.page.server'));
20
20
  (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageFilesList', 'string[]'));
21
- (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageConfigs'));
22
- (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageConfigGlobal'));
23
- const { pageConfigs, pageConfigGlobal } = pageFilesExports;
24
- (0, assertPageConfigs_js_1.assertPageConfigs)(pageConfigs);
25
- parsePageConfigs(pageConfigs);
26
- (0, assertPageConfigs_js_1.assertPageConfigGlobal)(pageConfigGlobal);
21
+ (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageConfigsSerialized'));
22
+ (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageConfigGlobalSerialized'));
23
+ const { pageConfigsSerialized, pageConfigGlobalSerialized } = pageFilesExports;
24
+ (0, assertPageConfigs_js_1.assertPageConfigsSerialized)(pageConfigsSerialized);
25
+ (0, assertPageConfigs_js_1.assertPageConfigGlobalSerialized)(pageConfigGlobalSerialized);
26
+ const { pageConfigs, pageConfigGlobal } = (0, parsePageConfigs_js_1.parsePageConfigs)(pageConfigsSerialized, pageConfigGlobalSerialized);
27
27
  const pageFilesMap = {};
28
28
  parseGlobResult(pageFilesExports.pageFilesLazy).forEach(({ filePath, pageFile, globValue }) => {
29
29
  pageFile = pageFilesMap[filePath] = pageFilesMap[filePath] ?? pageFile;
@@ -32,7 +32,7 @@ function parseGlobResults(pageFilesExports) {
32
32
  pageFile.loadFile = async () => {
33
33
  if (!('fileExports' in pageFile)) {
34
34
  pageFile.fileExports = await loadModule();
35
- (0, assertExports_js_1.assertExportValues)(pageFile);
35
+ (0, assert_exports_old_design_js_1.assertExportValues)(pageFile);
36
36
  }
37
37
  };
38
38
  });
@@ -91,37 +91,3 @@ function parseGlobResult(globObject) {
91
91
  function assertLoadModule(globValue) {
92
92
  (0, utils_js_1.assert)((0, utils_js_1.isCallable)(globValue));
93
93
  }
94
- function parsePageConfigs(pageConfigs) {
95
- pageConfigs.forEach((pageConfig) => {
96
- Object.entries(pageConfig.configValues).forEach(([configName, configValue]) => {
97
- {
98
- const { valueSerialized } = configValue;
99
- if (valueSerialized !== undefined) {
100
- configValue.value = (0, parse_1.parse)(valueSerialized);
101
- }
102
- }
103
- /*
104
- if (configName === 'route') {
105
- assertRouteConfigValue(configElement)
106
- }
107
- */
108
- });
109
- });
110
- }
111
- // TODO: use again
112
- // function assertRouteConfigValue(configElement: ConfigElement) {
113
- // assert(hasProp(configElement, 'configValue')) // route files are eagerly loaded
114
- // const { configValue } = configElement
115
- // const configValueType = typeof configValue
116
- // assertUsage(
117
- // configValueType === 'string' || isCallable(configValue),
118
- // `${configElement.configDefinedAt} has an invalid type '${configValueType}': it should be a string or a function instead, see https://vike.dev/route`
119
- // )
120
- // /* We don't do that to avoid unnecessarily bloating the client-side bundle when using Server Routing
121
- // * - When using Server Routing, this file is loaded as well
122
- // * - When using Server Routing, client-side validation is superfluous as Route Strings only need to be validated on the server-side
123
- // if (typeof configValue === 'string') {
124
- // assertRouteString(configValue, `${configElement.configDefinedAt} defines an`)
125
- // }
126
- // */
127
- // }
@@ -11,7 +11,9 @@ function getHook(pageContext, hookName) {
11
11
  (0, utils_js_1.assert)(file.exportValue === hookFn);
12
12
  if (hookFn === null)
13
13
  return null;
14
- const hookFilePath = file.exportSource;
14
+ const hookFilePath = file.filePath;
15
+ (0, utils_js_1.assert)(hookFilePath);
16
+ (0, utils_js_1.assert)(!hookFilePath.endsWith(' '));
15
17
  assertHookFn(hookFn, { hookName, hookFilePath });
16
18
  return { hookFn, hookName, hookFilePath };
17
19
  }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.assertExportsOfConfigFile = exports.assertExportsOfValueFile = void 0;
7
+ const utils_js_1 = require("../utils.js");
8
+ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
9
+ const EXPORTS_IGNORE = [
10
+ // vite-plugin-solid adds `export { $$registrations }`
11
+ '$$registrations',
12
+ // @vitejs/plugin-vue adds `export { _rerender_only }`
13
+ '_rerender_only'
14
+ ];
15
+ // Tolerate `export { frontmatter }` in .mdx files
16
+ const TOLERATE_SIDE_EXPORTS = ['.md', '.mdx'];
17
+ function assertExportsOfValueFile(fileExports, filePathToShowToUser, configName) {
18
+ assertExports(fileExports, filePathToShowToUser, configName);
19
+ }
20
+ exports.assertExportsOfValueFile = assertExportsOfValueFile;
21
+ function assertExportsOfConfigFile(fileExports, filePathToShowToUser) {
22
+ assertExports(fileExports, filePathToShowToUser);
23
+ const exportDefault = fileExports.default;
24
+ (0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(exportDefault), `The ${picocolors_1.default.cyan('export default')} of ${filePathToShowToUser} should be an object (but it's ${picocolors_1.default.cyan(`typeof exportDefault === ${JSON.stringify(typeof exportDefault)}`)} instead)`);
25
+ }
26
+ exports.assertExportsOfConfigFile = assertExportsOfConfigFile;
27
+ function assertExports(fileExports, filePathToShowToUser, configName) {
28
+ const exportsAll = Object.keys(fileExports);
29
+ const exportsRelevant = exportsAll.filter((exportName) => !EXPORTS_IGNORE.includes(exportName));
30
+ const exportsInvalid = exportsRelevant.filter((e) => e !== 'default' &&
31
+ // !!configName => isValueFile
32
+ e !== configName);
33
+ if (exportsInvalid.length === 0) {
34
+ if (exportsRelevant.length === 1) {
35
+ return;
36
+ }
37
+ else {
38
+ (0, utils_js_1.assert)(exportsRelevant.length === 0);
39
+ let errMsg = `${filePathToShowToUser} doesn't export any value, but it should have a ${picocolors_1.default.cyan('export default')}`;
40
+ if (configName)
41
+ errMsg += ` or ${picocolors_1.default.cyan(`export { ${configName} }`)}`;
42
+ (0, utils_js_1.assertUsage)(false, errMsg);
43
+ }
44
+ }
45
+ else {
46
+ // !configName => isConfigFile
47
+ if (!configName) {
48
+ const exportsInvalidStr = exportsInvalid.join(', ');
49
+ (0, utils_js_1.assertUsage)(false, `${filePathToShowToUser} replace ${picocolors_1.default.cyan(`export { ${exportsInvalidStr} }`)} with ${picocolors_1.default.cyan(`export default { ${exportsInvalidStr} }`)}`);
50
+ }
51
+ // !!configName => isValueFile
52
+ else {
53
+ if (TOLERATE_SIDE_EXPORTS.some((ext) => filePathToShowToUser.endsWith(ext)))
54
+ return;
55
+ exportsInvalid.forEach((exportInvalid) => {
56
+ (0, utils_js_1.assertWarning)(false, `${filePathToShowToUser} should have only a single export: move ${picocolors_1.default.cyan(`export { ${exportInvalid} }`)} to +config.h.js or its own +${exportsInvalid}.js`, { onlyOnce: true });
57
+ });
58
+ }
59
+ }
60
+ }
@@ -2,19 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getExportPath = void 0;
4
4
  const utils_js_1 = require("../utils.js");
5
- // TODO: return null instead of 'export default'
6
- // - Also return null insead of 'export *'?
7
- function getExportPath(fileExportPath) {
8
- let prefix = '';
9
- let suffix = '';
5
+ function getExportPath(fileExportPath, configName) {
6
+ if (!fileExportPath)
7
+ return null;
10
8
  let [exportName, ...exportObjectPath] = fileExportPath;
11
9
  if (!exportName)
12
10
  return null;
13
- if (exportName === '*') {
14
- (0, utils_js_1.assert)(exportObjectPath.length === 0);
15
- return 'export *';
16
- }
17
- else if (exportName === 'default') {
11
+ if (exportObjectPath.length === 0 && ['*', 'default', configName].includes(exportName))
12
+ return null;
13
+ (0, utils_js_1.assert)(exportName !== '*');
14
+ let prefix = '';
15
+ let suffix = '';
16
+ if (exportName === 'default') {
18
17
  prefix = 'export default';
19
18
  }
20
19
  else {
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadConfigValues = void 0;
4
+ const utils_js_1 = require("../utils.js");
5
+ const parseConfigValuesImported_js_1 = require("./serialize/parseConfigValuesImported.js");
6
+ async function loadConfigValues(pageConfig, isDev) {
7
+ if ('isLoaded' in pageConfig &&
8
+ // We don't need to cache in dev, since Vite already caches the virtual module
9
+ !isDev) {
10
+ return pageConfig;
11
+ }
12
+ const configValuesImported = await pageConfig.loadConfigValuesAll();
13
+ const configValuesAddendum = (0, parseConfigValuesImported_js_1.parseConfigValuesImported)(configValuesImported);
14
+ Object.assign(pageConfig.configValues, configValuesAddendum);
15
+ (0, utils_js_1.objectAssign)(pageConfig, { isLoaded: true });
16
+ return pageConfig;
17
+ }
18
+ exports.loadConfigValues = loadConfigValues;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertPageConfigGlobalSerialized = exports.assertPageConfigsSerialized = void 0;
4
+ const utils_js_1 = require("../../utils.js");
5
+ function assertPageConfigsSerialized(pageConfigsSerialized) {
6
+ (0, utils_js_1.assert)(Array.isArray(pageConfigsSerialized));
7
+ pageConfigsSerialized.forEach((pageConfigSerialized) => {
8
+ (0, utils_js_1.assert)((0, utils_js_1.isObject)(pageConfigSerialized));
9
+ (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'pageId', 'string'));
10
+ (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'routeFilesystem'));
11
+ (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'configValuesSerialized'));
12
+ (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'configValuesImported'));
13
+ });
14
+ }
15
+ exports.assertPageConfigsSerialized = assertPageConfigsSerialized;
16
+ function assertPageConfigGlobalSerialized(pageConfigGlobalSerialized) {
17
+ (0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigGlobalSerialized, 'configValuesImported'));
18
+ }
19
+ exports.assertPageConfigGlobalSerialized = assertPageConfigGlobalSerialized;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.parseConfigValuesImported = void 0;
7
+ const utils_js_1 = require("../../utils.js");
8
+ const assertExports_js_1 = require("../assertExports.js");
9
+ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
10
+ function parseConfigValuesImported(configValuesImported) {
11
+ const configValues = {};
12
+ const addConfigValue = (configName, value, importPath, exportName) => {
13
+ configValues[configName] = {
14
+ value,
15
+ definedAt: {
16
+ file: {
17
+ // importPath cannot be relative to the current file, since the current file is a virtual file
18
+ filePathToShowToUser: importPath,
19
+ fileExportPath: [configName, 'default'].includes(exportName)
20
+ ? []
21
+ : // Side-effect config
22
+ [exportName]
23
+ }
24
+ }
25
+ };
26
+ assertIsNotNull(value, configName, importPath);
27
+ };
28
+ configValuesImported.forEach((configValueLoaded) => {
29
+ if (configValueLoaded.isValueFile) {
30
+ const { exportValues, importPath, configName } = configValueLoaded;
31
+ if (configName !== 'client') {
32
+ (0, assertExports_js_1.assertExportsOfValueFile)(exportValues, importPath, configName);
33
+ }
34
+ Object.entries(exportValues).forEach(([exportName, exportValue]) => {
35
+ const isSideExport = exportName !== 'default'; // .md files may have "side-exports" such as `export { frontmatter }`
36
+ const configName = isSideExport ? exportName : configValueLoaded.configName;
37
+ if (isSideExport && configName in configValues) {
38
+ // We can't avoid side-export conflicts upstream. (Because we cannot know about side-exports upstream at build-time.)
39
+ // Side-exports have the lowest priority.
40
+ return;
41
+ }
42
+ addConfigValue(configName, exportValue, importPath, exportName);
43
+ });
44
+ }
45
+ else {
46
+ const { configName, importPath, exportValue, exportName } = configValueLoaded;
47
+ addConfigValue(configName, exportValue, importPath, exportName);
48
+ }
49
+ });
50
+ return configValues;
51
+ }
52
+ exports.parseConfigValuesImported = parseConfigValuesImported;
53
+ function assertIsNotNull(configValue, configName, importPath) {
54
+ (0, utils_js_1.assert)(!importPath.includes('+config.'));
55
+ (0, utils_js_1.assertUsage)(configValue !== null, `Set ${picocolors_1.default.cyan(configName)} to ${picocolors_1.default.cyan('null')} in a +config.h.js file instead of ${importPath}`);
56
+ }