Skip to content

Commit 743d807

Browse files
committed
fix: convert more public types to arrow funcs
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
1 parent b25f2d0 commit 743d807

File tree

3 files changed

+54
-54
lines changed

3 files changed

+54
-54
lines changed

packages/kit/src/exports/public.d.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@ export interface Builder {
9393
/** Print messages to the console. `log.info` and `log.minor` are silent unless Vite's `logLevel` is `info`. */
9494
log: Logger;
9595
/** Remove `dir` and all its contents. */
96-
rimraf(dir: string): void;
96+
rimraf: (dir: string) => void;
9797
/** Create `dir` and any required parent directories. */
98-
mkdirp(dir: string): void;
98+
mkdirp: (dir: string) => void;
9999

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

115115
/**
116116
* Find all the assets imported by server files belonging to `routes`
117117
*/
118-
findServerAssets(routes: RouteDefinition[]): string[];
118+
findServerAssets: (routes: RouteDefinition[]) => string[];
119119

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

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

130130
/**
131131
* Generate a server-side manifest to initialise the SvelteKit [server](https://svelte.dev/docs/kit/@sveltejs-kit#Server) with.
132132
* @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
133133
*/
134-
generateManifest(opts: { relativePath: string; routes?: RouteDefinition[] }): string;
134+
generateManifest: (opts: { relativePath: string; routes?: RouteDefinition[] }) => string;
135135

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

148148
/**
149149
* Write client assets to `dest`.
150150
* @param dest the destination folder
151151
* @returns an array of files written to `dest`
152152
*/
153-
writeClient(dest: string): string[];
153+
writeClient: (dest: string) => string[];
154154
/**
155155
* Write prerendered files to `dest`.
156156
* @param dest the destination folder
157157
* @returns an array of files written to `dest`
158158
*/
159-
writePrerendered(dest: string): string[];
159+
writePrerendered: (dest: string) => string[];
160160
/**
161161
* Write server-side code to `dest`.
162162
* @param dest the destination folder
163163
* @returns an array of files written to `dest`
164164
*/
165-
writeServer(dest: string): string[];
165+
writeServer: (dest: string) => string[];
166166
/**
167167
* Copy a file or directory.
168168
* @param from the source file or directory
@@ -171,20 +171,20 @@ export interface Builder {
171171
* @param opts.replace a map of strings to replace
172172
* @returns an array of files that were copied
173173
*/
174-
copy(
174+
copy: (
175175
from: string,
176176
to: string,
177177
opts?: {
178178
filter?(basename: string): boolean;
179179
replace?: Record<string, string>;
180180
}
181-
): string[];
181+
) => string[];
182182

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

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

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

225225
/**
226226
* 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.
@@ -232,11 +232,11 @@ export interface Cookies {
232232
* @param value the cookie value
233233
* @param opts the options, passed directly to `cookie.serialize`. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
234234
*/
235-
set(
235+
set: (
236236
name: string,
237237
value: string,
238238
opts: import('cookie').CookieSerializeOptions & { path: string }
239-
): void;
239+
) => void;
240240

241241
/**
242242
* Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
@@ -245,7 +245,7 @@ export interface Cookies {
245245
* @param name the name of the cookie
246246
* @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)
247247
*/
248-
delete(name: string, opts: import('cookie').CookieSerializeOptions & { path: string }): void;
248+
delete: (name: string, opts: import('cookie').CookieSerializeOptions & { path: string }) => void;
249249

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

268268
/**
@@ -945,7 +945,7 @@ export interface BeforeNavigate extends Navigation {
945945
/**
946946
* Call this to prevent the navigation from starting.
947947
*/
948-
cancel(): void;
948+
cancel: () => void;
949949
}
950950

951951
/**
@@ -1195,7 +1195,7 @@ export interface SSRManifest {
11951195
client: NonNullable<BuildData['client']>;
11961196
nodes: SSRNodeLoader[];
11971197
routes: SSRRoute[];
1198-
matchers(): Promise<Record<string, ParamMatcher>>;
1198+
matchers: () => Promise<Record<string, ParamMatcher>>;
11991199
/** A `[file]: size` map of all assets imported by server code */
12001200
server_assets: Record<string, number>;
12011201
};

