vike 0.4.143-commit-fa295e1 → 0.4.144-commit-e40e9b1
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/buildConfig.js +1 -1
- package/dist/cjs/node/plugin/plugins/config/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +17 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +69 -87
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +7 -42
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +24 -26
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +6 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +18 -0
- package/dist/cjs/node/plugin/shared/findPageFiles.js +2 -1
- package/dist/cjs/node/plugin/utils.js +1 -1
- package/dist/cjs/node/prerender/runPrerender.js +4 -4
- package/dist/cjs/node/runtime/renderPage.js +1 -1
- package/dist/cjs/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/cjs/shared/getPageFiles/getExports.js +4 -4
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +3 -3
- package/dist/cjs/shared/page-configs/getExportPath.js +7 -8
- package/dist/cjs/shared/page-configs/loadConfigValues.js +1 -1
- package/dist/cjs/shared/page-configs/serialize/PageConfigSerialized.js +2 -0
- package/dist/cjs/shared/{getPageFiles → page-configs/serialize}/assertPageConfigs.js +1 -1
- package/dist/cjs/shared/page-configs/{parseConfigValuesImported.js → serialize/parseConfigValuesImported.js} +13 -10
- package/dist/cjs/shared/{getPageFiles/parsePageConfigsSerialized.js → page-configs/serialize/parsePageConfigs.js} +6 -6
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +58 -0
- package/dist/cjs/shared/page-configs/utils.js +11 -12
- package/dist/cjs/shared/route/loadPageRoutes.js +1 -1
- package/dist/cjs/utils/getOutDirs.js +25 -18
- package/dist/cjs/utils/getValuePrintable.js +1 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/warnIfErrorIsNotObject.js +1 -1
- package/dist/esm/client/client-routing-runtime/useClientRouter.js +1 -1
- package/dist/esm/node/plugin/plugins/buildConfig.js +2 -2
- package/dist/esm/node/plugin/plugins/config/index.js +2 -2
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +4 -6
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +18 -9
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +69 -87
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +1 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +6 -38
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +21 -23
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.d.ts +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +6 -8
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +7 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +15 -0
- package/dist/esm/node/plugin/shared/findPageFiles.js +3 -2
- package/dist/esm/node/plugin/utils.js +1 -1
- package/dist/esm/node/prerender/runPrerender.js +5 -5
- package/dist/esm/node/runtime/renderPage.js +1 -1
- package/dist/esm/shared/assertPageContextProvidedByUser.js +1 -1
- package/dist/esm/shared/getPageFiles/getExports.js +4 -4
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +3 -3
- package/dist/esm/shared/page-configs/PageConfig.d.ts +25 -62
- package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
- package/dist/esm/shared/page-configs/getExportPath.js +7 -8
- package/dist/esm/shared/page-configs/loadConfigValues.js +1 -1
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +32 -0
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.js +1 -0
- package/dist/esm/shared/{getPageFiles → page-configs/serialize}/assertPageConfigs.d.ts +1 -1
- package/dist/esm/shared/{getPageFiles → page-configs/serialize}/assertPageConfigs.js +1 -1
- package/dist/esm/shared/page-configs/{parseConfigValuesImported.d.ts → serialize/parseConfigValuesImported.d.ts} +2 -1
- package/dist/esm/shared/page-configs/{parseConfigValuesImported.js → serialize/parseConfigValuesImported.js} +13 -10
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +7 -0
- package/dist/esm/shared/{getPageFiles/parsePageConfigsSerialized.js → page-configs/serialize/parsePageConfigs.js} +5 -5
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.d.ts +8 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +52 -0
- package/dist/esm/shared/page-configs/utils.d.ts +3 -3
- package/dist/esm/shared/page-configs/utils.js +11 -12
- package/dist/esm/shared/route/loadPageRoutes.js +1 -1
- package/dist/esm/utils/getOutDirs.d.ts +0 -2
- package/dist/esm/utils/getOutDirs.js +24 -17
- package/dist/esm/utils/getValuePrintable.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/warnIfErrorIsNotObject.js +1 -1
- package/package.json +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -13
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -10
- package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.d.ts +0 -6
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.projectInfo = void 0;
|
|
4
4
|
const assertSingleInstance_js_1 = require("./assertSingleInstance.js");
|
|
5
|
-
const PROJECT_VERSION = '0.4.
|
|
5
|
+
const PROJECT_VERSION = '0.4.144-commit-e40e9b1';
|
|
6
6
|
const projectInfo = {
|
|
7
7
|
projectName: 'Vike',
|
|
8
8
|
projectVersion: PROJECT_VERSION,
|
|
@@ -12,7 +12,7 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
12
12
|
// It would be cleaner to:
|
|
13
13
|
// - Call assertUsageErrorIsObject() right after calling the user's hook
|
|
14
14
|
// - Attach the original error: assertUsageError.originalErrorValue = err
|
|
15
|
-
// - Show the original error in
|
|
15
|
+
// - Show the original error in Vike's error handling
|
|
16
16
|
// - Use assertErrorIsObject() throughout Vike's source code
|
|
17
17
|
function warnIfErrorIsNotObject(err) {
|
|
18
18
|
if (!(0, isObject_js_1.isObject)(err)) {
|
|
@@ -320,7 +320,7 @@ function onBrowserHistoryNavigation(callback) {
|
|
|
320
320
|
if (isHashNavigation) {
|
|
321
321
|
// - `history.state` is uninitialized (`null`) when:
|
|
322
322
|
// - The vike app runs `window.location.hash = '#section'`.
|
|
323
|
-
// - The user clicks on an anchor link `<a href="#section">Section</a>`. (Because
|
|
323
|
+
// - The user clicks on an anchor link `<a href="#section">Section</a>`. (Because Vike's `onLinkClick()` handler skips hash links.)
|
|
324
324
|
// - `history.state` is `null` when uninitialized: https://developer.mozilla.org/en-US/docs/Web/API/History/state
|
|
325
325
|
// - Alternatively, we completely take over hash navigation and reproduce the browser's native behavior upon hash navigation.
|
|
326
326
|
// - Problem: we cannot intercept `window.location.hash = '#section'`. (Or maybe we can with the `hashchange` event?)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { buildConfig };
|
|
2
2
|
export { assertRollupInput };
|
|
3
3
|
export { analyzeClientEntries };
|
|
4
|
-
import { assert, resolveOutDir, isObject, viteIsSSR, getFilePathAbsolute, addOnBeforeLogHook, removeFileExtention, unique, assertPosixPath, assertUsage } from '../utils.js';
|
|
4
|
+
import { assert, resolveOutDir, isObject, viteIsSSR, getFilePathAbsolute, addOnBeforeLogHook, removeFileExtention, unique, assertPosixPath, assertUsage, getOutDirs, } from '../utils.js';
|
|
5
5
|
import { virtualFileIdImportUserCodeServer } from '../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
6
6
|
import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
7
7
|
import { getConfigValue } from '../../../shared/page-configs/utils.js';
|
|
@@ -69,7 +69,7 @@ function buildConfig() {
|
|
|
69
69
|
async function getEntries(config) {
|
|
70
70
|
const configVike = await getConfigVike(config);
|
|
71
71
|
const pageFileEntries = await getPageFileEntries(config, configVike.includeAssetsImportedByServer); // TODO/v1-release: remove
|
|
72
|
-
const { pageConfigs } = await getVikeConfig(config.root, false, configVike.extensions);
|
|
72
|
+
const { pageConfigs } = await getVikeConfig(config.root, getOutDirs(config).outDirRoot, false, configVike.extensions);
|
|
73
73
|
assertUsage(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
|
|
74
74
|
if (viteIsSSR(config)) {
|
|
75
75
|
const serverEntries = analyzeServerEntries(pageConfigs);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { resolveVikeConfig };
|
|
2
2
|
import { assertVikeConfig } from './assertVikeConfig.js';
|
|
3
|
-
import { isDev2 } from '../../utils.js';
|
|
3
|
+
import { getOutDirs, isDev2 } from '../../utils.js';
|
|
4
4
|
import { findConfigVikeFromStemPackages } from './findConfigVikeFromStemPackages.js';
|
|
5
5
|
import { pickFirst } from './pickFirst.js';
|
|
6
6
|
import { resolveExtensions } from './resolveExtensions.js';
|
|
@@ -24,7 +24,7 @@ async function resolveConfig(vikeConfig, config) {
|
|
|
24
24
|
const fromStemPackages = await findConfigVikeFromStemPackages(config.root);
|
|
25
25
|
const configs = [fromPluginOptions, ...fromStemPackages, fromViteConfig];
|
|
26
26
|
const extensions = resolveExtensions(configs, config);
|
|
27
|
-
const { globalVikeConfig: fromPlusConfigFile } = await getVikeConfig(config.root, isDev2(config), extensions);
|
|
27
|
+
const { globalVikeConfig: fromPlusConfigFile } = await getVikeConfig(config.root, getOutDirs(config).outDirRoot, isDev2(config), extensions);
|
|
28
28
|
configs.push(fromPlusConfigFile);
|
|
29
29
|
assertVikeConfig(fromPlusConfigFile, ({ prop, errMsg }) => {
|
|
30
30
|
// TODO: add config file path ?
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export { determineOptimizeDeps };
|
|
2
2
|
import { findPageFiles } from '../../shared/findPageFiles.js';
|
|
3
|
-
import { assert, getFilePathAbsolute, isNotNullish, isNpmPackageImport, unique } from '../../utils.js';
|
|
3
|
+
import { assert, getFilePathAbsolute, getOutDirs, isNotNullish, isNpmPackageImport, unique } from '../../utils.js';
|
|
4
4
|
import { getVikeConfig } from '../importUserCode/v1-design/getVikeConfig.js';
|
|
5
5
|
import { getConfigValueSourcesRelevant } from '../../shared/getConfigValueSourcesRelevant.js';
|
|
6
6
|
import { analyzeClientEntries } from '../buildConfig.js';
|
|
7
7
|
import { virtualFileIdImportUserCodeClientCR, virtualFileIdImportUserCodeClientSR } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
8
8
|
async function determineOptimizeDeps(config, configVike, isDev) {
|
|
9
|
-
const { pageConfigs } = await getVikeConfig(config.root, isDev, configVike.extensions);
|
|
9
|
+
const { pageConfigs } = await getVikeConfig(config.root, getOutDirs(config).outDirRoot, isDev, configVike.extensions);
|
|
10
10
|
const { entries, include } = await getPageDeps(config, pageConfigs, isDev);
|
|
11
11
|
{
|
|
12
12
|
// This actually doesn't work: Vite's dep optimizer doesn't seem to be able to crawl virtual files.
|
|
@@ -22,7 +22,7 @@ async function determineOptimizeDeps(config, configVike, isDev) {
|
|
|
22
22
|
*/
|
|
23
23
|
config.optimizeDeps.include = [...include, ...normalizeInclude(config.optimizeDeps.include)];
|
|
24
24
|
config.optimizeDeps.entries = [...entries, ...normalizeEntries(config.optimizeDeps.entries)];
|
|
25
|
-
console.log('config.optimizeDeps', config.optimizeDeps)
|
|
25
|
+
// console.log('config.optimizeDeps', { entries: config.optimizeDeps.entries, include: config.optimizeDeps.include })
|
|
26
26
|
}
|
|
27
27
|
async function getPageDeps(config, pageConfigs, isDev) {
|
|
28
28
|
let entries = [];
|
|
@@ -34,15 +34,13 @@ async function getPageDeps(config, pageConfigs, isDev) {
|
|
|
34
34
|
configValueSourcesRelevant.forEach((configValueSource) => {
|
|
35
35
|
if (!configValueSource.valueIsImportedAtRuntime)
|
|
36
36
|
return;
|
|
37
|
-
if (configValueSource.isComputed)
|
|
38
|
-
return;
|
|
39
37
|
const { definedAtInfo, configEnv } = configValueSource;
|
|
40
38
|
if (configEnv !== 'client-only' && configEnv !== 'server-and-client')
|
|
41
39
|
return;
|
|
42
40
|
if (definedAtInfo.filePathRelativeToUserRootDir !== null) {
|
|
43
41
|
const { filePathAbsolute } = definedAtInfo;
|
|
44
42
|
assert(filePathAbsolute);
|
|
45
|
-
//
|
|
43
|
+
// Surprisingly Vite expects entries to be absolute paths
|
|
46
44
|
entries.push(filePathAbsolute);
|
|
47
45
|
}
|
|
48
46
|
else {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getVirtualFileImportUserCode };
|
|
2
|
-
import { assert, assertPosixPath, viteIsSSR_options, isNotNullish, scriptFileExtensions, debugGlob } from '../../utils.js';
|
|
2
|
+
import { assert, assertPosixPath, viteIsSSR_options, isNotNullish, scriptFileExtensions, debugGlob, getOutDirs } from '../../utils.js';
|
|
3
3
|
import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
4
4
|
import { fileTypes, determineFileType } from '../../../../shared/getPageFiles/fileTypes.js';
|
|
5
5
|
import path from 'path';
|
|
@@ -140,7 +140,7 @@ export const pageFilesList = [];
|
|
|
140
140
|
export const neverLoaded = {};
|
|
141
141
|
export const isGeneratedFile = true;
|
|
142
142
|
|
|
143
|
-
${await getVirtualFilePageConfigs(config.root, isForClientSide, isDev, id, configVike, isClientRouting)}
|
|
143
|
+
${await getVirtualFilePageConfigs(config.root, getOutDirs(config).outDirRoot, isForClientSide, isDev, id, configVike, isClientRouting)}
|
|
144
144
|
|
|
145
145
|
`;
|
|
146
146
|
fileTypes
|
|
@@ -204,10 +204,12 @@ function getGlobs(globRoots, isBuild, fileType, query) {
|
|
|
204
204
|
...globRoots.map((globRoot, i) => {
|
|
205
205
|
const varNameLocal = `${varName}${i + 1}`;
|
|
206
206
|
varNameLocals.push(varNameLocal);
|
|
207
|
-
const
|
|
207
|
+
const globIncludePath = `'${getGlobPath(globRoot.includeDir, fileType)}'`;
|
|
208
|
+
const globExcludePath = globRoot.excludeDir ? `'!${getGlobPath(globRoot.excludeDir, fileType)}'` : null;
|
|
208
209
|
const globOptions = JSON.stringify({ eager: isEager, as: query });
|
|
209
210
|
assert(globOptions.startsWith('{"eager":true') || globOptions.startsWith('{"eager":false'));
|
|
210
|
-
const
|
|
211
|
+
const globPaths = globExcludePath ? `[${globIncludePath}, ${globExcludePath}]` : `[${globIncludePath}]`;
|
|
212
|
+
const globLine = `const ${varNameLocal} = import.meta.glob(${globPaths}, ${globOptions});`;
|
|
211
213
|
return globLine;
|
|
212
214
|
}),
|
|
213
215
|
`const ${varName} = {${varNameLocals.map((varNameLocal) => `...${varNameLocal}`).join(',')}};`,
|
|
@@ -216,19 +218,26 @@ function getGlobs(globRoots, isBuild, fileType, query) {
|
|
|
216
218
|
].join('\n');
|
|
217
219
|
}
|
|
218
220
|
function getGlobRoots(config, configVike) {
|
|
219
|
-
const globRoots = [
|
|
221
|
+
const globRoots = [
|
|
222
|
+
{
|
|
223
|
+
includeDir: '/',
|
|
224
|
+
excludeDir: path.posix.relative(config.root, getOutDirs(config).outDirRoot)
|
|
225
|
+
}
|
|
226
|
+
];
|
|
220
227
|
configVike.extensions
|
|
221
228
|
.map(({ pageConfigsSrcDir }) => pageConfigsSrcDir)
|
|
222
229
|
.filter(isNotNullish)
|
|
223
230
|
.forEach((pageConfigsSrcDir) => {
|
|
224
|
-
const globRoot =
|
|
231
|
+
const globRoot = {
|
|
232
|
+
includeDir: path.posix.relative(config.root, pageConfigsSrcDir)
|
|
233
|
+
};
|
|
225
234
|
globRoots.push(globRoot);
|
|
226
235
|
});
|
|
227
236
|
return globRoots;
|
|
228
237
|
}
|
|
229
|
-
function getGlobPath(
|
|
230
|
-
assertPosixPath(
|
|
231
|
-
let globPath = [...
|
|
238
|
+
function getGlobPath(globRootDir, fileType) {
|
|
239
|
+
assertPosixPath(globRootDir);
|
|
240
|
+
let globPath = [...globRootDir.split('/'), '**', `*${fileType}.${scriptFileExtensions}`].filter(Boolean).join('/');
|
|
232
241
|
if (!globPath.startsWith('/')) {
|
|
233
242
|
globPath = '/' + globPath;
|
|
234
243
|
}
|
|
@@ -3,7 +3,7 @@ import { normalizePath } from 'vite';
|
|
|
3
3
|
import { getConfigVike } from '../../../shared/getConfigVike.js';
|
|
4
4
|
import { getVirtualFilePageConfigValuesAll } from './v1-design/getVirtualFilePageConfigValuesAll.js';
|
|
5
5
|
import { getVirtualFileImportUserCode } from './getVirtualFileImportUserCode.js';
|
|
6
|
-
import { assert, assertPosixPath, getFilePathRelativeToUserRootDir, getVirtualFileId, isDev1, isDev1_onConfigureServer, isVirtualFileId, resolveVirtualFileId } from '../../utils.js';
|
|
6
|
+
import { assert, assertPosixPath, getFilePathRelativeToUserRootDir, getOutDirs, getVirtualFileId, isDev1, isDev1_onConfigureServer, isVirtualFileId, resolveVirtualFileId } from '../../utils.js';
|
|
7
7
|
import { isVirtualFileIdPageConfigValuesAll } from '../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
8
8
|
import { isVirtualFileIdImportUserCode } from '../../../shared/virtual-files/virtualFileImportUserCode.js';
|
|
9
9
|
import { vikeConfigDependencies, reloadVikeConfig, isVikeConfigFile } from './v1-design/getVikeConfig.js';
|
|
@@ -47,7 +47,7 @@ function importUserCode() {
|
|
|
47
47
|
return undefined;
|
|
48
48
|
id = getVirtualFileId(id);
|
|
49
49
|
if (isVirtualFileIdPageConfigValuesAll(id)) {
|
|
50
|
-
const code = await getVirtualFilePageConfigValuesAll(id, config.root, isDev, configVike);
|
|
50
|
+
const code = await getVirtualFilePageConfigValuesAll(id, config.root, getOutDirs(config).outDirRoot, isDev, configVike);
|
|
51
51
|
return code;
|
|
52
52
|
}
|
|
53
53
|
if (isVirtualFileIdImportUserCode(id)) {
|
|
@@ -120,7 +120,7 @@ function reloadConfig(filePath, config, configVike, op) {
|
|
|
120
120
|
const msg = `${op} ${filePathToShowToUser}`;
|
|
121
121
|
logConfigInfo(msg, 'info');
|
|
122
122
|
}
|
|
123
|
-
reloadVikeConfig(config.root, configVike.extensions);
|
|
123
|
+
reloadVikeConfig(config.root, getOutDirs(config).outDirRoot, configVike.extensions);
|
|
124
124
|
}
|
|
125
125
|
function getVirtualModules(server) {
|
|
126
126
|
const virtualModules = Array.from(server.moduleGraph.urlToModuleMap.keys())
|
|
@@ -4,7 +4,7 @@ export type { ConfigDefinition };
|
|
|
4
4
|
export type { ConfigDefinitionInternal };
|
|
5
5
|
export type { ConfigNameGlobal };
|
|
6
6
|
export type { ConfigEffect };
|
|
7
|
-
import type { ConfigEnvInternal, ConfigEnv,
|
|
7
|
+
import type { ConfigEnvInternal, ConfigEnv, ConfigValueSources } from '../../../../../../shared/page-configs/PageConfig.js';
|
|
8
8
|
import type { Config, ConfigNameBuiltIn } from '../../../../../../shared/page-configs/Config.js';
|
|
9
9
|
/** The meta definition of a config.
|
|
10
10
|
*
|
|
@@ -44,7 +44,7 @@ type ConfigEffect = (config: {
|
|
|
44
44
|
}) => Config | undefined;
|
|
45
45
|
/** For Vike internal use */
|
|
46
46
|
type ConfigDefinitionInternal = Omit<ConfigDefinition, 'env'> & {
|
|
47
|
-
_computed?: (
|
|
47
|
+
_computed?: (configValueSources: ConfigValueSources) => unknown;
|
|
48
48
|
_valueIsFilePath?: true;
|
|
49
49
|
env: ConfigEnvInternal;
|
|
50
50
|
};
|
|
@@ -67,13 +67,13 @@ const configDefinitionsBuiltIn = {
|
|
|
67
67
|
},
|
|
68
68
|
isClientSideRenderable: {
|
|
69
69
|
env: 'server-and-client',
|
|
70
|
-
_computed: (
|
|
71
|
-
isConfigSet(
|
|
72
|
-
getConfigEnv(
|
|
70
|
+
_computed: (configValueSources) => isConfigSet(configValueSources, 'onRenderClient') &&
|
|
71
|
+
isConfigSet(configValueSources, 'Page') &&
|
|
72
|
+
getConfigEnv(configValueSources, 'Page') !== 'server-only'
|
|
73
73
|
},
|
|
74
74
|
onBeforeRenderEnv: {
|
|
75
75
|
env: 'client-only',
|
|
76
|
-
_computed: (
|
|
76
|
+
_computed: (configValueSources) => !isConfigSet(configValueSources, 'onBeforeRender') ? null : getConfigEnv(configValueSources, 'onBeforeRender')
|
|
77
77
|
}
|
|
78
78
|
};
|
|
79
79
|
const configDefinitionsBuiltInGlobal = {
|
|
@@ -10,6 +10,6 @@ type VikeConfig = {
|
|
|
10
10
|
globalVikeConfig: Record<string, unknown>;
|
|
11
11
|
};
|
|
12
12
|
declare const vikeConfigDependencies: Set<string>;
|
|
13
|
-
declare function reloadVikeConfig(userRootDir: string, extensions: ExtensionResolved[]): void;
|
|
14
|
-
declare function getVikeConfig(userRootDir: string, isDev: boolean, extensions: ExtensionResolved[], tolerateInvalidConfig?: boolean): Promise<VikeConfig>;
|
|
13
|
+
declare function reloadVikeConfig(userRootDir: string, outDirRoot: string, extensions: ExtensionResolved[]): void;
|
|
14
|
+
declare function getVikeConfig(userRootDir: string, outDirRoot: string, isDev: boolean, extensions: ExtensionResolved[], tolerateInvalidConfig?: boolean): Promise<VikeConfig>;
|
|
15
15
|
declare function isVikeConfigFile(filePath: string): boolean;
|
|
@@ -24,10 +24,10 @@ let wasConfigInvalid = null;
|
|
|
24
24
|
let vikeConfigPromise = null;
|
|
25
25
|
const vikeConfigDependencies = new Set();
|
|
26
26
|
const filesEnv = new Map();
|
|
27
|
-
function reloadVikeConfig(userRootDir, extensions) {
|
|
27
|
+
function reloadVikeConfig(userRootDir, outDirRoot, extensions) {
|
|
28
28
|
vikeConfigDependencies.clear();
|
|
29
29
|
filesEnv.clear();
|
|
30
|
-
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, true, extensions, true);
|
|
30
|
+
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, true, extensions, true);
|
|
31
31
|
handleReloadSideEffects();
|
|
32
32
|
}
|
|
33
33
|
async function handleReloadSideEffects() {
|
|
@@ -61,14 +61,14 @@ async function handleReloadSideEffects() {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
async function getVikeConfig(userRootDir, isDev, extensions, tolerateInvalidConfig = false) {
|
|
64
|
+
async function getVikeConfig(userRootDir, outDirRoot, isDev, extensions, tolerateInvalidConfig = false) {
|
|
65
65
|
if (!vikeConfigPromise) {
|
|
66
|
-
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, isDev, extensions, tolerateInvalidConfig);
|
|
66
|
+
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, extensions, tolerateInvalidConfig);
|
|
67
67
|
}
|
|
68
68
|
return await vikeConfigPromise;
|
|
69
69
|
}
|
|
70
|
-
async function loadInterfaceFiles(userRootDir, isDev, extensions) {
|
|
71
|
-
const plusFiles = await findPlusFiles(userRootDir, isDev, extensions);
|
|
70
|
+
async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
71
|
+
const plusFiles = await findPlusFiles(userRootDir, [outDirRoot], isDev, extensions);
|
|
72
72
|
const configFiles = [];
|
|
73
73
|
const valueFiles = [];
|
|
74
74
|
plusFiles.forEach((f) => {
|
|
@@ -166,12 +166,12 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
166
166
|
});
|
|
167
167
|
return interfaceFile;
|
|
168
168
|
}
|
|
169
|
-
async function loadVikeConfig_withErrorHandling(userRootDir, isDev, extensions, tolerateInvalidConfig) {
|
|
169
|
+
async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, extensions, tolerateInvalidConfig) {
|
|
170
170
|
let hasError = false;
|
|
171
171
|
let ret;
|
|
172
172
|
let err;
|
|
173
173
|
try {
|
|
174
|
-
ret = await loadVikeConfig(userRootDir, isDev, extensions);
|
|
174
|
+
ret = await loadVikeConfig(userRootDir, outDirRoot, isDev, extensions);
|
|
175
175
|
}
|
|
176
176
|
catch (err_) {
|
|
177
177
|
hasError = true;
|
|
@@ -207,8 +207,8 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, extensions,
|
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
-
async function loadVikeConfig(userRootDir, isDev, extensions) {
|
|
211
|
-
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, isDev, extensions);
|
|
210
|
+
async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
211
|
+
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions);
|
|
212
212
|
const { globalVikeConfig, pageConfigGlobal } = getGlobalConfigs(interfaceFilesByLocationId, userRootDir);
|
|
213
213
|
const pageConfigs = await Promise.all(Object.entries(interfaceFilesByLocationId)
|
|
214
214
|
.filter(([_pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
@@ -242,17 +242,17 @@ async function loadVikeConfig(userRootDir, isDev, extensions) {
|
|
|
242
242
|
configValueSources[configName] = sources;
|
|
243
243
|
});
|
|
244
244
|
const { routeFilesystem, isErrorPage } = determineRouteFilesystem(locationId, configValueSources);
|
|
245
|
+
applyEffectsAll(configValueSources, configDefinitionsRelevant);
|
|
246
|
+
const configValuesComputed = getComputed(configValueSources, configDefinitionsRelevant);
|
|
247
|
+
const configValues = getConfigValues(configValueSources, configValuesComputed, configDefinitionsRelevant);
|
|
245
248
|
const pageConfig = {
|
|
246
249
|
pageId: locationId,
|
|
247
250
|
isErrorPage,
|
|
248
251
|
routeFilesystem,
|
|
249
252
|
configValueSources,
|
|
250
|
-
|
|
253
|
+
configValuesComputed,
|
|
254
|
+
configValues
|
|
251
255
|
};
|
|
252
|
-
applyEffects(pageConfig, configDefinitionsRelevant);
|
|
253
|
-
pageConfig.configValues = getConfigValues(configValueSources, configDefinitionsRelevant);
|
|
254
|
-
applyComputed(pageConfig, configDefinitionsRelevant);
|
|
255
|
-
pageConfig.configValues = getConfigValues(configValueSources, configDefinitionsRelevant);
|
|
256
256
|
return pageConfig;
|
|
257
257
|
}));
|
|
258
258
|
// Show error message upon unknown config
|
|
@@ -339,10 +339,9 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
|
339
339
|
assert('value' in configValueSource);
|
|
340
340
|
if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
|
|
341
341
|
return;
|
|
342
|
-
|
|
343
|
-
const sourceFilePath = getFilePathToShowToUser2(configValueSource.definedAtInfo);
|
|
342
|
+
const sourceFilePath = getDefinedAtFilePathToShowToUser(configValueSource.definedAtInfo);
|
|
344
343
|
assert(sourceFilePath);
|
|
345
|
-
assertWarning(false, `Being able to define config ${pc.cyan(configName)} in ${sourceFilePath} is experimental and will likely be removed. Define the config ${pc.cyan(configName)} in
|
|
344
|
+
assertWarning(false, `Being able to define config ${pc.cyan(configName)} in ${sourceFilePath} is experimental and will likely be removed. Define the config ${pc.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
|
|
346
345
|
globalVikeConfig[configName] = configValueSource.value;
|
|
347
346
|
}
|
|
348
347
|
});
|
|
@@ -367,7 +366,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
367
366
|
{
|
|
368
367
|
const interfaceValueFiles = interfaceFilesDefiningConfig
|
|
369
368
|
.filter((interfaceFile) => interfaceFile.isValueFile &&
|
|
370
|
-
// We consider side-effect
|
|
369
|
+
// We consider side-effect configs (e.g. `export { frontmatter }` of .mdx files) later (i.e. with less priority)
|
|
371
370
|
interfaceFile.configName === configName)
|
|
372
371
|
.sort(makeOrderDeterministic);
|
|
373
372
|
const interfaceConfigFiles = interfaceFilesDefiningConfig
|
|
@@ -394,7 +393,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
394
393
|
// Side-effect configs such as `export { frontmatter }` in .mdx files
|
|
395
394
|
interfaceFilesDefiningConfig
|
|
396
395
|
.filter((interfaceFile) => interfaceFile.isValueFile &&
|
|
397
|
-
// Is side-effect
|
|
396
|
+
// Is side-effect config
|
|
398
397
|
interfaceFile.configName !== configName)
|
|
399
398
|
.forEach((interfaceValueFileSideEffect) => {
|
|
400
399
|
add(interfaceValueFileSideEffect);
|
|
@@ -425,8 +424,6 @@ function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden,
|
|
|
425
424
|
interfaceFilesOverriden.forEach((interfaceFileLoser) => {
|
|
426
425
|
const configValueSourceWinner = getConfigValueSource(configName, interfaceFileWinner, configDef, userRootDir);
|
|
427
426
|
const configValueSourceLoser = getConfigValueSource(configName, interfaceFileLoser, configDef, userRootDir);
|
|
428
|
-
assert(!configValueSourceLoser.isComputed);
|
|
429
|
-
assert(!configValueSourceWinner.isComputed);
|
|
430
427
|
assertWarning(false, `${getConfigSourceDefinedAtString(configName, configValueSourceLoser, undefined, true)} overriden by another ${getConfigSourceDefinedAtString(configName, configValueSourceWinner, undefined, false)}, remove one of the two`, { onlyOnce: false });
|
|
431
428
|
});
|
|
432
429
|
}
|
|
@@ -465,7 +462,6 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
465
462
|
valueIsFilePath: true,
|
|
466
463
|
configEnv,
|
|
467
464
|
valueIsImportedAtRuntime: true,
|
|
468
|
-
isComputed: false,
|
|
469
465
|
definedAtInfo
|
|
470
466
|
};
|
|
471
467
|
return configValueSource;
|
|
@@ -478,7 +474,6 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
478
474
|
const configValueSource = {
|
|
479
475
|
configEnv,
|
|
480
476
|
valueIsImportedAtRuntime: true,
|
|
481
|
-
isComputed: false,
|
|
482
477
|
definedAtInfo: import_
|
|
483
478
|
};
|
|
484
479
|
return configValueSource;
|
|
@@ -488,22 +483,22 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
488
483
|
value: configValue,
|
|
489
484
|
configEnv,
|
|
490
485
|
valueIsImportedAtRuntime: false,
|
|
491
|
-
isComputed: false,
|
|
492
486
|
definedAtInfo: definedAtConfigFile
|
|
493
487
|
};
|
|
494
488
|
return configValueSource;
|
|
495
489
|
}
|
|
496
490
|
}
|
|
497
491
|
else if (interfaceFile.isValueFile) {
|
|
498
|
-
// TODO: rethink file paths of ConfigElement
|
|
499
492
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
500
493
|
const configValueSource = {
|
|
501
494
|
configEnv,
|
|
502
495
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
503
|
-
isComputed: false,
|
|
504
496
|
definedAtInfo: {
|
|
505
497
|
...interfaceFile.filePath,
|
|
506
|
-
fileExportPath: configName === interfaceFile.configName
|
|
498
|
+
fileExportPath: configName === interfaceFile.configName
|
|
499
|
+
? []
|
|
500
|
+
: // Side-effect config (e.g. `export { frontmatter }` of .md files)
|
|
501
|
+
[configName]
|
|
507
502
|
}
|
|
508
503
|
};
|
|
509
504
|
if (valueAlreadyLoaded) {
|
|
@@ -663,20 +658,21 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
663
658
|
}
|
|
664
659
|
});
|
|
665
660
|
}
|
|
666
|
-
function
|
|
661
|
+
function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
|
|
667
662
|
objectEntries(configDefinitionsRelevant).forEach(([configName, configDef]) => {
|
|
668
663
|
if (!configDef.effect)
|
|
669
664
|
return;
|
|
670
665
|
// The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
|
|
671
666
|
// (We could support effect for non config-only by always loading its value at config time, regardless of the config's `env` value.)
|
|
672
|
-
|
|
673
|
-
`
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
const source = pageConfig.configValueSources[configName]?.[0];
|
|
667
|
+
assertUsage(configDef.env === 'config-only', [
|
|
668
|
+
`Cannot add effect to ${pc.cyan(configName)} because its ${pc.cyan('env')} is ${pc.cyan(configDef.env)}: effects can only be added to configs with an env that is ${pc.cyan('config-only')}.`
|
|
669
|
+
].join(' '));
|
|
670
|
+
const source = configValueSources[configName]?.[0];
|
|
677
671
|
if (!source)
|
|
678
672
|
return;
|
|
679
|
-
|
|
673
|
+
// The config value is eagerly loaded since `configDef.env === 'config-only``
|
|
674
|
+
assert('value' in source);
|
|
675
|
+
// Call effect
|
|
680
676
|
const configModFromEffect = configDef.effect({
|
|
681
677
|
configValue: source.value,
|
|
682
678
|
configDefinedAt: getConfigSourceDefinedAtString(configName, source)
|
|
@@ -684,14 +680,13 @@ function applyEffects(pageConfig, configDefinitionsRelevant) {
|
|
|
684
680
|
if (!configModFromEffect)
|
|
685
681
|
return;
|
|
686
682
|
assert(hasProp(source, 'value')); // We need to assume that the config value is loaded at build-time
|
|
687
|
-
applyEffect(configModFromEffect, source,
|
|
683
|
+
applyEffect(configModFromEffect, source, configValueSources);
|
|
688
684
|
});
|
|
689
685
|
}
|
|
690
686
|
function applyEffect(configModFromEffect, configValueEffectSource, configValueSources) {
|
|
691
|
-
const notSupported = `
|
|
687
|
+
const notSupported = `Effects currently only supports modifying the the ${pc.cyan('env')} of a config.`;
|
|
692
688
|
objectEntries(configModFromEffect).forEach(([configName, configValue]) => {
|
|
693
689
|
if (configName === 'meta') {
|
|
694
|
-
assert(!configValueEffectSource.isComputed);
|
|
695
690
|
assertMetaValue(configValue, getConfigSourceDefinedAtString(configName, configValueEffectSource, true));
|
|
696
691
|
objectEntries(configValue).forEach(([configTargetName, configTargetDef]) => {
|
|
697
692
|
{
|
|
@@ -702,6 +697,7 @@ function applyEffect(configModFromEffect, configValueEffectSource, configValueSo
|
|
|
702
697
|
const envOverriden = configTargetDef.env;
|
|
703
698
|
const sources = configValueSources[configTargetName];
|
|
704
699
|
sources?.forEach((configValueSource) => {
|
|
700
|
+
// Apply effect
|
|
705
701
|
configValueSource.configEnv = envOverriden;
|
|
706
702
|
});
|
|
707
703
|
});
|
|
@@ -713,29 +709,29 @@ function applyEffect(configModFromEffect, configValueEffectSource, configValueSo
|
|
|
713
709
|
}
|
|
714
710
|
});
|
|
715
711
|
}
|
|
716
|
-
function
|
|
712
|
+
function getComputed(configValueSources, configDefinitionsRelevant) {
|
|
713
|
+
const configValuesComputed = {};
|
|
717
714
|
objectEntries(configDefinitionsRelevant).forEach(([configName, configDef]) => {
|
|
718
|
-
var _a;
|
|
719
715
|
if (!configDef._computed)
|
|
720
716
|
return;
|
|
721
|
-
const value = configDef._computed(
|
|
717
|
+
const value = configDef._computed(configValueSources);
|
|
722
718
|
if (value === undefined)
|
|
723
719
|
return;
|
|
724
|
-
|
|
720
|
+
configValuesComputed[configName] = {
|
|
725
721
|
value,
|
|
726
|
-
configEnv: configDef.env
|
|
727
|
-
definedAtInfo: null,
|
|
728
|
-
isComputed: true,
|
|
729
|
-
valueIsImportedAtRuntime: false
|
|
722
|
+
configEnv: configDef.env
|
|
730
723
|
};
|
|
731
|
-
(_a = pageConfig.configValueSources)[configName] ?? (_a[configName] = []);
|
|
732
|
-
// Computed values are inserted last: they have the least priority (i.e. computed can be overriden)
|
|
733
|
-
pageConfig.configValueSources[configName].push(configValueSource);
|
|
734
724
|
});
|
|
725
|
+
return configValuesComputed;
|
|
735
726
|
}
|
|
736
|
-
async function findPlusFiles(userRootDir, isDev, extensions) {
|
|
727
|
+
async function findPlusFiles(userRootDir, ignoreDirs, isDev, extensions) {
|
|
737
728
|
const timeBase = new Date().getTime();
|
|
738
729
|
assertPosixPath(userRootDir);
|
|
730
|
+
const ignorePatterns = [];
|
|
731
|
+
for (const dir of ignoreDirs) {
|
|
732
|
+
assertPosixPath(dir);
|
|
733
|
+
ignorePatterns.push(`${path.posix.relative(userRootDir, dir)}/**`);
|
|
734
|
+
}
|
|
739
735
|
const result = await glob(`**/+*.${scriptFileExtensions}`, {
|
|
740
736
|
ignore: [
|
|
741
737
|
'**/node_modules/**',
|
|
@@ -744,7 +740,8 @@ async function findPlusFiles(userRootDir, isDev, extensions) {
|
|
|
744
740
|
// +Page.js
|
|
745
741
|
// +Page.telefunc.js
|
|
746
742
|
// ```
|
|
747
|
-
'**/*.telefunc.*'
|
|
743
|
+
'**/*.telefunc.*',
|
|
744
|
+
...ignorePatterns
|
|
748
745
|
],
|
|
749
746
|
cwd: userRootDir,
|
|
750
747
|
dot: false
|
|
@@ -752,7 +749,7 @@ async function findPlusFiles(userRootDir, isDev, extensions) {
|
|
|
752
749
|
const time = new Date().getTime() - timeBase;
|
|
753
750
|
if (isDev) {
|
|
754
751
|
// We only warn in dev, because while building it's expected to take a long time as fast-glob is competing for resources with other tasks
|
|
755
|
-
assertWarning(time < 2 * 1000, `Crawling your user files took an unexpected long time (${time}ms). Create a new issue on
|
|
752
|
+
assertWarning(time < 2 * 1000, `Crawling your user files took an unexpected long time (${time}ms). Create a new issue on Vike's GitHub.`, {
|
|
756
753
|
onlyOnce: 'slow-page-files-search'
|
|
757
754
|
});
|
|
758
755
|
}
|
|
@@ -1004,13 +1001,12 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
|
|
|
1004
1001
|
// Eagerly loaded since it's config-only
|
|
1005
1002
|
assert('value' in configFilesystemRoutingRoot);
|
|
1006
1003
|
const { value } = configFilesystemRoutingRoot;
|
|
1007
|
-
assert(!configFilesystemRoutingRoot.isComputed);
|
|
1008
1004
|
const configDefinedAt = getConfigSourceDefinedAtString(configName, configFilesystemRoutingRoot);
|
|
1009
1005
|
assertUsage(typeof value === 'string', `${configDefinedAt} should be a string`);
|
|
1010
1006
|
assertUsage(value.startsWith('/'), `${configDefinedAt} is ${pc.cyan(value)} but it should start with a leading slash ${pc.cyan('/')}`);
|
|
1011
|
-
|
|
1012
|
-
assert(
|
|
1013
|
-
const before = getFilesystemRouteString(getLocationId(
|
|
1007
|
+
const { filePathRelativeToUserRootDir } = configFilesystemRoutingRoot.definedAtInfo;
|
|
1008
|
+
assert(filePathRelativeToUserRootDir);
|
|
1009
|
+
const before = getFilesystemRouteString(getLocationId(filePathRelativeToUserRootDir));
|
|
1014
1010
|
const after = value;
|
|
1015
1011
|
const filesystemRoutingRootEffect = { before, after };
|
|
1016
1012
|
return { filesystemRoutingRootEffect, filesystemRoutingRootDefinedAt: configDefinedAt };
|
|
@@ -1047,19 +1043,23 @@ function assertImportPath(filePathAbsolute, importData, importerFilePath) {
|
|
|
1047
1043
|
function isVikeConfigFile(filePath) {
|
|
1048
1044
|
return !!getConfigName(filePath);
|
|
1049
1045
|
}
|
|
1050
|
-
function getConfigValues(configValueSources, configDefinitionsRelevant) {
|
|
1046
|
+
function getConfigValues(configValueSources, configValuesComputed, configDefinitionsRelevant) {
|
|
1051
1047
|
const configValues = {};
|
|
1048
|
+
Object.entries(configValuesComputed).forEach(([configName, configValueComputed]) => {
|
|
1049
|
+
configValues[configName] = {
|
|
1050
|
+
value: configValueComputed.value,
|
|
1051
|
+
definedAt: { isComputed: true }
|
|
1052
|
+
};
|
|
1053
|
+
});
|
|
1052
1054
|
Object.entries(configValueSources).forEach(([configName, sources]) => {
|
|
1053
1055
|
const configDef = configDefinitionsRelevant[configName];
|
|
1054
1056
|
assert(configDef);
|
|
1055
1057
|
if (!configDef.cumulative) {
|
|
1056
1058
|
const configValueSource = sources[0];
|
|
1057
1059
|
if ('value' in configValueSource) {
|
|
1058
|
-
const { value } = configValueSource;
|
|
1059
|
-
const definedAt = configValueSource.isComputed ? { isComputed: true } : getDefinedAt(configValueSource);
|
|
1060
1060
|
configValues[configName] = {
|
|
1061
|
-
value,
|
|
1062
|
-
definedAt
|
|
1061
|
+
value: configValueSource.value,
|
|
1062
|
+
definedAt: getDefinedAt(configValueSource)
|
|
1063
1063
|
};
|
|
1064
1064
|
}
|
|
1065
1065
|
}
|
|
@@ -1069,7 +1069,7 @@ function getConfigValues(configValueSources, configDefinitionsRelevant) {
|
|
|
1069
1069
|
value,
|
|
1070
1070
|
definedAt: {
|
|
1071
1071
|
isCumulative: true,
|
|
1072
|
-
|
|
1072
|
+
files: sources.map((source) => getDefinedAtFile(source))
|
|
1073
1073
|
}
|
|
1074
1074
|
};
|
|
1075
1075
|
}
|
|
@@ -1081,7 +1081,6 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1081
1081
|
const valuesSet = [];
|
|
1082
1082
|
let configValueSourcePrevious = null;
|
|
1083
1083
|
configValueSources.forEach((configValueSource) => {
|
|
1084
|
-
assert(!configValueSource.isComputed);
|
|
1085
1084
|
const configDefinedAt = getConfigSourceDefinedAtString(configName, configValueSource);
|
|
1086
1085
|
const configNameColored = pc.cyan(configName);
|
|
1087
1086
|
// We could, in principle, also support cumulative values to be defined in +${configName}.js but it ins't completely trivial to implement
|
|
@@ -1100,8 +1099,7 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1100
1099
|
if (vals2.length === 0)
|
|
1101
1100
|
return;
|
|
1102
1101
|
assert(configValueSourcePrevious);
|
|
1103
|
-
|
|
1104
|
-
const configPreviousDefinedAt = getConfigSourceDefinedAtString(configName, configValueSourcePrevious, undefined, true);
|
|
1102
|
+
const configPreviousDefinedAt = getConfigSourceDefinedAtString(configName, configValueSourcePrevious, undefined, false);
|
|
1105
1103
|
assertUsage(false, `${configDefinedAt} sets ${t1} but another ${configPreviousDefinedAt} sets ${t2} which is forbidden: the values must be all arrays or all sets (you cannot mix).`);
|
|
1106
1104
|
};
|
|
1107
1105
|
const { value } = configValueSource;
|
|
@@ -1138,40 +1136,24 @@ function getConfigSourceDefinedAtString(configName, { definedAtInfo }, isEffect
|
|
|
1138
1136
|
return getConfigDefinedAtString(configName, {
|
|
1139
1137
|
definedAt: {
|
|
1140
1138
|
isEffect,
|
|
1141
|
-
|
|
1142
|
-
filePathToShowToUser:
|
|
1139
|
+
file: {
|
|
1140
|
+
filePathToShowToUser: getDefinedAtFilePathToShowToUser(definedAtInfo),
|
|
1143
1141
|
fileExportPath: definedAtInfo.fileExportPath
|
|
1144
1142
|
}
|
|
1145
1143
|
}
|
|
1146
1144
|
}, sentenceBegin);
|
|
1147
1145
|
}
|
|
1148
|
-
|
|
1149
|
-
function getFilePathToShowToUser2(definedAtInfo) {
|
|
1146
|
+
function getDefinedAtFilePathToShowToUser(definedAtInfo) {
|
|
1150
1147
|
return definedAtInfo.filePathRelativeToUserRootDir ?? definedAtInfo.importPathAbsolute;
|
|
1151
|
-
/*
|
|
1152
|
-
if (definedAtInfo.filePathRelativeToUserRootDir !== null) {
|
|
1153
|
-
return definedAtInfo.filePathRelativeToUserRootDir
|
|
1154
|
-
}
|
|
1155
|
-
if (definedAtInfo.importPathAbsolute !== null) {
|
|
1156
|
-
return definedAtInfo.importPathAbsolute
|
|
1157
|
-
} else {
|
|
1158
|
-
const filePathToShowToUser = definedAtInfo.filePathAbsolute
|
|
1159
|
-
// TypeScript failes to infer that definedAtInfo.filePathAbsolute cannot be null
|
|
1160
|
-
assert(filePathToShowToUser)
|
|
1161
|
-
return filePathToShowToUser
|
|
1162
|
-
}
|
|
1163
|
-
*/
|
|
1164
1148
|
}
|
|
1165
|
-
|
|
1166
|
-
function getSourceDefinedAt(source) {
|
|
1167
|
-
assert(!source.isComputed);
|
|
1149
|
+
function getDefinedAtFile(source) {
|
|
1168
1150
|
return {
|
|
1169
|
-
filePathToShowToUser:
|
|
1151
|
+
filePathToShowToUser: getDefinedAtFilePathToShowToUser(source.definedAtInfo),
|
|
1170
1152
|
fileExportPath: source.definedAtInfo.fileExportPath
|
|
1171
1153
|
};
|
|
1172
1154
|
}
|
|
1173
1155
|
function getDefinedAt(configValueSource) {
|
|
1174
1156
|
return {
|
|
1175
|
-
|
|
1157
|
+
file: getDefinedAtFile(configValueSource)
|
|
1176
1158
|
};
|
|
1177
1159
|
}
|