Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
### Fixes

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

## 7.1.0

Expand Down
28 changes: 20 additions & 8 deletions packages/core/src/js/tools/vendor/metro/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,19 @@ import type * as sourceMapStringType from 'metro/private/DeltaBundler/Serializer
import type * as bundleToStringType from 'metro/private/lib/bundleToString';
import type { MetroSerializer } from '../../utils';

let baseJSBundle: typeof baseJSBundleType;
let baseJSBundleModule: any;
try {
baseJSBundle = require('metro/private/DeltaBundler/Serializers/baseJSBundle');
} catch (e) {
baseJSBundle = require('metro/src/DeltaBundler/Serializers/baseJSBundle');
baseJSBundleModule = require('metro/private/DeltaBundler/Serializers/baseJSBundle');
} catch {
baseJSBundleModule = require('metro/src/DeltaBundler/Serializers/baseJSBundle');
}

const baseJSBundle: typeof baseJSBundleType =
typeof baseJSBundleModule === 'function'
? baseJSBundleModule
: // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
baseJSBundleModule?.baseJSBundle ?? baseJSBundleModule?.default;

let sourceMapString: typeof sourceMapStringType;
try {
// eslint-disable-next-line @typescript-eslint/no-var-requires
Expand All @@ -52,13 +58,19 @@ try {
}
}

let bundleToString: typeof bundleToStringType;
let bundleToStringModule: any;
try {
bundleToString = require('metro/private/lib/bundleToString');
} catch (e) {
bundleToString = require('metro/src/lib/bundleToString');
bundleToStringModule = require('metro/private/lib/bundleToString');
} catch {
bundleToStringModule = require('metro/src/lib/bundleToString');
}

const bundleToString: typeof bundleToStringType =
typeof bundleToStringModule === 'function'
? bundleToStringModule
: // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
bundleToStringModule?.bundleToString ?? bundleToStringModule?.default;

type NewSourceMapStringExport = {
// Since Metro v0.80.10 https://github.com/facebook/metro/compare/v0.80.9...v0.80.10#diff-1b836d1729e527a725305eef0cec22e44605af2700fa413f4c2489ea1a03aebcL28
sourceMapString: typeof sourceMapString;
Expand Down
Loading