diff --git a/.prettierrc.js b/.prettierrc.js index 70a05cba5f46..cc544ffc1d91 100644 --- a/.prettierrc.js +++ b/.prettierrc.js @@ -23,7 +23,7 @@ module.exports = { }, }, { - files: ['*.js', '*.js.flow'], + files: ['*.js', '*.js.flow', '*.json.flow'], options: { parser: 'flow', }, diff --git a/packages/metro-config/package.json b/packages/metro-config/package.json index b8703bd178db..442a99293053 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.json": "./src/internalCallsites.json" }, "publishConfig": { "exports": { diff --git a/packages/metro-config/src/index.flow.js b/packages/metro-config/src/index.flow.js index 5fb4be2cd3fe..6855a6a35b0b 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.json'; 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.json b/packages/metro-config/src/internalCallsites.json new file mode 100644 index 000000000000..6a5c38964591 --- /dev/null +++ b/packages/metro-config/src/internalCallsites.json @@ -0,0 +1,21 @@ +[ + "/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\\]$" +] diff --git a/packages/metro-config/src/internalCallsites.json.flow b/packages/metro-config/src/internalCallsites.json.flow new file mode 100644 index 000000000000..e143159456e9 --- /dev/null +++ b/packages/metro-config/src/internalCallsites.json.flow @@ -0,0 +1,11 @@ +/** + * 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 + * @format + */ + +declare module.exports: ReadonlyArray;