@samitouri / QOS-React-2 / commits / 4a7a39b594

[Flare] Add RN build step for ReactTypes (#15926)

Dominic Gannaway committed Jun 19, 2019 at 13:27 UTC 4a7a39b594f58dbf4e5c36251c4947bda19fce47
5 files changed +26 -8
packages/react-native-renderer/src/ReactFabricHostConfig.js
+2 -1
@@ -13,6 +13,7 @@ import type {
13 MeasureOnSuccessCallback,
14 NativeMethodsMixinType,
15 ReactNativeBaseComponentViewConfig,
16 + ReactNativeEventResponder,
17 } from './ReactNativeTypes';
18 import type {ReactEventComponentInstance} from 'shared/ReactTypes';
19
@@ -76,7 +77,7 @@ export type UpdatePayload = Object;
77
78 export type TimeoutHandle = TimeoutID;
79 export type NoTimeout = -1;
79 -export type EventResponder = any;
80 +export type EventResponder = ReactNativeEventResponder;
81
82 // TODO: Remove this conditional once all changes have propagated.
83 if (registerEventHandler) {
packages/react-native-renderer/src/ReactNativeHostConfig.js
+5 -2
@@ -7,7 +7,10 @@
7 * @flow
8 */
9
10 -import type {ReactNativeBaseComponentViewConfig} from './ReactNativeTypes';
10 +import type {
11 + ReactNativeBaseComponentViewConfig,
12 + ReactNativeEventResponder,
13 +} from './ReactNativeTypes';
14 import type {ReactEventComponentInstance} from 'shared/ReactTypes';
15
16 import invariant from 'shared/invariant';
@@ -48,7 +51,7 @@ export type ChildSet = void; // Unused
51
52 export type TimeoutHandle = TimeoutID;
53 export type NoTimeout = -1;
51 -export type EventResponder = any;
54 +export type EventResponder = ReactNativeEventResponder;
55
56 const UPDATE_SIGNAL = {};
57 if (__DEV__) {
packages/react-native-renderer/src/ReactNativeTypes.js
+3
@@ -157,3 +157,6 @@ export type ReactFabricType = {
157
158 __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: SecretInternalsFabricType,
159 };
160 +
161 +// TODO will be addressed with upcoming React Flare support
162 +export type ReactNativeEventResponder = any;
packages/shared/ReactTypes.js
+1
@@ -7,6 +7,7 @@
7 * @flow
8 */
9
10 +// NOTE: this line is changed in the RN build, see: copyRNShims in packaging.js
11 import type {EventResponder} from 'react-reconciler/src/ReactFiberHostConfig';
12
13 export type ReactNode =
scripts/rollup/packaging.js
+15 -5
@@ -1,6 +1,12 @@
1 'use strict';
2
3 -const {existsSync, readdirSync, unlinkSync} = require('fs');
3 +const {
4 + existsSync,
5 + readdirSync,
6 + unlinkSync,
7 + readFileSync,
8 + writeFileSync,
9 +} = require('fs');
10 const Bundles = require('./bundles');
11 const {
12 asyncCopyTo,
@@ -87,18 +93,22 @@ async function copyWWWShims() {
93 }
94
95 async function copyRNShims() {
96 + const reactTypesBuildTarget = 'build/react-native/shims/ReactTypes.js';
97 await Promise.all([
98 // React Native
99 asyncCopyTo(`${__dirname}/shims/react-native`, 'build/react-native/shims'),
93 - asyncCopyTo(
94 - require.resolve('shared/ReactTypes.js'),
95 - 'build/react-native/shims/ReactTypes.js'
96 - ),
100 + asyncCopyTo(require.resolve('shared/ReactTypes.js'), reactTypesBuildTarget),
101 asyncCopyTo(
102 require.resolve('react-native-renderer/src/ReactNativeTypes.js'),
103 'build/react-native/shims/ReactNativeTypes.js'
104 ),
105 ]);
106 + // Modify the EventResponder type in ReactTypes
107 + const reactTypesSource = readFileSync(reactTypesBuildTarget, 'utf8');
108 + const original = `import type {EventResponder} from 'react-reconciler/src/ReactFiberHostConfig';`;
109 + const changeTo = `import type {ReactNativeEventResponder as EventResponder} from './ReactNativeTypes';`;
110 + const modifiedSource = reactTypesSource.replace(original, changeTo);
111 + writeFileSync(reactTypesBuildTarget, modifiedSource);
112 }
113
114 async function copyAllShims() {