Skip to content

Commit

Permalink
feat(astro): Add assets option to source maps upload options
Browse files Browse the repository at this point in the history
  • Loading branch information
Lms24 committed Nov 27, 2023
1 parent 97e04a0 commit f68fb96
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/astro/src/integration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
authToken: uploadOptions.authToken ?? env.SENTRY_AUTH_TOKEN,
telemetry: uploadOptions.telemetry ?? true,
sourcemaps: {
assets: [getSourcemapsAssetsGlob(config)],
assets: uploadOptions.assets ?? [getSourcemapsAssetsGlob(config)],
},
debug: options.debug ?? false,
}),
Expand Down
12 changes: 12 additions & 0 deletions packages/astro/src/integration/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ type SourceMapsOptions = {
* @default true
*/
telemetry?: boolean;

/**
* A glob or an array of globs that specify the build artifacts and source maps that will uploaded to Sentry.
*
* If this option is not specified, sensible defaults based on your `outDir`, `rootDir` and `adapter`
* config will be used. Use this option to override these defaults, for instance if you have a
* customized build setup that diverges from Astro's defaults.
*
* The globbing patterns must follow the implementation of the `glob` package.
* @see https://www.npmjs.com/package/glob#glob-primer
*/
assets?: string | Array<string>;
};
};

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

it('prefers user-specified assets-globs over the default values', async () => {
const integration = sentryAstro({
sourceMapsUploadOptions: {
enabled: true,
org: 'my-org',
project: 'my-project',
assets: ['dist/server/**/*, dist/client/**/*'],
},
});
// @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({
authToken: 'my-token',
org: 'my-org',
project: 'my-project',
telemetry: true,
debug: false,
sourcemaps: {
assets: ['dist/server/**/*, dist/client/**/*'],
},
});
});

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

0 comments on commit f68fb96

Please sign in to comment.