vike 0.4.143-commit-f03b42d → 0.4.143-commit-fa295e1

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 (49) hide show
  1. package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +30 -27
  2. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
  3. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +119 -64
  4. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -10
  5. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +11 -11
  6. package/dist/cjs/node/prerender/runPrerender.js +9 -8
  7. package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  8. package/dist/cjs/node/runtime/renderPage/log404/index.js +10 -5
  9. package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
  10. package/dist/cjs/node/shared/getClientEntryFilePath.js +1 -7
  11. package/dist/cjs/shared/getPageFiles/getExports.js +2 -5
  12. package/dist/cjs/shared/getPageFiles/parsePageConfigsSerialized.js +9 -6
  13. package/dist/cjs/shared/hooks/getHook.js +3 -1
  14. package/dist/cjs/shared/page-configs/getExportPath.js +2 -2
  15. package/dist/cjs/shared/page-configs/parseConfigValuesImported.js +8 -5
  16. package/dist/cjs/shared/page-configs/utils.js +66 -42
  17. package/dist/cjs/shared/route/loadPageRoutes.js +5 -6
  18. package/dist/cjs/utils/projectInfo.js +1 -1
  19. package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +30 -27
  20. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +11 -2
  21. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
  22. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +3 -2
  23. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +119 -64
  24. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +11 -10
  25. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +2 -2
  26. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +11 -11
  27. package/dist/esm/node/prerender/runPrerender.js +10 -9
  28. package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
  29. package/dist/esm/node/runtime/renderPage/log404/index.js +10 -5
  30. package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -2
  31. package/dist/esm/node/shared/getClientEntryFilePath.js +2 -8
  32. package/dist/esm/shared/addUrlComputedProps.d.ts +4 -2
  33. package/dist/esm/shared/getPageFiles/getExports.d.ts +1 -2
  34. package/dist/esm/shared/getPageFiles/getExports.js +3 -6
  35. package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.js +9 -6
  36. package/dist/esm/shared/hooks/getHook.js +3 -1
  37. package/dist/esm/shared/page-configs/Config.d.ts +1 -3
  38. package/dist/esm/shared/page-configs/PageConfig.d.ts +35 -10
  39. package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
  40. package/dist/esm/shared/page-configs/getExportPath.js +2 -2
  41. package/dist/esm/shared/page-configs/parseConfigValuesImported.js +8 -5
  42. package/dist/esm/shared/page-configs/utils.d.ts +19 -13
  43. package/dist/esm/shared/page-configs/utils.js +65 -41
  44. package/dist/esm/shared/route/loadPageRoutes.js +6 -7
  45. package/dist/esm/shared/types.d.ts +1 -0
  46. package/dist/esm/types/index.d.ts +1 -0
  47. package/dist/esm/utils/projectInfo.d.ts +1 -1
  48. package/dist/esm/utils/projectInfo.js +1 -1
  49. package/package.json +1 -1
@@ -72,8 +72,8 @@ function getPagesAndRoutesInfo(pageRoutes) {
72
72
  ...entries
73
73
  ];
74
74
  const terminalWidth = (0, utils_js_1.getTerminalWidth)() || 134;
75
- let width2 = Math.max(...linesContent.map(({ routeTypeSrc }) => routeTypeSrc.length));
76
- let width3 = Math.max(...linesContent.map(({ routeDefinedBy }) => routeDefinedBy.length));
75
+ let width2 = Math.max(...linesContent.map(({ routeTypeSrc }) => (0, utils_js_1.stripAnsi)(routeTypeSrc).length));
76
+ let width3 = Math.max(...linesContent.map(({ routeDefinedBy }) => (0, utils_js_1.stripAnsi)(routeDefinedBy).length));
77
77
  let width1 = terminalWidth - width3 - width2 - 10;
