@@ -4,12 +4,31 @@ import * as path from 'path';
44import * as url from 'url' ;
55import type { SupportedSvelteKitAdapters } from './detectAdapter' ;
66
7+ export type SvelteKitTracingConfig = {
8+ tracing ?: {
9+ server : boolean ;
10+ } ;
11+ instrumentation ?: {
12+ server : boolean ;
13+ } ;
14+ } ;
15+
16+ /**
17+ * Experimental tracing and instrumentation config is available
18+ * @since 2.31.0
19+ */
20+ type BackwardsForwardsCompatibleKitConfig = Config [ 'kit' ] & { experimental ?: SvelteKitTracingConfig } ;
21+
22+ interface BackwardsForwardsCompatibleSvelteConfig extends Config {
23+ kit ?: BackwardsForwardsCompatibleKitConfig ;
24+ }
25+
726/**
827 * Imports the svelte.config.js file and returns the config object.
928 * The sveltekit plugins import the config in the same way.
1029 * See: https://github.com/sveltejs/kit/blob/master/packages/kit/src/core/config/index.js#L63
1130 */
12- export async function loadSvelteConfig ( ) : Promise < Config > {
31+ export async function loadSvelteConfig ( ) : Promise < BackwardsForwardsCompatibleSvelteConfig > {
1332 // This can only be .js (see https://github.com/sveltejs/kit/pull/4031#issuecomment-1049475388)
1433 const SVELTE_CONFIG_FILE = 'svelte.config.js' ;
1534
@@ -23,7 +42,7 @@ export async function loadSvelteConfig(): Promise<Config> {
2342 const svelteConfigModule = await import ( `${ url . pathToFileURL ( configFile ) . href } ` ) ;
2443
2544 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
26- return ( svelteConfigModule ?. default as Config ) || { } ;
45+ return ( svelteConfigModule ?. default as BackwardsForwardsCompatibleSvelteConfig ) || { } ;
2746 } catch ( e ) {
2847 // eslint-disable-next-line no-console
2948 console . warn ( "[Source Maps Plugin] Couldn't load svelte.config.js:" ) ;
@@ -110,3 +129,21 @@ async function getNodeAdapterOutputDir(svelteConfig: Config): Promise<string> {
110129
111130 return outputDir ;
112131}
132+
133+ /**
134+ * Returns the Sveltekit tracing config users can enable in svelte.config.js.
135+ * Available in Kit @since 2.31.0
136+ */
137+ export function getTracingConfig (
138+ svelteConfig : BackwardsForwardsCompatibleSvelteConfig ,
139+ ) : BackwardsForwardsCompatibleKitConfig [ 'experimental' ] {
140+ const experimentalConfig = svelteConfig . kit ?. experimental ;
141+ return {
142+ instrumentation : {
143+ server : experimentalConfig ?. instrumentation ?. server ?? false ,
144+ } ,
145+ tracing : {
146+ server : experimentalConfig ?. tracing ?. server ?? false ,
147+ } ,
148+ } ;
149+ }
0 commit comments