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
|
@@ -2,7 +2,7 @@ export { getVikeConfig };
|
|
|
2
2
|
export { reloadVikeConfig };
|
|
3
3
|
export { vikeConfigDependencies };
|
|
4
4
|
export { isVikeConfigFile };
|
|
5
|
-
import { assertPosixPath, assert, isObject, assertUsage, toPosixPath, assertWarning,
|
|
5
|
+
import { assertPosixPath, assert, isObject, assertUsage, toPosixPath, assertWarning, objectEntries, hasProp, arrayIncludes, assertIsNotProductionRuntime, getMostSimilar, isNpmPackageImport, joinEnglish, lowerFirst, scriptFileExtensions, mergeCumulativeValues, requireResolve } from '../../../utils.js';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { configDefinitionsBuiltIn, configDefinitionsBuiltInGlobal } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
8
8
|
import glob from 'fast-glob';
|
|
@@ -15,20 +15,18 @@ import { logConfigError, logConfigErrorRecover } from '../../../shared/loggerNot
|
|
|
15
15
|
import { removeSuperfluousViteLog_enable, removeSuperfluousViteLog_disable } from '../../../shared/loggerVite/removeSuperfluousViteLog.js';
|
|
16
16
|
import { getFilePathToShowToUser } from './getFilePathToShowToUser.js';
|
|
17
17
|
import pc from '@brillout/picocolors';
|
|
18
|
-
import { createRequire } from 'module';
|
|
19
18
|
import { getConfigDefinedAtString } from '../../../../../shared/page-configs/utils.js';
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const require_ = createRequire(importMetaUrl);
|
|
19
|
+
import { assertExportsOfConfigFile, assertExportsOfValueFile } from '../../../../../shared/page-configs/assertExports.js';
|
|
20
|
+
import { getConfigValueSerialized } from './getVirtualFilePageConfigs.js';
|
|
23
21
|
assertIsNotProductionRuntime();
|
|
24
22
|
let devServerIsCorrupt = false;
|
|
25
23
|
let wasConfigInvalid = null;
|
|
26
24
|
let vikeConfigPromise = null;
|
|
27
25
|
const vikeConfigDependencies = new Set();
|
|
28
|
-
const
|
|
26
|
+
const filesEnv = new Map();
|
|
29
27
|
function reloadVikeConfig(userRootDir, extensions) {
|
|
30
28
|
vikeConfigDependencies.clear();
|
|
31
|
-
|
|
29
|
+
filesEnv.clear();
|
|
32
30
|
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, true, extensions, true);
|
|
33
31
|
handleReloadSideEffects();
|
|
34
32
|
}
|
|
@@ -86,7 +84,8 @@ async function loadInterfaceFiles(userRootDir, isDev, extensions) {
|
|
|
86
84
|
await Promise.all(configFiles.map(async ({ filePathAbsolute, filePathRelativeToUserRootDir }) => {
|
|
87
85
|
const configFilePath = {
|
|
88
86
|
filePathAbsolute: filePathAbsolute,
|
|
89
|
-
filePathRelativeToUserRootDir: filePathRelativeToUserRootDir
|
|
87
|
+
filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
|
|
88
|
+
importPathAbsolute: null
|
|
90
89
|
};
|
|
91
90
|
const { configFile, extendsConfigs } = await loadConfigFile(configFilePath, userRootDir, []);
|
|
92
91
|
const interfaceFile = getInterfaceFileFromConfigFile(configFile, false);
|
|
@@ -100,27 +99,28 @@ async function loadInterfaceFiles(userRootDir, isDev, extensions) {
|
|
|
100
99
|
}));
|
|
101
100
|
// Value files
|
|
102
101
|
await Promise.all(valueFiles.map(async ({ filePathAbsolute, filePathRelativeToUserRootDir }) => {
|
|
103
|
-
const
|
|
104
|
-
assert(
|
|
102
|
+
const configName = getConfigName(filePathRelativeToUserRootDir);
|
|
103
|
+
assert(configName);
|
|
105
104
|
const interfaceFile = {
|
|
106
105
|
filePath: {
|
|
107
106
|
filePathRelativeToUserRootDir,
|
|
108
|
-
filePathAbsolute
|
|
107
|
+
filePathAbsolute,
|
|
108
|
+
importPathAbsolute: null
|
|
109
109
|
},
|
|
110
110
|
configMap: {
|
|
111
|
-
[
|
|
111
|
+
[configName]: {}
|
|
112
112
|
},
|
|
113
113
|
isConfigFile: false,
|
|
114
114
|
isValueFile: true,
|
|
115
|
-
|
|
115
|
+
configName
|
|
116
116
|
};
|
|
117
117
|
{
|
|
118
118
|
// We don't have access to custom config definitions yet
|
|
119
|
-
// - We load +
|
|
119
|
+
// - We load +{configName}.js later
|
|
120
120
|
// - But we do need to eagerly load +meta.js (to get all the custom config definitions)
|
|
121
|
-
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn,
|
|
121
|
+
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn, configName);
|
|
122
122
|
if (configDef?.env === 'config-only') {
|
|
123
|
-
await loadValueFile(interfaceFile,
|
|
123
|
+
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
{
|
|
@@ -140,14 +140,13 @@ function getConfigDefinition(configDefinitionsRelevant, configName, definedByFil
|
|
|
140
140
|
function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
141
141
|
return configDefinitions[configName] ?? null;
|
|
142
142
|
}
|
|
143
|
-
async function loadValueFile(interfaceValueFile,
|
|
143
|
+
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
144
144
|
const { fileExports } = await transpileAndExecuteFile(interfaceValueFile.filePath, true, userRootDir);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
interfaceValueFile.configMap[configName] = { configValue };
|
|
145
|
+
const filePathToShowToUser = getFilePathToShowToUser(interfaceValueFile.filePath);
|
|
146
|
+
assertExportsOfValueFile(fileExports, filePathToShowToUser, configName);
|
|
147
|
+
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
148
|
+
const configName_ = exportName === 'default' ? configName : exportName;
|
|
149
|
+
interfaceValueFile.configMap[configName_] = { configValue };
|
|
151
150
|
});
|
|
152
151
|
}
|
|
153
152
|
function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
@@ -160,8 +159,8 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
160
159
|
isConfigExtend,
|
|
161
160
|
extendsFilePaths
|
|
162
161
|
};
|
|
163
|
-
const
|
|
164
|
-
|
|
162
|
+
const filePathToShowToUser = getFilePathToShowToUser(filePath);
|
|
163
|
+
assertExportsOfConfigFile(fileExports, filePathToShowToUser);
|
|
165
164
|
Object.entries(fileExports.default).forEach(([configName, configValue]) => {
|
|
166
165
|
interfaceFile.configMap[configName] = { configValue };
|
|
167
166
|
});
|
|
@@ -200,8 +199,7 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, extensions,
|
|
|
200
199
|
const dummyData = {
|
|
201
200
|
pageConfigs: [],
|
|
202
201
|
pageConfigGlobal: {
|
|
203
|
-
|
|
204
|
-
onBeforeRoute: null
|
|
202
|
+
configValueSources: {}
|
|
205
203
|
},
|
|
206
204
|
globalVikeConfig: {}
|
|
207
205
|
};
|
|
@@ -221,18 +219,18 @@ async function loadVikeConfig(userRootDir, isDev, extensions) {
|
|
|
221
219
|
await Promise.all(getInterfaceFileList(interfaceFilesRelevant).map(async (interfaceFile) => {
|
|
222
220
|
if (!interfaceFile.isValueFile)
|
|
223
221
|
return;
|
|
224
|
-
const {
|
|
225
|
-
if (isGlobalConfig(
|
|
222
|
+
const { configName } = interfaceFile;
|
|
223
|
+
if (isGlobalConfig(configName))
|
|
226
224
|
return;
|
|
227
|
-
const configDef = getConfigDefinition(configDefinitionsRelevant,
|
|
225
|
+
const configDef = getConfigDefinition(configDefinitionsRelevant, configName, getFilePathToShowToUser(interfaceFile.filePath));
|
|
228
226
|
if (configDef.env !== 'config-only')
|
|
229
227
|
return;
|
|
230
228
|
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
231
229
|
if (isAlreadyLoaded)
|
|
232
230
|
return;
|
|
233
231
|
// Value files for built-in confg-only configs should have already been loaded at loadInterfaceFiles()
|
|
234
|
-
assert(!(
|
|
235
|
-
await loadValueFile(interfaceFile,
|
|
232
|
+
assert(!(configName in configDefinitionsBuiltIn));
|
|
233
|
+
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
236
234
|
}));
|
|
237
235
|
const configValueSources = {};
|
|
238
236
|
objectEntries(configDefinitionsRelevant)
|
|
@@ -326,17 +324,16 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
|
326
324
|
}
|
|
327
325
|
const globalVikeConfig = {};
|
|
328
326
|
const pageConfigGlobal = {
|
|
329
|
-
|
|
330
|
-
onPrerenderStart: null
|
|
327
|
+
configValueSources: {}
|
|
331
328
|
};
|
|
332
329
|
objectEntries(configDefinitionsBuiltInGlobal).forEach(([configName, configDef]) => {
|
|
333
330
|
const sources = resolveConfigValueSources(configName, configDef, interfaceFilesGlobal, userRootDir);
|
|
334
331
|
const configValueSource = sources?.[0];
|
|
335
332
|
if (!configValueSource)
|
|
336
333
|
return;
|
|
337
|
-
if (
|
|
334
|
+
if (configName === 'onBeforeRoute' || configName === 'onPrerenderStart') {
|
|
338
335
|
assert(!('value' in configValueSource));
|
|
339
|
-
pageConfigGlobal[configName] = configValueSource;
|
|
336
|
+
pageConfigGlobal.configValueSources[configName] = [configValueSource];
|
|
340
337
|
}
|
|
341
338
|
else {
|
|
342
339
|
assert('value' in configValueSource);
|
|
@@ -369,7 +366,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
369
366
|
const interfaceValueFiles = interfaceFilesDefiningConfig
|
|
370
367
|
.filter((interfaceFile) => interfaceFile.isValueFile &&
|
|
371
368
|
// We consider side-effect exports (e.g. `export { frontmatter }` of .mdx files) later (i.e. with less priority)
|
|
372
|
-
interfaceFile.
|
|
369
|
+
interfaceFile.configName === configName)
|
|
373
370
|
.sort(makeOrderDeterministic);
|
|
374
371
|
const interfaceConfigFiles = interfaceFilesDefiningConfig
|
|
375
372
|
.filter((interfaceFile) => interfaceFile.isConfigFile &&
|
|
@@ -379,9 +376,9 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
379
376
|
const interfaceValueFile = interfaceValueFiles[0];
|
|
380
377
|
const interfaceConfigFile = interfaceConfigFiles[0];
|
|
381
378
|
// Make this value:
|
|
382
|
-
// /pages/some-page/+
|
|
379
|
+
// /pages/some-page/+{configName}.js > `export default`
|
|
383
380
|
// override that value:
|
|
384
|
-
// /pages/some-page/+config > `export default { someConfig }`
|
|
381
|
+
// /pages/some-page/+config.h.js > `export default { someConfig }`
|
|
385
382
|
const interfaceFileWinner = interfaceValueFile ?? interfaceConfigFile;
|
|
386
383
|
if (interfaceFileWinner) {
|
|
387
384
|
const interfaceFilesOverriden = [...interfaceValueFiles, ...interfaceConfigFiles].filter((f) => f !== interfaceFileWinner);
|
|
@@ -396,7 +393,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
396
393
|
interfaceFilesDefiningConfig
|
|
397
394
|
.filter((interfaceFile) => interfaceFile.isValueFile &&
|
|
398
395
|
// Is side-effect export
|
|
399
|
-
interfaceFile.
|
|
396
|
+
interfaceFile.configName !== configName)
|
|
400
397
|
.forEach((interfaceValueFileSideEffect) => {
|
|
401
398
|
add(interfaceValueFileSideEffect);
|
|
402
399
|
});
|
|
@@ -434,22 +431,22 @@ function isInterfaceFileUserLand(interfaceFile) {
|
|
|
434
431
|
}
|
|
435
432
|
function getConfigValueSource(configName, interfaceFile, configDef, userRootDir) {
|
|
436
433
|
// TODO: rethink file paths of ConfigElement
|
|
437
|
-
const
|
|
434
|
+
const filePathToShowToUser = interfaceFile.filePath.filePathRelativeToUserRootDir ?? interfaceFile.filePath.filePathAbsolute;
|
|
438
435
|
const conf = interfaceFile.configMap[configName];
|
|
439
436
|
assert(conf);
|
|
440
437
|
const configEnv = configDef.env;
|
|
441
438
|
const definedAtInfoConfigFile = {
|
|
442
|
-
filePath:
|
|
439
|
+
filePath: filePathToShowToUser,
|
|
443
440
|
fileExportPath: ['default', configName]
|
|
444
441
|
};
|
|
445
442
|
if (configDef._valueIsFilePath) {
|
|
446
443
|
let filePath;
|
|
447
444
|
if (interfaceFile.isConfigFile) {
|
|
448
445
|
const { configValue } = conf;
|
|
449
|
-
const import_ =
|
|
446
|
+
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
450
447
|
const configDefinedAt = getConfigDefinedAtString(configName, { definedAtInfo: definedAtInfoConfigFile }, true);
|
|
451
448
|
assertUsage(import_, `${configDefinedAt} should be an import`);
|
|
452
|
-
filePath = import_.
|
|
449
|
+
filePath = import_.filePathToShowToUser;
|
|
453
450
|
}
|
|
454
451
|
else {
|
|
455
452
|
assert(interfaceFile.isValueFile);
|
|
@@ -474,17 +471,16 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
474
471
|
if (interfaceFile.isConfigFile) {
|
|
475
472
|
assert('configValue' in conf);
|
|
476
473
|
const { configValue } = conf;
|
|
477
|
-
const import_ =
|
|
474
|
+
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
478
475
|
if (import_) {
|
|
479
|
-
const {
|
|
480
|
-
assertCodeFileEnv(importFilePath, configEnv, configName);
|
|
476
|
+
const { filePathToShowToUser, fileExportName: exportName } = import_;
|
|
481
477
|
const configValueSource = {
|
|
482
478
|
configEnv,
|
|
483
479
|
valueIsImportedAtRuntime: true,
|
|
484
480
|
isComputed: false,
|
|
485
481
|
definedAtInfo: {
|
|
486
|
-
filePath:
|
|
487
|
-
fileExportPath: [
|
|
482
|
+
filePath: filePathToShowToUser,
|
|
483
|
+
fileExportPath: [exportName]
|
|
488
484
|
}
|
|
489
485
|
};
|
|
490
486
|
return configValueSource;
|
|
@@ -502,16 +498,16 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
502
498
|
}
|
|
503
499
|
else if (interfaceFile.isValueFile) {
|
|
504
500
|
// TODO: rethink file paths of ConfigElement
|
|
505
|
-
const
|
|
506
|
-
const
|
|
501
|
+
const importPath = interfaceFile.filePath.filePathRelativeToUserRootDir ?? interfaceFile.filePath.filePathAbsolute;
|
|
502
|
+
const exportName = configName === interfaceFile.configName ? 'default' : configName;
|
|
507
503
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
508
504
|
const configValueSource = {
|
|
509
505
|
configEnv,
|
|
510
506
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
511
507
|
isComputed: false,
|
|
512
508
|
definedAtInfo: {
|
|
513
|
-
filePath:
|
|
514
|
-
fileExportPath: [
|
|
509
|
+
filePath: importPath,
|
|
510
|
+
fileExportPath: [exportName]
|
|
515
511
|
}
|
|
516
512
|
};
|
|
517
513
|
if (valueAlreadyLoaded) {
|
|
@@ -524,16 +520,17 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
524
520
|
}
|
|
525
521
|
assert(false);
|
|
526
522
|
}
|
|
527
|
-
function
|
|
528
|
-
|
|
529
|
-
|
|
523
|
+
function assertFileEnv(filePathForEnvCheck, configEnv, configName) {
|
|
524
|
+
assertPosixPath(filePathForEnvCheck);
|
|
525
|
+
if (!filesEnv.has(filePathForEnvCheck)) {
|
|
526
|
+
filesEnv.set(filePathForEnvCheck, []);
|
|
530
527
|
}
|
|
531
|
-
const
|
|
532
|
-
|
|
533
|
-
const configDifferentEnv =
|
|
528
|
+
const fileEnv = filesEnv.get(filePathForEnvCheck);
|
|
529
|
+
fileEnv.push({ configEnv, configName });
|
|
530
|
+
const configDifferentEnv = fileEnv.filter((c) => c.configEnv !== configEnv)[0];
|
|
534
531
|
if (configDifferentEnv) {
|
|
535
532
|
assertUsage(false, [
|
|
536
|
-
`${
|
|
533
|
+
`${filePathForEnvCheck} defines the value of configs living in different environments:`,
|
|
537
534
|
...[configDifferentEnv, { configName, configEnv }].map((c) => ` - config ${pc.cyan(c.configName)} which value lives in environment ${pc.cyan(c.configEnv)}`),
|
|
538
535
|
'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'
|
|
539
536
|
].join('\n'));
|
|
@@ -551,53 +548,60 @@ function isDefiningPage(interfaceFiles) {
|
|
|
551
548
|
function isDefiningPageConfig(configName) {
|
|
552
549
|
return ['Page', 'route'].includes(configName);
|
|
553
550
|
}
|
|
554
|
-
function
|
|
551
|
+
function resolveImport(configValue, importerFilePath, userRootDir, configEnv, configName) {
|
|
555
552
|
if (typeof configValue !== 'string')
|
|
556
553
|
return null;
|
|
557
554
|
const importData = parseImportData(configValue);
|
|
558
555
|
if (!importData)
|
|
559
556
|
return null;
|
|
560
|
-
|
|
561
|
-
|
|
557
|
+
const { importPath, exportName } = importData;
|
|
558
|
+
const filePathAbsolute = resolveImportPath(importData, importerFilePath);
|
|
559
|
+
let filePathToShowToUser;
|
|
560
|
+
if (importPath.startsWith('.')) {
|
|
562
561
|
// We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
|
|
563
562
|
// ```
|
|
564
563
|
// [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
|
|
565
564
|
// ```
|
|
566
|
-
|
|
565
|
+
assertImportPath(filePathAbsolute, importData, importerFilePath);
|
|
566
|
+
const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, importerFilePath, userRootDir);
|
|
567
|
+
filePathToShowToUser = filePathRelativeToUserRootDir;
|
|
567
568
|
}
|
|
568
569
|
else {
|
|
569
|
-
//
|
|
570
|
+
// importPath can be:
|
|
570
571
|
// - an npm package import
|
|
571
572
|
// - a path alias
|
|
573
|
+
filePathToShowToUser = importPath;
|
|
574
|
+
}
|
|
575
|
+
{
|
|
576
|
+
const filePathForEnvCheck = filePathAbsolute ?? importPath;
|
|
577
|
+
assertFileEnv(filePathForEnvCheck, configEnv, configName);
|
|
572
578
|
}
|
|
573
579
|
return {
|
|
574
|
-
|
|
575
|
-
|
|
580
|
+
filePathToShowToUser,
|
|
581
|
+
fileExportName: exportName
|
|
576
582
|
};
|
|
577
583
|
}
|
|
578
|
-
function
|
|
579
|
-
let importFilePath = resolveImport(importData, configFilePath);
|
|
580
|
-
// Make it a Vite path
|
|
584
|
+
function resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, configFilePath, userRootDir) {
|
|
581
585
|
assertPosixPath(userRootDir);
|
|
582
|
-
|
|
583
|
-
if (
|
|
584
|
-
|
|
586
|
+
let filePathRelativeToUserRootDir;
|
|
587
|
+
if (filePathAbsolute.startsWith(userRootDir)) {
|
|
588
|
+
filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsolute, userRootDir);
|
|
585
589
|
}
|
|
586
590
|
else {
|
|
587
|
-
assertUsage(false, `${getFilePathToShowToUser(configFilePath)} imports from a relative path ${pc.cyan(importData.
|
|
591
|
+
assertUsage(false, `${getFilePathToShowToUser(configFilePath)} imports from a relative path ${pc.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`);
|
|
588
592
|
// None of the following works. Seems to be a Vite bug?
|
|
589
593
|
// /*
|
|
590
|
-
// assert(
|
|
591
|
-
//
|
|
594
|
+
// assert(filePathAbsolute.startsWith('/'))
|
|
595
|
+
// filePath = `/@fs${filePathAbsolute}`
|
|
592
596
|
// /*/
|
|
593
|
-
//
|
|
594
|
-
// assert(
|
|
595
|
-
//
|
|
597
|
+
// filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsolute)
|
|
598
|
+
// assert(filePathRelativeToUserRootDir.startsWith('../'))
|
|
599
|
+
// filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir
|
|
596
600
|
// //*/
|
|
597
601
|
}
|
|
598
|
-
assertPosixPath(
|
|
599
|
-
assert(
|
|
600
|
-
return
|
|
602
|
+
assertPosixPath(filePathRelativeToUserRootDir);
|
|
603
|
+
assert(filePathRelativeToUserRootDir.startsWith('/'));
|
|
604
|
+
return filePathRelativeToUserRootDir;
|
|
601
605
|
}
|
|
602
606
|
function getVitePathFromAbsolutePath(filePathAbsolute, root) {
|
|
603
607
|
assertPosixPath(filePathAbsolute);
|
|
@@ -709,10 +713,9 @@ function applyEffect(configModFromEffect, configValueEffectSource, configValueSo
|
|
|
709
713
|
function applyComputed(pageConfig, configDefinitionsRelevant) {
|
|
710
714
|
objectEntries(configDefinitionsRelevant).forEach(([configName, configDef]) => {
|
|
711
715
|
var _a;
|
|
712
|
-
|
|
713
|
-
if (!computed)
|
|
716
|
+
if (!configDef._computed)
|
|
714
717
|
return;
|
|
715
|
-
const value =
|
|
718
|
+
const value = configDef._computed(pageConfig);
|
|
716
719
|
if (value === undefined)
|
|
717
720
|
return;
|
|
718
721
|
const configValueSource = {
|
|
@@ -796,7 +799,7 @@ function assertNoUnexpectedPlusSign(filePath, fileName) {
|
|
|
796
799
|
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`);
|
|
797
800
|
}
|
|
798
801
|
async function loadConfigFile(configFilePath, userRootDir, visited) {
|
|
799
|
-
const { filePathAbsolute
|
|
802
|
+
const { filePathAbsolute } = configFilePath;
|
|
800
803
|
assertNoInfiniteLoop(visited, filePathAbsolute);
|
|
801
804
|
const { fileExports } = await transpileAndExecuteFile(configFilePath, false, userRootDir);
|
|
802
805
|
const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
|
|
@@ -805,10 +808,7 @@ async function loadConfigFile(configFilePath, userRootDir, visited) {
|
|
|
805
808
|
]);
|
|
806
809
|
const configFile = {
|
|
807
810
|
fileExports,
|
|
808
|
-
filePath:
|
|
809
|
-
filePathRelativeToUserRootDir,
|
|
810
|
-
filePathAbsolute
|
|
811
|
-
},
|
|
811
|
+
filePath: configFilePath,
|
|
812
812
|
extendsFilePaths
|
|
813
813
|
};
|
|
814
814
|
return { configFile, extendsConfigs };
|
|
@@ -825,16 +825,20 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
825
825
|
const extendsImportData = getExtendsImportData(configFileExports, configFilePath);
|
|
826
826
|
const extendsConfigFiles = [];
|
|
827
827
|
extendsImportData.map((importData) => {
|
|
828
|
-
const {
|
|
828
|
+
const { importPath: importPath } = importData;
|
|
829
829
|
// TODO
|
|
830
830
|
// - validate extends configs
|
|
831
|
-
const filePathAbsolute =
|
|
831
|
+
const filePathAbsolute = resolveImportPath(importData, configFilePath);
|
|
832
|
+
assertImportPath(filePathAbsolute, importData, configFilePath);
|
|
832
833
|
assertExtendsImportPath(importPath, filePathAbsolute, configFilePath);
|
|
834
|
+
// - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
|
|
835
|
+
// - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsolute for added clarity
|
|
836
|
+
const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsolute, userRootDir);
|
|
833
837
|
extendsConfigFiles.push({
|
|
834
838
|
filePathAbsolute,
|
|
835
|
-
//
|
|
836
|
-
|
|
837
|
-
|
|
839
|
+
// TODO: fix type cast
|
|
840
|
+
filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
|
|
841
|
+
importPathAbsolute: importPath
|
|
838
842
|
});
|
|
839
843
|
});
|
|
840
844
|
const extendsConfigs = [];
|
|
@@ -874,7 +878,7 @@ function assertExtendsImportPath(importPath, filePath, configFilePath) {
|
|
|
874
878
|
}
|
|
875
879
|
function getExtendsImportData(configFileExports, configFilePath) {
|
|
876
880
|
const filePathToShowToUser = getFilePathToShowToUser(configFilePath);
|
|
877
|
-
|
|
881
|
+
assertExportsOfConfigFile(configFileExports, filePathToShowToUser);
|
|
878
882
|
const defaultExports = configFileExports.default;
|
|
879
883
|
const wrongUsage = `${filePathToShowToUser} sets the config 'extends' to an invalid value, see https://vike.dev/extends`;
|
|
880
884
|
let extendList;
|
|
@@ -954,13 +958,16 @@ function handleUnknownConfig(configName, configNames, definedByFile) {
|
|
|
954
958
|
else {
|
|
955
959
|
configNameSimilar = getMostSimilar(configName, configNames);
|
|
956
960
|
}
|
|
957
|
-
if (configNameSimilar) {
|
|
961
|
+
if (configNameSimilar || configName === 'page') {
|
|
962
|
+
assert(configNameSimilar);
|
|
958
963
|
assert(configNameSimilar !== configName);
|
|
959
964
|
errMsg += `, did you mean to define ${pc.cyan(configNameSimilar)} instead?`;
|
|
965
|
+
if (configName === 'page') {
|
|
966
|
+
errMsg += ` (The name of the config ${pc.cyan('Page')} starts with a capital letter ${pc.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.)`;
|
|
967
|
+
}
|
|
960
968
|
}
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
errMsg += ` (The name of the config ${pc.cyan('Page')} starts with a capital letter ${pc.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.)`;
|
|
969
|
+
else {
|
|
970
|
+
errMsg += `, you need to define the config ${pc.cyan(configName)} by using ${pc.cyan('config.meta')} https://vike.dev/meta`;
|
|
964
971
|
}
|
|
965
972
|
assertUsage(false, errMsg);
|
|
966
973
|
}
|
|
@@ -969,7 +976,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
969
976
|
const configFilesystemRoutingRoot = configValueSources[configName]?.[0];
|
|
970
977
|
let filesystemRouteString = getFilesystemRouteString(locationId);
|
|
971
978
|
if (determineIsErrorPage(filesystemRouteString)) {
|
|
972
|
-
return { isErrorPage: true, routeFilesystem:
|
|
979
|
+
return { isErrorPage: true, routeFilesystem: undefined };
|
|
973
980
|
}
|
|
974
981
|
let filesystemRouteDefinedBy = getFilesystemRouteDefinedBy(locationId); // for log404()
|
|
975
982
|
if (configFilesystemRoutingRoot) {
|
|
@@ -987,7 +994,7 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
987
994
|
routeString: filesystemRouteString,
|
|
988
995
|
definedBy: filesystemRouteDefinedBy
|
|
989
996
|
};
|
|
990
|
-
return { routeFilesystem, isErrorPage:
|
|
997
|
+
return { routeFilesystem, isErrorPage: undefined };
|
|
991
998
|
}
|
|
992
999
|
function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName) {
|
|
993
1000
|
assert(configFilesystemRoutingRoot.configEnv === 'config-only');
|
|
@@ -1007,33 +1014,22 @@ function determineIsErrorPage(routeFilesystem) {
|
|
|
1007
1014
|
assertPosixPath(routeFilesystem);
|
|
1008
1015
|
return routeFilesystem.split('/').includes('_error');
|
|
1009
1016
|
}
|
|
1010
|
-
function
|
|
1011
|
-
const
|
|
1012
|
-
assertPosixPath(
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
importedFile = require_.resolve(importData.importFilePath, { paths: [plusConfigFilDirPathAbsolute] });
|
|
1018
|
-
}
|
|
1019
|
-
catch {
|
|
1020
|
-
importedFile = null;
|
|
1021
|
-
}
|
|
1022
|
-
finally {
|
|
1023
|
-
clean();
|
|
1024
|
-
}
|
|
1025
|
-
assertImport(importedFile, importData, importerFilePath);
|
|
1026
|
-
importedFile = toPosixPath(importedFile);
|
|
1027
|
-
return importedFile;
|
|
1017
|
+
function resolveImportPath(importData, importerFilePath) {
|
|
1018
|
+
const importerFilePathAbsolute = importerFilePath.filePathAbsolute;
|
|
1019
|
+
assertPosixPath(importerFilePathAbsolute);
|
|
1020
|
+
const cwd = path.posix.dirname(importerFilePathAbsolute);
|
|
1021
|
+
// filePathAbsolute is expected to be null when importData.importPath is a Vite path alias
|
|
1022
|
+
const filePathAbsolute = requireResolve(importData.importPath, cwd);
|
|
1023
|
+
return filePathAbsolute;
|
|
1028
1024
|
}
|
|
1029
|
-
function
|
|
1030
|
-
const {
|
|
1025
|
+
function assertImportPath(filePathAbsolute, importData, importerFilePath) {
|
|
1026
|
+
const { importPath: importPath, importStringWasGenerated, importString } = importData;
|
|
1031
1027
|
const filePathToShowToUser = getFilePathToShowToUser(importerFilePath);
|
|
1032
|
-
if (!
|
|
1028
|
+
if (!filePathAbsolute) {
|
|
1033
1029
|
const importPathString = pc.cyan(`'${importPath}'`);
|
|
1034
|
-
const errIntro =
|
|
1030
|
+
const errIntro = importStringWasGenerated
|
|
1035
1031
|
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
1036
|
-
: `The import ${pc.cyan(
|
|
1032
|
+
: `The import ${pc.cyan(importString)} defined in ${filePathToShowToUser}`;
|
|
1037
1033
|
const errIntro2 = `${errIntro} couldn't be resolved: does ${importPathString}`;
|
|
1038
1034
|
if (importPath.startsWith('.')) {
|
|
1039
1035
|
assertUsage(false, `${errIntro2} point to an existing file?`);
|
|
@@ -1084,6 +1080,8 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1084
1080
|
/* This is more confusing than adding value. For example, this explanation shouldn't be shown for the passToClient config.
|
|
1085
1081
|
const explanation = `(Because the values of ${configNameColored} are cumulative and therefore merged together.)` as const
|
|
1086
1082
|
*/
|
|
1083
|
+
// Make sure configValueSource.value is serializable
|
|
1084
|
+
getConfigValueSerialized(configValueSource.value, configName, configValueSource.definedAtInfo);
|
|
1087
1085
|
const assertNoMixing = (isSet) => {
|
|
1088
1086
|
const vals1 = isSet ? valuesSet : valuesArr;
|
|
1089
1087
|
const t1 = isSet ? 'a Set' : 'an array';
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigValuesAll };
|
|
2
|
+
export { serializeConfigValueImported };
|
|
3
|
+
import type { ConfigValueSource } from '../../../../../shared/page-configs/PageConfig.js';
|
|
2
4
|
import type { ConfigVikeResolved } from '../../../../../shared/ConfigVike.js';
|
|
3
5
|
declare function getVirtualFilePageConfigValuesAll(id: string, userRootDir: string, isDev: boolean, configVike: ConfigVikeResolved): Promise<string>;
|
|
6
|
+
declare function serializeConfigValueImported(configValueSource: ConfigValueSource, configName: string, whitespace: string, varCounterContainer: {
|
|
7
|
+
varCounter: number;
|
|
8
|
+
}, importStatements: string[]): string[];
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigValuesAll };
|
|
2
|
+
export { serializeConfigValueImported };
|
|
2
3
|
import { assert, assertPosixPath } from '../../../utils.js';
|
|
3
4
|
import { generateEagerImport } from '../generateEagerImport.js';
|
|
4
5
|
import { getVirtualFileIdPageConfigValuesAll, isVirtualFileIdPageConfigValuesAll } from '../../../../shared/virtual-files/virtualFilePageConfigValuesAll.js';
|
|
@@ -7,7 +8,7 @@ import { extractAssetsAddQuery } from '../../../../shared/extractAssetsQuery.js'
|
|
|
7
8
|
import { debug } from './debug.js';
|
|
8
9
|
import path from 'path';
|
|
9
10
|
import { getConfigValue } from '../../../../../shared/page-configs/utils.js';
|
|
10
|
-
import { getConfigValueSourcesRelevant } from '../../../shared/
|
|
11
|
+
import { getConfigValueSourcesRelevant } from '../../../shared/getConfigValueSourcesRelevant.js';
|
|
11
12
|
import { isConfigEnvMatch } from './isConfigEnvMatch.js';
|
|
12
13
|
async function getVirtualFilePageConfigValuesAll(id, userRootDir, isDev, configVike) {
|
|
13
14
|
const result = isVirtualFileIdPageConfigValuesAll(id);
|
|
@@ -32,37 +33,17 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
32
33
|
const lines = [];
|
|
33
34
|
const importStatements = [];
|
|
34
35
|
lines.push('export default [');
|
|
35
|
-
|
|
36
|
+
const varCounterContainer = { varCounter: 0 };
|
|
36
37
|
getConfigValueSourcesRelevant(pageConfig).forEach((configValueSource) => {
|
|
37
|
-
const { valueIsImportedAtRuntime,
|
|
38
|
+
const { valueIsImportedAtRuntime, configEnv, configName } = configValueSource;
|
|
38
39
|
if (!valueIsImportedAtRuntime)
|
|
39
40
|
return;
|
|
40
41
|
if (configValueSource.valueIsFilePath)
|
|
41
42
|
return;
|
|
42
43
|
if (!isConfigEnvMatch(configEnv, isForClientSide, isClientRouting))
|
|
43
44
|
return;
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
const fileName = path.posix.basename(filePath);
|
|
47
|
-
const isPlusFile = fileName.startsWith('+');
|
|
48
|
-
const fileExportName = fileExportPath[0];
|
|
49
|
-
assert(!configValueSource.valueIsFilePath);
|
|
50
|
-
assert(fileExportName);
|
|
51
|
-
const { importVar, importStatement } = generateEagerImport(filePath, varCounter++, isPlusFile ? undefined : fileExportName);
|
|
52
|
-
importStatements.push(importStatement);
|
|
53
|
-
lines.push(` {`);
|
|
54
|
-
lines.push(` configName: '${configName}',`);
|
|
55
|
-
lines.push(` importFilePath: '${filePath}',`);
|
|
56
|
-
lines.push(` isPlusFile: ${JSON.stringify(isPlusFile)},`);
|
|
57
|
-
if (isPlusFile) {
|
|
58
|
-
lines.push(` importFileExports: ${importVar},`);
|
|
59
|
-
}
|
|
60
|
-
else {
|
|
61
|
-
lines.push(` importFileExportValue: ${importVar},`);
|
|
62
|
-
assert(fileExportName);
|
|
63
|
-
lines.push(` importFileExportName: ${JSON.stringify(fileExportName)},`);
|
|
64
|
-
}
|
|
65
|
-
lines.push(` },`);
|
|
45
|
+
const whitespace = ' ';
|
|
46
|
+
lines.push(...serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
66
47
|
});
|
|
67
48
|
lines.push('];');
|
|
68
49
|
if (includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
@@ -71,3 +52,32 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
71
52
|
const code = [...importStatements, ...lines].join('\n');
|
|
72
53
|
return code;
|
|
73
54
|
}
|
|
55
|
+
function serializeConfigValueImported(configValueSource, configName, whitespace, varCounterContainer, importStatements) {
|
|
56
|
+
assert(whitespace.replaceAll(' ', '').length === 0);
|
|
57
|
+
const { valueIsImportedAtRuntime, definedAtInfo } = configValueSource;
|
|
58
|
+
assert(valueIsImportedAtRuntime);
|
|
59
|
+
const { filePath, fileExportPath } = definedAtInfo;
|
|
60
|
+
assertPosixPath(filePath);
|
|
61
|
+
const fileName = path.posix.basename(filePath);
|
|
62
|
+
const isValueFile = fileName.startsWith('+');
|
|
63
|
+
const fileExportName = fileExportPath[0];
|
|
64
|
+
assert(!configValueSource.valueIsFilePath);
|
|
65
|
+
assert(fileExportName);
|
|
66
|
+
const { importName, importStatement } = generateEagerImport(filePath, varCounterContainer.varCounter++, isValueFile ? undefined : fileExportName);
|
|
67
|
+
importStatements.push(importStatement);
|
|
68
|
+
const lines = [];
|
|
69
|
+
lines.push(` {`);
|
|
70
|
+
lines.push(` configName: '${configName}',`);
|
|
71
|
+
lines.push(` importPath: '${filePath}',`);
|
|
72
|
+
lines.push(` isValueFile: ${JSON.stringify(isValueFile)},`);
|
|
73
|
+
if (isValueFile) {
|
|
74
|
+
lines.push(` importFileExports: ${importName},`);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
lines.push(` importFileExportValue: ${importName},`);
|
|
78
|
+
assert(fileExportName);
|
|
79
|
+
lines.push(` exportName: ${JSON.stringify(fileExportName)},`);
|
|
80
|
+
}
|
|
81
|
+
lines.push(` },`);
|
|
82
|
+
return lines;
|
|
83
|
+
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export { getVirtualFilePageConfigs };
|
|
2
|
+
export { getConfigValueSerialized };
|
|
3
|
+
import type { DefinedAtInfo } from '../../../../../shared/page-configs/PageConfig.js';
|
|
2
4
|
import type { ConfigVikeResolved } from '../../../../../shared/ConfigVike.js';
|
|
3
5
|
declare function getVirtualFilePageConfigs(userRootDir: string, isForClientSide: boolean, isDev: boolean, id: string, configVike: ConfigVikeResolved, isClientRouting: boolean): Promise<string>;
|
|
6
|
+
declare function getConfigValueSerialized(value: unknown, configName: string, definedAtInfo: null | DefinedAtInfo): string;
|