vike 0.4.160-commit-a1101c1 → 0.4.160-commit-30d535e
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 +150 -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 +149 -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,12 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
251
260
|
return;
|
|
252
261
|
configValueSources[configName] = sources;
|
|
253
262
|
}));
|
|
263
|
+
configValueSources = sortConfigValueSources(configValueSources, locationId);
|
|
264
|
+
console.log(JSON.stringify(configValueSources, null, 2));
|
|
254
265
|
const { routeFilesystem, isErrorPage } = determineRouteFilesystem(locationId, configValueSources);
|
|
255
|
-
applyEffectsAll(configValueSources,
|
|
256
|
-
const configValuesComputed = getComputed(configValueSources,
|
|
257
|
-
const configValues = getConfigValues(configValueSources, configValuesComputed,
|
|
266
|
+
applyEffectsAll(configValueSources, configDefinitions);
|
|
267
|
+
const configValuesComputed = getComputed(configValueSources, configDefinitions);
|
|
268
|
+
const configValues = getConfigValues(configValueSources, configValuesComputed, configDefinitions);
|
|
258
269
|
const pageConfig = {
|
|
259
270
|
pageId: locationId,
|
|
260
271
|
isErrorPage,
|
|
@@ -291,7 +302,7 @@ function interfacefileIsAlreaydLoaded(interfaceFile) {
|
|
|
291
302
|
return isAlreadyLoaded;
|
|
292
303
|
}
|
|
293
304
|
function getInterfaceFilesRelevant(interfaceFilesByLocationId, locationIdPage) {
|
|
294
|
-
const interfaceFilesRelevant = Object.fromEntries(
|
|
305
|
+
const interfaceFilesRelevant = Object.fromEntries((0, utils_js_1.objectEntries)(interfaceFilesByLocationId)
|
|
295
306
|
.filter(([locationId]) => {
|
|
296
307
|
return (0, filesystemRouting_js_1.isInherited)(locationId, locationIdPage);
|
|
297
308
|
})
|
|
@@ -306,14 +317,14 @@ function getInterfaceFileList(interfaceFilesByLocationId) {
|
|
|
306
317
|
return interfaceFiles;
|
|
307
318
|
}
|
|
308
319
|
async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded) {
|
|
309
|
-
const locationIds =
|
|
310
|
-
const interfaceFilesGlobal =
|
|
320
|
+
const locationIds = (0, utils_js_1.objectKeys)(interfaceFilesByLocationId);
|
|
321
|
+
const interfaceFilesGlobal = (0, utils_js_1.objectFromEntries)((0, utils_js_1.objectEntries)(interfaceFilesByLocationId).filter(([locationId]) => {
|
|
311
322
|
return (0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds);
|
|
312
323
|
}));
|
|
313
324
|
// Validate that global configs live in global interface files
|
|
314
325
|
{
|
|
315
326
|
const interfaceFilesGlobalPaths = [];
|
|
316
|
-
|
|
327
|
+
(0, utils_js_1.objectEntries)(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
|
|
317
328
|
(0, utils_js_1.assert)((0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds));
|
|
318
329
|
interfaceFiles.forEach(({ filePath: { filePathRelativeToUserRootDir } }) => {
|
|
319
330
|
if (filePathRelativeToUserRootDir) {
|
|
@@ -322,7 +333,7 @@ async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importe
|
|
|
322
333
|
});
|
|
323
334
|
});
|
|
324
335
|
const globalPaths = Array.from(new Set(interfaceFilesGlobalPaths.map((p) => path_1.default.posix.dirname(p))));
|
|
325
|
-
|
|
336
|
+
(0, utils_js_1.objectEntries)(interfaceFilesByLocationId).forEach(([locationId, interfaceFiles]) => {
|
|
326
337
|
interfaceFiles.forEach((interfaceFile) => {
|
|
327
338
|
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
328
339
|
if (!(0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds) && isGlobalConfig(configName)) {
|
|
@@ -446,6 +457,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
446
457
|
const conf = interfaceFile.fileExportsByConfigName[configName];
|
|
447
458
|
(0, utils_js_1.assert)(conf);
|
|
448
459
|
const configEnv = configDef.env;
|
|
460
|
+
const { locationId } = interfaceFile;
|
|
449
461
|
const definedAtConfigFile = {
|
|
450
462
|
...interfaceFile.filePath,
|
|
451
463
|
fileExportPathToShowToUser: ['default', configName]
|
|
@@ -471,6 +483,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
471
483
|
};
|
|
472
484
|
}
|
|
473
485
|
const configValueSource = {
|
|
486
|
+
locationId,
|
|
474
487
|
value: valueFilePath,
|
|
475
488
|
valueIsFilePath: true,
|
|
476
489
|
configEnv,
|
|
@@ -487,6 +500,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
487
500
|
const import_ = (0, resolveImportPath_js_1.resolveImport)(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
488
501
|
if (import_) {
|
|
489
502
|
const configValueSource = {
|
|
503
|
+
locationId,
|
|
490
504
|
configEnv,
|
|
491
505
|
valueIsImportedAtRuntime: true,
|
|
492
506
|
definedAt: import_
|
|
@@ -497,7 +511,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
497
511
|
configName !== 'extends') {
|
|
498
512
|
if (import_.filePathAbsoluteFilesystem) {
|
|
499
513
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(import_, 'filePathAbsoluteFilesystem', 'string')); // Help TS
|
|
500
|
-
const fileExport = await (0,
|
|
514
|
+
const fileExport = await (0, loadFileAtConfigTime_js_1.loadImportedFile)(import_, userRootDir, importedFilesLoaded);
|
|
501
515
|
configValueSource.value = fileExport;
|
|
502
516
|
}
|
|
503
517
|
else {
|
|
@@ -509,6 +523,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
509
523
|
}
|
|
510
524
|
// Defined by config file, i.e. +config.js file
|
|
511
525
|
const configValueSource = {
|
|
526
|
+
locationId,
|
|
512
527
|
value: configValue,
|
|
513
528
|
configEnv,
|
|
514
529
|
valueIsImportedAtRuntime: false,
|
|
@@ -521,6 +536,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
521
536
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
522
537
|
(0, utils_js_1.assert)(valueAlreadyLoaded === !!configEnv.config);
|
|
523
538
|
const configValueSource = {
|
|
539
|
+
locationId,
|
|
524
540
|
configEnv,
|
|
525
541
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
526
542
|
definedAt: {
|
|
@@ -551,8 +567,10 @@ function isDefiningPageConfig(configName) {
|
|
|
551
567
|
return ['Page', 'route'].includes(configName);
|
|
552
568
|
}
|
|
553
569
|
function getConfigDefinitions(interfaceFilesRelevant) {
|
|
554
|
-
const
|
|
555
|
-
Object.entries(interfaceFilesRelevant)
|
|
570
|
+
const configDefinitionsMerged = { ...configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn };
|
|
571
|
+
Object.entries(interfaceFilesRelevant)
|
|
572
|
+
.reverse()
|
|
573
|
+
.forEach(([_locationId, interfaceFiles]) => {
|
|
556
574
|
interfaceFiles.forEach((interfaceFile) => {
|
|
557
575
|
const configMeta = interfaceFile.fileExportsByConfigName['meta'];
|
|
558
576
|
if (!configMeta)
|
|
@@ -571,13 +589,14 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
571
589
|
});
|
|
572
590
|
(0, utils_js_1.objectEntries)(meta).forEach(([configName, configDefinition]) => {
|
|
573
591
|
// User can override an existing config definition
|
|
574
|
-
|
|
575
|
-
...
|
|
592
|
+
configDefinitionsMerged[configName] = {
|
|
593
|
+
...configDefinitionsMerged[configName],
|
|
576
594
|
...configDefinition
|
|
577
595
|
};
|
|
578
596
|
});
|
|
579
597
|
});
|
|
580
598
|
});
|
|
599
|
+
const configDefinitions = configDefinitionsMerged;
|
|
581
600
|
return configDefinitions;
|
|
582
601
|
}
|
|
583
602
|
function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
@@ -616,8 +635,8 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
616
635
|
}
|
|
617
636
|
});
|
|
618
637
|
}
|
|
619
|
-
function applyEffectsAll(configValueSources,
|
|
620
|
-
(0, utils_js_1.objectEntries)(
|
|
638
|
+
function applyEffectsAll(configValueSources, configDefinitions) {
|
|
639
|
+
(0, utils_js_1.objectEntries)(configDefinitions).forEach(([configName, configDef]) => {
|
|
621
640
|
if (!configDef.effect)
|
|
622
641
|
return;
|
|
623
642
|
// 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 +695,9 @@ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
|
676
695
|
}
|
|
677
696
|
});
|
|
678
697
|
}
|
|
679
|
-
function getComputed(configValueSources,
|
|
698
|
+
function getComputed(configValueSources, configDefinitions) {
|
|
680
699
|
const configValuesComputed = {};
|
|
681
|
-
(0, utils_js_1.objectEntries)(
|
|
700
|
+
(0, utils_js_1.objectEntries)(configDefinitions).forEach(([configName, configDef]) => {
|
|
682
701
|
if (!configDef._computed)
|
|
683
702
|
return;
|
|
684
703
|
const value = configDef._computed(configValueSources);
|
|
@@ -693,15 +712,7 @@ function getComputed(configValueSources, configDefinitionsRelevant) {
|
|
|
693
712
|
}
|
|
694
713
|
async function findPlusFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
695
714
|
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
|
-
});
|
|
715
|
+
const plusFiles = files.map(({ filePathRelativeToUserRootDir }) => (0, resolveFilePath_js_1.resolveFilePathRelativeToUserRootDir)(filePathRelativeToUserRootDir, userRootDir));
|
|
705
716
|
// TODO/v1-release: remove
|
|
706
717
|
extensions.forEach((extension) => {
|
|
707
718
|
extension.pageConfigsDistFiles?.forEach((pageConfigDistFile) => {
|
|
@@ -753,22 +764,6 @@ function assertNoUnexpectedPlusSign(filePath: string, fileName: string) {
|
|
|
753
764
|
)
|
|
754
765
|
}
|
|
755
766
|
*/
|
|
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
767
|
function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
773
768
|
let errMsg = `${filePathToShowToUser} defines an unknown config ${picocolors_1.default.cyan(configName)}`;
|
|
774
769
|
let configNameSimilar = null;
|
|
@@ -839,7 +834,7 @@ function isVikeConfigFile(filePath) {
|
|
|
839
834
|
return !!getConfigName(filePath);
|
|
840
835
|
}
|
|
841
836
|
exports.isVikeConfigFile = isVikeConfigFile;
|
|
842
|
-
function getConfigValues(configValueSources, configValuesComputed,
|
|
837
|
+
function getConfigValues(configValueSources, configValuesComputed, configDefinitions) {
|
|
843
838
|
const configValues = {};
|
|
844
839
|
Object.entries(configValuesComputed).forEach(([configName, configValueComputed]) => {
|
|
845
840
|
configValues[configName] = {
|
|
@@ -848,7 +843,7 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
848
843
|
};
|
|
849
844
|
});
|
|
850
845
|
Object.entries(configValueSources).forEach(([configName, sources]) => {
|
|
851
|
-
const configDef =
|
|
846
|
+
const configDef = configDefinitions[configName];
|
|
852
847
|
(0, utils_js_1.assert)(configDef);
|
|
853
848
|
if (!configDef.cumulative) {
|
|
854
849
|
const configValueSource = sources[0];
|
|
@@ -962,3 +957,48 @@ function getConfigEnvValue(val, errMsgIntro) {
|
|
|
962
957
|
*/
|
|
963
958
|
return val;
|
|
964
959
|
}
|
|
960
|
+
function getConfigDefinition(configDefinitions, configName, filePathToShowToUser) {
|
|
961
|
+
const configDef = configDefinitions[configName];
|
|
962
|
+
assertConfigExists(configName, Object.keys(configDefinitions), filePathToShowToUser);
|
|
963
|
+
(0, utils_js_1.assert)(configDef);
|
|
964
|
+
return configDef;
|
|
965
|
+
}
|
|
966
|
+
function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
967
|
+
return configDefinitions[configName] ?? null;
|
|
968
|
+
}
|
|
969
|
+
function isConfigEnv(configDef, configName) {
|
|
970
|
+
const configEnv = configDef.env;
|
|
971
|
+
if (configDef.cumulative) {
|
|
972
|
+
// In principle we could lift that requirement (but it requires non-trivial modifications)
|
|
973
|
+
(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)`);
|
|
974
|
+
}
|
|
975
|
+
return !!configEnv.config;
|
|
976
|
+
}
|
|
977
|
+
function isGlobalConfig(configName) {
|
|
978
|
+
if (configName === 'prerender')
|
|
979
|
+
return false;
|
|
980
|
+
const configNamesGlobal = getConfigNamesGlobal();
|
|
981
|
+
return (0, utils_js_1.arrayIncludes)(configNamesGlobal, configName);
|
|
982
|
+
}
|
|
983
|
+
function getConfigNamesGlobal() {
|
|
984
|
+
return Object.keys(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal);
|
|
985
|
+
}
|
|
986
|
+
function assertConfigExists(configName, configNamesRelevant, filePathToShowToUser) {
|
|
987
|
+
const configNames = [...configNamesRelevant, ...getConfigNamesGlobal()];
|
|
988
|
+
if (configNames.includes(configName))
|
|
989
|
+
return;
|
|
990
|
+
handleUnknownConfig(configName, configNames, filePathToShowToUser);
|
|
991
|
+
(0, utils_js_1.assert)(false);
|
|
992
|
+
}
|
|
993
|
+
function sortConfigValueSources(configValueSources, locationIdPage) {
|
|
994
|
+
return Object.fromEntries(Object.entries(configValueSources)
|
|
995
|
+
// Make order deterministic (no other purpose)
|
|
996
|
+
.sort(([, [source1]], [, [source2]]) => source1.definedAt.filePathAbsoluteVite < source2.definedAt.filePathAbsoluteVite ? -1 : 1)
|
|
997
|
+
// Sort after whether the config value was defined by an npm package
|
|
998
|
+
.sort((0, utils_js_1.makeFirst)(([, [source]]) => {
|
|
999
|
+
const { importPathAbsolute } = source.definedAt;
|
|
1000
|
+
return !!importPathAbsolute && (0, utils_js_1.isNpmPackageImport)(importPathAbsolute);
|
|
1001
|
+
}))
|
|
1002
|
+
// Sort after the filesystem inheritance of the config value
|
|
1003
|
+
.sort(([, [source1]], [, [source2]]) => (0, utils_js_1.reverse)((0, filesystemRouting_js_1.sortAfterInheritanceOrder)(source1.locationId, source2.locationId, locationIdPage))));
|
|
1004
|
+
}
|
|
@@ -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
|
}
|