vike 0.4.144 → 0.4.145-commit-2520555

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/dist/cjs/__internal/index.js +6 -2
  2. package/dist/cjs/node/plugin/plugins/buildConfig.js +3 -3
  3. package/dist/cjs/node/plugin/plugins/commonConfig.js +0 -3
  4. package/dist/cjs/node/plugin/plugins/config/index.js +3 -3
  5. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +8 -8
  6. package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -0
  7. package/dist/cjs/node/plugin/plugins/envVars.js +34 -20
  8. package/dist/cjs/node/plugin/plugins/importBuild/index.js +3 -3
  9. package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
  10. package/dist/cjs/node/plugin/plugins/importUserCode/index.js +3 -3
  11. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -4
  12. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
  13. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +249 -228
  14. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +8 -6
  15. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +36 -14
  16. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
  17. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +18 -0
  18. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +15 -17
  19. package/dist/cjs/node/plugin/plugins/previewConfig.js +11 -2
  20. package/dist/cjs/node/prerender/runPrerender.js +34 -26
  21. package/dist/cjs/node/prerender/utils.js +1 -1
  22. package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +20 -6
  23. package/dist/cjs/node/runtime/renderPage/debugPageFiles.js +5 -5
  24. package/dist/cjs/node/runtime/renderPage/log404/index.js +28 -17
  25. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -3
  26. package/dist/cjs/node/runtime/renderPage.js +3 -3
  27. package/dist/cjs/node/runtime/utils.js +1 -1
  28. package/dist/cjs/node/shared/getClientEntryFilePath.js +2 -2
  29. package/dist/cjs/node/shared/getConfigVike.js +4 -1
  30. package/dist/cjs/shared/addUrlComputedProps.js +24 -12
  31. package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +4 -6
  32. package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
  33. package/dist/cjs/shared/hooks/getHook.js +1 -1
  34. package/dist/cjs/shared/page-configs/getExportPath.js +3 -3
  35. package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +43 -0
  36. package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +44 -0
  37. package/dist/cjs/shared/page-configs/helpers.js +33 -0
  38. package/dist/cjs/shared/page-configs/loadConfigValues.js +2 -2
  39. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +14 -13
  40. package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -2
  41. package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +9 -10
  42. package/dist/cjs/shared/route/abort.js +1 -1
  43. package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +41 -15
  44. package/dist/cjs/shared/route/index.js +22 -32
  45. package/dist/cjs/shared/route/loadPageRoutes.js +11 -10
  46. package/dist/cjs/shared/route/noRouteMatch.js +4 -0
  47. package/dist/cjs/shared/route/resolveRouteFunction.js +1 -1
  48. package/dist/cjs/shared/utils.js +1 -1
  49. package/dist/cjs/utils/getFilePathAbsolute.js +11 -11
  50. package/dist/cjs/utils/isExternalLink.js +7 -0
  51. package/dist/cjs/utils/{hasPropertyGetter.js → isPropertyGetter.js} +3 -3
  52. package/dist/cjs/utils/onPageVisibilityChange.js +19 -0
  53. package/dist/cjs/utils/parseUrl.js +1 -1
  54. package/dist/cjs/utils/projectInfo.js +1 -1
  55. package/dist/cjs/utils/truncateString.js +12 -7
  56. package/dist/esm/__internal/index.d.ts +6 -3
  57. package/dist/esm/__internal/index.js +8 -3
  58. package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -3
  59. package/dist/esm/client/client-routing-runtime/createPageContext.js +3 -4
  60. package/dist/esm/client/client-routing-runtime/entry.js +2 -2
  61. package/dist/esm/client/client-routing-runtime/getBaseServer.d.ts +2 -1
  62. package/dist/esm/client/client-routing-runtime/getBaseServer.js +2 -1
  63. package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +39 -0
  64. package/dist/esm/client/client-routing-runtime/{getPageContext.js → getPageContextFromHooks.js} +50 -79
  65. package/dist/esm/client/client-routing-runtime/history.d.ts +3 -1
  66. package/dist/esm/client/client-routing-runtime/history.js +31 -9
  67. package/dist/esm/client/client-routing-runtime/installClientRouter.d.ts +2 -0
  68. package/dist/esm/client/client-routing-runtime/installClientRouter.js +22 -0
  69. package/dist/esm/client/client-routing-runtime/isClientSideRoutable.d.ts +8 -0
  70. package/dist/esm/client/client-routing-runtime/isClientSideRoutable.js +12 -0
  71. package/dist/esm/client/client-routing-runtime/navigate.d.ts +0 -2
  72. package/dist/esm/client/client-routing-runtime/navigate.js +9 -8
  73. package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.d.ts +4 -0
  74. package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +63 -0
  75. package/dist/esm/client/client-routing-runtime/onLinkClick.d.ts +2 -0
  76. package/dist/esm/client/client-routing-runtime/onLinkClick.js +40 -0
  77. package/dist/esm/client/client-routing-runtime/prefetch.js +54 -29
  78. package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +19 -0
  79. package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +347 -0
  80. package/dist/esm/client/client-routing-runtime/scrollRestoration.d.ts +6 -0
  81. package/dist/esm/client/client-routing-runtime/scrollRestoration.js +25 -0
  82. package/dist/esm/client/client-routing-runtime/setScrollPosition.d.ts +7 -0
  83. package/dist/esm/client/client-routing-runtime/setScrollPosition.js +77 -0
  84. package/dist/esm/client/client-routing-runtime/skipLink.d.ts +0 -1
  85. package/dist/esm/client/client-routing-runtime/skipLink.js +9 -5
  86. package/dist/esm/client/client-routing-runtime/utils.d.ts +2 -0
  87. package/dist/esm/client/client-routing-runtime/utils.js +2 -0
  88. package/dist/esm/client/server-routing-runtime/getPageContext.js +1 -1
  89. package/dist/esm/client/shared/executeOnRenderClientHook.js +6 -5
  90. package/dist/esm/client/shared/getPageContextProxyForUser.js +13 -7
  91. package/dist/esm/client/shared/loadPageFilesClientSide.d.ts +8 -3
  92. package/dist/esm/client/shared/loadPageFilesClientSide.js +5 -5
  93. package/dist/esm/node/plugin/plugins/buildConfig.js +3 -3
  94. package/dist/esm/node/plugin/plugins/commonConfig.js +0 -3
  95. package/dist/esm/node/plugin/plugins/config/index.js +4 -4
  96. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +9 -9
  97. package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -0
  98. package/dist/esm/node/plugin/plugins/envVars.d.ts +2 -0
  99. package/dist/esm/node/plugin/plugins/envVars.js +35 -20
  100. package/dist/esm/node/plugin/plugins/importBuild/index.js +3 -3
  101. package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
  102. package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -3
  103. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
  104. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -4
  105. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
  106. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
  107. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -1
  108. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +250 -229
  109. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +2 -2
  110. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +7 -5
  111. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +2 -2
  112. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +37 -15
  113. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
  114. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +7 -0
  115. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +15 -0
  116. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
  117. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +16 -18
  118. package/dist/esm/node/plugin/plugins/previewConfig.js +11 -2
  119. package/dist/esm/node/prerender/runPrerender.js +29 -21
  120. package/dist/esm/node/prerender/utils.d.ts +1 -1
  121. package/dist/esm/node/prerender/utils.js +1 -1
  122. package/dist/esm/node/runtime/html/serializePageContextClientSide.js +21 -7
  123. package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +5 -5
  124. package/dist/esm/node/runtime/renderPage/debugPageFiles.js +5 -5
  125. package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.d.ts +2 -2
  126. package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
  127. package/dist/esm/node/runtime/renderPage/log404/index.js +28 -16
  128. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
  129. package/dist/esm/node/runtime/renderPage.js +3 -3
  130. package/dist/esm/node/runtime/utils.d.ts +1 -1
  131. package/dist/esm/node/runtime/utils.js +1 -1
  132. package/dist/esm/node/shared/getClientEntryFilePath.js +1 -1
  133. package/dist/esm/node/shared/getConfigVike.d.ts +2 -1
  134. package/dist/esm/node/shared/getConfigVike.js +4 -1
  135. package/dist/esm/shared/addUrlComputedProps.d.ts +1 -0
  136. package/dist/esm/shared/addUrlComputedProps.js +25 -13
  137. package/dist/esm/shared/getPageFiles/analyzeClientSide.js +2 -4
  138. package/dist/esm/shared/getPageFiles/getExports.js +2 -2
  139. package/dist/esm/shared/hooks/getHook.js +1 -1
  140. package/dist/esm/shared/page-configs/PageConfig.d.ts +55 -31
  141. package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
  142. package/dist/esm/shared/page-configs/getExportPath.js +3 -3
  143. package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +7 -0
  144. package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +37 -0
  145. package/dist/esm/shared/page-configs/helpers/getConfigValue.d.ts +14 -0
  146. package/dist/esm/shared/page-configs/helpers/getConfigValue.js +38 -0
  147. package/dist/esm/shared/page-configs/helpers.d.ts +13 -0
  148. package/dist/esm/shared/page-configs/helpers.js +27 -0
  149. package/dist/esm/shared/page-configs/loadConfigValues.js +2 -2
  150. package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +4 -4
  151. package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +15 -11
  152. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -2
  153. package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +9 -10
  154. package/dist/esm/shared/route/abort.js +1 -1
  155. package/dist/esm/shared/route/executeOnBeforeRouteHook.d.ts +5 -8
  156. package/dist/esm/shared/route/executeOnBeforeRouteHook.js +41 -15
  157. package/dist/esm/shared/route/index.d.ts +12 -10
  158. package/dist/esm/shared/route/index.js +23 -33
  159. package/dist/esm/shared/route/loadPageRoutes.js +8 -7
  160. package/dist/esm/shared/route/noRouteMatch.d.ts +1 -0
  161. package/dist/esm/shared/route/noRouteMatch.js +1 -0
  162. package/dist/esm/shared/route/resolveRouteFunction.js +1 -1
  163. package/dist/esm/shared/utils.d.ts +1 -1
  164. package/dist/esm/shared/utils.js +1 -1
  165. package/dist/esm/utils/getFilePathAbsolute.d.ts +1 -1
  166. package/dist/esm/utils/getFilePathAbsolute.js +11 -11
  167. package/dist/esm/utils/isPropertyGetter.d.ts +1 -0
  168. package/dist/esm/utils/{hasPropertyGetter.js → isPropertyGetter.js} +1 -1
  169. package/dist/esm/utils/onPageVisibilityChange.d.ts +4 -0
  170. package/dist/esm/utils/onPageVisibilityChange.js +16 -0
  171. package/dist/esm/utils/parseUrl.js +1 -1
  172. package/dist/esm/utils/projectInfo.d.ts +1 -1
  173. package/dist/esm/utils/projectInfo.js +1 -1
  174. package/dist/esm/utils/truncateString.d.ts +2 -1
  175. package/dist/esm/utils/truncateString.js +10 -7
  176. package/node/cli/bin-entry.js +1 -1
  177. package/package.json +2 -3
  178. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -16
  179. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -13
  180. package/dist/cjs/shared/page-configs/utils.js +0 -103
  181. package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +0 -29
  182. package/dist/esm/client/client-routing-runtime/getPageId.d.ts +0 -10
  183. package/dist/esm/client/client-routing-runtime/getPageId.js +0 -17
  184. package/dist/esm/client/client-routing-runtime/navigationState.d.ts +0 -5
  185. package/dist/esm/client/client-routing-runtime/navigationState.js +0 -14
  186. package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.d.ts +0 -2
  187. package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.js +0 -15
  188. package/dist/esm/client/client-routing-runtime/useClientRouter.d.ts +0 -6
  189. package/dist/esm/client/client-routing-runtime/useClientRouter.js +0 -493
  190. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +0 -24
  191. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -13
  192. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.d.ts +0 -3
  193. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -10
  194. package/dist/esm/shared/page-configs/utils.d.ts +0 -35
  195. package/dist/esm/shared/page-configs/utils.js +0 -97
  196. package/dist/esm/utils/hasPropertyGetter.d.ts +0 -1
  197. /package/dist/esm/{client/client-routing-runtime → utils}/isExternalLink.d.ts +0 -0
  198. /package/dist/esm/{client/client-routing-runtime → utils}/isExternalLink.js +0 -0
