This is a WIP attempt to add support for using static JS bundles instead of the RN packager to happo-target-react-native. It adds a usePackager option that defaults to true. When false, it will call the buildBundle function to build a static JS bundle using the RN CLI.
This was excruciatingly slow to test, because I hit a number of roadblocks along the way:
When running npm run happo from happo-example-react-native-project, the Appium runner would almost always stall and not initial Happo. This happens on both iOS and Android apps, even on master. Occasionally Appium would kick off the Happo app on the emulator but it's not clear to me under what conditions this happens correctly.
In the example project Happo entry file, happo-example-react-native-project/happo.js, the bundler will throw an error if react is imported:
[Bundler]: Error:
Unable to resolve module `react` from `/Users/spike/code/happo/packages/happo-example-react-native-project/happo.js`: Module does not exist in the module map or in these directories:
/Users/spike/code/happo/packages/happo-example-react-native-project/node_modules
, /Users/spike/code/happo/node_modules
This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
1. Clear watchman watches: `watchman watch-del-all`.
2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
3. Reset packager cache: `rm -fr $TMPDIR/react-*` or `npm start --reset-cache`.
Maybe this is a result of the Lerna setup and the nested projects? I'm not sure why it can't find react because it definitely exists here:
As a workaround to move forward, I commented out the import and any JSX in the file and the bundle step works.
I kept getting this error:
which is the result of babelHelpers["typeof"] not being present. I upgraded to RN 0.42 in an attempt to fix it, however it persisted. I hacked around it by manually editing the JS bundle file. I think the issue may be that Babel is being run on the babelHelpers.js shipped by RN. Here's why I think that; this is the typeof helper that lives in RN's babelHelpers.js:
babelHelpers.typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
and here is the corresponding output in my main.jsbundle file:
babelHelpers.typeof = typeof Symbol === "function" && typeof (typeof Symbol === "function" ? Symbol.iterator : "@@iterator") === "symbol" ? function (obj) {
return typeof obj;
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== (typeof Symbol === "function" ? Symbol.prototype : "@@prototype") ? "symbol" : typeof obj;
};
Manually editing main.jsbundle and replacing the typeof helper with what ships with RN fixes it.
Maybe there are conflicting Babel setups? Could it be a side effect of the Lerna setup?
[x] Upgraded RN to 0.42 in happo-target-react-native and happo-example-react-native-project
[x] Upgraded Gradle to 2.2.2 in happo-example-react-native-project
[ ] Figure out babelHelpers.typeof issue
[ ] Add logic to iOS runner to auto-detect if packager is running
[ ] Figure out packager error when importing React
This is a WIP attempt to add support for using static JS bundles instead of the RN packager to
happo-target-react-native
. It adds ausePackager
option that defaults totrue
. Whenfalse
, it will call thebuildBundle
function to build a static JS bundle using the RN CLI.This was excruciatingly slow to test, because I hit a number of roadblocks along the way:
When running
npm run happo
fromhappo-example-react-native-project
, the Appium runner would almost always stall and not initial Happo. This happens on both iOS and Android apps, even onmaster
. Occasionally Appium would kick off the Happo app on the emulator but it's not clear to me under what conditions this happens correctly.In the example project Happo entry file,
happo-example-react-native-project/happo.js
, the bundler will throw an error ifreact
is imported:Maybe this is a result of the Lerna setup and the nested projects? I'm not sure why it can't find
react
because it definitely exists here:As a workaround to move forward, I commented out the import and any JSX in the file and the bundle step works.
which is the result of
babelHelpers["typeof"]
not being present. I upgraded to RN 0.42 in an attempt to fix it, however it persisted. I hacked around it by manually editing the JS bundle file. I think the issue may be that Babel is being run on thebabelHelpers.js
shipped by RN. Here's why I think that; this is thetypeof
helper that lives in RN'sbabelHelpers.js
:and here is the corresponding output in my
main.jsbundle
file:Manually editing
main.jsbundle
and replacing thetypeof
helper with what ships with RN fixes it.Maybe there are conflicting Babel setups? Could it be a side effect of the Lerna setup?
happo-target-react-native
andhappo-example-react-native-project
happo-example-react-native-project
babelHelpers.typeof
issuecc: @lelandrichardson