Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion packages/astro/src/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
};

const sourceMapsNeeded = sdkEnabled.client || sdkEnabled.server;
const uploadOptions = options.sourceMapsUploadOptions || {};
const { unstable_sentryVitePluginOptions, ...uploadOptions } = options.sourceMapsUploadOptions || {};
const shouldUploadSourcemaps = (sourceMapsNeeded && uploadOptions?.enabled) ?? true;

// We don't need to check for AUTH_TOKEN here, because the plugin will pick it up from the env
Expand Down Expand Up @@ -85,6 +85,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
},
},
debug: options.debug ?? false,
...unstable_sentryVitePluginOptions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory we need to spread this into all of the sub-options to be correct. Similar to how we do it here:

...sentryBuildOptions.unstable_sentryWebpackPluginOptions?.reactComponentAnnotation,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done: 15198e3 (#15638)

Btw. I'm not sure if the nextjs package spreads into sub-options correctly. It looks to me like at the end, it overwrites them anyway:

...sentryBuildOptions.unstable_sentryWebpackPluginOptions,

It looks like there is no test that would test a scenario with unstable_sentryWebpackPluginOptions set 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I think you're right. Thanks for catching that. I'll fix that in a follow-up 👍

}),
),
],
Expand Down
15 changes: 15 additions & 0 deletions packages/astro/src/integration/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { BrowserOptions } from '@sentry/browser';
import type { Options } from '@sentry/core';
import type { SentryVitePluginOptions } from '@sentry/vite-plugin';

type SdkInitPaths = {
/**
Expand Down Expand Up @@ -83,6 +84,20 @@ type SourceMapsOptions = {
* The globbing patterns follow the implementation of the glob package. (https://www.npmjs.com/package/glob)
*/
filesToDeleteAfterUpload?: string | Array<string>;

/**
* Options to further customize the Sentry Vite Plugin (@sentry/vite-plugin) behavior directly.
* Options specified in this object take precedence over all other options.
*
* @see https://www.npmjs.com/package/@sentry/vite-plugin/v/2.14.2#options which lists all available options.
*
* Warning: Options within this object are subject to change at any time.
* We DO NOT guarantee semantic versioning for these options, meaning breaking
* changes can occur at any time within a major SDK version.
*
* Furthermore, some options are untested with Astro specifically. Use with caution.
*/
unstable_sentryVitePluginOptions?: Partial<SentryVitePluginOptions>
};

type BundleSizeOptimizationOptions = {
Expand Down
45 changes: 45 additions & 0 deletions packages/astro/test/integration/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,51 @@ describe('sentryAstro integration', () => {
);
});

it('prefers user-specified unstable vite plugin options over everything else', async () => {
const integration = sentryAstro({
sourceMapsUploadOptions: {
enabled: true,
org: 'my-org',
project: 'my-project',
assets: ['dist/server/**/*, dist/client/**/*'],
debug: true,
unstable_sentryVitePluginOptions: {
org: 'my-other-org',
project: 'my-other-project',
applicationKey: 'my-application-key',
debug: false,
sourcemaps: {
assets: ['foo/*.js'],
ignore: ['bar/*.js'],
},
}
},
});
// @ts-expect-error - the hook exists, and we only need to pass what we actually use
await integration.hooks['astro:config:setup']({
updateConfig,
injectScript,
// @ts-expect-error - only passing in partial config
config: {
outDir: new URL('file://path/to/project/build'),
},
});

expect(sentryVitePluginSpy).toHaveBeenCalledTimes(1);
expect(sentryVitePluginSpy).toHaveBeenCalledWith(
expect.objectContaining({
org: 'my-other-org',
project: 'my-other-project',
applicationKey: 'my-application-key',
debug: false,
sourcemaps: {
assets: ['foo/*.js'],
ignore: ['bar/*.js'],
},
}),
);
});

it("doesn't enable source maps if `sourceMapsUploadOptions.enabled` is `false`", async () => {
const integration = sentryAstro({
sourceMapsUploadOptions: { enabled: false },
Expand Down
Loading