vike 0.4.171-commit-75e1588 → 0.4.171-commit-6e37128
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/plugin/plugins/buildConfig.js +3 -4
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -15
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +30 -74
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +4 -42
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +9 -49
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +6 -0
- package/dist/cjs/node/prerender/runPrerender.js +33 -13
- package/dist/cjs/node/prerender/utils.js +1 -0
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +9 -7
- package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +1 -1
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +7 -7
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +4 -5
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +2 -2
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -5
- package/dist/cjs/node/shared/assertV1Design.js +3 -4
- package/dist/cjs/shared/{addUrlComputedProps.js → getPageContextUrlComputed.js} +52 -42
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +2 -2
- package/dist/cjs/shared/hooks/getHook.js +2 -2
- package/dist/cjs/shared/page-configs/getConfigValue.js +14 -17
- package/dist/cjs/shared/page-configs/getConfigValueBuildTime.js +70 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +3 -12
- package/dist/cjs/shared/page-configs/serialize/assertPageConfigsSerialized.js +1 -2
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +110 -16
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +198 -0
- package/dist/cjs/shared/route/index.js +2 -2
- package/dist/cjs/shared/route/loadPageRoutes.js +2 -2
- package/dist/cjs/shared/route/resolveRouteFunction.js +2 -2
- package/dist/cjs/shared/utils.js +2 -0
- package/dist/cjs/utils/changeEnumerable.js +9 -0
- package/dist/cjs/utils/hasProp.js +5 -7
- package/dist/cjs/utils/objectAssign.js +1 -1
- package/dist/cjs/utils/objectDefineProperty.js +8 -0
- package/dist/cjs/utils/projectInfo.js +1 -1
- package/dist/esm/client/client-routing-runtime/createPageContext.d.ts +6 -4
- package/dist/esm/client/client-routing-runtime/createPageContext.js +4 -3
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +14 -10
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +4 -4
- package/dist/esm/client/shared/loadUserFilesClientSide.js +4 -4
- package/dist/esm/node/plugin/plugins/buildConfig.js +3 -4
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +18 -15
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.d.ts +2 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +30 -74
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +4 -42
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +9 -49
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.d.ts +1 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +6 -0
- package/dist/esm/node/prerender/runPrerender.js +35 -15
- package/dist/esm/node/prerender/utils.d.ts +1 -0
- package/dist/esm/node/prerender/utils.js +1 -0
- package/dist/esm/node/runtime/renderPage/analyzePage.js +9 -7
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject/getCacheControl.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +7 -7
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +1 -9
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +4 -5
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +27 -50
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +6 -5
- package/dist/esm/node/shared/assertV1Design.d.ts +2 -2
- package/dist/esm/node/shared/assertV1Design.js +3 -4
- package/dist/esm/shared/{addUrlComputedProps.d.ts → getPageContextUrlComputed.d.ts} +23 -21
- package/dist/esm/shared/{addUrlComputedProps.js → getPageContextUrlComputed.js} +52 -42
- package/dist/esm/shared/getPageFiles/analyzeClientSide.js +3 -3
- package/dist/esm/shared/hooks/getHook.d.ts +2 -2
- package/dist/esm/shared/hooks/getHook.js +3 -3
- package/dist/esm/shared/page-configs/PageConfig.d.ts +10 -4
- package/dist/esm/shared/page-configs/getConfigValue.d.ts +12 -12
- package/dist/esm/shared/page-configs/getConfigValue.js +13 -16
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.d.ts +9 -0
- package/dist/esm/shared/page-configs/getConfigValueBuildTime.js +67 -0
- package/dist/esm/shared/page-configs/loadConfigValues.js +3 -12
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +15 -19
- package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.js +1 -2
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.d.ts +4 -1
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +109 -15
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +5 -0
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +192 -0
- package/dist/esm/shared/route/index.d.ts +3 -3
- package/dist/esm/shared/route/index.js +2 -2
- package/dist/esm/shared/route/loadPageRoutes.js +3 -3
- package/dist/esm/shared/route/resolveRouteFunction.d.ts +2 -2
- package/dist/esm/shared/route/resolveRouteFunction.js +2 -2
- package/dist/esm/shared/types.d.ts +4 -4
- package/dist/esm/shared/utils.d.ts +2 -0
- package/dist/esm/shared/utils.js +2 -0
- package/dist/esm/types/index.d.ts +1 -1
- package/dist/esm/utils/changeEnumerable.d.ts +2 -0
- package/dist/esm/utils/changeEnumerable.js +5 -0
- package/dist/esm/utils/hasProp.d.ts +4 -13
- package/dist/esm/utils/hasProp.js +5 -7
- package/dist/esm/utils/objectAssign.js +1 -1
- package/dist/esm/utils/objectDefineProperty.d.ts +4 -0
- package/dist/esm/utils/objectDefineProperty.js +4 -0
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +0 -101
- package/dist/cjs/node/plugin/shared/getConfigValueSourcesNotOverriden.js +0 -14
- package/dist/cjs/node/shared/getClientEntry.js +0 -12
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesImported.js +0 -85
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesSerialized.js +0 -24
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValue.js +0 -49
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.d.ts +0 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +0 -95
- package/dist/esm/node/plugin/shared/getConfigValueSourcesNotOverriden.d.ts +0 -5
- package/dist/esm/node/plugin/shared/getConfigValueSourcesNotOverriden.js +0 -11
- package/dist/esm/node/shared/getClientEntry.d.ts +0 -3
- package/dist/esm/node/shared/getClientEntry.js +0 -9
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.d.ts +0 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesImported.js +0 -82
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.d.ts +0 -4
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.js +0 -21
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.d.ts +0 -6
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +0 -46
|
@@ -6,19 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.manifestTempFile = exports.analyzeClientEntries = exports.assertRollupInput = exports.buildConfig = void 0;
|
|
7
7
|
const utils_js_1 = require("../utils.js");
|
|
8
8
|
const getVikeConfig_js_1 = require("./importUserCode/v1-design/getVikeConfig.js");
|
|
9
|
-
const getConfigValue_js_1 = require("../../../shared/page-configs/getConfigValue.js");
|
|
10
9
|
const findPageFiles_js_1 = require("../shared/findPageFiles.js");
|
|
11
10
|
const getConfigVike_js_1 = require("../../shared/getConfigVike.js");
|
|
12
11
|
const virtualFilePageConfigValuesAll_js_1 = require("../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
13
12
|
const extractAssetsQuery_js_1 = require("../../shared/extractAssetsQuery.js");
|
|
14
13
|
const module_1 = require("module");
|
|
15
|
-
const getClientEntry_js_1 = require("../../shared/getClientEntry.js");
|
|
16
14
|
const promises_1 = __importDefault(require("fs/promises"));
|
|
17
15
|
const path_1 = __importDefault(require("path"));
|
|
18
16
|
const fixServerAssets_js_1 = require("./buildConfig/fixServerAssets.js");
|
|
19
17
|
const index_js_1 = require("./importBuild/index.js");
|
|
20
18
|
const prependEntriesDir_js_1 = require("../../shared/prependEntriesDir.js");
|
|
21
19
|
const getFilePath_js_1 = require("../shared/getFilePath.js");
|
|
20
|
+
const getConfigValueBuildTime_js_1 = require("../../../shared/page-configs/getConfigValueBuildTime.js");
|
|
22
21
|
// @ts-ignore Shimmed by dist-cjs-fixup.js for CJS build.
|
|
23
22
|
const importMetaUrl = `file://${__filename}`;
|
|
24
23
|
const require_ = (0, module_1.createRequire)(importMetaUrl);
|
|
@@ -156,7 +155,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
156
155
|
let clientEntries = {};
|
|
157
156
|
let clientEntryList = [];
|
|
158
157
|
pageConfigs.forEach((pageConfig) => {
|
|
159
|
-
const configValue = (0,
|
|
158
|
+
const configValue = (0, getConfigValueBuildTime_js_1.getConfigValueBuildTime)(pageConfig, 'clientRouting', 'boolean');
|
|
160
159
|
if (configValue?.value) {
|
|
161
160
|
hasClientRouting = true;
|
|
162
161
|
}
|
|
@@ -169,7 +168,7 @@ function analyzeClientEntries(pageConfigs, config) {
|
|
|
169
168
|
clientEntries[entryName] = entryTarget;
|
|
170
169
|
}
|
|
171
170
|
{
|
|
172
|
-
const clientEntry = (0,
|
|
171
|
+
const clientEntry = (0, getConfigValueBuildTime_js_1.getConfigValueBuildTime)(pageConfig, 'client', 'string')?.value ?? null;
|
|
173
172
|
if (clientEntry) {
|
|
174
173
|
clientEntryList.push(clientEntry);
|
|
175
174
|
}
|
|
@@ -4,7 +4,6 @@ exports.determineOptimizeDeps = void 0;
|
|
|
4
4
|
const findPageFiles_js_1 = require("../../shared/findPageFiles.js");
|
|
5
5
|
const utils_js_1 = require("../../utils.js");
|
|
6
6
|
const getVikeConfig_js_1 = require("../importUserCode/v1-design/getVikeConfig.js");
|
|
7
|
-
const getConfigValueSourcesNotOverriden_js_1 = require("../../shared/getConfigValueSourcesNotOverriden.js");
|
|
8
7
|
const buildConfig_js_1 = require("../buildConfig.js");
|
|
9
8
|
const virtualFileImportUserCode_js_1 = require("../../../shared/virtual-files/virtualFileImportUserCode.js");
|
|
10
9
|
const getFilePath_js_1 = require("../../shared/getFilePath.js");
|
|
@@ -48,20 +47,24 @@ async function getPageDeps(config, pageConfigs, isDev) {
|
|
|
48
47
|
// V1 design
|
|
49
48
|
{
|
|
50
49
|
pageConfigs.forEach((pageConfig) => {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
50
|
+
Object.values(pageConfig.configValueSources).forEach((sources) => {
|
|
51
|
+
sources
|
|
52
|
+
.filter((c) => !c.isOverriden)
|
|
53
|
+
.forEach((configValueSource) => {
|
|
54
|
+
if (!configValueSource.valueIsImportedAtRuntime)
|
|
55
|
+
return;
|
|
56
|
+
const { definedAtFilePath, configEnv } = configValueSource;
|
|
57
|
+
if (!configEnv.client)
|
|
58
|
+
return;
|
|
59
|
+
if (definedAtFilePath.filePathAbsoluteUserRootDir !== null) {
|
|
60
|
+
// Vite expects entries to be filesystem absolute paths (surprisingly so).
|
|
61
|
+
addEntry(definedAtFilePath.filePathAbsoluteFilesystem);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// Adding definedAtFilePath.filePathAbsoluteFilesystem doesn't work for npm packages, I guess because of Vite's config.server.fs.allow
|
|
65
|
+
addInclude(definedAtFilePath.importPathAbsolute);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
65
68
|
});
|
|
66
69
|
});
|
|
67
70
|
}
|
|
@@ -22,7 +22,7 @@ const configDefinitionsBuiltIn = {
|
|
|
22
22
|
env: { server: true }
|
|
23
23
|
},
|
|
24
24
|
onBeforePrerenderStart: {
|
|
25
|
-
env: { server: true }
|
|
25
|
+
env: { server: true, production: true }
|
|
26
26
|
},
|
|
27
27
|
Page: {
|
|
28
28
|
env: { server: true, client: true }
|
|
@@ -48,7 +48,7 @@ const configDefinitionsBuiltIn = {
|
|
|
48
48
|
},
|
|
49
49
|
client: {
|
|
50
50
|
// The value of the client config is merely the file path to the client entry file, which is only needed on the sever-side
|
|
51
|
-
env: { server: true },
|
|
51
|
+
env: { server: true, config: true },
|
|
52
52
|
_valueIsFilePath: true
|
|
53
53
|
},
|
|
54
54
|
clientRouting: {
|
|
@@ -97,7 +97,7 @@ const configDefinitionsBuiltIn = {
|
|
|
97
97
|
exports.configDefinitionsBuiltIn = configDefinitionsBuiltIn;
|
|
98
98
|
const configDefinitionsBuiltInGlobal = {
|
|
99
99
|
onPrerenderStart: {
|
|
100
|
-
env: { server: true }
|
|
100
|
+
env: { server: true, production: true }
|
|
101
101
|
},
|
|
102
102
|
onBeforeRoute: {
|
|
103
103
|
env: { server: true, client: 'if-client-routing', eager: true }
|
|
@@ -15,12 +15,12 @@ const loggerNotProd_js_1 = require("../../../shared/loggerNotProd.js");
|
|
|
15
15
|
const removeSuperfluousViteLog_js_1 = require("../../../shared/loggerVite/removeSuperfluousViteLog.js");
|
|
16
16
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
17
17
|
const getConfigDefinedAt_js_1 = require("../../../../../shared/page-configs/getConfigDefinedAt.js");
|
|
18
|
-
const getConfigValuesSerialized_js_1 = require("./getConfigValuesSerialized.js");
|
|
19
18
|
const crawlPlusFiles_js_1 = require("./getVikeConfig/crawlPlusFiles.js");
|
|
20
19
|
const getConfigFileExport_js_1 = require("./getConfigFileExport.js");
|
|
21
20
|
const loadFileAtConfigTime_js_1 = require("./getVikeConfig/loadFileAtConfigTime.js");
|
|
22
21
|
const resolvePointerImport_js_1 = require("./getVikeConfig/resolvePointerImport.js");
|
|
23
22
|
const getFilePath_js_1 = require("../../../shared/getFilePath.js");
|
|
23
|
+
const getConfigValueBuildTime_js_1 = require("../../../../../shared/page-configs/getConfigValueBuildTime.js");
|
|
24
24
|
(0, utils_js_1.assertIsNotProductionRuntime)();
|
|
25
25
|
let devServerIsCorrupt = false;
|
|
26
26
|
let wasConfigInvalid = null;
|
|
@@ -171,7 +171,7 @@ async function loadInterfaceFiles(userRootDir, outDirRoot, isDev) {
|
|
|
171
171
|
// - If `configDef` is `undefined` => we load the file +{configName}.js later.
|
|
172
172
|
// - We already need to load +meta.js here (to get the custom config definitions defined by the user)
|
|
173
173
|
const configDef = getConfigDefinitionOptional(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltIn, configName);
|
|
174
|
-
if (configDef &&
|
|
174
|
+
if (configDef && isLoadableAtBuildTime(configDef)) {
|
|
175
175
|
await (0, loadFileAtConfigTime_js_1.loadValueFile)(interfaceFile, configName, userRootDir);
|
|
176
176
|
}
|
|
177
177
|
}
|
|
@@ -246,6 +246,7 @@ async function loadVikeConfig_withErrorHandling(userRootDir, outDirRoot, isDev,
|
|
|
246
246
|
const dummyData = {
|
|
247
247
|
pageConfigs: [],
|
|
248
248
|
pageConfigGlobal: {
|
|
249
|
+
configDefinitions: {},
|
|
249
250
|
configValueSources: {}
|
|
250
251
|
},
|
|
251
252
|
globalVikeConfig: {}
|
|
@@ -271,7 +272,7 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev) {
|
|
|
271
272
|
if (isGlobalConfig(configName))
|
|
272
273
|
return;
|
|
273
274
|
const configDef = getConfigDefinition(configDefinitions, configName, interfaceFile.filePath.filePathToShowToUser);
|
|
274
|
-
if (!
|
|
275
|
+
if (!isLoadableAtBuildTime(configDef))
|
|
275
276
|
return;
|
|
276
277
|
const isAlreadyLoaded = interfacefileIsAlreaydLoaded(interfaceFile);
|
|
277
278
|
if (isAlreadyLoaded)
|
|
@@ -293,14 +294,13 @@ async function loadVikeConfig(userRootDir, outDirRoot, isDev) {
|
|
|
293
294
|
const { routeFilesystem, isErrorPage } = determineRouteFilesystem(locationId, configValueSources);
|
|
294
295
|
applyEffectsAll(configValueSources, configDefinitions);
|
|
295
296
|
const configValuesComputed = getComputed(configValueSources, configDefinitions);
|
|
296
|
-
const configValues = getConfigValues(configValueSources, configValuesComputed, configDefinitions);
|
|
297
297
|
const pageConfig = {
|
|
298
298
|
pageId: locationId,
|
|
299
299
|
isErrorPage,
|
|
300
300
|
routeFilesystem,
|
|
301
|
+
configDefinitions,
|
|
301
302
|
configValueSources,
|
|
302
|
-
configValuesComputed
|
|
303
|
-
configValues
|
|
303
|
+
configValuesComputed
|
|
304
304
|
};
|
|
305
305
|
return pageConfig;
|
|
306
306
|
}));
|
|
@@ -333,7 +333,7 @@ function assertOnBeforeRenderEnv(pageConfig) {
|
|
|
333
333
|
if (!onBeforeRenderConfig)
|
|
334
334
|
return;
|
|
335
335
|
const onBeforeRenderEnv = onBeforeRenderConfig.configEnv;
|
|
336
|
-
const isClientRouting =
|
|
336
|
+
const isClientRouting = (0, getConfigValueBuildTime_js_1.getConfigValueBuildTime)(pageConfig, 'clientRouting', 'boolean');
|
|
337
337
|
// When using Server Routing, loading a onBeforeRender() hook on the client-side hasn't any effect (the Server Routing's client runtime never calls it); it unnecessarily bloats client bundle sizes
|
|
338
338
|
(0, utils_js_1.assertUsage)(!(onBeforeRenderEnv.client && !isClientRouting), `Page ${pageConfig.pageId} has an onBeforeRender() hook with env ${picocolors_1.default.cyan(JSON.stringify(onBeforeRenderEnv))} which doesn't make sense because the page is using Server Routing: onBeforeRender() can be run in the client only when using Client Routing.`);
|
|
339
339
|
}
|
|
@@ -394,6 +394,7 @@ async function getGlobalConfigs(interfaceFilesByLocationId, userRootDir, importe
|
|
|
394
394
|
}
|
|
395
395
|
const globalVikeConfig = {};
|
|
396
396
|
const pageConfigGlobal = {
|
|
397
|
+
configDefinitions: configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal,
|
|
397
398
|
configValueSources: {}
|
|
398
399
|
};
|
|
399
400
|
await Promise.all((0, utils_js_1.objectEntries)(configDefinitionsBuiltIn_js_1.configDefinitionsBuiltInGlobal).map(async ([configName, configDef]) => {
|
|
@@ -427,7 +428,15 @@ async function resolveConfigValueSources(configName, configDef, interfaceFilesRe
|
|
|
427
428
|
const add = (interfaceFile) => {
|
|
428
429
|
(0, utils_js_1.assert)(!visited.has(interfaceFile));
|
|
429
430
|
visited.add(interfaceFile);
|
|
430
|
-
sourcesInfo.
|
|
431
|
+
const isHighestInheritancePrecedence = sourcesInfo.length === 0;
|
|
432
|
+
sourcesInfo.push([
|
|
433
|
+
configName,
|
|
434
|
+
interfaceFile,
|
|
435
|
+
configDef,
|
|
436
|
+
userRootDir,
|
|
437
|
+
importedFilesLoaded,
|
|
438
|
+
isHighestInheritancePrecedence
|
|
439
|
+
]);
|
|
431
440
|
};
|
|
432
441
|
// Main resolution logic
|
|
433
442
|
{
|
|
@@ -498,7 +507,7 @@ function warnOverridenConfigValues(interfaceFileWinner, interfaceFilesOverriden,
|
|
|
498
507
|
function isInterfaceFileUserLand(interfaceFile) {
|
|
499
508
|
return (interfaceFile.isConfigFile && !interfaceFile.isConfigExtend) || interfaceFile.isValueFile;
|
|
500
509
|
}
|
|
501
|
-
async function getConfigValueSource(configName, interfaceFile, configDef, userRootDir, importedFilesLoaded) {
|
|
510
|
+
async function getConfigValueSource(configName, interfaceFile, configDef, userRootDir, importedFilesLoaded, isHighestInheritancePrecedence) {
|
|
502
511
|
const conf = interfaceFile.fileExportsByConfigName[configName];
|
|
503
512
|
(0, utils_js_1.assert)(conf);
|
|
504
513
|
const configEnv = deriveConfigEnvFromFileName(configDef.env, interfaceFile.filePath.fileName);
|
|
@@ -507,6 +516,7 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
507
516
|
...interfaceFile.filePath,
|
|
508
517
|
fileExportPathToShowToUser: ['default', configName]
|
|
509
518
|
};
|
|
519
|
+
const isOverriden = configDef.cumulative ? false : !isHighestInheritancePrecedence;
|
|
510
520
|
// +client.js
|
|
511
521
|
if (configDef._valueIsFilePath) {
|
|
512
522
|
let definedAtFilePath;
|
|
@@ -533,7 +543,8 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
533
543
|
valueIsFilePath: true,
|
|
534
544
|
configEnv,
|
|
535
545
|
valueIsImportedAtRuntime: true,
|
|
536
|
-
|
|
546
|
+
valueIsDefinedByPlusFile: false,
|
|
547
|
+
isOverriden,
|
|
537
548
|
definedAtFilePath
|
|
538
549
|
};
|
|
539
550
|
return configValueSource;
|
|
@@ -549,11 +560,12 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
549
560
|
locationId,
|
|
550
561
|
configEnv,
|
|
551
562
|
valueIsImportedAtRuntime: true,
|
|
552
|
-
|
|
563
|
+
valueIsDefinedByPlusFile: false,
|
|
564
|
+
isOverriden,
|
|
553
565
|
definedAtFilePath: pointerImport
|
|
554
566
|
};
|
|
555
567
|
// Load pointer import
|
|
556
|
-
if (
|
|
568
|
+
if (isLoadableAtBuildTime(configDef) &&
|
|
557
569
|
// The value of `extends` was already loaded and already used: we don't need the value of `extends` anymore
|
|
558
570
|
configName !== 'extends') {
|
|
559
571
|
if (pointerImport.filePathAbsoluteFilesystem) {
|
|
@@ -573,7 +585,8 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
573
585
|
value: configValue,
|
|
574
586
|
configEnv,
|
|
575
587
|
valueIsImportedAtRuntime: false,
|
|
576
|
-
|
|
588
|
+
valueIsDefinedByPlusFile: false,
|
|
589
|
+
isOverriden,
|
|
577
590
|
definedAtFilePath: definedAtFilePath_
|
|
578
591
|
};
|
|
579
592
|
return configValueSource;
|
|
@@ -586,7 +599,8 @@ async function getConfigValueSource(configName, interfaceFile, configDef, userRo
|
|
|
586
599
|
locationId,
|
|
587
600
|
configEnv,
|
|
588
601
|
valueIsImportedAtRuntime: !valueAlreadyLoaded,
|
|
589
|
-
|
|
602
|
+
valueIsDefinedByPlusFile: true,
|
|
603
|
+
isOverriden,
|
|
590
604
|
definedAtFilePath: {
|
|
591
605
|
...interfaceFile.filePath,
|
|
592
606
|
fileExportPathToShowToUser: configName === interfaceFile.configName
|
|
@@ -882,59 +896,6 @@ function isVikeConfigFile(filePath) {
|
|
|
882
896
|
return !!getConfigName(filePath);
|
|
883
897
|
}
|
|
884
898
|
exports.isVikeConfigFile = isVikeConfigFile;
|
|
885
|
-
function getConfigValues(configValueSources, configValuesComputed, configDefinitions) {
|
|
886
|
-
const configValues = {};
|
|
887
|
-
Object.entries(configValuesComputed).forEach(([configName, configValueComputed]) => {
|
|
888
|
-
configValues[configName] = {
|
|
889
|
-
type: 'computed',
|
|
890
|
-
value: configValueComputed.value,
|
|
891
|
-
definedAtData: null
|
|
892
|
-
};
|
|
893
|
-
});
|
|
894
|
-
Object.entries(configValueSources).forEach(([configName, sources]) => {
|
|
895
|
-
const configDef = configDefinitions[configName];
|
|
896
|
-
(0, utils_js_1.assert)(configDef);
|
|
897
|
-
if (!configDef.cumulative) {
|
|
898
|
-
const configValueSource = sources[0];
|
|
899
|
-
if ('value' in configValueSource) {
|
|
900
|
-
configValues[configName] = {
|
|
901
|
-
type: 'standard',
|
|
902
|
-
value: configValueSource.value,
|
|
903
|
-
definedAtData: getDefinedAtFile(configValueSource)
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
else {
|
|
908
|
-
const value = mergeCumulative(configName, sources);
|
|
909
|
-
const definedAtData = sources.map((source) => getDefinedAtFile(source));
|
|
910
|
-
(0, utils_js_1.assert)(value.length === definedAtData.length);
|
|
911
|
-
configValues[configName] = {
|
|
912
|
-
type: 'cumulative',
|
|
913
|
-
value,
|
|
914
|
-
definedAtData
|
|
915
|
-
};
|
|
916
|
-
}
|
|
917
|
-
});
|
|
918
|
-
return configValues;
|
|
919
|
-
}
|
|
920
|
-
function getDefinedAtFile(configValueSource) {
|
|
921
|
-
return {
|
|
922
|
-
filePathToShowToUser: configValueSource.definedAtFilePath.filePathToShowToUser,
|
|
923
|
-
fileExportPathToShowToUser: configValueSource.definedAtFilePath.fileExportPathToShowToUser
|
|
924
|
-
};
|
|
925
|
-
}
|
|
926
|
-
function mergeCumulative(configName, configValueSources) {
|
|
927
|
-
const configValues = [];
|
|
928
|
-
configValueSources.forEach((configValueSource) => {
|
|
929
|
-
// We could, in principle, also support cumulative for values that aren't loaded at config-time but it isn't completely trivial to implement.
|
|
930
|
-
(0, utils_js_1.assert)('value' in configValueSource);
|
|
931
|
-
// Make sure configValueSource.value is serializable
|
|
932
|
-
(0, getConfigValuesSerialized_js_1.assertConfigValueIsSerializable)(configValueSource.value, configName, getDefinedAtFile(configValueSource));
|
|
933
|
-
const { value } = configValueSource;
|
|
934
|
-
configValues.push(value);
|
|
935
|
-
});
|
|
936
|
-
return configValues;
|
|
937
|
-
}
|
|
938
899
|
function getConfigEnvValue(val, errMsgIntro) {
|
|
939
900
|
const errInvalidValue = `${errMsgIntro} an invalid value ${picocolors_1.default.cyan(JSON.stringify(val))}`;
|
|
940
901
|
// Legacy outdated values
|
|
@@ -977,13 +938,8 @@ function getConfigDefinition(configDefinitions, configName, filePathToShowToUser
|
|
|
977
938
|
function getConfigDefinitionOptional(configDefinitions, configName) {
|
|
978
939
|
return configDefinitions[configName] ?? null;
|
|
979
940
|
}
|
|
980
|
-
function
|
|
981
|
-
|
|
982
|
-
if (configDef.cumulative) {
|
|
983
|
-
// In principle we could lift that requirement (but it requires non-trivial modifications)
|
|
984
|
-
(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)`);
|
|
985
|
-
}
|
|
986
|
-
return !!configEnv.config;
|
|
941
|
+
function isLoadableAtBuildTime(configDef) {
|
|
942
|
+
return !!configDef.env.config && !configDef._valueIsFilePath;
|
|
987
943
|
}
|
|
988
944
|
function isGlobalConfig(configName) {
|
|
989
945
|
if (configName === 'prerender')
|
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -6,13 +6,11 @@ const virtualFilePageConfigValuesAll_js_1 = require("../../../../shared/virtual-
|
|
|
6
6
|
const getVikeConfig_js_1 = require("./getVikeConfig.js");
|
|
7
7
|
const extractAssetsQuery_js_1 = require("../../../../shared/extractAssetsQuery.js");
|
|
8
8
|
const debug_js_1 = require("./debug.js");
|
|
9
|
-
const getConfigValue_js_1 = require("../../../../../shared/page-configs/getConfigValue.js");
|
|
10
|
-
const getConfigValueSourcesNotOverriden_js_1 = require("../../../shared/getConfigValueSourcesNotOverriden.js");
|
|
11
9
|
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
12
|
-
const
|
|
10
|
+
const serializeConfigValues_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValues.js");
|
|
13
11
|
const getConfigVike_js_1 = require("../../../../shared/getConfigVike.js");
|
|
14
|
-
const getConfigValuesSerialized_js_1 = require("./getConfigValuesSerialized.js");
|
|
15
12
|
const fixServerAssets_js_1 = require("../../buildConfig/fixServerAssets.js");
|
|
13
|
+
const getConfigValueBuildTime_js_1 = require("../../../../../shared/page-configs/getConfigValueBuildTime.js");
|
|
16
14
|
async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
|
|
17
15
|
const result = (0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(id);
|
|
18
16
|
(0, utils_js_1.assert)(result);
|
|
@@ -35,16 +33,9 @@ exports.getVirtualFilePageConfigValuesAll = getVirtualFilePageConfigValuesAll;
|
|
|
35
33
|
function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAssetsImportedByServer, isDev) {
|
|
36
34
|
const lines = [];
|
|
37
35
|
const importStatements = [];
|
|
38
|
-
const isClientRouting = (0,
|
|
39
|
-
lines.push('export const configValuesImported = [');
|
|
40
|
-
lines.push(getConfigValuesImported(pageConfig, isForClientSide, isClientRouting, importStatements));
|
|
41
|
-
lines.push('];');
|
|
36
|
+
const isClientRouting = (0, getConfigValueBuildTime_js_1.getConfigValueBuildTime)(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
42
37
|
lines.push('export const configValuesSerialized = {');
|
|
43
|
-
lines.push((0,
|
|
44
|
-
isImport: false,
|
|
45
|
-
isForClientSide,
|
|
46
|
-
isClientRouting
|
|
47
|
-
})));
|
|
38
|
+
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: false, isDev }), ''));
|
|
48
39
|
lines.push('};');
|
|
49
40
|
if (!(0, fixServerAssets_js_1.fixServerAssets_isEnabled)() && includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
50
41
|
importStatements.push(`import '${(0, extractAssetsQuery_js_1.extractAssetsAddQuery)((0, virtualFilePageConfigValuesAll_js_1.getVirtualFileIdPageConfigValuesAll)(pageId, false))}'`);
|
|
@@ -52,32 +43,3 @@ function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAsse
|
|
|
52
43
|
const code = [...importStatements, ...lines].join('\n');
|
|
53
44
|
return code;
|
|
54
45
|
}
|
|
55
|
-
function getConfigValuesImported(pageConfig, isForClientSide, isClientRouting, importStatements) {
|
|
56
|
-
const lines = [];
|
|
57
|
-
(0, getConfigValueSourcesNotOverriden_js_1.getConfigValueSourcesNotOverriden)(pageConfig).forEach((configValueSource) => {
|
|
58
|
-
if (!isEnvMatch(configValueSource.configEnv, checkWhetherIsImport(configValueSource), {
|
|
59
|
-
isImport: true,
|
|
60
|
-
isForClientSide,
|
|
61
|
-
isClientRouting
|
|
62
|
-
}))
|
|
63
|
-
return;
|
|
64
|
-
const whitespace = ' ';
|
|
65
|
-
lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configValueSource.configName, whitespace, importStatements));
|
|
66
|
-
});
|
|
67
|
-
const code = lines.join('\n');
|
|
68
|
-
return code;
|
|
69
|
-
}
|
|
70
|
-
function checkWhetherIsImport(configValueSource) {
|
|
71
|
-
const { valueIsImportedAtRuntime, valueIsFilePath } = configValueSource;
|
|
72
|
-
return valueIsImportedAtRuntime && !valueIsFilePath;
|
|
73
|
-
}
|
|
74
|
-
function isEnvMatch(configEnv, isImport, runtime) {
|
|
75
|
-
// Whether config value is imported or serialized
|
|
76
|
-
if (isImport !== runtime.isImport)
|
|
77
|
-
return false;
|
|
78
|
-
// Runtime match
|
|
79
|
-
const { isForClientSide, isClientRouting } = runtime;
|
|
80
|
-
if (!(0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: false }))
|
|
81
|
-
return false;
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getVirtualFilePageConfigs = void 0;
|
|
4
|
-
const utils_js_1 = require("../../../utils.js");
|
|
5
4
|
const virtualFilePageConfigValuesAll_js_1 = require("../../../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
6
5
|
const debug_js_1 = require("./debug.js");
|
|
7
6
|
const getVikeConfig_js_1 = require("./getVikeConfig.js");
|
|
8
7
|
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
9
|
-
const
|
|
10
|
-
const getConfigValuesSerialized_js_1 = require("./getConfigValuesSerialized.js");
|
|
8
|
+
const serializeConfigValues_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValues.js");
|
|
11
9
|
async function getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, config) {
|
|
12
10
|
const { pageConfigs, pageConfigGlobal } = await (0, getVikeConfig_js_1.getVikeConfig)(config, isDev, true);
|
|
13
11
|
return getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
|
|
@@ -17,16 +15,16 @@ function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isCl
|
|
|
17
15
|
const lines = [];
|
|
18
16
|
const importStatements = [];
|
|
19
17
|
lines.push('export const pageConfigsSerialized = [');
|
|
20
|
-
lines.push(getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements));
|
|
18
|
+
lines.push(getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, isDev, importStatements));
|
|
21
19
|
lines.push('];');
|
|
22
20
|
lines.push('export const pageConfigGlobalSerialized = {');
|
|
23
|
-
lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements));
|
|
21
|
+
lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements));
|
|
24
22
|
lines.push('};');
|
|
25
23
|
const code = [...importStatements, ...lines].join('\n');
|
|
26
24
|
(0, debug_js_1.debug)(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
27
25
|
return code;
|
|
28
26
|
}
|
|
29
|
-
function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements) {
|
|
27
|
+
function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, isDev, importStatements) {
|
|
30
28
|
const lines = [];
|
|
31
29
|
pageConfigs.forEach((pageConfig) => {
|
|
32
30
|
const { pageId, routeFilesystem, isErrorPage } = pageConfig;
|
|
@@ -36,57 +34,19 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
|
|
|
36
34
|
lines.push(` isErrorPage: ${JSON.stringify(isErrorPage)},`);
|
|
37
35
|
lines.push(` routeFilesystem: ${JSON.stringify(routeFilesystem)},`);
|
|
38
36
|
lines.push(` loadConfigValuesAll: () => import(${JSON.stringify(virtualFileIdPageConfigValuesAll)}),`);
|
|
39
|
-
// Serialized config values
|
|
40
37
|
lines.push(` configValuesSerialized: {`);
|
|
41
|
-
lines.push((0,
|
|
38
|
+
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: true, isDev }), ' '));
|
|
42
39
|
lines.push(` },`);
|
|
43
|
-
// Imported config values
|
|
44
|
-
const whitespace = ' ';
|
|
45
|
-
lines.push(`${whitespace}configValuesImported: [`);
|
|
46
|
-
Object.entries(pageConfig.configValueSources).forEach(([configName, sources]) => {
|
|
47
|
-
const configValue = pageConfig.configValues[configName];
|
|
48
|
-
if (configValue)
|
|
49
|
-
return;
|
|
50
|
-
const configValueSource = sources[0];
|
|
51
|
-
(0, utils_js_1.assert)(configValueSource);
|
|
52
|
-
if (!configValueSource.configEnv.eager)
|
|
53
|
-
return;
|
|
54
|
-
if (!(0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configValueSource.configEnv, { isForClientSide, isClientRouting, isEager: true }))
|
|
55
|
-
return;
|
|
56
|
-
lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configName, whitespace, importStatements));
|
|
57
|
-
});
|
|
58
|
-
lines.push(`${whitespace}],`);
|
|
59
40
|
lines.push(` },`);
|
|
60
41
|
});
|
|
61
42
|
const code = lines.join('\n');
|
|
62
43
|
return code;
|
|
63
44
|
}
|
|
64
|
-
function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements) {
|
|
45
|
+
function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements) {
|
|
65
46
|
const lines = [];
|
|
66
|
-
|
|
67
|
-
lines.push(
|
|
68
|
-
lines.push(` },`)
|
|
69
|
-
*/
|
|
70
|
-
lines.push(` configValuesImported: [`);
|
|
71
|
-
(0, utils_js_1.objectEntries)(pageConfigGlobal.configValueSources).forEach(([configName, sources]) => {
|
|
72
|
-
if (configName === 'onBeforeRoute') {
|
|
73
|
-
// if( isForClientSide && !isClientRouting ) return
|
|
74
|
-
}
|
|
75
|
-
else if (configName === 'onPrerenderStart') {
|
|
76
|
-
if (isDev || isForClientSide) {
|
|
77
|
-
// Only load onPrerenderStart() in server production runtime
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
(0, utils_js_1.assert)(false);
|
|
83
|
-
}
|
|
84
|
-
const configValueSource = sources[0];
|
|
85
|
-
(0, utils_js_1.assert)(configValueSource);
|
|
86
|
-
const whitespace = ' ';
|
|
87
|
-
lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configName, whitespace, importStatements));
|
|
88
|
-
});
|
|
89
|
-
lines.push(` ],`);
|
|
47
|
+
lines.push(` configValuesSerialized: {`);
|
|
48
|
+
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfigGlobal, importStatements, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: true, isDev }), ' '));
|
|
49
|
+
lines.push(` },`);
|
|
90
50
|
const code = lines.join('\n');
|
|
91
51
|
return code;
|
|
92
52
|
}
|
|
@@ -16,6 +16,12 @@ function isRuntimeEnvMatch(configEnv, runtime) {
|
|
|
16
16
|
// Eager
|
|
17
17
|
if (runtime.isEager !== !!configEnv.eager)
|
|
18
18
|
return false;
|
|
19
|
+
// Production/development
|
|
20
|
+
if (
|
|
21
|
+
//
|
|
22
|
+
(configEnv.production === true && runtime.isDev) ||
|
|
23
|
+
(configEnv.production === false && !runtime.isDev))
|
|
24
|
+
return false;
|
|
19
25
|
return true;
|
|
20
26
|
}
|
|
21
27
|
exports.isRuntimeEnvMatch = isRuntimeEnvMatch;
|
|
@@ -44,7 +44,7 @@ const helpers_js_1 = require("../../shared/page-configs/helpers.js");
|
|
|
44
44
|
const getConfigValue_js_1 = require("../../shared/page-configs/getConfigValue.js");
|
|
45
45
|
const loadConfigValues_js_1 = require("../../shared/page-configs/loadConfigValues.js");
|
|
46
46
|
const error_page_js_1 = require("../../shared/error-page.js");
|
|
47
|
-
const
|
|
47
|
+
const getPageContextUrlComputed_js_1 = require("../../shared/getPageContextUrlComputed.js");
|
|
48
48
|
const abort_js_1 = require("../../shared/route/abort.js");
|
|
49
49
|
const loadUserFilesServerSide_js_1 = require("../runtime/renderPage/loadUserFilesServerSide.js");
|
|
50
50
|
const getHook_js_1 = require("../../shared/hooks/getHook.js");
|
|
@@ -52,6 +52,7 @@ const noRouteMatch_js_1 = require("../../shared/route/noRouteMatch.js");
|
|
|
52
52
|
const getVikeConfig_js_1 = require("../plugin/plugins/importUserCode/v1-design/getVikeConfig.js");
|
|
53
53
|
const logErrorHint_js_1 = require("../runtime/renderPage/logErrorHint.js");
|
|
54
54
|
const executeHook_js_1 = require("../../shared/hooks/executeHook.js");
|
|
55
|
+
const getConfigValueBuildTime_js_1 = require("../../shared/page-configs/getConfigValueBuildTime.js");
|
|
55
56
|
async function runPrerenderFromAPI(options = {}) {
|
|
56
57
|
await runPrerender(options, 'prerender()');
|
|
57
58
|
// - 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.
|
|
@@ -142,7 +143,7 @@ async function collectDoNoPrerenderList(renderContext, pageConfigs, doNotPrerend
|
|
|
142
143
|
// V1 design
|
|
143
144
|
pageConfigs.forEach((pageConfig) => {
|
|
144
145
|
const configName = 'prerender';
|
|
145
|
-
const configValue = (0,
|
|
146
|
+
const configValue = (0, getConfigValueBuildTime_js_1.getConfigValueBuildTime)(pageConfig, configName, 'boolean');
|
|
146
147
|
if (configValue?.value === false) {
|
|
147
148
|
const configValueFilePathToShowToUser = (0, helpers_js_1.getConfigValueFilePathToShowToUser)(configValue.definedAtData);
|
|
148
149
|
(0, utils_js_1.assert)(configValueFilePathToShowToUser);
|
|
@@ -268,9 +269,9 @@ async function callOnBeforePrerenderStartHooks(prerenderContext, renderContext,
|
|
|
268
269
|
prerenderContext.pageContexts.push(pageContextNew);
|
|
269
270
|
if (pageContext) {
|
|
270
271
|
(0, utils_js_1.objectAssign)(pageContextNew, {
|
|
271
|
-
_pageContextAlreadyProvidedByOnPrerenderHook: true
|
|
272
|
-
...pageContext
|
|
272
|
+
_pageContextAlreadyProvidedByOnPrerenderHook: true
|
|
273
273
|
});
|
|
274
|
+
(0, utils_js_1.objectAssign)(pageContextNew, pageContext);
|
|
274
275
|
}
|
|
275
276
|
});
|
|
276
277
|
})));
|
|
@@ -328,14 +329,11 @@ function createPageContext(urlOriginal, renderContext, prerenderContext) {
|
|
|
328
329
|
_prerenderContext: prerenderContext
|
|
329
330
|
};
|
|
330
331
|
const pageContextInit = {
|
|
331
|
-
urlOriginal
|
|
332
|
-
...prerenderContext.pageContextInit
|
|
332
|
+
urlOriginal
|
|
333
333
|
};
|
|
334
|
+
(0, utils_js_1.objectAssign)(pageContextInit, prerenderContext.pageContextInit);
|
|
334
335
|
{
|
|
335
|
-
const pageContextInitEnhanced = (0, renderPageAlreadyRouted_js_1.getPageContextInitEnhanced)(pageContextInit, renderContext
|
|
336
|
-
// We set `enumerable` to `false` to avoid computed URL properties from being iterated & copied in a onPrerenderStart() hook, e.g. /examples/i18n/
|
|
337
|
-
urlComputedPropsNonEnumerable: true
|
|
338
|
-
});
|
|
336
|
+
const pageContextInitEnhanced = (0, renderPageAlreadyRouted_js_1.getPageContextInitEnhanced)(pageContextInit, renderContext);
|
|
339
337
|
(0, utils_js_1.objectAssign)(pageContext, pageContextInitEnhanced);
|
|
340
338
|
}
|
|
341
339
|
return pageContext;
|
|
@@ -410,6 +408,8 @@ async function callOnPrerenderStartHook(prerenderContext, renderContext) {
|
|
|
410
408
|
pageContext._urlOriginalBeforeHook = pageContext.urlOriginal;
|
|
411
409
|
});
|
|
412
410
|
const docLink = 'https://vike.dev/i18n#pre-rendering';
|
|
411
|
+
// Set `enumerable` to `false` to avoid computed URL properties from being iterated & copied in onPrerenderStart() hook, e.g. /examples/i18n/
|
|
412
|
+
const { restoreEnumerable, addPageContextComputedUrl } = makePageContextComputedUrlNonEnumerable(prerenderContext.pageContexts);
|
|
413
413
|
let result = await (0, executeHook_js_1.executeHook)(() => hookFn({
|
|
414
414
|
pageContexts: prerenderContext.pageContexts,
|
|
415
415
|
// TODO/v1-release: remove warning
|
|
@@ -421,6 +421,7 @@ async function callOnPrerenderStartHook(prerenderContext, renderContext) {
|
|
|
421
421
|
return prerenderContext.pageContexts;
|
|
422
422
|
}
|
|
423
423
|
}), onPrerenderStartHook, null);
|
|
424
|
+
restoreEnumerable();
|
|
424
425
|
if (result === null || result === undefined) {
|
|
425
426
|
return;
|
|
426
427
|
}
|
|
@@ -458,9 +459,8 @@ async function callOnPrerenderStartHook(prerenderContext, renderContext) {
|
|
|
458
459
|
hookName
|
|
459
460
|
};
|
|
460
461
|
}
|
|
461
|
-
// Restore as URL computed props are lost when user makes a pageContext copy
|
|
462
|
-
(0, addUrlComputedProps_js_1.addUrlComputedProps)(pageContext);
|
|
463
462
|
});
|
|
463
|
+
addPageContextComputedUrl(prerenderContext.pageContexts);
|
|
464
464
|
}
|
|
465
465
|
async function routeAndPrerender(prerenderContext, concurrencyLimit, onComplete) {
|
|
466
466
|
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
@@ -502,7 +502,7 @@ async function routeAndPrerender(prerenderContext, concurrencyLimit, onComplete)
|
|
|
502
502
|
if (pageContext._pageConfigs.length > 0) {
|
|
503
503
|
const pageConfig = pageContext._pageConfigs.find((p) => p.pageId === pageId);
|
|
504
504
|
(0, utils_js_1.assert)(pageConfig);
|
|
505
|
-
usesClientRouter = (0, getConfigValue_js_1.
|
|
505
|
+
usesClientRouter = (0, getConfigValue_js_1.getConfigValueRuntime)(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
506
506
|
}
|
|
507
507
|
else {
|
|
508
508
|
usesClientRouter = globalContext.pluginManifest.usesClientRouter;
|
|
@@ -743,3 +743,23 @@ function assertIsNotAbort(err, urlOr404) {
|
|
|
743
743
|
(0, utils_js_1.assert)(abortCall);
|
|
744
744
|
(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`);
|
|
745
745
|
}
|
|
746
|
+
function makePageContextComputedUrlNonEnumerable(pageContexts) {
|
|
747
|
+
change(false);
|
|
748
|
+
return { restoreEnumerable, addPageContextComputedUrl };
|
|
749
|
+
function restoreEnumerable() {
|
|
750
|
+
change(true);
|
|
751
|
+
}
|
|
752
|
+
function addPageContextComputedUrl(pageContexts) {
|
|
753
|
+
// Add URL computed props to the user-generated pageContext copies
|
|
754
|
+
pageContexts.forEach((pageContext) => {
|
|
755
|
+
const pageContextUrlComputed = (0, getPageContextUrlComputed_js_1.getPageContextUrlComputed)(pageContext);
|
|
756
|
+
(0, utils_js_1.objectAssign)(pageContext, pageContextUrlComputed);
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
function change(enumerable) {
|
|
760
|
+
pageContexts.forEach((pageContext) => {
|
|
761
|
+
(0, utils_js_1.changeEnumerable)(pageContext, 'urlPathname', enumerable);
|
|
762
|
+
(0, utils_js_1.changeEnumerable)(pageContext, 'urlParsed', enumerable);
|
|
763
|
+
});
|
|
764
|
+
}
|
|
765
|
+
}
|
|
@@ -31,3 +31,4 @@ __exportStar(require("../../utils/assertNodeEnv.js"), exports);
|
|
|
31
31
|
__exportStar(require("../../utils/pLimit.js"), exports);
|
|
32
32
|
__exportStar(require("../../utils/assertPathFilesystemAbsolute.js"), exports);
|
|
33
33
|
__exportStar(require("../../utils/isArray.js"), exports);
|
|
34
|
+
__exportStar(require("../../utils/changeEnumerable.js"), exports);
|