Skip to content

Commit c0976a5

Browse files
author
Luca Forstner
authored
fix: Disable debug ID injection when sourcemaps.disable is set (#589)
1 parent db774ce commit c0976a5

File tree

5 files changed

+81
-1
lines changed

5 files changed

+81
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,9 @@ export function sentryUnpluginFactory({
351351
);
352352
}
353353

354-
plugins.push(debugIdInjectionPlugin(logger));
354+
if (!options.sourcemaps?.disable) {
355+
plugins.push(debugIdInjectionPlugin(logger));
356+
}
355357

356358
if (options.sourcemaps?.disable) {
357359
logger.debug(
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/* eslint-disable jest/no-standalone-expect */
2+
/* eslint-disable jest/expect-expect */
3+
import childProcess from "child_process";
4+
import path from "path";
5+
import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf";
6+
7+
function checkBundle(bundlePath1: string, bundlePath2: string) {
8+
const process1Output = childProcess.execSync(`node ${bundlePath1}`, { encoding: "utf-8" });
9+
expect(process1Output).toBe("undefined\n");
10+
11+
const process2Output = childProcess.execSync(`node ${bundlePath2}`, { encoding: "utf-8" });
12+
expect(process2Output).toBe("undefined\n");
13+
}
14+
15+
describe("should not inject debug IDs when `sourcemaps.disable` is `true`", () => {
16+
test("esbuild bundle", () => {
17+
checkBundle(
18+
path.join(__dirname, "out", "esbuild", "bundle1.js"),
19+
path.join(__dirname, "out", "esbuild", "bundle2.js")
20+
);
21+
});
22+
23+
test("rollup bundle", () => {
24+
checkBundle(
25+
path.join(__dirname, "out", "rollup", "bundle1.js"),
26+
path.join(__dirname, "out", "rollup", "bundle2.js")
27+
);
28+
});
29+
30+
test("vite bundle", () => {
31+
checkBundle(
32+
path.join(__dirname, "out", "vite", "bundle1.js"),
33+
path.join(__dirname, "out", "vite", "bundle2.js")
34+
);
35+
});
36+
37+
testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => {
38+
checkBundle(
39+
path.join(__dirname, "out", "webpack4", "bundle1.js"),
40+
path.join(__dirname, "out", "webpack4", "bundle2.js")
41+
);
42+
});
43+
44+
test("webpack 5 bundle", () => {
45+
checkBundle(
46+
path.join(__dirname, "out", "webpack5", "bundle1.js"),
47+
path.join(__dirname, "out", "webpack5", "bundle2.js")
48+
);
49+
});
50+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// eslint-disable-next-line no-console
2+
console.log(JSON.stringify(global._sentryDebugIds));
3+
4+
// Just so the two bundles generate different hashes:
5+
global.iAmBundle1 = 1;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// eslint-disable-next-line no-console
2+
console.log(JSON.stringify(global._sentryDebugIds));
3+
4+
// Just so the two bundles generate different hashes:
5+
global.iAmBundle2 = 2;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import * as path from "path";
2+
import { createCjsBundles } from "../../utils/create-cjs-bundles";
3+
4+
const outputDir = path.resolve(__dirname, "out");
5+
6+
createCjsBundles(
7+
{
8+
bundle1: path.resolve(__dirname, "input", "bundle1.js"),
9+
bundle2: path.resolve(__dirname, "input", "bundle2.js"),
10+
},
11+
outputDir,
12+
{
13+
telemetry: false,
14+
sourcemaps: {
15+
disable: true,
16+
},
17+
}
18+
);

0 commit comments

Comments
 (0)