vike 0.4.146-commit-701e2e5 → 0.4.147-commit-2fa53b2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/plugin/index.js +6 -4
- package/dist/cjs/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -4
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +76 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +61 -40
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +104 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +62 -75
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +43 -17
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +12 -70
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +11 -8
- package/dist/cjs/node/plugin/shared/{getConfigValueSourcesRelevant.js → getConfigValueSourcesNotOverriden.js} +3 -3
- package/dist/cjs/node/plugin/utils.js +2 -0
- package/dist/cjs/node/prerender/runPrerender.js +75 -67
- package/dist/cjs/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
- package/dist/cjs/node/runtime/index-common.js +3 -1
- package/dist/cjs/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.js +12 -12
- package/dist/cjs/node/runtime/renderPage/createHttpResponseObject.js +3 -3
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +1 -2
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +1 -1
- package/dist/cjs/node/runtime/renderPage.js +8 -5
- package/dist/cjs/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +1 -0
- package/dist/cjs/shared/page-configs/loadConfigValues.js +12 -3
- package/dist/cjs/shared/page-configs/serialize/parseConfigValuesSerialized.js +19 -0
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +3 -12
- package/dist/cjs/utils/assertKeys.js +28 -0
- package/dist/cjs/utils/joinEnglish.js +3 -3
- package/dist/cjs/utils/parseUrl.js +24 -16
- package/dist/cjs/utils/projectInfo.js +3 -2
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.js +25 -11
- package/dist/esm/client/client-routing-runtime/index.d.ts +1 -0
- package/dist/esm/client/client-routing-runtime/index.js +1 -0
- package/dist/esm/client/client-routing-runtime/onBrowserHistoryNavigation.js +2 -2
- package/dist/esm/client/shared/getPageContextSerializedInHtml.js +1 -1
- package/dist/esm/node/plugin/index.d.ts +1 -0
- package/dist/esm/node/plugin/index.js +1 -0
- package/dist/esm/node/plugin/plugins/devConfig/determineOptimizeDeps.js +3 -4
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +70 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +58 -37
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +5 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +98 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +63 -76
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +43 -17
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.d.ts +0 -3
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +13 -68
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +11 -8
- package/dist/esm/node/plugin/shared/getConfigValueSourcesNotOverriden.d.ts +5 -0
- package/dist/esm/node/plugin/shared/{getConfigValueSourcesRelevant.js → getConfigValueSourcesNotOverriden.js} +2 -2
- package/dist/esm/node/plugin/utils.d.ts +2 -0
- package/dist/esm/node/plugin/utils.js +2 -0
- package/dist/esm/node/prerender/runPrerender.js +75 -67
- package/dist/esm/node/runtime/html/injectAssets/injectAssets__public.js +1 -1
- package/dist/esm/node/runtime/index-common.d.ts +1 -0
- package/dist/esm/node/runtime/index-common.js +1 -0
- package/dist/esm/node/runtime/renderPage/analyzePage.js +2 -2
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.js +12 -12
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createHttpResponseObject.js +3 -3
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +1 -2
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +1 -1
- package/dist/esm/node/runtime/renderPage.js +9 -6
- package/dist/esm/shared/getPageFiles/analyzePageClientSide/determineClientEntry.js +1 -0
- package/dist/esm/shared/page-configs/PageConfig.d.ts +14 -4
- package/dist/esm/shared/page-configs/loadConfigValues.js +12 -3
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.d.ts +4 -0
- package/dist/esm/shared/page-configs/serialize/parseConfigValuesSerialized.js +16 -0
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +4 -13
- package/dist/esm/utils/assertKeys.d.ts +4 -0
- package/dist/esm/utils/assertKeys.js +22 -0
- package/dist/esm/utils/joinEnglish.d.ts +1 -1
- package/dist/esm/utils/joinEnglish.js +3 -3
- package/dist/esm/utils/parseUrl.js +24 -16
- package/dist/esm/utils/projectInfo.d.ts +3 -1
- package/dist/esm/utils/projectInfo.js +2 -1
- package/package.json +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/helpers.js +0 -28
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.d.ts +0 -5
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/helpers.js +0 -25
- package/dist/esm/node/plugin/shared/getConfigValueSourcesRelevant.d.ts +0 -5
package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js
CHANGED
|
@@ -7,10 +7,11 @@ 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
9
|
const helpers_js_1 = require("../../../../../shared/page-configs/helpers.js");
|
|
10
|
-
const
|
|
10
|
+
const getConfigValueSourcesNotOverriden_js_1 = require("../../../shared/getConfigValueSourcesNotOverriden.js");
|
|
11
11
|
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
|
+
const getConfigValuesSerialized_js_1 = require("./getConfigValuesSerialized.js");
|
|
14
15
|
async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
|
|
15
16
|
const result = (0, virtualFilePageConfigValuesAll_js_1.isVirtualFileIdPageConfigValuesAll)(id);
|
|
16
17
|
(0, utils_js_1.assert)(result);
|
|
@@ -31,27 +32,52 @@ async function getVirtualFilePageConfigValuesAll(id, isDev, config) {
|
|
|
31
32
|
}
|
|
32
33
|
exports.getVirtualFilePageConfigValuesAll = getVirtualFilePageConfigValuesAll;
|
|
33
34
|
function getLoadConfigValuesAll(pageConfig, isForClientSide, pageId, includeAssetsImportedByServer, isDev) {
|
|
34
|
-
const configValue = (0, helpers_js_1.getConfigValue)(pageConfig, 'clientRouting', 'boolean');
|
|
35
|
-
const isClientRouting = configValue?.value ?? false;
|
|
36
35
|
const lines = [];
|
|
37
36
|
const importStatements = [];
|
|
38
|
-
|
|
39
|
-
const
|
|
40
|
-
(
|
|
41
|
-
const { valueIsImportedAtRuntime, configEnv, configName } = configValueSource;
|
|
42
|
-
if (!valueIsImportedAtRuntime)
|
|
43
|
-
return;
|
|
44
|
-
if (configValueSource.valueIsFilePath)
|
|
45
|
-
return;
|
|
46
|
-
if (!(0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: false }))
|
|
47
|
-
return;
|
|
48
|
-
const whitespace = ' ';
|
|
49
|
-
lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
50
|
-
});
|
|
37
|
+
const isClientRouting = (0, helpers_js_1.getConfigValue)(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
38
|
+
lines.push('export const configValuesImported = [');
|
|
39
|
+
lines.push(getConfigValuesImported(pageConfig, isForClientSide, isClientRouting, importStatements));
|
|
51
40
|
lines.push('];');
|
|
41
|
+
lines.push('export const configValuesSerialized = {');
|
|
42
|
+
lines.push((0, getConfigValuesSerialized_js_1.getConfigValuesSerialized)(pageConfig, (configEnv, configValueSource) => isEnvMatch(configEnv, !configValueSource ? false : checkWhetherIsImport(configValueSource), {
|
|
43
|
+
isImport: false,
|
|
44
|
+
isForClientSide,
|
|
45
|
+
isClientRouting
|
|
46
|
+
})));
|
|
47
|
+
lines.push('};');
|
|
52
48
|
if (includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
53
|
-
|
|
49
|
+
importStatements.push(`import '${(0, extractAssetsQuery_js_1.extractAssetsAddQuery)((0, virtualFilePageConfigValuesAll_js_1.getVirtualFileIdPageConfigValuesAll)(pageId, false))}'`);
|
|
54
50
|
}
|
|
55
51
|
const code = [...importStatements, ...lines].join('\n');
|
|
56
52
|
return code;
|
|
57
53
|
}
|
|
54
|
+
function getConfigValuesImported(pageConfig, isForClientSide, isClientRouting, importStatements) {
|
|
55
|
+
const lines = [];
|
|
56
|
+
const varCounterContainer = { varCounter: 0 };
|
|
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, varCounterContainer, 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,19 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
3
|
+
exports.getVirtualFilePageConfigs = void 0;
|
|
7
4
|
const utils_js_1 = require("../../../utils.js");
|
|
8
5
|
const virtualFilePageConfigValuesAll_js_1 = require("../../../../shared/virtual-files/virtualFilePageConfigValuesAll.js");
|
|
9
6
|
const debug_js_1 = require("./debug.js");
|
|
10
|
-
const stringify_1 = require("@brillout/json-serializer/stringify");
|
|
11
|
-
const helpers_js_1 = require("./helpers.js");
|
|
12
|
-
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
13
7
|
const getVikeConfig_js_1 = require("./getVikeConfig.js");
|
|
14
8
|
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
15
|
-
const helpers_js_2 = require("../../../../../shared/page-configs/helpers.js");
|
|
16
9
|
const serializeConfigValue_js_1 = require("../../../../../shared/page-configs/serialize/serializeConfigValue.js");
|
|
10
|
+
const getConfigValuesSerialized_js_1 = require("./getConfigValuesSerialized.js");
|
|
17
11
|
async function getVirtualFilePageConfigs(isForClientSide, isDev, id, isClientRouting, config) {
|
|
18
12
|
const { pageConfigs, pageConfigGlobal } = await (0, getVikeConfig_js_1.getVikeConfig)(config, isDev, true);
|
|
19
13
|
return getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isClientRouting);
|
|
@@ -23,15 +17,18 @@ function getCode(pageConfigs, pageConfigGlobal, isForClientSide, isDev, id, isCl
|
|
|
23
17
|
const lines = [];
|
|
24
18
|
const importStatements = [];
|
|
25
19
|
const varCounterContainer = { varCounter: 0 };
|
|
20
|
+
lines.push('export const pageConfigsSerialized = [');
|
|
26
21
|
lines.push(getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements, varCounterContainer));
|
|
22
|
+
lines.push('];');
|
|
23
|
+
lines.push('export const pageConfigGlobalSerialized = {');
|
|
27
24
|
lines.push(getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements, varCounterContainer));
|
|
25
|
+
lines.push('};');
|
|
28
26
|
const code = [...importStatements, ...lines].join('\n');
|
|
29
27
|
(0, debug_js_1.debug)(id, isForClientSide ? 'CLIENT-SIDE' : 'SERVER-SIDE', code);
|
|
30
28
|
return code;
|
|
31
29
|
}
|
|
32
30
|
function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRouting, importStatements, varCounterContainer) {
|
|
33
31
|
const lines = [];
|
|
34
|
-
lines.push('export const pageConfigsSerialized = [');
|
|
35
32
|
pageConfigs.forEach((pageConfig) => {
|
|
36
33
|
const { pageId, routeFilesystem, isErrorPage } = pageConfig;
|
|
37
34
|
const virtualFileIdPageConfigValuesAll = (0, virtualFilePageConfigValuesAll_js_1.getVirtualFileIdPageConfigValuesAll)(pageId, isForClientSide);
|
|
@@ -39,35 +36,13 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
|
|
|
39
36
|
lines.push(` pageId: ${JSON.stringify(pageId)},`);
|
|
40
37
|
lines.push(` isErrorPage: ${JSON.stringify(isErrorPage)},`);
|
|
41
38
|
lines.push(` routeFilesystem: ${JSON.stringify(routeFilesystem)},`);
|
|
42
|
-
lines.push(` loadConfigValuesAll:
|
|
39
|
+
lines.push(` loadConfigValuesAll: () => import(${JSON.stringify(virtualFileIdPageConfigValuesAll)}),`);
|
|
40
|
+
// Serialized config values
|
|
43
41
|
lines.push(` configValuesSerialized: {`);
|
|
44
|
-
|
|
45
|
-
const { value, configEnv } = configValuesComputed;
|
|
46
|
-
if (!(0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: true }))
|
|
47
|
-
return;
|
|
48
|
-
if (pageConfig.configValueSources[configName])
|
|
49
|
-
return;
|
|
50
|
-
const configValue = pageConfig.configValues[configName];
|
|
51
|
-
(0, utils_js_1.assert)(configValue);
|
|
52
|
-
const { definedAt } = configValue;
|
|
53
|
-
const valueSerialized = getConfigValueSerialized(value, configName, definedAt);
|
|
54
|
-
(0, serializeConfigValue_js_1.serializeConfigValue)(lines, configName, { definedAt, valueSerialized });
|
|
55
|
-
});
|
|
56
|
-
Object.entries(pageConfig.configValueSources).forEach(([configName]) => {
|
|
57
|
-
const configValue = pageConfig.configValues[configName];
|
|
58
|
-
if (configValue) {
|
|
59
|
-
const configEnv = (0, helpers_js_1.getConfigEnv)(pageConfig.configValueSources, configName);
|
|
60
|
-
(0, utils_js_1.assert)(configEnv, configName);
|
|
61
|
-
const isEnvMatch = (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: true });
|
|
62
|
-
if (!isEnvMatch)
|
|
63
|
-
return;
|
|
64
|
-
const { value, definedAt } = configValue;
|
|
65
|
-
const valueSerialized = getConfigValueSerialized(value, configName, definedAt);
|
|
66
|
-
(0, serializeConfigValue_js_1.serializeConfigValue)(lines, configName, { definedAt, valueSerialized });
|
|
67
|
-
}
|
|
68
|
-
});
|
|
42
|
+
lines.push((0, getConfigValuesSerialized_js_1.getConfigValuesSerialized)(pageConfig, (configEnv) => (0, isRuntimeEnvMatch_js_1.isRuntimeEnvMatch)(configEnv, { isForClientSide, isClientRouting, isEager: true })));
|
|
69
43
|
lines.push(` },`);
|
|
70
|
-
|
|
44
|
+
// Imported config values
|
|
45
|
+
const whitespace = ' ';
|
|
71
46
|
lines.push(`${whitespace}configValuesImported: [`);
|
|
72
47
|
Object.entries(pageConfig.configValueSources).forEach(([configName, sources]) => {
|
|
73
48
|
const configValue = pageConfig.configValues[configName];
|
|
@@ -75,21 +50,18 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
|
|
|
75
50
|
return;
|
|
76
51
|
const configValueSource = sources[0];
|
|
77
52
|
(0, utils_js_1.assert)(configValueSource);
|
|
78
|
-
if (configValueSource.configEnv
|
|
53
|
+
if (!configValueSource.configEnv.eager)
|
|
79
54
|
return;
|
|
80
55
|
lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
81
56
|
});
|
|
82
57
|
lines.push(`${whitespace}],`);
|
|
83
|
-
// pageConfig end
|
|
84
58
|
lines.push(` },`);
|
|
85
59
|
});
|
|
86
|
-
lines.push('];');
|
|
87
60
|
const code = lines.join('\n');
|
|
88
61
|
return code;
|
|
89
62
|
}
|
|
90
63
|
function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isDev, importStatements, varCounterContainer) {
|
|
91
64
|
const lines = [];
|
|
92
|
-
lines.push('export const pageConfigGlobalSerialized = {');
|
|
93
65
|
/* Nothing (yet)
|
|
94
66
|
lines.push(` configValuesSerialized: {`)
|
|
95
67
|
lines.push(` },`)
|
|
@@ -114,36 +86,6 @@ function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, is
|
|
|
114
86
|
lines.push(...(0, serializeConfigValue_js_1.serializeConfigValueImported)(configValueSource, configName, whitespace, varCounterContainer, importStatements));
|
|
115
87
|
});
|
|
116
88
|
lines.push(` ],`);
|
|
117
|
-
lines.push('};');
|
|
118
89
|
const code = lines.join('\n');
|
|
119
90
|
return code;
|
|
120
91
|
}
|
|
121
|
-
function getConfigValueSerialized(value, configName, definedAt) {
|
|
122
|
-
const valueName = `config${(0, utils_js_1.getPropAccessNotation)(configName)}`;
|
|
123
|
-
let configValueSerialized;
|
|
124
|
-
try {
|
|
125
|
-
configValueSerialized = (0, stringify_1.stringify)(value, { valueName, forbidReactElements: true });
|
|
126
|
-
}
|
|
127
|
-
catch (err) {
|
|
128
|
-
let serializationErrMsg = '';
|
|
129
|
-
if ((0, stringify_1.isJsonSerializerError)(err)) {
|
|
130
|
-
serializationErrMsg = err.messageCore;
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
// When a property getter throws an error
|
|
134
|
-
console.error('Serialization error:');
|
|
135
|
-
console.error(err);
|
|
136
|
-
serializationErrMsg = 'see serialization error printed above';
|
|
137
|
-
}
|
|
138
|
-
const configValueFilePathToShowToUser = (0, helpers_js_2.getConfigValueFilePathToShowToUser)({ definedAt });
|
|
139
|
-
(0, utils_js_1.assert)(configValueFilePathToShowToUser);
|
|
140
|
-
(0, utils_js_1.assertUsage)(false, [
|
|
141
|
-
`The value of the config ${picocolors_1.default.cyan(configName)} cannot be defined inside the file ${configValueFilePathToShowToUser}:`,
|
|
142
|
-
`its value must be defined in an another file and then imported by ${configValueFilePathToShowToUser}. (Because its value isn't serializable: ${serializationErrMsg}.)`,
|
|
143
|
-
`Only serializable config values can be defined inside +config.h.js files, see https://vike.dev/header-file.`
|
|
144
|
-
].join(' '));
|
|
145
|
-
}
|
|
146
|
-
configValueSerialized = JSON.stringify(configValueSerialized);
|
|
147
|
-
return configValueSerialized;
|
|
148
|
-
}
|
|
149
|
-
exports.getConfigValueSerialized = getConfigValueSerialized;
|
|
@@ -2,17 +2,20 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isRuntimeEnvMatch = void 0;
|
|
4
4
|
function isRuntimeEnvMatch(configEnv, runtime) {
|
|
5
|
-
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
if (configEnv === (isForClientSide ? 'server-only' : 'client-only'))
|
|
9
|
-
return false;
|
|
10
|
-
if (configEnv === '_routing-eager' || configEnv === '_routing-lazy') {
|
|
11
|
-
if (isForClientSide && !isClientRouting)
|
|
5
|
+
// Runtime
|
|
6
|
+
if (!runtime.isForClientSide) {
|
|
7
|
+
if (!configEnv.server)
|
|
12
8
|
return false;
|
|
13
|
-
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
if (!configEnv.client)
|
|
12
|
+
return false;
|
|
13
|
+
if (configEnv.client === 'if-client-routing' && !runtime.isClientRouting)
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
|
+
// Eager
|
|
17
|
+
if (runtime.isEager !== !!configEnv.eager)
|
|
18
|
+
return false;
|
|
16
19
|
return true;
|
|
17
20
|
}
|
|
18
21
|
exports.isRuntimeEnvMatch = isRuntimeEnvMatch;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getConfigValueSourcesNotOverriden = void 0;
|
|
4
4
|
const utils_js_1 = require("../../shared/utils.js");
|
|
5
5
|
(0, utils_js_1.assertIsNotBrowser)();
|
|
6
|
-
function
|
|
6
|
+
function getConfigValueSourcesNotOverriden(pageConfig) {
|
|
7
7
|
const configValueSourcesRelevant = Object.entries(pageConfig.configValueSources).map(([configName, sources]) => {
|
|
8
8
|
const configValueSource = sources[0];
|
|
9
9
|
(0, utils_js_1.assert)(configValueSource);
|
|
@@ -11,4 +11,4 @@ function getConfigValueSourcesRelevant(pageConfig) {
|
|
|
11
11
|
});
|
|
12
12
|
return configValueSourcesRelevant;
|
|
13
13
|
}
|
|
14
|
-
exports.
|
|
14
|
+
exports.getConfigValueSourcesNotOverriden = getConfigValueSourcesNotOverriden;
|
|
@@ -38,3 +38,5 @@ __exportStar(require("../../utils/removeEmptyLines.js"), exports);
|
|
|
38
38
|
__exportStar(require("../../utils/findUserPackageJsonPath.js"), exports);
|
|
39
39
|
__exportStar(require("../../utils/getPropAccessNotation.js"), exports);
|
|
40
40
|
__exportStar(require("../../utils/mergeCumulativeValues.js"), exports);
|
|
41
|
+
__exportStar(require("../../utils/deepEqual.js"), exports);
|
|
42
|
+
__exportStar(require("../../utils/assertKeys.js"), exports);
|
|
@@ -99,19 +99,25 @@ async function runPrerender(options, manuallyTriggered) {
|
|
|
99
99
|
const doNotPrerenderList = [];
|
|
100
100
|
const vikeConfig = await (0, getVikeConfig_js_1.getVikeConfig)(viteConfig, false);
|
|
101
101
|
await collectDoNoPrerenderList(renderContext, vikeConfig.pageConfigs, doNotPrerenderList, concurrencyLimit);
|
|
102
|
-
await callOnBeforePrerenderStartHooks(prerenderContext, renderContext, concurrencyLimit);
|
|
102
|
+
await callOnBeforePrerenderStartHooks(prerenderContext, renderContext, concurrencyLimit, doNotPrerenderList);
|
|
103
103
|
await handlePagesWithStaticRoutes(prerenderContext, renderContext, doNotPrerenderList, concurrencyLimit);
|
|
104
104
|
await callOnPrerenderStartHook(prerenderContext, renderContext);
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
105
|
+
const prerenderedPageContexts = {};
|
|
106
|
+
let prerenderedCount = 0;
|
|
107
|
+
const onComplete = async (htmlFile) => {
|
|
108
|
+
prerenderedCount++;
|
|
109
|
+
if (htmlFile.pageId) {
|
|
110
|
+
prerenderedPageContexts[htmlFile.pageId] = htmlFile.pageContext;
|
|
111
|
+
}
|
|
112
|
+
await writeFiles(htmlFile, root, outDirClient, options.onPagePrerender, logLevel);
|
|
113
|
+
};
|
|
114
|
+
await routeAndPrerender(prerenderContext, concurrencyLimit, onComplete);
|
|
115
|
+
warnContradictoryNoPrerenderList(prerenderedPageContexts, doNotPrerenderList);
|
|
116
|
+
await prerender404(prerenderedPageContexts, renderContext, prerenderContext, onComplete);
|
|
110
117
|
if (logLevel === 'info') {
|
|
111
|
-
console.log(`${picocolors_1.default.green(`✓`)} ${
|
|
118
|
+
console.log(`${picocolors_1.default.green(`✓`)} ${prerenderedCount} HTML documents pre-rendered.`);
|
|
112
119
|
}
|
|
113
|
-
|
|
114
|
-
warnMissingPages(prerenderPageIds, doNotPrerenderList, renderContext, partial);
|
|
120
|
+
warnMissingPages(prerenderedPageContexts, doNotPrerenderList, renderContext, partial);
|
|
115
121
|
}
|
|
116
122
|
async function collectDoNoPrerenderList(renderContext, pageConfigs, doNotPrerenderList, concurrencyLimit) {
|
|
117
123
|
// V1 design
|
|
@@ -173,7 +179,7 @@ function assertExportNames(pageFile) {
|
|
|
173
179
|
const { exportNames, fileType } = pageFile;
|
|
174
180
|
(0, utils_js_1.assert)(exportNames || fileType === '.page.route' || fileType === '.css', pageFile.filePath);
|
|
175
181
|
}
|
|
176
|
-
async function callOnBeforePrerenderStartHooks(prerenderContext, renderContext, concurrencyLimit) {
|
|
182
|
+
async function callOnBeforePrerenderStartHooks(prerenderContext, renderContext, concurrencyLimit, doNotPrerenderList) {
|
|
177
183
|
const onBeforePrerenderStartHooks = [];
|
|
178
184
|
// V1 design
|
|
179
185
|
await Promise.all(renderContext.pageConfigs.map((pageConfig) => concurrencyLimit(async () => {
|
|
@@ -189,7 +195,8 @@ async function callOnBeforePrerenderStartHooks(prerenderContext, renderContext,
|
|
|
189
195
|
onBeforePrerenderStartHooks.push({
|
|
190
196
|
hookFn,
|
|
191
197
|
hookName: 'onBeforePrerenderStart',
|
|
192
|
-
hookFilePath
|
|
198
|
+
hookFilePath,
|
|
199
|
+
pageId: pageConfig.pageId
|
|
193
200
|
});
|
|
194
201
|
})));
|
|
195
202
|
// 0.4 design
|
|
@@ -212,10 +219,14 @@ async function callOnBeforePrerenderStartHooks(prerenderContext, renderContext,
|
|
|
212
219
|
onBeforePrerenderStartHooks.push({
|
|
213
220
|
hookFn,
|
|
214
221
|
hookName: 'prerender',
|
|
215
|
-
hookFilePath
|
|
222
|
+
hookFilePath,
|
|
223
|
+
pageId: p.pageId
|
|
216
224
|
});
|
|
217
225
|
})));
|
|
218
|
-
await Promise.all(onBeforePrerenderStartHooks.map(({ hookFn, hookName, hookFilePath }) => concurrencyLimit(async () => {
|
|
226
|
+
await Promise.all(onBeforePrerenderStartHooks.map(({ hookFn, hookName, hookFilePath, pageId }) => concurrencyLimit(async () => {
|
|
227
|
+
if (doNotPrerenderList.find((p) => p.pageId === pageId)) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
219
230
|
const prerenderResult = await hookFn();
|
|
220
231
|
const result = normalizeOnPrerenderHookResult(prerenderResult, hookFilePath, hookName);
|
|
221
232
|
result.forEach(({ url, pageContext }) => {
|
|
@@ -434,7 +445,7 @@ async function callOnPrerenderStartHook(prerenderContext, renderContext) {
|
|
|
434
445
|
(0, addUrlComputedProps_js_1.addUrlComputedProps)(pageContext);
|
|
435
446
|
});
|
|
436
447
|
}
|
|
437
|
-
async function routeAndPrerender(prerenderContext,
|
|
448
|
+
async function routeAndPrerender(prerenderContext, concurrencyLimit, onComplete) {
|
|
438
449
|
const globalContext = (0, globalContext_js_1.getGlobalContext)();
|
|
439
450
|
(0, utils_js_1.assert)(globalContext.isPrerendering);
|
|
440
451
|
// Route all URLs
|
|
@@ -494,7 +505,7 @@ async function routeAndPrerender(prerenderContext, htmlFiles, prerenderPageIds,
|
|
|
494
505
|
throw err;
|
|
495
506
|
}
|
|
496
507
|
const { documentHtml, pageContextSerialized } = res;
|
|
497
|
-
|
|
508
|
+
await onComplete({
|
|
498
509
|
urlOriginal,
|
|
499
510
|
pageContext,
|
|
500
511
|
htmlString: documentHtml,
|
|
@@ -502,11 +513,10 @@ async function routeAndPrerender(prerenderContext, htmlFiles, prerenderPageIds,
|
|
|
502
513
|
doNotCreateExtraDirectory: prerenderContext._noExtraDir,
|
|
503
514
|
pageId
|
|
504
515
|
});
|
|
505
|
-
prerenderPageIds[pageId] = pageContext;
|
|
506
516
|
})));
|
|
507
517
|
}
|
|
508
|
-
function warnContradictoryNoPrerenderList(
|
|
509
|
-
Object.entries(
|
|
518
|
+
function warnContradictoryNoPrerenderList(prerenderedPageContexts, doNotPrerenderList) {
|
|
519
|
+
Object.entries(prerenderedPageContexts).forEach(([pageId, pageContext]) => {
|
|
510
520
|
const doNotPrerenderListEntry = doNotPrerenderList.find((p) => p.pageId === pageId);
|
|
511
521
|
const { urlOriginal, _providedByHook: providedByHook } = pageContext;
|
|
512
522
|
{
|
|
@@ -518,7 +528,7 @@ function warnContradictoryNoPrerenderList(prerenderPageIds, doNotPrerenderList)
|
|
|
518
528
|
(0, utils_js_1.assertWarning)(false, `The ${providedByHook.hookName}() hook defined by ${providedByHook.hookFilePath} returns the URL ${picocolors_1.default.cyan(urlOriginal)}, while ${setByConfigFile} sets the config ${picocolors_1.default.cyan(setByConfigName)} to ${picocolors_1.default.cyan(String(setByConfigValue))}. This is contradictory: either don't set the config ${picocolors_1.default.cyan(setByConfigName)} to ${picocolors_1.default.cyan(String(setByConfigValue))} or remove the URL ${picocolors_1.default.cyan(urlOriginal)} from the list of URLs to be pre-rendered.`, { onlyOnce: true });
|
|
519
529
|
});
|
|
520
530
|
}
|
|
521
|
-
function warnMissingPages(
|
|
531
|
+
function warnMissingPages(prerenderedPageContexts, doNotPrerenderList, renderContext, partial) {
|
|
522
532
|
const isV1 = renderContext.pageConfigs.length > 0;
|
|
523
533
|
const hookName = isV1 ? 'onBeforePrerenderStart' : 'prerender';
|
|
524
534
|
/* TODO/after-v1-design-release: document setting `prerender: false` as an alternative to using prerender.partial (both in the warnings and the docs)
|
|
@@ -526,7 +536,7 @@ function warnMissingPages(prerenderPageIds, doNotPrerenderList, renderContext, p
|
|
|
526
536
|
const msgAddendum = `Explicitly opt-out by setting the config ${optOutName} to ${isV1 ? 'false' : 'true'} or use the option prerender.partial`
|
|
527
537
|
*/
|
|
528
538
|
renderContext.allPageIds
|
|
529
|
-
.filter((pageId) => !
|
|
539
|
+
.filter((pageId) => !prerenderedPageContexts[pageId])
|
|
530
540
|
.filter((pageId) => !doNotPrerenderList.find((p) => p.pageId === pageId))
|
|
531
541
|
.filter((pageId) => !(0, error_page_js_1.isErrorPage)(pageId, renderContext.pageConfigs))
|
|
532
542
|
.forEach((pageId) => {
|
|
@@ -534,8 +544,8 @@ function warnMissingPages(prerenderPageIds, doNotPrerenderList, renderContext, p
|
|
|
534
544
|
(0, utils_js_1.assertWarning)(partial, `Cannot pre-render page ${pageAt} because it has a non-static route, while no ${hookName}() hook returned any URL matching the page's route. You need to use a ${hookName}() hook (https://vike.dev/${hookName}) providing a list of URLs for ${pageAt} that should be pre-rendered. If you don't want to pre-render ${pageAt} then use the option prerender.partial (https://vike.dev/prerender-config#partial) to suppress this warning.`, { onlyOnce: true });
|
|
535
545
|
});
|
|
536
546
|
}
|
|
537
|
-
async function prerender404(
|
|
538
|
-
if (!
|
|
547
|
+
async function prerender404(prerenderedPageContexts, renderContext, prerenderContext, onComplete) {
|
|
548
|
+
if (!Object.values(prerenderedPageContexts).find(({ urlOriginal }) => urlOriginal === '/404')) {
|
|
539
549
|
let result;
|
|
540
550
|
try {
|
|
541
551
|
result = await (0, renderPageAlreadyRouted_js_1.prerender404Page)(renderContext, prerenderContext.pageContextInit);
|
|
@@ -547,7 +557,7 @@ async function prerender404(htmlFiles, renderContext, prerenderContext) {
|
|
|
547
557
|
if (result) {
|
|
548
558
|
const urlOriginal = '/404';
|
|
549
559
|
const { documentHtml, pageContext } = result;
|
|
550
|
-
|
|
560
|
+
await onComplete({
|
|
551
561
|
urlOriginal,
|
|
552
562
|
pageContext,
|
|
553
563
|
htmlString: documentHtml,
|
|
@@ -558,59 +568,57 @@ async function prerender404(htmlFiles, renderContext, prerenderContext) {
|
|
|
558
568
|
}
|
|
559
569
|
}
|
|
560
570
|
}
|
|
561
|
-
async function
|
|
571
|
+
async function writeFiles({ urlOriginal, pageContext, htmlString, pageContextSerialized, doNotCreateExtraDirectory }, root, outDirClient, onPagePrerender, logLevel) {
|
|
562
572
|
(0, utils_js_1.assert)(urlOriginal.startsWith('/'));
|
|
563
573
|
const writeJobs = [
|
|
564
|
-
write(urlOriginal, pageContext, '.html', htmlString, root, outDirClient, doNotCreateExtraDirectory,
|
|
574
|
+
write(urlOriginal, pageContext, '.html', htmlString, root, outDirClient, doNotCreateExtraDirectory, onPagePrerender, logLevel)
|
|
565
575
|
];
|
|
566
576
|
if (pageContextSerialized !== null) {
|
|
567
|
-
writeJobs.push(write(urlOriginal, pageContext, '.pageContext.json', pageContextSerialized, root, outDirClient, doNotCreateExtraDirectory,
|
|
577
|
+
writeJobs.push(write(urlOriginal, pageContext, '.pageContext.json', pageContextSerialized, root, outDirClient, doNotCreateExtraDirectory, onPagePrerender, logLevel));
|
|
568
578
|
}
|
|
569
579
|
await Promise.all(writeJobs);
|
|
570
580
|
}
|
|
571
|
-
function write(urlOriginal, pageContext, fileExtension, fileContent, root, outDirClient, doNotCreateExtraDirectory,
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
fileContent
|
|
594
|
-
}
|
|
595
|
-
});
|
|
596
|
-
await onPagePrerender(prerenderPageContext);
|
|
597
|
-
}
|
|
598
|
-
else {
|
|
599
|
-
const { promises } = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
600
|
-
const { writeFile, mkdir } = promises;
|
|
601
|
-
await mkdir(path_1.default.posix.dirname(filePath), { recursive: true });
|
|
602
|
-
await writeFile(filePath, fileContent);
|
|
603
|
-
if (logLevel === 'info') {
|
|
604
|
-
(0, utils_js_1.assertPosixPath)(root);
|
|
605
|
-
(0, utils_js_1.assertPosixPath)(outDirClient);
|
|
606
|
-
let outDirClientRelative = path_1.default.posix.relative(root, outDirClient);
|
|
607
|
-
if (!outDirClientRelative.endsWith('/')) {
|
|
608
|
-
outDirClientRelative = outDirClientRelative + '/';
|
|
609
|
-
}
|
|
610
|
-
console.log(`${picocolors_1.default.dim(outDirClientRelative)}${picocolors_1.default.blue(filePathRelative)}`);
|
|
581
|
+
async function write(urlOriginal, pageContext, fileExtension, fileContent, root, outDirClient, doNotCreateExtraDirectory, onPagePrerender, logLevel) {
|
|
582
|
+
let fileUrl;
|
|
583
|
+
if (fileExtension === '.html') {
|
|
584
|
+
fileUrl = (0, utils_js_1.urlToFile)(urlOriginal, '.html', doNotCreateExtraDirectory);
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
fileUrl = (0, getPageContextRequestUrl_js_1.getPageContextRequestUrl)(urlOriginal);
|
|
588
|
+
}
|
|
589
|
+
(0, utils_js_1.assertPosixPath)(fileUrl);
|
|
590
|
+
(0, utils_js_1.assert)(fileUrl.startsWith('/'));
|
|
591
|
+
const filePathRelative = fileUrl.slice(1);
|
|
592
|
+
(0, utils_js_1.assert)(!filePathRelative.startsWith('/'));
|
|
593
|
+
(0, utils_js_1.assertPosixPath)(outDirClient);
|
|
594
|
+
(0, utils_js_1.assertPosixPath)(filePathRelative);
|
|
595
|
+
const filePath = path_1.default.posix.join(outDirClient, filePathRelative);
|
|
596
|
+
if (onPagePrerender) {
|
|
597
|
+
const prerenderPageContext = {};
|
|
598
|
+
(0, utils_js_1.objectAssign)(prerenderPageContext, pageContext);
|
|
599
|
+
(0, utils_js_1.objectAssign)(prerenderPageContext, {
|
|
600
|
+
_prerenderResult: {
|
|
601
|
+
filePath,
|
|
602
|
+
fileContent
|
|
611
603
|
}
|
|
604
|
+
});
|
|
605
|
+
await onPagePrerender(prerenderPageContext);
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
const { promises } = await Promise.resolve().then(() => __importStar(require('fs')));
|
|
609
|
+
const { writeFile, mkdir } = promises;
|
|
610
|
+
await mkdir(path_1.default.posix.dirname(filePath), { recursive: true });
|
|
611
|
+
await writeFile(filePath, fileContent);
|
|
612
|
+
if (logLevel === 'info') {
|
|
613
|
+
(0, utils_js_1.assertPosixPath)(root);
|
|
614
|
+
(0, utils_js_1.assertPosixPath)(outDirClient);
|
|
615
|
+
let outDirClientRelative = path_1.default.posix.relative(root, outDirClient);
|
|
616
|
+
if (!outDirClientRelative.endsWith('/')) {
|
|
617
|
+
outDirClientRelative = outDirClientRelative + '/';
|
|
618
|
+
}
|
|
619
|
+
console.log(`${picocolors_1.default.dim(outDirClientRelative)}${picocolors_1.default.blue(filePathRelative)}`);
|
|
612
620
|
}
|
|
613
|
-
}
|
|
621
|
+
}
|
|
614
622
|
}
|
|
615
623
|
function normalizeOnPrerenderHookResult(prerenderResult, prerenderHookFile, hookName) {
|
|
616
624
|
if (Array.isArray(prerenderResult)) {
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.injectAssets__public = void 0;
|
|
4
4
|
const utils_js_1 = require("../../utils.js");
|
|
5
5
|
const injectAssets_js_1 = require("../injectAssets.js");
|
|
6
|
-
// TODO: remove
|
|
6
|
+
// TODO/v1-release: remove
|
|
7
7
|
async function injectAssets__public(htmlString, pageContext) {
|
|
8
8
|
(0, utils_js_1.assertWarning)(false, '`_injectAssets()` is deprecated and will be removed.', { onlyOnce: true, showStackTrace: true });
|
|
9
9
|
(0, utils_js_1.assertUsage)(typeof htmlString === 'string', '[injectAssets(htmlString, pageContext)]: Argument `htmlString` should be a string.', { showStackTrace: true });
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.createPageRenderer = exports._injectAssets = exports.stampPipe = exports.pipeStream = exports.pipeNodeStream = exports.pipeWebStream = exports.dangerouslySkipEscape = exports.escapeInject = exports.renderPage = void 0;
|
|
3
|
+
exports.createPageRenderer = exports._injectAssets = exports.version = exports.stampPipe = exports.pipeStream = exports.pipeNodeStream = exports.pipeWebStream = exports.dangerouslySkipEscape = exports.escapeInject = exports.renderPage = void 0;
|
|
4
4
|
var renderPage_js_1 = require("./renderPage.js");
|
|
5
5
|
Object.defineProperty(exports, "renderPage", { enumerable: true, get: function () { return renderPage_js_1.renderPage; } });
|
|
6
6
|
var renderHtml_js_1 = require("./html/renderHtml.js");
|
|
@@ -11,6 +11,8 @@ Object.defineProperty(exports, "pipeWebStream", { enumerable: true, get: functio
|
|
|
11
11
|
Object.defineProperty(exports, "pipeNodeStream", { enumerable: true, get: function () { return stream_js_1.pipeNodeStream; } });
|
|
12
12
|
Object.defineProperty(exports, "pipeStream", { enumerable: true, get: function () { return stream_js_1.pipeStream; } });
|
|
13
13
|
Object.defineProperty(exports, "stampPipe", { enumerable: true, get: function () { return stream_js_1.stampPipe; } });
|
|
14
|
+
var utils_js_1 = require("./utils.js");
|
|
15
|
+
Object.defineProperty(exports, "version", { enumerable: true, get: function () { return utils_js_1.PROJECT_VERSION; } });
|
|
14
16
|
// TODO/v1-release: remove
|
|
15
17
|
var injectAssets__public_js_1 = require("./html/injectAssets/injectAssets__public.js");
|
|
16
18
|
Object.defineProperty(exports, "_injectAssets", { enumerable: true, get: function () { return injectAssets__public_js_1.injectAssets__public; } });
|
|
@@ -31,8 +31,8 @@ function analyzePage(pageFilesAll, pageConfig, pageId) {
|
|
|
31
31
|
if (configElement.importPath) {
|
|
32
32
|
const { env } = configElement
|
|
33
33
|
assert(env)
|
|
34
|
-
const onlyAssets = env ===
|
|
35
|
-
const eagerlyImported = env === '
|
|
34
|
+
const onlyAssets = env === { server: true }
|
|
35
|
+
const eagerlyImported = env === { server: true, client: 'if-client-routing', eager: true }
|
|
36
36
|
if (onlyAssets || eagerlyImported) {
|
|
37
37
|
clientDependencies.push({
|
|
38
38
|
id: configElement.importPath,
|
package/dist/cjs/node/runtime/renderPage/createHttpResponseObject/assertNoInfiniteHttpRedirect.js
CHANGED
|
@@ -9,21 +9,21 @@ const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
|
9
9
|
const globalObject = (0, utils_js_1.getGlobalObject)('assertNoInfiniteHttpRedirect.ts', {
|
|
10
10
|
redirectGraph: {}
|
|
11
11
|
});
|
|
12
|
-
function assertNoInfiniteHttpRedirect(
|
|
13
|
-
if (
|
|
14
|
-
// We assume that
|
|
15
|
-
// - There isn't a reliable way to check whether the redirect points to an external origin or the same origin
|
|
12
|
+
function assertNoInfiniteHttpRedirect(urlRedirectTarget, urlLogical) {
|
|
13
|
+
if (urlRedirectTarget.startsWith('http')) {
|
|
14
|
+
// We assume that urlRedirectTarget points to an origin that is external (not the same origin), and we can therefore assume that the app doesn't define an infinite loop (in itself).
|
|
15
|
+
// - There isn't a reliable way to check whether the redirect points to an external origin or the same origin. For same origins, we assume/hope the user to pass the URL without origin.
|
|
16
16
|
// ```js
|
|
17
|
-
// //
|
|
17
|
+
// // For same-origin, the user usually/hopefully passes a URL without origin
|
|
18
18
|
// renderPage({ urlOriginal: '/some/pathname' })
|
|
19
19
|
// ```
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
|
-
(0, utils_js_1.assert)(
|
|
23
|
-
(0, utils_js_1.assert)(
|
|
22
|
+
(0, utils_js_1.assert)(urlRedirectTarget.startsWith('/'));
|
|
23
|
+
(0, utils_js_1.assert)(urlLogical.startsWith('/'));
|
|
24
24
|
const graph = copy(globalObject.redirectGraph);
|
|
25
|
-
graph[
|
|
26
|
-
graph[
|
|
25
|
+
graph[urlRedirectTarget] ?? (graph[urlRedirectTarget] = new Set());
|
|
26
|
+
graph[urlRedirectTarget].add(urlLogical);
|
|
27
27
|
validate(graph);
|
|
28
28
|
globalObject.redirectGraph = graph;
|
|
29
29
|
}
|
|
@@ -32,6 +32,9 @@ function copy(G) {
|
|
|
32
32
|
return Object.fromEntries(Object.entries(G).map(([key, val]) => [key, new Set(val)]));
|
|
33
33
|
}
|
|
34
34
|
// Adapted from: https://stackoverflow.com/questions/60904464/detect-cycle-in-directed-graph/60907076#60907076
|
|
35
|
+
function validate(G) {
|
|
36
|
+
Object.keys(G).forEach((n) => check(G, n, []));
|
|
37
|
+
}
|
|
35
38
|
function check(G, n, path) {
|
|
36
39
|
if (path.includes(n)) {
|
|
37
40
|
const cycle = path.slice(path.indexOf(n)).concat(n);
|
|
@@ -39,6 +42,3 @@ function check(G, n, path) {
|
|
|
39
42
|
}
|
|
40
43
|
G[n]?.forEach((node) => check(G, node, [...path, n]));
|
|
41
44
|
}
|
|
42
|
-
function validate(G) {
|
|
43
|
-
Object.keys(G).forEach((n) => check(G, n, []));
|
|
44
|
-
}
|
|
@@ -35,9 +35,9 @@ async function createHttpResponsePageContextJson(pageContextSerialized) {
|
|
|
35
35
|
}
|
|
36
36
|
exports.createHttpResponsePageContextJson = createHttpResponsePageContextJson;
|
|
37
37
|
function createHttpResponseObjectRedirect({ url, statusCode },
|
|
38
|
-
// The URL
|
|
39
|
-
|
|
40
|
-
(0, assertNoInfiniteHttpRedirect_js_1.assertNoInfiniteHttpRedirect)(url,
|
|
38
|
+
// The URL we assume the redirect to be logically based on
|
|
39
|
+
urlLogical) {
|
|
40
|
+
(0, assertNoInfiniteHttpRedirect_js_1.assertNoInfiniteHttpRedirect)(url, urlLogical);
|
|
41
41
|
(0, utils_js_1.assert)(url);
|
|
42
42
|
(0, utils_js_1.assert)(statusCode);
|
|
43
43
|
(0, utils_js_1.assert)(300 <= statusCode && statusCode <= 399);
|
|
@@ -14,8 +14,7 @@ const assertHookReturnedObject_js_1 = require("../../../shared/assertHookReturne
|
|
|
14
14
|
const loggerRuntime_js_1 = require("./loggerRuntime.js");
|
|
15
15
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
16
16
|
async function executeOnRenderHtmlHook(pageContext) {
|
|
17
|
-
const
|
|
18
|
-
const { renderHook, hookFn } = hookFound;
|
|
17
|
+
const { renderHook, hookFn } = getRenderHook(pageContext);
|
|
19
18
|
(0, utils_js_1.objectAssign)(pageContext, { _renderHook: renderHook });
|
|
20
19
|
(0, preparePageContextForUserConsumptionServerSide_js_1.preparePageContextForUserConsumptionServerSide)(pageContext);
|
|
21
20
|
const hookReturnValue = await (0, utils_js_1.executeHook)(() => hookFn(pageContext), renderHook.hookName, renderHook.hookFilePath);
|