vike 0.4.144-commit-756f5d7 → 0.4.144-commit-6aef8a6

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 (42) hide show
  1. package/dist/cjs/node/plugin/plugins/importBuild/index.js +3 -3
  2. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
  3. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +140 -127
  4. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +2 -4
  5. package/dist/cjs/node/runtime/renderPage/log404/index.js +27 -17
  6. package/dist/cjs/shared/page-configs/getExportPath.js +3 -3
  7. package/dist/cjs/shared/page-configs/loadConfigValues.js +2 -2
  8. package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +1 -1
  9. package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +8 -9
  10. package/dist/cjs/shared/page-configs/utils.js +8 -15
  11. package/dist/cjs/shared/route/abort.js +1 -1
  12. package/dist/cjs/shared/route/loadPageRoutes.js +1 -1
  13. package/dist/cjs/utils/projectInfo.js +1 -1
  14. package/dist/cjs/utils/truncateString.js +12 -7
  15. package/dist/esm/node/plugin/plugins/importBuild/index.js +3 -3
  16. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
  17. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
  18. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
  19. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +140 -127
  20. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
  21. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +2 -4
  22. package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
  23. package/dist/esm/node/runtime/renderPage/log404/index.js +27 -16
  24. package/dist/esm/shared/page-configs/PageConfig.d.ts +51 -21
  25. package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
  26. package/dist/esm/shared/page-configs/getExportPath.js +3 -3
  27. package/dist/esm/shared/page-configs/loadConfigValues.js +2 -2
  28. package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +4 -4
  29. package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +1 -1
  30. package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +8 -9
  31. package/dist/esm/shared/page-configs/utils.d.ts +3 -3
  32. package/dist/esm/shared/page-configs/utils.js +8 -15
  33. package/dist/esm/shared/route/abort.js +1 -1
  34. package/dist/esm/shared/route/loadPageRoutes.js +1 -1
  35. package/dist/esm/utils/projectInfo.d.ts +1 -1
  36. package/dist/esm/utils/projectInfo.js +1 -1
  37. package/dist/esm/utils/truncateString.d.ts +2 -1
  38. package/dist/esm/utils/truncateString.js +10 -7
  39. package/package.json +1 -1
  40. package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -16
  41. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +0 -24
  42. package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -13
@@ -32,15 +32,15 @@ function importBuild() {
32
32
  }
33
33
  exports.importBuild = importBuild;
