Skip to content

Commit 985b74a

Browse files
committed
fix(plugin-manager): Respect sourcemap.ignore values for injecting debugIDs
1 parent 36b714b commit 985b74a

File tree

4 files changed

+52
-12
lines changed

4 files changed

+52
-12
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,8 +555,13 @@ export function createSentryBuildPluginManager(
554555
try {
555556
const cliInstance = createCliInstance(options);
556557
await cliInstance.execute(
557-
["sourcemaps", "inject", ...buildArtifactPaths],
558558
options.debug ?? false
559+
[
560+
"sourcemaps",
561+
"inject",
562+
...serializeIgnoreOptions(options.sourcemaps?.ignore),
563+
...buildArtifactPaths,
564+
],
559565
);
560566
} catch (e) {
561567
sentryScope.captureException('Error in "debugIdInjectionPlugin" writeBundle hook');

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/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+
});

yarn.lock

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8109,15 +8109,6 @@ istanbul-reports@^3.1.3:
81098109
html-escaper "^2.0.0"
81108110
istanbul-lib-report "^3.0.0"
81118111

8112-
jackspeak@^2.0.3:
8113-
version "2.2.1"
8114-
resolved "https://registry.npmjs.org/jackspeak/-/jackspeak-2.2.1.tgz#655e8cf025d872c9c03d3eb63e8f0c024fef16a6"
8115-
integrity sha512-MXbxovZ/Pm42f6cDIDkl3xpwv1AGwObKwfmjs2nQePiy85tP3fatofl3FC1aBsOtP/6fq5SbtgHwWcMsLP+bDw==
8116-
dependencies:
8117-
"@isaacs/cliui" "^8.0.2"
8118-
optionalDependencies:
8119-
"@pkgjs/parseargs" "^0.11.0"
8120-
81218112
jackspeak@^3.1.2:
81228113
version "3.4.3"
81238114
resolved "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.3.tgz#8833a9d89ab4acde6188942bd1c53b6390ed5a8a"
@@ -9608,7 +9599,7 @@ minimatch@^8.0.2:
96089599
dependencies:
96099600
brace-expansion "^2.0.1"
96109601

9611-
minimatch@^9.0.0, minimatch@^9.0.1:
9602+
minimatch@^9.0.0:
96129603
version "9.0.1"
96139604
resolved "https://registry.npmjs.org/minimatch/-/minimatch-9.0.1.tgz#8a555f541cf976c622daf078bb28f29fb927c253"
96149605
integrity sha512-0jWhJpD/MdhPXwPuiRkCbfYfSKp2qnn2eOc279qI7f+osl/l+prKSrvhg157zSYvx/1nmgn2NqdT6k2Z7zSH9w==
@@ -10764,7 +10755,7 @@ path-scurry@^1.11.1:
1076410755
lru-cache "^10.2.0"
1076510756
minipass "^5.0.0 || ^6.0.2 || ^7.0.0"
1076610757

10767-
path-scurry@^1.6.1, path-scurry@^1.7.0:
10758+
path-scurry@^1.6.1:
1076810759
version "1.9.2"
1076910760
resolved "https://registry.npmjs.org/path-scurry/-/path-scurry-1.9.2.tgz#90f9d296ac5e37e608028e28a447b11d385b3f63"
1077010761
integrity sha512-qSDLy2aGFPm8i4rsbHd4MNyTcrzHFsLQykrtbuGRknZZCBBVXSv2tSCDN2Cg6Rt/GFRw8GoW9y9Ecw5rIPG1sg==

0 commit comments

Comments
 (0)