From 1d306fb47223605f06ff299773afbc369577ceb7 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 4 Mar 2021 17:44:45 -0500 Subject: [PATCH 1/8] typecheck in CI (#441) --- .github/workflows/ci.yml | 3 ++- package.json | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6b6bdac75467..1788df562cb1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,7 +78,7 @@ jobs: - run: npm install -g pnpm - run: pnpm install --frozen-lockfile - run: pnpm -r build - Lint: + Lint/typecheck: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 @@ -96,3 +96,4 @@ jobs: - run: pnpm install --frozen-lockfile - run: pnpm build --filter ./packages - run: pnpm lint + - run: pnpm check diff --git a/package.json b/package.json index 2afa39dea074..db040f7963ad 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "build": "pnpm build --filter=\"@sveltejs/*\" --filter=\"create-svelte\"", "test": "pnpm -r test --workspace-concurrency=1", + "check": "pnpm -r check", "lint": "pnpm -r lint", "format": "pnpm -r format", "release": "pnpm publish --tag=next --filter=\"@sveltejs/*\" --filter=\"create-svelte\"" From 7290101b08feac693667aa9430868d65b4dfe479 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 4 Mar 2021 17:57:43 -0500 Subject: [PATCH 2/8] Update .github/workflows/ci.yml Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1788df562cb1..4fe8d9f35d39 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,7 +78,7 @@ jobs: - run: npm install -g pnpm - run: pnpm install --frozen-lockfile - run: pnpm -r build - Lint/typecheck: + Lint / typecheck: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 From 8fd13ee9efc0e9879186ba7d14656f4df9bfa900 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 4 Mar 2021 17:59:21 -0500 Subject: [PATCH 3/8] maybe the name has to be alphanumeric or something --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4fe8d9f35d39..b23912930eaf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,7 +78,7 @@ jobs: - run: npm install -g pnpm - run: pnpm install --frozen-lockfile - run: pnpm -r build - Lint / typecheck: + Lint: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 From 5c42d5ce0cac99d1c077c098cf6dd96ffb4a1237 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 17 Mar 2021 21:19:38 -0400 Subject: [PATCH 4/8] fix some types --- packages/kit/src/core/load_config/index.js | 2 +- packages/kit/src/runtime/server/page.js | 4 ++-- packages/kit/types.internal.d.ts | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/kit/src/core/load_config/index.js b/packages/kit/src/core/load_config/index.js index 64a56f1bb3d5..7455ef7844cb 100644 --- a/packages/kit/src/core/load_config/index.js +++ b/packages/kit/src/core/load_config/index.js @@ -98,7 +98,7 @@ export async function load_config({ cwd = process.cwd() } = {}) { } /** - * @param {import('../../../../types.internal').Config} config + * @param {import('../../../types').Config} config * @returns {import('../../../types.internal.js').ValidatedConfig} */ export function validate_config(config) { diff --git a/packages/kit/src/runtime/server/page.js b/packages/kit/src/runtime/server/page.js index 068aa08b33d5..d7fa65cf51af 100644 --- a/packages/kit/src/runtime/server/page.js +++ b/packages/kit/src/runtime/server/page.js @@ -43,7 +43,7 @@ async function get_response({ request, options, $session, route, status = 200, e /** * @param {string} url - * @param {import('node-fetch').RequestInit} opts + * @param {RequestInit} opts */ const fetcher = async (url, opts = {}) => { if (options.local && url.startsWith(options.paths.assets)) { @@ -64,7 +64,7 @@ async function get_response({ request, options, $session, route, status = 200, e if (parsed.protocol) { // external fetch - response = await fetch(parsed.href, opts); + response = await fetch(parsed.href, /** @type {import('node-fetch').RequestInit} */ (opts)); } else { // otherwise we're dealing with an internal fetch const resolved = resolve(request.path, parsed.pathname); diff --git a/packages/kit/types.internal.d.ts b/packages/kit/types.internal.d.ts index f57e5a4b7bb2..f5b8bf7bca16 100644 --- a/packages/kit/types.internal.d.ts +++ b/packages/kit/types.internal.d.ts @@ -67,7 +67,6 @@ export type Request = { headers: Headers; path: string; body: any; - params: Record; query: URLSearchParams; }; @@ -156,6 +155,7 @@ export type SSRManifest = { endpoints: Endpoint[]; }; +// TODO separate out runtime options from the ones fixed in dev/build export type SSRRenderOptions = { paths?: { base: string; @@ -182,7 +182,7 @@ export type SSRRenderOptions = { app_dir?: string; host?: string; host_header?: string; - get_component_path: (id: string) => string; + get_component_path?: (id: string) => string; get_stack?: (error: Error) => string; get_static_file?: (file: string) => Buffer; get_amp_css?: (dep: string) => string; From 6f47ec97c7fe6d8741ba55e202798fa4587aa2c3 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 17 Mar 2021 22:03:48 -0400 Subject: [PATCH 5/8] more types --- packages/kit/src/core/dev/index.js | 2 +- packages/kit/src/core/start/index.js | 3 ++- packages/kit/src/runtime/server/page.js | 7 +++++-- packages/kit/types.internal.d.ts | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/packages/kit/src/core/dev/index.js b/packages/kit/src/core/dev/index.js index 86be56fd15ab..5a4381cf7632 100644 --- a/packages/kit/src/core/dev/index.js +++ b/packages/kit/src/core/dev/index.js @@ -126,7 +126,7 @@ class Watcher extends EventEmitter { const rendered = await ssr( { - headers: req.headers, + headers: /** @type {import('../../../types.internal').Headers} */ (req.headers), method: req.method, host: null, path: parsed.pathname, diff --git a/packages/kit/src/core/start/index.js b/packages/kit/src/core/start/index.js index 1527dafda10c..f377bfd0bf2b 100644 --- a/packages/kit/src/core/start/index.js +++ b/packages/kit/src/core/start/index.js @@ -44,8 +44,9 @@ export async function start({ port, config, cwd = process.cwd() }) { static_handler(req, res, async () => { const rendered = await app.render( { + host: `localhost:${port}`, method: req.method, - headers: req.headers, + headers: /** @type {import('../../../types.internal').Headers} */ (req.headers), path: parsed.pathname, body: await get_body(req), query: new URLSearchParams(parsed.query || '') diff --git a/packages/kit/src/runtime/server/page.js b/packages/kit/src/runtime/server/page.js index d7fa65cf51af..a6b435de0d66 100644 --- a/packages/kit/src/runtime/server/page.js +++ b/packages/kit/src/runtime/server/page.js @@ -88,7 +88,10 @@ async function get_response({ request, options, $session, route, status = 200, e }); } else { // TODO we need to know what protocol to use - response = await fetch(`http://${page.host}/${asset.file}`, opts); + response = await fetch( + `http://${page.host}/${asset.file}`, + /** @type {import('node-fetch').RequestInit} */ (opts) + ); } } @@ -97,7 +100,7 @@ async function get_response({ request, options, $session, route, status = 200, e { host: request.host, method: opts.method || 'GET', - headers: opts.headers || {}, // TODO inject credentials... + headers: /** @type {import('../../../types.internal').Headers} */ (opts.headers || {}), // TODO inject credentials... path: resolved, body: opts.body, query: new URLSearchParams(parsed.query || '') diff --git a/packages/kit/types.internal.d.ts b/packages/kit/types.internal.d.ts index f5b8bf7bca16..7e2ec5b1fb84 100644 --- a/packages/kit/types.internal.d.ts +++ b/packages/kit/types.internal.d.ts @@ -174,7 +174,7 @@ export type SSRRenderOptions = { context?: any; headers?: Headers; }; - getSession: ({ context }: { context: any }) => any; + getSession?: ({ context }: { context: any }) => any; }; dev?: boolean; amp?: boolean; From 3acd28df953ceb76dcec5d74da49113b27324f5e Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 18 Mar 2021 11:28:35 -0400 Subject: [PATCH 6/8] add note to self --- packages/kit/src/runtime/server/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/kit/src/runtime/server/index.js b/packages/kit/src/runtime/server/index.js index 18789a2fdeed..a2b6b8133ce4 100644 --- a/packages/kit/src/runtime/server/index.js +++ b/packages/kit/src/runtime/server/index.js @@ -50,6 +50,8 @@ export async function ssr(request, options) { return { status: response.status, + // TODO header merging is more involved than this — see the 'message.headers' + // section of https://nodejs.org/api/http.html#http_class_http_incomingmessage headers: { ...headers, ...response.headers }, body: response.body, dependencies: response.dependencies From dbbddaf6d2e16dde31f36fd07661fe39173b1409 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 18 Mar 2021 11:28:44 -0400 Subject: [PATCH 7/8] use Headers type --- packages/kit/types.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/kit/types.d.ts b/packages/kit/types.d.ts index ba27ea7dd5fe..a462be3444db 100644 --- a/packages/kit/types.d.ts +++ b/packages/kit/types.d.ts @@ -1,4 +1,4 @@ -import { LoadInput, LoadOutput, Logger } from './types.internal'; +import { Headers, LoadInput, LoadOutput, Logger } from './types.internal'; export type Config = { compilerOptions?: any; @@ -56,7 +56,7 @@ interface ReadOnlyFormData extends Iterator<[string, string]> { export type RequestHandler = ( request?: { host: string; - headers: Record; + headers: Headers; path: string; params: Record; query: URLSearchParams; From 63e85470fd3bad803af434b5bb0ac3806fa43ad7 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 18 Mar 2021 12:00:06 -0400 Subject: [PATCH 8/8] add note about response headers --- packages/kit/types.internal.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/kit/types.internal.d.ts b/packages/kit/types.internal.d.ts index 7e2ec5b1fb84..b80f94d6060e 100644 --- a/packages/kit/types.internal.d.ts +++ b/packages/kit/types.internal.d.ts @@ -59,6 +59,10 @@ export type App = { render: (request: Request, options: SSRRenderOptions) => Response; }; +// TODO we want to differentiate between request headers, which +// always follow this type, and response headers, in which +// 'set-cookie' is a `string[]` (or at least `string | string[]`) +// but this can't happen until TypeScript 4.3 export type Headers = Record; export type Request = {