@@ -12,8 +12,8 @@ import * as dotenv from "dotenv";
1212import * as fs from "fs" ;
1313import * as os from "os" ;
1414import * 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" ;
1717import {
1818 allowedToSendTelemetry ,
1919 createSentryInstance ,
@@ -25,7 +25,60 @@ import { glob } from "glob";
2525import { defaultRewriteSourcesHook , prepareBundleForDebugIdUpload } from "./debug-id-upload" ;
2626import { dynamicSamplingContextToSentryBaggageHeader } from "@sentry/utils" ;
2727
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+ } ;
2982
3083/**
3184 * 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(
4497 */
4598 loggerPrefix : string ;
4699 }
47- ) {
100+ ) : SentryBuildPluginManager {
48101 const logger = createLogger ( {
49102 prefix : bundlerPluginMetaContext . loggerPrefix ,
50103 silent : userOptions . silent ?? false ,
@@ -73,6 +126,36 @@ export function createSentryBuildPluginManager(
73126
74127 const options = normalizeUserOptions ( userOptions ) ;
75128
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+
76159 const shouldSendTelemetry = allowedToSendTelemetry ( options ) ;
77160 const { sentryScope, sentryClient } = createSentryInstance (
78161 options ,
0 commit comments