Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Babel 7 + RN 0.57 #477

Merged
merged 30 commits into from Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
5bc3859
Update babel deps to v7
hedgepigdaniel Sep 17, 2018
465f4fe
Patch haste resolver plugin to account for the removal of @provides a…
hedgepigdaniel Sep 17, 2018
d7509a3
Remove babel6 only logic to allow shorthand specification of babel pl…
hedgepigdaniel Sep 17, 2018
ddbb364
Update ignore option to @babel/register to be an array
hedgepigdaniel Sep 17, 2018
e466bba
Update @babel/preset-env's "useBuiltIns" option from true to "entry"
hedgepigdaniel Sep 17, 2018
0bd849c
Port babel plugin to new @babel/types API
hedgepigdaniel Sep 17, 2018
ff11e1e
Narrow scope of haste modules to just the Libraries directory in reac…
hedgepigdaniel Sep 17, 2018
4745777
Upgrade react-hot-loader
hedgepigdaniel Sep 22, 2018
6aa43f0
Upgrade react-hot-loader to 4.0
hedgepigdaniel Sep 23, 2018
8b2c701
Update react-hot-loader patching to use the new export instead of the…
hedgepigdaniel Sep 23, 2018
68c5a31
Add polyfill for Object.setPrototypeOf (used in react-hot-loader and …
hedgepigdaniel Sep 23, 2018
b6901f1
Try removing all the monkey patching of react-hot-loader
hedgepigdaniel Sep 23, 2018
80e9744
Remove hotPatch.js and automatically add hot/patch to all webpack ent…
hedgepigdaniel Sep 24, 2018
ae0d0d0
Upgrade dependencies
hedgepigdaniel Sep 24, 2018
b6bcdba
fixtures/example-app: react-native-git-upgrade to 0.57.1
hedgepigdaniel Sep 24, 2018
82b3ee7
fixtures/react-native-clean: react-native-git-upgrade to 0.57.1
hedgepigdaniel Sep 24, 2018
89a5e67
fixtures/react-native-with-haul: react-native-git-upgrade to 0.57.1
hedgepigdaniel Sep 24, 2018
0855585
fixture/react-native-clean: upgrade deps
hedgepigdaniel Sep 24, 2018
ff48f4e
fixtures/reactt-native-with-haul: upgrade deps
hedgepigdaniel Sep 24, 2018
0abb30d
Update replacePathsInObject to not replace paths with src inside node…
hedgepigdaniel Sep 24, 2018
0456b49
fixtures/example-app: add dependency on metro-react-native-babel-preset
hedgepigdaniel Sep 24, 2018
8d176e6
fixtures/react-native-clean: haul install
hedgepigdaniel Sep 24, 2018
2319b65
Use file extension for hot patch entry point
hedgepigdaniel Sep 24, 2018
e3c5a5b
Update snapshots
hedgepigdaniel Sep 24, 2018
32363b0
Merge remote-tracking branch 'upstream/next' into babel7
hedgepigdaniel Sep 24, 2018
063ea4e
Allow custom providesModuleNodeModules options to restrict haste root.
Oct 8, 2018
fb89a74
dev server returns 404 with `platform=ios` param
Oct 9, 2018
6ae0c09
Apply suggested fix for hot patch
Oct 10, 2018
a18a664
merge latest
Oct 10, 2018
8462453
update snapshots
Oct 10, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .npmrc
@@ -0,0 +1,3 @@
@office-iss:registry=https://office.pkgs.visualstudio.com/_packaging/Office/npm/registry/
registry=https://office.pkgs.visualstudio.com/_packaging/Office/npm/registry/
always-auth=true
6 changes: 4 additions & 2 deletions docs/HMR_API.md
Expand Up @@ -18,11 +18,13 @@ require('haul/hot/patch');
* In production (`NODE_ENV === 'production'`):
does nothing.

* In development (`NODE_ENV !== 'production'`):
* In development with HMR enabled
(`NODE_ENV !== 'production' && module.hot`):

Patches React's `createElement` and `createFactory`, so that they use `react-proxy` and return a proxied component. Those components behave like the normal ones, but have their state persisted between updates.

This file __must be imported/required in the root file / entry file before anything else__, since the code must be executed at the very beginning.
This file is automatically imported before all configured entry
points, since the code must be executed at the very beginning.

## Module `haul/hot/index.js`

Expand Down
13 changes: 3 additions & 10 deletions docs/HMR_Setup.md
Expand Up @@ -43,14 +43,9 @@ This guide below is not a list of steps, but rather a set of rules and tips on h

------

Haul uses `react-hot-loader` to support HMR, so the first step is to _patch_ React's `createElement` and `createFactory` functions to use `react-proxy`. Proxied component can be updated with a new implementation but it's state is persisted between updates.
In order to do that, add the following line to `__the root file__` - the one that is used as an entrypoint, before any other code:

```javascript
import 'haul/hot/patch';
```

It's important that __the code from `haul/hot/patch` is evaluated before anything else!__
Haul uses `react-hot-loader` to support HMR. `react-hot-loader/patch`
is automatically imported in all entry points in development when
HMR is enabled.

Now, we need to wrap the __root component factories__ using `makeHot` function. Root component factory is a function that returns a __root component__:

Expand Down Expand Up @@ -148,7 +143,6 @@ Now, you need to replace empty strings with the paths according to the following
### Single root component in a entry file

```javascript
import 'haul/hot/patch';
import {
makeHot,
tryUpdateSelf,
Expand Down Expand Up @@ -176,7 +170,6 @@ if (module.hot) {

```javascript
// index.js
import 'haul/hot/patch';
import './screens';
```

Expand Down
22 changes: 1 addition & 21 deletions docs/HMR_react-native-navigation.md
Expand Up @@ -7,30 +7,10 @@ Since we don't know how your project looks like, we will use one of the possible

---

Let's assume you have `index.js` file which imports your screens and bootstraps the navigation. Add `import 'haul/hot/patch';` at the beginning:
Let's assume you have `index.js` file which imports your screens and bootstraps the navigation. Make the following changes:

```diff
// index.js
+ import 'haul/hot/patch';
import { Navigation } from 'react-native-navigation';

// Screens
import Calendar from './Calendar';
import Localization from './Localization';
import Information from './Information';

Navigation.registerComponent('Calendar', () => Calendar);
Navigation.registerComponent('Localization', () => Localization);
Navigation.registerComponent('Information',() => Information);
```

`import 'haul/hot/patch';` should be placed in the root file / entry file, since __the code from this file must be executed before anything else!__

Now, make the following changes:

```diff
// index.js
import 'haul/hot/patch';
import { Navigation } from 'react-native-navigation';
+ import {
+ makeHot,
Expand Down
6 changes: 0 additions & 6 deletions docs/HMR_react-navigation.md
Expand Up @@ -31,7 +31,6 @@ First thing you need to do is to add the following code snipped at the top of `A

```diff
// index.js
+ import 'haul/hot/patch';
+ import { makeHot, clearCacheFor, redraw } from 'haul/hot';
import {
AppRegistry,
Expand All @@ -49,15 +48,12 @@ const MyApp = StackNavigator({
AppRegistry.registerComponent('MyApp', () => MyApp);
```

`import 'haul/hot/patch'` must be placed before anything else, since __the code in that file must be executed at the very beginning!__

---

Now, if you're defining your screens using `screen` property, you must replace it with `getScreen` and convert the value to a function:

```diff
// index.js
import 'haul/hot/patch';
import { makeHot, clearCacheFor, redraw } from 'haul/hot';
import {
AppRegistry,
Expand All @@ -81,7 +77,6 @@ Then, wrap those screen factories with `makeHot` call and pass the name of the s

```diff
// index.js
import 'haul/hot/patch';
import { makeHot, clearCacheFor, redraw } from 'haul/hot';
import {
AppRegistry,
Expand All @@ -108,7 +103,6 @@ Place the following code snipped at the end of the file:

```diff
// index.js
import 'haul/hot/patch';
import { makeHot, clearCacheFor, redraw } from 'haul/hot';
import {
AppRegistry,
Expand Down
2 changes: 1 addition & 1 deletion fixtures/example-app/.babelrc
@@ -1,3 +1,3 @@
{
"presets": ["react-native"]
"presets": ["module:metro-react-native-babel-preset"]
}
18 changes: 17 additions & 1 deletion fixtures/example-app/.flowconfig
Expand Up @@ -29,7 +29,23 @@ node_modules/react-native/flow-github/
[options]
emoji=true

esproposal.optional_chaining=enable
esproposal.nullish_coalescing=enable

module.system=haste
module.system.haste.use_name_reducers=true
# get basename
module.system.haste.name_reducers='^.*/\([a-zA-Z0-9$_.-]+\.js\(\.flow\)?\)$' -> '\1'
# strip .js or .js.flow suffix
module.system.haste.name_reducers='^\(.*\)\.js\(\.flow\)?$' -> '\1'
# strip .ios suffix
module.system.haste.name_reducers='^\(.*\)\.ios$' -> '\1'
module.system.haste.name_reducers='^\(.*\)\.android$' -> '\1'
module.system.haste.name_reducers='^\(.*\)\.native$' -> '\1'
module.system.haste.paths.blacklist=.*/__tests__/.*
module.system.haste.paths.blacklist=.*/__mocks__/.*
module.system.haste.paths.blacklist=<PROJECT_ROOT>/node_modules/react-native/Libraries/Animated/src/polyfills/.*
module.system.haste.paths.whitelist=<PROJECT_ROOT>/node_modules/react-native/Libraries/.*

munge_underscores=true

Expand All @@ -51,4 +67,4 @@ suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy
suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError

[version]
^0.63.0
^0.78.0
4 changes: 4 additions & 0 deletions fixtures/example-app/.gitignore
Expand Up @@ -55,3 +55,7 @@ buck-out/
# Haul
#
haul-debug.log

# Bundle artifact
#
*.jsbundle
14 changes: 7 additions & 7 deletions fixtures/example-app/android/app/build.gradle
Expand Up @@ -94,13 +94,13 @@ def enableSeparateBuildPerCPUArchitecture = false
def enableProguardInReleaseBuilds = false

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion

defaultConfig {
applicationId "com.example"
minSdkVersion 16
targetSdkVersion 22
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 1
versionName "1.0"
ndk {
Expand Down Expand Up @@ -137,9 +137,9 @@ android {
}

dependencies {
compile fileTree(dir: "libs", include: ["*.jar"])
compile "com.android.support:appcompat-v7:23.0.1"
compile "com.facebook.react:react-native:+" // From node_modules
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
implementation "com.facebook.react:react-native:+" // From node_modules
}

// Run this once to be able to run the application with BUCK
Expand Down
53 changes: 0 additions & 53 deletions fixtures/example-app/android/app/proguard-rules.pro
Expand Up @@ -15,56 +15,3 @@
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Disabling obfuscation is useful if you collect stack traces from production crashes
# (unless you are using a system that supports de-obfuscate the stack traces).
-dontobfuscate

# React Native

# Keep our interfaces so they can be used by other ProGuard rules.
# See http://sourceforge.net/p/proguard/bugs/466/
-keep,allowobfuscation @interface com.facebook.proguard.annotations.DoNotStrip
-keep,allowobfuscation @interface com.facebook.proguard.annotations.KeepGettersAndSetters
-keep,allowobfuscation @interface com.facebook.common.internal.DoNotStrip

# Do not strip any method/class that is annotated with @DoNotStrip
-keep @com.facebook.proguard.annotations.DoNotStrip class *
-keep @com.facebook.common.internal.DoNotStrip class *
-keepclassmembers class * {
@com.facebook.proguard.annotations.DoNotStrip *;
@com.facebook.common.internal.DoNotStrip *;
}

-keepclassmembers @com.facebook.proguard.annotations.KeepGettersAndSetters class * {
void set*(***);
*** get*();
}

-keep class * extends com.facebook.react.bridge.JavaScriptModule { *; }
-keep class * extends com.facebook.react.bridge.NativeModule { *; }
-keepclassmembers,includedescriptorclasses class * { native <methods>; }
-keepclassmembers class * { @com.facebook.react.uimanager.UIProp <fields>; }
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactProp <methods>; }
-keepclassmembers class * { @com.facebook.react.uimanager.annotations.ReactPropGroup <methods>; }

-dontwarn com.facebook.react.**

# TextLayoutBuilder uses a non-public Android constructor within StaticLayout.
# See libs/proxy/src/main/java/com/facebook/fbui/textlayoutbuilder/proxy for details.
-dontwarn android.text.StaticLayout

# okhttp

-keepattributes Signature
-keepattributes *Annotation*
-keep class okhttp3.** { *; }
-keep interface okhttp3.** { *; }
-dontwarn okhttp3.**

# okio

-keep class sun.misc.Unsafe { *; }
-dontwarn java.nio.file.*
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn okio.**
10 changes: 2 additions & 8 deletions fixtures/example-app/android/app/src/main/AndroidManifest.xml
@@ -1,20 +1,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example"
android:versionCode="1"
android:versionName="1.0">
package="com.example">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="22" />

<application
android:name=".MainApplication"
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:allowBackup="false"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion fixtures/example-app/android/build.gradle
@@ -1,11 +1,19 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext {
buildToolsVersion = "27.0.3"
minSdkVersion = 16
compileSdkVersion = 27
targetSdkVersion = 26
supportLibVersion = "27.1.1"
}
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.android.tools.build:gradle:3.1.4'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -20,5 +28,12 @@ allprojects {
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
url "$rootDir/../node_modules/react-native/android"
}
google()
}
}


task wrapper(type: Wrapper) {
gradleVersion = '4.4'
distributionUrl = distributionUrl.replace("bin", "all")
}
2 changes: 0 additions & 2 deletions fixtures/example-app/android/gradle.properties
Expand Up @@ -16,5 +16,3 @@
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

android.useDeprecatedNdk=true
Binary file modified fixtures/example-app/android/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
Expand Up @@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip