Skip to content

Commit 832a10e

Browse files
author
Luca Forstner
authored
Merge branch 'main' into main
2 parents b2907a6 + e729f02 commit 832a10e

File tree

30 files changed

+248
-1178
lines changed

30 files changed

+248
-1178
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44

55
- "You know what they say ‘Fool me once, strike one, but fool me twice… strike three.’" — Michael Scott
66

7+
## 2.23.0
8+
9+
- chore(deps): bump nanoid from 3.3.6 to 3.3.8 (#641)
10+
- feat(core): Detect Railway release name (#639)
11+
- feat(core): Write module injections to `globalThis` (#636)
12+
- feat(react-component-annotate): Allow skipping annotations on specified components (#617)
13+
- ref(core): Rename release management plugin name (#647)
14+
15+
Work in this release contributed by @conor-ob. Thank you for your contribution!
16+
717
## 2.22.7
818

919
- deps: Bump `@sentry/cli` to `2.39.1` and require specific version (#632)

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
3-
"version": "2.22.7",
3+
"version": "2.23.0",
44
"npmClient": "yarn",
55
"useWorkspaces": true
66
}

packages/babel-plugin-component-annotate/README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ Using pnpm:
4747
pnpm add @sentry/babel-plugin-component-annotate --save-dev
4848
```
4949

50+
## Options
51+
52+
### `ignoredComponents`
53+
54+
Type: `string[]`
55+
56+
A list of strings representing the names of components to ignore. The plugin will not apply `data-sentry` annotations on the DOM element for these components.
57+
5058
## Example
5159

5260
```js
@@ -57,7 +65,8 @@ pnpm add @sentry/babel-plugin-component-annotate --save-dev
5765

5866
plugins: [
5967
// Put this plugin before any other plugins you have that transform JSX code
60-
['@sentry/babel-plugin-component-annotate']
68+
// The options are set by providing an object as the second element in the array, but not required
69+
['@sentry/babel-plugin-component-annotate', {ignoredComponents: ['Foo', 'Bar']}]
6170
],
6271
}
6372
```

packages/babel-plugin-component-annotate/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sentry/babel-plugin-component-annotate",
3-
"version": "2.22.7",
3+
"version": "2.23.0",
44
"description": "A Babel plugin that annotates frontend components with additional data to enrich the experience in Sentry",
55
"repository": "git://github.com/getsentry/sentry-javascript-bundler-plugins.git",
66
"homepage": "https://github.com/getsentry/sentry-javascript-bundler-plugins/tree/main/packages/babel-plugin-component-annotate",
@@ -56,8 +56,8 @@
5656
"@babel/preset-typescript": "7.17.12",
5757
"@rollup/plugin-babel": "5.3.1",
5858
"@rollup/plugin-node-resolve": "13.3.0",
59-
"@sentry-internal/eslint-config": "2.22.7",
60-
"@sentry-internal/sentry-bundler-plugin-tsconfig": "2.22.7",
59+
"@sentry-internal/eslint-config": "2.23.0",
60+
"@sentry-internal/sentry-bundler-plugin-tsconfig": "2.23.0",
6161
"@swc/core": "^1.2.205",
6262
"@swc/jest": "^0.2.21",
6363
"@types/jest": "^28.1.3",

packages/babel-plugin-component-annotate/src/index.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ const nativeSourceFileName = "dataSentrySourceFile";
4848
interface AnnotationOpts {
4949
native?: boolean;
5050
"annotate-fragments"?: boolean;
51-
ignoreComponents?: IgnoredComponent[];
51+
ignoredComponents?: string[];
5252
}
5353

5454
interface AnnotationPluginPass extends PluginPass {
5555
opts: AnnotationOpts;
5656
}
5757

58-
type IgnoredComponent = [file: string, component: string, element: string];
59-
6058
type AnnotationPlugin = PluginObj<AnnotationPluginPass>;
6159

6260
// We must export the plugin as default, otherwise the Babel loader will not be able to resolve it when configured using its string identifier
@@ -78,7 +76,7 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel):
7876
path.node.id.name,
7977
sourceFileNameFromState(state),
8078
attributeNamesFromState(state),
81-
state.opts.ignoreComponents ?? []
79+
state.opts.ignoredComponents ?? []
8280
);
8381
},
8482
ArrowFunctionExpression(path, state) {
@@ -106,7 +104,7 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel):
106104
parent.id.name,
107105
sourceFileNameFromState(state),
108106
attributeNamesFromState(state),
109-
state.opts.ignoreComponents ?? []
107+
state.opts.ignoredComponents ?? []
110108
);
111109
},
112110
ClassDeclaration(path, state) {
@@ -120,7 +118,7 @@ export default function componentNameAnnotatePlugin({ types: t }: typeof Babel):
120118
return;
121119
}
122120

123-
const ignoredComponents = state.opts.ignoreComponents ?? [];
121+
const ignoredComponents = state.opts.ignoredComponents ?? [];
124122

125123
render.traverse({
126124
ReturnStatement(returnStatement) {
@@ -153,7 +151,7 @@ function functionBodyPushAttributes(
153151
componentName: string,
154152
sourceFileName: string | undefined,
155153
attributeNames: string[],
156-
ignoredComponents: IgnoredComponent[]
154+
ignoredComponents: string[]
157155
) {
158156
let jsxNode: Babel.NodePath;
159157

@@ -249,7 +247,7 @@ function processJSX(
249247
componentName: string | null,
250248
sourceFileName: string | undefined,
251249
attributeNames: string[],
252-
ignoredComponents: IgnoredComponent[]
250+
ignoredComponents: string[]
253251
) {
254252
if (!jsxNode) {
255253
return;
@@ -324,7 +322,7 @@ function applyAttributes(
324322
componentName: string | null,
325323
sourceFileName: string | undefined,
326324
attributeNames: string[],
327-
ignoredComponents: IgnoredComponent[]
325+
ignoredComponents: string[]
328326
) {
329327
const [componentAttributeName, elementAttributeName, sourceFileAttributeName] = attributeNames;
330328

@@ -340,10 +338,7 @@ function applyAttributes(
340338
const elementName = getPathName(t, openingElement);
341339

342340
const isAnIgnoredComponent = ignoredComponents.some(
343-
(ignoredComponent) =>
344-
matchesIgnoreRule(ignoredComponent[0], sourceFileName) &&
345-
matchesIgnoreRule(ignoredComponent[1], componentName) &&
346-
matchesIgnoreRule(ignoredComponent[2], elementName)
341+
(ignoredComponent) => ignoredComponent === componentName || ignoredComponent === elementName
347342
);
348343

349344
// Add a stable attribute for the element name but only for non-DOM names
@@ -501,10 +496,6 @@ function isReactFragment(t: typeof Babel.types, openingElement: Babel.NodePath):
501496
return false;
502497
}
503498

504-
function matchesIgnoreRule(rule: string, name: string | undefined | null) {
505-
return rule === "*" || rule === name;
506-
}
507-
508499
function hasAttributeWithName(
509500
openingElement: Babel.NodePath<Babel.types.JSXOpeningElement>,
510501
name: string | undefined | null

0 commit comments

Comments
 (0)