1- import { CompileOptions } from 'svelte/types/compiler' ;
21import { PreprocessorGroup } from 'svelte/types/compiler/preprocess' ;
32
43import { componentTrackingPreprocessor , defaultComponentTrackingOptions } from './preprocessors' ;
5- import { ComponentTrackingInitOptions , SentryPreprocessorGroup } from './types' ;
6-
7- export type SvelteConfig = {
8- [ key : string ] : unknown ;
9- preprocess ?: PreprocessorGroup [ ] | PreprocessorGroup ;
10- compilerOptions ?: CompileOptions ;
11- } ;
12-
13- export type SentrySvelteConfigOptions = {
14- componentTracking ?: ComponentTrackingInitOptions ;
15- } ;
4+ import { SentryPreprocessorGroup , SentrySvelteConfigOptions , SvelteConfig } from './types' ;
165
176const DEFAULT_SENTRY_OPTIONS : SentrySvelteConfigOptions = {
187 componentTracking : defaultComponentTrackingOptions ,
@@ -36,19 +25,16 @@ export function withSentryConfig(
3625 } ;
3726
3827 const originalPreprocessors = getOriginalPreprocessorArray ( originalConfig ) ;
39- const sentryPreprocessors : SentryPreprocessorGroup [ ] = [ ] ;
28+ const allSentryPreprocessors : SentryPreprocessorGroup [ ] = [ ] ;
4029
4130 const shouldTrackComponents = mergedOptions . componentTracking && mergedOptions . componentTracking . trackComponents ;
4231 if ( shouldTrackComponents ) {
4332 // TODO(v8): Remove eslint rule
4433 // eslint-disable-next-line deprecation/deprecation
45- sentryPreprocessors . push ( componentTrackingPreprocessor ( mergedOptions . componentTracking ) ) ;
34+ allSentryPreprocessors . push ( componentTrackingPreprocessor ( mergedOptions . componentTracking ) ) ;
4635 }
4736
48- const dedupedSentryPreprocessors = sentryPreprocessors . filter (
49- sentryPreproc =>
50- originalPreprocessors . find ( p => ( p as SentryPreprocessorGroup ) . id === sentryPreproc . id ) === undefined ,
51- ) ;
37+ const dedupedSentryPreprocessors = dedupePreprocessors ( allSentryPreprocessors , originalPreprocessors ) ;
5238
5339 const mergedPreprocessors = [ ...dedupedSentryPreprocessors , ...originalPreprocessors ] ;
5440
@@ -60,7 +46,7 @@ export function withSentryConfig(
6046
6147/**
6248 * Standardizes the different ways the user-provided preprocessor option can be specified.
63- * Users can specify an array of preprocessors, one single one or nothing at all .
49+ * Users can specify an array of preprocessors, a single one or no preprocessor .
6450 *
6551 * @param originalConfig the user-provided svelte config oject
6652 * @return an array of preprocessors or an empty array if no preprocessors were specified
@@ -74,3 +60,13 @@ function getOriginalPreprocessorArray(originalConfig: SvelteConfig): Preprocesso
7460 }
7561 return [ ] ;
7662}
63+
64+ function dedupePreprocessors (
65+ sentryPreprocessors : SentryPreprocessorGroup [ ] ,
66+ originalPreprocessors : PreprocessorGroup [ ] ,
67+ ) : PreprocessorGroup [ ] {
68+ return sentryPreprocessors . filter (
69+ sentryPreproc =>
70+ originalPreprocessors . find ( p => ( p as SentryPreprocessorGroup ) . id === sentryPreproc . id ) === undefined ,
71+ ) ;
72+ }
0 commit comments