From c0fd1df760b983e5bbb53d2c3c6753ddbcc424af Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Mon, 7 Jul 2025 17:33:39 +0200 Subject: [PATCH 1/4] disable debugId upload --- packages/bundler-plugin-core/src/index.ts | 34 +++++++------- .../disabled-sourcemaps-upload.test.ts | 45 +++++++++++++++++++ .../input/bundle.js | 2 + packages/integration-tests/package.json | 2 +- packages/rollup-plugin/src/index.ts | 6 +++ 5 files changed, 71 insertions(+), 18 deletions(-) create mode 100644 packages/integration-tests/fixtures/disabled-sourcemaps-upload/disabled-sourcemaps-upload.test.ts create mode 100644 packages/integration-tests/fixtures/disabled-sourcemaps-upload/input/bundle.js diff --git a/packages/bundler-plugin-core/src/index.ts b/packages/bundler-plugin-core/src/index.ts index d487483b..25ed91e2 100644 --- a/packages/bundler-plugin-core/src/index.ts +++ b/packages/bundler-plugin-core/src/index.ts @@ -126,24 +126,24 @@ export function sentryUnpluginFactory({ if (!options.sourcemaps?.disable) { plugins.push(debugIdInjectionPlugin(logger)); - } - // This option is only strongly typed for the webpack plugin, where it is used. It has no effect on other plugins - const webpack_forceExitOnBuildComplete = - typeof options._experiments["forceExitOnBuildCompletion"] === "boolean" - ? options._experiments["forceExitOnBuildCompletion"] - : undefined; - - plugins.push( - debugIdUploadPlugin( - createDebugIdUploadFunction({ - sentryBuildPluginManager, - }), - logger, - sentryBuildPluginManager.createDependencyOnBuildArtifacts, - webpack_forceExitOnBuildComplete - ) - ); + // This option is only strongly typed for the webpack plugin, where it is used. It has no effect on other plugins + const webpack_forceExitOnBuildComplete = + typeof options._experiments["forceExitOnBuildCompletion"] === "boolean" + ? options._experiments["forceExitOnBuildCompletion"] + : undefined; + + plugins.push( + debugIdUploadPlugin( + createDebugIdUploadFunction({ + sentryBuildPluginManager, + }), + logger, + sentryBuildPluginManager.createDependencyOnBuildArtifacts, + webpack_forceExitOnBuildComplete + ) + ); + } if (options.reactComponentAnnotation) { if (!options.reactComponentAnnotation.enabled) { diff --git a/packages/integration-tests/fixtures/disabled-sourcemaps-upload/disabled-sourcemaps-upload.test.ts b/packages/integration-tests/fixtures/disabled-sourcemaps-upload/disabled-sourcemaps-upload.test.ts new file mode 100644 index 00000000..781c4e4f --- /dev/null +++ b/packages/integration-tests/fixtures/disabled-sourcemaps-upload/disabled-sourcemaps-upload.test.ts @@ -0,0 +1,45 @@ +import path from "path"; + +import * as rollup from "rollup"; +import { sentryRollupPlugin } from "@sentry/rollup-plugin"; + +function getGlobalWithDebugIdUploads(): typeof global & { + __SENTRY_DEBUG_ID_UPLOAD_TEST__?: boolean; +} { + return global; +} + +test("should not call upload plugin when sourcemaps are disabled", async () => { + const gbl = getGlobalWithDebugIdUploads(); + gbl.__SENTRY_DEBUG_ID_UPLOAD_TEST__ = false; + + await rollup.rollup({ + input: { bundle1: path.resolve(__dirname, "input", "bundle.js") }, + plugins: [ + sentryRollupPlugin({ + telemetry: false, + sourcemaps: { + disable: true, + }, + }), + ], + }); + + expect(gbl.__SENTRY_DEBUG_ID_UPLOAD_TEST__).toBe(false); +}); + +test("should call upload plugin when sourcemaps are enabled", async () => { + const gbl = getGlobalWithDebugIdUploads(); + gbl.__SENTRY_DEBUG_ID_UPLOAD_TEST__ = false; + + await rollup.rollup({ + input: { bundle1: path.resolve(__dirname, "input", "bundle.js") }, + plugins: [ + sentryRollupPlugin({ + telemetry: false, + }), + ], + }); + + expect(gbl.__SENTRY_DEBUG_ID_UPLOAD_TEST__).toBe(true); +}); diff --git a/packages/integration-tests/fixtures/disabled-sourcemaps-upload/input/bundle.js b/packages/integration-tests/fixtures/disabled-sourcemaps-upload/input/bundle.js new file mode 100644 index 00000000..85b0fd2b --- /dev/null +++ b/packages/integration-tests/fixtures/disabled-sourcemaps-upload/input/bundle.js @@ -0,0 +1,2 @@ +// eslint-disable-next-line no-console +console.log("Beep!"); diff --git a/packages/integration-tests/package.json b/packages/integration-tests/package.json index 54c0cce7..0f4ae8bc 100644 --- a/packages/integration-tests/package.json +++ b/packages/integration-tests/package.json @@ -47,4 +47,4 @@ "volta": { "extends": "../../package.json" } -} +} \ No newline at end of file diff --git a/packages/rollup-plugin/src/index.ts b/packages/rollup-plugin/src/index.ts index 6ca2466f..04d345ba 100644 --- a/packages/rollup-plugin/src/index.ts +++ b/packages/rollup-plugin/src/index.ts @@ -45,6 +45,12 @@ function rollupDebugIdUploadPlugin( logger: Logger, createDependencyOnBuildArtifacts: () => () => void ): UnpluginOptions { + // Only for testing purposes + if (process.env["NODE_ENV"] === "test") { + if ("__SENTRY_DEBUG_ID_UPLOAD_TEST__" in global) { + global.__SENTRY_DEBUG_ID_UPLOAD_TEST__ = true; + } + } return { name: "sentry-rollup-debug-id-upload-plugin", rollup: createRollupDebugIdUploadHooks(upload, logger, createDependencyOnBuildArtifacts), From b796df6e05dd8a53d4dcfb1740eda149941ed8d6 Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Mon, 7 Jul 2025 17:37:27 +0200 Subject: [PATCH 2/4] Update packages/integration-tests/package.json Co-authored-by: Abhijeet Prasad --- packages/integration-tests/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/integration-tests/package.json b/packages/integration-tests/package.json index 0f4ae8bc..54c0cce7 100644 --- a/packages/integration-tests/package.json +++ b/packages/integration-tests/package.json @@ -47,4 +47,4 @@ "volta": { "extends": "../../package.json" } -} \ No newline at end of file +} From 20744640e188c8c47c07d6037658c9525f9dd47c Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Mon, 7 Jul 2025 17:41:50 +0200 Subject: [PATCH 3/4] use different env --- .../disabled-sourcemaps-upload.test.ts | 4 ++++ packages/rollup-plugin/src/index.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/integration-tests/fixtures/disabled-sourcemaps-upload/disabled-sourcemaps-upload.test.ts b/packages/integration-tests/fixtures/disabled-sourcemaps-upload/disabled-sourcemaps-upload.test.ts index 781c4e4f..7eb2dfc0 100644 --- a/packages/integration-tests/fixtures/disabled-sourcemaps-upload/disabled-sourcemaps-upload.test.ts +++ b/packages/integration-tests/fixtures/disabled-sourcemaps-upload/disabled-sourcemaps-upload.test.ts @@ -10,6 +10,7 @@ function getGlobalWithDebugIdUploads(): typeof global & { } test("should not call upload plugin when sourcemaps are disabled", async () => { + process.env["SENTRY_NODE_ENV"] = "test"; const gbl = getGlobalWithDebugIdUploads(); gbl.__SENTRY_DEBUG_ID_UPLOAD_TEST__ = false; @@ -26,9 +27,11 @@ test("should not call upload plugin when sourcemaps are disabled", async () => { }); expect(gbl.__SENTRY_DEBUG_ID_UPLOAD_TEST__).toBe(false); + delete process.env["SENTRY_NODE_ENV"]; }); test("should call upload plugin when sourcemaps are enabled", async () => { + process.env["SENTRY_NODE_ENV"] = "test"; const gbl = getGlobalWithDebugIdUploads(); gbl.__SENTRY_DEBUG_ID_UPLOAD_TEST__ = false; @@ -42,4 +45,5 @@ test("should call upload plugin when sourcemaps are enabled", async () => { }); expect(gbl.__SENTRY_DEBUG_ID_UPLOAD_TEST__).toBe(true); + delete process.env["SENTRY_NODE_ENV"]; }); diff --git a/packages/rollup-plugin/src/index.ts b/packages/rollup-plugin/src/index.ts index 04d345ba..0b0cd408 100644 --- a/packages/rollup-plugin/src/index.ts +++ b/packages/rollup-plugin/src/index.ts @@ -46,7 +46,7 @@ function rollupDebugIdUploadPlugin( createDependencyOnBuildArtifacts: () => () => void ): UnpluginOptions { // Only for testing purposes - if (process.env["NODE_ENV"] === "test") { + if (process.env["SENTRY_NODE_ENV"] === "test") { if ("__SENTRY_DEBUG_ID_UPLOAD_TEST__" in global) { global.__SENTRY_DEBUG_ID_UPLOAD_TEST__ = true; } From af20339900c290249ac246e1a9dbb370460ee25a Mon Sep 17 00:00:00 2001 From: Charly Gomez Date: Mon, 7 Jul 2025 18:07:24 +0200 Subject: [PATCH 4/4] simplify test --- .../disabled-sourcemaps-upload.test.ts | 55 ++++++------------- packages/rollup-plugin/src/index.ts | 6 -- 2 files changed, 16 insertions(+), 45 deletions(-) diff --git a/packages/integration-tests/fixtures/disabled-sourcemaps-upload/disabled-sourcemaps-upload.test.ts b/packages/integration-tests/fixtures/disabled-sourcemaps-upload/disabled-sourcemaps-upload.test.ts index 7eb2dfc0..dd22ef31 100644 --- a/packages/integration-tests/fixtures/disabled-sourcemaps-upload/disabled-sourcemaps-upload.test.ts +++ b/packages/integration-tests/fixtures/disabled-sourcemaps-upload/disabled-sourcemaps-upload.test.ts @@ -1,49 +1,26 @@ -import path from "path"; - -import * as rollup from "rollup"; import { sentryRollupPlugin } from "@sentry/rollup-plugin"; -function getGlobalWithDebugIdUploads(): typeof global & { - __SENTRY_DEBUG_ID_UPLOAD_TEST__?: boolean; -} { - return global; -} +const debugIdUploadPluginName = "sentry-rollup-debug-id-upload-plugin"; -test("should not call upload plugin when sourcemaps are disabled", async () => { - process.env["SENTRY_NODE_ENV"] = "test"; - const gbl = getGlobalWithDebugIdUploads(); - gbl.__SENTRY_DEBUG_ID_UPLOAD_TEST__ = false; +test("should not call upload plugin when sourcemaps are disabled", () => { + const plugins = sentryRollupPlugin({ + telemetry: false, + sourcemaps: { + disable: true, + }, + }) as Array<{ name: string }>; - await rollup.rollup({ - input: { bundle1: path.resolve(__dirname, "input", "bundle.js") }, - plugins: [ - sentryRollupPlugin({ - telemetry: false, - sourcemaps: { - disable: true, - }, - }), - ], - }); + const debugIdUploadPlugin = plugins.find((plugin) => plugin.name === debugIdUploadPluginName); - expect(gbl.__SENTRY_DEBUG_ID_UPLOAD_TEST__).toBe(false); - delete process.env["SENTRY_NODE_ENV"]; + expect(debugIdUploadPlugin).toBeUndefined(); }); -test("should call upload plugin when sourcemaps are enabled", async () => { - process.env["SENTRY_NODE_ENV"] = "test"; - const gbl = getGlobalWithDebugIdUploads(); - gbl.__SENTRY_DEBUG_ID_UPLOAD_TEST__ = false; +test("should call upload plugin when sourcemaps are enabled", () => { + const plugins = sentryRollupPlugin({ + telemetry: false, + }) as Array<{ name: string }>; - await rollup.rollup({ - input: { bundle1: path.resolve(__dirname, "input", "bundle.js") }, - plugins: [ - sentryRollupPlugin({ - telemetry: false, - }), - ], - }); + const debugIdUploadPlugin = plugins.find((plugin) => plugin.name === debugIdUploadPluginName); - expect(gbl.__SENTRY_DEBUG_ID_UPLOAD_TEST__).toBe(true); - delete process.env["SENTRY_NODE_ENV"]; + expect(debugIdUploadPlugin).toBeDefined(); }); diff --git a/packages/rollup-plugin/src/index.ts b/packages/rollup-plugin/src/index.ts index 0b0cd408..6ca2466f 100644 --- a/packages/rollup-plugin/src/index.ts +++ b/packages/rollup-plugin/src/index.ts @@ -45,12 +45,6 @@ function rollupDebugIdUploadPlugin( logger: Logger, createDependencyOnBuildArtifacts: () => () => void ): UnpluginOptions { - // Only for testing purposes - if (process.env["SENTRY_NODE_ENV"] === "test") { - if ("__SENTRY_DEBUG_ID_UPLOAD_TEST__" in global) { - global.__SENTRY_DEBUG_ID_UPLOAD_TEST__ = true; - } - } return { name: "sentry-rollup-debug-id-upload-plugin", rollup: createRollupDebugIdUploadHooks(upload, logger, createDependencyOnBuildArtifacts),