vike 0.4.221-commit-937dbfb → 0.4.222-commit-207e079
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/node/plugin/index.js +1 -1
- package/dist/cjs/node/plugin/plugins/baseUrls.js +6 -1
- package/dist/cjs/node/plugin/plugins/commonConfig.js +4 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/index.js +73 -39
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +37 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +2 -40
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +2 -0
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +39 -14
- package/dist/cjs/node/runtime/globalContext.js +24 -8
- package/dist/cjs/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -4
- package/dist/cjs/node/runtime/renderPage.js +4 -8
- package/dist/cjs/node/shared/resolveBase.js +0 -13
- package/dist/cjs/shared/getPageConfigsRuntime.js +10 -1
- package/dist/cjs/shared/route/loadPageRoutes.js +1 -1
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assertSingleInstance.js +1 -1
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.d.ts +5 -0
- package/dist/esm/client/client-routing-runtime/renderPageClientSide.js +7 -0
- package/dist/esm/node/plugin/index.d.ts +4 -1
- package/dist/esm/node/plugin/index.js +1 -1
- package/dist/esm/node/plugin/plugins/baseUrls.js +6 -1
- package/dist/esm/node/plugin/plugins/commonConfig.d.ts +1 -0
- package/dist/esm/node/plugin/plugins/commonConfig.js +4 -1
- package/dist/esm/node/plugin/plugins/importUserCode/index.js +73 -39
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.d.ts +4 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/crawlPlusFiles.js +38 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.d.ts +0 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js +2 -37
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js +2 -0
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +3 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +39 -14
- package/dist/esm/node/runtime/globalContext.d.ts +10 -7
- package/dist/esm/node/runtime/globalContext.js +24 -8
- package/dist/esm/node/runtime/html/injectAssets/getViteDevScript.d.ts +2 -2
- package/dist/esm/node/runtime/html/injectAssets.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/analyzePage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/getPageAssets.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/handleErrorWithoutErrorPage.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/log404/index.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +8 -8
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.js +2 -4
- package/dist/esm/node/runtime/renderPage.js +4 -8
- package/dist/esm/node/shared/resolveBase.d.ts +1 -9
- package/dist/esm/node/shared/resolveBase.js +0 -13
- package/dist/esm/shared/getPageConfigsRuntime.d.ts +2 -1
- package/dist/esm/shared/getPageConfigsRuntime.js +10 -1
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +6 -0
- package/dist/esm/shared/route/loadPageRoutes.js +1 -1
- package/dist/esm/shared/types.d.ts +9 -0
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assertSingleInstance.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -18,7 +18,7 @@ export { assertBuildInfo };
|
|
|
18
18
|
export { getViteConfigRuntime };
|
|
19
19
|
export { updateUserFiles };
|
|
20
20
|
// The core logic revolves around:
|
|
21
|
-
// - globalObject.userFiles which is the main requirement for
|
|
21
|
+
// - globalObject.userFiles which is the main requirement for resolveGlobalContext()
|
|
22
22
|
// - In production: globalObject.buildEntry which is the production entry set by @brillout/vite-plugin-server-entry
|
|
23
23
|
// - loadBuildEntry() sets globalObject.buildEntry and then sets globalObject.userFiles
|
|
24
24
|
// - With vike-server it's set at server start: @brillout/vite-plugin-server-entry injects `import './entry.mjs'` (the production entry generated by @brillout/vite-plugin-server-entry) as first line of code of dist/server/index.mjs while dist/server/entry.mjs calls setGlobalContext_buildEntry()
|
|
@@ -32,6 +32,7 @@ import pc from '@brillout/picocolors';
|
|
|
32
32
|
import { loadPageRoutes } from '../../shared/route/loadPageRoutes.js';
|
|
33
33
|
import { assertV1Design } from '../shared/assertV1Design.js';
|
|
34
34
|
import { getPageConfigsRuntime } from '../../shared/getPageConfigsRuntime.js';
|
|
35
|
+
import { resolveBase } from '../shared/resolveBase.js';
|
|
35
36
|
const debug = createDebugger('vike:globalContext');
|
|
36
37
|
const globalObject = getGlobalObject('globalContext.ts', getInitialGlobalContext());
|
|
37
38
|
async function getGlobalContextInternal() {
|
|
@@ -75,8 +76,14 @@ async function getGlobalContextAsync(isProduction) {
|
|
|
75
76
|
return globalContext_public;
|
|
76
77
|
}
|
|
77
78
|
function makePublic(globalContext) {
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
const globalContextPublic = makePublicCopy(globalContext, 'globalContext', [
|
|
80
|
+
'assetsManifest',
|
|
81
|
+
'config',
|
|
82
|
+
'viteConfig',
|
|
83
|
+
'pages',
|
|
84
|
+
'baseServer',
|
|
85
|
+
'baseAssets'
|
|
86
|
+
]);
|
|
80
87
|
return globalContextPublic;
|
|
81
88
|
}
|
|
82
89
|
async function setGlobalContext_viteDevServer(viteDevServer) {
|
|
@@ -180,7 +187,7 @@ function setIsProduction(isProduction) {
|
|
|
180
187
|
globalObject.isProduction = isProduction;
|
|
181
188
|
}
|
|
182
189
|
function defineGlobalContext() {
|
|
183
|
-
const globalContext =
|
|
190
|
+
const globalContext = resolveGlobalContext();
|
|
184
191
|
assertIsDefined(globalContext);
|
|
185
192
|
const globalContext_public = makePublic(globalContext);
|
|
186
193
|
objectAssign(globalContext, { globalContext_public });
|
|
@@ -189,7 +196,7 @@ function defineGlobalContext() {
|
|
|
189
196
|
assertGlobalContextIsDefined();
|
|
190
197
|
onSetupRuntime();
|
|
191
198
|
}
|
|
192
|
-
function
|
|
199
|
+
function resolveGlobalContext() {
|
|
193
200
|
const { viteDevServer, viteConfig, isPrerendering, isProduction, userFiles } = globalObject;
|
|
194
201
|
assert(typeof isProduction === 'boolean');
|
|
195
202
|
let globalContext;
|
|
@@ -208,7 +215,8 @@ function assembleGlobalContext() {
|
|
|
208
215
|
viteDevServer,
|
|
209
216
|
viteConfig,
|
|
210
217
|
...userFiles,
|
|
211
|
-
viteConfigRuntime
|
|
218
|
+
viteConfigRuntime,
|
|
219
|
+
...resolveBaseRuntime(viteConfigRuntime, userFiles.config)
|
|
212
220
|
};
|
|
213
221
|
}
|
|
214
222
|
else {
|
|
@@ -225,7 +233,8 @@ function assembleGlobalContext() {
|
|
|
225
233
|
...userFiles,
|
|
226
234
|
viteDevServer: null,
|
|
227
235
|
viteConfigRuntime: buildInfo.viteConfigRuntime,
|
|
228
|
-
usesClientRouter: buildInfo.usesClientRouter
|
|
236
|
+
usesClientRouter: buildInfo.usesClientRouter,
|
|
237
|
+
...resolveBaseRuntime(buildInfo.viteConfigRuntime, userFiles.config)
|
|
229
238
|
};
|
|
230
239
|
if (isPrerendering) {
|
|
231
240
|
assert(viteConfig);
|
|
@@ -250,7 +259,7 @@ async function getUserFiles() {
|
|
|
250
259
|
const globalObject_ = globalObject;
|
|
251
260
|
const { pageConfigsRuntime } = globalObject_;
|
|
252
261
|
assert(pageConfigsRuntime);
|
|
253
|
-
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, globalConfig } = pageConfigsRuntime;
|
|
262
|
+
const { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, globalConfig, pageConfigsUserFriendly } = pageConfigsRuntime;
|
|
254
263
|
const { pageRoutes, onBeforeRouteHook } = await loadPageRoutes(pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds);
|
|
255
264
|
const userFiles = {
|
|
256
265
|
pageFilesAll,
|
|
@@ -259,6 +268,7 @@ async function getUserFiles() {
|
|
|
259
268
|
allPageIds,
|
|
260
269
|
pageRoutes,
|
|
261
270
|
onBeforeRouteHook,
|
|
271
|
+
pages: pageConfigsUserFriendly,
|
|
262
272
|
config: globalConfig.config
|
|
263
273
|
};
|
|
264
274
|
assertV1Design(
|
|
@@ -393,3 +403,9 @@ function getInitialGlobalContext() {
|
|
|
393
403
|
viteDevServerPromiseResolve
|
|
394
404
|
};
|
|
395
405
|
}
|
|
406
|
+
function resolveBaseRuntime(viteConfigRuntime, config) {
|
|
407
|
+
const baseViteOriginal = viteConfigRuntime._baseViteOriginal;
|
|
408
|
+
const baseServerUnresolved = config.baseServer ?? null;
|
|
409
|
+
const baseAssetsUnresolved = config.baseAssets ?? null;
|
|
410
|
+
return resolveBase(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved);
|
|
411
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getViteDevScript };
|
|
2
|
-
import type {
|
|
2
|
+
import type { GlobalContextInternal } from '../../globalContext.js';
|
|
3
3
|
declare function getViteDevScript(pageContext: {
|
|
4
|
-
_globalContext:
|
|
4
|
+
_globalContext: GlobalContextInternal;
|
|
5
5
|
}): Promise<string>;
|
|
@@ -8,7 +8,7 @@ import { type PreloadFilter } from './injectAssets/getHtmlTags.js';
|
|
|
8
8
|
import type { StreamFromReactStreamingPackage } from './stream/react-streaming.js';
|
|
9
9
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
10
10
|
import type { PageContextSerialization } from './serializePageContextClientSide.js';
|
|
11
|
-
import type {
|
|
11
|
+
import type { GlobalContextInternal } from '../globalContext.js';
|
|
12
12
|
type PageContextInjectAssets = {
|
|
13
13
|
urlPathname: string;
|
|
14
14
|
__getPageAssets: () => Promise<PageAsset[]>;
|
|
@@ -22,7 +22,7 @@ type PageContextInjectAssets = {
|
|
|
22
22
|
_baseServer: string;
|
|
23
23
|
_pageConfigs: PageConfigRuntime[];
|
|
24
24
|
is404: null | boolean;
|
|
25
|
-
_globalContext:
|
|
25
|
+
_globalContext: GlobalContextInternal;
|
|
26
26
|
} & PageContextSerialization;
|
|
27
27
|
declare function injectHtmlTagsToString(htmlParts: HtmlPart[], pageContext: PageContextInjectAssets & {
|
|
28
28
|
_isStream: false;
|
|
@@ -2,5 +2,5 @@ export { analyzePage };
|
|
|
2
2
|
import type { PageFile } from '../../../shared/getPageFiles/getPageFileObject.js';
|
|
3
3
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
4
4
|
import { type AnalysisResult } from '../../../shared/getPageFiles/analyzePageClientSide.js';
|
|
5
|
-
import type {
|
|
6
|
-
declare function analyzePage(pageFilesAll: PageFile[], pageConfig: null | PageConfigRuntime, pageId: string, globalContext:
|
|
5
|
+
import type { GlobalContextInternal } from '../globalContext.js';
|
|
6
|
+
declare function analyzePage(pageFilesAll: PageFile[], pageConfig: null | PageConfigRuntime, pageId: string, globalContext: GlobalContextInternal): Promise<AnalysisResult>;
|
|
@@ -5,7 +5,7 @@ export type { GetPageAssets };
|
|
|
5
5
|
export type { PageContextGetPageAssets };
|
|
6
6
|
import { type MediaType } from './inferMediaType.js';
|
|
7
7
|
import type { ClientDependency } from '../../../shared/getPageFiles/analyzePageClientSide/ClientDependency.js';
|
|
8
|
-
import type {
|
|
8
|
+
import type { GlobalContextInternal } from '../globalContext.js';
|
|
9
9
|
import type { ResolveClientEntriesDev } from '../../plugin/shared/resolveClientEntriesDev.js';
|
|
10
10
|
type PageAsset = {
|
|
11
11
|
src: string;
|
|
@@ -18,7 +18,7 @@ type PageContextGetPageAssets = {
|
|
|
18
18
|
_baseServer: string;
|
|
19
19
|
_baseAssets: string | null;
|
|
20
20
|
_includeAssetsImportedByServer: boolean;
|
|
21
|
-
_globalContext:
|
|
21
|
+
_globalContext: GlobalContextInternal;
|
|
22
22
|
};
|
|
23
23
|
declare function getPageAssets(pageContext: PageContextGetPageAssets, clientDependencies: ClientDependency[], clientEntries: string[]): Promise<PageAsset[]>;
|
|
24
24
|
declare function setResolveClientEntriesDev(resolveClientEntriesDev: ResolveClientEntriesDev): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { handleErrorWithoutErrorPage };
|
|
2
|
-
import type {
|
|
2
|
+
import type { GlobalContextInternal } from '../globalContext.js';
|
|
3
3
|
import type { PageContextAfterRender } from './renderPageAlreadyRouted.js';
|
|
4
4
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
5
5
|
import type { PageFile } from '../../../shared/getPageFiles.js';
|
|
@@ -10,6 +10,6 @@ declare function handleErrorWithoutErrorPage<PageContext extends {
|
|
|
10
10
|
pageId: null;
|
|
11
11
|
_pageFilesAll: PageFile[];
|
|
12
12
|
_pageConfigs: PageConfigRuntime[];
|
|
13
|
-
_globalContext:
|
|
13
|
+
_globalContext: GlobalContextInternal;
|
|
14
14
|
urlOriginal: string;
|
|
15
15
|
}>(pageContext: PageContext): Promise<PageContext & PageContextAfterRender>;
|
|
@@ -6,12 +6,12 @@ import { PromiseType } from '../utils.js';
|
|
|
6
6
|
import { PageContextGetPageAssets, type PageAsset } from './getPageAssets.js';
|
|
7
7
|
import { type PageContextDebugRouteMatches } from './debugPageFiles.js';
|
|
8
8
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
9
|
-
import type {
|
|
9
|
+
import type { GlobalContextInternal } from '../globalContext.js';
|
|
10
10
|
type PageContext_loadUserFilesServerSide = PageContextGetPageAssets & PageContextDebugRouteMatches & {
|
|
11
11
|
urlOriginal: string;
|
|
12
12
|
_pageFilesAll: PageFile[];
|
|
13
13
|
_pageConfigs: PageConfigRuntime[];
|
|
14
|
-
_globalContext:
|
|
14
|
+
_globalContext: GlobalContextInternal;
|
|
15
15
|
};
|
|
16
16
|
type PageFiles = PromiseType<ReturnType<typeof loadUserFilesServerSide>>;
|
|
17
17
|
declare function loadUserFilesServerSide(pageContext: {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
export { log404 };
|
|
2
2
|
export { getRoutesInfo };
|
|
3
3
|
import type { PageRoutes } from '../../../../shared/route/index.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { GlobalContextInternal } from '../../globalContext.js';
|
|
5
5
|
declare function log404(pageContext: {
|
|
6
6
|
urlPathname: string;
|
|
7
7
|
errorWhileRendering: null | Error;
|
|
8
8
|
isClientSideNavigation: boolean;
|
|
9
9
|
_pageRoutes: PageRoutes;
|
|
10
|
-
_globalContext:
|
|
10
|
+
_globalContext: GlobalContextInternal;
|
|
11
11
|
}): Promise<void>;
|
|
12
12
|
declare function getRoutesInfo(pageRoutes: PageRoutes): string | null;
|
package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { PageContextUrlInternal } from '../../../shared/getPageContextUrlCompute
|
|
|
4
4
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
5
5
|
import type { PageConfigUserFriendly } from '../../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
6
6
|
import { PageContextBuiltInServerInternal } from '../../../shared/types.js';
|
|
7
|
-
import type {
|
|
7
|
+
import type { GlobalContextInternal, GlobalContextPublic } from '../globalContext.js';
|
|
8
8
|
type PageContextForUserConsumptionServerSide = PageContextBuiltInServerInternal & PageConfigUserFriendly & {
|
|
9
9
|
urlOriginal: string;
|
|
10
10
|
/** @deprecated */
|
|
@@ -18,7 +18,7 @@ type PageContextForUserConsumptionServerSide = PageContextBuiltInServerInternal
|
|
|
18
18
|
is404: null | boolean;
|
|
19
19
|
isClientSideNavigation: boolean;
|
|
20
20
|
pageProps?: Record<string, unknown>;
|
|
21
|
-
_globalContext:
|
|
21
|
+
_globalContext: GlobalContextInternal;
|
|
22
22
|
globalContext: GlobalContextPublic;
|
|
23
23
|
} & Record<string, unknown>;
|
|
24
24
|
declare function preparePageContextForUserConsumptionServerSide(pageContext: PageContextForUserConsumptionServerSide): void;
|
|
@@ -5,7 +5,7 @@ export { getPageContextInitEnhanced };
|
|
|
5
5
|
export type { PageContextAfterRender };
|
|
6
6
|
export type { PageContextInitEnhanced };
|
|
7
7
|
import { type PageContextUrlInternal } from '../../../shared/getPageContextUrlComputed.js';
|
|
8
|
-
import type {
|
|
8
|
+
import type { GlobalContextInternal } from '../globalContext.js';
|
|
9
9
|
import { HttpResponse } from './createHttpResponse.js';
|
|
10
10
|
import { PageContext_loadUserFilesServerSide, type PageFiles } from './loadUserFilesServerSide.js';
|
|
11
11
|
type PageContextAfterRender = {
|
|
@@ -46,7 +46,7 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
|
|
|
46
46
|
_allPageIds: string[];
|
|
47
47
|
_pageRoutes: import("../../../__internal/index.js").PageRoutes;
|
|
48
48
|
_onBeforeRouteHook: import("../../../shared/hooks/getHook.js").Hook | null;
|
|
49
|
-
_globalContext:
|
|
49
|
+
_globalContext: GlobalContextInternal;
|
|
50
50
|
/** @experimental This is a beta feature https://vike.dev/getGlobalContext */
|
|
51
51
|
globalContext: import("../globalContext.js").GlobalContextPublic;
|
|
52
52
|
_pageContextInit: {
|
|
@@ -100,7 +100,7 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
|
|
|
100
100
|
_allPageIds: string[];
|
|
101
101
|
_pageRoutes: import("../../../__internal/index.js").PageRoutes;
|
|
102
102
|
_onBeforeRouteHook: import("../../../shared/hooks/getHook.js").Hook | null;
|
|
103
|
-
_globalContext:
|
|
103
|
+
_globalContext: GlobalContextInternal;
|
|
104
104
|
/** @experimental This is a beta feature https://vike.dev/getGlobalContext */
|
|
105
105
|
globalContext: import("../globalContext.js").GlobalContextPublic;
|
|
106
106
|
_pageContextInit: {
|
|
@@ -137,7 +137,7 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
|
|
|
137
137
|
_urlHandler: null;
|
|
138
138
|
};
|
|
139
139
|
}>;
|
|
140
|
-
declare function prerender404Page(pageContextInit_: Record<string, unknown> | null, globalContext:
|
|
140
|
+
declare function prerender404Page(pageContextInit_: Record<string, unknown> | null, globalContext: GlobalContextInternal): Promise<{
|
|
141
141
|
documentHtml: string;
|
|
142
142
|
pageContextSerialized: null;
|
|
143
143
|
pageContext: {
|
|
@@ -155,7 +155,7 @@ declare function prerender404Page(pageContextInit_: Record<string, unknown> | nu
|
|
|
155
155
|
_allPageIds: string[];
|
|
156
156
|
_pageRoutes: import("../../../__internal/index.js").PageRoutes;
|
|
157
157
|
_onBeforeRouteHook: import("../../../shared/hooks/getHook.js").Hook | null;
|
|
158
|
-
_globalContext:
|
|
158
|
+
_globalContext: GlobalContextInternal;
|
|
159
159
|
/** @experimental This is a beta feature https://vike.dev/getGlobalContext */
|
|
160
160
|
globalContext: import("../globalContext.js").GlobalContextPublic;
|
|
161
161
|
_pageContextInit: {
|
|
@@ -209,7 +209,7 @@ declare function prerender404Page(pageContextInit_: Record<string, unknown> | nu
|
|
|
209
209
|
_allPageIds: string[];
|
|
210
210
|
_pageRoutes: import("../../../__internal/index.js").PageRoutes;
|
|
211
211
|
_onBeforeRouteHook: import("../../../shared/hooks/getHook.js").Hook | null;
|
|
212
|
-
_globalContext:
|
|
212
|
+
_globalContext: GlobalContextInternal;
|
|
213
213
|
/** @experimental This is a beta feature https://vike.dev/getGlobalContext */
|
|
214
214
|
globalContext: import("../globalContext.js").GlobalContextPublic;
|
|
215
215
|
_pageContextInit: {
|
|
@@ -251,7 +251,7 @@ declare function getPageContextInitEnhanced(pageContextInit: {
|
|
|
251
251
|
urlOriginal: string;
|
|
252
252
|
headersOriginal?: unknown;
|
|
253
253
|
headers?: unknown;
|
|
254
|
-
}, globalContext:
|
|
254
|
+
}, globalContext: GlobalContextInternal, { ssr: { urlRewrite, urlHandler, isClientSideNavigation } }?: {
|
|
255
255
|
ssr?: {
|
|
256
256
|
urlRewrite: null | string;
|
|
257
257
|
urlHandler: null | ((url: string) => string);
|
|
@@ -272,7 +272,7 @@ declare function getPageContextInitEnhanced(pageContextInit: {
|
|
|
272
272
|
_allPageIds: string[];
|
|
273
273
|
_pageRoutes: import("../../../__internal/index.js").PageRoutes;
|
|
274
274
|
_onBeforeRouteHook: import("../../../shared/hooks/getHook.js").Hook | null;
|
|
275
|
-
_globalContext:
|
|
275
|
+
_globalContext: GlobalContextInternal;
|
|
276
276
|
/** @experimental This is a beta feature https://vike.dev/getGlobalContext */
|
|
277
277
|
globalContext: import("../globalContext.js").GlobalContextPublic;
|
|
278
278
|
_pageContextInit: {
|
|
@@ -17,7 +17,6 @@ import { preparePageContextForUserConsumptionServerSide } from './preparePageCon
|
|
|
17
17
|
import { executeGuardHook } from '../../../shared/route/executeGuardHook.js';
|
|
18
18
|
import pc from '@brillout/picocolors';
|
|
19
19
|
import { isServerSideError } from '../../../shared/misc/isServerSideError.js';
|
|
20
|
-
import { resolveBaseRuntime } from '../../shared/resolveBase.js';
|
|
21
20
|
async function renderPageAlreadyRouted(pageContext) {
|
|
22
21
|
// pageContext.pageId can either be the:
|
|
23
22
|
// - ID of the page matching the routing, or the
|
|
@@ -112,14 +111,13 @@ async function getPageContextInitEnhanced(pageContextInit, globalContext, { ssr:
|
|
|
112
111
|
isClientSideNavigation: false
|
|
113
112
|
} } = {}) {
|
|
114
113
|
assert(pageContextInit.urlOriginal);
|
|
115
|
-
const { baseServer, baseAssets } = resolveBaseRuntime(globalContext);
|
|
116
114
|
const pageContextInitEnhanced = {};
|
|
117
115
|
objectAssign(pageContextInitEnhanced, pageContextInit);
|
|
118
116
|
objectAssign(pageContextInitEnhanced, {
|
|
119
117
|
_objectCreatedByVike: true,
|
|
120
118
|
// The following is defined on `pageContext` because we can eventually make these non-global
|
|
121
|
-
_baseServer: baseServer,
|
|
122
|
-
_baseAssets: baseAssets,
|
|
119
|
+
_baseServer: globalContext.baseServer,
|
|
120
|
+
_baseAssets: globalContext.baseAssets,
|
|
123
121
|
// TODO/now: add meta.default
|
|
124
122
|
_includeAssetsImportedByServer: globalContext.config.includeAssetsImportedByServer ?? true,
|
|
125
123
|
// TODO/soon: use GloablContext instead
|
|
@@ -18,7 +18,6 @@ import { getErrorPageId } from '../../shared/error-page.js';
|
|
|
18
18
|
import { handleErrorWithoutErrorPage } from './renderPage/handleErrorWithoutErrorPage.js';
|
|
19
19
|
import { loadUserFilesServerSide } from './renderPage/loadUserFilesServerSide.js';
|
|
20
20
|
import { resolveRedirects } from './renderPage/resolveRedirects.js';
|
|
21
|
-
import { resolveBaseRuntime } from '../shared/resolveBase.js';
|
|
22
21
|
const globalObject = getGlobalObject('runtime/renderPage.ts', {
|
|
23
22
|
httpRequestsCount: 0
|
|
24
23
|
});
|
|
@@ -337,7 +336,6 @@ function assertIsNotViteRequest(urlPathname, urlOriginal) {
|
|
|
337
336
|
assertUsage(false, `${pc.code('renderPage(pageContextInit)')} called with ${pc.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which is unexpected because the URL ${pc.bold(urlOriginal)} should have already been handled by the development middleware: make sure the ${pc.cyan('createDevMiddleware()')} middleware is executed *before* the ${pc.cyan('renderPage()')} middleware, see ${pc.underline('https://vike.dev/renderPage')}`);
|
|
338
337
|
}
|
|
339
338
|
async function normalizeUrl(pageContextInit, globalContext, httpRequestId) {
|
|
340
|
-
const { baseServer } = resolveBaseRuntime(globalContext);
|
|
341
339
|
const { trailingSlash, disableUrlNormalization } = globalContext.config;
|
|
342
340
|
if (disableUrlNormalization)
|
|
343
341
|
return null;
|
|
@@ -345,7 +343,7 @@ async function normalizeUrl(pageContextInit, globalContext, httpRequestId) {
|
|
|
345
343
|
const { isPageContextRequest } = handlePageContextRequestUrl(urlOriginal);
|
|
346
344
|
if (isPageContextRequest)
|
|
347
345
|
return null;
|
|
348
|
-
const urlNormalized = normalizeUrlPathname(urlOriginal, trailingSlash ?? false, baseServer);
|
|
346
|
+
const urlNormalized = normalizeUrlPathname(urlOriginal, trailingSlash ?? false, globalContext.baseServer);
|
|
349
347
|
if (!urlNormalized)
|
|
350
348
|
return null;
|
|
351
349
|
logRuntimeInfo?.(`URL normalized from ${pc.cyan(urlOriginal)} to ${pc.cyan(urlNormalized)} (https://vike.dev/url-normalization)`, httpRequestId, 'info');
|
|
@@ -355,8 +353,7 @@ async function normalizeUrl(pageContextInit, globalContext, httpRequestId) {
|
|
|
355
353
|
return pageContextHttpResponse;
|
|
356
354
|
}
|
|
357
355
|
async function getPermanentRedirect(pageContextInit, globalContext, httpRequestId) {
|
|
358
|
-
const
|
|
359
|
-
const urlWithoutBase = removeBaseServer(pageContextInit.urlOriginal, baseServer);
|
|
356
|
+
const urlWithoutBase = removeBaseServer(pageContextInit.urlOriginal, globalContext.baseServer);
|
|
360
357
|
let origin = null;
|
|
361
358
|
let urlTargetExternal = null;
|
|
362
359
|
let urlTarget = modifyUrlPathname(urlWithoutBase, (urlPathname) => {
|
|
@@ -387,9 +384,8 @@ async function getPermanentRedirect(pageContextInit, globalContext, httpRequestI
|
|
|
387
384
|
}
|
|
388
385
|
if (normalize(urlTarget) === normalize(urlWithoutBase))
|
|
389
386
|
return null;
|
|
390
|
-
const { baseServer } = resolveBaseRuntime(globalContext);
|
|
391
387
|
if (!originChanged)
|
|
392
|
-
urlTarget = prependBase(urlTarget, baseServer);
|
|
388
|
+
urlTarget = prependBase(urlTarget, globalContext.baseServer);
|
|
393
389
|
assert(urlTarget !== pageContextInit.urlOriginal);
|
|
394
390
|
}
|
|
395
391
|
logRuntimeInfo?.(`Permanent redirection defined by config.redirects (https://vike.dev/redirects)`, httpRequestId, 'info');
|
|
@@ -453,7 +449,7 @@ pageContextNominalPageInit, httpRequestId, pageContextErrorPageInit, globalConte
|
|
|
453
449
|
return { pageContextAbort };
|
|
454
450
|
}
|
|
455
451
|
async function assertBaseUrl(pageContextInit, globalContext) {
|
|
456
|
-
const { baseServer } =
|
|
452
|
+
const { baseServer } = globalContext;
|
|
457
453
|
const { urlOriginal } = pageContextInit;
|
|
458
454
|
const { urlWithoutPageContextRequestSuffix } = handlePageContextRequestUrl(urlOriginal);
|
|
459
455
|
const { hasBaseServer } = parseUrl(urlWithoutPageContextRequestSuffix, baseServer);
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
export { resolveBase };
|
|
2
|
-
export {
|
|
3
|
-
export { resolveBaseFromResolvedConfig };
|
|
4
|
-
import type { ResolvedConfig } from 'vite';
|
|
5
|
-
import type { GlobalContext } from '../runtime/globalContext.js';
|
|
6
|
-
declare function resolveBaseFromResolvedConfig(baseServer: string | null, baseAssets: string | null, config: ResolvedConfig): {
|
|
7
|
-
baseServer: string;
|
|
8
|
-
baseAssets: string;
|
|
9
|
-
};
|
|
2
|
+
export type { BaseUrlsResolved };
|
|
10
3
|
type BaseUrlsResolved = {
|
|
11
4
|
baseServer: string;
|
|
12
5
|
baseAssets: string;
|
|
13
6
|
};
|
|
14
|
-
declare function resolveBaseRuntime(globalContext: GlobalContext): BaseUrlsResolved;
|
|
15
7
|
declare function resolveBase(baseViteOriginal: string | null, baseServerUnresolved: string | null, baseAssetsUnresolved: string | null): BaseUrlsResolved;
|
|
@@ -1,19 +1,6 @@
|
|
|
1
1
|
export { resolveBase };
|
|
2
|
-
export { resolveBaseRuntime };
|
|
3
|
-
export { resolveBaseFromResolvedConfig };
|
|
4
2
|
import { assert, assertUsage, isBaseServer, isBaseAssets } from './utils.js';
|
|
5
3
|
import pc from '@brillout/picocolors';
|
|
6
|
-
function resolveBaseFromResolvedConfig(baseServer, baseAssets, config) {
|
|
7
|
-
let baseViteOriginal = config._baseViteOriginal;
|
|
8
|
-
assert(baseViteOriginal === null || typeof baseViteOriginal == 'string');
|
|
9
|
-
return resolveBase(baseViteOriginal, baseServer, baseAssets);
|
|
10
|
-
}
|
|
11
|
-
function resolveBaseRuntime(globalContext) {
|
|
12
|
-
const baseViteOriginal = globalContext.viteConfigRuntime._baseViteOriginal;
|
|
13
|
-
const baseServerUnresolved = globalContext.config.baseServer ?? null;
|
|
14
|
-
const baseAssetsUnresolved = globalContext.config.baseAssets ?? null;
|
|
15
|
-
return resolveBase(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved);
|
|
16
|
-
}
|
|
17
4
|
function resolveBase(baseViteOriginal, baseServerUnresolved, baseAssetsUnresolved) {
|
|
18
5
|
if (baseViteOriginal === '/__UNSET__')
|
|
19
6
|
baseViteOriginal = null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { getPageConfigsRuntime };
|
|
2
2
|
export { getAllPageIds };
|
|
3
3
|
import type { PageFile } from './getPageFiles.js';
|
|
4
|
-
import { type ConfigUserFriendly } from './page-configs/getPageConfigUserFriendly.js';
|
|
4
|
+
import { type ConfigUserFriendly, type PageConfigsUserFriendly } from './page-configs/getPageConfigUserFriendly.js';
|
|
5
5
|
import type { PageConfigGlobalRuntime, PageConfigRuntime } from './page-configs/PageConfig.js';
|
|
6
6
|
declare function getPageConfigsRuntime(virtualFileExports: unknown): {
|
|
7
7
|
pageFilesAll: PageFile[];
|
|
@@ -9,5 +9,6 @@ declare function getPageConfigsRuntime(virtualFileExports: unknown): {
|
|
|
9
9
|
pageConfigs: PageConfigRuntime[];
|
|
10
10
|
pageConfigGlobal: PageConfigGlobalRuntime;
|
|
11
11
|
globalConfig: ConfigUserFriendly;
|
|
12
|
+
pageConfigsUserFriendly: PageConfigsUserFriendly;
|
|
12
13
|
};
|
|
13
14
|
declare function getAllPageIds(pageFilesAll: PageFile[], pageConfigs: PageConfigRuntime[]): string[];
|
|
@@ -8,7 +8,16 @@ function getPageConfigsRuntime(virtualFileExports) {
|
|
|
8
8
|
const allPageIds = getAllPageIds(pageFilesAll, pageConfigs);
|
|
9
9
|
// TODO/now: re-use this call, instead of calling it twice
|
|
10
10
|
const globalConfig = getPageConfigUserFriendlyNew(pageConfigGlobal);
|
|
11
|
-
|
|
11
|
+
// TODO/now DEDUPE
|
|
12
|
+
const pageConfigsUserFriendly = Object.fromEntries(pageConfigs.map((pageConfig) => {
|
|
13
|
+
const configValues = { ...pageConfigGlobal.configValues, ...pageConfig.configValues };
|
|
14
|
+
const page = {
|
|
15
|
+
...getPageConfigUserFriendlyNew({ configValues }),
|
|
16
|
+
route: pageConfig.routeFilesystem?.routeString ?? null
|
|
17
|
+
};
|
|
18
|
+
return [pageConfig.pageId, page];
|
|
19
|
+
}));
|
|
20
|
+
return { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, globalConfig, pageConfigsUserFriendly };
|
|
12
21
|
}
|
|
13
22
|
function getAllPageIds(pageFilesAll, pageConfigs) {
|
|
14
23
|
const fileIds = pageFilesAll.filter(({ isDefaultPageFile }) => !isDefaultPageFile).map(({ pageId }) => pageId);
|
|
@@ -2,6 +2,7 @@ export { getPageConfigUserFriendlyOld };
|
|
|
2
2
|
export { getPageConfigUserFriendlyNew };
|
|
3
3
|
export type { ConfigUserFriendly };
|
|
4
4
|
export type { PageConfigUserFriendly };
|
|
5
|
+
export type { PageConfigsUserFriendly };
|
|
5
6
|
export type { Source };
|
|
6
7
|
export type { Sources };
|
|
7
8
|
export type { From };
|
|
@@ -73,6 +74,11 @@ type SourceConfigsComputed = {
|
|
|
73
74
|
type: 'configsComputed';
|
|
74
75
|
value: unknown;
|
|
75
76
|
};
|
|
77
|
+
type PageConfigsUserFriendly = Record<string, // pageId
|
|
78
|
+
// pageId
|
|
79
|
+
ConfigUserFriendly & {
|
|
80
|
+
route: string | null;
|
|
81
|
+
}>;
|
|
76
82
|
type ConfigUserFriendly = {
|
|
77
83
|
config: ConfigResolved;
|
|
78
84
|
_source: Source;
|
|
@@ -8,7 +8,7 @@ import { getDefinedAtString } from '../page-configs/getConfigDefinedAt.js';
|
|
|
8
8
|
import { warnDeprecatedAllowKey } from './resolveRouteFunction.js';
|
|
9
9
|
import { getHookFromPageConfigGlobal, getHookTimeoutDefault } from '../hooks/getHook.js';
|
|
10
10
|
async function loadPageRoutes(
|
|
11
|
-
// Remove all arguments and use
|
|
11
|
+
// Remove all arguments and use GlobalContextInternal instead?
|
|
12
12
|
pageFilesAll, pageConfigs, pageConfigGlobal, allPageIds) {
|
|
13
13
|
// TODO/next-major: remove & make this function sync
|
|
14
14
|
await Promise.all(pageFilesAll.filter((p) => p.fileType === '.page.route').map((p) => p.loadFile?.()));
|
|
@@ -12,6 +12,7 @@ import type { ConfigEntries, ExportsAll, From, Source, Sources } from './page-co
|
|
|
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';
|
|
15
|
+
import type { GlobalContextPublic } from '../node/runtime/globalContext.js';
|
|
15
16
|
type PageContextServer<Data = unknown> = PageContextBuiltInServer<Data> & Vike.PageContext;
|
|
16
17
|
type PageContext<Data = unknown> = PageContextClient<Data> | PageContextServer<Data>;
|
|
17
18
|
type PageContextClient<Data = unknown> = PageContextBuiltInClientWithClientRouting<Data> & Vike.PageContext;
|
|
@@ -118,6 +119,14 @@ type PageContextBuiltInCommon<Data> = {
|
|
|
118
119
|
source: Source;
|
|
119
120
|
/** @experimental https://github.com/vikejs/vike/issues/1268 */
|
|
120
121
|
sources: Sources;
|
|
122
|
+
/**
|
|
123
|
+
* Information shared by all pages.
|
|
124
|
+
*
|
|
125
|
+
* https://vike.dev/getGlobalContext
|
|
126
|
+
*
|
|
127
|
+
* @experimental
|
|
128
|
+
*/
|
|
129
|
+
globalContext: GlobalContextPublic;
|
|
121
130
|
/** @deprecated */
|
|
122
131
|
url: string;
|
|
123
132
|
/** @deprecated */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.222-commit-207e079";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.
|
|
2
|
+
export const PROJECT_VERSION = '0.4.222-commit-207e079';
|
|
@@ -22,7 +22,7 @@ function assertSingleInstance() {
|
|
|
22
22
|
const versions = unique(globalObject.instances);
|
|
23
23
|
assertUsage(versions.length <= 1,
|
|
24
24
|
// DO *NOT* patch vike to remove this error: because of multiple conflicting versions, you *will* eventually encounter insidious issues that hard to debug and potentially a security hazard, see for example https://github.com/vikejs/vike/issues/1108
|
|
25
|
-
`vike@${pc.bold(versions[0])} and vike@${pc.bold(versions[1])} loaded but
|
|
25
|
+
`vike@${pc.bold(versions[0])} and vike@${pc.bold(versions[1])} loaded but it's forbidden to load different versions`);
|
|
26
26
|
}
|
|
27
27
|
if (globalObject.checkSingleInstance && globalObject.instances.length > 1) {
|
|
28
28
|
/*/ Not sure whether circular dependency can cause problems? In principle not since client-side code is ESM.
|