Types for RenderOptions.root
MODIFY
packages/app-utils/index.d.ts
packages/app-utils/index.d.ts
-export { EndpointManifest, PageManifest, PageComponentManifest } from './src/types';
+export {
+ EndpointManifest,
+ PageManifest,
+ PageComponentManifest,
+ SetupModule,
+ RootModule
+} from './src/types';

MODIFY
packages/app-utils/src/renderer/manifest/index.spec.data.ts
packages/app-utils/src/renderer/manifest/index.spec.data.ts
@@ -4,8 +4,9 @@ const examplePageComponentManifest: PageComponentManifest = {
default: true,
type: 'foo',
name: 'bar',
- file: 'baz'
-}
+ file: 'baz',
+ url: 'boo'
+};
const examplePageManifest: PageManifest = {
pattern: /a/,
@@ -14,7 +15,7 @@ const examplePageManifest: PageManifest = {
component: examplePageComponentManifest,
params: [ 'quux', 'corge' ]
} ]
-}
+};
const exampleEndpointManifest: EndpointManifest = {
name: 'grault',
@@ -22,7 +23,7 @@ const exampleEndpointManifest: EndpointManifest = {
file: 'garply',
url: 'bla',
params: [ 'waldo', 'fred' ]
-}
+};
export const exampleRouteManifest: RouteManifest = {
layout: examplePageComponentManifest,
@@ -30,4 +31,4 @@ export const exampleRouteManifest: RouteManifest = {
components: [ examplePageComponentManifest, examplePageComponentManifest ],
pages: [ examplePageManifest, examplePageManifest ],
endpoints: [ exampleEndpointManifest, exampleEndpointManifest ]
-}
+};

MODIFY
packages/app-utils/src/types.d.ts
packages/app-utils/src/types.d.ts
@@ -23,19 +23,31 @@ export type PageResponse = EndpointResponse & {
dependencies: Record<string, EndpointResponse>;
};
-type SetupModule = {
+export type SetupModule = {
prepare?: (headers: Headers) => Promise<{ context: any, headers: Headers }>;
getSession?: (context: any) => Promise<any>;
setSession?: (context: any, session: any) => Promise<any>;
};
+export interface SSRComponentModule {
+ default: SSRComponent;
+}
+
+export interface SSRComponent {
+ render(props: unknown): {
+ html: string
+ head: string
+ css: { code: string, map: unknown };
+ }
+}
+
export type RenderOptions = {
only_prerender: boolean; // TODO this shouldn't really be part of the public API
static_dir: string;
template: string;
manifest: RouteManifest;
client: ClientManifest;
- root: any; // TODO
+ root: SSRComponentModule;
setup: SetupModule;
load: (route: PageComponentManifest | EndpointManifest) => Promise<any>; // TODO
dev: boolean; // TODO this is awkward

MODIFY
packages/kit/src/api/dev/index.ts
packages/kit/src/api/dev/index.ts
@@ -14,6 +14,7 @@ import { ManifestData, ReadyEvent } from '../../interfaces';
import { mkdirp } from '@sveltejs/app-utils/files';
import { render } from '@sveltejs/app-utils/renderer';
import { get_body } from '@sveltejs/app-utils/http';
+import { RootModule, SetupModule } from '@sveltejs/app-utils';
import { DevConfig, Loader } from './types';
import { copy_assets } from '../utils';
import { readFileSync } from 'fs';
@@ -129,24 +130,24 @@ class Watcher extends EventEmitter {
);
const parsed = parse(req.url);
- let setup;
+ let setup: SetupModule;
try {
- setup = await load(`/_app/setup/index.js`);
+ setup = await load('/_app/setup/index.js');
} catch (err) {
if (!err.message.endsWith('NOT_FOUND')) throw err;
setup = {};
}
- let root;
+ let root: RootModule;
try {
- root = await load(`/_app/main/generated/root.js`);
+ root = await load('/_app/main/generated/root.js');
}
catch (e) {
res.statusCode = 500;
res.end(e.toString());
- return
+ return;
}
const body = await get_body(req);

Types for RenderOptions.root