-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix(nuxt): Add @sentry/nuxt
as external in Rollup
#16407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import { consoleSandbox } from '@sentry/core'; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import type { ExternalOption } from 'rollup'; | ||
|
||
/** | ||
* Find the default SDK init file for the given type (client or server). | ||
|
@@ -52,6 +53,37 @@ export function removeSentryQueryFromPath(url: string): string { | |
return url.replace(regex, ''); | ||
} | ||
|
||
/** | ||
* Add @sentry/nuxt to the external options of the Rollup configuration to prevent Rollup bundling all dependencies | ||
* that would result in adding imports from OpenTelemetry libraries etc. to the server build. | ||
*/ | ||
export function getExternalOptionsWithSentryNuxt(previousExternal: ExternalOption | undefined): ExternalOption { | ||
const sentryExternals = [/^@sentry\/nuxt$/]; | ||
let external: ExternalOption; | ||
|
||
if (typeof previousExternal === 'function') { | ||
external = new Proxy(previousExternal, { | ||
apply(target, thisArg, args: [string, string | undefined, boolean]) { | ||
const [source] = args; | ||
if ( | ||
sentryExternals.some(external => (typeof external === 'string' ? source === external : external.test(source))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. l: Are we ever expecting more than one external here? The comment and function name make it sound like it's always only going to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. true, I had 'import-in-the-middle' added to the array at first as well. But as this is actually not necessary, I can remove it 👍 |
||
) { | ||
return true; | ||
} | ||
return Reflect.apply(target, thisArg, args); | ||
}, | ||
}); | ||
} else if (Array.isArray(previousExternal)) { | ||
external = [...sentryExternals, ...previousExternal]; | ||
} else if (previousExternal) { | ||
external = [...sentryExternals, previousExternal]; | ||
} else { | ||
external = sentryExternals; | ||
} | ||
|
||
return external; | ||
} | ||
|
||
/** | ||
* Extracts and sanitizes function re-export and function wrap query parameters from a query string. | ||
* If it is a default export, it is not considered for re-exporting. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
l: Technically, I don't think this needs to be an array at all, right? Just thinking that the
.some
call below as well as the object spreads are kinda unnecessary if we only have one element in the array (in the sense of a slight perf overhead as well as code readability).(I read Andrei's comment, so feel free to ignore this if I happen to review in an in-between state 😅)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lms24 simplified.