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
@@ -0,0 +1,27 @@
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 { assert } from '../utils.js';
7
+ function getPageConfig(pageId, pageConfigs) {
8
+ const pageConfig = pageConfigs.find((p) => p.pageId === pageId);
9
+ assert(pageConfigs.length > 0);
10
+ assert(pageConfig);
11
+ return pageConfig;
12
+ }
13
+ function getConfigValueFilePathToShowToUser({ definedAt }) {
14
+ // A unique file path only exists if the config value isn't cumulative nor computed:
15
+ // - cumulative config values have multiple file paths
16
+ // - computed values don't have any file path
17
+ if ('isComputed' in definedAt || 'files' in definedAt)
18
+ return null;
19
+ const { filePathToShowToUser } = definedAt;
20
+ assert(filePathToShowToUser);
21
+ return filePathToShowToUser;
22
+ }
23
+ function getHookFilePathToShowToUser({ definedAt }) {
24
+ const filePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
25
+ assert(filePathToShowToUser);
26
+ return filePathToShowToUser;
27
+ }
@@ -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;
@@ -8,14 +8,12 @@ function parseConfigValuesImported(configValuesImported) {
8
8
  configValues[configName] = {
9
9
  value,
10
10
  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
- }
11
+ // importPath cannot be relative to the current file, since the current file is a virtual file
12
+ filePathToShowToUser: importPath,
13
+ fileExportPathToShowToUser: [configName, 'default'].includes(exportName)
14
+ ? []
15
+ : // Side-effect config
16
+ [exportName]
19
17
  }
20
18
  };
21
19
  assertIsNotNull(value, configName, importPath);
@@ -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);
@@ -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
@@ -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-commit-756f5d7";
8
+ projectVersion: "0.4.144-commit-f7ab002";
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-commit-756f5d7';
3
+ const PROJECT_VERSION = '0.4.144-commit-f7ab002';
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.144-commit-756f5d7",
3
+ "version": "0.4.144-commit-f7ab002",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",
@@ -13,7 +13,7 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "@brillout/import": "0.2.3",
16
- "@brillout/json-serializer": "^0.5.6",
16
+ "@brillout/json-serializer": "^0.5.8",
17
17
  "@brillout/picocolors": "^1.0.9",
18
18
  "@brillout/require-shim": "^0.1.2",
