Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(webpack): Gate forced process exit behind experimental flag #663

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]
: undefined;

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 };
Loading