diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 38b6ab085ab1..b71bac45b396 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: cache: pnpm - run: pnpm install --frozen-lockfile - run: pnpm run lint - - run: cd packages/kit && pnpm prepublishOnly && { [ "`git status --porcelain=v1`" == "" ] || echo "Generated types have changed — please run prepublishOnly locally and commit the changes after you have reviewed them"; } + - run: cd packages/kit && pnpm prepublishOnly && { [ "`git status --porcelain=v1`" == "" ] || (echo "Generated types have changed — please run prepublishOnly locally and commit the changes after you have reviewed them" && exit 1); } - run: pnpm run check Tests: runs-on: ${{ matrix.os }} diff --git a/packages/kit/src/exports/vite/index.js b/packages/kit/src/exports/vite/index.js index b430f0235217..acd5b88f2b09 100644 --- a/packages/kit/src/exports/vite/index.js +++ b/packages/kit/src/exports/vite/index.js @@ -30,10 +30,6 @@ import sirv from 'sirv'; export { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; -/** @typedef {import('http').IncomingMessage} Req */ -/** @typedef {import('http').ServerResponse} Res */ -/** @typedef {(req: Req, res: Res, next: () => void) => void} Handler */ - const cwd = process.cwd(); /** @type {import('./types.js').EnforcedConfig} */ @@ -940,8 +936,8 @@ const create_service_worker_module = (config) => dedent` /** * @param {string} scope - * @param {Handler} handler - * @returns {Handler} + * @param {(req: import('http').IncomingMessage, res: import('http').ServerResponse, next: () => void) => void} handler + * @returns {(req: import('http').IncomingMessage, res: import('http').ServerResponse, next: () => void) => void} */ function scoped(scope, handler) { if (scope === '') return handler; diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 88884e1a16ab..01771fe5149c 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -2,7 +2,7 @@ /// declare module '@sveltejs/kit' { - import type { CompileOptions } from 'svelte/types/compiler/interfaces'; + import type { CompileOptions } from 'svelte/compiler'; import type { PluginOptions } from '@sveltejs/vite-plugin-svelte'; /** * [Adapters](https://kit.svelte.dev/docs/adapters) are responsible for taking the production build and turning it into something that can be deployed to a platform of your choosing. @@ -19,20 +19,11 @@ declare module '@sveltejs/kit' { adapt(builder: Builder): MaybePromise; } - type AwaitedPropertiesUnion | void> = input extends void + export type LoadProperties | void> = input extends void ? undefined // needs to be undefined, because void will break intellisense : input extends Record - ? { - [key in keyof input]: Awaited; - } - : {} extends input // handles the any case - ? input - : unknown; - - export type AwaitedProperties | void> = - AwaitedPropertiesUnion extends Record - ? OptionalUnion> - : AwaitedPropertiesUnion; + ? input + : unknown; export type AwaitedActions any>> = OptionalUnion< { @@ -192,34 +183,42 @@ declare module '@sveltejs/kit' { * * The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP. The `sameSite` option defaults to `lax`. * - * By default, the `path` of a cookie is the 'directory' of the current pathname. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app. + * You must specify a `path` for the cookie. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children * @param name the name of the cookie * @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(name: string, value: string, opts?: import('cookie').CookieSerializeOptions): void; + set( + name: string, + value: string, + opts: import('cookie').CookieSerializeOptions & { path: string } + ): void; /** * Deletes a cookie by setting its value to an empty string and setting the expiry date in the past. * - * By default, the `path` of a cookie is the 'directory' of the current pathname. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app. + * You must specify a `path` for the cookie. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children * @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): 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. * * The `httpOnly` and `secure` options are `true` by default (except on http://localhost, where `secure` is `false`), and must be explicitly disabled if you want cookies to be readable by client-side JavaScript and/or transmitted over HTTP. The `sameSite` option defaults to `lax`. * - * By default, the `path` of a cookie is the current pathname. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app. + * You must specify a `path` for the cookie. In most cases you should explicitly set `path: '/'` to make the cookie available throughout your app. You can use relative paths, or set `path: ''` to make the cookie only available on the current path and its children * * @param name the name of the cookie * @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(name: string, value: string, opts?: import('cookie').CookieSerializeOptions): string; + serialize( + name: string, + value: string, + opts: import('cookie').CookieSerializeOptions & { path: string } + ): string; } export interface KitConfig { @@ -323,16 +322,6 @@ declare module '@sveltejs/kit' { */ checkOrigin?: boolean; }; - /** - * Here be dragons. Enable at your peril. - */ - dangerZone?: { - /** - * Automatically add server-side `fetch`ed URLs to the `dependencies` map of `load` functions. This will expose secrets - * to the client if your URL contains them. - */ - trackServerFetches?: boolean; - }; /** * Whether or not the app is embedded inside a larger app. If `true`, SvelteKit will add its event listeners related to navigation etc on the parent of `%sveltekit.body%` instead of `window`, and will pass `params` from the server rather than inferring them from `location.pathname`. * @default false @@ -453,15 +442,18 @@ declare module '@sveltejs/kit' { */ base?: '' | `/${string}`; /** - * Whether to use relative asset paths. By default, if `paths.assets` is not external, SvelteKit will replace `%sveltekit.assets%` with a relative path and use relative paths to reference build artifacts, but `base` and `assets` imported from `$app/paths` will be as specified in your config. + * Whether to use relative asset paths. * - * If `true`, `base` and `assets` imported from `$app/paths` will be replaced with relative asset paths during server-side rendering, resulting in portable HTML. + * If `true`, `base` and `assets` imported from `$app/paths` will be replaced with relative asset paths during server-side rendering, resulting in more portable HTML. * If `false`, `%sveltekit.assets%` and references to build artifacts will always be root-relative paths, unless `paths.assets` is an external URL * * If your app uses a `` element, you should set this to `false`, otherwise asset URLs will incorrectly be resolved against the `` URL rather than the current page. - * @default undefined + * + * In 1.0, `undefined` was a valid value, which was set by default. In that case, if `paths.assets` was not external, SvelteKit would replace `%sveltekit.assets%` with a relative path and use relative paths to reference build artifacts, but `base` and `assets` imported from `$app/paths` would be as specified in your config. + * + * @default true */ - relative?: boolean | undefined; + relative?: boolean; }; /** * See [Prerendering](https://kit.svelte.dev/docs/page-options#prerender). @@ -759,7 +751,7 @@ declare module '@sveltejs/kit' { * * ``` */ - depends(...deps: string[]): void; + depends(...deps: Array<`${string}:${string}`>): void; } export interface NavigationEvent< @@ -826,7 +818,7 @@ declare module '@sveltejs/kit' { /** * The type of navigation: * - `form`: The user submitted a `
` - * - `leave`: The user is leaving the app by closing the tab or using the back/forward buttons to go to a different document + * - `leave`: The app is being left either because the tab is being closed or a navigation to a different document is occurring * - `link`: Navigation was triggered by a link click * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect * - `popstate`: Navigation was triggered by back/forward navigation @@ -1691,6 +1683,7 @@ declare module '@sveltejs/kit' { type ValidatedConfig = RecursiveRequired; export function error(status: number, body: App.Error): HttpError_1; + export function error(status: number, body?: { message: string; } extends App.Error ? App.Error | string | undefined : never): HttpError_1; @@ -1821,10 +1814,7 @@ declare module '@sveltejs/kit/node/polyfills' { /** * Make various web APIs available as globals: * - `crypto` - * - `fetch` (only in node < 18.11) - * - `Headers` (only in node < 18.11) - * - `Request` (only in node < 18.11) - * - `Response` (only in node < 18.11) + * - `File` */ export function installPolyfills(): void; } @@ -1911,8 +1901,6 @@ declare module '$app/navigation' { * * @param url Where to navigate to. Note that if you've set [`config.kit.paths.base`](https://kit.svelte.dev/docs/configuration#paths) and the URL is root-relative, you need to prepend the base path if you want to navigate within the app. * @param {Object} opts Options related to the navigation - * @param invalidateAll If `true`, all `load` functions of the page will be rerun. See https://kit.svelte.dev/docs/load#rerunning-load-functions for more info on invalidation. - * @param opts.state The state of the new/updated history entry * */ export const goto: (url: string | URL, opts?: { replaceState?: boolean;