vike 0.4.160 → 0.4.161-commit-0e9c635
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/cli/bin.js +5 -0
- package/dist/cjs/node/client/router.js +4 -2
- package/dist/cjs/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/cjs/node/plugin/plugins/buildConfig/fixServerAssets.js +148 -0
- package/dist/cjs/node/plugin/plugins/buildConfig.js +61 -35
- package/dist/cjs/node/plugin/plugins/commonConfig.js +5 -13
- package/dist/cjs/node/plugin/plugins/config/stemUtils.js +1 -1
- package/dist/cjs/node/plugin/plugins/distFileNames.js +9 -1
- package/dist/cjs/node/plugin/plugins/envVars.js +6 -2
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +16 -4
- package/dist/cjs/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/cjs/node/plugin/plugins/importBuild/getVikeManifest.js +1 -21
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +5 -8
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +11 -91
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +28 -46
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +5 -5
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +33 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +7 -7
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +21 -27
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +157 -111
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/cjs/node/plugin/plugins/setGlobalContext.js +0 -14
- package/dist/cjs/node/plugin/shared/rollupSourceMap.js +20 -0
- package/dist/cjs/node/plugin/utils.js +3 -2
- package/dist/cjs/node/prerender/runPrerender.js +13 -5
- package/dist/cjs/node/runtime/globalContext.js +15 -23
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/cjs/node/runtime/html/renderHtml.js +1 -1
- package/dist/cjs/node/runtime/html/stream.js +2 -2
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +39 -39
- package/dist/cjs/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -5
- package/dist/cjs/node/runtime/renderPage/getPageAssets/getManifestEntry.js +6 -7
- package/dist/cjs/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +23 -28
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +81 -43
- package/dist/cjs/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -23
- package/dist/cjs/node/runtime/utils.js +1 -1
- package/dist/cjs/node/shared/assertPluginManifest.js +1 -4
- package/dist/cjs/node/shared/assertV1Design.js +26 -0
- package/dist/cjs/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +3 -3
- package/dist/cjs/node/shared/prependEntriesDir.js +13 -0
- package/dist/cjs/node/shared/utils.js +2 -0
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/cjs/shared/route/executeGuardHook.js +3 -2
- package/dist/cjs/shared/utils.js +0 -1
- package/dist/cjs/utils/assertNodeVersion.js +2 -2
- package/dist/cjs/utils/{findUserPackageJsonPath.js → findFile.js} +11 -8
- package/dist/cjs/utils/isVersionOrAbove.js +29 -0
- package/dist/cjs/utils/nodeEnv.js +23 -1
- package/dist/cjs/utils/objectKeys.js +19 -3
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/cjs/utils/sorter.js +62 -1
- package/dist/esm/client/client-routing-runtime/index.d.ts +1 -1
- package/dist/esm/client/client-routing-runtime/index.js +1 -1
- package/dist/esm/node/cli/bin.js +3 -1
- package/dist/esm/node/client/router.d.ts +2 -0
- package/dist/esm/node/client/router.js +3 -1
- package/dist/esm/node/plugin/plugins/autoFullBuild.js +2 -2
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.d.ts +13 -0
- package/dist/esm/node/plugin/plugins/buildConfig/fixServerAssets.js +142 -0
- package/dist/esm/node/plugin/plugins/buildConfig.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/buildConfig.js +60 -34
- package/dist/esm/node/plugin/plugins/commonConfig.js +6 -14
- package/dist/esm/node/plugin/plugins/config/stemUtils.js +2 -2
- package/dist/esm/node/plugin/plugins/distFileNames.js +9 -1
- package/dist/esm/node/plugin/plugins/envVars.js +6 -2
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +17 -5
- package/dist/esm/node/plugin/plugins/extractExportNamesPlugin.js +2 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.d.ts +1 -2
- package/dist/esm/node/plugin/plugins/importBuild/getVikeManifest.js +2 -19
- package/dist/esm/node/plugin/plugins/importBuild/index.d.ts +6 -1
- package/dist/esm/node/plugin/plugins/importBuild/index.js +5 -8
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +13 -93
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +1 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.d.ts +39 -12
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/filesystemRouting.js +29 -47
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.js → loadFileAtConfigTime.js} +4 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveFilePath.js +27 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/resolveImportPath.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.d.ts → transformFileImports.d.ts} +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{transformImports.js → transformFileImports.js} +6 -6
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.d.ts +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +20 -26
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +155 -109
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/esm/node/plugin/plugins/setGlobalContext.js +1 -15
- package/dist/esm/node/plugin/shared/rollupSourceMap.d.ts +14 -0
- package/dist/esm/node/plugin/shared/rollupSourceMap.js +17 -0
- package/dist/esm/node/plugin/utils.d.ts +3 -2
- package/dist/esm/node/plugin/utils.js +3 -2
- package/dist/esm/node/prerender/runPrerender.js +15 -7
- package/dist/esm/node/runtime/globalContext.d.ts +3 -10
- package/dist/esm/node/runtime/globalContext.js +15 -23
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +2 -2
- package/dist/esm/node/runtime/html/renderHtml.js +1 -1
- package/dist/esm/node/runtime/html/stream.js +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +2 -2
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.d.ts +6 -5
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +39 -39
- package/dist/esm/node/runtime/renderPage/getPageAssets/assertClientEntryId.js +0 -5
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/getManifestEntry.js +6 -7
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsProd.js +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +24 -29
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +8 -0
- package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError.js → logErrorHint.js} +80 -42
- package/dist/esm/node/runtime/renderPage/loggerProd.js +3 -3
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +3 -24
- package/dist/esm/node/runtime/utils.d.ts +1 -1
- package/dist/esm/node/runtime/utils.js +1 -1
- package/dist/esm/node/shared/ViteManifest.d.ts +1 -0
- package/dist/esm/node/shared/assertPluginManifest.d.ts +0 -1
- package/dist/esm/node/shared/assertPluginManifest.js +2 -5
- package/dist/esm/node/shared/assertV1Design.d.ts +4 -0
- package/dist/esm/node/shared/assertV1Design.js +23 -0
- package/dist/esm/node/shared/getClientEntry.d.ts +3 -0
- package/dist/esm/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +2 -2
- package/dist/esm/node/shared/prependEntriesDir.d.ts +2 -0
- package/dist/esm/node/shared/prependEntriesDir.js +10 -0
- package/dist/esm/node/shared/utils.d.ts +2 -0
- package/dist/esm/node/shared/utils.js +2 -0
- package/dist/esm/shared/page-configs/Config.d.ts +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +3 -3
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +53 -26
- package/dist/esm/shared/route/executeGuardHook.js +3 -2
- package/dist/esm/shared/utils.d.ts +0 -1
- package/dist/esm/shared/utils.js +0 -1
- package/dist/esm/utils/assertNodeVersion.js +2 -2
- package/dist/esm/utils/findFile.d.ts +3 -0
- package/dist/esm/utils/findFile.js +21 -0
- package/dist/esm/utils/getOutDirs.d.ts +1 -0
- package/dist/esm/utils/isVersionOrAbove.d.ts +2 -0
- package/dist/esm/utils/isVersionOrAbove.js +26 -0
- package/dist/esm/utils/nodeEnv.d.ts +4 -0
- package/dist/esm/utils/nodeEnv.js +19 -0
- package/dist/esm/utils/objectKeys.d.ts +10 -1
- package/dist/esm/utils/objectKeys.js +20 -3
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/dist/esm/utils/sorter.d.ts +59 -0
- package/dist/esm/utils/sorter.js +61 -0
- package/package.json +2 -2
- package/dist/cjs/node/plugin/shared/removeSourceMap.js +0 -12
- package/dist/cjs/utils/objectEntries.js +0 -8
- package/dist/esm/node/plugin/shared/removeSourceMap.d.ts +0 -7
- package/dist/esm/node/plugin/shared/removeSourceMap.js +0 -9
- package/dist/esm/node/runtime/renderPage/logHintForCjsEsmError.d.ts +0 -13
- package/dist/esm/node/shared/getClientEntryFilePath.d.ts +0 -3
- package/dist/esm/utils/findUserPackageJsonPath.d.ts +0 -2
- package/dist/esm/utils/findUserPackageJsonPath.js +0 -18
- package/dist/esm/utils/objectEntries.d.ts +0 -4
- package/dist/esm/utils/objectEntries.js +0 -5
- /package/dist/cjs/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
- /package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/{loadFileConfigEnv.d.ts → loadFileAtConfigTime.d.ts} +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.d.ts +0 -0
- /package/dist/esm/node/runtime/renderPage/{logHintForCjsEsmError → logErrorHint}/errors.js +0 -0
|
@@ -2,7 +2,8 @@ export { getVikeConfig };
|
|
|
2
2
|
export { reloadVikeConfig };
|
|
3
3
|
export { vikeConfigDependencies };
|
|
4
4
|
export { isVikeConfigFile };
|
|
5
|
-
|
|
5
|
+
export { isV1Design };
|
|
6
|
+
import { assertPosixPath, assert, isObject, assertUsage, assertWarning, objectEntries, hasProp, arrayIncludes, assertIsNotProductionRuntime, getMostSimilar, joinEnglish, lowerFirst, mergeCumulativeValues, getOutDirs, assertKeys, objectKeys, objectFromEntries, makeFirst, isNpmPackageImport, reverse } from '../../../utils.js';
|
|
6
7
|
import path from 'path';
|
|
7
8
|
import { configDefinitionsBuiltIn, configDefinitionsBuiltInGlobal } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
8
9
|
import { getLocationId, getFilesystemRouteString, getFilesystemRouteDefinedBy, isInherited, sortAfterInheritanceOrder, isGlobalLocation, applyFilesystemRoutingRootEffect } from './getVikeConfig/filesystemRouting.js';
|
|
@@ -17,8 +18,9 @@ import { getConfigVike } from '../../../../shared/getConfigVike.js';
|
|
|
17
18
|
import { assertConfigValueIsSerializable } from './getConfigValuesSerialized.js';
|
|
18
19
|
import { crawlPlusFiles } from './getVikeConfig/crawlPlusFiles.js';
|
|
19
20
|
import { getConfigFileExport } from './getConfigFileExport.js';
|
|
20
|
-
import { loadConfigFile, loadImportedFile, loadValueFile } from './getVikeConfig/
|
|
21
|
+
import { loadConfigFile, loadImportedFile, loadValueFile } from './getVikeConfig/loadFileAtConfigTime.js';
|
|
21
22
|
import { clearFilesEnvMap, resolveImport } from './getVikeConfig/resolveImportPath.js';
|
|
23
|
+
import { resolveFilePathRelativeToUserRootDir } from './getVikeConfig/resolveFilePath.js';
|
|
22
24
|
assertIsNotProductionRuntime();
|
|
23
25
|
let devServerIsCorrupt = false;
|
|
24
26
|
let wasConfigInvalid = null;
|
|
@@ -69,6 +71,12 @@ async function getVikeConfig(config, isDev, tolerateInvalidConfig = false, exten
|
|
|
69
71
|
}
|
|
70
72
|
return await vikeConfigPromise;
|
|
71
73
|
}
|
|
74
|
+
async function isV1Design(config, isDev) {
|
|
75
|
+
const vikeConfig = await getVikeConfig(config, isDev);
|
|
76
|
+
const { pageConfigs } = vikeConfig;
|
|
77
|
+
const isV1Design = pageConfigs.length > 0;
|
|
78
|
+
return isV1Design;
|
|
79
|
+
}
|
|
72
80
|
async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
73
81
|
const plusFiles = await findPlusFiles(userRootDir, outDirRoot, isDev, extensions);
|
|
74
82
|
const configFiles = [];
|
|
@@ -82,69 +90,77 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
82
90
|
}
|
|
83
91
|
});
|
|
84
92
|
let interfaceFilesByLocationId = {};
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const interfaceFile = getInterfaceFileFromConfigFile(
|
|
94
|
-
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
95
|
-
});
|
|
96
|
-
}));
|
|
97
|
-
// Value files
|
|
98
|
-
await Promise.all(valueFiles.map(async (filePath) => {
|
|
99
|
-
const configName = getConfigName(filePath.filePathAbsoluteVite);
|
|
100
|
-
assert(configName);
|
|
101
|
-
const interfaceFile = {
|
|
102
|
-
filePath,
|
|
103
|
-
fileExportsByConfigName: {
|
|
104
|
-
[configName]: {}
|
|
105
|
-
},
|
|
106
|
-
isConfigFile: false,
|
|
107
|
-
isValueFile: true,
|
|
108
|
-
configName
|
|
109
|
-
};
|
|
110
|
-
{
|
|
111
|
-
// We don't have access to the custom config definitions defined by the user yet.
|
|
112
|
-
// - If `configDef` is `undefined` => we load the file +{configName}.js later.
|
|
113
|
-
// - We already need to load +meta.js here (to get the custom config definitions defined by the user)
|
|
114
|
-
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn, configName);
|
|
115
|
-
if (configDef && isConfigEnv(configDef, configName)) {
|
|
116
|
-
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
{
|
|
120
|
-
const locationId = getLocationId(filePath.filePathAbsoluteVite);
|
|
93
|
+
await Promise.all([
|
|
94
|
+
// Config files
|
|
95
|
+
...configFiles.map(async (filePath) => {
|
|
96
|
+
const { filePathRelativeToUserRootDir } = filePath;
|
|
97
|
+
assert(filePathRelativeToUserRootDir);
|
|
98
|
+
const { configFile, extendsConfigs } = await loadConfigFile(filePath, userRootDir, [], false);
|
|
99
|
+
assert(filePath.filePathRelativeToUserRootDir);
|
|
100
|
+
const locationId = getLocationId(filePathRelativeToUserRootDir);
|
|
101
|
+
const interfaceFile = getInterfaceFileFromConfigFile(configFile, false, locationId);
|
|
121
102
|
interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
|
|
122
103
|
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
123
|
-
|
|
124
|
-
|
|
104
|
+
extendsConfigs.forEach((extendsConfig) => {
|
|
105
|
+
/* We purposely use the same locationId because the Vike extension's config should only apply to where it's being extended from, for example:
|
|
106
|
+
```js
|
|
107
|
+
// /pages/admin/+config.h.js
|
|
108
|
+
|
|
109
|
+
import vikeVue from 'vike-vue/config'
|
|
110
|
+
// Should only apply to /pages/admin/**
|
|
111
|
+
export default { extends: [vikeVue] }
|
|
112
|
+
```
|
|
113
|
+
```js
|
|
114
|
+
// /pages/marketing/+config.h.js
|
|
115
|
+
|
|
116
|
+
import vikeReact from 'vike-react/config'
|
|
117
|
+
// Should only apply to /pages/marketing/**
|
|
118
|
+
export default { extends: [vikeReact] }
|
|
119
|
+
```
|
|
120
|
+
*/
|
|
121
|
+
const interfaceFile = getInterfaceFileFromConfigFile(extendsConfig, true, locationId);
|
|
122
|
+
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
123
|
+
});
|
|
124
|
+
}),
|
|
125
|
+
// Value files
|
|
126
|
+
...valueFiles.map(async (filePath) => {
|
|
127
|
+
const { filePathRelativeToUserRootDir } = filePath;
|
|
128
|
+
assert(filePathRelativeToUserRootDir);
|
|
129
|
+
const configName = getConfigName(filePathRelativeToUserRootDir);
|
|
130
|
+
assert(configName);
|
|
131
|
+
const locationId = getLocationId(filePathRelativeToUserRootDir);
|
|
132
|
+
const interfaceFile = {
|
|
133
|
+
locationId,
|
|
134
|
+
filePath,
|
|
135
|
+
fileExportsByConfigName: {
|
|
136
|
+
[configName]: {}
|
|
137
|
+
},
|
|
138
|
+
isConfigFile: false,
|
|
139
|
+
isValueFile: true,
|
|
140
|
+
configName
|
|
141
|
+
};
|
|
142
|
+
{
|
|
143
|
+
// We don't have access to the custom config definitions defined by the user yet.
|
|
144
|
+
// - If `configDef` is `undefined` => we load the file +{configName}.js later.
|
|
145
|
+
// - We already need to load +meta.js here (to get the custom config definitions defined by the user)
|
|
146
|
+
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn, configName);
|
|
147
|
+
if (configDef && isConfigEnv(configDef, configName)) {
|
|
148
|
+
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
{
|
|
152
|
+
interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
|
|
153
|
+
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
154
|
+
}
|
|
155
|
+
})
|
|
156
|
+
]);
|
|
125
157
|
assertAllConfigsAreKnown(interfaceFilesByLocationId);
|
|
126
158
|
return interfaceFilesByLocationId;
|
|
127
159
|
}
|
|
128
|
-
function
|
|
129
|
-
const configDef = configDefinitionsRelevant[configName];
|
|
130
|
-
assertConfigExists(configName, Object.keys(configDefinitionsRelevant), filePathToShowToUser);
|
|
131
|
-
assert(configDef);
|
|
132
|
-
return configDef;
|
|
133
|
-
}
|
|
134
|
-
function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
135
|
-
return configDefinitions[configName] ?? null;
|
|
136
|
-
}
|
|
137
|
-
function isConfigEnv(configDef, configName) {
|
|
138
|
-
const configEnv = configDef.env;
|
|
139
|
-
if (configDef.cumulative) {
|
|
140
|
-
// In principle we could lift that requirement (but it requires non-trivial modifications)
|
|
141
|
-
assertUsage(configEnv.config, `Config ${pc.cyan(configName)} needs its ${pc.cyan('env')} to have ${pc.cyan('{ config: true }')} (because ${pc.cyan(configName)} is a ${pc.cyan('cumulative')} config)`);
|
|
142
|
-
}
|
|
143
|
-
return !!configEnv.config;
|
|
144
|
-
}
|
|
145
|
-
function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
160
|
+
function getInterfaceFileFromConfigFile(configFile, isConfigExtend, locationId) {
|
|
146
161
|
const { fileExports, filePath, extendsFilePaths } = configFile;
|
|
147
162
|
const interfaceFile = {
|
|
163
|
+
locationId,
|
|
148
164
|
filePath,
|
|
149
165
|
fileExportsByConfigName: {},
|
|
150
166
|
isConfigFile: true,
|
|
@@ -160,12 +176,12 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
160
176
|
}
|
|
161
177
|
/** Show error message upon unknown config */
|
|
162
178
|
function assertAllConfigsAreKnown(interfaceFilesByLocationId) {
|
|
163
|
-
|
|
179
|
+
objectEntries(interfaceFilesByLocationId).forEach(([locationId, interfaceFiles]) => {
|
|
164
180
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesByLocationId, locationId);
|
|
165
|
-
const
|
|
181
|
+
const configDefinitions = getConfigDefinitions(interfaceFilesRelevant);
|
|
166
182
|
interfaceFiles.forEach((interfaceFile) => {
|
|
167
183
|
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
168
|
-
assertConfigExists(configName, Object.keys(
|
|
184
|
+
assertConfigExists(configName, Object.keys(configDefinitions), interfaceFile.filePath.filePathToShowToUser);
|
|
169
185
|
});
|
|
170
186
|
});
|
|
171
187
|
});
|
|
@@ -215,11 +231,11 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
215
231
|
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions);
|
|
216
232
|
const importedFilesLoaded = {};
|
|
217
233
|
const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
|
|
218
|
-
const pageConfigs = await Promise.all(
|
|
234
|
+
const pageConfigs = await Promise.all(objectEntries(interfaceFilesByLocationId)
|
|
219
235
|
.filter(([_pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
220
236
|
.map(async ([locationId]) => {
|
|
221
237
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesByLocationId, locationId);
|
|
222
|
-
const
|
|
238
|
+
const configDefinitions = getConfigDefinitions(interfaceFilesRelevant);
|
|
223
239
|
// Load value files of custom config-only configs
|
|
224
240
|
await Promise.all(getInterfaceFileList(interfaceFilesRelevant).map(async (interfaceFile) => {
|
|
225
241
|
if (!interfaceFile.isValueFile)
|
|
@@ -227,7 +243,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
227
243
|
const { configName } = interfaceFile;
|
|
228
244
|
if (isGlobalConfig(configName))
|
|
229
245
|
return;
|
|
230
|
-
const configDef = getConfigDefinition(
|
|
246
|
+
const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
231
247
|
if (!isConfigEnv(configDef, configName))
|
|
232
248
|
return;
|
|
233
249
|
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
@@ -237,8 +253,8 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
237
253
|
assert(!(configName in configDefinitionsBuiltIn));
|
|
238
254
|
await loadValueFile(interfaceFile, configName, userRootDir);
|
|
239
255
|
}));
|
|
240
|
-
|
|
241
|
-
await Promise.all(objectEntries(
|
|
256
|
+
let configValueSources = {};
|
|
257
|
+
await Promise.all(objectEntries(configDefinitions)
|
|
242
258
|
.filter(([configName]) => !isGlobalConfig(configName))
|
|
243
259
|
.map(async ([configName, configDef]) => {
|
|
244
260
|
const sources = await resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir, importedFilesLoaded);
|
|
@@ -246,10 +262,11 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
246
262
|
return;
|
|
247
263
|
configValueSources[configName] = sources;
|
|
248
264
|
}));
|
|
265
|
+
configValueSources = sortConfigValueSources(configValueSources, locationId);
|
|
249
266
|
const { routeFilesystem, isErrorPage } = determineRouteFilesystem(locationId, configValueSources);
|
|
250
|
-
applyEffectsAll(configValueSources,
|
|
251
|
-
const configValuesComputed = getComputed(configValueSources,
|
|
252
|
-
const configValues = getConfigValues(configValueSources, configValuesComputed,
|
|
267
|
+
applyEffectsAll(configValueSources, configDefinitions);
|
|
268
|
+
const configValuesComputed = getComputed(configValueSources, configDefinitions);
|
|
269
|
+
const configValues = getConfigValues(configValueSources, configValuesComputed, configDefinitions);
|
|
253
270
|
const pageConfig = {
|
|
254
271
|
pageId: locationId,
|
|
255
272
|
isErrorPage,
|
|
@@ -286,7 +303,7 @@ function interfacefileIsAlreaydLoaded(interfaceFile) {
|
|
|
286
303
|
return isAlreadyLoaded;
|
|
287
304
|
}
|
|
288
305
|
function getInterfaceFilesRelevant(interfaceFilesByLocationId, locationIdPage) {
|
|
289
|
-
const interfaceFilesRelevant = Object.fromEntries(
|
|
306
|
+
const interfaceFilesRelevant = Object.fromEntries(objectEntries(interfaceFilesByLocationId)
|
|
290
307
|
.filter(([locationId]) => {
|
|
291
308
|
return isInherited(locationId, locationIdPage);
|
|
292
309
|
})
|
|
@@ -301,14 +318,14 @@ function getInterfaceFileList(interfaceFilesByLocationId) {
|
|
|
301
318
|
return interfaceFiles;
|
|
302
319
|
}
|
|
303
320
|
async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded) {
|
|
304
|
-
const locationIds =
|
|
305
|
-
const interfaceFilesGlobal =
|
|
321
|
+
const locationIds = objectKeys(interfaceFilesByLocationId);
|
|
322
|
+
const interfaceFilesGlobal = objectFromEntries(objectEntries(interfaceFilesByLocationId).filter(([locationId]) => {
|
|
306
323
|
return isGlobalLocation(locationId, locationIds);
|
|
307
324
|
}));
|
|
308
325
|
// Validate that global configs live in global interface files
|
|
309
326
|
{
|
|
310
327
|
const interfaceFilesGlobalPaths = [];
|
|
311
|
-
|
|
328
|
+
objectEntries(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
|
|
312
329
|
assert(isGlobalLocation(locationId, locationIds));
|
|
313
330
|
interfaceFiles.forEach(({ filePath: { filePathRelativeToUserRootDir } }) => {
|
|
314
331
|
if (filePathRelativeToUserRootDir) {
|
|
@@ -317,7 +334,7 @@ async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importe
|
|
|
317
334
|
});
|
|
318
335
|
});
|
|
319
336
|
const globalPaths = Array.from(new Set(interfaceFilesGlobalPaths.map((p) => path.posix.dirname(p))));
|
|
320
|
-
|
|
337
|
+
objectEntries(interfaceFilesByLocationId).forEach(([locationId, interfaceFiles]) => {
|
|
321
338
|
interfaceFiles.forEach((interfaceFile) => {
|
|
322
339
|
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
323
340
|
if (!isGlobalLocation(locationId, locationIds) && isGlobalConfig(configName)) {
|
|
@@ -441,6 +458,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
441
458
|
const conf = interfaceFile.fileExportsByConfigName[configName];
|
|
442
459
|
assert(conf);
|
|
443
460
|
const configEnv = configDef.env;
|
|
461
|
+
const { locationId } = interfaceFile;
|
|
444
462
|
const definedAtConfigFile = {
|
|
445
463
|
...interfaceFile.filePath,
|
|
446
464
|
fileExportPathToShowToUser: ['default', configName]
|
|
@@ -466,6 +484,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
466
484
|
};
|
|
467
485
|
}
|
|
468
486
|
const configValueSource = {
|
|
487
|
+
locationId,
|
|
469
488
|
value: valueFilePath,
|
|
470
489
|
valueIsFilePath: true,
|
|
471
490
|
configEnv,
|
|
@@ -482,6 +501,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
482
501
|
const import_ = resolveImport(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
483
502
|
if (import_) {
|
|
484
503
|
const configValueSource = {
|
|
504
|
+
locationId,
|
|
485
505
|
configEnv,
|
|
486
506
|
valueIsImportedAtRuntime: true,
|
|
487
507
|
definedAt: import_
|
|
@@ -504,6 +524,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
504
524
|
}
|
|
505
525
|
// Defined by config file, i.e. +config.js file
|
|
506
526
|
const configValueSource = {
|
|
527
|
+
locationId,
|
|
507
528
|
value: configValue,
|
|
508
529
|
configEnv,
|
|
509
530
|
valueIsImportedAtRuntime: false,
|
|
@@ -516,6 +537,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
516
537
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
517
538
|
assert(valueAlreadyLoaded === !!configEnv.config);
|
|
518
539
|
const configValueSource = {
|
|
540
|
+
locationId,
|
|
519
541
|
configEnv,
|
|
520
542
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
521
543
|
definedAt: {
|
|
@@ -546,8 +568,10 @@ function isDefiningPageConfig(configName) {
|
|
|
546
568
|
return ['Page', 'route'].includes(configName);
|
|
547
569
|
}
|
|
548
570
|
function getConfigDefinitions(interfaceFilesRelevant) {
|
|
549
|
-
const
|
|
550
|
-
Object.entries(interfaceFilesRelevant)
|
|
571
|
+
const configDefinitionsMerged = { ...configDefinitionsBuiltIn };
|
|
572
|
+
Object.entries(interfaceFilesRelevant)
|
|
573
|
+
.reverse()
|
|
574
|
+
.forEach(([_locationId, interfaceFiles]) => {
|
|
551
575
|
interfaceFiles.forEach((interfaceFile) => {
|
|
552
576
|
const configMeta = interfaceFile.fileExportsByConfigName['meta'];
|
|
553
577
|
if (!configMeta)
|
|
@@ -566,13 +590,14 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
566
590
|
});
|
|
567
591
|
objectEntries(meta).forEach(([configName, configDefinition]) => {
|
|
568
592
|
// User can override an existing config definition
|
|
569
|
-
|
|
570
|
-
...
|
|
593
|
+
configDefinitionsMerged[configName] = {
|
|
594
|
+
...configDefinitionsMerged[configName],
|
|
571
595
|
...configDefinition
|
|
572
596
|
};
|
|
573
597
|
});
|
|
574
598
|
});
|
|
575
599
|
});
|
|
600
|
+
const configDefinitions = configDefinitionsMerged;
|
|
576
601
|
return configDefinitions;
|
|
577
602
|
}
|
|
578
603
|
function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
@@ -611,8 +636,8 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
611
636
|
}
|
|
612
637
|
});
|
|
613
638
|
}
|
|
614
|
-
function applyEffectsAll(configValueSources,
|
|
615
|
-
objectEntries(
|
|
639
|
+
function applyEffectsAll(configValueSources, configDefinitions) {
|
|
640
|
+
objectEntries(configDefinitions).forEach(([configName, configDef]) => {
|
|
616
641
|
if (!configDef.effect)
|
|
617
642
|
return;
|
|
618
643
|
// 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,9 +696,9 @@ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
|
671
696
|
}
|
|
672
697
|
});
|
|
673
698
|
}
|
|
674
|
-
function getComputed(configValueSources,
|
|
699
|
+
function getComputed(configValueSources, configDefinitions) {
|
|
675
700
|
const configValuesComputed = {};
|
|
676
|
-
objectEntries(
|
|
701
|
+
objectEntries(configDefinitions).forEach(([configName, configDef]) => {
|
|
677
702
|
if (!configDef._computed)
|
|
678
703
|
return;
|
|
679
704
|
const value = configDef._computed(configValueSources);
|
|
@@ -688,15 +713,7 @@ function getComputed(configValueSources, configDefinitionsRelevant) {
|
|
|
688
713
|
}
|
|
689
714
|
async function findPlusFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
690
715
|
const files = await crawlPlusFiles(userRootDir, outDirRoot, isDev);
|
|
691
|
-
const plusFiles = files.map(({ filePathRelativeToUserRootDir
|
|
692
|
-
return {
|
|
693
|
-
filePathRelativeToUserRootDir,
|
|
694
|
-
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
695
|
-
filePathAbsoluteFilesystem,
|
|
696
|
-
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
697
|
-
importPathAbsolute: null
|
|
698
|
-
};
|
|
699
|
-
});
|
|
716
|
+
const plusFiles = files.map(({ filePathRelativeToUserRootDir }) => resolveFilePathRelativeToUserRootDir(filePathRelativeToUserRootDir, userRootDir));
|
|
700
717
|
// TODO/v1-release: remove
|
|
701
718
|
extensions.forEach((extension) => {
|
|
702
719
|
extension.pageConfigsDistFiles?.forEach((pageConfigDistFile) => {
|
|
@@ -748,22 +765,6 @@ function assertNoUnexpectedPlusSign(filePath: string, fileName: string) {
|
|
|
748
765
|
)
|
|
749
766
|
}
|
|
750
767
|
*/
|
|
751
|
-
function isGlobalConfig(configName) {
|
|
752
|
-
if (configName === 'prerender')
|
|
753
|
-
return false;
|
|
754
|
-
const configNamesGlobal = getConfigNamesGlobal();
|
|
755
|
-
return arrayIncludes(configNamesGlobal, configName);
|
|
756
|
-
}
|
|
757
|
-
function getConfigNamesGlobal() {
|
|
758
|
-
return Object.keys(configDefinitionsBuiltInGlobal);
|
|
759
|
-
}
|
|
760
|
-
function assertConfigExists(configName, configNamesRelevant, filePathToShowToUser) {
|
|
761
|
-
const configNames = [...configNamesRelevant, ...getConfigNamesGlobal()];
|
|
762
|
-
if (configNames.includes(configName))
|
|
763
|
-
return;
|
|
764
|
-
handleUnknownConfig(configName, configNames, filePathToShowToUser);
|
|
765
|
-
assert(false);
|
|
766
|
-
}
|
|
767
768
|
function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
768
769
|
let errMsg = `${filePathToShowToUser} defines an unknown config ${pc.cyan(configName)}`;
|
|
769
770
|
let configNameSimilar = null;
|
|
@@ -833,7 +834,7 @@ function determineIsErrorPage(routeFilesystem) {
|
|
|
833
834
|
function isVikeConfigFile(filePath) {
|
|
834
835
|
return !!getConfigName(filePath);
|
|
835
836
|
}
|
|
836
|
-
function getConfigValues(configValueSources, configValuesComputed,
|
|
837
|
+
function getConfigValues(configValueSources, configValuesComputed, configDefinitions) {
|
|
837
838
|
const configValues = {};
|
|
838
839
|
Object.entries(configValuesComputed).forEach(([configName, configValueComputed]) => {
|
|
839
840
|
configValues[configName] = {
|
|
@@ -842,7 +843,7 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
842
843
|
};
|
|
843
844
|
});
|
|
844
845
|
Object.entries(configValueSources).forEach(([configName, sources]) => {
|
|
845
|
-
const configDef =
|
|
846
|
+
const configDef = configDefinitions[configName];
|
|
846
847
|
assert(configDef);
|
|
847
848
|
if (!configDef.cumulative) {
|
|
848
849
|
const configValueSource = sources[0];
|
|
@@ -956,3 +957,48 @@ function getConfigEnvValue(val, errMsgIntro) {
|
|
|
956
957
|
*/
|
|
957
958
|
return val;
|
|
958
959
|
}
|
|
960
|
+
function getConfigDefinition(configDefinitions, configName, filePathToShowToUser) {
|
|
961
|
+
const configDef = configDefinitions[configName];
|
|
962
|
+
assertConfigExists(configName, Object.keys(configDefinitions), filePathToShowToUser);
|
|
963
|
+
assert(configDef);
|
|
964
|
+
return configDef;
|
|
965
|
+
}
|
|
966
|
+
function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
967
|
+
return configDefinitions[configName] ?? null;
|
|
968
|
+
}
|
|
969
|
+
function isConfigEnv(configDef, configName) {
|
|
970
|
+
const configEnv = configDef.env;
|
|
971
|
+
if (configDef.cumulative) {
|
|
972
|
+
// In principle we could lift that requirement (but it requires non-trivial modifications)
|
|
973
|
+
assertUsage(configEnv.config, `Config ${pc.cyan(configName)} needs its ${pc.cyan('env')} to have ${pc.cyan('{ config: true }')} (because ${pc.cyan(configName)} is a ${pc.cyan('cumulative')} config)`);
|
|
974
|
+
}
|
|
975
|
+
return !!configEnv.config;
|
|
976
|
+
}
|
|
977
|
+
function isGlobalConfig(configName) {
|
|
978
|
+
if (configName === 'prerender')
|
|
979
|
+
return false;
|
|
980
|
+
const configNamesGlobal = getConfigNamesGlobal();
|
|
981
|
+
return arrayIncludes(configNamesGlobal, configName);
|
|
982
|
+
}
|
|
983
|
+
function getConfigNamesGlobal() {
|
|
984
|
+
return Object.keys(configDefinitionsBuiltInGlobal);
|
|
985
|
+
}
|
|
986
|
+
function assertConfigExists(configName, configNamesRelevant, filePathToShowToUser) {
|
|
987
|
+
const configNames = [...configNamesRelevant, ...getConfigNamesGlobal()];
|
|
988
|
+
if (configNames.includes(configName))
|
|
989
|
+
return;
|
|
990
|
+
handleUnknownConfig(configName, configNames, filePathToShowToUser);
|
|
991
|
+
assert(false);
|
|
992
|
+
}
|
|
993
|
+
function sortConfigValueSources(configValueSources, locationIdPage) {
|
|
994
|
+
return Object.fromEntries(Object.entries(configValueSources)
|
|
995
|
+
// Make order deterministic (no other purpose)
|
|
996
|
+
.sort(([, [source1]], [, [source2]]) => source1.definedAt.filePathAbsoluteVite < source2.definedAt.filePathAbsoluteVite ? -1 : 1)
|
|
997
|
+
// Sort after whether the config value was defined by an npm package
|
|
998
|
+
.sort(makeFirst(([, [source]]) => {
|
|
999
|
+
const { importPathAbsolute } = source.definedAt;
|
|
1000
|
+
return !!importPathAbsolute && isNpmPackageImport(importPathAbsolute);
|
|
1001
|
+
}))
|
|
1002
|
+
// Sort after the filesystem inheritance of the config value
|
|
1003
|
+
.sort(([, [source1]], [, [source2]]) => reverse(sortAfterInheritanceOrder(source1.locationId, source2.locationId, locationIdPage))));
|
|
1004
|
+
}
|
package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -10,6 +10,7 @@ import { isRuntimeEnvMatch } from './isRuntimeEnvMatch.js';
|
|
|
10
10
|
import { serializeConfigValueImported } from '../../../../../shared/page-configs/serialize/serializeConfigValue.js';
|
|
11
11
|
import { getConfigVike } from '../../../../shared/getConfigVike.js';
|
|
12
12
|
import { getConfigValuesSerialized } from './getConfigValuesSerialized.js';
|
|
13
|
+
import { fixServerAssets_isEnabled } from '../../buildConfig/fixServerAssets.js';
|
|
13
14
|
async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
|
|
14
15
|
const result = isVirtualFileIdPageConfigValuesAll(id);
|
|
15
16
|
assert(result);
|
|
@@ -42,7 +43,7 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
42
43
|
isClientRouting
|
|
43
44
|
})));
|
|
44
45
|
lines.push('};');
|
|
45
|
-
if (includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
46
|
+
if (!fixServerAssets_isEnabled() && includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
46
47
|
importStatements.push(`import '${extractAssetsAddQuery(getVirtualFileIdPageConfigValuesAll(pageId, false))}'`);
|
|
47
48
|
}
|
|
48
49
|
const code = [...importStatements, ...lines].join('\n');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { setGlobalContext };
|
|
2
|
-
import { setGlobalContext_viteDevServer
|
|
2
|
+
import { setGlobalContext_viteDevServer } from '../../runtime/globalContext.js';
|
|
3
3
|
function setGlobalContext() {
|
|
4
4
|
return {
|
|
5
5
|
name: 'vike:setGlobalContext',
|
|
@@ -9,20 +9,6 @@ function setGlobalContext() {
|
|
|
9
9
|
handler(viteDevServer) {
|
|
10
10
|
setGlobalContext_viteDevServer(viteDevServer);
|
|
11
11
|
}
|
|
12
|
-
},
|
|
13
|
-
configurePreviewServer: {
|
|
14
|
-
order: 'pre',
|
|
15
|
-
handler(vitePreviewServer) {
|
|
16
|
-
setGlobalContext_vitePreviewServer(
|
|
17
|
-
// Type cast won't be necessary after https://github.com/vitejs/vite/pull/14119 is released in Vite 5
|
|
18
|
-
vitePreviewServer);
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
configResolved: {
|
|
22
|
-
order: 'pre',
|
|
23
|
-
handler(config) {
|
|
24
|
-
setGlobalContext_viteConfig(config);
|
|
25
|
-
}
|
|
26
12
|
}
|
|
27
13
|
};
|
|
28
14
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { sourceMapRemove };
|
|
2
|
+
export { sourceMapPassthrough };
|
|
3
|
+
/** Remove entire source mapping, to save KBs. */
|
|
4
|
+
declare function sourceMapRemove(code: string): {
|
|
5
|
+
code: string;
|
|
6
|
+
map: {
|
|
7
|
+
mappings: '';
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
/** Don't provide any source map, pass through current source map instead. */
|
|
11
|
+
declare function sourceMapPassthrough(code: string): {
|
|
12
|
+
code: string;
|
|
13
|
+
map: null;
|
|
14
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { sourceMapRemove };
|
|
2
|
+
export { sourceMapPassthrough };
|
|
3
|
+
// https://rollupjs.org/guide/en/#source-code-transformations
|
|
4
|
+
/** Remove entire source mapping, to save KBs. */
|
|
5
|
+
function sourceMapRemove(code) {
|
|
6
|
+
return {
|
|
7
|
+
code,
|
|
8
|
+
map: { mappings: '' }
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
/** Don't provide any source map, pass through current source map instead. */
|
|
12
|
+
function sourceMapPassthrough(code) {
|
|
13
|
+
return {
|
|
14
|
+
code,
|
|
15
|
+
map: null
|
|
16
|
+
};
|
|
17
|
+
}
|
|
@@ -5,7 +5,6 @@ export * from '../../utils/getDependencyPackageJson.js';
|
|
|
5
5
|
export * from '../../utils/requireResolve.js';
|
|
6
6
|
export * from '../../utils/arrayIncludes.js';
|
|
7
7
|
export * from '../../utils/isDev.js';
|
|
8
|
-
export * from '../../utils/objectKeys.js';
|
|
9
8
|
export * from '../../utils/getMostSimilar.js';
|
|
10
9
|
export * from '../../utils/getRandomId.js';
|
|
11
10
|
export * from '../../utils/joinEnglish.js';
|
|
@@ -13,10 +12,12 @@ export * from '../../utils/escapeRegex.js';
|
|
|
13
12
|
export * from '../../utils/stripAnsi.js';
|
|
14
13
|
export * from '../../utils/trimWithAnsi.js';
|
|
15
14
|
export * from '../../utils/removeEmptyLines.js';
|
|
16
|
-
export * from '../../utils/
|
|
15
|
+
export * from '../../utils/findFile.js';
|
|
17
16
|
export * from '../../utils/getPropAccessNotation.js';
|
|
18
17
|
export * from '../../utils/mergeCumulativeValues.js';
|
|
19
18
|
export * from '../../utils/deepEqual.js';
|
|
20
19
|
export * from '../../utils/assertKeys.js';
|
|
21
20
|
export * from '../../utils/injectRollupInputs.js';
|
|
22
21
|
export * from '../../utils/humanizeTime.js';
|
|
22
|
+
export * from '../../utils/pLimit.js';
|
|
23
|
+
export * from '../../utils/isVersionOrAbove.js';
|
|
@@ -11,7 +11,6 @@ export * from '../../utils/getDependencyPackageJson.js';
|
|
|
11
11
|
export * from '../../utils/requireResolve.js';
|
|
12
12
|
export * from '../../utils/arrayIncludes.js';
|
|
13
13
|
export * from '../../utils/isDev.js';
|
|
14
|
-
export * from '../../utils/objectKeys.js';
|
|
15
14
|
export * from '../../utils/getMostSimilar.js';
|
|
16
15
|
export * from '../../utils/getRandomId.js';
|
|
17
16
|
export * from '../../utils/joinEnglish.js';
|
|
@@ -19,10 +18,12 @@ export * from '../../utils/escapeRegex.js';
|
|
|
19
18
|
export * from '../../utils/stripAnsi.js';
|
|
20
19
|
export * from '../../utils/trimWithAnsi.js';
|
|
21
20
|
export * from '../../utils/removeEmptyLines.js';
|
|
22
|
-
export * from '../../utils/
|
|
21
|
+
export * from '../../utils/findFile.js';
|
|
23
22
|
export * from '../../utils/getPropAccessNotation.js';
|
|
24
23
|
export * from '../../utils/mergeCumulativeValues.js';
|
|
25
24
|
export * from '../../utils/deepEqual.js';
|
|
26
25
|
export * from '../../utils/assertKeys.js';
|
|
27
26
|
export * from '../../utils/injectRollupInputs.js';
|
|
28
27
|
export * from '../../utils/humanizeTime.js';
|
|
28
|
+
export * from '../../utils/pLimit.js';
|
|
29
|
+
export * from '../../utils/isVersionOrAbove.js';
|
|
@@ -5,12 +5,12 @@ export { runPrerender_forceExit };
|
|
|
5
5
|
import '../runtime/page-files/setup.js';
|
|
6
6
|
import path from 'path';
|
|
7
7
|
import { route } from '../../shared/route/index.js';
|
|
8
|
-
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, executeHook, isPlainObject, setNodeEnvToProduction, isUserHookError } from './utils.js';
|
|
8
|
+
import { assert, assertUsage, assertWarning, hasProp, projectInfo, objectAssign, isObjectWithKeys, isCallable, getOutDirs, isPropertyGetter, assertPosixPath, urlToFile, executeHook, isPlainObject, setNodeEnvToProduction, isUserHookError, assertNodeEnvIsNotDev, getNodeEnv } from './utils.js';
|
|
9
9
|
import { pLimit } from '../../utils/pLimit.js';
|
|
10
10
|
import { prerenderPage, prerender404Page, getRenderContext, getPageContextInitEnhanced } from '../runtime/renderPage/renderPageAlreadyRouted.js';
|
|
11
11
|
import pc from '@brillout/picocolors';
|
|
12
12
|
import { cpus } from 'os';
|
|
13
|
-
import { getGlobalContext, initGlobalContext } from '../runtime/globalContext.js';
|
|
13
|
+
import { getGlobalContext, initGlobalContext, setGlobalContext_prerender } from '../runtime/globalContext.js';
|
|
14
14
|
import { resolveConfig } from 'vite';
|
|
15
15
|
import { getConfigVike } from '../shared/getConfigVike.js';
|
|
16
16
|
import { getPageFilesServerSide } from '../../shared/getPageFiles.js';
|
|
@@ -26,11 +26,11 @@ import { loadUserFilesServerSide } from '../runtime/renderPage/loadUserFilesServ
|
|
|
26
26
|
import { getHookFromPageConfig, getHookFromPageConfigGlobal, getHookTimeoutDefault, setIsPrerenderering } from '../../shared/hooks/getHook.js';
|
|
27
27
|
import { noRouteMatch } from '../../shared/route/noRouteMatch.js';
|
|
28
28
|
import { getVikeConfig } from '../plugin/plugins/importUserCode/v1-design/getVikeConfig.js';
|
|
29
|
-
import {
|
|
29
|
+
import { logErrorHint } from '../runtime/renderPage/logErrorHint.js';
|
|
30
30
|
async function runPrerenderFromAPI(options = {}) {
|
|
31
31
|
await runPrerender(options, 'prerender()');
|
|
32
32
|
// - We purposely propagate the error to the user land, so that the error interrupts the user land. It's also, I guess, a nice-to-have that the user has control over the error.
|
|
33
|
-
// - We don't use
|
|
33
|
+
// - We don't use logErrorHint() because we don't have control over what happens with the error. For example, if the user land purposely swallows the error then the hint shouldn't be logged. Also, it's best if the hint is shown to the user *after* the error, but we cannot do/guarentee that.
|
|
34
34
|
}
|
|
35
35
|
async function runPrerenderFromCLI(options) {
|
|
36
36
|
try {
|
|
@@ -38,7 +38,7 @@ async function runPrerenderFromCLI(options) {
|
|
|
38
38
|
}
|
|
39
39
|
catch (err) {
|
|
40
40
|
console.error(err);
|
|
41
|
-
|
|
41
|
+
logErrorHint(err);
|
|
42
42
|
process.exit(1);
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -48,7 +48,7 @@ async function runPrerenderFromAutoFullBuild(options) {
|
|
|
48
48
|
}
|
|
49
49
|
catch (err) {
|
|
50
50
|
console.error(err);
|
|
51
|
-
|
|
51
|
+
logErrorHint(err);
|
|
52
52
|
process.exit(1);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
@@ -59,9 +59,10 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
59
59
|
if (logLevel === 'info') {
|
|
60
60
|
console.log(`${pc.cyan(`vike v${projectInfo.projectVersion}`)} ${pc.green('pre-rendering HTML...')}`);
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
handleNodeEnv();
|
|
63
63
|
await disableReactStreaming();
|
|
64
64
|
const viteConfig = await resolveConfig(options.viteConfig || {}, 'vike pre-rendering', 'production');
|
|
65
|
+
setGlobalContext_prerender(viteConfig);
|
|
65
66
|
assertLoadedConfig(viteConfig, options);
|
|
66
67
|
const configVike = await getConfigVike(viteConfig);
|
|
67
68
|
const { outDirClient, outDirRoot } = getOutDirs(viteConfig);
|
|
@@ -713,3 +714,10 @@ function assertIsNotAbort(err, urlOr404) {
|
|
|
713
714
|
assert(abortCall);
|
|
714
715
|
assertUsage(false, `${pc.cyan(abortCall)} thrown${thrownBy} while pre-rendering ${urlOr404} but ${pc.cyan(abortCaller)} isn't supported for pre-rendered pages`);
|
|
715
716
|
}
|
|
717
|
+
function handleNodeEnv() {
|
|
718
|
+
const assertNodeEnv = () => assertNodeEnvIsNotDev('pre-rendering');
|
|
719
|
+
if (getNodeEnv())
|
|
720
|
+
assertNodeEnv();
|
|
721
|
+
setNodeEnvToProduction();
|
|
722
|
+
assertNodeEnv();
|
|
723
|
+
}
|