# Why
support building hermes bytecode bundle for ios
# How
- add ios and shared `jsEngine` support to `isEnableHermesManaged`
- some refactoring to make `maybeAddHermesBundleAsync` clear
= move sdk check into HermesBundler.ts
= move throwing error of `maybeInconsistentEngine*` into HermesBundler.ts
- add `maybeInconsistentEngineIosAsync` to support Podfile.properties.json
# Test Plan
### new unit tests
```
PASS @expo/dev-server src/__tests__/HermesBundler-test.ts
isEnableHermesManaged
✓ should support shared jsEngine key
✓ platform jsEngine should override shared jsEngine
✓ should exclude old SDK (18 ms)
maybeThrowFromInconsistentEngineAsync - ios
✓ should resolve if ":hermes_enabled => true" in Podfile and "jsEngine: 'hermes'" in app.json (1 ms)
✓ should throw if ":hermes_enabled => true" in Podfile but no "jsEngine: 'hermes'" in app.json
✓ should throw if (":hermes_enabled => false" or not existed in Podfile) and "jsEngine: 'hermes'" in app.json (1 ms)
✓ should resolve if "expo.jsEngine": 'hermes' in Podfile.properties.json and "jsEngine: 'hermes'" in app.json
✓ should handle the inconsistency between Podfile and Podfile.properties.json
```
### updated unit tests (mostly for `maybeThrowFromInconsistentEngineAsync` interface change)
```
maybeThrowFromInconsistentEngineAsync - common
✓ should resolve for managed project
maybeThrowFromInconsistentEngineAsync - android
✓ should resolve if "enableHermes: true" in app/build.gradle and "jsEngine: 'hermes'" in app.json (3 ms)
✓ should throw if "enableHermes: false" in app/build.gradle and "jsEngine: 'hermes'" in app.json (1 ms)
✓ should resolve if "expo.jsEngine=hermes" in gradle.properties and "jsEngine: 'hermes'" in app.json (1 ms)
✓ should resolve if "expo.jsEngine=hermes" in gradle.properties but no "jsEngine: 'hermes'" in app.json
✓ should resolve for old sdk bare project
✓ should handle the inconsistency between app/build.gradle and gradle.properties
```
### manually test
```sh
$ expo init extest # select managed
# add `jsEngine: "hermes"` and `sdkVersion: "UNVERSIONED"` to app.json
$ EXPO_SKIP_MANIFEST_VALIDATION_TOKEN=1 /path/to/expo-cli/packages/expo-cli/bin/expo.js export -p https://example.com/
```
Extract server up to internal abstraction
Setup attachWebsocketServer
attachWebsocketServer
Extract dev server up to web socket layer
Refactor
Delete attachWebsocketServer.ts
# Why
fix https://github.com/expo/expo/issues/13626
# How
on windows, the resolving path should include `.exe` suffix.
# Test Plan
setup jsEngine as hermes
```sh
$ jq .expo.android.jsEngine app.json
hermes
```
expo export on macos and windows
# Why
For dev-client running on android emulator, user may try to load bundles from http://10.0.2.2:8081/.
This is the [host loopback address](https://developer.android.com/studio/run/emulator-networking)
To query available inspector, we tried to send `/json/list` request to metro server but using HOST address in request headers.
In this case, HOST is 10.0.2.2:8081. For metro server, sending requests to 10.0.2.2:8081 is usually unreachable.
# How
Should use metro's local server address instead of request header HOST address.
# Test Plan
1. Use dev-client to load http://10.0.2.2:8081 bundle on android emulator.
2. Open dev-menu and see if there are any timeout errros.
# Why
this pr addresses some missing parts of hermes support.
# How
1. add hermes bytecode bundle to `printBundleSizes`.
2. add hermes bytecode bundle support for `expo publish`.
3. support managed workflow by reading the `android.jsEngine` config in app.json.
4. `android.jsEngine` in app.json is now the single source of truth to determine if we need to generate hermes bytecode bundle.
5. introduce `maybeInconsistentEngineAsync()` to show an error prompt if there are inconsistencies between app config and native project.
# Test Plan
1. expo export + managed workflow app with `android.jsEngine=hermes` in app.json.
make sure exported assets has hermes bytecode bundle.
2. expo publish + managed workflow app with `android.jsEngine=hermes` in app.json.
download the asset and make sure it is a hermes bytecode bundle.
### Unit Test
```
packages/dev-server/src/__tests__/HermesBundler-test.ts
maybeInconsistentEngineAsync - android
should return false for managed project
should return false if "enableHermes: true" in app/build.gradle and "jsEngine: 'hermes'" in app.json (1 ms)
should return true if "enableHermes: false" in app/build.gradle and "jsEngine: 'hermes'" in app.json
should return false if "expo.jsEngine=hermes" in gradle.properties and "jsEngine: 'hermes'" in app.json (2 ms)
should return false for default sdk41 bare project
should return true for default sdk41 bare project but user enabled hermes manually
should handle the inconsistency between app/build.gradle and gradle.properties
```
# Why
to support hermes for managed workflow
closes [ENG-1222](https://linear.app/expo/issue/ENG-1222)
# How
add config-plugins and prebuild-configs to read `android.jsEngine` from app.json and update `expo.jsEngine` in `gradle.properties`
# Test Plan
### Unit Test
```
packages/config-plugins/src/android/__tests__/JsEngine-test.ts
jsEngine
returns default engine if no engine is provided (2 ms)
return the engine if provided
set the property if no property is existed (2 ms)
overwrite the property if an old property is existed
```
# Why
If an app is running with hermes runtime, `expo export` for self hosting update should also generate hermes bytecode instead of plain javascript.
# How
Assuming project should setup with pre-defined shape which set the runtime in gradle.properties like expo/expo#13052.
If exporting project is running with hermes, right after calling metro to build js bundles, we should further call `hermesc` to compile hbc.
The sourcemap also needs to re-compose by metro-source-map.
The overall flow is reference from [react-native's react.gradle](https://github.com/facebook/react-native/blob/0.63-stable/react.gradle).
# Test Plan
### Unit Test
```
HermesBundler-test.ts
parseGradleProperties
should return array of key-value tuple (2 ms)
should keep "=" in value if there are multiple "="
should exclude comment (1 ms)
getHermesBytecodeBundleVersionAsync
should return hermes bytecode version 74 for plain.74.hbc (13 ms)
should throw exception for plain javascript file (5 ms)
should throw exception for nonexistent file
isHermesBytecodeBundleAsync
should return true for hermes bytecode bundle file
should return false for plain javascript file
should throw exception for nonexistent file
```
### E2E Test
```
export-test.ts
should export hbc bundle if running with hermes (31292 ms)
```
# Why
For dev-menu to launch Hermes inspector.
# How
Through from metro-inspector-proxy (http://localhost:8081/json/list), we could get the url to open inspector. This requires manual steps to open inspector.
In this PR, we will launch chromium to open the inspector automatically.
# Test Plan
### Unit Test
```
createJsInspectorMiddleware
should return specific app entity for GET request with given applicationId (5 ms)
should return 404 for GET request with nonexistent applicationId (1 ms)
should return 400 for GET request without parameters
should open browser for PUT request with given applicationId (14 ms)
```