-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(browser): Include Spotlight in development bundles #18078
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
base: develop
Are you sure you want to change the base?
Changes from 9 commits
4805008
aae7360
18d31e5
84ff77d
92bc9f6
1cb7253
eb515c4
e72bc89
83b3890
8fff1ab
2c86f37
0e52d5e
9fc0f3f
c48144c
7229c7a
eb3e548
5202eec
51c05d2
4ea4e31
5d2f9ec
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 |
|---|---|---|
|
|
@@ -125,6 +125,24 @@ export function makeDebugBuildStatementReplacePlugin() { | |
| }); | ||
| } | ||
|
|
||
| export function makeProductionReplacePlugin() { | ||
| const pattern = /\/\* rollup-include-development-only \*\/[\s\S]*?\/\* rollup-include-development-only-end \*\/\s*/g; | ||
|
Member
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. Not very confident about using regex here. I'm guessing AST based operation is either unavailable or more expensive?
Member
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. Are you okay me exploring rollup-plugin-define or Vite (which uses rolldown under the hood which should be fully compatible with rollup) that has the define feature built-in: https://vite.dev/config/#using-environment-variables-in-config Once we do that, we can set NODE_ENV to development or production based on the build, and use regular if blocks rather than surround the code with magic comments. These if blocks will have a static condition at build time which will then be optimized (stripped out or unwrapped) via terser or whatever minified/optimizer we are using.
Collaborator
Author
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. When building the SDK npm module, we preserve the individual files (ie. This is why I went this route vs replace/define plugins. |
||
|
|
||
| function stripDevBlocks(code) { | ||
| if (!code) return null; | ||
| if (!code.includes('rollup-include-development-only')) return null; | ||
| const replaced = code.replace(pattern, ''); | ||
| return { code: replaced, map: null }; | ||
| } | ||
timfish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return { | ||
| name: 'remove-dev-mode-blocks', | ||
| renderChunk(code) { | ||
| return stripDevBlocks(code); | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a plugin to replace build flags of rrweb with either a constant (if passed true/false) or with a safe statement that: | ||
| * a) evaluates to `true` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,4 +16,5 @@ export default makeNPMConfigVariants( | |
| }, | ||
| }, | ||
| }), | ||
| { splitDevProd: true }, | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import { browserSessionIntegration } from './integrations/browsersession'; | |
| import { globalHandlersIntegration } from './integrations/globalhandlers'; | ||
| import { httpContextIntegration } from './integrations/httpcontext'; | ||
| import { linkedErrorsIntegration } from './integrations/linkederrors'; | ||
| import { spotlightBrowserIntegration } from './integrations/spotlight'; | ||
timfish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import { defaultStackParser } from './stack-parsers'; | ||
| import { makeFetchTransport } from './transports/fetch'; | ||
| import { checkAndWarnIfIsEmbeddedBrowserExtension } from './utils/detectBrowserExtension'; | ||
|
|
@@ -90,14 +91,26 @@ export function init(options: BrowserOptions = {}): Client | undefined { | |
| const shouldDisableBecauseIsBrowserExtenstion = | ||
| !options.skipBrowserExtensionCheck && checkAndWarnIfIsEmbeddedBrowserExtension(); | ||
|
|
||
| let defaultIntegrations = | ||
| options.defaultIntegrations == null ? getDefaultIntegrations(options) : options.defaultIntegrations; | ||
|
|
||
| /* rollup-include-development-only */ | ||
| if (options.spotlight) { | ||
|
Member
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. How hard would it be to fill this value from the env variables? I'm okay with trying all variants like Happy to do this in a follow up too.
Collaborator
Author
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. Yeah probably best in a follow up PR. If we can keep it between the magic comments it'll all get striped out! |
||
| if (!defaultIntegrations) { | ||
| defaultIntegrations = []; | ||
| } | ||
| const args = typeof options.spotlight === 'string' ? { sidecarUrl: options.spotlight } : undefined; | ||
| defaultIntegrations.push(spotlightBrowserIntegration(args)); | ||
| } | ||
timfish marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /* rollup-include-development-only-end */ | ||
|
|
||
| const clientOptions: BrowserClientOptions = { | ||
| ...options, | ||
| enabled: shouldDisableBecauseIsBrowserExtenstion ? false : options.enabled, | ||
| stackParser: stackParserFromStackParserOptions(options.stackParser || defaultStackParser), | ||
| integrations: getIntegrationsToSetup({ | ||
| integrations: options.integrations, | ||
| defaultIntegrations: | ||
| options.defaultIntegrations == null ? getDefaultIntegrations(options) : options.defaultIntegrations, | ||
| defaultIntegrations, | ||
| }), | ||
| transport: options.transport || makeFetchTransport, | ||
| }; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.