Skip to content

Commit

Permalink
fix: convert more public types to arrow funcs
Browse files Browse the repository at this point in the history
Convert the rest of the public types in `src/exports/public.d.ts` to use
arrow function types instead of bound function types.

I kept the following types in `public.d.ts` using non-arrow functions,
since

- These functions are for user inputs, which might rely on these
  functions being bound, and so it might be a breaking change to
  change these types:
  - [`Emulator['platform']`][1]
  - functions in `KitConfig`
- Class methods that rely on `this`:
  - [`Server`][2]

[1]: https://github.com/sveltejs/kit/blob/b25f2d052bbf22e832ac57cbf9e12c48ac922f96/packages/kit/src/exports/public.d.ts#L272-L276
[2]: https://github.com/sveltejs/kit/blob/b25f2d052bbf22e832ac57cbf9e12c48ac922f96/packages/kit/src/exports/public.d.ts#L1174-L1178
  • Loading branch information
aloisklink committed Nov 21, 2024
1 parent b25f2d0 commit 743d807
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 54 deletions.
52 changes: 26 additions & 26 deletions packages/kit/src/exports/public.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ export interface Builder {
/** Print messages to the console. `log.info` and `log.minor` are silent unless Vite's `logLevel` is `info`. */
log: Logger;
/** Remove `dir` and all its contents. */
rimraf(dir: string): void;
rimraf: (dir: string) => void;
/** Create `dir` and any required parent directories. */
mkdirp(dir: string): void;
mkdirp: (dir: string) => void;

/** The fully resolved `svelte.config.js`. */
config: ValidatedConfig;
Expand All @@ -110,59 +110,59 @@ export interface Builder {
* @param fn A function that groups a set of routes into an entry point
* @deprecated Use `builder.routes` instead
*/
createEntries(fn: (route: RouteDefinition) => AdapterEntry): Promise<void>;
createEntries: (fn: (route: RouteDefinition) => AdapterEntry) => Promise<void>;

/**
* Find all the assets imported by server files belonging to `routes`
*/
findServerAssets(routes: RouteDefinition[]): string[];
findServerAssets: (routes: RouteDefinition[]) => string[];

/**
* Generate a fallback page for a static webserver to use when no route is matched. Useful for single-page apps.
*/
generateFallback(dest: string): Promise<void>;
generateFallback: (dest: string) => Promise<void>;

/**
* Generate a module exposing build-time environment variables as `$env/dynamic/public`.
*/
generateEnvModule(): void;
generateEnvModule: () => void;

/**
* Generate a server-side manifest to initialise the SvelteKit [server](https://svelte.dev/docs/kit/@sveltejs-kit#Server) with.
* @param opts a relative path to the base directory of the app and optionally in which format (esm or cjs) the manifest should be generated
*/
generateManifest(opts: { relativePath: string; routes?: RouteDefinition[] }): string;
generateManifest: (opts: { relativePath: string; routes?: RouteDefinition[] }) => string;

/**
* Resolve a path to the `name` directory inside `outDir`, e.g. `/path/to/.svelte-kit/my-adapter`.
* @param name path to the file, relative to the build directory
*/
getBuildDirectory(name: string): string;
getBuildDirectory: (name: string) => string;
/** Get the fully resolved path to the directory containing client-side assets, including the contents of your `static` directory. */
getClientDirectory(): string;
getClientDirectory: () => string;
/** Get the fully resolved path to the directory containing server-side code. */
getServerDirectory(): string;
getServerDirectory: () => string;
/** Get the application path including any configured `base` path, e.g. `my-base-path/_app`. */
getAppPath(): string;
getAppPath: () => string;

/**
* Write client assets to `dest`.
* @param dest the destination folder
* @returns an array of files written to `dest`
*/
writeClient(dest: string): string[];
writeClient: (dest: string) => string[];
/**
* Write prerendered files to `dest`.
* @param dest the destination folder
* @returns an array of files written to `dest`
*/
writePrerendered(dest: string): string[];
writePrerendered: (dest: string) => string[];
/**
* Write server-side code to `dest`.
* @param dest the destination folder
* @returns an array of files written to `dest`
*/
writeServer(dest: string): string[];
writeServer: (dest: string) => string[];
/**
* Copy a file or directory.
* @param from the source file or directory
Expand All @@ -171,20 +171,20 @@ export interface Builder {
* @param opts.replace a map of strings to replace
* @returns an array of files that were copied
*/
copy(
copy: (
from: string,
to: string,
opts?: {
filter?(basename: string): boolean;
replace?: Record<string, string>;
}
): string[];
) => string[];

/**
* Compress files in `directory` with gzip and brotli, where appropriate. Generates `.gz` and `.br` files alongside the originals.
* @param {string} directory The directory containing the files to be compressed
*/
compress(directory: string): Promise<void>;
compress: (directory: string) => Promise<void>;
}

export interface Config {
Expand Down Expand Up @@ -214,13 +214,13 @@ export interface Cookies {
* @param name the name of the cookie
* @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options)
*/
get(name: string, opts?: import('cookie').CookieParseOptions): string | undefined;
get: (name: string, opts?: import('cookie').CookieParseOptions) => string | undefined;

/**
* Gets all cookies that were previously set with `cookies.set`, or from the request headers.
* @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options)
*/
getAll(opts?: import('cookie').CookieParseOptions): Array<{ name: string; value: string }>;
getAll: (opts?: import('cookie').CookieParseOptions) => Array<{ name: string; value: string }>;

/**
* Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request.
Expand All @@ -232,11 +232,11 @@ export interface Cookies {
* @param value the cookie value
* @param opts the options, passed directly to `cookie.serialize`. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
*/
set(
set: (
name: string,
value: string,
opts: import('cookie').CookieSerializeOptions & { path: string }
): void;
) => void;

/**
* Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
Expand All @@ -245,7 +245,7 @@ export interface Cookies {
* @param name the name of the cookie
* @param opts the options, passed directly to `cookie.serialize`. The `path` must match the path of the cookie you want to delete. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
*/
delete(name: string, opts: import('cookie').CookieSerializeOptions & { path: string }): void;
delete: (name: string, opts: import('cookie').CookieSerializeOptions & { path: string }) => void;

/**
* Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
Expand All @@ -258,11 +258,11 @@ export interface Cookies {
* @param value the cookie value
* @param opts the options, passed directly to `cookie.serialize`. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
*/
serialize(
serialize: (
name: string,
value: string,
opts: import('cookie').CookieSerializeOptions & { path: string }
): string;
) => string;
}

/**
Expand Down Expand Up @@ -945,7 +945,7 @@ export interface BeforeNavigate extends Navigation {
/**
* Call this to prevent the navigation from starting.
*/
cancel(): void;
cancel: () => void;
}