@@ -2,7 +2,7 @@ export { loadConfigValues };
2
2
  import { objectAssign } from '../utils.js';
3
3
  import { parseConfigValuesImported } from './serialize/parseConfigValuesImported.js';
4
4
  async function loadConfigValues(pageConfig, isDev) {
5
- if ('isLoaded' in pageConfig &&
5
+ if ('isAllLoaded' in pageConfig &&
6
6
  // We don't need to cache in dev, since Vite already caches the virtual module
7
7
  !isDev) {
8
8
  return pageConfig;
@@ -10,6 +10,6 @@ async function loadConfigValues(pageConfig, isDev) {
10
10
  const configValuesImported = await pageConfig.loadConfigValuesAll();
11
11
  const configValuesAddendum = parseConfigValuesImported(configValuesImported);
12
12
  Object.assign(pageConfig.configValues, configValuesAddendum);
13
- objectAssign(pageConfig, { isLoaded: true });
13
+ objectAssign(pageConfig, { isAllLoaded: true });
14
14
  return pageConfig;
15
15
  }
@@ -3,9 +3,9 @@ export type { PageConfigGlobalRuntimeSerialized };
3
3
  export type { ConfigValueSerialized };
4
4
  export type { ConfigValueImported };
5
5
  import type { DefinedAt, PageConfigRuntime } from '../PageConfig.js';
6
- /** page config data structure serialized in virtual files: parsing it results in PageConfigRuntime */
6
+ /** Page config data structure serialized in virtual files: parsing it results in PageConfigRuntime */
7
7
  type PageConfigRuntimeSerialized = Omit<PageConfigRuntime, 'configValues'> & {
8
- /** Config values that are loaded eagerly and serializable such as config.passToClient */
8
+ /** Config values that are serializable and loaded eagerly such as config.passToClient */
9
9
  configValuesSerialized: Record<string, ConfigValueSerialized>;
10
10
  /** Config values imported eagerly such as config.route */
11
11
  configValuesImported: ConfigValueImported[];
@@ -13,12 +13,12 @@ type PageConfigRuntimeSerialized = Omit<PageConfigRuntime, 'configValues'> & {
13
13
  type PageConfigGlobalRuntimeSerialized = {
14
14
  configValuesImported: ConfigValueImported[];
15
15
  };
16
- /** Value is serialized. */
16
+ /** Value is serialized */
17
17
  type ConfigValueSerialized = {
18
18
  valueSerialized: string;
19
19
  definedAt: DefinedAt;
20
20
  };
21
- /** Value is imported. */
21
+ /** Value is imported */
22
22
  type ConfigValueImported = {
23
23
  configName: string;
24
24
  importPath: string;
@@ -1,21 +1,18 @@
1
1
  export { parseConfigValuesImported };
2
- import { assert, assertUsage } from '../../utils.js';
2
+ import { assert } from '../../utils.js';
3
3
  import { assertExportsOfValueFile } from '../assertExports.js';
4
- import pc from '@brillout/picocolors';
5
4
  function parseConfigValuesImported(configValuesImported) {
6
5
  const configValues = {};
7
6
  const addConfigValue = (configName, value, importPath, exportName) => {
8
7
  configValues[configName] = {
9
8
  value,
10
9
  definedAt: {
11
- file: {
12
- // importPath cannot be relative to the current file, since the current file is a virtual file
13
- filePathToShowToUser: importPath,
14
- fileExportPath: [configName, 'default'].includes(exportName)
15
- ? []
16
- : // Side-effect config
17
- [exportName]
18
- }
10
+ // importPath cannot be relative to the current file, since the current file is a virtual file
11
+ filePathToShowToUser: importPath,
12
+ fileExportPathToShowToUser: [configName, 'default'].includes(exportName)
13
+ ? []
14
+ : // Side-effect config
15
+ [exportName]
19
16
  }
20
17
  };
21
18
  assertIsNotNull(value, configName, importPath);
@@ -46,5 +43,12 @@ function parseConfigValuesImported(configValuesImported) {
46
43
  }
47
44
  function assertIsNotNull(configValue, configName, importPath) {
48
45
  assert(!importPath.includes('+config.'));
49
- assertUsage(configValue !== null, `Set ${pc.cyan(configName)} to ${pc.cyan('null')} in a +config.h.js file instead of ${importPath}`);
46
+ /* Re-use this for:
47
+ * - upcoming config.requestPageContextOnNavigation
48
+ * - for cumulative values in the future: we don't need this for now because, currently, cumulative values are never imported.
49
+ assertUsage(
50
+ configValue !== null,
51
+ `Set ${pc.cyan(configName)} to ${pc.cyan('null')} in a +config.h.js file instead of ${importPath}`
52
+ )
53
+ */
50
54
  }
@@ -2,7 +2,7 @@ export { parsePageConfigs };
2
2
  import { parse } from '@brillout/json-serializer/parse';
3
3
  import { parseConfigValuesImported } from './parseConfigValuesImported.js';
4
4
  import { assert, assertUsage, isCallable } from '../../utils.js';
5
- import { getConfigDefinedAtString } from '../utils.js';
5
+ import { getConfigDefinedAtString } from '../helpers.js';
6
6
  function parsePageConfigs(pageConfigsSerialized, pageConfigGlobalSerialized) {
7
7
  const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
8
8
  const configValues = {};
@@ -49,7 +49,7 @@ function assertRouteConfigValue(configValues) {
49
49
  return;
50
50
  const { value } = configValue;
51
51
  const configValueType = typeof value;
52
- const configDefinedAt = getConfigDefinedAtString(configName, configValue, true);
52
+ const configDefinedAt = getConfigDefinedAtString('Config', configName, configValue);
53
53
  assertUsage(configValueType === 'string' || isCallable(value), `${configDefinedAt} has an invalid type '${configValueType}': it should be a string or a function instead, see https://vike.dev/route`);
54
54
  /* We don't use assertRouteString() in order to avoid unnecessarily bloating the client-side bundle when using Server Routing:
55
55
  * - When using Server Routing, this file is loaded => loading assertRouteString() would bloat the client bundle.
@@ -23,29 +23,28 @@ function serializeConfigValue(lines, configName, configValueSerialized) {
23
23
  function serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements) {
24
24
  assert(!configValueSource.valueIsFilePath);
25
25
  assert(whitespace.replaceAll(' ', '').length === 0);
26
- const { valueIsImportedAtRuntime, definedAtInfo } = configValueSource;
26
+ const { valueIsImportedAtRuntime, definedAt } = configValueSource;
27
27
  assert(valueIsImportedAtRuntime);
28
- const { filePathRelativeToUserRootDir, importPathAbsolute, exportName } = definedAtInfo;
29
- const importPath = filePathRelativeToUserRootDir ?? importPathAbsolute;
30
- assertPosixPath(importPath);
31
- const fileName = path.posix.basename(importPath);
28
+ const { filePathAbsoluteVite, fileExportName } = definedAt;
29
+ assertPosixPath(filePathAbsoluteVite);
30
+ const fileName = path.posix.basename(filePathAbsoluteVite);
32
31
  const isValueFile = fileName.startsWith('+');
33
32
  if (isValueFile)
34
- assert(exportName === undefined);
35
- const { importName, importStatement } = generateEagerImport(importPath, varCounterContainer.varCounter++, exportName);
33
+ assert(fileExportName === undefined);
34
+ const { importName, importStatement } = generateEagerImport(filePathAbsoluteVite, varCounterContainer.varCounter++, fileExportName);
36
35
  importStatements.push(importStatement);
37
36
  const lines = [];
38
37
  lines.push(` {`);
39
38
  lines.push(` configName: '${configName}',`);
40
- lines.push(` importPath: '${importPath}',`);
39
+ lines.push(` importPath: '${filePathAbsoluteVite}',`);
41
40
  lines.push(` isValueFile: ${JSON.stringify(isValueFile)},`);
42
41
  if (isValueFile) {
43
42
  lines.push(` exportValues: ${importName},`);
44
43
  }
45
44
  else {
46
45
  lines.push(` exportValue: ${importName},`);
47
- assert(exportName);
48
- lines.push(` exportName: ${JSON.stringify(exportName)},`);
46
+ assert(fileExportName);
47
+ lines.push(` exportName: ${JSON.stringify(fileExportName)},`);
49
48
  }
50
49
  lines.push(` },`);
51
50
  return lines;
@@ -41,7 +41,7 @@ function redirect(url, statusCode) {
41
41
  function render(value, abortReason) {
42
42
  const args = [typeof value === 'number' ? String(value) : JSON.stringify(value)];
43
43
  if (abortReason !== undefined)
44
- args.push(truncateString(JSON.stringify(abortReason), 30, null));
44
+ args.push(truncateString(JSON.stringify(abortReason), 30));
45
45
  const abortCaller = 'throw render()';
46
46
  const abortCall = `throw render(${args.join(', ')})`;
47
47
  return render_(value, abortReason, abortCall, abortCaller);
@@ -1,3 +1,4 @@
1
+ import type { PageContextForRoute, PageContextFromRoute } from './index.js';
1
2
  export { executeOnBeforeRouteHook };
2
3
  export type { OnBeforeRouteHook };
3
4
  type OnBeforeRouteHook = {
@@ -6,12 +7,8 @@ type OnBeforeRouteHook = {
6
7
  urlOriginal: string;
7
8
  } & Record<string, unknown>) => unknown;
8
9
  };
9
- declare function executeOnBeforeRouteHook(onBeforeRouteHook: OnBeforeRouteHook, pageContext: {
10
- urlOriginal: string;
11
- _allPageIds: string[];
12
- }): Promise<null | {
13
- urlOriginal?: string;
14
- _urlOriginalPristine?: string;
15
- _pageId?: string | null;
16
- routeParams?: Record<string, string>;
10
+ declare function executeOnBeforeRouteHook(pageContext: PageContextForRoute): Promise<null | ({
11
+ _routingProvidedByOnBeforeRouteHook: true;
12
+ } & PageContextFromRoute) | {
13
+ _routingProvidedByOnBeforeRouteHook: false;
17
14
  }>;
@@ -1,11 +1,40 @@
1
1
  import { assertPageContextProvidedByUser } from '../assertPageContextProvidedByUser.js';
2
- import { assertUsage, hasProp, isObjectWithKeys, objectAssign, assertWarning, assertUsageUrl, joinEnglish } from './utils.js';
2
+ import { assertUsage, hasProp, isObjectWithKeys, objectAssign, assertWarning, assertUsageUrl, joinEnglish, assert } from './utils.js';
3
3
  import { assertRouteParams, assertSyncRouting } from './resolveRouteFunction.js';
4
4
  import pc from '@brillout/picocolors';
5
5
  export { executeOnBeforeRouteHook };
6
- async function executeOnBeforeRouteHook(onBeforeRouteHook, pageContext) {
6
+ async function executeOnBeforeRouteHook(pageContext) {
7
+ const pageContextFromOnBeforeRouteHook = {};
8
+ if (!pageContext._onBeforeRouteHook)
9
+ return null;
10
+ const pageContextFromHook = await executeHook(pageContext._onBeforeRouteHook, pageContext);
11
+ if (pageContextFromHook) {
12
+ objectAssign(pageContextFromOnBeforeRouteHook, pageContextFromHook);
13
+ if (hasProp(pageContextFromOnBeforeRouteHook, '_pageId', 'string') ||
14
+ hasProp(pageContextFromOnBeforeRouteHook, '_pageId', 'null')) {
15
+ // We bypass Vike's routing
16
+ if (!hasProp(pageContextFromOnBeforeRouteHook, 'routeParams')) {
17
+ objectAssign(pageContextFromOnBeforeRouteHook, { routeParams: {} });
18
+ }
19
+ else {
20
+ assert(hasProp(pageContextFromOnBeforeRouteHook, 'routeParams', 'object'));
21
+ }
22
+ objectAssign(pageContextFromOnBeforeRouteHook, {
23
+ _routingProvidedByOnBeforeRouteHook: true,
24
+ _debugRouteMatches: 'CUSTOM_ROUTING'
25
+ });
26
+ return pageContextFromOnBeforeRouteHook;
27
+ }
28
+ }
29
+ objectAssign(pageContextFromOnBeforeRouteHook, {
30
+ _routingProvidedByOnBeforeRouteHook: false
31
+ });
32
+ return pageContextFromOnBeforeRouteHook;
33
+ }
34
+ async function executeHook(onBeforeRouteHook, pageContext) {
7
35
  let hookReturn = onBeforeRouteHook.onBeforeRoute(pageContext);
8
36
  assertSyncRouting(hookReturn, `The onBeforeRoute() hook ${onBeforeRouteHook.hookFilePath}`);
37
+ // TODO/v1-release: make executeOnBeforeRouteHook() and route() sync
9
38
  hookReturn = await hookReturn;
10
39
  const errPrefix = `The onBeforeRoute() hook defined by ${onBeforeRouteHook.hookFilePath}`;
11
40
  assertUsage(hookReturn === null ||
@@ -23,28 +52,25 @@ async function executeOnBeforeRouteHook(onBeforeRouteHook, pageContext) {
23
52
  if (hasProp(hookReturn.pageContext, 'routeParams')) {
24
53
  assertRouteParams(hookReturn.pageContext, `${errPrefix} returned ${pc.cyan('{ pageContext: { routeParams } }')} but routeParams should`);
25
54
  }
26
- const pageContextAddendumHook = {};
55
+ const deprecatedReturn = (prop) => `${errPrefix} returned ${pc.cyan(`{ pageContext: { ${prop} } }`)} which is deprecated. Return ${pc.cyan('{ pageContext: { urlLogical } }')} instead.`;
27
56
  if (hasProp(hookReturn.pageContext, 'url')) {
28
- assertWarning(false, `${errPrefix} returned ${pc.cyan('{ pageContext: { url } }')} but ${pc.cyan('pageContext.url')} has been renamed to ${pc.cyan('pageContext.urlOriginal')}. Return ${pc.cyan('{ pageContext: { urlOriginal } }')} instead. (See https://vike.dev/migration/0.4.23 for more information.)`, { onlyOnce: true });
29
- hookReturn.pageContext.urlOriginal = hookReturn.pageContext.url;
57
+ assertWarning(false, deprecatedReturn('url'), { onlyOnce: true });
58
+ hookReturn.pageContext.urlLogical = hookReturn.pageContext.url;
30
59
  delete hookReturn.pageContext.url;
31
60
  }
32
61
  if (hasProp(hookReturn.pageContext, 'urlOriginal')) {
33
- assertUsageUrl(hookReturn.pageContext.urlOriginal, `${errPrefix} returned ${pc.cyan('{ pageContext: { urlOriginal } }')} but ${pc.cyan('urlOriginal')}`);
34
- // Ugly workaround: ideally urlOriginal should be immutable.
35
- // - Instead of using pageContext._urlOriginalPristine, maybe we can keep pageContext.urlOriginal immutable while re-using `pageContext._urlRewrite`.
36
- // - Or better yet we rename pageContext._urlRewrite to pageContext.urlLogical and we allow the user to override pageContext.urlLogical, and we rename pageContext.urlOriginal => `pageContext.urlReal`.
37
- // - pageContext.urlReal / pageContext.urlLogical
38
- // VS
39
- // pageContext.urlReal / pageContext.urlModified
40
- // VS
41
- // pageContext.urlOriginal / pageContext.urlModified
42
- objectAssign(pageContextAddendumHook, { _urlOriginalPristine: pageContext.urlOriginal });
62
+ assertWarning(false, deprecatedReturn('urlOriginal'), { onlyOnce: true });
63
+ hookReturn.pageContext.urlLogical = hookReturn.pageContext.urlOriginal;
64
+ delete hookReturn.pageContext.urlOriginal;
65
+ }
66
+ if (hasProp(hookReturn.pageContext, 'urlLogical')) {
67
+ assertUsageUrl(hookReturn.pageContext.urlLogical, `${errPrefix} returned ${pc.cyan('{ pageContext: { urlLogical } }')} but ${pc.cyan('urlLogical')}`);
43
68
  }
44
69
  assertPageContextProvidedByUser(hookReturn.pageContext, {
45
70
  hookFilePath: onBeforeRouteHook.hookFilePath,
46
71
  hookName: 'onBeforeRoute'
47
72
  });
73
+ const pageContextAddendumHook = {};
48
74
  objectAssign(pageContextAddendumHook, hookReturn.pageContext);
49
75
  return pageContextAddendumHook;
50
76
  }
@@ -1,5 +1,8 @@
1
1
  export { route };
2
- export type { PageRoutes, PageContextForRoute, RouteMatches };
2
+ export type { PageContextForRoute };
3
+ export type { PageContextFromRoute };
4
+ export type { PageRoutes };
5
+ export type { RouteMatches };
3
6
  import type { PageFile } from '../getPageFiles.js';
4
7
  import { PageContextUrlComputedPropsInternal, PageContextUrlSources } from '../addUrlComputedProps.js';
5
8
  import { type OnBeforeRouteHook } from './executeOnBeforeRouteHook.js';
@@ -13,6 +16,12 @@ type PageContextForRoute = PageContextUrlComputedPropsInternal & {
13
16
  _pageRoutes: PageRoutes;
14
17
  _onBeforeRouteHook: OnBeforeRouteHook | null;
15
18
  } & PageContextUrlSources;
19
+ type PageContextFromRoute = {
20
+ _pageId: string | null;
21
+ routeParams: Record<string, string>;
22
+ _routingProvidedByOnBeforeRouteHook?: boolean;
23
+ _debugRouteMatches: RouteMatches;
24
+ };
16
25
  type RouteMatch = {
17
26
  pageId: string;
18
27
  routeString?: string;
@@ -20,12 +29,5 @@ type RouteMatch = {
20
29
  routeType: RouteType;
21
30
  routeParams: Record<string, string>;
22
31
  };
23
- type RouteMatches = 'CUSTOM_ROUTE' | RouteMatch[];
24
- declare function route(pageContext: PageContextForRoute): Promise<{
25
- pageContextAddendum: {
26
- _pageId: string | null;
27
- routeParams: Record<string, string>;
28
- _routingProvidedByOnBeforeRouteHook: boolean;
29
- _routeMatches: RouteMatches;
30
- } & Record<string, unknown>;
31
- }>;
32
+ type RouteMatches = 'CUSTOM_ROUTING' | RouteMatch[];
33
+ declare function route(pageContextForRoute: PageContextForRoute): Promise<PageContextFromRoute>;
@@ -5,7 +5,7 @@ import { isBrowser } from '../../utils/isBrowser.js';
5
5
  if (isBrowser()) {
6
6
  assertClientRouting();
7
7
  }
8
- import { assert, assertUsage, hasProp, isPlainObject, objectAssign } from './utils.js';
8
+ import { assert, assertUsage, isPlainObject, objectAssign } from './utils.js';
9
9
  import { addUrlComputedProps } from '../addUrlComputedProps.js';
10
10
  import { resolvePrecendence } from './resolvePrecedence.js';
11
11
  import { resolveRouteString } from './resolveRouteString.js';
@@ -13,35 +13,25 @@ import { resolveRouteFunction } from './resolveRouteFunction.js';
13
13
  import { executeOnBeforeRouteHook } from './executeOnBeforeRouteHook.js';
14
14
  import { debug } from './debug.js';
15
15
  import pc from '@brillout/picocolors';
16
- async function route(pageContext) {
17
- addUrlComputedProps(pageContext);
18
- debug('Pages routes:', pageContext._pageRoutes);
19
- const pageContextAddendum = {};
20
- if (pageContext._onBeforeRouteHook) {
21
- const pageContextAddendumHook = await executeOnBeforeRouteHook(pageContext._onBeforeRouteHook, pageContext);
22
- if (pageContextAddendumHook) {
23
- objectAssign(pageContextAddendum, pageContextAddendumHook);
24
- if (hasProp(pageContextAddendum, '_pageId', 'string') || hasProp(pageContextAddendum, '_pageId', 'null')) {
25
- // We bypass Vike's routing
26
- if (!hasProp(pageContextAddendum, 'routeParams')) {
27
- objectAssign(pageContextAddendum, { routeParams: {} });
28
- }
29
- else {
30
- assert(hasProp(pageContextAddendum, 'routeParams', 'object'));
31
- }
32
- objectAssign(pageContextAddendum, {
33
- _routingProvidedByOnBeforeRouteHook: true,
34
- _routeMatches: 'CUSTOM_ROUTE'
35
- });
36
- return { pageContextAddendum };
37
- }
38
- // We already assign so that `pageContext.urlOriginal === pageContextAddendum.urlOriginal`; enabling the `onBeforeRoute()` hook to mutate `pageContext.urlOriginal` before routing.
39
- objectAssign(pageContext, pageContextAddendum);
16
+ async function route(pageContextForRoute) {
17
+ debug('Pages routes:', pageContextForRoute._pageRoutes);
18
+ addUrlComputedProps(pageContextForRoute);
19
+ const pageContextFromRoute = {};
20
+ // onBeforeRoute()
21
+ const pageContextFromOnBeforeRouteHook = await executeOnBeforeRouteHook(pageContextForRoute);
22
+ if (pageContextFromOnBeforeRouteHook) {
23
+ if (pageContextFromOnBeforeRouteHook._routingProvidedByOnBeforeRouteHook) {
24
+ assert(pageContextFromOnBeforeRouteHook._pageId);
25
+ return pageContextFromOnBeforeRouteHook;
26
+ }
27
+ else {
28
+ objectAssign(pageContextFromRoute, pageContextFromOnBeforeRouteHook);
40
29
  }
41
30
  }
42
- objectAssign(pageContextAddendum, {
43
- _routingProvidedByOnBeforeRouteHook: false
44
- });
31
+ // We take into account pageContext.urlLogical set by onBeforeRoute()
32
+ const pageContext = {};
33
+ objectAssign(pageContext, pageContextForRoute);
34
+ objectAssign(pageContext, pageContextFromOnBeforeRouteHook);
45
35
  // Vike's routing
46
36
  const allPageIds = pageContext._allPageIds;
47
37
  assert(allPageIds.length >= 0);
@@ -93,21 +83,21 @@ async function route(pageContext) {
93
83
  resolvePrecendence(routeMatches);
94
84
  const winner = routeMatches[0];
95
85
  debug(`Route matches for URL ${pc.cyan(urlPathname)} (in precedence order):`, routeMatches);
96
- objectAssign(pageContextAddendum, { _routeMatches: routeMatches });
86
+ objectAssign(pageContextFromRoute, { _debugRouteMatches: routeMatches });
97
87
  if (!winner) {
98
- objectAssign(pageContextAddendum, {
88
+ objectAssign(pageContextFromRoute, {
99
89
  _pageId: null,
100
90
  routeParams: {}
101
91
  });
102
- return { pageContextAddendum };
92
+ return pageContextFromRoute;
103
93
  }
104
94
  {
105
95
  const { routeParams } = winner;
106
96
  assert(isPlainObject(routeParams));
107
- objectAssign(pageContextAddendum, {
97
+ objectAssign(pageContextFromRoute, {
108
98
  _pageId: winner.pageId,
109
99
  routeParams: winner.routeParams
110
100
  });
111
101
  }
112
- return { pageContextAddendum };
102
+ return pageContextFromRoute;
113
103
  }
@@ -3,10 +3,10 @@ import { isErrorPageId } from '../error-page.js';
3
3
  import { assert, assertUsage, hasProp, slice } from './utils.js';
4
4
  import { deduceRouteStringFromFilesystemPath } from './deduceRouteStringFromFilesystemPath.js';
5
5
  import { isCallable } from '../utils.js';
6
- import { getConfigValue, getDefinedAtString, getHookFilePathToShowToUser } from '../page-configs/utils.js';
6
+ import { getConfigDefinedAtString, getConfigValue, getDefinedAtString, getHookFilePathToShowToUser } from '../page-configs/helpers.js';
7
7
  import { warnDeprecatedAllowKey } from './resolveRouteFunction.js';
8
8
  async function loadPageRoutes(
9
- // TODO: remove all arguments and use GlobalContext instead
9
+ // Remove all arguments and use GlobalContext instead?
10
10
  pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
11
11
  await Promise.all(pageFilesAll.filter((p) => p.fileType === '.page.route').map((p) => p.loadFile?.()));
12
12
  const { onBeforeRouteHook, filesystemRoots } = getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal);
@@ -31,7 +31,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
31
31
  const configValue = getConfigValue(pageConfig, configName);
32
32
  if (configValue) {
33
33
  const route = configValue.value;
34
- const definedAt = getDefinedAtString(configValue, configName);
34
+ const definedAt = getDefinedAtString(configValue.definedAt, configName);
35
35
  if (typeof route === 'string') {
36
36
  pageRoute = {
37
37
  pageId,
@@ -136,12 +136,13 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
136
136
  function getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal) {
137
137
  // V1 Design
138
138
  if (pageConfigs.length > 0) {
139
- if (pageConfigGlobal.configValues.onBeforeRoute?.value) {
140
- const configValue = pageConfigGlobal.configValues.onBeforeRoute;
139
+ const hookName = 'onBeforeRoute';
140
+ if (pageConfigGlobal.configValues[hookName]?.value) {
141
+ const configValue = pageConfigGlobal.configValues[hookName];
141
142
  const { value: hookFn } = configValue;
142
143
  const hookFilePath = getHookFilePathToShowToUser(configValue);
143
- // TODO: use getConfigDefinedAtString()
144
- assertUsage(isCallable(hookFn), `The hook onBeforeRoute() defined by ${hookFilePath} should be a function.`);
144
+ const hookDefinedAt = getConfigDefinedAtString('Hook', hookName, configValue);
145
+ assertUsage(isCallable(hookFn), `${hookDefinedAt} should be a function.`);
145
146
  const onBeforeRouteHook = {
146
147
  hookFilePath: hookFilePath,
147
148
  onBeforeRoute: hookFn
@@ -0,0 +1 @@
1
+ export declare const noRouteMatch = "doesn't match the route of any of your pages";
@@ -0,0 +1 @@
1
+ export const noRouteMatch = "doesn't match the route of any of your pages";
@@ -9,7 +9,7 @@ async function resolveRouteFunction(routeFunction, pageContext, routeDefinedAt)
9
9
  assertPageContextUrlComputedProps(pageContext);
10
10
  let result = routeFunction(pageContext);
11
11
  assertSyncRouting(result, `The Route Function ${routeDefinedAt}`);
12
- // TODO/v1-release
12
+ // TODO/v1-release: make resolveRouteFunction() and route() sync
13
13
  //* We disallow asynchronous routing, because we need to check whether a link is a Vike link in a synchronous fashion before calling ev.preventDefault() in the 'click' event listener
14
14
  result = await result;
15
15
  //*/
@@ -15,7 +15,7 @@ export * from '../utils/stringifyStringArray.js';
15
15
  export * from '../utils/filesystemPathHandling.js';
16
16
  export * from '../utils/cast.js';
17
17
  export * from '../utils/projectInfo.js';
18
- export * from '../utils/hasPropertyGetter.js';
18
+ export * from '../utils/isPropertyGetter.js';
19
19
  export * from '../utils/isPromise.js';
20
20
  export * from '../utils/checkType.js';
21
21
  export * from '../utils/objectEntries.js';
@@ -19,7 +19,7 @@ export * from '../utils/stringifyStringArray.js';
19
19
  export * from '../utils/filesystemPathHandling.js';
20
20
  export * from '../utils/cast.js';
21
21
  export * from '../utils/projectInfo.js';
22
- export * from '../utils/hasPropertyGetter.js';
22
+ export * from '../utils/isPropertyGetter.js';
23
23
  export * from '../utils/isPromise.js';
24
24
  export * from '../utils/checkType.js';
25
25
  export * from '../utils/objectEntries.js';
@@ -2,4 +2,4 @@ export { getFilePathAbsolute };
2
2
  export { getFilePathRelativeToUserRootDir };
3
3
  import type { ResolvedConfig } from 'vite';
4
4
  declare function getFilePathAbsolute(filePath: string, config: ResolvedConfig): string;
5
- declare function getFilePathRelativeToUserRootDir(filePathAbsolute: string, userRootDir: string, alwaysRelative?: boolean): string;
5
+ declare function getFilePathRelativeToUserRootDir(filePathAbsoluteFilesystem: string, userRootDir: string, alwaysRelative?: boolean): string;
@@ -30,26 +30,26 @@ function getFilePathAbsolute(filePath, config) {
30
30
  filePathUnresolved = path.posix.join(root, filePath);
31
31
  assertPathIsFilesystemAbsolute(filePathUnresolved);
32
32
  }
33
- let filePathAbsolute;
33
+ let filePathAbsoluteFilesystem;
34
34
  try {
35
- filePathAbsolute = require_.resolve(filePathUnresolved, { paths: [config.root] });
35
+ filePathAbsoluteFilesystem = require_.resolve(filePathUnresolved, { paths: [config.root] });
36
36
  }
37
37
  catch (err) {
38
38
  console.error(err);
39
39
  assert(false);
40
40
  }
41
- filePathAbsolute = toPosixPath(filePathAbsolute);
42
- assertPathIsFilesystemAbsolute(filePathAbsolute);
43
- return filePathAbsolute;
41
+ filePathAbsoluteFilesystem = toPosixPath(filePathAbsoluteFilesystem);
42
+ assertPathIsFilesystemAbsolute(filePathAbsoluteFilesystem);
43
+ return filePathAbsoluteFilesystem;
44
44
  }
45
- function getFilePathRelativeToUserRootDir(filePathAbsolute, userRootDir, alwaysRelative = false) {
46
- assertPosixPath(filePathAbsolute);
45
+ function getFilePathRelativeToUserRootDir(filePathAbsoluteFilesystem, userRootDir, alwaysRelative = false) {
46
+ assertPosixPath(filePathAbsoluteFilesystem);
47
47
  assertPosixPath(userRootDir);
48
- let filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsolute);
49
- if (filePathAbsolute.startsWith(userRootDir)) {
48
+ let filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem);
49
+ if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
50
50
  assert(!filePathRelativeToUserRootDir.startsWith('.') && !filePathRelativeToUserRootDir.startsWith('/'),
51
51
  // Surprinsingly, this assertion seem to fail sometimes: https://github.com/vikejs/vike/issues/1139
52
- { filePathRelativeToUserRootDir, filePathAbsolute, userRootDir });
52
+ { filePathRelativeToUserRootDir, filePathAbsoluteFilesystem, userRootDir });
53
53
  filePathRelativeToUserRootDir = `/${filePathRelativeToUserRootDir}`;
54
54
  return filePathRelativeToUserRootDir;
55
55
  }
@@ -58,7 +58,7 @@ function getFilePathRelativeToUserRootDir(filePathAbsolute, userRootDir, alwaysR
58
58
  return filePathRelativeToUserRootDir;
59
59
  }
60
60
  else {
61
- return filePathAbsolute;
61
+ return filePathAbsoluteFilesystem;
62
62
  }
63
63
  }
64
64
  }
@@ -0,0 +1 @@
1
+ export declare function isPropertyGetter(obj: Object, prop: string): boolean;
@@ -1,4 +1,4 @@
1
- export function hasPropertyGetter(obj, prop) {
1
+ export function isPropertyGetter(obj, prop) {
2
2
  const descriptor = Object.getOwnPropertyDescriptor(obj, prop);
3
3
  return !!descriptor && !('value' in descriptor) && !!descriptor.get;
4
4
  }
@@ -0,0 +1,4 @@
1
+ export { onPageHide };
2
+ export { onPageShow };
3
+ declare function onPageHide(listener: () => void): void;
4
+ declare function onPageShow(listener: () => void): void;
@@ -0,0 +1,16 @@
1
+ export { onPageHide };
2
+ export { onPageShow };
3
+ function onPageHide(listener) {
4
+ window.addEventListener('visibilitychange', () => {
5
+ if (document.visibilityState === 'hidden') {
6
+ listener();
7
+ }
8
+ });
9
+ }
10
+ function onPageShow(listener) {
11
+ window.addEventListener('visibilitychange', () => {
12
+ if (document.visibilityState === 'visible') {
13
+ listener();
14
+ }
15
+ });
16
+ }
@@ -51,7 +51,7 @@ function parseUrl(url, baseServer) {
51
51
  const searchAll = {};
52
52
  Array.from(new URLSearchParams(searchOriginal || '')).forEach(([key, val]) => {
53
53
  search[key] = val;
54
- searchAll[key] = [...(searchAll[key] || []), val];
54
+ searchAll[key] = [...(searchAll.hasOwnProperty(key) ? searchAll[key] : []), val];
55
55
  });
56
56
  // Origin + pathname
57
57
  const { origin, pathname: pathnameResolved } = parsePathname(urlWithoutHashNorSearch, baseServer);
@@ -5,7 +5,7 @@ type ProjectVersion = typeof projectInfo.projectVersion;
5
5
  type ProjectTag = `[${PackageName}]` | `[${PackageName}@${ProjectVersion}]`;
6
6
  declare const projectInfo: {
7
7
  projectName: "Vike";
8
- projectVersion: "0.4.144";
8
+ projectVersion: "0.4.145-commit-2520555";
9
9
  npmPackageName: "vike";
10
10
  githubRepository: "https://github.com/vikejs/vike";
11
11
  };
@@ -1,6 +1,6 @@
1
1
  export { projectInfo };
2
2
  import { onProjectInfo } from './assertSingleInstance.js';
3
- const PROJECT_VERSION = '0.4.144';
3
+ const PROJECT_VERSION = '0.4.145-commit-2520555';
4
4
  const projectInfo = {
5
5
  projectName: 'Vike',
6
6
  projectVersion: PROJECT_VERSION,
@@ -1 +1,2 @@
1
- export declare function truncateString(str: string, lenMax: number, dim: null | ((ellipsis: string) => string)): string;
1
+ export { truncateString };
2
+ declare function truncateString(str: string, lenMax: number): string;
@@ -1,14 +1,17 @@
1
- export function truncateString(str, lenMax, dim) {
1
+ export { truncateString };
2
+ import pc from '@brillout/picocolors';
3
+ import { assert } from './assert.js';
4
+ function truncateString(str, lenMax) {
5
+ const lenMaxReal = lenMax - 3;
6
+ assert(lenMaxReal >= 1); // Show at least one character before the ellipsis
2
7
  if (str.length < lenMax) {
3
8
  return str;
4
9
  }
5
10
  else {
6
- // May break ANSI codes
7
- // - So far, the str we pass to truncateString(str) are expected to not contain any ANSI code
8
- str = str.substring(0, lenMax - 3);
9
- let ellipsis = '...';
10
- if (dim)
11
- ellipsis = dim(ellipsis);
11
+ // Breaks ANSI codes.
12
+ // - So far, the `str` we pass to truncateString(str) is always expected to not contain any ANSI code
13
+ str = str.substring(0, lenMaxReal);
14
+ const ellipsis = pc.dim('...');
12
15
  str = str + ellipsis;
13
16
  return str;
14
17
  }
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- import '../../dist/esm/node/cli/bin.mjs'
3
+ import '../../dist/esm/node/cli/bin.js'