Skip to content

Commit

Permalink
fix: Disable debug ID injection when sourcemaps.disable is set (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst authored Aug 14, 2024
1 parent db774ce commit c0976a5
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/bundler-plugin-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,9 @@ export function sentryUnpluginFactory({
);
}

plugins.push(debugIdInjectionPlugin(logger));
if (!options.sourcemaps?.disable) {
plugins.push(debugIdInjectionPlugin(logger));
}

if (options.sourcemaps?.disable) {
logger.debug(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* eslint-disable jest/no-standalone-expect */
/* eslint-disable jest/expect-expect */
import childProcess from "child_process";
import path from "path";
import { testIfNodeMajorVersionIsLessThan18 } from "../../utils/testIf";

function checkBundle(bundlePath1: string, bundlePath2: string) {
const process1Output = childProcess.execSync(`node ${bundlePath1}`, { encoding: "utf-8" });
expect(process1Output).toBe("undefined\n");

const process2Output = childProcess.execSync(`node ${bundlePath2}`, { encoding: "utf-8" });
expect(process2Output).toBe("undefined\n");
}

describe("should not inject debug IDs when `sourcemaps.disable` is `true`", () => {
test("esbuild bundle", () => {
checkBundle(
path.join(__dirname, "out", "esbuild", "bundle1.js"),
path.join(__dirname, "out", "esbuild", "bundle2.js")
);
});

test("rollup bundle", () => {
checkBundle(
path.join(__dirname, "out", "rollup", "bundle1.js"),
path.join(__dirname, "out", "rollup", "bundle2.js")
);
});

test("vite bundle", () => {
checkBundle(
path.join(__dirname, "out", "vite", "bundle1.js"),
path.join(__dirname, "out", "vite", "bundle2.js")
);
});

testIfNodeMajorVersionIsLessThan18("webpack 4 bundle", () => {
checkBundle(
path.join(__dirname, "out", "webpack4", "bundle1.js"),
path.join(__dirname, "out", "webpack4", "bundle2.js")
);
});

test("webpack 5 bundle", () => {
checkBundle(
path.join(__dirname, "out", "webpack5", "bundle1.js"),
path.join(__dirname, "out", "webpack5", "bundle2.js")
);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// eslint-disable-next-line no-console
console.log(JSON.stringify(global._sentryDebugIds));

// Just so the two bundles generate different hashes:
global.iAmBundle1 = 1;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// eslint-disable-next-line no-console
console.log(JSON.stringify(global._sentryDebugIds));

// Just so the two bundles generate different hashes:
global.iAmBundle2 = 2;
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as path from "path";
import { createCjsBundles } from "../../utils/create-cjs-bundles";

const outputDir = path.resolve(__dirname, "out");

createCjsBundles(
{
bundle1: path.resolve(__dirname, "input", "bundle1.js"),
bundle2: path.resolve(__dirname, "input", "bundle2.js"),
},
outputDir,
{
telemetry: false,
sourcemaps: {
disable: true,
},
}
);

0 comments on commit c0976a5

Please sign in to comment.