vike 0.4.159 → 0.4.160-commit-a1101c1
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/index.js +20 -1
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +18 -0
- 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/{replaceImportStatements.js → getVikeConfig/transformImports.js} +44 -13
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.js → getVikeConfig/transpileAndExecuteFile.js} +110 -77
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +58 -279
- package/dist/cjs/node/plugin/plugins/previewConfig.js +1 -1
- package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
- package/dist/cjs/node/plugin/shared/loggerNotProd/log.js +3 -3
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +4 -3
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/html/renderHtml.js +1 -1
- package/dist/cjs/node/runtime/html/stream.js +2 -2
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +1 -1
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/shared/page-configs/assertPlusFileExport.js +44 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +2 -2
- package/dist/cjs/shared/route/abort.js +1 -1
- package/dist/cjs/utils/assert.js +5 -6
- package/dist/cjs/utils/assertIsNotProductionRuntime.js +35 -17
- package/dist/cjs/utils/nodeEnv.js +11 -1
- package/dist/cjs/utils/projectInfo.js +2 -4
- package/dist/esm/node/plugin/index.js +21 -2
- package/dist/esm/node/plugin/plugins/devConfig/index.js +2 -2
- package/dist/esm/node/plugin/plugins/importBuild/index.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigFileExport.js +12 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +6 -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/{replaceImportStatements.d.ts → getVikeConfig/transformImports.d.ts} +5 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{replaceImportStatements.js → getVikeConfig/transformImports.js} +43 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.d.ts → getVikeConfig/transpileAndExecuteFile.d.ts} +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/{transpileAndExecuteFile.js → getVikeConfig/transpileAndExecuteFile.js} +110 -77
- 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 +55 -276
- package/dist/esm/node/plugin/plugins/previewConfig.js +2 -2
- package/dist/esm/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
- package/dist/esm/node/plugin/shared/loggerNotProd/log.js +3 -3
- package/dist/esm/node/plugin/shared/loggerNotProd.js +1 -1
- package/dist/esm/node/runtime/globalContext.js +5 -4
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/esm/node/runtime/html/renderHtml.js +1 -1
- package/dist/esm/node/runtime/html/stream.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +1 -1
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/esm/shared/page-configs/Config.d.ts +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +4 -0
- package/dist/esm/shared/page-configs/assertPlusFileExport.d.ts +2 -0
- package/dist/esm/shared/page-configs/assertPlusFileExport.js +38 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +2 -2
- package/dist/esm/shared/route/abort.js +2 -2
- package/dist/esm/utils/assert.js +5 -6
- package/dist/esm/utils/assertIsNotProductionRuntime.d.ts +8 -6
- package/dist/esm/utils/assertIsNotProductionRuntime.js +35 -17
- package/dist/esm/utils/debug.d.ts +1 -1
- package/dist/esm/utils/nodeEnv.d.ts +2 -0
- package/dist/esm/utils/nodeEnv.js +10 -0
- package/dist/esm/utils/projectInfo.d.ts +2 -8
- package/dist/esm/utils/projectInfo.js +2 -4
- package/package.json +1 -1
- package/dist/cjs/shared/page-configs/assertExports.js +0 -67
- package/dist/esm/shared/page-configs/assertExports.d.ts +0 -6
- package/dist/esm/shared/page-configs/assertExports.js +0 -61
|
@@ -8,28 +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 replaceImportStatements_js_1 = require("./replaceImportStatements.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 assertExports_js_1 = require("../../../../../shared/page-configs/assertExports.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");
|
|
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");
|
|
23
24
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
24
25
|
let devServerIsCorrupt = false;
|
|
25
26
|
let wasConfigInvalid = null;
|
|
26
27
|
let vikeConfigPromise = null;
|
|
27
28
|
const vikeConfigDependencies = new Set();
|
|
28
29
|
exports.vikeConfigDependencies = vikeConfigDependencies;
|
|
29
|
-
const filesEnv = new Map();
|
|
30
30
|
function reloadVikeConfig(userRootDir, outDirRoot, extensions) {
|
|
31
31
|
vikeConfigDependencies.clear();
|
|
32
|
-
|
|
32
|
+
(0, resolveImportPath_js_1.clearFilesEnvMap)();
|
|
33
33
|
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, true, extensions, true);
|
|
34
34
|
handleReloadSideEffects();
|
|
35
35
|
}
|
|
@@ -89,7 +89,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
89
89
|
let interfaceFilesByLocationId = {};
|
|
90
90
|
// Config files
|
|
91
91
|
await Promise.all(configFiles.map(async (filePath) => {
|
|
92
|
-
const { configFile, extendsConfigs } = await loadConfigFile(filePath, userRootDir, []);
|
|
92
|
+
const { configFile, extendsConfigs } = await (0, loadFileConfigEnv_js_1.loadConfigFile)(filePath, userRootDir, [], false);
|
|
93
93
|
const interfaceFile = getInterfaceFileFromConfigFile(configFile, false);
|
|
94
94
|
const locationId = (0, filesystemRouting_js_1.getLocationId)(filePath.filePathAbsoluteVite);
|
|
95
95
|
interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
|
|
@@ -105,7 +105,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
105
105
|
(0, utils_js_1.assert)(configName);
|
|
106
106
|
const interfaceFile = {
|
|
107
107
|
filePath,
|
|
108
|
-
|
|
108
|
+
fileExportsByConfigName: {
|
|
109
109
|
[configName]: {}
|
|
110
110
|
},
|
|
111
111
|
isConfigFile: false,
|
|
@@ -118,7 +118,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
118
118
|
// - We already need to load +meta.js here (to get the custom config definitions defined by the user)
|
|
119
119
|
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn, configName);
|
|
120
120
|
if (configDef && isConfigEnv(configDef, configName)) {
|
|
121
|
-
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
121
|
+
await (0, loadFileConfigEnv_js_1.loadValueFile)(interfaceFile, configName, userRootDir);
|
|
122
122
|
}
|
|
123
123
|
}
|
|
124
124
|
{
|
|
@@ -139,23 +139,6 @@ function getConfigDefinition(configDefinitionsRelevant, configName, filePathToSh
|
|
|
139
139
|
function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
140
140
|
return configDefinitions[configName] ?? null;
|
|
141
141
|
}
|
|
142
|
-
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
143
|
-
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath, true, userRootDir);
|
|
144
|
-
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
145
|
-
(0, assertExports_js_1.assertExportsOfValueFile)(fileExports, filePathToShowToUser, configName);
|
|
146
|
-
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
147
|
-
const configName_ = exportName === 'default' ? configName : exportName;
|
|
148
|
-
interfaceValueFile.configMap[configName_] = { configValue };
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
async function loadImportedFile(filePath, userRootDir, importedFilesLoaded) {
|
|
152
|
-
const f = filePath.filePathAbsoluteFilesystem;
|
|
153
|
-
if (!importedFilesLoaded[f]) {
|
|
154
|
-
importedFilesLoaded[f] = (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(filePath, true, userRootDir).then((r) => r.fileExports);
|
|
155
|
-
}
|
|
156
|
-
const fileExports = await importedFilesLoaded[f];
|
|
157
|
-
return fileExports;
|
|
158
|
-
}
|
|
159
142
|
function isConfigEnv(configDef, configName) {
|
|
160
143
|
const configEnv = configDef.env;
|
|
161
144
|
if (configDef.cumulative) {
|
|
@@ -168,16 +151,15 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
168
151
|
const { fileExports, filePath, extendsFilePaths } = configFile;
|
|
169
152
|
const interfaceFile = {
|
|
170
153
|
filePath,
|
|
171
|
-
|
|
154
|
+
fileExportsByConfigName: {},
|
|
172
155
|
isConfigFile: true,
|
|
173
156
|
isValueFile: false,
|
|
174
157
|
isConfigExtend,
|
|
175
158
|
extendsFilePaths
|
|
176
159
|
};
|
|
177
|
-
const
|
|
178
|
-
(
|
|
179
|
-
|
|
180
|
-
interfaceFile.configMap[configName] = { configValue };
|
|
160
|
+
const fileExport = (0, getConfigFileExport_js_1.getConfigFileExport)(fileExports, filePath.filePathToShowToUser);
|
|
161
|
+
Object.entries(fileExport).forEach(([configName, configValue]) => {
|
|
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, replaceImportStatements_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
|
-
Object.entries(interfaceFilesRelevant).forEach(([_locationId, interfaceFiles]) => {
|
|
555
|
+
Object.entries(interfaceFilesRelevant).reverse().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,109 +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
|
-
assertExtendsImportPath(importPath, filePathAbsoluteFilesystem, 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);
|
|
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 assertExtendsImportPath(importPath, filePath, configFilePath) {
|
|
912
|
-
if ((0, utils_js_1.isNpmPackageImport)(importPath)) {
|
|
913
|
-
const fileDir = path_1.default.posix.dirname(filePath) + '/';
|
|
914
|
-
const fileName = path_1.default.posix.basename(filePath);
|
|
915
|
-
const fileNameBaseCorrect = '+config';
|
|
916
|
-
const [fileNameBase, ...fileNameRest] = fileName.split('.');
|
|
917
|
-
const fileNameCorrect = [fileNameBaseCorrect, ...fileNameRest].join('.');
|
|
918
|
-
(0, utils_js_1.assertWarning)(fileNameBase === fileNameBaseCorrect, `Rename ${fileName} to ${fileNameCorrect} in ${fileDir}`, {
|
|
919
|
-
onlyOnce: true
|
|
920
|
-
});
|
|
921
|
-
}
|
|
922
|
-
else {
|
|
923
|
-
(0, utils_js_1.assertWarning)(false, `${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 feature.`, { onlyOnce: true });
|
|
924
|
-
}
|
|
925
|
-
}
|
|
926
|
-
function getExtendsImportData(configFileExports, configFilePath) {
|
|
927
|
-
const { filePathToShowToUser } = configFilePath;
|
|
928
|
-
(0, assertExports_js_1.assertExportsOfConfigFile)(configFileExports, filePathToShowToUser);
|
|
929
|
-
const defaultExports = configFileExports.default;
|
|
930
|
-
const wrongUsage = `${filePathToShowToUser} sets the config ${picocolors_1.default.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
|
|
931
|
-
let extendList;
|
|
932
|
-
if (!('extends' in defaultExports)) {
|
|
933
|
-
return [];
|
|
934
|
-
}
|
|
935
|
-
else if ((0, utils_js_1.hasProp)(defaultExports, 'extends', 'string')) {
|
|
936
|
-
extendList = [defaultExports.extends];
|
|
937
|
-
}
|
|
938
|
-
else if ((0, utils_js_1.hasProp)(defaultExports, 'extends', 'string[]')) {
|
|
939
|
-
extendList = defaultExports.extends;
|
|
940
|
-
}
|
|
941
|
-
else {
|
|
942
|
-
(0, utils_js_1.assertUsage)(false, wrongUsage);
|
|
943
|
-
}
|
|
944
|
-
const extendsImportData = extendList.map((importDataSerialized) => {
|
|
945
|
-
const importData = (0, replaceImportStatements_js_1.parseImportData)(importDataSerialized);
|
|
946
|
-
(0, utils_js_1.assertUsage)(importData, wrongUsage);
|
|
947
|
-
return importData;
|
|
948
|
-
});
|
|
949
|
-
return extendsImportData;
|
|
950
|
-
}
|
|
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
|
+
*/
|
|
951
756
|
function isGlobalConfig(configName) {
|
|
952
757
|
if (configName === 'prerender')
|
|
953
758
|
return false;
|
|
@@ -1030,32 +835,6 @@ function determineIsErrorPage(routeFilesystem) {
|
|
|
1030
835
|
(0, utils_js_1.assertPosixPath)(routeFilesystem);
|
|
1031
836
|
return routeFilesystem.split('/').includes('_error');
|
|
1032
837
|
}
|
|
1033
|
-
function resolveImportPath(importData, importerFilePath) {
|
|
1034
|
-
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
1035
|
-
(0, utils_js_1.assertPosixPath)(importerFilePathAbsolute);
|
|
1036
|
-
const cwd = path_1.default.posix.dirname(importerFilePathAbsolute);
|
|
1037
|
-
// 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
|
|
1038
|
-
// filePathAbsoluteFilesystem is expected to be null when importData.importPath is a Vite path alias
|
|
1039
|
-
const filePathAbsoluteFilesystem = (0, utils_js_1.requireResolve)(importData.importPath, cwd);
|
|
1040
|
-
return filePathAbsoluteFilesystem;
|
|
1041
|
-
}
|
|
1042
|
-
function assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath) {
|
|
1043
|
-
const { importPath: importPath, importStringWasGenerated, importString } = importData;
|
|
1044
|
-
const { filePathToShowToUser } = importerFilePath;
|
|
1045
|
-
if (!filePathAbsoluteFilesystem) {
|
|
1046
|
-
const importPathString = picocolors_1.default.cyan(`'${importPath}'`);
|
|
1047
|
-
const errIntro = importStringWasGenerated
|
|
1048
|
-
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
1049
|
-
: `The import ${picocolors_1.default.cyan(importString)} defined in ${filePathToShowToUser}`;
|
|
1050
|
-
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
1051
|
-
if (importPath.startsWith('.')) {
|
|
1052
|
-
(0, utils_js_1.assertUsage)(false, `${errIntro2} point to an existing file?`);
|
|
1053
|
-
}
|
|
1054
|
-
else {
|
|
1055
|
-
(0, utils_js_1.assertUsage)(false, `${errIntro2} exist?`);
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
838
|
function isVikeConfigFile(filePath) {
|
|
1060
839
|
return !!getConfigName(filePath);
|
|
1061
840
|
}
|
|
@@ -33,7 +33,7 @@ function previewConfig() {
|
|
|
33
33
|
- This ugly hack to set appType for preview won't be need once https://github.com/vitejs/vite/pull/14855 is merged.
|
|
34
34
|
config.appType = 'mpa'
|
|
35
35
|
*/
|
|
36
|
-
(0, utils_js_1.
|
|
36
|
+
(0, utils_js_1.markEnvAsVitePreview)();
|
|
37
37
|
return () => {
|
|
38
38
|
assertDist();
|
|
39
39
|
/* We don't use this condition (we wrongfully always use the SSR middleware) because of the regression introduced by https://github.com/vitejs/vite/pull/14756 which stops servering .html files when `appType: 'custom'`.
|
|
@@ -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)();
|
|
@@ -22,10 +22,10 @@ exports.logWithVikeTag = logWithVikeTag;
|
|
|
22
22
|
function getProjectTag(showVikeVersion) {
|
|
23
23
|
let projectTag;
|
|
24
24
|
if (showVikeVersion) {
|
|
25
|
-
projectTag = `[
|
|
25
|
+
projectTag = `[vike@${utils_js_1.projectInfo.projectVersion}]`;
|
|
26
26
|
}
|
|
27
27
|
else {
|
|
28
|
-
projectTag = `[
|
|
28
|
+
projectTag = `[vike]`;
|
|
29
29
|
}
|
|
30
30
|
return projectTag;
|
|
31
31
|
}
|
|
@@ -89,7 +89,7 @@ function prependTags(msg, projectTag, category, logType) {
|
|
|
89
89
|
return picocolors_1.default.yellow(s);
|
|
90
90
|
if (projectTag === '[vite]')
|
|
91
91
|
return picocolors_1.default.bold(picocolors_1.default.cyan(s));
|
|
92
|
-
if (projectTag.startsWith(`[
|
|
92
|
+
if (projectTag.startsWith(`[vike`))
|
|
93
93
|
return picocolors_1.default.bold(picocolors_1.default.cyan(s));
|
|
94
94
|
(0, utils_js_1.assert)(false);
|
|
95
95
|
};
|
|
@@ -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");
|
|
@@ -157,7 +157,8 @@ function assertNodeEnv(hasViteDevServer) {
|
|
|
157
157
|
const nodeEnv = (0, utils_js_1.getNodeEnv)();
|
|
158
158
|
if (nodeEnv === null || nodeEnv === 'test')
|
|
159
159
|
return;
|
|
160
|
-
const isDevNodeEnv =
|
|
161
|
-
//
|
|
162
|
-
|
|
160
|
+
const isDevNodeEnv = (0, utils_js_1.isNodeEnvDev)();
|
|
161
|
+
// - Calling Vite's createServer() is enough for hasViteDevServer to be true, even without actually adding Vite's development middleware to the server: https://github.com/vikejs/vike/issues/792#issuecomment-1516830759
|
|
162
|
+
// - We should change this to be a warning if it blocks users (e.g. if a bad-citizen tool sets a wrong process.env.NODE_ENV value).
|
|
163
|
+
(0, utils_js_1.assertUsage)(hasViteDevServer === isDevNodeEnv, `Vite's development server was${hasViteDevServer ? '' : "n't"} instantiated while the environment is set to be a ${isDevNodeEnv ? 'development' : 'production'} environment by ${picocolors_1.default.cyan(`process.env.NODE_ENV === ${JSON.stringify(nodeEnv)}`)} which is contradictory, see https://vike.dev/NODE_ENV`);
|
|
163
164
|
}
|
|
@@ -91,7 +91,7 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
|
|
|
91
91
|
const positionJavaScriptEntry = (() => {
|
|
92
92
|
if (pageContext._pageContextPromise) {
|
|
93
93
|
(0, utils_js_1.assertWarning)(!injectToStream, "[getHtmlTags()] We recommend against using streaming and a pageContext promise at the same time as progressive hydration won't work", { onlyOnce: true });
|
|
94
|
-
// If there is a pageContext._pageContextPromise (which is resolved after the stream has ended) then the pageContext JSON data needs to await for it: https://vike.dev/
|
|
94
|
+
// If there is a pageContext._pageContextPromise (which is resolved after the stream has ended) then the pageContext JSON data needs to await for it: https://vike.dev/streaming#initial-data-after-stream-end
|
|
95
95
|
return 'HTML_END';
|
|
96
96
|
}
|
|
97
97
|
if (injectToStream) {
|
|
@@ -186,7 +186,7 @@ async function renderTemplate(templateContent, pageContext) {
|
|
|
186
186
|
const varType = typeof templateVar;
|
|
187
187
|
const streamNote = ['boolean', 'number', 'bigint', 'symbol'].includes(varType)
|
|
188
188
|
? null
|
|
189
|
-
: '(See https://vike.dev/
|
|
189
|
+
: '(See https://vike.dev/streaming for HTML streaming.)';
|
|
190
190
|
(0, utils_js_1.assertUsage)(varType === 'string', getErrMsg(picocolors_1.default.cyan(`typeof htmlVar === "${varType}"`), streamNote));
|
|
191
191
|
}
|
|
192
192
|
{
|
|
@@ -631,7 +631,7 @@ exports.isStream = isStream;
|
|
|
631
631
|
const __streamPipeWeb = '__streamPipeWeb';
|
|
632
632
|
/** @deprecated */
|
|
633
633
|
function pipeWebStream(pipe) {
|
|
634
|
-
(0, utils_js_1.assertWarning)(false, 'pipeWebStream() is outdated, use stampPipe() instead. See https://vike.dev/
|
|
634
|
+
(0, utils_js_1.assertWarning)(false, 'pipeWebStream() is outdated, use stampPipe() instead. See https://vike.dev/streaming', {
|
|
635
635
|
onlyOnce: true,
|
|
636
636
|
showStackTrace: true
|
|
637
637
|
});
|
|
@@ -668,7 +668,7 @@ exports.isStreamPipeWeb = isStreamPipeWeb;
|
|
|
668
668
|
const __streamPipeNode = '__streamPipeNode';
|
|
669
669
|
/** @deprecated */
|
|
670
670
|
function pipeNodeStream(pipe) {
|
|
671
|
-
(0, utils_js_1.assertWarning)(false, 'pipeNodeStream() is outdated, use stampPipe() instead. See https://vike.dev/
|
|
671
|
+
(0, utils_js_1.assertWarning)(false, 'pipeNodeStream() is outdated, use stampPipe() instead. See https://vike.dev/streaming', {
|
|
672
672
|
onlyOnce: true,
|
|
673
673
|
showStackTrace: true
|
|
674
674
|
});
|
|
@@ -125,11 +125,11 @@ function processHookReturnValue(hookReturnValue, renderHook) {
|
|
|
125
125
|
const val = hookReturnValue.pageContext;
|
|
126
126
|
const errBegin = `${errPrefix} returned ${picocolors_1.default.cyan('{ pageContext }')}, but ${picocolors_1.default.cyan('pageContext')}`;
|
|
127
127
|
if ((0, utils_js_1.isPromise)(val) || (0, utils_js_1.isCallable)(val)) {
|
|
128
|
-
(0, utils_js_1.assertWarning)(!(0, utils_js_1.isPromise)(val), `${errBegin} is a promise which is deprecated in favor of async functions, see https://vike.dev/
|
|
128
|
+
(0, utils_js_1.assertWarning)(!(0, utils_js_1.isPromise)(val), `${errBegin} is a promise which is deprecated in favor of async functions, see https://vike.dev/streaming#initial-data-after-stream-end`, { onlyOnce: true });
|
|
129
129
|
pageContextPromise = val;
|
|
130
130
|
}
|
|
131
131
|
else {
|
|
132
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(val), `${errBegin} should be an object or an async function, see https://vike.dev/
|
|
132
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isObject)(val), `${errBegin} should be an object or an async function, see https://vike.dev/streaming#initial-data-after-stream-end`);
|
|
133
133
|
(0, assertPageContextProvidedByUser_js_1.assertPageContextProvidedByUser)(val, renderHook);
|
|
134
134
|
pageContextProvidedByRenderHook = val;
|
|
135
135
|
}
|
|
@@ -8,7 +8,7 @@ const stream_js_1 = require("../html/stream.js");
|
|
|
8
8
|
const utils_js_1 = require("../utils.js");
|
|
9
9
|
const renderHtml_js_1 = require("../html/renderHtml.js");
|
|
10
10
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
11
|
-
const streamDocs = 'See https://vike.dev/
|
|
11
|
+
const streamDocs = 'See https://vike.dev/streaming for more information.';
|
|
12
12
|
function getHttpResponseBody(htmlRender, renderHook) {
|
|
13
13
|
if (typeof htmlRender !== 'string') {
|
|
14
14
|
(0, utils_js_1.assertUsage)(false, getErrMsg(htmlRender, renderHook, 'body', `Use ${picocolors_1.default.cyan('pageContext.httpResponse.pipe()')} instead`));
|