Skip to content

Commit

Permalink
misc(esbuild): Log warning when attempting to inject debug IDs with e…
Browse files Browse the repository at this point in the history
…sbuild `bundle` option active (#526)
  • Loading branch information
lforst committed May 3, 2024
1 parent 295fa19 commit fd2a99c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
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 @@ -281,7 +281,7 @@ export function sentryUnpluginFactory({
);
}

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

if (!options.authToken) {
logger.warn(
Expand Down Expand Up @@ -592,3 +592,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

0 comments on commit fd2a99c

Please sign in to comment.