Skip to content

Commit 0ed8414

Browse files
authored
fix(vite): Ensure sentryVitePlugin always returns an array of plugins (#832)
Normalizes the vite plugin to always return an array of plugins.
1 parent 4728fc1 commit 0ed8414

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/vite-plugin/src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ const sentryUnplugin = sentryUnpluginFactory({
7373
bundleSizeOptimizationsPlugin: viteBundleSizeOptimizationsPlugin,
7474
});
7575

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

7882
export type { Options as SentryVitePluginOptions } from "@sentry/bundler-plugin-core";
7983
export { sentryCliBinaryExists } from "@sentry/bundler-plugin-core";

packages/vite-plugin/test/public-api.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,17 @@ describe("sentryVitePlugin", () => {
3232
])
3333
);
3434
});
35+
36+
it("returns an array of Vite pluginswhen unplugin returns a single plugin", () => {
37+
const plugins = sentryVitePlugin({
38+
authToken: "test-token",
39+
org: "test-org",
40+
project: "test-project",
41+
disable: true, // This causes unplugin to return only the noop plugin
42+
});
43+
44+
expect(Array.isArray(plugins)).toBe(true);
45+
expect(plugins.length).toBeGreaterThanOrEqual(1);
46+
expect(plugins[0]).toHaveProperty("name");
47+
});
3548
});

0 commit comments

Comments
 (0)