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 adapters #4220

Merged
merged 4 commits into from Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rich-icons-swim.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

Expose Server and SSRManifest as public types
4 changes: 4 additions & 0 deletions packages/adapter-auto/package.json
Expand Up @@ -26,11 +26,15 @@
"scripts": {
"lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format",
"format": "npm run check-format -- --write",
"check": "tsc",
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore"
},
"dependencies": {
"@sveltejs/adapter-cloudflare": "workspace:*",
"@sveltejs/adapter-netlify": "workspace:*",
"@sveltejs/adapter-vercel": "workspace:*"
},
"devDependencies": {
"typescript": "^4.6.2"
}
}
13 changes: 13 additions & 0 deletions packages/adapter-auto/tsconfig.json
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"allowJs": true,
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"baseUrl": ".",
"paths": {
"@sveltejs/kit": ["../kit/types/index"]
}
},
"include": ["**/*.js"]
}
4 changes: 2 additions & 2 deletions packages/adapter-cloudflare-workers/index.js
Expand Up @@ -19,7 +19,7 @@ export default function () {
// @ts-ignore
const entrypoint = site['entry-point'] || 'workers-site';

const files = fileURLToPath(new URL('./files', import.meta.url));
const files = fileURLToPath(new URL('./files', import.meta.url).href);
const tmp = builder.getBuildDirectory('cloudflare-workers-tmp');

builder.rimraf(bucket);
Expand Down Expand Up @@ -67,7 +67,7 @@ export default function () {
};
}

/** @param {import('@sveltejs/kit').Builder} builder */
/** @param {any} builder */
benmccann marked this conversation as resolved.
Show resolved Hide resolved
function validate_config(builder) {
if (existsSync('wrangler.toml')) {
let wrangler_config;
Expand Down
3 changes: 2 additions & 1 deletion packages/adapter-cloudflare-workers/package.json
Expand Up @@ -24,6 +24,7 @@
"scripts": {
"lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format",
"format": "npm run check-format -- --write",
"check": "tsc",
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore"
},
"dependencies": {
Expand All @@ -32,6 +33,6 @@
},
"devDependencies": {
"@cloudflare/kv-asset-handler": "^0.2.0",
"@sveltejs/kit": "workspace:*"
"typescript": "^4.6.2"
}
}
9 changes: 6 additions & 3 deletions packages/adapter-cloudflare-workers/tsconfig.json
Expand Up @@ -4,10 +4,13 @@
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"target": "es2020",
"module": "es2020",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"@sveltejs/kit": ["../kit/types/index"]
}
},
"include": ["./index.js", "files"]
"include": ["**/*.js", "ambient.d.ts"]
}
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare/index.js
Expand Up @@ -8,7 +8,7 @@ export default function (options = {}) {
return {
name: '@sveltejs/adapter-cloudflare',
async adapt(builder) {
const files = fileURLToPath(new URL('./files', import.meta.url));
const files = fileURLToPath(new URL('./files', import.meta.url).href);
const dest = builder.getBuildDirectory('cloudflare');
const tmp = builder.getBuildDirectory('cloudflare-tmp');

Expand Down
3 changes: 2 additions & 1 deletion packages/adapter-cloudflare/package.json
Expand Up @@ -25,13 +25,14 @@
"scripts": {
"lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format",
"format": "npm run check-format -- --write",
"check": "tsc",
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore"
},
"dependencies": {
"esbuild": "^0.14.21"
},
"devDependencies": {
"@sveltejs/kit": "workspace:*"
"typescript": "^4.6.2"
},
"publishConfig": {
"access": "public"
Expand Down
8 changes: 5 additions & 3 deletions packages/adapter-cloudflare/tsconfig.json
Expand Up @@ -4,10 +4,12 @@
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"target": "es2020",
"module": "es2020",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
"baseUrl": ".",
"paths": {
"@sveltejs/kit": ["../kit/types/index"]
}
},
"include": ["./index.js", "./files"]
"include": ["**/*.js", "ambient.d.ts"]
}
4 changes: 2 additions & 2 deletions packages/adapter-netlify/index.js
Expand Up @@ -12,7 +12,7 @@ import toml from '@iarna/toml';
* } & toml.JsonMap} NetlifyConfig
*/

