vike 0.4.144-commit-756f5d7 → 0.4.144-commit-f7ab002

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 (82) hide show
  1. package/dist/cjs/node/plugin/plugins/buildConfig.js +2 -2
  2. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
  3. package/dist/cjs/node/plugin/plugins/importBuild/index.js +3 -3
  4. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -3
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
  6. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +152 -152
  7. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -2
  8. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +13 -5
  9. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
  10. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +2 -4
  11. package/dist/cjs/node/plugin/plugins/previewConfig.js +6 -2
  12. package/dist/cjs/node/prerender/runPrerender.js +8 -8
  13. package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +19 -6
  14. package/dist/cjs/node/runtime/renderPage/log404/index.js +27 -17
  15. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
  16. package/dist/cjs/node/shared/getClientEntryFilePath.js +2 -2
  17. package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +4 -6
  18. package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
  19. package/dist/cjs/shared/hooks/getHook.js +1 -1
  20. package/dist/cjs/shared/page-configs/getExportPath.js +3 -3
  21. package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +43 -0
  22. package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +44 -0
  23. package/dist/cjs/shared/page-configs/helpers.js +33 -0
  24. package/dist/cjs/shared/page-configs/loadConfigValues.js +2 -2
  25. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +6 -8
  26. package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -2
  27. package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +9 -10
  28. package/dist/cjs/shared/route/abort.js +1 -1
  29. package/dist/cjs/shared/route/loadPageRoutes.js +11 -10
  30. package/dist/cjs/utils/projectInfo.js +1 -1
  31. package/dist/cjs/utils/truncateString.js +12 -7
  32. package/dist/esm/client/client-routing-runtime/getPageContext.js +1 -1
  33. package/dist/esm/node/plugin/plugins/buildConfig.js +1 -1
  34. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
  35. package/dist/esm/node/plugin/plugins/importBuild/index.js +3 -3
  36. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
  37. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -3
  38. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
  39. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
  40. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +152 -152
  41. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
  42. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +14 -6
  43. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
  44. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
  45. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +2 -4
  46. package/dist/esm/node/plugin/plugins/previewConfig.js +6 -2
  47. package/dist/esm/node/prerender/runPrerender.js +2 -2
  48. package/dist/esm/node/runtime/html/serializePageContextClientSide.js +20 -7
  49. package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
  50. package/dist/esm/node/runtime/renderPage/log404/index.js +27 -16
  51. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
  52. package/dist/esm/node/shared/getClientEntryFilePath.js +1 -1
  53. package/dist/esm/shared/getPageFiles/analyzeClientSide.js +2 -4
  54. package/dist/esm/shared/getPageFiles/getExports.js +2 -2
  55. package/dist/esm/shared/hooks/getHook.js +1 -1
  56. package/dist/esm/shared/page-configs/PageConfig.d.ts +53 -31
  57. package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
  58. package/dist/esm/shared/page-configs/getExportPath.js +3 -3
  59. package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +7 -0
  60. package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +37 -0
  61. package/dist/esm/shared/page-configs/helpers/getConfigValue.d.ts +14 -0
  62. package/dist/esm/shared/page-configs/helpers/getConfigValue.js +38 -0
  63. package/dist/esm/shared/page-configs/helpers.d.ts +13 -0
  64. package/dist/esm/shared/page-configs/helpers.js +27 -0
  65. package/dist/esm/shared/page-configs/loadConfigValues.js +2 -2
  66. package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +4 -4
  67. package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +6 -8
  68. package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -2
  69. package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +9 -10
  70. package/dist/esm/shared/route/abort.js +1 -1
  71. package/dist/esm/shared/route/loadPageRoutes.js +8 -7
  72. package/dist/esm/utils/projectInfo.d.ts +1 -1
  73. package/dist/esm/utils/projectInfo.js +1 -1
  74. package/dist/esm/utils/truncateString.d.ts +2 -1
  75. package/dist/esm/utils/truncateString.js +10 -7
  76. package/package.json +2 -2
  77. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -16
  78. package/dist/cjs/shared/page-configs/utils.js +0 -103
  79. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +0 -24
  80. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -13
  81. package/dist/esm/shared/page-configs/utils.d.ts +0 -35
  82. package/dist/esm/shared/page-configs/utils.js +0 -97
