diff --git a/packages/metro-config/package.json b/packages/metro-config/package.json index b8703bd178db..e4a834061e09 100644 --- a/packages/metro-config/package.json +++ b/packages/metro-config/package.json @@ -20,7 +20,8 @@ }, "exports": { ".": "./src/index.js", - "./package.json": "./package.json" + "./package.json": "./package.json", + "./src/internalCallsites": "./src/internalCallsites.js" }, "publishConfig": { "exports": { diff --git a/packages/metro-config/src/index.flow.js b/packages/metro-config/src/index.flow.js index 5fb4be2cd3fe..e4c54ec2ab39 100644 --- a/packages/metro-config/src/index.flow.js +++ b/packages/metro-config/src/index.flow.js @@ -10,32 +10,13 @@ import type {ConfigT, InputConfigT} from 'metro-config'; +import {INTERNAL_CALLSITES_PATTERNS} from './internalCallsites'; import {getDefaultConfig as getBaseConfig, mergeConfig} from 'metro-config'; export type {MetroConfig} from 'metro-config'; const INTERNAL_CALLSITES_REGEX = new RegExp( - [ - '/Libraries/BatchedBridge/MessageQueue\\.js$', - '/Libraries/Core/.+\\.js$', - '/Libraries/LogBox/.+\\.js$', - '/Libraries/Network/.+\\.js$', - '/Libraries/Pressability/.+\\.js$', - '/Libraries/Renderer/implementations/.+\\.js$', - '/Libraries/Utilities/.+\\.js$', - '/Libraries/vendor/.+\\.js$', - '/Libraries/WebSocket/.+\\.js$', - '/src/private/renderer/errorhandling/.+\\.js$', - '/metro-runtime/.+\\.js$', - '/node_modules/@babel/runtime/.+\\.js$', - '/node_modules/@react-native/js-polyfills/.+\\.js$', - '/node_modules/invariant/.+\\.js$', - '/node_modules/react-devtools-core/.+\\.js$', - '/node_modules/react-native/index.js$', - '/node_modules/react-refresh/.+\\.js$', - '/node_modules/scheduler/.+\\.js$', - '^\\[native code\\]$', - ] + INTERNAL_CALLSITES_PATTERNS // Make patterns work with both Windows and POSIX paths. .map(pathPattern => pathPattern.replaceAll('/', '[/\\\\]')) .join('|'), diff --git a/packages/metro-config/src/internalCallsites.js b/packages/metro-config/src/internalCallsites.js new file mode 100644 index 000000000000..6e496e58835c --- /dev/null +++ b/packages/metro-config/src/internalCallsites.js @@ -0,0 +1,45 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow strict-local + * @format + */ + +'use strict'; + +/** + * Path suffixes identifying stack frames from React Native internals. Used + * to collapse internal callsites in the symbolicator and to detect + * third-party modules in the serializer. + * + * Plain JavaScript with no dependencies: this module is also required + * directly (bypassing `src/index.js`) from runtimes without the monorepo + * toolchain, like the Buck worker zip, where `scripts/shared/babelRegister` + * cannot be resolved and Flow syntax cannot be parsed. + */ +const INTERNAL_CALLSITES_PATTERNS = [ + '/react-native/Libraries/BatchedBridge/MessageQueue\\.js$', + '/react-native/Libraries/Core/.+\\.js$', + '/react-native/Libraries/LogBox/.+\\.js$', + '/react-native/Libraries/Network/.+\\.js$', + '/react-native/Libraries/Pressability/.+\\.js$', + '/react-native/Libraries/Renderer/implementations/.+\\.js$', + '/react-native/Libraries/Utilities/.+\\.js$', + '/react-native/Libraries/vendor/.+\\.js$', + '/react-native/Libraries/WebSocket/.+\\.js$', + '/react-native/src/private/renderer/errorhandling/.+\\.js$', + '/metro-runtime/.+\\.js$', + '/node_modules/@babel/runtime/.+\\.js$', + '/node_modules/@react-native/js-polyfills/.+\\.js$', + '/node_modules/invariant/.+\\.js$', + '/node_modules/react-devtools-core/.+\\.js$', + '/node_modules/react-native/index.js$', + '/node_modules/react-refresh/.+\\.js$', + '/node_modules/scheduler/.+\\.js$', + '^\\[native code\\]$', +]; + +module.exports = {INTERNAL_CALLSITES_PATTERNS};