Skip to content

Commit 11caf99

Browse files
logaretmclaude
andcommitted
ref(nitro): Use BuildTimeOptionsBase for SentryNitroOptions type
Derive `SentryNitroOptions` from `BuildTimeOptionsBase` (from `@sentry/core`) instead of picking from the bundler plugin's internal `Options` type. This provides a stable public API that follows this repo's semver, rather than exposing bundler-plugin-specific fields like `_metaOptions` and top-level `disable`. Key changes: - `url` option renamed to `sentryUrl` (consistent with other SDKs) - Top-level `disable` removed (use `sourcemaps.disable` instead) - `_metaOptions` no longer user-configurable Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent dfdfecd commit 11caf99

File tree

3 files changed

+17
-44
lines changed

3 files changed

+17
-44
lines changed

packages/nitro/src/config.ts

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
1-
import type { Options as SentryBundlerPluginOptions } from '@sentry/bundler-plugin-core';
1+
import type { BuildTimeOptionsBase } from '@sentry/core';
22
import type { NitroConfig } from 'nitro/types';
33
import { createNitroModule } from './module';
44
import { configureSourcemapSettings } from './sourceMaps';
55

6-
export type SentryNitroOptions = Pick<
7-
SentryBundlerPluginOptions,
8-
| 'org'
9-
| 'project'
10-
| 'authToken'
11-
| 'url'
12-
| 'headers'
13-
| 'debug'
14-
| 'silent'
15-
| 'errorHandler'
16-
| 'telemetry'
17-
| 'disable'
18-
| 'sourcemaps'
19-
| 'release'
20-
| 'bundleSizeOptimizations'
21-
| '_metaOptions'
22-
>;
6+
export type SentryNitroOptions = BuildTimeOptionsBase;
237

