1
- import { CompileOptions } from 'svelte/types/compiler' ;
2
1
import { PreprocessorGroup } from 'svelte/types/compiler/preprocess' ;
3
2
4
3
import { 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' ;
16
5
17
6
const DEFAULT_SENTRY_OPTIONS : SentrySvelteConfigOptions = {
18
7
componentTracking : defaultComponentTrackingOptions ,
@@ -36,19 +25,16 @@ export function withSentryConfig(
36
25
} ;
37
26
38
27
const originalPreprocessors = getOriginalPreprocessorArray ( originalConfig ) ;
39
- const sentryPreprocessors : SentryPreprocessorGroup [ ] = [ ] ;
28
+ const allSentryPreprocessors : SentryPreprocessorGroup [ ] = [ ] ;
40
29
41
30
const shouldTrackComponents = mergedOptions . componentTracking && mergedOptions . componentTracking . trackComponents ;
42
31
if ( shouldTrackComponents ) {
43
32
// TODO(v8): Remove eslint rule
44
33
// eslint-disable-next-line deprecation/deprecation
45
- sentryPreprocessors . push ( componentTrackingPreprocessor ( mergedOptions . componentTracking ) ) ;
34
+ allSentryPreprocessors . push ( componentTrackingPreprocessor ( mergedOptions . componentTracking ) ) ;
46
35
}
47
36
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 ) ;
52
38
53
39
const mergedPreprocessors = [ ...dedupedSentryPreprocessors , ...originalPreprocessors ] ;
54
40
@@ -60,7 +46,7 @@ export function withSentryConfig(
60
46
61
47
/**
62
48
* 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 .
64
50
*
65
51
* @param originalConfig the user-provided svelte config oject
66
52
* @return an array of preprocessors or an empty array if no preprocessors were specified
@@ -74,3 +60,13 @@ function getOriginalPreprocessorArray(originalConfig: SvelteConfig): Preprocesso
74
60
}
75
61
return [ ] ;
76
62
}
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