Skip to content
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
6 changes: 5 additions & 1 deletion packages/vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ const sentryUnplugin = sentryUnpluginFactory({
bundleSizeOptimizationsPlugin: viteBundleSizeOptimizationsPlugin,
});

export const sentryVitePlugin: (options?: Options) => VitePlugin[] = sentryUnplugin.vite;
export const sentryVitePlugin = (options?: Options): VitePlugin[] => {
const result = sentryUnplugin.vite(options);
// unplugin returns a single plugin instead of an array when only one plugin is created, so we normalize this here.
return Array.isArray(result) ? result : [result];
};

export type { Options as SentryVitePluginOptions } from "@sentry/bundler-plugin-core";
export { sentryCliBinaryExists } from "@sentry/bundler-plugin-core";
13 changes: 13 additions & 0 deletions packages/vite-plugin/test/public-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,17 @@ describe("sentryVitePlugin", () => {
])
);
});

it("returns an array of Vite pluginswhen unplugin returns a single plugin", () => {
const plugins = sentryVitePlugin({
authToken: "test-token",
org: "test-org",
project: "test-project",
disable: true, // This causes unplugin to return only the noop plugin
});

expect(Array.isArray(plugins)).toBe(true);
expect(plugins.length).toBeGreaterThanOrEqual(1);
expect(plugins[0]).toHaveProperty("name");
});
});
Loading