Skip to content

Commit

Permalink
feat(sveltekit): Remove SDK initialization via dedicated files (#7791)
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
Lms24 authored Apr 7, 2023
1 parent d099af8 commit 87b33e2
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 276 deletions.
62 changes: 0 additions & 62 deletions packages/sveltekit/src/vite/injectInitPlugin.ts

This file was deleted.

29 changes: 4 additions & 25 deletions packages/sveltekit/src/vite/sentrySvelteKitPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import type { Plugin, UserConfig } from 'vite';

import { injectSentryInitPlugin } from './injectInitPlugin';
import { hasSentryInitFiles } from './utils';

/**
* Vite Plugin for the Sentry SvelteKit SDK, taking care of:
*
Expand All @@ -23,31 +20,13 @@ export function sentrySvelteKitPlugin(): Plugin {
}

function addSentryConfig(originalConfig: UserConfig): UserConfig {
const sentryPlugins = [];

const shouldAddInjectInitPlugin = hasSentryInitFiles();
const sentryPlugins: Plugin[] = [];

if (shouldAddInjectInitPlugin) {
sentryPlugins.push(injectSentryInitPlugin);
}
// TODO: Add sentry vite plugin here

const config = {
const config: UserConfig = {
...originalConfig,
plugins: originalConfig.plugins ? [...sentryPlugins, ...originalConfig.plugins] : [...sentryPlugins],
};

const mergedDevServerFileSystemConfig: UserConfig['server'] = shouldAddInjectInitPlugin
? {
fs: {
...(config.server && config.server.fs),
allow: [...((config.server && config.server.fs && config.server.fs.allow) || []), '.'],
},
}
: {};

config.server = {
...config.server,
...mergedDevServerFileSystemConfig,
plugins: [...sentryPlugins, ...(originalConfig.plugins || [])],
};

return config;
Expand Down
28 changes: 0 additions & 28 deletions packages/sveltekit/src/vite/utils.ts

This file was deleted.

65 changes: 0 additions & 65 deletions packages/sveltekit/test/vite/injectInitPlugin.test.ts

This file was deleted.

96 changes: 0 additions & 96 deletions packages/sveltekit/test/vite/sentrySvelteKitPlugin.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { vi } from 'vitest';

import { sentrySvelteKitPlugin } from './../../src/vite/sentrySvelteKitPlugin';
import * as utils from './../../src/vite/utils';

describe('sentrySvelteKitPlugin', () => {
it('returns a Vite plugin with name, enforce, and config hook', () => {
Expand All @@ -12,97 +9,4 @@ describe('sentrySvelteKitPlugin', () => {
expect(plugin.name).toEqual('sentry-sveltekit');
expect(plugin.enforce).toEqual('pre');
});

describe('config hook', () => {
const hasSentryInitFilesSpy = vi.spyOn(utils, 'hasSentryInitFiles').mockReturnValue(true);

beforeEach(() => {
hasSentryInitFilesSpy.mockClear();
});

it('adds the injectInitPlugin and adjusts the dev server config if init config files exist', () => {
const plugin = sentrySvelteKitPlugin();
const originalConfig = {};

// @ts-ignore - plugin.config exists and is callable
const modifiedConfig = plugin.config(originalConfig);

expect(modifiedConfig).toEqual({
plugins: [
{
enforce: 'pre',
name: 'sentry-init-injection-plugin',
transform: expect.any(Function),
},
],
server: {
fs: {
allow: ['.'],
},
},
});
expect(hasSentryInitFilesSpy).toHaveBeenCalledTimes(1);
});

it('merges user-defined options with Sentry-specifc ones', () => {
const plugin = sentrySvelteKitPlugin();
const originalConfig = {
test: {
include: ['src/**/*.{test,spec}.{js,ts}'],
},
build: {
sourcemap: 'css',
},
plugins: [{ name: 'some plugin' }],
server: {
fs: {
allow: ['./build/**/*.{js}'],
},
},
};

// @ts-ignore - plugin.config exists and is callable
const modifiedConfig = plugin.config(originalConfig);

expect(modifiedConfig).toEqual({
test: {
include: ['src/**/*.{test,spec}.{js,ts}'],
},
build: {
sourcemap: 'css',
},
plugins: [
{
enforce: 'pre',
name: 'sentry-init-injection-plugin',
transform: expect.any(Function),
},
{ name: 'some plugin' },
],
server: {
fs: {
allow: ['./build/**/*.{js}', '.'],
},
},
});
expect(hasSentryInitFilesSpy).toHaveBeenCalledTimes(1);
});

it("doesn't add the injectInitPlugin if init config files don't exist", () => {
hasSentryInitFilesSpy.mockReturnValue(false);
const plugin = sentrySvelteKitPlugin();
const originalConfig = {
plugins: [{ name: 'some plugin' }],
};

// @ts-ignore - plugin.config exists and is callable
const modifiedConfig = plugin.config(originalConfig);

expect(modifiedConfig).toEqual({
plugins: [{ name: 'some plugin' }],
server: {},
});
expect(hasSentryInitFilesSpy).toHaveBeenCalledTimes(1);
});
});
});

0 comments on commit 87b33e2

Please sign in to comment.