vike 0.4.181-commit-2f53249 → 0.4.181-commit-3fe2549

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.
@@ -277,6 +277,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
277
277
  const { routeFilesystem, isErrorPage } = determineRouteFilesystem(locationId, configValueSources);
278
278
  applyEffectsAll(configValueSources, configDefinitions);
279
279
  const configValuesComputed = getComputed(configValueSources, configDefinitions);
280
+ assertUsageGlobalConfigs(interfaceFilesRelevantList, configDefinitions, interfaceFilesByLocationId);
280
281
  const pageConfig = {
281
282
  pageId: locationId,
282
283
  isErrorPage,
@@ -290,6 +291,49 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
290
291
  assertPageConfigs(pageConfigs);
291
292
  return { pageConfigs, pageConfigGlobal, globalVikeConfig };
292
293
  }
294
+ // TODO/soon: refactor
295
+ // - Dedupe: most of the assertUsageGlobalConfigs() code below is a copy-paste of the assertUsage() logic inside getGlobalConfigs()
296
+ // Global configs should be defined at global locations
297
+ function assertUsageGlobalConfigs(interfaceFilesRelevantList, configDefinitions, interfaceFilesByLocationId) {
298
+ interfaceFilesRelevantList.forEach(async (interfaceFile) => {
299
+ const configNames = [];
300
+ if (interfaceFile.isValueFile) {
301
+ configNames.push(interfaceFile.configName);
302
+ }
303
+ else {
304
+ configNames.push(...Object.keys(interfaceFile.fileExportsByConfigName));
305
+ }
306
+ configNames.forEach((configName) => {
307
+ if (isGlobalConfig(configName))
308
+ return;
309
+ const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
310
+ if (configDef.global) {
311
+ const locationIds = (0, utils_js_1.objectKeys)(interfaceFilesByLocationId);
312
+ if (!(0, filesystemRouting_js_1.isGlobalLocation)(interfaceFile.locationId, locationIds)) {
313
+ const interfaceFilesGlobal = (0, utils_js_1.objectFromEntries)((0, utils_js_1.objectEntries)(interfaceFilesByLocationId).filter(([locationId]) => {
314
+ return (0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds);
315
+ }));
316
+ const interfaceFilesGlobalPaths = [];
317
+ (0, utils_js_1.objectEntries)(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
318
+ (0, utils_js_1.assert)((0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds));
319
+ interfaceFiles.forEach(({ filePath: { filePathAbsoluteUserRootDir } }) => {
320
+ if (filePathAbsoluteUserRootDir) {
321
+ interfaceFilesGlobalPaths.push(filePathAbsoluteUserRootDir);
322
+ }
323
+ });
324
+ });
325
+ const globalPaths = Array.from(new Set(interfaceFilesGlobalPaths.map((p) => path_1.default.posix.dirname(p))));
326
+ (0, utils_js_1.assertUsage)(false, [
327
+ `${interfaceFile.filePath.filePathToShowToUser} defines the config ${picocolors_1.default.cyan(configName)} which is global:`,
328
+ globalPaths.length
329
+ ? `define ${picocolors_1.default.cyan(configName)} in ${(0, utils_js_1.joinEnglish)(globalPaths, 'or')} instead`
330
+ : `create a global config (e.g. /pages/+config.js) and define ${picocolors_1.default.cyan(configName)} there instead`
331
+ ].join(' '));
332
+ }
333
+ }
334
+ });
335
+ });
336
+ }
293
337
  function deriveConfigEnvFromFileName(env, fileName) {
294
338
  env = { ...env };
295
339
  if (fileName.includes('.server.')) {
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.181-commit-2f53249';
5
+ exports.PROJECT_VERSION = '0.4.181-commit-3fe2549';
@@ -31,6 +31,14 @@ type ConfigDefinition = {
31
31
  * https://vike.dev/meta
32
32
  */
33
33
  effect?: ConfigEffect;
34
+ /**
35
+ * Whether the configuration always applies to all pages (no config inheritance).
36
+ *
37
+ * @default false
38
+ *
39
+ * https://vike.dev/extends#inheritance
40
+ */
41
+ global?: boolean;
34
42
  };
35
43
  /**
36
44
  * Function called when the config value is defined.
@@ -273,6 +273,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
273
273
  const { routeFilesystem, isErrorPage } = determineRouteFilesystem(locationId, configValueSources);
274
274
  applyEffectsAll(configValueSources, configDefinitions);
275
275
  const configValuesComputed = getComputed(configValueSources, configDefinitions);
276
+ assertUsageGlobalConfigs(interfaceFilesRelevantList, configDefinitions, interfaceFilesByLocationId);
276
277
  const pageConfig = {
277
278
  pageId: locationId,
278
279
  isErrorPage,
@@ -286,6 +287,49 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, crawlWithGit) {
286
287
  assertPageConfigs(pageConfigs);
287
288
  return { pageConfigs, pageConfigGlobal, globalVikeConfig };
288
289
  }
290
+ // TODO/soon: refactor
291
+ // - Dedupe: most of the assertUsageGlobalConfigs() code below is a copy-paste of the assertUsage() logic inside getGlobalConfigs()
292
+ // Global configs should be defined at global locations
293
+ function assertUsageGlobalConfigs(interfaceFilesRelevantList, configDefinitions, interfaceFilesByLocationId) {
294
+ interfaceFilesRelevantList.forEach(async (interfaceFile) => {
295
+ const configNames = [];
296
+ if (interfaceFile.isValueFile) {
297
+ configNames.push(interfaceFile.configName);
298
+ }
299
+ else {
300
+ configNames.push(...Object.keys(interfaceFile.fileExportsByConfigName));
301
+ }
302
+ configNames.forEach((configName) => {
303
+ if (isGlobalConfig(configName))
304
+ return;
305
+ const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
306
+ if (configDef.global) {
307
+ const locationIds = objectKeys(interfaceFilesByLocationId);
308
+ if (!isGlobalLocation(interfaceFile.locationId, locationIds)) {
309
+ const interfaceFilesGlobal = objectFromEntries(objectEntries(interfaceFilesByLocationId).filter(([locationId]) => {
310
+ return isGlobalLocation(locationId, locationIds);
311
+ }));
312
+ const interfaceFilesGlobalPaths = [];
313
+ objectEntries(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
314
+ assert(isGlobalLocation(locationId, locationIds));
315
+ interfaceFiles.forEach(({ filePath: { filePathAbsoluteUserRootDir } }) => {
316
+ if (filePathAbsoluteUserRootDir) {
317
+ interfaceFilesGlobalPaths.push(filePathAbsoluteUserRootDir);
318
+ }
319
+ });
320
+ });
321
+ const globalPaths = Array.from(new Set(interfaceFilesGlobalPaths.map((p) => path.posix.dirname(p))));
322
+ assertUsage(false, [
323
+ `${interfaceFile.filePath.filePathToShowToUser} defines the config ${pc.cyan(configName)} which is global:`,
324
+ globalPaths.length
325
+ ? `define ${pc.cyan(configName)} in ${joinEnglish(globalPaths, 'or')} instead`
326
+ : `create a global config (e.g. /pages/+config.js) and define ${pc.cyan(configName)} there instead`
327
+ ].join(' '));
328
+ }
329
+ }
330
+ });
331
+ });
332
+ }
289
333
  function deriveConfigEnvFromFileName(env, fileName) {
290
334
  env = { ...env };
291
335
  if (fileName.includes('.server.')) {
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.181-commit-2f53249";
1
+ export declare const PROJECT_VERSION: "0.4.181-commit-3fe2549";
@@ -1,2 +1,2 @@
1
1
  // Automatically updated by @brillout/release-me
2
- export const PROJECT_VERSION = '0.4.181-commit-2f53249';
2
+ export const PROJECT_VERSION = '0.4.181-commit-3fe2549';
@@ -1,4 +1,4 @@
1
1
  export declare const projectInfo: {
2
2
  projectName: "Vike";
3
- projectVersion: "0.4.181-commit-2f53249";
3
+ projectVersion: "0.4.181-commit-3fe2549";
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.181-commit-2f53249",
3
+ "version": "0.4.181-commit-3fe2549",
4
4
  "scripts": {
5
5
  "dev": "tsc --watch",
6
6
  "build": "rimraf dist/ && pnpm run build:esm && pnpm run build:cjs",