vike 0.4.236-commit-eab75f6 → 0.4.237
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/client/shared/createGetGlobalContextClient.js +2 -4
- package/dist/cjs/node/runtime/html/serializeContext.js +8 -47
- package/dist/cjs/node/runtime/html/stream.js +1 -1
- package/dist/cjs/node/runtime/renderPage/createPageContextServerSide.js +4 -7
- package/dist/cjs/node/runtime/renderPage/handlePageContextRequestUrl.js +50 -14
- package/dist/cjs/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +19 -6
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -3
- package/dist/cjs/node/runtime/renderPage.js +7 -6
- package/dist/cjs/node/vite/plugins/pluginDev/determineOptimizeDeps.js +45 -43
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +67 -0
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +1 -2
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +2 -3
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
- package/dist/cjs/node/vite/shared/resolveVikeConfigInternal.js +7 -18
- package/dist/cjs/shared/createGlobalContextShared.js +13 -0
- package/dist/cjs/shared/modifyUrlSameOrigin.js +9 -4
- package/dist/cjs/shared/page-configs/serialize/serializeConfigValues.js +12 -13
- package/dist/cjs/shared/utils.js +2 -0
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/cast.js +1 -1
- package/dist/esm/client/runtime-client-routing/getPageContextFromHooks.js +35 -48
- package/dist/esm/client/runtime-client-routing/history.d.ts +3 -5
- package/dist/esm/client/runtime-client-routing/history.js +39 -22
- package/dist/esm/client/runtime-client-routing/initClientRouter.js +2 -3
- package/dist/esm/client/runtime-client-routing/utils.d.ts +2 -0
- package/dist/esm/client/runtime-client-routing/utils.js +2 -0
- package/dist/esm/client/shared/createGetGlobalContextClient.js +2 -4
- package/dist/esm/node/runtime/html/serializeContext.d.ts +8 -3
- package/dist/esm/node/runtime/html/serializeContext.js +8 -47
- package/dist/esm/node/runtime/html/stream.js +1 -1
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/createPageContextServerSide.js +4 -7
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/handlePageContextRequestUrl.js +51 -15
- package/dist/esm/node/runtime/renderPage/loadPageConfigsLazyServerSide.js +20 -7
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForPublicUsageServer.d.ts +0 -1
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +4 -5
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +1 -3
- package/dist/esm/node/runtime/renderPage.d.ts +1 -0
- package/dist/esm/node/runtime/renderPage.js +7 -6
- package/dist/esm/node/vite/plugins/pluginDev/determineOptimizeDeps.js +46 -44
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.d.ts +14 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getConfigValueSourcesRelevant.js +65 -0
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigLazy.js +1 -2
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/getVirtualFilePageConfigsEager.js +2 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.d.ts +2 -2
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal/configDefinitionsBuiltIn.js +31 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.d.ts +1 -3
- package/dist/esm/node/vite/shared/resolveVikeConfigInternal.js +8 -19
- package/dist/esm/shared/createGlobalContextShared.js +14 -1
- package/dist/esm/shared/modifyUrlSameOrigin.d.ts +1 -1
- package/dist/esm/shared/modifyUrlSameOrigin.js +9 -4
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.d.ts +3 -2
- package/dist/esm/shared/page-configs/serialize/serializeConfigValues.js +12 -13
- package/dist/esm/shared/utils.d.ts +2 -0
- package/dist/esm/shared/utils.js +2 -0
- package/dist/esm/types/Config.d.ts +33 -98
- package/dist/esm/types/index.d.ts +3 -1
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/cast.d.ts +2 -2
- package/dist/esm/utils/cast.js +1 -1
- package/dist/esm/utils/objectFilter.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -23
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.d.ts +0 -7
- package/dist/esm/node/vite/plugins/pluginVirtualFiles/isRuntimeEnvMatch.js +0 -21
|
@@ -20,10 +20,8 @@ function createGetGlobalContextClient(virtualFileExports, isClientRouting, addGl
|
|
|
20
20
|
getGlobalContext();
|
|
21
21
|
return getGlobalContext;
|
|
22
22
|
async function getGlobalContext() {
|
|
23
|
-
//
|
|
24
|
-
if (globalObject.virtualFileExports
|
|
25
|
-
// Don't break HMR
|
|
26
|
-
globalObject.virtualFileExports === virtualFileExports) {
|
|
23
|
+
// HMR => virtualFileExports differ
|
|
24
|
+
if (globalObject.virtualFileExports === virtualFileExports) {
|
|
27
25
|
const globalContext = await globalObject.globalContextPromise;
|
|
28
26
|
return globalContext;
|
|
29
27
|
}
|
|
@@ -32,41 +32,24 @@ const passToClientBuiltInPageContext = [
|
|
|
32
32
|
const pageToClientBuiltInPageContextError = ['pageProps', 'is404', isServerSideError_js_1.isServerSideError];
|
|
33
33
|
function getPageContextClientSerialized(pageContext, isHtmlJsonScript) {
|
|
34
34
|
const passToClientPageContext = getPassToClientPageContext(pageContext);
|
|
35
|
-
const
|
|
36
|
-
if (passToClientEntry.once)
|
|
37
|
-
return undefined; // pass it to client-side globalContext
|
|
38
|
-
return { obj: pageContext, objName: 'pageContext' };
|
|
39
|
-
};
|
|
40
|
-
const res = applyPassToClient(passToClientPageContext, getObj);
|
|
35
|
+
const res = applyPassToClient(passToClientPageContext, pageContext);
|
|
41
36
|
const pageContextClient = res.objClient;
|
|
42
37
|
const pageContextClientProps = res.objClientProps;
|
|
43
38
|
if (pageContextClientProps.some((prop) => (0, propKeys_js_1.getPropVal)(pageContext._pageContextInit, prop))) {
|
|
44
39
|
pageContextClient[pageContextInitIsPassedToClient_js_1.pageContextInitIsPassedToClient] = true;
|
|
45
40
|
}
|
|
46
|
-
const pageContextClientSerialized = serializeObject(pageContextClient, passToClientPageContext,
|
|
41
|
+
const pageContextClientSerialized = serializeObject(pageContextClient, passToClientPageContext, 'pageContext', isHtmlJsonScript);
|
|
47
42
|
return pageContextClientSerialized;
|
|
48
43
|
}
|
|
49
44
|
function getGlobalContextClientSerialized(pageContext, isHtmlJsonScript) {
|
|
50
45
|
const passToClient = pageContext._passToClient;
|
|
51
46
|
const globalContext = pageContext._globalContext;
|
|
52
|
-
const
|
|
53
|
-
if (once && (0, propKeys_js_1.getPropVal)(pageContext, prop)) {
|
|
54
|
-
(0, utils_js_1.assert)(typeof pageContext.isClientSideNavigation === 'boolean');
|
|
55
|
-
if (!pageContext.isClientSideNavigation) {
|
|
56
|
-
return { obj: pageContext, objName: 'pageContext' }; // pass it to client-side globalContext
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
return undefined; // already passed to client-side
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return { obj: globalContext, objName: 'globalContext' };
|
|
63
|
-
};
|
|
64
|
-
const res = applyPassToClient(passToClient, getObj);
|
|
47
|
+
const res = applyPassToClient(passToClient, globalContext);
|
|
65
48
|
const globalContextClient = res.objClient;
|
|
66
|
-
const globalContextClientSerialized = serializeObject(globalContextClient, passToClient,
|
|
49
|
+
const globalContextClientSerialized = serializeObject(globalContextClient, passToClient, 'globalContext', isHtmlJsonScript);
|
|
67
50
|
return globalContextClientSerialized;
|
|
68
51
|
}
|
|
69
|
-
function serializeObject(obj, passToClient,
|
|
52
|
+
function serializeObject(obj, passToClient, objName, isHtmlJsonScript) {
|
|
70
53
|
let serialized;
|
|
71
54
|
try {
|
|
72
55
|
serialized = serializeValue(obj, isHtmlJsonScript);
|
|
@@ -75,15 +58,11 @@ function serializeObject(obj, passToClient, getObj, isHtmlJsonScript) {
|
|
|
75
58
|
const h = (s) => picocolors_1.default.cyan(s);
|
|
76
59
|
let hasWarned = false;
|
|
77
60
|
const propsNonSerializable = [];
|
|
78
|
-
passToClient.forEach((
|
|
79
|
-
const entryNormalized = normalizePassToClientEntry(entry);
|
|
80
|
-
const { prop } = entryNormalized;
|
|
61
|
+
passToClient.forEach((prop) => {
|
|
81
62
|
const res = (0, propKeys_js_1.getPropVal)(obj, prop);
|
|
82
63
|
if (!res)
|
|
83
64
|
return;
|
|
84
65
|
const { value } = res;
|
|
85
|
-
const { objName } = getObj(entryNormalized) ?? {};
|
|
86
|
-
(0, utils_js_1.assert)(objName);
|
|
87
66
|
const varName = `${objName}${(0, propKeys_js_1.getPropKeys)(prop).map(utils_js_1.getPropAccessNotation).join('')}`;
|
|
88
67
|
try {
|
|
89
68
|
serializeValue(value, isHtmlJsonScript, varName);
|
|
@@ -193,15 +172,10 @@ function getPageContextClientSerializedAbort(pageContext, isHtmlJsonScript) {
|
|
|
193
172
|
}
|
|
194
173
|
return serializeValue(pageContext, isHtmlJsonScript);
|
|
195
174
|
}
|
|
196
|
-
function applyPassToClient(passToClient,
|
|
175
|
+
function applyPassToClient(passToClient, obj) {
|
|
197
176
|
const objClient = {};
|
|
198
177
|
const objClientProps = [];
|
|
199
|
-
passToClient.forEach((
|
|
200
|
-
const entryNormalized = normalizePassToClientEntry(entry);
|
|
201
|
-
const { prop } = entryNormalized;
|
|
202
|
-
const { obj } = getObj(entryNormalized) ?? {};
|
|
203
|
-
if (!obj)
|
|
204
|
-
return;
|
|
178
|
+
passToClient.forEach((prop) => {
|
|
205
179
|
// Get value from pageContext
|
|
206
180
|
const res = (0, propKeys_js_1.getPropVal)(obj, prop);
|
|
207
181
|
if (!res)
|
|
@@ -213,16 +187,3 @@ function applyPassToClient(passToClient, getObj) {
|
|
|
213
187
|
});
|
|
214
188
|
return { objClient, objClientProps };
|
|
215
189
|
}
|
|
216
|
-
function normalizePassToClientEntry(entry) {
|
|
217
|
-
let once;
|
|
218
|
-
let prop;
|
|
219
|
-
if (typeof entry === 'string') {
|
|
220
|
-
prop = entry;
|
|
221
|
-
once = false;
|
|
222
|
-
}
|
|
223
|
-
else {
|
|
224
|
-
prop = entry.prop;
|
|
225
|
-
once = entry.once ?? false;
|
|
226
|
-
}
|
|
227
|
-
return { prop, once };
|
|
228
|
-
}
|
|
@@ -527,8 +527,8 @@ async function createStreamWrapper({ streamOriginal, onError, onData, onEnd, onF
|
|
|
527
527
|
const closeStream = async () => {
|
|
528
528
|
if (isClosed)
|
|
529
529
|
return;
|
|
530
|
-
isClosed = true;
|
|
531
530
|
await onEnd(isCancel);
|
|
531
|
+
isClosed = true;
|
|
532
532
|
controllerProxy.close();
|
|
533
533
|
};
|
|
534
534
|
let controllerProxy;
|
|
@@ -5,12 +5,9 @@ exports.createPageContextServerSideWithoutGlobalContext = createPageContextServe
|
|
|
5
5
|
const utils_js_1 = require("../utils.js");
|
|
6
6
|
const getPageContextUrlComputed_js_1 = require("../../../shared/getPageContextUrlComputed.js");
|
|
7
7
|
const createPageContextShared_js_1 = require("../../../shared/createPageContextShared.js");
|
|
8
|
-
function createPageContextServerSide(pageContextInit, globalContext,
|
|
9
|
-
urlHandler: null,
|
|
10
|
-
isClientSideNavigation: false,
|
|
11
|
-
}, }) {
|
|
8
|
+
function createPageContextServerSide(pageContextInit, globalContext, args) {
|
|
12
9
|
(0, utils_js_1.assert)(pageContextInit.urlOriginal);
|
|
13
|
-
const pageContextCreated = createPageContext(pageContextInit, isPrerendering);
|
|
10
|
+
const pageContextCreated = createPageContext(pageContextInit, args.isPrerendering);
|
|
14
11
|
(0, utils_js_1.objectAssign)(pageContextCreated, {
|
|
15
12
|
_globalContext: globalContext,
|
|
16
13
|
_pageFilesAll: globalContext._pageFilesAll, // TO-DO/next-major-release: remove
|
|
@@ -19,8 +16,8 @@ function createPageContextServerSide(pageContextInit, globalContext, { isPrerend
|
|
|
19
16
|
_baseAssets: globalContext.baseAssets,
|
|
20
17
|
_pageContextInit: pageContextInit,
|
|
21
18
|
_urlRewrite: null,
|
|
22
|
-
_urlHandler: urlHandler,
|
|
23
|
-
isClientSideNavigation,
|
|
19
|
+
_urlHandler: args.ssr?.urlHandler ?? null,
|
|
20
|
+
isClientSideNavigation: args.ssr?.isClientSideNavigation ?? false,
|
|
24
21
|
});
|
|
25
22
|
(0, utils_js_1.objectAssign)(pageContextCreated, globalContext._vikeConfigPublicGlobal);
|
|
26
23
|
// pageContext.urlParsed
|
|
@@ -2,31 +2,67 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handlePageContextRequestUrl = handlePageContextRequestUrl;
|
|
4
4
|
const getPageContextRequestUrl_js_1 = require("../../../shared/getPageContextRequestUrl.js");
|
|
5
|
+
const modifyUrl_js_1 = require("../../../shared/modifyUrl.js");
|
|
5
6
|
const utils_js_1 = require("../utils.js");
|
|
6
7
|
// See also shared/getPageContextRequestUrl.ts
|
|
7
8
|
function handlePageContextRequestUrl(url) {
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
const urlParsed = (0, utils_js_1.parseUrl)(url, utils_js_1.baseServer);
|
|
10
|
+
if (!isMatch(urlParsed)) {
|
|
11
|
+
return {
|
|
12
|
+
isPageContextJsonRequest: false,
|
|
13
|
+
urlWithoutPageContextRequestSuffix: url,
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const { urlWithoutPageContextRequestSuffix, searchVikeArgs } = processUrl(urlParsed, url);
|
|
18
|
+
const previousUrl = parseSearchVikeArgs(searchVikeArgs);
|
|
19
|
+
return {
|
|
20
|
+
/* TO-DO/soon/once: pass & use previousUrl
|
|
21
|
+
isPageContextJsonRequest: { previousUrl },
|
|
22
|
+
/*/
|
|
23
|
+
isPageContextJsonRequest: true,
|
|
24
|
+
//*/
|
|
25
|
+
urlWithoutPageContextRequestSuffix,
|
|
26
|
+
};
|
|
10
27
|
}
|
|
11
|
-
return { urlWithoutPageContextRequestSuffix: removePageContextUrlSuffix(url), isPageContextRequest: true };
|
|
12
28
|
}
|
|
13
|
-
function
|
|
14
|
-
const { pathnameOriginal, pathname } =
|
|
15
|
-
(0, utils_js_1.assert)(
|
|
16
|
-
|
|
17
|
-
});
|
|
18
|
-
return pathnameOriginal.endsWith(getPageContextRequestUrl_js_1.pageContextJsonFileExtension);
|
|
29
|
+
function isMatch(urlParsed) {
|
|
30
|
+
const { pathnameOriginal, pathname } = urlParsed;
|
|
31
|
+
(0, utils_js_1.assert)(pathname.endsWith(getPageContextRequestUrl_js_1.pageContextJsonFileExtension) === pathnameOriginal.endsWith(getPageContextRequestUrl_js_1.pageContextJsonFileExtension));
|
|
32
|
+
return pathname.endsWith(getPageContextRequestUrl_js_1.pageContextJsonFileExtension);
|
|
19
33
|
}
|
|
20
|
-
function
|
|
21
|
-
const urlParsed = (0, utils_js_1.parseUrl)(url, utils_js_1.baseServer);
|
|
34
|
+
function processUrl(urlParsed, url) {
|
|
22
35
|
// We cannot use `urlParsed.pathname` because it would break the `urlParsed.pathnameOriginal` value of subsequent `parseUrl()` calls.
|
|
23
|
-
const {
|
|
36
|
+
const { pathnameOriginal, search } = urlParsed;
|
|
24
37
|
(0, utils_js_1.assert)(getPageContextRequestUrl_js_1.doNotCreateExtraDirectory === false);
|
|
25
38
|
const urlSuffix = `/index${getPageContextRequestUrl_js_1.pageContextJsonFileExtension}`;
|
|
26
39
|
(0, utils_js_1.assert)(pathnameOriginal.endsWith(urlSuffix), { url });
|
|
27
40
|
let pathnameModified = (0, utils_js_1.slice)(pathnameOriginal, 0, -1 * urlSuffix.length);
|
|
28
41
|
if (pathnameModified === '')
|
|
29
42
|
pathnameModified = '/';
|
|
30
|
-
|
|
31
|
-
|
|
43
|
+
const searchVikeArgs = search?._vike;
|
|
44
|
+
const urlWithoutPageContextRequestSuffix = (0, modifyUrl_js_1.modifyUrl)(url, {
|
|
45
|
+
pathname: pathnameModified,
|
|
46
|
+
search: {
|
|
47
|
+
_vike: searchVikeArgs ? null : undefined,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
return {
|
|
51
|
+
searchVikeArgs,
|
|
52
|
+
urlWithoutPageContextRequestSuffix,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
function parseSearchVikeArgs(searchVikeArgs) {
|
|
56
|
+
const args = {
|
|
57
|
+
previousUrl: null,
|
|
58
|
+
};
|
|
59
|
+
if (searchVikeArgs) {
|
|
60
|
+
const parsed = JSON.parse(searchVikeArgs);
|
|
61
|
+
(0, utils_js_1.assert)((0, utils_js_1.isObject)(parsed));
|
|
62
|
+
if ('previousUrl' in parsed) {
|
|
63
|
+
(0, utils_js_1.assert)((0, utils_js_1.hasProp)(parsed, 'previousUrl', 'string'));
|
|
64
|
+
args.previousUrl = parsed.previousUrl;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return args;
|
|
32
68
|
}
|
|
@@ -31,19 +31,32 @@ async function loadPageConfigsLazyServerSide(pageContext) {
|
|
|
31
31
|
const { isHtmlOnly, isClientRouting, clientEntries, clientDependencies, pageFilesClientSide, pageFilesServerSide } = await (0, analyzePage_js_1.analyzePage)(pageContext._globalContext._pageFilesAll, pageConfig, pageContext.pageId, globalContext);
|
|
32
32
|
const isV1Design = !!pageConfig;
|
|
33
33
|
const passToClient = [];
|
|
34
|
-
const
|
|
34
|
+
const errMsgSuffix = ' should be an array of strings.';
|
|
35
35
|
if (!isV1Design) {
|
|
36
36
|
configPublicPageLazy.exportsAll.passToClient?.forEach((e) => {
|
|
37
|
-
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(e, 'exportValue', 'string[]'), `${e.exportSource}${
|
|
37
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(e, 'exportValue', 'string[]'), `${e.exportSource}${errMsgSuffix}`);
|
|
38
38
|
passToClient.push(...e.exportValue);
|
|
39
39
|
});
|
|
40
40
|
}
|
|
41
41
|
else {
|
|
42
42
|
configPublicPageLazy.from.configsCumulative.passToClient?.values.forEach((v) => {
|
|
43
|
-
const { value } = v;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
const { value, definedAt } = v;
|
|
44
|
+
const errMsg = `+passToClient value defined at ${definedAt}${errMsgSuffix}`;
|
|
45
|
+
//*/ TO-DO/next-major-release: remove the passToClient once setting from the public API
|
|
46
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.isArray)(value), `+passToClient value defined at ${definedAt} should be an array`);
|
|
47
|
+
const valS = value.map((el) => {
|
|
48
|
+
if ((0, utils_js_1.isObject)(el)) {
|
|
49
|
+
(0, utils_js_1.assertWarning)(!('once' in el), 'The passToClient once setting is deprecated and no longer has any effect. Instead, see the upcoming .once.js suffix (see https://github.com/vikejs/vike/issues/2566 for more information).', { onlyOnce: true });
|
|
50
|
+
(0, utils_js_1.assertUsage)((0, utils_js_1.hasProp)(el, 'prop', 'string'), errMsg);
|
|
51
|
+
return el.prop;
|
|
52
|
+
}
|
|
53
|
+
(0, utils_js_1.assertUsage)(typeof el === 'string', errMsg);
|
|
54
|
+
return el;
|
|
55
|
+
});
|
|
56
|
+
/*/
|
|
57
|
+
assertUsage(isArrayOfStrings(value), errMsg)
|
|
58
|
+
//*/
|
|
59
|
+
passToClient.push(...valS);
|
|
47
60
|
});
|
|
48
61
|
}
|
|
49
62
|
const pageContextAddendum = {};
|
|
@@ -63,8 +63,7 @@ async function renderPageAlreadyRouted(pageContext) {
|
|
|
63
63
|
}
|
|
64
64
|
async function prerenderPage(pageContext) {
|
|
65
65
|
(0, utils_js_1.objectAssign)(pageContext, {
|
|
66
|
-
|
|
67
|
-
_urlHandler: null,
|
|
66
|
+
_isPageContextJsonRequest: null,
|
|
68
67
|
});
|
|
69
68
|
/* Should we execute the guard() hook upon pre-rendering? Is there a use case for this?
|
|
70
69
|
* - It isn't trivial to implement, as it requires to duplicate / factor out the isAbortError() handling
|
|
@@ -73,7 +72,6 @@ async function prerenderPage(pageContext) {
|
|
|
73
72
|
await (0, execHookDataAndOnBeforeRender_js_1.execHookDataAndOnBeforeRender)(pageContext);
|
|
74
73
|
const { htmlRender, renderHook } = await (0, execHookOnRenderHtml_js_1.execHookOnRenderHtml)(pageContext);
|
|
75
74
|
(0, utils_js_1.assertUsage)(htmlRender !== null, `Cannot pre-render ${picocolors_1.default.cyan(pageContext.urlOriginal)} because the ${renderHook.hookName}() hook defined by ${renderHook.hookFilePath} didn't return an HTML string.`);
|
|
76
|
-
(0, utils_js_1.assert)(pageContext.isClientSideNavigation === false);
|
|
77
75
|
const documentHtml = await (0, renderHtml_js_1.getHtmlString)(htmlRender);
|
|
78
76
|
(0, utils_js_1.assert)(typeof documentHtml === 'string');
|
|
79
77
|
if (!pageContext._usesClientRouter) {
|
|
@@ -312,7 +312,7 @@ async function getPageContextErrorPageInit(pageContextBegin, errNominalPage, pag
|
|
|
312
312
|
return pageContext;
|
|
313
313
|
}
|
|
314
314
|
function getPageContextBegin(pageContextInit, globalContext, httpRequestId) {
|
|
315
|
-
const { isClientSideNavigation, _urlHandler } = handlePageContextUrl(pageContextInit.urlOriginal);
|
|
315
|
+
const { isClientSideNavigation, _urlHandler, _isPageContextJsonRequest } = handlePageContextUrl(pageContextInit.urlOriginal);
|
|
316
316
|
const pageContextBegin = (0, createPageContextServerSide_js_1.createPageContextServerSide)(pageContextInit, globalContext, {
|
|
317
317
|
isPrerendering: false,
|
|
318
318
|
ssr: {
|
|
@@ -320,13 +320,14 @@ function getPageContextBegin(pageContextInit, globalContext, httpRequestId) {
|
|
|
320
320
|
isClientSideNavigation,
|
|
321
321
|
},
|
|
322
322
|
});
|
|
323
|
-
(0, utils_js_1.objectAssign)(pageContextBegin, { _httpRequestId: httpRequestId });
|
|
323
|
+
(0, utils_js_1.objectAssign)(pageContextBegin, { _httpRequestId: httpRequestId, _isPageContextJsonRequest });
|
|
324
324
|
return pageContextBegin;
|
|
325
325
|
}
|
|
326
326
|
function handlePageContextUrl(urlOriginal) {
|
|
327
|
-
const {
|
|
327
|
+
const { isPageContextJsonRequest } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(urlOriginal);
|
|
328
328
|
return {
|
|
329
|
-
isClientSideNavigation:
|
|
329
|
+
isClientSideNavigation: !!isPageContextJsonRequest,
|
|
330
|
+
_isPageContextJsonRequest: isPageContextJsonRequest,
|
|
330
331
|
_urlHandler: (url) => (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(url).urlWithoutPageContextRequestSuffix,
|
|
331
332
|
};
|
|
332
333
|
}
|
|
@@ -350,8 +351,8 @@ async function normalizeUrl(pageContextBegin, globalContext, httpRequestId) {
|
|
|
350
351
|
if (disableUrlNormalization)
|
|
351
352
|
return null;
|
|
352
353
|
const { urlOriginal } = pageContext;
|
|
353
|
-
const {
|
|
354
|
-
if (
|
|
354
|
+
const { isPageContextJsonRequest } = (0, handlePageContextRequestUrl_js_1.handlePageContextRequestUrl)(urlOriginal);
|
|
355
|
+
if (isPageContextJsonRequest)
|
|
355
356
|
return null;
|
|
356
357
|
const urlNormalized = (0, utils_js_1.normalizeUrlPathname)(urlOriginal, trailingSlash ?? false, globalContext.baseServer);
|
|
357
358
|
if (!urlNormalized)
|
|
@@ -7,6 +7,7 @@ const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigIn
|
|
|
7
7
|
const pluginBuildConfig_js_1 = require("../pluginBuild/pluginBuildConfig.js");
|
|
8
8
|
const virtualFileEntry_js_1 = require("../../../shared/virtualFiles/virtualFileEntry.js");
|
|
9
9
|
const getFilePath_js_1 = require("../../shared/getFilePath.js");
|
|
10
|
+
const getConfigValueSourcesRelevant_js_1 = require("../pluginVirtualFiles/getConfigValueSourcesRelevant.js");
|
|
10
11
|
const debug = (0, utils_js_1.createDebugger)('vike:optimizeDeps');
|
|
11
12
|
async function determineOptimizeDeps(config) {
|
|
12
13
|
const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)();
|
|
@@ -40,43 +41,36 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
40
41
|
let entriesServer = [];
|
|
41
42
|
let includeClient = [];
|
|
42
43
|
let includeServer = [];
|
|
43
|
-
const addEntry = (e,
|
|
44
|
+
const addEntry = (e, isForClientSide, definedAt) => {
|
|
44
45
|
(0, utils_js_1.assert)(e);
|
|
45
46
|
// optimizeDeps.entries expects filesystem absolute paths
|
|
46
47
|
(0, utils_js_1.assert)((0, utils_js_1.isVirtualFileId)(e) || (0, utils_js_1.isFilePathAbsoluteFilesystem)(e));
|
|
47
|
-
if (
|
|
48
|
+
if (isExcluded(e, isForClientSide, definedAt))
|
|
49
|
+
return;
|
|
50
|
+
if (isForClientSide) {
|
|
48
51
|
entriesClient.push(e);
|
|
49
52
|
}
|
|
50
|
-
|
|
53
|
+
else {
|
|
51
54
|
entriesServer.push(e);
|
|
52
55
|
}
|
|
53
56
|
};
|
|
54
|
-
const addInclude = (e,
|
|
57
|
+
const addInclude = (e, isForClientSide, definedAt) => {
|
|
55
58
|
(0, utils_js_1.assert)(e);
|
|
56
59
|
// optimizeDeps.include expects npm packages
|
|
57
60
|
(0, utils_js_1.assert)(!e.startsWith('/'));
|
|
58
61
|
// Shouldn't be a path alias, as path aliases would need to be added to optimizeDeps.entries instead of optimizeDeps.include
|
|
59
62
|
(0, utils_js_1.assertIsImportPathNpmPackage)(e);
|
|
60
|
-
if (
|
|
63
|
+
if (isExcluded(e, isForClientSide, definedAt))
|
|
64
|
+
return;
|
|
65
|
+
if (isForClientSide) {
|
|
61
66
|
includeClient.push(e);
|
|
62
67
|
}
|
|
63
|
-
if (isRelevant(e, true, configEnv, definedAt)) {
|
|
64
|
-
includeServer.push(e);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
const isRelevant = (e, server, configEnv, definedAt) => {
|
|
68
|
-
if (server) {
|
|
69
|
-
if (!configEnv || !configEnv.server)
|
|
70
|
-
return false;
|
|
71
|
-
}
|
|
72
68
|
else {
|
|
73
|
-
|
|
74
|
-
return false;
|
|
69
|
+
includeServer.push(e);
|
|
75
70
|
}
|
|
76
|
-
return !isExcluded(e, server, definedAt);
|
|
77
71
|
};
|
|
78
|
-
const isExcluded = (e,
|
|
79
|
-
const exclude =
|
|
72
|
+
const isExcluded = (e, isForClientSide, definedAt) => {
|
|
73
|
+
const exclude = isForClientSide ? config.optimizeDeps.exclude : config.ssr.optimizeDeps.exclude;
|
|
80
74
|
if (!exclude)
|
|
81
75
|
return false;
|
|
82
76
|
if (definedAt?.importPathAbsolute) {
|
|
@@ -88,26 +82,34 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
88
82
|
};
|
|
89
83
|
// V1 design
|
|
90
84
|
{
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
85
|
+
;
|
|
86
|
+
[true, false].forEach((isForClientSide) => {
|
|
87
|
+
pageConfigs.forEach((pageConfig) => {
|
|
88
|
+
Object.entries(pageConfig.configValueSources).forEach(([configName]) => {
|
|
89
|
+
const runtimeEnv = {
|
|
90
|
+
isForClientSide,
|
|
91
|
+
isDev: true,
|
|
92
|
+
// TO-DO/eventually/remove-server-router: let's eventually remove support for Server Routing
|
|
93
|
+
isClientRouting: true,
|
|
94
|
+
};
|
|
95
|
+
const sourcesRelevant = (0, getConfigValueSourcesRelevant_js_1.getConfigValueSourcesRelevant)(configName, runtimeEnv, pageConfig);
|
|
96
|
+
sourcesRelevant.forEach((configValueSource) => {
|
|
97
|
+
if (!configValueSource.valueIsLoadedWithImport && !configValueSource.valueIsFilePath)
|
|
98
|
+
return;
|
|
99
|
+
const { definedAt } = configValueSource;
|
|
100
|
+
if (definedAt.definedBy)
|
|
101
|
+
return;
|
|
102
|
+
if (definedAt.filePathAbsoluteUserRootDir !== null) {
|
|
103
|
+
addEntry(
|
|
104
|
+
// optimizeDeps.entries expects filesystem absolute paths
|
|
105
|
+
definedAt.filePathAbsoluteFilesystem, isForClientSide, definedAt);
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
addInclude(
|
|
109
|
+
// optimizeDeps.include expects npm packages
|
|
110
|
+
definedAt.importPathAbsolute, isForClientSide, definedAt);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
111
113
|
});
|
|
112
114
|
});
|
|
113
115
|
});
|
|
@@ -119,7 +121,7 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
119
121
|
pageFiles.forEach((filePathAbsoluteUserRootDir) => {
|
|
120
122
|
const entry = (0, getFilePath_js_1.getFilePathResolved)({ filePathAbsoluteUserRootDir, userRootDir });
|
|
121
123
|
const { filePathAbsoluteFilesystem } = entry;
|
|
122
|
-
addEntry(filePathAbsoluteFilesystem);
|
|
124
|
+
addEntry(filePathAbsoluteFilesystem, true);
|
|
123
125
|
});
|
|
124
126
|
}
|
|
125
127
|
// Add virtual files.
|
|
@@ -129,11 +131,11 @@ async function getPageDeps(config, pageConfigs) {
|
|
|
129
131
|
// - If we do, then we need to adjust include/entries (maybe by making include === entries -> will Vite complain?)
|
|
130
132
|
{
|
|
131
133
|
const { hasClientRouting, hasServerRouting, clientEntries } = (0, pluginBuildConfig_js_1.analyzeClientEntries)(pageConfigs, config);
|
|
132
|
-
Object.values(clientEntries).forEach((e) => addEntry(e));
|
|
134
|
+
Object.values(clientEntries).forEach((e) => addEntry(e, true));
|
|
133
135
|
if (hasClientRouting)
|
|
134
|
-
addEntry(virtualFileEntry_js_1.virtualFileIdEntryClientCR);
|
|
136
|
+
addEntry(virtualFileEntry_js_1.virtualFileIdEntryClientCR, true);
|
|
135
137
|
if (hasServerRouting)
|
|
136
|
-
addEntry(virtualFileEntry_js_1.virtualFileIdEntryClientSR);
|
|
138
|
+
addEntry(virtualFileEntry_js_1.virtualFileIdEntryClientSR, true);
|
|
137
139
|
}
|
|
138
140
|
entriesClient = entriesClient;
|
|
139
141
|
entriesServer = entriesServer;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getConfigValueSourcesRelevant = getConfigValueSourcesRelevant;
|
|
4
|
+
exports.isRuntimeEnvMatch = isRuntimeEnvMatch;
|
|
5
|
+
const utils_js_1 = require("../../utils.js");
|
|
6
|
+
function getConfigValueSourcesRelevant(configName, runtimeEnv, pageConfig) {
|
|
7
|
+
const configDef = pageConfig.configDefinitions[configName];
|
|
8
|
+
(0, utils_js_1.assert)(configDef);
|
|
9
|
+
let sourcesRelevant = pageConfig.configValueSources[configName];
|
|
10
|
+
if (!sourcesRelevant)
|
|
11
|
+
return [];
|
|
12
|
+
if (!configDef.cumulative) {
|
|
13
|
+
const source = sourcesRelevant[0];
|
|
14
|
+
if (source) {
|
|
15
|
+
sourcesRelevant = [source];
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
(0, utils_js_1.assert)(sourcesRelevant.length === 0);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
// isOverridden() must be called before isRuntimeEnvMatch() is called (otherwise isOverridden() will return a wrong value)
|
|
23
|
+
sourcesRelevant = sourcesRelevant.filter((source) => !isOverridden(source, configName, pageConfig));
|
|
24
|
+
}
|
|
25
|
+
sourcesRelevant = sourcesRelevant.filter((source) => isRuntimeEnvMatch(source.configEnv, runtimeEnv));
|
|
26
|
+
return sourcesRelevant;
|
|
27
|
+
}
|
|
28
|
+
function isRuntimeEnvMatch(configEnv, runtimeEnv) {
|
|
29
|
+
if ('isForConfig' in runtimeEnv)
|
|
30
|
+
return !!configEnv.config;
|
|
31
|
+
// Runtime
|
|
32
|
+
if (!runtimeEnv.isForClientSide) {
|
|
33
|
+
if (!configEnv.server)
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
if (!configEnv.client)
|
|
38
|
+
return false;
|
|
39
|
+
if (configEnv.client === 'if-client-routing' && !runtimeEnv.isClientRouting)
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
// Production/development
|
|
43
|
+
if (configEnv.production !== undefined) {
|
|
44
|
+
(0, utils_js_1.assert)(typeof configEnv.production === 'boolean');
|
|
45
|
+
(0, utils_js_1.assert)(typeof runtimeEnv.isDev === 'boolean');
|
|
46
|
+
if (configEnv.production) {
|
|
47
|
+
if (runtimeEnv.isDev)
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
if (!runtimeEnv.isDev)
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
function isOverridden(source, configName, pageConfig) {
|
|
58
|
+
const configDef = pageConfig.configDefinitions[configName];
|
|
59
|
+
(0, utils_js_1.assert)(configDef);
|
|
60
|
+
if (configDef.cumulative)
|
|
61
|
+
return false;
|
|
62
|
+
const sources = pageConfig.configValueSources[configName];
|
|
63
|
+
(0, utils_js_1.assert)(sources);
|
|
64
|
+
const idx = sources.indexOf(source);
|
|
65
|
+
(0, utils_js_1.assert)(idx >= 0);
|
|
66
|
+
return idx > 0;
|
|
67
|
+
}
|
|
@@ -7,7 +7,6 @@ const virtualFilePageConfigLazy_js_1 = require("../../../shared/virtualFiles/vir
|
|
|
7
7
|
const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigInternal.js");
|
|
8
8
|
const extractAssetsQuery_js_1 = require("../../../shared/extractAssetsQuery.js");
|
|
9
9
|
const debug_js_1 = require("./debug.js");
|
|
10
|
-
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
11
10
|
const serializeConfigValues_js_1 = require("../../../../shared/page-configs/serialize/serializeConfigValues.js");
|
|
12
11
|
const handleAssetsManifest_js_1 = require("../pluginBuild/handleAssetsManifest.js");
|
|
13
12
|
const getConfigValueBuildTime_js_1 = require("../../../../shared/page-configs/getConfigValueBuildTime.js");
|
|
@@ -46,7 +45,7 @@ function getLoadConfigLazy(pageConfig, isForClientSide, pageId, includeAssetsImp
|
|
|
46
45
|
const filesEnv = new Map();
|
|
47
46
|
const isClientRouting = (0, getConfigValueBuildTime_js_1.getConfigValueBuildTime)(pageConfig, 'clientRouting', 'boolean')?.value ?? false;
|
|
48
47
|
lines.push('export const configValuesSerialized = {');
|
|
49
|
-
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, filesEnv,
|
|
48
|
+
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, '', false));
|
|
50
49
|
lines.push('};');
|
|
51
50
|
if (!(0, handleAssetsManifest_js_1.handleAssetsManifest_isFixEnabled)(config) && includeAssetsImportedByServer && isForClientSide && !isDev) {
|
|
52
51
|
importStatements.push(`import '${(0, extractAssetsQuery_js_1.extractAssetsAddQuery)((0, virtualFilePageConfigLazy_js_1.getVirtualFileIdPageConfigLazy)(pageId, false))}'`);
|
|
@@ -4,7 +4,6 @@ exports.getVirtualFilePageConfigsEager = getVirtualFilePageConfigsEager;
|
|
|
4
4
|
const virtualFilePageConfigLazy_js_1 = require("../../../shared/virtualFiles/virtualFilePageConfigLazy.js");
|
|
5
5
|
const debug_js_1 = require("./debug.js");
|
|
6
6
|
const resolveVikeConfigInternal_js_1 = require("../../shared/resolveVikeConfigInternal.js");
|
|
7
|
-
const isRuntimeEnvMatch_js_1 = require("./isRuntimeEnvMatch.js");
|
|
8
7
|
const serializeConfigValues_js_1 = require("../../../../shared/page-configs/serialize/serializeConfigValues.js");
|
|
9
8
|
async function getVirtualFilePageConfigsEager(isForClientSide, isDev, id, isClientRouting) {
|
|
10
9
|
const vikeConfig = await (0, resolveVikeConfigInternal_js_1.getVikeConfigInternal)(true);
|
|
@@ -41,7 +40,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
|
|
|
41
40
|
const load = `() => ({ moduleId: ${virtualFileId}, moduleExports: import(${virtualFileId}) })`;
|
|
42
41
|
lines.push(` loadConfigLazy: ${load},`);
|
|
43
42
|
lines.push(` configValuesSerialized: {`);
|
|
44
|
-
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, filesEnv,
|
|
43
|
+
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfig, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, ' ', true));
|
|
45
44
|
lines.push(` },`);
|
|
46
45
|
lines.push(` },`);
|
|
47
46
|
});
|
|
@@ -51,7 +50,7 @@ function getCodePageConfigsSerialized(pageConfigs, isForClientSide, isClientRout
|
|
|
51
50
|
function getCodePageConfigGlobalSerialized(pageConfigGlobal, isForClientSide, isClientRouting, isDev, importStatements, filesEnv) {
|
|
52
51
|
const lines = [];
|
|
53
52
|
lines.push(` configValuesSerialized: {`);
|
|
54
|
-
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfigGlobal, importStatements, filesEnv,
|
|
53
|
+
lines.push(...(0, serializeConfigValues_js_1.serializeConfigValues)(pageConfigGlobal, importStatements, filesEnv, { isForClientSide, isClientRouting, isDev }, ' ', null));
|
|
55
54
|
lines.push(` },`);
|
|
56
55
|
const code = lines.join('\n');
|
|
57
56
|
return code;
|