File tree Expand file tree Collapse file tree 2 files changed +33
-1
lines changed
packages/bundler-plugin-core Expand file tree Collapse file tree 2 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -90,7 +90,13 @@ export function normalizeUserOptions(userOptions: UserOptions): InternalOptions
9090 // Sentry CLI will internally query env variables and read its config file if
9191 // the passed options are undefined.
9292 authToken : userOptions . authToken , // env var: `SENTRY_AUTH_TOKEN`
93- customHeader : userOptions . customHeader , // env var: `CUSTOM_HEADER`
93+
94+ // CLI v1 (and the "old" webpack plugin) use `CUSTOM_HEADER`,
95+ // but CLI v2 uses `SENTRY_HEADER` (which is also better aligned with other naming)
96+ // In the spirit of maximum compatibility, we allow both here.
97+ customHeader :
98+ userOptions . customHeader ?? process . env [ "SENTRY_HEADER" ] ?? process . env [ "CUSTOM_HEADER" ] ,
99+
94100 url : userOptions . url , // env var: `SENTRY_URL`
95101 vcsRemote : userOptions . vcsRemote , // env var: `SENTRY_VSC_REMOTE`
96102
Original file line number Diff line number Diff line change @@ -78,6 +78,32 @@ describe("normalizeUserOptions()", () => {
7878 injectReleasesMap : false ,
7979 } ) ;
8080 } ) ;
81+
82+ test ( "should handle `SENTRY_HEADER` & `CUSTOM_HEADER` env" , ( ) => {
83+ const userOptions : Options = {
84+ org : "my-org" ,
85+ project : "my-project" ,
86+ authToken : "my-auth-token" ,
87+ release : "my-release" ,
88+ include : "./out" ,
89+ } ;
90+
91+ const _original_SENTRY_HEADER = process . env [ "SENTRY_HEADER" ] ;
92+ const _original_CUSTOM_HEADER = process . env [ "CUSTOM_HEADER" ] ;
93+
94+ expect ( normalizeUserOptions ( userOptions ) . customHeader ) . toBeUndefined ( ) ;
95+
96+ process . env [ "CUSTOM_HEADER" ] = "custom-header" ;
97+
98+ expect ( normalizeUserOptions ( userOptions ) . customHeader ) . toBe ( "custom-header" ) ;
99+
100+ process . env [ "SENTRY_HEADER" ] = "sentry-header" ;
101+
102+ expect ( normalizeUserOptions ( userOptions ) . customHeader ) . toBe ( "sentry-header" ) ;
103+
104+ process . env [ "SENTRY_HEADER" ] = _original_SENTRY_HEADER ;
105+ process . env [ "CUSTOM_HEADER" ] = _original_CUSTOM_HEADER ;
106+ } ) ;
81107} ) ;
82108
83109describe ( "validateOptions" , ( ) => {
You can’t perform that action at this time.
0 commit comments