@sveltejs/kit
Advanced tools
Comparing version 2.2.2 to 2.3.0
{ | ||
"name": "@sveltejs/kit", | ||
"version": "2.2.2", | ||
"version": "2.3.0", | ||
"description": "The fastest way to build Svelte apps", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -96,2 +96,3 @@ import fs from 'node:fs'; | ||
validated.kit.files.hooks.server = path.resolve(cwd, validated.kit.files.hooks.server); | ||
validated.kit.files.hooks.universal = path.resolve(cwd, validated.kit.files.hooks.universal); | ||
} else { | ||
@@ -98,0 +99,0 @@ // @ts-expect-error |
@@ -126,3 +126,4 @@ import { join } from 'node:path'; | ||
client: string(join('src', 'hooks.client')), | ||
server: string(join('src', 'hooks.server')) | ||
server: string(join('src', 'hooks.server')), | ||
universal: string(join('src', 'hooks')) | ||
}), | ||
@@ -129,0 +130,0 @@ lib: string(join('src', 'lib')), |
@@ -111,3 +111,4 @@ import path from 'node:path'; | ||
const hooks_file = resolve_entry(kit.files.hooks.client); | ||
const client_hooks_file = resolve_entry(kit.files.hooks.client); | ||
const universal_hooks_file = resolve_entry(kit.files.hooks.universal); | ||
@@ -129,3 +130,12 @@ const typo = resolve_entry('src/+hooks.client'); | ||
dedent` | ||
${hooks_file ? `import * as client_hooks from '${relative_path(output, hooks_file)}';` : ''} | ||
${ | ||
client_hooks_file | ||
? `import * as client_hooks from '${relative_path(output, client_hooks_file)}';` | ||
: '' | ||
} | ||
${ | ||
universal_hooks_file | ||
? `import * as universal_hooks from '${relative_path(output, universal_hooks_file)}';` | ||
: '' | ||
} | ||
@@ -144,4 +154,6 @@ export { matchers } from './matchers.js'; | ||
handleError: ${ | ||
hooks_file ? 'client_hooks.handleError || ' : '' | ||
client_hooks_file ? 'client_hooks.handleError || ' : '' | ||
}(({ error }) => { console.error(error) }), | ||
reroute: ${universal_hooks_file ? 'universal_hooks.reroute || ' : ''}(() => {}) | ||
}; | ||
@@ -148,0 +160,0 @@ |
@@ -12,3 +12,4 @@ import path from 'node:path'; | ||
* @param {{ | ||
* hooks: string | null; | ||
* server_hooks: string | null; | ||
* universal_hooks: string | null; | ||
* config: import('types').ValidatedConfig; | ||
@@ -23,3 +24,4 @@ * has_service_worker: boolean; | ||
config, | ||
hooks, | ||
server_hooks, | ||
universal_hooks, | ||
has_service_worker, | ||
@@ -64,4 +66,7 @@ runtime_directory, | ||
export function get_hooks() { | ||
return ${hooks ? `import(${s(hooks)})` : '{}'}; | ||
export async function get_hooks() { | ||
return { | ||
${server_hooks ? `...(await import(${s(server_hooks)})),` : ''} | ||
${universal_hooks ? `...(await import(${s(universal_hooks)})),` : ''} | ||
}; | ||
} | ||
@@ -82,3 +87,4 @@ | ||
export function write_server(config, output) { | ||
const hooks_file = resolve_entry(config.kit.files.hooks.server); | ||
const server_hooks_file = resolve_entry(config.kit.files.hooks.server); | ||
const universal_hooks_file = resolve_entry(config.kit.files.hooks.universal); | ||
@@ -106,3 +112,4 @@ const typo = resolve_entry('src/+hooks.server'); | ||
config, | ||
hooks: hooks_file ? relative(hooks_file) : null, | ||
server_hooks: server_hooks_file ? relative(server_hooks_file) : null, | ||
universal_hooks: universal_hooks_file ? relative(universal_hooks_file) : null, | ||
has_service_worker: | ||
@@ -109,0 +116,0 @@ config.kit.serviceWorker.register && !!resolve_entry(config.kit.files.serviceWorker), |
@@ -397,2 +397,8 @@ import 'svelte'; // pick up `declare module "*.svelte"` | ||
server?: string; | ||
/** | ||
* The location of your universal [hooks](https://kit.svelte.dev/docs/hooks). | ||
* @default "src/hooks" | ||
* @since 2.3.0 | ||
*/ | ||
universal?: string; | ||
}; | ||
@@ -688,2 +694,8 @@ /** | ||
/** | ||
* The [`reroute`](https://kit.svelte.dev/docs/hooks#universal-hooks-reroute) hook allows you to modify the URL before it is used to determine which route to render. | ||
* @since 2.3.0 | ||
*/ | ||
export type Reroute = (event: { url: URL }) => void | string; | ||
/** | ||
* The generic form of `PageLoad` and `LayoutLoad`. You should import those from `./$types` (see [generated types](https://kit.svelte.dev/docs/types#generated-types)) | ||
@@ -690,0 +702,0 @@ * rather than using `Load` directly. |
declare module '__SERVER__/internal.js' { | ||
export const options: import('types').SSROptions; | ||
export const get_hooks: () => Promise<{ | ||
handle?: import('@sveltejs/kit').Handle; | ||
handleError?: import('@sveltejs/kit').HandleServerError; | ||
handleFetch?: import('@sveltejs/kit').HandleFetch; | ||
}>; | ||
export const get_hooks: () => Promise<Partial<import('types').ServerHooks>>; | ||
} |
@@ -65,3 +65,4 @@ import { respond } from './respond.js'; | ||
handleError: module.handleError || (({ error }) => console.error(error)), | ||
handleFetch: module.handleFetch || (({ request, fetch }) => fetch(request)) | ||
handleFetch: module.handleFetch || (({ request, fetch }) => fetch(request)), | ||
reroute: module.reroute || (() => {}) | ||
}; | ||
@@ -75,3 +76,4 @@ } catch (error) { | ||
handleError: ({ error }) => console.error(error), | ||
handleFetch: ({ request, fetch }) => fetch(request) | ||
handleFetch: ({ request, fetch }) => fetch(request), | ||
reroute: () => {} | ||
}; | ||
@@ -78,0 +80,0 @@ } else { |
@@ -82,5 +82,15 @@ import { DEV } from 'esm-env'; | ||
// reroute could alter the given URL, so we pass a copy | ||
let rerouted_path; | ||
try { | ||
rerouted_path = options.hooks.reroute({ url: new URL(url) }) ?? url.pathname; | ||
} catch (e) { | ||
return text('Internal Server Error', { | ||
status: 500 | ||
}); | ||
} | ||
let decoded; | ||
try { | ||
decoded = decode_pathname(url.pathname); | ||
decoded = decode_pathname(rerouted_path); | ||
} catch { | ||
@@ -87,0 +97,0 @@ return text('Malformed URI', { status: 400 }); |
@@ -15,3 +15,4 @@ import { SvelteComponent } from 'svelte'; | ||
Actions, | ||
HandleClientError | ||
HandleClientError, | ||
Reroute | ||
} from '@sveltejs/kit'; | ||
@@ -103,2 +104,3 @@ import { | ||
handleError: HandleServerError; | ||
reroute: Reroute; | ||
} | ||
@@ -108,2 +110,3 @@ | ||
handleError: HandleClientError; | ||
reroute: Reroute; | ||
} | ||
@@ -110,0 +113,0 @@ |
// generated during release, do not modify | ||
/** @type {string} */ | ||
export const VERSION = '2.2.2'; | ||
export const VERSION = '2.3.0'; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
707515
20676