78
78
  linesContent.forEach((lineContent) => {
79
79
  let { routeStr } = lineContent;
@@ -88,9 +88,9 @@ function getPagesAndRoutesInfo(pageRoutes) {
88
88
  });
89
89
  width1 = Math.max(...linesContent.map(({ routeStr }) => (0, utils_js_1.stripAnsi)(routeStr).length));
90
90
  let lines = linesContent.map(({ routeStr, routeTypeSrc, routeDefinedBy }, i) => {
91
- let cell1 = routeStr.padEnd(width1 + (routeStr.length - (0, utils_js_1.stripAnsi)(routeStr).length), ' ');
92
- let cell2 = routeTypeSrc.padEnd(width2, ' ');
93
- let cell3 = routeDefinedBy.padEnd(width3, ' ');
91
+ let cell1 = padEnd(routeStr, width1 + ((0, utils_js_1.stripAnsi)(routeStr).length - (0, utils_js_1.stripAnsi)(routeStr).length));
92
+ let cell2 = padEnd(routeTypeSrc, width2);
93
+ let cell3 = padEnd(routeDefinedBy, width3);
94
94
  const isHeader = i === 0;
95
95
  if (isHeader) {
96
96
  cell1 = picocolors_1.default.dim(cell1);
@@ -125,6 +125,11 @@ function truncateRouteFunction(routeStr, lenMax) {
125
125
  routeStr = (0, utils_js_1.truncateString)(routeStr, lenMax, (s) => picocolors_1.default.dim(s));
126
126
  return routeStr;
127
127
  }
128
+ /** Same as String.prototype.padEnd but with stripAnsi() */
129
+ function padEnd(str, width) {
130
+ const padWidth = Math.max(0, width - (0, utils_js_1.stripAnsi)(str).length);
131
+ return str + ''.padEnd(padWidth, ' ');
132
+ }
128
133
  function removeNonAscii(str) {
129
134
  // https://stackoverflow.com/questions/20856197/remove-non-ascii-character-in-string/20856346#20856346
130
135
  return str.replace(/[^\x00-\x7F]/g, '');
@@ -21,6 +21,7 @@ const preparePageContextForUserConsumptionServerSide_js_1 = require("./preparePa
21
21
  const executeGuardHook_js_1 = require("../../../shared/route/executeGuardHook.js");
22
22
  const loadPageRoutes_js_1 = require("../../../shared/route/loadPageRoutes.js");
23
23
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
24
+ const utils_js_2 = require("../../../shared/page-configs/utils.js");
24
25
  async function renderPageAlreadyRouted(pageContext) {
25
26
  // pageContext._pageId can either be the:
26
27
  // - ID of the page matching the routing, or the
@@ -172,9 +173,9 @@ function assertNonMixedDesign(pageFilesAll, pageConfigs) {
172
173
  const indent = '- ';
173
174
  const v1Files = (0, utils_js_1.unique)(pageConfigs
174
175
  .map((p) => Object.values(p.configValues)
175
- .map(({ definedAtInfo }) => definedAtInfo)
176
+ .map(utils_js_2.getConfigValueFilePathToShowToUser)
176
177
  .filter(utils_js_1.isNotNullish)
177
- .map((definedAtInfo) => indent + definedAtInfo.filePath))
178
+ .map((filePathToShowToUser) => indent + filePathToShowToUser))
178
179
  .flat(2));
179
180
  (0, utils_js_1.assertUsage)(false, [
180
181
  'Mixing the new V1 design with the old V0.4 design is forbidden.',
@@ -2,17 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getClientEntryFilePath = void 0;
4
4
  const utils_js_1 = require("../../shared/page-configs/utils.js");
5
- const utils_js_2 = require("./utils.js");
6
5
  function getClientEntryFilePath(pageConfig) {
7
6
  const configName = 'client';
8
7
  const configValue = (0, utils_js_1.getConfigValue)(pageConfig, configName, 'string');
9
8
  if (!configValue)
10
9
  return null;
11
- const definedAtInfo = (0, utils_js_1.getConfigDefinedAtInfo)(pageConfig, configName);
12
- const { value } = configValue;
13
- // Users should be able to suppress client entry by setting its value to null
14
- (0, utils_js_2.assert)(value !== null);
15
- const clientEntryFilePath = definedAtInfo.filePath;
16
- return clientEntryFilePath;
10
+ return configValue.value;
17
11
  }
18
12
  exports.getClientEntryFilePath = getClientEntryFilePath;
@@ -33,11 +33,8 @@ function getExports(pageFiles, pageConfig) {
33
33
  // V1 design
34
34
  if (pageConfig) {
35
35
  Object.entries(pageConfig.configValues).forEach(([configName, configValue]) => {
36
- const { value, definedAtInfo } = configValue;
37
- let filePath = null;
38
- if (definedAtInfo) {
39
- filePath = definedAtInfo.filePath;
40
- }
36
+ const { value } = configValue;
37
+ const filePath = (0, utils_js_2.getConfigValueFilePathToShowToUser)(configValue);
41
38
  const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, configValue, true);
42
39
  config[configName] = config[configName] ?? value;
43
40
  configEntries[configName] = configEntries[configName] ?? [];
@@ -4,6 +4,7 @@ exports.parsePageConfigsSerialized = void 0;
4
4
  const parse_1 = require("@brillout/json-serializer/parse");
5
5
  const parseConfigValuesImported_js_1 = require("../page-configs/parseConfigValuesImported.js");
6
6
  const utils_js_1 = require("../utils.js");
7
+ const utils_js_2 = require("../page-configs/utils.js");
7
8
  function parsePageConfigsSerialized(pageConfigsSerialized, pageConfigGlobalSerialized) {
8
9
  const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
9
10
  const configValues = {};
@@ -11,12 +12,12 @@ function parsePageConfigsSerialized(pageConfigsSerialized, pageConfigGlobalSeria
11
12
  const { configValuesSerialized } = pageConfigSerialized;
12
13
  Object.entries(configValuesSerialized).forEach(([configName, configValueSeriliazed]) => {
13
14
  {
14
- const { valueSerialized, definedAtInfo } = configValueSeriliazed;
15
+ const { valueSerialized, definedAt } = configValueSeriliazed;
15
16
  (0, utils_js_1.assert)(valueSerialized);
16
17
  (0, utils_js_1.assert)(!configValues[configName]);
17
18
  configValues[configName] = {
18
19
  value: (0, parse_1.parse)(valueSerialized),
19
- definedAtInfo
20
+ definedAt
20
21
  };
21
22
  }
22
23
  });
@@ -45,12 +46,14 @@ function parsePageConfigsSerialized(pageConfigsSerialized, pageConfigGlobalSeria
45
46
  }
46
47
  exports.parsePageConfigsSerialized = parsePageConfigsSerialized;
47
48
  function assertRouteConfigValue(configValues) {
48
- if (!configValues.route)
49
+ const configName = 'route';
50
+ const configValue = configValues[configName];
51
+ if (!configValue)
49
52
  return;
50
- const { value, definedAtInfo } = configValues.route;
53
+ const { value } = configValue;
51
54
  const configValueType = typeof value;
52
- (0, utils_js_1.assert)(definedAtInfo);
53
- (0, utils_js_1.assertUsage)(configValueType === 'string' || (0, utils_js_1.isCallable)(value), `${definedAtInfo.filePath} has an invalid type '${configValueType}': it should be a string or a function instead, see https://vike.dev/route`);
55
+ const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, configValue, true);
56
+ (0, utils_js_1.assertUsage)(configValueType === 'string' || (0, utils_js_1.isCallable)(value), `${configDefinedAt} has an invalid type '${configValueType}': it should be a string or a function instead, see https://vike.dev/route`);
54
57
  /* We don't use assertRouteString() in order to avoid unnecessarily bloating the client-side bundle when using Server Routing:
55
58
  * - When using Server Routing, this file is loaded => loading assertRouteString() would bloat the client bundle.
56
59
  * - assertRouteString() is already called on the server-side
@@ -11,7 +11,9 @@ function getHook(pageContext, hookName) {
11
11
  (0, utils_js_1.assert)(file.exportValue === hookFn);
12
12
  if (hookFn === null)
13
13
  return null;
14
- const hookFilePath = file.exportSource;
14
+ const hookFilePath = file.filePath;
15
+ (0, utils_js_1.assert)(hookFilePath);
16
+ (0, utils_js_1.assert)(!hookFilePath.endsWith(' '));
15
17
  assertHookFn(hookFn, { hookName, hookFilePath });
16
18
  return { hookFn, hookName, hookFilePath };
17
19
  }
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getExportPath = void 0;
4
4
  const utils_js_1 = require("../utils.js");
5
- // TODO: return null instead of 'export default'
6
- // - Also return null insead of 'export *'?
7
5
  function getExportPath(fileExportPath) {
6
+ if (!fileExportPath)
7
+ return null;
8
8
  let prefix = '';
9
9
  let suffix = '';
10
10
  let [exportName, ...exportObjectPath] = fileExportPath;
@@ -9,15 +9,18 @@ const assertExports_js_1 = require("./assertExports.js");
9
9
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
10
10
  function parseConfigValuesImported(configValuesImported) {
11
11
  const configValues = {};
12
- const addConfigValue = (configName, value, filePath, exportName) => {
12
+ const addConfigValue = (configName, value, importPath, exportName) => {
13
13
  configValues[configName] = {
14
14
  value,
15
- definedAtInfo: {
16
- filePath,
17
- fileExportPath: [exportName]
15
+ definedAt: {
16
+ source: {
17
+ // importPath is always relative the user's root directory (it cannot be relative to the current file since the current file is a virtual file)
18
+ filePathToShowToUser: importPath,
19
+ fileExportPath: [exportName]
20
+ }
18
21
  }
19
22
  };
20
- assertIsNotNull(value, configName, filePath);
23
+ assertIsNotNull(value, configName, importPath);
21
24
  };
22
25
  configValuesImported.forEach((configValueLoaded) => {
23
26
  if (configValueLoaded.isValueFile) {
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getDefinedAtString = exports.getConfigDefinedAtInfo = exports.getConfigDefinedAtString = exports.getPageConfig = exports.getConfigValue = void 0;
6
+ exports.getHookFilePathToShowToUser = exports.getConfigValueFilePathToShowToUser = exports.getDefinedAtString = exports.getConfigDefinedAtString = exports.getPageConfig = exports.getConfigValue = void 0;
7
7
  const utils_js_1 = require("../utils.js");
8
8
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
9
9
  const getExportPath_js_1 = require("./getExportPath.js");
@@ -12,33 +12,30 @@ function getConfigValue(pageConfig, configName, type) {
12
12
  const configValue = getConfigValueEntry(pageConfig, configName);
13
13
  if (configValue === null)
14
14
  return null;
15
- const { value, definedAtInfo } = configValue;
15
+ const { value, definedAt } = configValue;
16
16
  if (type)
17
- assertConfigValueType(value, type, configName, definedAtInfo);
18
- return { value };
17
+ assertConfigValueType(value, type, configName, definedAt);
18
+ return configValue;
19
19
  }
20
20
  exports.getConfigValue = getConfigValue;
21
- function getConfigDefinedAtInfo(pageConfig, configName) {
22
- const configValue = getConfigValueEntry(pageConfig, configName);
23
- // We assume the caller to have ensured that the config value exists prior to calling getConfigDefinedAtInfo()
24
- (0, utils_js_1.assert)(configValue);
25
- const { definedAtInfo } = configValue;
26
- // definedAtInfo is available only for config values that aren't:
27
- // - computed, nor
28
- // - cumulative
29
- (0, utils_js_1.assert)(definedAtInfo);
30
- return definedAtInfo;
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`);
31
30
  }
32
- exports.getConfigDefinedAtInfo = getConfigDefinedAtInfo;
33
31
  function getConfigValueEntry(pageConfig, configName) {
34
32
  const configValue = pageConfig.configValues[configName];
35
33
  if (!configValue)
36
34
  return null;
37
- const { value, definedAtInfo } = configValue;
38
35
  // Enable users to suppress global config values by setting the local config value to null
39
- if (value === null)
36
+ if (configValue.value === null)
40
37
  return null;
41
- return { value, definedAtInfo };
38
+ return configValue;
42
39
  }
43
40
  function getPageConfig(pageId, pageConfigs) {
44
41
  const pageConfig = pageConfigs.find((p) => p.pageId === pageId);
@@ -47,34 +44,61 @@ function getPageConfig(pageId, pageConfigs) {
47
44
  return pageConfig;
48
45
  }
49
46
  exports.getPageConfig = getPageConfig;
50
- function assertConfigValueType(value, type, configName, definedAtInfo) {
51
- (0, utils_js_1.assert)(value !== null);
52
- const typeActual = typeof value;
53
- if (typeActual === type)
54
- return;
55
- const valuePrintable = (0, utils_js_1.getValuePrintable)(value);
56
- const problem = valuePrintable !== null ? `value ${picocolors_1.default.cyan(valuePrintable)}` : `type ${picocolors_1.default.cyan(typeActual)}`;
57
- const configDefinedAt = getConfigDefinedAtString(configName, { definedAtInfo }, true);
58
- (0, utils_js_1.assertUsage)(false, `${configDefinedAt} has an invalid ${problem}: it should be a ${picocolors_1.default.cyan(type)} instead`);
59
- }
60
- function getConfigDefinedAtString(configName, { definedAtInfo }, sentenceBegin, append) {
61
- let configDefinedAt = `${sentenceBegin ? `Config` : `config`} ${picocolors_1.default.cyan(configName)}`;
62
- if (definedAtInfo !== null) {
63
- configDefinedAt = `${configDefinedAt} defined at ${getDefinedAtString(definedAtInfo, append)}`;
64
- }
47
+ function getConfigDefinedAtString(configName, { definedAt }, sentenceBegin) {
48
+ const configDefinedAt = `${sentenceBegin ? `Config` : `config`} ${picocolors_1.default.cyan(configName)} defined ${getSourceString(definedAt)}`;
65
49
  return configDefinedAt;
66
50
  }
67
51
  exports.getConfigDefinedAtString = getConfigDefinedAtString;
68
- function getDefinedAtString(definedAtInfo, append) {
69
- const { filePath, fileExportPath } = definedAtInfo;
70
- let definedAt = filePath;
71
- const exportPath = (0, getExportPath_js_1.getExportPath)(fileExportPath);
72
- if (exportPath) {
73
- definedAt = `${definedAt} > ${picocolors_1.default.cyan(exportPath)}`;
52
+ function getSourceString(definedAt) {
53
+ if (definedAt.isComputed) {
54
+ return 'internally';
74
55
  }
75
- if (append) {
76
- definedAt = `${definedAt} > (${picocolors_1.default.blue(append)})`;
56
+ let sources;
57
+ if (definedAt.isCumulative) {
58
+ sources = definedAt.sources;
77
59
  }
78
- return definedAt;
60
+ else {
61
+ sources = [definedAt.source];
62
+ }
63
+ (0, utils_js_1.assert)(sources.length >= 1);
64
+ const sourceString = sources
65
+ .map((source) => {
66
+ const { filePathToShowToUser, fileExportPath } = source;
67
+ let s = filePathToShowToUser;
68
+ const exportPath = (0, getExportPath_js_1.getExportPath)(fileExportPath);
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) {
81
+ let sourceString = getSourceString(configValue.definedAt);
82
+ if (sourceString.startsWith('at '))
83
+ sourceString = sourceString.slice('at '.length);
84
+ return sourceString;
79
85
  }
80
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 { source } = definedAt;
94
+ const { filePathToShowToUser } = source;
95
+ (0, utils_js_1.assert)(filePathToShowToUser);
96
+ return filePathToShowToUser;
97
+ }
98
+ exports.getConfigValueFilePathToShowToUser = getConfigValueFilePathToShowToUser;
99
+ function getHookFilePathToShowToUser({ definedAt }) {
100
+ const filePathToShowToUser = getConfigValueFilePathToShowToUser({ definedAt });
101
+ (0, utils_js_1.assert)(filePathToShowToUser);
102
+ return filePathToShowToUser;
103
+ }
104
+ exports.getHookFilePathToShowToUser = getHookFilePathToShowToUser;
@@ -33,9 +33,8 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
33
33
  const configName = 'route';
34
34
  const configValue = (0, utils_js_3.getConfigValue)(pageConfig, configName);
35
35
  if (configValue) {
36
- const definedAtInfo = (0, utils_js_3.getConfigDefinedAtInfo)(pageConfig, configName);
37
36
  const route = configValue.value;
38
- const definedAt = (0, utils_js_3.getDefinedAtString)(definedAtInfo);
37
+ const definedAt = (0, utils_js_3.getDefinedAtString)(configValue);
39
38
  if (typeof route === 'string') {
40
39
  pageRoute = {
41
40
  pageId,
@@ -141,10 +140,10 @@ function getGlobalHooks(pageFilesAll, pageConfigs, pageConfigGlobal) {
141
140
  // V1 Design
142
141
  if (pageConfigs.length > 0) {
143
142
  if (pageConfigGlobal.configValues.onBeforeRoute?.value) {
144
- const { value: hookFn, definedAtInfo } = pageConfigGlobal.configValues.onBeforeRoute;
145
- // config.onBeforeRoute isn't a computed nor a cumulative config => definedAtInfo should always be defined
146
- (0, utils_js_1.assert)(definedAtInfo);
147
- const hookFilePath = definedAtInfo.filePath;
143
+ const configValue = pageConfigGlobal.configValues.onBeforeRoute;
144
+ const { value: hookFn } = configValue;
145
+ const hookFilePath = (0, utils_js_3.getHookFilePathToShowToUser)(configValue);
146
+ // TODO: use getConfigDefinedAtString()
148
147
  (0, utils_js_1.assertUsage)((0, utils_js_2.isCallable)(hookFn), `The hook onBeforeRoute() defined by ${hookFilePath} should be a function.`);
149
148
  const onBeforeRouteHook = {
150
149
  hookFilePath: hookFilePath,
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.projectInfo = void 0;
4
4
  const assertSingleInstance_js_1 = require("./assertSingleInstance.js");
5
- const PROJECT_VERSION = '0.4.143-commit-f03b42d';
5
+ const PROJECT_VERSION = '0.4.143-commit-fa295e1';
6
6
  const projectInfo = {
7
7
  projectName: 'Vike',
8
8
  projectVersion: PROJECT_VERSION,
@@ -22,7 +22,7 @@ async function determineOptimizeDeps(config, configVike, isDev) {
22
22
  */
23
23
  config.optimizeDeps.include = [...include, ...normalizeInclude(config.optimizeDeps.include)];
24
24
  config.optimizeDeps.entries = [...entries, ...normalizeEntries(config.optimizeDeps.entries)];
25
- // console.log('config.optimizeDeps', config.optimizeDeps)
25
+ console.log('config.optimizeDeps', config.optimizeDeps);
26
26
  }
27
27
  async function getPageDeps(config, pageConfigs, isDev) {
28
28
  let entries = [];
@@ -32,37 +32,40 @@ async function getPageDeps(config, pageConfigs, isDev) {
32
32
  pageConfigs.forEach((pageConfig) => {
33
33
  const configValueSourcesRelevant = getConfigValueSourcesRelevant(pageConfig);
34
34
  configValueSourcesRelevant.forEach((configValueSource) => {
35
- const { valueIsImportedAtRuntime, configEnv, definedAtInfo } = configValueSource;
36
- if (!valueIsImportedAtRuntime)
35
+ if (!configValueSource.valueIsImportedAtRuntime)
37
36
  return;
38
- const { filePath } = definedAtInfo;
39
- assert(filePath);
40
- if (configEnv !== 'client-only' && configEnv !== 'server-and-client')
37
+ if (configValueSource.isComputed)
41
38
  return;
42
- if (filePath.startsWith('/')) {
43
- // Is getFilePathAbsolute() really needed? This contradicts the code below that doesn't need getFilePathAbsolute().
44
- entries.push(getFilePathAbsolute(filePath, config));
39
+ const { definedAtInfo, configEnv } = configValueSource;
40
+ if (configEnv !== 'client-only' && configEnv !== 'server-and-client')
45
41
  return;
46
- }
47
- // getVikeConfig() resolves relative import paths
48
- assert(!filePath.startsWith('.'));
49
- // We need to differentiate between npm package imports and path aliases.
50
- // There are path aliases that cannot be distinguished from npm package names.
51
- // We recommend users to use the '#' prefix convention for path aliases, see https://vike.dev/path-aliases#vite and assertResolveAlias()
52
- if (isNpmPackageImport(filePath)) {
53
- // isNpmPackageImport() returns false for a path alias like #root/renderer/onRenderClient
54
- assert(!filePath.startsWith('#'));
55
- include.push(filePath);
42
+ if (definedAtInfo.filePathRelativeToUserRootDir !== null) {
43
+ const { filePathAbsolute } = definedAtInfo;
44
+ assert(filePathAbsolute);
45
+ // Surpsingly Vite expects entries to be absolute paths
46
+ entries.push(filePathAbsolute);
56
47
  }
57
48
  else {
58
- /* Path aliases, e.g.:
59
- * ```js
60
- * // /renderer/+config.js
61
- * import onRenderClient from '#root/renderer/onRenderClient'
62
- * ```
63
- * Does Vite resolve the path aliases or is getFilePathAbsolute() needed?
64
- */
65
- entries.push(filePath);
49
+ // Adding definedAtInfo.filePathAbsolute doesn't work for npm packages, I guess because of Vite's config.server.fs.allow
50
+ const { importPathAbsolute } = definedAtInfo;
51
+ assert(importPathAbsolute);
52
+ // We need to differentiate between npm package imports and path aliases.
53
+ // There are path aliases that cannot be distinguished from npm package names.
54
+ // We recommend users to use the '#' prefix convention for path aliases, see https://vike.dev/path-aliases#vite and assertResolveAlias()
55
+ if (isNpmPackageImport(importPathAbsolute)) {
56
+ // isNpmPackageImport() returns false for a path alias like #root/renderer/onRenderClient
57
+ assert(!importPathAbsolute.startsWith('#'));
58
+ include.push(importPathAbsolute);
59
+ }
60
+ else {
61
+ /* Path aliases, e.g.:
62
+ * ```js
63
+ * // /renderer/+config.js
64
+ * import onRenderClient from '#root/renderer/onRenderClient'
65
+ * ```
66
+ */
67
+ entries.push(importPathAbsolute);
68
+ }
66
69
  }
67
70
  });
68
71
  });
@@ -6,10 +6,19 @@ type FilePath = {
6
6
  * Example: `/home/rom/code/my-app/pages/some-page/Page.js`
7
7
  */
8
8
  filePathAbsolute: string;
9
+ } & ({
9
10
  /** The file's path relative to the Vite's root (i.e. the user's project root directory).
10
11
  *
11
12
  * Example: `/pages/some-page/Page.js`
12
13
  */
13
- filePathRelativeToUserRootDir: null | string;
14
- };
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
+ });
15
24
  declare function getFilePathToShowToUser(filePath: FilePath): string;
@@ -1,5 +1,11 @@
1
1
  export { getFilePathToShowToUser };
2
2
  import { assert } from '../../../utils.js';
3
+ /*
4
+ const f: FilePath = 1 as any
5
+ if (f.filePathRelativeToUserRootDir === null) {
6
+ f.importPathAbsolute
7
+ }
8
+ //*/
3
9
  function getFilePathToShowToUser(filePath) {
4
10
  const filePathToShowToUser = filePath.filePathRelativeToUserRootDir ?? filePath.filePathAbsolute;
5
11
  assert(filePathToShowToUser);
@@ -31,17 +31,18 @@ type ConfigDefinition = {
31
31
  effect?: ConfigEffect;
32
32
  };
33
33
  type ConfigEffect = (config: {
34
- /** The resolved config value.
34
+ /** The config value.
35
35
  *
36
36
  * https://vike.dev/meta
37
37
  */
38
38
  configValue: unknown;
39
- /** Place where the resolved config value comes from.
39
+ /** Where the config value is defined.
40
40
  *
41
41
  * https://vike.dev/meta
42
42
  */
43
43
  configDefinedAt: `Config ${string}`;
44
44
  }) => Config | undefined;
45
+ /** For Vike internal use */
45
46
  type ConfigDefinitionInternal = Omit<ConfigDefinition, 'env'> & {
46
47
  _computed?: (pageConfig: PageConfigBuildTime) => unknown;
47
48
  _valueIsFilePath?: true;