vike 0.4.159-commit-0424983 → 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} +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.js → getVikeConfig/transpileAndExecuteFile.js} +43 -29
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +54 -274
- 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} +3 -3
- 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} +44 -30
- 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 -270
- 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
|
@@ -2,32 +2,31 @@ export { getVikeConfig };
|
|
|
2
2
|
export { reloadVikeConfig };
|
|
3
3
|
export { vikeConfigDependencies };
|
|
4
4
|
export { isVikeConfigFile };
|
|
5
|
-
import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEntries, hasProp, arrayIncludes, assertIsNotProductionRuntime, getMostSimilar,
|
|
5
|
+
import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEntries, hasProp, arrayIncludes, assertIsNotProductionRuntime, getMostSimilar, joinEnglish, lowerFirst, mergeCumulativeValues, getOutDirs, assertKeys } from '../../../utils.js';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { configDefinitionsBuiltIn, configDefinitionsBuiltInGlobal } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
8
8
|
import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, isGlobalLocation, applyFilesystemRoutingRootEffect } from './getVikeConfig/filesystemRouting.js';
|
|
9
|
-
import { isTmpFile
|
|
10
|
-
import { parseImportData } from './transformImports.js';
|
|
9
|
+
import { isTmpFile } from './getVikeConfig/transpileAndExecuteFile.js';
|
|
11
10
|
import { isConfigInvalid, isConfigInvalid_set } from '../../../../runtime/renderPage/isConfigInvalid.js';
|
|
12
11
|
import { getViteDevServer } from '../../../../runtime/globalContext.js';
|
|
13
12
|
import { logConfigError, logConfigErrorRecover } from '../../../shared/loggerNotProd.js';
|
|
14
13
|
import { removeSuperfluousViteLog_enable, removeSuperfluousViteLog_disable } from '../../../shared/loggerVite/removeSuperfluousViteLog.js';
|
|
15
14
|
import pc from '@brillout/picocolors';
|
|
16
15
|
import { getConfigDefinedAtString } from '../../../../../shared/page-configs/helpers.js';
|
|
17
|
-
import { assertPlusFileExport } from '../../../../../shared/page-configs/assertPlusFileExport.js';
|
|
18
16
|
import { getConfigVike } from '../../../../shared/getConfigVike.js';
|
|
19
17
|
import { assertConfigValueIsSerializable } from './getConfigValuesSerialized.js';
|
|
20
18
|
import { crawlPlusFiles } from './getVikeConfig/crawlPlusFiles.js';
|
|
21
19
|
import { getConfigFileExport } from './getConfigFileExport.js';
|
|
20
|
+
import { loadConfigFile, loadImportedFile, loadValueFile } from './getVikeConfig/loadFileConfigEnv.js';
|
|
21
|
+
import { clearFilesEnvMap, resolveImport } from './getVikeConfig/resolveImportPath.js';
|
|
22
22
|
assertIsNotProductionRuntime();
|
|
23
23
|
let devServerIsCorrupt = false;
|
|
24
24
|
let wasConfigInvalid = null;
|
|
25
25
|
let vikeConfigPromise = null;
|
|
26
26
|
const vikeConfigDependencies = new Set();
|
|
27
|
-
const filesEnv = new Map();
|
|
28
27
|
function reloadVikeConfig(userRootDir, outDirRoot, extensions) {
|
|
29
28
|
vikeConfigDependencies.clear();
|
|
30
|
-
|
|
29
|
+
clearFilesEnvMap();
|
|
31
30
|
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, true, extensions, true);
|
|
32
31
|
handleReloadSideEffects();
|
|
33
32
|
}
|
|
@@ -101,7 +100,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
101
100
|
assert(configName);
|
|
102
101
|
const interfaceFile = {
|
|
103
102
|
filePath,
|
|
104
|
-
|
|
103
|
+
fileExportsByConfigName: {
|
|
105
104
|
[configName]: {}
|
|
106
105
|
},
|
|
107
106
|
isConfigFile: false,
|
|
@@ -135,23 +134,6 @@ function getConfigDefinition(configDefinitionsRelevant, configName, filePathToSh
|
|
|
135
134
|
function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
136
135
|
return configDefinitions[configName] ?? null;
|
|
137
136
|
}
|
|
138
|
-
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
139
|
-
const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath, true, userRootDir);
|
|
140
|
-
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
141
|
-
assertPlusFileExport(fileExports, filePathToShowToUser, configName);
|
|
142
|
-
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
143
|
-
const configName_ = exportName === 'default' ? configName : exportName;
|
|
144
|
-
interfaceValueFile.configMap[configName_] = { configValue };
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
async function loadImportedFile(filePath, userRootDir, importedFilesLoaded) {
|
|
148
|
-
const f = filePath.filePathAbsoluteFilesystem;
|
|
149
|
-
if (!importedFilesLoaded[f]) {
|
|
150
|
-
importedFilesLoaded[f] = transpileAndExecuteFile(filePath, true, userRootDir).then((r) => r.fileExports);
|
|
151
|
-
}
|
|
152
|
-
const fileExports = await importedFilesLoaded[f];
|
|
153
|
-
return fileExports;
|
|
154
|
-
}
|
|
155
137
|
function isConfigEnv(configDef, configName) {
|
|
156
138
|
const configEnv = configDef.env;
|
|
157
139
|
if (configDef.cumulative) {
|
|
@@ -164,7 +146,7 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
164
146
|
const { fileExports, filePath, extendsFilePaths } = configFile;
|
|
165
147
|
const interfaceFile = {
|
|
166
148
|
filePath,
|
|
167
|
-
|
|
149
|
+
fileExportsByConfigName: {},
|
|
168
150
|
isConfigFile: true,
|
|
169
151
|
isValueFile: false,
|
|
170
152
|
isConfigExtend,
|
|
@@ -172,7 +154,7 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
172
154
|
};
|
|
173
155
|
const fileExport = getConfigFileExport(fileExports, filePath.filePathToShowToUser);
|
|
174
156
|
Object.entries(fileExport).forEach(([configName, configValue]) => {
|
|
175
|
-
interfaceFile.
|
|
157
|
+
interfaceFile.fileExportsByConfigName[configName] = { configValue };
|
|
176
158
|
});
|
|
177
159
|
return interfaceFile;
|
|
178
160
|
}
|
|
@@ -182,7 +164,7 @@ function assertAllConfigsAreKnown(interfaceFilesByLocationId) {
|
|
|
182
164
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesByLocationId, locationId);
|
|
183
165
|
const configDefinitionsRelevant = getConfigDefinitions(interfaceFilesRelevant);
|
|
184
166
|
interfaceFiles.forEach((interfaceFile) => {
|
|
185
|
-
Object.keys(interfaceFile.
|
|
167
|
+
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
186
168
|
assertConfigExists(configName, Object.keys(configDefinitionsRelevant), interfaceFile.filePath.filePathToShowToUser);
|
|
187
169
|
});
|
|
188
170
|
});
|
|
@@ -296,7 +278,7 @@ function assertOnBeforeRenderEnv(pageConfig) {
|
|
|
296
278
|
assertUsage(!(onBeforeRenderEnv.client && !isClientRouting), `Page ${pageConfig.pageId} has an onBeforeRender() hook with env ${pc.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.`);
|
|
297
279
|
}
|
|
298
280
|
function interfacefileIsAlreaydLoaded(interfaceFile) {
|
|
299
|
-
const configMapValues = Object.values(interfaceFile.
|
|
281
|
+
const configMapValues = Object.values(interfaceFile.fileExportsByConfigName);
|
|
300
282
|
const isAlreadyLoaded = configMapValues.some((conf) => 'configValue' in conf);
|
|
301
283
|
if (isAlreadyLoaded) {
|
|
302
284
|
assert(configMapValues.every((conf) => 'configValue' in conf));
|
|
@@ -337,7 +319,7 @@ async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importe
|
|
|
337
319
|
const globalPaths = Array.from(new Set(interfaceFilesGlobalPaths.map((p) => path.posix.dirname(p))));
|
|
338
320
|
Object.entries(interfaceFilesByLocationId).forEach(([locationId, interfaceFiles]) => {
|
|
339
321
|
interfaceFiles.forEach((interfaceFile) => {
|
|
340
|
-
Object.keys(interfaceFile.
|
|
322
|
+
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
341
323
|
if (!isGlobalLocation(locationId, locationIds) && isGlobalConfig(configName)) {
|
|
342
324
|
assertUsage(false, [
|
|
343
325
|
`${interfaceFile.filePath.filePathToShowToUser} defines the config ${pc.cyan(configName)} which is global:`,
|
|
@@ -378,7 +360,7 @@ async function resolveConfigValueSources(configName, configDef, interfaceFilesRe
|
|
|
378
360
|
const sourcesInfo = [];
|
|
379
361
|
// interfaceFilesRelevant is sorted by sortAfterInheritanceOrder()
|
|
380
362
|
for (const interfaceFiles of Object.values(interfaceFilesRelevant)) {
|
|
381
|
-
const interfaceFilesDefiningConfig = interfaceFiles.filter((interfaceFile) => interfaceFile.
|
|
363
|
+
const interfaceFilesDefiningConfig = interfaceFiles.filter((interfaceFile) => interfaceFile.fileExportsByConfigName[configName]);
|
|
382
364
|
if (interfaceFilesDefiningConfig.length === 0)
|
|
383
365
|
continue;
|
|
384
366
|
const visited = new WeakSet();
|
|
@@ -456,13 +438,14 @@ function isInterfaceFileUserLand(interfaceFile) {
|
|
|
456
438
|
return (interfaceFile.isConfigFile && !interfaceFile.isConfigExtend) || interfaceFile.isValueFile;
|
|
457
439
|
}
|
|
458
440
|
async function getConfigValueSource(configName, interfaceFile, configDef, userRootDir, importedFilesLoaded) {
|
|
459
|
-
const conf = interfaceFile.
|
|
441
|
+
const conf = interfaceFile.fileExportsByConfigName[configName];
|
|
460
442
|
assert(conf);
|
|
461
443
|
const configEnv = configDef.env;
|
|
462
444
|
const definedAtConfigFile = {
|
|
463
445
|
...interfaceFile.filePath,
|
|
464
446
|
fileExportPathToShowToUser: ['default', configName]
|
|
465
447
|
};
|
|
448
|
+
// +client.js
|
|
466
449
|
if (configDef._valueIsFilePath) {
|
|
467
450
|
let definedAt;
|
|
468
451
|
let valueFilePath;
|
|
@@ -491,9 +474,11 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
491
474
|
};
|
|
492
475
|
return configValueSource;
|
|
493
476
|
}
|
|
477
|
+
// +config.js
|
|
494
478
|
if (interfaceFile.isConfigFile) {
|
|
495
479
|
assert('configValue' in conf);
|
|
496
480
|
const { configValue } = conf;
|
|
481
|
+
// fake import
|
|
497
482
|
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
498
483
|
if (import_) {
|
|
499
484
|
const configValueSource = {
|
|
@@ -501,12 +486,14 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
501
486
|
valueIsImportedAtRuntime: true,
|
|
502
487
|
definedAt: import_
|
|
503
488
|
};
|
|
504
|
-
// Load
|
|
505
|
-
if (isConfigEnv(configDef, configName)
|
|
489
|
+
// Load fake import
|
|
490
|
+
if (isConfigEnv(configDef, configName) &&
|
|
491
|
+
// The value of `extends` was already loaded and already used: we don't need the value of `extends` anymore
|
|
492
|
+
configName !== 'extends') {
|
|
506
493
|
if (import_.filePathAbsoluteFilesystem) {
|
|
507
494
|
assert(hasProp(import_, 'filePathAbsoluteFilesystem', 'string')); // Help TS
|
|
508
|
-
const
|
|
509
|
-
configValueSource.value =
|
|
495
|
+
const fileExport = await loadImportedFile(import_, userRootDir, importedFilesLoaded);
|
|
496
|
+
configValueSource.value = fileExport;
|
|
510
497
|
}
|
|
511
498
|
else {
|
|
512
499
|
const configDefinedAt = getConfigDefinedAtString('Config', configName, configValueSource);
|
|
@@ -515,17 +502,17 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
515
502
|
}
|
|
516
503
|
return configValueSource;
|
|
517
504
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
}
|
|
505
|
+
// Defined by config file, i.e. +config.js file
|
|
506
|
+
const configValueSource = {
|
|
507
|
+
value: configValue,
|
|
508
|
+
configEnv,
|
|
509
|
+
valueIsImportedAtRuntime: false,
|
|
510
|
+
definedAt: definedAtConfigFile
|
|
511
|
+
};
|
|
512
|
+
return configValueSource;
|
|
527
513
|
}
|
|
528
|
-
|
|
514
|
+
// Defined by value file, i.e. +{configName}.js
|
|
515
|
+
if (interfaceFile.isValueFile) {
|
|
529
516
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
530
517
|
assert(valueAlreadyLoaded === !!configEnv.config);
|
|
531
518
|
const configValueSource = {
|
|
@@ -546,25 +533,9 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
546
533
|
}
|
|
547
534
|
assert(false);
|
|
548
535
|
}
|
|
549
|
-
function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
|
|
550
|
-
assertPosixPath(filePathForEnvCheck);
|
|
551
|
-
if (!filesEnv.has(filePathForEnvCheck)) {
|
|
552
|
-
filesEnv.set(filePathForEnvCheck, []);
|
|
553
|
-
}
|
|
554
|
-
const fileEnv = filesEnv.get(filePathForEnvCheck);
|
|
555
|
-
fileEnv.push({ configEnv, configName });
|
|
556
|
-
const configDifferentEnv = fileEnv.filter((c) => !deepEqual(c.configEnv, configEnv))[0];
|
|
557
|
-
if (configDifferentEnv) {
|
|
558
|
-
assertUsage(false, [
|
|
559
|
-
`${filePathForEnvCheck} defines the value of configs living in different environments:`,
|
|
560
|
-
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${pc.cyan(c.configName)} which value lives in environment ${pc.cyan(JSON.stringify(c.configEnv))}`),
|
|
561
|
-
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/header-file'
|
|
562
|
-
].join('\n'));
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
536
|
function isDefiningPage(interfaceFiles) {
|
|
566
537
|
for (const interfaceFile of interfaceFiles) {
|
|
567
|
-
const configNames = Object.keys(interfaceFile.
|
|
538
|
+
const configNames = Object.keys(interfaceFile.fileExportsByConfigName);
|
|
568
539
|
if (configNames.some((configName) => isDefiningPageConfig(configName))) {
|
|
569
540
|
return true;
|
|
570
541
|
}
|
|
@@ -574,90 +545,11 @@ function isDefiningPage(interfaceFiles) {
|
|
|
574
545
|
function isDefiningPageConfig(configName) {
|
|
575
546
|
return ['Page', 'route'].includes(configName);
|
|
576
547
|
}
|
|
577
|
-
function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
578
|
-
if (typeof configValue !== 'string')
|
|
579
|
-
return null;
|
|
580
|
-
const importData = parseImportData(configValue);
|
|
581
|
-
if (!importData)
|
|
582
|
-
return null;
|
|
583
|
-
const { importPath, exportName } = importData;
|
|
584
|
-
const filePathAbsoluteFilesystem = resolveImportPath(importData, importerFilePath);
|
|
585
|
-
assertFileEnv(filePathAbsoluteFilesystem ?? importPath, configEnv, configName);
|
|
586
|
-
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
587
|
-
if (importPath.startsWith('.')) {
|
|
588
|
-
// We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
|
|
589
|
-
// ```
|
|
590
|
-
// [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
|
|
591
|
-
// ```
|
|
592
|
-
assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
|
|
593
|
-
const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, importerFilePath, userRootDir);
|
|
594
|
-
const filePath = {
|
|
595
|
-
filePathAbsoluteFilesystem,
|
|
596
|
-
filePathRelativeToUserRootDir,
|
|
597
|
-
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
598
|
-
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
599
|
-
importPathAbsolute: null
|
|
600
|
-
};
|
|
601
|
-
return {
|
|
602
|
-
...filePath,
|
|
603
|
-
fileExportName: exportName,
|
|
604
|
-
fileExportPathToShowToUser
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
else {
|
|
608
|
-
// importPath can be:
|
|
609
|
-
// - an npm package import
|
|
610
|
-
// - a path alias
|
|
611
|
-
const filePath = {
|
|
612
|
-
filePathAbsoluteFilesystem,
|
|
613
|
-
filePathRelativeToUserRootDir: null,
|
|
614
|
-
filePathAbsoluteVite: importPath,
|
|
615
|
-
filePathToShowToUser: importPath,
|
|
616
|
-
importPathAbsolute: importPath
|
|
617
|
-
};
|
|
618
|
-
return {
|
|
619
|
-
...filePath,
|
|
620
|
-
fileExportName: exportName,
|
|
621
|
-
fileExportPathToShowToUser
|
|
622
|
-
};
|
|
623
|
-
}
|
|
624
|
-
}
|
|
625
|
-
function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
|
|
626
|
-
assertPosixPath(userRootDir);
|
|
627
|
-
let filePathRelativeToUserRootDir;
|
|
628
|
-
if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
629
|
-
filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, userRootDir);
|
|
630
|
-
}
|
|
631
|
-
else {
|
|
632
|
-
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`);
|
|
633
|
-
// None of the following works. Seems to be a Vite bug?
|
|
634
|
-
// /*
|
|
635
|
-
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
636
|
-
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
637
|
-
// /*/
|
|
638
|
-
// filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem)
|
|
639
|
-
// assert(filePathRelativeToUserRootDir.startsWith('../'))
|
|
640
|
-
// filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir
|
|
641
|
-
// //*/
|
|
642
|
-
}
|
|
643
|
-
assertPosixPath(filePathRelativeToUserRootDir);
|
|
644
|
-
assert(filePathRelativeToUserRootDir.startsWith('/'));
|
|
645
|
-
return filePathRelativeToUserRootDir;
|
|
646
|
-
}
|
|
647
|
-
function getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, root) {
|
|
648
|
-
assertPosixPath(filePathAbsoluteFilesystem);
|
|
649
|
-
assertPosixPath(root);
|
|
650
|
-
assert(filePathAbsoluteFilesystem.startsWith(root));
|
|
651
|
-
let vitePath = path.posix.relative(root, filePathAbsoluteFilesystem);
|
|
652
|
-
assert(!vitePath.startsWith('/') && !vitePath.startsWith('.'));
|
|
653
|
-
vitePath = '/' + vitePath;
|
|
654
|
-
return vitePath;
|
|
655
|
-
}
|
|
656
548
|
function getConfigDefinitions(interfaceFilesRelevant) {
|
|
657
549
|
const configDefinitions = { ...configDefinitionsBuiltIn };
|
|
658
550
|
Object.entries(interfaceFilesRelevant).forEach(([_locationId, interfaceFiles]) => {
|
|
659
551
|
interfaceFiles.forEach((interfaceFile) => {
|
|
660
|
-
const configMeta = interfaceFile.
|
|
552
|
+
const configMeta = interfaceFile.fileExportsByConfigName['meta'];
|
|
661
553
|
if (!configMeta)
|
|
662
554
|
return;
|
|
663
555
|
const meta = configMeta.configValue;
|
|
@@ -840,108 +732,22 @@ function getConfigName(filePath) {
|
|
|
840
732
|
return configName;
|
|
841
733
|
}
|
|
842
734
|
}
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
const
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
}
|
|
856
|
-
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
const idx = visited.indexOf(filePathAbsoluteFilesystem);
|
|
860
|
-
if (idx === -1)
|
|
861
|
-
return;
|
|
862
|
-
const loop = visited.slice(idx);
|
|
863
|
-
assert(loop[0] === filePathAbsoluteFilesystem);
|
|
864
|
-
assertUsage(idx === -1, `Infinite extends loop ${[...loop, filePathAbsoluteFilesystem].join('>')}`);
|
|
865
|
-
}
|
|
866
|
-
async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir, visited) {
|
|
867
|
-
const extendsImportData = getExtendsImportData(configFileExports, configFilePath);
|
|
868
|
-
const extendsConfigFiles = [];
|
|
869
|
-
extendsImportData.map((importData) => {
|
|
870
|
-
const { importPath: importPath } = importData;
|
|
871
|
-
const filePathAbsoluteFilesystem = resolveImportPath(importData, configFilePath);
|
|
872
|
-
assertImportPath(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
873
|
-
assertExtendsImportPath(importPath, filePathAbsoluteFilesystem, configFilePath);
|
|
874
|
-
// - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
|
|
875
|
-
// - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsoluteFilesystem for added clarity
|
|
876
|
-
const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir);
|
|
877
|
-
const filePathAbsoluteVite = filePathRelativeToUserRootDir ?? importPath;
|
|
878
|
-
extendsConfigFiles.push({
|
|
879
|
-
filePathAbsoluteFilesystem,
|
|
880
|
-
filePathAbsoluteVite,
|
|
881
|
-
filePathRelativeToUserRootDir,
|
|
882
|
-
filePathToShowToUser: filePathAbsoluteVite,
|
|
883
|
-
importPathAbsolute: importPath
|
|
884
|
-
});
|
|
885
|
-
});
|
|
886
|
-
const extendsConfigs = [];
|
|
887
|
-
await Promise.all(extendsConfigFiles.map(async (configFilePath) => {
|
|
888
|
-
const result = await loadConfigFile(configFilePath, userRootDir, visited, true);
|
|
889
|
-
extendsConfigs.push(result.configFile);
|
|
890
|
-
extendsConfigs.push(...result.extendsConfigs);
|
|
891
|
-
}));
|
|
892
|
-
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
893
|
-
return { extendsConfigs, extendsFilePaths };
|
|
894
|
-
}
|
|
895
|
-
function determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir) {
|
|
896
|
-
assertPosixPath(filePathAbsoluteFilesystem);
|
|
897
|
-
assertPosixPath(userRootDir);
|
|
898
|
-
if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
899
|
-
return null;
|
|
900
|
-
}
|
|
901
|
-
let filePathRelativeToUserRootDir = filePathAbsoluteFilesystem.slice(userRootDir.length);
|
|
902
|
-
if (!filePathRelativeToUserRootDir.startsWith('/'))
|
|
903
|
-
filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
|
|
904
|
-
return filePathRelativeToUserRootDir;
|
|
905
|
-
}
|
|
906
|
-
function assertExtendsImportPath(importPath, filePath, configFilePath) {
|
|
907
|
-
if (isNpmPackageImport(importPath)) {
|
|
908
|
-
const fileDir = path.posix.dirname(filePath) + '/';
|
|
909
|
-
const fileName = path.posix.basename(filePath);
|
|
910
|
-
const fileNameBaseCorrect = '+config';
|
|
911
|
-
const [fileNameBase, ...fileNameRest] = fileName.split('.');
|
|
912
|
-
const fileNameCorrect = [fileNameBaseCorrect, ...fileNameRest].join('.');
|
|
913
|
-
assertWarning(fileNameBase === fileNameBaseCorrect, `Rename ${fileName} to ${fileNameCorrect} in ${fileDir}`, {
|
|
914
|
-
onlyOnce: true
|
|
915
|
-
});
|
|
916
|
-
}
|
|
917
|
-
else {
|
|
918
|
-
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 });
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
function getExtendsImportData(configFileExports, configFilePath) {
|
|
922
|
-
const { filePathToShowToUser } = configFilePath;
|
|
923
|
-
const configFileExport = getConfigFileExport(configFileExports, filePathToShowToUser);
|
|
924
|
-
const wrongUsage = `${filePathToShowToUser} sets the config ${pc.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
|
|
925
|
-
let extendList;
|
|
926
|
-
if (!('extends' in configFileExport)) {
|
|
927
|
-
return [];
|
|
928
|
-
}
|
|
929
|
-
else if (hasProp(configFileExport, 'extends', 'string')) {
|
|
930
|
-
extendList = [configFileExport.extends];
|
|
931
|
-
}
|
|
932
|
-
else if (hasProp(configFileExport, 'extends', 'string[]')) {
|
|
933
|
-
extendList = configFileExport.extends;
|
|
934
|
-
}
|
|
935
|
-
else {
|
|
936
|
-
assertUsage(false, wrongUsage);
|
|
937
|
-
}
|
|
938
|
-
const extendsImportData = extendList.map((importDataSerialized) => {
|
|
939
|
-
const importData = parseImportData(importDataSerialized);
|
|
940
|
-
assertUsage(importData, wrongUsage);
|
|
941
|
-
return importData;
|
|
942
|
-
});
|
|
943
|
-
return extendsImportData;
|
|
944
|
-
}
|
|
735
|
+
/* https://github.com/vikejs/vike/issues/1407
|
|
736
|
+
function assertNoUnexpectedPlusSign(filePath: string, fileName: string) {
|
|
737
|
+
const dirs = path.posix.dirname(filePath).split('/')
|
|
738
|
+
dirs.forEach((dir, i) => {
|
|
739
|
+
const dirPath = dirs.slice(0, i + 1).join('/')
|
|
740
|
+
assertUsage(
|
|
741
|
+
!dir.includes('+'),
|
|
742
|
+
`Character '+' is a reserved character: remove '+' from the directory name ${dirPath}/`
|
|
743
|
+
)
|
|
744
|
+
})
|
|
745
|
+
assertUsage(
|
|
746
|
+
!fileName.slice(1).includes('+'),
|
|
747
|
+
`Character '+' is only allowed at the beginning of filenames: make sure ${filePath} doesn't contain any '+' in its filename other than its first letter`
|
|
748
|
+
)
|
|
749
|
+
}
|
|
750
|
+
*/
|
|
945
751
|
function isGlobalConfig(configName) {
|
|
946
752
|
if (configName === 'prerender')
|
|
947
753
|
return false;
|
|
@@ -1024,32 +830,6 @@ function determineIsErrorPage(routeFilesystem) {
|
|
|
1024
830
|
assertPosixPath(routeFilesystem);
|
|
1025
831
|
return routeFilesystem.split('/').includes('_error');
|
|
1026
832
|
}
|
|
1027
|
-
function resolveImportPath(importData, importerFilePath) {
|
|
1028
|
-
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
1029
|
-
assertPosixPath(importerFilePathAbsolute);
|
|
1030
|
-
const cwd = path.posix.dirname(importerFilePathAbsolute);
|
|
1031
|
-
// 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
|
|
1032
|
-
// filePathAbsoluteFilesystem is expected to be null when importData.importPath is a Vite path alias
|
|
1033
|
-
const filePathAbsoluteFilesystem = requireResolve(importData.importPath, cwd);
|
|
1034
|
-
return filePathAbsoluteFilesystem;
|
|
1035
|
-
}
|
|
1036
|
-
function assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath) {
|
|
1037
|
-
const { importPath: importPath, importStringWasGenerated, importString } = importData;
|
|
1038
|
-
const { filePathToShowToUser } = importerFilePath;
|
|
1039
|
-
if (!filePathAbsoluteFilesystem) {
|
|
1040
|
-
const importPathString = pc.cyan(`'${importPath}'`);
|
|
1041
|
-
const errIntro = importStringWasGenerated
|
|
1042
|
-
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
1043
|
-
: `The import ${pc.cyan(importString)} defined in ${filePathToShowToUser}`;
|
|
1044
|
-
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
1045
|
-
if (importPath.startsWith('.')) {
|
|
1046
|
-
assertUsage(false, `${errIntro2} point to an existing file?`);
|
|
1047
|
-
}
|
|
1048
|
-
else {
|
|
1049
|
-
assertUsage(false, `${errIntro2} exist?`);
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
833
|
function isVikeConfigFile(filePath) {
|
|
1054
834
|
return !!getConfigName(filePath);
|
|
1055
835
|
}
|
|
@@ -12,7 +12,7 @@ export { getHttpRequestAsyncStore };
|
|
|
12
12
|
export { installHttpRequestAsyncStore };
|
|
13
13
|
import { renderPage_addWrapper } from '../../runtime/renderPage.js';
|
|
14
14
|
import { assert, assertIsNotProductionRuntime, isObject } from '../utils.js';
|
|
15
|
-
import { getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/transpileAndExecuteFile.js';
|
|
15
|
+
import { getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js';
|
|
16
16
|
import { logErrorDebugNote } from './loggerNotProd.js';
|
|
17
17
|
import { isEquivalentErrorWithCodeSnippet } from './loggerNotProd/errorWithCodeSnippet.js';
|
|
18
18
|
assertIsNotProductionRuntime();
|
|
@@ -18,7 +18,7 @@ import { assert, assertIsNotProductionRuntime, formatHintLog, getAssertErrMsg, i
|
|
|
18
18
|
import { getHttpRequestAsyncStore } from './getHttpRequestAsyncStore.js';
|
|
19
19
|
import { isErrorDebug } from './isErrorDebug.js';
|
|
20
20
|
import { isErrorWithCodeSnippet, getPrettyErrorWithCodeSnippet } from './loggerNotProd/errorWithCodeSnippet.js';
|
|
21
|
-
import { getConfigExecutionErrorIntroMsg, getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/transpileAndExecuteFile.js';
|
|
21
|
+
import { getConfigExecutionErrorIntroMsg, getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js';
|
|
22
22
|
import { logWithVikeTag, logWithViteTag, logDirectly, isFirstLog, screenHasErrors, clearScreen, applyViteSourceMapToStackTrace } from './loggerNotProd/log.js';
|
|
23
23
|
import pc from '@brillout/picocolors';
|
|
24
24
|
import { setAlreadyLogged } from '../../runtime/renderPage/isNewError.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
|
-
declare const PROJECT_VERSION: "0.4.159-commit-
|
|
3
|
+
declare const PROJECT_VERSION: "0.4.159-commit-d73533a";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.159-commit-
|
|
6
|
+
projectVersion: "0.4.159-commit-d73533a";
|
|
7
7
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
3
|
import { onProjectInfo } from './assertSingleInstance.js';
|
|
4
|
-
const PROJECT_VERSION = '0.4.159-commit-
|
|
4
|
+
const PROJECT_VERSION = '0.4.159-commit-d73533a';
|
|
5
5
|
const projectInfo = {
|
|
6
6
|
projectName: 'Vike',
|
|
7
7
|
projectVersion: PROJECT_VERSION
|
package/package.json
CHANGED