Skip to content

Commit b7d8ea6

Browse files
authored
fix(webpack): Await source map deletion before signaling build completion (#918)
* fix(webpack): Await source map deletion before signaling build completion This PR reworks the webpack plugin to await the source map deletion before moving on. This matches the behavior of the rollup and esbuild plugins. * Clean up code structure to use try/catch/await
1 parent ae53f55 commit b7d8ea6

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

packages/webpack-plugin/src/webpack4and5.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -277,28 +277,30 @@ export function sentryWebpackPluginFactory({
277277

278278
compiler.hooks.afterEmit.tapAsync(
279279
"sentry-webpack-plugin",
280-
(compilation: WebpackCompilation, callback: () => void) => {
280+
(compilation: WebpackCompilation, callback: (err?: Error) => void) => {
281281
const freeGlobalDependencyOnBuildArtifacts = createDependencyOnBuildArtifacts();
282282
const upload = createDebugIdUploadFunction({ sentryBuildPluginManager });
283283

284-
void sentryBuildPluginManager
285-
.createRelease()
286-
.then(async () => {
284+
const run = async (): Promise<void> => {
285+
try {
286+
await sentryBuildPluginManager.createRelease();
287287
if (sourcemapsEnabled && options.sourcemaps?.disable !== "disable-upload") {
288288
const outputPath = compilation.outputOptions.path ?? path.resolve();
289289
const buildArtifacts = Object.keys(compilation.assets).map((asset) =>
290290
path.join(outputPath, asset)
291291
);
292292
await upload(buildArtifacts);
293293
}
294-
})
295-
.then(() => {
296-
callback();
297-
})
298-
.finally(() => {
294+
} finally {
299295
freeGlobalDependencyOnBuildArtifacts();
300-
void sentryBuildPluginManager.deleteArtifacts();
301-
});
296+
await sentryBuildPluginManager.deleteArtifacts();
297+
}
298+
};
299+
300+
run().then(
301+
() => callback(),
302+
(err: Error) => callback(err)
303+
);
302304
}
303305
);
304306

0 commit comments

Comments
 (0)