forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetro.config.js
More file actions
74 lines (61 loc) · 3.42 KB
/
Copy pathmetro.config.js
File metadata and controls
74 lines (61 loc) · 3.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
const {getDefaultConfig: getExpoDefaultConfig} = require('expo/metro-config');
const {getDefaultConfig: getReactNativeDefaultConfig} = require('@react-native/metro-config');
const {mergeConfig} = require('@react-native/metro-config');
const {wrapWithReanimatedMetroConfig} = require('react-native-reanimated/metro-config');
const {withSentryConfig} = require('@sentry/react-native/metro');
const {createSentryMetroSerializer} = require('@sentry/react-native/dist/js/tools/sentryMetroSerializer');
const path = require('path');
const {wrapTransformResultMaps} = require('@expo/metro-config/build/serializer/packedMap');
const Bundler = require('metro/private/Bundler').default;
// Expo SDK 56's transformer emits packed per-module source maps stock metro-source-map can't
// read ("Unexpected module with full source map found"); unpack them here as Expo's CLI does.
function patchMetroForExpoPackedSourceMaps() {
// Rock never exposes a Bundler instance, so we patch the shared prototype; the flag stops
// repeated config evaluation from stacking wrappers.
if (Bundler.prototype.__expoPackedSourceMapsPatched) {
return;
}
const originalTransformFile = Bundler.prototype.transformFile;
Bundler.prototype.transformFile = async function transformFile(...args) {
return wrapTransformResultMaps(await originalTransformFile.apply(this, args));
};
Bundler.prototype.__expoPackedSourceMapsPatched = true;
}
patchMetroForExpoPackedSourceMaps();
// Prefer explicit ENVFILE (Fastlane/GHA set this), else fall back to local .env
const envPath = process.env.ENVFILE ? (path.isAbsolute(process.env.ENVFILE) ? process.env.ENVFILE : path.join(__dirname, process.env.ENVFILE)) : path.join(__dirname, '.env');
require('dotenv').config({path: envPath});
// Expo SDK 56 replaces global fetch with expo/fetch on native, which breaks large API responses (e.g. OpenApp).
// Keep React Native's built-in fetch unless explicitly overridden.
process.env.EXPO_PUBLIC_USE_RN_FETCH = process.env.EXPO_PUBLIC_USE_RN_FETCH ?? '1';
const defaultConfig = getReactNativeDefaultConfig(__dirname);
const expoConfig = getExpoDefaultConfig(__dirname);
const isDev = process.env.ENVIRONMENT === undefined || process.env.ENVIRONMENT === 'development';
/**
* Metro configuration
* https://reactnative.dev/docs/metro
*
* @type {import('metro-config').MetroConfig}
*/
const defaultGetPolyfills = defaultConfig.serializer?.getPolyfills ?? (() => []);
const config = {
resolver: {
assetExts: [...defaultConfig.resolver.assetExts, 'lottie'],
sourceExts: [...defaultConfig.resolver.sourceExts, ...defaultConfig.watcher.additionalExts, 'jsx'],
},
// We are merging the default config from Expo and React Native and expo one is overriding the React Native one so inlineRequires is set to false so we want to set it to true
// for fix cycling dependencies and improve performance of app startup
transformer: {
getTransformOptions: async () => ({
transform: {
inlineRequires: true,
},
}),
},
serializer: {
getPolyfills: (opts) => [...defaultGetPolyfills(opts), path.resolve(__dirname, 'src/setup/moduleInitPolyfill.ts')],
...(!isDev ? {customSerializer: createSentryMetroSerializer()} : {}),
},
};
const mergedConfig = wrapWithReanimatedMetroConfig(mergeConfig(defaultConfig, expoConfig, config));
module.exports = isDev ? mergedConfig : withSentryConfig(mergedConfig);