vike 0.4.160-commit-a1101c1 → 0.4.160-commit-facd36e
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/autoFullBuild.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +9 -0
- package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +28 -46
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +5 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +33 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +7 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +21 -27
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +149 -110
- package/dist/cjs/node/plugin/utils.js +1 -2
- package/dist/cjs/node/prerender/runPrerender.js +12 -5
- package/dist/cjs/node/runtime/globalContext.js +7 -4
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +81 -43
- package/dist/cjs/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/cjs/shared/route/executeGuardHook.js +3 -2
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/{findUserPackageJsonPath.js → findFile.js} +11 -8
- package/dist/cjs/utils/nodeEnv.js +23 -1
- package/dist/cjs/utils/objectKeys.js +19 -3
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/sorter.js +62 -1
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +10 -1
- package/dist/esm/node/plugin/plugins/commonConfig.js +2 -2
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +39 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +29 -47
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +27 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.d.ts → transformFileImports.d.ts} +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +6 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +20 -26
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +148 -109
- package/dist/esm/node/plugin/utils.d.ts +1 -2
- package/dist/esm/node/plugin/utils.js +1 -2
- package/dist/esm/node/prerender/runPrerender.js +13 -6
- package/dist/esm/node/runtime/globalContext.js +8 -5
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +1 -1
- package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +8 -0
- package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +80 -42
- package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +2 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/esm/shared/route/executeGuardHook.js +3 -2
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- package/dist/esm/utils/findFile.d.ts +3 -0
- package/dist/esm/utils/findFile.js +21 -0
- package/dist/esm/utils/nodeEnv.d.ts +4 -0
- package/dist/esm/utils/nodeEnv.js +19 -0
- package/dist/esm/utils/objectKeys.d.ts +10 -1
- package/dist/esm/utils/objectKeys.js +20 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/sorter.d.ts +59 -0
- package/dist/esm/utils/sorter.js +61 -0
- package/package.json +1 -1
- package/dist/cjs/utils/objectEntries.js +0 -8
- package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +0 -13
- package/dist/esm/utils/findUserPackageJsonPath.d.ts +0 -2
- package/dist/esm/utils/findUserPackageJsonPath.js +0 -18
- package/dist/esm/utils/objectEntries.d.ts +0 -4
- package/dist/esm/utils/objectEntries.js +0 -5
- /package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.d.ts → loadFileAtConfigTime.d.ts} +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.d.ts +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
|
@@ -19,8 +19,9 @@ const getConfigVike_js_1 = require("../../../../shared/getConfigVike.js");
|
|
|
19
19
|
const getConfigValuesSerialized_js_1 = require("./getConfigValuesSerialized.js");
|
|
20
20
|
const crawlPlusFiles_js_1 = require("./getVikeConfig/crawlPlusFiles.js");
|
|
21
21
|
const getConfigFileExport_js_1 = require("./getConfigFileExport.js");
|
|
22
|
-
const
|
|
22
|
+
const loadFileAtConfigTime_js_1 = require("./getVikeConfig/loadFileAtConfigTime.js");
|
|
23
23
|
const resolveImportPath_js_1 = require("./getVikeConfig/resolveImportPath.js");
|
|
24
|
+
const resolveFilePath_js_1 = require("./getVikeConfig/resolveFilePath.js");
|
|
24
25
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
25
26
|
let devServerIsCorrupt = false;
|
|
26
27
|
let wasConfigInvalid = null;
|
|
@@ -87,69 +88,77 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
87
88
|
}
|
|
88
89
|
});
|
|
89
90
|
let interfaceFilesByLocationId = {};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const interfaceFile = getInterfaceFileFromConfigFile(
|
|
99
|
-
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
100
|
-
});
|
|
101
|
-
}));
|
|
102
|
-
// Value files
|
|
103
|
-
await Promise.all(valueFiles.map(async (filePath) => {
|
|
104
|
-
const configName = getConfigName(filePath.filePathAbsoluteVite);
|
|
105
|
-
(0, utils_js_1.assert)(configName);
|
|
106
|
-
const interfaceFile = {
|
|
107
|
-
filePath,
|
|
108
|
-
fileExportsByConfigName: {
|
|
109
|
-
[configName]: {}
|
|
110
|
-
},
|
|
111
|
-
isConfigFile: false,
|
|
112
|
-
isValueFile: true,
|
|
113
|
-
configName
|
|
114
|
-
};
|
|
115
|
-
{
|
|
116
|
-
// We don't have access to the custom config definitions defined by the user yet.
|
|
117
|
-
// - If `configDef` is `undefined` => we load the file +{configName}.js later.
|
|
118
|
-
// - We already need to load +meta.js here (to get the custom config definitions defined by the user)
|
|
119
|
-
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn, configName);
|
|
120
|
-
if (configDef && isConfigEnv(configDef, configName)) {
|
|
121
|
-
await (0, loadFileConfigEnv_js_1.loadValueFile)(interfaceFile, configName, userRootDir);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
{
|
|
125
|
-
const locationId = (0, filesystemRouting_js_1.getLocationId)(filePath.filePathAbsoluteVite);
|
|
91
|
+
await Promise.all([
|
|
92
|
+
// Config files
|
|
93
|
+
...configFiles.map(async (filePath) => {
|
|
94
|
+
const { filePathRelativeToUserRootDir } = filePath;
|
|
95
|
+
(0, utils_js_1.assert)(filePathRelativeToUserRootDir);
|
|
96
|
+
const { configFile, extendsConfigs } = await (0, loadFileAtConfigTime_js_1.loadConfigFile)(filePath, userRootDir, [], false);
|
|
97
|
+
(0, utils_js_1.assert)(filePath.filePathRelativeToUserRootDir);
|
|
98
|
+
const locationId = (0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir);
|
|
99
|
+
const interfaceFile = getInterfaceFileFromConfigFile(configFile, false, locationId);
|
|
126
100
|
interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
|
|
127
101
|
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
128
|
-
|
|
129
|
-
|
|
102
|
+
extendsConfigs.forEach((extendsConfig) => {
|
|
103
|
+
/* We purposely use the same locationId because the Vike extension's config should only apply to where it's being extended from, for example:
|
|
104
|
+
```js
|
|
105
|
+
// /pages/admin/+config.h.js
|
|
106
|
+
|
|
107
|
+
import vikeVue from 'vike-vue/config'
|
|
108
|
+
// Should only apply to /pages/admin/**
|
|
109
|
+
export default { extends: [vikeVue] }
|
|
110
|
+
```
|
|
111
|
+
```js
|
|
112
|
+
// /pages/marketing/+config.h.js
|
|
113
|
+
|
|
114
|
+
import vikeReact from 'vike-react/config'
|
|
115
|
+
// Should only apply to /pages/marketing/**
|
|
116
|
+
export default { extends: [vikeReact] }
|
|
117
|
+
```
|
|
118
|
+
*/
|
|
119
|
+
const interfaceFile = getInterfaceFileFromConfigFile(extendsConfig, true, locationId);
|
|
120
|
+
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
121
|
+
});
|
|
122
|
+
}),
|
|
123
|
+
// Value files
|
|
124
|
+
...valueFiles.map(async (filePath) => {
|
|
125
|
+
const { filePathRelativeToUserRootDir } = filePath;
|
|
126
|
+
(0, utils_js_1.assert)(filePathRelativeToUserRootDir);
|
|
127
|
+
const configName = getConfigName(filePathRelativeToUserRootDir);
|
|
128
|
+
(0, utils_js_1.assert)(configName);
|
|
129
|
+
const locationId = (0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir);
|
|
130
|
+
const interfaceFile = {
|
|
131
|
+
locationId,
|
|
132
|
+
filePath,
|
|
133
|
+
fileExportsByConfigName: {
|
|
134
|
+
[configName]: {}
|
|
135
|
+
},
|
|
136
|
+
isConfigFile: false,
|
|
137
|
+
isValueFile: true,
|
|
138
|
+
configName
|
|
139
|
+
};
|
|
140
|
+
{
|
|
141
|
+
// We don't have access to the custom config definitions defined by the user yet.
|
|
142
|
+
// - If `configDef` is `undefined` => we load the file +{configName}.js later.
|
|
143
|
+
// - We already need to load +meta.js here (to get the custom config definitions defined by the user)
|
|
144
|
+
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn, configName);
|
|
145
|
+
if (configDef && isConfigEnv(configDef, configName)) {
|
|
146
|
+
await (0, loadFileAtConfigTime_js_1.loadValueFile)(interfaceFile, configName, userRootDir);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
{
|
|
150
|
+
interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
|
|
151
|
+
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
]);
|
|
130
155
|
assertAllConfigsAreKnown(interfaceFilesByLocationId);
|
|
131
156
|
return interfaceFilesByLocationId;
|
|
132
157
|
}
|
|
133
|
-
function
|
|
134
|
-
const configDef = configDefinitionsRelevant[configName];
|
|
135
|
-
assertConfigExists(configName, Object.keys(configDefinitionsRelevant), filePathToShowToUser);
|
|
136
|
-
(0, utils_js_1.assert)(configDef);
|
|
137
|
-
return configDef;
|
|
138
|
-
}
|
|
139
|
-
function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
140
|
-
return configDefinitions[configName] ?? null;
|
|
141
|
-
}
|
|
142
|
-
function isConfigEnv(configDef, configName) {
|
|
143
|
-
const configEnv = configDef.env;
|
|
144
|
-
if (configDef.cumulative) {
|
|
145
|
-
// In principle we could lift that requirement (but it requires non-trivial modifications)
|
|
146
|
-
(0, utils_js_1.assertUsage)(configEnv.config, `Config ${picocolors_1.default.cyan(configName)} needs its ${picocolors_1.default.cyan('env')} to have ${picocolors_1.default.cyan('{ config: true }')} (because ${picocolors_1.default.cyan(configName)} is a ${picocolors_1.default.cyan('cumulative')} config)`);
|
|
147
|
-
}
|
|
148
|
-
return !!configEnv.config;
|
|
149
|
-
}
|
|
150
|
-
function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
158
|
+
function getInterfaceFileFromConfigFile(configFile, isConfigExtend, locationId) {
|
|
151
159
|
const { fileExports, filePath, extendsFilePaths } = configFile;
|
|
152
160
|
const interfaceFile = {
|
|
161
|
+
locationId,
|
|
153
162
|
filePath,
|
|
154
163
|
fileExportsByConfigName: {},
|
|
155
164
|
isConfigFile: true,
|
|
@@ -165,12 +174,12 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
165
174
|
}
|
|
166
175
|
/** Show error message upon unknown config */
|
|
167
176
|
function assertAllConfigsAreKnown(interfaceFilesByLocationId) {
|
|
168
|
-
|
|
177
|
+
(0, utils_js_1.objectEntries)(interfaceFilesByLocationId).forEach(([locationId, interfaceFiles]) => {
|
|
169
178
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesByLocationId, locationId);
|
|
170
|
-
const
|
|
179
|
+
const configDefinitions = getConfigDefinitions(interfaceFilesRelevant);
|
|
171
180
|
interfaceFiles.forEach((interfaceFile) => {
|
|
172
181
|
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
173
|
-
assertConfigExists(configName, Object.keys(
|
|
182
|
+
assertConfigExists(configName, Object.keys(configDefinitions), interfaceFile.filePath.filePathToShowToUser);
|
|
174
183
|
});
|
|
175
184
|
});
|
|
176
185
|
});
|
|
@@ -220,11 +229,11 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
220
229
|
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions);
|
|
221
230
|
const importedFilesLoaded = {};
|
|
222
231
|
const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
|
|
223
|
-
const pageConfigs = await Promise.all(
|
|
232
|
+
const pageConfigs = await Promise.all((0, utils_js_1.objectEntries)(interfaceFilesByLocationId)
|
|
224
233
|
.filter(([_pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
225
234
|
.map(async ([locationId]) => {
|
|
226
235
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesByLocationId, locationId);
|
|
227
|
-
const
|
|
236
|
+
const configDefinitions = getConfigDefinitions(interfaceFilesRelevant);
|
|
228
237
|
// Load value files of custom config-only configs
|
|
229
238
|
await Promise.all(getInterfaceFileList(interfaceFilesRelevant).map(async (interfaceFile) => {
|
|
230
239
|
if (!interfaceFile.isValueFile)
|
|
@@ -232,7 +241,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
232
241
|
const { configName } = interfaceFile;
|
|
233
242
|
if (isGlobalConfig(configName))
|
|
234
243
|
return;
|
|
235
|
-
const configDef = getConfigDefinition(
|
|
244
|
+
const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
236
245
|
if (!isConfigEnv(configDef, configName))
|
|
237
246
|
return;
|
|
238
247
|
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
@@ -240,10 +249,10 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
240
249
|
return;
|
|
241
250
|
// Value files of built-in configs should have already been loaded at loadInterfaceFiles()
|
|
242
251
|
(0, utils_js_1.assert)(!(configName in configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn));
|
|
243
|
-
await (0,
|
|
252
|
+
await (0, loadFileAtConfigTime_js_1.loadValueFile)(interfaceFile, configName, userRootDir);
|
|
244
253
|
}));
|
|
245
|
-
|
|
246
|
-
await Promise.all((0, utils_js_1.objectEntries)(
|
|
254
|
+
let configValueSources = {};
|
|
255
|
+
await Promise.all((0, utils_js_1.objectEntries)(configDefinitions)
|
|
247
256
|
.filter(([configName]) => !isGlobalConfig(configName))
|
|
248
257
|
.map(async ([configName, configDef]) => {
|
|
249
258
|
const sources = await resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir, importedFilesLoaded);
|
|
@@ -251,10 +260,11 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
251
260
|
return;
|
|
252
261
|
configValueSources[configName] = sources;
|
|
253
262
|
}));
|
|
263
|
+
configValueSources = sortConfigValueSources(configValueSources, locationId);
|
|
254
264
|
const { routeFilesystem, isErrorPage } = determineRouteFilesystem(locationId, configValueSources);
|
|
255
|
-
applyEffectsAll(configValueSources,
|
|
256
|
-
const configValuesComputed = getComputed(configValueSources,
|
|
257
|
-
const configValues = getConfigValues(configValueSources, configValuesComputed,
|
|
265
|
+
applyEffectsAll(configValueSources, configDefinitions);
|
|
266
|
+
const configValuesComputed = getComputed(configValueSources, configDefinitions);
|
|
267
|
+
const configValues = getConfigValues(configValueSources, configValuesComputed, configDefinitions);
|
|
258
268
|
const pageConfig = {
|
|
259
269
|
pageId: locationId,
|
|
260
270
|
isErrorPage,
|
|
@@ -291,7 +301,7 @@ function interfacefileIsAlreaydLoaded(interfaceFile) {
|
|
|
291
301
|
return isAlreadyLoaded;
|
|
292
302
|
}
|
|
293
303
|
function getInterfaceFilesRelevant(interfaceFilesByLocationId, locationIdPage) {
|
|
294
|
-
const interfaceFilesRelevant = Object.fromEntries(
|
|
304
|
+
const interfaceFilesRelevant = Object.fromEntries((0, utils_js_1.objectEntries)(interfaceFilesByLocationId)
|
|
295
305
|
.filter(([locationId]) => {
|
|
296
306
|
return (0, filesystemRouting_js_1.isInherited)(locationId, locationIdPage);
|
|
297
307
|
})
|
|
@@ -306,14 +316,14 @@ function getInterfaceFileList(interfaceFilesByLocationId) {
|
|
|
306
316
|
return interfaceFiles;
|
|
307
317
|
}
|
|
308
318
|
async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded) {
|
|
309
|
-
const locationIds =
|
|
310
|
-
const interfaceFilesGlobal =
|
|
319
|
+
const locationIds = (0, utils_js_1.objectKeys)(interfaceFilesByLocationId);
|
|
320
|
+
const interfaceFilesGlobal = (0, utils_js_1.objectFromEntries)((0, utils_js_1.objectEntries)(interfaceFilesByLocationId).filter(([locationId]) => {
|
|
311
321
|
return (0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds);
|
|
312
322
|
}));
|
|
313
323
|
// Validate that global configs live in global interface files
|
|
314
324
|
{
|
|
315
325
|
const interfaceFilesGlobalPaths = [];
|
|
316
|
-
|
|
326
|
+
(0, utils_js_1.objectEntries)(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
|
|
317
327
|
(0, utils_js_1.assert)((0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds));
|
|
318
328
|
interfaceFiles.forEach(({ filePath: { filePathRelativeToUserRootDir } }) => {
|
|
319
329
|
if (filePathRelativeToUserRootDir) {
|
|
@@ -322,7 +332,7 @@ async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importe
|
|
|
322
332
|
});
|
|
323
333
|
});
|
|
324
334
|
const globalPaths = Array.from(new Set(interfaceFilesGlobalPaths.map((p) => path_1.default.posix.dirname(p))));
|
|
325
|
-
|
|
335
|
+
(0, utils_js_1.objectEntries)(interfaceFilesByLocationId).forEach(([locationId, interfaceFiles]) => {
|
|
326
336
|
interfaceFiles.forEach((interfaceFile) => {
|
|
327
337
|
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
328
338
|
if (!(0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds) && isGlobalConfig(configName)) {
|
|
@@ -446,6 +456,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
446
456
|
const conf = interfaceFile.fileExportsByConfigName[configName];
|
|
447
457
|
(0, utils_js_1.assert)(conf);
|
|
448
458
|
const configEnv = configDef.env;
|
|
459
|
+
const { locationId } = interfaceFile;
|
|
449
460
|
const definedAtConfigFile = {
|
|
450
461
|
...interfaceFile.filePath,
|
|
451
462
|
fileExportPathToShowToUser: ['default', configName]
|
|
@@ -471,6 +482,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
471
482
|
};
|
|
472
483
|
}
|
|
473
484
|
const configValueSource = {
|
|
485
|
+
locationId,
|
|
474
486
|
value: valueFilePath,
|
|
475
487
|
valueIsFilePath: true,
|
|
476
488
|
configEnv,
|
|
@@ -487,6 +499,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
487
499
|
const import_ = (0, resolveImportPath_js_1.resolveImport)(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
488
500
|
if (import_) {
|
|
489
501
|
const configValueSource = {
|
|
502
|
+
locationId,
|
|
490
503
|
configEnv,
|
|
491
504
|
valueIsImportedAtRuntime: true,
|
|
492
505
|
definedAt: import_
|
|
@@ -497,7 +510,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
497
510
|
configName !== 'extends') {
|
|
498
511
|
if (import_.filePathAbsoluteFilesystem) {
|
|
499
512
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(import_, 'filePathAbsoluteFilesystem', 'string')); // Help TS
|
|
500
|
-
const fileExport = await (0,
|
|
513
|
+
const fileExport = await (0, loadFileAtConfigTime_js_1.loadImportedFile)(import_, userRootDir, importedFilesLoaded);
|
|
501
514
|
configValueSource.value = fileExport;
|
|
502
515
|
}
|
|
503
516
|
else {
|
|
@@ -509,6 +522,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
509
522
|
}
|
|
510
523
|
// Defined by config file, i.e. +config.js file
|
|
511
524
|
const configValueSource = {
|
|
525
|
+
locationId,
|
|
512
526
|
value: configValue,
|
|
513
527
|
configEnv,
|
|
514
528
|
valueIsImportedAtRuntime: false,
|
|
@@ -521,6 +535,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
521
535
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
522
536
|
(0, utils_js_1.assert)(valueAlreadyLoaded === !!configEnv.config);
|
|
523
537
|
const configValueSource = {
|
|
538
|
+
locationId,
|
|
524
539
|
configEnv,
|
|
525
540
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
526
541
|
definedAt: {
|
|
@@ -551,8 +566,10 @@ function isDefiningPageConfig(configName) {
|
|
|
551
566
|
return ['Page', 'route'].includes(configName);
|
|
552
567
|
}
|
|
553
568
|
function getConfigDefinitions(interfaceFilesRelevant) {
|
|
554
|
-
const
|
|
555
|
-
Object.entries(interfaceFilesRelevant)
|
|
569
|
+
const configDefinitionsMerged = { ...configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn };
|
|
570
|
+
Object.entries(interfaceFilesRelevant)
|
|
571
|
+
.reverse()
|
|
572
|
+
.forEach(([_locationId, interfaceFiles]) => {
|
|
556
573
|
interfaceFiles.forEach((interfaceFile) => {
|
|
557
574
|
const configMeta = interfaceFile.fileExportsByConfigName['meta'];
|
|
558
575
|
if (!configMeta)
|
|
@@ -571,13 +588,14 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
571
588
|
});
|
|
572
589
|
(0, utils_js_1.objectEntries)(meta).forEach(([configName, configDefinition]) => {
|
|
573
590
|
// User can override an existing config definition
|
|
574
|
-
|
|
575
|
-
...
|
|
591
|
+
configDefinitionsMerged[configName] = {
|
|
592
|
+
...configDefinitionsMerged[configName],
|
|
576
593
|
...configDefinition
|
|
577
594
|
};
|
|
578
595
|
});
|
|
579
596
|
});
|
|
580
597
|
});
|
|
598
|
+
const configDefinitions = configDefinitionsMerged;
|
|
581
599
|
return configDefinitions;
|
|
582
600
|
}
|
|
583
601
|
function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
@@ -616,8 +634,8 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
616
634
|
}
|
|
617
635
|
});
|
|
618
636
|
}
|
|
619
|
-
function applyEffectsAll(configValueSources,
|
|
620
|
-
(0, utils_js_1.objectEntries)(
|
|
637
|
+
function applyEffectsAll(configValueSources, configDefinitions) {
|
|
638
|
+
(0, utils_js_1.objectEntries)(configDefinitions).forEach(([configName, configDef]) => {
|
|
621
639
|
if (!configDef.effect)
|
|
622
640
|
return;
|
|
623
641
|
// The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
|
|
@@ -676,9 +694,9 @@ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
|
676
694
|
}
|
|
677
695
|
});
|
|
678
696
|
}
|
|
679
|
-
function getComputed(configValueSources,
|
|
697
|
+
function getComputed(configValueSources, configDefinitions) {
|
|
680
698
|
const configValuesComputed = {};
|
|
681
|
-
(0, utils_js_1.objectEntries)(
|
|
699
|
+
(0, utils_js_1.objectEntries)(configDefinitions).forEach(([configName, configDef]) => {
|
|
682
700
|
if (!configDef._computed)
|
|
683
701
|
return;
|
|
684
702
|
const value = configDef._computed(configValueSources);
|
|
@@ -693,15 +711,7 @@ function getComputed(configValueSources, configDefinitionsRelevant) {
|
|
|
693
711
|
}
|
|
694
712
|
async function findPlusFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
695
713
|
const files = await (0, crawlPlusFiles_js_1.crawlPlusFiles)(userRootDir, outDirRoot, isDev);
|
|
696
|
-
const plusFiles = files.map(({ filePathRelativeToUserRootDir
|
|
697
|
-
return {
|
|
698
|
-
filePathRelativeToUserRootDir,
|
|
699
|
-
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
700
|
-
filePathAbsoluteFilesystem,
|
|
701
|
-
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
702
|
-
importPathAbsolute: null
|
|
703
|
-
};
|
|
704
|
-
});
|
|
714
|
+
const plusFiles = files.map(({ filePathRelativeToUserRootDir }) => (0, resolveFilePath_js_1.resolveFilePathRelativeToUserRootDir)(filePathRelativeToUserRootDir, userRootDir));
|
|
705
715
|
// TODO/v1-release: remove
|
|
706
716
|
extensions.forEach((extension) => {
|
|
707
717
|
extension.pageConfigsDistFiles?.forEach((pageConfigDistFile) => {
|
|
@@ -753,22 +763,6 @@ function assertNoUnexpectedPlusSign(filePath: string, fileName: string) {
|
|
|
753
763
|
)
|
|
754
764
|
}
|
|
755
765
|
*/
|
|
756
|
-
function isGlobalConfig(configName) {
|
|
757
|
-
if (configName === 'prerender')
|
|
758
|
-
return false;
|
|
759
|
-
const configNamesGlobal = getConfigNamesGlobal();
|
|
760
|
-
return (0, utils_js_1.arrayIncludes)(configNamesGlobal, configName);
|
|
761
|
-
}
|
|
762
|
-
function getConfigNamesGlobal() {
|
|
763
|
-
return Object.keys(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal);
|
|
764
|
-
}
|
|
765
|
-
function assertConfigExists(configName, configNamesRelevant, filePathToShowToUser) {
|
|
766
|
-
const configNames = [...configNamesRelevant, ...getConfigNamesGlobal()];
|
|
767
|
-
if (configNames.includes(configName))
|
|
768
|
-
return;
|
|
769
|
-
handleUnknownConfig(configName, configNames, filePathToShowToUser);
|
|
770
|
-
(0, utils_js_1.assert)(false);
|
|
771
|
-
}
|
|
772
766
|
function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
773
767
|
let errMsg = `${filePathToShowToUser} defines an unknown config ${picocolors_1.default.cyan(configName)}`;
|
|
774
768
|
let configNameSimilar = null;
|
|
@@ -839,7 +833,7 @@ function isVikeConfigFile(filePath) {
|
|
|
839
833
|
return !!getConfigName(filePath);
|
|
840
834
|
}
|
|
841
835
|
exports.isVikeConfigFile = isVikeConfigFile;
|
|
842
|
-
function getConfigValues(configValueSources, configValuesComputed,
|
|
836
|
+
function getConfigValues(configValueSources, configValuesComputed, configDefinitions) {
|
|
843
837
|
const configValues = {};
|
|
844
838
|
Object.entries(configValuesComputed).forEach(([configName, configValueComputed]) => {
|
|
845
839
|
configValues[configName] = {
|
|
@@ -848,7 +842,7 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
848
842
|
};
|
|
849
843
|
});
|
|
850
844
|
Object.entries(configValueSources).forEach(([configName, sources]) => {
|
|
851
|
-
const configDef =
|
|
845
|
+
const configDef = configDefinitions[configName];
|
|
852
846
|
(0, utils_js_1.assert)(configDef);
|
|
853
847
|
if (!configDef.cumulative) {
|
|
854
848
|
const configValueSource = sources[0];
|
|
@@ -962,3 +956,48 @@ function getConfigEnvValue(val, errMsgIntro) {
|
|
|
962
956
|
*/
|
|
963
957
|
return val;
|
|
964
958
|
}
|
|
959
|
+
function getConfigDefinition(configDefinitions, configName, filePathToShowToUser) {
|
|
960
|
+
const configDef = configDefinitions[configName];
|
|
961
|
+
assertConfigExists(configName, Object.keys(configDefinitions), filePathToShowToUser);
|
|
962
|
+
(0, utils_js_1.assert)(configDef);
|
|
963
|
+
return configDef;
|
|
964
|
+
}
|
|
965
|
+
function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
966
|
+
return configDefinitions[configName] ?? null;
|
|
967
|
+
}
|
|
968
|
+
function isConfigEnv(configDef, configName) {
|
|
969
|
+
const configEnv = configDef.env;
|
|
970
|
+
if (configDef.cumulative) {
|
|
971
|
+
// In principle we could lift that requirement (but it requires non-trivial modifications)
|
|
972
|
+
(0, utils_js_1.assertUsage)(configEnv.config, `Config ${picocolors_1.default.cyan(configName)} needs its ${picocolors_1.default.cyan('env')} to have ${picocolors_1.default.cyan('{ config: true }')} (because ${picocolors_1.default.cyan(configName)} is a ${picocolors_1.default.cyan('cumulative')} config)`);
|
|
973
|
+
}
|
|
974
|
+
return !!configEnv.config;
|
|
975
|
+
}
|
|
976
|
+
function isGlobalConfig(configName) {
|
|
977
|
+
if (configName === 'prerender')
|
|
978
|
+
return false;
|
|
979
|
+
const configNamesGlobal = getConfigNamesGlobal();
|
|
980
|
+
return (0, utils_js_1.arrayIncludes)(configNamesGlobal, configName);
|
|
981
|
+
}
|
|
982
|
+
function getConfigNamesGlobal() {
|
|
983
|
+
return Object.keys(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal);
|
|
984
|
+
}
|
|
985
|
+
function assertConfigExists(configName, configNamesRelevant, filePathToShowToUser) {
|
|
986
|
+
const configNames = [...configNamesRelevant, ...getConfigNamesGlobal()];
|
|
987
|
+
if (configNames.includes(configName))
|
|
988
|
+
return;
|
|
989
|
+
handleUnknownConfig(configName, configNames, filePathToShowToUser);
|
|
990
|
+
(0, utils_js_1.assert)(false);
|
|
991
|
+
}
|
|
992
|
+
function sortConfigValueSources(configValueSources, locationIdPage) {
|
|
993
|
+
return Object.fromEntries(Object.entries(configValueSources)
|
|
994
|
+
// Make order deterministic (no other purpose)
|
|
995
|
+
.sort(([, [source1]], [, [source2]]) => source1.definedAt.filePathAbsoluteVite < source2.definedAt.filePathAbsoluteVite ? -1 : 1)
|
|
996
|
+
// Sort after whether the config value was defined by an npm package
|
|
997
|
+
.sort((0, utils_js_1.makeFirst)(([, [source]]) => {
|
|
998
|
+
const { importPathAbsolute } = source.definedAt;
|
|
999
|
+
return !!importPathAbsolute && (0, utils_js_1.isNpmPackageImport)(importPathAbsolute);
|
|
1000
|
+
}))
|
|
1001
|
+
// Sort after the filesystem inheritance of the config value
|
|
1002
|
+
.sort(([, [source1]], [, [source2]]) => (0, utils_js_1.reverse)((0, filesystemRouting_js_1.sortAfterInheritanceOrder)(source1.locationId, source2.locationId, locationIdPage))));
|
|
1003
|
+
}
|
|
@@ -27,7 +27,6 @@ __exportStar(require("../../utils/getDependencyPackageJson.js"), exports);
|
|
|
27
27
|
__exportStar(require("../../utils/requireResolve.js"), exports);
|
|
28
28
|
__exportStar(require("../../utils/arrayIncludes.js"), exports);
|
|
29
29
|
__exportStar(require("../../utils/isDev.js"), exports);
|
|
30
|
-
__exportStar(require("../../utils/objectKeys.js"), exports);
|
|
31
30
|
__exportStar(require("../../utils/getMostSimilar.js"), exports);
|
|
32
31
|
__exportStar(require("../../utils/getRandomId.js"), exports);
|
|
33
32
|
__exportStar(require("../../utils/joinEnglish.js"), exports);
|
|
@@ -35,7 +34,7 @@ __exportStar(require("../../utils/escapeRegex.js"), exports);
|
|
|
35
34
|
__exportStar(require("../../utils/stripAnsi.js"), exports);
|
|
36
35
|
__exportStar(require("../../utils/trimWithAnsi.js"), exports);
|
|
37
36
|
__exportStar(require("../../utils/removeEmptyLines.js"), exports);
|
|
38
|
-
__exportStar(require("../../utils/
|
|
37
|
+
__exportStar(require("../../utils/findFile.js"), exports);
|
|
39
38
|
__exportStar(require("../../utils/getPropAccessNotation.js"), exports);
|
|
40
39
|
__exportStar(require("../../utils/mergeCumulativeValues.js"), exports);
|
|
41
40
|
__exportStar(require("../../utils/deepEqual.js"), exports);
|
|
@@ -51,11 +51,11 @@ const loadUserFilesServerSide_js_1 = require("../runtime/renderPage/loadUserFile
|
|
|
51
51
|
const getHook_js_1 = require("../../shared/hooks/getHook.js");
|
|
52
52
|
const noRouteMatch_js_1 = require("../../shared/route/noRouteMatch.js");
|
|
53
53
|
const getVikeConfig_js_1 = require("../plugin/plugins/importUserCode/v1-design/getVikeConfig.js");
|
|
54
|
-
const
|
|
54
|
+
const logErrorHint_js_1 = require("../runtime/renderPage/logErrorHint.js");
|
|
55
55
|
async function runPrerenderFromAPI(options = {}) {
|
|
56
56
|
await runPrerender(options, 'prerender()');
|
|
57
57
|
// - We purposely propagate the error to the user land, so that the error interrupts the user land. It's also, I guess, a nice-to-have that the user has control over the error.
|
|
58
|
-
// - We don't use
|
|
58
|
+
// - We don't use logErrorHint() because we don't have control over what happens with the error. For example, if the user land purposely swallows the error then the hint shouldn't be logged. Also, it's best if the hint is shown to the user *after* the error, but we cannot do/guarentee that.
|
|
59
59
|
}
|
|
60
60
|
exports.runPrerenderFromAPI = runPrerenderFromAPI;
|
|
61
61
|
async function runPrerenderFromCLI(options) {
|
|
@@ -64,7 +64,7 @@ async function runPrerenderFromCLI(options) {
|
|
|
64
64
|
}
|
|
65
65
|
catch (err) {
|
|
66
66
|
console.error(err);
|
|
67
|
-
(0,
|
|
67
|
+
(0, logErrorHint_js_1.logErrorHint)(err);
|
|
68
68
|
process.exit(1);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -75,7 +75,7 @@ async function runPrerenderFromAutoFullBuild(options) {
|
|
|
75
75
|
}
|
|
76
76
|
catch (err) {
|
|
77
77
|
console.error(err);
|
|
78
|
-
(0,
|
|
78
|
+
(0, logErrorHint_js_1.logErrorHint)(err);
|
|
79
79
|
process.exit(1);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -87,7 +87,7 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
87
87
|
if (logLevel === 'info') {
|
|
88
88
|
console.log(`${picocolors_1.default.cyan(`vike v${utils_js_1.projectInfo.projectVersion}`)} ${picocolors_1.default.green('pre-rendering HTML...')}`);
|
|
89
89
|
}
|
|
90
|
-
(
|
|
90
|
+
handleNodeEnv();
|
|
91
91
|
await disableReactStreaming();
|
|
92
92
|
const viteConfig = await (0, vite_1.resolveConfig)(options.viteConfig || {}, 'vike pre-rendering', 'production');
|
|
93
93
|
assertLoadedConfig(viteConfig, options);
|
|
@@ -742,3 +742,10 @@ function assertIsNotAbort(err, urlOr404) {
|
|
|
742
742
|
(0, utils_js_1.assert)(abortCall);
|
|
743
743
|
(0, utils_js_1.assertUsage)(false, `${picocolors_1.default.cyan(abortCall)} thrown${thrownBy} while pre-rendering ${urlOr404} but ${picocolors_1.default.cyan(abortCaller)} isn't supported for pre-rendered pages`);
|
|
744
744
|
}
|
|
745
|
+
function handleNodeEnv() {
|
|
746
|
+
const assertNodeEnv = () => (0, utils_js_1.assertNodeEnvIsNotDev)('pre-rendering');
|
|
747
|
+
if ((0, utils_js_1.getNodeEnv)())
|
|
748
|
+
assertNodeEnv();
|
|
749
|
+
(0, utils_js_1.setNodeEnvToProduction)();
|
|
750
|
+
assertNodeEnv();
|
|
751
|
+
}
|
|
@@ -157,8 +157,11 @@ function assertNodeEnv(hasViteDevServer) {
|
|
|
157
157
|
const nodeEnv = (0, utils_js_1.getNodeEnv)();
|
|
158
158
|
if (nodeEnv === null || nodeEnv === 'test')
|
|
159
159
|
return;
|
|
160
|
-
const
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
|
|
160
|
+
const isDev = (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
|
+
if (hasViteDevServer === isDev)
|
|
163
|
+
return;
|
|
164
|
+
const nodeEnvDesc = (0, utils_js_1.getNodeEnvDesc)();
|
|
165
|
+
// 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)
|
|
166
|
+
(0, utils_js_1.assertUsage)(false, `Vite's development server was${hasViteDevServer ? '' : "n't"} instantiated while the ${nodeEnvDesc} which is contradictory, see https://vike.dev/NODE_ENV`);
|
|
164
167
|
}
|
|
@@ -90,7 +90,7 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
|
|
|
90
90
|
// See https://github.com/vikejs/vike/pull/1271
|
|
91
91
|
const positionJavaScriptEntry = (() => {
|
|
92
92
|
if (pageContext._pageContextPromise) {
|
|
93
|
-
(0, utils_js_1.assertWarning)(!injectToStream, "[getHtmlTags()] We recommend against using streaming and a pageContext promise at the same time
|
|
93
|
+
(0, utils_js_1.assertWarning)(!injectToStream, "[getHtmlTags()] We recommend against using streaming and a pageContext promise at the same time, because progressive hydration won't work.", { onlyOnce: true });
|
|
94
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
|
}
|