-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathindex.ts
More file actions
50 lines (41 loc) · 1.66 KB
/
index.ts
File metadata and controls
50 lines (41 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { SentryWebpackPluginOptions, sentryWebpackUnpluginFactory } from "./webpack4and5";
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore webpack is a peer dep
import * as webpack4or5 from "webpack";
const BannerPlugin = webpack4or5?.BannerPlugin || webpack4or5?.default?.BannerPlugin;
const DefinePlugin = webpack4or5?.DefinePlugin || webpack4or5?.default?.DefinePlugin;
// Detect webpack major version for telemetry (helps differentiate webpack 4 vs 5 usage)
function getWebpackMajorVersion(): string | undefined {
try {
const webpack = webpack4or5 as unknown as
| { version?: string; default?: { version?: string } }
| undefined;
const version = webpack?.version ?? webpack?.default?.version;
const webpackMajorVersion = version?.split(".")[0]; // "4" or "5"
return webpackMajorVersion;
} catch (error) {
return undefined;
}
}
const webpackMajorVersion = getWebpackMajorVersion();
const sentryUnplugin = sentryWebpackUnpluginFactory({
BannerPlugin,
DefinePlugin,
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const sentryWebpackPlugin: (options?: SentryWebpackPluginOptions) => any = (options) => {
const enhancedOptions: SentryWebpackPluginOptions = {
...options,
_metaOptions: {
...options?._metaOptions,
telemetry: {
...options?._metaOptions?.telemetry,
bundlerMajorVersion:
options?._metaOptions?.telemetry?.bundlerMajorVersion ?? webpackMajorVersion,
},
},
};
return sentryUnplugin.webpack(enhancedOptions);
};
export { sentryCliBinaryExists } from "@sentry/bundler-plugin-core";
export type { SentryWebpackPluginOptions };