vike 0.4.160 → 0.4.161-commit-ba539a4
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/extractAssetsPlugin.js +7 -2
- package/dist/cjs/node/plugin/plugins/importBuild/index.js +4 -7
- 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 +155 -111
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- package/dist/cjs/node/plugin/utils.js +3 -2
- package/dist/cjs/node/prerender/runPrerender.js +12 -5
- package/dist/cjs/node/runtime/globalContext.js +7 -4
- 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 +8 -7
- package/dist/cjs/node/runtime/renderPage/getPageAssets.js +15 -19
- 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/utils.js +1 -1
- package/dist/cjs/node/shared/{getClientEntryFilePath.js → getClientEntry.js} +3 -3
- package/dist/cjs/node/shared/prependEntriesDir.js +13 -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/extractAssetsPlugin.js +8 -3
- package/dist/esm/node/plugin/plugins/importBuild/index.d.ts +6 -1
- package/dist/esm/node/plugin/plugins/importBuild/index.js +4 -7
- 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 +4 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +153 -109
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +2 -1
- 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 +13 -6
- package/dist/esm/node/runtime/globalContext.js +8 -5
- 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.js +8 -7
- package/dist/esm/node/runtime/renderPage/getPageAssets.js +16 -20
- 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/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/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/shared/page-configs/Config.d.ts +1 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +2 -0
- 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/utils/objectEntries.js +0 -8
- 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
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isVikeConfigFile = exports.vikeConfigDependencies = exports.reloadVikeConfig = exports.getVikeConfig = void 0;
|
|
6
|
+
exports.isV1Design = exports.isVikeConfigFile = exports.vikeConfigDependencies = exports.reloadVikeConfig = exports.getVikeConfig = void 0;
|
|
7
7
|
const utils_js_1 = require("../../../utils.js");
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const configDefinitionsBuiltIn_js_1 = require("./getVikeConfig/configDefinitionsBuiltIn.js");
|
|
@@ -19,8 +19,9 @@ const getConfigVike_js_1 = require("../../../../shared/getConfigVike.js");
|
|
|
19
19
|
const getConfigValuesSerialized_js_1 = require("./getConfigValuesSerialized.js");
|
|
20
20
|
const crawlPlusFiles_js_1 = require("./getVikeConfig/crawlPlusFiles.js");
|
|
21
21
|
const getConfigFileExport_js_1 = require("./getConfigFileExport.js");
|
|
22
|
-
const
|
|
22
|
+
const loadFileAtConfigTime_js_1 = require("./getVikeConfig/loadFileAtConfigTime.js");
|
|
23
23
|
const resolveImportPath_js_1 = require("./getVikeConfig/resolveImportPath.js");
|
|
24
|
+
const resolveFilePath_js_1 = require("./getVikeConfig/resolveFilePath.js");
|
|
24
25
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
25
26
|
let devServerIsCorrupt = false;
|
|
26
27
|
let wasConfigInvalid = null;
|
|
@@ -74,6 +75,11 @@ async function getVikeConfig(config, isDev, tolerateInvalidConfig = false, exten
|
|
|
74
75
|
return await vikeConfigPromise;
|
|
75
76
|
}
|
|
76
77
|
exports.getVikeConfig = getVikeConfig;
|
|
78
|
+
async function isV1Design(config, isDev) {
|
|
79
|
+
const isV1Design = (await getVikeConfig(config, isDev)).pageConfigs.length > 0;
|
|
80
|
+
return isV1Design;
|
|
81
|
+
}
|
|
82
|
+
exports.isV1Design = isV1Design;
|
|
77
83
|
async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
78
84
|
const plusFiles = await findPlusFiles(userRootDir, outDirRoot, isDev, extensions);
|
|
79
85
|
const configFiles = [];
|
|
@@ -87,69 +93,77 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
87
93
|
}
|
|
88
94
|
});
|
|
89
95
|
let interfaceFilesByLocationId = {};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const interfaceFile = getInterfaceFileFromConfigFile(
|
|
99
|
-
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
100
|
-
});
|
|
101
|
-
}));
|
|
102
|
-
// Value files
|
|
103
|
-
await Promise.all(valueFiles.map(async (filePath) => {
|
|
104
|
-
const configName = getConfigName(filePath.filePathAbsoluteVite);
|
|
105
|
-
(0, utils_js_1.assert)(configName);
|
|
106
|
-
const interfaceFile = {
|
|
107
|
-
filePath,
|
|
108
|
-
fileExportsByConfigName: {
|
|
109
|
-
[configName]: {}
|
|
110
|
-
},
|
|
111
|
-
isConfigFile: false,
|
|
112
|
-
isValueFile: true,
|
|
113
|
-
configName
|
|
114
|
-
};
|
|
115
|
-
{
|
|
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)
|
|
119
|
-
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn, configName);
|
|
120
|
-
if (configDef && isConfigEnv(configDef, configName)) {
|
|
121
|
-
await (0, loadFileConfigEnv_js_1.loadValueFile)(interfaceFile, configName, userRootDir);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
{
|
|
125
|
-
const locationId = (0, filesystemRouting_js_1.getLocationId)(filePath.filePathAbsoluteVite);
|
|
96
|
+
await Promise.all([
|
|
97
|
+
// Config files
|
|
98
|
+
...configFiles.map(async (filePath) => {
|
|
99
|
+
const { filePathRelativeToUserRootDir } = filePath;
|
|
100
|
+
(0, utils_js_1.assert)(filePathRelativeToUserRootDir);
|
|
101
|
+
const { configFile, extendsConfigs } = await (0, loadFileAtConfigTime_js_1.loadConfigFile)(filePath, userRootDir, [], false);
|
|
102
|
+
(0, utils_js_1.assert)(filePath.filePathRelativeToUserRootDir);
|
|
103
|
+
const locationId = (0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir);
|
|
104
|
+
const interfaceFile = getInterfaceFileFromConfigFile(configFile, false, locationId);
|
|
126
105
|
interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
|
|
127
106
|
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
128
|
-
|
|
129
|
-
|
|
107
|
+
extendsConfigs.forEach((extendsConfig) => {
|
|
108
|
+
/* We purposely use the same locationId because the Vike extension's config should only apply to where it's being extended from, for example:
|
|
109
|
+
```js
|
|
110
|
+
// /pages/admin/+config.h.js
|
|
111
|
+
|
|
112
|
+
import vikeVue from 'vike-vue/config'
|
|
113
|
+
// Should only apply to /pages/admin/**
|
|
114
|
+
export default { extends: [vikeVue] }
|
|
115
|
+
```
|
|
116
|
+
```js
|
|
117
|
+
// /pages/marketing/+config.h.js
|
|
118
|
+
|
|
119
|
+
import vikeReact from 'vike-react/config'
|
|
120
|
+
// Should only apply to /pages/marketing/**
|
|
121
|
+
export default { extends: [vikeReact] }
|
|
122
|
+
```
|
|
123
|
+
*/
|
|
124
|
+
const interfaceFile = getInterfaceFileFromConfigFile(extendsConfig, true, locationId);
|
|
125
|
+
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
126
|
+
});
|
|
127
|
+
}),
|
|
128
|
+
// Value files
|
|
129
|
+
...valueFiles.map(async (filePath) => {
|
|
130
|
+
const { filePathRelativeToUserRootDir } = filePath;
|
|
131
|
+
(0, utils_js_1.assert)(filePathRelativeToUserRootDir);
|
|
132
|
+
const configName = getConfigName(filePathRelativeToUserRootDir);
|
|
133
|
+
(0, utils_js_1.assert)(configName);
|
|
134
|
+
const locationId = (0, filesystemRouting_js_1.getLocationId)(filePathRelativeToUserRootDir);
|
|
135
|
+
const interfaceFile = {
|
|
136
|
+
locationId,
|
|
137
|
+
filePath,
|
|
138
|
+
fileExportsByConfigName: {
|
|
139
|
+
[configName]: {}
|
|
140
|
+
},
|
|
141
|
+
isConfigFile: false,
|
|
142
|
+
isValueFile: true,
|
|
143
|
+
configName
|
|
144
|
+
};
|
|
145
|
+
{
|
|
146
|
+
// We don't have access to the custom config definitions defined by the user yet.
|
|
147
|
+
// - If `configDef` is `undefined` => we load the file +{configName}.js later.
|
|
148
|
+
// - We already need to load +meta.js here (to get the custom config definitions defined by the user)
|
|
149
|
+
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn, configName);
|
|
150
|
+
if (configDef && isConfigEnv(configDef, configName)) {
|
|
151
|
+
await (0, loadFileAtConfigTime_js_1.loadValueFile)(interfaceFile, configName, userRootDir);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
{
|
|
155
|
+
interfaceFilesByLocationId[locationId] = interfaceFilesByLocationId[locationId] ?? [];
|
|
156
|
+
interfaceFilesByLocationId[locationId].push(interfaceFile);
|
|
157
|
+
}
|
|
158
|
+
})
|
|
159
|
+
]);
|
|
130
160
|
assertAllConfigsAreKnown(interfaceFilesByLocationId);
|
|
131
161
|
return interfaceFilesByLocationId;
|
|
132
162
|
}
|
|
133
|
-
function
|
|
134
|
-
const configDef = configDefinitionsRelevant[configName];
|
|
135
|
-
assertConfigExists(configName, Object.keys(configDefinitionsRelevant), filePathToShowToUser);
|
|
136
|
-
(0, utils_js_1.assert)(configDef);
|
|
137
|
-
return configDef;
|
|
138
|
-
}
|
|
139
|
-
function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
140
|
-
return configDefinitions[configName] ?? null;
|
|
141
|
-
}
|
|
142
|
-
function isConfigEnv(configDef, configName) {
|
|
143
|
-
const configEnv = configDef.env;
|
|
144
|
-
if (configDef.cumulative) {
|
|
145
|
-
// In principle we could lift that requirement (but it requires non-trivial modifications)
|
|
146
|
-
(0, utils_js_1.assertUsage)(configEnv.config, `Config ${picocolors_1.default.cyan(configName)} needs its ${picocolors_1.default.cyan('env')} to have ${picocolors_1.default.cyan('{ config: true }')} (because ${picocolors_1.default.cyan(configName)} is a ${picocolors_1.default.cyan('cumulative')} config)`);
|
|
147
|
-
}
|
|
148
|
-
return !!configEnv.config;
|
|
149
|
-
}
|
|
150
|
-
function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
163
|
+
function getInterfaceFileFromConfigFile(configFile, isConfigExtend, locationId) {
|
|
151
164
|
const { fileExports, filePath, extendsFilePaths } = configFile;
|
|
152
165
|
const interfaceFile = {
|
|
166
|
+
locationId,
|
|
153
167
|
filePath,
|
|
154
168
|
fileExportsByConfigName: {},
|
|
155
169
|
isConfigFile: true,
|
|
@@ -165,12 +179,12 @@ function getInterfaceFileFromConfigFile(configFile, isConfigExtend) {
|
|
|
165
179
|
}
|
|
166
180
|
/** Show error message upon unknown config */
|
|
167
181
|
function assertAllConfigsAreKnown(interfaceFilesByLocationId) {
|
|
168
|
-
|
|
182
|
+
(0, utils_js_1.objectEntries)(interfaceFilesByLocationId).forEach(([locationId, interfaceFiles]) => {
|
|
169
183
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesByLocationId, locationId);
|
|
170
|
-
const
|
|
184
|
+
const configDefinitions = getConfigDefinitions(interfaceFilesRelevant);
|
|
171
185
|
interfaceFiles.forEach((interfaceFile) => {
|
|
172
186
|
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
173
|
-
assertConfigExists(configName, Object.keys(
|
|
187
|
+
assertConfigExists(configName, Object.keys(configDefinitions), interfaceFile.filePath.filePathToShowToUser);
|
|
174
188
|
});
|
|
175
189
|
});
|
|
176
190
|
});
|
|
@@ -220,11 +234,11 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
220
234
|
const interfaceFilesByLocationId = await loadInterfaceFiles(userRootDir, outDirRoot, isDev, extensions);
|
|
221
235
|
const importedFilesLoaded = {};
|
|
222
236
|
const { globalVikeConfig, pageConfigGlobal } = await getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded);
|
|
223
|
-
const pageConfigs = await Promise.all(
|
|
237
|
+
const pageConfigs = await Promise.all((0, utils_js_1.objectEntries)(interfaceFilesByLocationId)
|
|
224
238
|
.filter(([_pageId, interfaceFiles]) => isDefiningPage(interfaceFiles))
|
|
225
239
|
.map(async ([locationId]) => {
|
|
226
240
|
const interfaceFilesRelevant = getInterfaceFilesRelevant(interfaceFilesByLocationId, locationId);
|
|
227
|
-
const
|
|
241
|
+
const configDefinitions = getConfigDefinitions(interfaceFilesRelevant);
|
|
228
242
|
// Load value files of custom config-only configs
|
|
229
243
|
await Promise.all(getInterfaceFileList(interfaceFilesRelevant).map(async (interfaceFile) => {
|
|
230
244
|
if (!interfaceFile.isValueFile)
|
|
@@ -232,7 +246,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
232
246
|
const { configName } = interfaceFile;
|
|
233
247
|
if (isGlobalConfig(configName))
|
|
234
248
|
return;
|
|
235
|
-
const configDef = getConfigDefinition(
|
|
249
|
+
const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
236
250
|
if (!isConfigEnv(configDef, configName))
|
|
237
251
|
return;
|
|
238
252
|
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
@@ -240,10 +254,10 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
240
254
|
return;
|
|
241
255
|
// Value files of built-in configs should have already been loaded at loadInterfaceFiles()
|
|
242
256
|
(0, utils_js_1.assert)(!(configName in configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn));
|
|
243
|
-
await (0,
|
|
257
|
+
await (0, loadFileAtConfigTime_js_1.loadValueFile)(interfaceFile, configName, userRootDir);
|
|
244
258
|
}));
|
|
245
|
-
|
|
246
|
-
await Promise.all((0, utils_js_1.objectEntries)(
|
|
259
|
+
let configValueSources = {};
|
|
260
|
+
await Promise.all((0, utils_js_1.objectEntries)(configDefinitions)
|
|
247
261
|
.filter(([configName]) => !isGlobalConfig(configName))
|
|
248
262
|
.map(async ([configName, configDef]) => {
|
|
249
263
|
const sources = await resolveConfigValueSources(configName, configDef, interfaceFilesRelevant, userRootDir, importedFilesLoaded);
|
|
@@ -251,10 +265,11 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev, extensions) {
|
|
|
251
265
|
return;
|
|
252
266
|
configValueSources[configName] = sources;
|
|
253
267
|
}));
|
|
268
|
+
configValueSources = sortConfigValueSources(configValueSources, locationId);
|
|
254
269
|
const { routeFilesystem, isErrorPage } = determineRouteFilesystem(locationId, configValueSources);
|
|
255
|
-
applyEffectsAll(configValueSources,
|
|
256
|
-
const configValuesComputed = getComputed(configValueSources,
|
|
257
|
-
const configValues = getConfigValues(configValueSources, configValuesComputed,
|
|
270
|
+
applyEffectsAll(configValueSources, configDefinitions);
|
|
271
|
+
const configValuesComputed = getComputed(configValueSources, configDefinitions);
|
|
272
|
+
const configValues = getConfigValues(configValueSources, configValuesComputed, configDefinitions);
|
|
258
273
|
const pageConfig = {
|
|
259
274
|
pageId: locationId,
|
|
260
275
|
isErrorPage,
|
|
@@ -291,7 +306,7 @@ function interfacefileIsAlreaydLoaded(interfaceFile) {
|
|
|
291
306
|
return isAlreadyLoaded;
|
|
292
307
|
}
|
|
293
308
|
function getInterfaceFilesRelevant(interfaceFilesByLocationId, locationIdPage) {
|
|
294
|
-
const interfaceFilesRelevant = Object.fromEntries(
|
|
309
|
+
const interfaceFilesRelevant = Object.fromEntries((0, utils_js_1.objectEntries)(interfaceFilesByLocationId)
|
|
295
310
|
.filter(([locationId]) => {
|
|
296
311
|
return (0, filesystemRouting_js_1.isInherited)(locationId, locationIdPage);
|
|
297
312
|
})
|
|
@@ -306,14 +321,14 @@ function getInterfaceFileList(interfaceFilesByLocationId) {
|
|
|
306
321
|
return interfaceFiles;
|
|
307
322
|
}
|
|
308
323
|
async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importedFilesLoaded) {
|
|
309
|
-
const locationIds =
|
|
310
|
-
const interfaceFilesGlobal =
|
|
324
|
+
const locationIds = (0, utils_js_1.objectKeys)(interfaceFilesByLocationId);
|
|
325
|
+
const interfaceFilesGlobal = (0, utils_js_1.objectFromEntries)((0, utils_js_1.objectEntries)(interfaceFilesByLocationId).filter(([locationId]) => {
|
|
311
326
|
return (0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds);
|
|
312
327
|
}));
|
|
313
328
|
// Validate that global configs live in global interface files
|
|
314
329
|
{
|
|
315
330
|
const interfaceFilesGlobalPaths = [];
|
|
316
|
-
|
|
331
|
+
(0, utils_js_1.objectEntries)(interfaceFilesGlobal).forEach(([locationId, interfaceFiles]) => {
|
|
317
332
|
(0, utils_js_1.assert)((0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds));
|
|
318
333
|
interfaceFiles.forEach(({ filePath: { filePathRelativeToUserRootDir } }) => {
|
|
319
334
|
if (filePathRelativeToUserRootDir) {
|
|
@@ -322,7 +337,7 @@ async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importe
|
|
|
322
337
|
});
|
|
323
338
|
});
|
|
324
339
|
const globalPaths = Array.from(new Set(interfaceFilesGlobalPaths.map((p) => path_1.default.posix.dirname(p))));
|
|
325
|
-
|
|
340
|
+
(0, utils_js_1.objectEntries)(interfaceFilesByLocationId).forEach(([locationId, interfaceFiles]) => {
|
|
326
341
|
interfaceFiles.forEach((interfaceFile) => {
|
|
327
342
|
Object.keys(interfaceFile.fileExportsByConfigName).forEach((configName) => {
|
|
328
343
|
if (!(0, filesystemRouting_js_1.isGlobalLocation)(locationId, locationIds) && isGlobalConfig(configName)) {
|
|
@@ -446,6 +461,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
446
461
|
const conf = interfaceFile.fileExportsByConfigName[configName];
|
|
447
462
|
(0, utils_js_1.assert)(conf);
|
|
448
463
|
const configEnv = configDef.env;
|
|
464
|
+
const { locationId } = interfaceFile;
|
|
449
465
|
const definedAtConfigFile = {
|
|
450
466
|
...interfaceFile.filePath,
|
|
451
467
|
fileExportPathToShowToUser: ['default', configName]
|
|
@@ -471,6 +487,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
471
487
|
};
|
|
472
488
|
}
|
|
473
489
|
const configValueSource = {
|
|
490
|
+
locationId,
|
|
474
491
|
value: valueFilePath,
|
|
475
492
|
valueIsFilePath: true,
|
|
476
493
|
configEnv,
|
|
@@ -487,6 +504,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
487
504
|
const import_ = (0, resolveImportPath_js_1.resolveImport)(configValue, interfaceFile.filePath, userRootDir, configEnv, configName);
|
|
488
505
|
if (import_) {
|
|
489
506
|
const configValueSource = {
|
|
507
|
+
locationId,
|
|
490
508
|
configEnv,
|
|
491
509
|
valueIsImportedAtRuntime: true,
|
|
492
510
|
definedAt: import_
|
|
@@ -497,7 +515,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
497
515
|
configName !== 'extends') {
|
|
498
516
|
if (import_.filePathAbsoluteFilesystem) {
|
|
499
517
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(import_, 'filePathAbsoluteFilesystem', 'string')); // Help TS
|
|
500
|
-
const fileExport = await (0,
|
|
518
|
+
const fileExport = await (0, loadFileAtConfigTime_js_1.loadImportedFile)(import_, userRootDir, importedFilesLoaded);
|
|
501
519
|
configValueSource.value = fileExport;
|
|
502
520
|
}
|
|
503
521
|
else {
|
|
@@ -509,6 +527,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
509
527
|
}
|
|
510
528
|
// Defined by config file, i.e. +config.js file
|
|
511
529
|
const configValueSource = {
|
|
530
|
+
locationId,
|
|
512
531
|
value: configValue,
|
|
513
532
|
configEnv,
|
|
514
533
|
valueIsImportedAtRuntime: false,
|
|
@@ -521,6 +540,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
521
540
|
const valueAlreadyLoaded = 'configValue' in conf;
|
|
522
541
|
(0, utils_js_1.assert)(valueAlreadyLoaded === !!configEnv.config);
|
|
523
542
|
const configValueSource = {
|
|
543
|
+
locationId,
|
|
524
544
|
configEnv,
|
|
525
545
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
526
546
|
definedAt: {
|
|
@@ -551,8 +571,10 @@ function isDefiningPageConfig(configName) {
|
|
|
551
571
|
return ['Page', 'route'].includes(configName);
|
|
552
572
|
}
|
|
553
573
|
function getConfigDefinitions(interfaceFilesRelevant) {
|
|
554
|
-
const
|
|
555
|
-
Object.entries(interfaceFilesRelevant)
|
|
574
|
+
const configDefinitionsMerged = { ...configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn };
|
|
575
|
+
Object.entries(interfaceFilesRelevant)
|
|
576
|
+
.reverse()
|
|
577
|
+
.forEach(([_locationId, interfaceFiles]) => {
|
|
556
578
|
interfaceFiles.forEach((interfaceFile) => {
|
|
557
579
|
const configMeta = interfaceFile.fileExportsByConfigName['meta'];
|
|
558
580
|
if (!configMeta)
|
|
@@ -571,13 +593,14 @@ function getConfigDefinitions(interfaceFilesRelevant) {
|
|
|
571
593
|
});
|
|
572
594
|
(0, utils_js_1.objectEntries)(meta).forEach(([configName, configDefinition]) => {
|
|
573
595
|
// User can override an existing config definition
|
|
574
|
-
|
|
575
|
-
...
|
|
596
|
+
configDefinitionsMerged[configName] = {
|
|
597
|
+
...configDefinitionsMerged[configName],
|
|
576
598
|
...configDefinition
|
|
577
599
|
};
|
|
578
600
|
});
|
|
579
601
|
});
|
|
580
602
|
});
|
|
603
|
+
const configDefinitions = configDefinitionsMerged;
|
|
581
604
|
return configDefinitions;
|
|
582
605
|
}
|
|
583
606
|
function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
@@ -616,8 +639,8 @@ function assertMetaValue(metaVal, configMetaDefinedAt) {
|
|
|
616
639
|
}
|
|
617
640
|
});
|
|
618
641
|
}
|
|
619
|
-
function applyEffectsAll(configValueSources,
|
|
620
|
-
(0, utils_js_1.objectEntries)(
|
|
642
|
+
function applyEffectsAll(configValueSources, configDefinitions) {
|
|
643
|
+
(0, utils_js_1.objectEntries)(configDefinitions).forEach(([configName, configDef]) => {
|
|
621
644
|
if (!configDef.effect)
|
|
622
645
|
return;
|
|
623
646
|
// The value needs to be loaded at config time, that's why we only support effect for configs that are config-only for now.
|
|
@@ -676,9 +699,9 @@ function applyEffect(configModFromEffect, configValueSources, configDefEffect) {
|
|
|
676
699
|
}
|
|
677
700
|
});
|
|
678
701
|
}
|
|
679
|
-
function getComputed(configValueSources,
|
|
702
|
+
function getComputed(configValueSources, configDefinitions) {
|
|
680
703
|
const configValuesComputed = {};
|
|
681
|
-
(0, utils_js_1.objectEntries)(
|
|
704
|
+
(0, utils_js_1.objectEntries)(configDefinitions).forEach(([configName, configDef]) => {
|
|
682
705
|
if (!configDef._computed)
|
|
683
706
|
return;
|
|
684
707
|
const value = configDef._computed(configValueSources);
|
|
@@ -693,15 +716,7 @@ function getComputed(configValueSources, configDefinitionsRelevant) {
|
|
|
693
716
|
}
|
|
694
717
|
async function findPlusFiles(userRootDir, outDirRoot, isDev, extensions) {
|
|
695
718
|
const files = await (0, crawlPlusFiles_js_1.crawlPlusFiles)(userRootDir, outDirRoot, isDev);
|
|
696
|
-
const plusFiles = files.map(({ filePathRelativeToUserRootDir
|
|
697
|
-
return {
|
|
698
|
-
filePathRelativeToUserRootDir,
|
|
699
|
-
filePathAbsoluteVite: filePathRelativeToUserRootDir,
|
|
700
|
-
filePathAbsoluteFilesystem,
|
|
701
|
-
filePathToShowToUser: filePathRelativeToUserRootDir,
|
|
702
|
-
importPathAbsolute: null
|
|
703
|
-
};
|
|
704
|
-
});
|
|
719
|
+
const plusFiles = files.map(({ filePathRelativeToUserRootDir }) => (0, resolveFilePath_js_1.resolveFilePathRelativeToUserRootDir)(filePathRelativeToUserRootDir, userRootDir));
|
|
705
720
|
// TODO/v1-release: remove
|
|
706
721
|
extensions.forEach((extension) => {
|
|
707
722
|
extension.pageConfigsDistFiles?.forEach((pageConfigDistFile) => {
|
|
@@ -753,22 +768,6 @@ function assertNoUnexpectedPlusSign(filePath: string, fileName: string) {
|
|
|
753
768
|
)
|
|
754
769
|
}
|
|
755
770
|
*/
|
|
756
|
-
function isGlobalConfig(configName) {
|
|
757
|
-
if (configName === 'prerender')
|
|
758
|
-
return false;
|
|
759
|
-
const configNamesGlobal = getConfigNamesGlobal();
|
|
760
|
-
return (0, utils_js_1.arrayIncludes)(configNamesGlobal, configName);
|
|
761
|
-
}
|
|
762
|
-
function getConfigNamesGlobal() {
|
|
763
|
-
return Object.keys(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal);
|
|
764
|
-
}
|
|
765
|
-
function assertConfigExists(configName, configNamesRelevant, filePathToShowToUser) {
|
|
766
|
-
const configNames = [...configNamesRelevant, ...getConfigNamesGlobal()];
|
|
767
|
-
if (configNames.includes(configName))
|
|
768
|
-
return;
|
|
769
|
-
handleUnknownConfig(configName, configNames, filePathToShowToUser);
|
|
770
|
-
(0, utils_js_1.assert)(false);
|
|
771
|
-
}
|
|
772
771
|
function handleUnknownConfig(configName, configNames, filePathToShowToUser) {
|
|
773
772
|
let errMsg = `${filePathToShowToUser} defines an unknown config ${picocolors_1.default.cyan(configName)}`;
|
|
774
773
|
let configNameSimilar = null;
|
|
@@ -839,7 +838,7 @@ function isVikeConfigFile(filePath) {
|
|
|
839
838
|
return !!getConfigName(filePath);
|
|
840
839
|
}
|
|
841
840
|
exports.isVikeConfigFile = isVikeConfigFile;
|
|
842
|
-
function getConfigValues(configValueSources, configValuesComputed,
|
|
841
|
+
function getConfigValues(configValueSources, configValuesComputed, configDefinitions) {
|
|
843
842
|
const configValues = {};
|
|
844
843
|
Object.entries(configValuesComputed).forEach(([configName, configValueComputed]) => {
|
|
845
844
|
configValues[configName] = {
|
|
@@ -848,7 +847,7 @@ function getConfigValues(configValueSources, configValuesComputed, configDefinit
|
|
|
848
847
|
};
|
|
849
848
|
});
|
|
850
849
|
Object.entries(configValueSources).forEach(([configName, sources]) => {
|
|
851
|
-
const configDef =
|
|
850
|
+
const configDef = configDefinitions[configName];
|
|
852
851
|
(0, utils_js_1.assert)(configDef);
|
|
853
852
|
if (!configDef.cumulative) {
|
|
854
853
|
const configValueSource = sources[0];
|
|
@@ -962,3 +961,48 @@ function getConfigEnvValue(val, errMsgIntro) {
|
|
|
962
961
|
*/
|
|
963
962
|
return val;
|
|
964
963
|
}
|
|
964
|
+
function getConfigDefinition(configDefinitions, configName, filePathToShowToUser) {
|
|
965
|
+
const configDef = configDefinitions[configName];
|
|
966
|
+
assertConfigExists(configName, Object.keys(configDefinitions), filePathToShowToUser);
|
|
967
|
+
(0, utils_js_1.assert)(configDef);
|
|
968
|
+
return configDef;
|
|
969
|
+
}
|
|
970
|
+
function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
971
|
+
return configDefinitions[configName] ?? null;
|
|
972
|
+
}
|
|
973
|
+
function isConfigEnv(configDef, configName) {
|
|
974
|
+
const configEnv = configDef.env;
|
|
975
|
+
if (configDef.cumulative) {
|
|
976
|
+
// In principle we could lift that requirement (but it requires non-trivial modifications)
|
|
977
|
+
(0, utils_js_1.assertUsage)(configEnv.config, `Config ${picocolors_1.default.cyan(configName)} needs its ${picocolors_1.default.cyan('env')} to have ${picocolors_1.default.cyan('{ config: true }')} (because ${picocolors_1.default.cyan(configName)} is a ${picocolors_1.default.cyan('cumulative')} config)`);
|
|
978
|
+
}
|
|
979
|
+
return !!configEnv.config;
|
|
980
|
+
}
|
|
981
|
+
function isGlobalConfig(configName) {
|
|
982
|
+
if (configName === 'prerender')
|
|
983
|
+
return false;
|
|
984
|
+
const configNamesGlobal = getConfigNamesGlobal();
|
|
985
|
+
return (0, utils_js_1.arrayIncludes)(configNamesGlobal, configName);
|
|
986
|
+
}
|
|
987
|
+
function getConfigNamesGlobal() {
|
|
988
|
+
return Object.keys(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal);
|
|
989
|
+
}
|
|
990
|
+
function assertConfigExists(configName, configNamesRelevant, filePathToShowToUser) {
|
|
991
|
+
const configNames = [...configNamesRelevant, ...getConfigNamesGlobal()];
|
|
992
|
+
if (configNames.includes(configName))
|
|
993
|
+
return;
|
|
994
|
+
handleUnknownConfig(configName, configNames, filePathToShowToUser);
|
|
995
|
+
(0, utils_js_1.assert)(false);
|
|
996
|
+
}
|
|
997
|
+
function sortConfigValueSources(configValueSources, locationIdPage) {
|
|
998
|
+
return Object.fromEntries(Object.entries(configValueSources)
|
|
999
|
+
// Make order deterministic (no other purpose)
|
|
1000
|
+
.sort(([, [source1]], [, [source2]]) => source1.definedAt.filePathAbsoluteVite < source2.definedAt.filePathAbsoluteVite ? -1 : 1)
|
|
1001
|
+
// Sort after whether the config value was defined by an npm package
|
|
1002
|
+
.sort((0, utils_js_1.makeFirst)(([, [source]]) => {
|
|
1003
|
+
const { importPathAbsolute } = source.definedAt;
|
|
1004
|
+
return !!importPathAbsolute && (0, utils_js_1.isNpmPackageImport)(importPathAbsolute);
|
|
1005
|
+
}))
|
|
1006
|
+
// Sort after the filesystem inheritance of the config value
|
|
1007
|
+
.sort(([, [source1]], [, [source2]]) => (0, utils_js_1.reverse)((0, filesystemRouting_js_1.sortAfterInheritanceOrder)(source1.locationId, source2.locationId, locationIdPage))));
|
|
1008
|
+
}
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -12,6 +12,7 @@ const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
|
12
12
|
const serializeConfigValue_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValue.js");
|
|
13
13
|
const getConfigVike_js_1 = require("../../../../shared/getConfigVike.js");
|
|
14
14
|
const getConfigValuesSerialized_js_1 = require("./getConfigValuesSerialized.js");
|
|
15
|
+
const fixServerAssets_js_1 = require("../../buildConfig/fixServerAssets.js");
|
|
15
16
|
async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
|
|
16
17
|
const result = (0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(id);
|
|
17
18
|
(0, utils_js_1.assert)(result);
|
|
@@ -45,7 +46,7 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
45
46
|
isClientRouting
|
|
46
47
|
})));
|
|
47
48
|
lines.push('};');
|
|
48
|
-
if (includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
49
|
+
if (!(0, fixServerAssets_js_1.fixServerAssets_isEnabled)() && includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
49
50
|
importStatements.push(`import '${(0, extractAssetsQuery_js_1.extractAssetsAddQuery)((0, virtualFilePageConfigValuesAll_js_1.getVirtualFileIdPageConfigValuesAll)(pageId, false))}'`);
|
|
50
51
|
}
|
|
51
52
|
const code = [...importStatements, ...lines].join('\n');
|
|
@@ -27,7 +27,6 @@ __exportStar(require("../../utils/getDependencyPackageJson.js"), exports);
|
|
|
27
27
|
__exportStar(require("../../utils/requireResolve.js"), exports);
|
|
28
28
|
__exportStar(require("../../utils/arrayIncludes.js"), exports);
|
|
29
29
|
__exportStar(require("../../utils/isDev.js"), exports);
|
|
30
|
-
__exportStar(require("../../utils/objectKeys.js"), exports);
|
|
31
30
|
__exportStar(require("../../utils/getMostSimilar.js"), exports);
|
|
32
31
|
__exportStar(require("../../utils/getRandomId.js"), exports);
|
|
33
32
|
__exportStar(require("../../utils/joinEnglish.js"), exports);
|
|
@@ -35,10 +34,12 @@ __exportStar(require("../../utils/escapeRegex.js"), exports);
|
|
|
35
34
|
__exportStar(require("../../utils/stripAnsi.js"), exports);
|
|
36
35
|
__exportStar(require("../../utils/trimWithAnsi.js"), exports);
|
|
37
36
|
__exportStar(require("../../utils/removeEmptyLines.js"), exports);
|
|
38
|
-
__exportStar(require("../../utils/
|
|
37
|
+
__exportStar(require("../../utils/findFile.js"), exports);
|
|
39
38
|
__exportStar(require("../../utils/getPropAccessNotation.js"), exports);
|
|
40
39
|
__exportStar(require("../../utils/mergeCumulativeValues.js"), exports);
|
|
41
40
|
__exportStar(require("../../utils/deepEqual.js"), exports);
|
|
42
41
|
__exportStar(require("../../utils/assertKeys.js"), exports);
|
|
43
42
|
__exportStar(require("../../utils/injectRollupInputs.js"), exports);
|
|
44
43
|
__exportStar(require("../../utils/humanizeTime.js"), exports);
|
|
44
|
+
__exportStar(require("../../utils/pLimit.js"), exports);
|
|
45
|
+
__exportStar(require("../../utils/isVersionOrAbove.js"), exports);
|
|
@@ -51,11 +51,11 @@ const loadUserFilesServerSide_js_1 = require("../runtime/renderPage/loadUserFile
|
|
|
51
51
|
const getHook_js_1 = require("../../shared/hooks/getHook.js");
|
|
52
52
|
const noRouteMatch_js_1 = require("../../shared/route/noRouteMatch.js");
|
|
53
53
|
const getVikeConfig_js_1 = require("../plugin/plugins/importUserCode/v1-design/getVikeConfig.js");
|
|
54
|
-
const
|
|
54
|
+
const logErrorHint_js_1 = require("../runtime/renderPage/logErrorHint.js");
|
|
55
55
|
async function runPrerenderFromAPI(options = {}) {
|
|
56
56
|
await runPrerender(options, 'prerender()');
|
|
57
57
|
// - 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.
|
|
58
|
-
// - We don't use
|
|
58
|
+
// - 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.
|
|
59
59
|
}
|
|
60
60
|
exports.runPrerenderFromAPI = runPrerenderFromAPI;
|
|
61
61
|
async function runPrerenderFromCLI(options) {
|
|
@@ -64,7 +64,7 @@ async function runPrerenderFromCLI(options) {
|
|
|
64
64
|
}
|
|
65
65
|
catch (err) {
|
|
66
66
|
console.error(err);
|
|
67
|
-
(0,
|
|
67
|
+
(0, logErrorHint_js_1.logErrorHint)(err);
|
|
68
68
|
process.exit(1);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -75,7 +75,7 @@ async function runPrerenderFromAutoFullBuild(options) {
|
|
|
75
75
|
}
|
|
76
76
|
catch (err) {
|
|
77
77
|
console.error(err);
|
|
78
|
-
(0,
|
|
78
|
+
(0, logErrorHint_js_1.logErrorHint)(err);
|
|
79
79
|
process.exit(1);
|
|
80
80
|
}
|
|
81
81
|
}
|
|
@@ -87,7 +87,7 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
87
87
|
if (logLevel === 'info') {
|
|
88
88
|
console.log(`${picocolors_1.default.cyan(`vike v${utils_js_1.projectInfo.projectVersion}`)} ${picocolors_1.default.green('pre-rendering HTML...')}`);
|
|
89
89
|
}
|
|
90
|
-
(
|
|
90
|
+
handleNodeEnv();
|
|
91
91
|
await disableReactStreaming();
|
|
92
92
|
const viteConfig = await (0, vite_1.resolveConfig)(options.viteConfig || {}, 'vike pre-rendering', 'production');
|
|
93
93
|
assertLoadedConfig(viteConfig, options);
|
|
@@ -742,3 +742,10 @@ function assertIsNotAbort(err, urlOr404) {
|
|
|
742
742
|
(0, utils_js_1.assert)(abortCall);
|
|
743
743
|
(0, utils_js_1.assertUsage)(false, `${picocolors_1.default.cyan(abortCall)} thrown${thrownBy} while pre-rendering ${urlOr404} but ${picocolors_1.default.cyan(abortCaller)} isn't supported for pre-rendered pages`);
|
|
744
744
|
}
|
|
745
|
+
function handleNodeEnv() {
|
|
746
|
+
const assertNodeEnv = () => (0, utils_js_1.assertNodeEnvIsNotDev)('pre-rendering');
|
|
747
|
+
if ((0, utils_js_1.getNodeEnv)())
|
|
748
|
+
assertNodeEnv();
|
|
749
|
+
(0, utils_js_1.setNodeEnvToProduction)();
|
|
750
|
+
assertNodeEnv();
|
|
751
|
+
}
|
|
@@ -157,8 +157,11 @@ function assertNodeEnv(hasViteDevServer) {
|
|
|
157
157
|
const nodeEnv = (0, utils_js_1.getNodeEnv)();
|
|
158
158
|
if (nodeEnv === null || nodeEnv === 'test')
|
|
159
159
|
return;
|
|
160
|
-
const
|
|
161
|
-
//
|
|
162
|
-
|
|
163
|
-
|
|
160
|
+
const isDev = (0, utils_js_1.isNodeEnvDev)();
|
|
161
|
+
// Calling Vite's createServer() is enough for hasViteDevServer to be true, even without actually adding Vite's development middleware to the server: https://github.com/vikejs/vike/issues/792#issuecomment-1516830759
|
|
162
|
+
if (hasViteDevServer === isDev)
|
|
163
|
+
return;
|
|
164
|
+
const nodeEnvDesc = (0, utils_js_1.getNodeEnvDesc)();
|
|
165
|
+
// We should change this to be a warning if it blocks users (e.g. if a bad-citizen tool sets a wrong process.env.NODE_ENV value)
|
|
166
|
+
(0, utils_js_1.assertUsage)(false, `Vite's development server was${hasViteDevServer ? '' : "n't"} instantiated while the ${nodeEnvDesc} which is contradictory, see https://vike.dev/NODE_ENV`);
|
|
164
167
|
}
|
|
@@ -90,8 +90,8 @@ async function getHtmlTags(pageContext, injectToStream, injectFilter) {
|
|
|
90
90
|
// See https://github.com/vikejs/vike/pull/1271
|
|
91
91
|
const positionJavaScriptEntry = (() => {
|
|
92
92
|
if (pageContext._pageContextPromise) {
|
|
93
|
-
(0, utils_js_1.assertWarning)(!injectToStream, "[getHtmlTags()] We recommend against using streaming and a pageContext promise at the same time
|
|
94
|
-
// If there is a pageContext._pageContextPromise (which is resolved after the stream has ended) then the pageContext JSON data needs to await for it: https://vike.dev/
|
|
93
|
+
(0, utils_js_1.assertWarning)(!injectToStream, "[getHtmlTags()] We recommend against using streaming and a pageContext promise at the same time, because progressive hydration won't work.", { onlyOnce: true });
|
|
94
|
+
// If there is a pageContext._pageContextPromise (which is resolved after the stream has ended) then the pageContext JSON data needs to await for it: https://vike.dev/streaming#initial-data-after-stream-end
|
|
95
95
|
return 'HTML_END';
|
|
96
96
|
}
|
|
97
97
|
if (injectToStream) {
|
|
@@ -186,7 +186,7 @@ async function renderTemplate(templateContent, pageContext) {
|
|
|
186
186
|
const varType = typeof templateVar;
|
|
187
187
|
const streamNote = ['boolean', 'number', 'bigint', 'symbol'].includes(varType)
|
|
188
188
|
? null
|
|
189
|
-
: '(See https://vike.dev/
|
|
189
|
+
: '(See https://vike.dev/streaming for HTML streaming.)';
|
|
190
190
|
(0, utils_js_1.assertUsage)(varType === 'string', getErrMsg(picocolors_1.default.cyan(`typeof htmlVar === "${varType}"`), streamNote));
|
|
191
191
|
}
|
|
192
192
|
{
|
|
@@ -631,7 +631,7 @@ exports.isStream = isStream;
|
|
|
631
631
|
const __streamPipeWeb = '__streamPipeWeb';
|
|
632
632
|
/** @deprecated */
|
|
633
633
|
function pipeWebStream(pipe) {
|
|
634
|
-
(0, utils_js_1.assertWarning)(false, 'pipeWebStream() is outdated, use stampPipe() instead. See https://vike.dev/
|
|
634
|
+
(0, utils_js_1.assertWarning)(false, 'pipeWebStream() is outdated, use stampPipe() instead. See https://vike.dev/streaming', {
|
|
635
635
|
onlyOnce: true,
|
|
636
636
|
showStackTrace: true
|
|
637
637
|
});
|
|
@@ -668,7 +668,7 @@ exports.isStreamPipeWeb = isStreamPipeWeb;
|
|
|
668
668
|
const __streamPipeNode = '__streamPipeNode';
|
|
669
669
|
/** @deprecated */
|
|
670
670
|
function pipeNodeStream(pipe) {
|
|
671
|
-
(0, utils_js_1.assertWarning)(false, 'pipeNodeStream() is outdated, use stampPipe() instead. See https://vike.dev/
|
|
671
|
+
(0, utils_js_1.assertWarning)(false, 'pipeNodeStream() is outdated, use stampPipe() instead. See https://vike.dev/streaming', {
|
|
672
672
|
onlyOnce: true,
|
|
673
673
|
showStackTrace: true
|
|
674
674
|
});
|
|
@@ -6,11 +6,11 @@ const analyzePageClientSide_js_1 = require("../../../shared/getPageFiles/analyze
|
|
|
6
6
|
const virtualFilePageConfigValuesAll_js_1 = require("../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
7
7
|
const analyzeClientSide_js_1 = require("../../../shared/getPageFiles/analyzeClientSide.js");
|
|
8
8
|
const globalContext_js_1 = require("../globalContext.js");
|
|
9
|
-
const
|
|
9
|
+
const getClientEntry_js_1 = require("../../shared/getClientEntry.js");
|
|
10
10
|
function analyzePage(pageFilesAll, pageConfig, pageId) {
|
|
11
11
|
if (pageConfig) {
|
|
12
12
|
const { isClientSideRenderable, isClientRouting } = (0, analyzeClientSide_js_1.analyzeClientSide)(pageConfig, pageFilesAll, pageId);
|
|
13
|
-
const clientFilePath = (0,
|
|
13
|
+
const clientFilePath = (0, getClientEntry_js_1.getClientEntry)(pageConfig);
|
|
14
14
|
const clientEntry = !isClientSideRenderable ? clientFilePath : (0, determineClientEntry_js_1.getVikeClientEntry)(isClientRouting);
|
|
15
15
|
const clientDependencies = [];
|
|
16
16
|
clientDependencies.push({
|