@@ -3,12 +3,12 @@ import * as path from 'path';
3
3
/* eslint-disable complexity */
4
4
/* eslint-disable max-lines */
5
5
import { getSentryRelease } from '@sentry/node-experimental' ;
6
- import { arrayify , dropUndefinedKeys , escapeStringForRegex , loadModule , logger } from '@sentry/utils' ;
7
- import type SentryCliPlugin from '@sentry/webpack-plugin' ;
6
+ import { arrayify , dropUndefinedKeys , escapeStringForRegex , logger } from '@sentry/utils' ;
8
7
import * as chalk from 'chalk' ;
9
8
import { sync as resolveSync } from 'resolve' ;
10
- import type { Compiler } from 'webpack' ;
11
9
10
+ import type { SentryWebpackPluginOptions } from '@sentry/webpack-plugin' ;
11
+ import { sentryWebpackPlugin } from '@sentry/webpack-plugin' ;
12
12
import { DEBUG_BUILD } from '../common/debug-build' ;
13
13
import type { VercelCronsConfig } from '../common/types' ;
14
14
// Note: If you need to import a type from Webpack, do it in `types.ts` and export it from there. Otherwise, our
@@ -18,13 +18,11 @@ import type {
18
18
EntryPropertyObject ,
19
19
NextConfigObject ,
20
20
SentryBuildtimeOptions ,
21
- SentryWebpackPluginOptions ,
22
21
WebpackConfigFunction ,
23
22
WebpackConfigObject ,
24
23
WebpackConfigObjectWithModuleRules ,
25
24
WebpackEntryProperty ,
26
25
WebpackModuleRule ,
27
- WebpackPluginInstance ,
28
26
} from './types' ;
29
27
30
28
const RUNTIME_TO_SDK_ENTRYPOINT_MAP = {
@@ -35,17 +33,9 @@ const RUNTIME_TO_SDK_ENTRYPOINT_MAP = {
35
33
36
34
// Next.js runs webpack 3 times, once for the client, the server, and for edge. Because we don't want to print certain
37
35
// warnings 3 times, we keep track of them here.
38
- let showedMissingAuthTokenErrorMsg = false ;
39
- let showedMissingOrgSlugErrorMsg = false ;
40
- let showedMissingProjectSlugErrorMsg = false ;
41
36
let showedHiddenSourceMapsWarningMsg = false ;
42
- let showedMissingCliBinaryWarningMsg = false ;
43
37
let showedMissingGlobalErrorWarningMsg = false ;
44
38
45
- // TODO: merge default SentryWebpackPlugin ignore with their SentryWebpackPlugin ignore or ignoreFile
46
- // TODO: merge default SentryWebpackPlugin include with their SentryWebpackPlugin include
47
- // TODO: drop merged keys from override check? `includeDefaults` option?
48
-
49
39
/**
50
40
* Construct the function which will be used as the nextjs config's `webpack` value.
51
41
*
@@ -347,6 +337,7 @@ export function constructWebpackConfigFunction(
347
337
}
348
338
}
349
339
340
+ // TODO(v8): Remove this logic since we are deprecating es5.
350
341
// The SDK uses syntax (ES6 and ES6+ features like object spread) which isn't supported by older browsers. For users
351
342
// who want to support such browsers, `transpileClientSDK` allows them to force the SDK code to go through the same
352
343
// transpilation that their code goes through. We don't turn this on by default because it increases bundle size
@@ -406,17 +397,10 @@ export function constructWebpackConfigFunction(
406
397
// without, the option to use `hidden-source-map` only applies to the client-side build.
407
398
newConfig . devtool = userSentryOptions . hideSourceMaps && ! isServer ? 'hidden-source-map' : 'source-map' ;
408
399
409
- const SentryWebpackPlugin = loadModule < SentryCliPlugin > ( '@sentry/webpack-plugin' ) ;
410
- if ( SentryWebpackPlugin ) {
411
- newConfig . plugins = newConfig . plugins || [ ] ;
412
- newConfig . plugins . push ( new SentryCliDownloadPlugin ( ) ) ;
413
- newConfig . plugins . push (
414
- // @ts -expect-error - this exists, the dynamic import just doesn't know about it
415
- new SentryWebpackPlugin (
416
- getWebpackPluginOptions ( buildContext , userSentryWebpackPluginOptions , userSentryOptions ) ,
417
- ) ,
418
- ) ;
419
- }
400
+ newConfig . plugins = newConfig . plugins || [ ] ;
401
+ newConfig . plugins . push (
402
+ sentryWebpackPlugin ( getWebpackPluginOptions ( buildContext , userSentryWebpackPluginOptions , userSentryOptions ) ) ,
403
+ ) ;
420
404
}
421
405
}
422
406
@@ -486,13 +470,11 @@ function findTranspilationRules(rules: WebpackModuleRule[] | undefined, projectD
486
470
// Each entry in `module.rules` is either a rule in and of itself or an object with a `oneOf` property, whose value is
487
471
// an array of rules
488
472
rules . forEach ( rule => {
489
- // if (rule.oneOf) {
490
473
if ( isMatchingRule ( rule , projectDir ) ) {
491
474
matchingRules . push ( rule ) ;
492
475
} else if ( rule . oneOf ) {
493
476
const matchingOneOfRules = rule . oneOf . filter ( oneOfRule => isMatchingRule ( oneOfRule , projectDir ) ) ;
494
477
matchingRules . push ( ...matchingOneOfRules ) ;
495
- // } else if (isMatchingRule(rule, projectDir)) {
496
478
}
497
479
} ) ;
498
480
@@ -673,30 +655,6 @@ function addFilesToExistingEntryPoint(
673
655
entryProperty [ entryPointName ] = newEntryPoint ;
674
656
}
675
657
676
- /**
677
- * Check the SentryWebpackPlugin options provided by the user against the options we set by default, and warn if any of
678
- * our default options are getting overridden. (Note: If any of our default values is undefined, it won't be included in
679
- * the warning.)
680
- *
681
- * @param defaultOptions Default SentryWebpackPlugin options
682
- * @param userOptions The user's SentryWebpackPlugin options
683
- */
684
- function checkWebpackPluginOverrides (
685
- defaultOptions : SentryWebpackPluginOptions ,
686
- userOptions : Partial < SentryWebpackPluginOptions > ,
687
- ) : void {
688
- // warn if any of the default options for the webpack plugin are getting overridden
689
- const sentryWebpackPluginOptionOverrides = Object . keys ( defaultOptions ) . filter ( key => key in userOptions ) ;
690
- if ( sentryWebpackPluginOptionOverrides . length > 0 ) {
691
- DEBUG_BUILD &&
692
- logger . warn (
693
- '[Sentry] You are overriding the following automatically-set SentryWebpackPlugin config options:\n' +
694
- `\t${ sentryWebpackPluginOptionOverrides . toString ( ) } ,\n` +
695
- "which has the possibility of breaking source map upload and application. This is only a good idea if you know what you're doing." ,
696
- ) ;
697
- }
698
- }
699
-
700
658
/**
701
659
* Determine if this is an entry point into which both `Sentry.init()` code and the release value should be injected
702
660
*
@@ -770,116 +728,9 @@ export function getWebpackPluginOptions(
770
728
release : getSentryRelease ( buildId ) ,
771
729
} ) ;
772
730
773
- checkWebpackPluginOverrides ( defaultPluginOptions , userPluginOptions ) ;
774
-
775
731
return {
776
- ...defaultPluginOptions ,
777
- ...userPluginOptions ,
778
- errorHandler ( err , invokeErr , compilation ) {
779
- if ( err ) {
780
- const errorMessagePrefix = `${ chalk . red ( 'error' ) } -` ;
781
-
782
- if ( err . message . includes ( 'ENOENT' ) ) {
783
- if ( ! showedMissingCliBinaryWarningMsg ) {
784
- // eslint-disable-next-line no-console
785
- console . error (
786
- `\n${ errorMessagePrefix } ${ chalk . bold (
787
- 'The Sentry binary to upload sourcemaps could not be found.' ,
788
- ) } Source maps will not be uploaded. Please check that post-install scripts are enabled in your package manager when installing your dependencies and please run your build once without any caching to avoid caching issues of dependencies.\n`,
789
- ) ;
790
- showedMissingCliBinaryWarningMsg = true ;
791
- }
792
- return ;
793
- }
794
-
795
- // Hardcoded way to check for missing auth token until we have a better way of doing this.
796
- if ( err . message . includes ( 'Authentication credentials were not provided.' ) ) {
797
- let msg ;
798
-
799
- if ( process . env . VERCEL ) {
800
- msg = `To fix this, use Sentry's Vercel integration to automatically set the ${ chalk . bold . cyan (
801
- 'SENTRY_AUTH_TOKEN' ,
802
- ) } environment variable: https://vercel.com/integrations/sentry`;
803
- } else {
804
- msg =
805
- 'You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/\n' +
806
- `After generating a Sentry auth token, set it via the ${ chalk . bold . cyan (
807
- 'SENTRY_AUTH_TOKEN' ,
808
- ) } environment variable during the build.`;
809
- }
810
-
811
- if ( ! showedMissingAuthTokenErrorMsg ) {
812
- // eslint-disable-next-line no-console
813
- console . error (
814
- `${ errorMessagePrefix } ${ chalk . bold (
815
- 'No Sentry auth token configured.' ,
816
- ) } Source maps will not be uploaded.\n${ msg } \n`,
817
- ) ;
818
- showedMissingAuthTokenErrorMsg = true ;
819
- }
820
-
821
- return ;
822
- }
823
-
824
- // Hardcoded way to check for missing org slug until we have a better way of doing this.
825
- if ( err . message . includes ( 'An organization slug is required' ) ) {
826
- let msg ;
827
- if ( process . env . VERCEL ) {
828
- msg = `To fix this, use Sentry's Vercel integration to automatically set the ${ chalk . bold . cyan (
829
- 'SENTRY_ORG' ,
830
- ) } environment variable: https://vercel.com/integrations/sentry`;
831
- } else {
832
- msg = `To fix this, set the ${ chalk . bold . cyan (
833
- 'SENTRY_ORG' ,
834
- ) } environment variable to the to your organization slug during the build.`;
835
- }
836
-
837
- if ( ! showedMissingOrgSlugErrorMsg ) {
838
- // eslint-disable-next-line no-console
839
- console . error (
840
- `${ errorMessagePrefix } ${ chalk . bold (
841
- 'No Sentry organization slug configured.' ,
842
- ) } Source maps will not be uploaded.\n${ msg } \n`,
843
- ) ;
844
- showedMissingOrgSlugErrorMsg = true ;
845
- }
846
-
847
- return ;
848
- }
849
-
850
- // Hardcoded way to check for missing project slug until we have a better way of doing this.
851
- if ( err . message . includes ( 'A project slug is required' ) ) {
852
- let msg ;
853
- if ( process . env . VERCEL ) {
854
- msg = `To fix this, use Sentry's Vercel integration to automatically set the ${ chalk . bold . cyan (
855
- 'SENTRY_PROJECT' ,
856
- ) } environment variable: https://vercel.com/integrations/sentry`;
857
- } else {
858
- msg = `To fix this, set the ${ chalk . bold . cyan (
859
- 'SENTRY_PROJECT' ,
860
- ) } environment variable to the name of your Sentry project during the build.`;
861
- }
862
-
863
- if ( ! showedMissingProjectSlugErrorMsg ) {
864
- // eslint-disable-next-line no-console
865
- console . error (
866
- `${ errorMessagePrefix } ${ chalk . bold (
867
- 'No Sentry project slug configured.' ,
868
- ) } Source maps will not be uploaded.\n${ msg } \n`,
869
- ) ;
870
- showedMissingProjectSlugErrorMsg = true ;
871
- }
872
-
873
- return ;
874
- }
875
- }
876
-
877
- if ( userPluginOptions . errorHandler ) {
878
- return userPluginOptions . errorHandler ( err , invokeErr , compilation ) ;
879
- }
880
-
881
- return invokeErr ( ) ;
882
- } ,
732
+ authToken : 'todo' ,
733
+ url : 'todo' ,
883
734
} ;
884
735
}
885
736
@@ -1076,54 +927,3 @@ function getRequestAsyncStorageModuleLocation(
1076
927
1077
928
return undefined ;
1078
929
}
1079
-
1080
- let downloadingCliAttempted = false ;
1081
-
1082
- class SentryCliDownloadPlugin implements WebpackPluginInstance {
1083
- public apply ( compiler : Compiler ) : void {
1084
- compiler . hooks . beforeRun . tapAsync ( 'SentryCliDownloadPlugin' , ( compiler , callback ) => {
1085
- const SentryWebpackPlugin = loadModule < SentryCliPlugin > ( '@sentry/webpack-plugin' ) ;
1086
- if ( ! SentryWebpackPlugin ) {
1087
- // Pretty much an invariant.
1088
- return callback ( ) ;
1089
- }
1090
-
1091
- // @ts -expect-error - this exists, the dynamic import just doesn't know it
1092
- if ( SentryWebpackPlugin . cliBinaryExists ( ) ) {
1093
- return callback ( ) ;
1094
- }
1095
-
1096
- if ( ! downloadingCliAttempted ) {
1097
- downloadingCliAttempted = true ;
1098
- // eslint-disable-next-line no-console
1099
- logger . info (
1100
- `\n${ chalk . cyan ( 'info' ) } - ${ chalk . bold (
1101
- 'Sentry binary to upload source maps not found.' ,
1102
- ) } Package manager post-install scripts are likely disabled or there is a caching issue. Manually downloading instead...`,
1103
- ) ;
1104
-
1105
- // @ts -expect-error - this exists, the dynamic import just doesn't know it
1106
- const cliDownloadPromise : Promise < void > = SentryWebpackPlugin . downloadCliBinary ( {
1107
- log : ( ) => {
1108
- // No logs from directly from CLI
1109
- } ,
1110
- } ) ;
1111
-
1112
- cliDownloadPromise . then (
1113
- ( ) => {
1114
- // eslint-disable-next-line no-console
1115
- logger . info ( `${ chalk . cyan ( 'info' ) } - Sentry binary was successfully downloaded.\n` ) ;
1116
- return callback ( ) ;
1117
- } ,
1118
- e => {
1119
- // eslint-disable-next-line no-console
1120
- logger . error ( `${ chalk . red ( 'error' ) } - Sentry binary download failed:` , e ) ;
1121
- return callback ( ) ;
1122
- } ,
1123
- ) ;
1124
- } else {
1125
- return callback ( ) ;
1126
- }
1127
- } ) ;
1128
- }
1129
- }
0 commit comments