diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/configs/sourcemaps-assets.config.d.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/configs/sourcemaps-assets.config.d.ts new file mode 100644 index 000000000000..192b614bc29b --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/configs/sourcemaps-assets.config.d.ts @@ -0,0 +1,2 @@ +import type { SentryRollupPluginOptions } from "@sentry/bundler-plugins/rollup"; +export declare const sentryConfig: SentryRollupPluginOptions; diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/configs/sourcemaps-assets.config.js b/dev-packages/bundler-plugin-integration-tests/fixtures/configs/sourcemaps-assets.config.js new file mode 100644 index 000000000000..a78ae93f7ec1 --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/configs/sourcemaps-assets.config.js @@ -0,0 +1,10 @@ +export const sentryConfig = { + telemetry: false, + authToken: "fake-auth", + org: "fake-org", + project: "fake-project", + release: { inject: false }, + sourcemaps: { + assets: ["out/sourcemaps-assets/entry1.js"], + }, +}; diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/configs/sourcemaps-ignore.config.d.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/configs/sourcemaps-ignore.config.d.ts new file mode 100644 index 000000000000..192b614bc29b --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/configs/sourcemaps-ignore.config.d.ts @@ -0,0 +1,2 @@ +import type { SentryRollupPluginOptions } from "@sentry/bundler-plugins/rollup"; +export declare const sentryConfig: SentryRollupPluginOptions; diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/configs/sourcemaps-ignore.config.js b/dev-packages/bundler-plugin-integration-tests/fixtures/configs/sourcemaps-ignore.config.js new file mode 100644 index 000000000000..2c6890272dfd --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/configs/sourcemaps-ignore.config.js @@ -0,0 +1,10 @@ +export const sentryConfig = { + telemetry: false, + authToken: "fake-auth", + org: "fake-org", + project: "fake-project", + release: { inject: false }, + sourcemaps: { + ignore: ["**/entry2.js"], + }, +}; diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/sourcemaps-assets.config.js b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/sourcemaps-assets.config.js new file mode 100644 index 000000000000..59ca69b920d6 --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/sourcemaps-assets.config.js @@ -0,0 +1,15 @@ +import * as esbuild from "esbuild"; +import { sentryEsbuildPlugin } from "@sentry/bundler-plugins/esbuild"; +import { sentryConfig } from "../configs/sourcemaps-assets.config.js"; + +await esbuild.build({ + entryPoints: ["./src/entry1.js", "./src/entry2.js"], + bundle: true, + outdir: "./out/sourcemaps-assets", + minify: false, + format: "esm", + splitting: true, + chunkNames: "[name]", + sourcemap: true, + plugins: [sentryEsbuildPlugin(sentryConfig)], +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/sourcemaps-assets.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/sourcemaps-assets.test.ts new file mode 100644 index 000000000000..f16619de3be6 --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/sourcemaps-assets.test.ts @@ -0,0 +1,36 @@ +import { expect } from "vitest"; +import { test } from "./utils"; + +test(import.meta.url, ({ runBundler, readOutputFiles }) => { + runBundler({ SENTRY_TEST_RECORD_UPLOADED_SOURCES: "1" }); + const files = readOutputFiles(); + + expect(Object.keys(files).sort()).toMatchInlineSnapshot(` + [ + "chunk.js", + "chunk.js.map", + "entry1.js", + "entry1.js.map", + "entry2.js", + "entry2.js.map", + "sentry-cli-mock.json", + "sentry-uploaded-sources.json", + ] + `); + expect(JSON.parse(files["sentry-uploaded-sources.json"]!)).toMatchInlineSnapshot(` + [ + [ + "sentry-debug-id-stub:_sentry-debug-id-injection-stub?sentry-module-id=00000000-0000-0000-0000-000000000000", + "../../src/entry1.js", + "../../src/entry1.js", + ], + ] + `); + expect(files["sentry-cli-mock.json"]).toMatchInlineSnapshot(` + "["release","create","CURRENT_SHA","--project","fake-project"], + ["release","set-commits","CURRENT_SHA","--auto"], + ["release","finalize","CURRENT_SHA"], + ["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"], + " + `); +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/sourcemaps-ignore.config.js b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/sourcemaps-ignore.config.js new file mode 100644 index 000000000000..7ecbc3a35e0e --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/sourcemaps-ignore.config.js @@ -0,0 +1,15 @@ +import * as esbuild from "esbuild"; +import { sentryEsbuildPlugin } from "@sentry/bundler-plugins/esbuild"; +import { sentryConfig } from "../configs/sourcemaps-ignore.config.js"; + +await esbuild.build({ + entryPoints: ["./src/entry1.js", "./src/entry2.js"], + bundle: true, + outdir: "./out/sourcemaps-ignore", + minify: false, + format: "esm", + splitting: true, + chunkNames: "[name]", + sourcemap: true, + plugins: [sentryEsbuildPlugin(sentryConfig)], +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/sourcemaps-ignore.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/sourcemaps-ignore.test.ts new file mode 100644 index 000000000000..f16619de3be6 --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/esbuild/sourcemaps-ignore.test.ts @@ -0,0 +1,36 @@ +import { expect } from "vitest"; +import { test } from "./utils"; + +test(import.meta.url, ({ runBundler, readOutputFiles }) => { + runBundler({ SENTRY_TEST_RECORD_UPLOADED_SOURCES: "1" }); + const files = readOutputFiles(); + + expect(Object.keys(files).sort()).toMatchInlineSnapshot(` + [ + "chunk.js", + "chunk.js.map", + "entry1.js", + "entry1.js.map", + "entry2.js", + "entry2.js.map", + "sentry-cli-mock.json", + "sentry-uploaded-sources.json", + ] + `); + expect(JSON.parse(files["sentry-uploaded-sources.json"]!)).toMatchInlineSnapshot(` + [ + [ + "sentry-debug-id-stub:_sentry-debug-id-injection-stub?sentry-module-id=00000000-0000-0000-0000-000000000000", + "../../src/entry1.js", + "../../src/entry1.js", + ], + ] + `); + expect(files["sentry-cli-mock.json"]).toMatchInlineSnapshot(` + "["release","create","CURRENT_SHA","--project","fake-project"], + ["release","set-commits","CURRENT_SHA","--auto"], + ["release","finalize","CURRENT_SHA"], + ["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"], + " + `); +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rolldown/sourcemaps-assets.config.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rolldown/sourcemaps-assets.config.ts new file mode 100644 index 000000000000..6990dda586fa --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rolldown/sourcemaps-assets.config.ts @@ -0,0 +1,13 @@ +import { sentryRollupPlugin } from "@sentry/bundler-plugins/rollup"; +import { defineConfig } from "rolldown"; +import { sentryConfig } from "../configs/sourcemaps-assets.config.js"; + +export default defineConfig({ + input: ["src/entry1.js", "src/entry2.js"], + output: { + dir: "out/sourcemaps-assets", + chunkFileNames: "[name].js", + sourcemap: true, + }, + plugins: [sentryRollupPlugin(sentryConfig)], +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rolldown/sourcemaps-assets.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rolldown/sourcemaps-assets.test.ts new file mode 100644 index 000000000000..af148b26891b --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rolldown/sourcemaps-assets.test.ts @@ -0,0 +1,34 @@ +import { expect } from "vitest"; +import { test } from "./utils"; + +test(import.meta.url, ({ runBundler, readOutputFiles }) => { + runBundler({ SENTRY_TEST_RECORD_UPLOADED_SOURCES: "1" }); + const files = readOutputFiles(); + + expect(Object.keys(files).sort()).toMatchInlineSnapshot(` + [ + "common.js", + "common.js.map", + "entry1.js", + "entry1.js.map", + "entry2.js", + "entry2.js.map", + "sentry-cli-mock.json", + "sentry-uploaded-sources.json", + ] + `); + expect(JSON.parse(files["sentry-uploaded-sources.json"]!)).toMatchInlineSnapshot(` + [ + [ + "../../src/entry1.js", + ], + ] + `); + expect(files["sentry-cli-mock.json"]).toMatchInlineSnapshot(` + "["release","create","CURRENT_SHA","--project","fake-project"], + ["release","set-commits","CURRENT_SHA","--auto"], + ["release","finalize","CURRENT_SHA"], + ["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"], + " + `); +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rolldown/sourcemaps-ignore.config.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rolldown/sourcemaps-ignore.config.ts new file mode 100644 index 000000000000..0cb7600ca4db --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rolldown/sourcemaps-ignore.config.ts @@ -0,0 +1,13 @@ +import { sentryRollupPlugin } from "@sentry/bundler-plugins/rollup"; +import { defineConfig } from "rolldown"; +import { sentryConfig } from "../configs/sourcemaps-ignore.config.js"; + +export default defineConfig({ + input: ["src/entry1.js", "src/entry2.js"], + output: { + dir: "out/sourcemaps-ignore", + chunkFileNames: "[name].js", + sourcemap: true, + }, + plugins: [sentryRollupPlugin(sentryConfig)], +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rolldown/sourcemaps-ignore.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rolldown/sourcemaps-ignore.test.ts new file mode 100644 index 000000000000..d320a622a424 --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rolldown/sourcemaps-ignore.test.ts @@ -0,0 +1,37 @@ +import { expect } from "vitest"; +import { test } from "./utils"; + +test(import.meta.url, ({ runBundler, readOutputFiles }) => { + runBundler({ SENTRY_TEST_RECORD_UPLOADED_SOURCES: "1" }); + const files = readOutputFiles(); + + expect(Object.keys(files).sort()).toMatchInlineSnapshot(` + [ + "common.js", + "common.js.map", + "entry1.js", + "entry1.js.map", + "entry2.js", + "entry2.js.map", + "sentry-cli-mock.json", + "sentry-uploaded-sources.json", + ] + `); + expect(JSON.parse(files["sentry-uploaded-sources.json"]!)).toMatchInlineSnapshot(` + [ + [ + "../../src/common.js", + ], + [ + "../../src/entry1.js", + ], + ] + `); + expect(files["sentry-cli-mock.json"]).toMatchInlineSnapshot(` + "["release","create","CURRENT_SHA","--project","fake-project"], + ["release","set-commits","CURRENT_SHA","--auto"], + ["release","finalize","CURRENT_SHA"], + ["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"], + " + `); +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/sourcemaps-assets.config.js b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/sourcemaps-assets.config.js new file mode 100644 index 000000000000..fdd3564869a6 --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/sourcemaps-assets.config.js @@ -0,0 +1,13 @@ +import { sentryRollupPlugin } from "@sentry/bundler-plugins/rollup"; +import { defineConfig } from "rollup"; +import { sentryConfig } from "../configs/sourcemaps-assets.config.js"; + +export default defineConfig({ + input: ["src/entry1.js", "src/entry2.js"], + output: { + dir: "out/sourcemaps-assets", + chunkFileNames: "[name].js", + sourcemap: true, + }, + plugins: [sentryRollupPlugin(sentryConfig)], +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/sourcemaps-assets.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/sourcemaps-assets.test.ts new file mode 100644 index 000000000000..af148b26891b --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/sourcemaps-assets.test.ts @@ -0,0 +1,34 @@ +import { expect } from "vitest"; +import { test } from "./utils"; + +test(import.meta.url, ({ runBundler, readOutputFiles }) => { + runBundler({ SENTRY_TEST_RECORD_UPLOADED_SOURCES: "1" }); + const files = readOutputFiles(); + + expect(Object.keys(files).sort()).toMatchInlineSnapshot(` + [ + "common.js", + "common.js.map", + "entry1.js", + "entry1.js.map", + "entry2.js", + "entry2.js.map", + "sentry-cli-mock.json", + "sentry-uploaded-sources.json", + ] + `); + expect(JSON.parse(files["sentry-uploaded-sources.json"]!)).toMatchInlineSnapshot(` + [ + [ + "../../src/entry1.js", + ], + ] + `); + expect(files["sentry-cli-mock.json"]).toMatchInlineSnapshot(` + "["release","create","CURRENT_SHA","--project","fake-project"], + ["release","set-commits","CURRENT_SHA","--auto"], + ["release","finalize","CURRENT_SHA"], + ["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"], + " + `); +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/sourcemaps-ignore.config.js b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/sourcemaps-ignore.config.js new file mode 100644 index 000000000000..d4fb120db1c0 --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/sourcemaps-ignore.config.js @@ -0,0 +1,13 @@ +import { sentryRollupPlugin } from "@sentry/bundler-plugins/rollup"; +import { defineConfig } from "rollup"; +import { sentryConfig } from "../configs/sourcemaps-ignore.config.js"; + +export default defineConfig({ + input: ["src/entry1.js", "src/entry2.js"], + output: { + dir: "out/sourcemaps-ignore", + chunkFileNames: "[name].js", + sourcemap: true, + }, + plugins: [sentryRollupPlugin(sentryConfig)], +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/sourcemaps-ignore.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/sourcemaps-ignore.test.ts new file mode 100644 index 000000000000..d320a622a424 --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/rollup4/sourcemaps-ignore.test.ts @@ -0,0 +1,37 @@ +import { expect } from "vitest"; +import { test } from "./utils"; + +test(import.meta.url, ({ runBundler, readOutputFiles }) => { + runBundler({ SENTRY_TEST_RECORD_UPLOADED_SOURCES: "1" }); + const files = readOutputFiles(); + + expect(Object.keys(files).sort()).toMatchInlineSnapshot(` + [ + "common.js", + "common.js.map", + "entry1.js", + "entry1.js.map", + "entry2.js", + "entry2.js.map", + "sentry-cli-mock.json", + "sentry-uploaded-sources.json", + ] + `); + expect(JSON.parse(files["sentry-uploaded-sources.json"]!)).toMatchInlineSnapshot(` + [ + [ + "../../src/common.js", + ], + [ + "../../src/entry1.js", + ], + ] + `); + expect(files["sentry-cli-mock.json"]).toMatchInlineSnapshot(` + "["release","create","CURRENT_SHA","--project","fake-project"], + ["release","set-commits","CURRENT_SHA","--auto"], + ["release","finalize","CURRENT_SHA"], + ["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"], + " + `); +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/sentry-stub/index.cjs b/dev-packages/bundler-plugin-integration-tests/fixtures/sentry-stub/index.cjs index cd449620c86d..fd2c7a2bbb3f 100644 --- a/dev-packages/bundler-plugin-integration-tests/fixtures/sentry-stub/index.cjs +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/sentry-stub/index.cjs @@ -27,6 +27,25 @@ function record(args) { fs.appendFileSync(out, `${JSON.stringify(args)},\n`); } +/** + * Write the `sources` of every source map in the upload directory to `sentry-uploaded-sources.json`. + * The plugin renames uploaded files to `-.js`, so only the `sources` tell which + * chunks were uploaded. Opt-in through `SENTRY_TEST_RECORD_UPLOADED_SOURCES` so other snapshots + * stay unchanged. + */ +function recordUploadedSources(directory) { + const outDir = process.env['SENTRY_TEST_OUT_DIR']; + if (!outDir || !process.env['SENTRY_TEST_RECORD_UPLOADED_SOURCES'] || !fs.existsSync(directory)) { + return; + } + const sources = fs + .readdirSync(directory) + .filter(file => file.endsWith('.map')) + .map(file => JSON.parse(fs.readFileSync(path.join(directory, file), 'utf8')).sources) + .sort((a, b) => String(a).localeCompare(String(b))); + fs.writeFileSync(path.join(outDir, 'sentry-uploaded-sources.json'), `${JSON.stringify(sources, null, 2)}\n`); +} + /** Append boolean flags (only when true) and value flags (only when set) to an args array. */ function pushFlags(args, flags, spec) { for (const [key, flag] of Object.entries(spec)) { @@ -83,6 +102,7 @@ function createSentrySDK(options = {}) { pushFlags(args, params, { release: '--release', dist: '--dist' }); if (params.directory) { args.push(params.directory); + recordUploadedSources(params.directory); } pushFlags(args, params, { ext: '--ext', diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/vite8/sourcemaps-assets.config.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/vite8/sourcemaps-assets.config.ts new file mode 100644 index 000000000000..cbb96a3b4f7b --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/vite8/sourcemaps-assets.config.ts @@ -0,0 +1,19 @@ +import { sentryVitePlugin } from "@sentry/bundler-plugins/vite"; +import { defineConfig } from "vite"; +import { sentryConfig } from "../configs/sourcemaps-assets.config.js"; + +export default defineConfig({ + build: { + minify: false, + sourcemap: true, + rollupOptions: { + input: ["src/entry1.js", "src/entry2.js"], + output: { + dir: "out/sourcemaps-assets", + chunkFileNames: "[name].js", + entryFileNames: "[name].js", + }, + }, + }, + plugins: [sentryVitePlugin(sentryConfig)], +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/vite8/sourcemaps-assets.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/vite8/sourcemaps-assets.test.ts new file mode 100644 index 000000000000..af148b26891b --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/vite8/sourcemaps-assets.test.ts @@ -0,0 +1,34 @@ +import { expect } from "vitest"; +import { test } from "./utils"; + +test(import.meta.url, ({ runBundler, readOutputFiles }) => { + runBundler({ SENTRY_TEST_RECORD_UPLOADED_SOURCES: "1" }); + const files = readOutputFiles(); + + expect(Object.keys(files).sort()).toMatchInlineSnapshot(` + [ + "common.js", + "common.js.map", + "entry1.js", + "entry1.js.map", + "entry2.js", + "entry2.js.map", + "sentry-cli-mock.json", + "sentry-uploaded-sources.json", + ] + `); + expect(JSON.parse(files["sentry-uploaded-sources.json"]!)).toMatchInlineSnapshot(` + [ + [ + "../../src/entry1.js", + ], + ] + `); + expect(files["sentry-cli-mock.json"]).toMatchInlineSnapshot(` + "["release","create","CURRENT_SHA","--project","fake-project"], + ["release","set-commits","CURRENT_SHA","--auto"], + ["release","finalize","CURRENT_SHA"], + ["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"], + " + `); +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/vite8/sourcemaps-ignore.config.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/vite8/sourcemaps-ignore.config.ts new file mode 100644 index 000000000000..54fad01a9a8b --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/vite8/sourcemaps-ignore.config.ts @@ -0,0 +1,19 @@ +import { sentryVitePlugin } from "@sentry/bundler-plugins/vite"; +import { defineConfig } from "vite"; +import { sentryConfig } from "../configs/sourcemaps-ignore.config.js"; + +export default defineConfig({ + build: { + minify: false, + sourcemap: true, + rollupOptions: { + input: ["src/entry1.js", "src/entry2.js"], + output: { + dir: "out/sourcemaps-ignore", + chunkFileNames: "[name].js", + entryFileNames: "[name].js", + }, + }, + }, + plugins: [sentryVitePlugin(sentryConfig)], +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/vite8/sourcemaps-ignore.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/vite8/sourcemaps-ignore.test.ts new file mode 100644 index 000000000000..d320a622a424 --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/vite8/sourcemaps-ignore.test.ts @@ -0,0 +1,37 @@ +import { expect } from "vitest"; +import { test } from "./utils"; + +test(import.meta.url, ({ runBundler, readOutputFiles }) => { + runBundler({ SENTRY_TEST_RECORD_UPLOADED_SOURCES: "1" }); + const files = readOutputFiles(); + + expect(Object.keys(files).sort()).toMatchInlineSnapshot(` + [ + "common.js", + "common.js.map", + "entry1.js", + "entry1.js.map", + "entry2.js", + "entry2.js.map", + "sentry-cli-mock.json", + "sentry-uploaded-sources.json", + ] + `); + expect(JSON.parse(files["sentry-uploaded-sources.json"]!)).toMatchInlineSnapshot(` + [ + [ + "../../src/common.js", + ], + [ + "../../src/entry1.js", + ], + ] + `); + expect(files["sentry-cli-mock.json"]).toMatchInlineSnapshot(` + "["release","create","CURRENT_SHA","--project","fake-project"], + ["release","set-commits","CURRENT_SHA","--auto"], + ["release","finalize","CURRENT_SHA"], + ["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"], + " + `); +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/sourcemaps-assets.config.js b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/sourcemaps-assets.config.js new file mode 100644 index 000000000000..2b4b72ec6bc7 --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/sourcemaps-assets.config.js @@ -0,0 +1,21 @@ +import { sentryWebpackPlugin } from "@sentry/bundler-plugins/webpack"; +import { sentryConfig } from "../configs/sourcemaps-assets.config.js"; +import { resolve } from "node:path"; + +export default { + cache: false, + entry: { + entry1: "./src/entry1.js", + entry2: "./src/entry2.js", + }, + output: { + path: resolve("./out/sourcemaps-assets"), + filename: "[name].js", + }, + devtool: "source-map", + optimization: { + minimize: false, + }, + mode: "production", + plugins: [sentryWebpackPlugin(sentryConfig)], +}; diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/sourcemaps-assets.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/sourcemaps-assets.test.ts new file mode 100644 index 000000000000..24236bd8553a --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/sourcemaps-assets.test.ts @@ -0,0 +1,33 @@ +import { expect } from "vitest"; +import { test } from "./utils"; + +test(import.meta.url, ({ runBundler, readOutputFiles }) => { + runBundler({ SENTRY_TEST_RECORD_UPLOADED_SOURCES: "1" }); + const files = readOutputFiles(); + + expect(Object.keys(files).sort()).toMatchInlineSnapshot(` + [ + "entry1.js", + "entry1.js.map", + "entry2.js", + "entry2.js.map", + "sentry-cli-mock.json", + "sentry-uploaded-sources.json", + ] + `); + expect(JSON.parse(files["sentry-uploaded-sources.json"]!)).toMatchInlineSnapshot(` + [ + [ + "webpack5-integration-tests/./src/common.js", + "webpack5-integration-tests/./src/entry1.js", + ], + ] + `); + expect(files["sentry-cli-mock.json"]).toMatchInlineSnapshot(` + "["release","create","CURRENT_SHA","--project","fake-project"], + ["release","set-commits","CURRENT_SHA","--auto"], + ["release","finalize","CURRENT_SHA"], + ["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"], + " + `); +}); diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/sourcemaps-ignore.config.js b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/sourcemaps-ignore.config.js new file mode 100644 index 000000000000..406ff5d7aaba --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/sourcemaps-ignore.config.js @@ -0,0 +1,21 @@ +import { sentryWebpackPlugin } from "@sentry/bundler-plugins/webpack"; +import { sentryConfig } from "../configs/sourcemaps-ignore.config.js"; +import { resolve } from "node:path"; + +export default { + cache: false, + entry: { + entry1: "./src/entry1.js", + entry2: "./src/entry2.js", + }, + output: { + path: resolve("./out/sourcemaps-ignore"), + filename: "[name].js", + }, + devtool: "source-map", + optimization: { + minimize: false, + }, + mode: "production", + plugins: [sentryWebpackPlugin(sentryConfig)], +}; diff --git a/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/sourcemaps-ignore.test.ts b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/sourcemaps-ignore.test.ts new file mode 100644 index 000000000000..24236bd8553a --- /dev/null +++ b/dev-packages/bundler-plugin-integration-tests/fixtures/webpack5/sourcemaps-ignore.test.ts @@ -0,0 +1,33 @@ +import { expect } from "vitest"; +import { test } from "./utils"; + +test(import.meta.url, ({ runBundler, readOutputFiles }) => { + runBundler({ SENTRY_TEST_RECORD_UPLOADED_SOURCES: "1" }); + const files = readOutputFiles(); + + expect(Object.keys(files).sort()).toMatchInlineSnapshot(` + [ + "entry1.js", + "entry1.js.map", + "entry2.js", + "entry2.js.map", + "sentry-cli-mock.json", + "sentry-uploaded-sources.json", + ] + `); + expect(JSON.parse(files["sentry-uploaded-sources.json"]!)).toMatchInlineSnapshot(` + [ + [ + "webpack5-integration-tests/./src/common.js", + "webpack5-integration-tests/./src/entry1.js", + ], + ] + `); + expect(files["sentry-cli-mock.json"]).toMatchInlineSnapshot(` + "["release","create","CURRENT_SHA","--project","fake-project"], + ["release","set-commits","CURRENT_SHA","--auto"], + ["release","finalize","CURRENT_SHA"], + ["sourcemap","upload","-p","fake-project","--release","CURRENT_SHA","sentry-bundler-plugin-upload-path"], + " + `); +});