vike 0.4.159-commit-a6bc208 → 0.4.159-commit-d73533a
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/getVikeConfig/loadFileConfigEnv.js +129 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +139 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{transformImports.js → getVikeConfig/transformImports.js} +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.js → getVikeConfig/transpileAndExecuteFile.js} +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +54 -262
- package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileConfigEnv.d.ts +21 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileConfigEnv.js +123 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +12 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +133 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{transformImports.js → getVikeConfig/transformImports.js} +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.d.ts → getVikeConfig/transpileAndExecuteFile.d.ts} +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.js → getVikeConfig/transpileAndExecuteFile.js} +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +14 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +50 -258
- package/dist/esm/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
- package/dist/esm/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +1 -1
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{transformImports.d.ts → getVikeConfig/transformImports.d.ts} +0 -0
|
@@ -8,29 +8,28 @@ const utils_js_1 = require("../../../utils.js");
|
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const configDefinitionsBuiltIn_js_1 = require("./getVikeConfig/configDefinitionsBuiltIn.js");
|
|
10
10
|
const filesystemRouting_js_1 = require("./getVikeConfig/filesystemRouting.js");
|
|
11
|
-
const transpileAndExecuteFile_js_1 = require("./transpileAndExecuteFile.js");
|
|
12
|
-
const transformImports_js_1 = require("./transformImports.js");
|
|
11
|
+
const transpileAndExecuteFile_js_1 = require("./getVikeConfig/transpileAndExecuteFile.js");
|
|
13
12
|
const isConfigInvalid_js_1 = require("../../../../runtime/renderPage/isConfigInvalid.js");
|
|
14
13
|
const globalContext_js_1 = require("../../../../runtime/globalContext.js");
|
|
15
14
|
const loggerNotProd_js_1 = require("../../../shared/loggerNotProd.js");
|
|
16
15
|
const removeSuperfluousViteLog_js_1 = require("../../../shared/loggerVite/removeSuperfluousViteLog.js");
|
|
17
16
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
18
17
|
const helpers_js_1 = require("../../../../../shared/page-configs/helpers.js");
|
|
19
|
-
const assertPlusFileExport_js_1 = require("../../../../../shared/page-configs/assertPlusFileExport.js");
|
|
20
18
|
const getConfigVike_js_1 = require("../../../../shared/getConfigVike.js");
|
|
21
19
|
const getConfigValuesSerialized_js_1 = require("./getConfigValuesSerialized.js");
|
|
22
20
|
const crawlPlusFiles_js_1 = require("./getVikeConfig/crawlPlusFiles.js");
|
|
23
21
|
const getConfigFileExport_js_1 = require("./getConfigFileExport.js");
|
|
22
|
+
const loadFileConfigEnv_js_1 = require("./getVikeConfig/loadFileConfigEnv.js");
|
|
23
|
+
const resolveImportPath_js_1 = require("./getVikeConfig/resolveImportPath.js");
|
|
24
24
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
25
25
|
let devServerIsCorrupt = false;
|
|
26
26
|
let wasConfigInvalid = null;
|
|
27
27
|
let vikeConfigPromise = null;
|
|
28
28
|
const vikeConfigDependencies = new Set();
|
|
29
29
|
exports.vikeConfigDependencies = vikeConfigDependencies;
|
|
30
|
-
const filesEnv = new Map();
|
|
31
30
|
function reloadVikeConfig(userRootDir, outDirRoot, extensions) {
|
|
32
31
|
vikeConfigDependencies.clear();
|
|
33
|
-
|
|
32
|
+
(0, resolveImportPath_js_1.clearFilesEnvMap)();
|
|
34
33
|
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, true, extensions, true);
|
|
35
34
|
handleReloadSideEffects();
|
|
36
35
|
}
|
|
@@ -90,7 +89,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
90
89
|
let interfaceFilesByLocationId = {};
|
|
91
90
|
// Config files
|
|
92
91
|
await Promise.all(configFiles.map(async (filePath) => {
|
|
93
|
-
const { configFile, extendsConfigs } = await loadConfigFile(filePath, userRootDir, [], false);
|
|
92
|
+
const { configFile, extendsConfigs } = await (0, loadFileConfigEnv_js_1.loadConfigFile)(filePath, userRootDir, [], false);
|
|
94
93
|
const interfaceFile = getInterfaceFileFromConfigFile(configFile, false);
|
|
95
94
|
const locationId = (0, filesystemRouting_js_1.getLocationId)(filePath.filePathAbsoluteVite);
|
|
96
95
|
interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
|
|
@@ -106,7 +105,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
106
105
|
(0, utils_js_1.assert)(configName);
|
|
107
106
|
const interfaceFile = {
|
|
108
107
|
filePath,
|
|
109
|
-
|
|
108
|
+
fileExportsByConfigName: {
|
|
110
109
|
[configName]: {}
|
|
111
110
|
},
|
|
112
111
|
isConfigFile: false,
|
|
@@ -119,7 +118,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
119
118
|
// - We already need to load +meta.js here (to get the custom config definitions defined by the user)
|
|
120
119
|
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn, configName);
|
|
121
120
|
if (configDef && isConfigEnv(configDef, configName)) {
|
|
122
|
-
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
121
|
+
await (0, loadFileConfigEnv_js_1.loadValueFile)(interfaceFile, configName, userRootDir);
|
|
123
122
|
}
|
|
124
123
|
}
|
|
125
124
|
{
|
|
@@ -140,23 +139,6 @@ function getConfigDefinition(configDefinitionsRelevant, configName, filePathToSh
|
|
|
140
139
|
function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
141
140
|
return configDefinitions[configName] ?? null;
|
|
142
141
|
}
|
|
143
|
-
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
144
|
-
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath, true, userRootDir);
|
|
145
|
-
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
146
|
-
(0, assertPlusFileExport_js_1.assertPlusFileExport)(fileExports, filePathToShowToUser, configName);
|
|
147
|
-
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
148
|
-
const configName_ = exportName === 'default' ? configName : exportName;
|
|
149
|
-
interfaceValueFile.configMap[configName_] = { configValue };
|
|
150
|
-
});
|
|
151
|
-
}
|
|
152
|
-
async function loadImportedFile(filePath, userRootDir, importedFilesLoaded) {
|
|
153
|
-
const f = filePath.filePathAbsoluteFilesystem;
|
|
154
|
-
if (!importedFilesLoaded[f]) {
|
|
155
|
-
importedFilesLoaded[f] = (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(filePath, true, userRootDir).then((r) => r.fileExports);
|
|
156
|
-
}
|
|
157
|
-
const fileExports = await importedFilesLoaded[f];
|
|
158
|
-
return fileExports;
|
|
159
|
-
}
|
|
160
142
|
function isConfigEnv(configDef, configName) {
|
|
161
143
|
const configEnv = configDef.env;
|
|
162
144
|
if (configDef.cumulative) {
|
|
@@ -169,7 +151,7 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
169
151
|
const { fileExports, filePath, extendsFilePaths } = configFile;
|
|
170
152
|
const interfaceFile = {
|
|
171
153
|
filePath,
|
|
172
|
-
|
|
154
|
+
fileExportsByConfigName: {},
|
|
173
155
|
isConfigFile: true,
|
|
174
156
|
isValueFile: false,
|
|
175
157
|
isConfigExtend,
|
|
@@ -177,7 +159,7 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
177
159
|
};
|
|
178
160
|
const fileExport = (0, getConfigFileExport_js_1.getConfigFileExport)(fileExports, filePath.filePathToShowToUser);
|
|
179
161
|
Object.entries(fileExport).forEach(([configName, configValue]) => {
|
|
180
|
-
interfaceFile.
|
|
162
|
+
interfaceFile.fileExportsByConfigName[configName] = { configValue };
|
|
181
163
|
});
|
|
182
164
|
return interfaceFile;
|
|
183
165
|
}
|
|
@@ -187,7 +169,7 @@ function assertAllConfigsAreKnown(interfaceFilesByLocationId) {
|
|
|
187
169
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesByLocationId, locationId);
|
|
188
170
|
const configDefinitionsRelevant = getConfigDefinitions(interfaceFilesRelevant);
|
|
189
171
|
interfaceFiles.forEach((interfaceFile) => {
|
|
190
|
-
Object.keys(interfaceFile.
|
|
172
|
+
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
191
173
|
assertConfigExists(configName, Object.keys(configDefinitionsRelevant), interfaceFile.filePath.filePathToShowToUser);
|
|
192
174
|
});
|
|
193
175
|
});
|
|
@@ -258,7 +240,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
258
240
|
return;
|
|
259
241
|
// Value files of built-in configs should have already been loaded at loadInterfaceFiles()
|
|
260
242
|
(0, utils_js_1.assert)(!(configName in configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn));
|
|
261
|
-
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
243
|
+
await (0, loadFileConfigEnv_js_1.loadValueFile)(interfaceFile, configName, userRootDir);
|
|
262
244
|
}));
|
|
263
245
|
const configValueSources = {};
|
|
264
246
|
await Promise.all((0, utils_js_1.objectEntries)(configDefinitionsRelevant)
|
|
@@ -301,7 +283,7 @@ function assertOnBeforeRenderEnv(pageConfig) {
|
|
|
301
283
|
(0, utils_js_1.assertUsage)(!(onBeforeRenderEnv.client && !isClientRouting), `Page ${pageConfig.pageId} has an onBeforeRender() hook with env ${picocolors_1.default.cyan(JSON.stringify(onBeforeRenderEnv))} which doesn't make sense because the page is using Server Routing: onBeforeRender() can be run in the client only when using Client Routing.`);
|
|
302
284
|
}
|
|
303
285
|
function interfacefileIsAlreaydLoaded(interfaceFile) {
|
|
304
|
-
const configMapValues = Object.values(interfaceFile.
|
|
286
|
+
const configMapValues = Object.values(interfaceFile.fileExportsByConfigName);
|
|
305
287
|
const isAlreadyLoaded = configMapValues.some((conf) => 'configValue' in conf);
|
|
306
288
|
if (isAlreadyLoaded) {
|
|
307
289
|
(0, utils_js_1.assert)(configMapValues.every((conf) => 'configValue' in conf));
|
|
@@ -342,7 +324,7 @@ async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importe
|
|
|
342
324
|
const globalPaths = Array.from(new Set(interfaceFilesGlobalPaths.map((p) => path_1.default.posix.dirname(p))));
|
|
343
325
|
Object.entries(interfaceFilesByLocationId).forEach(([locationId, interfaceFiles]) => {
|
|
344
326
|
interfaceFiles.forEach((interfaceFile) => {
|
|
345
|
-
Object.keys(interfaceFile.
|
|
327
|
+
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
346
328
|
if (!(0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds) && isGlobalConfig(configName)) {
|
|
347
329
|
(0, utils_js_1.assertUsage)(false, [
|
|
348
330
|
`${interfaceFile.filePath.filePathToShowToUser} defines the config ${picocolors_1.default.cyan(configName)} which is global:`,
|
|
@@ -383,7 +365,7 @@ async function resolveConfigValueSources(configName, configDef, interfaceFilesRe
|
|
|
383
365
|
const sourcesInfo = [];
|
|
384
366
|
// interfaceFilesRelevant is sorted by sortAfterInheritanceOrder()
|
|
385
367
|
for (const interfaceFiles of Object.values(interfaceFilesRelevant)) {
|
|
386
|
-
const interfaceFilesDefiningConfig = interfaceFiles.filter((interfaceFile) => interfaceFile.
|
|
368
|
+
const interfaceFilesDefiningConfig = interfaceFiles.filter((interfaceFile) => interfaceFile.fileExportsByConfigName[configName]);
|
|
387
369
|
if (interfaceFilesDefiningConfig.length === 0)
|
|
388
370
|
continue;
|
|
389
371
|
const visited = new WeakSet();
|
|
@@ -461,19 +443,20 @@ function isInterfaceFileUserLand(interfaceFile) {
|
|
|
461
443
|
return (interfaceFile.isConfigFile && !interfaceFile.isConfigExtend) || interfaceFile.isValueFile;
|
|
462
444
|
}
|
|
463
445
|
async function getConfigValueSource(configName, interfaceFile, configDef, userRootDir, importedFilesLoaded) {
|
|
464
|
-
const conf = interfaceFile.
|
|
446
|
+
const conf = interfaceFile.fileExportsByConfigName[configName];
|
|
465
447
|
(0, utils_js_1.assert)(conf);
|
|
466
448
|
const configEnv = configDef.env;
|
|
467
449
|
const definedAtConfigFile = {
|
|
468
450
|
...interfaceFile.filePath,
|
|
469
451
|
fileExportPathToShowToUser: ['default', configName]
|
|
470
452
|
};
|
|
453
|
+
// +client.js
|
|
471
454
|
if (configDef._valueIsFilePath) {
|
|
472
455
|
let definedAt;
|
|
473
456
|
let valueFilePath;
|
|
474
457
|
if (interfaceFile.isConfigFile) {
|
|
475
458
|
const { configValue } = conf;
|
|
476
|
-
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
459
|
+
const import_ = (0, resolveImportPath_js_1.resolveImport)(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
477
460
|
const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, { definedAt: definedAtConfigFile });
|
|
478
461
|
(0, utils_js_1.assertUsage)(import_, `${configDefinedAt} should be an import`);
|
|
479
462
|
valueFilePath = import_.filePathAbsoluteVite;
|
|
@@ -496,22 +479,26 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
496
479
|
};
|
|
497
480
|
return configValueSource;
|
|
498
481
|
}
|
|
482
|
+
// +config.js
|
|
499
483
|
if (interfaceFile.isConfigFile) {
|
|
500
484
|
(0, utils_js_1.assert)('configValue' in conf);
|
|
501
485
|
const { configValue } = conf;
|
|
502
|
-
|
|
486
|
+
// fake import
|
|
487
|
+
const import_ = (0, resolveImportPath_js_1.resolveImport)(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
503
488
|
if (import_) {
|
|
504
489
|
const configValueSource = {
|
|
505
490
|
configEnv,
|
|
506
491
|
valueIsImportedAtRuntime: true,
|
|
507
492
|
definedAt: import_
|
|
508
493
|
};
|
|
509
|
-
// Load
|
|
510
|
-
if (isConfigEnv(configDef, configName)
|
|
494
|
+
// Load fake import
|
|
495
|
+
if (isConfigEnv(configDef, configName) &&
|
|
496
|
+
// The value of `extends` was already loaded and already used: we don't need the value of `extends` anymore
|
|
497
|
+
configName !== 'extends') {
|
|
511
498
|
if (import_.filePathAbsoluteFilesystem) {
|
|
512
499
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(import_, 'filePathAbsoluteFilesystem', 'string')); // Help TS
|
|
513
|
-
const
|
|
514
|
-
configValueSource.value =
|
|
500
|
+
const fileExport = await (0, loadFileConfigEnv_js_1.loadImportedFile)(import_, userRootDir, importedFilesLoaded);
|
|
501
|
+
configValueSource.value = fileExport;
|
|
515
502
|
}
|
|
516
503
|
else {
|
|
517
504
|
const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configValueSource);
|
|
@@ -520,17 +507,17 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
520
507
|
}
|
|
521
508
|
return configValueSource;
|
|
522
509
|
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
}
|
|
510
|
+
// Defined by config file, i.e. +config.js file
|
|
511
|
+
const configValueSource = {
|
|
512
|
+
value: configValue,
|
|
513
|
+
configEnv,
|
|
514
|
+
valueIsImportedAtRuntime: false,
|
|
515
|
+
definedAt: definedAtConfigFile
|
|
516
|
+
};
|
|
517
|
+
return configValueSource;
|
|
532
518
|
}
|
|
533
|
-
|
|
519
|
+
// Defined by value file, i.e. +{configName}.js
|
|
520
|
+
if (interfaceFile.isValueFile) {
|
|
534
521
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
535
522
|
(0, utils_js_1.assert)(valueAlreadyLoaded === !!configEnv.config);
|
|
536
523
|
const configValueSource = {
|
|
@@ -551,25 +538,9 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
551
538
|
}
|
|
552
539
|
(0, utils_js_1.assert)(false);
|
|
553
540
|
}
|
|
554
|
-
function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
|
|
555
|
-
(0, utils_js_1.assertPosixPath)(filePathForEnvCheck);
|
|
556
|
-
if (!filesEnv.has(filePathForEnvCheck)) {
|
|
557
|
-
filesEnv.set(filePathForEnvCheck, []);
|
|
558
|
-
}
|
|
559
|
-
const fileEnv = filesEnv.get(filePathForEnvCheck);
|
|
560
|
-
fileEnv.push({ configEnv, configName });
|
|
561
|
-
const configDifferentEnv = fileEnv.filter((c) => !(0, utils_js_1.deepEqual)(c.configEnv, configEnv))[0];
|
|
562
|
-
if (configDifferentEnv) {
|
|
563
|
-
(0, utils_js_1.assertUsage)(false, [
|
|
564
|
-
`${filePathForEnvCheck} defines the value of configs living in different environments:`,
|
|
565
|
-
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${picocolors_1.default.cyan(c.configName)} which value lives in environment ${picocolors_1.default.cyan(JSON.stringify(c.configEnv))}`),
|
|
566
|
-
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/header-file'
|
|
567
|
-
].join('\n'));
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
541
|
function isDefiningPage(interfaceFiles) {
|
|
571
542
|
for (const interfaceFile of interfaceFiles) {
|
|
572
|
-
const configNames = Object.keys(interfaceFile.
|
|
543
|
+
const configNames = Object.keys(interfaceFile.fileExportsByConfigName);
|
|
573
544
|
if (configNames.some((configName) => isDefiningPageConfig(configName))) {
|
|
574
545
|
return true;
|
|
575
546
|
}
|
|
@@ -579,90 +550,11 @@ function isDefiningPage(interfaceFiles) {
|
|
|
579
550
|
function isDefiningPageConfig(configName) {
|
|
580
551
|
return ['Page', 'route'].includes(configName);
|
|
581
552
|
}
|
|
582
|
-
function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
583
|
-
if (typeof configValue !== 'string')
|
|
584
|
-
return null;
|
|
585
|
-
const importData = (0, transformImports_js_1.parseImportData)(configValue);
|
|
586
|
-
if (!importData)
|
|
587
|
-
return null;
|
|
588
|
-
const { importPath, exportName } = importData;
|
|
589
|
-
const filePathAbsoluteFilesystem = resolveImportPath(importData, importerFilePath);
|
|
590
|
-
assertFileEnv(filePathAbsoluteFilesystem ?? importPath, configEnv, configName);
|
|
591
|
-
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
592
|
-
if (importPath.startsWith('.')) {
|
|
593
|
-
// We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
|
|
594
|
-
// ```
|
|
595
|
-
// [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
|
|
596
|
-
// ```
|
|
597
|
-
assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
|
|
598
|
-
const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, importerFilePath, userRootDir);
|
|
599
|
-
const filePath = {
|
|
600
|
-
filePathAbsoluteFilesystem,
|
|
601
|
-
filePathRelativeToUserRootDir,
|
|
602
|
-
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
603
|
-
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
604
|
-
importPathAbsolute: null
|
|
605
|
-
};
|
|
606
|
-
return {
|
|
607
|
-
...filePath,
|
|
608
|
-
fileExportName: exportName,
|
|
609
|
-
fileExportPathToShowToUser
|
|
610
|
-
};
|
|
611
|
-
}
|
|
612
|
-
else {
|
|
613
|
-
// importPath can be:
|
|
614
|
-
// - an npm package import
|
|
615
|
-
// - a path alias
|
|
616
|
-
const filePath = {
|
|
617
|
-
filePathAbsoluteFilesystem,
|
|
618
|
-
filePathRelativeToUserRootDir: null,
|
|
619
|
-
filePathAbsoluteVite: importPath,
|
|
620
|
-
filePathToShowToUser: importPath,
|
|
621
|
-
importPathAbsolute: importPath
|
|
622
|
-
};
|
|
623
|
-
return {
|
|
624
|
-
...filePath,
|
|
625
|
-
fileExportName: exportName,
|
|
626
|
-
fileExportPathToShowToUser
|
|
627
|
-
};
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
|
|
631
|
-
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
632
|
-
let filePathRelativeToUserRootDir;
|
|
633
|
-
if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
634
|
-
filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, userRootDir);
|
|
635
|
-
}
|
|
636
|
-
else {
|
|
637
|
-
(0, utils_js_1.assertUsage)(false, `${configFilePath.filePathToShowToUser} imports from a relative path ${picocolors_1.default.cyan(importData.importPath)} outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
|
|
638
|
-
// None of the following works. Seems to be a Vite bug?
|
|
639
|
-
// /*
|
|
640
|
-
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
641
|
-
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
642
|
-
// /*/
|
|
643
|
-
// filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem)
|
|
644
|
-
// assert(filePathRelativeToUserRootDir.startsWith('../'))
|
|
645
|
-
// filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir
|
|
646
|
-
// //*/
|
|
647
|
-
}
|
|
648
|
-
(0, utils_js_1.assertPosixPath)(filePathRelativeToUserRootDir);
|
|
649
|
-
(0, utils_js_1.assert)(filePathRelativeToUserRootDir.startsWith('/'));
|
|
650
|
-
return filePathRelativeToUserRootDir;
|
|
651
|
-
}
|
|
652
|
-
function getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, root) {
|
|
653
|
-
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
654
|
-
(0, utils_js_1.assertPosixPath)(root);
|
|
655
|
-
(0, utils_js_1.assert)(filePathAbsoluteFilesystem.startsWith(root));
|
|
656
|
-
let vitePath = path_1.default.posix.relative(root, filePathAbsoluteFilesystem);
|
|
657
|
-
(0, utils_js_1.assert)(!vitePath.startsWith('/') && !vitePath.startsWith('.'));
|
|
658
|
-
vitePath = '/' + vitePath;
|
|
659
|
-
return vitePath;
|
|
660
|
-
}
|
|
661
553
|
function getConfigDefinitions(interfaceFilesRelevant) {
|
|
662
554
|
const configDefinitions = { ...configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn };
|
|
663
555
|
Object.entries(interfaceFilesRelevant).forEach(([_locationId, interfaceFiles]) => {
|
|
664
556
|
interfaceFiles.forEach((interfaceFile) => {
|
|
665
|
-
const configMeta = interfaceFile.
|
|
557
|
+
const configMeta = interfaceFile.fileExportsByConfigName['meta'];
|
|
666
558
|
if (!configMeta)
|
|
667
559
|
return;
|
|
668
560
|
const meta = configMeta.configValue;
|
|
@@ -845,96 +737,22 @@ function getConfigName(filePath) {
|
|
|
845
737
|
return configName;
|
|
846
738
|
}
|
|
847
739
|
}
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
const
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
const idx = visited.indexOf(filePathAbsoluteFilesystem);
|
|
865
|
-
if (idx === -1)
|
|
866
|
-
return;
|
|
867
|
-
const loop = visited.slice(idx);
|
|
868
|
-
(0, utils_js_1.assert)(loop[0] === filePathAbsoluteFilesystem);
|
|
869
|
-
(0, utils_js_1.assertUsage)(idx === -1, `Infinite extends loop ${[...loop, filePathAbsoluteFilesystem].join('>')}`);
|
|
870
|
-
}
|
|
871
|
-
async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir, visited) {
|
|
872
|
-
const extendsImportData = getExtendsImportData(configFileExports, configFilePath);
|
|
873
|
-
const extendsConfigFiles = [];
|
|
874
|
-
extendsImportData.map((importData) => {
|
|
875
|
-
const { importPath: importPath } = importData;
|
|
876
|
-
const filePathAbsoluteFilesystem = resolveImportPath(importData, configFilePath);
|
|
877
|
-
assertImportPath(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
878
|
-
warnUserLandExtension(importPath, configFilePath);
|
|
879
|
-
// - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
|
|
880
|
-
// - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsoluteFilesystem for added clarity
|
|
881
|
-
const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir);
|
|
882
|
-
const filePathAbsoluteVite = filePathRelativeToUserRootDir ?? importPath;
|
|
883
|
-
extendsConfigFiles.push({
|
|
884
|
-
filePathAbsoluteFilesystem,
|
|
885
|
-
filePathAbsoluteVite,
|
|
886
|
-
filePathRelativeToUserRootDir,
|
|
887
|
-
filePathToShowToUser: filePathAbsoluteVite,
|
|
888
|
-
importPathAbsolute: importPath
|
|
889
|
-
});
|
|
890
|
-
});
|
|
891
|
-
const extendsConfigs = [];
|
|
892
|
-
await Promise.all(extendsConfigFiles.map(async (configFilePath) => {
|
|
893
|
-
const result = await loadConfigFile(configFilePath, userRootDir, visited, true);
|
|
894
|
-
extendsConfigs.push(result.configFile);
|
|
895
|
-
extendsConfigs.push(...result.extendsConfigs);
|
|
896
|
-
}));
|
|
897
|
-
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
898
|
-
return { extendsConfigs, extendsFilePaths };
|
|
899
|
-
}
|
|
900
|
-
function determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir) {
|
|
901
|
-
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
902
|
-
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
903
|
-
if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
904
|
-
return null;
|
|
905
|
-
}
|
|
906
|
-
let filePathRelativeToUserRootDir = filePathAbsoluteFilesystem.slice(userRootDir.length);
|
|
907
|
-
if (!filePathRelativeToUserRootDir.startsWith('/'))
|
|
908
|
-
filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
|
|
909
|
-
return filePathRelativeToUserRootDir;
|
|
910
|
-
}
|
|
911
|
-
function warnUserLandExtension(importPath, configFilePath) {
|
|
912
|
-
(0, utils_js_1.assertWarning)((0, utils_js_1.isNpmPackageImport)(importPath), `${configFilePath.filePathToShowToUser} uses ${picocolors_1.default.cyan('extends')} to inherit from ${picocolors_1.default.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this.`, { onlyOnce: true });
|
|
913
|
-
}
|
|
914
|
-
function getExtendsImportData(configFileExports, configFilePath) {
|
|
915
|
-
const { filePathToShowToUser } = configFilePath;
|
|
916
|
-
const configFileExport = (0, getConfigFileExport_js_1.getConfigFileExport)(configFileExports, filePathToShowToUser);
|
|
917
|
-
const wrongUsage = `${filePathToShowToUser} sets the config ${picocolors_1.default.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
|
|
918
|
-
let extendList;
|
|
919
|
-
if (!('extends' in configFileExport)) {
|
|
920
|
-
return [];
|
|
921
|
-
}
|
|
922
|
-
else if ((0, utils_js_1.hasProp)(configFileExport, 'extends', 'string')) {
|
|
923
|
-
extendList = [configFileExport.extends];
|
|
924
|
-
}
|
|
925
|
-
else if ((0, utils_js_1.hasProp)(configFileExport, 'extends', 'string[]')) {
|
|
926
|
-
extendList = configFileExport.extends;
|
|
927
|
-
}
|
|
928
|
-
else {
|
|
929
|
-
(0, utils_js_1.assertUsage)(false, wrongUsage);
|
|
930
|
-
}
|
|
931
|
-
const extendsImportData = extendList.map((importDataSerialized) => {
|
|
932
|
-
const importData = (0, transformImports_js_1.parseImportData)(importDataSerialized);
|
|
933
|
-
(0, utils_js_1.assertUsage)(importData, wrongUsage);
|
|
934
|
-
return importData;
|
|
935
|
-
});
|
|
936
|
-
return extendsImportData;
|
|
937
|
-
}
|
|
740
|
+
/* https://github.com/vikejs/vike/issues/1407
|
|
741
|
+
function assertNoUnexpectedPlusSign(filePath: string, fileName: string) {
|
|
742
|
+
const dirs = path.posix.dirname(filePath).split('/')
|
|
743
|
+
dirs.forEach((dir, i) => {
|
|
744
|
+
const dirPath = dirs.slice(0, i + 1).join('/')
|
|
745
|
+
assertUsage(
|
|
746
|
+
!dir.includes('+'),
|
|
747
|
+
`Character '+' is a reserved character: remove '+' from the directory name ${dirPath}/`
|
|
748
|
+
)
|
|
749
|
+
})
|
|
750
|
+
assertUsage(
|
|
751
|
+
!fileName.slice(1).includes('+'),
|
|
752
|
+
`Character '+' is only allowed at the beginning of filenames: make sure ${filePath} doesn't contain any '+' in its filename other than its first letter`
|
|
753
|
+
)
|
|
754
|
+
}
|
|
755
|
+
*/
|
|
938
756
|
function isGlobalConfig(configName) {
|
|
939
757
|
if (configName === 'prerender')
|
|
940
758
|
return false;
|
|
@@ -1017,32 +835,6 @@ function determineIsErrorPage(routeFilesystem) {
|
|
|
1017
835
|
(0, utils_js_1.assertPosixPath)(routeFilesystem);
|
|
1018
836
|
return routeFilesystem.split('/').includes('_error');
|
|
1019
837
|
}
|
|
1020
|
-
function resolveImportPath(importData, importerFilePath) {
|
|
1021
|
-
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
1022
|
-
(0, utils_js_1.assertPosixPath)(importerFilePathAbsolute);
|
|
1023
|
-
const cwd = path_1.default.posix.dirname(importerFilePathAbsolute);
|
|
1024
|
-
// We can't use import.meta.resolve() as of Junary 2023 (and probably for a lot longer): https://stackoverflow.com/questions/54977743/do-require-resolve-for-es-modules#comment137174954_62272600:~:text=But%20the%20argument%20parent%20(aka%20cwd)%20still%20requires%20a%20flag
|
|
1025
|
-
// filePathAbsoluteFilesystem is expected to be null when importData.importPath is a Vite path alias
|
|
1026
|
-
const filePathAbsoluteFilesystem = (0, utils_js_1.requireResolve)(importData.importPath, cwd);
|
|
1027
|
-
return filePathAbsoluteFilesystem;
|
|
1028
|
-
}
|
|
1029
|
-
function assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath) {
|
|
1030
|
-
const { importPath: importPath, importStringWasGenerated, importString } = importData;
|
|
1031
|
-
const { filePathToShowToUser } = importerFilePath;
|
|
1032
|
-
if (!filePathAbsoluteFilesystem) {
|
|
1033
|
-
const importPathString = picocolors_1.default.cyan(`'${importPath}'`);
|
|
1034
|
-
const errIntro = importStringWasGenerated
|
|
1035
|
-
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
1036
|
-
: `The import ${picocolors_1.default.cyan(importString)} defined in ${filePathToShowToUser}`;
|
|
1037
|
-
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
1038
|
-
if (importPath.startsWith('.')) {
|
|
1039
|
-
(0, utils_js_1.assertUsage)(false, `${errIntro2} point to an existing file?`);
|
|
1040
|
-
}
|
|
1041
|
-
else {
|
|
1042
|
-
(0, utils_js_1.assertUsage)(false, `${errIntro2} exist?`);
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
}
|
|
1046
838
|
function isVikeConfigFile(filePath) {
|
|
1047
839
|
return !!getConfigName(filePath);
|
|
1048
840
|
}
|
|
@@ -29,7 +29,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
29
29
|
exports.installHttpRequestAsyncStore = exports.getHttpRequestAsyncStore = void 0;
|
|
30
30
|
const renderPage_js_1 = require("../../runtime/renderPage.js");
|
|
31
31
|
const utils_js_1 = require("../utils.js");
|
|
32
|
-
const transpileAndExecuteFile_js_1 = require("../plugins/importUserCode/v1-design/transpileAndExecuteFile.js");
|
|
32
|
+
const transpileAndExecuteFile_js_1 = require("../plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js");
|
|
33
33
|
const loggerNotProd_js_1 = require("./loggerNotProd.js");
|
|
34
34
|
const errorWithCodeSnippet_js_1 = require("./loggerNotProd/errorWithCodeSnippet.js");
|
|
35
35
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
@@ -17,7 +17,7 @@ const utils_js_1 = require("../utils.js");
|
|
|
17
17
|
const getHttpRequestAsyncStore_js_1 = require("./getHttpRequestAsyncStore.js");
|
|
18
18
|
const isErrorDebug_js_1 = require("./isErrorDebug.js");
|
|
19
19
|
const errorWithCodeSnippet_js_1 = require("./loggerNotProd/errorWithCodeSnippet.js");
|
|
20
|
-
const transpileAndExecuteFile_js_1 = require("../plugins/importUserCode/v1-design/transpileAndExecuteFile.js");
|
|
20
|
+
const transpileAndExecuteFile_js_1 = require("../plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js");
|
|
21
21
|
const log_js_1 = require("./loggerNotProd/log.js");
|
|
22
22
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
23
23
|
const isNewError_js_1 = require("../../runtime/renderPage/isNewError.js");
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PROJECT_VERSION = exports.projectInfo = void 0;
|
|
4
4
|
const assertSingleInstance_js_1 = require("./assertSingleInstance.js");
|
|
5
|
-
const PROJECT_VERSION = '0.4.159-commit-
|
|
5
|
+
const PROJECT_VERSION = '0.4.159-commit-d73533a';
|
|
6
6
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
7
7
|
const projectInfo = {
|
|
8
8
|
projectName: 'Vike',
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileConfigEnv.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { loadImportedFile };
|
|
2
|
+
export { loadValueFile };
|
|
3
|
+
export { loadConfigFile };
|
|
4
|
+
export type { ImportedFilesLoaded };
|
|
5
|
+
export type { ConfigFile };
|
|
6
|
+
import type { FilePathResolved } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
7
|
+
import type { InterfaceValueFile } from '../getVikeConfig.js';
|
|
8
|
+
type ImportedFilesLoaded = Record<string, Promise<Record<string, unknown>>>;
|
|
9
|
+
type ConfigFile = {
|
|
10
|
+
fileExports: Record<string, unknown>;
|
|
11
|
+
filePath: FilePathResolved;
|
|
12
|
+
extendsFilePaths: string[];
|
|
13
|
+
};
|
|
14
|
+
declare function loadImportedFile(import_: FilePathResolved & {
|
|
15
|
+
fileExportName: string;
|
|
16
|
+
}, userRootDir: string, importedFilesLoaded: ImportedFilesLoaded): Promise<unknown>;
|
|
17
|
+
declare function loadValueFile(interfaceValueFile: InterfaceValueFile, configName: string, userRootDir: string): Promise<void>;
|
|
18
|
+
declare function loadConfigFile(configFilePath: FilePathResolved, userRootDir: string, visited: string[], isConfigOfExtension: boolean): Promise<{
|
|
19
|
+
configFile: ConfigFile;
|
|
20
|
+
extendsConfigs: ConfigFile[];
|
|
21
|
+
}>;
|