vike-lite 1.0.13 → 1.0.14
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/__internal/server.d.mts +4 -7
- package/dist/__internal/shared.d.mts +2 -2
- package/dist/index-B6dJFVs8.d.mts +29 -0
- package/dist/index-kftPCG4J.d.mts +33 -0
- package/dist/index.d.mts +2 -65
- package/dist/server.mjs +27 -25
- package/dist/vite.mjs +7 -0
- package/package.json +1 -1
- package/dist/index-Ck5rzSdQ.d.mts +0 -22
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { r as Manifest } from "../index-B6dJFVs8.mjs";
|
|
2
|
+
import { t as Config } from "../index-kftPCG4J.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/server/store.d.ts
|
|
4
5
|
interface VikeState {
|
|
5
6
|
routes: any[];
|
|
6
7
|
errorRoute: any | null;
|
|
7
|
-
config:
|
|
8
|
-
|
|
9
|
-
default: (ctx: RenderContext) => Promise<string>;
|
|
10
|
-
}>;
|
|
11
|
-
} | null;
|
|
12
|
-
manifest: Record<string, any> | undefined;
|
|
8
|
+
config: Config | null;
|
|
9
|
+
manifest: Manifest | undefined;
|
|
13
10
|
}
|
|
14
11
|
declare const store: VikeState;
|
|
15
12
|
declare function setVikeState(newState: Partial<VikeState>): void;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as matchRoute, t as
|
|
2
|
-
export { RenderContext, matchRoute };
|
|
1
|
+
import { n as RenderContext, r as matchRoute, t as Config } from "../index-kftPCG4J.mjs";
|
|
2
|
+
export { Config, RenderContext, matchRoute };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/index.d.ts
|
|
2
|
+
type PageContext<Data = unknown> = {
|
|
3
|
+
routeParams: Record<string, string>;
|
|
4
|
+
urlOriginal: string;
|
|
5
|
+
urlPathname: string;
|
|
6
|
+
data?: Data;
|
|
7
|
+
title?: string;
|
|
8
|
+
is404?: boolean;
|
|
9
|
+
is500?: boolean;
|
|
10
|
+
errorMessage?: string;
|
|
11
|
+
};
|
|
12
|
+
type DataAsync<Data = unknown> = (pageContext: PageContext) => Promise<Data>;
|
|
13
|
+
type DataSync<Data = unknown> = (pageContext: PageContext) => Data;
|
|
14
|
+
type Route = {
|
|
15
|
+
path: string;
|
|
16
|
+
page: string;
|
|
17
|
+
layout?: string;
|
|
18
|
+
head?: string;
|
|
19
|
+
hasData?: boolean;
|
|
20
|
+
hasTitle?: boolean;
|
|
21
|
+
};
|
|
22
|
+
type Manifest = Record<string, {
|
|
23
|
+
file: string;
|
|
24
|
+
css?: string[];
|
|
25
|
+
imports?: string[];
|
|
26
|
+
isEntry?: boolean;
|
|
27
|
+
}>;
|
|
28
|
+
//#endregion
|
|
29
|
+
export { Route as a, PageContext as i, DataSync as n, Manifest as r, DataAsync as t };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
//#region src/shared/matchRoute.d.ts
|
|
2
|
+
declare function matchRoute(urlPathname: string, routes: typeof import('virtual:routes').routes): {
|
|
3
|
+
route: any;
|
|
4
|
+
routeParams: Record<string, string>;
|
|
5
|
+
} | null;
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/shared/index.d.ts
|
|
8
|
+
interface RenderContext {
|
|
9
|
+
pageContext: any;
|
|
10
|
+
Page: unknown;
|
|
11
|
+
Head?: unknown;
|
|
12
|
+
Layout?: unknown;
|
|
13
|
+
pageTitleTag: string;
|
|
14
|
+
serializedContext: string;
|
|
15
|
+
assets: {
|
|
16
|
+
cssLinks: string;
|
|
17
|
+
jsPreloads: string;
|
|
18
|
+
entryClient: string;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
type Config = {
|
|
22
|
+
onRenderHtml: () => Promise<{
|
|
23
|
+
default: (ctx: RenderContext) => Promise<string>;
|
|
24
|
+
}>;
|
|
25
|
+
onRenderClient: () => Promise<{
|
|
26
|
+
default: (opts: {
|
|
27
|
+
routes: any[];
|
|
28
|
+
errorRoute: any;
|
|
29
|
+
}) => void;
|
|
30
|
+
}>;
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
export { RenderContext as n, matchRoute as r, Config as t };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,65 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
routeParams: Record<string, string>;
|
|
4
|
-
urlOriginal: string;
|
|
5
|
-
urlPathname: string;
|
|
6
|
-
data?: Data;
|
|
7
|
-
title?: string;
|
|
8
|
-
is404?: boolean;
|
|
9
|
-
is500?: boolean;
|
|
10
|
-
errorMessage?: string;
|
|
11
|
-
};
|
|
12
|
-
type DataAsync<Data = unknown> = (pageContext: PageContext) => Promise<Data>;
|
|
13
|
-
type DataSync<Data = unknown> = (pageContext: PageContext) => Data;
|
|
14
|
-
type Route = {
|
|
15
|
-
path: string;
|
|
16
|
-
page: string;
|
|
17
|
-
layout?: string;
|
|
18
|
-
head?: string;
|
|
19
|
-
hasData?: boolean;
|
|
20
|
-
hasTitle?: boolean;
|
|
21
|
-
};
|
|
22
|
-
type Manifest = Record<string, {
|
|
23
|
-
file: string;
|
|
24
|
-
css?: string[];
|
|
25
|
-
imports?: string[];
|
|
26
|
-
}>;
|
|
27
|
-
declare module 'virtual:routes' {
|
|
28
|
-
type Imported<Name extends string, T> = () => Promise<({ [K in Name]: T } & {
|
|
29
|
-
default?: T;
|
|
30
|
-
}) | ({ [K in Name]?: T } & {
|
|
31
|
-
default: T;
|
|
32
|
-
})>;
|
|
33
|
-
const config: {
|
|
34
|
-
onRenderClient: () => Promise<{
|
|
35
|
-
onRenderClient: () => void;
|
|
36
|
-
}>;
|
|
37
|
-
onRenderHtml: () => Promise<{
|
|
38
|
-
onRenderHtml: (pageContext: any) => string;
|
|
39
|
-
}>;
|
|
40
|
-
};
|
|
41
|
-
const routes: Array<{
|
|
42
|
-
path: string;
|
|
43
|
-
page: string;
|
|
44
|
-
hasData: boolean;
|
|
45
|
-
hasTitle: boolean;
|
|
46
|
-
Page: Imported<'Page', HTMLElement>;
|
|
47
|
-
Head?: Imported<'Head', HTMLElement>;
|
|
48
|
-
Layout?: Imported<'Layout', HTMLElement>;
|
|
49
|
-
data?: Imported<'data', (pageContext: PageContext) => Promise<PageContext['data']>>;
|
|
50
|
-
title?: Imported<'title', string | ((pageContext: PageContext) => string)>;
|
|
51
|
-
}>;
|
|
52
|
-
const errorRoute: {
|
|
53
|
-
path: string;
|
|
54
|
-
page: string;
|
|
55
|
-
Page: Imported<'Page', HTMLElement>;
|
|
56
|
-
Head?: Imported<'Head', HTMLElement>;
|
|
57
|
-
Layout?: Imported<'Layout', HTMLElement>;
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
declare module 'virtual:client-manifest' {
|
|
61
|
-
const manifest: Manifest;
|
|
62
|
-
export default manifest;
|
|
63
|
-
}
|
|
64
|
-
//#endregion
|
|
65
|
-
export { DataAsync, DataSync, PageContext, Route };
|
|
1
|
+
import { a as Route, i as PageContext, n as DataSync, r as Manifest, t as DataAsync } from "./index-B6dJFVs8.mjs";
|
|
2
|
+
export { DataAsync, DataSync, Manifest, PageContext, Route };
|
package/dist/server.mjs
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
import { t as matchRoute } from "./matchRoute-BONrLRYy.mjs";
|
|
2
2
|
import { n as store } from "./store-BRWiOtOy.mjs";
|
|
3
|
+
//#region src/utils/serializeContext.ts
|
|
4
|
+
const ESCAPE_LOOKUP = {
|
|
5
|
+
"&": String.raw`\u0026`,
|
|
6
|
+
">": String.raw`\u003e`,
|
|
7
|
+
"<": String.raw`\u003c`,
|
|
8
|
+
"\u2028": String.raw`\u2028`,
|
|
9
|
+
"\u2029": String.raw`\u2029`
|
|
10
|
+
};
|
|
11
|
+
const ESCAPE_REGEX = /[&><\u{2028}\u{2029}]/gu;
|
|
12
|
+
function serializeContext(data) {
|
|
13
|
+
return JSON.stringify(data).replaceAll(ESCAPE_REGEX, (match) => ESCAPE_LOOKUP[match]);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
3
16
|
//#region src/server/abort.ts
|
|
4
17
|
var AbortRender = class extends Error {
|
|
5
18
|
statusCode;
|
|
@@ -13,17 +26,6 @@ var AbortRender = class extends Error {
|
|
|
13
26
|
//#endregion
|
|
14
27
|
//#region src/server/renderPage.tsx
|
|
15
28
|
const isProd = process.env.NODE_ENV === "production";
|
|
16
|
-
const ESCAPE_LOOKUP = {
|
|
17
|
-
"&": String.raw`\u0026`,
|
|
18
|
-
">": String.raw`\u003e`,
|
|
19
|
-
"<": String.raw`\u003c`,
|
|
20
|
-
"\u2028": String.raw`\u2028`,
|
|
21
|
-
"\u2029": String.raw`\u2029`
|
|
22
|
-
};
|
|
23
|
-
const ESCAPE_REGEX = /[&><\u{2028}\u{2029}]/gu;
|
|
24
|
-
function serializeContext(data) {
|
|
25
|
-
return JSON.stringify(data).replaceAll(ESCAPE_REGEX, (match) => ESCAPE_LOOKUP[match]);
|
|
26
|
-
}
|
|
27
29
|
function getAssets(pageModuleId) {
|
|
28
30
|
if (!isProd) return {
|
|
29
31
|
cssLinks: "",
|
|
@@ -32,10 +34,10 @@ function getAssets(pageModuleId) {
|
|
|
32
34
|
};
|
|
33
35
|
const cssFiles = /* @__PURE__ */ new Set();
|
|
34
36
|
const jsFiles = /* @__PURE__ */ new Set();
|
|
35
|
-
const manifest = store
|
|
36
|
-
function
|
|
37
|
+
const { manifest } = store;
|
|
38
|
+
function getVirtualEntryClientKey() {
|
|
37
39
|
for (const key in manifest) if (manifest[key].isEntry) return key;
|
|
38
|
-
throw new Error("
|
|
40
|
+
throw new Error("entry-client not found in manifest");
|
|
39
41
|
}
|
|
40
42
|
function collectAssets(key) {
|
|
41
43
|
const chunk = manifest[key];
|
|
@@ -44,23 +46,23 @@ function getAssets(pageModuleId) {
|
|
|
44
46
|
if (chunk.css) for (const css of chunk.css) cssFiles.add(css);
|
|
45
47
|
if (chunk.imports) for (const imp of chunk.imports) collectAssets(imp);
|
|
46
48
|
}
|
|
47
|
-
const
|
|
48
|
-
collectAssets(
|
|
49
|
+
const virtualEntryClientKey = getVirtualEntryClientKey();
|
|
50
|
+
collectAssets(virtualEntryClientKey);
|
|
49
51
|
collectAssets(pageModuleId.replace("@/", ""));
|
|
50
52
|
return {
|
|
51
53
|
cssLinks: [...cssFiles].map((href) => `<link rel="stylesheet" href="/${href}">`).join(""),
|
|
52
54
|
jsPreloads: [...jsFiles].map((href) => `<link rel="modulepreload" href="/${href}">`).join(""),
|
|
53
|
-
entryClient: "/" + manifest[
|
|
55
|
+
entryClient: "/" + manifest[virtualEntryClientKey].file
|
|
54
56
|
};
|
|
55
57
|
}
|
|
56
|
-
async function buildPageContext(
|
|
57
|
-
const matched = matchRoute(
|
|
58
|
+
async function buildPageContext(urlPathname, urlOriginal, isJsonRequest) {
|
|
59
|
+
const matched = matchRoute(urlPathname, store.routes);
|
|
58
60
|
if (!matched) return null;
|
|
59
61
|
const { route, routeParams } = matched;
|
|
60
62
|
const pageContext = {
|
|
61
63
|
routeParams,
|
|
62
|
-
urlOriginal
|
|
63
|
-
urlPathname
|
|
64
|
+
urlOriginal,
|
|
65
|
+
urlPathname
|
|
64
66
|
};
|
|
65
67
|
const [dataMod, titleMod, PageModule, HeadModule, LayoutModule] = await Promise.all([
|
|
66
68
|
route.data?.() ?? null,
|
|
@@ -72,14 +74,14 @@ async function buildPageContext(pathname, fullUrl, isJsonRequest) {
|
|
|
72
74
|
if (dataMod) try {
|
|
73
75
|
pageContext.data = await (dataMod.data ?? dataMod.default)(pageContext);
|
|
74
76
|
} catch (error) {
|
|
75
|
-
console.error("+data hook failed at:",
|
|
77
|
+
console.error("+data hook failed at:", urlPathname);
|
|
76
78
|
throw error;
|
|
77
79
|
}
|
|
78
80
|
if (titleMod) try {
|
|
79
81
|
const titleFn = titleMod.title ?? titleMod.default;
|
|
80
82
|
pageContext.title = typeof titleFn === "function" ? titleFn(pageContext) : titleFn;
|
|
81
83
|
} catch (error) {
|
|
82
|
-
console.error("+title hook failed at:",
|
|
84
|
+
console.error("+title hook failed at:", urlPathname);
|
|
83
85
|
throw error;
|
|
84
86
|
}
|
|
85
87
|
return {
|
|
@@ -93,7 +95,7 @@ async function buildPageContext(pathname, fullUrl, isJsonRequest) {
|
|
|
93
95
|
async function renderErrorPage(req, status, originalPathname, error) {
|
|
94
96
|
if (!store.errorRoute) return new Response(status === 404 ? "Not Found" : "Internal Server Error", { status });
|
|
95
97
|
try {
|
|
96
|
-
const { onRenderHtml } = await store.config.onRenderHtml();
|
|
98
|
+
const { default: onRenderHtml } = await store.config.onRenderHtml();
|
|
97
99
|
const [PageModule, HeadModule, LayoutModule] = await Promise.all([
|
|
98
100
|
store.errorRoute.Page(),
|
|
99
101
|
store.errorRoute.Head?.() ?? null,
|
|
@@ -141,7 +143,7 @@ async function renderPage(req) {
|
|
|
141
143
|
}
|
|
142
144
|
const { pageContext, route, PageModule, HeadModule, LayoutModule } = resolved;
|
|
143
145
|
if (isJsonRequest) return Response.json(pageContext);
|
|
144
|
-
const { onRenderHtml } = await store.config.onRenderHtml();
|
|
146
|
+
const { default: onRenderHtml } = await store.config.onRenderHtml();
|
|
145
147
|
const html = await onRenderHtml({
|
|
146
148
|
pageContext,
|
|
147
149
|
Page: PageModule.Page ?? PageModule.default,
|
package/dist/vite.mjs
CHANGED
|
@@ -201,6 +201,13 @@ function routerPlugin({ pagesDir = "pages", serverEntry = "server/index.ts", api
|
|
|
201
201
|
server.middlewares.use(async (req, res, next) => {
|
|
202
202
|
try {
|
|
203
203
|
const ssrEnv = server.environments.ssr;
|
|
204
|
+
const { routes, errorRoute, config } = await ssrEnv.runner.import(virtualModuleId);
|
|
205
|
+
const { setVikeState } = await ssrEnv.runner.import("vike-lite/__internal/server");
|
|
206
|
+
setVikeState({
|
|
207
|
+
routes,
|
|
208
|
+
errorRoute,
|
|
209
|
+
config
|
|
210
|
+
});
|
|
204
211
|
const absoluteServerEntry = path.join(viteConfigRoot, serverEntry);
|
|
205
212
|
const { default: app } = await ssrEnv.runner.import(absoluteServerEntry);
|
|
206
213
|
const headers = new Headers();
|
package/package.json
CHANGED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
//#region src/shared/matchRoute.d.ts
|
|
2
|
-
declare function matchRoute(urlPathname: string, routes: Route[]): {
|
|
3
|
-
route: Route;
|
|
4
|
-
routeParams: Record<string, string>;
|
|
5
|
-
} | null;
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/shared/index.d.ts
|
|
8
|
-
interface RenderContext {
|
|
9
|
-
pageContext: any;
|
|
10
|
-
Page: unknown;
|
|
11
|
-
Head?: unknown;
|
|
12
|
-
Layout?: unknown;
|
|
13
|
-
pageTitleTag: string;
|
|
14
|
-
serializedContext: string;
|
|
15
|
-
assets: {
|
|
16
|
-
cssLinks: string;
|
|
17
|
-
jsPreloads: string;
|
|
18
|
-
entryClient: string;
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
//#endregion
|
|
22
|
-
export { matchRoute as n, RenderContext as t };
|