File tree Expand file tree Collapse file tree 3 files changed +47
-3
lines changed Expand file tree Collapse file tree 3 files changed +47
-3
lines changed Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ export const sentryAstro = (options: SentryOptions = {}): AstroIntegration => {
4242 authToken : uploadOptions . authToken ?? env . SENTRY_AUTH_TOKEN ,
4343 telemetry : uploadOptions . telemetry ?? true ,
4444 sourcemaps : {
45- assets : [ getSourcemapsAssetsGlob ( config ) ] ,
45+ assets : uploadOptions . assets ?? [ getSourcemapsAssetsGlob ( config ) ] ,
4646 } ,
4747 debug : options . debug ?? false ,
4848 } ) ,
@@ -106,13 +106,13 @@ function getSourcemapsAssetsGlob(config: AstroConfig): string {
106106 // only copied over to <root>/.vercel. This seems to happen too late though.
107107 // So we glob on both of these directories.
108108 // Another case of "it ain't pretty but it works":(
109- if ( config . adapter && config . adapter . name ?. startsWith ( '@astrojs/vercel' ) ) {
109+ if ( config . adapter ? .name ?. startsWith ( '@astrojs/vercel' ) ) {
110110 return '{.vercel,dist}/**/*' ;
111111 }
112112
113113 // paths are stored as "file://" URLs
114114 const outDirPathname = config . outDir && path . resolve ( config . outDir . pathname ) ;
115- const rootDirName = path . resolve ( ( config . root && config . root . pathname ) || process . cwd ( ) ) ;
115+ const rootDirName = path . resolve ( config . root ?. pathname || process . cwd ( ) ) ;
116116
117117 if ( outDirPathname ) {
118118 const relativePath = path . relative ( rootDirName , outDirPathname ) ;
Original file line number Diff line number Diff line change @@ -68,6 +68,18 @@ type SourceMapsOptions = {
6868 * @default true
6969 */
7070 telemetry ?: boolean ;
71+
72+ /**
73+ * A glob or an array of globs that specify the build artifacts and source maps that will uploaded to Sentry.
74+ *
75+ * If this option is not specified, sensible defaults based on your `outDir`, `rootDir` and `adapter`
76+ * config will be used. Use this option to override these defaults, for instance if you have a
77+ * customized build setup that diverges from Astro's defaults.
78+ *
79+ * The globbing patterns must follow the implementation of the `glob` package.
80+ * @see https://www.npmjs.com/package/glob#glob-primer
81+ */
82+ assets ?: string | Array < string > ;
7183 } ;
7284} ;
7385
Original file line number Diff line number Diff line change @@ -110,6 +110,38 @@ describe('sentryAstro integration', () => {
110110 } ) ;
111111 } ) ;
112112
113+ it ( 'prefers user-specified assets-globs over the default values' , async ( ) => {
114+ const integration = sentryAstro ( {
115+ sourceMapsUploadOptions : {
116+ enabled : true ,
117+ org : 'my-org' ,
118+ project : 'my-project' ,
119+ assets : [ 'dist/server/**/*, dist/client/**/*' ] ,
120+ } ,
121+ } ) ;
122+ // @ts -expect-error - the hook exists and we only need to pass what we actually use
123+ await integration . hooks [ 'astro:config:setup' ] ( {
124+ updateConfig,
125+ injectScript,
126+ // @ts -expect-error - only passing in partial config
127+ config : {
128+ outDir : new URL ( 'file://path/to/project/build' ) ,
129+ } ,
130+ } ) ;
131+
132+ expect ( sentryVitePluginSpy ) . toHaveBeenCalledTimes ( 1 ) ;
133+ expect ( sentryVitePluginSpy ) . toHaveBeenCalledWith ( {
134+ authToken : 'my-token' ,
135+ org : 'my-org' ,
136+ project : 'my-project' ,
137+ telemetry : true ,
138+ debug : false ,
139+ sourcemaps : {
140+ assets : [ 'dist/server/**/*, dist/client/**/*' ] ,
141+ } ,
142+ } ) ;
143+ } ) ;
144+
113145 it ( "doesn't enable source maps if `sourceMapsUploadOptions.enabled` is `false`" , async ( ) => {
114146 const integration = sentryAstro ( {
115147 sourceMapsUploadOptions : { enabled : false } ,
You can’t perform that action at this time.
0 commit comments