248
/**
259
* Modifies the passed in Nitro configuration with automatic build-time instrumentation.

packages/nitro/src/sourceMaps.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Options } from '@sentry/bundler-plugin-core';
1+
import type { Options as BundlerPluginOptions } from '@sentry/bundler-plugin-core';
22
import { createSentryBuildPluginManager } from '@sentry/bundler-plugin-core';
33
import { debug } from '@sentry/core';
44
import type { Nitro, NitroConfig } from 'nitro/types';
@@ -15,7 +15,7 @@ export function setupSourceMaps(nitro: Nitro, options?: SentryNitroOptions): voi
1515
}
1616

1717
// Respect user's explicit disable
18-
if (options?.sourcemaps?.disable === true || options?.disable === true) {
18+
if (options?.sourcemaps?.disable === true) {
1919
return;
2020
}
2121

@@ -62,12 +62,12 @@ function normalizePath(path: string): string {
6262
*
6363
* Only exported for testing purposes.
6464
*/
65-
export function getPluginOptions(options?: SentryNitroOptions): Options {
65+
export function getPluginOptions(options?: SentryNitroOptions): BundlerPluginOptions {
6666
return {
6767
org: options?.org ?? process.env.SENTRY_ORG,
6868
project: options?.project ?? process.env.SENTRY_PROJECT,
6969
authToken: options?.authToken ?? process.env.SENTRY_AUTH_TOKEN,
70-
url: options?.url ?? process.env.SENTRY_URL,
70+
url: options?.sentryUrl ?? process.env.SENTRY_URL,
7171
headers: options?.headers,
7272
telemetry: options?.telemetry ?? true,
7373
debug: options?.debug ?? false,
@@ -86,7 +86,6 @@ export function getPluginOptions(options?: SentryNitroOptions): Options {
8686
telemetry: {
8787
metaFramework: 'nitro',
8888
},
89-
...options?._metaOptions,
9089
},
9190
};
9291
}
@@ -95,7 +94,7 @@ export function getPluginOptions(options?: SentryNitroOptions): Options {
9594
* Configures the Nitro config to enable source map generation.
9695
*/
9796
export function configureSourcemapSettings(config: NitroConfig, moduleOptions?: SentryNitroOptions): void {
98-
const sourcemapUploadDisabled = moduleOptions?.sourcemaps?.disable === true || moduleOptions?.disable === true;
97+
const sourcemapUploadDisabled = moduleOptions?.sourcemaps?.disable === true;
9998
if (sourcemapUploadDisabled) {
10099
return;
101100
}

packages/nitro/test/sourceMaps.test.ts

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,31 @@ describe('getPluginOptions', () => {
5656
expect(options.org).toBe('env-org');
5757
expect(options.project).toBe('env-project');
5858
expect(options.authToken).toBe('env-token');
59-
expect(options.url).toBe('https://custom.sentry.io');
59+
expect(options.url).toBe('https://custom.sentry.io'); // sentryUrl maps to url
6060
});
6161

6262
it('prefers direct options over environment variables', () => {
6363
process.env.SENTRY_ORG = 'env-org';
6464
process.env.SENTRY_AUTH_TOKEN = 'env-token';
65+
process.env.SENTRY_URL = 'https://env.sentry.io';
6566

6667
const options = getPluginOptions({
6768
org: 'direct-org',
6869
authToken: 'direct-token',
70+
sentryUrl: 'https://direct.sentry.io',
6971
});
7072

7173
expect(options.org).toBe('direct-org');
7274
expect(options.authToken).toBe('direct-token');
75+
expect(options.url).toBe('https://direct.sentry.io');
7376
});
7477

7578
it('passes through all user options', () => {
7679
const sentryOptions: SentryNitroOptions = {
7780
org: 'my-org',
7881
project: 'my-project',
7982
authToken: 'my-token',
80-
url: 'https://my-sentry.io',
83+
sentryUrl: 'https://my-sentry.io',
8184
headers: { 'X-Custom': 'header' },
8285
debug: true,
8386
silent: true,
@@ -119,10 +122,9 @@ describe('getPluginOptions', () => {
119122
});
120123

121124
it('always sets metaFramework to nitro', () => {
122-
const options = getPluginOptions({ _metaOptions: { loggerPrefixOverride: '[custom]' } });
125+
const options = getPluginOptions();
123126

124127
expect(options._metaOptions?.telemetry?.metaFramework).toBe('nitro');
125-
expect(options._metaOptions?.loggerPrefixOverride).toBe('[custom]');
126128
});
127129

128130
it('passes through sourcemaps.disable', () => {
@@ -182,11 +184,11 @@ describe('configureSourcemapSettings', () => {
182184
expect(config.sourcemap).toBe(false);
183185
});
184186

185-
it('skips sourcemap config when disable is true', () => {
186-
const config: NitroConfig = { sourcemap: false };
187-
configureSourcemapSettings(config, { disable: true });
187+
it('still configures sourcemaps when sourcemaps.disable is disable-upload', () => {
188+
const config: NitroConfig = {};
189+
configureSourcemapSettings(config, { sourcemaps: { disable: 'disable-upload' } });
188190

189-
expect(config.sourcemap).toBe(false);
191+
expect(config.sourcemap).toBe(true);
190192
});
191193
});
192194

@@ -240,18 +242,6 @@ describe('setupSourceMaps', () => {
240242
expect(hookFn).not.toHaveBeenCalled();
241243
});
242244

243-
it('does not register hook when disable is true', () => {
244-
const hookFn = vi.fn();
245-
const nitro = {
246-
options: { dev: false, output: { serverDir: '/output/server' } },
247-
hooks: { hook: hookFn },
248-
} as any;
249-
250-
setupSourceMaps(nitro, { disable: true });
251-
252-
expect(hookFn).not.toHaveBeenCalled();
253-
});
254-
255245
it('registers compiled hook in production mode', () => {
256246
const hookFn = vi.fn();
257247
const nitro = {

0 commit comments

Comments
 (0)