Skip to content

Commit ce76a0b

Browse files
fix(metro): Remove sentry-internal/replay package on demand (#4774)
1 parent f8fa2ad commit ce76a0b

File tree

3 files changed

+53
-50
lines changed

3 files changed

+53
-50
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
### Fixes
1212

1313
- Export `extraErrorDataIntegration` from `@sentry/core` ([#4762](https://github.com/getsentry/sentry-react-native/pull/4762))
14+
- Remove `@sentry-internal/replay` when `includeWebReplay: false` ([#4774](https://github.com/getsentry/sentry-react-native/pull/4774))
1415

1516
### Dependencies
1617

packages/core/src/js/tools/metroconfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ export function withSentryResolver(config: MetroConfig, includeWebReplay: boolea
212212
if (
213213
(includeWebReplay === false ||
214214
(includeWebReplay === undefined && (platform === 'android' || platform === 'ios'))) &&
215-
(oldMetroModuleName ?? moduleName).includes('@sentry/replay')
215+
!!(oldMetroModuleName ?? moduleName).match(/@sentry(?:-internal)?\/replay/)
216216
) {
217217
return { type: 'empty' } as Resolution;
218218
}

packages/core/test/tools/metroconfig.test.ts

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -169,72 +169,74 @@ describe('metroconfig', () => {
169169
}));
170170
});
171171

172-
test('keep Web Replay when platform is web and includeWebReplay is true', () => {
173-
const modifiedConfig = withSentryResolver(config, true);
174-
resolveRequest(modifiedConfig, contextMock, '@sentry/replay', 'web');
172+
describe.each([['@sentry/replay'], ['@sentry-internal/replay']])('with %s', replayPackage => {
173+
test('keep Web Replay when platform is web and includeWebReplay is true', () => {
174+
const modifiedConfig = withSentryResolver(config, true);
175+
resolveRequest(modifiedConfig, contextMock, replayPackage, 'web');
175176

176-
ExpectToBeCalledWithMetroParameters(originalResolverMock, contextMock, '@sentry/replay', 'web');
177-
});
177+
ExpectToBeCalledWithMetroParameters(originalResolverMock, contextMock, replayPackage, 'web');
178+
});
178179

179-
test('removes Web Replay when platform is web and includeWebReplay is false', () => {
180-
const modifiedConfig = withSentryResolver(config, false);
181-
const result = resolveRequest(modifiedConfig, contextMock, '@sentry/replay', 'web');
180+
test('removes Web Replay when platform is web and includeWebReplay is false', () => {
181+
const modifiedConfig = withSentryResolver(config, false);
182+
const result = resolveRequest(modifiedConfig, contextMock, replayPackage, 'web');
182183

183-
expect(result).toEqual({ type: 'empty' });
184-
expect(originalResolverMock).not.toHaveBeenCalled();
185-
});
184+
expect(result).toEqual({ type: 'empty' });
185+
expect(originalResolverMock).not.toHaveBeenCalled();
186+
});
186187

187-
test('keep Web Replay when platform is android and includeWebReplay is true', () => {
188-
const modifiedConfig = withSentryResolver(config, true);
189-
resolveRequest(modifiedConfig, contextMock, '@sentry/replay', 'android');
188+
test('keep Web Replay when platform is android and includeWebReplay is true', () => {
189+
const modifiedConfig = withSentryResolver(config, true);
190+
resolveRequest(modifiedConfig, contextMock, replayPackage, 'android');
190191

191-
ExpectToBeCalledWithMetroParameters(originalResolverMock, contextMock, '@sentry/replay', 'android');
192-
});
192+
ExpectToBeCalledWithMetroParameters(originalResolverMock, contextMock, replayPackage, 'android');
193+
});
193194

194-
test('removes Web Replay when platform is android and includeWebReplay is false', () => {
195-
const modifiedConfig = withSentryResolver(config, false);
196-
const result = resolveRequest(modifiedConfig, contextMock, '@sentry/replay', 'android');
195+
test('removes Web Replay when platform is android and includeWebReplay is false', () => {
196+
const modifiedConfig = withSentryResolver(config, false);
197+
const result = resolveRequest(modifiedConfig, contextMock, replayPackage, 'android');
197198

198-
expect(result).toEqual({ type: 'empty' });
199-
expect(originalResolverMock).not.toHaveBeenCalled();
200-
});
199+
expect(result).toEqual({ type: 'empty' });
200+
expect(originalResolverMock).not.toHaveBeenCalled();
201+
});
201202

202-
test('removes Web Replay when platform is android and includeWebReplay is undefined', () => {
203-
const modifiedConfig = withSentryResolver(config, undefined);
204-
const result = resolveRequest(modifiedConfig, contextMock, '@sentry/replay', 'android');
203+
test('removes Web Replay when platform is android and includeWebReplay is undefined', () => {
204+
const modifiedConfig = withSentryResolver(config, undefined);
205+
const result = resolveRequest(modifiedConfig, contextMock, replayPackage, 'android');
205206

206-
expect(result).toEqual({ type: 'empty' });
207-
expect(originalResolverMock).not.toHaveBeenCalled();
208-
});
207+
expect(result).toEqual({ type: 'empty' });
208+
expect(originalResolverMock).not.toHaveBeenCalled();
209+
});
209210

210-
test('keep Web Replay when platform is undefined and includeWebReplay is null', () => {
211-
const modifiedConfig = withSentryResolver(config, undefined);
212-
resolveRequest(modifiedConfig, contextMock, '@sentry/replay', null);
211+
test('keep Web Replay when platform is undefined and includeWebReplay is null', () => {
212+
const modifiedConfig = withSentryResolver(config, undefined);
213+
resolveRequest(modifiedConfig, contextMock, replayPackage, null);
213214

214-
ExpectToBeCalledWithMetroParameters(originalResolverMock, contextMock, '@sentry/replay', null);
215-
});
215+
ExpectToBeCalledWithMetroParameters(originalResolverMock, contextMock, replayPackage, null);
216+
});
216217

217-
test('keep Web Replay when platform is ios and includeWebReplay is true', () => {
218-
const modifiedConfig = withSentryResolver(config, true);
219-
resolveRequest(modifiedConfig, contextMock, '@sentry/replay', 'ios');
218+
test('keep Web Replay when platform is ios and includeWebReplay is true', () => {
219+
const modifiedConfig = withSentryResolver(config, true);
220+
resolveRequest(modifiedConfig, contextMock, replayPackage, 'ios');
220221

221-
ExpectToBeCalledWithMetroParameters(originalResolverMock, contextMock, '@sentry/replay', 'ios');
222-
});
222+
ExpectToBeCalledWithMetroParameters(originalResolverMock, contextMock, replayPackage, 'ios');
223+
});
223224

224-
test('removes Web Replay when platform is ios and includeWebReplay is false', () => {
225-
const modifiedConfig = withSentryResolver(config, false);
226-
const result = resolveRequest(modifiedConfig, contextMock, '@sentry/replay', 'ios');
225+
test('removes Web Replay when platform is ios and includeWebReplay is false', () => {
226+
const modifiedConfig = withSentryResolver(config, false);
227+
const result = resolveRequest(modifiedConfig, contextMock, replayPackage, 'ios');
227228

228-
expect(result).toEqual({ type: 'empty' });
229-
expect(originalResolverMock).not.toHaveBeenCalled();
230-
});
229+
expect(result).toEqual({ type: 'empty' });
230+
expect(originalResolverMock).not.toHaveBeenCalled();
231+
});
231232

232-
test('removes Web Replay when platform is ios and includeWebReplay is undefined', () => {
233-
const modifiedConfig = withSentryResolver(config, undefined);
234-
const result = resolveRequest(modifiedConfig, contextMock, '@sentry/replay', 'ios');
233+
test('removes Web Replay when platform is ios and includeWebReplay is undefined', () => {
234+
const modifiedConfig = withSentryResolver(config, undefined);
235+
const result = resolveRequest(modifiedConfig, contextMock, replayPackage, 'ios');
235236

236-
expect(result).toEqual({ type: 'empty' });
237-
expect(originalResolverMock).not.toHaveBeenCalled();
237+
expect(result).toEqual({ type: 'empty' });
238+
expect(originalResolverMock).not.toHaveBeenCalled();
239+
});
238240
});
239241

240242
test('calls originalResolver when moduleName is not @sentry/replay', () => {

0 commit comments

Comments
 (0)