Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions packages/bundler-plugins/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
8 changes: 7 additions & 1 deletion packages/bundler-plugins/src/babel-plugin/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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: {
Expand Down
8 changes: 7 additions & 1 deletion packages/bundler-plugins/src/babel-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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: {
Expand Down
10 changes: 10 additions & 0 deletions packages/bundler-plugins/src/babel-plugin/types.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Loading