Skip to content

Commit f99ea8a

Browse files
fix(metro): Conditionally use Set or CountingSet in Sentry Metro plugin (#3409)
1 parent 0c20c6c commit f99ea8a

File tree

6 files changed

+44
-3
lines changed

6 files changed

+44
-3
lines changed

.github/workflows/e2e.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ jobs:
279279
--project ios/RnDiffApp.xcodeproj/project.pbxproj \
280280
--rn-version '${{ matrix.rn-version }}'
281281
282+
# This prevents modules resolution from outside of the RN Test App projects
283+
# during the native app build
284+
- name: Clean SDK node_modules
285+
run: rm -rf node_modules
286+
282287
- name: Build Android App
283288
if: ${{ matrix.platform == 'android' }}
284289
working-directory: test/react-native/versions/${{ matrix.rn-version }}/RnDiffApp/android

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
### Fixes
1010

11+
- Conditionally use Set or CountingSet in Sentry Metro plugin ([#3409](https://github.com/getsentry/sentry-react-native/pull/3409))
12+
- This makes sentryMetroSerializer compatible with Metro 0.66.2 and newer
1113
- Fix SIGSEV, SIGABRT and SIGBUS crashes happening after/around the August Google Play System update, see [#2955](https://github.com/getsentry/sentry-java/issues/2955) for more details
1214

1315
### Dependencies

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"@sentry/typescript": "^5.20.1",
7474
"@sentry/wizard": "3.16.3",
7575
"@types/jest": "^29.5.3",
76+
"@types/node": "^20.9.3",
7677
"@types/react": "^18.2.14",
7778
"@types/uglify-js": "^3.17.2",
7879
"@types/uuid": "^9.0.4",

src/js/tools/sentryMetroSerializer.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import * as crypto from 'crypto';
22
import type { MixedOutput, Module } from 'metro';
3-
import CountingSet from 'metro/src/lib/CountingSet';
43
import * as countLines from 'metro/src/lib/countLines';
54

65
import type { Bundle, MetroSerializer, MetroSerializerOutput, SerializedBundle, VirtualJSOutput } from './utils';
7-
import { createDebugIdSnippet, determineDebugIdFromBundleSource, stringToUUID } from './utils';
6+
import { createDebugIdSnippet, createSet, determineDebugIdFromBundleSource, stringToUUID } from './utils';
87
import { createDefaultMetroSerializer } from './vendor/metro/utils';
98

109
type SourceMap = Record<string, unknown>;
@@ -139,7 +138,7 @@ function createDebugIdModule(debugId: string): Module<VirtualJSOutput> & { setSo
139138
},
140139
dependencies: new Map(),
141140
getSource: () => Buffer.from(debugIdCode),
142-
inverseDependencies: new CountingSet(),
141+
inverseDependencies: createSet(),
143142
path: DEBUG_ID_MODULE_PATH,
144143
output: [
145144
{

src/js/tools/utils.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as crypto from 'crypto';
22
import type { Module, ReadOnlyGraph, SerializerOptions } from 'metro';
3+
import type CountingSet from 'metro/src/lib/CountingSet';
34

45
// Variant of MixedOutput
56
// https://github.com/facebook/metro/blob/9b85f83c9cc837d8cd897aa7723be7da5b296067/packages/metro/src/DeltaBundler/types.flow.js#L21
@@ -74,3 +75,24 @@ export function determineDebugIdFromBundleSource(code: string): string | undefin
7475
);
7576
return match ? match[1] : undefined;
7677
}
78+
79+
/**
80+
* CountingSet was added in Metro 0.72.0 before that NodeJS Set was used.
81+
*
82+
* https://github.com/facebook/metro/blob/fc29a1177f883144674cf85a813b58567f69d545/packages/metro/src/lib/CountingSet.js
83+
*/
84+
function resolveSetCreator(): () => CountingSet<string> {
85+
try {
86+
// eslint-disable-next-line @typescript-eslint/no-var-requires
87+
const { default: MetroSet } = require('metro/src/lib/CountingSet');
88+
return () => new MetroSet();
89+
} catch (e) {
90+
if (e instanceof Error && 'code' in e && e.code === 'MODULE_NOT_FOUND') {
91+
return () => new Set() as unknown as CountingSet<string>;
92+
} else {
93+
throw e;
94+
}
95+
}
96+
}
97+
98+
export const createSet = resolveSetCreator();

yarn.lock

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,13 @@
22932293
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.11.1.tgz#56af902ad157e763f9ba63d671c39cda3193c835"
22942294
integrity sha512-oTQgnd0hblfLsJ6BvJzzSL+Inogp3lq9fGgqRkMB/ziKMgEUaFl801OncOzUmalfzt14N0oPHMK47ipl+wbTIw==
22952295

2296+
"@types/node@^20.9.3":
2297+
version "20.9.3"
2298+
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.9.3.tgz#e089e1634436f676ff299596c9531bd2b59fffc6"
2299+
integrity sha512-nk5wXLAXGBKfrhLB0cyHGbSqopS+nz0BUgZkUQqSHSSgdee0kssp1IAqlQOu333bW+gMNs2QREx7iynm19Abxw==
2300+
dependencies:
2301+
undici-types "~5.26.4"
2302+
22962303
"@types/prop-types@*":
22972304
version "15.7.3"
22982305
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
@@ -8411,6 +8418,11 @@ unbox-primitive@^1.0.2:
84118418
has-symbols "^1.0.3"
84128419
which-boxed-primitive "^1.0.2"
84138420

8421+
undici-types@~5.26.4:
8422+
version "5.26.5"
8423+
resolved "https://registry.yarnpkg.com/undici-types/-/undici-types-5.26.5.tgz#bcd539893d00b56e964fd2657a4866b221a65617"
8424+
integrity sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==
8425+
84148426
unicode-canonical-property-names-ecmascript@^1.0.4:
84158427
version "1.0.4"
84168428
resolved "https://registry.yarnpkg.com/unicode-canonical-property-names-ecmascript/-/unicode-canonical-property-names-ecmascript-1.0.4.tgz#2619800c4c825800efdd8343af7dd9933cbe2818"

0 commit comments

Comments
 (0)