vike 0.4.171 → 0.4.172
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/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 +17 -13
- 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/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 +17 -13
- 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,48 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// URLs props need to be computed props, because the user can modify the URL e.g. with onBeforeRoute() for i18n
|
|
3
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.
|
|
3
|
+
exports.assertPageContextUrl = exports.getPageContextUrlComputed = void 0;
|
|
4
|
+
// =====================
|
|
5
|
+
// File determining the URL logic.
|
|
6
|
+
// URLs need to be computed, because the user can modify the URL e.g. with onBeforeRoute() for i18n.
|
|
7
|
+
// =====================
|
|
8
|
+
const objectDefineProperty_js_1 = require("../utils/objectDefineProperty.js");
|
|
5
9
|
const utils_js_1 = require("./utils.js");
|
|
6
|
-
function
|
|
7
|
-
(0, utils_js_1.assert)(pageContext.urlOriginal);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
```js
|
|
12
|
-
// Add property getters such as pageContext.urlPathname to pageContext
|
|
13
|
-
addUrlComputedProps(pageContext)
|
|
14
|
-
// ❌ Breaks the property getters of pageContext set by addUrlComputedProps() such as pageContext.urlPathname
|
|
15
|
-
Object.assign(pageContext2, pageContext)
|
|
16
|
-
// ❌ Also breaks the property getters
|
|
17
|
-
const pageContext3 = { ...pageContext }
|
|
18
|
-
// ✅ Preserves property getters of pageContext (see objectAssign() implementation)
|
|
19
|
-
objectAssign(pageContext2, pageContext)
|
|
20
|
-
```
|
|
21
|
-
*/
|
|
22
|
-
(0, utils_js_1.assert)((0, utils_js_1.isPropertyGetter)(pageContext, 'urlPathname'));
|
|
23
|
-
}
|
|
24
|
-
if ('urlParsed' in pageContext)
|
|
25
|
-
(0, utils_js_1.assert)((0, utils_js_1.isPropertyGetter)(pageContext, 'urlParsed'));
|
|
26
|
-
// TODO/v1-release: move pageContext.urlParsed to pageContext.url
|
|
27
|
-
if ('url' in pageContext)
|
|
28
|
-
(0, utils_js_1.assert)((0, utils_js_1.isPropertyGetter)(pageContext, 'url'));
|
|
29
|
-
Object.defineProperty(pageContext, 'urlPathname', {
|
|
10
|
+
function getPageContextUrlComputed(pageContext) {
|
|
11
|
+
(0, utils_js_1.assert)(typeof pageContext.urlOriginal === 'string');
|
|
12
|
+
assertPageContextUrlComputed(pageContext);
|
|
13
|
+
const pageContextUrlComputed = {};
|
|
14
|
+
(0, objectDefineProperty_js_1.objectDefineProperty)(pageContextUrlComputed, 'urlPathname', {
|
|
30
15
|
get: urlPathnameGetter,
|
|
31
|
-
enumerable,
|
|
16
|
+
enumerable: true,
|
|
32
17
|
configurable: true
|
|
33
18
|
});
|
|
34
|
-
|
|
19
|
+
(0, objectDefineProperty_js_1.objectDefineProperty)(pageContextUrlComputed, 'url', {
|
|
35
20
|
get: urlGetter,
|
|
36
21
|
enumerable: false,
|
|
37
22
|
configurable: true
|
|
38
23
|
});
|
|
39
|
-
|
|
24
|
+
(0, objectDefineProperty_js_1.objectDefineProperty)(pageContextUrlComputed, 'urlParsed', {
|
|
40
25
|
get: urlParsedGetter,
|
|
41
|
-
enumerable,
|
|
26
|
+
enumerable: true,
|
|
42
27
|
configurable: true
|
|
43
28
|
});
|
|
29
|
+
return pageContextUrlComputed;
|
|
44
30
|
}
|
|
45
|
-
exports.
|
|
31
|
+
exports.getPageContextUrlComputed = getPageContextUrlComputed;
|
|
46
32
|
function getUrlParsed(pageContext) {
|
|
47
33
|
// We need a url handler function because the onBeforeRoute() hook may set pageContext.urlLogical (typically for i18n)
|
|
48
34
|
let urlHandler = pageContext._urlHandler;
|
|
@@ -92,7 +78,7 @@ function urlParsedGetter() {
|
|
|
92
78
|
const { origin, pathname, pathnameOriginal, search, searchAll, searchOriginal, hash, hashOriginal } = urlParsedOriginal;
|
|
93
79
|
const hashIsAvailable = (0, utils_js_1.isBrowser)();
|
|
94
80
|
const warnHashNotAvailable = (prop) => {
|
|
95
|
-
(0, utils_js_1.assertWarning)(hashIsAvailable, `pageContext.urlParsed.${prop} isn't available on the server-side (HTTP requests don't include the URL hash
|
|
81
|
+
(0, utils_js_1.assertWarning)(hashIsAvailable, `pageContext.urlParsed.${prop} isn't available on the server-side (HTTP requests don't include the URL hash)`, { onlyOnce: true, showStackTrace: true });
|
|
96
82
|
};
|
|
97
83
|
const urlParsed = {
|
|
98
84
|
origin,
|
|
@@ -122,22 +108,46 @@ function urlParsedGetter() {
|
|
|
122
108
|
return searchOriginal;
|
|
123
109
|
}
|
|
124
110
|
};
|
|
125
|
-
|
|
126
|
-
|
|
111
|
+
(0, utils_js_1.changeEnumerable)(urlParsed, 'hashString', false);
|
|
112
|
+
(0, utils_js_1.changeEnumerable)(urlParsed, 'searchString', false);
|
|
127
113
|
if (!hashIsAvailable) {
|
|
128
|
-
|
|
129
|
-
|
|
114
|
+
(0, utils_js_1.changeEnumerable)(urlParsed, 'hash', false);
|
|
115
|
+
(0, utils_js_1.changeEnumerable)(urlParsed, 'hashOriginal', false);
|
|
130
116
|
}
|
|
131
117
|
return urlParsed;
|
|
132
118
|
}
|
|
133
|
-
function
|
|
134
|
-
const descriptor = Object.getOwnPropertyDescriptor(obj, prop);
|
|
135
|
-
Object.defineProperty(obj, prop, { ...descriptor, enumerable: false });
|
|
136
|
-
}
|
|
137
|
-
function assertPageContextUrlComputedProps(pageContext) {
|
|
119
|
+
function assertPageContextUrl(pageContext) {
|
|
138
120
|
(0, utils_js_1.assert)(typeof pageContext.urlOriginal === 'string');
|
|
139
121
|
(0, utils_js_1.assert)(typeof pageContext.urlPathname === 'string');
|
|
140
122
|
(0, utils_js_1.assert)((0, utils_js_1.isPlainObject)(pageContext.urlParsed));
|
|
141
123
|
(0, utils_js_1.assert)(pageContext.urlPathname === pageContext.urlParsed.pathname);
|
|
124
|
+
assertPageContextUrlComputed(pageContext);
|
|
125
|
+
}
|
|
126
|
+
exports.assertPageContextUrl = assertPageContextUrl;
|
|
127
|
+
function assertPageContextUrlComputed(pageContext) {
|
|
128
|
+
/*
|
|
129
|
+
If the isPropertyGetter() assertions fail then it's most likely because Object.assign() was used instead of `objectAssign()`:
|
|
130
|
+
```js
|
|
131
|
+
const PageContextUrlComputed = getPageContextUrlComputed(pageContext)
|
|
132
|
+
|
|
133
|
+
// ❌ Breaks the property descriptors/getters of pageContext defined by getPageContextUrlComputed() such as pageContext.urlPathname
|
|
134
|
+
Object.assign(pageContext, pageContextUrlComputed)
|
|
135
|
+
|
|
136
|
+
// ❌ Also breaks property descriptors/getters
|
|
137
|
+
const pageContext = { ...pageContextUrlComputed }
|
|
138
|
+
|
|
139
|
+
// ✅ Preserves property descriptors/getters (see objectAssign() implementation)
|
|
140
|
+
objectAssign(pageContext, pageContextUrlComputed)
|
|
141
|
+
```
|
|
142
|
+
*/
|
|
143
|
+
if ('urlPathname' in pageContext) {
|
|
144
|
+
(0, utils_js_1.assert)(typeof pageContext.urlPathname === 'string');
|
|
145
|
+
(0, utils_js_1.assert)((0, utils_js_1.isPropertyGetter)(pageContext, 'urlPathname'));
|
|
146
|
+
(0, utils_js_1.assert)((0, utils_js_1.isPropertyGetter)(pageContext, 'urlParsed'));
|
|
147
|
+
(0, utils_js_1.assert)((0, utils_js_1.isPropertyGetter)(pageContext, 'url'));
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
(0, utils_js_1.assert)(!('urlParsed' in pageContext));
|
|
151
|
+
(0, utils_js_1.assert)(!('url' in pageContext));
|
|
152
|
+
}
|
|
142
153
|
}
|
|
143
|
-
exports.assertPageContextUrlComputedProps = assertPageContextUrlComputedProps;
|
|
@@ -6,8 +6,8 @@ const analyzePageClientSide_js_1 = require("./analyzePageClientSide.js");
|
|
|
6
6
|
function analyzeClientSide(pageConfig, pageFilesAll, pageId) {
|
|
7
7
|
// V1 design
|
|
8
8
|
if (pageConfig) {
|
|
9
|
-
const isClientRouting = (0, getConfigValue_js_1.
|
|
10
|
-
const isClientSideRenderable = (0, getConfigValue_js_1.
|
|
9
|
+
const isClientRouting = (0, getConfigValue_js_1.getConfigValueRuntime)(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
10
|
+
const isClientSideRenderable = (0, getConfigValue_js_1.getConfigValueRuntime)(pageConfig, 'isClientSideRenderable', 'boolean')?.value ?? false;
|
|
11
11
|
return { isClientSideRenderable, isClientRouting };
|
|
12
12
|
}
|
|
13
13
|
else {
|
|
@@ -32,6 +32,18 @@ function getPageContextExports(pageFiles, pageConfig) {
|
|
|
32
32
|
});
|
|
33
33
|
});
|
|
34
34
|
// V1 design
|
|
35
|
+
const source = {};
|
|
36
|
+
const sources = {};
|
|
37
|
+
const addSrc = (src, configName) => {
|
|
38
|
+
source[configName] = src;
|
|
39
|
+
sources[configName] ?? (sources[configName] = []);
|
|
40
|
+
sources[configName].push(src);
|
|
41
|
+
};
|
|
42
|
+
const from = {
|
|
43
|
+
configsStandard: {},
|
|
44
|
+
configsCumulative: {},
|
|
45
|
+
configsComputed: {}
|
|
46
|
+
};
|
|
35
47
|
if (pageConfig) {
|
|
36
48
|
Object.entries(pageConfig.configValues).forEach(([configName, configValue]) => {
|
|
37
49
|
const { value } = configValue;
|
|
@@ -46,6 +58,39 @@ function getPageContextExports(pageFiles, pageConfig) {
|
|
|
46
58
|
configDefinedAt,
|
|
47
59
|
configDefinedByFile: configValueFilePathToShowToUser
|
|
48
60
|
});
|
|
61
|
+
if (configValue.type === 'standard') {
|
|
62
|
+
const src = {
|
|
63
|
+
type: 'configsStandard',
|
|
64
|
+
value: configValue.value,
|
|
65
|
+
definedAt: (0, getConfigDefinedAt_js_1.getDefinedAtString)(configValue.definedAtData, configName)
|
|
66
|
+
};
|
|
67
|
+
addSrc(src, configName);
|
|
68
|
+
from.configsStandard[configName] = src;
|
|
69
|
+
}
|
|
70
|
+
if (configValue.type === 'cumulative') {
|
|
71
|
+
const src = {
|
|
72
|
+
type: 'configsCumulative',
|
|
73
|
+
values: configValue.value.map((value, i) => {
|
|
74
|
+
const definedAtFile = configValue.definedAtData[i];
|
|
75
|
+
(0, utils_js_1.assert)(definedAtFile);
|
|
76
|
+
const definedAt = (0, getConfigDefinedAt_js_1.getDefinedAtString)(definedAtFile, configName);
|
|
77
|
+
return {
|
|
78
|
+
value,
|
|
79
|
+
definedAt
|
|
80
|
+
};
|
|
81
|
+
})
|
|
82
|
+
};
|
|
83
|
+
addSrc(src, configName);
|
|
84
|
+
from.configsCumulative[configName] = src;
|
|
85
|
+
}
|
|
86
|
+
if (configValue.type === 'computed') {
|
|
87
|
+
const src = {
|
|
88
|
+
type: 'configsComputed',
|
|
89
|
+
value: configValue.value
|
|
90
|
+
};
|
|
91
|
+
addSrc(src, configName);
|
|
92
|
+
from.configsComputed[configName] = src;
|
|
93
|
+
}
|
|
49
94
|
// TODO/v1-release: remove
|
|
50
95
|
const exportName = configName;
|
|
51
96
|
exportsAll[exportName] = exportsAll[exportName] ?? [];
|
|
@@ -75,9 +120,12 @@ function getPageContextExports(pageFiles, pageConfig) {
|
|
|
75
120
|
(0, utils_js_1.assert)(!('default' in exports));
|
|
76
121
|
(0, utils_js_1.assert)(!('default' in exportsAll));
|
|
77
122
|
const pageContextExports = {
|
|
123
|
+
from,
|
|
124
|
+
source,
|
|
125
|
+
sources,
|
|
126
|
+
// TODO/eventually: deprecate/remove every prop below
|
|
78
127
|
config,
|
|
79
128
|
configEntries,
|
|
80
|
-
// TODO/v1-release: remove
|
|
81
129
|
exports,
|
|
82
130
|
exportsAll,
|
|
83
131
|
pageExports
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseGlobResults = void 0;
|
|
4
|
+
// TODO/v1-release: remove old design code, and remove all assertions.
|
|
4
5
|
const utils_js_1 = require("../utils.js");
|
|
5
6
|
const assert_exports_old_design_js_1 = require("./assert_exports_old_design.js");
|
|
6
7
|
const getPageFileObject_js_1 = require("./getPageFileObject.js");
|
|
7
8
|
const fileTypes_js_1 = require("./fileTypes.js");
|
|
8
|
-
const assertPageConfigsSerialized_js_1 = require("../page-configs/serialize/assertPageConfigsSerialized.js");
|
|
9
9
|
const parsePageConfigs_js_1 = require("../page-configs/serialize/parsePageConfigs.js");
|
|
10
10
|
function parseGlobResults(pageFilesExports) {
|
|
11
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'isGeneratedFile'));
|
|
12
|
-
(0, utils_js_1.assert)(pageFilesExports.isGeneratedFile !== false, `vike was re-installed(/re-built). Restart your app.`);
|
|
13
|
-
(0, utils_js_1.assert)(pageFilesExports.isGeneratedFile === true, `\`isGeneratedFile === ${pageFilesExports.isGeneratedFile}\``);
|
|
14
11
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageFilesLazy', 'object'));
|
|
15
12
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageFilesEager', 'object'));
|
|
16
13
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageFilesExportNamesLazy', 'object'));
|
|
@@ -21,8 +18,8 @@ function parseGlobResults(pageFilesExports) {
|
|
|
21
18
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageConfigsSerialized'));
|
|
22
19
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageFilesExports, 'pageConfigGlobalSerialized'));
|
|
23
20
|
const { pageConfigsSerialized, pageConfigGlobalSerialized } = pageFilesExports;
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
assertPageConfigsSerialized(pageConfigsSerialized);
|
|
22
|
+
assertPageConfigGlobalSerialized(pageConfigGlobalSerialized);
|
|
26
23
|
const { pageConfigs, pageConfigGlobal } = (0, parsePageConfigs_js_1.parsePageConfigs)(pageConfigsSerialized, pageConfigGlobalSerialized);
|
|
27
24
|
const pageFilesMap = {};
|
|
28
25
|
parseGlobResult(pageFilesExports.pageFilesLazy).forEach(({ filePath, pageFile, globValue }) => {
|
|
@@ -43,8 +40,6 @@ function parseGlobResults(pageFilesExports) {
|
|
|
43
40
|
pageFile.loadExportNames = async () => {
|
|
44
41
|
if (!('exportNames' in pageFile)) {
|
|
45
42
|
const moduleExports = await loadModule();
|
|
46
|
-
// Vite 2 seems to choke following assertion: https://github.com/vikejs/vike/issues/455
|
|
47
|
-
(0, utils_js_1.assertUsage)('exportNames' in moduleExports, 'You seem to be using Vite 2 but the latest vike versions only work with Vite 3');
|
|
48
43
|
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(moduleExports, 'exportNames', 'string[]'), pageFile.filePath);
|
|
49
44
|
pageFile.exportNames = moduleExports.exportNames;
|
|
50
45
|
}
|
|
@@ -91,3 +86,15 @@ function parseGlobResult(globObject) {
|
|
|
91
86
|
function assertLoadModule(globValue) {
|
|
92
87
|
(0, utils_js_1.assert)((0, utils_js_1.isCallable)(globValue));
|
|
93
88
|
}
|
|
89
|
+
function assertPageConfigsSerialized(pageConfigsSerialized) {
|
|
90
|
+
(0, utils_js_1.assert)((0, utils_js_1.isArray)(pageConfigsSerialized));
|
|
91
|
+
pageConfigsSerialized.forEach((pageConfigSerialized) => {
|
|
92
|
+
(0, utils_js_1.assert)((0, utils_js_1.isObject)(pageConfigSerialized));
|
|
93
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'pageId', 'string'));
|
|
94
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'routeFilesystem'));
|
|
95
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'configValuesSerialized'));
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function assertPageConfigGlobalSerialized(pageConfigGlobalSerialized) {
|
|
99
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigGlobalSerialized, 'configValuesSerialized'));
|
|
100
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isUserHookError = exports.executeHook = void 0;
|
|
3
|
+
exports.isUserHookError = exports.getPageContext = exports.executeHook = void 0;
|
|
4
4
|
const assert_js_1 = require("../../utils/assert.js");
|
|
5
5
|
const getGlobalObject_js_1 = require("../../utils/getGlobalObject.js");
|
|
6
6
|
const humanizeTime_js_1 = require("../../utils/humanizeTime.js");
|
|
7
7
|
const isObject_js_1 = require("../../utils/isObject.js");
|
|
8
8
|
const globalObject = (0, getGlobalObject_js_1.getGlobalObject)('utils/executeHook.ts', {
|
|
9
|
-
userHookErrors: new WeakMap()
|
|
9
|
+
userHookErrors: new WeakMap(),
|
|
10
|
+
pageContext: null
|
|
10
11
|
});
|
|
11
12
|
function isUserHookError(err) {
|
|
12
13
|
if (!(0, isObject_js_1.isObject)(err))
|
|
@@ -14,7 +15,7 @@ function isUserHookError(err) {
|
|
|
14
15
|
return globalObject.userHookErrors.get(err) ?? false;
|
|
15
16
|
}
|
|
16
17
|
exports.isUserHookError = isUserHookError;
|
|
17
|
-
function executeHook(hookFnCaller, hook) {
|
|
18
|
+
function executeHook(hookFnCaller, hook, pageContext) {
|
|
18
19
|
const { hookName, hookFilePath, hookTimeout: { error: timeoutErr, warning: timeoutWarn } } = hook;
|
|
19
20
|
let resolve;
|
|
20
21
|
let reject;
|
|
@@ -45,6 +46,7 @@ function executeHook(hookFnCaller, hook) {
|
|
|
45
46
|
}, timeoutErr);
|
|
46
47
|
(async () => {
|
|
47
48
|
try {
|
|
49
|
+
providePageContext(pageContext);
|
|
48
50
|
const ret = await hookFnCaller();
|
|
49
51
|
resolve(ret);
|
|
50
52
|
}
|
|
@@ -61,3 +63,20 @@ exports.executeHook = executeHook;
|
|
|
61
63
|
function isNotDisabled(timeout) {
|
|
62
64
|
return !!timeout && timeout !== Infinity;
|
|
63
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* Access `pageContext` object inside Vike hooks, in order to create universal hooks.
|
|
68
|
+
*
|
|
69
|
+
* https://vike.dev/getPageContext
|
|
70
|
+
*/
|
|
71
|
+
function getPageContext() {
|
|
72
|
+
return globalObject.pageContext;
|
|
73
|
+
}
|
|
74
|
+
exports.getPageContext = getPageContext;
|
|
75
|
+
function providePageContext(pageContext) {
|
|
76
|
+
globalObject.pageContext = pageContext;
|
|
77
|
+
// Promise.resolve() is quicker than process.nextTick() and setImmediate()
|
|
78
|
+
// https://stackoverflow.com/questions/67949576/process-nexttick-before-promise-resolve-then
|
|
79
|
+
Promise.resolve().then(() => {
|
|
80
|
+
globalObject.pageContext = null;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
@@ -31,8 +31,8 @@ function getHook(pageContext, hookName) {
|
|
|
31
31
|
}
|
|
32
32
|
exports.getHook = getHook;
|
|
33
33
|
function getHookFromPageConfig(pageConfig, hookName) {
|
|
34
|
-
const configValue = (0, getConfigValue_js_1.
|
|
35
|
-
const hooksTimeout = (0, getConfigValue_js_1.
|
|
34
|
+
const configValue = (0, getConfigValue_js_1.getConfigValueRuntime)(pageConfig, hookName);
|
|
35
|
+
const hooksTimeout = (0, getConfigValue_js_1.getConfigValueRuntime)(pageConfig, 'hooksTimeout')?.value;
|
|
36
36
|
if (!configValue)
|
|
37
37
|
return null;
|
|
38
38
|
const hookFn = configValue.value;
|
|
@@ -3,22 +3,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.getConfigValueTyped = exports.getConfigValueRuntime = void 0;
|
|
7
7
|
const utils_js_1 = require("../utils.js");
|
|
8
8
|
const picocolors_1 = __importDefault(require("@brillout/picocolors"));
|
|
9
9
|
const getConfigDefinedAt_js_1 = require("./getConfigDefinedAt.js");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return null;
|
|
10
|
+
function getConfigValueTyped(configValue, configName, type) {
|
|
11
|
+
/* [NULL_HANDLING] Do we really need this? This doesn't seem to make sense, let's eventually (re)move this.
|
|
12
|
+
// Enable users to suppress global config values by setting the local config value to null
|
|
13
|
+
if (configValue.value === null) return null
|
|
14
|
+
*/
|
|
16
15
|
const { value, definedAtData } = configValue;
|
|
17
16
|
if (type)
|
|
18
17
|
assertConfigValueType(value, type, configName, definedAtData);
|
|
19
18
|
return configValue;
|
|
20
19
|
}
|
|
21
|
-
exports.
|
|
20
|
+
exports.getConfigValueTyped = getConfigValueTyped;
|
|
21
|
+
function getConfigValueRuntime(pageConfig, configName, type) {
|
|
22
|
+
const configValue = pageConfig.configValues[configName];
|
|
23
|
+
if (!configValue)
|
|
24
|
+
return null;
|
|
25
|
+
return getConfigValueTyped(configValue, configName, type);
|
|
26
|
+
}
|
|
27
|
+
exports.getConfigValueRuntime = getConfigValueRuntime;
|
|
22
28
|
function assertConfigValueType(value, type, configName, definedAtData) {
|
|
23
29
|
(0, utils_js_1.assert)(value !== null);
|
|
24
30
|
const typeActual = typeof value;
|
|
@@ -32,12 +38,3 @@ function assertConfigValueType(value, type, configName, definedAtData) {
|
|
|
32
38
|
const errMsg = `${configDefinedAt} has an invalid ${problem}: it should be a ${picocolors_1.default.cyan(type)} instead`;
|
|
33
39
|
(0, utils_js_1.assertUsage)(false, errMsg);
|
|
34
40
|
}
|
|
35
|
-
function getConfigValueEntry(pageConfig, configName) {
|
|
36
|
-
const configValue = pageConfig.configValues[configName];
|
|
37
|
-
if (!configValue)
|
|
38
|
-
return null;
|
|
39
|
-
// Enable users to suppress global config values by setting the local config value to null
|
|
40
|
-
if (configValue.value === null)
|
|
41
|
-
return null;
|
|
42
|
-
return configValue;
|
|
43
|
-
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConfigValueBuildTime = void 0;
|
|
4
|
+
const utils_js_1 = require("../utils.js");
|
|
5
|
+
const getConfigValue_js_1 = require("./getConfigValue.js");
|
|
6
|
+
const assertIsNotProductionRuntime_js_1 = require("../../utils/assertIsNotProductionRuntime.js");
|
|
7
|
+
(0, assertIsNotProductionRuntime_js_1.assertIsNotProductionRuntime)();
|
|
8
|
+
function getConfigValueBuildTime(pageConfig, configName, type) {
|
|
9
|
+
const configValue = getConfigValue(pageConfig, configName);
|
|
10
|
+
if (!configValue)
|
|
11
|
+
return null;
|
|
12
|
+
return (0, getConfigValue_js_1.getConfigValueTyped)(configValue, configName, type);
|
|
13
|
+
}
|
|
14
|
+
exports.getConfigValueBuildTime = getConfigValueBuildTime;
|
|
15
|
+
function getConfigValue(pageConfig, configName) {
|
|
16
|
+
const { configValueSources, configValuesComputed, configDefinitions } = pageConfig;
|
|
17
|
+
const configValueComputed = configValuesComputed[configName];
|
|
18
|
+
if (configValueComputed) {
|
|
19
|
+
return {
|
|
20
|
+
type: 'computed',
|
|
21
|
+
value: configValueComputed.value,
|
|
22
|
+
definedAtData: null
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
const sources = configValueSources[configName];
|
|
26
|
+
if (!sources)
|
|
27
|
+
return null;
|
|
28
|
+
(0, utils_js_1.assert)(sources.every((s) => s.configEnv.config === true));
|
|
29
|
+
const configDef = configDefinitions[configName];
|
|
30
|
+
(0, utils_js_1.assert)(configDef);
|
|
31
|
+
if (!configDef.cumulative) {
|
|
32
|
+
const configValueSource = sources[0];
|
|
33
|
+
(0, utils_js_1.assert)(configValueSource);
|
|
34
|
+
(0, utils_js_1.assert)(configValueSource.isOverriden === false);
|
|
35
|
+
(0, utils_js_1.assert)(sources.slice(1).every((s) => s.isOverriden === true));
|
|
36
|
+
(0, utils_js_1.assert)('value' in configValueSource);
|
|
37
|
+
return {
|
|
38
|
+
type: 'standard',
|
|
39
|
+
value: configValueSource.value,
|
|
40
|
+
definedAtData: getDefinedAtFile(configValueSource)
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
const { value, definedAtData } = mergeCumulative(sources);
|
|
45
|
+
(0, utils_js_1.assert)(value.length === definedAtData.length);
|
|
46
|
+
return {
|
|
47
|
+
type: 'cumulative',
|
|
48
|
+
value,
|
|
49
|
+
definedAtData
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function mergeCumulative(configValueSources) {
|
|
54
|
+
const value = [];
|
|
55
|
+
const definedAtData = [];
|
|
56
|
+
configValueSources.forEach((configValueSource) => {
|
|
57
|
+
(0, utils_js_1.assert)(configValueSource.isOverriden === false);
|
|
58
|
+
(0, utils_js_1.assert)(configValueSource.configEnv.config === true);
|
|
59
|
+
(0, utils_js_1.assert)('value' in configValueSource);
|
|
60
|
+
value.push(configValueSource.value);
|
|
61
|
+
definedAtData.push(getDefinedAtFile(configValueSource));
|
|
62
|
+
});
|
|
63
|
+
return { value, definedAtData };
|
|
64
|
+
}
|
|
65
|
+
function getDefinedAtFile(configValueSource) {
|
|
66
|
+
return {
|
|
67
|
+
filePathToShowToUser: configValueSource.definedAtFilePath.filePathToShowToUser,
|
|
68
|
+
fileExportPathToShowToUser: configValueSource.definedAtFilePath.fileExportPathToShowToUser
|
|
69
|
+
};
|
|
70
|
+
}
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadConfigValues = void 0;
|
|
4
4
|
const utils_js_1 = require("../utils.js");
|
|
5
|
-
const
|
|
6
|
-
const parseConfigValuesSerialized_js_1 = require("./serialize/parseConfigValuesSerialized.js");
|
|
5
|
+
const parsePageConfigs_js_1 = require("./serialize/parsePageConfigs.js");
|
|
7
6
|
async function loadConfigValues(pageConfig, isDev) {
|
|
8
7
|
if ('isAllLoaded' in pageConfig &&
|
|
9
8
|
// We don't need to cache in dev, since Vite already caches the virtual module
|
|
@@ -11,16 +10,8 @@ async function loadConfigValues(pageConfig, isDev) {
|
|
|
11
10
|
return pageConfig;
|
|
12
11
|
}
|
|
13
12
|
const configValuesLoaded = await pageConfig.loadConfigValuesAll();
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const configValuesAddendum = (0, parseConfigValuesImported_js_1.parseConfigValuesImported)(configValuesImported);
|
|
17
|
-
Object.assign(pageConfig.configValues, configValuesAddendum);
|
|
18
|
-
}
|
|
19
|
-
{
|
|
20
|
-
const { configValuesSerialized } = configValuesLoaded;
|
|
21
|
-
const configValuesAddendum = (0, parseConfigValuesSerialized_js_1.parseConfigValuesSerialized)(configValuesSerialized);
|
|
22
|
-
Object.assign(pageConfig.configValues, configValuesAddendum);
|
|
23
|
-
}
|
|
13
|
+
const configValues = (0, parsePageConfigs_js_1.parseConfigValuesSerialized)(configValuesLoaded.configValuesSerialized);
|
|
14
|
+
Object.assign(pageConfig.configValues, configValues);
|
|
24
15
|
(0, utils_js_1.objectAssign)(pageConfig, { isAllLoaded: true });
|
|
25
16
|
return pageConfig;
|
|
26
17
|
}
|
|
@@ -1,19 +1 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.assertPageConfigGlobalSerialized = exports.assertPageConfigsSerialized = void 0;
|
|
4
|
-
const utils_js_1 = require("../../utils.js");
|
|
5
|
-
function assertPageConfigsSerialized(pageConfigsSerialized) {
|
|
6
|
-
(0, utils_js_1.assert)((0, utils_js_1.isArray)(pageConfigsSerialized));
|
|
7
|
-
pageConfigsSerialized.forEach((pageConfigSerialized) => {
|
|
8
|
-
(0, utils_js_1.assert)((0, utils_js_1.isObject)(pageConfigSerialized));
|
|
9
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'pageId', 'string'));
|
|
10
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'routeFilesystem'));
|
|
11
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'configValuesSerialized'));
|
|
12
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigSerialized, 'configValuesImported'));
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
exports.assertPageConfigsSerialized = assertPageConfigsSerialized;
|
|
16
|
-
function assertPageConfigGlobalSerialized(pageConfigGlobalSerialized) {
|
|
17
|
-
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(pageConfigGlobalSerialized, 'configValuesImported'));
|
|
18
|
-
}
|
|
19
|
-
exports.assertPageConfigGlobalSerialized = assertPageConfigGlobalSerialized;
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parsePageConfigs = void 0;
|
|
4
|
-
const parseConfigValuesImported_js_1 = require("./parseConfigValuesImported.js");
|
|
3
|
+
exports.parseConfigValuesSerialized = exports.parsePageConfigs = void 0;
|
|
5
4
|
const utils_js_1 = require("../../utils.js");
|
|
6
5
|
const getConfigDefinedAt_js_1 = require("../getConfigDefinedAt.js");
|
|
7
|
-
const
|
|
6
|
+
const parse_1 = require("@brillout/json-serializer/parse");
|
|
7
|
+
const assertPlusFileExport_js_1 = require("../assertPlusFileExport.js");
|
|
8
|
+
function parseConfigValuesSerialized(configValuesSerialized) {
|
|
9
|
+
const configValues = parseConfigValuesSerialized_tmp(configValuesSerialized);
|
|
10
|
+
return configValues;
|
|
11
|
+
}
|
|
12
|
+
exports.parseConfigValuesSerialized = parseConfigValuesSerialized;
|
|
8
13
|
function parsePageConfigs(pageConfigsSerialized, pageConfigGlobalSerialized) {
|
|
14
|
+
// pageConfigs
|
|
9
15
|
const pageConfigs = pageConfigsSerialized.map((pageConfigSerialized) => {
|
|
10
|
-
const configValues =
|
|
11
|
-
{
|
|
12
|
-
const { configValuesSerialized } = pageConfigSerialized;
|
|
13
|
-
const configValuesAddendum = (0, parseConfigValuesSerialized_js_1.parseConfigValuesSerialized)(configValuesSerialized);
|
|
14
|
-
Object.assign(configValues, configValuesAddendum);
|
|
15
|
-
}
|
|
16
|
-
{
|
|
17
|
-
const { configValuesImported } = pageConfigSerialized;
|
|
18
|
-
const configValuesAddendum = (0, parseConfigValuesImported_js_1.parseConfigValuesImported)(configValuesImported);
|
|
19
|
-
Object.assign(configValues, configValuesAddendum);
|
|
20
|
-
}
|
|
16
|
+
const configValues = parseConfigValuesSerialized(pageConfigSerialized.configValuesSerialized);
|
|
21
17
|
const { pageId, isErrorPage, routeFilesystem, loadConfigValuesAll } = pageConfigSerialized;
|
|
22
18
|
assertRouteConfigValue(configValues);
|
|
23
19
|
return {
|
|
@@ -28,10 +24,11 @@ function parsePageConfigs(pageConfigsSerialized, pageConfigGlobalSerialized) {
|
|
|
28
24
|
loadConfigValuesAll
|
|
29
25
|
};
|
|
30
26
|
});
|
|
27
|
+
// pageConfigsGlobal
|
|
31
28
|
const pageConfigGlobal = { configValues: {} };
|
|
32
29
|
{
|
|
33
|
-
const
|
|
34
|
-
Object.assign(pageConfigGlobal.configValues,
|
|
30
|
+
const configValues = parseConfigValuesSerialized(pageConfigGlobalSerialized.configValuesSerialized);
|
|
31
|
+
Object.assign(pageConfigGlobal.configValues, configValues);
|
|
35
32
|
}
|
|
36
33
|
return { pageConfigs, pageConfigGlobal };
|
|
37
34
|
}
|
|
@@ -55,3 +52,100 @@ function assertRouteConfigValue(configValues) {
|
|
|
55
52
|
}
|
|
56
53
|
*/
|
|
57
54
|
}
|
|
55
|
+
function parseConfigValuesSerialized_tmp(configValuesSerialized) {
|
|
56
|
+
const configValues = {};
|
|
57
|
+
Object.entries(configValuesSerialized).forEach(([configName, configValueSeriliazed]) => {
|
|
58
|
+
let configValue;
|
|
59
|
+
if (configValueSeriliazed.type === 'cumulative') {
|
|
60
|
+
const { valueSerialized, ...common } = configValueSeriliazed;
|
|
61
|
+
const value = valueSerialized.map((valueSerializedElement, i) => {
|
|
62
|
+
const { value, sideExports } = parseValueSerialized(valueSerializedElement, configName, () => {
|
|
63
|
+
const definedAtFile = configValueSeriliazed.definedAtData[i];
|
|
64
|
+
(0, utils_js_1.assert)(definedAtFile);
|
|
65
|
+
return definedAtFile;
|
|
66
|
+
});
|
|
67
|
+
addSideExports(sideExports);
|
|
68
|
+
return value;
|
|
69
|
+
});
|
|
70
|
+
configValue = { value, ...common };
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const { valueSerialized, ...common } = configValueSeriliazed;
|
|
74
|
+
const { value, sideExports } = parseValueSerialized(valueSerialized, configName, () => {
|
|
75
|
+
(0, utils_js_1.assert)(configValueSeriliazed.type !== 'computed');
|
|
76
|
+
return configValueSeriliazed.definedAtData;
|
|
77
|
+
});
|
|
78
|
+
addSideExports(sideExports);
|
|
79
|
+
configValue = { value, ...common };
|
|
80
|
+
}
|
|
81
|
+
configValues[configName] = configValue;
|
|
82
|
+
});
|
|
83
|
+
return configValues;
|
|
84
|
+
function addSideExports(sideExports) {
|
|
85
|
+
sideExports.forEach((sideExport) => {
|
|
86
|
+
const { configName, configValue } = sideExport;
|
|
87
|
+
if (!configValues[configName]) {
|
|
88
|
+
configValues[configName] = configValue;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
// Side-exports have lower precedence.
|
|
92
|
+
// We can't avoid side-export conflicts upstream. (We cannot know about side-exports at build-time.)
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function parseValueSerialized(valueSerialized, configName, getDefinedAtFile) {
|
|
98
|
+
if (valueSerialized.type === 'js-serialized') {
|
|
99
|
+
let { value } = valueSerialized;
|
|
100
|
+
value = (0, parse_1.parseTransform)(value);
|
|
101
|
+
return { value, sideExports: [] };
|
|
102
|
+
}
|
|
103
|
+
if (valueSerialized.type === 'pointer-import') {
|
|
104
|
+
const { value } = valueSerialized;
|
|
105
|
+
return { value, sideExports: [] };
|
|
106
|
+
}
|
|
107
|
+
if (valueSerialized.type === 'plus-file') {
|
|
108
|
+
const definedAtFile = getDefinedAtFile();
|
|
109
|
+
const { exportValues } = valueSerialized;
|
|
110
|
+
(0, assertPlusFileExport_js_1.assertPlusFileExport)(exportValues, definedAtFile.filePathToShowToUser, configName);
|
|
111
|
+
let value;
|
|
112
|
+
let valueWasFound = false;
|
|
113
|
+
const sideExports = [];
|
|
114
|
+
Object.entries(exportValues).forEach(([exportName, exportValue]) => {
|
|
115
|
+
const isSideExport = exportName !== 'default' && exportName !== configName;
|
|
116
|
+
if (!isSideExport) {
|
|
117
|
+
value = exportValue;
|
|
118
|
+
(0, utils_js_1.assert)(!valueWasFound);
|
|
119
|
+
valueWasFound = true;
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
sideExports.push({
|
|
123
|
+
configName: exportName,
|
|
124
|
+
configValue: {
|
|
125
|
+
type: 'standard', // We don't support side exports for cumulative values. We could support it but it isn't trivial.
|
|
126
|
+
value: exportValue,
|
|
127
|
+
definedAtData: {
|
|
128
|
+
filePathToShowToUser: definedAtFile.filePathToShowToUser,
|
|
129
|
+
fileExportPathToShowToUser: [exportName]
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
(0, utils_js_1.assert)(valueWasFound);
|
|
136
|
+
return { value, sideExports };
|
|
137
|
+
}
|
|
138
|
+
(0, utils_js_1.assert)(false);
|
|
139
|
+
}
|
|
140
|
+
/* [NULL_HANDLING] Do we really need this?
|
|
141
|
+
function assertIsNotNull(configValue: unknown, configName: string, filePathToShowToUser: string) {
|
|
142
|
+
assert(!filePathToShowToUser.includes('+config.'))
|
|
143
|
+
// Re-use this for:
|
|
144
|
+
// - upcoming config.requestPageContextOnNavigation
|
|
145
|
+
// - for cumulative values in the future: we don't need this for now because, currently, cumulative values are never imported.
|
|
146
|
+
assertUsage(
|
|
147
|
+
configValue !== null,
|
|
148
|
+
`Set ${pc.cyan(configName)} to ${pc.cyan('null')} in a +config.js file instead of ${filePathToShowToUser}`
|
|
149
|
+
)
|
|
150
|
+
}
|
|
151
|
+
*/
|