mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/51416 Deletes `oncall` annotations from the `facebook/react-native` repository. Changelog: [Internal] Reviewed By: javache Differential Revision: D74902524 fbshipit-source-id: 32a6a5b2ff27281792d572f151e2b094d9a79029
50 lines
1.5 KiB
JavaScript
50 lines
1.5 KiB
JavaScript
/**
|
|
* 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);
|
|
};
|
|
}
|