vike 0.4.171 → 0.4.172-commit-ea2b76c
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/devConfig/index.js +2 -1
- package/dist/cjs/node/plugin/plugins/envVars.js +2 -1
- package/dist/cjs/node/plugin/plugins/extractAssetsPlugin.js +1 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/{generateEagerImport.js → addImportStatement.js} +8 -10
- package/dist/cjs/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +0 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js +3 -3
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +17 -6
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +31 -75
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +4 -43
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +9 -50
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/isRuntimeEnvMatch.js +6 -0
- package/dist/cjs/node/plugin/shared/addSsrMiddleware.js +17 -2
- package/dist/cjs/node/prerender/runPrerender.js +35 -15
- package/dist/cjs/node/prerender/utils.js +1 -0
- package/dist/cjs/node/runtime/html/injectAssets/getHtmlTags.js +3 -3
- package/dist/cjs/node/runtime/html/injectAssets/getViteDevScripts.js +2 -1
- package/dist/cjs/node/runtime/html/injectAssets/mergeScriptTags.js +2 -8
- package/dist/cjs/node/runtime/html/renderHtml.js +19 -20
- package/dist/cjs/node/runtime/html/stream.js +9 -9
- 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/executeOnBeforeRenderAndDataHooks.js +2 -2
- package/dist/cjs/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -8
- package/dist/cjs/node/runtime/renderPage/getHttpResponseBody.js +2 -2
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +4 -5
- package/dist/cjs/node/runtime/renderPage/logErrorHint.js +91 -282
- package/dist/cjs/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.js +2 -2
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +30 -10
- package/dist/cjs/node/runtime/renderPage.js +24 -17
- package/dist/cjs/node/runtime/utils.js +2 -0
- package/dist/cjs/node/shared/assertV1Design.js +3 -4
- package/dist/cjs/shared/getPageContext.js +5 -0
- package/dist/cjs/shared/{addUrlComputedProps.js → getPageContextUrlComputed.js} +52 -42
- package/dist/cjs/shared/getPageFiles/analyzeClientSide.js +2 -2
- package/dist/cjs/shared/getPageFiles/getExports.js +49 -1
- package/dist/cjs/shared/getPageFiles/parseGlobResults.js +15 -8
- package/dist/cjs/shared/hooks/executeHook.js +22 -3
- 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 +0 -18
- 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/executeGuardHook.js +1 -1
- package/dist/cjs/shared/route/executeOnBeforeRouteHook.js +1 -1
- 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/sortPageContext.js +4 -8
- package/dist/cjs/shared/utils.js +2 -0
- package/dist/cjs/utils/assert.js +1 -1
- package/dist/cjs/utils/assertNodeVersion.js +1 -1
- package/dist/cjs/utils/changeEnumerable.js +9 -0
- package/dist/cjs/utils/escapeHtml.js +14 -0
- package/dist/cjs/utils/getPropAccessNotation.js +1 -4
- package/dist/cjs/utils/hasProp.js +5 -7
- package/dist/cjs/utils/normalizeHeaders.js +13 -0
- package/dist/cjs/utils/objectAssign.js +1 -1
- package/dist/cjs/utils/objectDefineProperty.js +8 -0
- package/dist/cjs/utils/objectKeys.js +8 -4
- 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 +16 -12
- package/dist/esm/client/client-routing-runtime/installClientRouter.js +18 -10
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +3 -3
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +4 -4
- package/dist/esm/client/server-routing-runtime/utils.d.ts +1 -0
- package/dist/esm/client/server-routing-runtime/utils.js +1 -0
- package/dist/esm/client/shared/executeOnRenderClientHook.js +1 -1
- package/dist/esm/client/shared/getPageContextProxyForUser.d.ts +3 -2
- package/dist/esm/client/shared/getPageContextProxyForUser.js +35 -48
- 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/devConfig/index.js +2 -1
- package/dist/esm/node/plugin/plugins/envVars.js +2 -1
- package/dist/esm/node/plugin/plugins/extractAssetsPlugin.js +1 -1
- package/dist/esm/node/plugin/plugins/importUserCode/addImportStatement.d.ts +14 -0
- package/dist/esm/node/plugin/plugins/importUserCode/{generateEagerImport.js → addImportStatement.js} +7 -9
- package/dist/esm/node/plugin/plugins/importUserCode/getVirtualFileImportUserCode.js +0 -1
- 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/crawlPlusFiles.js +18 -7
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/loadFileAtConfigTime.js +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +31 -75
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigValuesAll.js +4 -43
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVirtualFilePageConfigs.js +9 -50
- 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/plugin/shared/addSsrMiddleware.js +14 -2
- package/dist/esm/node/prerender/runPrerender.js +37 -17
- package/dist/esm/node/prerender/utils.d.ts +1 -0
- package/dist/esm/node/prerender/utils.js +1 -0
- package/dist/esm/node/runtime/html/injectAssets/getHtmlTags.js +3 -3
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScripts.js +3 -2
- package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.d.ts +1 -1
- package/dist/esm/node/runtime/html/injectAssets/mergeScriptTags.js +2 -8
- package/dist/esm/node/runtime/html/renderHtml.js +19 -20
- package/dist/esm/node/runtime/html/stream.d.ts +1 -1
- package/dist/esm/node/runtime/html/stream.js +9 -9
- 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/executeOnBeforeRenderAndDataHooks.js +2 -2
- package/dist/esm/node/runtime/renderPage/executeOnRenderHtmlHook.js +8 -8
- package/dist/esm/node/runtime/renderPage/getHttpResponseBody.js +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +1 -6
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +4 -5
- package/dist/esm/node/runtime/renderPage/logErrorHint.d.ts +2 -6
- package/dist/esm/node/runtime/renderPage/logErrorHint.js +92 -283
- 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 +65 -39
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +31 -11
- package/dist/esm/node/runtime/renderPage.js +24 -17
- package/dist/esm/node/runtime/utils.d.ts +2 -0
- package/dist/esm/node/runtime/utils.js +2 -0
- package/dist/esm/node/shared/assertV1Design.d.ts +2 -2
- package/dist/esm/node/shared/assertV1Design.js +3 -4
- package/dist/esm/shared/VikeNamespace.d.ts +9 -0
- package/dist/esm/shared/getPageContext.d.ts +1 -0
- package/dist/esm/shared/getPageContext.js +1 -0
- 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/getPageFiles/getExports.d.ts +36 -0
- package/dist/esm/shared/getPageFiles/getExports.js +50 -2
- package/dist/esm/shared/getPageFiles/parseGlobResults.js +14 -7
- package/dist/esm/shared/hooks/executeHook.d.ts +10 -1
- package/dist/esm/shared/hooks/executeHook.js +21 -2
- 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/Config/PageContextConfig.d.ts +2 -2
- package/dist/esm/shared/page-configs/PageConfig.d.ts +14 -8
- 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 +17 -21
- package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.d.ts +1 -5
- package/dist/esm/shared/page-configs/serialize/assertPageConfigsSerialized.js +1 -16
- 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/executeGuardHook.js +1 -1
- package/dist/esm/shared/route/executeOnBeforeRouteHook.js +1 -1
- 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/sortPageContext.js +4 -8
- package/dist/esm/shared/types.d.ts +32 -6
- 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/assert.js +1 -1
- package/dist/esm/utils/assertNodeVersion.js +1 -1
- package/dist/esm/utils/changeEnumerable.d.ts +2 -0
- package/dist/esm/utils/changeEnumerable.js +5 -0
- package/dist/esm/utils/escapeHtml.d.ts +1 -0
- package/dist/esm/utils/escapeHtml.js +10 -0
- package/dist/esm/utils/getPropAccessNotation.d.ts +1 -2
- package/dist/esm/utils/getPropAccessNotation.js +2 -6
- package/dist/esm/utils/hasProp.d.ts +4 -13
- package/dist/esm/utils/hasProp.js +5 -7
- package/dist/esm/utils/normalizeHeaders.d.ts +1 -0
- package/dist/esm/utils/normalizeHeaders.js +9 -0
- 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/objectKeys.d.ts +1 -3
- package/dist/esm/utils/objectKeys.js +8 -4
- package/dist/esm/utils/projectInfo.d.ts +2 -2
- package/dist/esm/utils/projectInfo.js +1 -1
- package/package.json +21 -12
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getConfigValuesSerialized.js +0 -76
- 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 -50
- package/dist/esm/node/plugin/plugins/importUserCode/generateEagerImport.d.ts +0 -16
- 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 -70
- 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 -8
- package/dist/esm/shared/page-configs/serialize/serializeConfigValue.js +0 -47
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
export { parsePageConfigs };
|
|
2
|
-
|
|
2
|
+
export { parseConfigValuesSerialized };
|
|
3
3
|
import { assert, assertUsage, isCallable } from '../../utils.js';
|
|
4
4
|
import { getConfigDefinedAt } from '../getConfigDefinedAt.js';
|
|
5
|
-
import {
|
|
5
|
+
import { parseTransform } from '@brillout/json-serializer/parse';
|
|
6
|
+
import { assertPlusFileExport } from '../assertPlusFileExport.js';
|
|
7
|
+
function parseConfigValuesSerialized(configValuesSerialized) {
|
|
8
|
+
const configValues = parseConfigValuesSerialized_tmp(configValuesSerialized);
|
|
9
|
+
return configValues;
|
|
10
|
+
}
|
|
6
11
|
function parsePageConfigs(pageConfigsSerialized, pageConfigGlobalSerialized) {
|
|
12
|
+
// pageConfigs
|
|
7
13
|
const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
|
|
8
|
-
const configValues =
|
|
9
|
-
{
|
|
10
|
-
const { configValuesSerialized } = pageConfigSerialized;
|
|
11
|
-
const configValuesAddendum = parseConfigValuesSerialized(configValuesSerialized);
|
|
12
|
-
Object.assign(configValues, configValuesAddendum);
|
|
13
|
-
}
|
|
14
|
-
{
|
|
15
|
-
const { configValuesImported } = pageConfigSerialized;
|
|
16
|
-
const configValuesAddendum = parseConfigValuesImported(configValuesImported);
|
|
17
|
-
Object.assign(configValues, configValuesAddendum);
|
|
18
|
-
}
|
|
14
|
+
const configValues = parseConfigValuesSerialized(pageConfigSerialized.configValuesSerialized);
|
|
19
15
|
const { pageId, isErrorPage, routeFilesystem, loadConfigValuesAll } = pageConfigSerialized;
|
|
20
16
|
assertRouteConfigValue(configValues);
|
|
21
17
|
return {
|
|
@@ -26,10 +22,11 @@ function parsePageConfigs(pageConfigsSerialized, pageConfigGlobalSerialized) {
|
|
|
26
22
|
loadConfigValuesAll
|
|
27
23
|
};
|
|
28
24
|
});
|
|
25
|
+
// pageConfigsGlobal
|
|
29
26
|
const pageConfigGlobal = { configValues: {} };
|
|
30
27
|
{
|
|
31
|
-
const
|
|
32
|
-
Object.assign(pageConfigGlobal.configValues,
|
|
28
|
+
const configValues = parseConfigValuesSerialized(pageConfigGlobalSerialized.configValuesSerialized);
|
|
29
|
+
Object.assign(pageConfigGlobal.configValues, configValues);
|
|
33
30
|
}
|
|
34
31
|
return { pageConfigs, pageConfigGlobal };
|
|
35
32
|
}
|
|
@@ -52,3 +49,100 @@ function assertRouteConfigValue(configValues) {
|
|
|
52
49
|
}
|
|
53
50
|
*/
|
|
54
51
|
}
|
|
52
|
+
function parseConfigValuesSerialized_tmp(configValuesSerialized) {
|
|
53
|
+
const configValues = {};
|
|
54
|
+
Object.entries(configValuesSerialized).forEach(([configName, configValueSeriliazed]) => {
|
|
55
|
+
let configValue;
|
|
56
|
+
if (configValueSeriliazed.type === 'cumulative') {
|
|
57
|
+
const { valueSerialized, ...common } = configValueSeriliazed;
|
|
58
|
+
const value = valueSerialized.map((valueSerializedElement, i) => {
|
|
59
|
+
const { value, sideExports } = parseValueSerialized(valueSerializedElement, configName, () => {
|
|
60
|
+
const definedAtFile = configValueSeriliazed.definedAtData[i];
|
|
61
|
+
assert(definedAtFile);
|
|
62
|
+
return definedAtFile;
|
|
63
|
+
});
|
|
64
|
+
addSideExports(sideExports);
|
|
65
|
+
return value;
|
|
66
|
+
});
|
|
67
|
+
configValue = { value, ...common };
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
const { valueSerialized, ...common } = configValueSeriliazed;
|
|
71
|
+
const { value, sideExports } = parseValueSerialized(valueSerialized, configName, () => {
|
|
72
|
+
assert(configValueSeriliazed.type !== 'computed');
|
|
73
|
+
return configValueSeriliazed.definedAtData;
|
|
74
|
+
});
|
|
75
|
+
addSideExports(sideExports);
|
|
76
|
+
configValue = { value, ...common };
|
|
77
|
+
}
|
|
78
|
+
configValues[configName] = configValue;
|
|
79
|
+
});
|
|
80
|
+
return configValues;
|
|
81
|
+
function addSideExports(sideExports) {
|
|
82
|
+
sideExports.forEach((sideExport) => {
|
|
83
|
+
const { configName, configValue } = sideExport;
|
|
84
|
+
if (!configValues[configName]) {
|
|
85
|
+
configValues[configName] = configValue;
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
// Side-exports have lower precedence.
|
|
89
|
+
// We can't avoid side-export conflicts upstream. (We cannot know about side-exports at build-time.)
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
function parseValueSerialized(valueSerialized, configName, getDefinedAtFile) {
|
|
95
|
+
if (valueSerialized.type === 'js-serialized') {
|
|
96
|
+
let { value } = valueSerialized;
|
|
97
|
+
value = parseTransform(value);
|
|
98
|
+
return { value, sideExports: [] };
|
|
99
|
+
}
|
|
100
|
+
if (valueSerialized.type === 'pointer-import') {
|
|
101
|
+
const { value } = valueSerialized;
|
|
102
|
+
return { value, sideExports: [] };
|
|
103
|
+
}
|
|
104
|
+
if (valueSerialized.type === 'plus-file') {
|
|
105
|
+
const definedAtFile = getDefinedAtFile();
|
|
106
|
+
const { exportValues } = valueSerialized;
|
|
107
|
+
assertPlusFileExport(exportValues, definedAtFile.filePathToShowToUser, configName);
|
|
108
|
+
let value;
|
|
109
|
+
let valueWasFound = false;
|
|
110
|
+
const sideExports = [];
|
|
111
|
+
Object.entries(exportValues).forEach(([exportName, exportValue]) => {
|
|
112
|
+
const isSideExport = exportName !== 'default' && exportName !== configName;
|
|
113
|
+
if (!isSideExport) {
|
|
114
|
+
value = exportValue;
|
|
115
|
+
assert(!valueWasFound);
|
|
116
|
+
valueWasFound = true;
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
sideExports.push({
|
|
120
|
+
configName: exportName,
|
|
121
|
+
configValue: {
|
|
122
|
+
type: 'standard', // We don't support side exports for cumulative values. We could support it but it isn't trivial.
|
|
123
|
+
value: exportValue,
|
|
124
|
+
definedAtData: {
|
|
125
|
+
filePathToShowToUser: definedAtFile.filePathToShowToUser,
|
|
126
|
+
fileExportPathToShowToUser: [exportName]
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
assert(valueWasFound);
|
|
133
|
+
return { value, sideExports };
|
|
134
|
+
}
|
|
135
|
+
assert(false);
|
|
136
|
+
}
|
|
137
|
+
/* [NULL_HANDLING] Do we really need this?
|
|
138
|
+
function assertIsNotNull(configValue: unknown, configName: string, filePathToShowToUser: string) {
|
|
139
|
+
assert(!filePathToShowToUser.includes('+config.'))
|
|
140
|
+
// Re-use this for:
|
|
141
|
+
// - upcoming config.requestPageContextOnNavigation
|
|
142
|
+
// - for cumulative values in the future: we don't need this for now because, currently, cumulative values are never imported.
|
|
143
|
+
assertUsage(
|
|
144
|
+
configValue !== null,
|
|
145
|
+
`Set ${pc.cyan(configName)} to ${pc.cyan('null')} in a +config.js file instead of ${filePathToShowToUser}`
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
*/
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { serializeConfigValues };
|
|
2
|
+
import type { ConfigEnvInternal, PageConfigBuildTime, PageConfigGlobalBuildTime } from '../PageConfig.js';
|
|
3
|
+
declare function serializeConfigValues(pageConfig: PageConfigBuildTime | (PageConfigGlobalBuildTime & {
|
|
4
|
+
configValuesComputed?: undefined;
|
|
5
|
+
}), importStatements: string[], isEnvMatch: (configEnv: ConfigEnvInternal) => boolean, tabspace: string): string[];
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
export { serializeConfigValues };
|
|
2
|
+
import { assertIsNotProductionRuntime } from '../../../utils/assertIsNotProductionRuntime.js';
|
|
3
|
+
import { assert, assertUsage, getPropAccessNotation } from '../../../node/plugin/utils.js';
|
|
4
|
+
import { addImportStatement } from '../../../node/plugin/plugins/importUserCode/addImportStatement.js';
|
|
5
|
+
import { parsePointerImportData } from '../../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transformFileImports.js';
|
|
6
|
+
import { getConfigValueFilePathToShowToUser } from '../helpers.js';
|
|
7
|
+
import { stringify } from '@brillout/json-serializer/stringify';
|
|
8
|
+
import pc from '@brillout/picocolors';
|
|
9
|
+
const REPLACE_ME_BEFORE = '__VIKE__REPLACE_ME_BEFORE__';
|
|
10
|
+
const REPLACE_ME_AFTER = '__VIKE__REPLACE_ME_AFTER__';
|
|
11
|
+
// This file is never loaded on the client-side but we save it under the vike/shared/ directory in order to collocate it with parsePageConfigs()
|
|
12
|
+
// - vike/shared/page-configs/serialize/parsePageConfigs.ts
|
|
13
|
+
// - parsePageConfigs() is loaded on both the client- and server-side.
|
|
14
|
+
assertIsNotProductionRuntime();
|
|
15
|
+
function serializeConfigValues(pageConfig, importStatements, isEnvMatch, tabspace) {
|
|
16
|
+
const lines = [];
|
|
17
|
+
tabspace += ' ';
|
|
18
|
+
Object.entries(pageConfig.configValuesComputed ?? {}).forEach(([configName, configValuesComputed]) => {
|
|
19
|
+
if (!isEnvMatch(configValuesComputed.configEnv))
|
|
20
|
+
return;
|
|
21
|
+
// Is there a use case for overriding computed values? If yes, then configValeSources has higher precedence
|
|
22
|
+
if (pageConfig.configValueSources[configName])
|
|
23
|
+
return;
|
|
24
|
+
const valueData = serializeWithJson(configValuesComputed.value, configName, null, importStatements);
|
|
25
|
+
const configValueBase = {
|
|
26
|
+
type: 'computed',
|
|
27
|
+
definedAtData: null
|
|
28
|
+
};
|
|
29
|
+
serializeConfigValue(configValueBase, valueData, configName, lines, tabspace);
|
|
30
|
+
});
|
|
31
|
+
Object.entries(pageConfig.configValueSources).forEach(([configName, sources]) => {
|
|
32
|
+
const configDef = pageConfig.configDefinitions[configName];
|
|
33
|
+
assert(configDef);
|
|
34
|
+
if (!configDef.cumulative) {
|
|
35
|
+
const configValueSource = sources[0];
|
|
36
|
+
assert(configValueSource);
|
|
37
|
+
assert(sources.slice(1).every((s) => s.isOverriden === true));
|
|
38
|
+
if (!isEnvMatch(configValueSource.configEnv))
|
|
39
|
+
return;
|
|
40
|
+
const { valueData, definedAtFile } = serializeConfigValueSource(configValueSource, configName, importStatements);
|
|
41
|
+
const configValueBase = {
|
|
42
|
+
type: 'standard',
|
|
43
|
+
definedAtData: definedAtFile
|
|
44
|
+
};
|
|
45
|
+
serializeConfigValue(configValueBase, valueData, configName, lines, tabspace);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const valueDataList = [];
|
|
49
|
+
const definedAtData = [];
|
|
50
|
+
sources
|
|
51
|
+
.filter((s) => !s.isOverriden)
|
|
52
|
+
.forEach((configValueSource) => {
|
|
53
|
+
if (!isEnvMatch(configValueSource.configEnv))
|
|
54
|
+
return;
|
|
55
|
+
const { valueData, definedAtFile } = serializeConfigValueSource(configValueSource, configName, importStatements);
|
|
56
|
+
valueDataList.push(valueData);
|
|
57
|
+
definedAtData.push(definedAtFile);
|
|
58
|
+
});
|
|
59
|
+
if (valueDataList.length === 0)
|
|
60
|
+
return;
|
|
61
|
+
const configValueBase = {
|
|
62
|
+
type: 'cumulative',
|
|
63
|
+
definedAtData
|
|
64
|
+
};
|
|
65
|
+
serializeConfigValue(configValueBase, valueDataList, configName, lines, tabspace);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return lines;
|
|
69
|
+
}
|
|
70
|
+
function serializeConfigValueSource(configValueSource, configName, importStatements) {
|
|
71
|
+
assert(configValueSource.isOverriden === false);
|
|
72
|
+
let valueData;
|
|
73
|
+
if ('value' in configValueSource) {
|
|
74
|
+
valueData = serializeWithJson(configValueSource.value, configName, configValueSource.definedAtFilePath, importStatements);
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
valueData = serializeWithImport(configValueSource, importStatements);
|
|
78
|
+
}
|
|
79
|
+
const definedAtFile = {
|
|
80
|
+
filePathToShowToUser: configValueSource.definedAtFilePath.filePathToShowToUser,
|
|
81
|
+
fileExportPathToShowToUser: configValueSource.definedAtFilePath.fileExportPathToShowToUser
|
|
82
|
+
};
|
|
83
|
+
return { valueData, definedAtFile };
|
|
84
|
+
}
|
|
85
|
+
function serializeConfigValue(configValueBase, valueData, configName, lines, tabspace) {
|
|
86
|
+
lineAdd(`[${JSON.stringify(configName)}]: {`);
|
|
87
|
+
{
|
|
88
|
+
tab();
|
|
89
|
+
lineAdd(`type: "${configValueBase.type}",`);
|
|
90
|
+
lineAdd(`definedAtData: ${JSON.stringify(configValueBase.definedAtData)},`);
|
|
91
|
+
lineAdd(`valueSerialized:`);
|
|
92
|
+
if (!Array.isArray(valueData)) {
|
|
93
|
+
serializeValueData(valueData);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
lineAppend(' [');
|
|
97
|
+
valueData.forEach(serializeValueData);
|
|
98
|
+
lineAppend(` ],`);
|
|
99
|
+
}
|
|
100
|
+
untab();
|
|
101
|
+
}
|
|
102
|
+
lineAdd('},');
|
|
103
|
+
return;
|
|
104
|
+
function serializeValueData(valueData) {
|
|
105
|
+
lineAppend(` {`);
|
|
106
|
+
tab();
|
|
107
|
+
lineAdd(`type: "${valueData.type}",`);
|
|
108
|
+
const valueProp = valueData.type !== 'plus-file' ? 'value' : 'exportValues';
|
|
109
|
+
lineAdd(`${valueProp}: ${valueData.valueAsJsCode},`);
|
|
110
|
+
untab();
|
|
111
|
+
lineAdd(`},`);
|
|
112
|
+
}
|
|
113
|
+
function lineAppend(str) {
|
|
114
|
+
const i = lines.length - 1;
|
|
115
|
+
lines[i] = lines[i] += str;
|
|
116
|
+
}
|
|
117
|
+
function lineAdd(str) {
|
|
118
|
+
lines.push(`${tabspace}${str}`);
|
|
119
|
+
}
|
|
120
|
+
function tab() {
|
|
121
|
+
tabspace += ' ';
|
|
122
|
+
}
|
|
123
|
+
function untab() {
|
|
124
|
+
tabspace = tabspace.slice(2);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
function serializeWithImport(configValueSource, importStatements) {
|
|
128
|
+
assert(!configValueSource.valueIsFilePath);
|
|
129
|
+
const { valueIsImportedAtRuntime, valueIsDefinedByPlusFile, definedAtFilePath } = configValueSource;
|
|
130
|
+
assert(valueIsImportedAtRuntime);
|
|
131
|
+
const { filePathAbsoluteVite, fileExportName } = definedAtFilePath;
|
|
132
|
+
if (valueIsDefinedByPlusFile)
|
|
133
|
+
assert(fileExportName === undefined);
|
|
134
|
+
const { importName } = addImportStatement(importStatements, filePathAbsoluteVite, fileExportName || '*');
|
|
135
|
+
return {
|
|
136
|
+
type: valueIsDefinedByPlusFile ? 'plus-file' : 'pointer-import',
|
|
137
|
+
valueAsJsCode: importName
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
function serializeWithJson(value, configName, definedAtData, importStatements) {
|
|
141
|
+
const valueAsJsCode = valueToJson(value, configName, definedAtData, importStatements);
|
|
142
|
+
return {
|
|
143
|
+
type: 'js-serialized',
|
|
144
|
+
valueAsJsCode
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
function valueToJson(value, configName, definedAtData, importStatements) {
|
|
148
|
+
const valueName = `config${getPropAccessNotation(configName)}`;
|
|
149
|
+
let configValueSerialized;
|
|
150
|
+
try {
|
|
151
|
+
configValueSerialized = stringify(value, {
|
|
152
|
+
valueName,
|
|
153
|
+
forbidReactElements: true,
|
|
154
|
+
replacer(_, value) {
|
|
155
|
+
if (typeof value === 'string') {
|
|
156
|
+
const importData = parsePointerImportData(value);
|
|
157
|
+
if (importData) {
|
|
158
|
+
const { importName } = addImportStatement(importStatements, importData.importPath, importData.exportName);
|
|
159
|
+
const replacement = [REPLACE_ME_BEFORE, importName, REPLACE_ME_AFTER].join('');
|
|
160
|
+
return { replacement };
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
logJsonSerializeError(err, configName, definedAtData);
|
|
168
|
+
assert(false);
|
|
169
|
+
}
|
|
170
|
+
configValueSerialized = configValueSerialized.replaceAll(`"${REPLACE_ME_BEFORE}`, '');
|
|
171
|
+
configValueSerialized = configValueSerialized.replaceAll(`${REPLACE_ME_AFTER}"`, '');
|
|
172
|
+
assert(!configValueSerialized.includes(REPLACE_ME_BEFORE));
|
|
173
|
+
assert(!configValueSerialized.includes(REPLACE_ME_AFTER));
|
|
174
|
+
return configValueSerialized;
|
|
175
|
+
}
|
|
176
|
+
function logJsonSerializeError(err, configName, definedAtData) {
|
|
177
|
+
/*
|
|
178
|
+
// import { isJsonSerializerError } from '@brillout/json-serializer/stringify'
|
|
179
|
+
let serializationErrMsg = ''
|
|
180
|
+
if (isJsonSerializerError(err)) {
|
|
181
|
+
serializationErrMsg = err.messageCore
|
|
182
|
+
} else {
|
|
183
|
+
// When a property getter throws an error
|
|
184
|
+
console.error('Serialization error:')
|
|
185
|
+
console.error(err)
|
|
186
|
+
serializationErrMsg = 'see serialization error printed above'
|
|
187
|
+
}
|
|
188
|
+
//*/
|
|
189
|
+
const configValueFilePathToShowToUser = getConfigValueFilePathToShowToUser(definedAtData);
|
|
190
|
+
assert(configValueFilePathToShowToUser);
|
|
191
|
+
assertUsage(false, `${pc.cyan(configName)} defined by ${configValueFilePathToShowToUser} must be defined over a so-called "pointer import", see https://vike.dev/config#pointer-imports`);
|
|
192
|
+
}
|
|
@@ -21,7 +21,7 @@ async function executeGuardHook(pageContext, prepareForUserConsumption) {
|
|
|
21
21
|
const res = prepareForUserConsumption(pageContext);
|
|
22
22
|
if (res)
|
|
23
23
|
pageContextForUserConsumption = res;
|
|
24
|
-
const hookResult = await executeHook(() => guard(pageContextForUserConsumption), hook);
|
|
24
|
+
const hookResult = await executeHook(() => guard(pageContextForUserConsumption), hook, pageContext);
|
|
25
25
|
assertUsage(hookResult === undefined, `${errIntro} ${hook.hookFilePath} returns a value, but guard() shouldn't return any value`);
|
|
26
26
|
}
|
|
27
27
|
function findPageGuard(pageId, pageFilesAll) {
|
|
@@ -36,7 +36,7 @@ async function getPageContextFromHook(onBeforeRouteHook, pageContext) {
|
|
|
36
36
|
let hookReturn = onBeforeRouteHook.hookFn(pageContext);
|
|
37
37
|
assertSyncRouting(hookReturn, `The onBeforeRoute() hook ${onBeforeRouteHook.hookFilePath}`);
|
|
38
38
|
// TODO/v1-release: make executeOnBeforeRouteHook() and route() sync
|
|
39
|
-
hookReturn = await executeHook(() => hookReturn, onBeforeRouteHook);
|
|
39
|
+
hookReturn = await executeHook(() => hookReturn, onBeforeRouteHook, pageContext);
|
|
40
40
|
const errPrefix = `The onBeforeRoute() hook defined by ${onBeforeRouteHook.hookFilePath}`;
|
|
41
41
|
assertUsage(hookReturn === null ||
|
|
42
42
|
hookReturn === undefined ||
|
|
@@ -4,18 +4,18 @@ export type { PageContextFromRoute };
|
|
|
4
4
|
export type { PageRoutes };
|
|
5
5
|
export type { RouteMatches };
|
|
6
6
|
import type { PageFile } from '../getPageFiles.js';
|
|
7
|
-
import {
|
|
7
|
+
import { type PageContextUrlInternal, type PageContextUrlSource } from '../getPageContextUrlComputed.js';
|
|
8
8
|
import type { PageRoutes, RouteType } from './loadPageRoutes.js';
|
|
9
9
|
import type { PageConfigRuntime, PageConfigGlobalRuntime } from '../page-configs/PageConfig.js';
|
|
10
10
|
import type { Hook } from '../hooks/getHook.js';
|
|
11
|
-
type PageContextForRoute =
|
|
11
|
+
type PageContextForRoute = PageContextUrlInternal & {
|
|
12
12
|
_pageFilesAll: PageFile[];
|
|
13
13
|
_pageConfigs: PageConfigRuntime[];
|
|
14
14
|
_allPageIds: string[];
|
|
15
15
|
_pageConfigGlobal: PageConfigGlobalRuntime;
|
|
16
16
|
_pageRoutes: PageRoutes;
|
|
17
17
|
_onBeforeRouteHook: Hook | null;
|
|
18
|
-
} &
|
|
18
|
+
} & PageContextUrlSource;
|
|
19
19
|
type PageContextFromRoute = {
|
|
20
20
|
_pageId: string | null;
|
|
21
21
|
routeParams: Record<string, string>;
|
|
@@ -6,7 +6,7 @@ if (isBrowser()) {
|
|
|
6
6
|
assertClientRouting();
|
|
7
7
|
}
|
|
8
8
|
import { assert, assertUsage, isPlainObject, objectAssign } from './utils.js';
|
|
9
|
-
import {
|
|
9
|
+
import { assertPageContextUrl } from '../getPageContextUrlComputed.js';
|
|
10
10
|
import { resolvePrecendence } from './resolvePrecedence.js';
|
|
11
11
|
import { resolveRouteString } from './resolveRouteString.js';
|
|
12
12
|
import { resolveRouteFunction } from './resolveRouteFunction.js';
|
|
@@ -15,7 +15,7 @@ import { debug } from './debug.js';
|
|
|
15
15
|
import pc from '@brillout/picocolors';
|
|
16
16
|
async function route(pageContextForRoute) {
|
|
17
17
|
debug('Pages routes:', pageContextForRoute._pageRoutes);
|
|
18
|
-
|
|
18
|
+
assertPageContextUrl(pageContextForRoute);
|
|
19
19
|
const pageContextFromRoute = {};
|
|
20
20
|
// onBeforeRoute()
|
|
21
21
|
const pageContextFromOnBeforeRouteHook = await executeOnBeforeRouteHook(pageContextForRoute);
|
|
@@ -3,7 +3,7 @@ import { isErrorPageId } from '../error-page.js';
|
|
|
3
3
|
import { assert, assertUsage, hasProp, slice } from './utils.js';
|
|
4
4
|
import { deduceRouteStringFromFilesystemPath } from './deduceRouteStringFromFilesystemPath.js';
|
|
5
5
|
import { isCallable } from '../utils.js';
|
|
6
|
-
import {
|
|
6
|
+
import { getConfigValueRuntime } from '../page-configs/getConfigValue.js';
|
|
7
7
|
import { getDefinedAtString } from '../page-configs/getConfigDefinedAt.js';
|
|
8
8
|
import { warnDeprecatedAllowKey } from './resolveRouteFunction.js';
|
|
9
9
|
import { getHookFromPageConfigGlobal, getHookTimeoutDefault } from '../hooks/getHook.js';
|
|
@@ -28,7 +28,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
28
28
|
let pageRoute = null;
|
|
29
29
|
{
|
|
30
30
|
const configName = 'route';
|
|
31
|
-
const configValue =
|
|
31
|
+
const configValue = getConfigValueRuntime(pageConfig, configName);
|
|
32
32
|
if (configValue) {
|
|
33
33
|
const route = configValue.value;
|
|
34
34
|
assert(configValue.definedAtData);
|
|
@@ -44,7 +44,7 @@ function getPageRoutes(filesystemRoots, pageFilesAll, pageConfigs, allPageIds) {
|
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
46
|
assert(isCallable(route));
|
|
47
|
-
if (
|
|
47
|
+
if (getConfigValueRuntime(pageConfig, 'iKnowThePerformanceRisksOfAsyncRouteFunctions', 'boolean'))
|
|
48
48
|
warnDeprecatedAllowKey();
|
|
49
49
|
pageRoute = {
|
|
50
50
|
pageId,
|
|
@@ -2,8 +2,8 @@ export { resolveRouteFunction };
|
|
|
2
2
|
export { assertRouteParams };
|
|
3
3
|
export { assertSyncRouting };
|
|
4
4
|
export { warnDeprecatedAllowKey };
|
|
5
|
-
import {
|
|
6
|
-
declare function resolveRouteFunction(routeFunction: Function, pageContext:
|
|
5
|
+
import { PageContextUrlInternal } from '../getPageContextUrlComputed.js';
|
|
6
|
+
declare function resolveRouteFunction(routeFunction: Function, pageContext: PageContextUrlInternal, routeDefinedAtString: string): Promise<null | {
|
|
7
7
|
precedence: number | null;
|
|
8
8
|
routeParams: Record<string, string>;
|
|
9
9
|
}>;
|
|
@@ -2,11 +2,11 @@ export { resolveRouteFunction };
|
|
|
2
2
|
export { assertRouteParams };
|
|
3
3
|
export { assertSyncRouting };
|
|
4
4
|
export { warnDeprecatedAllowKey };
|
|
5
|
-
import {
|
|
5
|
+
import { assertPageContextUrl } from '../getPageContextUrlComputed.js';
|
|
6
6
|
import { assert, assertUsage, assertWarning, hasProp, isPlainObject, isPromise } from './utils.js';
|
|
7
7
|
import pc from '@brillout/picocolors';
|
|
8
8
|
async function resolveRouteFunction(routeFunction, pageContext, routeDefinedAtString) {
|
|
9
|
-
|
|
9
|
+
assertPageContextUrl(pageContext);
|
|
10
10
|
let result = routeFunction(pageContext);
|
|
11
11
|
assertSyncRouting(result, `The Route Function ${routeDefinedAtString}`);
|
|
12
12
|
// TODO/v1-release: make resolveRouteFunction() and route() sync
|
|
@@ -2,13 +2,9 @@ import { compareString } from './utils.js';
|
|
|
2
2
|
export { sortPageContext };
|
|
3
3
|
// Sort `pageContext` keys alphabetically, in order to make reading `console.log(pageContext)` easier
|
|
4
4
|
function sortPageContext(pageContext) {
|
|
5
|
-
|
|
6
|
-
for (const key
|
|
5
|
+
let descriptors = Object.getOwnPropertyDescriptors(pageContext);
|
|
6
|
+
for (const key of Object.keys(pageContext))
|
|
7
7
|
delete pageContext[key];
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
.sort(([key1], [key2]) => compareString(key1, key2))
|
|
11
|
-
.forEach(([key, val]) => {
|
|
12
|
-
pageContext[key] = val;
|
|
13
|
-
});
|
|
8
|
+
descriptors = Object.fromEntries(Object.entries(descriptors).sort(([key1], [key2]) => compareString(key1, key2)));
|
|
9
|
+
Object.defineProperties(pageContext, descriptors);
|
|
14
10
|
}
|
|
@@ -7,8 +7,8 @@ export { PageContextBuiltInServerInternal };
|
|
|
7
7
|
export { PageContextBuiltInServer_deprecated as PageContextBuiltInServer };
|
|
8
8
|
export { PageContextBuiltInClientWithClientRouting_deprecated as PageContextBuiltInClientWithClientRouting };
|
|
9
9
|
export { PageContextBuiltInClientWithServerRouting_deprecated as PageContextBuiltInClientWithServerRouting };
|
|
10
|
-
import type {
|
|
11
|
-
import type { ConfigEntries, ExportsAll } from './getPageFiles/getExports.js';
|
|
10
|
+
import type { PageContextUrlInternal, PageContextUrlClient, PageContextUrlServer } from './getPageContextUrlComputed.js';
|
|
11
|
+
import type { ConfigEntries, ExportsAll, From, Source, Sources } from './getPageFiles/getExports.js';
|
|
12
12
|
import type { Config } from './page-configs/Config.js';
|
|
13
13
|
import type { PageContextConfig } from './page-configs/Config/PageContextConfig.js';
|
|
14
14
|
import type { AbortStatusCode } from './route/abort.js';
|
|
@@ -59,6 +59,26 @@ type PageContextBuiltInCommon<Data> = {
|
|
|
59
59
|
* https://vike.dev/renderPage
|
|
60
60
|
*/
|
|
61
61
|
urlOriginal: string;
|
|
62
|
+
/**
|
|
63
|
+
* The HTTP Headers of the incoming HTTP Request.
|
|
64
|
+
*
|
|
65
|
+
* As a string object normalized by Vike.
|
|
66
|
+
*
|
|
67
|
+
* See also:
|
|
68
|
+
* - https://vike.dev/headers
|
|
69
|
+
* - `pageContext.headersOriginal`
|
|
70
|
+
*/
|
|
71
|
+
headers: Record<string, string> | null;
|
|
72
|
+
/**
|
|
73
|
+
* The HTTP Headers of the incoming HTTP Request.
|
|
74
|
+
*
|
|
75
|
+
* The original object provided by the server.
|
|
76
|
+
*
|
|
77
|
+
* See also:
|
|
78
|
+
* - https://vike.dev/headers
|
|
79
|
+
* - `pageContext.headers`
|
|
80
|
+
*/
|
|
81
|
+
headersOriginal?: unknown;
|
|
62
82
|
/** If an error occurs, whether the error is a `404 Page Not Found`.
|
|
63
83
|
*
|
|
64
84
|
* https://vike.dev/error-page
|
|
@@ -88,13 +108,19 @@ type PageContextBuiltInCommon<Data> = {
|
|
|
88
108
|
* https://vike.dev/errors
|
|
89
109
|
*/
|
|
90
110
|
errorWhileRendering?: unknown;
|
|
111
|
+
/** @experimental https://github.com/vikejs/vike/issues/1268 */
|
|
112
|
+
from: From;
|
|
113
|
+
/** @experimental https://github.com/vikejs/vike/issues/1268 */
|
|
114
|
+
source: Source;
|
|
115
|
+
/** @experimental https://github.com/vikejs/vike/issues/1268 */
|
|
116
|
+
sources: Sources;
|
|
91
117
|
/** @deprecated */
|
|
92
118
|
url: string;
|
|
93
119
|
/** @deprecated */
|
|
94
120
|
pageExports: Record<string, unknown>;
|
|
95
121
|
};
|
|
96
|
-
type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> &
|
|
97
|
-
type PageContextBuiltInClientWithClientRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'pageExports' | 'config' | 'configEntries' | 'exports' | 'exportsAll' | 'abortReason' | 'data'> & {
|
|
122
|
+
type PageContextBuiltInServer<Data> = PageContextBuiltInCommon<Data> & PageContextUrlServer;
|
|
123
|
+
type PageContextBuiltInClientWithClientRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'pageExports' | 'config' | 'configEntries' | 'exports' | 'exportsAll' | 'abortReason' | 'data' | 'source' | 'sources' | 'from'> & {
|
|
98
124
|
/** Whether the current page is already rendered to HTML */
|
|
99
125
|
isHydration: boolean;
|
|
100
126
|
/**
|
|
@@ -103,7 +129,7 @@ type PageContextBuiltInClientWithClientRouting<Data> = Partial<PageContextBuiltI
|
|
|
103
129
|
* The value is `true` when the user clicks on his browser's backward navigation button, or when invoking `history.back()`.
|
|
104
130
|
*/
|
|
105
131
|
isBackwardNavigation: boolean | null;
|
|
106
|
-
} &
|
|
132
|
+
} & PageContextUrlClient;
|
|
107
133
|
type PageContextBuiltInClientWithServerRouting<Data> = Partial<PageContextBuiltInCommon<Data>> & Pick<PageContextBuiltInCommon<Data>, 'Page' | 'pageExports' | 'exports' | 'abortReason' | 'data'> & {
|
|
108
134
|
/**
|
|
109
135
|
* Whether the current page is already rendered to HTML.
|
|
@@ -119,7 +145,7 @@ type PageContextBuiltInClientWithServerRouting<Data> = Partial<PageContextBuiltI
|
|
|
119
145
|
isBackwardNavigation: null;
|
|
120
146
|
};
|
|
121
147
|
/** For Vike internal use */
|
|
122
|
-
type PageContextBuiltInServerInternal = Omit<PageContextBuiltInCommon<unknown> &
|
|
148
|
+
type PageContextBuiltInServerInternal = Omit<PageContextBuiltInCommon<unknown> & PageContextUrlInternal, 'data'>;
|
|
123
149
|
/** @deprecated
|
|
124
150
|
* Replace:
|
|
125
151
|
* ```
|
|
@@ -21,3 +21,5 @@ export * from '../utils/checkType.js';
|
|
|
21
21
|
export * from '../utils/getValuePrintable.js';
|
|
22
22
|
export * from '../utils/escapeRegex.js';
|
|
23
23
|
export * from '../utils/isArray.js';
|
|
24
|
+
export * from '../utils/changeEnumerable.js';
|
|
25
|
+
export * from '../utils/objectDefineProperty.js';
|
package/dist/esm/shared/utils.js
CHANGED
|
@@ -25,3 +25,5 @@ export * from '../utils/checkType.js';
|
|
|
25
25
|
export * from '../utils/getValuePrintable.js';
|
|
26
26
|
export * from '../utils/escapeRegex.js';
|
|
27
27
|
export * from '../utils/isArray.js';
|
|
28
|
+
export * from '../utils/changeEnumerable.js';
|
|
29
|
+
export * from '../utils/objectDefineProperty.js';
|
|
@@ -10,7 +10,7 @@ export type { Config, ConfigMeta as Meta, DataAsync, DataSync, GuardAsync, Guard
|
|
|
10
10
|
export type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
|
|
11
11
|
export type { ConfigDefinition, ConfigEffect } from '../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js';
|
|
12
12
|
export type { ConfigEntries } from '../shared/getPageFiles/getExports.js';
|
|
13
|
-
export type { Url } from '../shared/
|
|
13
|
+
export type { Url } from '../shared/getPageContextUrlComputed.js';
|
|
14
14
|
export type { InjectFilterEntry } from '../node/runtime/html/injectAssets/getHtmlTags.js';
|
|
15
15
|
export { defineConfig } from './defineConfig.js';
|
|
16
16
|
import type { ConfigEnv } from '../shared/page-configs/PageConfig.js';
|
package/dist/esm/utils/assert.js
CHANGED
|
@@ -92,7 +92,7 @@ function assertWarning(condition, msg, { onlyOnce, showStackTrace }) {
|
|
|
92
92
|
}
|
|
93
93
|
globalObject.onBeforeLog?.();
|
|
94
94
|
if (showStackTrace) {
|
|
95
|
-
const err =
|
|
95
|
+
const err = createErrorWithCleanStackTrace(msg, numberOfStackTraceLinesToRemove);
|
|
96
96
|
globalObject.showStackTraceList.add(err);
|
|
97
97
|
globalObject.logger(err, 'warn');
|
|
98
98
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function escapeHtml(unsafeString: string): string;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copied from https://stackoverflow.com/questions/6234773/can-i-escape-html-special-chars-in-javascript/6234804#6234804
|
|
2
|
+
export function escapeHtml(unsafeString) {
|
|
3
|
+
const safe = unsafeString
|
|
4
|
+
.replace(/&/g, '&')
|
|
5
|
+
.replace(/</g, '<')
|
|
6
|
+
.replace(/>/g, '>')
|
|
7
|
+
.replace(/"/g, '"')
|
|
8
|
+
.replace(/'/g, ''');
|
|
9
|
+
return safe;
|
|
10
|
+
}
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
declare function getPropAccessNotation(key: string): `.${string}` | `[${string}]`;
|
|
1
|
+
export declare function getPropAccessNotation(key: unknown): `.${string}` | `[${string}]`;
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
return isKeyDotNotationCompatible(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
|
|
4
|
-
}
|
|
5
|
-
function isKeyDotNotationCompatible(key) {
|
|
6
|
-
return /^[a-z0-9\$_]+$/i.test(key);
|
|
1
|
+
export function getPropAccessNotation(key) {
|
|
2
|
+
return typeof key === 'string' && /^[a-z0-9\$_]+$/i.test(key) ? `.${key}` : `[${JSON.stringify(key)}]`;
|
|
7
3
|
}
|