19
19
  "@brillout/vite-plugin-import-build": "^0.2.20",
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFilePathToShowToUser = void 0;
4
- const utils_js_1 = require("../../../utils.js");
5
- /*
6
- const f: FilePath = 1 as any
7
- if (f.filePathRelativeToUserRootDir === null) {
8
- f.importPathAbsolute
9
- }
10
- //*/
11
- function getFilePathToShowToUser(filePath) {
12
- const filePathToShowToUser = filePath.filePathRelativeToUserRootDir ?? filePath.filePathAbsoluteFilesystem;
13
- (0, utils_js_1.assert)(filePathToShowToUser);
14
- return filePathToShowToUser;
15
- }
16
- exports.getFilePathToShowToUser = getFilePathToShowToUser;
@@ -1,103 +0,0 @@
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.getHookFilePathToShowToUser = exports.getConfigValueFilePathToShowToUser = exports.getDefinedAtString = exports.getConfigDefinedAtString = exports.getPageConfig = exports.getConfigValue = void 0;
7
- const utils_js_1 = require("../utils.js");
8
- const picocolors_1 = __importDefault(require("@brillout/picocolors"));
9
- const getExportPath_js_1 = require("./getExportPath.js");
10
- // prettier-ignore
11
- function getConfigValue(pageConfig, configName, type) {
12
- const configValue = getConfigValueEntry(pageConfig, configName);
13
- if (configValue === null)
14
- return null;
15
- const { value, definedAt } = configValue;
16
- if (type)
17
- assertConfigValueType(value, type, configName, definedAt);
18
- return configValue;
19
- }
20
- exports.getConfigValue = getConfigValue;
21
- function assertConfigValueType(value, type, configName, definedAt) {
22
- (0, utils_js_1.assert)(value !== null);
23
- const typeActual = typeof value;
24
- if (typeActual === type)
25
- return;
26
- const valuePrintable = (0, utils_js_1.getValuePrintable)(value);
27
- const problem = valuePrintable !== null ? `value ${picocolors_1.default.cyan(valuePrintable)}` : `type ${picocolors_1.default.cyan(typeActual)}`;
28
- const configDefinedAt = getConfigDefinedAtString(configName, { definedAt }, true);
29
- (0, utils_js_1.assertUsage)(false, `${configDefinedAt} has an invalid ${problem}: it should be a ${picocolors_1.default.cyan(type)} instead`);
30
- }
31
- function getConfigValueEntry(pageConfig, configName) {
32
- const configValue = pageConfig.configValues[configName];
33
- if (!configValue)
34
- return null;
35
- // Enable users to suppress global config values by setting the local config value to null
36
- if (configValue.value === null)
37
- return null;
38
- return configValue;
39
- }
40
- function getPageConfig(pageId, pageConfigs) {
41
- const pageConfig = pageConfigs.find((p) => p.pageId === pageId);
42
- (0, utils_js_1.assert)(pageConfigs.length > 0);
43
- (0, utils_js_1.assert)(pageConfig);
44
- return pageConfig;
45
- }
46
- exports.getPageConfig = getPageConfig;
47
- function getConfigDefinedAtString(configName, { definedAt }, sentenceBegin) {
48
- const configDefinedAt = `${sentenceBegin ? `Config` : `config`} ${picocolors_1.default.cyan(configName)} defined ${getSourceString(definedAt, configName)}`;
49
- return configDefinedAt;
50
- }
51
- exports.getConfigDefinedAtString = getConfigDefinedAtString;
52
- function getSourceString(definedAt, configName) {
53
- if (definedAt.isComputed) {
54
- return 'internally';
55
- }
56
- let files;
57
- if (definedAt.isCumulative) {
58
- files = definedAt.files;
59
- }
60
- else {
61
- files = [definedAt.file];
62
- }
63
- (0, utils_js_1.assert)(files.length >= 1);
64
- const sourceString = files
65
- .map((source) => {
66
- const { filePathToShowToUser, fileExportPath } = source;
67
- let s = filePathToShowToUser;
68
- const exportPath = (0, getExportPath_js_1.getExportPath)(fileExportPath, configName);
69
- if (exportPath) {
70
- s = `${s} > ${picocolors_1.default.cyan(exportPath)}`;
71
- }
72
- if (definedAt.isEffect) {
73
- s = `${s} > (${picocolors_1.default.blue('effect')})`;
74
- }
75
- return s;
76
- })
77
- .join(' / ');
78
- return `at ${sourceString}`;
79
- }
80
- function getDefinedAtString(configValue, configName) {
81
- let sourceString = getSourceString(configValue.definedAt, configName);
82
- if (sourceString.startsWith('at '))
83
- sourceString = sourceString.slice('at '.length);
84
- return sourceString;
85
- }
86
- exports.getDefinedAtString = getDefinedAtString;
87
- function getConfigValueFilePathToShowToUser({ definedAt }) {
88
- // A unique file path only exists if the config value isn't cumulative nor computed:
89
- // - cumulative config values have multiple file paths
90
- // - computed values don't have any file path
91
- if (definedAt.isComputed || definedAt.isCumulative)
92
- return null;
93
- const { filePathToShowToUser } = definedAt.file;
94
- (0, utils_js_1.assert)(filePathToShowToUser);
95
- return filePathToShowToUser;
96
- }
97
- exports.getConfigValueFilePathToShowToUser = getConfigValueFilePathToShowToUser;
98
- function getHookFilePathToShowToUser({ definedAt }) {
99
- const filePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
100
- (0, utils_js_1.assert)(filePathToShowToUser);
101
- return filePathToShowToUser;
102
- }
103
- exports.getHookFilePathToShowToUser = getHookFilePathToShowToUser;
@@ -1,24 +0,0 @@
1
- export { getFilePathToShowToUser };
2
- export type { FilePath };
3
- type FilePath = {
4
- /** The file's path relative to the filesystem root.
5
- *
6
- * Example: `/home/rom/code/my-app/pages/some-page/Page.js`
7
- */
8
- filePathAbsoluteFilesystem: string;
9
- } & ({
10
- /** The file's path relative to the Vite's root (i.e. the user's project root directory).
11
- *
12
- * Example: `/pages/some-page/Page.js`
13
- */
14
- filePathRelativeToUserRootDir: string;
15
- importPathAbsolute: null;
16
- } | {
17
- filePathRelativeToUserRootDir: null;
18
- /** The file's absolute import path.
19
- *
20
- * Example: `vike-react/config`
21
- */
22
- importPathAbsolute: string;
23
- });
24
- declare function getFilePathToShowToUser(filePath: FilePath): string;
@@ -1,13 +0,0 @@
1
- export { getFilePathToShowToUser };
2
- import { assert } from '../../../utils.js';
3
- /*
4
- const f: FilePath = 1 as any
5
- if (f.filePathRelativeToUserRootDir === null) {
6
- f.importPathAbsolute
7
- }
8
- //*/
9
- function getFilePathToShowToUser(filePath) {
10
- const filePathToShowToUser = filePath.filePathRelativeToUserRootDir ?? filePath.filePathAbsoluteFilesystem;
11
- assert(filePathToShowToUser);
12
- return filePathToShowToUser;
13
- }
@@ -1,35 +0,0 @@
1
- export { getConfigValue };
2
- export { getPageConfig };
3
- export { getConfigDefinedAtString };
4
- export { getDefinedAtString };
5
- export { getConfigValueFilePathToShowToUser };
6
- export { getHookFilePathToShowToUser };
7
- import type { PageConfigRuntime, PageConfigBuildTime, ConfigValue, DefinedAt } from './PageConfig.js';
8
- import type { ConfigNameBuiltIn } from './Config.js';
9
- type PageConfigCommon = PageConfigRuntime | PageConfigBuildTime;
10
- type ConfigName = ConfigNameBuiltIn;
11
- declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'string'): null | ConfigValue & {
12
- value: string;
13
- };
14
- declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName, type: 'boolean'): null | ConfigValue & {
15
- value: boolean;
16
- };
17
- declare function getConfigValue(pageConfig: PageConfigCommon, configName: ConfigName): null | ConfigValue & {
18
- value: unknown;
19
- };
20
- declare function getPageConfig(pageId: string, pageConfigs: PageConfigRuntime[]): PageConfigRuntime;
21
- type ConfigDefinedAtUppercase<ConfigName extends string> = `Config ${ConfigName} defined ${'internally' | `at ${string}`}`;
22
- type ConfigDefinedAtLowercase<ConfigName extends string> = `config ${ConfigName} defined ${'internally' | `at ${string}`}`;
23
- declare function getConfigDefinedAtString<ConfigName extends string>(configName: ConfigName, { definedAt }: {
24
- definedAt: DefinedAt;
25
- }, sentenceBegin: true, append?: 'effect'): ConfigDefinedAtUppercase<ConfigName>;
26
- declare function getConfigDefinedAtString<ConfigName extends string>(configName: ConfigName, { definedAt }: {
27
- definedAt: DefinedAt;
28
- }, sentenceBegin: false, append?: 'effect'): ConfigDefinedAtLowercase<ConfigName>;
29
- declare function getDefinedAtString(configValue: ConfigValue, configName: string): string;
30
- declare function getConfigValueFilePathToShowToUser({ definedAt }: {
31
- definedAt: DefinedAt;
32
- }): null | string;
33
- declare function getHookFilePathToShowToUser({ definedAt }: {
34
- definedAt: DefinedAt;
35
- }): string;
@@ -1,97 +0,0 @@
1
- export { getConfigValue };
2
- export { getPageConfig };
3
- export { getConfigDefinedAtString };
4
- export { getDefinedAtString };
5
- export { getConfigValueFilePathToShowToUser };
6
- export { getHookFilePathToShowToUser };
7
- import { assert, assertUsage, getValuePrintable } from '../utils.js';
8
- import pc from '@brillout/picocolors';
9
- import { getExportPath } from './getExportPath.js';
10
- // prettier-ignore
11
- function getConfigValue(pageConfig, configName, type) {
12
- const configValue = getConfigValueEntry(pageConfig, configName);
13
- if (configValue === null)
14
- return null;
15
- const { value, definedAt } = configValue;
16
- if (type)
17
- assertConfigValueType(value, type, configName, definedAt);
18
- return configValue;
19
- }
20
- function assertConfigValueType(value, type, configName, definedAt) {
21
- assert(value !== null);
22
- const typeActual = typeof value;
23
- if (typeActual === type)
24
- return;
25
- const valuePrintable = getValuePrintable(value);
26
- const problem = valuePrintable !== null ? `value ${pc.cyan(valuePrintable)}` : `type ${pc.cyan(typeActual)}`;
27
- const configDefinedAt = getConfigDefinedAtString(configName, { definedAt }, true);
28
- assertUsage(false, `${configDefinedAt} has an invalid ${problem}: it should be a ${pc.cyan(type)} instead`);
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
- }
39
- function getPageConfig(pageId, pageConfigs) {
40
- const pageConfig = pageConfigs.find((p) => p.pageId === pageId);
41
- assert(pageConfigs.length > 0);
42
- assert(pageConfig);
43
- return pageConfig;
44
- }
45
- function getConfigDefinedAtString(configName, { definedAt }, sentenceBegin) {
46
- const configDefinedAt = `${sentenceBegin ? `Config` : `config`} ${pc.cyan(configName)} defined ${getSourceString(definedAt, configName)}`;
47
- return configDefinedAt;
48
- }
49
- function getSourceString(definedAt, configName) {
50
- if (definedAt.isComputed) {
51
- return 'internally';
52
- }
53
- let files;
54
- if (definedAt.isCumulative) {
55
- files = definedAt.files;
56
- }
57
- else {
58
- files = [definedAt.file];
59
- }
60
- assert(files.length >= 1);
61
- const sourceString = files
62
- .map((source) => {
63
- const { filePathToShowToUser, fileExportPath } = source;
64
- let s = filePathToShowToUser;
65
- const exportPath = getExportPath(fileExportPath, configName);
66
- if (exportPath) {
67
- s = `${s} > ${pc.cyan(exportPath)}`;
68
- }
69
- if (definedAt.isEffect) {
70
- s = `${s} > (${pc.blue('effect')})`;
71
- }
72
- return s;
73
- })
74
- .join(' / ');
75
- return `at ${sourceString}`;
76
- }
77
- function getDefinedAtString(configValue, configName) {
78
- let sourceString = getSourceString(configValue.definedAt, configName);
79
- if (sourceString.startsWith('at '))
80
- sourceString = sourceString.slice('at '.length);
81
- return sourceString;
82
- }
83
- function getConfigValueFilePathToShowToUser({ definedAt }) {
84
- // A unique file path only exists if the config value isn't cumulative nor computed:
85
- // - cumulative config values have multiple file paths
86
- // - computed values don't have any file path
87
- if (definedAt.isComputed || definedAt.isCumulative)
88
- return null;
89
- const { filePathToShowToUser } = definedAt.file;
90
- assert(filePathToShowToUser);
91
- return filePathToShowToUser;
92
- }
93
- function getHookFilePathToShowToUser({ definedAt }) {
94
- const filePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
95
- assert(filePathToShowToUser);
96
- return filePathToShowToUser;
97
- }