Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sveltekit): Remove SDK initialization via dedicated files #7791

Merged
merged 1 commit into from
Apr 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
});
});