vike 0.4.142 → 0.4.143-commit-dc6fea0
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/getFilePathToShowToUser.js +6 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +122 -124
- 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/injectAssets/getHtmlTags.js +1 -1
- 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/runtime/renderPage/log404/index.js +10 -5
- 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 +19 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +6 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +3 -2
- 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 +123 -125
- 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/getHtmlTags.js +1 -1
- 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/log404/index.js +10 -5
- 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/addUrlComputedProps.d.ts +4 -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 +201 -14
- package/dist/esm/shared/page-configs/PageConfig.d.ts +60 -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 +8 -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 +3 -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
|
}
|
|
@@ -91,7 +89,8 @@ async function loadInterfaceFiles(userRootDir, isDev, extensions) {
|
|
|
91
89
|
await Promise.all(configFiles.map(async ({ filePathAbsolute, filePathRelativeToUserRootDir }) => {
|
|
92
90
|
const configFilePath = {
|
|
93
91
|
filePathAbsolute: filePathAbsolute,
|
|
94
|
-
filePathRelativeToUserRootDir: filePathRelativeToUserRootDir
|
|
92
|
+
filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
|
|
93
|
+
importPathAbsolute: null
|
|
95
94
|
};
|
|
96
95
|
const { configFile, extendsConfigs } = await loadConfigFile(configFilePath, userRootDir, []);
|
|
97
96
|
const interfaceFile = getInterfaceFileFromConfigFile(configFile, false);
|
|
@@ -105,27 +104,28 @@ async function loadInterfaceFiles(userRootDir, isDev, extensions) {
|
|
|
105
104
|
}));
|
|
106
105
|
// Value files
|
|
107
106
|
await Promise.all(valueFiles.map(async ({ filePathAbsolute, filePathRelativeToUserRootDir }) => {
|
|
108
|
-
const
|
|
109
|
-
(0, utils_js_1.assert)(
|
|
107
|
+
const configName = getConfigName(filePathRelativeToUserRootDir);
|
|
108
|
+
(0, utils_js_1.assert)(configName);
|
|
110
109
|
const interfaceFile = {
|
|
111
110
|
filePath: {
|
|
112
111
|
filePathRelativeToUserRootDir,
|
|
113
|
-
filePathAbsolute
|
|
112
|
+
filePathAbsolute,
|
|
113
|
+
importPathAbsolute: null
|
|
114
114
|
},
|
|
115
115
|
configMap: {
|
|
116
|
-
[
|
|
116
|
+
[configName]: {}
|
|
117
117
|
},
|
|
118
118
|
isConfigFile: false,
|
|
119
119
|
isValueFile: true,
|
|
120
|
-
|
|
120
|
+
configName
|
|
121
121
|
};
|
|
122
122
|
{
|
|
123
123
|
// We don't have access to custom config definitions yet
|
|
124
|
-
// - We load +
|
|
124
|
+
// - We load +{configName}.js later
|
|
125
125
|
// - But we do need to eagerly load +meta.js (to get all the custom config definitions)
|
|
126
|
-
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn,
|
|
126
|
+
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn, configName);
|
|
127
127
|
if (configDef?.env === 'config-only') {
|
|
128
|
-
await loadValueFile(interfaceFile,
|
|
128
|
+
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
{
|
|
@@ -145,14 +145,13 @@ function getConfigDefinition(configDefinitionsRelevant, configName, definedByFil
|
|
|
145
145
|
function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
146
146
|
return configDefinitions[configName] ?? null;
|
|
147
147
|
}
|
|
148
|
-
async function loadValueFile(interfaceValueFile,
|
|
148
|
+
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
149
149
|
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath, true, userRootDir);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
155
|
-
interfaceValueFile.configMap[configName] = { configValue };
|
|
150
|
+
const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceValueFile.filePath);
|
|
151
|
+
(0, assertExports_js_1.assertExportsOfValueFile)(fileExports, filePathToShowToUser, configName);
|
|
152
|
+
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
153
|
+
const configName_ = exportName === 'default' ? configName : exportName;
|
|
154
|
+
interfaceValueFile.configMap[configName_] = { configValue };
|
|
156
155
|
});
|
|
157
156
|
}
|
|
158
157
|
function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
@@ -165,8 +164,8 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
165
164
|
isConfigExtend,
|
|
166
165
|
extendsFilePaths
|
|
167
166
|
};
|
|
168
|
-
const
|
|
169
|
-
(0,
|
|
167
|
+
const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(filePath);
|
|
168
|
+
(0, assertExports_js_1.assertExportsOfConfigFile)(fileExports, filePathToShowToUser);
|
|
170
169
|
Object.entries(fileExports.default).forEach(([configName, configValue]) => {
|
|
171
170
|
interfaceFile.configMap[configName] = { configValue };
|
|
172
171
|
});
|
|
@@ -205,8 +204,7 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, extensions,
|
|
|
205
204
|
const dummyData = {
|
|
206
205
|
pageConfigs: [],
|
|
207
206
|
pageConfigGlobal: {
|
|
208
|
-
|
|
209
|
-
onBeforeRoute: null
|
|
207
|
+
configValueSources: {}
|
|
210
208
|
},
|
|
211
209
|
globalVikeConfig: {}
|
|
212
210
|
};
|
|
@@ -226,18 +224,18 @@ async function loadVikeConfig(userRootDir, isDev, extensions) {
|
|
|
226
224
|
await Promise.all(getInterfaceFileList(interfaceFilesRelevant).map(async (interfaceFile) => {
|
|
227
225
|
if (!interfaceFile.isValueFile)
|
|
228
226
|
return;
|
|
229
|
-
const {
|
|
230
|
-
if (isGlobalConfig(
|
|
227
|
+
const { configName } = interfaceFile;
|
|
228
|
+
if (isGlobalConfig(configName))
|
|
231
229
|
return;
|
|
232
|
-
const configDef = getConfigDefinition(configDefinitionsRelevant,
|
|
230
|
+
const configDef = getConfigDefinition(configDefinitionsRelevant, configName, (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(interfaceFile.filePath));
|
|
233
231
|
if (configDef.env !== 'config-only')
|
|
234
232
|
return;
|
|
235
233
|
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
236
234
|
if (isAlreadyLoaded)
|
|
237
235
|
return;
|
|
238
236
|
// 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,
|
|
237
|
+
(0, utils_js_1.assert)(!(configName in configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn));
|
|
238
|
+
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
241
239
|
}));
|
|
242
240
|
const configValueSources = {};
|
|
243
241
|
(0, utils_js_1.objectEntries)(configDefinitionsRelevant)
|
|
@@ -331,17 +329,16 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
|
331
329
|
}
|
|
332
330
|
const globalVikeConfig = {};
|
|
333
331
|
const pageConfigGlobal = {
|
|
334
|
-
|
|
335
|
-
onPrerenderStart: null
|
|
332
|
+
configValueSources: {}
|
|
336
333
|
};
|
|
337
334
|
(0, utils_js_1.objectEntries)(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal).forEach(([configName, configDef]) => {
|
|
338
335
|
const sources = resolveConfigValueSources(configName, configDef, interfaceFilesGlobal, userRootDir);
|
|
339
336
|
const configValueSource = sources?.[0];
|
|
340
337
|
if (!configValueSource)
|
|
341
338
|
return;
|
|
342
|
-
if (
|
|
339
|
+
if (configName === 'onBeforeRoute' || configName === 'onPrerenderStart') {
|
|
343
340
|
(0, utils_js_1.assert)(!('value' in configValueSource));
|
|
344
|
-
pageConfigGlobal[configName] = configValueSource;
|
|
341
|
+
pageConfigGlobal.configValueSources[configName] = [configValueSource];
|
|
345
342
|
}
|
|
346
343
|
else {
|
|
347
344
|
(0, utils_js_1.assert)('value' in configValueSource);
|
|
@@ -374,7 +371,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
374
371
|
const interfaceValueFiles = interfaceFilesDefiningConfig
|
|
375
372
|
.filter((interfaceFile) => interfaceFile.isValueFile &&
|
|
376
373
|
// We consider side-effect exports (e.g. `export { frontmatter }` of .mdx files) later (i.e. with less priority)
|
|
377
|
-
interfaceFile.
|
|
374
|
+
interfaceFile.configName === configName)
|
|
378
375
|
.sort(makeOrderDeterministic);
|
|
379
376
|
const interfaceConfigFiles = interfaceFilesDefiningConfig
|
|
380
377
|
.filter((interfaceFile) => interfaceFile.isConfigFile &&
|
|
@@ -384,9 +381,9 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
384
381
|
const interfaceValueFile = interfaceValueFiles[0];
|
|
385
382
|
const interfaceConfigFile = interfaceConfigFiles[0];
|
|
386
383
|
// Make this value:
|
|
387
|
-
// /pages/some-page/+
|
|
384
|
+
// /pages/some-page/+{configName}.js > `export default`
|
|
388
385
|
// override that value:
|
|
389
|
-
// /pages/some-page/+config > `export default { someConfig }`
|
|
386
|
+
// /pages/some-page/+config.h.js > `export default { someConfig }`
|
|
390
387
|
const interfaceFileWinner = interfaceValueFile ?? interfaceConfigFile;
|
|
391
388
|
if (interfaceFileWinner) {
|
|
392
389
|
const interfaceFilesOverriden = [...interfaceValueFiles, ...interfaceConfigFiles].filter((f) => f !== interfaceFileWinner);
|
|
@@ -401,7 +398,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
401
398
|
interfaceFilesDefiningConfig
|
|
402
399
|
.filter((interfaceFile) => interfaceFile.isValueFile &&
|
|
403
400
|
// Is side-effect export
|
|
404
|
-
interfaceFile.
|
|
401
|
+
interfaceFile.configName !== configName)
|
|
405
402
|
.forEach((interfaceValueFileSideEffect) => {
|
|
406
403
|
add(interfaceValueFileSideEffect);
|
|
407
404
|
});
|
|
@@ -439,22 +436,22 @@ function isInterfaceFileUserLand(interfaceFile) {
|
|
|
439
436
|
}
|
|
440
437
|
function getConfigValueSource(configName, interfaceFile, configDef, userRootDir) {
|
|
441
438
|
// TODO: rethink file paths of ConfigElement
|
|
442
|
-
const
|
|
439
|
+
const filePathToShowToUser = interfaceFile.filePath.filePathRelativeToUserRootDir ?? interfaceFile.filePath.filePathAbsolute;
|
|
443
440
|
const conf = interfaceFile.configMap[configName];
|
|
444
441
|
(0, utils_js_1.assert)(conf);
|
|
445
442
|
const configEnv = configDef.env;
|
|
446
443
|
const definedAtInfoConfigFile = {
|
|
447
|
-
filePath:
|
|
444
|
+
filePath: filePathToShowToUser,
|
|
448
445
|
fileExportPath: ['default', configName]
|
|
449
446
|
};
|
|
450
447
|
if (configDef._valueIsFilePath) {
|
|
451
448
|
let filePath;
|
|
452
449
|
if (interfaceFile.isConfigFile) {
|
|
453
450
|
const { configValue } = conf;
|
|
454
|
-
const import_ =
|
|
451
|
+
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
455
452
|
const configDefinedAt = (0, utils_js_2.getConfigDefinedAtString)(configName, { definedAtInfo: definedAtInfoConfigFile }, true);
|
|
456
453
|
(0, utils_js_1.assertUsage)(import_, `${configDefinedAt} should be an import`);
|
|
457
|
-
filePath = import_.
|
|
454
|
+
filePath = import_.filePathToShowToUser;
|
|
458
455
|
}
|
|
459
456
|
else {
|
|
460
457
|
(0, utils_js_1.assert)(interfaceFile.isValueFile);
|
|
@@ -479,17 +476,16 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
479
476
|
if (interfaceFile.isConfigFile) {
|
|
480
477
|
(0, utils_js_1.assert)('configValue' in conf);
|
|
481
478
|
const { configValue } = conf;
|
|
482
|
-
const import_ =
|
|
479
|
+
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
483
480
|
if (import_) {
|
|
484
|
-
const {
|
|
485
|
-
assertCodeFileEnv(importFilePath, configEnv, configName);
|
|
481
|
+
const { filePathToShowToUser, fileExportName: exportName } = import_;
|
|
486
482
|
const configValueSource = {
|
|
487
483
|
configEnv,
|
|
488
484
|
valueIsImportedAtRuntime: true,
|
|
489
485
|
isComputed: false,
|
|
490
486
|
definedAtInfo: {
|
|
491
|
-
filePath:
|
|
492
|
-
fileExportPath: [
|
|
487
|
+
filePath: filePathToShowToUser,
|
|
488
|
+
fileExportPath: [exportName]
|
|
493
489
|
}
|
|
494
490
|
};
|
|
495
491
|
return configValueSource;
|
|
@@ -507,16 +503,16 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
507
503
|
}
|
|
508
504
|
else if (interfaceFile.isValueFile) {
|
|
509
505
|
// TODO: rethink file paths of ConfigElement
|
|
510
|
-
const
|
|
511
|
-
const
|
|
506
|
+
const importPath = interfaceFile.filePath.filePathRelativeToUserRootDir ?? interfaceFile.filePath.filePathAbsolute;
|
|
507
|
+
const exportName = configName === interfaceFile.configName ? 'default' : configName;
|
|
512
508
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
513
509
|
const configValueSource = {
|
|
514
510
|
configEnv,
|
|
515
511
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
516
512
|
isComputed: false,
|
|
517
513
|
definedAtInfo: {
|
|
518
|
-
filePath:
|
|
519
|
-
fileExportPath: [
|
|
514
|
+
filePath: importPath,
|
|
515
|
+
fileExportPath: [exportName]
|
|
520
516
|
}
|
|
521
517
|
};
|
|
522
518
|
if (valueAlreadyLoaded) {
|
|
@@ -529,16 +525,17 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
529
525
|
}
|
|
530
526
|
(0, utils_js_1.assert)(false);
|
|
531
527
|
}
|
|
532
|
-
function
|
|
533
|
-
|
|
534
|
-
|
|
528
|
+
function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
|
|
529
|
+
(0, utils_js_1.assertPosixPath)(filePathForEnvCheck);
|
|
530
|
+
if (!filesEnv.has(filePathForEnvCheck)) {
|
|
531
|
+
filesEnv.set(filePathForEnvCheck, []);
|
|
535
532
|
}
|
|
536
|
-
const
|
|
537
|
-
|
|
538
|
-
const configDifferentEnv =
|
|
533
|
+
const fileEnv = filesEnv.get(filePathForEnvCheck);
|
|
534
|
+
fileEnv.push({ configEnv, configName });
|
|
535
|
+
const configDifferentEnv = fileEnv.filter((c) => c.configEnv !== configEnv)[0];
|
|
539
536
|
if (configDifferentEnv) {
|
|
540
537
|
(0, utils_js_1.assertUsage)(false, [
|
|
541
|
-
`${
|
|
538
|
+
`${filePathForEnvCheck} defines the value of configs living in different environments:`,
|
|
542
539
|
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${picocolors_1.default.cyan(c.configName)} which value lives in environment ${picocolors_1.default.cyan(c.configEnv)}`),
|
|
543
540
|
'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
541
|
].join('\n'));
|
|
@@ -556,53 +553,60 @@ function isDefiningPage(interfaceFiles) {
|
|
|
556
553
|
function isDefiningPageConfig(configName) {
|
|
557
554
|
return ['Page', 'route'].includes(configName);
|
|
558
555
|
}
|
|
559
|
-
function
|
|
556
|
+
function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
560
557
|
if (typeof configValue !== 'string')
|
|
561
558
|
return null;
|
|
562
559
|
const importData = (0, replaceImportStatements_js_1.parseImportData)(configValue);
|
|
563
560
|
if (!importData)
|
|
564
561
|
return null;
|
|
565
|
-
|
|
566
|
-
|
|
562
|
+
const { importPath, exportName } = importData;
|
|
563
|
+
const filePathAbsolute = resolveImportPath(importData, importerFilePath);
|
|
564
|
+
let filePathToShowToUser;
|
|
565
|
+
if (importPath.startsWith('.')) {
|
|
567
566
|
// We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
|
|
568
567
|
// ```
|
|
569
568
|
// [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
|
|
570
569
|
// ```
|
|
571
|
-
|
|
570
|
+
assertImportPath(filePathAbsolute, importData, importerFilePath);
|
|
571
|
+
const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, importerFilePath, userRootDir);
|
|
572
|
+
filePathToShowToUser = filePathRelativeToUserRootDir;
|
|
572
573
|
}
|
|
573
574
|
else {
|
|
574
|
-
//
|
|
575
|
+
// importPath can be:
|
|
575
576
|
// - an npm package import
|
|
576
577
|
// - a path alias
|
|
578
|
+
filePathToShowToUser = importPath;
|
|
579
|
+
}
|
|
580
|
+
{
|
|
581
|
+
const filePathForEnvCheck = filePathAbsolute ?? importPath;
|
|
582
|
+
assertFileEnv(filePathForEnvCheck, configEnv, configName);
|
|
577
583
|
}
|
|
578
584
|
return {
|
|
579
|
-
|
|
580
|
-
|
|
585
|
+
filePathToShowToUser,
|
|
586
|
+
fileExportName: exportName
|
|
581
587
|
};
|
|
582
588
|
}
|
|
583
|
-
function
|
|
584
|
-
let importFilePath = resolveImport(importData, configFilePath);
|
|
585
|
-
// Make it a Vite path
|
|
589
|
+
function resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, configFilePath, userRootDir) {
|
|
586
590
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
587
|
-
|
|
588
|
-
if (
|
|
589
|
-
|
|
591
|
+
let filePathRelativeToUserRootDir;
|
|
592
|
+
if (filePathAbsolute.startsWith(userRootDir)) {
|
|
593
|
+
filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsolute, userRootDir);
|
|
590
594
|
}
|
|
591
595
|
else {
|
|
592
|
-
(0, utils_js_1.assertUsage)(false, `${(0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(configFilePath)} imports from a relative path ${picocolors_1.default.cyan(importData.
|
|
596
|
+
(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
597
|
// None of the following works. Seems to be a Vite bug?
|
|
594
598
|
// /*
|
|
595
|
-
// assert(
|
|
596
|
-
//
|
|
599
|
+
// assert(filePathAbsolute.startsWith('/'))
|
|
600
|
+
// filePath = `/@fs${filePathAbsolute}`
|
|
597
601
|
// /*/
|
|
598
|
-
//
|
|
599
|
-
// assert(
|
|
600
|
-
//
|
|
602
|
+
// filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsolute)
|
|
603
|
+
// assert(filePathRelativeToUserRootDir.startsWith('../'))
|
|
604
|
+
// filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir
|
|
601
605
|
// //*/
|
|
602
606
|
}
|
|
603
|
-
(0, utils_js_1.assertPosixPath)(
|
|
604
|
-
(0, utils_js_1.assert)(
|
|
605
|
-
return
|
|
607
|
+
(0, utils_js_1.assertPosixPath)(filePathRelativeToUserRootDir);
|
|
608
|
+
(0, utils_js_1.assert)(filePathRelativeToUserRootDir.startsWith('/'));
|
|
609
|
+
return filePathRelativeToUserRootDir;
|
|
606
610
|
}
|
|
607
611
|
function getVitePathFromAbsolutePath(filePathAbsolute, root) {
|
|
608
612
|
(0, utils_js_1.assertPosixPath)(filePathAbsolute);
|
|
@@ -714,10 +718,9 @@ function applyEffect(configModFromEffect, configValueEffectSource, configValueSo
|
|
|
714
718
|
function applyComputed(pageConfig, configDefinitionsRelevant) {
|
|
715
719
|
(0, utils_js_1.objectEntries)(configDefinitionsRelevant).forEach(([configName, configDef]) => {
|
|
716
720
|
var _a;
|
|
717
|
-
|
|
718
|
-
if (!computed)
|
|
721
|
+
if (!configDef._computed)
|
|
719
722
|
return;
|
|
720
|
-
const value =
|
|
723
|
+
const value = configDef._computed(pageConfig);
|
|
721
724
|
if (value === undefined)
|
|
722
725
|
return;
|
|
723
726
|
const configValueSource = {
|
|
@@ -801,7 +804,7 @@ function assertNoUnexpectedPlusSign(filePath, fileName) {
|
|
|
801
804
|
(0, utils_js_1.assertUsage)(!fileName.slice(1).includes('+'), `Character '+' is only allowed at the beginning of filenames: make sure ${filePath} doesn't contain any '+' in its filename other than its first letter`);
|
|
802
805
|
}
|
|
803
806
|
async function loadConfigFile(configFilePath, userRootDir, visited) {
|
|
804
|
-
const { filePathAbsolute
|
|
807
|
+
const { filePathAbsolute } = configFilePath;
|
|
805
808
|
assertNoInfiniteLoop(visited, filePathAbsolute);
|
|
806
809
|
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(configFilePath, false, userRootDir);
|
|
807
810
|
const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
|
|
@@ -810,10 +813,7 @@ async function loadConfigFile(configFilePath, userRootDir, visited) {
|
|
|
810
813
|
]);
|
|
811
814
|
const configFile = {
|
|
812
815
|
fileExports,
|
|
813
|
-
filePath:
|
|
814
|
-
filePathRelativeToUserRootDir,
|
|
815
|
-
filePathAbsolute
|
|
816
|
-
},
|
|
816
|
+
filePath: configFilePath,
|
|
817
817
|
extendsFilePaths
|
|
818
818
|
};
|
|
819
819
|
return { configFile, extendsConfigs };
|
|
@@ -830,16 +830,20 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
830
830
|
const extendsImportData = getExtendsImportData(configFileExports, configFilePath);
|
|
831
831
|
const extendsConfigFiles = [];
|
|
832
832
|
extendsImportData.map((importData) => {
|
|
833
|
-
const {
|
|
833
|
+
const { importPath: importPath } = importData;
|
|
834
834
|
// TODO
|
|
835
835
|
// - validate extends configs
|
|
836
|
-
const filePathAbsolute =
|
|
836
|
+
const filePathAbsolute = resolveImportPath(importData, configFilePath);
|
|
837
|
+
assertImportPath(filePathAbsolute, importData, configFilePath);
|
|
837
838
|
assertExtendsImportPath(importPath, filePathAbsolute, configFilePath);
|
|
839
|
+
// - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
|
|
840
|
+
// - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsolute for added clarity
|
|
841
|
+
const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsolute, userRootDir);
|
|
838
842
|
extendsConfigFiles.push({
|
|
839
843
|
filePathAbsolute,
|
|
840
|
-
//
|
|
841
|
-
|
|
842
|
-
|
|
844
|
+
// TODO: fix type cast
|
|
845
|
+
filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
|
|
846
|
+
importPathAbsolute: importPath
|
|
843
847
|
});
|
|
844
848
|
});
|
|
845
849
|
const extendsConfigs = [];
|
|
@@ -879,7 +883,7 @@ function assertExtendsImportPath(importPath, filePath, configFilePath) {
|
|
|
879
883
|
}
|
|
880
884
|
function getExtendsImportData(configFileExports, configFilePath) {
|
|
881
885
|
const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(configFilePath);
|
|
882
|
-
(0,
|
|
886
|
+
(0, assertExports_js_1.assertExportsOfConfigFile)(configFileExports, filePathToShowToUser);
|
|
883
887
|
const defaultExports = configFileExports.default;
|
|
884
888
|
const wrongUsage = `${filePathToShowToUser} sets the config 'extends' to an invalid value, see https://vike.dev/extends`;
|
|
885
889
|
let extendList;
|
|
@@ -959,13 +963,16 @@ function handleUnknownConfig(configName, configNames, definedByFile) {
|
|
|
959
963
|
else {
|
|
960
964
|
configNameSimilar = (0, utils_js_1.getMostSimilar)(configName, configNames);
|
|
961
965
|
}
|
|
962
|
-
if (configNameSimilar) {
|
|
966
|
+
if (configNameSimilar || configName === 'page') {
|
|
967
|
+
(0, utils_js_1.assert)(configNameSimilar);
|
|
963
968
|
(0, utils_js_1.assert)(configNameSimilar !== configName);
|
|
964
969
|
errMsg += `, did you mean to define ${picocolors_1.default.cyan(configNameSimilar)} instead?`;
|
|
970
|
+
if (configName === 'page') {
|
|
971
|
+
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
|
+
}
|
|
965
973
|
}
|
|
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.)`;
|
|
974
|
+
else {
|
|
975
|
+
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
976
|
}
|
|
970
977
|
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
971
978
|
}
|
|
@@ -974,7 +981,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
974
981
|
const configFilesystemRoutingRoot = configValueSources[configName]?.[0];
|
|
975
982
|
let filesystemRouteString = (0, filesystemRouting_js_1.getFilesystemRouteString)(locationId);
|
|
976
983
|
if (determineIsErrorPage(filesystemRouteString)) {
|
|
977
|
-
return { isErrorPage: true, routeFilesystem:
|
|
984
|
+
return { isErrorPage: true, routeFilesystem: undefined };
|
|
978
985
|
}
|
|
979
986
|
let filesystemRouteDefinedBy = (0, filesystemRouting_js_1.getFilesystemRouteDefinedBy)(locationId); // for log404()
|
|
980
987
|
if (configFilesystemRoutingRoot) {
|
|
@@ -992,7 +999,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
992
999
|
routeString: filesystemRouteString,
|
|
993
1000
|
definedBy: filesystemRouteDefinedBy
|
|
994
1001
|
};
|
|
995
|
-
return { routeFilesystem, isErrorPage:
|
|
1002
|
+
return { routeFilesystem, isErrorPage: undefined };
|
|
996
1003
|
}
|
|
997
1004
|
function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName) {
|
|
998
1005
|
(0, utils_js_1.assert)(configFilesystemRoutingRoot.configEnv === 'config-only');
|
|
@@ -1012,33 +1019,22 @@ function determineIsErrorPage(routeFilesystem) {
|
|
|
1012
1019
|
(0, utils_js_1.assertPosixPath)(routeFilesystem);
|
|
1013
1020
|
return routeFilesystem.split('/').includes('_error');
|
|
1014
1021
|
}
|
|
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;
|
|
1022
|
+
function resolveImportPath(importData, importerFilePath) {
|
|
1023
|
+
const importerFilePathAbsolute = importerFilePath.filePathAbsolute;
|
|
1024
|
+
(0, utils_js_1.assertPosixPath)(importerFilePathAbsolute);
|
|
1025
|
+
const cwd = path_1.default.posix.dirname(importerFilePathAbsolute);
|
|
1026
|
+
// filePathAbsolute is expected to be null when importData.importPath is a Vite path alias
|
|
1027
|
+
const filePathAbsolute = (0, utils_js_1.requireResolve)(importData.importPath, cwd);
|
|
1028
|
+
return filePathAbsolute;
|
|
1033
1029
|
}
|
|
1034
|
-
function
|
|
1035
|
-
const {
|
|
1030
|
+
function assertImportPath(filePathAbsolute, importData, importerFilePath) {
|
|
1031
|
+
const { importPath: importPath, importStringWasGenerated, importString } = importData;
|
|
1036
1032
|
const filePathToShowToUser = (0, getFilePathToShowToUser_js_1.getFilePathToShowToUser)(importerFilePath);
|
|
1037
|
-
if (!
|
|
1033
|
+
if (!filePathAbsolute) {
|
|
1038
1034
|
const importPathString = picocolors_1.default.cyan(`'${importPath}'`);
|
|
1039
|
-
const errIntro =
|
|
1035
|
+
const errIntro = importStringWasGenerated
|
|
1040
1036
|
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
1041
|
-
: `The import ${picocolors_1.default.cyan(
|
|
1037
|
+
: `The import ${picocolors_1.default.cyan(importString)} defined in ${filePathToShowToUser}`;
|
|
1042
1038
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
1043
1039
|
if (importPath.startsWith('.')) {
|
|
1044
1040
|
(0, utils_js_1.assertUsage)(false, `${errIntro2} point to an existing file?`);
|
|
@@ -1090,6 +1086,8 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1090
1086
|
/* This is more confusing than adding value. For example, this explanation shouldn't be shown for the passToClient config.
|
|
1091
1087
|
const explanation = `(Because the values of ${configNameColored} are cumulative and therefore merged together.)` as const
|
|
1092
1088
|
*/
|
|
1089
|
+
// Make sure configValueSource.value is serializable
|
|
1090
|
+
(0, getVirtualFilePageConfigs_js_1.getConfigValueSerialized)(configValueSource.value, configName, configValueSource.definedAtInfo);
|
|
1093
1091
|
const assertNoMixing = (isSet) => {
|
|
1094
1092
|
const vals1 = isSet ? valuesSet : valuesArr;
|
|
1095
1093
|
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;
|