@@ -4,7 +4,7 @@ import { getVirtualFileIdPageConfigValuesAll, isVirtualFileIdPageConfigValuesAll
4
4
  import { getVikeConfig } from './getVikeConfig.js';
5
5
  import { extractAssetsAddQuery } from '../../../../shared/extractAssetsQuery.js';
6
6
  import { debug } from './debug.js';
7
- import { getConfigValue } from '../../../../../shared/page-configs/utils.js';
7
+ import { getConfigValue } from '../../../../../shared/page-configs/helpers.js';
8
8
  import { getConfigValueSourcesRelevant } from '../../../shared/getConfigValueSourcesRelevant.js';
9
9
  import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
10
10
  import { serializeConfigValueImported } from '../../../../../shared/page-configs/serialize/serializeConfigValue.js';
@@ -1,14 +1,14 @@
1
1
  export { getVirtualFilePageConfigs };
2
2
  export { getConfigValueSerialized };
3
- import { assert, assertUsage, getPropAccessNotation, hasProp, objectEntries } from '../../../utils.js';
3
+ import { assert, assertUsage, getPropAccessNotation, objectEntries } from '../../../utils.js';
4
4
  import { getVirtualFileIdPageConfigValuesAll } from '../../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
5
5
  import { debug } from './debug.js';
6
- import { stringify } from '@brillout/json-serializer/stringify';
6
+ import { isJsonSerializerError, stringify } from '@brillout/json-serializer/stringify';
7
7
  import { getConfigEnv } from './helpers.js';
8
8
  import pc from '@brillout/picocolors';
9
9
  import { getVikeConfig } from './getVikeConfig.js';
10
10
  import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
11
- import { getConfigValueFilePathToShowToUser } from '../../../../../shared/page-configs/utils.js';
11
+ import { getConfigValueFilePathToShowToUser } from '../../../../../shared/page-configs/helpers.js';
12
12
  import { serializeConfigValue, serializeConfigValueImported } from '../../../../../shared/page-configs/serialize/serializeConfigValue.js';
13
13
  async function getVirtualFilePageConfigs(userRootDir, outDirRoot, isForClientSide, isDev, id, configVike, isClientRouting) {
14
14
  const { pageConfigs, pageConfigGlobal } = await getVikeConfig(userRootDir, outDirRoot, isDev, configVike.extensions, true);
@@ -105,15 +105,23 @@ function getConfigValueSerialized(value, configName, definedAt) {
105
105
  const valueName = `config${getPropAccessNotation(configName)}`;
106
106
  let configValueSerialized;
107
107
  try {
108
- configValueSerialized = stringify(value, { valueName });
108
+ configValueSerialized = stringify(value, { valueName, forbidReactElements: true });
109
109
  }
110
110
  catch (err) {
111
- assert(hasProp(err, 'messageCore', 'string'));
111
+ let serializationErrMsg = '';
112
+ if (isJsonSerializerError(err)) {
113
+ serializationErrMsg = err.messageCore;
114
+ }
115
+ else {
116
+ console.error('Serialization error:');
117
+ console.error(err);
118
+ serializationErrMsg = 'see serialization error printed above';
119
+ }
112
120
  const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
113
121
  assert(configValueFilePathToShowToUser);
114
122
  assertUsage(false, [
115
123
  `The value of the config ${pc.cyan(configName)} cannot be defined inside the file ${configValueFilePathToShowToUser}:`,
116
- `its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because the value isn't serializable: ${err.messageCore}.)`,
124
+ `its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because its value isn't serializable: ${serializationErrMsg}.)`,
117
125
  `Only serializable config values can be defined inside +config.h.js files, see https://vike.dev/header-file.`
118
126
  ].join(' '));
119
127
  }
@@ -6,20 +6,7 @@ function getConfigEnv(configValueSources, configName) {
6
6
  const configValueSource = getConfigValueSource(configValueSources, configName);
7
7
  if (!configValueSource)
8
8
  return null;
9
- if (configValueSource) {
10
- return configValueSource.configEnv;
11
- }
12
- else {
13
- // In case of effect/computed config values, there isn't any configValueSource
14
- // TODO: make it work for custom config definitions
15
- // - Ideally set configValueSource also for effect/computed config values?
16
- assert(false, 'TODO');
17
- /*
18
- const configDef = configDefinitionsBuiltIn[configName as keyof typeof configDefinitionsBuiltIn]
19
- if (!configDef) return null
20
- return configDef.env
21
- */
22
- }
9
+ return configValueSource.configEnv;
23
10
  }
24
11
  function isConfigSet(configValueSources, configName) {
25
12
  const configValueSource = getConfigValueSource(configValueSources, configName);
@@ -3,8 +3,8 @@ export { getConfigBuildErrorFormatted };
3
3
  export { getConfigExecutionErrorIntroMsg as getConfigExecutionErrorIntroMsg };
4
4
  export { isTmpFile };
5
5
  import 'source-map-support/register.js';
6
- import { type FilePath } from './getFilePathToShowToUser.js';
7
- declare function transpileAndExecuteFile(filePath: FilePath, isValueFile: boolean, userRootDir: string): Promise<{
6
+ import type { FilePathResolved } from '../../../../../shared/page-configs/PageConfig.js';
7
+ declare function transpileAndExecuteFile(filePath: FilePathResolved, isValueFile: boolean, userRootDir: string): Promise<{
8
8
  fileExports: Record<string, unknown>;
9
9
  }>;
10
10
  declare function getConfigBuildErrorFormatted(err: unknown): null | string;
@@ -11,7 +11,6 @@ import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, uni
11
11
  import { isImportData, replaceImportStatements } from './replaceImportStatements.js';
12
12
  import { vikeConfigDependencies } from './getVikeConfig.js';
13
13
  import 'source-map-support/register.js';
14
- import { getFilePathToShowToUser } from './getFilePathToShowToUser.js';
15
14
  import { assertExportsOfConfigFile } from '../../../../../shared/page-configs/assertExports.js';
16
15
  assertIsNotProductionRuntime();
17
16
  async function transpileAndExecuteFile(filePath, isValueFile, userRootDir) {
@@ -36,14 +35,13 @@ async function transpileFile(filePath, isValueFile, userRootDir) {
36
35
  }
37
36
  function transpileImports(codeOriginal, filePath, isValueFile) {
38
37
  // Do we need to remove the imports?
39
- const { filePathAbsoluteFilesystem } = filePath;
38
+ const { filePathAbsoluteFilesystem, filePathToShowToUser } = filePath;
40
39
  assertPosixPath(filePathAbsoluteFilesystem);
41
40
  const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
42
41
  const isPageConfigFile = !isValueFile;
43
42
  if (!isHeader && !isPageConfigFile) {
44
43
  return null;
45
44
  }
46
- const filePathToShowToUser = getFilePathToShowToUser(filePath);
47
45
  assertWarning(isPageConfigFile, `${filePathToShowToUser} is a JavaScript header file (.h.js), but JavaScript header files should only be used for +config.h.js, see https://vike.dev/header-file`, { onlyOnce: true });
48
46
  // Remove the imports
49
47
  const res = replaceImportStatements(codeOriginal, filePathToShowToUser);
@@ -273,7 +271,7 @@ function triggerPrepareStackTrace(err) {
273
271
  function getErrIntroMsg(operation, filePath) {
274
272
  const msg = [
275
273
  pc.red(`Failed to ${operation}`),
276
- pc.bold(pc.red(getFilePathToShowToUser(filePath))),
274
+ pc.bold(pc.red(filePath.filePathToShowToUser)),
277
275
  pc.red(`because:`)
278
276
  ].join(' ');
279
277
  return msg;
@@ -26,9 +26,13 @@ function previewConfig() {
26
26
  markEnvAsPreview();
27
27
  return () => {
28
28
  assertDist();
29
- if (!configVike.prerender) {
30
- addSsrMiddleware(server.middlewares);
29
+ /* We don't use this condition (we wrongfully always use the SSR middleware) because of the regression introduced by https://github.com/vitejs/vite/pull/14756 which stops servering .html files when `appType: 'custom'`.
30
+ if (!configVike.prerender || configVike.prerender.partial) {
31
+ addSsrMiddleware(server.middlewares)
31
32
  }
33
+ /*/
34
+ addSsrMiddleware(server.middlewares);
35
+ //*/
32
36
  addStatic404Middleware(server.middlewares);
33
37
  };
34
38
  }
@@ -16,7 +16,7 @@ import { getConfigVike } from '../shared/getConfigVike.js';
16
16
  import { getPageFilesServerSide } from '../../shared/getPageFiles.js';
17
17
  import { getPageContextRequestUrl } from '../../shared/getPageContextRequestUrl.js';
18
18
  import { getUrlFromRouteString } from '../../shared/route/resolveRouteString.js';
19
- import { getConfigValue, getConfigValueFilePathToShowToUser, getHookFilePathToShowToUser } from '../../shared/page-configs/utils.js';
19
+ import { getConfigValue, getConfigValueFilePathToShowToUser, getHookFilePathToShowToUser } from '../../shared/page-configs/helpers.js';
20
20
  import { loadConfigValues } from '../../shared/page-configs/loadConfigValues.js';
21
21
  import { isErrorPage } from '../../shared/error-page.js';
22
22
  import { addUrlComputedProps } from '../../shared/addUrlComputedProps.js';
@@ -285,7 +285,7 @@ async function callOnPrerenderStartHook(prerenderContext, renderContext) {
285
285
  const configValue = pageConfigGlobal.configValues.onPrerenderStart;
286
286
  if (configValue?.value) {
287
287
  const { value: hookFn } = configValue;
288
- // config.onPrerenderStart isn't a computed nor a cumulative config => definedAtInfo should always be defined
288
+ // config.onPrerenderStart isn't a computed nor a cumulative config => definedAt should always be defined
289
289
  const hookFilePath = getHookFilePathToShowToUser(configValue);
290
290
  assert(hookFilePath);
291
291
  onPrerenderStartHook = {
@@ -1,6 +1,6 @@
1
1
  export { serializePageContextClientSide };
2
2
  export { serializePageContextAbort };
3
- import { stringify } from '@brillout/json-serializer/stringify';
3
+ import { stringify, isJsonSerializerError } from '@brillout/json-serializer/stringify';
4
4
  import { assert, assertWarning, hasProp, unique } from '../utils.js';
5
5
  import { isErrorPage } from '../../../shared/error-page.js';
6
6
  import { addIs404ToPageProps } from '../../../shared/addIs404ToPageProps.js';
@@ -46,19 +46,32 @@ function serializePageContextClientSide(pageContext) {
46
46
  catch (err) {
47
47
  hasWarned = true;
48
48
  propsNonSerializable.push(prop);
49
- assert(hasProp(err, 'messageCore', 'string'));
50
- assertWarning(false, [
49
+ let msg = [
51
50
  `${varName} cannot be serialized and, therefore, cannot be passed to the client.`,
52
- `Make sure that ${varName} is serializable, or remove ${h(propName)} from ${h('passToClient')}.`,
53
- `Serialization error: ${err.messageCore}.`
54
- ].join(' '), { onlyOnce: false });
51
+ `Make sure that ${varName} is serializable, or remove ${h(propName)} from ${h('passToClient')}.`
52
+ ].join(' ');
53
+ if (isJsonSerializerError(err)) {
54
+ msg = `${msg} Serialization error: ${err.messageCore}.`;
55
+ }
56
+ else {
57
+ console.warn('Serialization error:');
58
+ console.warn(err);
59
+ msg = `${msg} The serialization failed because of the error printed above.`;
60
+ }
61
+ // We warn (instead of throwing an error) since Vike's client runtime throws an error (with `assertUsage()`) if the user's client code tries to access the property that cannot be serialized
62
+ assertWarning(false, msg, { onlyOnce: false });
55
63
  }
56
64
  });
57
65
  assert(hasWarned);
58
66
  propsNonSerializable.forEach((prop) => {
59
67
  pageContextClient[prop] = notSerializable;
60
68
  });
61
- pageContextSerialized = serialize(pageContextClient);
69
+ try {
70
+ pageContextSerialized = serialize(pageContextClient);
71
+ }
72
+ catch (err) {
73
+ assert(false);
74
+ }
62
75
  }
63
76
  return pageContextSerialized;
64
77
  }
@@ -1,5 +1,5 @@
1
1
  export { log404 };
2
- export { getPagesAndRoutesInfo };
2
+ export { getRoutesInfo };
3
3
  import type { PageRoutes } from '../../../../shared/route/index.js';
4
4
  declare function log404(pageContext: {
5
5
  urlPathname: string;
@@ -7,4 +7,4 @@ declare function log404(pageContext: {
7
7
  isClientSideNavigation: boolean;
8
8
  _pageRoutes: PageRoutes;
9
9
  }): Promise<void>;
10
- declare function getPagesAndRoutesInfo(pageRoutes: PageRoutes): string;
10
+ declare function getRoutesInfo(pageRoutes: PageRoutes): string | null;
@@ -1,5 +1,6 @@
1
1
  export { log404 };
2
- export { getPagesAndRoutesInfo };
2
+ // Exported for ./index.spec.ts
3
+ export { getRoutesInfo };
3
4
  import { getGlobalContext } from '../../globalContext.js';
4
5
  import { assert, assertUsage, assertInfo, compareString, stripAnsi, getTerminalWidth, truncateString } from '../../utils.js';
5
6
  import pc from '@brillout/picocolors';
@@ -13,14 +14,19 @@ async function log404(pageContext) {
13
14
  );
14
15
  const globalContext = getGlobalContext();
15
16
  if (!globalContext.isProduction && !isFileRequest(urlPathname) && !pageContext.isClientSideNavigation) {
16
- assertInfo(false, [
17
- `URL ${pc.cyan(urlPathname)} doesn't match the route of any of your pages:`,
18
- getPagesAndRoutesInfo(pageRoutes),
19
- 'See https://vike.dev/routing for more information about routing.'
20
- ].join('\n'), { onlyOnce: false });
17
+ const routesInfo = getRoutesInfo(pageRoutes);
18
+ let msg = `URL ${pc.cyan(urlPathname)} doesn't match the route of any of your pages`;
19
+ const outro = 'See https://vike.dev/routing for more information about routing.';
20
+ if (!routesInfo) {
21
+ msg = `${msg}. ${pc.dim(outro)}`;
22
+ }
23
+ else {
24
+ msg = `${msg}:\n${routesInfo}\n${outro}`;
25
+ }
26
+ assertInfo(false, msg, { onlyOnce: false });
21
27
  }
22
28
  }
23
- function getPagesAndRoutesInfo(pageRoutes) {
29
+ function getRoutesInfo(pageRoutes) {
24
30
  const entries = pageRoutes
25
31
  .map((pageRoute) => {
26
32
  let routeStr;
@@ -69,19 +75,24 @@ function getPagesAndRoutesInfo(pageRoutes) {
69
75
  const terminalWidth = getTerminalWidth() || 134;
70
76
  let width2 = Math.max(...linesContent.map(({ routeTypeSrc }) => stripAnsi(routeTypeSrc).length));
71
77
  let width3 = Math.max(...linesContent.map(({ routeDefinedBy }) => stripAnsi(routeDefinedBy).length));
72
- let width1 = terminalWidth - width3 - width2 - 10;
78
+ const width1_max = terminalWidth -
79
+ width3 -
80
+ width2 -
81
+ // Total width of table border & padding
82
+ 10;
83
+ if (width1_max < 10)
84
+ return null;
73
85
  linesContent.forEach((lineContent) => {
74
86
  let { routeStr } = lineContent;
75
- if (lineContent.routeTypeSrc !== 'Route Function') {
76
- routeStr = truncateString(routeStr, width1, (s) => pc.dim(s));
77
- }
78
- else {
79
- routeStr = truncateRouteFunction(routeStr, width1);
87
+ if (lineContent.routeTypeSrc === 'Route Function') {
88
+ routeStr = truncateRouteFunction(routeStr, width1_max);
89
+ assert(stripAnsi(routeStr).length <= width1_max);
80
90
  }
81
- assert(stripAnsi(routeStr).length <= width1);
82
91
  lineContent.routeStr = routeStr;
83
92
  });
84
- width1 = Math.max(...linesContent.map(({ routeStr }) => stripAnsi(routeStr).length));
93
+ let width1 = Math.max(...linesContent.map(({ routeStr }) => stripAnsi(routeStr).length));
94
+ if (width1 > width1_max)
95
+ return null;
85
96
  let lines = linesContent.map(({ routeStr, routeTypeSrc, routeDefinedBy }, i) => {
86
97
  let cell1 = padEnd(routeStr, width1 + (stripAnsi(routeStr).length - stripAnsi(routeStr).length));
87
98
  let cell2 = padEnd(routeTypeSrc, width2);
@@ -116,7 +127,7 @@ function truncateRouteFunction(routeStr, lenMax) {
116
127
  routeStr = stripAnsi(routeStr);
117
128
  routeStr = removeNonAscii(routeStr);
118
129
  routeStr = routeStr.split(/\s/).filter(Boolean).join(' ');
119
- routeStr = truncateString(routeStr, lenMax, (s) => pc.dim(s));
130
+ routeStr = truncateString(routeStr, lenMax);
120
131
  return routeStr;
121
132
  }
122
133
  /** Same as String.prototype.padEnd but with stripAnsi() */
@@ -20,7 +20,7 @@ import { preparePageContextForUserConsumptionServerSide } from './preparePageCon
20
20
  import { executeGuardHook } from '../../../shared/route/executeGuardHook.js';
21
21
  import { loadPageRoutes } from '../../../shared/route/loadPageRoutes.js';
22
22
  import pc from '@brillout/picocolors';
23
- import { getConfigValueFilePathToShowToUser } from '../../../shared/page-configs/utils.js';
23
+ import { getConfigValueFilePathToShowToUser } from '../../../shared/page-configs/helpers.js';
24
24
  async function renderPageAlreadyRouted(pageContext) {
25
25
  // pageContext._pageId can either be the:
26
26
  // - ID of the page matching the routing, or the
@@ -1,5 +1,5 @@
1
1
  export { getClientEntryFilePath };
2
- import { getConfigValue } from '../../shared/page-configs/utils.js';
2
+ import { getConfigValue } from '../../shared/page-configs/helpers.js';
3
3
  function getClientEntryFilePath(pageConfig) {
4
4
  const configName = 'client';
5
5
  const configValue = getConfigValue(pageConfig, configName, 'string');
@@ -1,5 +1,5 @@
1
1
  export { analyzeClientSide };
2
- import { getConfigValue } from '../page-configs/utils.js';
2
+ import { getConfigValue } from '../page-configs/helpers.js';
3
3
  import { analyzePageClientSide } from './analyzePageClientSide.js';
4
4
  function analyzeClientSide(pageConfig, pageFilesAll, pageId) {
5
5
  // V1 design
@@ -9,9 +9,7 @@ function analyzeClientSide(pageConfig, pageFilesAll, pageId) {
9
9
  return { isClientSideRenderable, isClientRouting };
10
10
  }
11
11
  else {
12
- // TODO/v1-release:
13
- // - remove V0.4 implementation
14
- // - globally rename isHtmlOnly to !isClientSideRenderable
12
+ // TODO/v1-release: remove
15
13
  // V0.4 design
16
14
  const { isHtmlOnly, isClientRouting } = analyzePageClientSide(pageFilesAll, pageId);
17
15
  return { isClientSideRenderable: !isHtmlOnly, isClientRouting };
@@ -3,7 +3,7 @@ export { getExports };
3
3
  import { isScriptFile, isTemplateFile } from '../../utils/isScriptFile.js';
4
4
  import { assert, hasProp, isObject, assertWarning, assertUsage, makeLast, isBrowser } from '../utils.js';
5
5
  import { assertDefaultExports, forbiddenDefaultExports } from './assert_exports_old_design.js';
6
- import { getConfigDefinedAtString, getConfigValueFilePathToShowToUser } from '../page-configs/utils.js';
6
+ import { getConfigDefinedAtString, getConfigValueFilePathToShowToUser } from '../page-configs/helpers.js';
7
7
  import pc from '@brillout/picocolors';
8
8
  function getExports(pageFiles, pageConfig) {
9
9
  const configEntries = {};
@@ -31,7 +31,7 @@ function getExports(pageFiles, pageConfig) {
31
31
  Object.entries(pageConfig.configValues).forEach(([configName, configValue]) => {
32
32
  const { value } = configValue;
33
33
  const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser(configValue);
34
- const configDefinedAt = getConfigDefinedAtString(configName, configValue, true);
34
+ const configDefinedAt = getConfigDefinedAtString('Config', configName, configValue);
35
35
  config[configName] = config[configName] ?? value;
36
36
  configEntries[configName] = configEntries[configName] ?? [];
37
37
  // Currently each configName has only one entry. Adding an entry for each overriden config value isn't implemented yet. (This is an isomorphic file and it isn't clear whether this can/should be implemented on the client-side. We should load a minimum amount of code on the client-side.)
@@ -23,6 +23,6 @@ function assertHook(pageContext, hookName) {
23
23
  function assertHookFn(hookFn, { hookName, hookFilePath }) {
24
24
  assert(hookName && hookFilePath);
25
25
  assert(!hookName.endsWith(')'));
26
- assertUsage(isCallable(hookFn), `hook ${hookName}() defined by ${hookFilePath} should be a function`);
26
+ assertUsage(isCallable(hookFn), `Hook ${hookName}() defined by ${hookFilePath} should be a function`);
27
27
  checkType(hookFn);
28
28
  }
@@ -13,7 +13,9 @@ export type { ConfigValueComputed };
13
13
  export type { ConfigValuesComputed };
14
14
  export type { DefinedAt };
15
15
  export type { DefinedAtFile };
16
- export type { DefinedAtFileInfo };
16
+ export type { DefinedAtFileFullInfo };
17
+ export type { FilePathResolved };
18
+ export type { FilePath };
17
19
  import type { ConfigValueImported } from './serialize/PageConfigSerialized.js';
18
20
  type PageConfigBase = {
19
21
  pageId: string;
@@ -23,9 +25,9 @@ type PageConfigBase = {
23
25
  definedBy: string;
24
26
  };
25
27
  };
26
- /** Page config data structure available and used at runtime */
28
+ /** Page config data structure available at runtime */
27
29
  type PageConfigRuntime = PageConfigBase & {
28
- /** Loaded config values */
30
+ /** All loaded config values */
29
31
  configValues: ConfigValues;
30
32
  /** Load config values that are lazily loaded such as config.Page */
31
33
  loadConfigValuesAll: () => Promise<ConfigValueImported[]>;
@@ -33,9 +35,9 @@ type PageConfigRuntime = PageConfigBase & {
33
35
  /** Same as PageConfigRuntime but also contains all lazily loaded config values such as config.Page */
34
36
  type PageConfigRuntimeLoaded = PageConfigRuntime & {
35
37
  /** Whether loadConfigValuesAll() was called */
36
- isLoaded: true;
38
+ isAllLoaded: true;
37
39
  };
38
- /** Page config data structure available and used at build-time */
40
+ /** Page config data structure available at build-time */
39
41
  type PageConfigBuildTime = PageConfigBase & {
40
42
  configValues: ConfigValues;
41
43
  configValueSources: ConfigValueSources;
@@ -54,52 +56,72 @@ type ConfigEnvInternal = ConfigEnv | '_routing-eager' | '_routing-lazy';
54
56
  type ConfigValueSource = {
55
57
  value?: unknown;
56
58
  configEnv: ConfigEnvInternal;
57
- definedAtInfo: DefinedAtFileInfo;
58
- /** Wether the config value is loaded at run-time, for example config.Page or config.onBeforeRender */
59
+ definedAt: DefinedAtFileFullInfo;
60
+ /** Wether the config value is loaded at runtime, for example config.Page or config.onBeforeRender */
59
61
  valueIsImportedAtRuntime: boolean;
60
62
  /** Whether the config value is a file path, for example config.client */
61
63
  valueIsFilePath?: true;
62
64
  };
65
+ type DefinedAtFileFullInfo = DefinedAtFile & FilePath & {
66
+ fileExportName?: string;
67
+ };
68
+ type ConfigValueSources = Record<string, ConfigValueSource[]>;
63
69
  type ConfigValueComputed = {
64
70
  configEnv: ConfigEnvInternal;
65
71
  value: unknown;
66
72
  };
67
73
  type ConfigValuesComputed = Record<string, ConfigValueComputed>;
68
- type ConfigValueSources = Record<string, ConfigValueSource[]>;
69
74
  type ConfigValue = {
70
75
  value: unknown;
71
76
  definedAt: DefinedAt;
72
77
  };
73
- type ConfigValues = Record<string, ConfigValue>;
74
- type DefinedAt = {
75
- file: DefinedAtFile;
76
- isEffect?: true;
77
- isComputed?: undefined;
78
- isCumulative?: undefined;
79
- } | {
80
- isCumulative: true;
78
+ type DefinedAt = DefinedAtFile | {
81
79
  files: DefinedAtFile[];
82
- isEffect?: undefined;
83
- isComputed?: undefined;
84
80
  } | {
85
81
  isComputed: true;
86
- isEffect?: undefined;
87
- isCumulative?: undefined;
88
82
  };
89
83
  type DefinedAtFile = {
90
84
  filePathToShowToUser: string;
91
- fileExportPath: null | string[];
85
+ fileExportPathToShowToUser: null | string[];
92
86
  };
93
- type DefinedAtFileInfo = // TODO: replace filePathRelativeToUserRootDir and importPathAbsolute with following?
94
- ({
95
- filePathRelativeToUserRootDir: string;
87
+ type ConfigValues = Record<string, ConfigValue>;
88
+ type FilePathResolved = FilePath & {
96
89
  filePathAbsoluteFilesystem: string;
97
- importPathAbsolute: null;
98
- } | {
99
- filePathRelativeToUserRootDir: null;
90
+ };
91
+ type FilePath = {
92
+ /** The file's path, absolute from Vite's perspective.
93
+ *
94
+ * We use this to generate import paths in virtual modules. (Virtual modules cannot have relative import paths.)
95
+ *
96
+ * Its value is equivalent to `filePath.filePathRelativeToUserRootDir ?? filePath.importPathAbsolute`, for example:
97
+ * - `vike-react/config`, or
98
+ * - `/pages/+config.h.js`.
99
+ */
100
+ filePathAbsoluteVite: string;
101
+ /** The file's path, absolute from the filesystem root.
102
+ *
103
+ * Example: `/home/rom/code/my-app/pages/some-page/Page.js`
104
+ *
105
+ * The value is `null` upon aliased import paths which we cannot resolve (we'd need to re-implement https://www.npmjs.com/package/@rollup/plugin-alias).
106
+ */
100
107
  filePathAbsoluteFilesystem: string | null;
108
+ /** The file's path, shown to user upon logging.
109
+ *
110
+ * Currently, its value is equivalent to `FilePath['filePathAbsoluteVite']`.
111
+ */
112
+ filePathToShowToUser: string;
113
+ } & ({
114
+ filePathRelativeToUserRootDir: null;
115
+ /** The file's path, as absolute import path. It's either:
116
+ * - an npm package import (e.g. `vike-react/config`), or
117
+ * - an alias (`#components/Counter').
118
+ */
101
119
  importPathAbsolute: string;
102
- }) & {
103
- exportName?: string;
104
- fileExportPath: null | string[];
105
- };
120
+ } | {
121
+ /** The file's path, relative to Vite's root (i.e. the user project's root directory).
122
+ *
123
+ * Example: `/pages/some-page/Page.js`
124
+ */
125
+ filePathRelativeToUserRootDir: string;
126
+ importPathAbsolute: null | string;
127
+ });
@@ -1,2 +1,2 @@
1
1
  export { getExportPath };
2
- declare function getExportPath(fileExportPath: null | string[], configName: string): null | string;
2
+ declare function getExportPath(fileExportPathToShowToUser: null | string[], configName: string): null | string;
@@ -1,9 +1,9 @@
1
1
  export { getExportPath };
2
2
  import { assert } from '../utils.js';
3
- function getExportPath(fileExportPath, configName) {
4
- if (!fileExportPath)
3
+ function getExportPath(fileExportPathToShowToUser, configName) {
4
+ if (!fileExportPathToShowToUser)
5
5
  return null;
6
- let [exportName, ...exportObjectPath] = fileExportPath;
6
+ let [exportName, ...exportObjectPath] = fileExportPathToShowToUser;
7
7
  if (!exportName)
8
8
  return null;
9
9
  if (exportObjectPath.length === 0 && ['*', 'default', configName].includes(exportName))
@@ -0,0 +1,7 @@
1
+ export { getConfigDefinedAtString };
2
+ export { getDefinedAtString };
3
+ import type { DefinedAt } from '../PageConfig.js';
4
+ declare function getConfigDefinedAtString<ConfigName extends string, SentenceBegin extends 'Config' | 'config' | 'Hook'>(sentenceBegin: SentenceBegin, configName: ConfigName, { definedAt }: {
5
+ definedAt: DefinedAt;
6
+ }): `${SentenceBegin} ${ConfigName}${string} defined ${'internally' | `at ${string}`}`;
7
+ declare function getDefinedAtString(definedAt: DefinedAt, configName: string): string;
@@ -0,0 +1,37 @@
1
+ export { getConfigDefinedAtString };
2
+ export { getDefinedAtString };
3
+ import { assert } from '../../utils.js';
4
+ import pc from '@brillout/picocolors';
5
+ import { getExportPath } from '../getExportPath.js';
6
+ function getConfigDefinedAtString(sentenceBegin, configName, { definedAt }) {
7
+ const definedAtString = getDefinedAtString(definedAt, configName);
8
+ const definedAtStr = definedAtString === 'internally' ? definedAtString : `at ${definedAtString}`;
9
+ let configNameStr = `${configName}${sentenceBegin === 'Hook' ? '()' : ''}`;
10
+ const configDefinedAt = `${sentenceBegin} ${pc.cyan(configNameStr)} defined ${definedAtStr}`;
11
+ return configDefinedAt;
12
+ }
13
+ function getDefinedAtString(definedAt, configName) {
14
+ if ('isComputed' in definedAt) {
15
+ return 'internally';
16
+ }
17
+ let files;
18
+ if ('files' in definedAt) {
19
+ files = definedAt.files;
20
+ }
21
+ else {
22
+ files = [definedAt];
23
+ }
24
+ assert(files.length >= 1);
25
+ const definedAtString = files
26
+ .map((source) => {
27
+ const { filePathToShowToUser, fileExportPathToShowToUser } = source;
28
+ let s = filePathToShowToUser;
29
+ const exportPath = getExportPath(fileExportPathToShowToUser, configName);
30
+ if (exportPath) {
31
+ s = `${s} > ${pc.cyan(exportPath)}`;
32
+ }
33
+ return s;
34
+ })
35
+ .join(' / ');
36
+ return definedAtString;
37
+ }
@@ -0,0 +1,14 @@
1
+ export { getConfigValue };
2
+ import type { PageConfigRuntime, PageConfigBuildTime, ConfigValue } from '../PageConfig.js';
3
+ import type { ConfigNameBuiltIn } from '../Config.js';
4
+ type PageConfigCommon = PageConfigRuntime | PageConfigBuildTime;
5
+ type ConfigName = ConfigNameBuiltIn;
6
+ declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'string'): null | ConfigValue & {
7
+ value: string;
8
+ };
9
+ declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'boolean'): null | ConfigValue & {
10
+ value: boolean;
11
+ };
12
+ declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName): null | ConfigValue & {
13
+ value: unknown;
14
+ };
@@ -0,0 +1,38 @@
1
+ export { getConfigValue };
2
+ import { assert, assertUsage, getValuePrintable } from '../../utils.js';
3
+ import pc from '@brillout/picocolors';
4
+ import { getConfigDefinedAtString } from './getConfigDefinedAtString.js';
5
+ // prettier-ignore
6
+ function getConfigValue(pageConfig, configName, type) {
7
+ const configValue = getConfigValueEntry(pageConfig, configName);
8
+ if (configValue === null)
9
+ return null;
10
+ const { value, definedAt } = configValue;
11
+ if (type)
12
+ assertConfigValueType(value, type, configName, definedAt);
13
+ return configValue;
14
+ }
15
+ function assertConfigValueType(value, type, configName, definedAt) {
16
+ assert(value !== null);
17
+ const typeActual = typeof value;
18
+ if (typeActual === type)
19
+ return;
20
+ const valuePrintable = getValuePrintable(value);
21
+ const problem = valuePrintable !== null
22
+ ? `value ${pc.cyan(valuePrintable)}`
23
+ : `type ${pc.cyan(typeActual)}`;
24
+ const configDefinedAt = getConfigDefinedAtString('Config', configName, {
25
+ definedAt
26
+ });
27
+ const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${pc.cyan(type)} instead`;
28
+ assertUsage(false, errMsg);
29
+ }
30
+ function getConfigValueEntry(pageConfig, configName) {
31
+ const configValue = pageConfig.configValues[configName];
32
+ if (!configValue)
33
+ return null;
34
+ // Enable users to suppress global config values by setting the local config value to null
35
+ if (configValue.value === null)
36
+ return null;
37
+ return configValue;
38
+ }
@@ -0,0 +1,13 @@
1
+ export { getPageConfig };
2
+ export { getConfigValueFilePathToShowToUser };
3
+ export { getHookFilePathToShowToUser };
4
+ export { getConfigDefinedAtString, getDefinedAtString } from './helpers/getConfigDefinedAtString.js';
5
+ export { getConfigValue } from './helpers/getConfigValue.js';
6
+ import type { PageConfigRuntime, DefinedAt } from './PageConfig.js';
7
+ declare function getPageConfig(pageId: string, pageConfigs: PageConfigRuntime[]): PageConfigRuntime;
8
+ declare function getConfigValueFilePathToShowToUser({ definedAt }: {
9
+ definedAt: DefinedAt;
10
+ }): null | string;
11
+ declare function getHookFilePathToShowToUser({ definedAt }: {
12
+ definedAt: DefinedAt;
13
+ }): string;