@@ -7,12 +7,9 @@ import { glob } from "glob";
77import MagicString from "magic-string" ;
88import * as path from "path" ;
99import { createUnplugin , TransformResult , UnpluginOptions } from "unplugin" ;
10- import { createSentryBuildPluginManager } from "./api-primitives " ;
10+ import { createSentryBuildPluginManager } from "./build-plugin-manager " ;
1111import { createDebugIdUploadFunction } from "./debug-id-upload" ;
12- import { releaseManagementPlugin } from "./plugins/release-management" ;
13- import { fileDeletionPlugin } from "./plugins/sourcemap-deletion" ;
14- import { telemetryPlugin } from "./plugins/telemetry" ;
15- import { Logger } from "./sentry/logger" ;
12+ import { Logger } from "./logger" ;
1613import { Options , SentrySDKBuildFlags } from "./types" ;
1714import {
1815 generateGlobalInjectorCode ,
@@ -40,30 +37,7 @@ interface SentryUnpluginFactoryOptions {
4037}
4138
4239/**
43- * The sentry bundler plugin concerns itself with two things:
44- * - Release injection
45- * - Sourcemaps upload
46- *
47- * Release injection:
48- * Per default the sentry bundler plugin will inject a global `SENTRY_RELEASE` into each JavaScript/TypeScript module
49- * that is part of the bundle. On a technical level this is done by appending an import (`import "sentry-release-injector";`)
50- * to all entrypoint files of the user code (see `transformInclude` and `transform` hooks). This import is then resolved
51- * by the sentry plugin to a virtual module that sets the global variable (see `resolveId` and `load` hooks).
52- * If a user wants to inject the release into a particular set of modules they can use the `releaseInjectionTargets` option.
53- *
54- * Source maps upload:
55- *
56- * The sentry bundler plugin will also take care of uploading source maps to Sentry. This
57- * is all done in the `writeBundle` hook. In this hook the sentry plugin will execute the
58- * release creation pipeline:
59- *
60- * 1. Create a new release
61- * 2. Upload sourcemaps based on `include` and source-map-specific options
62- * 3. Associate a range of commits with the release (if `setCommits` is specified)
63- * 4. Finalize the release (unless `finalize` is disabled)
64- * 5. Add deploy information to the release (if `deploy` is specified)
65- *
66- * This release creation pipeline relies on Sentry CLI to execute the different steps.
40+ * Creates an unplugin instance used to create Sentry plugins for Vite, Rollup, esbuild, and Webpack.
6741 */
6842export function sentryUnpluginFactory ( {
6943 releaseInjectionPlugin,
@@ -103,11 +77,13 @@ export function sentryUnpluginFactory({
10377
10478 const plugins : UnpluginOptions [ ] = [ ] ;
10579
106- plugins . push (
107- telemetryPlugin ( {
108- sentryBuildPluginManager,
109- } )
110- ) ;
80+ // Add plugin to emit a telemetry signal when the build starts
81+ plugins . push ( {
82+ name : "sentry-telemetry-plugin" ,
83+ async buildStart ( ) {
84+ await sentryBuildPluginManager . telemetry . emitBundlerPluginExecutionSignal ( ) ;
85+ } ,
86+ } ) ;
11187
11288 if ( Object . keys ( bundleSizeOptimizationReplacementValues ) . length > 0 ) {
11389 plugins . push ( bundleSizeOptimizationsPlugin ( bundleSizeOptimizationReplacementValues ) ) ;
@@ -136,11 +112,19 @@ export function sentryUnpluginFactory({
136112 plugins . push ( moduleMetadataInjectionPlugin ( injectionCode ) ) ;
137113 }
138114
139- plugins . push (
140- releaseManagementPlugin ( {
141- sentryBuildPluginManager,
142- } )
143- ) ;
115+ // Add plugin to create and finalize releases, and also take care of adding commits and legacy sourcemaps
116+ const freeGlobalDependencyOnBuildArtifacts =
117+ sentryBuildPluginManager . createDependencyOnBuildArtifacts ( ) ;
118+ plugins . push ( {
119+ name : "sentry-release-management-plugin" ,
120+ async writeBundle ( ) {
121+ try {
122+ await sentryBuildPluginManager . createRelease ( ) ;
123+ } finally {
124+ freeGlobalDependencyOnBuildArtifacts ( ) ;
125+ }
126+ } ,
127+ } ) ;
144128
145129 if ( ! options . sourcemaps ?. disable ) {
146130 plugins . push ( debugIdInjectionPlugin ( logger ) ) ;
@@ -180,16 +164,22 @@ export function sentryUnpluginFactory({
180164 }
181165 }
182166
183- plugins . push (
184- fileDeletionPlugin ( {
185- sentryBuildPluginManager,
186- } )
187- ) ;
167+ // Add plugin to delete unwanted artifacts like source maps after the uploads have completed
168+ plugins . push ( {
169+ name : "sentry-file-deletion-plugin" ,
170+ async writeBundle ( ) {
171+ await sentryBuildPluginManager . deleteArtifacts ( ) ;
172+ } ,
173+ } ) ;
188174
189175 return plugins ;
190176 } ) ;
191177}
192178
179+ /**
180+ * @deprecated
181+ */
182+ // TODO(v4): Don't export this from the package
193183export function getBuildInformation ( ) {
194184 const packageJson = getPackageJson ( ) ;
195185
@@ -458,6 +448,6 @@ export function getDebugIdSnippet(debugId: string): string {
458448 return `;{try{let e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="${ debugId } ",e._sentryDebugIdIdentifier="sentry-dbid-${ debugId } ")}catch(e){}};` ;
459449}
460450
461- export type { Logger } from "./sentry/ logger" ;
451+ export type { Logger } from "./logger" ;
462452export type { Options , SentrySDKBuildFlags } from "./types" ;
463453export { replaceBooleanFlagsInCode , stringToUUID } from "./utils" ;
0 commit comments