Skip to content

Commit 2edffa5

Browse files
authored
feat: webpack no longer uses unplugin (#870)
1 parent 4bda281 commit 2edffa5

File tree

7 files changed

+308
-138
lines changed

7 files changed

+308
-138
lines changed

packages/bundler-plugin-core/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,3 +495,5 @@ export type { Logger } from "./logger";
495495
export type { Options, SentrySDKBuildFlags } from "./types";
496496
export { CodeInjection, replaceBooleanFlagsInCode, stringToUUID } from "./utils";
497497
export { createSentryBuildPluginManager } from "./build-plugin-manager";
498+
export { generateGlobalInjectorCode, generateModuleMetadataInjectorCode } from "./utils";
499+
export { createDebugIdUploadFunction } from "./debug-id-upload";

packages/webpack-plugin/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
},
5555
"dependencies": {
5656
"@sentry/bundler-plugin-core": "4.9.1",
57-
"unplugin": "1.0.1",
5857
"uuid": "^9.0.0"
5958
},
6059
"devDependencies": {

packages/webpack-plugin/rollup.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import babel from "@rollup/plugin-babel";
33
import packageJson from "./package.json";
44
import modulePackage from "module";
55

6-
const input = ["src/index.ts", "src/webpack5.ts"];
6+
const input = ["src/index.ts", "src/webpack5.ts", "src/component-annotation-transform.ts"];
77

88
const extensions = [".ts"];
99

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Webpack loader for component annotation transform
2+
// Based on unplugin v1.0.1 transform loader pattern
3+
4+
export default async function transform(
5+
this: {
6+
async: () => (err: Error | null, content?: string, sourceMap?: unknown) => void;
7+
resourcePath: string;
8+
query: {
9+
transform?: (
10+
code: string,
11+
id: string
12+
) => Promise<{ code: string; map?: unknown } | null | undefined | string>;
13+
};
14+
},
15+
source: string,
16+
map: unknown
17+
): Promise<void> {
18+
const callback = this.async();
19+
const { transform: transformFn } = this.query;
20+
21+
if (!transformFn) {
22+
return callback(null, source, map);
23+
}
24+
25+
try {
26+
const id = this.resourcePath;
27+
const result = await transformFn(source, id);
28+
29+
if (result == null) {
30+
callback(null, source, map);
31+
} else if (typeof result === "string") {
32+
callback(null, result, map);
33+
} else {
34+
callback(null, result.code, result.map || map);
35+
}
36+
} catch (error) {
37+
if (error instanceof Error) {
38+
callback(error);
39+
} else {
40+
callback(new Error(String(error)));
41+
}
42+
}
43+
}

packages/webpack-plugin/src/index.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SentryWebpackPluginOptions, sentryWebpackUnpluginFactory } from "./webpack4and5";
1+
import { SentryWebpackPluginOptions, sentryWebpackPluginFactory } from "./webpack4and5";
22

33
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
44
// @ts-ignore webpack is a peer dep
@@ -8,14 +8,12 @@ const BannerPlugin = webpack4or5?.BannerPlugin || webpack4or5?.default?.BannerPl
88

99
const DefinePlugin = webpack4or5?.DefinePlugin || webpack4or5?.default?.DefinePlugin;
1010

11-
const sentryUnplugin = sentryWebpackUnpluginFactory({
12-
BannerPlugin,
13-
DefinePlugin,
14-
});
15-
1611
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1712
export const sentryWebpackPlugin: (options?: SentryWebpackPluginOptions) => any =
18-
sentryUnplugin.webpack;
13+
sentryWebpackPluginFactory({
14+
BannerPlugin,
15+
DefinePlugin,
16+
});
1917

2018
export { sentryCliBinaryExists } from "@sentry/bundler-plugin-core";
2119

0 commit comments

Comments
 (0)