@@ -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,35 @@ 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+ } ) ;
87+
88+ // Add plugin to create and finalize releases, and also take care of adding commits and legacy sourcemaps
89+ const freeGlobalDependencyOnBuildArtifacts =
90+ sentryBuildPluginManager . createDependencyOnBuildArtifacts ( ) ;
91+ plugins . push ( {
92+ name : "sentry-release-management-plugin" ,
93+ async writeBundle ( ) {
94+ try {
95+ await sentryBuildPluginManager . createRelease ( ) ;
96+ } finally {
97+ freeGlobalDependencyOnBuildArtifacts ( ) ;
98+ }
99+ } ,
100+ } ) ;
101+
102+ // Add plugin to delete unwanted artifacts like source maps after the uploads have completed
103+ plugins . push ( {
104+ name : "sentry-file-deletion-plugin" ,
105+ async writeBundle ( ) {
106+ await sentryBuildPluginManager . deleteArtifacts ( ) ;
107+ } ,
108+ } ) ;
111109
112110 if ( Object . keys ( bundleSizeOptimizationReplacementValues ) . length > 0 ) {
113111 plugins . push ( bundleSizeOptimizationsPlugin ( bundleSizeOptimizationReplacementValues ) ) ;
@@ -136,12 +134,6 @@ export function sentryUnpluginFactory({
136134 plugins . push ( moduleMetadataInjectionPlugin ( injectionCode ) ) ;
137135 }
138136
139- plugins . push (
140- releaseManagementPlugin ( {
141- sentryBuildPluginManager,
142- } )
143- ) ;
144-
145137 if ( ! options . sourcemaps ?. disable ) {
146138 plugins . push ( debugIdInjectionPlugin ( logger ) ) ;
147139 }
@@ -180,16 +172,14 @@ export function sentryUnpluginFactory({
180172 }
181173 }
182174
183- plugins . push (
184- fileDeletionPlugin ( {
185- sentryBuildPluginManager,
186- } )
187- ) ;
188-
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