Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typecheck in CI #445

Merged
merged 10 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ jobs:
- run: pnpm install --frozen-lockfile
- run: pnpm build --filter ./packages
- run: pnpm lint
- run: pnpm check
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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\""
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/core/load_config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion packages/kit/src/core/start/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 || '')
Expand Down
2 changes: 2 additions & 0 deletions packages/kit/src/runtime/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 7 additions & 4 deletions packages/kit/src/runtime/server/page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
Expand All @@ -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)
);
}
}

Expand All @@ -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 || '')
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LoadInput, LoadOutput, Logger } from './types.internal';
import { Headers, LoadInput, LoadOutput, Logger } from './types.internal';

export type Config = {
compilerOptions?: any;
Expand Down Expand Up @@ -56,7 +56,7 @@ interface ReadOnlyFormData extends Iterator<[string, string]> {
export type RequestHandler = (
request?: {
host: string;
headers: Record<string, string>;
headers: Headers;
path: string;
params: Record<string, string>;
query: URLSearchParams;
Expand Down
10 changes: 7 additions & 3 deletions packages/kit/types.internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>;

export type Request = {
Expand All @@ -67,7 +71,6 @@ export type Request = {
headers: Headers;
path: string;
body: any;
params: Record<string, string>;
query: URLSearchParams;
};

Expand Down Expand Up @@ -156,6 +159,7 @@ export type SSRManifest = {
endpoints: Endpoint[];
};

// TODO separate out runtime options from the ones fixed in dev/build
export type SSRRenderOptions = {
paths?: {
base: string;
Expand All @@ -174,15 +178,15 @@ export type SSRRenderOptions = {
context?: any;
headers?: Headers;
};
getSession: ({ context }: { context: any }) => any;
getSession?: ({ context }: { context: any }) => any;
};
dev?: boolean;
amp?: boolean;
only_prerender?: boolean;
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;
Expand Down