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

Support expo-dev-client #142

Merged
merged 2 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"printWidth": 100,
"tabWidth": 2,
"singleQuote": true,
"bracketSameLine": true,
"trailingComma": "es5"
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This project aims to support V8 replacement runtime for React Native. Designed a
For managed projects, you can install through the single command:

```sh
$ expo install react-native-v8 v8-android-jit expo-build-properties
$ expo install react-native-v8 v8-android-jit
```

- Please make sure you don't have [`"jsEngine": "hermes"`](https://docs.expo.dev/guides/using-hermes/#android-setup).
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@
],
"devDependencies": {
"clang-format": "^1.8.0",
"expo-build-properties": "^0.1.0",
"expo-module-scripts": "^2.0.0"
"expo": "^46.0.10",
"expo-module-scripts": "^2.1.1"
},
"peerDependencies": {
"expo-build-properties": "^0.1.0"
"expo": "*"
},
"peerDependenciesMeta": {
"expo-build-properties": {
"expo": {
"optional": true
}
}
Expand Down
6 changes: 5 additions & 1 deletion plugin/build/withV8ExpoAdapter.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import type { ConfigPlugin } from "@expo/config-plugins";
import type { ConfigPlugin } from '@expo/config-plugins';
declare const _default: ConfigPlugin<void>;
export default _default;
/**
* Update *android/app/build.gradle* to add the packaging options
*/
export declare function updateAndroidAppGradle(contents: string): string;
48 changes: 40 additions & 8 deletions plugin/build/withV8ExpoAdapter.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateAndroidAppGradle = void 0;
const config_plugins_1 = require("@expo/config-plugins");
const expo_build_properties_1 = require("expo-build-properties");
const generateCode_1 = require("@expo/config-plugins/build/utils/generateCode");
const withV8ExpoAdapter = (config) => {
return (0, expo_build_properties_1.withBuildProperties)(config, {
android: {
packagingOptions: {
exclude: ["**/**/libjsc*"],
},
},
return (0, config_plugins_1.withAppBuildGradle)(config, (config) => {
if (config.modResults.language === 'groovy') {
config.modResults.contents = updateAndroidAppGradle(config.modResults.contents);
}
else {
throw new Error('Cannot update app gradle file for react-native-v8 because the file is not groovy.');
}
return config;
});
};
const pkg = require("react-native-v8/package.json");
const pkg = require('react-native-v8/package.json');
exports.default = (0, config_plugins_1.createRunOncePlugin)(withV8ExpoAdapter, pkg.name, pkg.version);
/**
* Update *android/app/build.gradle* to add the packaging options
*/
function updateAndroidAppGradle(contents) {
const mergeTag = 'react-native-v8';
const packagingDsl = `
android {
androidComponents {
onVariants(selector().withBuildType('release')) {
packaging.jniLibs.excludes.add('**/**/libjsc*')
packaging.jniLibs.excludes.add('**/**/libhermes*')
}
}
}`;
let mergeResults;
mergeResults = (0, generateCode_1.mergeContents)({
tag: mergeTag,
src: contents,
newSrc: packagingDsl,
anchor: /^/,
offset: contents.length,
comment: '//',
});
if (mergeResults.didMerge || mergeResults.didClear) {
return mergeResults.contents;
}
return contents;
}
exports.updateAndroidAppGradle = updateAndroidAppGradle;
54 changes: 44 additions & 10 deletions plugin/src/withV8ExpoAdapter.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,51 @@
import { createRunOncePlugin } from "@expo/config-plugins";
import type { ConfigPlugin } from "@expo/config-plugins";
import { withBuildProperties } from "expo-build-properties";
import { createRunOncePlugin, withAppBuildGradle } from '@expo/config-plugins';
import { mergeContents, MergeResults } from '@expo/config-plugins/build/utils/generateCode';
import type { ConfigPlugin } from '@expo/config-plugins';

const withV8ExpoAdapter: ConfigPlugin = (config) => {
return withBuildProperties(config, {
android: {
packagingOptions: {
exclude: ["**/**/libjsc*"],
},
},
return withAppBuildGradle(config, (config) => {
if (config.modResults.language === 'groovy') {
config.modResults.contents = updateAndroidAppGradle(config.modResults.contents);
} else {
throw new Error(
'Cannot update app gradle file for react-native-v8 because the file is not groovy.'
);
}
return config;
});
};

const pkg = require("react-native-v8/package.json");
const pkg = require('react-native-v8/package.json');

export default createRunOncePlugin(withV8ExpoAdapter, pkg.name, pkg.version);

/**
* Update *android/app/build.gradle* to add the packaging options
*/
export function updateAndroidAppGradle(contents: string): string {
const mergeTag = 'react-native-v8';
const packagingDsl = `
android {
androidComponents {
onVariants(selector().withBuildType('release')) {
packaging.jniLibs.excludes.add('**/**/libjsc*')
packaging.jniLibs.excludes.add('**/**/libhermes*')
}
}
}`;

let mergeResults: MergeResults;
mergeResults = mergeContents({
tag: mergeTag,
src: contents,
newSrc: packagingDsl,
anchor: /^/,
offset: contents.length,
comment: '//',
});

if (mergeResults.didMerge || mergeResults.didClear) {
return mergeResults.contents;
}
return contents;
}
Loading