Skip to content

Commit ea286f6

Browse files
committed
cleanup
1 parent 59c0e84 commit ea286f6

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

packages/svelte/src/config.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
1-
import { CompileOptions } from 'svelte/types/compiler';
21
import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
32

43
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';
165

176
const 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+
}

packages/svelte/src/types.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { CompileOptions } from 'svelte/types/compiler';
12
import { PreprocessorGroup } from 'svelte/types/compiler/preprocess';
23

34
// Adds an id property to the preprocessor object we can use to check for duplication
@@ -6,6 +7,22 @@ export interface SentryPreprocessorGroup extends PreprocessorGroup {
67
id?: string;
78
}
89

10+
/**
11+
* The object exported from `svelte.config.js`
12+
*/
13+
export type SvelteConfig = {
14+
[key: string]: unknown;
15+
preprocess?: PreprocessorGroup[] | PreprocessorGroup;
16+
compilerOptions?: CompileOptions;
17+
};
18+
19+
/**
20+
* Options users can provide to `withSentryConfig` to customize what Sentry adds too the Svelte config
21+
*/
22+
export type SentrySvelteConfigOptions = {
23+
componentTracking?: ComponentTrackingInitOptions;
24+
};
25+
926
// Alternatively, we could use a direct from svelte/compiler/preprocess
1027
// TODO: figure out what's better and roll with that
1128

0 commit comments

Comments
 (0)