mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-28 20:25:33 +08:00
Consume react, fbjs from npm
Summary: We don't (yet) treat these the same as any other modules because we still have special resolution rules for them in the packager allowing the use of `providesModule`, but I believe this allows people to use npm react in their RN projects and not have duplicate copies of React. Fixes facebook/react-native#2985. This relies on fbjs 0.6, which includes `.flow` files alongside the `.js` files to allow them to be typechecked without additional configuration. This also uses react 0.14.5, which shims a couple of files (as `.native.js`) to avoid DOM-specific bits. Once we fix these in React, we will use the same code on web and native. Hopefully we can also remove the packager support I'm adding here for `.native.js`. This diff is not the desired end state for us – ideally the packager would know nothing of react or fbjs, and we'll get there eventually by not relying on `providesModule` in order to load react and fbjs modules. (fbjs change posted here but not merged yet: https://github.com/facebook/fbjs/pull/84.) This should also allow relay to work seamlessly with RN, but I haven't verified this. public Reviewed By: sebmarkbage Differential Revision: D2786197 fb-gh-sync-id: ff50f28445e949edc9501f4b599df7970813870d
This commit is contained in:
committed by
facebook-github-bot-9
parent
5bf1f4c05e
commit
6a838a4201
@@ -18,6 +18,7 @@ const Promise = require('promise');
|
||||
class ResolutionRequest {
|
||||
constructor({
|
||||
platform,
|
||||
preferNativePlatform,
|
||||
entryPath,
|
||||
hasteMap,
|
||||
deprecatedAssetMap,
|
||||
@@ -26,6 +27,7 @@ class ResolutionRequest {
|
||||
fastfs,
|
||||
}) {
|
||||
this._platform = platform;
|
||||
this._preferNativePlatform = preferNativePlatform;
|
||||
this._entryPath = entryPath;
|
||||
this._hasteMap = hasteMap;
|
||||
this._deprecatedAssetMap = deprecatedAssetMap;
|
||||
@@ -329,6 +331,9 @@ class ResolutionRequest {
|
||||
} else if (this._platform != null &&
|
||||
this._fastfs.fileExists(potentialModulePath + '.' + this._platform + '.js')) {
|
||||
file = potentialModulePath + '.' + this._platform + '.js';
|
||||
} else if (this._preferNativePlatform &&
|
||||
this._fastfs.fileExists(potentialModulePath + '.native.js')) {
|
||||
file = potentialModulePath + '.native.js';
|
||||
} else if (this._fastfs.fileExists(potentialModulePath + '.js')) {
|
||||
file = potentialModulePath + '.js';
|
||||
} else if (this._fastfs.fileExists(potentialModulePath + '.json')) {
|
||||
|
||||
Reference in New Issue
Block a user