const files = fileURLToPath(new URL('./files', import.meta.url));
const files = fileURLToPath(new URL('./files', import.meta.url).href);

/** @type {import('.')} */
export default function ({ split = false } = {}) {
Expand Down Expand Up @@ -153,7 +153,7 @@ function get_netlify_config() {

/**
* @param {NetlifyConfig} netlify_config
* @param {import('@sveltejs/kit').Builder} builder
* @param {any} builder
benmccann marked this conversation as resolved.
Show resolved Hide resolved
**/
function get_publish_directory(netlify_config, builder) {
if (netlify_config) {
Expand Down
2 changes: 2 additions & 0 deletions packages/adapter-netlify/package.json
Expand Up @@ -25,6 +25,7 @@
"dev": "rimraf files && rollup -cw",
"build": "rimraf files && rollup -c",
"test": "uvu src \"(spec\\.js|test[\\\\/]index\\.js)\"",
"check": "tsc",
"lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format",
"format": "npm run check-format -- --write",
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
Expand All @@ -43,6 +44,7 @@
"@sveltejs/kit": "workspace:*",
"rimraf": "^3.0.2",
"rollup": "^2.58.0",
"typescript": "^4.6.2",
"uvu": "^0.5.2"
}
}
41 changes: 21 additions & 20 deletions packages/adapter-netlify/rollup.config.js
Expand Up @@ -2,24 +2,25 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';

export default [
{
input: {
handler: 'src/handler.js',
shims: 'src/shims.js'
/** @type {import('rollup').RollupOptions} */
const config = {
input: {
handler: 'src/handler.js',
shims: 'src/shims.js'
},
output: [
{
dir: 'files/cjs',
format: 'cjs'
},
output: [
{
dir: 'files/cjs',
format: 'cjs'
},
{
dir: 'files/esm',
format: 'esm'
}
],
plugins: [nodeResolve(), commonjs(), json()],
external: (id) => id === '0APP' || id.startsWith('node:'),
preserveEntrySignatures: true
}
];
{
dir: 'files/esm',
format: 'esm'
}
],
plugins: [nodeResolve(), commonjs(), json()],
external: (id) => id === '0SERVER' || id.startsWith('node:'),
preserveEntrySignatures: 'exports-only'
};

export default config;
9 changes: 6 additions & 3 deletions packages/adapter-netlify/tsconfig.json
Expand Up @@ -4,10 +4,13 @@
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"target": "es2020",
"module": "es2020",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"@sveltejs/kit": ["../kit/types/index"]
}
},
"include": ["./index.js", "src"]
"include": ["*.js", "src/**/*.js", "ambient.d.ts"]
}
6 changes: 6 additions & 0 deletions packages/adapter-node/index.d.ts
@@ -1,5 +1,11 @@
import { Adapter } from '@sveltejs/kit';

declare global {
const HOST_ENV: string;
const PATH_ENV: string;
const PORT_ENV: string;
}

