Skip to content

Commit

Permalink
fix: Use sequential and post order for vite artifact deletion (#568)
Browse files Browse the repository at this point in the history
Co-authored-by: zhangrui11 <[email protected]>
  • Loading branch information
tyouzu1 and zhangrui11 authored Jul 10, 2024
1 parent a7e69d3 commit e26b875
Showing 1 changed file with 38 additions and 32 deletions.
70 changes: 38 additions & 32 deletions packages/bundler-plugin-core/src/plugins/sourcemap-deletion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
}

0 comments on commit e26b875

Please sign in to comment.