Skip to content

Commit 8e53019

Browse files
authored
fix(plugin-manager): Respect sourcemap.ignore values for injecting debugIDs (#836)
* fix(plugin-manager): Respect `sourcemap.ignore` values for injecting debugIDs * fix order * fix tests
1 parent 8b93465 commit 8e53019

File tree

4 files changed

+52
-3
lines changed

4 files changed

+52
-3
lines changed

packages/bundler-plugin-core/src/build-plugin-manager.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
arrayify,
2424
getProjects,
2525
getTurborepoEnvPassthroughWarning,
26+
serializeIgnoreOptions,
2627
stripQueryAndHashFromPath,
2728
} from "./utils";
2829
import { glob } from "glob";
@@ -554,7 +555,12 @@ export function createSentryBuildPluginManager(
554555
try {
555556
const cliInstance = createCliInstance(options);
556557
await cliInstance.execute(
557-
["sourcemaps", "inject", ...buildArtifactPaths],
558+
[
559+
"sourcemaps",
560+
"inject",
561+
...serializeIgnoreOptions(options.sourcemaps?.ignore),
562+
...buildArtifactPaths,
563+
],
558564
options.debug ? "rejectOnError" : false
559565
);
560566
} catch (e) {

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,23 @@ export function getProjects(project: string | string[] | undefined): string[] |
408408

409409
return undefined;
410410
}
411+
412+
/**
413+
* Inlined functionality from @sentry/cli helper code to add `--ignore` options.
414+
*
415+
* Temporary workaround until we expose a function for injecting debug IDs. Currently, we directly call `execute` with CLI args to inject them.
416+
*/
417+
export function serializeIgnoreOptions(ignoreValue: string | string[] | undefined): string[] {
418+
const DEFAULT_IGNORE = ["node_modules"];
419+
420+
const ignoreOptions: string[] = Array.isArray(ignoreValue)
421+
? ignoreValue
422+
: typeof ignoreValue === "string"
423+
? [ignoreValue]
424+
: DEFAULT_IGNORE;
425+
426+
return ignoreOptions.reduce(
427+
(acc, value) => acc.concat(["--ignore", String(value)]),
428+
[] as string[]
429+
);
430+
}

packages/bundler-plugin-core/test/build-plugin-manager.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ describe("createSentryBuildPluginManager", () => {
434434
await buildPluginManager.injectDebugIds(buildArtifactPaths);
435435

436436
expect(mockCliExecute).toHaveBeenCalledWith(
437-
["sourcemaps", "inject", "/path/to/1", "/path/to/2"],
437+
["sourcemaps", "inject", "--ignore", "node_modules", "/path/to/1", "/path/to/2"],
438438
false
439439
);
440440
});
@@ -459,7 +459,7 @@ describe("createSentryBuildPluginManager", () => {
459459
await buildPluginManager.injectDebugIds(buildArtifactPaths);
460460

461461
expect(mockCliExecute).toHaveBeenCalledWith(
462-
["sourcemaps", "inject", "/path/to/bundle"],
462+
["sourcemaps", "inject", "--ignore", "node_modules", "/path/to/bundle"],
463463
"rejectOnError"
464464
);
465465
});

packages/bundler-plugin-core/test/utils.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
getPackageJson,
66
parseMajorVersion,
77
replaceBooleanFlagsInCode,
8+
serializeIgnoreOptions,
89
stringToUUID,
910
} from "../src/utils";
1011

@@ -270,3 +271,25 @@ describe("generateModuleMetadataInjectorCode", () => {
270271
expect(generatedCode).toMatchSnapshot();
271272
});
272273
});
274+
275+
describe("serializeIgnoreOptions", () => {
276+
it("returns default ignore options when undefined", () => {
277+
const result = serializeIgnoreOptions(undefined);
278+
expect(result).toEqual(["--ignore", "node_modules"]);
279+
});
280+
281+
it("handles array of ignore patterns", () => {
282+
const result = serializeIgnoreOptions(["dist", "**/build/**", "*.log"]);
283+
expect(result).toEqual(["--ignore", "dist", "--ignore", "**/build/**", "--ignore", "*.log"]);
284+
});
285+
286+
it("handles single string pattern", () => {
287+
const result = serializeIgnoreOptions("dist");
288+
expect(result).toEqual(["--ignore", "dist"]);
289+
});
290+
291+
it("handles empty array", () => {
292+
const result = serializeIgnoreOptions([]);
293+
expect(result).toEqual([]);
294+
});
295+
});

0 commit comments

Comments
 (0)