@@ -12,8 +12,8 @@ import * as dotenv from "dotenv";
12
12
import * as fs from "fs" ;
13
13
import * as os from "os" ;
14
14
import * as path from "path" ;
15
- import { normalizeUserOptions , validateOptions } from "./options-mapping" ;
16
- import { createLogger } from "./logger" ;
15
+ import { NormalizedOptions , normalizeUserOptions , validateOptions } from "./options-mapping" ;
16
+ import { createLogger , Logger } from "./logger" ;
17
17
import {
18
18
allowedToSendTelemetry ,
19
19
createSentryInstance ,
@@ -25,7 +25,60 @@ import { glob } from "glob";
25
25
import { defaultRewriteSourcesHook , prepareBundleForDebugIdUpload } from "./debug-id-upload" ;
26
26
import { dynamicSamplingContextToSentryBaggageHeader } from "@sentry/utils" ;
27
27
28
- export type SentryBuildPluginManager = ReturnType < typeof createSentryBuildPluginManager > ;
28
+ export type SentryBuildPluginManager = {
29
+ /**
30
+ * A logger instance that takes the options passed to the build plugin manager into account. (for silencing and log level etc.)
31
+ */
32
+ logger : Logger ;
33
+
34
+ /**
35
+ * Options after normalization. Includes things like the inferred release name.
36
+ */
37
+ normalizedOptions : NormalizedOptions ;
38
+ /**
39
+ * Magic strings and their replacement values that can be used for bundle size optimizations. This already takes
40
+ * into account the options passed to the build plugin manager.
41
+ */
42
+ bundleSizeOptimizationReplacementValues : SentrySDKBuildFlags ;
43
+ /**
44
+ * Metadata that should be injected into bundles if possible. Takes into account options passed to the build plugin manager.
45
+ */
46
+ // See `generateModuleMetadataInjectorCode` for how this should be used exactly
47
+ bundleMetadata : Record < string , unknown > ;
48
+
49
+ /**
50
+ * Contains utility functions for emitting telemetry via the build plugin manager.
51
+ */
52
+ telemetry : {
53
+ /**
54
+ * Emits a `Sentry Bundler Plugin execution` signal.
55
+ */
56
+ emitBundlerPluginExecutionSignal ( ) : Promise < void > ;
57
+ } ;
58
+
59
+ /**
60
+ * Will potentially create a release based on the build plugin manager options.
61
+ *
62
+ * Also
63
+ * - finalizes the release
64
+ * - sets commits
65
+ * - uploads legacy sourcemaps
66
+ * - adds deploy information
67
+ */
68
+ createRelease ( ) : Promise < void > ;
69
+
70
+ /**
71
+ * Uploads sourcemaps using the "Debug ID" method. This function takes a list of build artifact paths that will be uploaded
72
+ */
73
+ uploadSourcemaps ( buildArtifactPaths : string [ ] ) : Promise < void > ;
74
+
75
+ /**
76
+ * Will delete artifacts based on the passed `sourcemaps.filesToDeleteAfterUpload` option.
77
+ */
78
+ deleteArtifacts ( ) : Promise < void > ;
79
+
80
+ createDependencyOnBuildArtifacts : ( ) => ( ) => void ;
81
+ } ;
29
82
30
83
/**
31
84
* Creates a build plugin manager that exposes primitives for everything that a Sentry JavaScript SDK or build tooling may do during a build.
@@ -44,7 +97,7 @@ export function createSentryBuildPluginManager(
44
97
*/
45
98
loggerPrefix : string ;
46
99
}
47
- ) {
100
+ ) : SentryBuildPluginManager {
48
101
const logger = createLogger ( {
49
102
prefix : bundlerPluginMetaContext . loggerPrefix ,
50
103
silent : userOptions . silent ?? false ,
@@ -73,6 +126,36 @@ export function createSentryBuildPluginManager(
73
126
74
127
const options = normalizeUserOptions ( userOptions ) ;
75
128
129
+ if ( options . disable ) {
130
+ // Early-return a noop build plugin manager instance so that we
131
+ // don't continue validating options, setting up Sentry, etc.
132
+ // Otherwise we might create side-effects or log messages that
133
+ // users don't expect from a disabled plugin.
134
+ return {
135
+ normalizedOptions : options ,
136
+ logger,
137
+ bundleSizeOptimizationReplacementValues : { } ,
138
+ telemetry : {
139
+ emitBundlerPluginExecutionSignal : async ( ) => {
140
+ /* noop */
141
+ } ,
142
+ } ,
143
+ bundleMetadata : { } ,
144
+ createRelease : async ( ) => {
145
+ /* noop */
146
+ } ,
147
+ uploadSourcemaps : async ( ) => {
148
+ /* noop */
149
+ } ,
150
+ deleteArtifacts : async ( ) => {
151
+ /* noop */
152
+ } ,
153
+ createDependencyOnBuildArtifacts : ( ) => ( ) => {
154
+ /* noop */
155
+ } ,
156
+ } ;
157
+ }
158
+
76
159
const shouldSendTelemetry = allowedToSendTelemetry ( options ) ;
77
160
const { sentryScope, sentryClient } = createSentryInstance (
78
161
options ,
0 commit comments