Skip to content

Commit

Permalink
feat(webpack): Gate forced process exit behind experimental flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Jan 24, 2025
1 parent 1bf2163 commit 094114b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
12 changes: 10 additions & 2 deletions packages/bundler-plugin-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ interface SentryUnpluginFactoryOptions {
debugIdInjectionPlugin: (logger: Logger) => UnpluginOptions;
debugIdUploadPlugin: (
upload: (buildArtifacts: string[]) => Promise<void>,
logger: Logger
logger: Logger,
webpack_forceExitOnBuildComplete?: boolean
) => UnpluginOptions;
bundleSizeOptimizationsPlugin: (buildFlags: SentrySDKBuildFlags) => UnpluginOptions;
}
Expand Down Expand Up @@ -379,6 +380,12 @@ export function sentryUnpluginFactory({
"No project provided. Will not upload source maps. Please set the `project` option to your Sentry project slug."
);
} else {
// This option is only strongly typed for the webpack plugin, where it is used. It has no effect on other plugins
const webpack_forceExitOnBuildComplete =
(typeof options._experiments["forceExitOnBuildCompletion"] === "boolean" &&
options._experiments["forceExitOnBuildCompletion"]) ??
false;

plugins.push(
debugIdUploadPlugin(
createDebugIdUploadFunction({
Expand All @@ -402,7 +409,8 @@ export function sentryUnpluginFactory({
headers: options.headers,
},
}),
logger
logger,
webpack_forceExitOnBuildComplete
)
);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/bundler-plugin-core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export interface Options {
* Defaults to `false`.
*/
injectBuildInformation?: boolean;
};
} & Record<string, unknown>;

/**
* Options that are useful for building wrappers around the plugin. You likely don't need these options unless you
Expand Down
25 changes: 21 additions & 4 deletions packages/webpack-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ function webpackDebugIdInjectionPlugin(): UnpluginOptions {

function webpackDebugIdUploadPlugin(
upload: (buildArtifacts: string[]) => Promise<void>,
logger: Logger
logger: Logger,
forceExitOnBuildCompletion?: boolean
): UnpluginOptions {
const pluginName = "sentry-webpack-debug-id-upload-plugin";
return {
Expand All @@ -136,7 +137,7 @@ function webpackDebugIdUploadPlugin(
});
});

if (compiler.options.mode === "production") {
if (forceExitOnBuildCompletion && compiler.options.mode === "production") {
compiler.hooks.done.tap(pluginName, () => {
setTimeout(() => {
logger.debug("Exiting process after debug file upload");
Expand Down Expand Up @@ -184,8 +185,24 @@ const sentryUnplugin = sentryUnpluginFactory({
bundleSizeOptimizationsPlugin: webpackBundleSizeOptimizationsPlugin,
});

type SentryWebpackPluginOptions = Options & {
_experiments: Options["_experiments"] & {
/**
* If enabled, the webpack plugin will exit the build process after the build completes.
* Use this with caution, as it will terminate the process.
*
* More information: https://github.com/getsentry/sentry-javascript-bundler-plugins/issues/345
*
* @default false
*/
forceExitOnBuildCompletion?: boolean;
};
};

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const sentryWebpackPlugin: (options?: Options) => any = sentryUnplugin.webpack;
export const sentryWebpackPlugin: (options?: SentryWebpackPluginOptions) => any =
sentryUnplugin.webpack;

export { sentryCliBinaryExists } from "@sentry/bundler-plugin-core";
export type { Options as SentryWebpackPluginOptions } from "@sentry/bundler-plugin-core";

export type { SentryWebpackPluginOptions };

0 comments on commit 094114b

Please sign in to comment.