From 32de1b1b05816d79c90f546f08e7c0050086b4f6 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Sun, 22 Aug 2021 15:05:45 +0700 Subject: [PATCH 01/15] rename to ambient-imports --- .../kit/types/{ambient-modules.d.ts => ambient-imports.d.ts} | 0 packages/kit/types/index.d.ts | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename packages/kit/types/{ambient-modules.d.ts => ambient-imports.d.ts} (100%) diff --git a/packages/kit/types/ambient-modules.d.ts b/packages/kit/types/ambient-imports.d.ts similarity index 100% rename from packages/kit/types/ambient-modules.d.ts rename to packages/kit/types/ambient-imports.d.ts diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index efc72fe67df1..1578711ca6d7 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -1,7 +1,7 @@ /// /// -import './ambient-modules'; +import './ambient-imports'; export { App, IncomingRequest } from './app'; export { Adapter, AdapterUtils, Config, PrerenderErrorHandler, ValidatedConfig } from './config'; From c21685d717a6fd901400d8fd2e7a472b97a515a1 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Sun, 22 Aug 2021 15:06:32 +0700 Subject: [PATCH 02/15] move kit/hooks to ambient modules --- packages/kit/types/ambient-imports.d.ts | 12 ------------ packages/kit/types/ambient-modules.d.ts | 11 +++++++++++ 2 files changed, 11 insertions(+), 12 deletions(-) create mode 100644 packages/kit/types/ambient-modules.d.ts diff --git a/packages/kit/types/ambient-imports.d.ts b/packages/kit/types/ambient-imports.d.ts index c702c5054f04..11000c605585 100644 --- a/packages/kit/types/ambient-imports.d.ts +++ b/packages/kit/types/ambient-imports.d.ts @@ -129,15 +129,3 @@ declare module '$service-worker' { */ export const timestamp: number; } - -declare module '@sveltejs/kit/hooks' { - type Handle = import('@sveltejs/kit').Handle; - - /** - * Utility function that allows chaining `handle` functions in a - * middleware-like manner. - * - * @param handlers The chain of `handle` functions - */ - export function sequence(...handlers: Handle[]): Handle; -} diff --git a/packages/kit/types/ambient-modules.d.ts b/packages/kit/types/ambient-modules.d.ts new file mode 100644 index 000000000000..1d23ac09c6a4 --- /dev/null +++ b/packages/kit/types/ambient-modules.d.ts @@ -0,0 +1,11 @@ +declare module '@sveltejs/kit/hooks' { + type Handle = import('@sveltejs/kit').Handle; + + /** + * Utility function that allows chaining `handle` functions in a + * middleware-like manner. + * + * @param handlers The chain of `handle` functions + */ + export function sequence(...handlers: Handle[]): Handle; +} From a71c844d5d52466631f96c8eb0446cdfa5b9f675 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Sun, 22 Aug 2021 15:18:59 +0700 Subject: [PATCH 03/15] add Respond types to @sveltejs/kit/srr --- packages/kit/src/runtime/server/index.js | 6 +----- packages/kit/types/ambient-modules.d.ts | 12 ++++++++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/packages/kit/src/runtime/server/index.js b/packages/kit/src/runtime/server/index.js index 9e3d30f197c5..4bfe7c4e0f32 100644 --- a/packages/kit/src/runtime/server/index.js +++ b/packages/kit/src/runtime/server/index.js @@ -7,11 +7,7 @@ import { lowercase_keys } from './utils.js'; import { coalesce_to_error } from '../utils.js'; import { hash } from '../hash.js'; -/** - * @param {import('types/app').IncomingRequest} incoming - * @param {import('types/internal').SSRRenderOptions} options - * @param {import('types/internal').SSRRenderState} [state] - */ +/** @type {import('@sveltejs/kit/ssr').Respond} */ export async function respond(incoming, options, state = {}) { if (incoming.path !== '/' && options.trailing_slash !== 'ignore') { const has_trailing_slash = incoming.path.endsWith('/'); diff --git a/packages/kit/types/ambient-modules.d.ts b/packages/kit/types/ambient-modules.d.ts index 1d23ac09c6a4..00f2f0c32cf2 100644 --- a/packages/kit/types/ambient-modules.d.ts +++ b/packages/kit/types/ambient-modules.d.ts @@ -9,3 +9,15 @@ declare module '@sveltejs/kit/hooks' { */ export function sequence(...handlers: Handle[]): Handle; } + +declare module '@sveltejs/kit/ssr' { + type IncomingRequest = import('@sveltejs/kit').IncomingRequest; + type Options = import('types/internal').SSRRenderOptions; + type State = import('types/internal').SSRRenderState; + type ServerResponse = import('@sveltejs/kit').Response; + + export interface Respond { + (incoming: IncomingRequest, options: Options, state?: State): ServerResponse; + } + export const respond: Respond; +} From 0b531d88a1af739b43d1e178c7d867d54510228a Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Sun, 22 Aug 2021 15:23:02 +0700 Subject: [PATCH 04/15] add GetRawBody types to @sveltejs/kit/node --- packages/kit/src/core/node/index.js | 5 +---- packages/kit/types/ambient-modules.d.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/kit/src/core/node/index.js b/packages/kit/src/core/node/index.js index a371cdbb6d8a..4d7ca271a53b 100644 --- a/packages/kit/src/core/node/index.js +++ b/packages/kit/src/core/node/index.js @@ -1,7 +1,4 @@ -/** - * @param {import('http').IncomingMessage} req - * @returns {Promise} - */ +/** @type {import('@sveltejs/kit/node').GetRawBody} */ export function getRawBody(req) { return new Promise((fulfil, reject) => { const h = req.headers; diff --git a/packages/kit/types/ambient-modules.d.ts b/packages/kit/types/ambient-modules.d.ts index 00f2f0c32cf2..64eb076f3f08 100644 --- a/packages/kit/types/ambient-modules.d.ts +++ b/packages/kit/types/ambient-modules.d.ts @@ -10,6 +10,16 @@ declare module '@sveltejs/kit/hooks' { export function sequence(...handlers: Handle[]): Handle; } +declare module '@sveltejs/kit/node' { + type IncomingMessage = import('http').IncomingMessage; + type RawBody = import('types/helper').RawBody; + + export interface GetRawBody { + (request: IncomingMessage): Promise; + } + export const getRawBody: GetRawBody; +} + declare module '@sveltejs/kit/ssr' { type IncomingRequest = import('@sveltejs/kit').IncomingRequest; type Options = import('types/internal').SSRRenderOptions; From 169664cd347272db5fd16ea43d5d4a550c834903 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Sun, 22 Aug 2021 15:55:46 +0700 Subject: [PATCH 05/15] re-import ambient modules --- packages/kit/types/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 1578711ca6d7..03e82c50a735 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -2,6 +2,7 @@ /// import './ambient-imports'; +import './ambient-modules'; export { App, IncomingRequest } from './app'; export { Adapter, AdapterUtils, Config, PrerenderErrorHandler, ValidatedConfig } from './config'; From 6fd051211f4e88b52c76f74ddf8db28cbad35e38 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Sun, 22 Aug 2021 15:56:08 +0700 Subject: [PATCH 06/15] add install-fetch ambient module types --- packages/kit/types/ambient-modules.d.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/kit/types/ambient-modules.d.ts b/packages/kit/types/ambient-modules.d.ts index 64eb076f3f08..388b163a9a44 100644 --- a/packages/kit/types/ambient-modules.d.ts +++ b/packages/kit/types/ambient-modules.d.ts @@ -31,3 +31,13 @@ declare module '@sveltejs/kit/ssr' { } export const respond: Respond; } + +declare module '@sveltejs/kit/install-fetch' { + type Fetch = import('node-fetch'); + type Headers = import('node-fetch').Headers; + type Request = import('node-fetch').Request; + type Response = import('node-fetch').Response; + + const fetch: Fetch; + export { fetch, Headers, Request, Response }; +} From ec94d78892e6fd1caa2a2ac4d6e82792886f9681 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Sun, 22 Aug 2021 17:23:36 +0700 Subject: [PATCH 07/15] es6 import style and dedup adapter types --- packages/adapter-begin/index.js | 2 +- .../adapter-cloudflare-workers/index.d.ts | 11 ++++++---- packages/adapter-cloudflare-workers/index.js | 12 +++------- packages/adapter-netlify/index.d.ts | 11 ++++++---- packages/adapter-netlify/index.js | 11 ++-------- packages/adapter-node/index.d.ts | 12 ++++++---- packages/adapter-node/index.js | 22 +++---------------- packages/adapter-node/src/server.js | 11 ++++++---- packages/adapter-node/src/shims.js | 2 +- packages/adapter-static/index.d.ts | 7 ++++-- packages/adapter-vercel/index.d.ts | 11 ++++++---- 11 files changed, 51 insertions(+), 61 deletions(-) diff --git a/packages/adapter-begin/index.js b/packages/adapter-begin/index.js index a1ad4dd12183..04c628e18679 100644 --- a/packages/adapter-begin/index.js +++ b/packages/adapter-begin/index.js @@ -3,7 +3,7 @@ export default function () { const adapter = { name: '@sveltejs/adapter-begin', - async adapt({ utils }) { + async adapt() { console.log('@sveltejs/adapter-begin can now be found at architect/sveltekit-adapter.'); } }; diff --git a/packages/adapter-cloudflare-workers/index.d.ts b/packages/adapter-cloudflare-workers/index.d.ts index 13bb56ed7b7e..7f3175d6e358 100644 --- a/packages/adapter-cloudflare-workers/index.d.ts +++ b/packages/adapter-cloudflare-workers/index.d.ts @@ -1,6 +1,9 @@ -type BuildOptions = import('esbuild').BuildOptions; -declare function plugin(options?: { - esbuild?: (defaultOptions: BuildOptions) => Promise | BuildOptions; -}): import('@sveltejs/kit').Adapter; +import { Adapter } from '@sveltejs/kit'; +import { BuildOptions } from 'esbuild'; +interface AdapterOptions { + esbuild?: (options: BuildOptions) => Promise | BuildOptions; +} + +declare function plugin(options?: AdapterOptions): Adapter; export = plugin; diff --git a/packages/adapter-cloudflare-workers/index.js b/packages/adapter-cloudflare-workers/index.js index c0913dc20024..746778083832 100644 --- a/packages/adapter-cloudflare-workers/index.js +++ b/packages/adapter-cloudflare-workers/index.js @@ -8,15 +8,11 @@ import { fileURLToPath } from 'url'; * @typedef {import('esbuild').BuildOptions} BuildOptions */ -/** - * @param {{ - * esbuild?: (defaultOptions: BuildOptions) => Promise | BuildOptions; - * }} [options] - **/ +/** @type {import('.')} */ export default function (options) { - /** @type {import('@sveltejs/kit').Adapter} */ - const adapter = { + return { name: '@sveltejs/adapter-cloudflare-workers', + async adapt({ utils }) { const { site } = validate_config(utils); @@ -64,8 +60,6 @@ export default function (options) { utils.copy_client_files(bucket); } }; - - return adapter; } function validate_config(utils) { diff --git a/packages/adapter-netlify/index.d.ts b/packages/adapter-netlify/index.d.ts index 13bb56ed7b7e..7f3175d6e358 100644 --- a/packages/adapter-netlify/index.d.ts +++ b/packages/adapter-netlify/index.d.ts @@ -1,6 +1,9 @@ -type BuildOptions = import('esbuild').BuildOptions; -declare function plugin(options?: { - esbuild?: (defaultOptions: BuildOptions) => Promise | BuildOptions; -}): import('@sveltejs/kit').Adapter; +import { Adapter } from '@sveltejs/kit'; +import { BuildOptions } from 'esbuild'; +interface AdapterOptions { + esbuild?: (options: BuildOptions) => Promise | BuildOptions; +} + +declare function plugin(options?: AdapterOptions): Adapter; export = plugin; diff --git a/packages/adapter-netlify/index.js b/packages/adapter-netlify/index.js index 07693b96dc5c..ad5e6cf3dd3c 100644 --- a/packages/adapter-netlify/index.js +++ b/packages/adapter-netlify/index.js @@ -8,14 +8,9 @@ import toml from '@iarna/toml'; * @typedef {import('esbuild').BuildOptions} BuildOptions */ -/** - * @param {{ - * esbuild?: (defaultOptions: BuildOptions) => Promise | BuildOptions; - * }} [options] - **/ +/** @type {import('.')} */ export default function (options) { - /** @type {import('@sveltejs/kit').Adapter} */ - const adapter = { + return { name: '@sveltejs/adapter-netlify', async adapt({ utils }) { @@ -65,8 +60,6 @@ export default function (options) { appendFileSync(redirectPath, '\n\n/* /.netlify/functions/__render 200'); } }; - - return adapter; } /** * @param {import('@sveltejs/kit').AdapterUtils} utils diff --git a/packages/adapter-node/index.d.ts b/packages/adapter-node/index.d.ts index fda7cc926fc3..99d467b63991 100644 --- a/packages/adapter-node/index.d.ts +++ b/packages/adapter-node/index.d.ts @@ -1,12 +1,16 @@ -type BuildOptions = import('esbuild').BuildOptions; -declare function plugin(options?: { +import { Adapter } from '@sveltejs/kit'; +import { BuildOptions } from 'esbuild'; + +interface AdapterOptions { out?: string; precompress?: boolean; env?: { + path?: string; host?: string; port?: string; }; - esbuild?: (defaultOptions: BuildOptions) => Promise | BuildOptions; -}): import('@sveltejs/kit').Adapter; + esbuild?: (options: BuildOptions) => Promise | BuildOptions; +} +declare function plugin(options?: AdapterOptions): Adapter; export = plugin; diff --git a/packages/adapter-node/index.js b/packages/adapter-node/index.js index bbcef9d35be1..ae7cad98ab59 100644 --- a/packages/adapter-node/index.js +++ b/packages/adapter-node/index.js @@ -20,26 +20,14 @@ const pipe = promisify(pipeline); * @typedef {import('esbuild').BuildOptions} BuildOptions */ -/** - * @param {{ - * out?: string; - * precompress?: boolean; - * env?: { - * path?: string; - * host?: string; - * port?: string; - * }; - * esbuild?: (defaultOptions: BuildOptions) => Promise | BuildOptions; - * }} options - */ +/** @type {import('.')} */ export default function ({ out = 'build', precompress, env: { path: path_env = 'SOCKET_PATH', host: host_env = 'HOST', port: port_env = 'PORT' } = {}, esbuild: esbuildConfig } = {}) { - /** @type {import('@sveltejs/kit').Adapter} */ - const adapter = { + return { name: '@sveltejs/adapter-node', async adapt({ utils, config }) { @@ -93,8 +81,6 @@ export default function ({ } } }; - - return adapter; } /** @@ -127,9 +113,7 @@ async function compress_file(file, format = 'gz') { [zlib.constants.BROTLI_PARAM_SIZE_HINT]: statSync(file).size } }) - : zlib.createGzip({ - level: zlib.constants.Z_BEST_COMPRESSION - }); + : zlib.createGzip({ level: zlib.constants.Z_BEST_COMPRESSION }); const source = createReadStream(file); const destination = createWriteStream(`${file}.${format}`); diff --git a/packages/adapter-node/src/server.js b/packages/adapter-node/src/server.js index dbbe304aadb7..b8143e50f987 100644 --- a/packages/adapter-node/src/server.js +++ b/packages/adapter-node/src/server.js @@ -1,4 +1,4 @@ -import { getRawBody } from '@sveltejs/kit/node'; // eslint-disable-line import/no-unresolved +import { getRawBody } from '@sveltejs/kit/node'; import compression from 'compression'; import fs from 'fs'; import { dirname, join } from 'path'; @@ -16,6 +16,8 @@ const paths = { prerendered: join(__dirname, '/prerendered') }; +// TODO: type render function from @sveltejs/kit/adapter +// @ts-ignore export function createServer({ render }) { const prerendered_handler = fs.existsSync(paths.prerendered) ? sirv(paths.prerendered, { @@ -28,9 +30,9 @@ export function createServer({ render }) { const assets_handler = fs.existsSync(paths.assets) ? sirv(paths.assets, { - setHeaders: (res, pathname, stats) => { - // eslint-disable-next-line no-undef - if (pathname.startsWith(APP_DIR)) { + setHeaders: (res, pathname) => { + // @ts-ignore - dynamically replaced with define + if (pathname.startsWith(/* eslint-disable-line no-undef */ APP_DIR)) { res.setHeader('cache-control', 'public, max-age=31536000, immutable'); } }, @@ -40,6 +42,7 @@ export function createServer({ render }) { : noop_handler; const server = polka().use( + // @ts-ignore - compression return doesn't play well with polka.use compression({ threshold: 0 }), assets_handler, prerendered_handler, diff --git a/packages/adapter-node/src/shims.js b/packages/adapter-node/src/shims.js index 8e96e704bd45..839b2dd5b108 100644 --- a/packages/adapter-node/src/shims.js +++ b/packages/adapter-node/src/shims.js @@ -1,5 +1,5 @@ import { createRequire } from 'module'; -export { fetch, Response, Request, Headers } from '@sveltejs/kit/install-fetch'; // eslint-disable-line import/no-unresolved +export { fetch, Response, Request, Headers } from '@sveltejs/kit/install-fetch'; // esbuild automatically renames "require" // So we still have to use Object.defineProperty here diff --git a/packages/adapter-static/index.d.ts b/packages/adapter-static/index.d.ts index 72296a4e0531..1f298a4a6f38 100644 --- a/packages/adapter-static/index.d.ts +++ b/packages/adapter-static/index.d.ts @@ -1,7 +1,10 @@ -declare function plugin(options?: { +import { Adapter } from '@sveltejs/kit'; + +interface AdapterOptions { pages?: string; assets?: string; fallback?: string; -}): import('@sveltejs/kit').Adapter; +} +declare function plugin(options?: AdapterOptions): Adapter; export = plugin; diff --git a/packages/adapter-vercel/index.d.ts b/packages/adapter-vercel/index.d.ts index 13bb56ed7b7e..7f3175d6e358 100644 --- a/packages/adapter-vercel/index.d.ts +++ b/packages/adapter-vercel/index.d.ts @@ -1,6 +1,9 @@ -type BuildOptions = import('esbuild').BuildOptions; -declare function plugin(options?: { - esbuild?: (defaultOptions: BuildOptions) => Promise | BuildOptions; -}): import('@sveltejs/kit').Adapter; +import { Adapter } from '@sveltejs/kit'; +import { BuildOptions } from 'esbuild'; +interface AdapterOptions { + esbuild?: (options: BuildOptions) => Promise | BuildOptions; +} + +declare function plugin(options?: AdapterOptions): Adapter; export = plugin; From 1c858fc7ce4ec4d96940412438ba9c52459fceb2 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Sun, 22 Aug 2021 17:23:50 +0700 Subject: [PATCH 08/15] snake_case! --- packages/adapter-cloudflare-workers/index.js | 8 ++++---- packages/adapter-netlify/index.js | 8 ++++---- packages/adapter-vercel/index.js | 19 ++++++------------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/packages/adapter-cloudflare-workers/index.js b/packages/adapter-cloudflare-workers/index.js index 746778083832..91909812030d 100644 --- a/packages/adapter-cloudflare-workers/index.js +++ b/packages/adapter-cloudflare-workers/index.js @@ -35,7 +35,7 @@ export default function (options) { utils.copy(`${files}/entry.js`, '.svelte-kit/cloudflare-workers/entry.js'); /** @type {BuildOptions} */ - const defaultOptions = { + const default_options = { entryPoints: ['.svelte-kit/cloudflare-workers/entry.js'], outfile: `${entrypoint}/index.js`, bundle: true, @@ -43,10 +43,10 @@ export default function (options) { platform: 'browser' }; - const buildOptions = - options && options.esbuild ? await options.esbuild(defaultOptions) : defaultOptions; + const build_options = + options && options.esbuild ? await options.esbuild(default_options) : default_options; - await esbuild.build(buildOptions); + await esbuild.build(build_options); fs.writeFileSync(`${entrypoint}/package.json`, JSON.stringify({ main: 'index.js' })); diff --git a/packages/adapter-netlify/index.js b/packages/adapter-netlify/index.js index ad5e6cf3dd3c..2368d0f2d1cd 100644 --- a/packages/adapter-netlify/index.js +++ b/packages/adapter-netlify/index.js @@ -27,7 +27,7 @@ export default function (options) { utils.copy(join(files, 'entry.js'), '.svelte-kit/netlify/entry.js'); /** @type {BuildOptions} */ - const defaultOptions = { + const default_options = { entryPoints: ['.svelte-kit/netlify/entry.js'], // Any functions in ".netlify/functions-internal" are bundled in addition to user-defined Netlify functions. // See https://github.com/netlify/build/pull/3213 for more details @@ -37,10 +37,10 @@ export default function (options) { platform: 'node' }; - const buildOptions = - options && options.esbuild ? await options.esbuild(defaultOptions) : defaultOptions; + const build_options = + options && options.esbuild ? await options.esbuild(default_options) : default_options; - await esbuild.build(buildOptions); + await esbuild.build(build_options); writeFileSync(join('.netlify', 'package.json'), JSON.stringify({ type: 'commonjs' })); diff --git a/packages/adapter-vercel/index.js b/packages/adapter-vercel/index.js index da0322553e72..d5c53689f143 100644 --- a/packages/adapter-vercel/index.js +++ b/packages/adapter-vercel/index.js @@ -7,14 +7,9 @@ import esbuild from 'esbuild'; * @typedef {import('esbuild').BuildOptions} BuildOptions */ -/** - * @param {{ - * esbuild?: (defaultOptions: BuildOptions) => Promise | BuildOptions; - * }} [options] - **/ +/** @type {import('.')} **/ export default function (options) { - /** @type {import('@sveltejs/kit').Adapter} */ - const adapter = { + return { name: '@sveltejs/adapter-vercel', async adapt({ utils }) { @@ -37,7 +32,7 @@ export default function (options) { utils.copy(join(files, 'entry.js'), '.svelte-kit/vercel/entry.js'); /** @type {BuildOptions} */ - const defaultOptions = { + const default_options = { entryPoints: ['.svelte-kit/vercel/entry.js'], outfile: join(dirs.lambda, 'index.js'), bundle: true, @@ -45,10 +40,10 @@ export default function (options) { platform: 'node' }; - const buildOptions = - options && options.esbuild ? await options.esbuild(defaultOptions) : defaultOptions; + const build_options = + options && options.esbuild ? await options.esbuild(default_options) : default_options; - await esbuild.build(buildOptions); + await esbuild.build(build_options); writeFileSync(join(dirs.lambda, 'package.json'), JSON.stringify({ type: 'commonjs' })); @@ -65,6 +60,4 @@ export default function (options) { utils.copy(join(files, 'routes.json'), join(dir, 'config/routes.json')); } }; - - return adapter; } From 77b486543533250a616ce568e9980579cb03a9af Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Sun, 22 Aug 2021 17:36:19 +0700 Subject: [PATCH 09/15] remove eslint-disable-line comments --- packages/adapter-cloudflare-workers/files/entry.js | 4 ++-- packages/adapter-netlify/files/entry.js | 2 +- packages/adapter-netlify/files/shims.js | 2 +- packages/adapter-node/src/index.js | 6 ++++-- packages/adapter-vercel/files/entry.js | 4 ++-- packages/adapter-vercel/files/shims.js | 2 +- 6 files changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/adapter-cloudflare-workers/files/entry.js b/packages/adapter-cloudflare-workers/files/entry.js index 2cba2395a393..09c6dd322edf 100644 --- a/packages/adapter-cloudflare-workers/files/entry.js +++ b/packages/adapter-cloudflare-workers/files/entry.js @@ -1,6 +1,6 @@ // TODO hardcoding the relative location makes this brittle -import { init, render } from '../output/server/app.js'; // eslint-disable-line import/no-unresolved -import { getAssetFromKV, NotFoundError } from '@cloudflare/kv-asset-handler'; // eslint-disable-line import/no-unresolved +import { init, render } from '../output/server/app.js'; +import { getAssetFromKV, NotFoundError } from '@cloudflare/kv-asset-handler'; init(); diff --git a/packages/adapter-netlify/files/entry.js b/packages/adapter-netlify/files/entry.js index 26f2965151d7..e5e7fd718c77 100644 --- a/packages/adapter-netlify/files/entry.js +++ b/packages/adapter-netlify/files/entry.js @@ -1,5 +1,5 @@ // TODO hardcoding the relative location makes this brittle -import { init, render } from '../output/server/app.js'; // eslint-disable-line import/no-unresolved +import { init, render } from '../output/server/app.js'; init(); diff --git a/packages/adapter-netlify/files/shims.js b/packages/adapter-netlify/files/shims.js index 8ef6d625bff2..cd9f71d6863c 100644 --- a/packages/adapter-netlify/files/shims.js +++ b/packages/adapter-netlify/files/shims.js @@ -1 +1 @@ -export { fetch, Response, Request, Headers } from '@sveltejs/kit/install-fetch'; // eslint-disable-line import/no-unresolved +export { fetch, Response, Request, Headers } from '@sveltejs/kit/install-fetch'; diff --git a/packages/adapter-node/src/index.js b/packages/adapter-node/src/index.js index b7d7c27dc5e4..4db8b8be6723 100644 --- a/packages/adapter-node/src/index.js +++ b/packages/adapter-node/src/index.js @@ -1,6 +1,8 @@ // TODO hardcoding the relative location makes this brittle -import { init, render } from '../output/server/app.js'; // eslint-disable-line import/no-unresolved -import { path, host, port } from './env.js'; // eslint-disable-line import/no-unresolved +// @ts-ignore +import { init, render } from '../output/server/app.js'; +// @ts-ignore +import { path, host, port } from './env.js'; import { createServer } from './server'; init(); diff --git a/packages/adapter-vercel/files/entry.js b/packages/adapter-vercel/files/entry.js index f1bb7f4d6b46..35d6e3170a7c 100644 --- a/packages/adapter-vercel/files/entry.js +++ b/packages/adapter-vercel/files/entry.js @@ -1,7 +1,7 @@ -import { getRawBody } from '@sveltejs/kit/node'; // eslint-disable-line import/no-unresolved +import { getRawBody } from '@sveltejs/kit/node'; // TODO hardcoding the relative location makes this brittle -import { init, render } from '../output/server/app.js'; // eslint-disable-line import/no-unresolved +import { init, render } from '../output/server/app.js'; init(); diff --git a/packages/adapter-vercel/files/shims.js b/packages/adapter-vercel/files/shims.js index 8ef6d625bff2..cd9f71d6863c 100644 --- a/packages/adapter-vercel/files/shims.js +++ b/packages/adapter-vercel/files/shims.js @@ -1 +1 @@ -export { fetch, Response, Request, Headers } from '@sveltejs/kit/install-fetch'; // eslint-disable-line import/no-unresolved +export { fetch, Response, Request, Headers } from '@sveltejs/kit/install-fetch'; From d09ea54303d588f3214c23a2d3981add35eec7bd Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Sun, 22 Aug 2021 17:39:51 +0700 Subject: [PATCH 10/15] no more import/no-unresolved --- packages/kit/src/runtime/client/start.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/kit/src/runtime/client/start.js b/packages/kit/src/runtime/client/start.js index 24e74c6eaaef..16b5407c546b 100644 --- a/packages/kit/src/runtime/client/start.js +++ b/packages/kit/src/runtime/client/start.js @@ -1,7 +1,7 @@ // @ts-ignore - value will be replaced on build step -import Root from 'ROOT'; // eslint-disable-line import/no-unresolved +import Root from 'ROOT'; // @ts-ignore - value will be replaced on build step -import { routes, fallback } from 'MANIFEST'; // eslint-disable-line import/no-unresolved +import { routes, fallback } from 'MANIFEST'; import { Router } from './router.js'; import { Renderer } from './renderer.js'; import { init } from './singletons.js'; From 35e893883e24b17b46a2b7b96f9e61b9104ebc3e Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Sun, 22 Aug 2021 17:56:46 +0700 Subject: [PATCH 11/15] merge ambient types for now --- packages/kit/types/ambient-imports.d.ts | 131 ----------------------- packages/kit/types/ambient-modules.d.ts | 132 ++++++++++++++++++++++++ packages/kit/types/index.d.ts | 1 - 3 files changed, 132 insertions(+), 132 deletions(-) delete mode 100644 packages/kit/types/ambient-imports.d.ts diff --git a/packages/kit/types/ambient-imports.d.ts b/packages/kit/types/ambient-imports.d.ts deleted file mode 100644 index 11000c605585..000000000000 --- a/packages/kit/types/ambient-imports.d.ts +++ /dev/null @@ -1,131 +0,0 @@ -declare module '$app/env' { - /** - * Whether or not app is in AMP mode. - */ - export const amp: boolean; - /** - * Whether the app is running in the browser or on the server. - */ - export const browser: boolean; - /** - * `true` in development mode, `false` in production. - */ - export const dev: boolean; - /** - * `true` when prerendering, `false` otherwise. - */ - export const prerendering: boolean; - /** - * The Vite.js mode the app is running in. Configure in `config.kit.vite.mode`. - * Vite.js loads the dotenv file associated with the provided mode, `.env.[mode]` or `.env.[mode].local`. - * By default, `svelte-kit dev` runs with `mode=development` and `svelte-kit build` runs with `mode=production`. - */ - export const mode: string; -} - -declare module '$app/navigation' { - /** - * Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified href. - * - * @param href Where to navigate to - * @param opts.replaceState If `true`, will replace the current `history` entry rather than creating a new one with `pushState` - * @param opts.noscroll If `true`, the browser will maintain its scroll position rather than scrolling to the top of the page after navigation - * @param opts.keepfocus If `true`, the currently focused element will retain focus after navigation. Otherwise, focus will be reset to the body - * @param opts.state The state of the new/updated history entry - */ - export function goto( - href: string, - opts?: { replaceState?: boolean; noscroll?: boolean; keepfocus?: boolean; state?: any } - ): Promise; - /** - * Returns a Promise that resolves when SvelteKit re-runs any current `load` functions that depend on `href` - * @param href The invalidated resource - */ - export function invalidate(href: string): Promise; - /** - * Programmatically prefetches the given page, which means - * 1. ensuring that the code for the page is loaded, and - * 2. calling the page's load function with the appropriate options. - * - * This is the same behaviour that SvelteKit triggers when the user taps or mouses over an `` element with `sveltekit:prefetch`. - * If the next navigation is to `href`, the values returned from load will be used, making navigation instantaneous. - * Returns a Promise that resolves when the prefetch is complete. - * - * @param href Page to prefetch - */ - export function prefetch(href: string): Promise; - /** - * Programmatically prefetches the code for routes that haven't yet been fetched. - * Typically, you might call this to speed up subsequent navigation. - * - * If no argument is given, all routes will be fetched, otherwise you can specify routes by any matching pathname - * such as `/about` (to match `src/routes/about.svelte`) or `/blog/*` (to match `src/routes/blog/[slug].svelte`). - * - * Unlike prefetch, this won't call preload for individual pages. - * Returns a Promise that resolves when the routes have been prefetched. - */ - export function prefetchRoutes(routes?: string[]): Promise; -} - -declare module '$app/paths' { - /** - * A root-relative (i.e. begins with a `/`) string that matches `config.kit.paths.base` in your project configuration. - */ - export const base: string; - /** - * A root-relative or absolute path that matches `config.kit.paths.assets` (after it has been resolved against base). - */ - export const assets: string; -} - -declare module '$app/stores' { - import { Readable, Writable } from 'svelte/store'; - type Page = import('@sveltejs/kit').Page; - type Navigating = { from: Page; to: Page }; - - /** - * A convenience function around `getContext` that returns `{ navigating, page, session }`. - * Most of the time, you won't need to use it. - */ - export function getStores(): { - navigating: Readable; - page: Readable; - session: Writable; - }; - /** - * A readable store whose value reflects the object passed to load functions. - */ - export const page: Readable; - /** - * A readable store. - * When navigating starts, its value is `{ from, to }`, where from and to both mirror the page store value. - * When navigating finishes, its value reverts to `null`. - */ - export const navigating: Readable; - /** - * A writable store whose initial value is whatever was returned from `getSession`. - * It can be written to, but this will not cause changes to persist on the server — this is something you must implement yourself. - */ - export const session: Writable; -} - -declare module '$service-worker' { - /** - * An array of URL strings representing the files generated by Vite, suitable for caching with `cache.addAll(build)`. - * This is only available to service workers. - */ - export const build: string[]; - /** - * An array of URL strings representing the files in your static directory, - * or whatever directory is specified by `config.kit.files.assets`. - * This is only available to service workers. - */ - export const files: string[]; - /** - * The result of calling `Date.now()` at build time. - * It's useful for generating unique cache names inside your service worker, - * so that a later deployment of your app can invalidate old caches. - * This is only available to service workers. - */ - export const timestamp: number; -} diff --git a/packages/kit/types/ambient-modules.d.ts b/packages/kit/types/ambient-modules.d.ts index 388b163a9a44..75fdc319ce4f 100644 --- a/packages/kit/types/ambient-modules.d.ts +++ b/packages/kit/types/ambient-modules.d.ts @@ -1,3 +1,135 @@ +declare module '$app/env' { + /** + * Whether or not app is in AMP mode. + */ + export const amp: boolean; + /** + * Whether the app is running in the browser or on the server. + */ + export const browser: boolean; + /** + * `true` in development mode, `false` in production. + */ + export const dev: boolean; + /** + * `true` when prerendering, `false` otherwise. + */ + export const prerendering: boolean; + /** + * The Vite.js mode the app is running in. Configure in `config.kit.vite.mode`. + * Vite.js loads the dotenv file associated with the provided mode, `.env.[mode]` or `.env.[mode].local`. + * By default, `svelte-kit dev` runs with `mode=development` and `svelte-kit build` runs with `mode=production`. + */ + export const mode: string; +} + +declare module '$app/navigation' { + /** + * Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified href. + * + * @param href Where to navigate to + * @param opts.replaceState If `true`, will replace the current `history` entry rather than creating a new one with `pushState` + * @param opts.noscroll If `true`, the browser will maintain its scroll position rather than scrolling to the top of the page after navigation + * @param opts.keepfocus If `true`, the currently focused element will retain focus after navigation. Otherwise, focus will be reset to the body + * @param opts.state The state of the new/updated history entry + */ + export function goto( + href: string, + opts?: { replaceState?: boolean; noscroll?: boolean; keepfocus?: boolean; state?: any } + ): Promise; + /** + * Returns a Promise that resolves when SvelteKit re-runs any current `load` functions that depend on `href` + * @param href The invalidated resource + */ + export function invalidate(href: string): Promise; + /** + * Programmatically prefetches the given page, which means + * 1. ensuring that the code for the page is loaded, and + * 2. calling the page's load function with the appropriate options. + * + * This is the same behaviour that SvelteKit triggers when the user taps or mouses over an `` element with `sveltekit:prefetch`. + * If the next navigation is to `href`, the values returned from load will be used, making navigation instantaneous. + * Returns a Promise that resolves when the prefetch is complete. + * + * @param href Page to prefetch + */ + export function prefetch(href: string): Promise; + /** + * Programmatically prefetches the code for routes that haven't yet been fetched. + * Typically, you might call this to speed up subsequent navigation. + * + * If no argument is given, all routes will be fetched, otherwise you can specify routes by any matching pathname + * such as `/about` (to match `src/routes/about.svelte`) or `/blog/*` (to match `src/routes/blog/[slug].svelte`). + * + * Unlike prefetch, this won't call preload for individual pages. + * Returns a Promise that resolves when the routes have been prefetched. + */ + export function prefetchRoutes(routes?: string[]): Promise; +} + +declare module '$app/paths' { + /** + * A root-relative (i.e. begins with a `/`) string that matches `config.kit.paths.base` in your project configuration. + */ + export const base: string; + /** + * A root-relative or absolute path that matches `config.kit.paths.assets` (after it has been resolved against base). + */ + export const assets: string; +} + +declare module '$app/stores' { + import { Readable, Writable } from 'svelte/store'; + type Page = import('@sveltejs/kit').Page; + type Navigating = { from: Page; to: Page }; + + /** + * A convenience function around `getContext` that returns `{ navigating, page, session }`. + * Most of the time, you won't need to use it. + */ + export function getStores(): { + navigating: Readable; + page: Readable; + session: Writable; + }; + /** + * A readable store whose value reflects the object passed to load functions. + */ + export const page: Readable; + /** + * A readable store. + * When navigating starts, its value is `{ from, to }`, where from and to both mirror the page store value. + * When navigating finishes, its value reverts to `null`. + */ + export const navigating: Readable; + /** + * A writable store whose initial value is whatever was returned from `getSession`. + * It can be written to, but this will not cause changes to persist on the server — this is something you must implement yourself. + */ + export const session: Writable; +} + +declare module '$service-worker' { + /** + * An array of URL strings representing the files generated by Vite, suitable for caching with `cache.addAll(build)`. + * This is only available to service workers. + */ + export const build: string[]; + /** + * An array of URL strings representing the files in your static directory, + * or whatever directory is specified by `config.kit.files.assets`. + * This is only available to service workers. + */ + export const files: string[]; + /** + * The result of calling `Date.now()` at build time. + * It's useful for generating unique cache names inside your service worker, + * so that a later deployment of your app can invalidate old caches. + * This is only available to service workers. + */ + export const timestamp: number; +} + declare module '@sveltejs/kit/hooks' { type Handle = import('@sveltejs/kit').Handle; diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 03e82c50a735..efc72fe67df1 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -1,7 +1,6 @@ /// /// -import './ambient-imports'; import './ambient-modules'; export { App, IncomingRequest } from './app'; From c1e64940adf9d344d523ab1d71f39f3603370420 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Mon, 23 Aug 2021 08:22:05 +0700 Subject: [PATCH 12/15] prefer expect-error --- packages/adapter-node/src/server.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/adapter-node/src/server.js b/packages/adapter-node/src/server.js index b8143e50f987..6342249b477d 100644 --- a/packages/adapter-node/src/server.js +++ b/packages/adapter-node/src/server.js @@ -31,7 +31,7 @@ export function createServer({ render }) { const assets_handler = fs.existsSync(paths.assets) ? sirv(paths.assets, { setHeaders: (res, pathname) => { - // @ts-ignore - dynamically replaced with define + // @ts-expect-error - dynamically replaced with define if (pathname.startsWith(/* eslint-disable-line no-undef */ APP_DIR)) { res.setHeader('cache-control', 'public, max-age=31536000, immutable'); } @@ -42,7 +42,7 @@ export function createServer({ render }) { : noop_handler; const server = polka().use( - // @ts-ignore - compression return doesn't play well with polka.use + // @ts-ignore TODO - compression return doesn't play well with polka.use compression({ threshold: 0 }), assets_handler, prerendered_handler, From bcf8b7351a8d138a2abd16ab8debf96f0ae42569 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Tue, 24 Aug 2021 07:37:36 +0700 Subject: [PATCH 13/15] update comments --- packages/adapter-node/src/server.js | 3 ++- packages/kit/src/runtime/client/start.js | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/adapter-node/src/server.js b/packages/adapter-node/src/server.js index 6342249b477d..9fb12ceb0f04 100644 --- a/packages/adapter-node/src/server.js +++ b/packages/adapter-node/src/server.js @@ -42,7 +42,8 @@ export function createServer({ render }) { : noop_handler; const server = polka().use( - // @ts-ignore TODO - compression return doesn't play well with polka.use + // https://github.com/lukeed/polka/issues/173 + // @ts-ignore - nothing we can do about so just ignore it compression({ threshold: 0 }), assets_handler, prerendered_handler, diff --git a/packages/kit/src/runtime/client/start.js b/packages/kit/src/runtime/client/start.js index 16b5407c546b..4af7187db07a 100644 --- a/packages/kit/src/runtime/client/start.js +++ b/packages/kit/src/runtime/client/start.js @@ -1,6 +1,6 @@ -// @ts-ignore - value will be replaced on build step +// @ts-expect-error - value will be replaced on build step import Root from 'ROOT'; -// @ts-ignore - value will be replaced on build step +// @ts-expect-error - value will be replaced on build step import { routes, fallback } from 'MANIFEST'; import { Router } from './router.js'; import { Renderer } from './renderer.js'; From 247e61f3741fca32634cfff6c27143a848f0d009 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Tue, 24 Aug 2021 09:57:17 +0700 Subject: [PATCH 14/15] rearrange and export required types --- .../src/runtime/server/parse_body/index.js | 2 +- packages/kit/types/app.d.ts | 31 ++++++++++--------- packages/kit/types/helper.d.ts | 6 +--- packages/kit/types/hooks.d.ts | 4 +-- packages/kit/types/index.d.ts | 2 +- 5 files changed, 21 insertions(+), 24 deletions(-) diff --git a/packages/kit/src/runtime/server/parse_body/index.js b/packages/kit/src/runtime/server/parse_body/index.js index 6e6d55cf1b7c..588a8a936127 100644 --- a/packages/kit/src/runtime/server/parse_body/index.js +++ b/packages/kit/src/runtime/server/parse_body/index.js @@ -1,7 +1,7 @@ import { read_only_form_data } from './read_only_form_data.js'; /** - * @param {import('types/helper').RawBody} raw + * @param {import('types/app').RawBody} raw * @param {import('types/helper').Headers} headers */ export function parse_body(raw, headers) { diff --git a/packages/kit/types/app.d.ts b/packages/kit/types/app.d.ts index 243b50020c18..720c49b4b819 100644 --- a/packages/kit/types/app.d.ts +++ b/packages/kit/types/app.d.ts @@ -1,21 +1,8 @@ -import { Headers, RawBody } from './helper'; +import { Headers, ReadOnlyFormData } from './helper'; import { ServerResponse } from './hooks'; -export interface IncomingRequest { - method: string; - host: string; - path: string; - query: URLSearchParams; - headers: Headers; - rawBody: RawBody; -} - export interface App { - init({ - paths, - prerendering, - read - }?: { + init(options?: { paths: { base: string; assets: string; @@ -34,3 +21,17 @@ export interface App { } ): Promise; } + +export type RawBody = null | Uint8Array; +export type ParameterizedBody = Body extends FormData + ? ReadOnlyFormData + : (string | RawBody | ReadOnlyFormData) & Body; + +export interface IncomingRequest { + method: string; + host: string; + path: string; + query: URLSearchParams; + headers: Headers; + rawBody: RawBody; +} diff --git a/packages/kit/types/helper.d.ts b/packages/kit/types/helper.d.ts index 475271b1cc15..1d7c2abe9980 100644 --- a/packages/kit/types/helper.d.ts +++ b/packages/kit/types/helper.d.ts @@ -8,17 +8,13 @@ interface ReadOnlyFormData { [Symbol.iterator](): Generator<[string, string], void>; } -export type RawBody = null | Uint8Array; -export type ParameterizedBody = Body extends FormData - ? ReadOnlyFormData - : (string | RawBody | ReadOnlyFormData) & Body; - // 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; +// Utility Types export type InferValue = T extends Record ? Val : Default; diff --git a/packages/kit/types/hooks.d.ts b/packages/kit/types/hooks.d.ts index 32500121574e..6320df30a0fe 100644 --- a/packages/kit/types/hooks.d.ts +++ b/packages/kit/types/hooks.d.ts @@ -1,5 +1,5 @@ -import { IncomingRequest } from './app'; -import { Headers, MaybePromise, ParameterizedBody } from './helper'; +import { IncomingRequest, ParameterizedBody } from './app'; +import { Headers, MaybePromise } from './helper'; export type StrictBody = string | Uint8Array; diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index efc72fe67df1..e9b4d91d90d3 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -3,7 +3,7 @@ import './ambient-modules'; -export { App, IncomingRequest } from './app'; +export { App, IncomingRequest, RawBody } from './app'; export { Adapter, AdapterUtils, Config, PrerenderErrorHandler, ValidatedConfig } from './config'; export { EndpointOutput, RequestHandler } from './endpoint'; export { ErrorLoad, ErrorLoadInput, Load, LoadInput, LoadOutput, Page } from './page'; From 0ca9c6398e678056bac6dddcbc912c10a6b83d4a Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Tue, 24 Aug 2021 10:11:51 +0700 Subject: [PATCH 15/15] esm import style --- packages/kit/tsconfig.json | 2 ++ packages/kit/types/ambient-modules.d.ts | 26 ++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/kit/tsconfig.json b/packages/kit/tsconfig.json index be93e50105b6..b288e319af6f 100644 --- a/packages/kit/tsconfig.json +++ b/packages/kit/tsconfig.json @@ -10,6 +10,8 @@ "allowSyntheticDefaultImports": true, "paths": { "@sveltejs/kit": ["./types/index"], + // paths after this are for internal use only + "@sveltejs/kit/types/*": ["./types/*"], "test": ["./test/types"], "types/*": ["./types/*"] } diff --git a/packages/kit/types/ambient-modules.d.ts b/packages/kit/types/ambient-modules.d.ts index 75fdc319ce4f..6e4f9b5de04d 100644 --- a/packages/kit/types/ambient-modules.d.ts +++ b/packages/kit/types/ambient-modules.d.ts @@ -1,3 +1,5 @@ +/* eslint-disable import/no-duplicates */ + declare module '$app/env' { /** * Whether or not app is in AMP mode. @@ -80,7 +82,7 @@ declare module '$app/paths' { declare module '$app/stores' { import { Readable, Writable } from 'svelte/store'; - type Page = import('@sveltejs/kit').Page; + import { Page } from '@sveltejs/kit'; type Navigating = { from: Page; to: Page }; /** @@ -131,7 +133,7 @@ declare module '$service-worker' { } declare module '@sveltejs/kit/hooks' { - type Handle = import('@sveltejs/kit').Handle; + import { Handle } from '@sveltejs/kit'; /** * Utility function that allows chaining `handle` functions in a @@ -143,8 +145,8 @@ declare module '@sveltejs/kit/hooks' { } declare module '@sveltejs/kit/node' { - type IncomingMessage = import('http').IncomingMessage; - type RawBody = import('types/helper').RawBody; + import { IncomingMessage } from 'http'; + import { RawBody } from '@sveltejs/kit'; export interface GetRawBody { (request: IncomingMessage): Promise; @@ -153,23 +155,19 @@ declare module '@sveltejs/kit/node' { } declare module '@sveltejs/kit/ssr' { - type IncomingRequest = import('@sveltejs/kit').IncomingRequest; - type Options = import('types/internal').SSRRenderOptions; - type State = import('types/internal').SSRRenderState; - type ServerResponse = import('@sveltejs/kit').Response; + import { IncomingRequest, Response } from '@sveltejs/kit'; + // TODO import from public types, right now its heavily coupled with internal + type Options = import('@sveltejs/kit/types/internal').SSRRenderOptions; + type State = import('@sveltejs/kit/types/internal').SSRRenderState; export interface Respond { - (incoming: IncomingRequest, options: Options, state?: State): ServerResponse; + (incoming: IncomingRequest, options: Options, state?: State): Response; } export const respond: Respond; } declare module '@sveltejs/kit/install-fetch' { - type Fetch = import('node-fetch'); - type Headers = import('node-fetch').Headers; - type Request = import('node-fetch').Request; - type Response = import('node-fetch').Response; + import fetch, { Headers, Request, Response } from 'node-fetch'; - const fetch: Fetch; export { fetch, Headers, Request, Response }; }