Skip to content

Commit 587ef78

Browse files
authored
feat(webpack): Gate forced process exit behind experimental flag (#663)
Revert the default behaviour of the webpack plugin to no longer exit the process. Instead, users can set an experimental flag to force exiting the process.
1 parent 1bf2163 commit 587ef78

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

packages/bundler-plugin-core/src/index.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ interface SentryUnpluginFactoryOptions {
3535
debugIdInjectionPlugin: (logger: Logger) => UnpluginOptions;
3636
debugIdUploadPlugin: (
3737
upload: (buildArtifacts: string[]) => Promise<void>,
38-
logger: Logger
38+
logger: Logger,
39+
webpack_forceExitOnBuildComplete?: boolean
3940
) => UnpluginOptions;
4041
bundleSizeOptimizationsPlugin: (buildFlags: SentrySDKBuildFlags) => UnpluginOptions;
4142
}
@@ -379,6 +380,12 @@ export function sentryUnpluginFactory({
379380
"No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug."
380381
);
381382
} else {
383+
// This option is only strongly typed for the webpack plugin, where it is used. It has no effect on other plugins
384+
const webpack_forceExitOnBuildComplete =
385+
typeof options._experiments["forceExitOnBuildCompletion"] === "boolean"
386+
? options._experiments["forceExitOnBuildCompletion"]
387+
: undefined;
388+
382389
plugins.push(
383390
debugIdUploadPlugin(
384391
createDebugIdUploadFunction({
@@ -402,7 +409,8 @@ export function sentryUnpluginFactory({
402409
headers: options.headers,
403410
},
404411
}),
405-
logger
412+
logger,
413+
webpack_forceExitOnBuildComplete
406414
)
407415
);
408416
}

packages/bundler-plugin-core/src/types.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ export interface Options {
324324
* Defaults to `false`.
325325
*/
326326
injectBuildInformation?: boolean;
327-
};
327+
} & Record<string, unknown>;
328328

329329
/**
330330
* Options that are useful for building wrappers around the plugin. You likely don't need these options unless you

packages/webpack-plugin/src/index.ts

+21-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ function webpackDebugIdInjectionPlugin(): UnpluginOptions {
119119

120120
function webpackDebugIdUploadPlugin(
121121
upload: (buildArtifacts: string[]) => Promise<void>,
122-
logger: Logger
122+
logger: Logger,
123+
forceExitOnBuildCompletion?: boolean
123124
): UnpluginOptions {
124125
const pluginName = "sentry-webpack-debug-id-upload-plugin";
125126
return {
@@ -136,7 +137,7 @@ function webpackDebugIdUploadPlugin(
136137
});
137138
});
138139

139-
if (compiler.options.mode === "production") {
140+
if (forceExitOnBuildCompletion && compiler.options.mode === "production") {
140141
compiler.hooks.done.tap(pluginName, () => {
141142
setTimeout(() => {
142143
logger.debug("Exiting process after debug file upload");
@@ -184,8 +185,24 @@ const sentryUnplugin = sentryUnpluginFactory({
184185
bundleSizeOptimizationsPlugin: webpackBundleSizeOptimizationsPlugin,
185186
});
186187

188+
type SentryWebpackPluginOptions = Options & {
189+
_experiments?: Options["_experiments"] & {
190+
/**
191+
* If enabled, the webpack plugin will exit the build process after the build completes.
192+
* Use this with caution, as it will terminate the process.
193+
*
194+
* More information: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/345
195+
*
196+
* @default false
197+
*/
198+
forceExitOnBuildCompletion?: boolean;
199+
};
200+
};
201+
187202
// eslint-disable-next-line @typescript-eslint/no-explicit-any
188-
export const sentryWebpackPlugin: (options?: Options) => any = sentryUnplugin.webpack;
203+
export const sentryWebpackPlugin: (options?: SentryWebpackPluginOptions) => any =
204+
sentryUnplugin.webpack;
189205

190206
export { sentryCliBinaryExists } from "@sentry/bundler-plugin-core";
191-
export type { Options as SentryWebpackPluginOptions } from "@sentry/bundler-plugin-core";
207+
208+
export type { SentryWebpackPluginOptions };

0 commit comments

Comments
 (0)