Skip to content

Commit 1b4d764

Browse files
authored
fix(metro): Fixes Metro 0.83.2 breakages (#5206)
* Fixes baseJSBundle resolution * Fixes bundleToString resolution * Temporarily set SENTRY_DISABLE_AUTO_UPLOAD to true * Add changelog * Revert "Temporarily set SENTRY_DISABLE_AUTO_UPLOAD to true" (#5209) This reverts commit 985e404.
1 parent a061528 commit 1b4d764

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
### Fixes
1717

1818
- Vendor `metro/countLines` function to avoid issues with the private import ([#5185](https://github.com/getsentry/sentry-react-native/pull/5185))
19+
- Fix baseJSBundle and bundleToString TypeErrors with Metro 0.83.2 ([#5206](https://github.com/getsentry/sentry-react-native/pull/5206))
1920

2021
## 7.1.0
2122

packages/core/src/js/tools/vendor/metro/utils.ts

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,19 @@ import type * as sourceMapStringType from 'metro/private/DeltaBundler/Serializer
3131
import type * as bundleToStringType from 'metro/private/lib/bundleToString';
3232
import type { MetroSerializer } from '../../utils';
3333

34-
let baseJSBundle: typeof baseJSBundleType;
34+
let baseJSBundleModule: any;
3535
try {
36-
baseJSBundle = require('metro/private/DeltaBundler/Serializers/baseJSBundle');
37-
} catch (e) {
38-
baseJSBundle = require('metro/src/DeltaBundler/Serializers/baseJSBundle');
36+
baseJSBundleModule = require('metro/private/DeltaBundler/Serializers/baseJSBundle');
37+
} catch {
38+
baseJSBundleModule = require('metro/src/DeltaBundler/Serializers/baseJSBundle');
3939
}
4040

41+
const baseJSBundle: typeof baseJSBundleType =
42+
typeof baseJSBundleModule === 'function'
43+
? baseJSBundleModule
44+
: // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
45+
baseJSBundleModule?.baseJSBundle ?? baseJSBundleModule?.default;
46+
4147
let sourceMapString: typeof sourceMapStringType;
4248
try {
4349
// eslint-disable-next-line @typescript-eslint/no-var-requires
@@ -52,13 +58,19 @@ try {
5258
}
5359
}
5460

55-
let bundleToString: typeof bundleToStringType;
61+
let bundleToStringModule: any;
5662
try {
57-
bundleToString = require('metro/private/lib/bundleToString');
58-
} catch (e) {
59-
bundleToString = require('metro/src/lib/bundleToString');
63+
bundleToStringModule = require('metro/private/lib/bundleToString');
64+
} catch {
65+
bundleToStringModule = require('metro/src/lib/bundleToString');
6066
}
6167

68+
const bundleToString: typeof bundleToStringType =
69+
typeof bundleToStringModule === 'function'
70+
? bundleToStringModule
71+
: // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
72+
bundleToStringModule?.bundleToString ?? bundleToStringModule?.default;
73+
6274
type NewSourceMapStringExport = {
6375
// Since Metro v0.80.10 https://github.com/facebook/metro/compare/v0.80.9...v0.80.10#diff-1b836d1729e527a725305eef0cec22e44605af2700fa413f4c2489ea1a03aebcL28
6476
sourceMapString: typeof sourceMapString;

0 commit comments

Comments
 (0)