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

misc(esbuild): Log warning when attempting to inject debug IDs with esbuild bundle option active #526

Merged
merged 2 commits into from
May 3, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/bundler-plugin-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { normalizeUserOptions, validateOptions } from "./options-mapping";
import { createDebugIdUploadFunction } from "./debug-id-upload";
import { releaseManagementPlugin } from "./plugins/release-management";
import { telemetryPlugin } from "./plugins/telemetry";
import { createLogger } from "./sentry/logger";
import { createLogger, Logger } from "./sentry/logger";
import { allowedToSendTelemetry, createSentryInstance } from "./sentry/telemetry";
import { Options, SentrySDKBuildFlags } from "./types";
import {
Expand All @@ -30,7 +30,7 @@ interface SentryUnpluginFactoryOptions {
releaseInjectionPlugin: (injectionCode: string) => UnpluginOptions;
componentNameAnnotatePlugin?: () => UnpluginOptions;
moduleMetadataInjectionPlugin?: (injectionCode: string) => UnpluginOptions;
debugIdInjectionPlugin: () => UnpluginOptions;
debugIdInjectionPlugin: (logger: Logger) => UnpluginOptions;
debugIdUploadPlugin: (upload: (buildArtifacts: string[]) => Promise<void>) => UnpluginOptions;
bundleSizeOptimizationsPlugin: (buildFlags: SentrySDKBuildFlags) => UnpluginOptions;
}
Expand Down Expand Up @@ -283,7 +283,7 @@ export function sentryUnpluginFactory({
);
}

plugins.push(debugIdInjectionPlugin());
plugins.push(debugIdInjectionPlugin(logger));

if (!options.authToken) {
logger.warn(
Expand Down Expand Up @@ -594,3 +594,4 @@ export function getDebugIdSnippet(debugId: string): string {
export { stringToUUID, replaceBooleanFlagsInCode } from "./utils";

export type { Options, SentrySDKBuildFlags } from "./types";
export type { Logger } from "./sentry/logger";
9 changes: 8 additions & 1 deletion packages/esbuild-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getDebugIdSnippet,
SentrySDKBuildFlags,
} from "@sentry/bundler-plugin-core";
import type { Logger } from "@sentry/bundler-plugin-core";
import type { UnpluginOptions } from "unplugin";
import * as path from "path";

Expand Down Expand Up @@ -41,7 +42,7 @@ function esbuildReleaseInjectionPlugin(injectionCode: string): UnpluginOptions {
};
}

function esbuildDebugIdInjectionPlugin(): UnpluginOptions {
function esbuildDebugIdInjectionPlugin(logger: Logger): UnpluginOptions {
const pluginName = "sentry-esbuild-debug-id-injection-plugin";
const stubNamespace = "sentry-debug-id-stub";

Expand All @@ -50,6 +51,12 @@ function esbuildDebugIdInjectionPlugin(): UnpluginOptions {

esbuild: {
setup({ initialOptions, onLoad, onResolve }) {
if (initialOptions.bundle) {
logger.warn(
"Esbuild's `bundle: true` option is currently not supported! Esbuild will probably crash now. Sorry about that. If you need to upload sourcemaps with the `bundle` option, it is recommended to use Sentry CLI instead: https://docs.sentry.io/platforms/javascript/sourcemaps/uploading/cli/"
);
}

onResolve({ filter: /.*/ }, (args) => {
if (args.kind !== "entry-point") {
return;
Expand Down