Skip to content

Commit

Permalink
fix(metro): Fix sourceMapString is not a function, support [email protected]
Browse files Browse the repository at this point in the history
….10 (see #4004)
  • Loading branch information
antonis committed Sep 19, 2024
1 parent df8f408 commit a0e0d80
Show file tree
Hide file tree
Showing 4 changed files with 19,533 additions and 14,387 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Fixes

- Support `[email protected]` new `sourceMapString` export ([#4004](https://github.com/getsentry/sentry-react-native/pull/4004))

### Dependencies

- Bump Cocoa SDK from v8.29.1 to v8.36.0 ([#4102](https://github.com/getsentry/sentry-react-native/pull/4102))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"jest-environment-jsdom": "^29.6.2",
"jest-extended": "^4.0.2",
"madge": "^6.1.0",
"metro": "0.76",
"metro": "0.80.10",
"prettier": "^2.0.5",
"react": "18.2.0",
"react-native": "0.73.2",
Expand Down
24 changes: 23 additions & 1 deletion src/js/tools/vendor/metro/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ import * as bundleToString from 'metro/src/lib/bundleToString';

import type { MetroSerializer } from '../../utils';

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

/**
* This function ensures that modules in source maps are sorted in the same
* order as in a plain JS bundle.
Expand Down Expand Up @@ -75,8 +80,25 @@ export const createDefaultMetroSerializer = (): MetroSerializer => {
return code;
}

let sourceMapStringFunction: typeof sourceMapString | undefined;
if (typeof sourceMapString === 'function') {
sourceMapStringFunction = sourceMapString;
} else if (
typeof sourceMapString === 'object' &&
sourceMapString != null &&
'sourceMapString' in sourceMapString &&
typeof sourceMapString['sourceMapString'] === 'function'
) {
sourceMapStringFunction = (sourceMapString as NewSourceMapStringExport).sourceMapString;
} else {
throw new Error(`
[@sentry/react-native/metro] Cannot find sourceMapString function in 'metro/src/DeltaBundler/Serializers/sourceMapString'.
Please check the version of Metro you are using and report the issue at http://www.github.com/getsentry/sentry-react-native/issues
`);
}

// Always generate source maps, can't use Sentry without source maps
const map = sourceMapString([...preModules, ...getSortedModules(graph, options)], {
const map = sourceMapStringFunction([...preModules, ...getSortedModules(graph, options)], {
processModuleFilter: options.processModuleFilter,
shouldAddToIgnoreList: options.shouldAddToIgnoreList,
});
Expand Down
Loading

0 comments on commit a0e0d80

Please sign in to comment.