vike 0.4.142 → 0.4.143-commit-f03b42d
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/index.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +4 -5
- package/dist/cjs/node/plugin/plugins/commonConfig.js +2 -7
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +2 -2
- package/dist/cjs/node/plugin/plugins/envVars.js +3 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +110 -114
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +37 -27
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +50 -80
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +12 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +19 -16
- package/dist/cjs/node/plugin/plugins/suppressRollupWarning.js +16 -3
- package/dist/cjs/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +1 -12
- package/dist/cjs/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +1 -1
- package/dist/cjs/node/plugin/shared/loggerNotProd.js +3 -3
- package/dist/cjs/node/plugin/utils.js +1 -2
- package/dist/cjs/node/prerender/runPrerender.js +13 -16
- package/dist/cjs/node/runtime/html/stream.js +4 -1
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
- package/dist/cjs/node/shared/virtual-files/virtualFilePageConfigValuesAll.js +1 -1
- package/dist/cjs/shared/error-page.js +1 -1
- package/dist/cjs/shared/getPageFiles/assertPageConfigs.js +13 -13
- package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +9 -43
- package/dist/cjs/shared/getPageFiles/parsePageConfigsSerialized.js +62 -0
- package/dist/cjs/shared/page-configs/assertExports.js +60 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +18 -0
- package/dist/cjs/shared/page-configs/parseConfigValuesImported.js +50 -0
- package/dist/cjs/shared/page-configs/utils.js +1 -1
- package/dist/cjs/shared/route/loadPageRoutes.js +11 -13
- package/dist/cjs/shared/route/resolvePrecedence.js +32 -11
- package/dist/cjs/shared/route/resolveRedirects.js +1 -1
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -0
- package/dist/cjs/shared/route/resolveRouteString.js +99 -43
- package/dist/cjs/shared/utils.js +1 -1
- package/dist/cjs/types/defineConfig.js +7 -0
- package/dist/cjs/types/index.js +3 -0
- package/dist/cjs/utils/getFilePathAbsolute.js +16 -12
- package/dist/cjs/utils/objectAssign.js +3 -1
- package/dist/cjs/utils/parseUrl.js +6 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/requireResolve.js +60 -0
- package/dist/esm/__internal/index.d.ts +3 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageId.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.js +3 -1
- package/dist/esm/client/client-routing-runtime/useClientRouter.js +2 -2
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
- package/dist/esm/client/shared/loadPageFilesClientSide.d.ts +2 -2
- package/dist/esm/client/shared/loadPageFilesClientSide.js +2 -2
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/plugin/index.js +3 -2
- package/dist/esm/node/plugin/plugins/buildConfig.js +4 -5
- package/dist/esm/node/plugin/plugins/commonConfig.js +2 -7
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +1 -1
- package/dist/esm/node/plugin/plugins/envVars.js +4 -6
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.d.ts +13 -2
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.js +19 -8
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +8 -0
- 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 +111 -115
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +35 -25
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +3 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +49 -79
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +10 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.d.ts +18 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/replaceImportStatements.js +25 -25
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +19 -16
- package/dist/esm/node/plugin/plugins/suppressRollupWarning.js +16 -3
- package/dist/esm/node/plugin/shared/{getConfigValueSource.d.ts → getConfigValueSourcesRelevant.d.ts} +0 -2
- package/dist/esm/node/plugin/shared/{getConfigValueSource.js → getConfigValueSourcesRelevant.js} +0 -11
- package/dist/esm/node/plugin/shared/loggerNotProd/errorWithCodeSnippet.js +2 -2
- package/dist/esm/node/plugin/shared/loggerNotProd.js +4 -4
- package/dist/esm/node/plugin/utils.d.ts +1 -2
- package/dist/esm/node/plugin/utils.js +1 -2
- package/dist/esm/node/prerender/runPrerender.js +13 -16
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/html/serializePageContextClientSide.d.ts +2 -2
- package/dist/esm/node/runtime/html/stream.js +4 -1
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +13 -13
- package/dist/esm/node/shared/getClientEntryFilePath.d.ts +2 -2
- package/dist/esm/node/shared/virtual-files/virtualFilePageConfigValuesAll.js +1 -1
- package/dist/esm/shared/addIs404ToPageProps.d.ts +2 -2
- package/dist/esm/shared/error-page.d.ts +3 -3
- package/dist/esm/shared/error-page.js +1 -1
- package/dist/esm/shared/getPageFiles/analyzeClientSide.d.ts +2 -2
- package/dist/esm/shared/getPageFiles/assertPageConfigs.d.ts +5 -5
- package/dist/esm/shared/getPageFiles/assertPageConfigs.js +12 -12
- package/dist/esm/shared/getPageFiles/getExports.d.ts +2 -2
- package/dist/esm/shared/getPageFiles/getExports.js +1 -1
- package/dist/esm/shared/getPageFiles/parseGlobResults.d.ts +3 -3
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +9 -43
- package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.d.ts +6 -0
- package/dist/esm/shared/getPageFiles/parsePageConfigsSerialized.js +59 -0
- package/dist/esm/shared/getPageFiles/setPageFiles.d.ts +3 -3
- package/dist/esm/shared/page-configs/Config.d.ts +200 -11
- package/dist/esm/shared/page-configs/PageConfig.d.ts +59 -39
- package/dist/esm/shared/page-configs/assertExports.d.ts +6 -0
- package/dist/esm/shared/page-configs/assertExports.js +54 -0
- package/dist/esm/shared/page-configs/findPageConfig.d.ts +2 -2
- package/dist/esm/shared/page-configs/loadConfigValues.d.ts +3 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +15 -0
- package/dist/esm/shared/page-configs/parseConfigValuesImported.d.ts +3 -0
- package/dist/esm/shared/page-configs/parseConfigValuesImported.js +44 -0
- package/dist/esm/shared/page-configs/utils.d.ts +3 -2
- package/dist/esm/shared/page-configs/utils.js +1 -1
- package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
- package/dist/esm/shared/route/index.d.ts +3 -3
- package/dist/esm/shared/route/loadPageRoutes.d.ts +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +11 -13
- package/dist/esm/shared/route/resolvePrecedence.js +33 -12
- package/dist/esm/shared/route/resolveRedirects.js +1 -1
- package/dist/esm/shared/route/resolveRouteFunction.js +1 -0
- package/dist/esm/shared/route/resolveRouteString.d.ts +21 -4
- package/dist/esm/shared/route/resolveRouteString.js +98 -42
- package/dist/esm/shared/types.d.ts +7 -6
- package/dist/esm/shared/utils.d.ts +1 -1
- package/dist/esm/shared/utils.js +1 -1
- package/dist/esm/types/defineConfig.d.ts +3 -0
- package/dist/esm/types/defineConfig.js +4 -0
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/types/index.js +1 -1
- package/dist/esm/utils/getFilePathAbsolute.d.ts +2 -2
- package/dist/esm/utils/getFilePathAbsolute.js +15 -11
- package/dist/esm/utils/objectAssign.js +3 -1
- package/dist/esm/utils/parseUrl.js +6 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/requireResolve.d.ts +2 -0
- package/dist/esm/utils/requireResolve.js +57 -0
- package/package.json +3 -3
- package/dist/cjs/shared/page-configs/loadPageCode.js +0 -63
- package/dist/cjs/utils/addFileExtensionsToRequireResolve.js +0 -23
- package/dist/cjs/utils/assertDefaultExport.js +0 -53
- package/dist/esm/shared/page-configs/loadPageCode.d.ts +0 -3
- package/dist/esm/shared/page-configs/loadPageCode.js +0 -57
- package/dist/esm/utils/addFileExtensionsToRequireResolve.d.ts +0 -2
- package/dist/esm/utils/addFileExtensionsToRequireResolve.js +0 -20
- package/dist/esm/utils/assertDefaultExport.d.ts +0 -8
- package/dist/esm/utils/assertDefaultExport.js +0 -47
- /package/dist/cjs/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
- /package/dist/esm/shared/getPageFiles/{assertExports.d.ts → assert_exports_old_design.d.ts} +0 -0
- /package/dist/esm/shared/getPageFiles/{assertExports.js → assert_exports_old_design.js} +0 -0
|
@@ -17,21 +17,19 @@ const loggerNotProd_js_1 = require("../../../shared/loggerNotProd.js");
|
|
|
17
17
|
const removeSuperfluousViteLog_js_1 = require("../../../shared/loggerVite/removeSuperfluousViteLog.js");
|
|
18
18
|
const getFilePathToShowToUser_js_1 = require("./getFilePathToShowToUser.js");
|
|
19
19
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
20
|
-
const module_1 = require("module");
|
|
21
20
|
const utils_js_2 = require("../../../../../shared/page-configs/utils.js");
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
21
|
+
const assertExports_js_1 = require("../../../../../shared/page-configs/assertExports.js");
|
|
22
|
+
const getVirtualFilePageConfigs_js_1 = require("./getVirtualFilePageConfigs.js");
|
|
25
23
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
26
24
|
let devServerIsCorrupt = false;
|
|
27
25
|
let wasConfigInvalid = null;
|
|
28
26
|
let vikeConfigPromise = null;
|
|
29
27
|
const vikeConfigDependencies = new Set();
|
|
30
28
|
exports.vikeConfigDependencies = vikeConfigDependencies;
|
|
31
|
-
const
|
|
29
|
+
const filesEnv = new Map();
|
|
32
30
|
function reloadVikeConfig(userRootDir, extensions) {
|
|
33
31
|
vikeConfigDependencies.clear();
|
|
34
|
-
|
|
32
|
+
filesEnv.clear();
|
|
35
33
|
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, true, extensions, true);
|
|
36
34
|
handleReloadSideEffects();
|
|
37
35
|
}
|
|
@@ -105,27 +103,27 @@ async function loadInterfaceFiles(userRootDir, isDev, extensions) {
|
|
|
105
103
|
}));
|
|
106
104
|
// Value files
|
|
107
105
|
await Promise.all(valueFiles.map(async ({ filePathAbsolute, filePathRelativeToUserRootDir }) => {
|
|
108
|
-
const
|
|
109
|
-
(0, utils_js_1.assert)(
|
|
106
|
+
const configName = getConfigName(filePathRelativeToUserRootDir);
|
|
107
|
+
(0, utils_js_1.assert)(configName);
|
|
110
108
|
const interfaceFile = {
|
|
111
109
|
filePath: {
|
|
112
110
|
filePathRelativeToUserRootDir,
|
|
113
111
|
filePathAbsolute
|
|
114
112
|
},
|
|
115
113
|
configMap: {
|
|
116
|
-
[
|
|
114
|
+
[configName]: {}
|
|
117
115
|
},
|
|
118
116
|
isConfigFile: false,
|
|
119
117
|
isValueFile: true,
|
|
120
|
-
|
|
118
|
+
configName
|
|
121
119
|
};
|
|
122
120
|
{
|
|
123
121
|
// We don't have access to custom config definitions yet
|
|
124
|
-
// - We load +
|
|
122
|
+
// - We load +{configName}.js later
|
|
125
123
|
// - But we do need to eagerly load +meta.js (to get all the custom config definitions)
|
|
126
|
-
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn,
|
|
124
|
+
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn, configName);
|
|
127
125
|
if (configDef?.env === 'config-only') {
|
|
128
|
-
await loadValueFile(interfaceFile,
|
|
126
|
+
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
129
127
|
}
|
|
130
128
|
}
|
|
131
129
|
{
|
|
@@ -145,14 +143,13 @@ function getConfigDefinition(configDefinitionsRelevant, configName, definedByFil
|
|
|
145
143
|
function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
146
144
|
return configDefinitions[configName] ?? null;
|
|
147
145
|
}
|
|
148
|
-
async function loadValueFile(interfaceValueFile,
|
|
146
|
+
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
149
147
|
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath, true, userRootDir);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
interfaceValueFile.configMap[configName] = { configValue };
|
|
148
|
+
const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceValueFile.filePath);
|
|
149
|
+
(0, assertExports_js_1.assertExportsOfValueFile)(fileExports, filePathToShowToUser, configName);
|
|
150
|
+
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
151
|
+
const configName_ = exportName === 'default' ? configName : exportName;
|
|
152
|
+
interfaceValueFile.configMap[configName_] = { configValue };
|
|
156
153
|
});
|
|
157
154
|
}
|
|
158
155
|
function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
@@ -165,8 +162,8 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
165
162
|
isConfigExtend,
|
|
166
163
|
extendsFilePaths
|
|
167
164
|
};
|
|
168
|
-
const
|
|
169
|
-
(0,
|
|
165
|
+
const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(filePath);
|
|
166
|
+
(0, assertExports_js_1.assertExportsOfConfigFile)(fileExports, filePathToShowToUser);
|
|
170
167
|
Object.entries(fileExports.default).forEach(([configName, configValue]) => {
|
|
171
168
|
interfaceFile.configMap[configName] = { configValue };
|
|
172
169
|
});
|
|
@@ -205,8 +202,7 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, extensions,
|
|
|
205
202
|
const dummyData = {
|
|
206
203
|
pageConfigs: [],
|
|
207
204
|
pageConfigGlobal: {
|
|
208
|
-
|
|
209
|
-
onBeforeRoute: null
|
|
205
|
+
configValueSources: {}
|
|
210
206
|
},
|
|
211
207
|
globalVikeConfig: {}
|
|
212
208
|
};
|
|
@@ -226,18 +222,18 @@ async function loadVikeConfig(userRootDir, isDev, extensions) {
|
|
|
226
222
|
await Promise.all(getInterfaceFileList(interfaceFilesRelevant).map(async (interfaceFile) => {
|
|
227
223
|
if (!interfaceFile.isValueFile)
|
|
228
224
|
return;
|
|
229
|
-
const {
|
|
230
|
-
if (isGlobalConfig(
|
|
225
|
+
const { configName } = interfaceFile;
|
|
226
|
+
if (isGlobalConfig(configName))
|
|
231
227
|
return;
|
|
232
|
-
const configDef = getConfigDefinition(configDefinitionsRelevant,
|
|
228
|
+
const configDef = getConfigDefinition(configDefinitionsRelevant, configName, (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceFile.filePath));
|
|
233
229
|
if (configDef.env !== 'config-only')
|
|
234
230
|
return;
|
|
235
231
|
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
236
232
|
if (isAlreadyLoaded)
|
|
237
233
|
return;
|
|
238
234
|
// Value files for built-in confg-only configs should have already been loaded at loadInterfaceFiles()
|
|
239
|
-
(0, utils_js_1.assert)(!(
|
|
240
|
-
await loadValueFile(interfaceFile,
|
|
235
|
+
(0, utils_js_1.assert)(!(configName in configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn));
|
|
236
|
+
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
241
237
|
}));
|
|
242
238
|
const configValueSources = {};
|
|
243
239
|
(0, utils_js_1.objectEntries)(configDefinitionsRelevant)
|
|
@@ -331,17 +327,16 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
|
331
327
|
}
|
|
332
328
|
const globalVikeConfig = {};
|
|
333
329
|
const pageConfigGlobal = {
|
|
334
|
-
|
|
335
|
-
onPrerenderStart: null
|
|
330
|
+
configValueSources: {}
|
|
336
331
|
};
|
|
337
332
|
(0, utils_js_1.objectEntries)(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal).forEach(([configName, configDef]) => {
|
|
338
333
|
const sources = resolveConfigValueSources(configName, configDef, interfaceFilesGlobal, userRootDir);
|
|
339
334
|
const configValueSource = sources?.[0];
|
|
340
335
|
if (!configValueSource)
|
|
341
336
|
return;
|
|
342
|
-
if (
|
|
337
|
+
if (configName === 'onBeforeRoute' || configName === 'onPrerenderStart') {
|
|
343
338
|
(0, utils_js_1.assert)(!('value' in configValueSource));
|
|
344
|
-
pageConfigGlobal[configName] = configValueSource;
|
|
339
|
+
pageConfigGlobal.configValueSources[configName] = [configValueSource];
|
|
345
340
|
}
|
|
346
341
|
else {
|
|
347
342
|
(0, utils_js_1.assert)('value' in configValueSource);
|
|
@@ -374,7 +369,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
374
369
|
const interfaceValueFiles = interfaceFilesDefiningConfig
|
|
375
370
|
.filter((interfaceFile) => interfaceFile.isValueFile &&
|
|
376
371
|
// We consider side-effect exports (e.g. `export { frontmatter }` of .mdx files) later (i.e. with less priority)
|
|
377
|
-
interfaceFile.
|
|
372
|
+
interfaceFile.configName === configName)
|
|
378
373
|
.sort(makeOrderDeterministic);
|
|
379
374
|
const interfaceConfigFiles = interfaceFilesDefiningConfig
|
|
380
375
|
.filter((interfaceFile) => interfaceFile.isConfigFile &&
|
|
@@ -384,9 +379,9 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
384
379
|
const interfaceValueFile = interfaceValueFiles[0];
|
|
385
380
|
const interfaceConfigFile = interfaceConfigFiles[0];
|
|
386
381
|
// Make this value:
|
|
387
|
-
// /pages/some-page/+
|
|
382
|
+
// /pages/some-page/+{configName}.js > `export default`
|
|
388
383
|
// override that value:
|
|
389
|
-
// /pages/some-page/+config > `export default { someConfig }`
|
|
384
|
+
// /pages/some-page/+config.h.js > `export default { someConfig }`
|
|
390
385
|
const interfaceFileWinner = interfaceValueFile ?? interfaceConfigFile;
|
|
391
386
|
if (interfaceFileWinner) {
|
|
392
387
|
const interfaceFilesOverriden = [...interfaceValueFiles, ...interfaceConfigFiles].filter((f) => f !== interfaceFileWinner);
|
|
@@ -401,7 +396,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
401
396
|
interfaceFilesDefiningConfig
|
|
402
397
|
.filter((interfaceFile) => interfaceFile.isValueFile &&
|
|
403
398
|
// Is side-effect export
|
|
404
|
-
interfaceFile.
|
|
399
|
+
interfaceFile.configName !== configName)
|
|
405
400
|
.forEach((interfaceValueFileSideEffect) => {
|
|
406
401
|
add(interfaceValueFileSideEffect);
|
|
407
402
|
});
|
|
@@ -439,22 +434,22 @@ function isInterfaceFileUserLand(interfaceFile) {
|
|
|
439
434
|
}
|
|
440
435
|
function getConfigValueSource(configName, interfaceFile, configDef, userRootDir) {
|
|
441
436
|
// TODO: rethink file paths of ConfigElement
|
|
442
|
-
const
|
|
437
|
+
const filePathToShowToUser = interfaceFile.filePath.filePathRelativeToUserRootDir ?? interfaceFile.filePath.filePathAbsolute;
|
|
443
438
|
const conf = interfaceFile.configMap[configName];
|
|
444
439
|
(0, utils_js_1.assert)(conf);
|
|
445
440
|
const configEnv = configDef.env;
|
|
446
441
|
const definedAtInfoConfigFile = {
|
|
447
|
-
filePath:
|
|
442
|
+
filePath: filePathToShowToUser,
|
|
448
443
|
fileExportPath: ['default', configName]
|
|
449
444
|
};
|
|
450
445
|
if (configDef._valueIsFilePath) {
|
|
451
446
|
let filePath;
|
|
452
447
|
if (interfaceFile.isConfigFile) {
|
|
453
448
|
const { configValue } = conf;
|
|
454
|
-
const import_ =
|
|
449
|
+
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
455
450
|
const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, { definedAtInfo: definedAtInfoConfigFile }, true);
|
|
456
451
|
(0, utils_js_1.assertUsage)(import_, `${configDefinedAt} should be an import`);
|
|
457
|
-
filePath = import_.
|
|
452
|
+
filePath = import_.filePathToShowToUser;
|
|
458
453
|
}
|
|
459
454
|
else {
|
|
460
455
|
(0, utils_js_1.assert)(interfaceFile.isValueFile);
|
|
@@ -479,17 +474,16 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
479
474
|
if (interfaceFile.isConfigFile) {
|
|
480
475
|
(0, utils_js_1.assert)('configValue' in conf);
|
|
481
476
|
const { configValue } = conf;
|
|
482
|
-
const import_ =
|
|
477
|
+
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
483
478
|
if (import_) {
|
|
484
|
-
const {
|
|
485
|
-
assertCodeFileEnv(importFilePath, configEnv, configName);
|
|
479
|
+
const { filePathToShowToUser, fileExportName: exportName } = import_;
|
|
486
480
|
const configValueSource = {
|
|
487
481
|
configEnv,
|
|
488
482
|
valueIsImportedAtRuntime: true,
|
|
489
483
|
isComputed: false,
|
|
490
484
|
definedAtInfo: {
|
|
491
|
-
filePath:
|
|
492
|
-
fileExportPath: [
|
|
485
|
+
filePath: filePathToShowToUser,
|
|
486
|
+
fileExportPath: [exportName]
|
|
493
487
|
}
|
|
494
488
|
};
|
|
495
489
|
return configValueSource;
|
|
@@ -507,16 +501,16 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
507
501
|
}
|
|
508
502
|
else if (interfaceFile.isValueFile) {
|
|
509
503
|
// TODO: rethink file paths of ConfigElement
|
|
510
|
-
const
|
|
511
|
-
const
|
|
504
|
+
const importPath = interfaceFile.filePath.filePathRelativeToUserRootDir ?? interfaceFile.filePath.filePathAbsolute;
|
|
505
|
+
const exportName = configName === interfaceFile.configName ? 'default' : configName;
|
|
512
506
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
513
507
|
const configValueSource = {
|
|
514
508
|
configEnv,
|
|
515
509
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
516
510
|
isComputed: false,
|
|
517
511
|
definedAtInfo: {
|
|
518
|
-
filePath:
|
|
519
|
-
fileExportPath: [
|
|
512
|
+
filePath: importPath,
|
|
513
|
+
fileExportPath: [exportName]
|
|
520
514
|
}
|
|
521
515
|
};
|
|
522
516
|
if (valueAlreadyLoaded) {
|
|
@@ -529,16 +523,17 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
529
523
|
}
|
|
530
524
|
(0, utils_js_1.assert)(false);
|
|
531
525
|
}
|
|
532
|
-
function
|
|
533
|
-
|
|
534
|
-
|
|
526
|
+
function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
|
|
527
|
+
(0, utils_js_1.assertPosixPath)(filePathForEnvCheck);
|
|
528
|
+
if (!filesEnv.has(filePathForEnvCheck)) {
|
|
529
|
+
filesEnv.set(filePathForEnvCheck, []);
|
|
535
530
|
}
|
|
536
|
-
const
|
|
537
|
-
|
|
538
|
-
const configDifferentEnv =
|
|
531
|
+
const fileEnv = filesEnv.get(filePathForEnvCheck);
|
|
532
|
+
fileEnv.push({ configEnv, configName });
|
|
533
|
+
const configDifferentEnv = fileEnv.filter((c) => c.configEnv !== configEnv)[0];
|
|
539
534
|
if (configDifferentEnv) {
|
|
540
535
|
(0, utils_js_1.assertUsage)(false, [
|
|
541
|
-
`${
|
|
536
|
+
`${filePathForEnvCheck} defines the value of configs living in different environments:`,
|
|
542
537
|
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${picocolors_1.default.cyan(c.configName)} which value lives in environment ${picocolors_1.default.cyan(c.configEnv)}`),
|
|
543
538
|
'Defining config values in the same file is allowed only if they live in the same environment, see https://vike.dev/header-file/import-from-same-file'
|
|
544
539
|
].join('\n'));
|
|
@@ -556,53 +551,60 @@ function isDefiningPage(interfaceFiles) {
|
|
|
556
551
|
function isDefiningPageConfig(configName) {
|
|
557
552
|
return ['Page', 'route'].includes(configName);
|
|
558
553
|
}
|
|
559
|
-
function
|
|
554
|
+
function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
560
555
|
if (typeof configValue !== 'string')
|
|
561
556
|
return null;
|
|
562
557
|
const importData = (0, replaceImportStatements_js_1.parseImportData)(configValue);
|
|
563
558
|
if (!importData)
|
|
564
559
|
return null;
|
|
565
|
-
|
|
566
|
-
|
|
560
|
+
const { importPath, exportName } = importData;
|
|
561
|
+
const filePathAbsolute = resolveImportPath(importData, importerFilePath);
|
|
562
|
+
let filePathToShowToUser;
|
|
563
|
+
if (importPath.startsWith('.')) {
|
|
567
564
|
// We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
|
|
568
565
|
// ```
|
|
569
566
|
// [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
|
|
570
567
|
// ```
|
|
571
|
-
|
|
568
|
+
assertImportPath(filePathAbsolute, importData, importerFilePath);
|
|
569
|
+
const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, importerFilePath, userRootDir);
|
|
570
|
+
filePathToShowToUser = filePathRelativeToUserRootDir;
|
|
572
571
|
}
|
|
573
572
|
else {
|
|
574
|
-
//
|
|
573
|
+
// importPath can be:
|
|
575
574
|
// - an npm package import
|
|
576
575
|
// - a path alias
|
|
576
|
+
filePathToShowToUser = importPath;
|
|
577
|
+
}
|
|
578
|
+
{
|
|
579
|
+
const filePathForEnvCheck = filePathAbsolute ?? importPath;
|
|
580
|
+
assertFileEnv(filePathForEnvCheck, configEnv, configName);
|
|
577
581
|
}
|
|
578
582
|
return {
|
|
579
|
-
|
|
580
|
-
|
|
583
|
+
filePathToShowToUser,
|
|
584
|
+
fileExportName: exportName
|
|
581
585
|
};
|
|
582
586
|
}
|
|
583
|
-
function
|
|
584
|
-
let importFilePath = resolveImport(importData, configFilePath);
|
|
585
|
-
// Make it a Vite path
|
|
587
|
+
function resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, configFilePath, userRootDir) {
|
|
586
588
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
587
|
-
|
|
588
|
-
if (
|
|
589
|
-
|
|
589
|
+
let filePathRelativeToUserRootDir;
|
|
590
|
+
if (filePathAbsolute.startsWith(userRootDir)) {
|
|
591
|
+
filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsolute, userRootDir);
|
|
590
592
|
}
|
|
591
593
|
else {
|
|
592
|
-
(0, utils_js_1.assertUsage)(false, `${(0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(configFilePath)} imports from a relative path ${picocolors_1.default.cyan(importData.
|
|
594
|
+
(0, utils_js_1.assertUsage)(false, `${(0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(configFilePath)} imports from a relative path ${picocolors_1.default.cyan(importData.importPath)} outside of ${userRootDir} which is forbidden: import from a relative path inside ${userRootDir}, or import from a dependency's package.json#exports entry instead`);
|
|
593
595
|
// None of the following works. Seems to be a Vite bug?
|
|
594
596
|
// /*
|
|
595
|
-
// assert(
|
|
596
|
-
//
|
|
597
|
+
// assert(filePathAbsolute.startsWith('/'))
|
|
598
|
+
// filePath = `/@fs${filePathAbsolute}`
|
|
597
599
|
// /*/
|
|
598
|
-
//
|
|
599
|
-
// assert(
|
|
600
|
-
//
|
|
600
|
+
// filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsolute)
|
|
601
|
+
// assert(filePathRelativeToUserRootDir.startsWith('../'))
|
|
602
|
+
// filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir
|
|
601
603
|
// //*/
|
|
602
604
|
}
|
|
603
|
-
(0, utils_js_1.assertPosixPath)(
|
|
604
|
-
(0, utils_js_1.assert)(
|
|
605
|
-
return
|
|
605
|
+
(0, utils_js_1.assertPosixPath)(filePathRelativeToUserRootDir);
|
|
606
|
+
(0, utils_js_1.assert)(filePathRelativeToUserRootDir.startsWith('/'));
|
|
607
|
+
return filePathRelativeToUserRootDir;
|
|
606
608
|
}
|
|
607
609
|
function getVitePathFromAbsolutePath(filePathAbsolute, root) {
|
|
608
610
|
(0, utils_js_1.assertPosixPath)(filePathAbsolute);
|
|
@@ -714,10 +716,9 @@ function applyEffect(configModFromEffect, configValueEffectSource, configValueSo
|
|
|
714
716
|
function applyComputed(pageConfig, configDefinitionsRelevant) {
|
|
715
717
|
(0, utils_js_1.objectEntries)(configDefinitionsRelevant).forEach(([configName, configDef]) => {
|
|
716
718
|
var _a;
|
|
717
|
-
|
|
718
|
-
if (!computed)
|
|
719
|
+
if (!configDef._computed)
|
|
719
720
|
return;
|
|
720
|
-
const value =
|
|
721
|
+
const value = configDef._computed(pageConfig);
|
|
721
722
|
if (value === undefined)
|
|
722
723
|
return;
|
|
723
724
|
const configValueSource = {
|
|
@@ -830,10 +831,11 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
830
831
|
const extendsImportData = getExtendsImportData(configFileExports, configFilePath);
|
|
831
832
|
const extendsConfigFiles = [];
|
|
832
833
|
extendsImportData.map((importData) => {
|
|
833
|
-
const {
|
|
834
|
+
const { importPath: importPath } = importData;
|
|
834
835
|
// TODO
|
|
835
836
|
// - validate extends configs
|
|
836
|
-
const filePathAbsolute =
|
|
837
|
+
const filePathAbsolute = resolveImportPath(importData, configFilePath);
|
|
838
|
+
assertImportPath(filePathAbsolute, importData, configFilePath);
|
|
837
839
|
assertExtendsImportPath(importPath, filePathAbsolute, configFilePath);
|
|
838
840
|
extendsConfigFiles.push({
|
|
839
841
|
filePathAbsolute,
|
|
@@ -879,7 +881,7 @@ function assertExtendsImportPath(importPath, filePath, configFilePath) {
|
|
|
879
881
|
}
|
|
880
882
|
function getExtendsImportData(configFileExports, configFilePath) {
|
|
881
883
|
const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(configFilePath);
|
|
882
|
-
(0,
|
|
884
|
+
(0, assertExports_js_1.assertExportsOfConfigFile)(configFileExports, filePathToShowToUser);
|
|
883
885
|
const defaultExports = configFileExports.default;
|
|
884
886
|
const wrongUsage = `${filePathToShowToUser} sets the config 'extends' to an invalid value, see https://vike.dev/extends`;
|
|
885
887
|
let extendList;
|
|
@@ -959,13 +961,16 @@ function handleUnknownConfig(configName, configNames, definedByFile) {
|
|
|
959
961
|
else {
|
|
960
962
|
configNameSimilar = (0, utils_js_1.getMostSimilar)(configName, configNames);
|
|
961
963
|
}
|
|
962
|
-
if (configNameSimilar) {
|
|
964
|
+
if (configNameSimilar || configName === 'page') {
|
|
965
|
+
(0, utils_js_1.assert)(configNameSimilar);
|
|
963
966
|
(0, utils_js_1.assert)(configNameSimilar !== configName);
|
|
964
967
|
errMsg += `, did you mean to define ${picocolors_1.default.cyan(configNameSimilar)} instead?`;
|
|
968
|
+
if (configName === 'page') {
|
|
969
|
+
errMsg += ` (The name of the config ${picocolors_1.default.cyan('Page')} starts with a capital letter ${picocolors_1.default.cyan('P')} because it usually defines a UI component: a ubiquitous JavaScript convention is to start the name of UI components with a capital letter.)`;
|
|
970
|
+
}
|
|
965
971
|
}
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
errMsg += ` (The name of the config ${picocolors_1.default.cyan('Page')} starts with a capital letter ${picocolors_1.default.cyan('P')} because it usually defines a UI component: a ubiquitous JavaScript convention is to start the name of UI components with a capital letter.)`;
|
|
972
|
+
else {
|
|
973
|
+
errMsg += `, you need to define the config ${picocolors_1.default.cyan(configName)} by using ${picocolors_1.default.cyan('config.meta')} https://vike.dev/meta`;
|
|
969
974
|
}
|
|
970
975
|
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
971
976
|
}
|
|
@@ -974,7 +979,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
974
979
|
const configFilesystemRoutingRoot = configValueSources[configName]?.[0];
|
|
975
980
|
let filesystemRouteString = (0, filesystemRouting_js_1.getFilesystemRouteString)(locationId);
|
|
976
981
|
if (determineIsErrorPage(filesystemRouteString)) {
|
|
977
|
-
return { isErrorPage: true, routeFilesystem:
|
|
982
|
+
return { isErrorPage: true, routeFilesystem: undefined };
|
|
978
983
|
}
|
|
979
984
|
let filesystemRouteDefinedBy = (0, filesystemRouting_js_1.getFilesystemRouteDefinedBy)(locationId); // for log404()
|
|
980
985
|
if (configFilesystemRoutingRoot) {
|
|
@@ -992,7 +997,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
992
997
|
routeString: filesystemRouteString,
|
|
993
998
|
definedBy: filesystemRouteDefinedBy
|
|
994
999
|
};
|
|
995
|
-
return { routeFilesystem, isErrorPage:
|
|
1000
|
+
return { routeFilesystem, isErrorPage: undefined };
|
|
996
1001
|
}
|
|
997
1002
|
function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName) {
|
|
998
1003
|
(0, utils_js_1.assert)(configFilesystemRoutingRoot.configEnv === 'config-only');
|
|
@@ -1012,33 +1017,22 @@ function determineIsErrorPage(routeFilesystem) {
|
|
|
1012
1017
|
(0, utils_js_1.assertPosixPath)(routeFilesystem);
|
|
1013
1018
|
return routeFilesystem.split('/').includes('_error');
|
|
1014
1019
|
}
|
|
1015
|
-
function
|
|
1016
|
-
const
|
|
1017
|
-
(0, utils_js_1.assertPosixPath)(
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
importedFile = require_.resolve(importData.importFilePath, { paths: [plusConfigFilDirPathAbsolute] });
|
|
1023
|
-
}
|
|
1024
|
-
catch {
|
|
1025
|
-
importedFile = null;
|
|
1026
|
-
}
|
|
1027
|
-
finally {
|
|
1028
|
-
clean();
|
|
1029
|
-
}
|
|
1030
|
-
assertImport(importedFile, importData, importerFilePath);
|
|
1031
|
-
importedFile = (0, utils_js_1.toPosixPath)(importedFile);
|
|
1032
|
-
return importedFile;
|
|
1020
|
+
function resolveImportPath(importData, importerFilePath) {
|
|
1021
|
+
const importerFilePathAbsolute = importerFilePath.filePathAbsolute;
|
|
1022
|
+
(0, utils_js_1.assertPosixPath)(importerFilePathAbsolute);
|
|
1023
|
+
const cwd = path_1.default.posix.dirname(importerFilePathAbsolute);
|
|
1024
|
+
// filePathAbsolute is expected to be null when importData.importPath is a Vite path alias
|
|
1025
|
+
const filePathAbsolute = (0, utils_js_1.requireResolve)(importData.importPath, cwd);
|
|
1026
|
+
return filePathAbsolute;
|
|
1033
1027
|
}
|
|
1034
|
-
function
|
|
1035
|
-
const {
|
|
1028
|
+
function assertImportPath(filePathAbsolute, importData, importerFilePath) {
|
|
1029
|
+
const { importPath: importPath, importStringWasGenerated, importString } = importData;
|
|
1036
1030
|
const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(importerFilePath);
|
|
1037
|
-
if (!
|
|
1031
|
+
if (!filePathAbsolute) {
|
|
1038
1032
|
const importPathString = picocolors_1.default.cyan(`'${importPath}'`);
|
|
1039
|
-
const errIntro =
|
|
1033
|
+
const errIntro = importStringWasGenerated
|
|
1040
1034
|
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
1041
|
-
: `The import ${picocolors_1.default.cyan(
|
|
1035
|
+
: `The import ${picocolors_1.default.cyan(importString)} defined in ${filePathToShowToUser}`;
|
|
1042
1036
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
1043
1037
|
if (importPath.startsWith('.')) {
|
|
1044
1038
|
(0, utils_js_1.assertUsage)(false, `${errIntro2} point to an existing file?`);
|
|
@@ -1090,6 +1084,8 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1090
1084
|
/* This is more confusing than adding value. For example, this explanation shouldn't be shown for the passToClient config.
|
|
1091
1085
|
const explanation = `(Because the values of ${configNameColored} are cumulative and therefore merged together.)` as const
|
|
1092
1086
|
*/
|
|
1087
|
+
// Make sure configValueSource.value is serializable
|
|
1088
|
+
(0, getVirtualFilePageConfigs_js_1.getConfigValueSerialized)(configValueSource.value, configName, configValueSource.definedAtInfo);
|
|
1093
1089
|
const assertNoMixing = (isSet) => {
|
|
1094
1090
|
const vals1 = isSet ? valuesSet : valuesArr;
|
|
1095
1091
|
const t1 = isSet ? 'a Set' : 'an array';
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getVirtualFilePageConfigValuesAll = void 0;
|
|
6
|
+
exports.serializeConfigValueImported = exports.getVirtualFilePageConfigValuesAll = void 0;
|
|
7
7
|
const utils_js_1 = require("../../../utils.js");
|
|
8
8
|
const generateEagerImport_js_1 = require("../generateEagerImport.js");
|
|
9
9
|
const virtualFilePageConfigValuesAll_js_1 = require("../../../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
@@ -12,7 +12,7 @@ const extractAssetsQuery_js_1 = require("../../../../shared/extractAssetsQuery.j
|
|
|
12
12
|
const debug_js_1 = require("./debug.js");
|
|
13
13
|
const path_1 = __importDefault(require("path"));
|
|
14
14
|
const utils_js_2 = require("../../../../../shared/page-configs/utils.js");
|
|
15
|
-
const
|
|
15
|
+
const getConfigValueSourcesRelevant_js_1 = require("../../../shared/getConfigValueSourcesRelevant.js");
|
|
16
16
|
const isConfigEnvMatch_js_1 = require("./isConfigEnvMatch.js");
|
|
17
17
|
async function getVirtualFilePageConfigValuesAll(id, userRootDir, isDev, configVike) {
|
|
18
18
|
const result = (0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(id);
|
|
@@ -38,37 +38,17 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
38
38
|
const lines = [];
|
|
39
39
|
const importStatements = [];
|
|
40
40
|
lines.push('export default [');
|
|
41
|
-
|
|
42
|
-
(0,
|
|
43
|
-
const { valueIsImportedAtRuntime,
|
|
41
|
+
const varCounterContainer = { varCounter: 0 };
|
|
42
|
+
(0, getConfigValueSourcesRelevant_js_1.getConfigValueSourcesRelevant)(pageConfig).forEach((configValueSource) => {
|
|
43
|
+
const { valueIsImportedAtRuntime, configEnv, configName } = configValueSource;
|
|
44
44
|
if (!valueIsImportedAtRuntime)
|
|
45
45
|
return;
|
|
46
46
|
if (configValueSource.valueIsFilePath)
|
|
47
47
|
return;
|
|
48
48
|
if (!(0, isConfigEnvMatch_js_1.isConfigEnvMatch)(configEnv, isForClientSide, isClientRouting))
|
|
49
49
|
return;
|
|
50
|
-
const
|
|
51
|
-
(
|
|
52
|
-
const fileName = path_1.default.posix.basename(filePath);
|
|
53
|
-
const isPlusFile = fileName.startsWith('+');
|
|
54
|
-
const fileExportName = fileExportPath[0];
|
|
55
|
-
(0, utils_js_1.assert)(!configValueSource.valueIsFilePath);
|
|
56
|
-
(0, utils_js_1.assert)(fileExportName);
|
|
57
|
-
const { importVar, importStatement } = (0, generateEagerImport_js_1.generateEagerImport)(filePath, varCounter++, isPlusFile ? undefined : fileExportName);
|
|
58
|
-
importStatements.push(importStatement);
|
|
59
|
-
lines.push(` {`);
|
|
60
|
-
lines.push(` configName: '${configName}',`);
|
|
61
|
-
lines.push(` importFilePath: '${filePath}',`);
|
|
62
|
-
lines.push(` isPlusFile: ${JSON.stringify(isPlusFile)},`);
|
|
63
|
-
if (isPlusFile) {
|
|
64
|
-
lines.push(` importFileExports: ${importVar},`);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
lines.push(` importFileExportValue: ${importVar},`);
|
|
68
|
-
(0, utils_js_1.assert)(fileExportName);
|
|
69
|
-
lines.push(` importFileExportName: ${JSON.stringify(fileExportName)},`);
|
|
70
|
-
}
|
|
71
|
-
lines.push(` },`);
|
|
50
|
+
const whitespace = ' ';
|
|
51
|
+
lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
72
52
|
});
|
|
73
53
|
lines.push('];');
|
|
74
54
|
if (includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
@@ -77,3 +57,33 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
77
57
|
const code = [...importStatements, ...lines].join('\n');
|
|
78
58
|
return code;
|
|
79
59
|
}
|
|
60
|
+
function serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements) {
|
|
61
|
+
(0, utils_js_1.assert)(whitespace.replaceAll(' ', '').length === 0);
|
|
62
|
+
const { valueIsImportedAtRuntime, definedAtInfo } = configValueSource;
|
|
63
|
+
(0, utils_js_1.assert)(valueIsImportedAtRuntime);
|
|
64
|
+
const { filePath, fileExportPath } = definedAtInfo;
|
|
65
|
+
(0, utils_js_1.assertPosixPath)(filePath);
|
|
66
|
+
const fileName = path_1.default.posix.basename(filePath);
|
|
67
|
+
const isValueFile = fileName.startsWith('+');
|
|
68
|
+
const fileExportName = fileExportPath[0];
|
|
69
|
+
(0, utils_js_1.assert)(!configValueSource.valueIsFilePath);
|
|
70
|
+
(0, utils_js_1.assert)(fileExportName);
|
|
71
|
+
const { importName, importStatement } = (0, generateEagerImport_js_1.generateEagerImport)(filePath, varCounterContainer.varCounter++, isValueFile ? undefined : fileExportName);
|
|
72
|
+
importStatements.push(importStatement);
|
|
73
|
+
const lines = [];
|
|
74
|
+
lines.push(` {`);
|
|
75
|
+
lines.push(` configName: '${configName}',`);
|
|
76
|
+
lines.push(` importPath: '${filePath}',`);
|
|
77
|
+
lines.push(` isValueFile: ${JSON.stringify(isValueFile)},`);
|
|
78
|
+
if (isValueFile) {
|
|
79
|
+
lines.push(` importFileExports: ${importName},`);
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
lines.push(` importFileExportValue: ${importName},`);
|
|
83
|
+
(0, utils_js_1.assert)(fileExportName);
|
|
84
|
+
lines.push(` exportName: ${JSON.stringify(fileExportName)},`);
|
|
85
|
+
}
|
|
86
|
+
lines.push(` },`);
|
|
87
|
+
return lines;
|
|
88
|
+
}
|
|
89
|
+
exports.serializeConfigValueImported = serializeConfigValueImported;
|