Skip to content
Merged
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
1 change: 1 addition & 0 deletions packages/bundler-plugin-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ export function sentryUnpluginFactory({
debugIdUploadPlugin({
assets: options.sourcemaps.assets,
ignore: options.sourcemaps.ignore,
deleteFilesAfterUpload: options.sourcemaps.deleteFilesAfterUpload,
dist: options.release.dist,
releaseName: options.release.name,
logger: logger,
Expand Down
19 changes: 19 additions & 0 deletions packages/bundler-plugin-core/src/plugins/debug-id-upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface DebugIdUploadPluginOptions {
handleRecoverableError: (error: unknown) => void;
sentryHub: Hub;
sentryClient: NodeClient;
deleteFilesAfterUpload?: string | string[];
sentryCliOptions: {
url: string;
authToken: string;
Expand All @@ -39,6 +40,7 @@ export function debugIdUploadPlugin({
sentryHub,
sentryClient,
sentryCliOptions,
deleteFilesAfterUpload,
}: DebugIdUploadPluginOptions): UnpluginOptions {
return {
name: "sentry-debug-id-upload-plugin",
Expand Down Expand Up @@ -88,6 +90,23 @@ export function debugIdUploadPlugin({
],
useArtifactBundle: true,
});

if (deleteFilesAfterUpload) {
const filePathsToDelete = await glob(deleteFilesAfterUpload, {
absolute: true,
nodir: true,
});

filePathsToDelete.forEach((filePathToDelete) => {
logger.debug(`Deleting asset after upload: ${filePathToDelete}`);
});

await Promise.all(
filePathsToDelete.map((filePathToDelete) =>
fs.promises.rm(filePathToDelete, { force: true })
)
);
}
} catch (e) {
sentryHub.captureException('Error in "debugIdUploadPlugin" writeBundle hook');
await sentryClient.flush();
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-plugin-core/src/sentry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export function setTelemetryDataOnHub(options: NormalizedOptions, hub: Hub, bund
if (sourcemaps?.assets) {
hub.setTag("debug-id-upload", true);
}
if (sourcemaps?.deleteAfterUpload) {
if (sourcemaps?.deleteFilesAfterUpload) {
hub.setTag("delete-after-upload", true);
}

Expand Down
4 changes: 1 addition & 3 deletions packages/bundler-plugin-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,8 @@ export interface Options {
* The globbing patterns follow the implementation of the `glob` package. (https://www.npmjs.com/package/glob)
*
* Use the `debug` option to print information about which files end up being deleted.
*
* @hidden Not yet implemented.
*/
deleteAfterUpload?: string | string[];
deleteFilesAfterUpload?: string | string[];
Copy link
Member

Choose a reason for hiding this comment

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

The default is undefined at the moment, right? wdyt about defaulting to the source maps assets glob path(s) instead?

Copy link
Author

Choose a reason for hiding this comment

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

That's a little too much magic for me on this level of abstraction. We could default to something like that for Next.js and Sveltekit. What we can consider is just adding this to the copy paste snippet in the docs.

};

/**
Expand Down