Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { SentryRollupPluginOptions } from "@sentry/bundler-plugins/rollup";
export declare const sentryConfig: SentryRollupPluginOptions;
Original file line number Diff line number Diff line change
@@ -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"],
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import type { SentryRollupPluginOptions } from "@sentry/bundler-plugins/rollup";
export declare const sentryConfig: SentryRollupPluginOptions;
Original file line number Diff line number Diff line change
@@ -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"],
},
};
Original file line number Diff line number Diff line change
@@ -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)],
});
Original file line number Diff line number Diff line change
@@ -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"],
"
`);
});
Original file line number Diff line number Diff line change
@@ -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)],
});
Original file line number Diff line number Diff line change
@@ -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"],
"
`);
});
Original file line number Diff line number Diff line change
@@ -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)],
});
Original file line number Diff line number Diff line change
@@ -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"],
"
`);
});
Original file line number Diff line number Diff line change
@@ -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)],
});
Original file line number Diff line number Diff line change
@@ -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"],
"
`);
});
Original file line number Diff line number Diff line change
@@ -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)],
});
Original file line number Diff line number Diff line change
@@ -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"],
"
`);
});
Original file line number Diff line number Diff line change
@@ -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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to raise that the fixtures never take the staged upload path, but I think that's covered by your stack? If this PR is meant only as a baseline before the stack, then we should maybe say that in the description, and make sure each stack PR adds the staged variant.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was going to raise that the fixtures never take the staged upload path, but I think that's covered by your stack?

The staged upload path will be covered in the stack but I haven't got that far yet. I've added a ref. to this in the description.

I think eventually It would be good to move Roll{up,down}, Vite and webpack to only use the staged path, but that's a behavioural change because we would stop picking up maps that weren't in the build. I would say that's desirable, but it is a change. It looks like esbuild, Turbopack, SvelteKit and Nuxt will not be able to go this route though 🤔

},
plugins: [sentryRollupPlugin(sentryConfig)],
});
Original file line number Diff line number Diff line change
@@ -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"],
"
`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<debug-id>-<index>.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)) {
Expand Down Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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)],
});
Loading
Loading