|
| 1 | +"use strict"; |
| 2 | + |
| 3 | +Object.defineProperty(exports, "__esModule", { |
| 4 | + value: true, |
| 5 | +}); |
| 6 | +exports.getDefaultConfig = getDefaultConfig; |
| 7 | +Object.defineProperty(exports, "mergeConfig", { |
| 8 | + enumerable: true, |
| 9 | + get: function () { |
| 10 | + return _metroConfig.mergeConfig; |
| 11 | + }, |
| 12 | +}); |
| 13 | +var _metroConfig = require("metro-config"); |
| 14 | +/** |
| 15 | + * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 16 | + * |
| 17 | + * This source code is licensed under the MIT license found in the |
| 18 | + * LICENSE file in the root directory of this source tree. |
| 19 | + * |
| 20 | + * |
| 21 | + * @format |
| 22 | + * @oncall react_native |
| 23 | + */ |
| 24 | + |
| 25 | +const INTERNAL_CALLSITES_REGEX = new RegExp( |
| 26 | + [ |
| 27 | + "/Libraries/BatchedBridge/MessageQueue\\.js$", |
| 28 | + "/Libraries/Core/.+\\.js$", |
| 29 | + "/Libraries/LogBox/.+\\.js$", |
| 30 | + "/Libraries/Network/.+\\.js$", |
| 31 | + "/Libraries/Pressability/.+\\.js$", |
| 32 | + "/Libraries/Renderer/implementations/.+\\.js$", |
| 33 | + "/Libraries/Utilities/.+\\.js$", |
| 34 | + "/Libraries/vendor/.+\\.js$", |
| 35 | + "/Libraries/WebSocket/.+\\.js$", |
| 36 | + "/Libraries/YellowBox/.+\\.js$", |
| 37 | + "/metro-runtime/.+\\.js$", |
| 38 | + "/node_modules/@babel/runtime/.+\\.js$", |
| 39 | + "/node_modules/@react-native/js-polyfills/.+\\.js$", |
| 40 | + "/node_modules/event-target-shim/.+\\.js$", |
| 41 | + "/node_modules/invariant/.+\\.js$", |
| 42 | + "/node_modules/react-devtools-core/.+\\.js$", |
| 43 | + "/node_modules/react-native/index.js$", |
| 44 | + "/node_modules/react-refresh/.+\\.js$", |
| 45 | + "/node_modules/scheduler/.+\\.js$", |
| 46 | + "^\\[native code\\]$", |
| 47 | + ] |
| 48 | + // Make patterns work with both Windows and POSIX paths. |
| 49 | + .map((pathPattern) => pathPattern.replaceAll("/", "[/\\\\]")) |
| 50 | + .join("|") |
| 51 | +); |
| 52 | +/** |
| 53 | + * Get the base Metro configuration for a React Native project. |
| 54 | + */ |
| 55 | +function getDefaultConfig(projectRoot) { |
| 56 | + const config = { |
| 57 | + resolver: { |
| 58 | + resolverMainFields: ["react-native", "browser", "main"], |
| 59 | + platforms: ["android", "ios"], |
| 60 | + unstable_conditionNames: ["require", "import", "react-native"], |
| 61 | + }, |
| 62 | + serializer: { |
| 63 | + // Note: This option is overridden in cli-plugin-metro (getOverrideConfig) |
| 64 | + getModulesRunBeforeMainModule: () => [ |
| 65 | + require.resolve("react-native/Libraries/Core/InitializeCore"), |
| 66 | + ], |
| 67 | + getPolyfills: () => require("@react-native/js-polyfills")(), |
| 68 | + isThirdPartyModule({ path: modulePath }) { |
| 69 | + return ( |
| 70 | + INTERNAL_CALLSITES_REGEX.test(modulePath) || |
| 71 | + /(?:^|[/\\])node_modules[/\\]/.test(modulePath) |
| 72 | + ); |
| 73 | + }, |
| 74 | + }, |
| 75 | + server: { |
| 76 | + port: Number(process.env.RCT_METRO_PORT) || 8081, |
| 77 | + }, |
| 78 | + symbolicator: { |
| 79 | + customizeFrame: (frame) => { |
| 80 | + const collapse = Boolean( |
| 81 | + frame.file != null && INTERNAL_CALLSITES_REGEX.test(frame.file) |
| 82 | + ); |
| 83 | + return { |
| 84 | + collapse, |
| 85 | + }; |
| 86 | + }, |
| 87 | + }, |
| 88 | + transformer: { |
| 89 | + allowOptionalDependencies: true, |
| 90 | + assetRegistryPath: "react-native/Libraries/Image/AssetRegistry", |
| 91 | + asyncRequireModulePath: require.resolve( |
| 92 | + "metro-runtime/src/modules/asyncRequire" |
| 93 | + ), |
| 94 | + babelTransformerPath: require.resolve( |
| 95 | + "@react-native/metro-babel-transformer" |
| 96 | + ), |
| 97 | + getTransformOptions: async () => ({ |
| 98 | + transform: { |
| 99 | + experimentalImportSupport: false, |
| 100 | + inlineRequires: true, |
| 101 | + }, |
| 102 | + }), |
| 103 | + }, |
| 104 | + watchFolders: [], |
| 105 | + }; |
| 106 | + |
| 107 | + // Set global hook so that the CLI can detect when this config has been loaded |
| 108 | + global.__REACT_NATIVE_METRO_CONFIG_LOADED = true; |
| 109 | + return (0, _metroConfig.mergeConfig)( |
| 110 | + _metroConfig.getDefaultConfig.getDefaultValues(projectRoot), |
| 111 | + config |
| 112 | + ); |
| 113 | +} |
0 commit comments