Skip to content

Commit 5374baa

Browse files
committed
remove support for ignoreFiles for now but add support for ignoreComponents
1 parent 213cb8c commit 5374baa

File tree

7 files changed

+30
-62
lines changed

7 files changed

+30
-62
lines changed

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

Lines changed: 5 additions & 10 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+
ignoreComponents?: 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
@@ -152,7 +150,7 @@ function functionBodyPushAttributes(
152150
componentName: string,
153151
sourceFileName: string | undefined,
154152
attributeNames: string[],
155-
ignoredComponents: IgnoredComponent[]
153+
ignoredComponents: string[]
156154
) {
157155
let jsxNode: Babel.NodePath;
158156

@@ -218,7 +216,7 @@ function processJSX(
218216
componentName: string | null,
219217
sourceFileName: string | undefined,
220218
attributeNames: string[],
221-
ignoredComponents: IgnoredComponent[]
219+
ignoredComponents: string[]
222220
) {
223221
if (!jsxNode) {
224222
return;
@@ -294,7 +292,7 @@ function applyAttributes(
294292
componentName: string | null,
295293
sourceFileName: string | undefined,
296294
attributeNames: string[],
297-
ignoredComponents: IgnoredComponent[]
295+
ignoredComponents: string[]
298296
) {
299297
const [componentAttributeName, elementAttributeName, sourceFileAttributeName] = attributeNames;
300298

@@ -310,10 +308,7 @@ function applyAttributes(
310308
const elementName = getPathName(t, openingElement);
311309

312310
const isAnIgnoredComponent = ignoredComponents.some(
313-
(ignoredComponent) =>
314-
matchesIgnoreRule(ignoredComponent[0], sourceFileName) &&
315-
matchesIgnoreRule(ignoredComponent[1], componentName) &&
316-
matchesIgnoreRule(ignoredComponent[2], elementName)
311+
(ignoredComponent) => ignoredComponent === componentName || ignoredComponent === elementName
317312
);
318313

319314
// Add a stable attribute for the element name but only for non-DOM names

packages/bundler-plugin-core/src/index.ts

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ import { fileDeletionPlugin } from "./plugins/sourcemap-deletion";
2929

3030
interface SentryUnpluginFactoryOptions {
3131
releaseInjectionPlugin: (injectionCode: string) => UnpluginOptions;
32-
componentNameAnnotatePlugin?: (
33-
ignoredFiles?: string[],
34-
ignoredComponents?: string[]
35-
) => UnpluginOptions;
32+
componentNameAnnotatePlugin?: (ignoreComponents?: string[]) => UnpluginOptions;
3633
moduleMetadataInjectionPlugin: (injectionCode: string) => UnpluginOptions;
3734
debugIdInjectionPlugin: (logger: Logger) => UnpluginOptions;
3835
debugIdUploadPlugin: (upload: (buildArtifacts: string[]) => Promise<void>) => UnpluginOptions;
@@ -404,10 +401,7 @@ export function sentryUnpluginFactory({
404401
} else {
405402
componentNameAnnotatePlugin &&
406403
plugins.push(
407-
componentNameAnnotatePlugin(
408-
options.reactComponentAnnotation.ignoredFiles,
409-
options.reactComponentAnnotation.ignoredComponents
410-
)
404+
componentNameAnnotatePlugin(options.reactComponentAnnotation.ignoreComponents)
411405
);
412406
}
413407
}
@@ -619,10 +613,7 @@ export function createRollupDebugIdUploadHooks(
619613
};
620614
}
621615

622-
export function createComponentNameAnnotateHooks(
623-
ignoredFiles?: string[],
624-
ignoredComponents?: string[]
625-
) {
616+
export function createComponentNameAnnotateHooks(ignoreComponents?: string[]) {
626617
type ParserPlugins = NonNullable<
627618
NonNullable<Parameters<typeof transformAsync>[1]>["parserOpts"]
628619
>["plugins"];
@@ -641,17 +632,6 @@ export function createComponentNameAnnotateHooks(
641632
return null;
642633
}
643634

644-
console.log("ignored files:");
645-
console.dir(ignoredFiles);
646-
console.log("current file:");
647-
console.log(idWithoutQueryAndHash);
648-
649-
const isIgnoredFile = ignoredFiles?.some((file) => idWithoutQueryAndHash.endsWith(file));
650-
if (isIgnoredFile) {
651-
console.log(`FOUND IGNORED FILE: ${idWithoutQueryAndHash}`);
652-
return null;
653-
}
654-
655635
const parserPlugins: ParserPlugins = [];
656636
if (idWithoutQueryAndHash.endsWith(".jsx")) {
657637
parserPlugins.push("jsx");
@@ -661,7 +641,7 @@ export function createComponentNameAnnotateHooks(
661641

662642
try {
663643
const result = await transformAsync(code, {
664-
plugins: [[componentNameAnnotatePlugin]],
644+
plugins: [[componentNameAnnotatePlugin, { ignoreComponents }]],
665645
filename: id,
666646
parserOpts: {
667647
sourceType: "module",

packages/bundler-plugin-core/src/types.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,13 +303,14 @@ export interface Options {
303303
*/
304304
enabled?: boolean;
305305
/**
306-
* A list of strings representing local paths to files to ignore. The plugin will not perform any annotations on components in these files
306+
* A list of strings representing the names of components to ignore. The plugin will not perform any annotations on these components
307307
*/
308-
ignoredFiles?: string[];
308+
ignoreComponents?: string[];
309+
// TODO: Support this option in the future
309310
/**
310-
* A list of strings representing the names of components to ignore. The plugin will not perform any annotations on these components
311+
* A list of strings representing local paths to files to ignore. The plugin will not perform any annotations on components in these files
311312
*/
312-
ignoredComponents?: string[];
313+
// ignoreFiles?: string[];
313314
};
314315

315316
/**

packages/dev-utils/src/generate-documentation-table.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -360,19 +360,20 @@ type IncludeEntry = {
360360
supportedBundlers: ["webpack", "vite", "rollup"],
361361
},
362362
{
363-
name: "ignoredFiles",
363+
name: "ignoreComponents",
364364
type: "string[]",
365365
fullDescription:
366-
"A list of strings representing local paths to files to ignore. The plugin will not perform any annotations on components in these files.",
367-
supportedBundlers: ["webpack", "vite", "rollup"],
368-
},
369-
{
370-
name: "ignoredComponents",
371-
type: "string[]",
372-
fullDescription:
373-
"A list of strings representing the names of components to ignore. The plugin will not perform any annotations on these components.",
366+
"A list of strings representing the names of components to ignore. The plugin will not perform apply `data-sentry` annotations on the DOM element for this component.",
374367
supportedBundlers: ["webpack", "vite", "rollup"],
375368
},
369+
// TODO: Support this option in the future
370+
// {
371+
// name: "ignoreFiles",
372+
// type: "string[]",
373+
// fullDescription:
374+
// "A list of strings representing local paths to files to ignore. The plugin will not perform any annotations on components in these files.",
375+
// supportedBundlers: ["webpack", "vite", "rollup"],
376+
// },
376377
],
377378
},
378379
{

packages/rollup-plugin/src/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,10 @@ function rollupReleaseInjectionPlugin(injectionCode: string): UnpluginOptions {
1818
};
1919
}
2020

21-
function rollupComponentNameAnnotatePlugin(
22-
ignoredFiles?: string[],
23-
ignoredComponents?: string[]
24-
): UnpluginOptions {
21+
function rollupComponentNameAnnotatePlugin(ignoreComponents?: string[]): UnpluginOptions {
2522
return {
2623
name: "sentry-rollup-component-name-annotate-plugin",
27-
rollup: createComponentNameAnnotateHooks(ignoredFiles, ignoredComponents),
24+
rollup: createComponentNameAnnotateHooks(ignoreComponents),
2825
};
2926
}
3027

packages/vite-plugin/src/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@ function viteReleaseInjectionPlugin(injectionCode: string): UnpluginOptions {
1919
};
2020
}
2121

22-
function viteComponentNameAnnotatePlugin(
23-
ignoredFiles?: string[],
24-
ignoredComponents?: string[]
25-
): UnpluginOptions {
22+
function viteComponentNameAnnotatePlugin(ignoreComponents?: string[]): UnpluginOptions {
2623
return {
2724
name: "sentry-vite-component-name-annotate-plugin",
2825
enforce: "pre" as const,
29-
vite: createComponentNameAnnotateHooks(ignoredFiles, ignoredComponents),
26+
vite: createComponentNameAnnotateHooks(ignoreComponents),
3027
};
3128
}
3229

packages/webpack-plugin/src/index.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,15 @@ function webpackReleaseInjectionPlugin(injectionCode: string): UnpluginOptions {
4747
};
4848
}
4949

50-
function webpackComponentNameAnnotatePlugin(
51-
ignoredFiles?: string[],
52-
ignoredComponents?: string[]
53-
): UnpluginOptions {
50+
function webpackComponentNameAnnotatePlugin(ignoreComponents?: string[]): UnpluginOptions {
5451
return {
5552
name: "sentry-webpack-component-name-annotate-plugin",
5653
enforce: "pre",
5754
// Webpack needs this hook for loader logic, so the plugin is not run on unsupported file types
5855
transformInclude(id) {
5956
return id.endsWith(".tsx") || id.endsWith(".jsx");
6057
},
61-
transform: createComponentNameAnnotateHooks(ignoredFiles, ignoredComponents).transform,
58+
transform: createComponentNameAnnotateHooks(ignoreComponents).transform,
6259
};
6360
}
6461

0 commit comments

Comments
 (0)