Skip to content

Commit

Permalink
typecheck adapters (#4220)
Browse files Browse the repository at this point in the history
* typecheck adapters

* changeset

* fix lockfile

* expose Builder
  • Loading branch information
Rich-Harris committed Mar 5, 2022
1 parent dd4749b commit 44bd29c
Show file tree
Hide file tree
Showing 32 changed files with 220 additions and 142 deletions.
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"]
}
2 changes: 1 addition & 1 deletion 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
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"]
}
File renamed without changes.
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"]
}
File renamed without changes.
2 changes: 1 addition & 1 deletion 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
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"]
}
File renamed without changes.
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"]
}
File renamed without changes.
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"]
}

0 comments on commit 44bd29c

Please sign in to comment.