build with ts without warnings
MODIFY
packages/app-utils/src/prerender/index.ts
packages/app-utils/src/prerender/index.ts
@@ -3,9 +3,9 @@ import { dirname, resolve as resolve_path } from 'path';
import { parse, resolve, URLSearchParams } from 'url';
import { mkdirp } from '../files';
import { render } from '../render';
-import { RouteManifest } from '../types';
+import { PageResponse, RouteManifest } from '../types';
-function clean_html(html) {
+function clean_html(html: string) {
return html
.replace(/<!\[CDATA\[[\s\S]*?\]\]>/gm, '')
.replace(/(<script[\s\S]*?>)[\s\S]*?<\/script>/gm, '$1</' + 'script>')
@@ -13,17 +13,17 @@ function clean_html(html) {
.replace(/<!--[\s\S]*?-->/gm, '');
}
-function get_href(attrs) {
+function get_href(attrs: string) {
const match = /href\s*=\s*(?:"(.*?)"|'(.*?)'|([^\s>]*))/.exec(attrs);
return match && (match[1] || match[2] || match[3]);
}
-function get_src(attrs) {
+function get_src(attrs: string) {
const match = /src\s*=\s*(?:"(.*?)"|'(.*?)'|([^\s>]*))/.exec(attrs);
return match && (match[1] || match[2] || match[3]);
}
-function get_srcset_urls(attrs) {
+function get_srcset_urls(attrs: string) {
const results = [];
// Note that the srcset allows any ASCII whitespace, including newlines.
const match = /srcset\s*=\s*(?:"(.*?)"|'(.*?)'|([^\s>]*))/s.exec(attrs);
@@ -130,9 +130,11 @@ export async function prerender({
log.error(`${rendered.status} ${path}`);
}
- if (rendered.dependencies) {
- for (const path in rendered.dependencies) {
- const result = rendered.dependencies[path];
+ const dependencies = (rendered as PageResponse).dependencies;
+
+ if (dependencies) {
+ for (const path in dependencies) {
+ const result = dependencies[path];
const response_type = Math.floor(result.status / 100);
const is_html = result.headers['content-type'] === 'text/html';

MODIFY
packages/app-utils/src/render/index.ts
packages/app-utils/src/render/index.ts
@@ -3,7 +3,7 @@ import render_page from './page';
import render_route from './route';
import { EndpointResponse, IncomingRequest, PageResponse, RenderOptions } from '../types';
-function md5(body) {
+function md5(body: string) {
return createHash('md5').update(body).digest('hex');
}

MODIFY
packages/app-utils/src/render/page.ts
packages/app-utils/src/render/page.ts
@@ -6,13 +6,13 @@ import devalue from 'devalue';
import fetch, { Response } from 'node-fetch';
import * as mime from 'mime';
import { render } from './index';
-import { IncomingRequest, RenderOptions, PageManifest } from '../types';
+import { IncomingRequest, RenderOptions, PageManifest, EndpointResponse, PageResponse, Headers } from '../types';
const noop = () => {};
type FetchOpts = {
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'HEAD' | 'OPTIONS';
- headers?: Record<string, string>;
+ headers?: Headers;
body?: any;
};
@@ -20,8 +20,13 @@ export default async function render_page(
request: IncomingRequest,
context: any,
options: RenderOptions
-) {
- let redirected;
+): Promise<{
+ status: number,
+ body?: string,
+ headers?: Headers,
+ dependencies?: Record< string, EndpointResponse | PageResponse>
+}> {
+ let redirected: { status: number; location?: string; headers: Headers };
let preload_error;
const page: PageManifest = options.manifest.pages.find(page => page.pattern.test(request.path));
@@ -53,10 +58,10 @@ export default async function render_page(
l++;
});
- const dependencies = {};
+ const dependencies: Record<string, EndpointResponse | PageResponse> = {};
const preload_context = {
- redirect: (status, location) => {
+ redirect: (status: number, location: string) => {
if (redirected && (redirected.status !== status || redirected.location !== location)) {
throw new Error(`Conflicting redirects`);
}

MODIFY
packages/app-utils/src/render/route.ts
packages/app-utils/src/render/route.ts
-import { IncomingRequest, RenderOptions, EndpointManifest } from '../types';
+import { IncomingRequest, RenderOptions, EndpointManifest, Headers } from '../types';
export default function render_route(
request: IncomingRequest,
context: any,
options: RenderOptions
-) {
+): Promise<{
+ status: number,
+ body: string,
+ headers?: Headers
+}> {
const route: EndpointManifest = options.manifest.endpoints.find(route => route.pattern.test(request.path));
if (!route) return;
@@ -53,7 +57,7 @@ export default function render_route(
});
}
-function lowercase_keys(obj) {
+function lowercase_keys(obj: Record<string, any>) {
const clone = {};
for (const key in obj) {
clone[key.toLowerCase()] = obj[key];

MODIFY
packages/kit/src/ambient.d.ts
packages/kit/src/ambient.d.ts
declare module "MANIFEST" {
export const components: any[];
export const routes: any[];
+ export const Layout: any;
}
declare module "ROOT" {

MODIFY
packages/kit/src/api/dev/sourcemap_stacktrace.ts
packages/kit/src/api/dev/sourcemap_stacktrace.ts
@@ -70,7 +70,9 @@ export function sourcemap_stacktrace(stack: string) {
return input;
}
- const consumer = new SourceMapConsumer(raw_sourcemap);
+ // TODO: according to typings, this code cannot work;
+ // the constructor returns a promise that needs to be awaited
+ const consumer = new (SourceMapConsumer as any)(raw_sourcemap);
const pos = consumer.originalPositionFor({
line: Number(line),
column: Number(column),

MODIFY
packages/kit/src/cli.ts
packages/kit/src/cli.ts
import relative from 'require-relative';
import sade from 'sade';
import colors from 'kleur';
-import * as pkg from '../package.json';
-import { ReadyEvent } from './interfaces';
+import pkg from '../package.json';
+import { ReadyEvent, SvelteAppConfig } from './interfaces';
-let config;
+let config: SvelteAppConfig;
try {
config = relative('./svelte.config.js', process.cwd());

MODIFY
packages/kit/tsconfig.json
packages/kit/tsconfig.json
{
"compilerOptions": {
- "declaration": true,
- "declarationDir": "declarations",
- "emitDeclarationOnly": true,
- "resolveJsonModule": true
+ "noEmit": true,
+ "resolveJsonModule": true,
+ "module": "esnext",
+ "moduleResolution": "node",
+ "target": "ES6",
+ "outDir": "build",
+ "esModuleInterop": true
},
"lib": ["ES2020", "dom", "node"]
}

build with ts without warnings