vike 0.4.144 → 0.4.145-commit-2520555
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/__internal/index.js +6 -2
- package/dist/cjs/node/plugin/plugins/buildConfig.js +3 -3
- package/dist/cjs/node/plugin/plugins/commonConfig.js +0 -3
- package/dist/cjs/node/plugin/plugins/config/index.js +3 -3
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +8 -8
- package/dist/cjs/node/plugin/plugins/devConfig/index.js +1 -0
- package/dist/cjs/node/plugin/plugins/envVars.js +34 -20
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +249 -228
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +8 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +36 -14
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +18 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +15 -17
- package/dist/cjs/node/plugin/plugins/previewConfig.js +11 -2
- package/dist/cjs/node/prerender/runPrerender.js +34 -26
- package/dist/cjs/node/prerender/utils.js +1 -1
- package/dist/cjs/node/runtime/html/serializePageContextClientSide.js +20 -6
- package/dist/cjs/node/runtime/renderPage/debugPageFiles.js +5 -5
- package/dist/cjs/node/runtime/renderPage/log404/index.js +28 -17
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -3
- package/dist/cjs/node/runtime/renderPage.js +3 -3
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/node/shared/getClientEntryFilePath.js +2 -2
- package/dist/cjs/node/shared/getConfigVike.js +4 -1
- package/dist/cjs/shared/addUrlComputedProps.js +24 -12
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +4 -6
- package/dist/cjs/shared/getPageFiles/getExports.js +3 -3
- package/dist/cjs/shared/hooks/getHook.js +1 -1
- package/dist/cjs/shared/page-configs/getExportPath.js +3 -3
- package/dist/cjs/shared/page-configs/helpers/getConfigDefinedAtString.js +43 -0
- package/dist/cjs/shared/page-configs/helpers/getConfigValue.js +44 -0
- package/dist/cjs/shared/page-configs/helpers.js +33 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +14 -13
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +9 -10
- package/dist/cjs/shared/route/abort.js +1 -1
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +41 -15
- package/dist/cjs/shared/route/index.js +22 -32
- package/dist/cjs/shared/route/loadPageRoutes.js +11 -10
- package/dist/cjs/shared/route/noRouteMatch.js +4 -0
- package/dist/cjs/shared/route/resolveRouteFunction.js +1 -1
- package/dist/cjs/shared/utils.js +1 -1
- package/dist/cjs/utils/getFilePathAbsolute.js +11 -11
- package/dist/cjs/utils/isExternalLink.js +7 -0
- package/dist/cjs/utils/{hasPropertyGetter.js → isPropertyGetter.js} +3 -3
- package/dist/cjs/utils/onPageVisibilityChange.js +19 -0
- package/dist/cjs/utils/parseUrl.js +1 -1
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/truncateString.js +12 -7
- package/dist/esm/__internal/index.d.ts +6 -3
- package/dist/esm/__internal/index.js +8 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +2 -3
- package/dist/esm/client/client-routing-runtime/createPageContext.js +3 -4
- package/dist/esm/client/client-routing-runtime/entry.js +2 -2
- package/dist/esm/client/client-routing-runtime/getBaseServer.d.ts +2 -1
- package/dist/esm/client/client-routing-runtime/getBaseServer.js +2 -1
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +39 -0
- package/dist/esm/client/client-routing-runtime/{getPageContext.js → getPageContextFromHooks.js} +50 -79
- package/dist/esm/client/client-routing-runtime/history.d.ts +3 -1
- package/dist/esm/client/client-routing-runtime/history.js +31 -9
- package/dist/esm/client/client-routing-runtime/installClientRouter.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/installClientRouter.js +22 -0
- package/dist/esm/client/client-routing-runtime/isClientSideRoutable.d.ts +8 -0
- package/dist/esm/client/client-routing-runtime/isClientSideRoutable.js +12 -0
- package/dist/esm/client/client-routing-runtime/navigate.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/navigate.js +9 -8
- package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.d.ts +4 -0
- package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +63 -0
- package/dist/esm/client/client-routing-runtime/onLinkClick.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/onLinkClick.js +40 -0
- package/dist/esm/client/client-routing-runtime/prefetch.js +54 -29
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +19 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +347 -0
- package/dist/esm/client/client-routing-runtime/scrollRestoration.d.ts +6 -0
- package/dist/esm/client/client-routing-runtime/scrollRestoration.js +25 -0
- package/dist/esm/client/client-routing-runtime/setScrollPosition.d.ts +7 -0
- package/dist/esm/client/client-routing-runtime/setScrollPosition.js +77 -0
- package/dist/esm/client/client-routing-runtime/skipLink.d.ts +0 -1
- package/dist/esm/client/client-routing-runtime/skipLink.js +9 -5
- package/dist/esm/client/client-routing-runtime/utils.d.ts +2 -0
- package/dist/esm/client/client-routing-runtime/utils.js +2 -0
- package/dist/esm/client/server-routing-runtime/getPageContext.js +1 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.js +6 -5
- package/dist/esm/client/shared/getPageContextProxyForUser.js +13 -7
- package/dist/esm/client/shared/loadPageFilesClientSide.d.ts +8 -3
- package/dist/esm/client/shared/loadPageFilesClientSide.js +5 -5
- package/dist/esm/node/plugin/plugins/buildConfig.js +3 -3
- package/dist/esm/node/plugin/plugins/commonConfig.js +0 -3
- package/dist/esm/node/plugin/plugins/config/index.js +4 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +9 -9
- package/dist/esm/node/plugin/plugins/devConfig/index.js +1 -0
- package/dist/esm/node/plugin/plugins/envVars.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/envVars.js +35 -20
- package/dist/esm/node/plugin/plugins/importBuild/index.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +5 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +12 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +250 -229
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +7 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +37 -15
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +1 -14
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +7 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +15 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/transpileAndExecuteFile.js +16 -18
- package/dist/esm/node/plugin/plugins/previewConfig.js +11 -2
- package/dist/esm/node/prerender/runPrerender.js +29 -21
- package/dist/esm/node/prerender/utils.d.ts +1 -1
- package/dist/esm/node/prerender/utils.js +1 -1
- package/dist/esm/node/runtime/html/serializePageContextClientSide.js +21 -7
- package/dist/esm/node/runtime/renderPage/debugPageFiles.d.ts +5 -5
- package/dist/esm/node/runtime/renderPage/debugPageFiles.js +5 -5
- package/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.js +28 -16
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -2
- package/dist/esm/node/runtime/renderPage.js +3 -3
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/node/shared/getClientEntryFilePath.js +1 -1
- package/dist/esm/node/shared/getConfigVike.d.ts +2 -1
- package/dist/esm/node/shared/getConfigVike.js +4 -1
- package/dist/esm/shared/addUrlComputedProps.d.ts +1 -0
- package/dist/esm/shared/addUrlComputedProps.js +25 -13
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +2 -4
- package/dist/esm/shared/getPageFiles/getExports.js +2 -2
- package/dist/esm/shared/hooks/getHook.js +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +55 -31
- package/dist/esm/shared/page-configs/getExportPath.d.ts +1 -1
- package/dist/esm/shared/page-configs/getExportPath.js +3 -3
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.d.ts +7 -0
- package/dist/esm/shared/page-configs/helpers/getConfigDefinedAtString.js +37 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.d.ts +14 -0
- package/dist/esm/shared/page-configs/helpers/getConfigValue.js +38 -0
- package/dist/esm/shared/page-configs/helpers.d.ts +13 -0
- package/dist/esm/shared/page-configs/helpers.js +27 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +2 -2
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +4 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +15 -11
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +9 -10
- package/dist/esm/shared/route/abort.js +1 -1
- package/dist/esm/shared/route/executeOnBeforeRouteHook.d.ts +5 -8
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +41 -15
- package/dist/esm/shared/route/index.d.ts +12 -10
- package/dist/esm/shared/route/index.js +23 -33
- package/dist/esm/shared/route/loadPageRoutes.js +8 -7
- package/dist/esm/shared/route/noRouteMatch.d.ts +1 -0
- package/dist/esm/shared/route/noRouteMatch.js +1 -0
- package/dist/esm/shared/route/resolveRouteFunction.js +1 -1
- package/dist/esm/shared/utils.d.ts +1 -1
- package/dist/esm/shared/utils.js +1 -1
- package/dist/esm/utils/getFilePathAbsolute.d.ts +1 -1
- package/dist/esm/utils/getFilePathAbsolute.js +11 -11
- package/dist/esm/utils/isPropertyGetter.d.ts +1 -0
- package/dist/esm/utils/{hasPropertyGetter.js → isPropertyGetter.js} +1 -1
- package/dist/esm/utils/onPageVisibilityChange.d.ts +4 -0
- package/dist/esm/utils/onPageVisibilityChange.js +16 -0
- package/dist/esm/utils/parseUrl.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/truncateString.d.ts +2 -1
- package/dist/esm/utils/truncateString.js +10 -7
- package/node/cli/bin-entry.js +1 -1
- package/package.json +2 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -16
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -13
- package/dist/cjs/shared/page-configs/utils.js +0 -103
- package/dist/esm/client/client-routing-runtime/getPageContext.d.ts +0 -29
- package/dist/esm/client/client-routing-runtime/getPageId.d.ts +0 -10
- package/dist/esm/client/client-routing-runtime/getPageId.js +0 -17
- package/dist/esm/client/client-routing-runtime/navigationState.d.ts +0 -5
- package/dist/esm/client/client-routing-runtime/navigationState.js +0 -14
- package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.d.ts +0 -2
- package/dist/esm/client/client-routing-runtime/skipLink/isClientSideRoutable.js +0 -15
- package/dist/esm/client/client-routing-runtime/useClientRouter.d.ts +0 -6
- package/dist/esm/client/client-routing-runtime/useClientRouter.js +0 -493
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.d.ts +0 -24
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getFilePathToShowToUser.js +0 -13
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isConfigEnvMatch.js +0 -10
- package/dist/esm/shared/page-configs/utils.d.ts +0 -35
- package/dist/esm/shared/page-configs/utils.js +0 -97
- package/dist/esm/utils/hasPropertyGetter.d.ts +0 -1
- /package/dist/esm/{client/client-routing-runtime → utils}/isExternalLink.d.ts +0 -0
- /package/dist/esm/{client/client-routing-runtime → utils}/isExternalLink.js +0 -0
|
@@ -15,11 +15,11 @@ const isConfigInvalid_js_1 = require("../../../../runtime/renderPage/isConfigInv
|
|
|
15
15
|
const globalContext_js_1 = require("../../../../runtime/globalContext.js");
|
|
16
16
|
const loggerNotProd_js_1 = require("../../../shared/loggerNotProd.js");
|
|
17
17
|
const removeSuperfluousViteLog_js_1 = require("../../../shared/loggerVite/removeSuperfluousViteLog.js");
|
|
18
|
-
const getFilePathToShowToUser_js_1 = require("./getFilePathToShowToUser.js");
|
|
19
18
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
20
|
-
const
|
|
19
|
+
const helpers_js_1 = require("../../../../../shared/page-configs/helpers.js");
|
|
21
20
|
const assertExports_js_1 = require("../../../../../shared/page-configs/assertExports.js");
|
|
22
21
|
const getVirtualFilePageConfigs_js_1 = require("./getVirtualFilePageConfigs.js");
|
|
22
|
+
const getConfigVike_js_1 = require("../../../../shared/getConfigVike.js");
|
|
23
23
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
24
24
|
let devServerIsCorrupt = false;
|
|
25
25
|
let wasConfigInvalid = null;
|
|
@@ -65,9 +65,11 @@ async function handleReloadSideEffects() {
|
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
async function getVikeConfig(
|
|
68
|
+
async function getVikeConfig(config, isDev, tolerateInvalidConfig = false, extensions) {
|
|
69
|
+
const { outDirRoot } = (0, utils_js_1.getOutDirs)(config);
|
|
70
|
+
const userRootDir = config.root;
|
|
69
71
|
if (!vikeConfigPromise) {
|
|
70
|
-
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, extensions, tolerateInvalidConfig);
|
|
72
|
+
vikeConfigPromise = loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev, extensions ?? (await (0, getConfigVike_js_1.getConfigVike)(config)).extensions, tolerateInvalidConfig);
|
|
71
73
|
}
|
|
72
74
|
return await vikeConfigPromise;
|
|
73
75
|
}
|
|
@@ -77,7 +79,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
77
79
|
const configFiles = [];
|
|
78
80
|
const valueFiles = [];
|
|
79
81
|
plusFiles.forEach((f) => {
|
|
80
|
-
if (getConfigName(f.
|
|
82
|
+
if (getConfigName(f.filePathAbsoluteFilesystem) === 'config') {
|
|
81
83
|
configFiles.push(f);
|
|
82
84
|
}
|
|
83
85
|
else {
|
|
@@ -86,15 +88,10 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
86
88
|
});
|
|
87
89
|
let interfaceFilesByLocationId = {};
|
|
88
90
|
// Config files
|
|
89
|
-
await Promise.all(configFiles.map(async (
|
|
90
|
-
const
|
|
91
|
-
filePathAbsolute: filePathAbsolute,
|
|
92
|
-
filePathRelativeToUserRootDir: filePathRelativeToUserRootDir,
|
|
93
|
-
importPathAbsolute: null
|
|
94
|
-
};
|
|
95
|
-
const { configFile, extendsConfigs } = await loadConfigFile(configFilePath, userRootDir, []);
|
|
91
|
+
await Promise.all(configFiles.map(async (filePath) => {
|
|
92
|
+
const { configFile, extendsConfigs } = await loadConfigFile(filePath, userRootDir, []);
|
|
96
93
|
const interfaceFile = getInterfaceFileFromConfigFile(configFile, false);
|
|
97
|
-
const locationId = (0, filesystemRouting_js_1.getLocationId)(
|
|
94
|
+
const locationId = (0, filesystemRouting_js_1.getLocationId)(filePath.filePathAbsoluteVite);
|
|
98
95
|
interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
|
|
99
96
|
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
100
97
|
extendsConfigs.forEach((extendsConfig) => {
|
|
@@ -103,15 +100,11 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
103
100
|
});
|
|
104
101
|
}));
|
|
105
102
|
// Value files
|
|
106
|
-
await Promise.all(valueFiles.map(async (
|
|
107
|
-
const configName = getConfigName(
|
|
103
|
+
await Promise.all(valueFiles.map(async (filePath) => {
|
|
104
|
+
const configName = getConfigName(filePath.filePathAbsoluteVite);
|
|
108
105
|
(0, utils_js_1.assert)(configName);
|
|
109
106
|
const interfaceFile = {
|
|
110
|
-
filePath
|
|
111
|
-
filePathRelativeToUserRootDir,
|
|
112
|
-
filePathAbsolute,
|
|
113
|
-
importPathAbsolute: null
|
|
114
|
-
},
|
|
107
|
+
filePath,
|
|
115
108
|
configMap: {
|
|
116
109
|
[configName]: {}
|
|
117
110
|
},
|
|
@@ -120,25 +113,25 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
120
113
|
configName
|
|
121
114
|
};
|
|
122
115
|
{
|
|
123
|
-
// We don't have access to custom config definitions yet
|
|
124
|
-
// -
|
|
125
|
-
// -
|
|
116
|
+
// We don't have access to the custom config definitions defined by the user yet.
|
|
117
|
+
// - If `configDef` is `undefined` => we load the file +{configName}.js later.
|
|
118
|
+
// - We already need to load +meta.js here (to get the custom config definitions defined by the user)
|
|
126
119
|
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn, configName);
|
|
127
|
-
if (configDef
|
|
120
|
+
if (configDef && isConfigEnv(configDef, configName)) {
|
|
128
121
|
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
129
122
|
}
|
|
130
123
|
}
|
|
131
124
|
{
|
|
132
|
-
const locationId = (0, filesystemRouting_js_1.getLocationId)(
|
|
125
|
+
const locationId = (0, filesystemRouting_js_1.getLocationId)(filePath.filePathAbsoluteVite);
|
|
133
126
|
interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
|
|
134
127
|
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
135
128
|
}
|
|
136
129
|
}));
|
|
137
130
|
return interfaceFilesByLocationId;
|
|
138
131
|
}
|
|
139
|
-
function getConfigDefinition(configDefinitionsRelevant, configName,
|
|
132
|
+
function getConfigDefinition(configDefinitionsRelevant, configName, filePathToShowToUser) {
|
|
140
133
|
const configDef = configDefinitionsRelevant[configName];
|
|
141
|
-
assertConfigExists(configName, Object.keys(configDefinitionsRelevant),
|
|
134
|
+
assertConfigExists(configName, Object.keys(configDefinitionsRelevant), filePathToShowToUser);
|
|
142
135
|
(0, utils_js_1.assert)(configDef);
|
|
143
136
|
return configDef;
|
|
144
137
|
}
|
|
@@ -147,13 +140,29 @@ function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
|
147
140
|
}
|
|
148
141
|
async function loadValueFile(interfaceValueFile, configName, userRootDir) {
|
|
149
142
|
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(interfaceValueFile.filePath, true, userRootDir);
|
|
150
|
-
const filePathToShowToUser =
|
|
143
|
+
const { filePathToShowToUser } = interfaceValueFile.filePath;
|
|
151
144
|
(0, assertExports_js_1.assertExportsOfValueFile)(fileExports, filePathToShowToUser, configName);
|
|
152
145
|
Object.entries(fileExports).forEach(([exportName, configValue]) => {
|
|
153
146
|
const configName_ = exportName === 'default' ? configName : exportName;
|
|
154
147
|
interfaceValueFile.configMap[configName_] = { configValue };
|
|
155
148
|
});
|
|
156
149
|
}
|
|
150
|
+
async function loadImportedFile(filePath, userRootDir, importedFilesLoaded) {
|
|
151
|
+
const f = filePath.filePathAbsoluteFilesystem;
|
|
152
|
+
if (!importedFilesLoaded[f]) {
|
|
153
|
+
importedFilesLoaded[f] = (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(filePath, true, userRootDir).then((r) => r.fileExports);
|
|
154
|
+
}
|
|
155
|
+
const fileExports = await importedFilesLoaded[f];
|
|
156
|
+
return fileExports;
|
|
157
|
+
}
|
|
158
|
+
function isConfigEnv(configDef, configName) {
|
|
159
|
+
if (configDef.cumulative)
|
|
160
|
+
return true;
|
|
161
|
+
if (configDef.env === 'config-only')
|
|
162
|
+
return true;
|
|
163
|
+
// TODO: replace with proper `env: { config: boolean }` implementation
|
|
164
|
+
return configName === 'clientRouting';
|
|
165
|
+
}
|
|
157
166
|
function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
158
167
|
const { fileExports, filePath, extendsFilePaths } = configFile;
|
|
159
168
|
const interfaceFile = {
|
|
@@ -164,7 +173,7 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
164
173
|
isConfigExtend,
|
|
165
174
|
extendsFilePaths
|
|
166
175
|
};
|
|
167
|
-
const filePathToShowToUser =
|
|
176
|
+
const { filePathToShowToUser } = filePath;
|
|
168
177
|
(0, assertExports_js_1.assertExportsOfConfigFile)(fileExports, filePathToShowToUser);
|
|
169
178
|
Object.entries(fileExports.default).forEach(([configName, configValue]) => {
|
|
170
179
|
interfaceFile.configMap[configName] = { configValue };
|
|
@@ -214,7 +223,8 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
|
|
|
214
223
|
}
|
|
215
224
|
async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
216
225
|
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions);
|
|
217
|
-
const
|
|
226
|
+
const importedFilesLoaded = {};
|
|
227
|
+
const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
|
|
218
228
|
const pageConfigs = await Promise.all(Object.entries(interfaceFilesByLocationId)
|
|
219
229
|
.filter(([_pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
220
230
|
.map(async ([locationId]) => {
|
|
@@ -227,25 +237,25 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
227
237
|
const { configName } = interfaceFile;
|
|
228
238
|
if (isGlobalConfig(configName))
|
|
229
239
|
return;
|
|
230
|
-
const configDef = getConfigDefinition(configDefinitionsRelevant, configName,
|
|
231
|
-
if (configDef
|
|
240
|
+
const configDef = getConfigDefinition(configDefinitionsRelevant, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
241
|
+
if (!isConfigEnv(configDef, configName))
|
|
232
242
|
return;
|
|
233
243
|
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
234
244
|
if (isAlreadyLoaded)
|
|
235
245
|
return;
|
|
236
|
-
// Value files
|
|
246
|
+
// Value files of built-in configs should have already been loaded at loadInterfaceFiles()
|
|
237
247
|
(0, utils_js_1.assert)(!(configName in configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn));
|
|
238
248
|
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
239
249
|
}));
|
|
240
250
|
const configValueSources = {};
|
|
241
|
-
(0, utils_js_1.objectEntries)(configDefinitionsRelevant)
|
|
251
|
+
await Promise.all((0, utils_js_1.objectEntries)(configDefinitionsRelevant)
|
|
242
252
|
.filter(([configName]) => !isGlobalConfig(configName))
|
|
243
|
-
.
|
|
244
|
-
const sources = resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir);
|
|
245
|
-
if (
|
|
253
|
+
.map(async ([configName, configDef]) => {
|
|
254
|
+
const sources = await resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir, importedFilesLoaded);
|
|
255
|
+
if (sources.length === 0)
|
|
246
256
|
return;
|
|
247
257
|
configValueSources[configName] = sources;
|
|
248
|
-
});
|
|
258
|
+
}));
|
|
249
259
|
const { routeFilesystem, isErrorPage } = determineRouteFilesystem(locationId, configValueSources);
|
|
250
260
|
applyEffectsAll(configValueSources, configDefinitionsRelevant);
|
|
251
261
|
const configValuesComputed = getComputed(configValueSources, configDefinitionsRelevant);
|
|
@@ -266,7 +276,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
266
276
|
const configDefinitionsRelevant = getConfigDefinitions(interfaceFilesRelevant);
|
|
267
277
|
interfaceFiles.forEach((interfaceFile) => {
|
|
268
278
|
Object.keys(interfaceFile.configMap).forEach((configName) => {
|
|
269
|
-
assertConfigExists(configName, Object.keys(configDefinitionsRelevant),
|
|
279
|
+
assertConfigExists(configName, Object.keys(configDefinitionsRelevant), interfaceFile.filePath.filePathToShowToUser);
|
|
270
280
|
});
|
|
271
281
|
});
|
|
272
282
|
});
|
|
@@ -295,7 +305,7 @@ function getInterfaceFileList(interfaceFilesByLocationId) {
|
|
|
295
305
|
});
|
|
296
306
|
return interfaceFiles;
|
|
297
307
|
}
|
|
298
|
-
function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
308
|
+
async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded) {
|
|
299
309
|
const locationIds = Object.keys(interfaceFilesByLocationId);
|
|
300
310
|
const interfaceFilesGlobal = Object.fromEntries(Object.entries(interfaceFilesByLocationId).filter(([locationId]) => {
|
|
301
311
|
return (0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds);
|
|
@@ -317,7 +327,7 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
|
317
327
|
Object.keys(interfaceFile.configMap).forEach((configName) => {
|
|
318
328
|
if (!(0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds) && isGlobalConfig(configName)) {
|
|
319
329
|
(0, utils_js_1.assertUsage)(false, [
|
|
320
|
-
`${
|
|
330
|
+
`${interfaceFile.filePath.filePathToShowToUser} defines the config ${picocolors_1.default.cyan(configName)} which is global:`,
|
|
321
331
|
globalPaths.length
|
|
322
332
|
? `define ${picocolors_1.default.cyan(configName)} in ${(0, utils_js_1.joinEnglish)(globalPaths, 'or')} instead`
|
|
323
333
|
: `create a global config (e.g. /pages/+config.js) and define ${picocolors_1.default.cyan(configName)} there instead`
|
|
@@ -331,9 +341,9 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
|
331
341
|
const pageConfigGlobal = {
|
|
332
342
|
configValueSources: {}
|
|
333
343
|
};
|
|
334
|
-
(0, utils_js_1.objectEntries)(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal).
|
|
335
|
-
const sources = resolveConfigValueSources(configName, configDef, interfaceFilesGlobal, userRootDir);
|
|
336
|
-
const configValueSource = sources
|
|
344
|
+
await Promise.all((0, utils_js_1.objectEntries)(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal).map(async ([configName, configDef]) => {
|
|
345
|
+
const sources = await resolveConfigValueSources(configName, configDef, interfaceFilesGlobal, userRootDir, importedFilesLoaded);
|
|
346
|
+
const configValueSource = sources[0];
|
|
337
347
|
if (!configValueSource)
|
|
338
348
|
return;
|
|
339
349
|
if (configName === 'onBeforeRoute' || configName === 'onPrerenderStart') {
|
|
@@ -344,28 +354,25 @@ function getGlobalConfigs(interfaceFilesByLocationId, userRootDir) {
|
|
|
344
354
|
(0, utils_js_1.assert)('value' in configValueSource);
|
|
345
355
|
if (configName === 'prerender' && typeof configValueSource.value === 'boolean')
|
|
346
356
|
return;
|
|
347
|
-
const
|
|
348
|
-
(0, utils_js_1.
|
|
349
|
-
(0, utils_js_1.assertWarning)(false, `Being able to define config ${picocolors_1.default.cyan(configName)} in ${sourceFilePath} is experimental and will likely be removed. Define the config ${picocolors_1.default.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
|
|
357
|
+
const { filePathToShowToUser } = configValueSource.definedAt;
|
|
358
|
+
(0, utils_js_1.assertWarning)(false, `Being able to define config ${picocolors_1.default.cyan(configName)} in ${filePathToShowToUser} is experimental and will likely be removed. Define the config ${picocolors_1.default.cyan(configName)} in Vike's Vite plugin options instead.`, { onlyOnce: true });
|
|
350
359
|
globalVikeConfig[configName] = configValueSource.value;
|
|
351
360
|
}
|
|
352
|
-
});
|
|
361
|
+
}));
|
|
353
362
|
return { pageConfigGlobal, globalVikeConfig };
|
|
354
363
|
}
|
|
355
|
-
function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir) {
|
|
356
|
-
|
|
364
|
+
async function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir, importedFilesLoaded) {
|
|
365
|
+
const sourcesInfo = [];
|
|
357
366
|
// interfaceFilesRelevant is sorted by sortAfterInheritanceOrder()
|
|
358
367
|
for (const interfaceFiles of Object.values(interfaceFilesRelevant)) {
|
|
359
368
|
const interfaceFilesDefiningConfig = interfaceFiles.filter((interfaceFile) => interfaceFile.configMap[configName]);
|
|
360
369
|
if (interfaceFilesDefiningConfig.length === 0)
|
|
361
370
|
continue;
|
|
362
|
-
sources = sources ?? [];
|
|
363
371
|
const visited = new WeakSet();
|
|
364
372
|
const add = (interfaceFile) => {
|
|
365
373
|
(0, utils_js_1.assert)(!visited.has(interfaceFile));
|
|
366
374
|
visited.add(interfaceFile);
|
|
367
|
-
|
|
368
|
-
sources.push(configValueSource);
|
|
375
|
+
sourcesInfo.push([configName, interfaceFile, configDef, userRootDir, importedFilesLoaded]);
|
|
369
376
|
};
|
|
370
377
|
// Main resolution logic
|
|
371
378
|
{
|
|
@@ -389,7 +396,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
389
396
|
if (interfaceFileWinner) {
|
|
390
397
|
const interfaceFilesOverriden = [...interfaceValueFiles, ...interfaceConfigFiles].filter((f) => f !== interfaceFileWinner);
|
|
391
398
|
// A user-land conflict of interfaceFiles with the same locationId means that the user has superfluously defined the config twice; the user should remove such redundancy making things unnecessarily ambiguous
|
|
392
|
-
warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden, configName
|
|
399
|
+
warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden, configName);
|
|
393
400
|
[interfaceFileWinner, ...interfaceFilesOverriden].forEach((interfaceFile) => {
|
|
394
401
|
add(interfaceFile);
|
|
395
402
|
});
|
|
@@ -414,7 +421,7 @@ function resolveConfigValueSources(configName, configDef, interfaceFilesRelevant
|
|
|
414
421
|
(0, utils_js_1.assert)(visited.has(interfaceFile));
|
|
415
422
|
});
|
|
416
423
|
}
|
|
417
|
-
|
|
424
|
+
const sources = await Promise.all(sourcesInfo.map(async (args) => await getConfigValueSource(...args)));
|
|
418
425
|
return sources;
|
|
419
426
|
}
|
|
420
427
|
function makeOrderDeterministic(interfaceFile1, interfaceFile2) {
|
|
@@ -425,41 +432,41 @@ function makeOrderDeterministic(interfaceFile1, interfaceFile2) {
|
|
|
425
432
|
return filePathRelativeToUserRootDir.length;
|
|
426
433
|
})(interfaceFile1, interfaceFile2);
|
|
427
434
|
}
|
|
428
|
-
function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden, configName
|
|
435
|
+
function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden, configName) {
|
|
429
436
|
interfaceFilesOverriden.forEach((interfaceFileLoser) => {
|
|
430
|
-
const
|
|
431
|
-
const
|
|
432
|
-
(0, utils_js_1.assertWarning)(false,
|
|
437
|
+
const loserFilePath = interfaceFileLoser.filePath.filePathToShowToUser;
|
|
438
|
+
const winnerFilePath = interfaceFileWinner.filePath.filePathToShowToUser;
|
|
439
|
+
(0, utils_js_1.assertWarning)(false, `Config ${configName} defined at ${loserFilePath} is always overwritten by ${configName} defined at ${winnerFilePath}, remove the superfluous ${configName} value defined at ${interfaceFileLoser}`, { onlyOnce: false });
|
|
433
440
|
});
|
|
434
441
|
}
|
|
435
442
|
function isInterfaceFileUserLand(interfaceFile) {
|
|
436
443
|
return (interfaceFile.isConfigFile && !interfaceFile.isConfigExtend) || interfaceFile.isValueFile;
|
|
437
444
|
}
|
|
438
|
-
function getConfigValueSource(configName, interfaceFile, configDef, userRootDir) {
|
|
445
|
+
async function getConfigValueSource(configName, interfaceFile, configDef, userRootDir, importedFilesLoaded) {
|
|
439
446
|
const conf = interfaceFile.configMap[configName];
|
|
440
447
|
(0, utils_js_1.assert)(conf);
|
|
441
448
|
const configEnv = configDef.env;
|
|
442
449
|
const definedAtConfigFile = {
|
|
443
450
|
...interfaceFile.filePath,
|
|
444
|
-
|
|
451
|
+
fileExportPathToShowToUser: ['default', configName]
|
|
445
452
|
};
|
|
446
453
|
if (configDef._valueIsFilePath) {
|
|
447
|
-
let
|
|
454
|
+
let definedAt;
|
|
448
455
|
let valueFilePath;
|
|
449
456
|
if (interfaceFile.isConfigFile) {
|
|
450
457
|
const { configValue } = conf;
|
|
451
458
|
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
452
|
-
const configDefinedAt =
|
|
459
|
+
const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, { definedAt: definedAtConfigFile });
|
|
453
460
|
(0, utils_js_1.assertUsage)(import_, `${configDefinedAt} should be an import`);
|
|
454
|
-
valueFilePath = import_.
|
|
455
|
-
|
|
461
|
+
valueFilePath = import_.filePathAbsoluteVite;
|
|
462
|
+
definedAt = import_;
|
|
456
463
|
}
|
|
457
464
|
else {
|
|
458
465
|
(0, utils_js_1.assert)(interfaceFile.isValueFile);
|
|
459
|
-
valueFilePath = interfaceFile.filePath.
|
|
460
|
-
|
|
466
|
+
valueFilePath = interfaceFile.filePath.filePathAbsoluteVite;
|
|
467
|
+
definedAt = {
|
|
461
468
|
...interfaceFile.filePath,
|
|
462
|
-
|
|
469
|
+
fileExportPathToShowToUser: []
|
|
463
470
|
};
|
|
464
471
|
}
|
|
465
472
|
const configValueSource = {
|
|
@@ -467,7 +474,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
467
474
|
valueIsFilePath: true,
|
|
468
475
|
configEnv,
|
|
469
476
|
valueIsImportedAtRuntime: true,
|
|
470
|
-
|
|
477
|
+
definedAt
|
|
471
478
|
};
|
|
472
479
|
return configValueSource;
|
|
473
480
|
}
|
|
@@ -479,8 +486,20 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
479
486
|
const configValueSource = {
|
|
480
487
|
configEnv,
|
|
481
488
|
valueIsImportedAtRuntime: true,
|
|
482
|
-
|
|
489
|
+
definedAt: import_
|
|
483
490
|
};
|
|
491
|
+
// Load config value
|
|
492
|
+
if (isConfigEnv(configDef, configName)) {
|
|
493
|
+
if (import_.filePathAbsoluteFilesystem) {
|
|
494
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(import_, 'filePathAbsoluteFilesystem', 'string')); // Help TS
|
|
495
|
+
const fileExports = await loadImportedFile(import_, userRootDir, importedFilesLoaded);
|
|
496
|
+
configValueSource.value = fileExports[import_.fileExportName];
|
|
497
|
+
}
|
|
498
|
+
else {
|
|
499
|
+
const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configValueSource);
|
|
500
|
+
(0, utils_js_1.assertUsage)(!configDef.cumulative, `${configDefinedAt} cannot be defined over an aliased import`);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
484
503
|
return configValueSource;
|
|
485
504
|
}
|
|
486
505
|
else {
|
|
@@ -488,7 +507,7 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
488
507
|
value: configValue,
|
|
489
508
|
configEnv,
|
|
490
509
|
valueIsImportedAtRuntime: false,
|
|
491
|
-
|
|
510
|
+
definedAt: definedAtConfigFile
|
|
492
511
|
};
|
|
493
512
|
return configValueSource;
|
|
494
513
|
}
|
|
@@ -498,9 +517,9 @@ function getConfigValueSource(configName, interfaceFile, configDef, userRootDir)
|
|
|
498
517
|
const configValueSource = {
|
|
499
518
|
configEnv,
|
|
500
519
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
501
|
-
|
|
520
|
+
definedAt: {
|
|
502
521
|
...interfaceFile.filePath,
|
|
503
|
-
|
|
522
|
+
fileExportPathToShowToUser: configName === interfaceFile.configName
|
|
504
523
|
? []
|
|
505
524
|
: // Side-effect config (e.g. `export { frontmatter }` of .md files)
|
|
506
525
|
[configName]
|
|
@@ -551,51 +570,61 @@ function resolveImport(configValue, importerFilePath, userRootDir, configEnv, co
|
|
|
551
570
|
if (!importData)
|
|
552
571
|
return null;
|
|
553
572
|
const { importPath, exportName } = importData;
|
|
554
|
-
const
|
|
555
|
-
assertFileEnv(
|
|
556
|
-
const
|
|
573
|
+
const filePathAbsoluteFilesystem = resolveImportPath(importData, importerFilePath);
|
|
574
|
+
assertFileEnv(filePathAbsoluteFilesystem ?? importPath, configEnv, configName);
|
|
575
|
+
const fileExportPathToShowToUser = exportName === 'default' || exportName === configName ? [] : [exportName];
|
|
557
576
|
if (importPath.startsWith('.')) {
|
|
558
577
|
// We need to resolve relative paths into absolute paths. Because the import paths are included in virtual files:
|
|
559
578
|
// ```
|
|
560
579
|
// [vite] Internal server error: Failed to resolve import "./onPageTransitionHooks" from "virtual:vike:pageConfigValuesAll:client:/pages/index". Does the file exist?
|
|
561
580
|
// ```
|
|
562
|
-
assertImportPath(
|
|
563
|
-
const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
fileExportPath,
|
|
567
|
-
filePathAbsolute,
|
|
581
|
+
assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath);
|
|
582
|
+
const filePathRelativeToUserRootDir = resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, importerFilePath, userRootDir);
|
|
583
|
+
const filePath = {
|
|
584
|
+
filePathAbsoluteFilesystem,
|
|
568
585
|
filePathRelativeToUserRootDir,
|
|
586
|
+
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
587
|
+
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
569
588
|
importPathAbsolute: null
|
|
570
589
|
};
|
|
590
|
+
return {
|
|
591
|
+
...filePath,
|
|
592
|
+
fileExportName: exportName,
|
|
593
|
+
fileExportPathToShowToUser
|
|
594
|
+
};
|
|
571
595
|
}
|
|
572
596
|
else {
|
|
573
597
|
// importPath can be:
|
|
574
598
|
// - an npm package import
|
|
575
599
|
// - a path alias
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
fileExportPath,
|
|
579
|
-
filePathAbsolute,
|
|
600
|
+
const filePath = {
|
|
601
|
+
filePathAbsoluteFilesystem,
|
|
580
602
|
filePathRelativeToUserRootDir: null,
|
|
603
|
+
filePathAbsoluteVite: importPath,
|
|
604
|
+
filePathToShowToUser: importPath,
|
|
581
605
|
importPathAbsolute: importPath
|
|
582
606
|
};
|
|
607
|
+
return {
|
|
608
|
+
...filePath,
|
|
609
|
+
fileExportName: exportName,
|
|
610
|
+
fileExportPathToShowToUser
|
|
611
|
+
};
|
|
583
612
|
}
|
|
584
613
|
}
|
|
585
|
-
function resolveImportPath_relativeToUserRootDir(
|
|
614
|
+
function resolveImportPath_relativeToUserRootDir(filePathAbsoluteFilesystem, importData, configFilePath, userRootDir) {
|
|
586
615
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
587
616
|
let filePathRelativeToUserRootDir;
|
|
588
|
-
if (
|
|
589
|
-
filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(
|
|
617
|
+
if (filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
618
|
+
filePathRelativeToUserRootDir = getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, userRootDir);
|
|
590
619
|
}
|
|
591
620
|
else {
|
|
592
|
-
(0, utils_js_1.assertUsage)(false, `${
|
|
621
|
+
(0, utils_js_1.assertUsage)(false, `${configFilePath.filePathToShowToUser} 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
622
|
// None of the following works. Seems to be a Vite bug?
|
|
594
623
|
// /*
|
|
595
|
-
// assert(
|
|
596
|
-
// filePath = `/@fs${
|
|
624
|
+
// assert(filePathAbsoluteFilesystem.startsWith('/'))
|
|
625
|
+
// filePath = `/@fs${filePathAbsoluteFilesystem}`
|
|
597
626
|
// /*/
|
|
598
|
-
// filePathRelativeToUserRootDir = path.posix.relative(userRootDir,
|
|
627
|
+
// filePathRelativeToUserRootDir = path.posix.relative(userRootDir, filePathAbsoluteFilesystem)
|
|
599
628
|
// assert(filePathRelativeToUserRootDir.startsWith('../'))
|
|
600
629
|
// filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir
|
|
601
630
|
// //*/
|
|
@@ -604,11 +633,11 @@ function resolveImportPath_relativeToUserRootDir(filePathAbsolute, importData, c
|
|
|
604
633
|
(0, utils_js_1.assert)(filePathRelativeToUserRootDir.startsWith('/'));
|
|
605
634
|
return filePathRelativeToUserRootDir;
|
|
606
635
|
}
|
|
607
|
-
function getVitePathFromAbsolutePath(
|
|
608
|
-
(0, utils_js_1.assertPosixPath)(
|
|
636
|
+
function getVitePathFromAbsolutePath(filePathAbsoluteFilesystem, root) {
|
|
637
|
+
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
609
638
|
(0, utils_js_1.assertPosixPath)(root);
|
|
610
|
-
(0, utils_js_1.assert)(
|
|
611
|
-
let vitePath = path_1.default.posix.relative(root,
|
|
639
|
+
(0, utils_js_1.assert)(filePathAbsoluteFilesystem.startsWith(root));
|
|
640
|
+
let vitePath = path_1.default.posix.relative(root, filePathAbsoluteFilesystem);
|
|
612
641
|
(0, utils_js_1.assert)(!vitePath.startsWith('/') && !vitePath.startsWith('.'));
|
|
613
642
|
vitePath = '/' + vitePath;
|
|
614
643
|
return vitePath;
|
|
@@ -621,9 +650,17 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
621
650
|
if (!configMeta)
|
|
622
651
|
return;
|
|
623
652
|
const meta = configMeta.configValue;
|
|
624
|
-
assertMetaValue(meta,
|
|
625
|
-
//
|
|
626
|
-
|
|
653
|
+
assertMetaValue(meta, `Config ${picocolors_1.default.cyan('meta')} defined at ${interfaceFile.filePath.filePathToShowToUser}`);
|
|
654
|
+
// Set configDef._userEffectDefinedAt
|
|
655
|
+
Object.entries(meta).forEach(([configName, configDef]) => {
|
|
656
|
+
if (!configDef.effect)
|
|
657
|
+
return;
|
|
658
|
+
(0, utils_js_1.assert)(interfaceFile.isConfigFile);
|
|
659
|
+
configDef._userEffectDefinedAt = {
|
|
660
|
+
...interfaceFile.filePath,
|
|
661
|
+
fileExportPathToShowToUser: ['default', 'meta', configName, 'effect']
|
|
662
|
+
};
|
|
663
|
+
});
|
|
627
664
|
(0, utils_js_1.objectEntries)(meta).forEach(([configName, configDefinition]) => {
|
|
628
665
|
// User can override an existing config definition
|
|
629
666
|
configDefinitions[configName] = {
|
|
@@ -636,9 +673,15 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
636
673
|
return configDefinitions;
|
|
637
674
|
}
|
|
638
675
|
function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
639
|
-
|
|
676
|
+
if (!(0, utils_js_1.isObject)(metaVal)) {
|
|
677
|
+
(0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
678
|
+
(0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} has an invalid type ${picocolors_1.default.cyan(typeof metaVal)}: it should be an object instead.`);
|
|
679
|
+
}
|
|
640
680
|
(0, utils_js_1.objectEntries)(metaVal).forEach(([configName, def]) => {
|
|
641
|
-
|
|
681
|
+
if (!(0, utils_js_1.isObject)(def)) {
|
|
682
|
+
(0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
683
|
+
(0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}`)} to a value with an invalid type ${picocolors_1.default.cyan(typeof def)}: it should be an object instead.`);
|
|
684
|
+
}
|
|
642
685
|
// env
|
|
643
686
|
{
|
|
644
687
|
const envValues = [
|
|
@@ -647,19 +690,34 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
647
690
|
'server-and-client',
|
|
648
691
|
'config-only'
|
|
649
692
|
];
|
|
650
|
-
const
|
|
651
|
-
`Set the value of ${picocolors_1.default.cyan(
|
|
693
|
+
const fix = [
|
|
694
|
+
`Set the value of ${picocolors_1.default.cyan(`meta.${configName}.env`)} to `,
|
|
652
695
|
(0, utils_js_1.joinEnglish)(envValues.map((s) => picocolors_1.default.cyan(`'${s}'`)), 'or'),
|
|
653
696
|
'.'
|
|
654
697
|
].join('');
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
698
|
+
if (!('env' in def)) {
|
|
699
|
+
(0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
700
|
+
(0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} doesn't set ${picocolors_1.default.cyan(`meta.${configName}.env`)} but it's required. ${fix}`);
|
|
701
|
+
}
|
|
702
|
+
if (!(0, utils_js_1.hasProp)(def, 'env', 'string')) {
|
|
703
|
+
(0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
704
|
+
(0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.env`)} to an invalid type ${picocolors_1.default.cyan(typeof def.env)}. ${fix}`);
|
|
705
|
+
}
|
|
706
|
+
if (!envValues.includes(def.env)) {
|
|
707
|
+
(0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
708
|
+
(0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.env`)} to an unknown value ${picocolors_1.default.cyan(`'${def.env}'`)}. ${fix}`);
|
|
709
|
+
}
|
|
658
710
|
}
|
|
659
711
|
// effect
|
|
660
712
|
if ('effect' in def) {
|
|
661
|
-
|
|
662
|
-
|
|
713
|
+
if (!(0, utils_js_1.hasProp)(def, 'effect', 'function')) {
|
|
714
|
+
(0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
715
|
+
(0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.effect`)} to an invalid type ${picocolors_1.default.cyan(typeof def.effect)}: it should be a function instead`);
|
|
716
|
+
}
|
|
717
|
+
if (def.env !== 'config-only') {
|
|
718
|
+
(0, utils_js_1.assert)(configMetaDefinedAt); // We expect internal effects to return a valid meta value
|
|
719
|
+
(0, utils_js_1.assertUsage)(false, `${configMetaDefinedAt} sets ${picocolors_1.default.cyan(`meta.${configName}.effect`)} but it's only supported if meta.${configName}.env is ${picocolors_1.default.cyan('config-only')} (but it's ${picocolors_1.default.cyan(def.env)} instead)`);
|
|
720
|
+
}
|
|
663
721
|
}
|
|
664
722
|
});
|
|
665
723
|
}
|
|
@@ -670,7 +728,7 @@ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
|
|
|
670
728
|
// The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
|
|
671
729
|
// (We could support effect for non config-only by always loading its value at config time, regardless of the config's `env` value.)
|
|
672
730
|
(0, utils_js_1.assertUsage)(configDef.env === 'config-only', [
|
|
673
|
-
`Cannot add effect to ${picocolors_1.default.cyan(configName)} because its ${picocolors_1.default.cyan('env')} is ${picocolors_1.default.cyan(configDef.env)}: effects can only be added to configs with an env
|
|
731
|
+
`Cannot add effect to ${picocolors_1.default.cyan(configName)} because its ${picocolors_1.default.cyan('env')} is ${picocolors_1.default.cyan(configDef.env)}: effects can only be added to configs with an ${picocolors_1.default.cyan('env')} value of ${picocolors_1.default.cyan('config-only')}.`
|
|
674
732
|
].join(' '));
|
|
675
733
|
const source = configValueSources[configName]?.[0];
|
|
676
734
|
if (!source)
|
|
@@ -680,19 +738,28 @@ function applyEffectsAll(configValueSources, configDefinitionsRelevant) {
|
|
|
680
738
|
// Call effect
|
|
681
739
|
const configModFromEffect = configDef.effect({
|
|
682
740
|
configValue: source.value,
|
|
683
|
-
configDefinedAt:
|
|
741
|
+
configDefinedAt: (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, source)
|
|
684
742
|
});
|
|
685
743
|
if (!configModFromEffect)
|
|
686
744
|
return;
|
|
687
745
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(source, 'value')); // We need to assume that the config value is loaded at build-time
|
|
688
|
-
applyEffect(configModFromEffect,
|
|
746
|
+
applyEffect(configModFromEffect, configValueSources, configDef);
|
|
689
747
|
});
|
|
690
748
|
}
|
|
691
|
-
function applyEffect(configModFromEffect,
|
|
749
|
+
function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
692
750
|
const notSupported = `Effects currently only supports modifying the the ${picocolors_1.default.cyan('env')} of a config.`;
|
|
693
751
|
(0, utils_js_1.objectEntries)(configModFromEffect).forEach(([configName, configValue]) => {
|
|
694
752
|
if (configName === 'meta') {
|
|
695
|
-
|
|
753
|
+
let configDefinedAtString;
|
|
754
|
+
if (configDefEffect._userEffectDefinedAt) {
|
|
755
|
+
configDefinedAtString = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, {
|
|
756
|
+
definedAt: configDefEffect._userEffectDefinedAt
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
else {
|
|
760
|
+
configDefinedAtString = null;
|
|
761
|
+
}
|
|
762
|
+
assertMetaValue(configValue, configDefinedAtString);
|
|
696
763
|
(0, utils_js_1.objectEntries)(configValue).forEach(([configTargetName, configTargetDef]) => {
|
|
697
764
|
{
|
|
698
765
|
const keys = Object.keys(configTargetDef);
|
|
@@ -710,7 +777,7 @@ function applyEffect(configModFromEffect, configValueEffectSource, configValueSo
|
|
|
710
777
|
else {
|
|
711
778
|
(0, utils_js_1.assertUsage)(false, notSupported);
|
|
712
779
|
// If we do end implementing being able to set the value of a config:
|
|
713
|
-
// - For setting
|
|
780
|
+
// - For setting definedAt: we could take the definedAt of the effect config while appending '(effect)' to definedAt.fileExportPathToShowToUser
|
|
714
781
|
}
|
|
715
782
|
});
|
|
716
783
|
}
|
|
@@ -761,20 +828,29 @@ async function findPlusFiles(userRootDir, ignoreDirs, isDev, extensions) {
|
|
|
761
828
|
const plusFiles = result.map((p) => {
|
|
762
829
|
p = (0, utils_js_1.toPosixPath)(p);
|
|
763
830
|
const filePathRelativeToUserRootDir = path_1.default.posix.join('/', p);
|
|
764
|
-
const
|
|
765
|
-
return {
|
|
831
|
+
const filePathAbsoluteFilesystem = path_1.default.posix.join(userRootDir, p);
|
|
832
|
+
return {
|
|
833
|
+
filePathRelativeToUserRootDir,
|
|
834
|
+
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
835
|
+
filePathAbsoluteFilesystem,
|
|
836
|
+
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
837
|
+
importPathAbsolute: null
|
|
838
|
+
};
|
|
766
839
|
});
|
|
840
|
+
// TODO/v1-release: remove
|
|
767
841
|
extensions.forEach((extension) => {
|
|
768
842
|
extension.pageConfigsDistFiles?.forEach((pageConfigDistFile) => {
|
|
769
|
-
// TODO/v1-release: remove
|
|
770
843
|
if (!pageConfigDistFile.importPath.includes('+'))
|
|
771
844
|
return;
|
|
772
845
|
(0, utils_js_1.assert)(pageConfigDistFile.importPath.includes('+'));
|
|
773
846
|
(0, utils_js_1.assert)(path_1.default.posix.basename(pageConfigDistFile.importPath).startsWith('+'));
|
|
774
847
|
const { importPath, filePath } = pageConfigDistFile;
|
|
775
848
|
plusFiles.push({
|
|
776
|
-
filePathRelativeToUserRootDir:
|
|
777
|
-
|
|
849
|
+
filePathRelativeToUserRootDir: null,
|
|
850
|
+
filePathAbsoluteVite: importPath,
|
|
851
|
+
filePathAbsoluteFilesystem: filePath,
|
|
852
|
+
filePathToShowToUser: importPath,
|
|
853
|
+
importPathAbsolute: importPath
|
|
778
854
|
});
|
|
779
855
|
});
|
|
780
856
|
});
|
|
@@ -804,12 +880,12 @@ function assertNoUnexpectedPlusSign(filePath, fileName) {
|
|
|
804
880
|
(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`);
|
|
805
881
|
}
|
|
806
882
|
async function loadConfigFile(configFilePath, userRootDir, visited) {
|
|
807
|
-
const {
|
|
808
|
-
assertNoInfiniteLoop(visited,
|
|
883
|
+
const { filePathAbsoluteFilesystem } = configFilePath;
|
|
884
|
+
assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem);
|
|
809
885
|
const { fileExports } = await (0, transpileAndExecuteFile_js_1.transpileAndExecuteFile)(configFilePath, false, userRootDir);
|
|
810
886
|
const { extendsConfigs, extendsFilePaths } = await loadExtendsConfigs(fileExports, configFilePath, userRootDir, [
|
|
811
887
|
...visited,
|
|
812
|
-
|
|
888
|
+
filePathAbsoluteFilesystem
|
|
813
889
|
]);
|
|
814
890
|
const configFile = {
|
|
815
891
|
fileExports,
|
|
@@ -818,31 +894,31 @@ async function loadConfigFile(configFilePath, userRootDir, visited) {
|
|
|
818
894
|
};
|
|
819
895
|
return { configFile, extendsConfigs };
|
|
820
896
|
}
|
|
821
|
-
function assertNoInfiniteLoop(visited,
|
|
822
|
-
const idx = visited.indexOf(
|
|
897
|
+
function assertNoInfiniteLoop(visited, filePathAbsoluteFilesystem) {
|
|
898
|
+
const idx = visited.indexOf(filePathAbsoluteFilesystem);
|
|
823
899
|
if (idx === -1)
|
|
824
900
|
return;
|
|
825
901
|
const loop = visited.slice(idx);
|
|
826
|
-
(0, utils_js_1.assert)(loop[0] ===
|
|
827
|
-
(0, utils_js_1.assertUsage)(idx === -1, `Infinite extends loop ${[...loop,
|
|
902
|
+
(0, utils_js_1.assert)(loop[0] === filePathAbsoluteFilesystem);
|
|
903
|
+
(0, utils_js_1.assertUsage)(idx === -1, `Infinite extends loop ${[...loop, filePathAbsoluteFilesystem].join('>')}`);
|
|
828
904
|
}
|
|
829
905
|
async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir, visited) {
|
|
830
906
|
const extendsImportData = getExtendsImportData(configFileExports, configFilePath);
|
|
831
907
|
const extendsConfigFiles = [];
|
|
832
908
|
extendsImportData.map((importData) => {
|
|
833
909
|
const { importPath: importPath } = importData;
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
assertImportPath(filePathAbsolute, importData, configFilePath);
|
|
838
|
-
assertExtendsImportPath(importPath, filePathAbsolute, configFilePath);
|
|
910
|
+
const filePathAbsoluteFilesystem = resolveImportPath(importData, configFilePath);
|
|
911
|
+
assertImportPath(filePathAbsoluteFilesystem, importData, configFilePath);
|
|
912
|
+
assertExtendsImportPath(importPath, filePathAbsoluteFilesystem, configFilePath);
|
|
839
913
|
// - filePathRelativeToUserRootDir has no functionality beyond nicer error messages for user
|
|
840
|
-
// - Using importPath would be visually nicer but it's ambigous => we rather pick
|
|
841
|
-
const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(
|
|
914
|
+
// - Using importPath would be visually nicer but it's ambigous => we rather pick filePathAbsoluteFilesystem for added clarity
|
|
915
|
+
const filePathRelativeToUserRootDir = determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir);
|
|
916
|
+
const filePathAbsoluteVite = filePathRelativeToUserRootDir ?? importPath;
|
|
842
917
|
extendsConfigFiles.push({
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
filePathRelativeToUserRootDir
|
|
918
|
+
filePathAbsoluteFilesystem,
|
|
919
|
+
filePathAbsoluteVite,
|
|
920
|
+
filePathRelativeToUserRootDir,
|
|
921
|
+
filePathToShowToUser: filePathAbsoluteVite,
|
|
846
922
|
importPathAbsolute: importPath
|
|
847
923
|
});
|
|
848
924
|
});
|
|
@@ -852,16 +928,16 @@ async function loadExtendsConfigs(configFileExports, configFilePath, userRootDir
|
|
|
852
928
|
extendsConfigs.push(result.configFile);
|
|
853
929
|
extendsConfigs.push(...result.extendsConfigs);
|
|
854
930
|
}));
|
|
855
|
-
const extendsFilePaths = extendsConfigFiles.map((f) => f.
|
|
931
|
+
const extendsFilePaths = extendsConfigFiles.map((f) => f.filePathAbsoluteFilesystem);
|
|
856
932
|
return { extendsConfigs, extendsFilePaths };
|
|
857
933
|
}
|
|
858
|
-
function determineFilePathRelativeToUserDir(
|
|
859
|
-
(0, utils_js_1.assertPosixPath)(
|
|
934
|
+
function determineFilePathRelativeToUserDir(filePathAbsoluteFilesystem, userRootDir) {
|
|
935
|
+
(0, utils_js_1.assertPosixPath)(filePathAbsoluteFilesystem);
|
|
860
936
|
(0, utils_js_1.assertPosixPath)(userRootDir);
|
|
861
|
-
if (!
|
|
937
|
+
if (!filePathAbsoluteFilesystem.startsWith(userRootDir)) {
|
|
862
938
|
return null;
|
|
863
939
|
}
|
|
864
|
-
let filePathRelativeToUserRootDir =
|
|
940
|
+
let filePathRelativeToUserRootDir = filePathAbsoluteFilesystem.slice(userRootDir.length);
|
|
865
941
|
if (!filePathRelativeToUserRootDir.startsWith('/'))
|
|
866
942
|
filePathRelativeToUserRootDir = '/' + filePathRelativeToUserRootDir;
|
|
867
943
|
return filePathRelativeToUserRootDir;
|
|
@@ -878,14 +954,14 @@ function assertExtendsImportPath(importPath, filePath, configFilePath) {
|
|
|
878
954
|
});
|
|
879
955
|
}
|
|
880
956
|
else {
|
|
881
|
-
(0, utils_js_1.assertWarning)(false, `${
|
|
957
|
+
(0, utils_js_1.assertWarning)(false, `${configFilePath.filePathToShowToUser} uses ${picocolors_1.default.cyan('extends')} to inherit from ${picocolors_1.default.cyan(importPath)} which is a user-land file: this is experimental and may be remove at any time. Reach out to a maintainer if you need this feature.`, { onlyOnce: true });
|
|
882
958
|
}
|
|
883
959
|
}
|
|
884
960
|
function getExtendsImportData(configFileExports, configFilePath) {
|
|
885
|
-
const filePathToShowToUser =
|
|
961
|
+
const { filePathToShowToUser } = configFilePath;
|
|
886
962
|
(0, assertExports_js_1.assertExportsOfConfigFile)(configFileExports, filePathToShowToUser);
|
|
887
963
|
const defaultExports = configFileExports.default;
|
|
888
|
-
const wrongUsage = `${filePathToShowToUser} sets the config 'extends' to an invalid value, see https://vike.dev/extends`;
|
|
964
|
+
const wrongUsage = `${filePathToShowToUser} sets the config ${picocolors_1.default.cyan('extends')} to an invalid value, see https://vike.dev/extends`;
|
|
889
965
|
let extendList;
|
|
890
966
|
if (!('extends' in defaultExports)) {
|
|
891
967
|
return [];
|
|
@@ -906,38 +982,6 @@ function getExtendsImportData(configFileExports, configFilePath) {
|
|
|
906
982
|
});
|
|
907
983
|
return extendsImportData;
|
|
908
984
|
}
|
|
909
|
-
// TODO: re-use this
|
|
910
|
-
function handleUserFileError(err, isDev) {
|
|
911
|
-
// Properly handle error during transpilation so that we can use assertUsage() during transpilation
|
|
912
|
-
if (isDev) {
|
|
913
|
-
throw err;
|
|
914
|
-
}
|
|
915
|
-
else {
|
|
916
|
-
// Avoid ugly error format:
|
|
917
|
-
// ```
|
|
918
|
-
// [vike:importUserCode] Could not load virtual:vike:importUserCode:server: [vike@0.4.70][Wrong Usage] /pages/+config.ts sets the config 'onRenderHtml' to the value './+config/onRenderHtml-i-dont-exist.js' but no file was found at /home/rom/code/vike/examples/v1/pages/+config/onRenderHtml-i-dont-exist.js
|
|
919
|
-
// Error: [vike@0.4.70][Wrong Usage] /pages/+config.ts sets the config 'onRenderHtml' to the value './+config/onRenderHtml-i-dont-exist.js' but no file was found at /home/rom/code/vike/examples/v1/pages/+config/onRenderHtml-i-dont-exist.js
|
|
920
|
-
// at ...
|
|
921
|
-
// at ...
|
|
922
|
-
// at ...
|
|
923
|
-
// at ...
|
|
924
|
-
// at ...
|
|
925
|
-
// at ...
|
|
926
|
-
// code: 'PLUGIN_ERROR',
|
|
927
|
-
// plugin: 'vike:importUserCode',
|
|
928
|
-
// hook: 'load',
|
|
929
|
-
// watchFiles: [
|
|
930
|
-
// '/home/rom/code/vike/vike/dist/esm/node/importBuild.js',
|
|
931
|
-
// '\x00virtual:vike:importUserCode:server'
|
|
932
|
-
// ]
|
|
933
|
-
// }
|
|
934
|
-
// ELIFECYCLE Command failed with exit code 1.
|
|
935
|
-
// ```
|
|
936
|
-
console.log('');
|
|
937
|
-
console.error(err);
|
|
938
|
-
process.exit(1);
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
985
|
function isGlobalConfig(configName) {
|
|
942
986
|
if (configName === 'prerender')
|
|
943
987
|
return false;
|
|
@@ -947,15 +991,15 @@ function isGlobalConfig(configName) {
|
|
|
947
991
|
function getConfigNamesGlobal() {
|
|
948
992
|
return Object.keys(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal);
|
|
949
993
|
}
|
|
950
|
-
function assertConfigExists(configName, configNamesRelevant,
|
|
994
|
+
function assertConfigExists(configName, configNamesRelevant, filePathToShowToUser) {
|
|
951
995
|
const configNames = [...configNamesRelevant, ...getConfigNamesGlobal()];
|
|
952
996
|
if (configNames.includes(configName))
|
|
953
997
|
return;
|
|
954
|
-
handleUnknownConfig(configName, configNames,
|
|
998
|
+
handleUnknownConfig(configName, configNames, filePathToShowToUser);
|
|
955
999
|
(0, utils_js_1.assert)(false);
|
|
956
1000
|
}
|
|
957
|
-
function handleUnknownConfig(configName, configNames,
|
|
958
|
-
let errMsg = `${
|
|
1001
|
+
function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
1002
|
+
let errMsg = `${filePathToShowToUser} defines an unknown config ${picocolors_1.default.cyan(configName)}`;
|
|
959
1003
|
let configNameSimilar = null;
|
|
960
1004
|
if (configName === 'page') {
|
|
961
1005
|
configNameSimilar = 'Page';
|
|
@@ -987,11 +1031,11 @@ function determineRouteFilesystem(locationId, configValueSources) {
|
|
|
987
1031
|
if (configFilesystemRoutingRoot) {
|
|
988
1032
|
const routingRoot = getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName);
|
|
989
1033
|
if (routingRoot) {
|
|
990
|
-
const { filesystemRoutingRootEffect
|
|
1034
|
+
const { filesystemRoutingRootEffect /*, filesystemRoutingRootDefinedAt*/ } = routingRoot;
|
|
991
1035
|
const debugInfo = { locationId, routeFilesystem: filesystemRouteString, configFilesystemRoutingRoot };
|
|
992
1036
|
(0, utils_js_1.assert)(filesystemRouteString.startsWith(filesystemRoutingRootEffect.before), debugInfo);
|
|
993
1037
|
filesystemRouteString = (0, filesystemRouting_js_1.applyFilesystemRoutingRootEffect)(filesystemRouteString, filesystemRoutingRootEffect);
|
|
994
|
-
filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${filesystemRoutingRootDefinedAt})
|
|
1038
|
+
// filesystemRouteDefinedBy = `${filesystemRouteDefinedBy} (with ${filesystemRoutingRootDefinedAt})`
|
|
995
1039
|
}
|
|
996
1040
|
}
|
|
997
1041
|
(0, utils_js_1.assert)(filesystemRouteString.startsWith('/'));
|
|
@@ -1006,10 +1050,10 @@ function getFilesystemRoutingRootEffect(configFilesystemRoutingRoot, configName)
|
|
|
1006
1050
|
// Eagerly loaded since it's config-only
|
|
1007
1051
|
(0, utils_js_1.assert)('value' in configFilesystemRoutingRoot);
|
|
1008
1052
|
const { value } = configFilesystemRoutingRoot;
|
|
1009
|
-
const configDefinedAt =
|
|
1053
|
+
const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configFilesystemRoutingRoot);
|
|
1010
1054
|
(0, utils_js_1.assertUsage)(typeof value === 'string', `${configDefinedAt} should be a string`);
|
|
1011
1055
|
(0, utils_js_1.assertUsage)(value.startsWith('/'), `${configDefinedAt} is ${picocolors_1.default.cyan(value)} but it should start with a leading slash ${picocolors_1.default.cyan('/')}`);
|
|
1012
|
-
const { filePathRelativeToUserRootDir } = configFilesystemRoutingRoot.
|
|
1056
|
+
const { filePathRelativeToUserRootDir } = configFilesystemRoutingRoot.definedAt;
|
|
1013
1057
|
(0, utils_js_1.assert)(filePathRelativeToUserRootDir);
|
|
1014
1058
|
const before = (0, filesystemRouting_js_1.getFilesystemRouteString)((0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir));
|
|
1015
1059
|
const after = value;
|
|
@@ -1021,17 +1065,17 @@ function determineIsErrorPage(routeFilesystem) {
|
|
|
1021
1065
|
return routeFilesystem.split('/').includes('_error');
|
|
1022
1066
|
}
|
|
1023
1067
|
function resolveImportPath(importData, importerFilePath) {
|
|
1024
|
-
const importerFilePathAbsolute = importerFilePath.
|
|
1068
|
+
const importerFilePathAbsolute = importerFilePath.filePathAbsoluteFilesystem;
|
|
1025
1069
|
(0, utils_js_1.assertPosixPath)(importerFilePathAbsolute);
|
|
1026
1070
|
const cwd = path_1.default.posix.dirname(importerFilePathAbsolute);
|
|
1027
|
-
//
|
|
1028
|
-
const
|
|
1029
|
-
return
|
|
1071
|
+
// filePathAbsoluteFilesystem is expected to be null when importData.importPath is a Vite path alias
|
|
1072
|
+
const filePathAbsoluteFilesystem = (0, utils_js_1.requireResolve)(importData.importPath, cwd);
|
|
1073
|
+
return filePathAbsoluteFilesystem;
|
|
1030
1074
|
}
|
|
1031
|
-
function assertImportPath(
|
|
1075
|
+
function assertImportPath(filePathAbsoluteFilesystem, importData, importerFilePath) {
|
|
1032
1076
|
const { importPath: importPath, importStringWasGenerated, importString } = importData;
|
|
1033
|
-
const filePathToShowToUser =
|
|
1034
|
-
if (!
|
|
1077
|
+
const { filePathToShowToUser } = importerFilePath;
|
|
1078
|
+
if (!filePathAbsoluteFilesystem) {
|
|
1035
1079
|
const importPathString = picocolors_1.default.cyan(`'${importPath}'`);
|
|
1036
1080
|
const errIntro = importStringWasGenerated
|
|
1037
1081
|
? `The import path ${importPathString} in ${filePathToShowToUser}`
|
|
@@ -1074,7 +1118,6 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
1074
1118
|
configValues[configName] = {
|
|
1075
1119
|
value,
|
|
1076
1120
|
definedAt: {
|
|
1077
|
-
isCumulative: true,
|
|
1078
1121
|
files: sources.map((source) => getDefinedAtFile(source))
|
|
1079
1122
|
}
|
|
1080
1123
|
};
|
|
@@ -1082,18 +1125,23 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
1082
1125
|
});
|
|
1083
1126
|
return configValues;
|
|
1084
1127
|
}
|
|
1128
|
+
function getDefinedAtFile(configValueSource) {
|
|
1129
|
+
return {
|
|
1130
|
+
filePathToShowToUser: configValueSource.definedAt.filePathToShowToUser,
|
|
1131
|
+
fileExportPathToShowToUser: configValueSource.definedAt.fileExportPathToShowToUser
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
function getDefinedAt(configValueSource) {
|
|
1135
|
+
return getDefinedAtFile(configValueSource);
|
|
1136
|
+
}
|
|
1085
1137
|
function mergeCumulative(configName, configValueSources) {
|
|
1086
1138
|
const valuesArr = [];
|
|
1087
1139
|
const valuesSet = [];
|
|
1088
1140
|
let configValueSourcePrevious = null;
|
|
1089
1141
|
configValueSources.forEach((configValueSource) => {
|
|
1090
|
-
const configDefinedAt =
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
(0, utils_js_1.assertUsage)('value' in configValueSource, `${configDefinedAt} is only allowed to be defined in a +config.h.js file. (Because the values of ${configNameColored} are cumulative.)`);
|
|
1094
|
-
/* This is more confusing than adding value. For example, this explanation shouldn't be shown for the passToClient config.
|
|
1095
|
-
const explanation = `(Because the values of ${configNameColored} are cumulative and therefore merged together.)` as const
|
|
1096
|
-
*/
|
|
1142
|
+
const configDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configValueSource);
|
|
1143
|
+
// We could, in principle, also support cumulative for values that aren't loaded at config-time but it isn't completely trivial to implement.
|
|
1144
|
+
(0, utils_js_1.assert)('value' in configValueSource);
|
|
1097
1145
|
// Make sure configValueSource.value is serializable
|
|
1098
1146
|
(0, getVirtualFilePageConfigs_js_1.getConfigValueSerialized)(configValueSource.value, configName, getDefinedAt(configValueSource));
|
|
1099
1147
|
const assertNoMixing = (isSet) => {
|
|
@@ -1105,7 +1153,7 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1105
1153
|
if (vals2.length === 0)
|
|
1106
1154
|
return;
|
|
1107
1155
|
(0, utils_js_1.assert)(configValueSourcePrevious);
|
|
1108
|
-
const configPreviousDefinedAt =
|
|
1156
|
+
const configPreviousDefinedAt = (0, helpers_js_1.getConfigDefinedAtString)('Config', configName, configValueSourcePrevious);
|
|
1109
1157
|
(0, utils_js_1.assertUsage)(false, `${configDefinedAt} sets ${t1} but another ${configPreviousDefinedAt} sets ${t2} which is forbidden: the values must be all arrays or all sets (you cannot mix).`);
|
|
1110
1158
|
};
|
|
1111
1159
|
const { value } = configValueSource;
|
|
@@ -1136,30 +1184,3 @@ function mergeCumulative(configName, configValueSources) {
|
|
|
1136
1184
|
}
|
|
1137
1185
|
(0, utils_js_1.assert)(false);
|
|
1138
1186
|
}
|
|
1139
|
-
// TODO: rename
|
|
1140
|
-
// TODO: refactor
|
|
1141
|
-
function getConfigSourceDefinedAtString(configName, { definedAtInfo }, isEffect = undefined, sentenceBegin = true) {
|
|
1142
|
-
return (0, utils_js_2.getConfigDefinedAtString)(configName, {
|
|
1143
|
-
definedAt: {
|
|
1144
|
-
isEffect,
|
|
1145
|
-
file: {
|
|
1146
|
-
filePathToShowToUser: getDefinedAtFilePathToShowToUser(definedAtInfo),
|
|
1147
|
-
fileExportPath: definedAtInfo.fileExportPath
|
|
1148
|
-
}
|
|
1149
|
-
}
|
|
1150
|
-
}, sentenceBegin);
|
|
1151
|
-
}
|
|
1152
|
-
function getDefinedAtFilePathToShowToUser(definedAtInfo) {
|
|
1153
|
-
return definedAtInfo.filePathRelativeToUserRootDir ?? definedAtInfo.importPathAbsolute;
|
|
1154
|
-
}
|
|
1155
|
-
function getDefinedAtFile(source) {
|
|
1156
|
-
return {
|
|
1157
|
-
filePathToShowToUser: getDefinedAtFilePathToShowToUser(source.definedAtInfo),
|
|
1158
|
-
fileExportPath: source.definedAtInfo.fileExportPath
|
|
1159
|
-
};
|
|
1160
|
-
}
|
|
1161
|
-
function getDefinedAt(configValueSource) {
|
|
1162
|
-
return {
|
|
1163
|
-
file: getDefinedAtFile(configValueSource)
|
|
1164
|
-
};
|
|
1165
|
-
}
|