@@ -4,19 +4,17 @@ import SentryCli from "@sentry/cli";
44import { logger } from "@sentry/utils" ;
55import * as fs from "fs" ;
66import { glob } from "glob" ;
7- import MagicString from "magic-string" ;
7+ import MagicString , { SourceMap } from "magic-string" ;
88import * as path from "path" ;
9- import { createUnplugin , TransformResult , UnpluginOptions } from "unplugin" ;
9+ import { createUnplugin , TransformResult , UnpluginInstance , UnpluginOptions } from "unplugin" ;
1010import { createSentryBuildPluginManager } from "./build-plugin-manager" ;
1111import { createDebugIdUploadFunction } from "./debug-id-upload" ;
1212import { Logger } from "./logger" ;
1313import { Options , SentrySDKBuildFlags } from "./types" ;
1414import {
1515 generateGlobalInjectorCode ,
1616 generateModuleMetadataInjectorCode ,
17- getDependencies ,
18- getPackageJson ,
19- parseMajorVersion ,
17+ getBuildInformation as actualGetBuildInformation ,
2018 replaceBooleanFlagsInCode ,
2119 stringToUUID ,
2220 stripQueryAndHashFromPath ,
@@ -46,7 +44,7 @@ export function sentryUnpluginFactory({
4644 debugIdInjectionPlugin,
4745 debugIdUploadPlugin,
4846 bundleSizeOptimizationsPlugin,
49- } : SentryUnpluginFactoryOptions ) {
47+ } : SentryUnpluginFactoryOptions ) : UnpluginInstance < Options | undefined , true > {
5048 return createUnplugin < Options | undefined , true > ( ( userOptions = { } , unpluginMetaContext ) => {
5149 const sentryBuildPluginManager = createSentryBuildPluginManager ( userOptions , {
5250 loggerPrefix :
@@ -177,22 +175,11 @@ export function sentryUnpluginFactory({
177175}
178176
179177/**
180- * @deprecated
178+ * @deprecated This will be removed in v4
181179 */
182- // TODO(v4): Don't export this from the package
183- export function getBuildInformation ( ) {
184- const packageJson = getPackageJson ( ) ;
185-
186- const { deps, depsVersions } = packageJson
187- ? getDependencies ( packageJson )
188- : { deps : [ ] , depsVersions : { } } ;
189-
190- return {
191- deps,
192- depsVersions,
193- nodeVersion : parseMajorVersion ( process . version ) ,
194- } ;
195- }
180+ // TODO(v4): Don't export this from the package but keep the utils version
181+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
182+ export const getBuildInformation = actualGetBuildInformation ;
196183
197184/**
198185 * Determines whether the Sentry CLI binary is in its expected location.
@@ -203,7 +190,11 @@ export function sentryCliBinaryExists(): boolean {
203190 return fs . existsSync ( SentryCli . getPath ( ) ) ;
204191}
205192
206- export function createRollupReleaseInjectionHooks ( injectionCode : string ) {
193+ export function createRollupReleaseInjectionHooks ( injectionCode : string ) : {
194+ resolveId : UnpluginOptions [ "resolveId" ] ;
195+ load : UnpluginOptions [ "load" ] ;
196+ transform : UnpluginOptions [ "transform" ] ;
197+ } {
207198 const virtualReleaseInjectionFileId = "\0sentry-release-injection-file" ;
208199 return {
209200 resolveId ( id : string ) {
@@ -260,7 +251,9 @@ export function createRollupReleaseInjectionHooks(injectionCode: string) {
260251 } ;
261252}
262253
263- export function createRollupBundleSizeOptimizationHooks ( replacementValues : SentrySDKBuildFlags ) {
254+ export function createRollupBundleSizeOptimizationHooks ( replacementValues : SentrySDKBuildFlags ) : {
255+ transform : UnpluginOptions [ "transform" ] ;
256+ } {
264257 return {
265258 transform ( code : string ) {
266259 return replaceBooleanFlagsInCode ( code , replacementValues ) ;
@@ -274,7 +267,24 @@ const COMMENT_USE_STRICT_REGEX =
274267 // Note: CodeQL complains that this regex potentially has n^2 runtime. This likely won't affect realistic files.
275268 / ^ (?: \s * | \/ \* (?: .| \r | \n ) * ?\* \/ | \/ \/ .* [ \n \r ] ) * (?: " [ ^ " ] * " ; | ' [ ^ ' ] * ' ; ) ? / ;
276269
277- export function createRollupDebugIdInjectionHooks ( ) {
270+ /**
271+ * Simplified `renderChunk` hook type from Rollup.
272+ * We can't reference the type directly because the Vite plugin complains
273+ * about type mismatches
274+ */
275+ type RenderChunkHook = (
276+ code : string ,
277+ chunk : {
278+ fileName : string ;
279+ }
280+ ) => {
281+ code : string ;
282+ map : SourceMap ;
283+ } | null ;
284+
285+ export function createRollupDebugIdInjectionHooks ( ) : {
286+ renderChunk : RenderChunkHook ;
287+ } {
278288 return {
279289 renderChunk ( code : string , chunk : { fileName : string } ) {
280290 if (
@@ -311,7 +321,9 @@ export function createRollupDebugIdInjectionHooks() {
311321 } ;
312322}
313323
314- export function createRollupModuleMetadataInjectionHooks ( injectionCode : string ) {
324+ export function createRollupModuleMetadataInjectionHooks ( injectionCode : string ) : {
325+ renderChunk : RenderChunkHook ;
326+ } {
315327 return {
316328 renderChunk ( code : string , chunk : { fileName : string } ) {
317329 if (
@@ -349,7 +361,12 @@ export function createRollupDebugIdUploadHooks(
349361 upload : ( buildArtifacts : string [ ] ) => Promise < void > ,
350362 _logger : Logger ,
351363 createDependencyOnBuildArtifacts : ( ) => ( ) => void
352- ) {
364+ ) : {
365+ writeBundle : (
366+ outputOptions : { dir ?: string ; file ?: string } ,
367+ bundle : { [ fileName : string ] : unknown }
368+ ) => Promise < void > ;
369+ } {
353370 const freeGlobalDependencyOnDebugIdSourcemapArtifacts = createDependencyOnBuildArtifacts ( ) ;
354371 return {
355372 async writeBundle (
@@ -390,7 +407,9 @@ export function createRollupDebugIdUploadHooks(
390407 } ;
391408}
392409
393- export function createComponentNameAnnotateHooks ( ignoredComponents ?: string [ ] ) {
410+ export function createComponentNameAnnotateHooks ( ignoredComponents ?: string [ ] ) : {
411+ transform : UnpluginOptions [ "transform" ] ;
412+ } {
394413 type ParserPlugins = NonNullable <
395414 NonNullable < Parameters < typeof transformAsync > [ 1 ] > [ "parserOpts" ]
396415 > [ "plugins" ] ;
0 commit comments