/
githubmr
/
facebook-react-native
Обзор
Документация
Войти
/
githubmr
/
facebook-react-native
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
main
packages/community-cli-plugin/src/utils/metroPlatformResolver.js
49 строк
2 KB
Tim Yung
RN: Delete `@oncall` Annotations (#51416)
18 май 2025, 02:18
18 май 2025, 02:18
84de8a0
Код
Авторство
О чём код?
/** * 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 */ import type {CustomResolver} from 'metro-resolver'; /** * This is an implementation of a metro resolveRequest option which will remap react-native imports * to different npm packages based on the platform requested. This allows a single metro instance/config * to produce bundles for multiple out of tree platforms at a time. * * @param platformImplementations * A map of platform to npm package that implements that platform * * Ex: * { * windows: 'react-native-windows' * macos: 'react-native-macos' * } */ export function reactNativePlatformResolver( platformImplementations: { [platform: string]: string, }, customResolver: ?CustomResolver, ): CustomResolver { return (context, moduleName, platform) => { let modifiedModuleName = moduleName; if (platform != null && platformImplementations[platform]) { if (moduleName === 'react-native') { modifiedModuleName = platformImplementations[platform]; } else if (moduleName.startsWith('react-native/')) { modifiedModuleName = `${ platformImplementations[platform] }/${modifiedModuleName.slice('react-native/'.length)}`; } } if (customResolver) { return customResolver(context, modifiedModuleName, platform); } return context.resolveRequest(context, modifiedModuleName, platform); }; }