Skip to content

Commit 251f5a1

Browse files
authored
Merge branch 'main' into cg-webpack-disable-upload
2 parents 33fac40 + c1441e8 commit 251f5a1

File tree

4 files changed

+109
-78
lines changed

4 files changed

+109
-78
lines changed

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

Lines changed: 74 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export interface Options {
1818
* Can be obtained from https://sentry.io/orgredirect/organizations/:orgslug/settings/auth-tokens/.
1919
*
2020
* This value can also be specified via the `SENTRY_AUTH_TOKEN` environment variable.
21+
*
22+
* @see https://docs.sentry.io/product/accounts/auth-tokens/#organization-auth-tokens
2123
*/
2224
authToken?: string;
2325

@@ -27,26 +29,27 @@ export interface Options {
2729
*
2830
* This value can also be set via the `SENTRY_URL` environment variable.
2931
*
30-
* Defaults to https://sentry.io/, which is the correct value for SaaS customers.
32+
* @default "https://sentry.io" (correct value for SaaS customers)
3133
*/
3234
url?: string;
3335

3436
/**
35-
* Headers added to every outgoing network request.
37+
* Additional headers to send with every outgoing request to Sentry.
3638
*/
3739
headers?: Record<string, string>;
3840

3941
/**
40-
* Print useful debug information.
42+
* Enable debug information logs during build-time.
43+
* Enabling this will give you, for example, logs about source maps.
4144
*
42-
* Defaults to `false`.
45+
* @default false
4346
*/
4447
debug?: boolean;
4548

4649
/**
47-
* Suppresses all logs.
50+
* Suppresses all build logs (all log levels, including errors).
4851
*
49-
* Defaults to `false`.
52+
* @default false
5053
*/
5154
silent?: boolean;
5255

@@ -68,14 +71,15 @@ export interface Options {
6871
errorHandler?: (err: Error) => void;
6972

7073
/**
71-
* If set to true, internal plugin errors and performance data will be sent to Sentry.
74+
* If this flag is `true`, internal plugin errors and performance data will be sent to Sentry.
75+
* It will not collect any sensitive or user-specific data.
7276
*
73-
* At Sentry we like to use Sentry ourselves to deliver faster and more stable products.
77+
* At Sentry, we like to use Sentry ourselves to deliver faster and more stable products.
7478
* We're very careful of what we're sending. We won't collect anything other than error
7579
* and high-level performance data. We will never collect your code or any details of the
7680
* projects in which you're using this plugin.
7781
*
78-
* Defaults to `true`.
82+
* @default true
7983
*/
8084
telemetry?: boolean;
8185

@@ -87,7 +91,7 @@ export interface Options {
8791
disable?: boolean;
8892

8993
/**
90-
* Options for source maps uploading.
94+
* Options related to source maps upload and processing.
9195
*/
9296
sourcemaps?: {
9397
/**
@@ -96,29 +100,30 @@ export interface Options {
96100
* If set to `"disable-upload"`, the plugin will not upload sourcemaps to Sentry, but will inject debug IDs into the build artifacts.
97101
* This is useful if you want to manually upload sourcemaps to Sentry at a later point in time.
98102
*
99-
* Defaults to `false`.
103+
* @default false
100104
*/
101105
disable?: boolean | "disable-upload";
102106

103107
/**
104-
* A glob or an array of globs that specifies the build artifacts that should be uploaded to Sentry.
108+
* A glob or an array of globs that specify the build artifacts and source maps that will be uploaded to Sentry.
105109
*
106-
* If this option is not specified, the plugin will try to upload all JavaScript files and source map files that are created during build.
110+
* The globbing patterns must follow the implementation of the `glob` package: https://www.npmjs.com/package/glob#glob-primer
107111
*
108-
* The globbing patterns follow the implementation of the `glob` package. (https://www.npmjs.com/package/glob)
112+
* If this option is not specified, the plugin will try to upload all JavaScript files and source map files that are created during build.
109113
*
110114
* Use the `debug` option to print information about which files end up being uploaded.
115+
*
111116
*/
112117
assets?: string | string[];
113118

114119
/**
115120
* A glob or an array of globs that specifies which build artifacts should not be uploaded to Sentry.
116121
*
117-
* Default: `[]`
118-
*
119-
* The globbing patterns follow the implementation of the `glob` package. (https://www.npmjs.com/package/glob)
122+
* The globbing patterns must follow the implementation of the `glob` package: https://www.npmjs.com/package/glob#glob-primer
120123
*
121124
* Use the `debug` option to print information about which files end up being uploaded.
125+
*
126+
* @default []
122127
*/
123128
ignore?: string | string[];
124129

@@ -153,11 +158,11 @@ export interface Options {
153158
/**
154159
* A glob or an array of globs that specifies the build artifacts that should be deleted after the artifact upload to Sentry has been completed.
155160
*
156-
* The globbing patterns follow the implementation of the `glob` package. (https://www.npmjs.com/package/glob)
157-
*
158-
* Note: If you pass in a promise that resolves to a string or array, the plugin will await the promise and use
161+
* Note: If you pass in a Promise that resolves to a string or array, the plugin will await the Promise and use
159162
* the resolved value globs. This is useful if you need to dynamically determine the files to delete. Some
160-
* higher-level Sentry SDKs or options use this feature (e.g. SvelteKit).
163+
* higher-level Sentry SDKs or options use this feature (e.g., SvelteKit).
164+
*
165+
* The globbing patterns must follow the implementation of the `glob` package: https://www.npmjs.com/package/glob#glob-primer
161166
*
162167
* Use the `debug` option to print information about which files end up being deleted.
163168
*/
@@ -176,10 +181,10 @@ export interface Options {
176181
* This value can also be specified via the `SENTRY_RELEASE` environment variable.
177182
*
178183
* Defaults to automatically detecting a value for your environment.
179-
* This includes values for Cordova, Heroku, AWS CodeBuild, CircleCI, Xcode, and Gradle, and otherwise uses the git `HEAD`'s commit SHA.
180-
* (the latter requires access to git CLI and for the root directory to be a valid repository)
184+
* This includes values for Cordova, Heroku, AWS CodeBuild, CircleCI, Xcode, and Gradle, and otherwise uses the git `HEAD`'s commit SHA
185+
* (the latter requires access to git CLI and for the root directory to be a valid repository).
181186
*
182-
* If you didn't provide a value and the plugin can't automatically detect one, no release will be created.
187+
* If no `name` is provided and the plugin can't automatically detect one, no release will be created.
183188
*/
184189
name?: string;
185190

@@ -192,44 +197,48 @@ export interface Options {
192197

193198
/**
194199
* Whether the plugin should create a release on Sentry during the build.
195-
* Note that a release may still appear in Sentry even if this is value is `false` because any Sentry event that has a release value attached will automatically create a release.
196-
* (for example via the `inject` option)
197200
*
198-
* Defaults to `true`.
201+
* Note that a release may still appear in Sentry even if this value is `false`. Any Sentry event that has a release value attached
202+
* will automatically create a release (for example, via the `inject` option).
203+
*
204+
* @default true
199205
*/
200206
create?: boolean;
201207

202208
/**
203-
* Whether the Sentry release should be automatically finalized (meaning an end timestamp is added) after the build ends.
209+
* Whether to automatically finalize the release. The release is finalized by adding an end timestamp after the build ends.
204210
*
205-
* Defaults to `true`.
211+
* @default true
206212
*/
207213
finalize?: boolean;
208214

209215
/**
210-
* Unique identifier for the distribution, used to further segment your release.
216+
* Unique distribution identifier for the release. Used to further segment the release.
217+
*
211218
* Usually your build number.
212219
*/
213220
dist?: string;
214221

215222
/**
216-
* Version control system remote name.
223+
* Version control system (VCS) remote name.
217224
*
218225
* This value can also be specified via the `SENTRY_VSC_REMOTE` environment variable.
219226
*
220-
* Defaults to 'origin'.
227+
* @default "origin"
221228
*/
222229
vcsRemote?: string;
223230

224231
/**
225-
* Associates the release with its commits in Sentry.
232+
* Configuration for associating the release with its commits in Sentry.
233+
*
234+
* Set to `false` to disable commit association.
226235
*
227-
* Defaults to `{ auto: true }`. Set to `false` to disable commit association.
236+
* @default { auto: true }
228237
*/
229238
setCommits?: SetCommitsOptions | false;
230239

231240
/**
232-
* Adds deployment information to the release in Sentry.
241+
* Configuration for adding deployment information to the release in Sentry.
233242
*/
234243
deploy?: DeployOptions;
235244

@@ -247,28 +256,34 @@ export interface Options {
247256
};
248257

249258
/**
250-
* Options related to bundle size optimizations.
259+
* Options for bundle size optimizations by excluding certain features.
251260
*/
252261
bundleSizeOptimizations?: {
253262
/**
254-
* If set to `true`, the plugin will attempt to tree-shake (remove) any debugging code within the Sentry SDK.
255-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
263+
* Exclude debug statements from the bundle, thus disabling features like the SDK's `debug` option.
256264
*
257-
* Setting this option to `true` will disable features like the SDK's `debug` option.
265+
* If set to `true`, the plugin will attempt to tree-shake (remove) any debugging code within the Sentry SDK during the build.
266+
* Note that the success of this depends on tree-shaking being enabled in your build tooling.
267+
*
268+
* @default false
258269
*/
259270
excludeDebugStatements?: boolean;
260271

261272
/**
273+
* Exclude tracing functionality from the bundle, thus disabling features like performance monitoring.
274+
*
262275
* If set to `true`, the plugin will attempt to tree-shake (remove) code within the Sentry SDK that is related to tracing and performance monitoring.
263-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
276+
* Note that the success of this depends on tree-shaking being enabled in your build tooling.
264277
*
265278
* **Notice:** Do not enable this when you're using any performance monitoring-related SDK features (e.g. `Sentry.startTransaction()`).
279+
280+
* @default false
266281
*/
267282
excludeTracing?: boolean;
268283

269284
/**
270285
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay Canvas recording functionality.
271-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
286+
* Note that the success of this depends on tree-shaking being enabled in your build tooling.
272287
*
273288
* You can safely do this when you do not want to capture any Canvas activity via Sentry Session Replay.
274289
*
@@ -277,26 +292,38 @@ export interface Options {
277292
excludeReplayCanvas?: boolean;
278293

279294
/**
295+
* Exclude Replay Shadow DOM functionality from the bundle.
296+
*
280297
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay Shadow DOM recording functionality.
281-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
298+
* Note that the success of this depends on tree-shaking being enabled in your build tooling.
282299
*
283300
* This option is safe to be used when you do not want to capture any Shadow DOM activity via Sentry Session Replay.
301+
*
302+
* @default false
284303
*/
285304
excludeReplayShadowDom?: boolean;
286305

287306
/**
288-
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay `iframe` recording functionality.
289-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
307+
* Exclude Replay iFrame functionality from the bundle.
308+
*
309+
* If set to `true`, the Sentry SDK will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay `iframe` recording functionality.
310+
* Note that the success of this depends on tree-shaking being enabled in your build tooling.
290311
*
291312
* You can safely do this when you do not want to capture any `iframe` activity via Sentry Session Replay.
313+
*
314+
* @default false
292315
*/
293316
excludeReplayIframe?: boolean;
294317

295318
/**
296-
* If set to `true`, the plugin will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay's Compression Web Worker.
297-
* Note that the success of this depends on tree shaking being enabled in your build tooling.
319+
* Exclude Replay worker functionality from the bundle.
320+
*
321+
* If set to `true`, the Sentry SDK will attempt to tree-shake (remove) code related to the Sentry SDK's Session Replay's Compression Web Worker.
322+
* Note that the success of this depends on tree-shaking being enabled in your build tooling.
298323
*
299324
* **Notice:** You should only use this option if you manually host a compression worker and configure it in your Sentry Session Replay integration config via the `workerUrl` option.
325+
*
326+
* @default false
300327
*/
301328
excludeReplayWorker?: boolean;
302329
};
@@ -576,7 +603,7 @@ type DeployOptions = {
576603
time?: number;
577604

578605
/**
579-
* Human readable name for the deployment.
606+
* Human-readable name for the deployment.
580607
*/
581608
name?: string;
582609

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export function generateGlobalInjectorCode({
314314
}): string {
315315
// The code below is mostly ternary operators because it saves bundle size.
316316
// The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
317-
let code = `!function(){var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};`;
317+
let code = `!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};`;
318318

319319
code += `e.SENTRY_RELEASE={id:${JSON.stringify(release)}};`;
320320

@@ -324,7 +324,7 @@ export function generateGlobalInjectorCode({
324324
code += `e.SENTRY_BUILD_INFO=${JSON.stringify(buildInfo)};`;
325325
}
326326

327-
code += "}();";
327+
code += "}catch(e){}}();";
328328

329329
return code;
330330
}
@@ -334,9 +334,10 @@ export function generateModuleMetadataInjectorCode(metadata: any): string {
334334
// The code below is mostly ternary operators because it saves bundle size.
335335
// The checks are to support as many environments as possible. (Node.js, Browser, webworkers, etc.)
336336
// We are merging the metadata objects in case modules are bundled twice with the plugin
337-
return `!function(){var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],${JSON.stringify(
337+
// Use try-catch to avoid issues when bundlers rename global variables like 'window' to 'k'
338+
return `!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],${JSON.stringify(
338339
metadata
339-
)})}();`;
340+
)})}catch(e){}}();`;
340341
}
341342

342343
export function getBuildInformation(): {
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`generateGlobalInjectorCode generates code with release 1`] = `"!function(){var e=\\"undefined\\"!=typeof window?window:\\"undefined\\"!=typeof global?global:\\"undefined\\"!=typeof globalThis?globalThis:\\"undefined\\"!=typeof self?self:{};e.SENTRY_RELEASE={id:\\"1.2.3\\"};}();"`;
3+
exports[`generateGlobalInjectorCode generates code with release 1`] = `"!function(){try{var e=\\"undefined\\"!=typeof window?window:\\"undefined\\"!=typeof global?global:\\"undefined\\"!=typeof globalThis?globalThis:\\"undefined\\"!=typeof self?self:{};e.SENTRY_RELEASE={id:\\"1.2.3\\"};}catch(e){}}();"`;
44

5-
exports[`generateGlobalInjectorCode generates code with release and build information 1`] = `"!function(){var e=\\"undefined\\"!=typeof window?window:\\"undefined\\"!=typeof global?global:\\"undefined\\"!=typeof globalThis?globalThis:\\"undefined\\"!=typeof self?self:{};e.SENTRY_RELEASE={id:\\"1.2.3\\"};e.SENTRY_BUILD_INFO={\\"deps\\":[\\"myDep\\",\\"rollup\\"],\\"depsVersions\\":{\\"rollup\\":3},\\"nodeVersion\\":18};}();"`;
5+
exports[`generateGlobalInjectorCode generates code with release and build information 1`] = `"!function(){try{var e=\\"undefined\\"!=typeof window?window:\\"undefined\\"!=typeof global?global:\\"undefined\\"!=typeof globalThis?globalThis:\\"undefined\\"!=typeof self?self:{};e.SENTRY_RELEASE={id:\\"1.2.3\\"};e.SENTRY_BUILD_INFO={\\"deps\\":[\\"myDep\\",\\"rollup\\"],\\"depsVersions\\":{\\"rollup\\":3},\\"nodeVersion\\":18};}catch(e){}}();"`;
66

7-
exports[`generateModuleMetadataInjectorCode generates code with empty metadata object 1`] = `"!function(){var e=\\"undefined\\"!=typeof window?window:\\"undefined\\"!=typeof global?global:\\"undefined\\"!=typeof globalThis?globalThis:\\"undefined\\"!=typeof self?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],{})}();"`;
7+
exports[`generateModuleMetadataInjectorCode generates code with empty metadata object 1`] = `"!function(){try{var e=\\"undefined\\"!=typeof window?window:\\"undefined\\"!=typeof global?global:\\"undefined\\"!=typeof globalThis?globalThis:\\"undefined\\"!=typeof self?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],{})}catch(e){}}();"`;
88
9-
exports[`generateModuleMetadataInjectorCode generates code with metadata object 1`] = `"!function(){var e=\\"undefined\\"!=typeof window?window:\\"undefined\\"!=typeof global?global:\\"undefined\\"!=typeof globalThis?globalThis:\\"undefined\\"!=typeof self?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],{\\"file1.js\\":{\\"foo\\":\\"bar\\"},\\"file2.js\\":{\\"bar\\":\\"baz\\"}})}();"`;
9+
exports[`generateModuleMetadataInjectorCode generates code with metadata object 1`] = `"!function(){try{var e=\\"undefined\\"!=typeof window?window:\\"undefined\\"!=typeof global?global:\\"undefined\\"!=typeof globalThis?globalThis:\\"undefined\\"!=typeof self?self:{};e._sentryModuleMetadata=e._sentryModuleMetadata||{},e._sentryModuleMetadata[(new e.Error).stack]=function(e){for(var n=1;n<arguments.length;n++){var a=arguments[n];if(null!=a)for(var t in a)a.hasOwnProperty(t)&&(e[t]=a[t])}return e}({},e._sentryModuleMetadata[(new e.Error).stack],{\\"file1.js\\":{\\"foo\\":\\"bar\\"},\\"file2.js\\":{\\"bar\\":\\"baz\\"}})}catch(e){}}();"`;

0 commit comments

Comments
 (0)