packages/kit/src/runtime/server/cookie.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export function get_cookies(request, url, trailing_slash) {
5252

5353
/**
5454
* @param {string} name
55-
* @param {import('cookie').CookieParseOptions} opts
55+
* @param {import('cookie').CookieParseOptions} [opts]
5656
*/
5757
get(name, opts) {
5858
const c = new_cookies[name];
@@ -89,7 +89,7 @@ export function get_cookies(request, url, trailing_slash) {
8989
},
9090

9191
/**
92-
* @param {import('cookie').CookieParseOptions} opts
92+
* @param {import('cookie').CookieParseOptions} [opts]
9393
*/
9494
getAll(opts) {
9595
const decoder = opts?.decode || decodeURIComponent;

packages/kit/types/index.d.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ declare module '@sveltejs/kit' {
7575
/** Print messages to the console. `log.info` and `log.minor` are silent unless Vite's `logLevel` is `info`. */
7676
log: Logger;
7777
/** Remove `dir` and all its contents. */
78-
rimraf(dir: string): void;
78+
rimraf: (dir: string) => void;
7979
/** Create `dir` and any required parent directories. */
80-
mkdirp(dir: string): void;
80+
mkdirp: (dir: string) => void;
8181

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

9797
/**
9898
* Find all the assets imported by server files belonging to `routes`
9999
*/
100-
findServerAssets(routes: RouteDefinition[]): string[];
100+
findServerAssets: (routes: RouteDefinition[]) => string[];
101101

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

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

112112
/**
113113
* Generate a server-side manifest to initialise the SvelteKit [server](https://svelte.dev/docs/kit/@sveltejs-kit#Server) with.
114114
* @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
115115
*/
116-
generateManifest(opts: { relativePath: string; routes?: RouteDefinition[] }): string;
116+
generateManifest: (opts: { relativePath: string; routes?: RouteDefinition[] }) => string;
117117

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

130130
/**
131131
* Write client assets to `dest`.
132132
* @param dest the destination folder
133133
* @returns an array of files written to `dest`
134134
*/
135-
writeClient(dest: string): string[];
135+
writeClient: (dest: string) => string[];
136136
/**
137137
* Write prerendered files to `dest`.
138138
* @param dest the destination folder
139139
* @returns an array of files written to `dest`
140140
*/
141-
writePrerendered(dest: string): string[];
141+
writePrerendered: (dest: string) => string[];
142142
/**
143143
* Write server-side code to `dest`.
144144
* @param dest the destination folder
145145
* @returns an array of files written to `dest`
146146
*/
147-
writeServer(dest: string): string[];
147+
writeServer: (dest: string) => string[];
148148
/**
149149
* Copy a file or directory.
150150
* @param from the source file or directory
@@ -153,20 +153,20 @@ declare module '@sveltejs/kit' {
153153
* @param opts.replace a map of strings to replace
154154
* @returns an array of files that were copied
155155
*/
156-
copy(
156+
copy: (
157157
from: string,
158158
to: string,
159159
opts?: {
160160
filter?(basename: string): boolean;
161161
replace?: Record<string, string>;
162162
}
163-
): string[];
163+
) => string[];
164164

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

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

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

207207
/**
208208
* 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.
@@ -214,11 +214,11 @@ declare module '@sveltejs/kit' {
214214
* @param value the cookie value
215215
* @param opts the options, passed directly to `cookie.serialize`. See documentation [here](https://github.com/jshttp/cookie#cookieserializename-value-options)
216216
*/
217-
set(
217+
set: (
218218
name: string,
219219
value: string,
220220
opts: import('cookie').CookieSerializeOptions & { path: string }
221-
): void;
221+
) => void;
222222

223223
/**
224224
* Deletes a cookie by setting its value to an empty string and setting the expiry date in the past.
@@ -227,7 +227,7 @@ declare module '@sveltejs/kit' {
227227
* @param name the name of the cookie
228228
* @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)
229229
*/
230-
delete(name: string, opts: import('cookie').CookieSerializeOptions & { path: string }): void;
230+
delete: (name: string, opts: import('cookie').CookieSerializeOptions & { path: string }) => void;
231231

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

250250
/**
@@ -927,7 +927,7 @@ declare module '@sveltejs/kit' {
927927
/**
928928
* Call this to prevent the navigation from starting.
929929
*/
930-
cancel(): void;
930+
cancel: () => void;
931931
}
932932

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

0 commit comments

Comments
 (0)