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

chore: clean up emulator types #11737

Merged
merged 3 commits into from
Jan 25, 2024
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
3 changes: 2 additions & 1 deletion packages/kit/src/core/adapt/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export async function adapt(
log,
vite_config
) {
const { name, adapt } = config.kit.adapter;
// This is only called when adapter is truthy, so the cast is safe
const { name, adapt } = /** @type {import('@sveltejs/kit').Adapter} */ (config.kit.adapter);

console.log(colors.bold().cyan(`\n> Using ${name}`));

Expand Down
2 changes: 1 addition & 1 deletion packages/kit/src/exports/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ export interface Cookies {
/**
* A collection of functions that influence the environment during dev, build and prerendering
*/
export class Emulator {
export interface Emulator {
/**
* A function that is called with the current route `config` and `prerender` option
* and returns an `App.Platform` object
Expand Down
2 changes: 0 additions & 2 deletions packages/kit/src/exports/vite/dev/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -419,8 +419,6 @@ export async function dev(vite, vite_config, svelte_config) {
});

const env = loadEnv(vite_config.mode, svelte_config.kit.env.dir, '');

// TODO because of `RecursiveRequired`, TypeScript thinks this is guaranteed to exist, but it isn't
const emulator = await svelte_config.kit.adapter?.emulate?.();

return () => {
Expand Down
1 change: 0 additions & 1 deletion packages/kit/src/exports/vite/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ export async function sveltekit() {
preprocess,
onwarn: svelte_config.onwarn,
compilerOptions: {
// @ts-expect-error SvelteKit requires hydratable true by default
hydratable: isSvelte5Plus() ? undefined : true,
...svelte_config.compilerOptions
},
Expand Down
1 change: 0 additions & 1 deletion packages/kit/src/exports/vite/preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ export async function preview(vite, vite_config, svelte_config) {
read: (file) => createReadableStream(`${dir}/${file}`)
});

// TODO because of `RecursiveRequired`, TypeScript thinks this is guaranteed to exist, but it isn't
const emulator = await svelte_config.kit.adapter?.emulate?.();

return () => {
Expand Down
12 changes: 9 additions & 3 deletions packages/kit/src/types/internal.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import {
Reroute,
RequestEvent,
SSRManifest,
Emulator
Emulator,
Adapter
} from '@sveltejs/kit';
import {
HttpMethod,
Expand Down Expand Up @@ -434,9 +435,14 @@ export interface Uses {
search_params: Set<string>;
}

export type ValidatedConfig = RecursiveRequired<Config>;
export type ValidatedConfig = Config & {
kit: ValidatedKitConfig;
extensions: string[];
};

export type ValidatedKitConfig = RecursiveRequired<KitConfig>;
export type ValidatedKitConfig = Omit<RecursiveRequired<KitConfig>, 'adapter'> & {
adapter?: Adapter;
};

export * from '../exports/index.js';
export * from './private.js';
11 changes: 9 additions & 2 deletions packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ declare module '@sveltejs/kit' {
/**
* A collection of functions that influence the environment during dev, build and prerendering
*/
export class Emulator {
export interface Emulator {
/**
* A function that is called with the current route `config` and `prerender` option
* and returns an `App.Platform` object
Expand Down Expand Up @@ -1748,7 +1748,14 @@ declare module '@sveltejs/kit' {
endpoint_id?: string;
}

type ValidatedConfig = RecursiveRequired<Config>;
type ValidatedConfig = Config & {
kit: ValidatedKitConfig;
extensions: string[];
};

type ValidatedKitConfig = Omit<RecursiveRequired<KitConfig>, 'adapter'> & {
adapter?: Adapter;
};
/**
* Throws an error with a HTTP status code and an optional message.
* When called during request handling, this will cause SvelteKit to
Expand Down
Loading