Skip to content

Commit 87b33e2

Browse files
authored
feat(sveltekit): Remove SDK initialization via dedicated files (#7791)
This PR removes the `injectInitPlugin` which means that initialization of the SDK via dedicated files is no longer supported. To initialized the SDK, the `hooks.(client|server).js` should be used, as already documented in the `README`.
1 parent d099af8 commit 87b33e2

File tree

5 files changed

+4
-276
lines changed

5 files changed

+4
-276
lines changed

packages/sveltekit/src/vite/injectInitPlugin.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

packages/sveltekit/src/vite/sentrySvelteKitPlugin.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import type { Plugin, UserConfig } from 'vite';
22

3-
import { injectSentryInitPlugin } from './injectInitPlugin';
4-
import { hasSentryInitFiles } from './utils';
5-
63
/**
74
* Vite Plugin for the Sentry SvelteKit SDK, taking care of:
85
*
@@ -23,31 +20,13 @@ export function sentrySvelteKitPlugin(): Plugin {
2320
}
2421

2522
function addSentryConfig(originalConfig: UserConfig): UserConfig {
26-
const sentryPlugins = [];
27-
28-
const shouldAddInjectInitPlugin = hasSentryInitFiles();
23+
const sentryPlugins: Plugin[] = [];
2924

30-
if (shouldAddInjectInitPlugin) {
31-
sentryPlugins.push(injectSentryInitPlugin);
32-
}
25+
// TODO: Add sentry vite plugin here
3326

34-
const config = {
27+
const config: UserConfig = {
3528
...originalConfig,
36-
plugins: originalConfig.plugins ? [...sentryPlugins, ...originalConfig.plugins] : [...sentryPlugins],
37-
};
38-
39-
const mergedDevServerFileSystemConfig: UserConfig['server'] = shouldAddInjectInitPlugin
40-
? {
41-
fs: {
42-
...(config.server && config.server.fs),
43-
allow: [...((config.server && config.server.fs && config.server.fs.allow) || []), '.'],
44-
},
45-
}
46-
: {};
47-
48-
config.server = {
49-
...config.server,
50-
...mergedDevServerFileSystemConfig,
29+
plugins: [...sentryPlugins, ...(originalConfig.plugins || [])],
5130
};
5231

5332
return config;

packages/sveltekit/src/vite/utils.ts

Lines changed: 0 additions & 28 deletions
This file was deleted.

packages/sveltekit/test/vite/injectInitPlugin.test.ts

Lines changed: 0 additions & 65 deletions
This file was deleted.
Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import { vi } from 'vitest';
2-
31
import { sentrySvelteKitPlugin } from './../../src/vite/sentrySvelteKitPlugin';
4-
import * as utils from './../../src/vite/utils';
52

63
describe('sentrySvelteKitPlugin', () => {
74
it('returns a Vite plugin with name, enforce, and config hook', () => {
@@ -12,97 +9,4 @@ describe('sentrySvelteKitPlugin', () => {
129
expect(plugin.name).toEqual('sentry-sveltekit');
1310
expect(plugin.enforce).toEqual('pre');
1411
});
15-
16-
describe('config hook', () => {
17-
const hasSentryInitFilesSpy = vi.spyOn(utils, 'hasSentryInitFiles').mockReturnValue(true);
18-
19-
beforeEach(() => {
20-
hasSentryInitFilesSpy.mockClear();
21-
});
22-
23-
it('adds the injectInitPlugin and adjusts the dev server config if init config files exist', () => {
24-
const plugin = sentrySvelteKitPlugin();
25-
const originalConfig = {};
26-
27-
// @ts-ignore - plugin.config exists and is callable
28-
const modifiedConfig = plugin.config(originalConfig);
29-
30-
expect(modifiedConfig).toEqual({
31-
plugins: [
32-
{
33-
enforce: 'pre',
34-
name: 'sentry-init-injection-plugin',
35-
transform: expect.any(Function),
36-
},
37-
],
38-
server: {
39-
fs: {
40-
allow: ['.'],
41-
},
42-
},
43-
});
44-
expect(hasSentryInitFilesSpy).toHaveBeenCalledTimes(1);
45-
});
46-
47-
it('merges user-defined options with Sentry-specifc ones', () => {
48-
const plugin = sentrySvelteKitPlugin();
49-
const originalConfig = {
50-
test: {
51-
include: ['src/**/*.{test,spec}.{js,ts}'],
52-
},
53-
build: {
54-
sourcemap: 'css',
55-
},
56-
plugins: [{ name: 'some plugin' }],
57-
server: {
58-
fs: {
59-
allow: ['./build/**/*.{js}'],
60-
},
61-
},
62-
};
63-
64-
// @ts-ignore - plugin.config exists and is callable
65-
const modifiedConfig = plugin.config(originalConfig);
66-
67-
expect(modifiedConfig).toEqual({
68-
test: {
69-
include: ['src/**/*.{test,spec}.{js,ts}'],
70-
},
71-
build: {
72-
sourcemap: 'css',
73-
},
74-
plugins: [
75-
{
76-
enforce: 'pre',
77-
name: 'sentry-init-injection-plugin',
78-
transform: expect.any(Function),
79-
},
80-
{ name: 'some plugin' },
81-
],
82-
server: {
83-
fs: {
84-
allow: ['./build/**/*.{js}', '.'],
85-
},
86-
},
87-
});
88-
expect(hasSentryInitFilesSpy).toHaveBeenCalledTimes(1);
89-
});
90-
91-
it("doesn't add the injectInitPlugin if init config files don't exist", () => {
92-
hasSentryInitFilesSpy.mockReturnValue(false);
93-
const plugin = sentrySvelteKitPlugin();
94-
const originalConfig = {
95-
plugins: [{ name: 'some plugin' }],
96-
};
97-
98-
// @ts-ignore - plugin.config exists and is callable
99-
const modifiedConfig = plugin.config(originalConfig);
100-
101-
expect(modifiedConfig).toEqual({
102-
plugins: [{ name: 'some plugin' }],
103-
server: {},
104-
});
105-
expect(hasSentryInitFilesSpy).toHaveBeenCalledTimes(1);
106-
});
107-
});
10812
});

0 commit comments

Comments
 (0)