-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
fix(bundler-plugins): Keep debug IDs on Vite source maps after the preload rewrite #24920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d753ac3
fix(bundler-plugins): Keep debug IDs on Vite source maps after the pr…
chen-anders 53d72a4
test(bundler-plugins): Cover disable-upload source maps for Vite chun…
timfish a79f69b
Merge branch 'develop' into fix/bundler-plugins/vite-sourcemap-debug-ids
timfish c248cc0
test(bundler-plugins): Read raw output in the Vite disable-upload fix…
timfish 1f805eb
Merge remote-tracking branch 'origin/develop' into fix/bundler-plugin…
timfish 0857f4a
Merge branch 'develop' into fix/bundler-plugins/vite-sourcemap-debug-ids
timfish File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
...s/bundler-plugin-integration-tests/fixtures/configs/sourcemaps-disable-upload.config.d.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; |
6 changes: 6 additions & 0 deletions
6
...ges/bundler-plugin-integration-tests/fixtures/configs/sourcemaps-disable-upload.config.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| export const sentryConfig = { | ||
| telemetry: false, | ||
| sourcemaps: { | ||
| disable: "disable-upload", | ||
| }, | ||
| }; |
19 changes: 19 additions & 0 deletions
19
...kages/bundler-plugin-integration-tests/fixtures/vite7/sourcemaps-disable-upload.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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-disable-upload.config.js"; | ||
|
|
||
| export default defineConfig({ | ||
| build: { | ||
| minify: false, | ||
| sourcemap: true, | ||
| rollupOptions: { | ||
| input: "src/dynamic-import.js", | ||
| output: { | ||
| dir: "out/sourcemaps-disable-upload", | ||
| entryFileNames: "[name].js", | ||
| chunkFileNames: "[name].js", | ||
| }, | ||
| }, | ||
| }, | ||
| plugins: [sentryVitePlugin(sentryConfig)], | ||
| }); |
25 changes: 25 additions & 0 deletions
25
...ackages/bundler-plugin-integration-tests/fixtures/vite7/sourcemaps-disable-upload.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { readFileSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import { expect } from "vitest"; | ||
| import { test } from "./utils"; | ||
|
|
||
| // Vite rewrites the source map of chunks with dynamic imports after the Sentry plugin stamps it. | ||
| // The debug ID must survive that for every chunk. Files are read raw here because | ||
| // `readOutputFiles` zeroes debug IDs, which would hide a mismatch between chunk and map. | ||
| test(import.meta.url, ({ runBundler, outDir }) => { | ||
| runBundler(); | ||
|
|
||
| const entry = readFileSync(join(outDir, "dynamic-import.js"), "utf-8"); | ||
| expect(entry).toContain("__vitePreload"); | ||
|
|
||
| for (const fileName of ["dynamic-import.js", "import.js"]) { | ||
| const chunk = readFileSync(join(outDir, fileName), "utf-8"); | ||
| const debugId = chunk.match(/sentry-dbid-([0-9a-f-]{36})/)?.[1]; | ||
| const map = JSON.parse(readFileSync(join(outDir, `${fileName}.map`), "utf-8")); | ||
|
|
||
| expect(debugId).toBeDefined(); | ||
| expect(chunk).toContain(`//# debugId=${debugId}`); | ||
| expect(map.debug_id).toBe(debugId); | ||
| expect(map.debugId).toBe(debugId); | ||
| } | ||
| }); | ||
5 changes: 5 additions & 0 deletions
5
dev-packages/bundler-plugin-integration-tests/fixtures/vite7/src/dynamic-import.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export async function load() { | ||
| return import("./import.js"); | ||
| } | ||
|
|
||
| load(); |
19 changes: 19 additions & 0 deletions
19
...kages/bundler-plugin-integration-tests/fixtures/vite8/sourcemaps-disable-upload.config.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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-disable-upload.config.js"; | ||
|
|
||
| export default defineConfig({ | ||
| build: { | ||
| minify: false, | ||
| sourcemap: true, | ||
| rollupOptions: { | ||
| input: "src/dynamic-import.js", | ||
| output: { | ||
| dir: "out/sourcemaps-disable-upload", | ||
| entryFileNames: "[name].js", | ||
| chunkFileNames: "[name].js", | ||
| }, | ||
| }, | ||
| }, | ||
| plugins: [sentryVitePlugin(sentryConfig)], | ||
| }); |
25 changes: 25 additions & 0 deletions
25
...ackages/bundler-plugin-integration-tests/fixtures/vite8/sourcemaps-disable-upload.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| import { readFileSync } from "node:fs"; | ||
| import { join } from "node:path"; | ||
| import { expect } from "vitest"; | ||
| import { test } from "./utils"; | ||
|
|
||
| // Vite rewrites the source map of chunks with dynamic imports after the Sentry plugin stamps it. | ||
| // The debug ID must survive that for every chunk. Files are read raw here because | ||
| // `readOutputFiles` zeroes debug IDs, which would hide a mismatch between chunk and map. | ||
| test(import.meta.url, ({ runBundler, outDir }) => { | ||
| runBundler(); | ||
|
|
||
| const entry = readFileSync(join(outDir, "dynamic-import.js"), "utf-8"); | ||
| expect(entry).toContain("__vitePreload"); | ||
|
|
||
| for (const fileName of ["dynamic-import.js", "import.js"]) { | ||
| const chunk = readFileSync(join(outDir, fileName), "utf-8"); | ||
| const debugId = chunk.match(/sentry-dbid-([0-9a-f-]{36})/)?.[1]; | ||
| const map = JSON.parse(readFileSync(join(outDir, `${fileName}.map`), "utf-8")); | ||
|
|
||
| expect(debugId).toBeDefined(); | ||
| expect(chunk).toContain(`//# debugId=${debugId}`); | ||
| expect(map.debug_id).toBe(debugId); | ||
| expect(map.debugId).toBe(debugId); | ||
| } | ||
| }); |
5 changes: 5 additions & 0 deletions
5
dev-packages/bundler-plugin-integration-tests/fixtures/vite8/src/dynamic-import.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export async function load() { | ||
| return import("./import.js"); | ||
| } | ||
|
|
||
| load(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| import { isJsFile, stampDebugId } from '../core'; | ||
|
|
||
| // The subset of Rollup's `OutputBundle` the stamping hooks read. | ||
| export type OutputBundle = Record< | ||
| string, | ||
| | { type: 'chunk'; fileName: string; code: string; sourcemapFileName?: string | null } | ||
| | { type: 'asset'; fileName: string; source: string | Uint8Array } | ||
| >; | ||
|
|
||
| export function stampDebugIds(bundle: OutputBundle, updateChunkCode: boolean): void { | ||
| for (const output of Object.values(bundle)) { | ||
| if (output.type !== 'chunk' || !isJsFile(output.fileName)) { | ||
| continue; | ||
| } | ||
|
|
||
| const sourceMapAsset = bundle[output.sourcemapFileName ?? `${output.fileName}.map`]; | ||
| const sourceMapSource = | ||
| sourceMapAsset?.type === 'asset' && typeof sourceMapAsset.source === 'string' ? sourceMapAsset.source : undefined; | ||
|
|
||
| const stamped = stampDebugId(output.code, sourceMapSource); | ||
| if (!stamped) { | ||
| continue; | ||
| } | ||
|
|
||
| if (updateChunkCode) { | ||
| output.code = stamped.bundleSource; | ||
| } | ||
| if (stamped.sourceMapSource !== undefined && sourceMapAsset?.type === 'asset') { | ||
| sourceMapAsset.source = stamped.sourceMapSource; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.