diff --git a/packages/bundler-plugins/package.json b/packages/bundler-plugins/package.json index 6cd9ce64fdf8..210eda6be54c 100644 --- a/packages/bundler-plugins/package.json +++ b/packages/bundler-plugins/package.json @@ -119,14 +119,10 @@ "supports-color": "^8.1.1" }, "peerDependencies": { - "@babel/core": "^7.18.5", "rollup": ">=3.2.0", "webpack": ">=5.1.0" }, "peerDependenciesMeta": { - "@babel/core": { - "optional": true - }, "rollup": { "optional": true }, diff --git a/packages/bundler-plugins/src/babel-plugin/experimental.ts b/packages/bundler-plugins/src/babel-plugin/experimental.ts index a5d05ec7ab6e..b80dc0595907 100644 --- a/packages/bundler-plugins/src/babel-plugin/experimental.ts +++ b/packages/bundler-plugins/src/babel-plugin/experimental.ts @@ -37,6 +37,8 @@ import type * as Babel from '@babel/core'; import type { PluginObj, PluginPass } from '@babel/core'; +import type { BabelApi, BabelPlugin } from './types'; + const REACT_NATIVE_ELEMENTS: string[] = [ 'Image', 'Text', @@ -92,7 +94,11 @@ interface JSXProcessingContext { } // We must export the plugin as default, otherwise the Babel loader will not be able to resolve it when configured using its string identifier -export function experimentalComponentNameAnnotatePlugin({ types: t }: typeof Babel): AnnotationPlugin { +export function experimentalComponentNameAnnotatePlugin(babel: BabelApi): BabelPlugin { + return createPlugin(babel as typeof Babel); +} + +function createPlugin({ types: t }: typeof Babel): AnnotationPlugin { return { visitor: { Program: { diff --git a/packages/bundler-plugins/src/babel-plugin/index.ts b/packages/bundler-plugins/src/babel-plugin/index.ts index ac97b5ff2be8..94f7347a3f87 100644 --- a/packages/bundler-plugins/src/babel-plugin/index.ts +++ b/packages/bundler-plugins/src/babel-plugin/index.ts @@ -47,6 +47,7 @@ import { type ComponentAnnotationAttributeNames, } from './component-annotation'; import { KNOWN_INCOMPATIBLE_PLUGINS } from './constants'; +import type { BabelApi, BabelPlugin } from './types'; const SENTRY_LABEL_ATTRIBUTE = 'sentry-label'; const MAX_LABEL_LENGTH = 64; @@ -100,9 +101,14 @@ interface JSXProcessingContext { } export { experimentalComponentNameAnnotatePlugin } from './experimental'; +export type { BabelApi, BabelPlugin } from './types'; // We must export the plugin as default, otherwise the Babel loader will not be able to resolve it when configured using its string identifier -export default function componentNameAnnotatePlugin({ types: t }: typeof Babel): AnnotationPlugin { +export default function componentNameAnnotatePlugin(babel: BabelApi): BabelPlugin { + return createPlugin(babel as typeof Babel); +} + +function createPlugin({ types: t }: typeof Babel): AnnotationPlugin { return { visitor: { Program: { diff --git a/packages/bundler-plugins/src/babel-plugin/types.ts b/packages/bundler-plugins/src/babel-plugin/types.ts new file mode 100644 index 000000000000..c68ecc600e18 --- /dev/null +++ b/packages/bundler-plugins/src/babel-plugin/types.ts @@ -0,0 +1,10 @@ +// The public signatures use these instead of `@babel/core` types, so +// consumers do not need Babel's types installed. + +export interface BabelApi { + types: object; +} + +export interface BabelPlugin { + visitor: object; +}