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
|
@@ -73,7 +73,7 @@ exports.buildConfig = buildConfig;
|
|
|
73
73
|
async function getEntries(config) {
|
|
74
74
|
const configVike = await (0, getConfigVike_js_1.getConfigVike)(config);
|
|
75
75
|
const pageFileEntries = await getPageFileEntries(config, configVike.includeAssetsImportedByServer); // TODO/v1-release: remove
|
|
76
|
-
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(config.root, false, configVike.extensions);
|
|
76
|
+
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(config.root, (0, utils_js_1.getOutDirs)(config).outDirRoot, false, configVike.extensions);
|
|
77
77
|
(0, utils_js_1.assertUsage)(Object.keys(pageFileEntries).length !== 0 || pageConfigs.length !== 0, 'At least one page should be defined, see https://vike.dev/add');
|
|
78
78
|
if ((0, utils_js_1.viteIsSSR)(config)) {
|
|
79
79
|
const serverEntries = analyzeServerEntries(pageConfigs);
|
|
@@ -30,7 +30,7 @@ async function resolveConfig(vikeConfig, config) {
|
|
|
30
30
|
const fromStemPackages = await (0, findConfigVikeFromStemPackages_js_1.findConfigVikeFromStemPackages)(config.root);
|
|
31
31
|
const configs = [fromPluginOptions, ...fromStemPackages, fromViteConfig];
|
|
32
32
|
const extensions = (0, resolveExtensions_js_1.resolveExtensions)(configs, config);
|
|
33
|
-
const { globalVikeConfig: fromPlusConfigFile } = await (0, getVikeConfig_js_1.getVikeConfig)(config.root, (0, utils_js_1.isDev2)(config), extensions);
|
|
33
|
+
const { globalVikeConfig: fromPlusConfigFile } = await (0, getVikeConfig_js_1.getVikeConfig)(config.root, (0, utils_js_1.getOutDirs)(config).outDirRoot, (0, utils_js_1.isDev2)(config), extensions);
|
|
34
34
|
configs.push(fromPlusConfigFile);
|
|
35
35
|
(0, assertVikeConfig_js_1.assertVikeConfig)(fromPlusConfigFile, ({ prop, errMsg }) => {
|
|
36
36
|
// TODO: add config file path ?
|
|
@@ -8,7 +8,7 @@ const getConfigValueSourcesRelevant_js_1 = require("../../shared/getConfigValueS
|
|
|
8
8
|
const buildConfig_js_1 = require("../buildConfig.js");
|
|
9
9
|
const virtualFileImportUserCode_js_1 = require("../../../shared/virtual-files/virtualFileImportUserCode.js");
|
|
10
10
|
async function determineOptimizeDeps(config, configVike, isDev) {
|
|
11
|
-
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(config.root, isDev, configVike.extensions);
|
|
11
|
+
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(config.root, (0, utils_js_1.getOutDirs)(config).outDirRoot, isDev, configVike.extensions);
|
|
12
12
|
const { entries, include } = await getPageDeps(config, pageConfigs, isDev);
|
|
13
13
|
{
|
|
14
14
|
// This actually doesn't work: Vite's dep optimizer doesn't seem to be able to crawl virtual files.
|
|
@@ -24,7 +24,7 @@ async function determineOptimizeDeps(config, configVike, isDev) {
|
|
|
24
24
|
*/
|
|
25
25
|
config.optimizeDeps.include = [...include, ...normalizeInclude(config.optimizeDeps.include)];
|
|
26
26
|
config.optimizeDeps.entries = [...entries, ...normalizeEntries(config.optimizeDeps.entries)];
|
|
27
|
-
console.log('config.optimizeDeps', config.optimizeDeps)
|
|
27
|
+
// console.log('config.optimizeDeps', { entries: config.optimizeDeps.entries, include: config.optimizeDeps.include })
|
|
28
28
|
}
|
|
29
29
|
exports.determineOptimizeDeps = determineOptimizeDeps;
|
|
30
30
|
async function getPageDeps(config, pageConfigs, isDev) {
|
|
@@ -37,15 +37,13 @@ async function getPageDeps(config, pageConfigs, isDev) {
|
|
|
37
37
|
configValueSourcesRelevant.forEach((configValueSource) => {
|
|
38
38
|
if (!configValueSource.valueIsImportedAtRuntime)
|
|
39
39
|
return;
|
|
40
|
-
if (configValueSource.isComputed)
|
|
41
|
-
return;
|
|
42
40
|
const { definedAtInfo, configEnv } = configValueSource;
|
|
43
41
|
if (configEnv !== 'client-only' && configEnv !== 'server-and-client')
|
|
44
42
|
return;
|
|
45
43
|
if (definedAtInfo.filePathRelativeToUserRootDir !== null) {
|
|
46
44
|
const { filePathAbsolute } = definedAtInfo;
|
|
47
45
|
(0, utils_js_1.assert)(filePathAbsolute);
|
|
48
|
-
//
|
|
46
|
+
// Surprisingly Vite expects entries to be absolute paths
|
|
49
47
|
entries.push(filePathAbsolute);
|
|
50
48
|
}
|
|
51
49
|
else {
|
|
@@ -146,7 +146,7 @@ export const pageFilesList = [];
|
|
|
146
146
|
export const neverLoaded = {};
|
|
147
147
|
export const isGeneratedFile = true;
|
|
148
148
|
|
|
149
|
-
${await (0, getVirtualFilePageConfigs_js_1.getVirtualFilePageConfigs)(config.root, isForClientSide, isDev, id, configVike, isClientRouting)}
|
|
149
|
+
${await (0, getVirtualFilePageConfigs_js_1.getVirtualFilePageConfigs)(config.root, (0, utils_js_1.getOutDirs)(config).outDirRoot, isForClientSide, isDev, id, configVike, isClientRouting)}
|
|
150
150
|
|
|
151
151
|
`;
|
|
152
152
|
fileTypes_js_1.fileTypes
|
|
@@ -210,10 +210,12 @@ function getGlobs(globRoots, isBuild, fileType, query) {
|
|
|
210
210
|
...globRoots.map((globRoot, i) => {
|
|
211
211
|
const varNameLocal = `${varName}${i + 1}`;
|
|
212
212
|
varNameLocals.push(varNameLocal);
|
|
213
|
-
const
|
|
213
|
+
const globIncludePath = `'${getGlobPath(globRoot.includeDir, fileType)}'`;
|
|
214
|
+
const globExcludePath = globRoot.excludeDir ? `'!${getGlobPath(globRoot.excludeDir, fileType)}'` : null;
|
|
214
215
|
const globOptions = JSON.stringify({ eager: isEager, as: query });
|
|
215
216
|
(0, utils_js_1.assert)(globOptions.startsWith('{"eager":true') || globOptions.startsWith('{"eager":false'));
|
|
216
|
-
const
|
|
217
|
+
const globPaths = globExcludePath ? `[${globIncludePath}, ${globExcludePath}]` : `[${globIncludePath}]`;
|
|
218
|
+
const globLine = `const ${varNameLocal} = import.meta.glob(${globPaths}, ${globOptions});`;
|
|
217
219
|
return globLine;
|
|
218
220
|
}),
|
|
219
221
|
`const ${varName} = {${varNameLocals.map((varNameLocal) => `...${varNameLocal}`).join(',')}};`,
|
|
@@ -222,19 +224,26 @@ function getGlobs(globRoots, isBuild, fileType, query) {
|
|
|
222
224
|
].join('\n');
|
|
223
225
|
}
|
|
224
226
|
function getGlobRoots(config, configVike) {
|
|
225
|
-
const globRoots = [
|
|
227
|
+
const globRoots = [
|
|
228
|
+
{
|
|
229
|
+
includeDir: '/',
|
|
230
|
+
excludeDir: path_1.default.posix.relative(config.root, (0, utils_js_1.getOutDirs)(config).outDirRoot)
|
|
231
|
+
}
|
|
232
|
+
];
|
|
226
233
|
configVike.extensions
|
|
227
234
|
.map(({ pageConfigsSrcDir }) => pageConfigsSrcDir)
|
|
228
235
|
.filter(utils_js_1.isNotNullish)
|
|
229
236
|
.forEach((pageConfigsSrcDir) => {
|
|
230
|
-
const globRoot =
|
|
237
|
+
const globRoot = {
|
|
238
|
+
includeDir: path_1.default.posix.relative(config.root, pageConfigsSrcDir)
|
|
239
|
+
};
|
|
231
240
|
globRoots.push(globRoot);
|
|
232
241
|
});
|
|
233
242
|
return globRoots;
|
|
234
243
|
}
|
|
235
|
-
function getGlobPath(
|
|
236
|
-
(0, utils_js_1.assertPosixPath)(
|
|
237
|
-
let globPath = [...
|
|
244
|
+
function getGlobPath(globRootDir, fileType) {
|
|
245
|
+
(0, utils_js_1.assertPosixPath)(globRootDir);
|
|
246
|
+
let globPath = [...globRootDir.split('/'), '**', `*${fileType}.${utils_js_1.scriptFileExtensions}`].filter(Boolean).join('/');
|
|
238
247
|
if (!globPath.startsWith('/')) {
|
|
239
248
|
globPath = '/' + globPath;
|
|
240
249
|
}
|
|
@@ -52,7 +52,7 @@ function importUserCode() {
|
|
|
52
52
|
return undefined;
|
|
53
53
|
id = (0, utils_js_1.getVirtualFileId)(id);
|
|
54
54
|
if ((0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(id)) {
|
|
55
|
-
const code = await (0, getVirtualFilePageConfigValuesAll_js_1.getVirtualFilePageConfigValuesAll)(id, config.root, isDev, configVike);
|
|
55
|
+
const code = await (0, getVirtualFilePageConfigValuesAll_js_1.getVirtualFilePageConfigValuesAll)(id, config.root, (0, utils_js_1.getOutDirs)(config).outDirRoot, isDev, configVike);
|
|
56
56
|
return code;
|
|
57
57
|
}
|
|
58
58
|
if ((0, virtualFileImportUserCode_js_1.isVirtualFileIdImportUserCode)(id)) {
|
|
@@ -126,7 +126,7 @@ function reloadConfig(filePath, config, configVike, op) {
|
|
|
126
126
|
const msg = `${op} ${filePathToShowToUser}`;
|
|
127
127
|
(0, loggerNotProd_js_1.logConfigInfo)(msg, 'info');
|
|
128
128
|
}
|
|
129
|
-
(0, getVikeConfig_js_1.reloadVikeConfig)(config.root, configVike.extensions);
|
|
129
|
+
(0, getVikeConfig_js_1.reloadVikeConfig)(config.root, (0, utils_js_1.getOutDirs)(config).outDirRoot, configVike.extensions);
|
|
130
130
|
}
|
|
131
131
|
function getVirtualModules(server) {
|
|
132
132
|
const virtualModules = Array.from(server.moduleGraph.urlToModuleMap.keys())
|
|
@@ -68,13 +68,13 @@ const configDefinitionsBuiltIn = {
|
|
|
68
68
|
},
|
|
69
69
|
isClientSideRenderable: {
|
|
70
70
|
env: 'server-and-client',
|
|
71
|
-
_computed: (
|
|
72
|
-
(0, helpers_js_1.isConfigSet)(
|
|
73
|
-
(0, helpers_js_1.getConfigEnv)(
|
|
71
|
+
_computed: (configValueSources) => (0, helpers_js_1.isConfigSet)(configValueSources, 'onRenderClient') &&
|
|
72
|
+
(0, helpers_js_1.isConfigSet)(configValueSources, 'Page') &&
|
|
73
|
+
(0, helpers_js_1.getConfigEnv)(configValueSources, 'Page') !== 'server-only'
|
|
74
74
|
},
|
|
75
75
|
onBeforeRenderEnv: {
|
|
76
76
|
env: 'client-only',
|
|
77
|
-
_computed: (
|
|
77
|
+
_computed: (configValueSources) => !(0, helpers_js_1.isConfigSet)(configValueSources, 'onBeforeRender') ? null : (0, helpers_js_1.getConfigEnv)(configValueSources, 'onBeforeRender')
|
|
78
78
|
}
|
|
79
79
|
};
|
|
80
80
|
exports.configDefinitionsBuiltIn = configDefinitionsBuiltIn;
|
|
@@ -27,10 +27,10 @@ let vikeConfigPromise = null;
|
|
|
27
27
|
const vikeConfigDependencies = new Set();
|
|
28
28
|
exports.vikeConfigDependencies = vikeConfigDependencies;
|
|
29
29
|
const filesEnv = new Map();
|
|
30
|
-
function reloadVikeConfig(userRootDir, extensions) {
|
|
30
|
+
function reloadVikeConfig(userRootDir, outDirRoot, extensions) {
|
|
31
31
|
vikeConfigDependencies.clear();
|
|
32
32
|
filesEnv.clear();
|
|
33
|
-
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, true, extensions, true);
|
|
33
|
+
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, true, extensions, true);
|
|
34
34
|
handleReloadSideEffects();
|
|
35
35
|
}
|
|
36
36
|
exports.reloadVikeConfig = reloadVikeConfig;
|
|
@@ -65,15 +65,15 @@ async function handleReloadSideEffects() {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
async function getVikeConfig(userRootDir, isDev, extensions, tolerateInvalidConfig = false) {
|
|
68
|
+
async function getVikeConfig(userRootDir, outDirRoot, isDev, extensions, tolerateInvalidConfig = false) {
|
|
69
69
|
if (!vikeConfigPromise) {
|
|
70
|
-
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, isDev, extensions, tolerateInvalidConfig);
|
|
70
|
+
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, extensions, tolerateInvalidConfig);
|
|
71
71
|
}
|
|
72
72
|
return await vikeConfigPromise;
|
|
73
73
|
}
|
|
74
74
|
exports.getVikeConfig = getVikeConfig;
|
|
75
|
-
async function loadInterfaceFiles(userRootDir, isDev, extensions) {
|
|
76
|
-
const plusFiles = await findPlusFiles(userRootDir, isDev, extensions);
|
|
75
|
+
async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
76
|
+
const plusFiles = await findPlusFiles(userRootDir, [outDirRoot], isDev, extensions);
|
|
77
77
|
const configFiles = [];
|
|
78
78
|
const valueFiles = [];
|
|
79
79
|
plusFiles.forEach((f) => {
|
|
@@ -171,12 +171,12 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
171
171
|
});
|
|
172
172
|
return interfaceFile;
|
|
173
173
|
}
|
|
174
|
-
async function loadVikeConfig_withErrorHandling(userRootDir, isDev, extensions, tolerateInvalidConfig) {
|
|
174
|
+
async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, extensions, tolerateInvalidConfig) {
|
|
175
175
|
let hasError = false;
|
|
176
176
|
let ret;
|
|
177
177
|
let err;
|
|
178
178
|
try {
|
|
179
|
-
ret = await loadVikeConfig(userRootDir, isDev, extensions);
|
|
179
|
+
ret = await loadVikeConfig(userRootDir, outDirRoot, isDev, extensions);
|
|
180
180
|
}
|
|
181
181
|
catch (err_) {
|
|
182
182
|
hasError = true;
|
|
@@ -212,8 +212,8 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, extensions,
|
|
|
212
212
|
}
|
|
213
213
|
}
|
|
214
214
|
}
|
|
215
|
-
async function loadVikeConfig(userRootDir, isDev, extensions) {
|
|
216
|
-
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, isDev, extensions);
|
|
215
|
+
async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
216
|
+
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions);
|
|
217
217
|
const { globalVikeConfig, pageConfigGlobal } = getGlobalConfigs(interfaceFilesByLocationId, userRootDir);
|
|
218
218
|
const pageConfigs = await Promise.all(Object.entries(interfaceFilesByLocationId)
|
|
219
219
|
.filter(([_pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
@@ -247,17 +247,17 @@ async function loadVikeConfig(userRootDir, isDev, extensions) {
|
|
|
247
247
|
configValueSources[configName] = sources;
|
|
248
248
|
});
|
|
249
249
|
const { routeFilesystem, isErrorPage } = determineRouteFilesystem(locationId, configValueSources);
|
|
250
|
+
applyEffectsAll(configValueSources, configDefinitionsRelevant);
|
|
251
|
+
const configValuesComputed = getComputed(configValueSources, configDefinitionsRelevant);
|
|
252
|
+
const configValues = getConfigValues(configValueSources, configValuesComputed, configDefinitionsRelevant);
|
|
250
253
|
const pageConfig = {
|
|
251
254
|
pageId: locationId,
|
|
252
255
|
isErrorPage,
|
|
253
256
|
routeFilesystem,
|
|
254
257
|
configValueSources,
|
|
255
|
-
|
|
258
|
+
configValuesComputed,
|
|
259
|
+
configValues
|
|
256
260
|
};
|
|
257
|
-
applyEffects(pageConfig, configDefinitionsRelevant);
|
|
258
|
-
pageConfig.configValues = getConfigValues(configValueSources, configDefinitionsRelevant);
|
|
259
|
-
applyComputed(pageConfig, configDefinitionsRelevant);
|
|
260
|
-
pageConfig.configValues = getConfigValues(configValueSources, configDefinitionsRelevant);
|
|
261
261
|
return pageConfig;
|
|
262
262
|
}));
|
|
263
263
|
// Show error message upon unknown config
|
|
@@ -344,10 +344,9 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
|
344
344
|
(0, utils_js_1.assert)('value' in configValueSource);
|
|
345
345
|
if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
|
|
346
346
|
return;
|
|
347
|
-
|
|
348
|
-
const sourceFilePath = getFilePathToShowToUser2(configValueSource.definedAtInfo);
|
|
347
|
+
const sourceFilePath = getDefinedAtFilePathToShowToUser(configValueSource.definedAtInfo);
|
|
349
348
|
(0, utils_js_1.assert)(sourceFilePath);
|
|
350
|
-
(0, utils_js_1.assertWarning)(false, `Being able to define config ${picocolors_1.default.cyan(configName)} in ${sourceFilePath} is experimental and will likely be removed. Define the config ${picocolors_1.default.cyan(configName)} in
|
|
349
|
+
(0, utils_js_1.assertWarning)(false, `Being able to define config ${picocolors_1.default.cyan(configName)} in ${sourceFilePath} is experimental and will likely be removed. Define the config ${picocolors_1.default.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
|
|
351
350
|
globalVikeConfig[configName] = configValueSource.value;
|
|
352
351
|
}
|
|
353
352
|
});
|
|
@@ -372,7 +371,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
372
371
|
{
|
|
373
372
|
const interfaceValueFiles = interfaceFilesDefiningConfig
|
|
374
373
|
.filter((interfaceFile) => interfaceFile.isValueFile &&
|
|
375
|
-
// We consider side-effect
|
|
374
|
+
// We consider side-effect configs (e.g. `export { frontmatter }` of .mdx files) later (i.e. with less priority)
|
|
376
375
|
interfaceFile.configName === configName)
|
|
377
376
|
.sort(makeOrderDeterministic);
|
|
378
377
|
const interfaceConfigFiles = interfaceFilesDefiningConfig
|
|
@@ -399,7 +398,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
399
398
|
// Side-effect configs such as `export { frontmatter }` in .mdx files
|
|
400
399
|
interfaceFilesDefiningConfig
|
|
401
400
|
.filter((interfaceFile) => interfaceFile.isValueFile &&
|
|
402
|
-
// Is side-effect
|
|
401
|
+
// Is side-effect config
|
|
403
402
|
interfaceFile.configName !== configName)
|
|
404
403
|
.forEach((interfaceValueFileSideEffect) => {
|
|
405
404
|
add(interfaceValueFileSideEffect);
|
|
@@ -430,8 +429,6 @@ function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden,
|
|
|
430
429
|
interfaceFilesOverriden.forEach((interfaceFileLoser) => {
|
|
431
430
|
const configValueSourceWinner = getConfigValueSource(configName, interfaceFileWinner, configDef, userRootDir);
|
|
432
431
|
const configValueSourceLoser = getConfigValueSource(configName, interfaceFileLoser, configDef, userRootDir);
|
|
433
|
-
(0, utils_js_1.assert)(!configValueSourceLoser.isComputed);
|
|
434
|
-
(0, utils_js_1.assert)(!configValueSourceWinner.isComputed);
|
|
435
432
|
(0, utils_js_1.assertWarning)(false, `${getConfigSourceDefinedAtString(configName, configValueSourceLoser, undefined, true)} overriden by another ${getConfigSourceDefinedAtString(configName, configValueSourceWinner, undefined, false)}, remove one of the two`, { onlyOnce: false });
|
|
436
433
|
});
|
|
437
434
|
}
|
|
@@ -470,7 +467,6 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
470
467
|
valueIsFilePath: true,
|
|
471
468
|
configEnv,
|
|
472
469
|
valueIsImportedAtRuntime: true,
|
|
473
|
-
isComputed: false,
|
|
474
470
|
definedAtInfo
|
|
475
471
|
};
|
|
476
472
|
return configValueSource;
|
|
@@ -483,7 +479,6 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
483
479
|
const configValueSource = {
|
|
484
480
|
configEnv,
|
|
485
481
|
valueIsImportedAtRuntime: true,
|
|
486
|
-
isComputed: false,
|
|
487
482
|
definedAtInfo: import_
|
|
488
483
|
};
|
|
489
484
|
return configValueSource;
|
|
@@ -493,22 +488,22 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
493
488
|
value: configValue,
|
|
494
489
|
configEnv,
|
|
495
490
|
valueIsImportedAtRuntime: false,
|
|
496
|
-
isComputed: false,
|
|
497
491
|
definedAtInfo: definedAtConfigFile
|
|
498
492
|
};
|
|
499
493
|
return configValueSource;
|
|
500
494
|
}
|
|
501
495
|
}
|
|
502
496
|
else if (interfaceFile.isValueFile) {
|
|
503
|
-
// TODO: rethink file paths of ConfigElement
|
|
504
497
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
505
498
|
const configValueSource = {
|
|
506
499
|
configEnv,
|
|
507
500
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
508
|
-
isComputed: false,
|
|
509
501
|
definedAtInfo: {
|
|
510
502
|
...interfaceFile.filePath,
|
|
511
|
-
fileExportPath: configName === interfaceFile.configName
|
|
503
|
+
fileExportPath: configName === interfaceFile.configName
|
|
504
|
+
? []
|
|
505
|
+
: // Side-effect config (e.g. `export { frontmatter }` of .md files)
|
|
506
|
+
[configName]
|
|
512
507
|
}
|
|
513
508
|
};
|
|
514
509
|
if (valueAlreadyLoaded) {
|
|
@@ -668,20 +663,21 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
668
663
|
}
|
|
669
664
|
});
|
|
670
665
|
}
|
|
671
|
-
function
|
|
666
|
+
function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
|
|
672
667
|
(0, utils_js_1.objectEntries)(configDefinitionsRelevant).forEach(([configName, configDef]) => {
|
|
673
668
|
if (!configDef.effect)
|
|
674
669
|
return;
|
|
675
670
|
// The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
|
|
676
671
|
// (We could support effect for non config-only by always loading its value at config time, regardless of the config's `env` value.)
|
|
677
|
-
(0, utils_js_1.
|
|
678
|
-
`
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
const source = pageConfig.configValueSources[configName]?.[0];
|
|
672
|
+
(0, utils_js_1.assertUsage)(configDef.env === 'config-only', [
|
|
673
|
+
`Cannot add effect to ${picocolors_1.default.cyan(configName)} because its ${picocolors_1.default.cyan('env')} is ${picocolors_1.default.cyan(configDef.env)}: effects can only be added to configs with an env that is ${picocolors_1.default.cyan('config-only')}.`
|
|
674
|
+
].join(' '));
|
|
675
|
+
const source = configValueSources[configName]?.[0];
|
|
682
676
|
if (!source)
|
|
683
677
|
return;
|
|
684
|
-
|
|
678
|
+
// The config value is eagerly loaded since `configDef.env === 'config-only``
|
|
679
|
+
(0, utils_js_1.assert)('value' in source);
|
|
680
|
+
// Call effect
|
|
685
681
|
const configModFromEffect = configDef.effect({
|
|
686
682
|
configValue: source.value,
|
|
687
683
|
configDefinedAt: getConfigSourceDefinedAtString(configName, source)
|
|
@@ -689,14 +685,13 @@ function applyEffects(pageConfig, configDefinitionsRelevant) {
|
|
|
689
685
|
if (!configModFromEffect)
|
|
690
686
|
return;
|
|
691
687
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(source, 'value')); // We need to assume that the config value is loaded at build-time
|
|
692
|
-
applyEffect(configModFromEffect, source,
|
|
688
|
+
applyEffect(configModFromEffect, source, configValueSources);
|
|
693
689
|
});
|
|
694
690
|
}
|
|
695
691
|
function applyEffect(configModFromEffect, configValueEffectSource, configValueSources) {
|
|
696
|
-
const notSupported = `
|
|
692
|
+
const notSupported = `Effects currently only supports modifying the the ${picocolors_1.default.cyan('env')} of a config.`;
|
|
697
693
|
(0, utils_js_1.objectEntries)(configModFromEffect).forEach(([configName, configValue]) => {
|
|
698
694
|
if (configName === 'meta') {
|
|
699
|
-
(0, utils_js_1.assert)(!configValueEffectSource.isComputed);
|
|
700
695
|
assertMetaValue(configValue, getConfigSourceDefinedAtString(configName, configValueEffectSource, true));
|
|
701
696
|
(0, utils_js_1.objectEntries)(configValue).forEach(([configTargetName, configTargetDef]) => {
|
|
702
697
|
{
|
|
@@ -707,6 +702,7 @@ function applyEffect(configModFromEffect, configValueEffectSource, configValueSo
|
|
|
707
702
|
const envOverriden = configTargetDef.env;
|
|
708
703
|
const sources = configValueSources[configTargetName];
|
|
709
704
|
sources?.forEach((configValueSource) => {
|
|
705
|
+
// Apply effect
|
|
710
706
|
configValueSource.configEnv = envOverriden;
|
|
711
707
|
});
|
|
712
708
|
});
|
|
@@ -718,29 +714,29 @@ function applyEffect(configModFromEffect, configValueEffectSource, configValueSo
|
|
|
718
714
|
}
|
|
719
715
|
});
|
|
720
716
|
}
|
|
721
|
-
function
|
|
717
|
+
function getComputed(configValueSources, configDefinitionsRelevant) {
|
|
718
|
+
const configValuesComputed = {};
|
|
722
719
|
(0, utils_js_1.objectEntries)(configDefinitionsRelevant).forEach(([configName, configDef]) => {
|
|
723
|
-
var _a;
|
|
724
720
|
if (!configDef._computed)
|
|
725
721
|
return;
|
|
726
|
-
const value = configDef._computed(
|
|
722
|
+
const value = configDef._computed(configValueSources);
|
|
727
723
|
if (value === undefined)
|
|
728
724
|
return;
|
|
729
|
-
|
|
725
|
+
configValuesComputed[configName] = {
|
|
730
726
|
value,
|
|
731
|
-
configEnv: configDef.env
|
|
732
|
-
definedAtInfo: null,
|
|
733
|
-
isComputed: true,
|
|
734
|
-
valueIsImportedAtRuntime: false
|
|
727
|
+
configEnv: configDef.env
|
|
735
728
|
};
|
|
736
|
-
(_a = pageConfig.configValueSources)[configName] ?? (_a[configName] = []);
|
|
737
|
-
// Computed values are inserted last: they have the least priority (i.e. computed can be overriden)
|
|
738
|
-
pageConfig.configValueSources[configName].push(configValueSource);
|
|
739
729
|
});
|
|
730
|
+
return configValuesComputed;
|
|
740
731
|
}
|
|
741
|
-
async function findPlusFiles(userRootDir, isDev, extensions) {
|
|
732
|
+
async function findPlusFiles(userRootDir, ignoreDirs, isDev, extensions) {
|
|
742
733
|
const timeBase = new Date().getTime();
|
|
743
734
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
735
|
+
const ignorePatterns = [];
|
|
736
|
+
for (const dir of ignoreDirs) {
|
|
737
|
+
(0, utils_js_1.assertPosixPath)(dir);
|
|
738
|
+
ignorePatterns.push(`${path_1.default.posix.relative(userRootDir, dir)}/**`);
|
|
739
|
+
}
|
|
744
740
|
const result = await (0, fast_glob_1.default)(`**/+*.${utils_js_1.scriptFileExtensions}`, {
|
|
745
741
|
ignore: [
|
|
746
742
|
'**/node_modules/**',
|
|
@@ -749,7 +745,8 @@ async function findPlusFiles(userRootDir, isDev, extensions) {
|
|
|
749
745
|
// +Page.js
|
|
750
746
|
// +Page.telefunc.js
|
|
751
747
|
// ```
|
|
752
|
-
'**/*.telefunc.*'
|
|
748
|
+
'**/*.telefunc.*',
|
|
749
|
+
...ignorePatterns
|
|
753
750
|
],
|
|
754
751
|
cwd: userRootDir,
|
|
755
752
|
dot: false
|
|
@@ -757,7 +754,7 @@ async function findPlusFiles(userRootDir, isDev, extensions) {
|
|
|
757
754
|
const time = new Date().getTime() - timeBase;
|
|
758
755
|
if (isDev) {
|
|
759
756
|
// 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
|
|
760
|
-
(0, utils_js_1.assertWarning)(time < 2 * 1000, `Crawling your user files took an unexpected long time (${time}ms). Create a new issue on
|
|
757
|
+
(0, utils_js_1.assertWarning)(time < 2 * 1000, `Crawling your user files took an unexpected long time (${time}ms). Create a new issue on Vike's GitHub.`, {
|
|
761
758
|
onlyOnce: 'slow-page-files-search'
|
|
762
759
|
});
|
|
763
760
|
}
|
|
@@ -1009,13 +1006,12 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
|
|
|
1009
1006
|
// Eagerly loaded since it's config-only
|
|
1010
1007
|
(0, utils_js_1.assert)('value' in configFilesystemRoutingRoot);
|
|
1011
1008
|
const { value } = configFilesystemRoutingRoot;
|
|
1012
|
-
(0, utils_js_1.assert)(!configFilesystemRoutingRoot.isComputed);
|
|
1013
1009
|
const configDefinedAt = getConfigSourceDefinedAtString(configName, configFilesystemRoutingRoot);
|
|
1014
1010
|
(0, utils_js_1.assertUsage)(typeof value === 'string', `${configDefinedAt} should be a string`);
|
|
1015
1011
|
(0, utils_js_1.assertUsage)(value.startsWith('/'), `${configDefinedAt} is ${picocolors_1.default.cyan(value)} but it should start with a leading slash ${picocolors_1.default.cyan('/')}`);
|
|
1016
|
-
|
|
1017
|
-
(0, utils_js_1.assert)(
|
|
1018
|
-
const before = (0, filesystemRouting_js_1.getFilesystemRouteString)((0, filesystemRouting_js_1.getLocationId)(
|
|
1012
|
+
const { filePathRelativeToUserRootDir } = configFilesystemRoutingRoot.definedAtInfo;
|
|
1013
|
+
(0, utils_js_1.assert)(filePathRelativeToUserRootDir);
|
|
1014
|
+
const before = (0, filesystemRouting_js_1.getFilesystemRouteString)((0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir));
|
|
1019
1015
|
const after = value;
|
|
1020
1016
|
const filesystemRoutingRootEffect = { before, after };
|
|
1021
1017
|
return { filesystemRoutingRootEffect, filesystemRoutingRootDefinedAt: configDefinedAt };
|
|
@@ -1053,19 +1049,23 @@ function isVikeConfigFile(filePath) {
|
|
|
1053
1049
|
return !!getConfigName(filePath);
|
|
1054
1050
|
}
|
|
1055
1051
|
exports.isVikeConfigFile = isVikeConfigFile;
|
|
1056
|
-
function getConfigValues(configValueSources, configDefinitionsRelevant) {
|
|
1052
|
+
function getConfigValues(configValueSources, configValuesComputed, configDefinitionsRelevant) {
|
|
1057
1053
|
const configValues = {};
|
|
1054
|
+
Object.entries(configValuesComputed).forEach(([configName, configValueComputed]) => {
|
|
1055
|
+
configValues[configName] = {
|
|
1056
|
+
value: configValueComputed.value,
|
|
1057
|
+
definedAt: { isComputed: true }
|
|
1058
|
+
};
|
|
1059
|
+
});
|
|
1058
1060
|
Object.entries(configValueSources).forEach(([configName, sources]) => {
|
|
1059
1061
|
const configDef = configDefinitionsRelevant[configName];
|
|
1060
1062
|
(0, utils_js_1.assert)(configDef);
|
|
1061
1063
|
if (!configDef.cumulative) {
|
|
1062
1064
|
const configValueSource = sources[0];
|
|
1063
1065
|
if ('value' in configValueSource) {
|
|
1064
|
-
const { value } = configValueSource;
|
|
1065
|
-
const definedAt = configValueSource.isComputed ? { isComputed: true } : getDefinedAt(configValueSource);
|
|
1066
1066
|
configValues[configName] = {
|
|
1067
|
-
value,
|
|
1068
|
-
definedAt
|
|
1067
|
+
value: configValueSource.value,
|
|
1068
|
+
definedAt: getDefinedAt(configValueSource)
|
|
1069
1069
|
};
|
|
1070
1070
|
}
|
|
1071
1071
|
}
|
|
@@ -1075,7 +1075,7 @@ function getConfigValues(configValueSources, configDefinitionsRelevant) {
|
|
|
1075
1075
|
value,
|
|
1076
1076
|
definedAt: {
|
|
1077
1077
|
isCumulative: true,
|
|
1078
|
-
|
|
1078
|
+
files: sources.map((source) => getDefinedAtFile(source))
|
|
1079
1079
|
}
|
|
1080
1080
|
};
|
|
1081
1081
|
}
|
|
@@ -1087,7 +1087,6 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1087
1087
|
const valuesSet = [];
|
|
1088
1088
|
let configValueSourcePrevious = null;
|
|
1089
1089
|
configValueSources.forEach((configValueSource) => {
|
|
1090
|
-
(0, utils_js_1.assert)(!configValueSource.isComputed);
|
|
1091
1090
|
const configDefinedAt = getConfigSourceDefinedAtString(configName, configValueSource);
|
|
1092
1091
|
const configNameColored = picocolors_1.default.cyan(configName);
|
|
1093
1092
|
// We could, in principle, also support cumulative values to be defined in +${configName}.js but it ins't completely trivial to implement
|
|
@@ -1106,8 +1105,7 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1106
1105
|
if (vals2.length === 0)
|
|
1107
1106
|
return;
|
|
1108
1107
|
(0, utils_js_1.assert)(configValueSourcePrevious);
|
|
1109
|
-
(
|
|
1110
|
-
const configPreviousDefinedAt = getConfigSourceDefinedAtString(configName, configValueSourcePrevious, undefined, true);
|
|
1108
|
+
const configPreviousDefinedAt = getConfigSourceDefinedAtString(configName, configValueSourcePrevious, undefined, false);
|
|
1111
1109
|
(0, utils_js_1.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).`);
|
|
1112
1110
|
};
|
|
1113
1111
|
const { value } = configValueSource;
|
|
@@ -1144,40 +1142,24 @@ function getConfigSourceDefinedAtString(configName, { definedAtInfo }, isEffect
|
|
|
1144
1142
|
return (0, utils_js_2.getConfigDefinedAtString)(configName, {
|
|
1145
1143
|
definedAt: {
|
|
1146
1144
|
isEffect,
|
|
1147
|
-
|
|
1148
|
-
filePathToShowToUser:
|
|
1145
|
+
file: {
|
|
1146
|
+
filePathToShowToUser: getDefinedAtFilePathToShowToUser(definedAtInfo),
|
|
1149
1147
|
fileExportPath: definedAtInfo.fileExportPath
|
|
1150
1148
|
}
|
|
1151
1149
|
}
|
|
1152
1150
|
}, sentenceBegin);
|
|
1153
1151
|
}
|
|
1154
|
-
|
|
1155
|
-
function getFilePathToShowToUser2(definedAtInfo) {
|
|
1152
|
+
function getDefinedAtFilePathToShowToUser(definedAtInfo) {
|
|
1156
1153
|
return definedAtInfo.filePathRelativeToUserRootDir ?? definedAtInfo.importPathAbsolute;
|
|
1157
|
-
/*
|
|
1158
|
-
if (definedAtInfo.filePathRelativeToUserRootDir !== null) {
|
|
1159
|
-
return definedAtInfo.filePathRelativeToUserRootDir
|
|
1160
|
-
}
|
|
1161
|
-
if (definedAtInfo.importPathAbsolute !== null) {
|
|
1162
|
-
return definedAtInfo.importPathAbsolute
|
|
1163
|
-
} else {
|
|
1164
|
-
const filePathToShowToUser = definedAtInfo.filePathAbsolute
|
|
1165
|
-
// TypeScript failes to infer that definedAtInfo.filePathAbsolute cannot be null
|
|
1166
|
-
assert(filePathToShowToUser)
|
|
1167
|
-
return filePathToShowToUser
|
|
1168
|
-
}
|
|
1169
|
-
*/
|
|
1170
1154
|
}
|
|
1171
|
-
|
|
1172
|
-
function getSourceDefinedAt(source) {
|
|
1173
|
-
(0, utils_js_1.assert)(!source.isComputed);
|
|
1155
|
+
function getDefinedAtFile(source) {
|
|
1174
1156
|
return {
|
|
1175
|
-
filePathToShowToUser:
|
|
1157
|
+
filePathToShowToUser: getDefinedAtFilePathToShowToUser(source.definedAtInfo),
|
|
1176
1158
|
fileExportPath: source.definedAtInfo.fileExportPath
|
|
1177
1159
|
};
|
|
1178
1160
|
}
|
|
1179
1161
|
function getDefinedAt(configValueSource) {
|
|
1180
1162
|
return {
|
|
1181
|
-
|
|
1163
|
+
file: getDefinedAtFile(configValueSource)
|
|
1182
1164
|
};
|
|
1183
1165
|
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
3
|
+
exports.getVirtualFilePageConfigValuesAll = void 0;
|
|
7
4
|
const utils_js_1 = require("../../../utils.js");
|
|
8
|
-
const generateEagerImport_js_1 = require("../generateEagerImport.js");
|
|
9
5
|
const virtualFilePageConfigValuesAll_js_1 = require("../../../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
10
6
|
const getVikeConfig_js_1 = require("./getVikeConfig.js");
|
|
11
7
|
const extractAssetsQuery_js_1 = require("../../../../shared/extractAssetsQuery.js");
|
|
12
8
|
const debug_js_1 = require("./debug.js");
|
|
13
|
-
const path_1 = __importDefault(require("path"));
|
|
14
9
|
const utils_js_2 = require("../../../../../shared/page-configs/utils.js");
|
|
15
10
|
const getConfigValueSourcesRelevant_js_1 = require("../../../shared/getConfigValueSourcesRelevant.js");
|
|
16
|
-
const
|
|
17
|
-
|
|
11
|
+
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
12
|
+
const serializeConfigValue_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValue.js");
|
|
13
|
+
async function getVirtualFilePageConfigValuesAll(id, userRootDir, outDirRoot, isDev, configVike) {
|
|
18
14
|
const result = (0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(id);
|
|
19
15
|
(0, utils_js_1.assert)(result);
|
|
20
16
|
/* This assertion fails when using includeAssetsImportedByServer
|
|
@@ -24,7 +20,7 @@ async function getVirtualFilePageConfigValuesAll(id, userRootDir, isDev, configV
|
|
|
24
20
|
}
|
|
25
21
|
*/
|
|
26
22
|
const { pageId, isForClientSide } = result;
|
|
27
|
-
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(userRootDir, isDev, configVike.extensions, true);
|
|
23
|
+
const { pageConfigs } = await (0, getVikeConfig_js_1.getVikeConfig)(userRootDir, outDirRoot, isDev, configVike.extensions, true);
|
|
28
24
|
const pageConfig = pageConfigs.find((pageConfig) => pageConfig.pageId === pageId);
|
|
29
25
|
(0, utils_js_1.assert)(pageConfig);
|
|
30
26
|
const code = getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, configVike.includeAssetsImportedByServer, isDev);
|
|
@@ -45,10 +41,10 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
45
41
|
return;
|
|
46
42
|
if (configValueSource.valueIsFilePath)
|
|
47
43
|
return;
|
|
48
|
-
if (!(0,
|
|
44
|
+
if (!(0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: false }))
|
|
49
45
|
return;
|
|
50
46
|
const whitespace = ' ';
|
|
51
|
-
lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
47
|
+
lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
52
48
|
});
|
|
53
49
|
lines.push('];');
|
|
54
50
|
if (includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
@@ -57,34 +53,3 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
57
53
|
const code = [...importStatements, ...lines].join('\n');
|
|
58
54
|
return code;
|
|
59
55
|
}
|
|
60
|
-
function serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements) {
|
|
61
|
-
(0, utils_js_1.assert)(!configValueSource.valueIsFilePath);
|
|
62
|
-
(0, utils_js_1.assert)(whitespace.replaceAll(' ', '').length === 0);
|
|
63
|
-
const { valueIsImportedAtRuntime, definedAtInfo } = configValueSource;
|
|
64
|
-
(0, utils_js_1.assert)(valueIsImportedAtRuntime);
|
|
65
|
-
const { filePathRelativeToUserRootDir, importPathAbsolute, exportName } = definedAtInfo;
|
|
66
|
-
const importPath = filePathRelativeToUserRootDir ?? importPathAbsolute;
|
|
67
|
-
(0, utils_js_1.assertPosixPath)(importPath);
|
|
68
|
-
const fileName = path_1.default.posix.basename(importPath);
|
|
69
|
-
const isValueFile = fileName.startsWith('+');
|
|
70
|
-
if (isValueFile)
|
|
71
|
-
(0, utils_js_1.assert)(exportName === undefined);
|
|
72
|
-
const { importName, importStatement } = (0, generateEagerImport_js_1.generateEagerImport)(importPath, varCounterContainer.varCounter++, exportName);
|
|
73
|
-
importStatements.push(importStatement);
|
|
74
|
-
const lines = [];
|
|
75
|
-
lines.push(` {`);
|
|
76
|
-
lines.push(` configName: '${configName}',`);
|
|
77
|
-
lines.push(` importPath: '${importPath}',`);
|
|
78
|
-
lines.push(` isValueFile: ${JSON.stringify(isValueFile)},`);
|
|
79
|
-
if (isValueFile) {
|
|
80
|
-
lines.push(` importFileExports: ${importName},`);
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
lines.push(` importFileExportValue: ${importName},`);
|
|
84
|
-
(0, utils_js_1.assert)(exportName);
|
|
85
|
-
lines.push(` exportName: ${JSON.stringify(exportName)},`);
|
|
86
|
-
}
|
|
87
|
-
lines.push(` },`);
|
|
88
|
-
return lines;
|
|
89
|
-
}
|
|
90
|
-
exports.serializeConfigValueImported = serializeConfigValueImported;
|