82 lines
2.6 KiB
TypeScript
82 lines
2.6 KiB
TypeScript
// Learn more https://docs.expo.io/guides/customizing-metro
|
|
import {type CustomResolver} from '@expo/metro/metro-resolver'
|
|
import {getDefaultConfig} from '@expo/metro-config'
|
|
import {getSentryExpoConfig} from '@sentry/react-native/metro.js'
|
|
|
|
const config = getSentryExpoConfig(import.meta.dirname, {
|
|
// TODO: confirm this doesn't break anything when we switch to metro web
|
|
includeWebReplay: false,
|
|
includeWebFeedback: false,
|
|
annotateReactComponents: {
|
|
textComponentNames: ['Text', 'ButtonText'],
|
|
},
|
|
getDefaultConfig: (projectRoot, options) => {
|
|
const config = getDefaultConfig(projectRoot, options)
|
|
|
|
if (typeof process.env.RN_SRC_EXT === 'string') {
|
|
// inject `.e2e.ts` and `.e2e.tsx` into the sourceExts when running tests)
|
|
config.resolver.sourceExts.unshift(...process.env.RN_SRC_EXT.split(','))
|
|
}
|
|
|
|
config.resolver.assetExts = [...config.resolver.assetExts, 'woff2']
|
|
|
|
if (config.resolver.resolveRequest) {
|
|
throw Error('Update this override because it is conflicting now.')
|
|
}
|
|
|
|
if (process.env.BSKY_PROFILE) {
|
|
// @ts-expect-error readonly property
|
|
config.cacheVersion += ':PROFILE'
|
|
}
|
|
|
|
const resolver: CustomResolver = (context, moduleName, platform) => {
|
|
if (
|
|
platform === 'web' &&
|
|
/^react-native-gesture-handler(\/|$)/.test(moduleName)
|
|
) {
|
|
throw new Error(
|
|
`react-native-gesture-handler must not be imported on web (requested from ${context.originModulePath})`,
|
|
)
|
|
}
|
|
/*
|
|
* react-native-webview has no web implementation (its fallback renders
|
|
* "does not support this platform"), so swap in react-native-web-webview
|
|
* to keep external media embeds working. Mirrors the old webpack alias.
|
|
*/
|
|
if (platform === 'web' && moduleName === 'react-native-webview') {
|
|
return context.resolveRequest(
|
|
context,
|
|
'react-native-web-webview',
|
|
platform,
|
|
)
|
|
}
|
|
if (
|
|
process.env.BSKY_PROFILE &&
|
|
moduleName.endsWith('ReactNativeRenderer-prod')
|
|
) {
|
|
return context.resolveRequest(
|
|
context,
|
|
moduleName.replace('-prod', '-profiling'),
|
|
platform,
|
|
)
|
|
}
|
|
return context.resolveRequest(context, moduleName, platform)
|
|
}
|
|
|
|
// @ts-expect-error readonly property
|
|
config.resolver.resolveRequest = resolver
|
|
|
|
config.transformer.getTransformOptions = () =>
|
|
Promise.resolve({
|
|
transform: {
|
|
experimentalImportSupport: true,
|
|
inlineRequires: true as false, // ??? typescript why?
|
|
},
|
|
})
|
|
|
|
return config as unknown as Record<string, unknown>
|
|
},
|
|
})
|
|
|
|
export default config
|