interface AdapterOptions {
out?: string;
precompress?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion packages/adapter-node/index.js
Expand Up @@ -7,7 +7,7 @@ import zlib from 'zlib';

const pipe = promisify(pipeline);

const files = fileURLToPath(new URL('./files', import.meta.url));
const files = fileURLToPath(new URL('./files', import.meta.url).href);

/** @type {import('.')} */
export default function ({
Expand Down
2 changes: 2 additions & 0 deletions packages/adapter-node/package.json
Expand Up @@ -25,6 +25,7 @@
"dev": "rimraf files && rollup -cw",
"build": "rimraf files && rollup -c",
"test": "echo \"tests temporarily disabled\" # c8 uvu tests",
"check": "tsc",
"lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format",
"format": "npm run check-format -- --write",
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
Expand All @@ -44,6 +45,7 @@
"rimraf": "^3.0.2",
"rollup": "^2.60.2",
"sirv": "^2.0.0",
"typescript": "^4.6.2",
"uvu": "^0.5.2"
}
}
9 changes: 9 additions & 0 deletions packages/adapter-node/src/handler.d.ts
@@ -0,0 +1,9 @@
import type { Handle } from '@sveltejs/kit';

declare global {
const ORIGIN: string;
const HOST_HEADER: string;
const PROTOCOL_HEADER: string;
}

export const handler: Handle;
11 changes: 7 additions & 4 deletions packages/adapter-node/tsconfig.json
Expand Up @@ -4,10 +4,13 @@
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"target": "es2020",
"module": "es2020",
"allowSyntheticDefaultImports": true,
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
"module": "es2020",
"baseUrl": ".",
"paths": {
"@sveltejs/kit": ["../kit/types/index"]
}
},
"include": ["index.js", "src"]
"include": ["index.js", "src/**/*.js", "ambient.d.ts"]
}
1 change: 1 addition & 0 deletions packages/adapter-static/package.json
Expand Up @@ -34,6 +34,7 @@
"port-authority": "^1.1.2",
"sirv": "^2.0.0",
"svelte": "^3.44.2",
"typescript": "^4.6.2",
"uvu": "^0.5.2"
}
}
8 changes: 5 additions & 3 deletions packages/adapter-static/tsconfig.json
Expand Up @@ -4,11 +4,13 @@
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"target": "es2020",
"module": "es2020",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
"baseUrl": ".",
"paths": {
"@sveltejs/kit": ["../kit/types/index"]
}
},
"include": ["index.js", "test/*.js"]
"include": ["index.js"]
}
2 changes: 1 addition & 1 deletion packages/adapter-vercel/index.js
Expand Up @@ -93,7 +93,7 @@ export default function ({ external = [] } = {}) {
builder.rimraf(dir);
builder.rimraf(tmp);

const files = fileURLToPath(new URL('./files', import.meta.url));
const files = fileURLToPath(new URL('./files', import.meta.url).href);

const dirs = {
static: `${dir}/static`,
Expand Down
6 changes: 4 additions & 2 deletions packages/adapter-vercel/package.json
Expand Up @@ -24,12 +24,14 @@
"scripts": {
"lint": "eslint --ignore-path .gitignore \"**/*.{ts,js,svelte}\" && npm run check-format",
"format": "npm run check-format -- --write",
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore"
"check-format": "prettier --check . --config ../../.prettierrc --ignore-path .gitignore",
"check": "tsc"
},
"dependencies": {
"esbuild": "^0.14.21"
},
"devDependencies": {
"@sveltejs/kit": "workspace:*"
"@sveltejs/kit": "workspace:*",
"typescript": "^4.6.2"
}
}
9 changes: 6 additions & 3 deletions packages/adapter-vercel/tsconfig.json
Expand Up @@ -4,10 +4,13 @@
"checkJs": true,
"noEmit": true,
"noImplicitAny": true,
"target": "es2020",
"module": "es2020",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"@sveltejs/kit": ["../kit/types/index"]
}
},
"include": ["./index.js", "files"]
"include": ["**/*.js", "ambient.d.ts"]
}
23 changes: 23 additions & 0 deletions packages/kit/types/index.d.ts
Expand Up @@ -16,10 +16,12 @@ import {
MaybePromise,
PrerenderOnErrorValue,
RequestEvent,
RequestOptions,
ResolveOptions,
ResponseHeaders,
TrailingSlash
} from './private';
import { SSRNodeLoader, SSRRoute } from './internal';

export interface Adapter {
name: string;
Expand Down Expand Up @@ -164,3 +166,24 @@ export type RequestHandlerOutput<Output extends Body = Body> = MaybePromise<
Fallthrough
>
>;

export class Server {
constructor(manifest: SSRManifest);
respond(request: Request, options?: RequestOptions): Promise<Response>;
}

export interface SSRManifest {
appDir: string;
assets: Set<string>;
/** private fields */
_: {
mime: Record<string, string>;
entry: {
file: string;
js: string[];
css: string[];
};
nodes: SSRNodeLoader[];
routes: SSRRoute[];
};
}