/**
Expand Down Expand Up @@ -1195,7 +1195,7 @@ export interface SSRManifest {
client: NonNullable<BuildData['client']>;
nodes: SSRNodeLoader[];
routes: SSRRoute[];
matchers(): Promise<Record<string, ParamMatcher>>;
matchers: () => Promise<Record<string, ParamMatcher>>;
/** A `[file]: size` map of all assets imported by server code */
server_assets: Record<string, number>;
};
Expand Down
4 changes: 2 additions & 2 deletions packages/kit/src/runtime/server/cookie.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export function get_cookies(request, url, trailing_slash) {

/**
* @param {string} name
* @param {import('cookie').CookieParseOptions} opts
* @param {import('cookie').CookieParseOptions} [opts]
*/
get(name, opts) {
const c = new_cookies[name];
Expand Down Expand Up @@ -89,7 +89,7 @@ export function get_cookies(request, url, trailing_slash) {
},

/**
* @param {import('cookie').CookieParseOptions} opts
* @param {import('cookie').CookieParseOptions} [opts]
*/
getAll(opts) {
const decoder = opts?.decode || decodeURIComponent;
Expand Down
52 changes: 26 additions & 26 deletions packages/kit/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ declare module '@sveltejs/kit' {
/** Print messages to the console. `log.info` and `log.minor` are silent unless Vite's `logLevel` is `info`. */
log: Logger;
/** Remove `dir` and all its contents. */
rimraf(dir: string): void;
rimraf: (dir: string) => void;
/** Create `dir` and any required parent directories. */
mkdirp(dir: string): void;
mkdirp: (dir: string) => void;

/** The fully resolved `svelte.config.js`. */
config: ValidatedConfig;
Expand All @@ -92,59 +92,59 @@ declare module '@sveltejs/kit' {
* @param fn A function that groups a set of routes into an entry point
* @deprecated Use `builder.routes` instead
*/
createEntries(fn: (route: RouteDefinition) => AdapterEntry): Promise<void>;
createEntries: (fn: (route: RouteDefinition) => AdapterEntry) => Promise<void>;

/**
* Find all the assets imported by server files belonging to `routes`
*/
findServerAssets(routes: RouteDefinition[]): string[];
findServerAssets: (routes: RouteDefinition[]) => string[];

/**
* Generate a fallback page for a static webserver to use when no route is matched. Useful for single-page apps.
*/
generateFallback(dest: string): Promise<void>;
generateFallback: (dest: string) => Promise<void>;

/**
* Generate a module exposing build-time environment variables as `$env/dynamic/public`.
*/
generateEnvModule(): void;
generateEnvModule: () => void;

/**
* Generate a server-side manifest to initialise the SvelteKit [server](https://svelte.dev/docs/kit/@sveltejs-kit#Server) with.
* @param opts a relative path to the base directory of the app and optionally in which format (esm or cjs) the manifest should be generated
*/
generateManifest(opts: { relativePath: string; routes?: RouteDefinition[] }): string;
generateManifest: (opts: { relativePath: string; routes?: RouteDefinition[] }) => string;

/**
* Resolve a path to the `name` directory inside `outDir`, e.g. `/path/to/.svelte-kit/my-adapter`.
* @param name path to the file, relative to the build directory
*/
getBuildDirectory(name: string): string;
getBuildDirectory: (name: string) => string;
/** Get the fully resolved path to the directory containing client-side assets, including the contents of your `static` directory. */
getClientDirectory(): string;
getClientDirectory: () => string;
/** Get the fully resolved path to the directory containing server-side code. */
getServerDirectory(): string;
getServerDirectory: () => string;
/** Get the application path including any configured `base` path, e.g. `my-base-path/_app`. */
getAppPath(): string;
getAppPath: () => string;

/**
* Write client assets to `dest`.
* @param dest the destination folder
* @returns an array of files written to `dest`
*/
writeClient(dest: string): string[];
writeClient: (dest: string) => string[];
/**
* Write prerendered files to `dest`.
* @param dest the destination folder
* @returns an array of files written to `dest`
*/
writePrerendered(dest: string): string[];
writePrerendered: (dest: string) => string[];
/**
* Write server-side code to `dest`.
* @param dest the destination folder
* @returns an array of files written to `dest`
*/
writeServer(dest: string): string[];
writeServer: (dest: string) => string[];
/**
* Copy a file or directory.
* @param from the source file or directory
Expand All @@ -153,20 +153,20 @@ declare module '@sveltejs/kit' {
* @param opts.replace a map of strings to replace
* @returns an array of files that were copied
*/
copy(
copy: (
from: string,
to: string,
opts?: {
filter?(basename: string): boolean;
replace?: Record<string, string>;
}
): string[];
) => string[];

/**
* Compress files in `directory` with gzip and brotli, where appropriate. Generates `.gz` and `.br` files alongside the originals.
* @param directory The directory containing the files to be compressed
*/
compress(directory: string): Promise<void>;
compress: (directory: string) => Promise<void>;
}

export interface Config {
Expand Down Expand Up @@ -196,13 +196,13 @@ declare module '@sveltejs/kit' {
* @param name the name of the cookie
* @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options)
*/
get(name: string, opts?: import('cookie').CookieParseOptions): string | undefined;
get: (name: string, opts?: import('cookie').CookieParseOptions) => string | undefined;

/**
* Gets all cookies that were previously set with `cookies.set`, or from the request headers.
* @param opts the options, passed directly to `cookie.parse`. See documentation [here](https://github.com/jshttp/cookie#cookieparsestr-options)
*/
getAll(opts?: import('cookie').CookieParseOptions): Array<{ name: string; value: string }>;
getAll: (opts?: import('cookie').CookieParseOptions) => Array<{ name: string; value: string }>;

/**
* Sets a cookie. This will add a `set-cookie` header to the response, but also make the cookie available via `cookies.get` or `cookies.getAll` during the current request.
Expand All @@ -214,11 +214,11 @@ declare module '@sveltejs/kit' {
* @param value the cookie value
* @param opts the options, passed directly to `cookie.serialize`. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
*/
set(
set: (
name: string,
value: string,
opts: import('cookie').CookieSerializeOptions & { path: string }
): void;
) => void;

/**
* Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
Expand All @@ -227,7 +227,7 @@ declare module '@sveltejs/kit' {
* @param name the name of the cookie
* @param opts the options, passed directly to `cookie.serialize`. The `path` must match the path of the cookie you want to delete. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
*/
delete(name: string, opts: import('cookie').CookieSerializeOptions & { path: string }): void;
delete: (name: string, opts: import('cookie').CookieSerializeOptions & { path: string }) => void;

/**
* Serialize a cookie name-value pair into a `Set-Cookie` header string, but don't apply it to the response.
Expand All @@ -240,11 +240,11 @@ declare module '@sveltejs/kit' {
* @param value the cookie value
* @param opts the options, passed directly to `cookie.serialize`. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
*/
serialize(
serialize: (
name: string,
value: string,
opts: import('cookie').CookieSerializeOptions & { path: string }
): string;
) => string;
}

/**
Expand Down Expand Up @@ -927,7 +927,7 @@ declare module '@sveltejs/kit' {
/**
* Call this to prevent the navigation from starting.
*/
cancel(): void;
cancel: () => void;
}

/**
Expand Down Expand Up @@ -1177,7 +1177,7 @@ declare module '@sveltejs/kit' {
client: NonNullable<BuildData['client']>;
nodes: SSRNodeLoader[];
routes: SSRRoute[];
matchers(): Promise<Record<string, ParamMatcher>>;
matchers: () => Promise<Record<string, ParamMatcher>>;
/** A `[file]: size` map of all assets imported by server code */
server_assets: Record<string, number>;
};
Expand Down

0 comments on commit 743d807

Please sign in to comment.