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.
- package/dist/cjs/node/plugin/plugins/buildConfig.js +2 -2
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +152 -152
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +13 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +2 -4
- package/dist/cjs/node/plugin/plugins/previewConfig.js +6 -2
- package/dist/cjs/node/prerender/runPrerender.js +8 -8
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +19 -6
- package/dist/cjs/node/runtime/renderPage/log404/index.js +27 -17
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
- package/dist/cjs/node/shared/getClientEntryFilePath.js +2 -2
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +4 -6
- package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
- package/dist/cjs/shared/hooks/getHook.js +1 -1
- package/dist/cjs/shared/page-configs/getExportPath.js +3 -3
- package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +43 -0
- package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +44 -0
- package/dist/cjs/shared/page-configs/helpers.js +33 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +6 -8
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +9 -10
- package/dist/cjs/shared/route/abort.js +1 -1
- package/dist/cjs/shared/route/loadPageRoutes.js +11 -10
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/truncateString.js +12 -7
- package/dist/esm/client/client-routing-runtime/getPageContext.js +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig.js +1 -1
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +5 -5
- package/dist/esm/node/plugin/plugins/importBuild/index.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +152 -152
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +14 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +2 -4
- package/dist/esm/node/plugin/plugins/previewConfig.js +6 -2
- package/dist/esm/node/prerender/runPrerender.js +2 -2
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +20 -7
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.js +27 -16
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -1
- package/dist/esm/node/shared/getClientEntryFilePath.js +1 -1
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +2 -4
- package/dist/esm/shared/getPageFiles/getExports.js +2 -2
- package/dist/esm/shared/hooks/getHook.js +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +53 -31
- package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
- package/dist/esm/shared/page-configs/getExportPath.js +3 -3
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +7 -0
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +37 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.d.ts +14 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.js +38 -0
- package/dist/esm/shared/page-configs/helpers.d.ts +13 -0
- package/dist/esm/shared/page-configs/helpers.js +27 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +2 -2
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +4 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +6 -8
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +9 -10
- package/dist/esm/shared/route/abort.js +1 -1
- package/dist/esm/shared/route/loadPageRoutes.js +8 -7
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/truncateString.d.ts +2 -1
- package/dist/esm/utils/truncateString.js +10 -7
- package/package.json +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -16
- package/dist/cjs/shared/page-configs/utils.js +0 -103
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +0 -24
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -13
- package/dist/esm/shared/page-configs/utils.d.ts +0 -35
- package/dist/esm/shared/page-configs/utils.js +0 -97
|
@@ -13,9 +13,8 @@ import { isConfigInvalid, isConfigInvalid_set } from '../../../../runtime/render
|
|
|
13
13
|
import { getViteDevServer } from '../../../../runtime/globalContext.js';
|
|
14
14
|
import { logConfigError, logConfigErrorRecover } from '../../../shared/loggerNotProd.js';
|
|
15
15
|
import { removeSuperfluousViteLog_enable, removeSuperfluousViteLog_disable } from '../../../shared/loggerVite/removeSuperfluousViteLog.js';
|
|
16
|
-
import { getFilePathToShowToUser } from './getFilePathToShowToUser.js';
|
|
17
16
|
import pc from '@brillout/picocolors';
|
|
18
|
-
import { getConfigDefinedAtString } from '../../../../../shared/page-configs/
|
|
17
|
+
import { getConfigDefinedAtString } from '../../../../../shared/page-configs/helpers.js';
|
|
19
18
|
import { assertExportsOfConfigFile, assertExportsOfValueFile } from '../../../../../shared/page-configs/assertExports.js';
|
|
20
19
|
import { getConfigValueSerialized } from './getVirtualFilePageConfigs.js';
|
|
21
20
|
assertIsNotProductionRuntime();
|
|
@@ -72,7 +71,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
72
71
|
const configFiles = [];
|
|
73
72
|
const valueFiles = [];
|
|
74
73
|
plusFiles.forEach((f) => {
|
|
75
|
-
if (getConfigName(f.
|
|
74
|
+
if (getConfigName(f.filePathAbsoluteFilesystem) === 'config') {
|
|
76
75
|
configFiles.push(f);
|
|
77
76
|
}
|
|
78
77
|
else {
|
|
@@ -81,15 +80,10 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
81
80
|
});
|
|
82
81
|
let interfaceFilesByLocationId = {};
|
|
83
82
|
// Config files
|
|
84
|
-
await Promise.all(configFiles.map(async (
|
|
85
|
-
const
|
|
86
|
-
filePathAbsoluteFilesystem: filePathAbsoluteFilesystem,
|
|
87
|
-
filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
|
|
88
|
-
importPathAbsolute: null
|
|
89
|
-
};
|
|
90
|
-
const { configFile, extendsConfigs } = await loadConfigFile(configFilePath, userRootDir, []);
|
|
83
|
+
await Promise.all(configFiles.map(async (filePath) => {
|
|
84
|
+
const { configFile, extendsConfigs } = await loadConfigFile(filePath, userRootDir, []);
|
|
91
85
|
const interfaceFile = getInterfaceFileFromConfigFile(configFile, false);
|
|
92
|
-
const locationId = getLocationId(
|
|
86
|
+
const locationId = getLocationId(filePath.filePathAbsoluteVite);
|
|
93
87
|
interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
|
|
94
88
|
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
95
89
|
extendsConfigs.forEach((extendsConfig) => {
|
|
@@ -98,15 +92,11 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
98
92
|
});
|
|
99
93
|
}));
|
|
100
94
|
// Value files
|
|
101
|
-
await Promise.all(valueFiles.map(async (
|
|
102
|
-
const configName = getConfigName(
|
|
95
|
+
await Promise.all(valueFiles.map(async (filePath) => {
|
|
96
|
+
const configName = getConfigName(filePath.filePathAbsoluteVite);
|
|
103
97
|
assert(configName);
|
|
104
98
|
const interfaceFile = {
|
|
105
|
-
filePath
|
|
106
|
-
filePathRelativeToUserRootDir,
|
|
107
|
-
filePathAbsoluteFilesystem,
|
|
108
|
-
importPathAbsolute: null
|
|
109
|
-
},
|
|
99
|
+
filePath,
|
|
110
100
|
configMap: {
|
|
111
101
|
[configName]: {}
|
|
112
102
|
},
|
|
@@ -124,16 +114,16 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
124
114
|
}
|
|
125
115
|
}
|
|
126
116
|
{
|
|
127
|
-
const locationId = getLocationId(
|
|
117
|
+
const locationId = getLocationId(filePath.filePathAbsoluteVite);
|
|
128
118
|
interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
|
|
129
119
|
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
130
120
|
}
|
|
131
121
|
}));
|
|
132
122
|
return interfaceFilesByLocationId;
|
|
133
123
|
}
|
|
134
|
-
function getConfigDefinition(configDefinitionsRelevant, configName,
|
|
124
|
+
function getConfigDefinition(configDefinitionsRelevant, configName, filePathToShowToUser) {
|
|
135
125
|
const configDef = configDefinitionsRelevant[configName];
|
|
136
|
-
assertConfigExists(configName, Object.keys(configDefinitionsRelevant),
|
|
126
|
+
assertConfigExists(configName, Object.keys(configDefinitionsRelevant), filePathToShowToUser);
|
|
137
127
|
assert(configDef);
|
|
138
128
|
return configDef;
|
|
139
129
|
}
|
|
@@ -142,7 +132,7 @@ function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
|
142
132
|
}
|
|
143
133
|
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
144
134
|
const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath, true, userRootDir);
|
|
145
|
-
const filePathToShowToUser =
|
|
135
|
+
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
146
136
|
assertExportsOfValueFile(fileExports, filePathToShowToUser, configName);
|
|
147
137
|
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
148
138
|
const configName_ = exportName === 'default' ? configName : exportName;
|
|
@@ -159,7 +149,7 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
159
149
|
isConfigExtend,
|
|
160
150
|
extendsFilePaths
|
|
161
151
|
};
|
|
162
|
-
const filePathToShowToUser =
|
|
152
|
+
const { filePathToShowToUser } = filePath;
|
|
163
153
|
assertExportsOfConfigFile(fileExports, filePathToShowToUser);
|
|
164
154
|
Object.entries(fileExports.default).forEach(([configName, configValue]) => {
|
|
165
155
|
interfaceFile.configMap[configName] = { configValue };
|
|
@@ -222,7 +212,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
222
212
|
const { configName } = interfaceFile;
|
|
223
213
|
if (isGlobalConfig(configName))
|
|
224
214
|
return;
|
|
225
|
-
const configDef = getConfigDefinition(configDefinitionsRelevant, configName,
|
|
215
|
+
const configDef = getConfigDefinition(configDefinitionsRelevant, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
226
216
|
if (configDef.env !== 'config-only')
|
|
227
217
|
return;
|
|
228
218
|
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
@@ -261,7 +251,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
261
251
|
const configDefinitionsRelevant = getConfigDefinitions(interfaceFilesRelevant);
|
|
262
252
|
interfaceFiles.forEach((interfaceFile) => {
|
|
263
253
|
Object.keys(interfaceFile.configMap).forEach((configName) => {
|
|
264
|
-
assertConfigExists(configName, Object.keys(configDefinitionsRelevant),
|
|
254
|
+
assertConfigExists(configName, Object.keys(configDefinitionsRelevant), interfaceFile.filePath.filePathToShowToUser);
|
|
265
255
|
});
|
|
266
256
|
});
|
|
267
257
|
});
|
|
@@ -312,7 +302,7 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
|
312
302
|
Object.keys(interfaceFile.configMap).forEach((configName) => {
|
|
313
303
|
if (!isGlobalLocation(locationId, locationIds) && isGlobalConfig(configName)) {
|
|
314
304
|
assertUsage(false, [
|
|
315
|
-
`${
|
|
305
|
+
`${interfaceFile.filePath.filePathToShowToUser} defines the config ${pc.cyan(configName)} which is global:`,
|
|
316
306
|
globalPaths.length
|
|
317
307
|
? `define ${pc.cyan(configName)} in ${joinEnglish(globalPaths, 'or')} instead`
|
|
318
308
|
: `create a global config (e.g. /pages/+config.js) and define ${pc.cyan(configName)} there instead`
|
|
@@ -339,9 +329,8 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
|
339
329
|
assert('value' in configValueSource);
|
|
340
330
|
if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
|
|
341
331
|
return;
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
assertWarning(false, `Being able to define config ${pc.cyan(configName)} in ${sourceFilePath} is experimental and will likely be removed. Define the config ${pc.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
|
|
332
|
+
const { filePathToShowToUser } = configValueSource.definedAt;
|
|
333
|
+
assertWarning(false, `Being able to define config ${pc.cyan(configName)} in ${filePathToShowToUser} is experimental and will likely be removed. Define the config ${pc.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
|
|
345
334
|
globalVikeConfig[configName] = configValueSource.value;
|
|
346
335
|
}
|
|
347
336
|
});
|
|
@@ -422,9 +411,14 @@ function makeOrderDeterministic(interfaceFile1, interfaceFile2) {
|
|
|
422
411
|
}
|
|
423
412
|
function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden, configName, configDef, userRootDir) {
|
|
424
413
|
interfaceFilesOverriden.forEach((interfaceFileLoser) => {
|
|
414
|
+
const configValueSourceLoser_ = getConfigValueSource(configName, interfaceFileLoser, configDef, userRootDir);
|
|
425
415
|
const configValueSourceWinner = getConfigValueSource(configName, interfaceFileWinner, configDef, userRootDir);
|
|
426
|
-
|
|
427
|
-
|
|
416
|
+
// prettier-ignore
|
|
417
|
+
const configLoser_DefinedAt = getConfigDefinedAtString('Config', configName, configValueSourceLoser_);
|
|
418
|
+
// prettier-ignore
|
|
419
|
+
const configWinnerDefinedAt = getConfigDefinedAtString('config', configName, configValueSourceWinner);
|
|
420
|
+
const errMsg = `${configLoser_DefinedAt} is overriden by another ${configWinnerDefinedAt}, remove one of the two`;
|
|
421
|
+
assertWarning(false, errMsg, { onlyOnce: false });
|
|
428
422
|
});
|
|
429
423
|
}
|
|
430
424
|
function isInterfaceFileUserLand(interfaceFile) {
|
|
@@ -436,25 +430,25 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
436
430
|
const configEnv = configDef.env;
|
|
437
431
|
const definedAtConfigFile = {
|
|
438
432
|
...interfaceFile.filePath,
|
|
439
|
-
|
|
433
|
+
fileExportPathToShowToUser: ['default', configName]
|
|
440
434
|
};
|
|
441
435
|
if (configDef._valueIsFilePath) {
|
|
442
|
-
let
|
|
436
|
+
let definedAt;
|
|
443
437
|
let valueFilePath;
|
|
444
438
|
if (interfaceFile.isConfigFile) {
|
|
445
439
|
const { configValue } = conf;
|
|
446
440
|
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
447
|
-
const configDefinedAt =
|
|
441
|
+
const configDefinedAt = getConfigDefinedAtString('Config', configName, { definedAt: definedAtConfigFile });
|
|
448
442
|
assertUsage(import_, `${configDefinedAt} should be an import`);
|
|
449
|
-
valueFilePath = import_.
|
|
450
|
-
|
|
443
|
+
valueFilePath = import_.filePathAbsoluteVite;
|
|
444
|
+
definedAt = import_;
|
|
451
445
|
}
|
|
452
446
|
else {
|
|
453
447
|
assert(interfaceFile.isValueFile);
|
|
454
|
-
valueFilePath = interfaceFile.filePath.
|
|
455
|
-
|
|
448
|
+
valueFilePath = interfaceFile.filePath.filePathAbsoluteVite;
|
|
449
|
+
definedAt = {
|
|
456
450
|
...interfaceFile.filePath,
|
|
457
|
-
|
|
451
|
+
fileExportPathToShowToUser: []
|
|
458
452
|
};
|
|
459
453
|
}
|
|
460
454
|
const configValueSource = {
|
|
@@ -462,7 +456,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
462
456
|
valueIsFilePath: true,
|
|
463
457
|
configEnv,
|
|
464
458
|
valueIsImportedAtRuntime: true,
|
|
465
|
-
|
|
459
|
+
definedAt
|
|
466
460
|
};
|
|
467
461
|
return configValueSource;
|
|
468
462
|
}
|
|
@@ -474,7 +468,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
474
468
|
const configValueSource = {
|
|
475
469
|
configEnv,
|
|
476
470
|
valueIsImportedAtRuntime: true,
|
|
477
|
-
|
|
471
|
+
definedAt: import_
|
|
478
472
|
};
|
|
479
473
|
return configValueSource;
|
|
480
474
|
}
|
|
@@ -483,7 +477,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
483
477
|
value: configValue,
|
|
484
478
|
configEnv,
|
|
485
479
|
valueIsImportedAtRuntime: false,
|
|
486
|
-
|
|
480
|
+
definedAt: definedAtConfigFile
|
|
487
481
|
};
|
|
488
482
|
return configValueSource;
|
|
489
483
|
}
|
|
@@ -493,9 +487,9 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
493
487
|
const configValueSource = {
|
|
494
488
|
configEnv,
|
|
495
489
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
496
|
-
|
|
490
|
+
definedAt: {
|
|
497
491
|
...interfaceFile.filePath,
|
|
498
|
-
|
|
492
|
+
fileExportPathToShowToUser: configName === interfaceFile.configName
|
|
499
493
|
? []
|
|
500
494
|
: // Side-effect config (e.g. `export { frontmatter }` of .md files)
|
|
501
495
|
[configName]
|
|
@@ -548,7 +542,7 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
|
|
|
548
542
|
const { importPath, exportName } = importData;
|
|
549
543
|
const filePathAbsoluteFilesystem = resolveImportPath(importData, importerFilePath);
|
|
550
544
|
assertFileEnv(filePathAbsoluteFilesystem ?? importPath, configEnv, configName);
|
|
551
|
-
const
|
|
545
|
+
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
552
546
|
if (importPath.startsWith('.')) {
|
|
553
547
|
// We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
|
|
554
548
|
// ```
|
|
@@ -556,25 +550,35 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
|
|
|
556
550
|
// ```
|
|
557
551
|
assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
|
|
558
552
|
const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, importerFilePath, userRootDir);
|
|
559
|
-
|
|
560
|
-
exportName,
|
|
561
|
-
fileExportPath,
|
|
553
|
+
const filePath = {
|
|
562
554
|
filePathAbsoluteFilesystem,
|
|
563
555
|
filePathRelativeToUserRootDir,
|
|
556
|
+
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
557
|
+
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
564
558
|
importPathAbsolute: null
|
|
565
559
|
};
|
|
560
|
+
return {
|
|
561
|
+
...filePath,
|
|
562
|
+
fileExportName: exportName,
|
|
563
|
+
fileExportPathToShowToUser
|
|
564
|
+
};
|
|
566
565
|
}
|
|
567
566
|
else {
|
|
568
567
|
// importPath can be:
|
|
569
568
|
// - an npm package import
|
|
570
569
|
// - a path alias
|
|
571
|
-
|
|
572
|
-
exportName,
|
|
573
|
-
fileExportPath,
|
|
570
|
+
const filePath = {
|
|
574
571
|
filePathAbsoluteFilesystem,
|
|
575
572
|
filePathRelativeToUserRootDir: null,
|
|
573
|
+
filePathAbsoluteVite: importPath,
|
|
574
|
+
filePathToShowToUser: importPath,
|
|
576
575
|
importPathAbsolute: importPath
|
|
577
576
|
};
|
|
577
|
+
return {
|
|
578
|
+
...filePath,
|
|
579
|
+
fileExportName: exportName,
|
|
580
|
+
fileExportPathToShowToUser
|
|
581
|
+
};
|
|
578
582
|
}
|
|
579
583
|
}
|
|
580
584
|
function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
|
|
@@ -584,7 +588,7 @@ function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, imp
|
|
|
584
588
|
filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, userRootDir);
|
|
585
589
|
}
|
|
586
590
|
else {
|
|
587
|
-
assertUsage(false, `${
|
|
591
|
+
assertUsage(false, `${configFilePath.filePathToShowToUser} imports from a relative path ${pc.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`);
|
|
588
592
|
// None of the following works. Seems to be a Vite bug?
|
|
589
593
|
// /*
|
|
590
594
|
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
@@ -616,9 +620,17 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
616
620
|
if (!configMeta)
|
|
617
621
|
return;
|
|
618
622
|
const meta = configMeta.configValue;
|
|
619
|
-
assertMetaValue(meta,
|
|
620
|
-
//
|
|
621
|
-
|
|
623
|
+
assertMetaValue(meta, `Config ${pc.cyan('meta')} defined at ${interfaceFile.filePath.filePathToShowToUser}`);
|
|
624
|
+
// Set configDef._userEffectDefinedAt
|
|
625
|
+
Object.entries(meta).forEach(([configName, configDef]) => {
|
|
626
|
+
if (!configDef.effect)
|
|
627
|
+
return;
|
|
628
|
+
assert(interfaceFile.isConfigFile);
|
|
629
|
+
configDef._userEffectDefinedAt = {
|
|
630
|
+
...interfaceFile.filePath,
|
|
631
|
+
fileExportPathToShowToUser: ['default', 'meta', configName, 'effect']
|
|
632
|
+
};
|
|
633
|
+
});
|
|
622
634
|
objectEntries(meta).forEach(([configName, configDefinition]) => {
|
|
623
635
|
// User can override an existing config definition
|
|
624
636
|
configDefinitions[configName] = {
|
|
@@ -631,9 +643,15 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
631
643
|
return configDefinitions;
|
|
632
644
|
}
|
|
633
645
|
function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
634
|
-
|
|
646
|
+
if (!isObject(metaVal)) {
|
|
647
|
+
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
648
|
+
assertUsage(false, `${configMetaDefinedAt} has an invalid type ${pc.cyan(typeof metaVal)}: it should be an object instead.`);
|
|
649
|
+
}
|
|
635
650
|
objectEntries(metaVal).forEach(([configName, def]) => {
|
|
636
|
-
|
|
651
|
+
if (!isObject(def)) {
|
|
652
|
+
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
653
|
+
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}`)} to a value with an invalid type ${pc.cyan(typeof def)}: it should be an object instead.`);
|
|
654
|
+
}
|
|
637
655
|
// env
|
|
638
656
|
{
|
|
639
657
|
const envValues = [
|
|
@@ -642,19 +660,34 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
642
660
|
'server-and-client',
|
|
643
661
|
'config-only'
|
|
644
662
|
];
|
|
645
|
-
const
|
|
646
|
-
`Set the value of ${pc.cyan(
|
|
663
|
+
const fix = [
|
|
664
|
+
`Set the value of ${pc.cyan(`meta.${configName}.env`)} to `,
|
|
647
665
|
joinEnglish(envValues.map((s) => pc.cyan(`'${s}'`)), 'or'),
|
|
648
666
|
'.'
|
|
649
667
|
].join('');
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
668
|
+
if (!('env' in def)) {
|
|
669
|
+
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
670
|
+
assertUsage(false, `${configMetaDefinedAt} doesn't set ${pc.cyan(`meta.${configName}.env`)} but it's required. ${fix}`);
|
|
671
|
+
}
|
|
672
|
+
if (!hasProp(def, 'env', 'string')) {
|
|
673
|
+
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
674
|
+
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}.env`)} to an invalid type ${pc.cyan(typeof def.env)}. ${fix}`);
|
|
675
|
+
}
|
|
676
|
+
if (!envValues.includes(def.env)) {
|
|
677
|
+
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
678
|
+
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}.env`)} to an unknown value ${pc.cyan(`'${def.env}'`)}. ${fix}`);
|
|
679
|
+
}
|
|
653
680
|
}
|
|
654
681
|
// effect
|
|
655
682
|
if ('effect' in def) {
|
|
656
|
-
|
|
657
|
-
|
|
683
|
+
if (!hasProp(def, 'effect', 'function')) {
|
|
684
|
+
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
685
|
+
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}.effect`)} to an invalid type ${pc.cyan(typeof def.effect)}: it should be a function instead`);
|
|
686
|
+
}
|
|
687
|
+
if (def.env !== 'config-only') {
|
|
688
|
+
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
689
|
+
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}.effect`)} but it's only supported if meta.${configName}.env is ${pc.cyan('config-only')} (but it's ${pc.cyan(def.env)} instead)`);
|
|
690
|
+
}
|
|
658
691
|
}
|
|
659
692
|
});
|
|
660
693
|
}
|
|
@@ -665,7 +698,7 @@ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
|
|
|
665
698
|
// The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
|
|
666
699
|
// (We could support effect for non config-only by always loading its value at config time, regardless of the config's `env` value.)
|
|
667
700
|
assertUsage(configDef.env === 'config-only', [
|
|
668
|
-
`Cannot add effect to ${pc.cyan(configName)} because its ${pc.cyan('env')} is ${pc.cyan(configDef.env)}: effects can only be added to configs with an env
|
|
701
|
+
`Cannot add effect to ${pc.cyan(configName)} because its ${pc.cyan('env')} is ${pc.cyan(configDef.env)}: effects can only be added to configs with an ${pc.cyan('env')} value of ${pc.cyan('config-only')}.`
|
|
669
702
|
].join(' '));
|
|
670
703
|
const source = configValueSources[configName]?.[0];
|
|
671
704
|
if (!source)
|
|
@@ -675,19 +708,28 @@ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
|
|
|
675
708
|
// Call effect
|
|
676
709
|
const configModFromEffect = configDef.effect({
|
|
677
710
|
configValue: source.value,
|
|
678
|
-
configDefinedAt:
|
|
711
|
+
configDefinedAt: getConfigDefinedAtString('Config', configName, source)
|
|
679
712
|
});
|
|
680
713
|
if (!configModFromEffect)
|
|
681
714
|
return;
|
|
682
715
|
assert(hasProp(source, 'value')); // We need to assume that the config value is loaded at build-time
|
|
683
|
-
applyEffect(configModFromEffect,
|
|
716
|
+
applyEffect(configModFromEffect, configValueSources, configDef);
|
|
684
717
|
});
|
|
685
718
|
}
|
|
686
|
-
function applyEffect(configModFromEffect,
|
|
719
|
+
function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
687
720
|
const notSupported = `Effects currently only supports modifying the the ${pc.cyan('env')} of a config.`;
|
|
688
721
|
objectEntries(configModFromEffect).forEach(([configName, configValue]) => {
|
|
689
722
|
if (configName === 'meta') {
|
|
690
|
-
|
|
723
|
+
let configDefinedAtString;
|
|
724
|
+
if (configDefEffect._userEffectDefinedAt) {
|
|
725
|
+
configDefinedAtString = getConfigDefinedAtString('Config', configName, {
|
|
726
|
+
definedAt: configDefEffect._userEffectDefinedAt
|
|
727
|
+
});
|
|
728
|
+
}
|
|
729
|
+
else {
|
|
730
|
+
configDefinedAtString = null;
|
|
731
|
+
}
|
|
732
|
+
assertMetaValue(configValue, configDefinedAtString);
|
|
691
733
|
objectEntries(configValue).forEach(([configTargetName, configTargetDef]) => {
|
|
692
734
|
{
|
|
693
735
|
const keys = Object.keys(configTargetDef);
|
|
@@ -705,7 +747,7 @@ function applyEffect(configModFromEffect, configValueEffectSource, configValueSo
|
|
|
705
747
|
else {
|
|
706
748
|
assertUsage(false, notSupported);
|
|
707
749
|
// If we do end implementing being able to set the value of a config:
|
|
708
|
-
// - For setting
|
|
750
|
+
// - For setting definedAt: we could take the definedAt of the effect config while appending '(effect)' to definedAt.fileExportPathToShowToUser
|
|
709
751
|
}
|
|
710
752
|
});
|
|
711
753
|
}
|
|
@@ -757,19 +799,28 @@ async function findPlusFiles(userRootDir, ignoreDirs, isDev, extensions) {
|
|
|
757
799
|
p = toPosixPath(p);
|
|
758
800
|
const filePathRelativeToUserRootDir = path.posix.join('/', p);
|
|
759
801
|
const filePathAbsoluteFilesystem = path.posix.join(userRootDir, p);
|
|
760
|
-
return {
|
|
802
|
+
return {
|
|
803
|
+
filePathRelativeToUserRootDir,
|
|
804
|
+
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
805
|
+
filePathAbsoluteFilesystem,
|
|
806
|
+
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
807
|
+
importPathAbsolute: null
|
|
808
|
+
};
|
|
761
809
|
});
|
|
810
|
+
// TODO/v1-release: remove
|
|
762
811
|
extensions.forEach((extension) => {
|
|
763
812
|
extension.pageConfigsDistFiles?.forEach((pageConfigDistFile) => {
|
|
764
|
-
// TODO/v1-release: remove
|
|
765
813
|
if (!pageConfigDistFile.importPath.includes('+'))
|
|
766
814
|
return;
|
|
767
815
|
assert(pageConfigDistFile.importPath.includes('+'));
|
|
768
816
|
assert(path.posix.basename(pageConfigDistFile.importPath).startsWith('+'));
|
|
769
817
|
const { importPath, filePath } = pageConfigDistFile;
|
|
770
818
|
plusFiles.push({
|
|
771
|
-
filePathRelativeToUserRootDir:
|
|
772
|
-
|
|
819
|
+
filePathRelativeToUserRootDir: null,
|
|
820
|
+
filePathAbsoluteVite: importPath,
|
|
821
|
+
filePathAbsoluteFilesystem: filePath,
|
|
822
|
+
filePathToShowToUser: importPath,
|
|
823
|
+
importPathAbsolute: importPath
|
|
773
824
|
});
|
|
774
825
|
});
|
|
775
826
|
});
|
|
@@ -826,18 +877,18 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
826
877
|
const extendsConfigFiles = [];
|
|
827
878
|
extendsImportData.map((importData) => {
|
|
828
879
|
const { importPath: importPath } = importData;
|
|
829
|
-
// TODO
|
|
830
|
-
// - validate extends configs
|
|
831
880
|
const filePathAbsoluteFilesystem = resolveImportPath(importData, configFilePath);
|
|
832
881
|
assertImportPath(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
833
882
|
assertExtendsImportPath(importPath, filePathAbsoluteFilesystem, configFilePath);
|
|
834
883
|
// - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
|
|
835
884
|
// - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsoluteFilesystem for added clarity
|
|
836
885
|
const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir);
|
|
886
|
+
const filePathAbsoluteVite = filePathRelativeToUserRootDir ?? importPath;
|
|
837
887
|
extendsConfigFiles.push({
|
|
838
888
|
filePathAbsoluteFilesystem,
|
|
839
|
-
|
|
840
|
-
filePathRelativeToUserRootDir
|
|
889
|
+
filePathAbsoluteVite,
|
|
890
|
+
filePathRelativeToUserRootDir,
|
|
891
|
+
filePathToShowToUser: filePathAbsoluteVite,
|
|
841
892
|
importPathAbsolute: importPath
|
|
842
893
|
});
|
|
843
894
|
});
|
|
@@ -873,14 +924,14 @@ function assertExtendsImportPath(importPath, filePath, configFilePath) {
|
|
|
873
924
|
});
|
|
874
925
|
}
|
|
875
926
|
else {
|
|
876
|
-
assertWarning(false, `${
|
|
927
|
+
assertWarning(false, `${configFilePath.filePathToShowToUser} uses ${pc.cyan('extends')} to inherit from ${pc.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 });
|
|
877
928
|
}
|
|
878
929
|
}
|
|
879
930
|
function getExtendsImportData(configFileExports, configFilePath) {
|
|
880
|
-
const filePathToShowToUser =
|
|
931
|
+
const { filePathToShowToUser } = configFilePath;
|
|
881
932
|
assertExportsOfConfigFile(configFileExports, filePathToShowToUser);
|
|
882
933
|
const defaultExports = configFileExports.default;
|
|
883
|
-
const wrongUsage = `${filePathToShowToUser} sets the config 'extends' to an invalid value, see https://vike.dev/extends`;
|
|
934
|
+
const wrongUsage = `${filePathToShowToUser} sets the config ${pc.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
|
|
884
935
|
let extendList;
|
|
885
936
|
if (!('extends' in defaultExports)) {
|
|
886
937
|
return [];
|
|
@@ -901,38 +952,6 @@ function getExtendsImportData(configFileExports, configFilePath) {
|
|
|
901
952
|
});
|
|
902
953
|
return extendsImportData;
|
|
903
954
|
}
|
|
904
|
-
// TODO: re-use this
|
|
905
|
-
function handleUserFileError(err, isDev) {
|
|
906
|
-
// Properly handle error during transpilation so that we can use assertUsage() during transpilation
|
|
907
|
-
if (isDev) {
|
|
908
|
-
throw err;
|
|
909
|
-
}
|
|
910
|
-
else {
|
|
911
|
-
// Avoid ugly error format:
|
|
912
|
-
// ```
|
|
913
|
-
// [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
|
|
914
|
-
// 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
|
|
915
|
-
// at ...
|
|
916
|
-
// at ...
|
|
917
|
-
// at ...
|
|
918
|
-
// at ...
|
|
919
|
-
// at ...
|
|
920
|
-
// at ...
|
|
921
|
-
// code: 'PLUGIN_ERROR',
|
|
922
|
-
// plugin: 'vike:importUserCode',
|
|
923
|
-
// hook: 'load',
|
|
924
|
-
// watchFiles: [
|
|
925
|
-
// '/home/rom/code/vike/vike/dist/esm/node/importBuild.js',
|
|
926
|
-
// '\x00virtual:vike:importUserCode:server'
|
|
927
|
-
// ]
|
|
928
|
-
// }
|
|
929
|
-
// ELIFECYCLE Command failed with exit code 1.
|
|
930
|
-
// ```
|
|
931
|
-
console.log('');
|
|
932
|
-
console.error(err);
|
|
933
|
-
process.exit(1);
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
955
|
function isGlobalConfig(configName) {
|
|
937
956
|
if (configName === 'prerender')
|
|
938
957
|
return false;
|
|
@@ -942,15 +961,15 @@ function isGlobalConfig(configName) {
|
|
|
942
961
|
function getConfigNamesGlobal() {
|
|
943
962
|
return Object.keys(configDefinitionsBuiltInGlobal);
|
|
944
963
|
}
|
|
945
|
-
function assertConfigExists(configName, configNamesRelevant,
|
|
964
|
+
function assertConfigExists(configName, configNamesRelevant, filePathToShowToUser) {
|
|
946
965
|
const configNames = [...configNamesRelevant, ...getConfigNamesGlobal()];
|
|
947
966
|
if (configNames.includes(configName))
|
|
948
967
|
return;
|
|
949
|
-
handleUnknownConfig(configName, configNames,
|
|
968
|
+
handleUnknownConfig(configName, configNames, filePathToShowToUser);
|
|
950
969
|
assert(false);
|
|
951
970
|
}
|
|
952
|
-
function handleUnknownConfig(configName, configNames,
|
|
953
|
-
let errMsg = `${
|
|
971
|
+
function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
972
|
+
let errMsg = `${filePathToShowToUser} defines an unknown config ${pc.cyan(configName)}`;
|
|
954
973
|
let configNameSimilar = null;
|
|
955
974
|
if (configName === 'page') {
|
|
956
975
|
configNameSimilar = 'Page';
|
|
@@ -982,11 +1001,11 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
982
1001
|
if (configFilesystemRoutingRoot) {
|
|
983
1002
|
const routingRoot = getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName);
|
|
984
1003
|
if (routingRoot) {
|
|
985
|
-
const { filesystemRoutingRootEffect
|
|
1004
|
+
const { filesystemRoutingRootEffect /*, filesystemRoutingRootDefinedAt*/ } = routingRoot;
|
|
986
1005
|
const debugInfo = { locationId, routeFilesystem: filesystemRouteString, configFilesystemRoutingRoot };
|
|
987
1006
|
assert(filesystemRouteString.startsWith(filesystemRoutingRootEffect.before), debugInfo);
|
|
988
1007
|
filesystemRouteString = applyFilesystemRoutingRootEffect(filesystemRouteString, filesystemRoutingRootEffect);
|
|
989
|
-
filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${filesystemRoutingRootDefinedAt})
|
|
1008
|
+
// filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${filesystemRoutingRootDefinedAt})`
|
|
990
1009
|
}
|
|
991
1010
|
}
|
|
992
1011
|
assert(filesystemRouteString.startsWith('/'));
|
|
@@ -1001,10 +1020,10 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
|
|
|
1001
1020
|
// Eagerly loaded since it's config-only
|
|
1002
1021
|
assert('value' in configFilesystemRoutingRoot);
|
|
1003
1022
|
const { value } = configFilesystemRoutingRoot;
|
|
1004
|
-
const configDefinedAt =
|
|
1023
|
+
const configDefinedAt = getConfigDefinedAtString('Config', configName, configFilesystemRoutingRoot);
|
|
1005
1024
|
assertUsage(typeof value === 'string', `${configDefinedAt} should be a string`);
|
|
1006
1025
|
assertUsage(value.startsWith('/'), `${configDefinedAt} is ${pc.cyan(value)} but it should start with a leading slash ${pc.cyan('/')}`);
|
|
1007
|
-
const { filePathRelativeToUserRootDir } = configFilesystemRoutingRoot.
|
|
1026
|
+
const { filePathRelativeToUserRootDir } = configFilesystemRoutingRoot.definedAt;
|
|
1008
1027
|
assert(filePathRelativeToUserRootDir);
|
|
1009
1028
|
const before = getFilesystemRouteString(getLocationId(filePathRelativeToUserRootDir));
|
|
1010
1029
|
const after = value;
|
|
@@ -1025,7 +1044,7 @@ function resolveImportPath(importData, importerFilePath) {
|
|
|
1025
1044
|
}
|
|
1026
1045
|
function assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath) {
|
|
1027
1046
|
const { importPath: importPath, importStringWasGenerated, importString } = importData;
|
|
1028
|
-
const filePathToShowToUser =
|
|
1047
|
+
const { filePathToShowToUser } = importerFilePath;
|
|
1029
1048
|
if (!filePathAbsoluteFilesystem) {
|
|
1030
1049
|
const importPathString = pc.cyan(`'${importPath}'`);
|
|
1031
1050
|
const errIntro = importStringWasGenerated
|
|
@@ -1068,7 +1087,6 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
1068
1087
|
configValues[configName] = {
|
|
1069
1088
|
value,
|
|
1070
1089
|
definedAt: {
|
|
1071
|
-
isCumulative: true,
|
|
1072
1090
|
files: sources.map((source) => getDefinedAtFile(source))
|
|
1073
1091
|
}
|
|
1074
1092
|
};
|
|
@@ -1076,12 +1094,21 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
1076
1094
|
});
|
|
1077
1095
|
return configValues;
|
|
1078
1096
|
}
|
|
1097
|
+
function getDefinedAtFile(configValueSource) {
|
|
1098
|
+
return {
|
|
1099
|
+
filePathToShowToUser: configValueSource.definedAt.filePathToShowToUser,
|
|
1100
|
+
fileExportPathToShowToUser: configValueSource.definedAt.fileExportPathToShowToUser
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
function getDefinedAt(configValueSource) {
|
|
1104
|
+
return getDefinedAtFile(configValueSource);
|
|
1105
|
+
}
|
|
1079
1106
|
function mergeCumulative(configName, configValueSources) {
|
|
1080
1107
|
const valuesArr = [];
|
|
1081
1108
|
const valuesSet = [];
|
|
1082
1109
|
let configValueSourcePrevious = null;
|
|
1083
1110
|
configValueSources.forEach((configValueSource) => {
|
|
1084
|
-
const configDefinedAt =
|
|
1111
|
+
const configDefinedAt = getConfigDefinedAtString('Config', configName, configValueSource);
|
|
1085
1112
|
const configNameColored = pc.cyan(configName);
|
|
1086
1113
|
// We could, in principle, also support cumulative values to be defined in +${configName}.js but it ins't completely trivial to implement
|
|
1087
1114
|
assertUsage('value' in configValueSource, `${configDefinedAt} is only allowed to be defined in a +config.h.js file. (Because the values of ${configNameColored} are cumulative.)`);
|
|
@@ -1099,7 +1126,7 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1099
1126
|
if (vals2.length === 0)
|
|
1100
1127
|
return;
|
|
1101
1128
|
assert(configValueSourcePrevious);
|
|
1102
|
-
const configPreviousDefinedAt =
|
|
1129
|
+
const configPreviousDefinedAt = getConfigDefinedAtString('Config', configName, configValueSourcePrevious);
|
|
1103
1130
|
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).`);
|
|
1104
1131
|
};
|
|
1105
1132
|
const { value } = configValueSource;
|
|
@@ -1130,30 +1157,3 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1130
1157
|
}
|
|
1131
1158
|
assert(false);
|
|
1132
1159
|
}
|
|
1133
|
-
// TODO: rename
|
|
1134
|
-
// TODO: refactor
|
|
1135
|
-
function getConfigSourceDefinedAtString(configName, { definedAtInfo }, isEffect = undefined, sentenceBegin = true) {
|
|
1136
|
-
return getConfigDefinedAtString(configName, {
|
|
1137
|
-
definedAt: {
|
|
1138
|
-
isEffect,
|
|
1139
|
-
file: {
|
|
1140
|
-
filePathToShowToUser: getDefinedAtFilePathToShowToUser(definedAtInfo),
|
|
1141
|
-
fileExportPath: definedAtInfo.fileExportPath
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
}, sentenceBegin);
|
|
1145
|
-
}
|
|
1146
|
-
function getDefinedAtFilePathToShowToUser(definedAtInfo) {
|
|
1147
|
-
return definedAtInfo.filePathRelativeToUserRootDir ?? definedAtInfo.importPathAbsolute;
|
|
1148
|
-
}
|
|
1149
|
-
function getDefinedAtFile(source) {
|
|
1150
|
-
return {
|
|
1151
|
-
filePathToShowToUser: getDefinedAtFilePathToShowToUser(source.definedAtInfo),
|
|
1152
|
-
fileExportPath: source.definedAtInfo.fileExportPath
|
|
1153
|
-
};
|
|
1154
|
-
}
|
|
1155
|
-
function getDefinedAt(configValueSource) {
|
|
1156
|
-
return {
|
|
1157
|
-
file: getDefinedAtFile(configValueSource)
|
|
1158
|
-
};
|
|
1159
|
-
}
|