vike 0.4.223-commit-e239e2b → 0.4.223-commit-3502685
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/commonConfig.js +2 -1
- package/dist/cjs/node/plugin/plugins/fileEnv.js +5 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +19 -9
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +2 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +10 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +112 -79
- package/dist/cjs/node/plugin/utils.js +1 -0
- package/dist/cjs/node/prerender/context.js +3 -8
- package/dist/cjs/node/prerender/resolvePrerenderConfig.js +23 -21
- package/dist/cjs/node/prerender/runPrerender.js +24 -28
- package/dist/cjs/node/prerender/utils.js +1 -0
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/isFilePathAbsoluteFilesystem.js +10 -4
- package/dist/cjs/utils/path.js +1 -0
- package/dist/esm/node/plugin/plugins/commonConfig.js +3 -2
- package/dist/esm/node/plugin/plugins/fileEnv.js +5 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +20 -10
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +11 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +112 -79
- package/dist/esm/node/plugin/utils.d.ts +1 -0
- package/dist/esm/node/plugin/utils.js +1 -0
- package/dist/esm/node/prerender/context.d.ts +0 -2
- package/dist/esm/node/prerender/context.js +4 -9
- package/dist/esm/node/prerender/resolvePrerenderConfig.d.ts +10 -6
- package/dist/esm/node/prerender/resolvePrerenderConfig.js +24 -22
- package/dist/esm/node/prerender/runPrerender.d.ts +7 -25
- package/dist/esm/node/prerender/runPrerender.js +25 -29
- 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 +2 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +165 -5
- package/dist/esm/shared/page-configs/Config.d.ts +8 -0
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +1 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/isFilePathAbsoluteFilesystem.js +8 -2
- package/dist/esm/utils/path.js +1 -0
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -18,6 +18,7 @@ const context_js_1 = require("../../api/context.js");
|
|
|
18
18
|
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
19
19
|
const prepareViteApiCall_js_1 = require("../../api/prepareViteApiCall.js");
|
|
20
20
|
const context_js_2 = require("../../prerender/context.js");
|
|
21
|
+
const resolvePrerenderConfig_js_1 = require("../../prerender/resolvePrerenderConfig.js");
|
|
21
22
|
const pluginName = 'vike:commonConfig';
|
|
22
23
|
function commonConfig(vikeVitePluginOptions) {
|
|
23
24
|
return [
|
|
@@ -43,7 +44,7 @@ function commonConfig(vikeVitePluginOptions) {
|
|
|
43
44
|
},
|
|
44
45
|
// TODO/v1-release: remove https://github.com/vikejs/vike/issues/2122
|
|
45
46
|
configVikePromise: Promise.resolve({
|
|
46
|
-
prerender: (0,
|
|
47
|
+
prerender: (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(vikeConfig).isEnabled
|
|
47
48
|
})
|
|
48
49
|
};
|
|
49
50
|
}
|
|
@@ -60,10 +60,13 @@ function fileEnv() {
|
|
|
60
60
|
Array.from(this.getModuleIds())
|
|
61
61
|
.filter((id) => !skip(id))
|
|
62
62
|
.forEach((moduleId) => {
|
|
63
|
-
const
|
|
63
|
+
const mod = this.getModuleInfo(moduleId);
|
|
64
|
+
const { importers } = mod;
|
|
64
65
|
if (importers.length === 0) {
|
|
65
66
|
// Dynamic imports can only be verified at runtime
|
|
66
|
-
|
|
67
|
+
/* This assertion can fail: https://github.com/vikejs/vike/issues/2227
|
|
68
|
+
assert(dynamicImporters.length > 0)
|
|
69
|
+
*/
|
|
67
70
|
return;
|
|
68
71
|
}
|
|
69
72
|
assertFileEnv(moduleId, !!config.build.ssr, importers, false);
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js
CHANGED
|
@@ -13,6 +13,7 @@ const child_process_1 = require("child_process");
|
|
|
13
13
|
const util_1 = require("util");
|
|
14
14
|
const transpileAndExecuteFile_js_1 = require("./transpileAndExecuteFile.js");
|
|
15
15
|
const getEnvVarObject_js_1 = require("../../../../shared/getEnvVarObject.js");
|
|
16
|
+
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
16
17
|
const execA = (0, util_1.promisify)(child_process_1.exec);
|
|
17
18
|
const debug = (0, utils_js_1.createDebugger)('vike:crawl');
|
|
18
19
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
@@ -20,6 +21,7 @@ const debug = (0, utils_js_1.createDebugger)('vike:crawl');
|
|
|
20
21
|
let gitIsNotUsable = false;
|
|
21
22
|
async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
|
|
22
23
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
24
|
+
(0, utils_js_1.assertFilePathAbsoluteFilesystem)(userRootDir);
|
|
23
25
|
//*/
|
|
24
26
|
const outDirRelativeFromUserRootDir = null;
|
|
25
27
|
/*/
|
|
@@ -37,8 +39,9 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
|
|
|
37
39
|
(!outDirRelativeFromUserRootDir.startsWith('./') &&
|
|
38
40
|
//
|
|
39
41
|
!outDirRelativeFromUserRootDir.startsWith('../')));
|
|
42
|
+
const crawSettings = getCrawlSettings();
|
|
40
43
|
// Crawl
|
|
41
|
-
const filesGit =
|
|
44
|
+
const filesGit = crawSettings.git !== false && (await gitLsFiles(userRootDir, outDirRelativeFromUserRootDir));
|
|
42
45
|
const filesGitNothingFound = !filesGit || filesGit.length === 0;
|
|
43
46
|
const filesGlob = (filesGitNothingFound || debug.isActivated) && (await tinyglobby(userRootDir, outDirRelativeFromUserRootDir));
|
|
44
47
|
let files = !filesGitNothingFound
|
|
@@ -46,8 +49,11 @@ async function crawlPlusFiles(userRootDir, outDirAbsoluteFilesystem) {
|
|
|
46
49
|
: // Fallback to tinyglobby for users that dynamically generate plus files. (Assuming that no plus file is found because of the user's .gitignore list.)
|
|
47
50
|
filesGlob;
|
|
48
51
|
(0, utils_js_1.assert)(files);
|
|
49
|
-
if (debug.isActivated)
|
|
50
|
-
(0, utils_js_1.assert)(
|
|
52
|
+
if (debug.isActivated) {
|
|
53
|
+
(0, utils_js_1.assert)(filesGit);
|
|
54
|
+
(0, utils_js_1.assert)(filesGlob);
|
|
55
|
+
(0, utils_js_1.assertWarning)((0, utils_js_1.deepEqual)(filesGlob.slice().sort(), filesGit.slice().sort()), "Git and glob results aren't matching.", { onlyOnce: false });
|
|
56
|
+
}
|
|
51
57
|
// Filter build files
|
|
52
58
|
files = files.filter((filePath) => !(0, transpileAndExecuteFile_js_1.isTemporaryBuildFile)(filePath));
|
|
53
59
|
// Normalize
|
|
@@ -134,8 +140,7 @@ async function tinyglobby(userRootDir, outDirRelativeFromUserRootDir) {
|
|
|
134
140
|
const options = {
|
|
135
141
|
ignore: getIgnoreAsPatterns(outDirRelativeFromUserRootDir),
|
|
136
142
|
cwd: userRootDir,
|
|
137
|
-
dot: false
|
|
138
|
-
expandDirectories: false
|
|
143
|
+
dot: false
|
|
139
144
|
};
|
|
140
145
|
const files = await (0, tinyglobby_1.glob)(pattern, options);
|
|
141
146
|
// Make build deterministic, in order to get a stable generated hash for dist/client/assets/entries/entry-client-routing.${hash}.js
|
|
@@ -158,7 +163,9 @@ function getIgnoreAsPatterns(outDirRelativeFromUserRootDir) {
|
|
|
158
163
|
// +Page.js
|
|
159
164
|
// +Page.telefunc.js
|
|
160
165
|
// ```
|
|
161
|
-
'**/*.telefunc.*'
|
|
166
|
+
'**/*.telefunc.*',
|
|
167
|
+
// https://github.com/vikejs/vike/discussions/2222
|
|
168
|
+
'**/*.generated.*'
|
|
162
169
|
];
|
|
163
170
|
if (outDirRelativeFromUserRootDir) {
|
|
164
171
|
(0, utils_js_1.assert)(!outDirRelativeFromUserRootDir.startsWith('/'));
|
|
@@ -172,6 +179,7 @@ function getIgnoreAsFilterFn(outDirRelativeFromUserRootDir) {
|
|
|
172
179
|
return (file) => !file.includes('node_modules/') &&
|
|
173
180
|
!file.includes('ejected/') &&
|
|
174
181
|
!file.includes('.telefunc.') &&
|
|
182
|
+
!file.includes('.generated.') &&
|
|
175
183
|
(outDirRelativeFromUserRootDir === null || !file.startsWith(`${outDirRelativeFromUserRootDir}/`));
|
|
176
184
|
}
|
|
177
185
|
// Whether Git is installed and whether we can use it
|
|
@@ -228,9 +236,11 @@ async function runCmd2(cmd, cwd) {
|
|
|
228
236
|
stderr = stderr.toString().trim();
|
|
229
237
|
return { stdout, stderr };
|
|
230
238
|
}
|
|
231
|
-
function
|
|
232
|
-
const
|
|
233
|
-
|
|
239
|
+
function getCrawlSettings() {
|
|
240
|
+
const crawlSettings = (0, getEnvVarObject_js_1.getEnvVarObject)('VIKE_CRAWL') ?? {};
|
|
241
|
+
const wrongUsage = (settingName, settingType) => `Setting ${picocolors_1.default.cyan(settingName)} in VIKE_CRAWL should be a ${picocolors_1.default.cyan(settingType)}`;
|
|
242
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(crawlSettings, 'git', 'boolean') || (0, utils_js_1.hasProp)(crawlSettings, 'git', 'undefined'), wrongUsage('git', 'boolean'));
|
|
243
|
+
return crawlSettings;
|
|
234
244
|
}
|
|
235
245
|
function isPlusFile(filePath) {
|
|
236
246
|
(0, utils_js_1.assertPosixPath)(filePath);
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js
CHANGED
|
@@ -44,6 +44,7 @@ function getLogicalPath(locationId, ignoredDirs, removeParenthesesDirs) {
|
|
|
44
44
|
assertIsPath(logicalPath);
|
|
45
45
|
return logicalPath;
|
|
46
46
|
}
|
|
47
|
+
// See getPlusFilesRelevant() and getPlusFilesOrdered()
|
|
47
48
|
function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
48
49
|
assertLocationId(locationId1);
|
|
49
50
|
assertLocationId(locationId2);
|
|
@@ -52,7 +53,7 @@ function sortAfterInheritanceOrder(locationId1, locationId2, locationIdPage) {
|
|
|
52
53
|
const inheritanceRoot1 = getInheritanceRoot(locationId1);
|
|
53
54
|
const inheritanceRoot2 = getInheritanceRoot(locationId2);
|
|
54
55
|
const inheritanceRootPage = getInheritanceRoot(locationIdPage);
|
|
55
|
-
//
|
|
56
|
+
// Only works if both locationId1 and locationId2 are inherited by the same page
|
|
56
57
|
(0, utils_js_1.assert)(isInherited(locationId1, locationIdPage));
|
|
57
58
|
(0, utils_js_1.assert)(isInherited(locationId2, locationIdPage));
|
|
58
59
|
// Equivalent assertion (see isInherited() implementation)
|
|
@@ -15,13 +15,14 @@ const import_1 = require("@brillout/import");
|
|
|
15
15
|
const utils_js_1 = require("../../../../utils.js");
|
|
16
16
|
const transformPointerImports_js_1 = require("./transformPointerImports.js");
|
|
17
17
|
const getVikeConfig_js_1 = require("../getVikeConfig.js");
|
|
18
|
-
require("source-map-support
|
|
18
|
+
const source_map_support_1 = __importDefault(require("source-map-support"));
|
|
19
19
|
const getFilePath_js_1 = require("../../../../shared/getFilePath.js");
|
|
20
20
|
const module_1 = require("module");
|
|
21
21
|
// @ts-ignore `file://${__filename}` is shimmed at dist/cjs by dist-cjs-fixup.js.
|
|
22
22
|
const importMetaUrl = `file://${__filename}`;
|
|
23
23
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
24
24
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
25
|
+
installSourceMapSupport();
|
|
25
26
|
const debug = (0, utils_js_1.createDebugger)('vike:pointer-imports');
|
|
26
27
|
const debugEsbuildResolve = (0, utils_js_1.createDebugger)('vike:esbuild-resolve');
|
|
27
28
|
if (debugEsbuildResolve.isActivated)
|
|
@@ -406,3 +407,11 @@ function cleanEsbuildErrors(errors) {
|
|
|
406
407
|
// ```
|
|
407
408
|
!note.text.includes('as external to exclude it from the bundle'))));
|
|
408
409
|
}
|
|
410
|
+
function installSourceMapSupport() {
|
|
411
|
+
// Don't break Vitest's source mapping
|
|
412
|
+
if ((0, utils_js_1.isVitest)())
|
|
413
|
+
return;
|
|
414
|
+
// How about other test runners?
|
|
415
|
+
// Should we call installSourceMapSupport() lazily in transpileAndExecuteFile() instead?
|
|
416
|
+
source_map_support_1.default.install();
|
|
417
|
+
}
|
|
@@ -148,7 +148,7 @@ async function loadVikeConfig(userRootDir, vikeVitePluginOptions) {
|
|
|
148
148
|
const configDefinitionsResolved = await resolveConfigDefinitions(plusFilesAll, userRootDir, esbuildCache);
|
|
149
149
|
assertKnownConfigs(configDefinitionsResolved, plusFilesAll);
|
|
150
150
|
const { pageConfigGlobal, pageConfigs } = getPageConfigsBuildTime(configDefinitionsResolved, plusFilesAll, userRootDir);
|
|
151
|
-
//
|
|
151
|
+
// Backwards compatibility for vike(options) in vite.config.js
|
|
152
152
|
temp_interopVikeVitePlugin(pageConfigGlobal, vikeVitePluginOptions, userRootDir);
|
|
153
153
|
// global
|
|
154
154
|
const pageConfigGlobalValues = getConfigValues(pageConfigGlobal);
|
|
@@ -161,9 +161,7 @@ async function loadVikeConfig(userRootDir, vikeVitePluginOptions) {
|
|
|
161
161
|
return { pageConfigs, pageConfigGlobal, global, pages };
|
|
162
162
|
}
|
|
163
163
|
async function resolveConfigDefinitions(plusFilesAll, userRootDir, esbuildCache) {
|
|
164
|
-
const configDefinitionsGlobal = getConfigDefinitions(
|
|
165
|
-
// We use `plusFilesAll` in order to allow local Vike extensions to create global configs.
|
|
166
|
-
sortForGlobal(plusFilesAll), (configDef) => !!configDef.global);
|
|
164
|
+
const configDefinitionsGlobal = getConfigDefinitions(sortAfterInheritanceOrderGlobal(plusFilesAll), (configDef) => !!configDef.global);
|
|
167
165
|
await loadCustomConfigBuildTimeFiles(plusFilesAll, configDefinitionsGlobal, userRootDir, esbuildCache);
|
|
168
166
|
const configDefinitionsLocal = {};
|
|
169
167
|
await Promise.all((0, utils_js_1.objectEntries)(plusFilesAll).map(async ([locationId, plusFiles]) => {
|
|
@@ -199,14 +197,13 @@ function getPageConfigsBuildTime(configDefinitionsResolved, plusFilesAll, userRo
|
|
|
199
197
|
configValueSources: {}
|
|
200
198
|
};
|
|
201
199
|
(0, utils_js_1.objectEntries)(configDefinitionsResolved.configDefinitionsGlobal).forEach(([configName, configDef]) => {
|
|
202
|
-
const sources = resolveConfigValueSources(configName, configDef,
|
|
203
|
-
// We use `plusFilesAll` in order to allow local Vike extensions to set the value of global configs (e.g. `vite`).
|
|
204
|
-
sortForGlobal(plusFilesAll), userRootDir, true);
|
|
200
|
+
const sources = resolveConfigValueSources(configName, configDef, sortAfterInheritanceOrderGlobal(plusFilesAll), userRootDir, true);
|
|
205
201
|
if (sources.length === 0)
|
|
206
202
|
return;
|
|
207
203
|
pageConfigGlobal.configValueSources[configName] = sources;
|
|
208
204
|
});
|
|
209
|
-
|
|
205
|
+
applyEffectsMetaEnv(pageConfigGlobal.configValueSources, configDefinitionsResolved.configDefinitionsGlobal);
|
|
206
|
+
applyEffectsConfVal(pageConfigGlobal.configValueSources, configDefinitionsResolved.configDefinitionsGlobal);
|
|
210
207
|
assertPageConfigGlobal(pageConfigGlobal, plusFilesAll);
|
|
211
208
|
const pageConfigs = (0, utils_js_1.objectEntries)(configDefinitionsResolved.configDefinitionsLocal)
|
|
212
209
|
.filter(([_locationId, { plusFiles }]) => isDefiningPage(plusFiles))
|
|
@@ -223,7 +220,8 @@ function getPageConfigsBuildTime(configDefinitionsResolved, plusFilesAll, userRo
|
|
|
223
220
|
configValueSources[configName] = sources;
|
|
224
221
|
});
|
|
225
222
|
const pageConfigRoute = determineRouteFilesystem(locationId, configValueSources);
|
|
226
|
-
|
|
223
|
+
applyEffectsMetaEnv(configValueSources, configDefinitionsLocal);
|
|
224
|
+
applyEffectsConfVal(configValueSources, configDefinitionsLocal);
|
|
227
225
|
const configValuesComputed = getComputed(configValueSources, configDefinitionsLocal);
|
|
228
226
|
const pageConfig = {
|
|
229
227
|
pageId: locationId,
|
|
@@ -366,18 +364,18 @@ function temp_interopVikeVitePlugin(pageConfigGlobal, vikeVitePluginOptions, use
|
|
|
366
364
|
});
|
|
367
365
|
});
|
|
368
366
|
}
|
|
367
|
+
// Together with getPlusFilesOrdered() this implements the whole config inheritance ordering for non-global configs. See sortAfterInheritanceOrderGlobal() for global configs.
|
|
369
368
|
function getPlusFilesRelevant(plusFilesAll, locationIdPage) {
|
|
370
369
|
const plusFilesRelevant = Object.fromEntries((0, utils_js_1.objectEntries)(plusFilesAll)
|
|
371
370
|
.filter(([locationId]) => {
|
|
372
371
|
return (0, filesystemRouting_js_1.isInherited)(locationId, locationIdPage);
|
|
373
372
|
})
|
|
374
|
-
// Sort after config inheritance.
|
|
375
|
-
// - Together with getPlusFilesOrdered() this implements the whole order of config inheritance.
|
|
376
|
-
// - See sortForGlobal() for global configs order.
|
|
377
373
|
.sort(([locationId1], [locationId2]) => (0, filesystemRouting_js_1.sortAfterInheritanceOrder)(locationId1, locationId2, locationIdPage)));
|
|
378
374
|
return plusFilesRelevant;
|
|
379
375
|
}
|
|
380
|
-
|
|
376
|
+
// This implements the whole config inheritance ordering for global configs.
|
|
377
|
+
// We use `plusFilesAll` in order to allow local Vike extensions to create global configs, and to set the value of global configs such as `+vite` (enabling Vike extensions to add Vite plugins).
|
|
378
|
+
function sortAfterInheritanceOrderGlobal(plusFilesAll) {
|
|
381
379
|
const plusFilesAllSorted = Object.fromEntries((0, utils_js_1.objectEntries)(plusFilesAll)
|
|
382
380
|
.sort((0, utils_js_1.lowerFirst)(([locationId]) => locationId.split('/').length))
|
|
383
381
|
.sort((0, utils_js_1.makeFirst)(([locationId]) => isGlobalLocation(locationId, plusFilesAll))));
|
|
@@ -391,22 +389,20 @@ function resolveConfigValueSources(configName, configDef, plusFilesRelevant, use
|
|
|
391
389
|
return configValueSource;
|
|
392
390
|
});
|
|
393
391
|
if ((0, utils_js_1.isCallable)(configDef.global)) {
|
|
394
|
-
const isGlobalValue = configDef.global;
|
|
395
392
|
(0, utils_js_1.assert)(configDef.env.config);
|
|
396
393
|
sources = sources.filter((source) => {
|
|
397
394
|
(0, utils_js_1.assert)(source.configEnv.config);
|
|
398
395
|
(0, utils_js_1.assert)(source.valueIsLoaded);
|
|
399
|
-
const valueIsGlobal =
|
|
396
|
+
const valueIsGlobal = resolveIsGlobalValue(configDef.global, source.value);
|
|
400
397
|
return isGlobal ? valueIsGlobal : !valueIsGlobal;
|
|
401
398
|
});
|
|
402
399
|
}
|
|
403
400
|
return sources;
|
|
404
401
|
}
|
|
405
|
-
// Together with
|
|
402
|
+
// Together with getPlusFilesRelevant() this implements the whole config inheritance ordering.
|
|
406
403
|
function getPlusFilesOrdered(configName, plusFilesRelevant) {
|
|
407
404
|
const plusFilesOrdered = [];
|
|
408
|
-
// `plusFilesRelevant` is already
|
|
409
|
-
// `plusFilesAtLocationId` is already sorted by sortMakeDeterministic() at getPlusFilesAll()
|
|
405
|
+
// `plusFilesRelevant` is already deterministic, see sortMakeDeterministic() at getPlusFilesAll()
|
|
410
406
|
for (const plusFilesAtLocationId of Object.values(plusFilesRelevant)) {
|
|
411
407
|
const plusFilesForConfigName = plusFilesAtLocationId.filter((plusFile) => getDefiningConfigNames(plusFile).includes(configName));
|
|
412
408
|
// We populate `plusFilesOrdered` with inheritance order.
|
|
@@ -583,6 +579,15 @@ function isDefiningPage(plusFiles) {
|
|
|
583
579
|
function isDefiningPageConfig(configName) {
|
|
584
580
|
return ['Page', 'route'].includes(configName);
|
|
585
581
|
}
|
|
582
|
+
function resolveIsGlobalValue(configDefGlobal, configValue) {
|
|
583
|
+
let isGlobal;
|
|
584
|
+
if ((0, utils_js_1.isCallable)(configDefGlobal))
|
|
585
|
+
isGlobal = configDefGlobal(configValue);
|
|
586
|
+
else
|
|
587
|
+
isGlobal = configDefGlobal ?? false;
|
|
588
|
+
(0, utils_js_1.assert)(typeof isGlobal === 'boolean');
|
|
589
|
+
return isGlobal;
|
|
590
|
+
}
|
|
586
591
|
function getDefiningConfigNames(plusFile) {
|
|
587
592
|
let configNames = [];
|
|
588
593
|
if (!plusFile.isConfigFile) {
|
|
@@ -667,75 +672,103 @@ function assertMetaUsage(metaVal, metaConfigDefinedAt) {
|
|
|
667
672
|
}
|
|
668
673
|
});
|
|
669
674
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
675
|
+
// Test: https://github.com/vikejs/vike/blob/441a37c4c1a3b07bb8f6efb1d1f7be297a53974a/test/playground/vite.config.ts#L39
|
|
676
|
+
function applyEffectsConfVal(configValueSources, configDefinitions) {
|
|
677
|
+
(0, utils_js_1.objectEntries)(configDefinitions).forEach(([configNameEffect, configDefEffect]) => {
|
|
678
|
+
const sourceEffect = configValueSources[configNameEffect]?.[0];
|
|
679
|
+
if (!sourceEffect)
|
|
673
680
|
return;
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
(0, utils_js_1.assertUsage)(configDef.env.config, [
|
|
677
|
-
`Cannot add effect to ${picocolors_1.default.cyan(configName)} because its ${picocolors_1.default.cyan('env')} is ${picocolors_1.default.cyan(JSON.stringify(configDef.env))}: effects can only be added to configs with an ${picocolors_1.default.cyan('env')} with ${picocolors_1.default.cyan('{ config: true }')}.`
|
|
678
|
-
].join(' '));
|
|
679
|
-
const source = configValueSources[configName]?.[0];
|
|
680
|
-
if (!source)
|
|
681
|
+
const effect = runEffect(configNameEffect, configDefEffect, sourceEffect);
|
|
682
|
+
if (!effect)
|
|
681
683
|
return;
|
|
682
|
-
|
|
683
|
-
(
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
684
|
+
const { configModFromEffect, configValueEffectSource } = effect;
|
|
685
|
+
applyEffectConfVal(configModFromEffect, sourceEffect, configValueSources, configNameEffect, configDefEffect, configDefinitions, configValueEffectSource);
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
// Test: https://github.com/vikejs/vike/blob/441a37c4c1a3b07bb8f6efb1d1f7be297a53974a/test/playground/pages/config-meta/effect/e2e-test.ts#L16
|
|
689
|
+
function applyEffectsMetaEnv(configValueSources, configDefinitions) {
|
|
690
|
+
(0, utils_js_1.objectEntries)(configDefinitions).forEach(([configNameEffect, configDefEffect]) => {
|
|
691
|
+
const sourceEffect = configValueSources[configNameEffect]?.[0];
|
|
692
|
+
if (!sourceEffect)
|
|
693
|
+
return;
|
|
694
|
+
const effect = runEffect(configNameEffect, configDefEffect, sourceEffect);
|
|
695
|
+
if (!effect)
|
|
690
696
|
return;
|
|
691
|
-
|
|
697
|
+
const { configModFromEffect } = effect;
|
|
698
|
+
applyEffectMetaEnv(configModFromEffect, configValueSources, configDefEffect);
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
function runEffect(configName, configDef, source) {
|
|
702
|
+
if (!configDef.effect)
|
|
703
|
+
return null;
|
|
704
|
+
// The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
|
|
705
|
+
(0, utils_js_1.assertUsage)(configDef.env.config, [
|
|
706
|
+
`Cannot add meta.effect to ${picocolors_1.default.cyan(configName)} because its meta.env is ${picocolors_1.default.cyan(JSON.stringify(configDef.env))} but an effect can only be added to a config that has a meta.env with ${picocolors_1.default.cyan('{ config: true }')}.`
|
|
707
|
+
].join(' '));
|
|
708
|
+
(0, utils_js_1.assert)(source.valueIsLoaded);
|
|
709
|
+
const configValueEffectSource = source.value;
|
|
710
|
+
// Call effect
|
|
711
|
+
const configModFromEffect = configDef.effect({
|
|
712
|
+
configValue: configValueEffectSource,
|
|
713
|
+
configDefinedAt: (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, source.definedAtFilePath)
|
|
692
714
|
});
|
|
715
|
+
if (!configModFromEffect)
|
|
716
|
+
return null;
|
|
717
|
+
return { configModFromEffect, configValueEffectSource };
|
|
693
718
|
}
|
|
694
|
-
function
|
|
719
|
+
function applyEffectConfVal(configModFromEffect, sourceEffect, configValueSources, configNameEffect, configDefEffect, configDefinitions, configValueEffectSource) {
|
|
720
|
+
(0, utils_js_1.objectEntries)(configModFromEffect).forEach(([configNameTarget, configValue]) => {
|
|
721
|
+
if (configNameTarget === 'meta')
|
|
722
|
+
return;
|
|
723
|
+
const configDef = configDefinitions[configNameTarget];
|
|
724
|
+
(0, utils_js_1.assert)(configDef);
|
|
725
|
+
(0, utils_js_1.assert)(configDefEffect._userEffectDefinedAtFilePath);
|
|
726
|
+
const configValueSource = {
|
|
727
|
+
definedAtFilePath: configDefEffect._userEffectDefinedAtFilePath,
|
|
728
|
+
plusFile: sourceEffect.plusFile,
|
|
729
|
+
locationId: sourceEffect.locationId,
|
|
730
|
+
configEnv: configDef.env,
|
|
731
|
+
isOverriden: false, // TODO/now check
|
|
732
|
+
valueIsLoadedWithImport: false,
|
|
733
|
+
valueIsDefinedByPlusValueFile: false,
|
|
734
|
+
valueIsLoaded: true,
|
|
735
|
+
value: configValue
|
|
736
|
+
};
|
|
737
|
+
const isValueGlobalSource = resolveIsGlobalValue(configDefEffect.global, configValueEffectSource);
|
|
738
|
+
const isValueGlobalTarget = resolveIsGlobalValue(configDef.global, configValue);
|
|
739
|
+
const isGlobalHumanReadable = (isGlobal) => `${isGlobal ? 'non-' : ''}global`;
|
|
740
|
+
// The error message make it sound like it's an inherent limitation, it actually isn't (both ways can make senses).
|
|
741
|
+
(0, utils_js_1.assertUsage)(isValueGlobalSource === isValueGlobalTarget, `The configuration ${picocolors_1.default.cyan(configNameEffect)} is set to ${picocolors_1.default.cyan(JSON.stringify(configValueEffectSource))} which is considered ${isGlobalHumanReadable(isValueGlobalSource)}. However, it has a meta.effect that sets the configuration ${picocolors_1.default.cyan(configNameTarget)} to ${picocolors_1.default.cyan(JSON.stringify(configValue))} which is considered ${isGlobalHumanReadable(isValueGlobalTarget)}. This is contradictory: make sure the values are either both non-global or both global.`);
|
|
742
|
+
configValueSources[configNameTarget] ?? (configValueSources[configNameTarget] = []);
|
|
743
|
+
configValueSources[configNameTarget].push(configValueSource);
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
function applyEffectMetaEnv(configModFromEffect, configValueSources, configDefEffect) {
|
|
695
747
|
const notSupported = `${picocolors_1.default.cyan('meta.effect')} currently only supports setting the value of a config, or modifying the ${picocolors_1.default.cyan('meta.env')} of a config.`;
|
|
696
|
-
(0, utils_js_1.objectEntries)(configModFromEffect).forEach(([
|
|
697
|
-
if (
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
else {
|
|
703
|
-
configDefinedAt = null;
|
|
704
|
-
}
|
|
705
|
-
assertMetaUsage(configValue, configDefinedAt);
|
|
706
|
-
(0, utils_js_1.objectEntries)(configValue).forEach(([configTargetName, configTargetDef]) => {
|
|
707
|
-
{
|
|
708
|
-
const keys = Object.keys(configTargetDef);
|
|
709
|
-
(0, utils_js_1.assertUsage)(keys.includes('env'), notSupported);
|
|
710
|
-
(0, utils_js_1.assertUsage)(keys.length === 1, notSupported);
|
|
711
|
-
}
|
|
712
|
-
const envOverriden = configTargetDef.env;
|
|
713
|
-
const sources = configValueSources[configTargetName];
|
|
714
|
-
sources?.forEach((configValueSource) => {
|
|
715
|
-
// Apply effect
|
|
716
|
-
configValueSource.configEnv = envOverriden;
|
|
717
|
-
});
|
|
718
|
-
});
|
|
748
|
+
(0, utils_js_1.objectEntries)(configModFromEffect).forEach(([configNameTarget, configValue]) => {
|
|
749
|
+
if (configNameTarget !== 'meta')
|
|
750
|
+
return;
|
|
751
|
+
let configDefinedAt;
|
|
752
|
+
if (configDefEffect._userEffectDefinedAtFilePath) {
|
|
753
|
+
configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configNameTarget, configDefEffect._userEffectDefinedAtFilePath);
|
|
719
754
|
}
|
|
720
755
|
else {
|
|
721
|
-
|
|
722
|
-
(0, utils_js_1.assert)(configDef);
|
|
723
|
-
(0, utils_js_1.assert)(configDefEffect._userEffectDefinedAtFilePath);
|
|
724
|
-
const configValueSource = {
|
|
725
|
-
definedAtFilePath: configDefEffect._userEffectDefinedAtFilePath,
|
|
726
|
-
plusFile: source.plusFile,
|
|
727
|
-
locationId: source.locationId,
|
|
728
|
-
configEnv: configDef.env,
|
|
729
|
-
isOverriden: false, // TODO/now check
|
|
730
|
-
valueIsLoadedWithImport: false,
|
|
731
|
-
valueIsDefinedByPlusValueFile: false,
|
|
732
|
-
valueIsLoaded: true,
|
|
733
|
-
value: configValue
|
|
734
|
-
};
|
|
735
|
-
(0, utils_js_1.assertUsage)(!!configDef.global === !!configDefEffect.global, `The configuration ${picocolors_1.default.cyan(configNameEffect)} has a ${picocolors_1.default.cyan('meta.effect')} that changes the configuration ${picocolors_1.default.cyan(configName)} and, consequently, both ${picocolors_1.default.cyan(configNameEffect)} and ${picocolors_1.default.cyan(configName)} must have the same ${picocolors_1.default.cyan('meta.global')} value.`);
|
|
736
|
-
configValueSources[configName] ?? (configValueSources[configName] = []);
|
|
737
|
-
configValueSources[configName].push(configValueSource);
|
|
756
|
+
configDefinedAt = null;
|
|
738
757
|
}
|
|
758
|
+
assertMetaUsage(configValue, configDefinedAt);
|
|
759
|
+
(0, utils_js_1.objectEntries)(configValue).forEach(([configTargetName, configTargetDef]) => {
|
|
760
|
+
{
|
|
761
|
+
const keys = Object.keys(configTargetDef);
|
|
762
|
+
(0, utils_js_1.assertUsage)(keys.includes('env'), notSupported);
|
|
763
|
+
(0, utils_js_1.assertUsage)(keys.length === 1, notSupported);
|
|
764
|
+
}
|
|
765
|
+
const envOverriden = configTargetDef.env;
|
|
766
|
+
const sources = configValueSources[configTargetName];
|
|
767
|
+
sources?.forEach((configValueSource) => {
|
|
768
|
+
// Apply effect
|
|
769
|
+
configValueSource.configEnv = envOverriden;
|
|
770
|
+
});
|
|
771
|
+
});
|
|
739
772
|
});
|
|
740
773
|
}
|
|
741
774
|
function getComputed(configValueSources, configDefinitions) {
|
|
@@ -849,7 +882,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
849
882
|
function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName) {
|
|
850
883
|
(0, utils_js_1.assert)(configFilesystemRoutingRoot.configEnv.config);
|
|
851
884
|
// Eagerly loaded since it's config-only
|
|
852
|
-
(0, utils_js_1.assert)(
|
|
885
|
+
(0, utils_js_1.assert)(configFilesystemRoutingRoot.valueIsLoaded);
|
|
853
886
|
const { value } = configFilesystemRoutingRoot;
|
|
854
887
|
const configDefinedAt = (0, getConfigDefinedAt_js_1.getConfigDefinedAt)('Config', configName, configFilesystemRoutingRoot.definedAtFilePath);
|
|
855
888
|
(0, utils_js_1.assertUsage)(typeof value === 'string', `${configDefinedAt} should be a string`);
|
|
@@ -44,3 +44,4 @@ __exportStar(require("../../utils/isArray.js"), exports);
|
|
|
44
44
|
__exportStar(require("../../utils/PROJECT_VERSION.js"), exports);
|
|
45
45
|
__exportStar(require("../../utils/isEqualStringList.js"), exports);
|
|
46
46
|
__exportStar(require("../../utils/isDocker.js"), exports);
|
|
47
|
+
__exportStar(require("../../utils/isVitest.js"), exports);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isPrerenderEnabled = isPrerenderEnabled;
|
|
4
3
|
exports.isPrerenderAutoRunEnabled = isPrerenderAutoRunEnabled;
|
|
5
4
|
exports.temp_disablePrerenderAutoRun = temp_disablePrerenderAutoRun;
|
|
6
5
|
exports.isPrerendering = isPrerendering;
|
|
@@ -8,14 +7,10 @@ exports.setContextIsPrerendering = setContextIsPrerendering;
|
|
|
8
7
|
const getGlobalObject_js_1 = require("../../utils/getGlobalObject.js");
|
|
9
8
|
const resolvePrerenderConfig_js_1 = require("./resolvePrerenderConfig.js");
|
|
10
9
|
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('prerender/context.ts', {});
|
|
11
|
-
function isPrerenderEnabled(vikeConfig) {
|
|
12
|
-
const prerenderConfig = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfig)(vikeConfig);
|
|
13
|
-
return !!prerenderConfig;
|
|
14
|
-
}
|
|
15
10
|
function isPrerenderAutoRunEnabled(vikeConfig) {
|
|
16
|
-
const
|
|
17
|
-
return (
|
|
18
|
-
!(
|
|
11
|
+
const prerenderConfigGlobal = (0, resolvePrerenderConfig_js_1.resolvePrerenderConfigGlobal)(vikeConfig);
|
|
12
|
+
return (prerenderConfigGlobal.isEnabled &&
|
|
13
|
+
!(prerenderConfigGlobal || {}).disableAutoRun &&
|
|
19
14
|
!globalObject.isDisabled &&
|
|
20
15
|
vikeConfig.global.config.disableAutoFullBuild !== 'prerender');
|
|
21
16
|
}
|
|
@@ -1,29 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.resolvePrerenderConfigGlobal = resolvePrerenderConfigGlobal;
|
|
4
4
|
exports.resolvePrerenderConfigLocal = resolvePrerenderConfigLocal;
|
|
5
5
|
const utils_js_1 = require("./utils.js");
|
|
6
6
|
const getConfigValueBuildTime_js_1 = require("../../shared/page-configs/getConfigValueBuildTime.js");
|
|
7
|
-
|
|
8
|
-
// TODO/now:
|
|
9
|
-
// - prerender.value
|
|
10
|
-
function resolvePrerenderConfig(vikeConfig) {
|
|
7
|
+
function resolvePrerenderConfigGlobal(vikeConfig) {
|
|
11
8
|
const prerenderConfigs = vikeConfig.global.config.prerender;
|
|
12
|
-
|
|
13
|
-
!vikeConfig.pageConfigs.some((pageConfig) => resolvePrerenderConfigLocal(pageConfig)?.value)) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
let prerenderSettings = prerenderConfigs || [];
|
|
9
|
+
let prerenderConfigList = prerenderConfigs || [];
|
|
17
10
|
// Needed because of backwards compatibility of `vike({prerender:true})` in `vite.config.js`; after we remove it we can remove this line.
|
|
18
|
-
|
|
19
|
-
(0, utils_js_1.assert)(
|
|
20
|
-
const
|
|
21
|
-
partial: pickFirst(
|
|
22
|
-
noExtraDir: pickFirst(
|
|
23
|
-
parallel: pickFirst(
|
|
24
|
-
disableAutoRun: pickFirst(
|
|
11
|
+
prerenderConfigList = prerenderConfigList.filter(isObject2);
|
|
12
|
+
(0, utils_js_1.assert)(prerenderConfigList.every(isObject2)); // Help TS
|
|
13
|
+
const prerenderConfigGlobal = {
|
|
14
|
+
partial: pickFirst(prerenderConfigList.map((c) => c.partial)) ?? false,
|
|
15
|
+
noExtraDir: pickFirst(prerenderConfigList.map((c) => c.noExtraDir)) ?? false,
|
|
16
|
+
parallel: pickFirst(prerenderConfigList.map((c) => c.parallel)) ?? true,
|
|
17
|
+
disableAutoRun: pickFirst(prerenderConfigList.map((c) => c.disableAutoRun)) ?? false
|
|
25
18
|
};
|
|
26
|
-
|
|
19
|
+
const prerenderConfigGlobalLocalValue = prerenderConfigList.map((c) => c.value).filter((v) => v !== null);
|
|
20
|
+
const defaultLocalValue = pickFirst(prerenderConfigGlobalLocalValue) ??
|
|
21
|
+
(prerenderConfigGlobalLocalValue.length > 0 ||
|
|
22
|
+
// Backwards compatibility for with vike({ prerender: true }) in vite.config.js
|
|
23
|
+
prerenderConfigs?.some((p) => p === true) ||
|
|
24
|
+
false);
|
|
25
|
+
(0, utils_js_1.objectAssign)(prerenderConfigGlobal, {
|
|
26
|
+
defaultLocalValue,
|
|
27
|
+
isEnabled: defaultLocalValue || vikeConfig.pageConfigs.some((pageConfig) => resolvePrerenderConfigLocal(pageConfig)?.value)
|
|
28
|
+
});
|
|
29
|
+
return prerenderConfigGlobal;
|
|
27
30
|
}
|
|
28
31
|
function resolvePrerenderConfigLocal(pageConfig) {
|
|
29
32
|
const configValue = (0, getConfigValueBuildTime_js_1.getConfigValueBuildTime)(pageConfig, 'prerender');
|
|
@@ -34,9 +37,8 @@ function resolvePrerenderConfigLocal(pageConfig) {
|
|
|
34
37
|
const value = values[0];
|
|
35
38
|
(0, utils_js_1.assert)(typeof value === 'boolean');
|
|
36
39
|
(0, utils_js_1.assert)((0, utils_js_1.isArray)(configValue.definedAtData));
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
return { value, configValueFilePathToShowToUser };
|
|
40
|
+
const prerenderConfigLocal = { value };
|
|
41
|
+
return prerenderConfigLocal;
|
|
40
42
|
}
|
|
41
43
|
function isObject2(p) {
|
|
42
44
|
return typeof p === 'object' && p !== null;
|