34
34
  function getImporterCode(config, pageFilesEntry) {
35
- const importPathAbsolute = (0, utils_js_1.toPosixPath)(
35
+ const filePathAbsolute = (0, utils_js_1.toPosixPath)(
36
36
  // [RELATIVE_PATH_FROM_DIST] Current file: node_modules/vike/dist/esm/node/plugin/plugins/importBuild/index.js
37
37
  require_.resolve(`../../../../../../dist/esm/node/runtime/globalContext/loadImportBuild.js`));
38
38
  const { outDirServer } = (0, utils_js_1.getOutDirs)(config);
39
- const importPath = path_1.default.posix.relative(outDirServer, importPathAbsolute);
39
+ const filePathRelative = path_1.default.posix.relative(outDirServer, filePathAbsolute);
40
40
  // The only reason we went for using CJS require() instead of ESM import() is because import() doesn't support .json files
41
41
  const importerCode = [
42
42
  '(async () => {',
43
- ` const { setImportBuildGetters } = await import('${importPath}');`,
43
+ ` const { setImportBuildGetters } = await import('${filePathRelative}');`,
44
44
  ' setImportBuildGetters({',
45
45
  ` pageFiles: () => import('./${pageFilesEntry}'),`,
46
46
  " clientManifest: () => require('../assets.json'),",
@@ -7,8 +7,8 @@ const utils_js_1 = require("../../../../utils.js");
7
7
  * getLocationId('/pages/some-page') => '/pages/some-page'
8
8
  * getLocationId('/renderer/+config.js') => '/renderer'
9
9
  */
10
- function getLocationId(somePath) {
11
- const locationId = removeFilename(somePath, true);
10
+ function getLocationId(filePathAbsoluteVite) {
11
+ const locationId = removeFilename(filePathAbsoluteVite, true);
12
12
  assertLocationId(locationId);
13
13
  return locationId;
14
14
  }
@@ -110,21 +110,21 @@ function removeDirectories(somePath, removeDirs) {
110
110
  somePath = '/';
111
111
  return somePath;
112
112
  }
113
- function removeFilename(filePath, optional) {
114
- (0, utils_js_1.assertPosixPath)(filePath);
115
- (0, utils_js_1.assert)(filePath.startsWith('/') || (0, utils_js_1.isNpmPackageImport)(filePath));
113
+ function removeFilename(filePathAbsoluteVite, optional) {
114
+ (0, utils_js_1.assertPosixPath)(filePathAbsoluteVite);
115
+ (0, utils_js_1.assert)(filePathAbsoluteVite.startsWith('/') || (0, utils_js_1.isNpmPackageImport)(filePathAbsoluteVite));
116
116
  {
117
- const filename = filePath.split('/').slice(-1)[0];
117
+ const filename = filePathAbsoluteVite.split('/').slice(-1)[0];
118
118
  if (!filename.includes('.')) {
119
119
  (0, utils_js_1.assert)(optional);
120
- return filePath;
120
+ return filePathAbsoluteVite;
121
121
  }
122
122
  }
123
- filePath = filePath.split('/').slice(0, -1).join('/');
124
- if (filePath === '')
125
- filePath = '/';
126
- assertLocationId(filePath);
127
- return filePath;
123
+ let locationId = filePathAbsoluteVite.split('/').slice(0, -1).join('/');
124
+ if (locationId === '')
125
+ locationId = '/';
126
+ assertLocationId(locationId);
127
+ return locationId;
128
128
  }
129
129
  function getFilesystemRouteDefinedBy(locationId) {
130
130
  if (locationId === '/')
@@ -15,7 +15,6 @@ const isConfigInvalid_js_1 = require("../../../../runtime/renderPage/isConfigInv
15
15
  const globalContext_js_1 = require("../../../../runtime/globalContext.js");
16
16
  const loggerNotProd_js_1 = require("../../../shared/loggerNotProd.js");
17
17
  const removeSuperfluousViteLog_js_1 = require("../../../shared/loggerVite/removeSuperfluousViteLog.js");
18
- const getFilePathToShowToUser_js_1 = require("./getFilePathToShowToUser.js");
19
18
  const picocolors_1 = __importDefault(require("@brillout/picocolors"));
20
19
  const utils_js_2 = require("../../../../../shared/page-configs/utils.js");
21
20
  const assertExports_js_1 = require("../../../../../shared/page-configs/assertExports.js");
@@ -77,7 +76,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
77
76
  const configFiles = [];
78
77
  const valueFiles = [];
79
78
  plusFiles.forEach((f) => {
80
- if (getConfigName(f.filePathRelativeToUserRootDir) === 'config') {
79
+ if (getConfigName(f.filePathAbsoluteFilesystem) === 'config') {
81
80
  configFiles.push(f);
82
81
  }
83
82
  else {
@@ -86,15 +85,10 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
86
85
  });
87
86
  let interfaceFilesByLocationId = {};
88
87
  // Config files
89
- await Promise.all(configFiles.map(async ({ filePathAbsoluteFilesystem, filePathRelativeToUserRootDir }) => {
90
- const configFilePath = {
91
- filePathAbsoluteFilesystem: filePathAbsoluteFilesystem,
92
- filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
93
- importPathAbsolute: null
94
- };
95
- const { configFile, extendsConfigs } = await loadConfigFile(configFilePath, userRootDir, []);
88
+ await Promise.all(configFiles.map(async (filePath) => {
89
+ const { configFile, extendsConfigs } = await loadConfigFile(filePath, userRootDir, []);
96
90
  const interfaceFile = getInterfaceFileFromConfigFile(configFile, false);
97
- const locationId = (0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir);
91
+ const locationId = (0, filesystemRouting_js_1.getLocationId)(filePath.filePathAbsoluteVite);
98
92
  interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
99
93
  interfaceFilesByLocationId[locationId].push(interfaceFile);
100
94
  extendsConfigs.forEach((extendsConfig) => {
@@ -103,15 +97,11 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
103
97
  });
104
98
  }));
105
99
  // Value files
106
- await Promise.all(valueFiles.map(async ({ filePathAbsoluteFilesystem, filePathRelativeToUserRootDir }) => {
107
- const configName = getConfigName(filePathRelativeToUserRootDir);
100
+ await Promise.all(valueFiles.map(async (filePath) => {
101
+ const configName = getConfigName(filePath.filePathAbsoluteVite);
108
102
  (0, utils_js_1.assert)(configName);
109
103
  const interfaceFile = {
110
- filePath: {
111
- filePathRelativeToUserRootDir,
112
- filePathAbsoluteFilesystem,
113
- importPathAbsolute: null
114
- },
104
+ filePath,
115
105
  configMap: {
116
106
  [configName]: {}
117
107
  },
@@ -129,16 +119,16 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
129
119
  }
130
120
  }
131
121
  {
132
- const locationId = (0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir);
122
+ const locationId = (0, filesystemRouting_js_1.getLocationId)(filePath.filePathAbsoluteVite);
133
123
  interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
134
124
  interfaceFilesByLocationId[locationId].push(interfaceFile);
135
125
  }
136
126
  }));
137
127
  return interfaceFilesByLocationId;
138
128
  }
139
- function getConfigDefinition(configDefinitionsRelevant, configName, definedByFile) {
129
+ function getConfigDefinition(configDefinitionsRelevant, configName, filePathToShowToUser) {
140
130
  const configDef = configDefinitionsRelevant[configName];
141
- assertConfigExists(configName, Object.keys(configDefinitionsRelevant), definedByFile);
131
+ assertConfigExists(configName, Object.keys(configDefinitionsRelevant), filePathToShowToUser);
142
132
  (0, utils_js_1.assert)(configDef);
143
133
  return configDef;
144
134
  }
@@ -147,7 +137,7 @@ function getConfigDefinitionOptional(configDefinitions, configName) {
147
137
  }
148
138
  async function loadValueFile(interfaceValueFile, configName, userRootDir) {
149
139
  const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath, true, userRootDir);
150
- const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceValueFile.filePath);
140
+ const { filePathToShowToUser } = interfaceValueFile.filePath;
151
141
  (0, assertExports_js_1.assertExportsOfValueFile)(fileExports, filePathToShowToUser, configName);
152
142
  Object.entries(fileExports).forEach(([exportName, configValue]) => {
153
143
  const configName_ = exportName === 'default' ? configName : exportName;
@@ -164,7 +154,7 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
164
154
  isConfigExtend,
165
155
  extendsFilePaths
166
156
  };
167
- const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(filePath);
157
+ const { filePathToShowToUser } = filePath;
168
158
  (0, assertExports_js_1.assertExportsOfConfigFile)(fileExports, filePathToShowToUser);
169
159
  Object.entries(fileExports.default).forEach(([configName, configValue]) => {
170
160
  interfaceFile.configMap[configName] = { configValue };
@@ -227,7 +217,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
227
217
  const { configName } = interfaceFile;
228
218
  if (isGlobalConfig(configName))
229
219
  return;
230
- const configDef = getConfigDefinition(configDefinitionsRelevant, configName, (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceFile.filePath));
220
+ const configDef = getConfigDefinition(configDefinitionsRelevant, configName, interfaceFile.filePath.filePathToShowToUser);
231
221
  if (configDef.env !== 'config-only')
232
222
  return;
233
223
  const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
@@ -266,7 +256,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
266
256
  const configDefinitionsRelevant = getConfigDefinitions(interfaceFilesRelevant);
267
257
  interfaceFiles.forEach((interfaceFile) => {
268
258
  Object.keys(interfaceFile.configMap).forEach((configName) => {
269
- assertConfigExists(configName, Object.keys(configDefinitionsRelevant), (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceFile.filePath));
259
+ assertConfigExists(configName, Object.keys(configDefinitionsRelevant), interfaceFile.filePath.filePathToShowToUser);
270
260
  });
271
261
  });
272
262
  });
@@ -317,7 +307,7 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
317
307
  Object.keys(interfaceFile.configMap).forEach((configName) => {
318
308
  if (!(0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds) && isGlobalConfig(configName)) {
319
309
  (0, utils_js_1.assertUsage)(false, [
320
- `${(0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceFile.filePath)} defines the config ${picocolors_1.default.cyan(configName)} which is global:`,
310
+ `${interfaceFile.filePath.filePathToShowToUser} defines the config ${picocolors_1.default.cyan(configName)} which is global:`,
321
311
  globalPaths.length
322
312
  ? `define ${picocolors_1.default.cyan(configName)} in ${(0, utils_js_1.joinEnglish)(globalPaths, 'or')} instead`
323
313
  : `create a global config (e.g. /pages/+config.js) and define ${picocolors_1.default.cyan(configName)} there instead`
@@ -344,9 +334,8 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
344
334
  (0, utils_js_1.assert)('value' in configValueSource);
345
335
  if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
346
336
  return;
347
- const sourceFilePath = getDefinedAtFilePathToShowToUser(configValueSource.definedAtInfo);
348
- (0, utils_js_1.assert)(sourceFilePath);
349
- (0, utils_js_1.assertWarning)(false, `Being able to define config ${picocolors_1.default.cyan(configName)} in ${sourceFilePath} is experimental and will likely be removed. Define the config ${picocolors_1.default.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
337
+ const { filePathToShowToUser } = configValueSource.definedAtInfo;
338
+ (0, utils_js_1.assertWarning)(false, `Being able to define config ${picocolors_1.default.cyan(configName)} in ${filePathToShowToUser} is experimental and will likely be removed. Define the config ${picocolors_1.default.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
350
339
  globalVikeConfig[configName] = configValueSource.value;
351
340
  }
352
341
  });
@@ -429,7 +418,7 @@ function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden,
429
418
  interfaceFilesOverriden.forEach((interfaceFileLoser) => {
430
419
  const configValueSourceWinner = getConfigValueSource(configName, interfaceFileWinner, configDef, userRootDir);
431
420
  const configValueSourceLoser = getConfigValueSource(configName, interfaceFileLoser, configDef, userRootDir);
432
- (0, utils_js_1.assertWarning)(false, `${getConfigSourceDefinedAtString(configName, configValueSourceLoser, undefined, true)} overriden by another ${getConfigSourceDefinedAtString(configName, configValueSourceWinner, undefined, false)}, remove one of the two`, { onlyOnce: false });
421
+ (0, utils_js_1.assertWarning)(false, `${getConfigSourceDefinedAtString(configName, configValueSourceLoser, true)} overriden by another ${getConfigSourceDefinedAtString(configName, configValueSourceWinner, false)}, remove one of the two`, { onlyOnce: false });
433
422
  });
434
423
  }
435
424
  function isInterfaceFileUserLand(interfaceFile) {
@@ -441,7 +430,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
441
430
  const configEnv = configDef.env;
442
431
  const definedAtConfigFile = {
443
432
  ...interfaceFile.filePath,
444
- fileExportPath: ['default', configName]
433
+ fileExportPathToShowToUser: ['default', configName]
445
434
  };
446
435
  if (configDef._valueIsFilePath) {
447
436
  let definedAtInfo;
@@ -451,15 +440,15 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
451
440
  const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
452
441
  const configDefinedAt = getConfigSourceDefinedAtString(configName, { definedAtInfo: definedAtConfigFile });
453
442
  (0, utils_js_1.assertUsage)(import_, `${configDefinedAt} should be an import`);
454
- valueFilePath = import_.filePathRelativeToUserRootDir ?? import_.importPathAbsolute;
443
+ valueFilePath = import_.filePathAbsoluteVite;
455
444
  definedAtInfo = import_;
456
445
  }
457
446
  else {
458
447
  (0, utils_js_1.assert)(interfaceFile.isValueFile);
459
- valueFilePath = interfaceFile.filePath.filePathRelativeToUserRootDir;
448
+ valueFilePath = interfaceFile.filePath.filePathAbsoluteVite;
460
449
  definedAtInfo = {
461
450
  ...interfaceFile.filePath,
462
- fileExportPath: []
451
+ fileExportPathToShowToUser: []
463
452
  };
464
453
  }
465
454
  const configValueSource = {
@@ -500,7 +489,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
500
489
  valueIsImportedAtRuntime: !valueAlreadyLoaded,
501
490
  definedAtInfo: {
502
491
  ...interfaceFile.filePath,
503
- fileExportPath: configName === interfaceFile.configName
492
+ fileExportPathToShowToUser: configName === interfaceFile.configName
504
493
  ? []
505
494
  : // Side-effect config (e.g. `export { frontmatter }` of .md files)
506
495
  [configName]
@@ -553,7 +542,7 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
553
542
  const { importPath, exportName } = importData;
554
543
  const filePathAbsoluteFilesystem = resolveImportPath(importData, importerFilePath);
555
544
  assertFileEnv(filePathAbsoluteFilesystem ?? importPath, configEnv, configName);
556
- const fileExportPath = exportName === 'default' || exportName === configName ? [] : [exportName];
545
+ const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
557
546
  if (importPath.startsWith('.')) {
558
547
  // We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
559
548
  // ```
@@ -561,25 +550,35 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
561
550
  // ```
562
551
  assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
563
552
  const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, importerFilePath, userRootDir);
564
- return {
565
- exportName,
566
- fileExportPath,
553
+ const filePath = {
567
554
  filePathAbsoluteFilesystem,
568
555
  filePathRelativeToUserRootDir,
556
+ filePathAbsoluteVite: filePathRelativeToUserRootDir,
557
+ filePathToShowToUser: filePathRelativeToUserRootDir,
569
558
  importPathAbsolute: null
570
559
  };
560
+ return {
561
+ ...filePath,
562
+ fileExportName: exportName,
563
+ fileExportPathToShowToUser
564
+ };
571
565
  }
572
566
  else {
573
567
  // importPath can be:
574
568
  // - an npm package import
575
569
  // - a path alias
576
- return {
577
- exportName,
578
- fileExportPath,
570
+ const filePath = {
579
571
  filePathAbsoluteFilesystem,
580
572
  filePathRelativeToUserRootDir: null,
573
+ filePathAbsoluteVite: importPath,
574
+ filePathToShowToUser: importPath,
581
575
  importPathAbsolute: importPath
582
576
  };
577
+ return {
578
+ ...filePath,
579
+ fileExportName: exportName,
580
+ fileExportPathToShowToUser
581
+ };
583
582
  }
584
583
  }
585
584
  function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
@@ -589,7 +588,7 @@ function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, imp
589
588
  filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, userRootDir);
590
589
  }
591
590
  else {
592
- (0, utils_js_1.assertUsage)(false, `${(0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(configFilePath)} imports from a relative path ${picocolors_1.default.cyan(importData.importPath)} outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
591
+ (0, utils_js_1.assertUsage)(false, `${configFilePath.filePathToShowToUser} imports from a relative path ${picocolors_1.default.cyan(importData.importPath)} outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
593
592
  // None of the following works. Seems to be a Vite bug?
594
593
  // /*
595
594
  // assert(filePathAbsoluteFilesystem.startsWith('/'))
@@ -622,8 +621,18 @@ function getConfigDefinitions(interfaceFilesRelevant) {
622
621
  return;
623
622
  const meta = configMeta.configValue;
624
623
  assertMetaValue(meta,
625
- // Maybe we should use the getConfigDefinedAtString() helper?
626
- `Config ${picocolors_1.default.cyan('meta')} defined at ${(0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceFile.filePath)}`);
624
+ // TODO: Maybe we should use the getConfigDefinedAtString() helper?
625
+ `Config ${picocolors_1.default.cyan('meta')} defined at ${interfaceFile.filePath.filePathToShowToUser}`);
626
+ // Set configDef._userEffectDefinedAt
627
+ Object.entries(meta).forEach(([configName, configDef]) => {
628
+ if (!configDef.effect)
629
+ return;
630
+ (0, utils_js_1.assert)(interfaceFile.isConfigFile);
631
+ configDef._userEffectDefinedAt = {
632
+ ...interfaceFile.filePath,
633
+ fileExportPathToShowToUser: ['default', 'meta', configName, 'effect']
634
+ };
635
+ });
627
636
  (0, utils_js_1.objectEntries)(meta).forEach(([configName, configDefinition]) => {
628
637
  // User can override an existing config definition
629
638
  configDefinitions[configName] = {
@@ -636,9 +645,15 @@ function getConfigDefinitions(interfaceFilesRelevant) {
636
645
  return configDefinitions;
637
646
  }
638
647
  function assertMetaValue(metaVal, configMetaDefinedAt) {
639
- (0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(metaVal), `${configMetaDefinedAt} has an invalid type ${picocolors_1.default.cyan(typeof metaVal)}: it should be an object instead.`);
648
+ if (!(0, utils_js_1.isObject)(metaVal)) {
649
+ (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
650
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} has an invalid type ${picocolors_1.default.cyan(typeof metaVal)}: it should be an object instead.`);
651
+ }
640
652
  (0, utils_js_1.objectEntries)(metaVal).forEach(([configName, def]) => {
641
- (0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(def), `${configMetaDefinedAt} sets meta.${configName} to a value with an invalid type ${picocolors_1.default.cyan(typeof def)}: it should be an object instead.`);
653
+ if (!(0, utils_js_1.isObject)(def)) {
654
+ (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
655
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}`)} to a value with an invalid type ${picocolors_1.default.cyan(typeof def)}: it should be an object instead.`);
656
+ }
642
657
  // env
643
658
  {
644
659
  const envValues = [
@@ -647,19 +662,34 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
647
662
  'server-and-client',
648
663
  'config-only'
649
664
  ];
650
- const hint = [
651
- `Set the value of ${picocolors_1.default.cyan('env')} to `,
665
+ const fix = [
666
+ `Set the value of ${picocolors_1.default.cyan(`meta.${configName}.env`)} to `,
652
667
  (0, utils_js_1.joinEnglish)(envValues.map((s) => picocolors_1.default.cyan(`'${s}'`)), 'or'),
653
668
  '.'
654
669
  ].join('');
655
- (0, utils_js_1.assertUsage)('env' in def, `${configMetaDefinedAt} doesn't set meta.${configName}.env but it's required. ${hint}`);
656
- (0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(def, 'env', 'string'), `${configMetaDefinedAt} sets meta.${configName}.env to an invalid type ${picocolors_1.default.cyan(typeof def.env)}. ${hint}`);
657
- (0, utils_js_1.assertUsage)(envValues.includes(def.env), `${configMetaDefinedAt} sets meta.${configName}.env to an invalid value ${picocolors_1.default.cyan(`'${def.env}'`)}. ${hint}`);
670
+ if (!('env' in def)) {
671
+ (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
672
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} doesn't set ${picocolors_1.default.cyan(`meta.${configName}.env`)} but it's required. ${fix}`);
673
+ }
674
+ if (!(0, utils_js_1.hasProp)(def, 'env', 'string')) {
675
+ (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
676
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.env`)} to an invalid type ${picocolors_1.default.cyan(typeof def.env)}. ${fix}`);
677
+ }
678
+ if (!envValues.includes(def.env)) {
679
+ (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
680
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.env`)} to an unknown value ${picocolors_1.default.cyan(`'${def.env}'`)}. ${fix}`);
681
+ }
658
682
  }
659
683
  // effect
660
684
  if ('effect' in def) {
661
- (0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(def, 'effect', 'function'), `${configMetaDefinedAt} sets meta.${configName}.effect to an invalid type ${picocolors_1.default.cyan(typeof def.effect)}: it should be a function instead`);
662
- (0, utils_js_1.assertUsage)(def.env === 'config-only', `${configMetaDefinedAt} sets meta.${configName}.effect but it's only supported if meta.${configName}.env is ${picocolors_1.default.cyan('config-only')} (but it's ${picocolors_1.default.cyan(def.env)} instead)`);
685
+ if (!(0, utils_js_1.hasProp)(def, 'effect', 'function')) {
686
+ (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
687
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.effect`)} to an invalid type ${picocolors_1.default.cyan(typeof def.effect)}: it should be a function instead`);
688
+ }
689
+ if (def.env !== 'config-only') {
690
+ (0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
691
+ (0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.effect`)} but it's only supported if meta.${configName}.env is ${picocolors_1.default.cyan('config-only')} (but it's ${picocolors_1.default.cyan(def.env)} instead)`);
692
+ }
663
693
  }
664
694
  });
665
695
  }
@@ -670,7 +700,7 @@ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
670
700
  // The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
671
701
  // (We could support effect for non config-only by always loading its value at config time, regardless of the config's `env` value.)
672
702
  (0, utils_js_1.assertUsage)(configDef.env === 'config-only', [
673
- `Cannot add effect to ${picocolors_1.default.cyan(configName)} because its ${picocolors_1.default.cyan('env')} is ${picocolors_1.default.cyan(configDef.env)}: effects can only be added to configs with an env that is ${picocolors_1.default.cyan('config-only')}.`
703
+ `Cannot add effect to ${picocolors_1.default.cyan(configName)} because its ${picocolors_1.default.cyan('env')} is ${picocolors_1.default.cyan(configDef.env)}: effects can only be added to configs with an ${picocolors_1.default.cyan('env')} value of ${picocolors_1.default.cyan('config-only')}.`
674
704
  ].join(' '));
675
705
  const source = configValueSources[configName]?.[0];
676
706
  if (!source)
@@ -685,14 +715,23 @@ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
685
715
  if (!configModFromEffect)
686
716
  return;
687
717
  (0, utils_js_1.assert)((0, utils_js_1.hasProp)(source, 'value')); // We need to assume that the config value is loaded at build-time
688
- applyEffect(configModFromEffect, source, configValueSources);
718
+ applyEffect(configModFromEffect, configValueSources, configDef);
689
719
  });
690
720
  }
691
- function applyEffect(configModFromEffect, configValueEffectSource, configValueSources) {
721
+ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
692
722
  const notSupported = `Effects currently only supports modifying the the ${picocolors_1.default.cyan('env')} of a config.`;
693
723
  (0, utils_js_1.objectEntries)(configModFromEffect).forEach(([configName, configValue]) => {
694
724
  if (configName === 'meta') {
695
- assertMetaValue(configValue, getConfigSourceDefinedAtString(configName, configValueEffectSource, true));
725
+ let configDefinedAtString;
726
+ if (configDefEffect._userEffectDefinedAt) {
727
+ configDefinedAtString = getConfigSourceDefinedAtString(configName, {
728
+ definedAtInfo: configDefEffect._userEffectDefinedAt
729
+ });
730
+ }
731
+ else {
732
+ configDefinedAtString = null;
733
+ }
734
+ assertMetaValue(configValue, configDefinedAtString);
696
735
  (0, utils_js_1.objectEntries)(configValue).forEach(([configTargetName, configTargetDef]) => {
697
736
  {
698
737
  const keys = Object.keys(configTargetDef);
@@ -710,7 +749,7 @@ function applyEffect(configModFromEffect, configValueEffectSource, configValueSo
710
749
  else {
711
750
  (0, utils_js_1.assertUsage)(false, notSupported);
712
751
  // If we do end implementing being able to set the value of a config:
713
- // - For setting definedAtInfo: we could take the definedAtInfo of the effect config while appending '(effect)' to definedAtInfo.fileExportPath
752
+ // - For setting definedAtInfo: we could take the definedAtInfo of the effect config while appending '(effect)' to definedAtInfo.fileExportPathToShowToUser
714
753
  }
715
754
  });
716
755
  }
@@ -762,19 +801,28 @@ async function findPlusFiles(userRootDir, ignoreDirs, isDev, extensions) {
762
801
  p = (0, utils_js_1.toPosixPath)(p);
763
802
  const filePathRelativeToUserRootDir = path_1.default.posix.join('/', p);
764
803
  const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, p);
765
- return { filePathRelativeToUserRootDir, filePathAbsoluteFilesystem };
804
+ return {
805
+ filePathRelativeToUserRootDir,
806
+ filePathAbsoluteVite: filePathRelativeToUserRootDir,
807
+ filePathAbsoluteFilesystem,
808
+ filePathToShowToUser: filePathRelativeToUserRootDir,
809
+ importPathAbsolute: null
810
+ };
766
811
  });
812
+ // TODO/v1-release: remove
767
813
  extensions.forEach((extension) => {
768
814
  extension.pageConfigsDistFiles?.forEach((pageConfigDistFile) => {
769
- // TODO/v1-release: remove
770
815
  if (!pageConfigDistFile.importPath.includes('+'))
771
816
  return;
772
817
  (0, utils_js_1.assert)(pageConfigDistFile.importPath.includes('+'));
773
818
  (0, utils_js_1.assert)(path_1.default.posix.basename(pageConfigDistFile.importPath).startsWith('+'));
774
819
  const { importPath, filePath } = pageConfigDistFile;
775
820
  plusFiles.push({
776
- filePathRelativeToUserRootDir: importPath,
777
- filePathAbsoluteFilesystem: filePath
821
+ filePathRelativeToUserRootDir: null,
822
+ filePathAbsoluteVite: importPath,
823
+ filePathAbsoluteFilesystem: filePath,
824
+ filePathToShowToUser: importPath,
825
+ importPathAbsolute: importPath
778
826
  });
779
827
  });
780
828
  });
@@ -839,10 +887,12 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
839
887
  // - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
840
888
  // - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsoluteFilesystem for added clarity
841
889
  const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir);
890
+ const filePathAbsoluteVite = filePathRelativeToUserRootDir ?? importPath;
842
891
  extendsConfigFiles.push({
843
892
  filePathAbsoluteFilesystem,
844
- // TODO: fix type cast
845
- filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
893
+ filePathAbsoluteVite,
894
+ filePathRelativeToUserRootDir,
895
+ filePathToShowToUser: filePathAbsoluteVite,
846
896
  importPathAbsolute: importPath
847
897
  });
848
898
  });
@@ -878,14 +928,14 @@ function assertExtendsImportPath(importPath, filePath, configFilePath) {
878
928
  });
879
929
  }
880
930
  else {
881
- (0, utils_js_1.assertWarning)(false, `${(0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(configFilePath)} uses ${picocolors_1.default.cyan('extends')} to inherit from ${picocolors_1.default.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this feature.`, { onlyOnce: true });
931
+ (0, utils_js_1.assertWarning)(false, `${configFilePath.filePathToShowToUser} uses ${picocolors_1.default.cyan('extends')} to inherit from ${picocolors_1.default.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this feature.`, { onlyOnce: true });
882
932
  }
883
933
  }
884
934
  function getExtendsImportData(configFileExports, configFilePath) {
885
- const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(configFilePath);
935
+ const { filePathToShowToUser } = configFilePath;
886
936
  (0, assertExports_js_1.assertExportsOfConfigFile)(configFileExports, filePathToShowToUser);
887
937
  const defaultExports = configFileExports.default;
888
- const wrongUsage = `${filePathToShowToUser} sets the config 'extends' to an invalid value, see https://vike.dev/extends`;
938
+ const wrongUsage = `${filePathToShowToUser} sets the config ${picocolors_1.default.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
889
939
  let extendList;
890
940
  if (!('extends' in defaultExports)) {
891
941
  return [];
@@ -906,38 +956,6 @@ function getExtendsImportData(configFileExports, configFilePath) {
906
956
  });
907
957
  return extendsImportData;
908
958
  }
909
- // TODO: re-use this
910
- function handleUserFileError(err, isDev) {
911
- // Properly handle error during transpilation so that we can use assertUsage() during transpilation
912
- if (isDev) {
913
- throw err;
914
- }
915
- else {
916
- // Avoid ugly error format:
917
- // ```
918
- // [vike:importUserCode] Could not load virtual:vike:importUserCode:server: [vike@0.4.70][Wrong Usage] /pages/+config.ts sets the config 'onRenderHtml' to the value './+config/onRenderHtml-i-dont-exist.js' but no file was found at /home/rom/code/vike/examples/v1/pages/+config/onRenderHtml-i-dont-exist.js
919
- // Error: [vike@0.4.70][Wrong Usage] /pages/+config.ts sets the config 'onRenderHtml' to the value './+config/onRenderHtml-i-dont-exist.js' but no file was found at /home/rom/code/vike/examples/v1/pages/+config/onRenderHtml-i-dont-exist.js
920
- // at ...
921
- // at ...
922
- // at ...
923
- // at ...
924
- // at ...
925
- // at ...
926
- // code: 'PLUGIN_ERROR',
927
- // plugin: 'vike:importUserCode',
928
- // hook: 'load',
929
- // watchFiles: [
930
- // '/home/rom/code/vike/vike/dist/esm/node/importBuild.js',
931
- // '\x00virtual:vike:importUserCode:server'
932
- // ]
933
- // }
934
- //  ELIFECYCLE  Command failed with exit code 1.
935
- // ```
936
- console.log('');
937
- console.error(err);
938
- process.exit(1);
939
- }
940
- }
941
959
  function isGlobalConfig(configName) {
942
960
  if (configName === 'prerender')
943
961
  return false;
@@ -947,15 +965,15 @@ function isGlobalConfig(configName) {
947
965
  function getConfigNamesGlobal() {
948
966
  return Object.keys(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal);
949
967
  }
950
- function assertConfigExists(configName, configNamesRelevant, definedByFile) {
968
+ function assertConfigExists(configName, configNamesRelevant, filePathToShowToUser) {
951
969
  const configNames = [...configNamesRelevant, ...getConfigNamesGlobal()];
952
970
  if (configNames.includes(configName))
953
971
  return;
954
- handleUnknownConfig(configName, configNames, definedByFile);
972
+ handleUnknownConfig(configName, configNames, filePathToShowToUser);
955
973
  (0, utils_js_1.assert)(false);
956
974
  }
957
- function handleUnknownConfig(configName, configNames, definedByFile) {
958
- let errMsg = `${definedByFile} defines an unknown config ${picocolors_1.default.cyan(configName)}`;
975
+ function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
976
+ let errMsg = `${filePathToShowToUser} defines an unknown config ${picocolors_1.default.cyan(configName)}`;
959
977
  let configNameSimilar = null;
960
978
  if (configName === 'page') {
961
979
  configNameSimilar = 'Page';
@@ -987,11 +1005,11 @@ function determineRouteFilesystem(locationId, configValueSources) {
987
1005
  if (configFilesystemRoutingRoot) {
988
1006
  const routingRoot = getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName);
989
1007
  if (routingRoot) {
990
- const { filesystemRoutingRootEffect, filesystemRoutingRootDefinedAt } = routingRoot;
1008
+ const { filesystemRoutingRootEffect /*, filesystemRoutingRootDefinedAt*/ } = routingRoot;
991
1009
  const debugInfo = { locationId, routeFilesystem: filesystemRouteString, configFilesystemRoutingRoot };
992
1010
  (0, utils_js_1.assert)(filesystemRouteString.startsWith(filesystemRoutingRootEffect.before), debugInfo);
993
1011
  filesystemRouteString = (0, filesystemRouting_js_1.applyFilesystemRoutingRootEffect)(filesystemRouteString, filesystemRoutingRootEffect);
994
- filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${filesystemRoutingRootDefinedAt})`;
1012
+ // filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${filesystemRoutingRootDefinedAt})`
995
1013
  }
996
1014
  }
997
1015
  (0, utils_js_1.assert)(filesystemRouteString.startsWith('/'));
@@ -1030,7 +1048,7 @@ function resolveImportPath(importData, importerFilePath) {
1030
1048
  }
1031
1049
  function assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath) {
1032
1050
  const { importPath: importPath, importStringWasGenerated, importString } = importData;
1033
- const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(importerFilePath);
1051
+ const { filePathToShowToUser } = importerFilePath;
1034
1052
  if (!filePathAbsoluteFilesystem) {
1035
1053
  const importPathString = picocolors_1.default.cyan(`'${importPath}'`);
1036
1054
  const errIntro = importStringWasGenerated
@@ -1082,6 +1100,17 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
1082
1100
  });
1083
1101
  return configValues;
1084
1102
  }
1103
+ function getDefinedAtFile(configValueSource) {
1104
+ return {
1105
+ filePathToShowToUser: configValueSource.definedAtInfo.filePathToShowToUser,
1106
+ fileExportPathToShowToUser: configValueSource.definedAtInfo.fileExportPathToShowToUser
1107
+ };
1108
+ }
1109
+ function getDefinedAt(configValueSource) {
1110
+ return {
1111
+ file: getDefinedAtFile(configValueSource)
1112
+ };
1113
+ }
1085
1114
  function mergeCumulative(configName, configValueSources) {
1086
1115
  const valuesArr = [];
1087
1116
  const valuesSet = [];
@@ -1105,7 +1134,7 @@ function mergeCumulative(configName, configValueSources) {
1105
1134
  if (vals2.length === 0)
1106
1135
  return;
1107
1136
  (0, utils_js_1.assert)(configValueSourcePrevious);
1108
- const configPreviousDefinedAt = getConfigSourceDefinedAtString(configName, configValueSourcePrevious, undefined, false);
1137
+ const configPreviousDefinedAt = getConfigSourceDefinedAtString(configName, configValueSourcePrevious, false);
1109
1138
  (0, utils_js_1.assertUsage)(false, `${configDefinedAt} sets ${t1} but another ${configPreviousDefinedAt} sets ${t2} which is forbidden: the values must be all arrays or all sets (you cannot mix).`);
1110
1139
  };
1111
1140
  const { value } = configValueSource;
@@ -1136,30 +1165,14 @@ function mergeCumulative(configName, configValueSources) {
1136
1165
  }
1137
1166
  (0, utils_js_1.assert)(false);
1138
1167
  }
1139
- // TODO: rename
1140
- // TODO: refactor
1141
- function getConfigSourceDefinedAtString(configName, { definedAtInfo }, isEffect = undefined, sentenceBegin = true) {
1168
+ // TODO: rename and/or refactor
1169
+ function getConfigSourceDefinedAtString(configName, { definedAtInfo }, sentenceBegin = true) {
1142
1170
  return (0, utils_js_2.getConfigDefinedAtString)(configName, {
1143
1171
  definedAt: {
1144
- isEffect,
1145
1172
  file: {
1146
- filePathToShowToUser: getDefinedAtFilePathToShowToUser(definedAtInfo),
1147
- fileExportPath: definedAtInfo.fileExportPath
1173
+ filePathToShowToUser: definedAtInfo.filePathToShowToUser,
1174
+ fileExportPathToShowToUser: definedAtInfo.fileExportPathToShowToUser
1148
1175
  }
1149
1176
  }
1150
1177
  }, sentenceBegin);
1151
1178
  }
1152
- function getDefinedAtFilePathToShowToUser(definedAtInfo) {
1153
- return definedAtInfo.filePathRelativeToUserRootDir ?? definedAtInfo.importPathAbsolute;
1154
- }
1155
- function getDefinedAtFile(source) {
1156
- return {
1157
- filePathToShowToUser: getDefinedAtFilePathToShowToUser(source.definedAtInfo),
1158
- fileExportPath: source.definedAtInfo.fileExportPath
1159
- };
1160
- }
1161
- function getDefinedAt(configValueSource) {
1162
- return {
1163
- file: getDefinedAtFile(configValueSource)
1164
- };
1165
- }