vike 0.4.218-commit-85af52a → 0.4.218-commit-ea8bb27
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/__internal/index.js +2 -3
- package/dist/cjs/node/api/prepareViteApiCall.js +1 -2
- package/dist/cjs/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +26 -22
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +111 -181
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +2 -2
- package/dist/cjs/node/prerender/runPrerender.js +73 -32
- package/dist/cjs/node/prerender/utils.js +1 -0
- package/dist/cjs/node/runtime/globalContext.js +31 -5
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +11 -33
- package/dist/cjs/node/runtime/renderPage/resolveRedirects.js +9 -1
- package/dist/cjs/node/runtime/renderPage.js +21 -22
- package/dist/cjs/node/shared/assertRuntimeManifest.js +0 -2
- package/dist/cjs/shared/getPageFiles/getPageFiles.js +6 -3
- package/dist/cjs/shared/page-configs/getPageConfigUserFriendly.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +4 -4
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/__internal/index.js +2 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.js +1 -4
- package/dist/esm/client/server-routing-runtime/getPageContext.js +1 -4
- package/dist/esm/node/api/prepareViteApiCall.js +1 -2
- package/dist/esm/node/plugin/plugins/baseUrls.js +1 -1
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +2 -4
- package/dist/esm/node/plugin/plugins/commonConfig.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +6 -9
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +25 -21
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +1 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +108 -178
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +2 -2
- package/dist/esm/node/prerender/runPrerender.js +75 -34
- package/dist/esm/node/prerender/utils.d.ts +1 -0
- package/dist/esm/node/prerender/utils.js +1 -0
- package/dist/esm/node/runtime/globalContext.d.ts +17 -3
- package/dist/esm/node/runtime/globalContext.js +32 -6
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +27 -42
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +11 -33
- package/dist/esm/node/runtime/renderPage/resolveRedirects.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/resolveRedirects.js +9 -1
- package/dist/esm/node/runtime/renderPage.js +22 -23
- package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertRuntimeManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertRuntimeManifest.js +1 -3
- package/dist/esm/shared/getPageFiles/getPageFiles.d.ts +2 -0
- package/dist/esm/shared/getPageFiles/getPageFiles.js +6 -3
- package/dist/esm/shared/page-configs/Config/PageContextConfig.d.ts +9 -5
- package/dist/esm/shared/page-configs/Config.d.ts +13 -1
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +7 -4
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.js +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +2 -6
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +4 -4
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -11,16 +11,15 @@ const index_js_1 = require("../shared/route/index.js");
|
|
|
11
11
|
const getPageFiles_js_1 = require("../shared/getPageFiles/getPageFiles.js");
|
|
12
12
|
const globalContext_js_2 = require("../node/runtime/globalContext.js");
|
|
13
13
|
const assertSetup_js_1 = require("../utils/assertSetup.js");
|
|
14
|
-
const renderPageAlreadyRouted_js_1 = require("../node/runtime/renderPage/renderPageAlreadyRouted.js");
|
|
15
14
|
/**
|
|
16
15
|
* Used by {@link https://github.com/magne4000/vite-plugin-vercel|vite-plugin-vercel} to compute some rewrite rules and extract { isr } configs.
|
|
17
16
|
*/
|
|
18
17
|
async function getPagesAndRoutes() {
|
|
19
18
|
(0, assertSetup_js_1.setNodeEnvProduction)();
|
|
20
|
-
const
|
|
19
|
+
const globalContext = (0, globalContext_js_2.getGlobalContext)();
|
|
21
20
|
const {
|
|
22
21
|
//
|
|
23
|
-
pageRoutes, pageFilesAll, pageConfigs, allPageIds } =
|
|
22
|
+
pageRoutes, pageFilesAll, pageConfigs, allPageIds } = globalContext;
|
|
24
23
|
return {
|
|
25
24
|
pageRoutes,
|
|
26
25
|
pageFilesAll,
|
|
@@ -70,8 +70,7 @@ async function enhanceViteConfig(viteConfig, operation) {
|
|
|
70
70
|
};
|
|
71
71
|
}
|
|
72
72
|
function addViteSettingsSetByUser(viteConfigEnhanced, vikeConfig) {
|
|
73
|
-
const
|
|
74
|
-
const viteConfigs = global.from.configsCumulative.vite;
|
|
73
|
+
const viteConfigs = vikeConfig.global.from.configsCumulative.vite;
|
|
75
74
|
if (!viteConfigs)
|
|
76
75
|
return viteConfigEnhanced;
|
|
77
76
|
viteConfigs.values.forEach((v) => {
|
|
@@ -13,7 +13,7 @@ function baseUrls() {
|
|
|
13
13
|
const isDev = config._isDev;
|
|
14
14
|
(0, utils_js_1.assert)(typeof isDev === 'boolean');
|
|
15
15
|
const baseViteOriginal = config.base ?? '/__UNSET__'; // '/__UNSET__' because Vite resolves `_baseViteOriginal: null` to `undefined`
|
|
16
|
-
basesResolved = (0, resolveBase_js_1.resolveBase)(baseViteOriginal, config.
|
|
16
|
+
basesResolved = (0, resolveBase_js_1.resolveBase)(baseViteOriginal, config.vike.vikeConfigGlobal.baseServer, config.vike.vikeConfigGlobal.baseAssets);
|
|
17
17
|
// We cannot define these in configResolved() because Vite picks up the env variables before any configResolved() hook is called
|
|
18
18
|
process.env.BASE_SERVER = basesResolved.baseServer;
|
|
19
19
|
process.env.BASE_ASSETS = basesResolved.baseAssets;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.configDefinitionsBuiltInAll = void 0;
|
|
4
4
|
const utils_js_1 = require("../../../../utils.js");
|
|
5
5
|
const getConfigDefinedAt_js_1 = require("../../../../../../shared/page-configs/getConfigDefinedAt.js");
|
|
6
|
-
const
|
|
6
|
+
const configDefinitionsBuiltInAll = {
|
|
7
7
|
onRenderHtml: {
|
|
8
8
|
env: { server: true }
|
|
9
9
|
},
|
|
@@ -62,9 +62,6 @@ const configDefinitionsBuiltIn = {
|
|
|
62
62
|
clientHooks: {
|
|
63
63
|
env: { config: true }
|
|
64
64
|
},
|
|
65
|
-
prerender: {
|
|
66
|
-
env: { config: true }
|
|
67
|
-
},
|
|
68
65
|
hydrationCanBeAborted: {
|
|
69
66
|
env: { client: true }
|
|
70
67
|
},
|
|
@@ -133,29 +130,36 @@ const configDefinitionsBuiltIn = {
|
|
|
133
130
|
env: { client: true }
|
|
134
131
|
},
|
|
135
132
|
// TODO/eventually: define it as a global config.
|
|
136
|
-
middleware: { env: { server: true }, cumulative: true, eager: true }
|
|
137
|
-
};
|
|
138
|
-
exports.configDefinitionsBuiltIn = configDefinitionsBuiltIn;
|
|
139
|
-
const configDefinitionsBuiltInGlobal = {
|
|
133
|
+
middleware: { env: { server: true }, cumulative: true, eager: true },
|
|
140
134
|
onPrerenderStart: {
|
|
141
135
|
env: { server: true, production: true },
|
|
142
|
-
eager: true
|
|
136
|
+
eager: true,
|
|
137
|
+
global: true
|
|
143
138
|
},
|
|
144
139
|
onBeforeRoute: {
|
|
145
140
|
env: { server: true, client: 'if-client-routing' },
|
|
146
|
-
eager: true
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
141
|
+
eager: true,
|
|
142
|
+
global: true
|
|
143
|
+
},
|
|
144
|
+
prerender: { env: { config: true }, global: (value) => typeof value !== 'object', type: ['boolean', 'object'] },
|
|
145
|
+
vite: { env: { config: true }, global: true, cumulative: true, type: 'object' },
|
|
146
|
+
disableAutoFullBuild: {
|
|
147
|
+
env: { config: true },
|
|
148
|
+
global: true,
|
|
149
|
+
type: [
|
|
150
|
+
'boolean',
|
|
151
|
+
// Can be 'prerender'
|
|
152
|
+
'string'
|
|
153
|
+
]
|
|
154
|
+
},
|
|
155
|
+
includeAssetsImportedByServer: { env: { config: true }, global: true, type: 'boolean' },
|
|
156
|
+
baseAssets: { env: { config: true }, global: true, type: 'string' },
|
|
157
|
+
baseServer: { env: { config: true }, global: true, type: 'string' },
|
|
158
|
+
redirects: { env: { server: true }, global: true, type: 'string{}', cumulative: true },
|
|
159
|
+
trailingSlash: { env: { server: true }, global: true, type: 'boolean' },
|
|
160
|
+
disableUrlNormalization: { env: { server: true }, global: true, type: 'boolean' }
|
|
157
161
|
};
|
|
158
|
-
exports.
|
|
162
|
+
exports.configDefinitionsBuiltInAll = configDefinitionsBuiltInAll;
|
|
159
163
|
function getConfigEnv(configValueSources, configName) {
|
|
160
164
|
const configValueSource = getConfigValueSource(configValueSources, configName);
|
|
161
165
|
if (!configValueSource)
|
|
@@ -30,6 +30,8 @@ const getConfigValueBuildTime_js_1 = require("../../../../../shared/page-configs
|
|
|
30
30
|
const assertExtensions_js_1 = require("./assertExtensions.js");
|
|
31
31
|
const getPageConfigUserFriendly_js_1 = require("../../../../../shared/page-configs/getPageConfigUserFriendly.js");
|
|
32
32
|
const serializeConfigValues_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValues.js");
|
|
33
|
+
const configDefinitionsBuiltIn = getConfigDefinitionsBuiltIn();
|
|
34
|
+
const configDefinitionsBuiltInGlobal = getConfigDefinitionsBuiltInGlobal();
|
|
33
35
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
34
36
|
let restartVite = false;
|
|
35
37
|
let wasConfigInvalid = null;
|
|
@@ -167,7 +169,7 @@ async function loadInterfaceFiles(userRootDir) {
|
|
|
167
169
|
// We don't have access to the custom config definitions defined by the user yet.
|
|
168
170
|
// - If `configDef` is `undefined` => we load the file +{configName}.js later.
|
|
169
171
|
// - We already need to load +meta.js here (to get the custom config definitions defined by the user)
|
|
170
|
-
const configDef = getConfigDefinitionOptional(
|
|
172
|
+
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn, configName);
|
|
171
173
|
if (configDef && isLoadableAtBuildTime(configDef)) {
|
|
172
174
|
await (0, loadFileAtConfigTime_js_1.loadValueFile)(interfaceFile, configName, userRootDir);
|
|
173
175
|
}
|
|
@@ -247,9 +249,7 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, vikeVitePlug
|
|
|
247
249
|
configValueSources: {}
|
|
248
250
|
},
|
|
249
251
|
vikeConfigGlobal: resolveVikeConfigGlobal({}, {}),
|
|
250
|
-
|
|
251
|
-
global: (0, getPageConfigUserFriendly_js_1.getPageConfigUserFriendlyNew)({ configValues: {} })
|
|
252
|
-
}
|
|
252
|
+
global: (0, getPageConfigUserFriendly_js_1.getPageConfigUserFriendlyNew)({ configValues: {} })
|
|
253
253
|
};
|
|
254
254
|
return dummyData;
|
|
255
255
|
}
|
|
@@ -258,7 +258,97 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, vikeVitePlug
|
|
|
258
258
|
async function loadVikeConfig(userRootDir, vikeVitePluginOptions) {
|
|
259
259
|
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir);
|
|
260
260
|
const importedFilesLoaded = {};
|
|
261
|
-
const
|
|
261
|
+
const [globalConfigs, pageConfigs] = await Promise.all([
|
|
262
|
+
getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded, vikeVitePluginOptions),
|
|
263
|
+
getPageConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded)
|
|
264
|
+
]);
|
|
265
|
+
return { pageConfigs, ...globalConfigs };
|
|
266
|
+
}
|
|
267
|
+
async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded, vikeVitePluginOptions) {
|
|
268
|
+
const locationIds = (0, utils_js_1.objectKeys)(interfaceFilesByLocationId);
|
|
269
|
+
const interfaceFilesGlobal = (0, utils_js_1.objectFromEntries)((0, utils_js_1.objectEntries)(interfaceFilesByLocationId).filter(([locationId]) => {
|
|
270
|
+
return (0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds);
|
|
271
|
+
}));
|
|
272
|
+
// Validate that global configs live in global interface files
|
|
273
|
+
{
|
|
274
|
+
const interfaceFilesGlobalPaths = [];
|
|
275
|
+
(0, utils_js_1.objectEntries)(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
|
|
276
|
+
(0, utils_js_1.assert)((0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds));
|
|
277
|
+
interfaceFiles.forEach(({ filePath: { filePathAbsoluteUserRootDir } }) => {
|
|
278
|
+
if (filePathAbsoluteUserRootDir) {
|
|
279
|
+
interfaceFilesGlobalPaths.push(filePathAbsoluteUserRootDir);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
const globalPaths = Array.from(new Set(interfaceFilesGlobalPaths.map((p) => path_1.default.posix.dirname(p))));
|
|
284
|
+
(0, utils_js_1.objectEntries)(interfaceFilesByLocationId).forEach(([locationId, interfaceFiles]) => {
|
|
285
|
+
interfaceFiles.forEach((interfaceFile) => {
|
|
286
|
+
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
287
|
+
if (!(0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds) && isGlobalConfig(configName)) {
|
|
288
|
+
(0, utils_js_1.assertUsage)(false, [
|
|
289
|
+
`${interfaceFile.filePath.filePathToShowToUser} defines the config ${picocolors_1.default.cyan(configName)} which is global:`,
|
|
290
|
+
globalPaths.length
|
|
291
|
+
? `define ${picocolors_1.default.cyan(configName)} in ${(0, utils_js_1.joinEnglish)(globalPaths, 'or')} instead`
|
|
292
|
+
: `create a global config (e.g. /pages/+config.js) and define ${picocolors_1.default.cyan(configName)} there instead`
|
|
293
|
+
].join(' '));
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
});
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
const pageConfigGlobalValues = {};
|
|
300
|
+
const pageConfigGlobal = {
|
|
301
|
+
configDefinitions: configDefinitionsBuiltInGlobal,
|
|
302
|
+
configValueSources: {}
|
|
303
|
+
};
|
|
304
|
+
await Promise.all((0, utils_js_1.objectEntries)(configDefinitionsBuiltInGlobal).map(async ([configName, configDef]) => {
|
|
305
|
+
const sources = await resolveConfigValueSources(configName, configDef, interfaceFilesGlobal, userRootDir, importedFilesLoaded);
|
|
306
|
+
const configValueSource = sources[0];
|
|
307
|
+
if (!configValueSource)
|
|
308
|
+
return;
|
|
309
|
+
pageConfigGlobal.configValueSources[configName] = sources;
|
|
310
|
+
// TODO/now
|
|
311
|
+
if (configName === 'onBeforeRoute' || configName === 'onPrerenderStart') {
|
|
312
|
+
(0, utils_js_1.assert)(!('value' in configValueSource));
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
(0, utils_js_1.assert)('value' in configValueSource);
|
|
316
|
+
// TODO/now
|
|
317
|
+
if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
|
|
318
|
+
return;
|
|
319
|
+
pageConfigGlobalValues[configName] = configValueSource.value;
|
|
320
|
+
}
|
|
321
|
+
}));
|
|
322
|
+
const vikeConfigGlobal = resolveVikeConfigGlobal(vikeVitePluginOptions, pageConfigGlobalValues);
|
|
323
|
+
{
|
|
324
|
+
(0, utils_js_1.assert)((0, utils_js_1.isObject)(vikeVitePluginOptions));
|
|
325
|
+
Object.entries(vikeVitePluginOptions).forEach(([configName, value]) => {
|
|
326
|
+
var _a;
|
|
327
|
+
(0, utils_js_1.assert)((0, utils_js_1.includes)((0, utils_js_1.objectKeys)(configDefinitionsBuiltInGlobal), configName));
|
|
328
|
+
const configDef = configDefinitionsBuiltInGlobal[configName];
|
|
329
|
+
const sources = ((_a = pageConfigGlobal.configValueSources)[configName] ?? (_a[configName] = []));
|
|
330
|
+
sources.push({
|
|
331
|
+
value,
|
|
332
|
+
configEnv: configDef.env,
|
|
333
|
+
definedAtFilePath: {
|
|
334
|
+
...(0, getFilePath_js_1.getFilePathResolved)({
|
|
335
|
+
userRootDir,
|
|
336
|
+
filePathAbsoluteUserRootDir: '/vite.config.js'
|
|
337
|
+
}),
|
|
338
|
+
fileExportPathToShowToUser: null
|
|
339
|
+
},
|
|
340
|
+
locationId: '/',
|
|
341
|
+
isOverriden: configDef.cumulative ? false : sources.length > 0,
|
|
342
|
+
valueIsImportedAtRuntime: false,
|
|
343
|
+
valueIsDefinedByPlusFile: false
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
const configValues = getConfigValues(pageConfigGlobal);
|
|
348
|
+
const global = (0, getPageConfigUserFriendly_js_1.getPageConfigUserFriendlyNew)({ configValues });
|
|
349
|
+
return { pageConfigGlobal, vikeConfigGlobal, global };
|
|
350
|
+
}
|
|
351
|
+
async function getPageConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded) {
|
|
262
352
|
const pageConfigs = await Promise.all((0, utils_js_1.objectEntries)(interfaceFilesByLocationId)
|
|
263
353
|
.filter(([_pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
264
354
|
.map(async ([locationId]) => {
|
|
@@ -280,7 +370,7 @@ async function loadVikeConfig(userRootDir, vikeVitePluginOptions) {
|
|
|
280
370
|
if (isAlreadyLoaded)
|
|
281
371
|
return;
|
|
282
372
|
// Value files of built-in configs should have already been loaded at loadInterfaceFiles()
|
|
283
|
-
(0, utils_js_1.assert)(!(configName in
|
|
373
|
+
(0, utils_js_1.assert)(!(configName in configDefinitionsBuiltIn));
|
|
284
374
|
await (0, loadFileAtConfigTime_js_1.loadValueFile)(interfaceFile, configName, userRootDir);
|
|
285
375
|
}));
|
|
286
376
|
let configValueSources = {};
|
|
@@ -308,13 +398,11 @@ async function loadVikeConfig(userRootDir, vikeVitePluginOptions) {
|
|
|
308
398
|
return pageConfig;
|
|
309
399
|
}));
|
|
310
400
|
assertPageConfigs(pageConfigs);
|
|
311
|
-
|
|
312
|
-
const global = (0, getPageConfigUserFriendly_js_1.getPageConfigUserFriendlyNew)({ configValues });
|
|
313
|
-
return { pageConfigs, pageConfigGlobal, vikeConfigGlobal, vikeConfigNew: { global } };
|
|
401
|
+
return pageConfigs;
|
|
314
402
|
}
|
|
315
403
|
function getConfigValues(pageConfig) {
|
|
316
404
|
const configValues = {};
|
|
317
|
-
(0, serializeConfigValues_js_1.getConfigValuesBase)(pageConfig, (configEnv) => !!configEnv.config).forEach((entry) => {
|
|
405
|
+
(0, serializeConfigValues_js_1.getConfigValuesBase)(pageConfig, (configEnv) => !!configEnv.config, null).forEach((entry) => {
|
|
318
406
|
if (entry.configValueBase.type === 'computed') {
|
|
319
407
|
(0, utils_js_1.assert)('value' in entry); // Help TS
|
|
320
408
|
const { configValueBase, value, configName } = entry;
|
|
@@ -340,7 +428,7 @@ function getConfigValues(pageConfig) {
|
|
|
340
428
|
});
|
|
341
429
|
return configValues;
|
|
342
430
|
}
|
|
343
|
-
// TODO/
|
|
431
|
+
// TODO/now: refactor
|
|
344
432
|
// - Dedupe: most of the assertUsageGlobalConfigs() code below is a copy-paste of the assertUsage() logic inside getGlobalConfigs()
|
|
345
433
|
// - This assertUsage() message is slightly better: use this one for getGlobalConfigs()
|
|
346
434
|
// Global configs should be defined at global locations
|
|
@@ -357,7 +445,7 @@ function assertUsageGlobalConfigs(interfaceFilesRelevantList, configDefinitions,
|
|
|
357
445
|
if (isGlobalConfig(configName))
|
|
358
446
|
return;
|
|
359
447
|
const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
360
|
-
if (configDef.global) {
|
|
448
|
+
if (configDef.global === true) {
|
|
361
449
|
const locationIds = (0, utils_js_1.objectKeys)(interfaceFilesByLocationId);
|
|
362
450
|
if (!(0, filesystemRouting_js_1.isGlobalLocation)(interfaceFile.locationId, locationIds)) {
|
|
363
451
|
const interfaceFilesGlobal = (0, utils_js_1.objectFromEntries)((0, utils_js_1.objectEntries)(interfaceFilesByLocationId).filter(([locationId]) => {
|
|
@@ -416,85 +504,6 @@ function getInterfaceFilesRelevant(interfaceFilesByLocationId, locationIdPage) {
|
|
|
416
504
|
.sort(([locationId1], [locationId2]) => (0, filesystemRouting_js_1.sortAfterInheritanceOrder)(locationId1, locationId2, locationIdPage)));
|
|
417
505
|
return interfaceFilesRelevant;
|
|
418
506
|
}
|
|
419
|
-
async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded, vikeVitePluginOptions) {
|
|
420
|
-
const locationIds = (0, utils_js_1.objectKeys)(interfaceFilesByLocationId);
|
|
421
|
-
const interfaceFilesGlobal = (0, utils_js_1.objectFromEntries)((0, utils_js_1.objectEntries)(interfaceFilesByLocationId).filter(([locationId]) => {
|
|
422
|
-
return (0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds);
|
|
423
|
-
}));
|
|
424
|
-
// Validate that global configs live in global interface files
|
|
425
|
-
{
|
|
426
|
-
const interfaceFilesGlobalPaths = [];
|
|
427
|
-
(0, utils_js_1.objectEntries)(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
|
|
428
|
-
(0, utils_js_1.assert)((0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds));
|
|
429
|
-
interfaceFiles.forEach(({ filePath: { filePathAbsoluteUserRootDir } }) => {
|
|
430
|
-
if (filePathAbsoluteUserRootDir) {
|
|
431
|
-
interfaceFilesGlobalPaths.push(filePathAbsoluteUserRootDir);
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
});
|
|
435
|
-
const globalPaths = Array.from(new Set(interfaceFilesGlobalPaths.map((p) => path_1.default.posix.dirname(p))));
|
|
436
|
-
(0, utils_js_1.objectEntries)(interfaceFilesByLocationId).forEach(([locationId, interfaceFiles]) => {
|
|
437
|
-
interfaceFiles.forEach((interfaceFile) => {
|
|
438
|
-
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
439
|
-
if (!(0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds) && isGlobalConfig(configName)) {
|
|
440
|
-
(0, utils_js_1.assertUsage)(false, [
|
|
441
|
-
`${interfaceFile.filePath.filePathToShowToUser} defines the config ${picocolors_1.default.cyan(configName)} which is global:`,
|
|
442
|
-
globalPaths.length
|
|
443
|
-
? `define ${picocolors_1.default.cyan(configName)} in ${(0, utils_js_1.joinEnglish)(globalPaths, 'or')} instead`
|
|
444
|
-
: `create a global config (e.g. /pages/+config.js) and define ${picocolors_1.default.cyan(configName)} there instead`
|
|
445
|
-
].join(' '));
|
|
446
|
-
}
|
|
447
|
-
});
|
|
448
|
-
});
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
const pageConfigGlobalValues = {};
|
|
452
|
-
const pageConfigGlobal = {
|
|
453
|
-
configDefinitions: configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal,
|
|
454
|
-
configValueSources: {}
|
|
455
|
-
};
|
|
456
|
-
await Promise.all((0, utils_js_1.objectEntries)(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal).map(async ([configName, configDef]) => {
|
|
457
|
-
const sources = await resolveConfigValueSources(configName, configDef, interfaceFilesGlobal, userRootDir, importedFilesLoaded);
|
|
458
|
-
const configValueSource = sources[0];
|
|
459
|
-
if (!configValueSource)
|
|
460
|
-
return;
|
|
461
|
-
pageConfigGlobal.configValueSources[configName] = sources;
|
|
462
|
-
if (configName === 'onBeforeRoute' || configName === 'onPrerenderStart') {
|
|
463
|
-
(0, utils_js_1.assert)(!('value' in configValueSource));
|
|
464
|
-
}
|
|
465
|
-
else {
|
|
466
|
-
(0, utils_js_1.assert)('value' in configValueSource);
|
|
467
|
-
if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
|
|
468
|
-
return;
|
|
469
|
-
pageConfigGlobalValues[configName] = configValueSource.value;
|
|
470
|
-
}
|
|
471
|
-
}));
|
|
472
|
-
const vikeConfigGlobal = resolveVikeConfigGlobal(vikeVitePluginOptions, pageConfigGlobalValues);
|
|
473
|
-
{
|
|
474
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(vikeVitePluginOptions));
|
|
475
|
-
Object.entries(vikeVitePluginOptions).forEach(([configName, value]) => {
|
|
476
|
-
if (pageConfigGlobal.configValueSources[configName])
|
|
477
|
-
return;
|
|
478
|
-
pageConfigGlobal.configValueSources[configName] = [];
|
|
479
|
-
pageConfigGlobal.configValueSources[configName].push({
|
|
480
|
-
value,
|
|
481
|
-
configEnv: { config: true },
|
|
482
|
-
definedAtFilePath: {
|
|
483
|
-
...(0, getFilePath_js_1.getFilePathResolved)({
|
|
484
|
-
userRootDir,
|
|
485
|
-
filePathAbsoluteUserRootDir: '/vite.config.js'
|
|
486
|
-
}),
|
|
487
|
-
fileExportPathToShowToUser: null
|
|
488
|
-
},
|
|
489
|
-
locationId: '/',
|
|
490
|
-
isOverriden: false,
|
|
491
|
-
valueIsImportedAtRuntime: false,
|
|
492
|
-
valueIsDefinedByPlusFile: false
|
|
493
|
-
});
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
|
-
return { pageConfigGlobal, pageConfigGlobalValues, vikeConfigGlobal };
|
|
497
|
-
}
|
|
498
507
|
async function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir, importedFilesLoaded) {
|
|
499
508
|
const sourcesInfo = [];
|
|
500
509
|
// interfaceFilesRelevant is sorted by sortAfterInheritanceOrder()
|
|
@@ -708,7 +717,7 @@ function isDefiningPageConfig(configName) {
|
|
|
708
717
|
return ['Page', 'route'].includes(configName);
|
|
709
718
|
}
|
|
710
719
|
function getConfigDefinitions(interfaceFilesRelevant) {
|
|
711
|
-
const configDefinitionsMerged = { ...
|
|
720
|
+
const configDefinitionsMerged = { ...configDefinitionsBuiltIn };
|
|
712
721
|
Object.entries(interfaceFilesRelevant)
|
|
713
722
|
.reverse()
|
|
714
723
|
.forEach(([_locationId, interfaceFiles]) => {
|
|
@@ -1037,13 +1046,20 @@ function isLoadableAtBuildTime(configDef) {
|
|
|
1037
1046
|
return !!configDef.env.config && !configDef._valueIsFilePath;
|
|
1038
1047
|
}
|
|
1039
1048
|
function isGlobalConfig(configName) {
|
|
1049
|
+
// TODO/now
|
|
1040
1050
|
if (configName === 'prerender')
|
|
1041
1051
|
return false;
|
|
1042
1052
|
const configNamesGlobal = getConfigNamesGlobal();
|
|
1043
1053
|
return (0, utils_js_1.includes)(configNamesGlobal, configName);
|
|
1044
1054
|
}
|
|
1045
1055
|
function getConfigNamesGlobal() {
|
|
1046
|
-
return Object.keys(
|
|
1056
|
+
return Object.keys(configDefinitionsBuiltInGlobal);
|
|
1057
|
+
}
|
|
1058
|
+
function getConfigDefinitionsBuiltInGlobal() {
|
|
1059
|
+
return (0, utils_js_1.objectFromEntries)((0, utils_js_1.objectEntries)(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInAll).filter(([_configName, configDef]) => configDef.global !== undefined));
|
|
1060
|
+
}
|
|
1061
|
+
function getConfigDefinitionsBuiltIn() {
|
|
1062
|
+
return (0, utils_js_1.objectFromEntries)((0, utils_js_1.objectEntries)(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInAll).filter(([_configName, configDef]) => configDef.global !== true));
|
|
1047
1063
|
}
|
|
1048
1064
|
function assertConfigExists(configName, configNamesRelevant, filePathToShowToUser) {
|
|
1049
1065
|
const configNames = [...configNamesRelevant, ...getConfigNamesGlobal()];
|
|
@@ -1071,23 +1087,15 @@ function sortConfigValueSources(configValueSources, locationIdPage) {
|
|
|
1071
1087
|
function getConfigValueInterfaceFile(interfaceFile, configName) {
|
|
1072
1088
|
return interfaceFile.fileExportsByConfigName[configName]?.configValue;
|
|
1073
1089
|
}
|
|
1074
|
-
// TODO: refactor code below
|
|
1090
|
+
// TODO/now: refactor code below
|
|
1075
1091
|
function resolveVikeConfigGlobal(vikeVitePluginOptions, pageConfigGlobalValues) {
|
|
1076
|
-
|
|
1077
|
-
assertVikeConfigGlobal(vikeVitePluginOptions, ({ prop, errMsg }) => `vite.config.js > vike option ${prop} ${errMsg}`);
|
|
1078
|
-
const configs = [vikeVitePluginOptions];
|
|
1079
|
-
assertVikeConfigGlobal(pageConfigGlobalValues, ({ prop, errMsg }) => {
|
|
1080
|
-
// Can we add the config file path ?
|
|
1081
|
-
return `config ${picocolors_1.default.cyan(prop)} ${errMsg}`;
|
|
1082
|
-
});
|
|
1083
|
-
configs.push(pageConfigGlobalValues);
|
|
1092
|
+
const configs = [vikeVitePluginOptions, pageConfigGlobalValues];
|
|
1084
1093
|
const vikeConfigGlobal = {
|
|
1085
1094
|
disableAutoFullBuild: pickFirst(configs.map((c) => c.disableAutoFullBuild)) ?? null,
|
|
1086
1095
|
prerender: resolvePrerenderOptions(configs),
|
|
1087
1096
|
includeAssetsImportedByServer: pickFirst(configs.map((c) => c.includeAssetsImportedByServer)) ?? true,
|
|
1088
1097
|
baseServer: pickFirst(configs.map((c) => c.baseServer)) ?? null,
|
|
1089
1098
|
baseAssets: pickFirst(configs.map((c) => c.baseAssets)) ?? null,
|
|
1090
|
-
redirects: merge(configs.map((c) => c.redirects)) ?? {},
|
|
1091
1099
|
disableUrlNormalization: pickFirst(configs.map((c) => c.disableUrlNormalization)) ?? false,
|
|
1092
1100
|
trailingSlash: pickFirst(configs.map((c) => c.trailingSlash)) ?? false
|
|
1093
1101
|
};
|
|
@@ -1108,84 +1116,6 @@ function resolvePrerenderOptions(configs) {
|
|
|
1108
1116
|
function isObject2(p) {
|
|
1109
1117
|
return typeof p === 'object';
|
|
1110
1118
|
}
|
|
1111
|
-
function merge(objs) {
|
|
1112
|
-
const obj = {};
|
|
1113
|
-
objs.forEach((e) => {
|
|
1114
|
-
Object.assign(obj, e);
|
|
1115
|
-
});
|
|
1116
|
-
return obj;
|
|
1117
|
-
}
|
|
1118
1119
|
function pickFirst(arr) {
|
|
1119
1120
|
return arr.filter((v) => v !== undefined)[0];
|
|
1120
1121
|
}
|
|
1121
|
-
function assertVikeConfigGlobal(vikeConfigGlobal, wrongUsageMsg) {
|
|
1122
|
-
const wrongUsageError = check(vikeConfigGlobal);
|
|
1123
|
-
if (wrongUsageError) {
|
|
1124
|
-
(0, utils_js_1.assertUsage)(false, wrongUsageMsg(wrongUsageError));
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
function check(vikeConfigGlobal) {
|
|
1128
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(vikeConfigGlobal));
|
|
1129
|
-
{
|
|
1130
|
-
const prop = 'disableUrlNormalization';
|
|
1131
|
-
if (!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'boolean') && !(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'undefined'))
|
|
1132
|
-
return { prop, errMsg: 'should be a boolean' };
|
|
1133
|
-
}
|
|
1134
|
-
{
|
|
1135
|
-
const prop = 'trailingSlash';
|
|
1136
|
-
if (!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'boolean') && !(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'undefined'))
|
|
1137
|
-
return { prop, errMsg: 'should be a boolean' };
|
|
1138
|
-
}
|
|
1139
|
-
{
|
|
1140
|
-
const prop = 'redirects';
|
|
1141
|
-
const { redirects } = vikeConfigGlobal;
|
|
1142
|
-
if (!(redirects === undefined ||
|
|
1143
|
-
((0, utils_js_1.isObject)(redirects) && Object.values(redirects).every((v) => typeof v === 'string'))))
|
|
1144
|
-
return { prop, errMsg: 'should be an object of strings' };
|
|
1145
|
-
}
|
|
1146
|
-
{
|
|
1147
|
-
const prop = 'disableAutoFullBuild';
|
|
1148
|
-
if (!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'boolean') &&
|
|
1149
|
-
!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'undefined') &&
|
|
1150
|
-
!(vikeConfigGlobal[prop] === 'prerender'))
|
|
1151
|
-
return { prop, errMsg: "should be a boolean or 'prerender'" };
|
|
1152
|
-
}
|
|
1153
|
-
{
|
|
1154
|
-
const prop = 'includeAssetsImportedByServer';
|
|
1155
|
-
if (!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'boolean') && !(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'undefined'))
|
|
1156
|
-
return { prop, errMsg: 'should be a boolean' };
|
|
1157
|
-
}
|
|
1158
|
-
{
|
|
1159
|
-
const prop = 'prerender';
|
|
1160
|
-
if (!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'object') &&
|
|
1161
|
-
!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'boolean') &&
|
|
1162
|
-
!(0, utils_js_1.hasProp)(vikeConfigGlobal, prop, 'undefined'))
|
|
1163
|
-
return { prop, errMsg: 'should be an object or a boolean' };
|
|
1164
|
-
}
|
|
1165
|
-
const configVikePrerender = vikeConfigGlobal.prerender;
|
|
1166
|
-
if (typeof configVikePrerender === 'object') {
|
|
1167
|
-
{
|
|
1168
|
-
const p = 'partial';
|
|
1169
|
-
if (!(0, utils_js_1.hasProp)(configVikePrerender, p, 'boolean') && !(0, utils_js_1.hasProp)(configVikePrerender, p, 'undefined'))
|
|
1170
|
-
return { prop: `prerender.${p}`, errMsg: 'should be a boolean' };
|
|
1171
|
-
}
|
|
1172
|
-
{
|
|
1173
|
-
const p = 'noExtraDir';
|
|
1174
|
-
if (!(0, utils_js_1.hasProp)(configVikePrerender, p, 'boolean') && !(0, utils_js_1.hasProp)(configVikePrerender, p, 'undefined'))
|
|
1175
|
-
return { prop: `prerender.${p}`, errMsg: 'should be a boolean' };
|
|
1176
|
-
}
|
|
1177
|
-
{
|
|
1178
|
-
const p = 'disableAutoRun';
|
|
1179
|
-
if (!(0, utils_js_1.hasProp)(configVikePrerender, p, 'boolean') && !(0, utils_js_1.hasProp)(configVikePrerender, p, 'undefined'))
|
|
1180
|
-
return { prop: `prerender.${p}`, errMsg: 'should be a boolean' };
|
|
1181
|
-
}
|
|
1182
|
-
{
|
|
1183
|
-
const p = 'parallel';
|
|
1184
|
-
if (!(0, utils_js_1.hasProp)(configVikePrerender, p, 'boolean') &&
|
|
1185
|
-
!(0, utils_js_1.hasProp)(configVikePrerender, p, 'number') &&
|
|
1186
|
-
!(0, utils_js_1.hasProp)(configVikePrerender, p, 'undefined'))
|
|
1187
|
-
return { prop: `prerender.${p}`, errMsg: 'should be a boolean or a number' };
|
|
1188
|
-
}
|
|
1189
|
-
}
|
|
1190
|
-
return null;
|
|
1191
|
-
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -33,7 +33,7 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
33
33
|
const importStatements = [];
|
|
34
34
|
const isClientRouting = (0, getConfigValueBuildTime_js_1.getConfigValueBuildTime)(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
35
35
|
lines.push('export const configValuesSerialized = {');
|
|
36
|
-
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isDev }),
|
|
36
|
+
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isDev }), '', false));
|
|
37
37
|
lines.push('};');
|
|
38
38
|
if (!(0, fixServerAssets_js_1.fixServerAssets_isEnabled)() && includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
39
39
|
importStatements.push(`import '${(0, extractAssetsQuery_js_1.extractAssetsAddQuery)((0, virtualFilePageConfigValuesAll_js_1.getVirtualFileIdPageConfigValuesAll)(pageId, false))}'`);
|
|
@@ -35,7 +35,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
|
|
|
35
35
|
lines.push(` routeFilesystem: ${JSON.stringify(routeFilesystem)},`);
|
|
36
36
|
lines.push(` loadConfigValuesAll: () => import(${JSON.stringify(virtualFileIdPageConfigValuesAll)}),`);
|
|
37
37
|
lines.push(` configValuesSerialized: {`);
|
|
38
|
-
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isDev }),
|
|
38
|
+
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isDev }), ' ', true));
|
|
39
39
|
lines.push(` },`);
|
|
40
40
|
lines.push(` },`);
|
|
41
41
|
});
|
|
@@ -45,7 +45,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
|
|
|
45
45
|
function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements) {
|
|
46
46
|
const lines = [];
|
|
47
47
|
lines.push(` configValuesSerialized: {`);
|
|
48
|
-
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfigGlobal, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isDev }),
|
|
48
|
+
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfigGlobal, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isDev }), ' ', null));
|
|
49
49
|
lines.push(` },`);
|
|
50
50
|
const code = lines.join('\n');
|
|
51
51
|
return code;
|