vike 0.4.222-commit-207e079 → 0.4.222-commit-5513d32
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/buildApp.js +9 -5
- package/dist/cjs/node/plugin/plugins/buildConfig.js +3 -0
- package/dist/cjs/node/plugin/plugins/envVars.js +0 -1
- package/dist/cjs/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +7 -14
- package/dist/cjs/node/plugin/shared/getHttpRequestAsyncStore.js +1 -1
- package/dist/cjs/node/runtime/globalContext.js +1 -1
- package/dist/cjs/node/runtime/renderPage/loadUserFilesServerSide.js +1 -1
- package/dist/cjs/node/runtime/renderPage.js +17 -13
- package/dist/cjs/node/runtime/universal-middleware.js +14 -0
- package/dist/cjs/shared/getPageConfigsRuntime.js +2 -8
- package/dist/cjs/shared/getPageContextUrlComputed.js +2 -2
- package/dist/cjs/shared/page-configs/getPageConfigUserFriendly.js +44 -12
- package/dist/cjs/shared/page-configs/serialize/parsePageConfigs.js +2 -8
- package/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/cjs/utils/assert.js +1 -1
- package/dist/cjs/utils/parseUrl-extras.js +2 -2
- package/dist/cjs/utils/parseUrl.js +5 -5
- package/dist/esm/client/client-routing-runtime/getPageContextCurrent.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/getPageContextFromHooks.d.ts +4 -4
- package/dist/esm/client/client-routing-runtime/prefetch/getPrefetchSettings.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/prefetch.js +2 -2
- package/dist/esm/client/client-routing-runtime/skipLink.js +2 -2
- package/dist/esm/client/server-routing-runtime/getPageContext.d.ts +1 -1
- package/dist/esm/client/shared/executeOnRenderClientHook.d.ts +2 -2
- package/dist/esm/client/shared/loadUserFilesClientSide.d.ts +2 -2
- package/dist/esm/client/shared/loadUserFilesClientSide.js +2 -2
- package/dist/esm/client/shared/preparePageContextForUserConsumptionClientSide.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/buildApp.js +9 -5
- package/dist/esm/node/plugin/plugins/buildConfig.js +3 -0
- package/dist/esm/node/plugin/plugins/envVars.js +0 -1
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.d.ts +2 -2
- package/dist/esm/node/plugin/plugins/importUserCode/v1-design/getVikeConfig.js +8 -15
- package/dist/esm/node/plugin/shared/getHttpRequestAsyncStore.js +2 -2
- package/dist/esm/node/runtime/globalContext.d.ts +2 -2
- package/dist/esm/node/runtime/globalContext.js +1 -1
- package/dist/esm/node/runtime/renderPage/executeOnBeforeRenderAndDataHooks.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.d.ts +1 -1
- package/dist/esm/node/runtime/renderPage/loadUserFilesServerSide.js +2 -2
- package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts +2 -2
- package/dist/esm/node/runtime/renderPage/renderPageAlreadyRouted.d.ts +4 -4
- package/dist/esm/node/runtime/renderPage.d.ts +5 -5
- package/dist/esm/node/runtime/renderPage.js +17 -12
- package/dist/esm/node/runtime/universal-middleware.d.ts +1 -0
- package/dist/esm/node/runtime/universal-middleware.js +11 -0
- package/dist/esm/shared/getPageConfigsRuntime.d.ts +2 -2
- package/dist/esm/shared/getPageConfigsRuntime.js +3 -9
- package/dist/esm/shared/getPageContextUrlComputed.js +2 -2
- package/dist/esm/shared/getPageFiles.d.ts +1 -1
- package/dist/esm/shared/hooks/getHook.d.ts +3 -3
- package/dist/esm/shared/page-configs/Config.d.ts +3 -1
- package/dist/esm/shared/page-configs/PageConfig.d.ts +9 -2
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.d.ts +24 -16
- package/dist/esm/shared/page-configs/getPageConfigUserFriendly.js +44 -12
- package/dist/esm/shared/page-configs/serialize/PageConfigSerialized.d.ts +3 -2
- package/dist/esm/shared/page-configs/serialize/parsePageConfigs.js +2 -8
- package/dist/esm/shared/route/executeGuardHook.d.ts +2 -2
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/assert.js +1 -1
- package/dist/esm/utils/parseUrl-extras.js +2 -2
- package/dist/esm/utils/parseUrl.d.ts +3 -4
- package/dist/esm/utils/parseUrl.js +5 -5
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +15 -2
- package/universal-middleware.js +3 -0
|
@@ -7,6 +7,9 @@ import { getVikeConfig } from './importUserCode/v1-design/getVikeConfig.js';
|
|
|
7
7
|
import { getFullBuildInlineConfig } from '../shared/getFullBuildInlineConfig.js';
|
|
8
8
|
function buildApp() {
|
|
9
9
|
let config;
|
|
10
|
+
// `builder.buildApp` can be overriden by another plugin e.g vike-vercel https://github.com/vikejs/vike/pull/2184#issuecomment-2659425195
|
|
11
|
+
// In that case, we should'nt `forceExit`.
|
|
12
|
+
let forceExit = false;
|
|
10
13
|
return [
|
|
11
14
|
{
|
|
12
15
|
name: 'vike:buildApp',
|
|
@@ -21,6 +24,10 @@ function buildApp() {
|
|
|
21
24
|
assert(builder.environments.ssr);
|
|
22
25
|
await builder.build(builder.environments.client);
|
|
23
26
|
await builder.build(builder.environments.ssr);
|
|
27
|
+
if (forceExit) {
|
|
28
|
+
runPrerender_forceExit();
|
|
29
|
+
assert(false);
|
|
30
|
+
}
|
|
24
31
|
}
|
|
25
32
|
},
|
|
26
33
|
environments: {
|
|
@@ -59,11 +66,8 @@ function buildApp() {
|
|
|
59
66
|
if (!isPrerenderAutoRunEnabled(vikeConfig))
|
|
60
67
|
return;
|
|
61
68
|
const configInline = getFullBuildInlineConfig(config);
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
runPrerender_forceExit();
|
|
65
|
-
assert(false);
|
|
66
|
-
}
|
|
69
|
+
const res = await runPrerenderFromAutoRun(configInline, config);
|
|
70
|
+
forceExit = res.forceExit;
|
|
67
71
|
}
|
|
68
72
|
}
|
|
69
73
|
];
|
|
@@ -80,6 +80,9 @@ function buildConfig() {
|
|
|
80
80
|
{
|
|
81
81
|
name: 'vike:buildConfig:pre',
|
|
82
82
|
apply: 'build',
|
|
83
|
+
applyToEnvironment(env) {
|
|
84
|
+
return env.name === 'ssr';
|
|
85
|
+
},
|
|
83
86
|
// Make sure other writeBundle() hooks are called after this writeBundle() hook.
|
|
84
87
|
// - set_ASSETS_MANIFEST() needs to be called before dist/server/ code is executed.
|
|
85
88
|
// - For example, the writeBundle() hook of vite-plugin-vercel needs to be called after this writeBundle() hook, otherwise: https://github.com/vikejs/vike/issues/1527
|
|
@@ -9,12 +9,12 @@ export type { VikeConfigObject };
|
|
|
9
9
|
import type { PageConfigGlobalBuildTime, PageConfigBuildTime } from '../../../../../shared/page-configs/PageConfig.js';
|
|
10
10
|
import { type ConfigDefinitions, type ConfigDefinitionInternal } from './getVikeConfig/configDefinitionsBuiltIn.js';
|
|
11
11
|
import type { ResolvedConfig } from 'vite';
|
|
12
|
-
import { type
|
|
12
|
+
import { type PageConfigUserFriendly, type PageConfigsUserFriendly } from '../../../../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
13
13
|
import { type PlusFile } from './getVikeConfig/getPlusFilesAll.js';
|
|
14
14
|
type VikeConfigObject = {
|
|
15
15
|
pageConfigs: PageConfigBuildTime[];
|
|
16
16
|
pageConfigGlobal: PageConfigGlobalBuildTime;
|
|
17
|
-
global:
|
|
17
|
+
global: PageConfigUserFriendly;
|
|
18
18
|
pages: PageConfigsUserFriendly;
|
|
19
19
|
};
|
|
20
20
|
declare const vikeConfigDependencies: Set<string>;
|
|
@@ -19,7 +19,7 @@ import { resolvePointerImport } from './getVikeConfig/resolvePointerImport.js';
|
|
|
19
19
|
import { getFilePathResolved } from '../../../shared/getFilePath.js';
|
|
20
20
|
import { getConfigValueBuildTime } from '../../../../../shared/page-configs/getConfigValueBuildTime.js';
|
|
21
21
|
import { assertExtensionsRequire } from './getVikeConfig/assertExtensions.js';
|
|
22
|
-
import {
|
|
22
|
+
import { getPageConfigGlobalUserFriendly, getPageConfigUserFriendly } from '../../../../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
23
23
|
import { getConfigValuesBase } from '../../../../../shared/page-configs/serialize/serializeConfigValues.js';
|
|
24
24
|
import { getPlusFilesAll } from './getVikeConfig/getPlusFilesAll.js';
|
|
25
25
|
assertIsNotProductionRuntime();
|
|
@@ -127,7 +127,7 @@ async function loadVikeConfig_withErrorHandling(userRootDir, isDev, vikeVitePlug
|
|
|
127
127
|
configDefinitions: {},
|
|
128
128
|
configValueSources: {}
|
|
129
129
|
},
|
|
130
|
-
global:
|
|
130
|
+
global: getPageConfigGlobalUserFriendly({ pageConfigGlobalValues: {} }),
|
|
131
131
|
pages: {}
|
|
132
132
|
};
|
|
133
133
|
return dummyData;
|
|
@@ -143,18 +143,12 @@ async function loadVikeConfig(userRootDir, vikeVitePluginOptions) {
|
|
|
143
143
|
// interop vike(options) in vite.config.js
|
|
144
144
|
temp_interopVikeVitePlugin(pageConfigGlobal, vikeVitePluginOptions, userRootDir);
|
|
145
145
|
// global
|
|
146
|
-
const
|
|
147
|
-
const global =
|
|
148
|
-
// TODO/now DEDUPE
|
|
146
|
+
const pageConfigGlobalValues = getConfigValues(pageConfigGlobal);
|
|
147
|
+
const global = getPageConfigGlobalUserFriendly({ pageConfigGlobalValues });
|
|
149
148
|
// pages
|
|
150
149
|
const pages = objectFromEntries(pageConfigs.map((pageConfig) => {
|
|
151
|
-
const
|
|
152
|
-
|
|
153
|
-
const page = {
|
|
154
|
-
...getPageConfigUserFriendlyNew({ configValues }),
|
|
155
|
-
route: pageConfig.routeFilesystem?.routeString ?? null
|
|
156
|
-
};
|
|
157
|
-
return [pageConfig.pageId, page];
|
|
150
|
+
const pageConfigValues = getConfigValues(pageConfig, true);
|
|
151
|
+
return getPageConfigUserFriendly(pageConfigGlobalValues, pageConfig, pageConfigValues);
|
|
158
152
|
}));
|
|
159
153
|
return { pageConfigs, pageConfigGlobal, global, pages };
|
|
160
154
|
}
|
|
@@ -219,13 +213,12 @@ function getPageConfigsBuildTime(configDefinitionsResolved, plusFilesAll, userRo
|
|
|
219
213
|
return;
|
|
220
214
|
configValueSources[configName] = sources;
|
|
221
215
|
});
|
|
222
|
-
const
|
|
216
|
+
const pageConfigRoute = determineRouteFilesystem(locationId, configValueSources);
|
|
223
217
|
applyEffectsAll(configValueSources, configDefinitionsLocal);
|
|
224
218
|
const configValuesComputed = getComputed(configValueSources, configDefinitionsLocal);
|
|
225
219
|
const pageConfig = {
|
|
226
220
|
pageId: locationId,
|
|
227
|
-
|
|
228
|
-
routeFilesystem,
|
|
221
|
+
...pageConfigRoute,
|
|
229
222
|
configDefinitions: configDefinitionsLocal,
|
|
230
223
|
plusFiles: plusFilesRelevant,
|
|
231
224
|
configValueSources,
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// - We dedupe errors ourself with getHttpRequestAsyncStore().shouldErrorBeSwallowed()
|
|
11
11
|
export { getHttpRequestAsyncStore };
|
|
12
12
|
export { installHttpRequestAsyncStore };
|
|
13
|
-
import {
|
|
13
|
+
import { renderPage_addAsyncHookwrapper } from '../../runtime/renderPage.js';
|
|
14
14
|
import { assert, assertIsNotProductionRuntime, isObject, unique } from '../utils.js';
|
|
15
15
|
import { getConfigBuildErrorFormatted } from '../plugins/importUserCode/v1-design/getVikeConfig/transpileAndExecuteFile.js';
|
|
16
16
|
import { logErrorDebugNote } from './loggerNotProd.js';
|
|
@@ -27,7 +27,7 @@ async function installHttpRequestAsyncStore() {
|
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
29
|
asyncLocalStorage = new mod.AsyncLocalStorage();
|
|
30
|
-
|
|
30
|
+
renderPage_addAsyncHookwrapper(async (httpRequestId, renderPage) => {
|
|
31
31
|
assert(asyncLocalStorage);
|
|
32
32
|
const loggedErrors = new Set();
|
|
33
33
|
const markErrorAsLogged = (err) => {
|
|
@@ -20,7 +20,7 @@ export type { GlobalContextInternal };
|
|
|
20
20
|
export type { GlobalContextPublic };
|
|
21
21
|
import type { ViteManifest } from '../shared/ViteManifest.js';
|
|
22
22
|
import type { ResolvedConfig, ViteDevServer } from 'vite';
|
|
23
|
-
import type {
|
|
23
|
+
import type { PageConfigUserFriendly, PageConfigsUserFriendly } from '../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
24
24
|
import type { ConfigVitePluginServerEntry } from '@brillout/vite-plugin-server-entry/plugin';
|
|
25
25
|
import { type BaseUrlsResolved } from '../shared/resolveBase.js';
|
|
26
26
|
type GlobalContextPublic = Pick<GlobalContext, 'assetsManifest' | 'config' | 'viteConfig' | 'pages' | 'baseAssets' | 'baseServer'>;
|
|
@@ -32,7 +32,7 @@ type GlobalContext = {
|
|
|
32
32
|
viteConfigRuntime: {
|
|
33
33
|
_baseViteOriginal: null | string;
|
|
34
34
|
};
|
|
35
|
-
config:
|
|
35
|
+
config: PageConfigUserFriendly['config'];
|
|
36
36
|
pages: PageConfigsUserFriendly;
|
|
37
37
|
} & BaseUrlsResolved & PageRuntimeInfo & ({
|
|
38
38
|
isProduction: false;
|
|
@@ -124,7 +124,7 @@ function getViteConfig() {
|
|
|
124
124
|
}
|
|
125
125
|
async function initGlobalContext_renderPage() {
|
|
126
126
|
debug('initGlobalContext_renderPage()');
|
|
127
|
-
// globalObject.isProduction
|
|
127
|
+
// `globalObject.isProduction === undefined` when using production server without `vike-server`. (There isn't any reliable signal we can use to determine early whether the environement is production or development.)
|
|
128
128
|
if (globalObject.isProduction === undefined)
|
|
129
129
|
setIsProduction(true);
|
|
130
130
|
await initGlobalContext();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { executeOnBeforeRenderAndDataHooks };
|
|
2
|
-
import { type
|
|
2
|
+
import { type PageConfigUserFriendlyOld } from '../../../shared/getPageFiles.js';
|
|
3
3
|
import { type PageContextForUserConsumptionServerSide } from './preparePageContextForUserConsumptionServerSide.js';
|
|
4
4
|
declare function executeOnBeforeRenderAndDataHooks(pageContext: {
|
|
5
5
|
pageId: string;
|
|
6
6
|
_pageContextAlreadyProvidedByOnPrerenderHook?: true;
|
|
7
|
-
} &
|
|
7
|
+
} & PageConfigUserFriendlyOld & PageContextForUserConsumptionServerSide): Promise<void>;
|
|
@@ -16,7 +16,7 @@ type PageContext_loadUserFilesServerSide = PageContextGetPageAssets & PageContex
|
|
|
16
16
|
type PageFiles = PromiseType<ReturnType<typeof loadUserFilesServerSide>>;
|
|
17
17
|
declare function loadUserFilesServerSide(pageContext: {
|
|
18
18
|
pageId: string;
|
|
19
|
-
} & PageContext_loadUserFilesServerSide): Promise<import("../../../shared/getPageFiles.js").
|
|
19
|
+
} & PageContext_loadUserFilesServerSide): Promise<import("../../../shared/getPageFiles.js").PageConfigUserFriendlyOld & {
|
|
20
20
|
Page: unknown;
|
|
21
21
|
_isHtmlOnly: boolean;
|
|
22
22
|
_passToClient: string[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { loadUserFilesServerSide };
|
|
2
2
|
import { getPageFilesServerSide } from '../../../shared/getPageFiles.js';
|
|
3
|
-
import {
|
|
3
|
+
import { getPageConfigUserFriendly_oldDesign } from '../../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
4
4
|
import { analyzePageClientSideInit } from '../../../shared/getPageFiles/analyzePageClientSide.js';
|
|
5
5
|
import { assert, assertUsage, assertWarning, hasProp, isArrayOfStrings, objectAssign, isArray } from '../utils.js';
|
|
6
6
|
import { getPageAssets } from './getPageAssets.js';
|
|
@@ -100,7 +100,7 @@ async function loadPageUserFiles(pageFilesAll, pageConfig, pageConfigGlobal, pag
|
|
|
100
100
|
const pageFilesServerSide = getPageFilesServerSide(pageFilesAll, pageId);
|
|
101
101
|
const pageConfigLoaded = !pageConfig ? null : await loadConfigValues(pageConfig, isDev);
|
|
102
102
|
await Promise.all(pageFilesServerSide.map((p) => p.loadFile?.()));
|
|
103
|
-
const pageContextExports =
|
|
103
|
+
const pageContextExports = getPageConfigUserFriendly_oldDesign(pageFilesServerSide, pageConfigLoaded, pageConfigGlobal);
|
|
104
104
|
return {
|
|
105
105
|
pageContextExports,
|
|
106
106
|
pageFilesLoaded: pageFilesServerSide
|
package/dist/esm/node/runtime/renderPage/preparePageContextForUserConsumptionServerSide.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ export { preparePageContextForUserConsumptionServerSide };
|
|
|
2
2
|
export type { PageContextForUserConsumptionServerSide };
|
|
3
3
|
import { PageContextUrlInternal } from '../../../shared/getPageContextUrlComputed.js';
|
|
4
4
|
import type { PageConfigRuntime } from '../../../shared/page-configs/PageConfig.js';
|
|
5
|
-
import type {
|
|
5
|
+
import type { PageConfigUserFriendlyOld } from '../../../shared/page-configs/getPageConfigUserFriendly.js';
|
|
6
6
|
import { PageContextBuiltInServerInternal } from '../../../shared/types.js';
|
|
7
7
|
import type { GlobalContextInternal, GlobalContextPublic } from '../globalContext.js';
|
|
8
|
-
type PageContextForUserConsumptionServerSide = PageContextBuiltInServerInternal &
|
|
8
|
+
type PageContextForUserConsumptionServerSide = PageContextBuiltInServerInternal & PageConfigUserFriendlyOld & {
|
|
9
9
|
urlOriginal: string;
|
|
10
10
|
/** @deprecated */
|
|
11
11
|
url: string;
|
|
@@ -63,7 +63,7 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
|
|
|
63
63
|
url: string;
|
|
64
64
|
} & {
|
|
65
65
|
headers: Record<string, string> | null;
|
|
66
|
-
} & import("../../../shared/getPageFiles.js").
|
|
66
|
+
} & import("../../../shared/getPageFiles.js").PageConfigUserFriendlyOld & {
|
|
67
67
|
Page: unknown;
|
|
68
68
|
_isHtmlOnly: boolean;
|
|
69
69
|
_passToClient: string[];
|
|
@@ -117,7 +117,7 @@ declare function prerenderPage(pageContext: PageContextInitEnhanced & PageFiles
|
|
|
117
117
|
url: string;
|
|
118
118
|
} & {
|
|
119
119
|
headers: Record<string, string> | null;
|
|
120
|
-
} & import("../../../shared/getPageFiles.js").
|
|
120
|
+
} & import("../../../shared/getPageFiles.js").PageConfigUserFriendlyOld & {
|
|
121
121
|
Page: unknown;
|
|
122
122
|
_isHtmlOnly: boolean;
|
|
123
123
|
_passToClient: string[];
|
|
@@ -172,7 +172,7 @@ declare function prerender404Page(pageContextInit_: Record<string, unknown> | nu
|
|
|
172
172
|
url: string;
|
|
173
173
|
} & {
|
|
174
174
|
headers: Record<string, string> | null;
|
|
175
|
-
} & import("../../../shared/getPageFiles.js").
|
|
175
|
+
} & import("../../../shared/getPageFiles.js").PageConfigUserFriendlyOld & {
|
|
176
176
|
Page: unknown;
|
|
177
177
|
_isHtmlOnly: boolean;
|
|
178
178
|
_passToClient: string[];
|
|
@@ -226,7 +226,7 @@ declare function prerender404Page(pageContextInit_: Record<string, unknown> | nu
|
|
|
226
226
|
url: string;
|
|
227
227
|
} & {
|
|
228
228
|
headers: Record<string, string> | null;
|
|
229
|
-
} & import("../../../shared/getPageFiles.js").
|
|
229
|
+
} & import("../../../shared/getPageFiles.js").PageConfigUserFriendlyOld & {
|
|
230
230
|
Page: unknown;
|
|
231
231
|
_isHtmlOnly: boolean;
|
|
232
232
|
_passToClient: string[];
|
|
@@ -1,11 +1,7 @@
|
|
|
1
1
|
export { renderPage };
|
|
2
|
-
export {
|
|
2
|
+
export { renderPage_addAsyncHookwrapper };
|
|
3
3
|
import { HttpResponse } from './renderPage/createHttpResponse.js';
|
|
4
4
|
import type { PageContextServer } from '../../types/index.js';
|
|
5
|
-
declare let renderPage_wrapper: <PageContext>(_httpRequestId: number, ret: () => Promise<PageContext>) => Promise<{
|
|
6
|
-
pageContextReturn: Awaited<PageContext>;
|
|
7
|
-
}>;
|
|
8
|
-
declare const renderPage_addWrapper: (wrapper: typeof renderPage_wrapper) => void;
|
|
9
5
|
declare function renderPage<PageContextUserAdded extends {}, PageContextInit extends {
|
|
10
6
|
/** @deprecated */
|
|
11
7
|
url?: string;
|
|
@@ -14,3 +10,7 @@ declare function renderPage<PageContextUserAdded extends {}, PageContextInit ext
|
|
|
14
10
|
}>(pageContextInit: PageContextInit): Promise<PageContextInit & {
|
|
15
11
|
httpResponse: HttpResponse;
|
|
16
12
|
} & Partial<PageContextServer & PageContextUserAdded>>;
|
|
13
|
+
declare let asyncHookWrapper: <PageContext>(_httpRequestId: number, ret: () => Promise<PageContext>) => Promise<{
|
|
14
|
+
pageContextReturn: Awaited<PageContext>;
|
|
15
|
+
}>;
|
|
16
|
+
declare function renderPage_addAsyncHookwrapper(wrapper: typeof asyncHookWrapper): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { renderPage };
|
|
2
|
-
export {
|
|
2
|
+
export { renderPage_addAsyncHookwrapper };
|
|
3
3
|
import { getPageContextInitEnhanced, renderPageAlreadyRouted } from './renderPage/renderPageAlreadyRouted.js';
|
|
4
4
|
import { route } from '../../shared/route/index.js';
|
|
5
5
|
import { assert, hasProp, objectAssign, isUrl, parseUrl, onSetupRuntime, assertWarning, getGlobalObject, checkType, assertUsage, normalizeUrlPathname, removeBaseServer, modifyUrlPathname, prependBase, removeUrlOrigin, setUrlOrigin, createUrlFromComponents, isUri, getUrlPretty } from './utils.js';
|
|
@@ -21,12 +21,6 @@ import { resolveRedirects } from './renderPage/resolveRedirects.js';
|
|
|
21
21
|
const globalObject = getGlobalObject('runtime/renderPage.ts', {
|
|
22
22
|
httpRequestsCount: 0
|
|
23
23
|
});
|
|
24
|
-
let renderPage_wrapper = async (_httpRequestId, ret) => ({
|
|
25
|
-
pageContextReturn: await ret()
|
|
26
|
-
});
|
|
27
|
-
const renderPage_addWrapper = (wrapper) => {
|
|
28
|
-
renderPage_wrapper = wrapper;
|
|
29
|
-
};
|
|
30
24
|
// `renderPage()` calls `renderPageNominal()` while ensuring that errors are `console.error(err)` instead of `throw err`, so that Vike never triggers a server shut down. (Throwing an error in an Express.js middleware shuts down the whole Express.js server.)
|
|
31
25
|
async function renderPage(pageContextInit) {
|
|
32
26
|
assertArguments(...arguments);
|
|
@@ -40,12 +34,20 @@ async function renderPage(pageContextInit) {
|
|
|
40
34
|
const httpRequestId = getRequestId();
|
|
41
35
|
const urlOriginalPretty = getUrlPretty(pageContextInit.urlOriginal);
|
|
42
36
|
logHttpRequest(urlOriginalPretty, httpRequestId);
|
|
43
|
-
const { pageContextReturn } = await
|
|
37
|
+
const { pageContextReturn } = await asyncHookWrapper(httpRequestId, () => renderPageAndPrepare(pageContextInit, httpRequestId));
|
|
44
38
|
logHttpResponse(urlOriginalPretty, httpRequestId, pageContextReturn);
|
|
45
39
|
checkType(pageContextReturn);
|
|
46
40
|
assert(pageContextReturn.httpResponse);
|
|
47
41
|
return pageContextReturn;
|
|
48
42
|
}
|
|
43
|
+
// Fallback wrapper if node:async_hooks isn't available
|
|
44
|
+
let asyncHookWrapper = async (_httpRequestId, ret) => ({
|
|
45
|
+
pageContextReturn: await ret()
|
|
46
|
+
});
|
|
47
|
+
// Add node:async_hooks wrapper
|
|
48
|
+
function renderPage_addAsyncHookwrapper(wrapper) {
|
|
49
|
+
asyncHookWrapper = wrapper;
|
|
50
|
+
}
|
|
49
51
|
async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
50
52
|
// Invalid config
|
|
51
53
|
const handleInvalidConfig = (err) => {
|
|
@@ -64,8 +66,11 @@ async function renderPageAndPrepare(pageContextInit, httpRequestId) {
|
|
|
64
66
|
await initGlobalContext_renderPage();
|
|
65
67
|
}
|
|
66
68
|
catch (err) {
|
|
67
|
-
// Errors are expected since assertUsage() is used in
|
|
68
|
-
//
|
|
69
|
+
// Errors are expected since assertUsage() is used in initGlobalContext_renderPage() such as:
|
|
70
|
+
// ```bash
|
|
71
|
+
// Re-build your app (you're using 1.2.3 but your app was built with 1.2.2)
|
|
72
|
+
// ```
|
|
73
|
+
// initGlobalContext_renderPage() doens't call any user hook => err isn't thrown from user code.
|
|
69
74
|
assert(!isAbortError(err));
|
|
70
75
|
logRuntimeError(err, httpRequestId);
|
|
71
76
|
const pageContextWithError = getPageContextHttpResponseError(err, pageContextInit, null);
|
|
@@ -452,6 +457,6 @@ async function assertBaseUrl(pageContextInit, globalContext) {
|
|
|
452
457
|
const { baseServer } = globalContext;
|
|
453
458
|
const { urlOriginal } = pageContextInit;
|
|
454
459
|
const { urlWithoutPageContextRequestSuffix } = handlePageContextRequestUrl(urlOriginal);
|
|
455
|
-
const {
|
|
456
|
-
assertUsage(
|
|
460
|
+
const { isBaseMissing } = parseUrl(urlWithoutPageContextRequestSuffix, baseServer);
|
|
461
|
+
assertUsage(!isBaseMissing, `${pc.code('renderPage(pageContextInit)')} (https://vike.dev/renderPage) called with ${pc.code(`pageContextInit.urlOriginal===${JSON.stringify(urlOriginal)}`)} which doesn't start with Base URL ${pc.code(baseServer)} (https://vike.dev/base-url)`);
|
|
457
462
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function universalVikeHandler(request: Request, context: Record<string, unknown>, runtime: Record<string, unknown>): Promise<Response>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { renderPage } from './index.js';
|
|
2
|
+
export default async function universalVikeHandler(request, context, runtime) {
|
|
3
|
+
const pageContextInit = { ...context, ...runtime, urlOriginal: request.url, headersOriginal: request.headers };
|
|
4
|
+
const pageContext = await renderPage(pageContextInit);
|
|
5
|
+
const response = pageContext.httpResponse;
|
|
6
|
+
const readable = response.getReadableWebStream();
|
|
7
|
+
return new Response(readable, {
|
|
8
|
+
status: response.statusCode,
|
|
9
|
+
headers: response.headers
|
|
10
|
+
});
|
|
11
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
export { getPageConfigsRuntime };
|
|
2
2
|
export { getAllPageIds };
|
|
3
3
|
import type { PageFile } from './getPageFiles.js';
|
|
4
|
-
import { type
|
|
4
|
+
import { type PageConfigUserFriendly, 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[];
|
|
8
8
|
allPageIds: string[];
|
|
9
9
|
pageConfigs: PageConfigRuntime[];
|
|
10
10
|
pageConfigGlobal: PageConfigGlobalRuntime;
|
|
11
|
-
globalConfig:
|
|
11
|
+
globalConfig: PageConfigUserFriendly;
|
|
12
12
|
pageConfigsUserFriendly: PageConfigsUserFriendly;
|
|
13
13
|
};
|
|
14
14
|
declare function getAllPageIds(pageFilesAll: PageFile[], pageConfigs: PageConfigRuntime[]): string[];
|
|
@@ -1,21 +1,15 @@
|
|
|
1
1
|
export { getPageConfigsRuntime };
|
|
2
2
|
export { getAllPageIds };
|
|
3
3
|
import { parseGlobResults } from './getPageFiles/parseGlobResults.js';
|
|
4
|
-
import {
|
|
4
|
+
import { getPageConfigGlobalUserFriendly, getPageConfigUserFriendly } from './page-configs/getPageConfigUserFriendly.js';
|
|
5
5
|
import { unique } from './utils.js';
|
|
6
6
|
function getPageConfigsRuntime(virtualFileExports) {
|
|
7
7
|
const { pageFilesAll, pageConfigs, pageConfigGlobal } = parseGlobResults(virtualFileExports);
|
|
8
8
|
const allPageIds = getAllPageIds(pageFilesAll, pageConfigs);
|
|
9
9
|
// TODO/now: re-use this call, instead of calling it twice
|
|
10
|
-
const globalConfig =
|
|
11
|
-
// TODO/now DEDUPE
|
|
10
|
+
const globalConfig = getPageConfigGlobalUserFriendly({ pageConfigGlobalValues: pageConfigGlobal.configValues });
|
|
12
11
|
const pageConfigsUserFriendly = Object.fromEntries(pageConfigs.map((pageConfig) => {
|
|
13
|
-
|
|
14
|
-
const page = {
|
|
15
|
-
...getPageConfigUserFriendlyNew({ configValues }),
|
|
16
|
-
route: pageConfig.routeFilesystem?.routeString ?? null
|
|
17
|
-
};
|
|
18
|
-
return [pageConfig.pageId, page];
|
|
12
|
+
return getPageConfigUserFriendly(pageConfigGlobal.configValues, pageConfig, pageConfig.configValues);
|
|
19
13
|
}));
|
|
20
14
|
return { pageFilesAll, allPageIds, pageConfigs, pageConfigGlobal, globalConfig, pageConfigsUserFriendly };
|
|
21
15
|
}
|
|
@@ -86,8 +86,8 @@ function urlGetter() {
|
|
|
86
86
|
}
|
|
87
87
|
function urlParsedGetter() {
|
|
88
88
|
const {
|
|
89
|
-
// remove
|
|
90
|
-
|
|
89
|
+
// remove isBaseMissing as it isn't part of UrlPublic
|
|
90
|
+
isBaseMissing: _, ...urlParsed } = getUrlParsed(this);
|
|
91
91
|
const hashIsAvailable = isBrowser();
|
|
92
92
|
const warnHashNotAvailable = (prop) => {
|
|
93
93
|
assertWarning(hashIsAvailable, `pageContext.urlParsed.${prop} isn't available on the server-side (HTTP requests don't include the URL hash)`, { onlyOnce: true, showStackTrace: true });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export type { PageFile } from './getPageFiles/getPageFileObject.js';
|
|
2
|
-
export type { ExportsAll,
|
|
2
|
+
export type { ExportsAll, PageConfigUserFriendlyOld } from './page-configs/getPageConfigUserFriendly.js';
|
|
3
3
|
export { getPageFilesClientSide } from './getPageFiles/getAllPageIdFiles.js';
|
|
4
4
|
export { getPageFilesServerSide } from './getPageFiles/getAllPageIdFiles.js';
|
|
@@ -9,7 +9,7 @@ export type { HookLoc };
|
|
|
9
9
|
export type { HookTimeout };
|
|
10
10
|
export type { HooksTimeoutProvidedByUser };
|
|
11
11
|
export { getHookTimeoutDefault };
|
|
12
|
-
import type {
|
|
12
|
+
import type { PageConfigUserFriendlyOld } from '../getPageFiles.js';
|
|
13
13
|
import type { HookName, HookNamePage, HookNameGlobal } from '../page-configs/Config.js';
|
|
14
14
|
import type { PageConfigGlobalRuntime, PageConfigRuntime } from '../page-configs/PageConfig.js';
|
|
15
15
|
type Hook = HookLoc & {
|
|
@@ -26,10 +26,10 @@ type HookTimeout = {
|
|
|
26
26
|
warning: number | false;
|
|
27
27
|
};
|
|
28
28
|
type HooksTimeoutProvidedByUser = false | Partial<Record<HookName, false | Partial<HookTimeout>>>;
|
|
29
|
-
declare function getHook(pageContext:
|
|
29
|
+
declare function getHook(pageContext: PageConfigUserFriendlyOld, hookName: HookName): null | Hook;
|
|
30
30
|
declare function getHookFromPageConfig(pageConfig: PageConfigRuntime, hookName: HookNamePage): null | Hook;
|
|
31
31
|
declare function getHookFromPageConfigGlobal(pageConfigGlobal: PageConfigGlobalRuntime, hookName: HookNameGlobal): null | Hook;
|
|
32
|
-
declare function assertHook<TPageContext extends
|
|
32
|
+
declare function assertHook<TPageContext extends PageConfigUserFriendlyOld, THookName extends PropertyKey & HookName>(pageContext: TPageContext, hookName: THookName): asserts pageContext is TPageContext & {
|
|
33
33
|
exports: Record<THookName, Function | undefined>;
|
|
34
34
|
};
|
|
35
35
|
declare function getHookTimeoutDefault(hookName: HookName): HookTimeout;
|
|
@@ -32,6 +32,7 @@ export type { OnRenderHtmlAsync };
|
|
|
32
32
|
export type { OnRenderHtmlSync };
|
|
33
33
|
export type { RouteAsync };
|
|
34
34
|
export type { RouteSync };
|
|
35
|
+
export type { Route };
|
|
35
36
|
export type { KeepScrollPosition };
|
|
36
37
|
import type { PrefetchSetting, PrefetchStaticAssets } from '../../client/client-routing-runtime/prefetch/PrefetchSetting.js';
|
|
37
38
|
import type { ConfigDefinition } from '../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/configDefinitionsBuiltIn.js';
|
|
@@ -223,6 +224,7 @@ type RouteSync = (pageContext: PageContextServer | PageContextClient) => {
|
|
|
223
224
|
routeParams?: Record<string, string>;
|
|
224
225
|
precedence?: number;
|
|
225
226
|
} | boolean;
|
|
227
|
+
type Route = string | RouteSync | RouteAsync;
|
|
226
228
|
/** Whether the page scrolls to the top upon navigation.
|
|
227
229
|
*
|
|
228
230
|
* https://vike.dev/keepScrollPosition
|
|
@@ -239,7 +241,7 @@ type ConfigBuiltIn = {
|
|
|
239
241
|
*
|
|
240
242
|
* https://vike.dev/route
|
|
241
243
|
*/
|
|
242
|
-
route?:
|
|
244
|
+
route?: Route | ImportString;
|
|
243
245
|
/** Protect page(s), e.g. forbid unauthorized access.
|
|
244
246
|
*
|
|
245
247
|
* https://vike.dev/guard
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export type { PageConfigRuntime };
|
|
2
2
|
export type { PageConfigRuntimeLoaded };
|
|
3
3
|
export type { PageConfigBuildTime };
|
|
4
|
+
export type { PageConfigCommon };
|
|
5
|
+
export type { PageConfigRoute };
|
|
4
6
|
export type { ConfigEnv };
|
|
5
7
|
export type { ConfigEnvInternal };
|
|
6
8
|
export type { PageConfigGlobalRuntime };
|
|
@@ -23,8 +25,13 @@ import type { ConfigDefinitions } from '../../node/plugin/plugins/importUserCode
|
|
|
23
25
|
import type { PlusFile, PlusFilesByLocationId } from '../../node/plugin/plugins/importUserCode/v1-design/getVikeConfig/getPlusFilesAll.js';
|
|
24
26
|
type PageConfigCommon = {
|
|
25
27
|
pageId: string;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
+
} & PageConfigRoute;
|
|
29
|
+
type PageConfigRoute = {
|
|
30
|
+
isErrorPage: true;
|
|
31
|
+
routeFilesystem?: undefined;
|
|
32
|
+
} | {
|
|
33
|
+
isErrorPage?: undefined;
|
|
34
|
+
routeFilesystem: {
|
|
28
35
|
routeString: string;
|
|
29
36
|
definedBy: string;
|
|
30
37
|
};
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
4
|
-
export type { PageConfigUserFriendly };
|
|
1
|
+
export { getPageConfigUserFriendly };
|
|
2
|
+
export { getPageConfigUserFriendly_oldDesign };
|
|
3
|
+
export { getPageConfigGlobalUserFriendly };
|
|
5
4
|
export type { PageConfigsUserFriendly };
|
|
5
|
+
export type { PageConfigUserFriendly };
|
|
6
|
+
export type { PageConfigUserFriendlyOld };
|
|
6
7
|
export type { Source };
|
|
7
8
|
export type { Sources };
|
|
8
9
|
export type { From };
|
|
@@ -10,9 +11,10 @@ export type { ExportsAll };
|
|
|
10
11
|
export type { ConfigEntries };
|
|
11
12
|
import type { FileType } from '../getPageFiles/fileTypes.js';
|
|
12
13
|
import type { PageFile } from '../getPageFiles/getPageFileObject.js';
|
|
13
|
-
import type { ConfigValues, PageConfigGlobalRuntime, PageConfigRuntimeLoaded } from './PageConfig.js';
|
|
14
|
+
import type { ConfigValues, PageConfigBuildTime, PageConfigGlobalRuntime, PageConfigRuntime, PageConfigRuntimeLoaded } from './PageConfig.js';
|
|
14
15
|
import { type ConfigDefinedAtOptional } from './getConfigDefinedAt.js';
|
|
15
16
|
import type { ConfigResolved } from './Config/PageContextConfig.js';
|
|
17
|
+
import type { Route } from './Config.js';
|
|
16
18
|
type ExportsAll = Record<string, {
|
|
17
19
|
exportValue: unknown;
|
|
18
20
|
exportSource: string;
|
|
@@ -33,7 +35,7 @@ type ConfigEntries = Record<string, {
|
|
|
33
35
|
configDefinedAt: ConfigDefinedAtOptional;
|
|
34
36
|
configDefinedByFile: string | null;
|
|
35
37
|
}[]>;
|
|
36
|
-
type
|
|
38
|
+
type PageConfigUserFriendlyOld = {
|
|
37
39
|
config: ConfigResolved;
|
|
38
40
|
source: Source;
|
|
39
41
|
sources: Sources;
|
|
@@ -74,18 +76,24 @@ type SourceConfigsComputed = {
|
|
|
74
76
|
type: 'configsComputed';
|
|
75
77
|
value: unknown;
|
|
76
78
|
};
|
|
77
|
-
type
|
|
78
|
-
// pageId
|
|
79
|
-
ConfigUserFriendly & {
|
|
80
|
-
route: string | null;
|
|
81
|
-
}>;
|
|
82
|
-
type ConfigUserFriendly = {
|
|
79
|
+
type PageConfigUserFriendly = {
|
|
83
80
|
config: ConfigResolved;
|
|
84
81
|
_source: Source;
|
|
85
82
|
_sources: Sources;
|
|
86
83
|
_from: From;
|
|
87
84
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
85
|
+
type PageConfigsUserFriendly = Record<string, // pageId
|
|
86
|
+
PageConfigUserFriendlyWithRoute>;
|
|
87
|
+
type WithRoute = {
|
|
88
|
+
route: Route;
|
|
89
|
+
isErrorPage?: undefined;
|
|
90
|
+
} | {
|
|
91
|
+
route?: undefined;
|
|
92
|
+
isErrorPage: true;
|
|
93
|
+
};
|
|
94
|
+
type PageConfigUserFriendlyWithRoute = PageConfigUserFriendly & WithRoute;
|
|
95
|
+
declare function getPageConfigUserFriendly(pageConfigGlobalValues: ConfigValues, pageConfig: PageConfigRuntime | PageConfigBuildTime, pageConfigValues: ConfigValues): [string, PageConfigUserFriendlyWithRoute];
|
|
96
|
+
declare function getPageConfigGlobalUserFriendly({ pageConfigGlobalValues }: {
|
|
97
|
+
pageConfigGlobalValues: ConfigValues;
|
|
98
|
+
}): PageConfigUserFriendly;
|
|
99
|
+
declare function getPageConfigUserFriendly_oldDesign(pageFiles: PageFile[], pageConfig: PageConfigRuntimeLoaded | null, pageConfigGlobal: PageConfigGlobalRuntime): PageConfigUserFriendlyOld;
|