diff --git a/packages/bundler-plugin-core/src/plugins/sourcemap-deletion.ts b/packages/bundler-plugin-core/src/plugins/sourcemap-deletion.ts index 53043df0..6ea38fb2 100644 --- a/packages/bundler-plugin-core/src/plugins/sourcemap-deletion.ts +++ b/packages/bundler-plugin-core/src/plugins/sourcemap-deletion.ts @@ -22,43 +22,49 @@ export function fileDeletionPlugin({ dependenciesAreFreedPromise, logger, }: FileDeletionPlugin): UnpluginOptions { - return { - name: "sentry-file-deletion-plugin", - async writeBundle() { - try { - if (filesToDeleteAfterUpload !== undefined) { - const filePathsToDelete = await glob(filesToDeleteAfterUpload, { - absolute: true, - nodir: true, - }); + const writeBundle = async () => { + try { + if (filesToDeleteAfterUpload !== undefined) { + const filePathsToDelete = await glob(filesToDeleteAfterUpload, { + absolute: true, + nodir: true, + }); - logger.debug( - "Waiting for dependencies on generated files to be freed before deleting..." - ); + logger.debug("Waiting for dependencies on generated files to be freed before deleting..."); - await dependenciesAreFreedPromise; + await dependenciesAreFreedPromise; - filePathsToDelete.forEach((filePathToDelete) => { - logger.debug(`Deleting asset after upload: ${filePathToDelete}`); - }); + filePathsToDelete.forEach((filePathToDelete) => { + logger.debug(`Deleting asset after upload: ${filePathToDelete}`); + }); - await Promise.all( - filePathsToDelete.map((filePathToDelete) => - fs.promises.rm(filePathToDelete, { force: true }).catch((e) => { - // This is allowed to fail - we just don't do anything - logger.debug( - `An error occurred while attempting to delete asset: ${filePathToDelete}`, - e - ); - }) - ) - ); - } - } catch (e) { - sentryHub.captureException('Error in "sentry-file-deletion-plugin" buildEnd hook'); - await safeFlushTelemetry(sentryClient); - handleRecoverableError(e); + await Promise.all( + filePathsToDelete.map((filePathToDelete) => + fs.promises.rm(filePathToDelete, { force: true }).catch((e) => { + // This is allowed to fail - we just don't do anything + logger.debug( + `An error occurred while attempting to delete asset: ${filePathToDelete}`, + e + ); + }) + ) + ); } + } catch (e) { + sentryHub.captureException('Error in "sentry-file-deletion-plugin" buildEnd hook'); + await safeFlushTelemetry(sentryClient); + handleRecoverableError(e); + } + }; + return { + name: "sentry-file-deletion-plugin", + vite: { + writeBundle: { + sequential: true, + order: "post", + handler: writeBundle, + }, }, + writeBundle, }; }