vike 0.4.220-commit-9a798ce → 0.4.220-commit-5c7810f
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/importUserCode/v1-design/assertExtensions.js +8 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +29 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +77 -76
- package/dist/cjs/shared/getPageContextUrlComputed.js +6 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/isDev.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/assertExtensions.js +9 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.d.ts +5 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +30 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +22 -7
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +79 -78
- package/dist/esm/shared/getPageContextUrlComputed.js +6 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/isDev.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -65,18 +65,22 @@ function assertExtensionsRequire(pageConfig) {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
function getConfigRequireValue(interfaceFile) {
|
|
68
|
-
const
|
|
69
|
-
if (!
|
|
68
|
+
const confVal = (0, getVikeConfig_js_1.getConfVal)(interfaceFile, 'require');
|
|
69
|
+
if (!confVal)
|
|
70
70
|
return null;
|
|
71
|
+
(0, utils_js_1.assert)(confVal.configValueLoaded);
|
|
72
|
+
const require = confVal.configValue;
|
|
71
73
|
const { filePathToShowToUserResolved } = interfaceFile.filePath;
|
|
72
74
|
(0, utils_js_1.assert)(filePathToShowToUserResolved);
|
|
73
75
|
(0, utils_js_1.assertUsage)((0, isObjectOfStrings_js_1.isObjectOfStrings)(require), `The setting ${picocolors_1.default.bold('require')} defined at ${filePathToShowToUserResolved} should be an object with string values (${picocolors_1.default.bold('Record<string, string>')}).`);
|
|
74
76
|
return require;
|
|
75
77
|
}
|
|
76
78
|
function getNameValue(interfaceFile) {
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
79
|
+
const confVal = (0, getVikeConfig_js_1.getConfVal)(interfaceFile, 'name');
|
|
80
|
+
if (!confVal)
|
|
79
81
|
return null;
|
|
82
|
+
(0, utils_js_1.assert)(confVal.configValueLoaded);
|
|
83
|
+
const name = confVal.configValue;
|
|
80
84
|
const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
|
|
81
85
|
(0, utils_js_1.assertUsage)(typeof name === 'string', `The setting ${picocolors_1.default.bold('name')} defined at ${filePathToShowToUser} should be a string.`);
|
|
82
86
|
return name;
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Files
|
|
2
|
+
// Files loaded at config time:
|
|
3
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
5
|
};
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.loadImportedFile = loadImportedFile;
|
|
8
8
|
exports.loadValueFile = loadValueFile;
|
|
9
|
+
exports.loadValueFiles = loadValueFiles;
|
|
9
10
|
exports.loadConfigFile = loadConfigFile;
|
|
10
11
|
const utils_js_1 = require("../../../../utils.js");
|
|
11
12
|
const transpileAndExecuteFile_js_1 = require("./transpileAndExecuteFile.js");
|
|
13
|
+
const getVikeConfig_js_1 = require("../getVikeConfig.js");
|
|
12
14
|
const assertPlusFileExport_js_1 = require("../../../../../../shared/page-configs/assertPlusFileExport.js");
|
|
13
15
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
14
16
|
const transformPointerImports_js_1 = require("./transformPointerImports.js");
|
|
@@ -26,15 +28,39 @@ async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
|
26
28
|
return fileExport;
|
|
27
29
|
}
|
|
28
30
|
// Load +{configName}.js
|
|
29
|
-
async function loadValueFile(interfaceValueFile,
|
|
31
|
+
async function loadValueFile(interfaceValueFile, configDefinitions, userRootDir) {
|
|
32
|
+
const { configName } = interfaceValueFile;
|
|
33
|
+
const configDef = (0, getVikeConfig_js_1.getConfigDefinitionOptional)(configDefinitions, configName);
|
|
34
|
+
if (!configDef || !(0, getVikeConfig_js_1.shouldBeLoadableAtBuildTime)(configDef)) {
|
|
35
|
+
// Only load value files with `env.config===true`
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (interfaceValueFile.isValueLoaded) {
|
|
39
|
+
await interfaceValueFile.isValueLoaded;
|
|
40
|
+
if (
|
|
41
|
+
// Help TS
|
|
42
|
+
true)
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const { promise, resolve } = (0, utils_js_1.genPromise)();
|
|
46
|
+
interfaceValueFile.isValueLoaded = promise;
|
|
47
|
+
(0, utils_js_1.assert)(interfaceValueFile.isValueLoaded);
|
|
48
|
+
interfaceValueFile.fileExportsByConfigName = {};
|
|
30
49
|
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath, userRootDir, false);
|
|
50
|
+
resolve();
|
|
31
51
|
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
32
52
|
(0, assertPlusFileExport_js_1.assertPlusFileExport)(fileExports, filePathToShowToUser, configName);
|
|
33
53
|
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
34
54
|
const configName_ = exportName === 'default' ? configName : exportName;
|
|
35
|
-
interfaceValueFile.fileExportsByConfigName[configName_] =
|
|
55
|
+
interfaceValueFile.fileExportsByConfigName[configName_] = configValue;
|
|
36
56
|
});
|
|
37
57
|
}
|
|
58
|
+
async function loadValueFiles(interfaceFiles, configDefinitions, userRootDir) {
|
|
59
|
+
await Promise.all(Object.values(interfaceFiles)
|
|
60
|
+
.flat(1)
|
|
61
|
+
.filter((interfaceFile) => interfaceFile.isValueFile)
|
|
62
|
+
.map(async (interfaceFile) => await loadValueFile(interfaceFile, configDefinitions, userRootDir)));
|
|
63
|
+
}
|
|
38
64
|
// Load +config.js, including all its extends pointer imports
|
|
39
65
|
async function loadConfigFile(configFilePath, userRootDir, visited, isExtensionConfig) {
|
|
40
66
|
const { filePathAbsoluteFilesystem } = configFilePath;
|
|
@@ -9,7 +9,9 @@ exports.getVikeConfig2 = getVikeConfig2;
|
|
|
9
9
|
exports.reloadVikeConfig = reloadVikeConfig;
|
|
10
10
|
exports.isVikeConfigFile = isVikeConfigFile;
|
|
11
11
|
exports.isV1Design = isV1Design;
|
|
12
|
-
exports.
|
|
12
|
+
exports.getConfVal = getConfVal;
|
|
13
|
+
exports.getConfigDefinitionOptional = getConfigDefinitionOptional;
|
|
14
|
+
exports.shouldBeLoadableAtBuildTime = shouldBeLoadableAtBuildTime;
|
|
13
15
|
const utils_js_1 = require("../../../utils.js");
|
|
14
16
|
const path_1 = __importDefault(require("path"));
|
|
15
17
|
const configDefinitionsBuiltIn_js_1 = require("./getVikeConfig/configDefinitionsBuiltIn.js");
|
|
@@ -158,26 +160,17 @@ async function loadInterfaceFiles(userRootDir) {
|
|
|
158
160
|
const interfaceFile = {
|
|
159
161
|
locationId,
|
|
160
162
|
filePath,
|
|
161
|
-
fileExportsByConfigName: {
|
|
162
|
-
[configName]: {}
|
|
163
|
-
},
|
|
164
163
|
isConfigFile: false,
|
|
165
164
|
isValueFile: true,
|
|
165
|
+
isValueLoaded: false,
|
|
166
166
|
configName
|
|
167
167
|
};
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
await (0, loadFileAtConfigTime_js_1.loadValueFile)(interfaceFile, configName, userRootDir);
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
{
|
|
178
|
-
interfaceFilesAll[locationId] = interfaceFilesAll[locationId] ?? [];
|
|
179
|
-
interfaceFilesAll[locationId].push(interfaceFile);
|
|
180
|
-
}
|
|
168
|
+
interfaceFilesAll[locationId] = interfaceFilesAll[locationId] ?? [];
|
|
169
|
+
interfaceFilesAll[locationId].push(interfaceFile);
|
|
170
|
+
// We don't have access to the custom config definitions defined by the user yet.
|
|
171
|
+
// - If `configDef` is `undefined` => we load the file +{configName}.js later.
|
|
172
|
+
// - We already need to load +meta.js here (to get the custom config definitions defined by the user)
|
|
173
|
+
await (0, loadFileAtConfigTime_js_1.loadValueFile)(interfaceFile, configDefinitionsBuiltIn, userRootDir);
|
|
181
174
|
})
|
|
182
175
|
]);
|
|
183
176
|
assertAllConfigsAreKnown(interfaceFilesAll);
|
|
@@ -191,12 +184,13 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend, locationId)
|
|
|
191
184
|
fileExportsByConfigName: {},
|
|
192
185
|
isConfigFile: true,
|
|
193
186
|
isValueFile: false,
|
|
187
|
+
isValueLoaded: true,
|
|
194
188
|
isConfigExtend,
|
|
195
189
|
extendsFilePaths
|
|
196
190
|
};
|
|
197
191
|
const fileExport = (0, getConfigFileExport_js_1.getConfigFileExport)(fileExports, filePath.filePathToShowToUser);
|
|
198
192
|
Object.entries(fileExport).forEach(([configName, configValue]) => {
|
|
199
|
-
interfaceFile.fileExportsByConfigName[configName] =
|
|
193
|
+
interfaceFile.fileExportsByConfigName[configName] = configValue;
|
|
200
194
|
});
|
|
201
195
|
return interfaceFile;
|
|
202
196
|
}
|
|
@@ -206,8 +200,11 @@ function assertAllConfigsAreKnown(interfaceFilesAll) {
|
|
|
206
200
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesAll, locationId);
|
|
207
201
|
const configDefinitions = getConfigDefinitions(interfaceFilesRelevant);
|
|
208
202
|
interfaceFiles.forEach((interfaceFile) => {
|
|
209
|
-
Object.keys(
|
|
210
|
-
|
|
203
|
+
const configNamesKnown = Object.keys(configDefinitions);
|
|
204
|
+
const { filePathToShowToUser } = interfaceFile.filePath;
|
|
205
|
+
const configNames = getDefiningConfigNames(interfaceFile);
|
|
206
|
+
configNames.forEach((configName) => {
|
|
207
|
+
assertConfigExists(configName, configNamesKnown, filePathToShowToUser);
|
|
211
208
|
});
|
|
212
209
|
});
|
|
213
210
|
});
|
|
@@ -283,7 +280,7 @@ async function getGlobalConfigs(interfaceFilesAll, userRootDir, importedFilesLoa
|
|
|
283
280
|
objectEntries(interfaceFilesAll).forEach(([locationId, interfaceFiles]) => {
|
|
284
281
|
interfaceFiles.forEach((interfaceFile) => {
|
|
285
282
|
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
286
|
-
if (!isGlobalLocation(locationId, locationIds) &&
|
|
283
|
+
if (!isGlobalLocation(locationId, locationIds) && isGlobalConfigOld(configName)) {
|
|
287
284
|
assertUsage(
|
|
288
285
|
false,
|
|
289
286
|
[
|
|
@@ -346,32 +343,15 @@ async function getPageConfigs(interfaceFilesAll, userRootDir, importedFilesLoade
|
|
|
346
343
|
pageConfigGlobal.configValueSources[configName] = sources;
|
|
347
344
|
}));
|
|
348
345
|
const pageConfigs = [];
|
|
349
|
-
await Promise.all((
|
|
350
|
-
.filter(([_locationId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
351
|
-
.map(async ([locationId]) => {
|
|
346
|
+
await Promise.all(getPageLocationIds(interfaceFilesAll).map(async (locationId) => {
|
|
352
347
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesAll, locationId);
|
|
353
|
-
const interfaceFilesRelevantList = Object.values(interfaceFilesRelevant).flat(1);
|
|
354
348
|
const configDefinitions = getConfigDefinitions(interfaceFilesRelevant);
|
|
355
|
-
// Load value files
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
return;
|
|
359
|
-
const { configName } = interfaceFile;
|
|
360
|
-
if (isGlobalConfig(configName))
|
|
361
|
-
return;
|
|
362
|
-
const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
363
|
-
if (!shouldBeLoadableAtBuildTime(configDef))
|
|
364
|
-
return;
|
|
365
|
-
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
366
|
-
if (isAlreadyLoaded)
|
|
367
|
-
return;
|
|
368
|
-
// Value files of built-in configs should have already been loaded at loadInterfaceFiles()
|
|
369
|
-
(0, utils_js_1.assert)(!(configName in configDefinitionsBuiltIn));
|
|
370
|
-
await (0, loadFileAtConfigTime_js_1.loadValueFile)(interfaceFile, configName, userRootDir);
|
|
371
|
-
}));
|
|
349
|
+
// Load value files (with `env.config===true`) of *custom* configs.
|
|
350
|
+
// - The value files of *built-in* configs are already loaded at `loadInterfaceFiles()`.
|
|
351
|
+
await (0, loadFileAtConfigTime_js_1.loadValueFiles)(interfaceFilesRelevant, configDefinitions, userRootDir);
|
|
372
352
|
let configValueSources = {};
|
|
373
353
|
await Promise.all((0, utils_js_1.objectEntries)(configDefinitions)
|
|
374
|
-
.filter(([configName]) => !
|
|
354
|
+
.filter(([configName]) => !isGlobalConfigOld(configName))
|
|
375
355
|
.map(async ([configName, configDef]) => {
|
|
376
356
|
const sources = await resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir, importedFilesLoaded);
|
|
377
357
|
if (sources.length === 0)
|
|
@@ -396,6 +376,15 @@ async function getPageConfigs(interfaceFilesAll, userRootDir, importedFilesLoade
|
|
|
396
376
|
assertPageConfigs(pageConfigs, interfaceFilesAll);
|
|
397
377
|
return { pageConfigs, pageConfigGlobal };
|
|
398
378
|
}
|
|
379
|
+
function getPageLocationIds(interfaceFilesAll) {
|
|
380
|
+
const locationIds = new Set();
|
|
381
|
+
(0, utils_js_1.objectEntries)(interfaceFilesAll).forEach(([locationId, interfaceFiles]) => {
|
|
382
|
+
if (isDefiningPage(interfaceFiles)) {
|
|
383
|
+
locationIds.add(locationId);
|
|
384
|
+
}
|
|
385
|
+
});
|
|
386
|
+
return Array.from(locationIds);
|
|
387
|
+
}
|
|
399
388
|
function assertPageConfigs(pageConfigs, interfaceFilesAll) {
|
|
400
389
|
pageConfigs.forEach((pageConfig) => {
|
|
401
390
|
assertGlobalConfigs(pageConfig, interfaceFilesAll);
|
|
@@ -419,7 +408,7 @@ function assertGlobalConfigs(pageConfig, interfaceFilesAll) {
|
|
|
419
408
|
configNames.push(...Object.keys(interfaceFile.fileExportsByConfigName));
|
|
420
409
|
}
|
|
421
410
|
configNames.forEach((configName) => {
|
|
422
|
-
if (
|
|
411
|
+
if (isGlobalConfigOld(configName))
|
|
423
412
|
return;
|
|
424
413
|
const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
425
414
|
if (configDef.global === true) {
|
|
@@ -488,14 +477,6 @@ function getConfigValues(pageConfig) {
|
|
|
488
477
|
});
|
|
489
478
|
return configValues;
|
|
490
479
|
}
|
|
491
|
-
function interfacefileIsAlreaydLoaded(interfaceFile) {
|
|
492
|
-
const configMapValues = Object.values(interfaceFile.fileExportsByConfigName);
|
|
493
|
-
const isAlreadyLoaded = configMapValues.some((conf) => 'configValue' in conf);
|
|
494
|
-
if (isAlreadyLoaded) {
|
|
495
|
-
(0, utils_js_1.assert)(configMapValues.every((conf) => 'configValue' in conf));
|
|
496
|
-
}
|
|
497
|
-
return isAlreadyLoaded;
|
|
498
|
-
}
|
|
499
480
|
function getInterfaceFilesRelevant(interfaceFilesAll, locationIdPage) {
|
|
500
481
|
const interfaceFilesRelevant = Object.fromEntries((0, utils_js_1.objectEntries)(interfaceFilesAll)
|
|
501
482
|
.filter(([locationId]) => {
|
|
@@ -508,7 +489,7 @@ async function resolveConfigValueSources(configName, configDef, interfaceFilesRe
|
|
|
508
489
|
const sourcesInfo = [];
|
|
509
490
|
// interfaceFilesRelevant is sorted by sortAfterInheritanceOrder()
|
|
510
491
|
for (const interfaceFiles of Object.values(interfaceFilesRelevant)) {
|
|
511
|
-
const interfaceFilesDefiningConfig = interfaceFiles.filter((interfaceFile) => interfaceFile.
|
|
492
|
+
const interfaceFilesDefiningConfig = interfaceFiles.filter((interfaceFile) => getDefiningConfigNames(interfaceFile).includes(configName));
|
|
512
493
|
if (interfaceFilesDefiningConfig.length === 0)
|
|
513
494
|
continue;
|
|
514
495
|
const visited = new WeakSet();
|
|
@@ -595,8 +576,8 @@ function isInterfaceFileUserLand(interfaceFile) {
|
|
|
595
576
|
return (interfaceFile.isConfigFile && !interfaceFile.isConfigExtend) || interfaceFile.isValueFile;
|
|
596
577
|
}
|
|
597
578
|
async function getConfigValueSource(configName, interfaceFile, configDef, userRootDir, importedFilesLoaded, isHighestInheritancePrecedence) {
|
|
598
|
-
const
|
|
599
|
-
(0, utils_js_1.assert)(
|
|
579
|
+
const confVal = getConfVal(interfaceFile, configName);
|
|
580
|
+
(0, utils_js_1.assert)(confVal);
|
|
600
581
|
const configValueSourceCommon = {
|
|
601
582
|
locationId: interfaceFile.locationId,
|
|
602
583
|
interfaceFile
|
|
@@ -612,7 +593,8 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
612
593
|
let valueFilePath;
|
|
613
594
|
if (interfaceFile.isConfigFile) {
|
|
614
595
|
// Defined over pointer import
|
|
615
|
-
|
|
596
|
+
(0, utils_js_1.assert)(confVal.configValueLoaded);
|
|
597
|
+
const resolved = (0, resolvePointerImport_js_1.resolvePointerImportOfConfig)(confVal.configValue, interfaceFile.filePath, userRootDir, configDef.env, configName);
|
|
616
598
|
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, definedAtFilePath_);
|
|
617
599
|
(0, utils_js_1.assertUsage)(resolved, `${configDefinedAt} should be an import`);
|
|
618
600
|
valueFilePath = resolved.pointerImport.filePathAbsoluteVite;
|
|
@@ -641,8 +623,8 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
641
623
|
}
|
|
642
624
|
// +config.js
|
|
643
625
|
if (interfaceFile.isConfigFile) {
|
|
644
|
-
(0, utils_js_1.assert)(
|
|
645
|
-
const { configValue } =
|
|
626
|
+
(0, utils_js_1.assert)(confVal.configValueLoaded);
|
|
627
|
+
const { configValue } = confVal;
|
|
646
628
|
// Defined over pointer import
|
|
647
629
|
const resolved = (0, resolvePointerImport_js_1.resolvePointerImportOfConfig)(configValue, interfaceFile.filePath, userRootDir, configDef.env, configName);
|
|
648
630
|
if (resolved) {
|
|
@@ -684,7 +666,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
684
666
|
// Defined by value file, i.e. +{configName}.js
|
|
685
667
|
if (interfaceFile.isValueFile) {
|
|
686
668
|
const configEnvResolved = (0, resolvePointerImport_js_1.resolveConfigEnvWithFileName)(configDef.env, interfaceFile.filePath);
|
|
687
|
-
const valueAlreadyLoaded =
|
|
669
|
+
const valueAlreadyLoaded = confVal.configValueLoaded;
|
|
688
670
|
(0, utils_js_1.assert)(valueAlreadyLoaded === !!configEnvResolved.config);
|
|
689
671
|
const configValueSource = {
|
|
690
672
|
...configValueSourceCommon,
|
|
@@ -701,7 +683,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
701
683
|
}
|
|
702
684
|
};
|
|
703
685
|
if (valueAlreadyLoaded) {
|
|
704
|
-
configValueSource.value =
|
|
686
|
+
configValueSource.value = confVal.configValue;
|
|
705
687
|
}
|
|
706
688
|
return configValueSource;
|
|
707
689
|
}
|
|
@@ -709,7 +691,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
709
691
|
}
|
|
710
692
|
function isDefiningPage(interfaceFiles) {
|
|
711
693
|
for (const interfaceFile of interfaceFiles) {
|
|
712
|
-
const configNames =
|
|
694
|
+
const configNames = getDefiningConfigNames(interfaceFile);
|
|
713
695
|
if (configNames.some((configName) => isDefiningPageConfig(configName))) {
|
|
714
696
|
return true;
|
|
715
697
|
}
|
|
@@ -719,16 +701,28 @@ function isDefiningPage(interfaceFiles) {
|
|
|
719
701
|
function isDefiningPageConfig(configName) {
|
|
720
702
|
return ['Page', 'route'].includes(configName);
|
|
721
703
|
}
|
|
704
|
+
function getDefiningConfigNames(interfaceFile) {
|
|
705
|
+
let configNames = [];
|
|
706
|
+
if (interfaceFile.isValueFile) {
|
|
707
|
+
configNames.push(interfaceFile.configName);
|
|
708
|
+
}
|
|
709
|
+
if (interfaceFile.isValueLoaded) {
|
|
710
|
+
configNames.push(...Object.keys(interfaceFile.fileExportsByConfigName));
|
|
711
|
+
}
|
|
712
|
+
configNames = (0, utils_js_1.unique)(configNames);
|
|
713
|
+
return configNames;
|
|
714
|
+
}
|
|
722
715
|
function getConfigDefinitions(interfaceFilesRelevant) {
|
|
723
716
|
const configDefinitionsMerged = { ...configDefinitionsBuiltIn };
|
|
724
717
|
Object.entries(interfaceFilesRelevant)
|
|
725
718
|
.reverse()
|
|
726
719
|
.forEach(([_locationId, interfaceFiles]) => {
|
|
727
720
|
interfaceFiles.forEach((interfaceFile) => {
|
|
728
|
-
const
|
|
729
|
-
if (!
|
|
721
|
+
const confVal = getConfVal(interfaceFile, 'meta');
|
|
722
|
+
if (!confVal)
|
|
730
723
|
return;
|
|
731
|
-
|
|
724
|
+
(0, utils_js_1.assert)(confVal.configValueLoaded);
|
|
725
|
+
const meta = confVal.configValue;
|
|
732
726
|
assertMetaUsage(meta, `Config ${picocolors_1.default.cyan('meta')} defined at ${interfaceFile.filePath.filePathToShowToUser}`);
|
|
733
727
|
// Set configDef._userEffectDefinedAtFilePath
|
|
734
728
|
Object.entries(meta).forEach(([configName, configDef]) => {
|
|
@@ -1048,24 +1042,25 @@ function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
|
1048
1042
|
function shouldBeLoadableAtBuildTime(configDef) {
|
|
1049
1043
|
return !!configDef.env.config && !configDef._valueIsFilePath;
|
|
1050
1044
|
}
|
|
1051
|
-
|
|
1045
|
+
// TODO/now: remove
|
|
1046
|
+
function isGlobalConfigOld(configName) {
|
|
1052
1047
|
// TODO/now
|
|
1053
1048
|
if (configName === 'prerender')
|
|
1054
1049
|
return false;
|
|
1055
1050
|
const configNamesGlobal = getConfigNamesGlobal();
|
|
1056
1051
|
return (0, utils_js_1.includes)(configNamesGlobal, configName);
|
|
1057
1052
|
}
|
|
1058
|
-
/*
|
|
1059
1053
|
// TODO/now
|
|
1060
|
-
function isGlobalConfig(configName
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1054
|
+
function isGlobalConfig(configName, configDefinitions, value) {
|
|
1055
|
+
const configSpec = configDefinitions[configName];
|
|
1056
|
+
(0, utils_js_1.assert)(configSpec);
|
|
1057
|
+
const globalValue = configSpec.global;
|
|
1058
|
+
if (!globalValue)
|
|
1059
|
+
return false;
|
|
1060
|
+
if (globalValue === true)
|
|
1061
|
+
return true;
|
|
1062
|
+
return globalValue(value);
|
|
1067
1063
|
}
|
|
1068
|
-
*/
|
|
1069
1064
|
function getConfigNamesGlobal() {
|
|
1070
1065
|
return Object.keys(configDefinitionsBuiltInGlobal);
|
|
1071
1066
|
}
|
|
@@ -1098,6 +1093,12 @@ function sortConfigValueSources(configValueSources, locationIdPage) {
|
|
|
1098
1093
|
// Sort after the filesystem inheritance of the config value
|
|
1099
1094
|
.sort(([, [source1]], [, [source2]]) => (0, utils_js_1.reverse)((0, filesystemRouting_js_1.sortAfterInheritanceOrder)(source1.locationId, source2.locationId, locationIdPage))));
|
|
1100
1095
|
}
|
|
1101
|
-
function
|
|
1102
|
-
|
|
1096
|
+
function getConfVal(interfaceFile, configName) {
|
|
1097
|
+
const configNames = getDefiningConfigNames(interfaceFile);
|
|
1098
|
+
if (!configNames.includes(configName))
|
|
1099
|
+
return null;
|
|
1100
|
+
if (!interfaceFile.isValueLoaded)
|
|
1101
|
+
return { configValueLoaded: false };
|
|
1102
|
+
const confVal = { configValue: interfaceFile.fileExportsByConfigName[configName], configValueLoaded: true };
|
|
1103
|
+
return confVal;
|
|
1103
1104
|
}
|
|
@@ -39,24 +39,29 @@ function getUrlParsed(pageContext) {
|
|
|
39
39
|
// 6. The value of pageContext.urlPathname is now '/login': the pathname of `pageContext.urlLogical`. (While pageContext.urlOriginal is still '/fr-FR/admin'.)
|
|
40
40
|
// Reproduction: https://github.com/vikejs/vike/discussions/1436#discussioncomment-8142023
|
|
41
41
|
// Determine logical URL
|
|
42
|
+
// TODO/soon: revert https://github.com/vikejs/vike/issues/2138#issuecomment-2631713411
|
|
43
|
+
const assertUrlResolved = (src) => (0, utils_js_1.assert)(urlResolved && typeof urlResolved === 'string', { src, urlResolved });
|
|
42
44
|
let urlResolved;
|
|
43
45
|
let baseToBeRemoved;
|
|
44
46
|
if (pageContext.urlLogical) {
|
|
45
47
|
// Set by onBeforeRoute()
|
|
46
48
|
urlResolved = pageContext.urlLogical;
|
|
47
49
|
baseToBeRemoved = false;
|
|
50
|
+
assertUrlResolved(1);
|
|
48
51
|
}
|
|
49
52
|
else if (pageContext._urlRewrite) {
|
|
50
53
|
// Set by `throw render()`
|
|
51
54
|
urlResolved = pageContext._urlRewrite;
|
|
52
55
|
baseToBeRemoved = false;
|
|
56
|
+
assertUrlResolved(2);
|
|
53
57
|
}
|
|
54
58
|
else {
|
|
55
59
|
// Set by renderPage()
|
|
56
60
|
urlResolved = pageContext.urlOriginal;
|
|
57
61
|
baseToBeRemoved = true;
|
|
62
|
+
assertUrlResolved(3);
|
|
58
63
|
}
|
|
59
|
-
(
|
|
64
|
+
assertUrlResolved(4);
|
|
60
65
|
// Remove .pageContext.json
|
|
61
66
|
let urlHandler = pageContext._urlHandler;
|
|
62
67
|
if (!urlHandler)
|
package/dist/cjs/utils/isDev.js
CHANGED
|
@@ -9,7 +9,7 @@ function isDevCheck(configEnv) {
|
|
|
9
9
|
const { isPreview, command } = configEnv;
|
|
10
10
|
// Released at vite@5.1.0 which is guaranteed with `assertVersion('Vite', version, '5.1.0')`
|
|
11
11
|
// - Release: https://github.com/vitejs/vite/blob/6f7466e6211027686f40ad7e4ce6ec8477414546/packages/vite/CHANGELOG.md#510-beta4-2024-01-26:~:text=fix(preview)%3A-,set%20isPreview%20true,-(%2315695)%20(93fce55
|
|
12
|
-
// - Surprisingly, this assert() can fail: https://github.com/vikejs/vike/issues/
|
|
12
|
+
// - Surprisingly, this assert() can fail: https://github.com/vikejs/vike/issues/2135
|
|
13
13
|
(0, assert_js_1.assert)(typeof isPreview === 'boolean', { isPreview, version: vite_1.version });
|
|
14
14
|
return command === 'serve' && !isPreview;
|
|
15
15
|
}
|
|
@@ -3,7 +3,7 @@ export { assertExtensionsRequire };
|
|
|
3
3
|
import pc from '@brillout/picocolors';
|
|
4
4
|
import { isObjectOfStrings } from '../../../../../utils/isObjectOfStrings.js';
|
|
5
5
|
import { PROJECT_VERSION, assert, assertUsage, assertWarning, findPackageJson } from '../../../utils.js';
|
|
6
|
-
import {
|
|
6
|
+
import { getConfVal } from './getVikeConfig.js';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import semver from 'semver';
|
|
9
9
|
function assertExtensionsConventions(interfaceFile) {
|
|
@@ -60,18 +60,22 @@ function assertExtensionsRequire(pageConfig) {
|
|
|
60
60
|
});
|
|
61
61
|
}
|
|
62
62
|
function getConfigRequireValue(interfaceFile) {
|
|
63
|
-
const
|
|
64
|
-
if (!
|
|
63
|
+
const confVal = getConfVal(interfaceFile, 'require');
|
|
64
|
+
if (!confVal)
|
|
65
65
|
return null;
|
|
66
|
+
assert(confVal.configValueLoaded);
|
|
67
|
+
const require = confVal.configValue;
|
|
66
68
|
const { filePathToShowToUserResolved } = interfaceFile.filePath;
|
|
67
69
|
assert(filePathToShowToUserResolved);
|
|
68
70
|
assertUsage(isObjectOfStrings(require), `The setting ${pc.bold('require')} defined at ${filePathToShowToUserResolved} should be an object with string values (${pc.bold('Record<string, string>')}).`);
|
|
69
71
|
return require;
|
|
70
72
|
}
|
|
71
73
|
function getNameValue(interfaceFile) {
|
|
72
|
-
const
|
|
73
|
-
if (!
|
|
74
|
+
const confVal = getConfVal(interfaceFile, 'name');
|
|
75
|
+
if (!confVal)
|
|
74
76
|
return null;
|
|
77
|
+
assert(confVal.configValueLoaded);
|
|
78
|
+
const name = confVal.configValue;
|
|
75
79
|
const filePathToShowToUser = getFilePathToShowToUser(interfaceFile);
|
|
76
80
|
assertUsage(typeof name === 'string', `The setting ${pc.bold('name')} defined at ${filePathToShowToUser} should be a string.`);
|
|
77
81
|
return name;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export { loadImportedFile };
|
|
2
2
|
export { loadValueFile };
|
|
3
|
+
export { loadValueFiles };
|
|
3
4
|
export { loadConfigFile };
|
|
4
5
|
export type { ImportedFilesLoaded };
|
|
5
6
|
export type { ConfigFile };
|
|
6
7
|
import type { FilePathResolved } from '../../../../../../shared/page-configs/FilePath.js';
|
|
7
|
-
import type
|
|
8
|
+
import { InterfaceFilesByLocationId, type InterfaceValueFile } from '../getVikeConfig.js';
|
|
9
|
+
import type { ConfigDefinitions } from './configDefinitionsBuiltIn.js';
|
|
8
10
|
type ImportedFilesLoaded = Record<string, Promise<Record<string, unknown>>>;
|
|
9
11
|
type ConfigFile = {
|
|
10
12
|
fileExports: Record<string, unknown>;
|
|
@@ -14,7 +16,8 @@ type ConfigFile = {
|
|
|
14
16
|
declare function loadImportedFile(import_: FilePathResolved & {
|
|
15
17
|
fileExportName: string;
|
|
16
18
|
}, userRootDir: string, importedFilesLoaded: ImportedFilesLoaded): Promise<unknown>;
|
|
17
|
-
declare function loadValueFile(interfaceValueFile: InterfaceValueFile,
|
|
19
|
+
declare function loadValueFile(interfaceValueFile: InterfaceValueFile, configDefinitions: ConfigDefinitions, userRootDir: string): Promise<void>;
|
|
20
|
+
declare function loadValueFiles(interfaceFiles: InterfaceFilesByLocationId, configDefinitions: ConfigDefinitions, userRootDir: string): Promise<void>;
|
|
18
21
|
declare function loadConfigFile(configFilePath: FilePathResolved, userRootDir: string, visited: string[], isExtensionConfig: boolean): Promise<{
|
|
19
22
|
configFile: ConfigFile;
|
|
20
23
|
extendsConfigs: ConfigFile[];
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
// Files
|
|
1
|
+
// Files loaded at config time:
|
|
2
2
|
export { loadImportedFile };
|
|
3
3
|
export { loadValueFile };
|
|
4
|
+
export { loadValueFiles };
|
|
4
5
|
export { loadConfigFile };
|
|
5
|
-
import { assert, assertUsage, assertIsNotProductionRuntime, isArrayOfStrings, isObject } from '../../../../utils.js';
|
|
6
|
+
import { assert, assertUsage, assertIsNotProductionRuntime, isArrayOfStrings, isObject, genPromise } from '../../../../utils.js';
|
|
6
7
|
import { transpileAndExecuteFile } from './transpileAndExecuteFile.js';
|
|
8
|
+
import { getConfigDefinitionOptional, shouldBeLoadableAtBuildTime } from '../getVikeConfig.js';
|
|
7
9
|
import { assertPlusFileExport } from '../../../../../../shared/page-configs/assertPlusFileExport.js';
|
|
8
10
|
import pc from '@brillout/picocolors';
|
|
9
11
|
import { parsePointerImportData } from './transformPointerImports.js';
|
|
@@ -21,15 +23,39 @@ async function loadImportedFile(import_, userRootDir, importedFilesLoaded) {
|
|
|
21
23
|
return fileExport;
|
|
22
24
|
}
|
|
23
25
|
// Load +{configName}.js
|
|
24
|
-
async function loadValueFile(interfaceValueFile,
|
|
26
|
+
async function loadValueFile(interfaceValueFile, configDefinitions, userRootDir) {
|
|
27
|
+
const { configName } = interfaceValueFile;
|
|
28
|
+
const configDef = getConfigDefinitionOptional(configDefinitions, configName);
|
|
29
|
+
if (!configDef || !shouldBeLoadableAtBuildTime(configDef)) {
|
|
30
|
+
// Only load value files with `env.config===true`
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (interfaceValueFile.isValueLoaded) {
|
|
34
|
+
await interfaceValueFile.isValueLoaded;
|
|
35
|
+
if (
|
|
36
|
+
// Help TS
|
|
37
|
+
true)
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const { promise, resolve } = genPromise();
|
|
41
|
+
interfaceValueFile.isValueLoaded = promise;
|
|
42
|
+
assert(interfaceValueFile.isValueLoaded);
|
|
43
|
+
interfaceValueFile.fileExportsByConfigName = {};
|
|
25
44
|
const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath, userRootDir, false);
|
|
45
|
+
resolve();
|
|
26
46
|
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
27
47
|
assertPlusFileExport(fileExports, filePathToShowToUser, configName);
|
|
28
48
|
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
29
49
|
const configName_ = exportName === 'default' ? configName : exportName;
|
|
30
|
-
interfaceValueFile.fileExportsByConfigName[configName_] =
|
|
50
|
+
interfaceValueFile.fileExportsByConfigName[configName_] = configValue;
|
|
31
51
|
});
|
|
32
52
|
}
|
|
53
|
+
async function loadValueFiles(interfaceFiles, configDefinitions, userRootDir) {
|
|
54
|
+
await Promise.all(Object.values(interfaceFiles)
|
|
55
|
+
.flat(1)
|
|
56
|
+
.filter((interfaceFile) => interfaceFile.isValueFile)
|
|
57
|
+
.map(async (interfaceFile) => await loadValueFile(interfaceFile, configDefinitions, userRootDir)));
|
|
58
|
+
}
|
|
33
59
|
// Load +config.js, including all its extends pointer imports
|
|
34
60
|
async function loadConfigFile(configFilePath, userRootDir, visited, isExtensionConfig) {
|
|
35
61
|
const { filePathAbsoluteFilesystem } = configFilePath;
|
|
@@ -4,12 +4,15 @@ export { reloadVikeConfig };
|
|
|
4
4
|
export { vikeConfigDependencies };
|
|
5
5
|
export { isVikeConfigFile };
|
|
6
6
|
export { isV1Design };
|
|
7
|
-
export {
|
|
7
|
+
export { getConfVal };
|
|
8
|
+
export { getConfigDefinitionOptional };
|
|
9
|
+
export { shouldBeLoadableAtBuildTime };
|
|
8
10
|
export type { VikeConfigObject };
|
|
9
11
|
export type { InterfaceValueFile };
|
|
10
12
|
export type { InterfaceFile };
|
|
11
13
|
export type { InterfaceFilesByLocationId };
|
|
12
14
|
import type { PageConfigGlobalBuildTime, PageConfigBuildTime } from '../../../../../shared/page-configs/PageConfig.js';
|
|
15
|
+
import { type ConfigDefinitions, type ConfigDefinitionInternal } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
13
16
|
import { type LocationId } from './getVikeConfig/filesystemRouting.js';
|
|
14
17
|
import type { ResolvedConfig } from 'vite';
|
|
15
18
|
import type { FilePathResolved } from '../../../../../shared/page-configs/FilePath.js';
|
|
@@ -18,22 +21,27 @@ type InterfaceFile = InterfaceConfigFile | InterfaceValueFile;
|
|
|
18
21
|
type InterfaceFileCommons = {
|
|
19
22
|
locationId: LocationId;
|
|
20
23
|
filePath: FilePathResolved;
|
|
21
|
-
fileExportsByConfigName: Record<ConfigName, {
|
|
22
|
-
configValue?: unknown;
|
|
23
|
-
}>;
|
|
24
24
|
};
|
|
25
25
|
type InterfaceConfigFile = InterfaceFileCommons & {
|
|
26
26
|
isConfigFile: true;
|
|
27
27
|
isValueFile: false;
|
|
28
28
|
extendsFilePaths: string[];
|
|
29
29
|
isConfigExtend: boolean;
|
|
30
|
+
isValueLoaded: true;
|
|
31
|
+
fileExportsByConfigName: Record<string, // configName
|
|
32
|
+
unknown>;
|
|
30
33
|
};
|
|
31
34
|
type InterfaceValueFile = InterfaceFileCommons & {
|
|
32
35
|
isConfigFile: false;
|
|
33
36
|
isValueFile: true;
|
|
34
37
|
configName: string;
|
|
35
|
-
}
|
|
36
|
-
|
|
38
|
+
} & ({
|
|
39
|
+
isValueLoaded: Promise<void>;
|
|
40
|
+
fileExportsByConfigName: Record<string, // configName
|
|
41
|
+
unknown>;
|
|
42
|
+
} | {
|
|
43
|
+
isValueLoaded: false;
|
|
44
|
+
});
|
|
37
45
|
type InterfaceFilesByLocationId = Record<LocationId, InterfaceFile[]>;
|
|
38
46
|
type VikeConfigObject = {
|
|
39
47
|
pageConfigs: PageConfigBuildTime[];
|
|
@@ -48,4 +56,11 @@ declare function getVikeConfig(config: ResolvedConfig, { doNotRestartViteOnError
|
|
|
48
56
|
declare function getVikeConfig2(userRootDir: string, isDev: boolean, vikeVitePluginOptions: unknown): Promise<VikeConfigObject>;
|
|
49
57
|
declare function isV1Design(config: ResolvedConfig): Promise<boolean>;
|
|
50
58
|
declare function isVikeConfigFile(filePath: string): boolean;
|
|
51
|
-
declare function
|
|
59
|
+
declare function getConfigDefinitionOptional(configDefinitions: ConfigDefinitions, configName: string): ConfigDefinitionInternal | null;
|
|
60
|
+
declare function shouldBeLoadableAtBuildTime(configDef: ConfigDefinitionInternal): boolean;
|
|
61
|
+
declare function getConfVal(interfaceFile: InterfaceFile, configName: string): null | {
|
|
62
|
+
configValue: unknown;
|
|
63
|
+
configValueLoaded: true;
|
|
64
|
+
} | {
|
|
65
|
+
configValueLoaded: false;
|
|
66
|
+
};
|
|
@@ -4,8 +4,10 @@ export { reloadVikeConfig };
|
|
|
4
4
|
export { vikeConfigDependencies };
|
|
5
5
|
export { isVikeConfigFile };
|
|
6
6
|
export { isV1Design };
|
|
7
|
-
export {
|
|
8
|
-
|
|
7
|
+
export { getConfVal };
|
|
8
|
+
export { getConfigDefinitionOptional };
|
|
9
|
+
export { shouldBeLoadableAtBuildTime };
|
|
10
|
+
import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEntries, hasProp, includes, assertIsNotProductionRuntime, getMostSimilar, joinEnglish, lowerFirst, assertKeys, objectKeys, objectFromEntries, makeFirst, isNpmPackageImport, reverse, unique } from '../../../utils.js';
|
|
9
11
|
import path from 'path';
|
|
10
12
|
import { configDefinitionsBuiltInAll } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
11
13
|
import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, isGlobalLocation, applyFilesystemRoutingRootEffect } from './getVikeConfig/filesystemRouting.js';
|
|
@@ -18,7 +20,7 @@ import pc from '@brillout/picocolors';
|
|
|
18
20
|
import { getConfigDefinedAt } from '../../../../../shared/page-configs/getConfigDefinedAt.js';
|
|
19
21
|
import { crawlPlusFiles } from './getVikeConfig/crawlPlusFiles.js';
|
|
20
22
|
import { getConfigFileExport } from './getConfigFileExport.js';
|
|
21
|
-
import { loadConfigFile, loadImportedFile, loadValueFile } from './getVikeConfig/loadFileAtConfigTime.js';
|
|
23
|
+
import { loadConfigFile, loadImportedFile, loadValueFile, loadValueFiles } from './getVikeConfig/loadFileAtConfigTime.js';
|
|
22
24
|
import { clearFilesEnvMap, resolveConfigEnvWithFileName, resolvePointerImportOfConfig } from './getVikeConfig/resolvePointerImport.js';
|
|
23
25
|
import { getFilePathResolved } from '../../../shared/getFilePath.js';
|
|
24
26
|
import { getConfigValueBuildTime } from '../../../../../shared/page-configs/getConfigValueBuildTime.js';
|
|
@@ -152,26 +154,17 @@ async function loadInterfaceFiles(userRootDir) {
|
|
|
152
154
|
const interfaceFile = {
|
|
153
155
|
locationId,
|
|
154
156
|
filePath,
|
|
155
|
-
fileExportsByConfigName: {
|
|
156
|
-
[configName]: {}
|
|
157
|
-
},
|
|
158
157
|
isConfigFile: false,
|
|
159
158
|
isValueFile: true,
|
|
159
|
+
isValueLoaded: false,
|
|
160
160
|
configName
|
|
161
161
|
};
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
{
|
|
172
|
-
interfaceFilesAll[locationId] = interfaceFilesAll[locationId] ?? [];
|
|
173
|
-
interfaceFilesAll[locationId].push(interfaceFile);
|
|
174
|
-
}
|
|
162
|
+
interfaceFilesAll[locationId] = interfaceFilesAll[locationId] ?? [];
|
|
163
|
+
interfaceFilesAll[locationId].push(interfaceFile);
|
|
164
|
+
// We don't have access to the custom config definitions defined by the user yet.
|
|
165
|
+
// - If `configDef` is `undefined` => we load the file +{configName}.js later.
|
|
166
|
+
// - We already need to load +meta.js here (to get the custom config definitions defined by the user)
|
|
167
|
+
await loadValueFile(interfaceFile, configDefinitionsBuiltIn, userRootDir);
|
|
175
168
|
})
|
|
176
169
|
]);
|
|
177
170
|
assertAllConfigsAreKnown(interfaceFilesAll);
|
|
@@ -185,12 +178,13 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend, locationId)
|
|
|
185
178
|
fileExportsByConfigName: {},
|
|
186
179
|
isConfigFile: true,
|
|
187
180
|
isValueFile: false,
|
|
181
|
+
isValueLoaded: true,
|
|
188
182
|
isConfigExtend,
|
|
189
183
|
extendsFilePaths
|
|
190
184
|
};
|
|
191
185
|
const fileExport = getConfigFileExport(fileExports, filePath.filePathToShowToUser);
|
|
192
186
|
Object.entries(fileExport).forEach(([configName, configValue]) => {
|
|
193
|
-
interfaceFile.fileExportsByConfigName[configName] =
|
|
187
|
+
interfaceFile.fileExportsByConfigName[configName] = configValue;
|
|
194
188
|
});
|
|
195
189
|
return interfaceFile;
|
|
196
190
|
}
|
|
@@ -200,8 +194,11 @@ function assertAllConfigsAreKnown(interfaceFilesAll) {
|
|
|
200
194
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesAll, locationId);
|
|
201
195
|
const configDefinitions = getConfigDefinitions(interfaceFilesRelevant);
|
|
202
196
|
interfaceFiles.forEach((interfaceFile) => {
|
|
203
|
-
Object.keys(
|
|
204
|
-
|
|
197
|
+
const configNamesKnown = Object.keys(configDefinitions);
|
|
198
|
+
const { filePathToShowToUser } = interfaceFile.filePath;
|
|
199
|
+
const configNames = getDefiningConfigNames(interfaceFile);
|
|
200
|
+
configNames.forEach((configName) => {
|
|
201
|
+
assertConfigExists(configName, configNamesKnown, filePathToShowToUser);
|
|
205
202
|
});
|
|
206
203
|
});
|
|
207
204
|
});
|
|
@@ -277,7 +274,7 @@ async function getGlobalConfigs(interfaceFilesAll, userRootDir, importedFilesLoa
|
|
|
277
274
|
objectEntries(interfaceFilesAll).forEach(([locationId, interfaceFiles]) => {
|
|
278
275
|
interfaceFiles.forEach((interfaceFile) => {
|
|
279
276
|
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
280
|
-
if (!isGlobalLocation(locationId, locationIds) &&
|
|
277
|
+
if (!isGlobalLocation(locationId, locationIds) && isGlobalConfigOld(configName)) {
|
|
281
278
|
assertUsage(
|
|
282
279
|
false,
|
|
283
280
|
[
|
|
@@ -340,32 +337,15 @@ async function getPageConfigs(interfaceFilesAll, userRootDir, importedFilesLoade
|
|
|
340
337
|
pageConfigGlobal.configValueSources[configName] = sources;
|
|
341
338
|
}));
|
|
342
339
|
const pageConfigs = [];
|
|
343
|
-
await Promise.all(
|
|
344
|
-
.filter(([_locationId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
345
|
-
.map(async ([locationId]) => {
|
|
340
|
+
await Promise.all(getPageLocationIds(interfaceFilesAll).map(async (locationId) => {
|
|
346
341
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesAll, locationId);
|
|
347
|
-
const interfaceFilesRelevantList = Object.values(interfaceFilesRelevant).flat(1);
|
|
348
342
|
const configDefinitions = getConfigDefinitions(interfaceFilesRelevant);
|
|
349
|
-
// Load value files
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
return;
|
|
353
|
-
const { configName } = interfaceFile;
|
|
354
|
-
if (isGlobalConfig(configName))
|
|
355
|
-
return;
|
|
356
|
-
const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
357
|
-
if (!shouldBeLoadableAtBuildTime(configDef))
|
|
358
|
-
return;
|
|
359
|
-
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
360
|
-
if (isAlreadyLoaded)
|
|
361
|
-
return;
|
|
362
|
-
// Value files of built-in configs should have already been loaded at loadInterfaceFiles()
|
|
363
|
-
assert(!(configName in configDefinitionsBuiltIn));
|
|
364
|
-
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
365
|
-
}));
|
|
343
|
+
// Load value files (with `env.config===true`) of *custom* configs.
|
|
344
|
+
// - The value files of *built-in* configs are already loaded at `loadInterfaceFiles()`.
|
|
345
|
+
await loadValueFiles(interfaceFilesRelevant, configDefinitions, userRootDir);
|
|
366
346
|
let configValueSources = {};
|
|
367
347
|
await Promise.all(objectEntries(configDefinitions)
|
|
368
|
-
.filter(([configName]) => !
|
|
348
|
+
.filter(([configName]) => !isGlobalConfigOld(configName))
|
|
369
349
|
.map(async ([configName, configDef]) => {
|
|
370
350
|
const sources = await resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir, importedFilesLoaded);
|
|
371
351
|
if (sources.length === 0)
|
|
@@ -390,6 +370,15 @@ async function getPageConfigs(interfaceFilesAll, userRootDir, importedFilesLoade
|
|
|
390
370
|
assertPageConfigs(pageConfigs, interfaceFilesAll);
|
|
391
371
|
return { pageConfigs, pageConfigGlobal };
|
|
392
372
|
}
|
|
373
|
+
function getPageLocationIds(interfaceFilesAll) {
|
|
374
|
+
const locationIds = new Set();
|
|
375
|
+
objectEntries(interfaceFilesAll).forEach(([locationId, interfaceFiles]) => {
|
|
376
|
+
if (isDefiningPage(interfaceFiles)) {
|
|
377
|
+
locationIds.add(locationId);
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
return Array.from(locationIds);
|
|
381
|
+
}
|
|
393
382
|
function assertPageConfigs(pageConfigs, interfaceFilesAll) {
|
|
394
383
|
pageConfigs.forEach((pageConfig) => {
|
|
395
384
|
assertGlobalConfigs(pageConfig, interfaceFilesAll);
|
|
@@ -413,7 +402,7 @@ function assertGlobalConfigs(pageConfig, interfaceFilesAll) {
|
|
|
413
402
|
configNames.push(...Object.keys(interfaceFile.fileExportsByConfigName));
|
|
414
403
|
}
|
|
415
404
|
configNames.forEach((configName) => {
|
|
416
|
-
if (
|
|
405
|
+
if (isGlobalConfigOld(configName))
|
|
417
406
|
return;
|
|
418
407
|
const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
419
408
|
if (configDef.global === true) {
|
|
@@ -482,14 +471,6 @@ function getConfigValues(pageConfig) {
|
|
|
482
471
|
});
|
|
483
472
|
return configValues;
|
|
484
473
|
}
|
|
485
|
-
function interfacefileIsAlreaydLoaded(interfaceFile) {
|
|
486
|
-
const configMapValues = Object.values(interfaceFile.fileExportsByConfigName);
|
|
487
|
-
const isAlreadyLoaded = configMapValues.some((conf) => 'configValue' in conf);
|
|
488
|
-
if (isAlreadyLoaded) {
|
|
489
|
-
assert(configMapValues.every((conf) => 'configValue' in conf));
|
|
490
|
-
}
|
|
491
|
-
return isAlreadyLoaded;
|
|
492
|
-
}
|
|
493
474
|
function getInterfaceFilesRelevant(interfaceFilesAll, locationIdPage) {
|
|
494
475
|
const interfaceFilesRelevant = Object.fromEntries(objectEntries(interfaceFilesAll)
|
|
495
476
|
.filter(([locationId]) => {
|
|
@@ -502,7 +483,7 @@ async function resolveConfigValueSources(configName, configDef, interfaceFilesRe
|
|
|
502
483
|
const sourcesInfo = [];
|
|
503
484
|
// interfaceFilesRelevant is sorted by sortAfterInheritanceOrder()
|
|
504
485
|
for (const interfaceFiles of Object.values(interfaceFilesRelevant)) {
|
|
505
|
-
const interfaceFilesDefiningConfig = interfaceFiles.filter((interfaceFile) => interfaceFile.
|
|
486
|
+
const interfaceFilesDefiningConfig = interfaceFiles.filter((interfaceFile) => getDefiningConfigNames(interfaceFile).includes(configName));
|
|
506
487
|
if (interfaceFilesDefiningConfig.length === 0)
|
|
507
488
|
continue;
|
|
508
489
|
const visited = new WeakSet();
|
|
@@ -589,8 +570,8 @@ function isInterfaceFileUserLand(interfaceFile) {
|
|
|
589
570
|
return (interfaceFile.isConfigFile && !interfaceFile.isConfigExtend) || interfaceFile.isValueFile;
|
|
590
571
|
}
|
|
591
572
|
async function getConfigValueSource(configName, interfaceFile, configDef, userRootDir, importedFilesLoaded, isHighestInheritancePrecedence) {
|
|
592
|
-
const
|
|
593
|
-
assert(
|
|
573
|
+
const confVal = getConfVal(interfaceFile, configName);
|
|
574
|
+
assert(confVal);
|
|
594
575
|
const configValueSourceCommon = {
|
|
595
576
|
locationId: interfaceFile.locationId,
|
|
596
577
|
interfaceFile
|
|
@@ -606,7 +587,8 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
606
587
|
let valueFilePath;
|
|
607
588
|
if (interfaceFile.isConfigFile) {
|
|
608
589
|
// Defined over pointer import
|
|
609
|
-
|
|
590
|
+
assert(confVal.configValueLoaded);
|
|
591
|
+
const resolved = resolvePointerImportOfConfig(confVal.configValue, interfaceFile.filePath, userRootDir, configDef.env, configName);
|
|
610
592
|
const configDefinedAt = getConfigDefinedAt('Config', configName, definedAtFilePath_);
|
|
611
593
|
assertUsage(resolved, `${configDefinedAt} should be an import`);
|
|
612
594
|
valueFilePath = resolved.pointerImport.filePathAbsoluteVite;
|
|
@@ -635,8 +617,8 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
635
617
|
}
|
|
636
618
|
// +config.js
|
|
637
619
|
if (interfaceFile.isConfigFile) {
|
|
638
|
-
assert(
|
|
639
|
-
const { configValue } =
|
|
620
|
+
assert(confVal.configValueLoaded);
|
|
621
|
+
const { configValue } = confVal;
|
|
640
622
|
// Defined over pointer import
|
|
641
623
|
const resolved = resolvePointerImportOfConfig(configValue, interfaceFile.filePath, userRootDir, configDef.env, configName);
|
|
642
624
|
if (resolved) {
|
|
@@ -678,7 +660,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
678
660
|
// Defined by value file, i.e. +{configName}.js
|
|
679
661
|
if (interfaceFile.isValueFile) {
|
|
680
662
|
const configEnvResolved = resolveConfigEnvWithFileName(configDef.env, interfaceFile.filePath);
|
|
681
|
-
const valueAlreadyLoaded =
|
|
663
|
+
const valueAlreadyLoaded = confVal.configValueLoaded;
|
|
682
664
|
assert(valueAlreadyLoaded === !!configEnvResolved.config);
|
|
683
665
|
const configValueSource = {
|
|
684
666
|
...configValueSourceCommon,
|
|
@@ -695,7 +677,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
695
677
|
}
|
|
696
678
|
};
|
|
697
679
|
if (valueAlreadyLoaded) {
|
|
698
|
-
configValueSource.value =
|
|
680
|
+
configValueSource.value = confVal.configValue;
|
|
699
681
|
}
|
|
700
682
|
return configValueSource;
|
|
701
683
|
}
|
|
@@ -703,7 +685,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
703
685
|
}
|
|
704
686
|
function isDefiningPage(interfaceFiles) {
|
|
705
687
|
for (const interfaceFile of interfaceFiles) {
|
|
706
|
-
const configNames =
|
|
688
|
+
const configNames = getDefiningConfigNames(interfaceFile);
|
|
707
689
|
if (configNames.some((configName) => isDefiningPageConfig(configName))) {
|
|
708
690
|
return true;
|
|
709
691
|
}
|
|
@@ -713,16 +695,28 @@ function isDefiningPage(interfaceFiles) {
|
|
|
713
695
|
function isDefiningPageConfig(configName) {
|
|
714
696
|
return ['Page', 'route'].includes(configName);
|
|
715
697
|
}
|
|
698
|
+
function getDefiningConfigNames(interfaceFile) {
|
|
699
|
+
let configNames = [];
|
|
700
|
+
if (interfaceFile.isValueFile) {
|
|
701
|
+
configNames.push(interfaceFile.configName);
|
|
702
|
+
}
|
|
703
|
+
if (interfaceFile.isValueLoaded) {
|
|
704
|
+
configNames.push(...Object.keys(interfaceFile.fileExportsByConfigName));
|
|
705
|
+
}
|
|
706
|
+
configNames = unique(configNames);
|
|
707
|
+
return configNames;
|
|
708
|
+
}
|
|
716
709
|
function getConfigDefinitions(interfaceFilesRelevant) {
|
|
717
710
|
const configDefinitionsMerged = { ...configDefinitionsBuiltIn };
|
|
718
711
|
Object.entries(interfaceFilesRelevant)
|
|
719
712
|
.reverse()
|
|
720
713
|
.forEach(([_locationId, interfaceFiles]) => {
|
|
721
714
|
interfaceFiles.forEach((interfaceFile) => {
|
|
722
|
-
const
|
|
723
|
-
if (!
|
|
715
|
+
const confVal = getConfVal(interfaceFile, 'meta');
|
|
716
|
+
if (!confVal)
|
|
724
717
|
return;
|
|
725
|
-
|
|
718
|
+
assert(confVal.configValueLoaded);
|
|
719
|
+
const meta = confVal.configValue;
|
|
726
720
|
assertMetaUsage(meta, `Config ${pc.cyan('meta')} defined at ${interfaceFile.filePath.filePathToShowToUser}`);
|
|
727
721
|
// Set configDef._userEffectDefinedAtFilePath
|
|
728
722
|
Object.entries(meta).forEach(([configName, configDef]) => {
|
|
@@ -1042,24 +1036,25 @@ function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
|
1042
1036
|
function shouldBeLoadableAtBuildTime(configDef) {
|
|
1043
1037
|
return !!configDef.env.config && !configDef._valueIsFilePath;
|
|
1044
1038
|
}
|
|
1045
|
-
|
|
1039
|
+
// TODO/now: remove
|
|
1040
|
+
function isGlobalConfigOld(configName) {
|
|
1046
1041
|
// TODO/now
|
|
1047
1042
|
if (configName === 'prerender')
|
|
1048
1043
|
return false;
|
|
1049
1044
|
const configNamesGlobal = getConfigNamesGlobal();
|
|
1050
1045
|
return includes(configNamesGlobal, configName);
|
|
1051
1046
|
}
|
|
1052
|
-
/*
|
|
1053
1047
|
// TODO/now
|
|
1054
|
-
function isGlobalConfig(configName
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1048
|
+
function isGlobalConfig(configName, configDefinitions, value) {
|
|
1049
|
+
const configSpec = configDefinitions[configName];
|
|
1050
|
+
assert(configSpec);
|
|
1051
|
+
const globalValue = configSpec.global;
|
|
1052
|
+
if (!globalValue)
|
|
1053
|
+
return false;
|
|
1054
|
+
if (globalValue === true)
|
|
1055
|
+
return true;
|
|
1056
|
+
return globalValue(value);
|
|
1061
1057
|
}
|
|
1062
|
-
*/
|
|
1063
1058
|
function getConfigNamesGlobal() {
|
|
1064
1059
|
return Object.keys(configDefinitionsBuiltInGlobal);
|
|
1065
1060
|
}
|
|
@@ -1092,6 +1087,12 @@ function sortConfigValueSources(configValueSources, locationIdPage) {
|
|
|
1092
1087
|
// Sort after the filesystem inheritance of the config value
|
|
1093
1088
|
.sort(([, [source1]], [, [source2]]) => reverse(sortAfterInheritanceOrder(source1.locationId, source2.locationId, locationIdPage))));
|
|
1094
1089
|
}
|
|
1095
|
-
function
|
|
1096
|
-
|
|
1090
|
+
function getConfVal(interfaceFile, configName) {
|
|
1091
|
+
const configNames = getDefiningConfigNames(interfaceFile);
|
|
1092
|
+
if (!configNames.includes(configName))
|
|
1093
|
+
return null;
|
|
1094
|
+
if (!interfaceFile.isValueLoaded)
|
|
1095
|
+
return { configValueLoaded: false };
|
|
1096
|
+
const confVal = { configValue: interfaceFile.fileExportsByConfigName[configName], configValueLoaded: true };
|
|
1097
|
+
return confVal;
|
|
1097
1098
|
}
|
|
@@ -37,24 +37,29 @@ function getUrlParsed(pageContext) {
|
|
|
37
37
|
// 6. The value of pageContext.urlPathname is now '/login': the pathname of `pageContext.urlLogical`. (While pageContext.urlOriginal is still '/fr-FR/admin'.)
|
|
38
38
|
// Reproduction: https://github.com/vikejs/vike/discussions/1436#discussioncomment-8142023
|
|
39
39
|
// Determine logical URL
|
|
40
|
+
// TODO/soon: revert https://github.com/vikejs/vike/issues/2138#issuecomment-2631713411
|
|
41
|
+
const assertUrlResolved = (src) => assert(urlResolved && typeof urlResolved === 'string', { src, urlResolved });
|
|
40
42
|
let urlResolved;
|
|
41
43
|
let baseToBeRemoved;
|
|
42
44
|
if (pageContext.urlLogical) {
|
|
43
45
|
// Set by onBeforeRoute()
|
|
44
46
|
urlResolved = pageContext.urlLogical;
|
|
45
47
|
baseToBeRemoved = false;
|
|
48
|
+
assertUrlResolved(1);
|
|
46
49
|
}
|
|
47
50
|
else if (pageContext._urlRewrite) {
|
|
48
51
|
// Set by `throw render()`
|
|
49
52
|
urlResolved = pageContext._urlRewrite;
|
|
50
53
|
baseToBeRemoved = false;
|
|
54
|
+
assertUrlResolved(2);
|
|
51
55
|
}
|
|
52
56
|
else {
|
|
53
57
|
// Set by renderPage()
|
|
54
58
|
urlResolved = pageContext.urlOriginal;
|
|
55
59
|
baseToBeRemoved = true;
|
|
60
|
+
assertUrlResolved(3);
|
|
56
61
|
}
|
|
57
|
-
|
|
62
|
+
assertUrlResolved(4);
|
|
58
63
|
// Remove .pageContext.json
|
|
59
64
|
let urlHandler = pageContext._urlHandler;
|
|
60
65
|
if (!urlHandler)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.220-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.220-commit-5c7810f";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.220-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.220-commit-5c7810f';
|
package/dist/esm/utils/isDev.js
CHANGED
|
@@ -7,7 +7,7 @@ function isDevCheck(configEnv) {
|
|
|
7
7
|
const { isPreview, command } = configEnv;
|
|
8
8
|
// Released at vite@5.1.0 which is guaranteed with `assertVersion('Vite', version, '5.1.0')`
|
|
9
9
|
// - Release: https://github.com/vitejs/vite/blob/6f7466e6211027686f40ad7e4ce6ec8477414546/packages/vite/CHANGELOG.md#510-beta4-2024-01-26:~:text=fix(preview)%3A-,set%20isPreview%20true,-(%2315695)%20(93fce55
|
|
10
|
-
// - Surprisingly, this assert() can fail: https://github.com/vikejs/vike/issues/
|
|
10
|
+
// - Surprisingly, this assert() can fail: https://github.com/vikejs/vike/issues/2135
|
|
11
11
|
assert(typeof isPreview === 'boolean', { isPreview, version });
|
|
12
12
|
return command === 'serve' && !isPreview;
|
|
13
13
|
}
|