@@ -4,31 +4,26 @@ import { UnpluginOptions } from "unplugin";
44import { v4 as uuidv4 } from "uuid" ;
55
66// eslint-disable-next-line @typescript-eslint/ban-ts-comment
7- // @ts -ignore No typedefs for webpack 4
8- import { BannerPlugin as Webpack4BannerPlugin } from "webpack-4 " ;
7+ // @ts -ignore webpack is a peer dep
8+ import * as webback4or5 from "webpack" ;
99
1010function webpackReleaseInjectionPlugin ( injectionCode : string ) : UnpluginOptions {
1111 return {
1212 name : "sentry-webpack-release-injection-plugin" ,
1313 webpack ( compiler ) {
14- if ( compiler ?. webpack ?. BannerPlugin ) {
15- compiler . options . plugins . push (
16- new compiler . webpack . BannerPlugin ( {
17- raw : true ,
18- include : / \. ( j s | t s | j s x | t s x | m j s | c j s ) $ / ,
19- banner : injectionCode ,
20- } )
21- ) ;
22- } else {
23- compiler . options . plugins . push (
24- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
25- new Webpack4BannerPlugin ( {
26- raw : true ,
27- include : / \. ( j s | t s | j s x | t s x | m j s | c j s ) $ / ,
28- banner : injectionCode ,
29- } )
30- ) ;
31- }
14+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
15+ // @ts -ignore webpack version compatibility shenanigans
16+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
17+ const BannerPlugin = compiler ?. webpack ?. BannerPlugin || webback4or5 ?. BannerPlugin ;
18+ compiler . options . plugins = compiler . options . plugins || [ ] ;
19+ compiler . options . plugins . push (
20+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
21+ new BannerPlugin ( {
22+ raw : true ,
23+ include : / \. ( j s | t s | j s x | t s x | m j s | c j s ) $ / ,
24+ banner : injectionCode ,
25+ } )
26+ ) ;
3227 } ,
3328 } ;
3429}
@@ -37,24 +32,19 @@ function webpackDebugIdInjectionPlugin(): UnpluginOptions {
3732 return {
3833 name : "sentry-webpack-debug-id-injection-plugin" ,
3934 webpack ( compiler ) {
40- if ( compiler ?. webpack ?. BannerPlugin ) {
41- compiler . options . plugins . push (
42- new compiler . webpack . BannerPlugin ( {
43- raw : true ,
44- include : / \. ( j s | t s | j s x | t s x | m j s | c j s ) $ / ,
45- banner : ( ) => getDebugIdSnippet ( uuidv4 ( ) ) ,
46- } )
47- ) ;
48- } else {
49- compiler . options . plugins . push (
50- // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
51- new Webpack4BannerPlugin ( {
52- raw : true ,
53- include : / \. ( j s | t s | j s x | t s x | m j s | c j s ) $ / ,
54- banner : ( ) => getDebugIdSnippet ( uuidv4 ( ) ) ,
55- } )
56- ) ;
57- }
35+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
36+ // @ts -ignore webpack version compatibility shenanigans
37+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access
38+ const BannerPlugin = compiler ?. webpack ?. BannerPlugin || webback4or5 ?. BannerPlugin ;
39+ compiler . options . plugins = compiler . options . plugins || [ ] ;
40+ compiler . options . plugins . push (
41+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
42+ new BannerPlugin ( {
43+ raw : true ,
44+ include : / \. ( j s | t s | j s x | t s x | m j s | c j s ) $ / ,
45+ banner : ( ) => getDebugIdSnippet ( uuidv4 ( ) ) ,
46+ } )
47+ ) ;
5848 } ,
5949 } ;
6050}
@@ -66,10 +56,11 @@ function webpackDebugIdUploadPlugin(
6656 return {
6757 name : pluginName ,
6858 webpack ( compiler ) {
69- compiler . hooks . afterEmit . tapAsync ( pluginName , ( compilation , callback ) => {
70- const outputPath = compilation . outputOptions . path ?? path . resolve ( ) ;
71- const buildArtifacts = Object . keys ( compilation . assets ) . map ( ( asset ) =>
72- path . join ( outputPath , asset )
59+ compiler . hooks . afterEmit . tapAsync ( pluginName , ( compilation , callback : ( ) => void ) => {
60+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
61+ const outputPath = ( compilation . outputOptions . path as string | undefined ) ?? path . resolve ( ) ;
62+ const buildArtifacts = Object . keys ( compilation . assets as Record < string , unknown > ) . map (
63+ ( asset ) => path . join ( outputPath , asset )
7364 ) ;
7465 void upload ( buildArtifacts ) . then ( ( ) => {
7566 callback ( ) ;
0 commit comments