vike 0.4.144-commit-756f5d7 → 0.4.144-commit-6aef8a6
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/importBuild/index.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +140 -127
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +2 -4
- package/dist/cjs/node/runtime/renderPage/log404/index.js +27 -17
- package/dist/cjs/shared/page-configs/getExportPath.js +3 -3
- package/dist/cjs/shared/page-configs/loadConfigValues.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +1 -1
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +8 -9
- package/dist/cjs/shared/page-configs/utils.js +8 -15
- package/dist/cjs/shared/route/abort.js +1 -1
- package/dist/cjs/shared/route/loadPageRoutes.js +1 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/truncateString.js +12 -7
- package/dist/esm/node/plugin/plugins/importBuild/index.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +140 -127
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +2 -4
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.js +27 -16
- package/dist/esm/shared/page-configs/PageConfig.d.ts +51 -21
- package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
- package/dist/esm/shared/page-configs/getExportPath.js +3 -3
- package/dist/esm/shared/page-configs/loadConfigValues.js +2 -2
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +4 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +1 -1
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +8 -9
- package/dist/esm/shared/page-configs/utils.d.ts +3 -3
- package/dist/esm/shared/page-configs/utils.js +8 -15
- package/dist/esm/shared/route/abort.js +1 -1
- package/dist/esm/shared/route/loadPageRoutes.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/truncateString.d.ts +2 -1
- package/dist/esm/utils/truncateString.js +10 -7
- package/package.json +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -16
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +0 -24
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -13
|
@@ -13,7 +13,6 @@ import { isConfigInvalid, isConfigInvalid_set } from '../../../../runtime/render
|
|
|
13
13
|
import { getViteDevServer } from '../../../../runtime/globalContext.js';
|
|
14
14
|
import { logConfigError, logConfigErrorRecover } from '../../../shared/loggerNotProd.js';
|
|
15
15
|
import { removeSuperfluousViteLog_enable, removeSuperfluousViteLog_disable } from '../../../shared/loggerVite/removeSuperfluousViteLog.js';
|
|
16
|
-
import { getFilePathToShowToUser } from './getFilePathToShowToUser.js';
|
|
17
16
|
import pc from '@brillout/picocolors';
|
|
18
17
|
import { getConfigDefinedAtString } from '../../../../../shared/page-configs/utils.js';
|
|
19
18
|
import { assertExportsOfConfigFile, assertExportsOfValueFile } from '../../../../../shared/page-configs/assertExports.js';
|
|
@@ -72,7 +71,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
72
71
|
const configFiles = [];
|
|
73
72
|
const valueFiles = [];
|
|
74
73
|
plusFiles.forEach((f) => {
|
|
75
|
-
if (getConfigName(f.
|
|
74
|
+
if (getConfigName(f.filePathAbsoluteFilesystem) === 'config') {
|
|
76
75
|
configFiles.push(f);
|
|
77
76
|
}
|
|
78
77
|
else {
|
|
@@ -81,15 +80,10 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
81
80
|
});
|
|
82
81
|
let interfaceFilesByLocationId = {};
|
|
83
82
|
// Config files
|
|
84
|
-
await Promise.all(configFiles.map(async (
|
|
85
|
-
const
|
|
86
|
-
filePathAbsoluteFilesystem: filePathAbsoluteFilesystem,
|
|
87
|
-
filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
|
|
88
|
-
importPathAbsolute: null
|
|
89
|
-
};
|
|
90
|
-
const { configFile, extendsConfigs } = await loadConfigFile(configFilePath, userRootDir, []);
|
|
83
|
+
await Promise.all(configFiles.map(async (filePath) => {
|
|
84
|
+
const { configFile, extendsConfigs } = await loadConfigFile(filePath, userRootDir, []);
|
|
91
85
|
const interfaceFile = getInterfaceFileFromConfigFile(configFile, false);
|
|
92
|
-
const locationId = getLocationId(
|
|
86
|
+
const locationId = getLocationId(filePath.filePathAbsoluteVite);
|
|
93
87
|
interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
|
|
94
88
|
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
95
89
|
extendsConfigs.forEach((extendsConfig) => {
|
|
@@ -98,15 +92,11 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
98
92
|
});
|
|
99
93
|
}));
|
|
100
94
|
// Value files
|
|
101
|
-
await Promise.all(valueFiles.map(async (
|
|
102
|
-
const configName = getConfigName(
|
|
95
|
+
await Promise.all(valueFiles.map(async (filePath) => {
|
|
96
|
+
const configName = getConfigName(filePath.filePathAbsoluteVite);
|
|
103
97
|
assert(configName);
|
|
104
98
|
const interfaceFile = {
|
|
105
|
-
filePath
|
|
106
|
-
filePathRelativeToUserRootDir,
|
|
107
|
-
filePathAbsoluteFilesystem,
|
|
108
|
-
importPathAbsolute: null
|
|
109
|
-
},
|
|
99
|
+
filePath,
|
|
110
100
|
configMap: {
|
|
111
101
|
[configName]: {}
|
|
112
102
|
},
|
|
@@ -124,16 +114,16 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
124
114
|
}
|
|
125
115
|
}
|
|
126
116
|
{
|
|
127
|
-
const locationId = getLocationId(
|
|
117
|
+
const locationId = getLocationId(filePath.filePathAbsoluteVite);
|
|
128
118
|
interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
|
|
129
119
|
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
130
120
|
}
|
|
131
121
|
}));
|
|
132
122
|
return interfaceFilesByLocationId;
|
|
133
123
|
}
|
|
134
|
-
function getConfigDefinition(configDefinitionsRelevant, configName,
|
|
124
|
+
function getConfigDefinition(configDefinitionsRelevant, configName, filePathToShowToUser) {
|
|
135
125
|
const configDef = configDefinitionsRelevant[configName];
|
|
136
|
-
assertConfigExists(configName, Object.keys(configDefinitionsRelevant),
|
|
126
|
+
assertConfigExists(configName, Object.keys(configDefinitionsRelevant), filePathToShowToUser);
|
|
137
127
|
assert(configDef);
|
|
138
128
|
return configDef;
|
|
139
129
|
}
|
|
@@ -142,7 +132,7 @@ function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
|
142
132
|
}
|
|
143
133
|
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
144
134
|
const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath, true, userRootDir);
|
|
145
|
-
const filePathToShowToUser =
|
|
135
|
+
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
146
136
|
assertExportsOfValueFile(fileExports, filePathToShowToUser, configName);
|
|
147
137
|
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
148
138
|
const configName_ = exportName === 'default' ? configName : exportName;
|
|
@@ -159,7 +149,7 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
159
149
|
isConfigExtend,
|
|
160
150
|
extendsFilePaths
|
|
161
151
|
};
|
|
162
|
-
const filePathToShowToUser =
|
|
152
|
+
const { filePathToShowToUser } = filePath;
|
|
163
153
|
assertExportsOfConfigFile(fileExports, filePathToShowToUser);
|
|
164
154
|
Object.entries(fileExports.default).forEach(([configName, configValue]) => {
|
|
165
155
|
interfaceFile.configMap[configName] = { configValue };
|
|
@@ -222,7 +212,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
222
212
|
const { configName } = interfaceFile;
|
|
223
213
|
if (isGlobalConfig(configName))
|
|
224
214
|
return;
|
|
225
|
-
const configDef = getConfigDefinition(configDefinitionsRelevant, configName,
|
|
215
|
+
const configDef = getConfigDefinition(configDefinitionsRelevant, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
226
216
|
if (configDef.env !== 'config-only')
|
|
227
217
|
return;
|
|
228
218
|
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
@@ -261,7 +251,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
261
251
|
const configDefinitionsRelevant = getConfigDefinitions(interfaceFilesRelevant);
|
|
262
252
|
interfaceFiles.forEach((interfaceFile) => {
|
|
263
253
|
Object.keys(interfaceFile.configMap).forEach((configName) => {
|
|
264
|
-
assertConfigExists(configName, Object.keys(configDefinitionsRelevant),
|
|
254
|
+
assertConfigExists(configName, Object.keys(configDefinitionsRelevant), interfaceFile.filePath.filePathToShowToUser);
|
|
265
255
|
});
|
|
266
256
|
});
|
|
267
257
|
});
|
|
@@ -312,7 +302,7 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
|
312
302
|
Object.keys(interfaceFile.configMap).forEach((configName) => {
|
|
313
303
|
if (!isGlobalLocation(locationId, locationIds) && isGlobalConfig(configName)) {
|
|
314
304
|
assertUsage(false, [
|
|
315
|
-
`${
|
|
305
|
+
`${interfaceFile.filePath.filePathToShowToUser} defines the config ${pc.cyan(configName)} which is global:`,
|
|
316
306
|
globalPaths.length
|
|
317
307
|
? `define ${pc.cyan(configName)} in ${joinEnglish(globalPaths, 'or')} instead`
|
|
318
308
|
: `create a global config (e.g. /pages/+config.js) and define ${pc.cyan(configName)} there instead`
|
|
@@ -339,9 +329,8 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
|
339
329
|
assert('value' in configValueSource);
|
|
340
330
|
if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
|
|
341
331
|
return;
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
assertWarning(false, `Being able to define config ${pc.cyan(configName)} in ${sourceFilePath} is experimental and will likely be removed. Define the config ${pc.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
|
|
332
|
+
const { filePathToShowToUser } = configValueSource.definedAtInfo;
|
|
333
|
+
assertWarning(false, `Being able to define config ${pc.cyan(configName)} in ${filePathToShowToUser} is experimental and will likely be removed. Define the config ${pc.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
|
|
345
334
|
globalVikeConfig[configName] = configValueSource.value;
|
|
346
335
|
}
|
|
347
336
|
});
|
|
@@ -424,7 +413,7 @@ function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden,
|
|
|
424
413
|
interfaceFilesOverriden.forEach((interfaceFileLoser) => {
|
|
425
414
|
const configValueSourceWinner = getConfigValueSource(configName, interfaceFileWinner, configDef, userRootDir);
|
|
426
415
|
const configValueSourceLoser = getConfigValueSource(configName, interfaceFileLoser, configDef, userRootDir);
|
|
427
|
-
assertWarning(false, `${getConfigSourceDefinedAtString(configName, configValueSourceLoser,
|
|
416
|
+
assertWarning(false, `${getConfigSourceDefinedAtString(configName, configValueSourceLoser, true)} overriden by another ${getConfigSourceDefinedAtString(configName, configValueSourceWinner, false)}, remove one of the two`, { onlyOnce: false });
|
|
428
417
|
});
|
|
429
418
|
}
|
|
430
419
|
function isInterfaceFileUserLand(interfaceFile) {
|
|
@@ -436,7 +425,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
436
425
|
const configEnv = configDef.env;
|
|
437
426
|
const definedAtConfigFile = {
|
|
438
427
|
...interfaceFile.filePath,
|
|
439
|
-
|
|
428
|
+
fileExportPathToShowToUser: ['default', configName]
|
|
440
429
|
};
|
|
441
430
|
if (configDef._valueIsFilePath) {
|
|
442
431
|
let definedAtInfo;
|
|
@@ -446,15 +435,15 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
446
435
|
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
447
436
|
const configDefinedAt = getConfigSourceDefinedAtString(configName, { definedAtInfo: definedAtConfigFile });
|
|
448
437
|
assertUsage(import_, `${configDefinedAt} should be an import`);
|
|
449
|
-
valueFilePath = import_.
|
|
438
|
+
valueFilePath = import_.filePathAbsoluteVite;
|
|
450
439
|
definedAtInfo = import_;
|
|
451
440
|
}
|
|
452
441
|
else {
|
|
453
442
|
assert(interfaceFile.isValueFile);
|
|
454
|
-
valueFilePath = interfaceFile.filePath.
|
|
443
|
+
valueFilePath = interfaceFile.filePath.filePathAbsoluteVite;
|
|
455
444
|
definedAtInfo = {
|
|
456
445
|
...interfaceFile.filePath,
|
|
457
|
-
|
|
446
|
+
fileExportPathToShowToUser: []
|
|
458
447
|
};
|
|
459
448
|
}
|
|
460
449
|
const configValueSource = {
|
|
@@ -495,7 +484,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
495
484
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
496
485
|
definedAtInfo: {
|
|
497
486
|
...interfaceFile.filePath,
|
|
498
|
-
|
|
487
|
+
fileExportPathToShowToUser: configName === interfaceFile.configName
|
|
499
488
|
? []
|
|
500
489
|
: // Side-effect config (e.g. `export { frontmatter }` of .md files)
|
|
501
490
|
[configName]
|
|
@@ -548,7 +537,7 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
|
|
|
548
537
|
const { importPath, exportName } = importData;
|
|
549
538
|
const filePathAbsoluteFilesystem = resolveImportPath(importData, importerFilePath);
|
|
550
539
|
assertFileEnv(filePathAbsoluteFilesystem ?? importPath, configEnv, configName);
|
|
551
|
-
const
|
|
540
|
+
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
552
541
|
if (importPath.startsWith('.')) {
|
|
553
542
|
// We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
|
|
554
543
|
// ```
|
|
@@ -556,25 +545,35 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
|
|
|
556
545
|
// ```
|
|
557
546
|
assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
|
|
558
547
|
const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, importerFilePath, userRootDir);
|
|
559
|
-
|
|
560
|
-
exportName,
|
|
561
|
-
fileExportPath,
|
|
548
|
+
const filePath = {
|
|
562
549
|
filePathAbsoluteFilesystem,
|
|
563
550
|
filePathRelativeToUserRootDir,
|
|
551
|
+
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
552
|
+
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
564
553
|
importPathAbsolute: null
|
|
565
554
|
};
|
|
555
|
+
return {
|
|
556
|
+
...filePath,
|
|
557
|
+
fileExportName: exportName,
|
|
558
|
+
fileExportPathToShowToUser
|
|
559
|
+
};
|
|
566
560
|
}
|
|
567
561
|
else {
|
|
568
562
|
// importPath can be:
|
|
569
563
|
// - an npm package import
|
|
570
564
|
// - a path alias
|
|
571
|
-
|
|
572
|
-
exportName,
|
|
573
|
-
fileExportPath,
|
|
565
|
+
const filePath = {
|
|
574
566
|
filePathAbsoluteFilesystem,
|
|
575
567
|
filePathRelativeToUserRootDir: null,
|
|
568
|
+
filePathAbsoluteVite: importPath,
|
|
569
|
+
filePathToShowToUser: importPath,
|
|
576
570
|
importPathAbsolute: importPath
|
|
577
571
|
};
|
|
572
|
+
return {
|
|
573
|
+
...filePath,
|
|
574
|
+
fileExportName: exportName,
|
|
575
|
+
fileExportPathToShowToUser
|
|
576
|
+
};
|
|
578
577
|
}
|
|
579
578
|
}
|
|
580
579
|
function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
|
|
@@ -584,7 +583,7 @@ function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, imp
|
|
|
584
583
|
filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, userRootDir);
|
|
585
584
|
}
|
|
586
585
|
else {
|
|
587
|
-
assertUsage(false, `${
|
|
586
|
+
assertUsage(false, `${configFilePath.filePathToShowToUser} imports from a relative path ${pc.cyan(importData.importPath)} outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
|
|
588
587
|
// None of the following works. Seems to be a Vite bug?
|
|
589
588
|
// /*
|
|
590
589
|
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
@@ -617,8 +616,18 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
617
616
|
return;
|
|
618
617
|
const meta = configMeta.configValue;
|
|
619
618
|
assertMetaValue(meta,
|
|
620
|
-
// Maybe we should use the getConfigDefinedAtString() helper?
|
|
621
|
-
`Config ${pc.cyan('meta')} defined at ${
|
|
619
|
+
// TODO: Maybe we should use the getConfigDefinedAtString() helper?
|
|
620
|
+
`Config ${pc.cyan('meta')} defined at ${interfaceFile.filePath.filePathToShowToUser}`);
|
|
621
|
+
// Set configDef._userEffectDefinedAt
|
|
622
|
+
Object.entries(meta).forEach(([configName, configDef]) => {
|
|
623
|
+
if (!configDef.effect)
|
|
624
|
+
return;
|
|
625
|
+
assert(interfaceFile.isConfigFile);
|
|
626
|
+
configDef._userEffectDefinedAt = {
|
|
627
|
+
...interfaceFile.filePath,
|
|
628
|
+
fileExportPathToShowToUser: ['default', 'meta', configName, 'effect']
|
|
629
|
+
};
|
|
630
|
+
});
|
|
622
631
|
objectEntries(meta).forEach(([configName, configDefinition]) => {
|
|
623
632
|
// User can override an existing config definition
|
|
624
633
|
configDefinitions[configName] = {
|
|
@@ -631,9 +640,15 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
631
640
|
return configDefinitions;
|
|
632
641
|
}
|
|
633
642
|
function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
634
|
-
|
|
643
|
+
if (!isObject(metaVal)) {
|
|
644
|
+
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
645
|
+
assertUsage(false, `${configMetaDefinedAt} has an invalid type ${pc.cyan(typeof metaVal)}: it should be an object instead.`);
|
|
646
|
+
}
|
|
635
647
|
objectEntries(metaVal).forEach(([configName, def]) => {
|
|
636
|
-
|
|
648
|
+
if (!isObject(def)) {
|
|
649
|
+
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
650
|
+
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}`)} to a value with an invalid type ${pc.cyan(typeof def)}: it should be an object instead.`);
|
|
651
|
+
}
|
|
637
652
|
// env
|
|
638
653
|
{
|
|
639
654
|
const envValues = [
|
|
@@ -642,19 +657,34 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
642
657
|
'server-and-client',
|
|
643
658
|
'config-only'
|
|
644
659
|
];
|
|
645
|
-
const
|
|
646
|
-
`Set the value of ${pc.cyan(
|
|
660
|
+
const fix = [
|
|
661
|
+
`Set the value of ${pc.cyan(`meta.${configName}.env`)} to `,
|
|
647
662
|
joinEnglish(envValues.map((s) => pc.cyan(`'${s}'`)), 'or'),
|
|
648
663
|
'.'
|
|
649
664
|
].join('');
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
665
|
+
if (!('env' in def)) {
|
|
666
|
+
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
667
|
+
assertUsage(false, `${configMetaDefinedAt} doesn't set ${pc.cyan(`meta.${configName}.env`)} but it's required. ${fix}`);
|
|
668
|
+
}
|
|
669
|
+
if (!hasProp(def, 'env', 'string')) {
|
|
670
|
+
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
671
|
+
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}.env`)} to an invalid type ${pc.cyan(typeof def.env)}. ${fix}`);
|
|
672
|
+
}
|
|
673
|
+
if (!envValues.includes(def.env)) {
|
|
674
|
+
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
675
|
+
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}.env`)} to an unknown value ${pc.cyan(`'${def.env}'`)}. ${fix}`);
|
|
676
|
+
}
|
|
653
677
|
}
|
|
654
678
|
// effect
|
|
655
679
|
if ('effect' in def) {
|
|
656
|
-
|
|
657
|
-
|
|
680
|
+
if (!hasProp(def, 'effect', 'function')) {
|
|
681
|
+
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
682
|
+
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}.effect`)} to an invalid type ${pc.cyan(typeof def.effect)}: it should be a function instead`);
|
|
683
|
+
}
|
|
684
|
+
if (def.env !== 'config-only') {
|
|
685
|
+
assert(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
686
|
+
assertUsage(false, `${configMetaDefinedAt} sets ${pc.cyan(`meta.${configName}.effect`)} but it's only supported if meta.${configName}.env is ${pc.cyan('config-only')} (but it's ${pc.cyan(def.env)} instead)`);
|
|
687
|
+
}
|
|
658
688
|
}
|
|
659
689
|
});
|
|
660
690
|
}
|
|
@@ -665,7 +695,7 @@ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
|
|
|
665
695
|
// The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
|
|
666
696
|
// (We could support effect for non config-only by always loading its value at config time, regardless of the config's `env` value.)
|
|
667
697
|
assertUsage(configDef.env === 'config-only', [
|
|
668
|
-
`Cannot add effect to ${pc.cyan(configName)} because its ${pc.cyan('env')} is ${pc.cyan(configDef.env)}: effects can only be added to configs with an env
|
|
698
|
+
`Cannot add effect to ${pc.cyan(configName)} because its ${pc.cyan('env')} is ${pc.cyan(configDef.env)}: effects can only be added to configs with an ${pc.cyan('env')} value of ${pc.cyan('config-only')}.`
|
|
669
699
|
].join(' '));
|
|
670
700
|
const source = configValueSources[configName]?.[0];
|
|
671
701
|
if (!source)
|
|
@@ -680,14 +710,23 @@ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
|
|
|
680
710
|
if (!configModFromEffect)
|
|
681
711
|
return;
|
|
682
712
|
assert(hasProp(source, 'value')); // We need to assume that the config value is loaded at build-time
|
|
683
|
-
applyEffect(configModFromEffect,
|
|
713
|
+
applyEffect(configModFromEffect, configValueSources, configDef);
|
|
684
714
|
});
|
|
685
715
|
}
|
|
686
|
-
function applyEffect(configModFromEffect,
|
|
716
|
+
function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
687
717
|
const notSupported = `Effects currently only supports modifying the the ${pc.cyan('env')} of a config.`;
|
|
688
718
|
objectEntries(configModFromEffect).forEach(([configName, configValue]) => {
|
|
689
719
|
if (configName === 'meta') {
|
|
690
|
-
|
|
720
|
+
let configDefinedAtString;
|
|
721
|
+
if (configDefEffect._userEffectDefinedAt) {
|
|
722
|
+
configDefinedAtString = getConfigSourceDefinedAtString(configName, {
|
|
723
|
+
definedAtInfo: configDefEffect._userEffectDefinedAt
|
|
724
|
+
});
|
|
725
|
+
}
|
|
726
|
+
else {
|
|
727
|
+
configDefinedAtString = null;
|
|
728
|
+
}
|
|
729
|
+
assertMetaValue(configValue, configDefinedAtString);
|
|
691
730
|
objectEntries(configValue).forEach(([configTargetName, configTargetDef]) => {
|
|
692
731
|
{
|
|
693
732
|
const keys = Object.keys(configTargetDef);
|
|
@@ -705,7 +744,7 @@ function applyEffect(configModFromEffect, configValueEffectSource, configValueSo
|
|
|
705
744
|
else {
|
|
706
745
|
assertUsage(false, notSupported);
|
|
707
746
|
// If we do end implementing being able to set the value of a config:
|
|
708
|
-
// - For setting definedAtInfo: we could take the definedAtInfo of the effect config while appending '(effect)' to definedAtInfo.
|
|
747
|
+
// - For setting definedAtInfo: we could take the definedAtInfo of the effect config while appending '(effect)' to definedAtInfo.fileExportPathToShowToUser
|
|
709
748
|
}
|
|
710
749
|
});
|
|
711
750
|
}
|
|
@@ -757,19 +796,28 @@ async function findPlusFiles(userRootDir, ignoreDirs, isDev, extensions) {
|
|
|
757
796
|
p = toPosixPath(p);
|
|
758
797
|
const filePathRelativeToUserRootDir = path.posix.join('/', p);
|
|
759
798
|
const filePathAbsoluteFilesystem = path.posix.join(userRootDir, p);
|
|
760
|
-
return {
|
|
799
|
+
return {
|
|
800
|
+
filePathRelativeToUserRootDir,
|
|
801
|
+
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
802
|
+
filePathAbsoluteFilesystem,
|
|
803
|
+
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
804
|
+
importPathAbsolute: null
|
|
805
|
+
};
|
|
761
806
|
});
|
|
807
|
+
// TODO/v1-release: remove
|
|
762
808
|
extensions.forEach((extension) => {
|
|
763
809
|
extension.pageConfigsDistFiles?.forEach((pageConfigDistFile) => {
|
|
764
|
-
// TODO/v1-release: remove
|
|
765
810
|
if (!pageConfigDistFile.importPath.includes('+'))
|
|
766
811
|
return;
|
|
767
812
|
assert(pageConfigDistFile.importPath.includes('+'));
|
|
768
813
|
assert(path.posix.basename(pageConfigDistFile.importPath).startsWith('+'));
|
|
769
814
|
const { importPath, filePath } = pageConfigDistFile;
|
|
770
815
|
plusFiles.push({
|
|
771
|
-
filePathRelativeToUserRootDir:
|
|
772
|
-
|
|
816
|
+
filePathRelativeToUserRootDir: null,
|
|
817
|
+
filePathAbsoluteVite: importPath,
|
|
818
|
+
filePathAbsoluteFilesystem: filePath,
|
|
819
|
+
filePathToShowToUser: importPath,
|
|
820
|
+
importPathAbsolute: importPath
|
|
773
821
|
});
|
|
774
822
|
});
|
|
775
823
|
});
|
|
@@ -834,10 +882,12 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
834
882
|
// - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
|
|
835
883
|
// - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsoluteFilesystem for added clarity
|
|
836
884
|
const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir);
|
|
885
|
+
const filePathAbsoluteVite = filePathRelativeToUserRootDir ?? importPath;
|
|
837
886
|
extendsConfigFiles.push({
|
|
838
887
|
filePathAbsoluteFilesystem,
|
|
839
|
-
|
|
840
|
-
filePathRelativeToUserRootDir
|
|
888
|
+
filePathAbsoluteVite,
|
|
889
|
+
filePathRelativeToUserRootDir,
|
|
890
|
+
filePathToShowToUser: filePathAbsoluteVite,
|
|
841
891
|
importPathAbsolute: importPath
|
|
842
892
|
});
|
|
843
893
|
});
|
|
@@ -873,14 +923,14 @@ function assertExtendsImportPath(importPath, filePath, configFilePath) {
|
|
|
873
923
|
});
|
|
874
924
|
}
|
|
875
925
|
else {
|
|
876
|
-
assertWarning(false, `${
|
|
926
|
+
assertWarning(false, `${configFilePath.filePathToShowToUser} uses ${pc.cyan('extends')} to inherit from ${pc.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this feature.`, { onlyOnce: true });
|
|
877
927
|
}
|
|
878
928
|
}
|
|
879
929
|
function getExtendsImportData(configFileExports, configFilePath) {
|
|
880
|
-
const filePathToShowToUser =
|
|
930
|
+
const { filePathToShowToUser } = configFilePath;
|
|
881
931
|
assertExportsOfConfigFile(configFileExports, filePathToShowToUser);
|
|
882
932
|
const defaultExports = configFileExports.default;
|
|
883
|
-
const wrongUsage = `${filePathToShowToUser} sets the config 'extends' to an invalid value, see https://vike.dev/extends`;
|
|
933
|
+
const wrongUsage = `${filePathToShowToUser} sets the config ${pc.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
|
|
884
934
|
let extendList;
|
|
885
935
|
if (!('extends' in defaultExports)) {
|
|
886
936
|
return [];
|
|
@@ -901,38 +951,6 @@ function getExtendsImportData(configFileExports, configFilePath) {
|
|
|
901
951
|
});
|
|
902
952
|
return extendsImportData;
|
|
903
953
|
}
|
|
904
|
-
// TODO: re-use this
|
|
905
|
-
function handleUserFileError(err, isDev) {
|
|
906
|
-
// Properly handle error during transpilation so that we can use assertUsage() during transpilation
|
|
907
|
-
if (isDev) {
|
|
908
|
-
throw err;
|
|
909
|
-
}
|
|
910
|
-
else {
|
|
911
|
-
// Avoid ugly error format:
|
|
912
|
-
// ```
|
|
913
|
-
// [vike:importUserCode] Could not load virtual:vike:importUserCode:server: [vike@0.4.70][Wrong Usage] /pages/+config.ts sets the config 'onRenderHtml' to the value './+config/onRenderHtml-i-dont-exist.js' but no file was found at /home/rom/code/vike/examples/v1/pages/+config/onRenderHtml-i-dont-exist.js
|
|
914
|
-
// Error: [vike@0.4.70][Wrong Usage] /pages/+config.ts sets the config 'onRenderHtml' to the value './+config/onRenderHtml-i-dont-exist.js' but no file was found at /home/rom/code/vike/examples/v1/pages/+config/onRenderHtml-i-dont-exist.js
|
|
915
|
-
// at ...
|
|
916
|
-
// at ...
|
|
917
|
-
// at ...
|
|
918
|
-
// at ...
|
|
919
|
-
// at ...
|
|
920
|
-
// at ...
|
|
921
|
-
// code: 'PLUGIN_ERROR',
|
|
922
|
-
// plugin: 'vike:importUserCode',
|
|
923
|
-
// hook: 'load',
|
|
924
|
-
// watchFiles: [
|
|
925
|
-
// '/home/rom/code/vike/vike/dist/esm/node/importBuild.js',
|
|
926
|
-
// '\x00virtual:vike:importUserCode:server'
|
|
927
|
-
// ]
|
|
928
|
-
// }
|
|
929
|
-
// ELIFECYCLE Command failed with exit code 1.
|
|
930
|
-
// ```
|
|
931
|
-
console.log('');
|
|
932
|
-
console.error(err);
|
|
933
|
-
process.exit(1);
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
954
|
function isGlobalConfig(configName) {
|
|
937
955
|
if (configName === 'prerender')
|
|
938
956
|
return false;
|
|
@@ -942,15 +960,15 @@ function isGlobalConfig(configName) {
|
|
|
942
960
|
function getConfigNamesGlobal() {
|
|
943
961
|
return Object.keys(configDefinitionsBuiltInGlobal);
|
|
944
962
|
}
|
|
945
|
-
function assertConfigExists(configName, configNamesRelevant,
|
|
963
|
+
function assertConfigExists(configName, configNamesRelevant, filePathToShowToUser) {
|
|
946
964
|
const configNames = [...configNamesRelevant, ...getConfigNamesGlobal()];
|
|
947
965
|
if (configNames.includes(configName))
|
|
948
966
|
return;
|
|
949
|
-
handleUnknownConfig(configName, configNames,
|
|
967
|
+
handleUnknownConfig(configName, configNames, filePathToShowToUser);
|
|
950
968
|
assert(false);
|
|
951
969
|
}
|
|
952
|
-
function handleUnknownConfig(configName, configNames,
|
|
953
|
-
let errMsg = `${
|
|
970
|
+
function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
971
|
+
let errMsg = `${filePathToShowToUser} defines an unknown config ${pc.cyan(configName)}`;
|
|
954
972
|
let configNameSimilar = null;
|
|
955
973
|
if (configName === 'page') {
|
|
956
974
|
configNameSimilar = 'Page';
|
|
@@ -982,11 +1000,11 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
982
1000
|
if (configFilesystemRoutingRoot) {
|
|
983
1001
|
const routingRoot = getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName);
|
|
984
1002
|
if (routingRoot) {
|
|
985
|
-
const { filesystemRoutingRootEffect
|
|
1003
|
+
const { filesystemRoutingRootEffect /*, filesystemRoutingRootDefinedAt*/ } = routingRoot;
|
|
986
1004
|
const debugInfo = { locationId, routeFilesystem: filesystemRouteString, configFilesystemRoutingRoot };
|
|
987
1005
|
assert(filesystemRouteString.startsWith(filesystemRoutingRootEffect.before), debugInfo);
|
|
988
1006
|
filesystemRouteString = applyFilesystemRoutingRootEffect(filesystemRouteString, filesystemRoutingRootEffect);
|
|
989
|
-
filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${filesystemRoutingRootDefinedAt})
|
|
1007
|
+
// filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${filesystemRoutingRootDefinedAt})`
|
|
990
1008
|
}
|
|
991
1009
|
}
|
|
992
1010
|
assert(filesystemRouteString.startsWith('/'));
|
|
@@ -1025,7 +1043,7 @@ function resolveImportPath(importData, importerFilePath) {
|
|
|
1025
1043
|
}
|
|
1026
1044
|
function assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath) {
|
|
1027
1045
|
const { importPath: importPath, importStringWasGenerated, importString } = importData;
|
|
1028
|
-
const filePathToShowToUser =
|
|
1046
|
+
const { filePathToShowToUser } = importerFilePath;
|
|
1029
1047
|
if (!filePathAbsoluteFilesystem) {
|
|
1030
1048
|
const importPathString = pc.cyan(`'${importPath}'`);
|
|
1031
1049
|
const errIntro = importStringWasGenerated
|
|
@@ -1076,6 +1094,17 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
1076
1094
|
});
|
|
1077
1095
|
return configValues;
|
|
1078
1096
|
}
|
|
1097
|
+
function getDefinedAtFile(configValueSource) {
|
|
1098
|
+
return {
|
|
1099
|
+
filePathToShowToUser: configValueSource.definedAtInfo.filePathToShowToUser,
|
|
1100
|
+
fileExportPathToShowToUser: configValueSource.definedAtInfo.fileExportPathToShowToUser
|
|
1101
|
+
};
|
|
1102
|
+
}
|
|
1103
|
+
function getDefinedAt(configValueSource) {
|
|
1104
|
+
return {
|
|
1105
|
+
file: getDefinedAtFile(configValueSource)
|
|
1106
|
+
};
|
|
1107
|
+
}
|
|
1079
1108
|
function mergeCumulative(configName, configValueSources) {
|
|
1080
1109
|
const valuesArr = [];
|
|
1081
1110
|
const valuesSet = [];
|
|
@@ -1099,7 +1128,7 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1099
1128
|
if (vals2.length === 0)
|
|
1100
1129
|
return;
|
|
1101
1130
|
assert(configValueSourcePrevious);
|
|
1102
|
-
const configPreviousDefinedAt = getConfigSourceDefinedAtString(configName, configValueSourcePrevious,
|
|
1131
|
+
const configPreviousDefinedAt = getConfigSourceDefinedAtString(configName, configValueSourcePrevious, false);
|
|
1103
1132
|
assertUsage(false, `${configDefinedAt} sets ${t1} but another ${configPreviousDefinedAt} sets ${t2} which is forbidden: the values must be all arrays or all sets (you cannot mix).`);
|
|
1104
1133
|
};
|
|
1105
1134
|
const { value } = configValueSource;
|
|
@@ -1130,30 +1159,14 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1130
1159
|
}
|
|
1131
1160
|
assert(false);
|
|
1132
1161
|
}
|
|
1133
|
-
// TODO: rename
|
|
1134
|
-
|
|
1135
|
-
function getConfigSourceDefinedAtString(configName, { definedAtInfo }, isEffect = undefined, sentenceBegin = true) {
|
|
1162
|
+
// TODO: rename and/or refactor
|
|
1163
|
+
function getConfigSourceDefinedAtString(configName, { definedAtInfo }, sentenceBegin = true) {
|
|
1136
1164
|
return getConfigDefinedAtString(configName, {
|
|
1137
1165
|
definedAt: {
|
|
1138
|
-
isEffect,
|
|
1139
1166
|
file: {
|
|
1140
|
-
filePathToShowToUser:
|
|
1141
|
-
|
|
1167
|
+
filePathToShowToUser: definedAtInfo.filePathToShowToUser,
|
|
1168
|
+
fileExportPathToShowToUser: definedAtInfo.fileExportPathToShowToUser
|
|
1142
1169
|
}
|
|
1143
1170
|
}
|
|
1144
1171
|
}, sentenceBegin);
|
|
1145
1172
|
}
|
|
1146
|
-
function getDefinedAtFilePathToShowToUser(definedAtInfo) {
|
|
1147
|
-
return definedAtInfo.filePathRelativeToUserRootDir ?? definedAtInfo.importPathAbsolute;
|
|
1148
|
-
}
|
|
1149
|
-
function getDefinedAtFile(source) {
|
|
1150
|
-
return {
|
|
1151
|
-
filePathToShowToUser: getDefinedAtFilePathToShowToUser(source.definedAtInfo),
|
|
1152
|
-
fileExportPath: source.definedAtInfo.fileExportPath
|
|
1153
|
-
};
|
|
1154
|
-
}
|
|
1155
|
-
function getDefinedAt(configValueSource) {
|
|
1156
|
-
return {
|
|
1157
|
-
file: getDefinedAtFile(configValueSource)
|
|
1158
|
-
};
|
|
1159
|
-
}
|
|
@@ -3,8 +3,8 @@ export { getConfigBuildErrorFormatted };
|
|
|
3
3
|
export { getConfigExecutionErrorIntroMsg as getConfigExecutionErrorIntroMsg };
|
|
4
4
|
export { isTmpFile };
|
|
5
5
|
import 'source-map-support/register.js';
|
|
6
|
-
import {
|
|
7
|
-
declare function transpileAndExecuteFile(filePath:
|
|
6
|
+
import type { FilePathResolved } from '../../../../../shared/page-configs/PageConfig.js';
|
|
7
|
+
declare function transpileAndExecuteFile(filePath: FilePathResolved, isValueFile: boolean, userRootDir: string): Promise<{
|
|
8
8
|
fileExports: Record<string, unknown>;
|
|
9
9
|
}>;
|
|
10
10
|
declare function getConfigBuildErrorFormatted(err: unknown): null | string;
|
|
@@ -11,7 +11,6 @@ import { assertPosixPath, getRandomId, assertIsNotProductionRuntime, assert, uni
|
|
|
11
11
|
import { isImportData, replaceImportStatements } from './replaceImportStatements.js';
|
|
12
12
|
import { vikeConfigDependencies } from './getVikeConfig.js';
|
|
13
13
|
import 'source-map-support/register.js';
|
|
14
|
-
import { getFilePathToShowToUser } from './getFilePathToShowToUser.js';
|
|
15
14
|
import { assertExportsOfConfigFile } from '../../../../../shared/page-configs/assertExports.js';
|
|
16
15
|
assertIsNotProductionRuntime();
|
|
17
16
|
async function transpileAndExecuteFile(filePath, isValueFile, userRootDir) {
|
|
@@ -36,14 +35,13 @@ async function transpileFile(filePath, isValueFile, userRootDir) {
|
|
|
36
35
|
}
|
|
37
36
|
function transpileImports(codeOriginal, filePath, isValueFile) {
|
|
38
37
|
// Do we need to remove the imports?
|
|
39
|
-
const { filePathAbsoluteFilesystem } = filePath;
|
|
38
|
+
const { filePathAbsoluteFilesystem, filePathToShowToUser } = filePath;
|
|
40
39
|
assertPosixPath(filePathAbsoluteFilesystem);
|
|
41
40
|
const isHeader = isHeaderFile(filePathAbsoluteFilesystem);
|
|
42
41
|
const isPageConfigFile = !isValueFile;
|
|
43
42
|
if (!isHeader && !isPageConfigFile) {
|
|
44
43
|
return null;
|
|
45
44
|
}
|
|
46
|
-
const filePathToShowToUser = getFilePathToShowToUser(filePath);
|
|
47
45
|
assertWarning(isPageConfigFile, `${filePathToShowToUser} is a JavaScript header file (.h.js), but JavaScript header files should only be used for +config.h.js, see https://vike.dev/header-file`, { onlyOnce: true });
|
|
48
46
|
// Remove the imports
|
|
49
47
|
const res = replaceImportStatements(codeOriginal, filePathToShowToUser);
|
|
@@ -273,7 +271,7 @@ function triggerPrepareStackTrace(err) {
|
|
|
273
271
|
function getErrIntroMsg(operation, filePath) {
|
|
274
272
|
const msg = [
|
|
275
273
|
pc.red(`Failed to ${operation}`),
|
|
276
|
-
pc.bold(pc.red(
|
|
274
|
+
pc.bold(pc.red(filePath.filePathToShowToUser)),
|
|
277
275
|
pc.red(`because:`)
|
|
278
276
|
].join(' ');
|
|
279
277
|
return msg;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { log404 };
|
|
2
|
-
export {
|
|
2
|
+
export { getRoutesInfo };
|
|
3
3
|
import type { PageRoutes } from '../../../../shared/route/index.js';
|
|
4
4
|
declare function log404(pageContext: {
|
|
5
5
|
urlPathname: string;
|
|
@@ -7,4 +7,4 @@ declare function log404(pageContext: {
|
|
|
7
7
|
isClientSideNavigation: boolean;
|
|
8
8
|
_pageRoutes: PageRoutes;
|
|
9
9
|
}): Promise<void>;
|
|
10
|
-
declare function
|
|
10
|
+
declare function getRoutesInfo(pageRoutes: PageRoutes): string | null;
|