feat: Intl support for android via withAndroidJscIntl

This commit is contained in:
Fernando Rojo authored and GitHub committed 2021-07-07 23:26:20 +00:00
1 parent 98f8cbf78b
commit eb6642c0e7
9 files changed
+173

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
// @generated by expo-module-scripts
module.exports = require('expo-module-scripts/eslintrc.base.js');
+50
View File
@@ -0,0 +1,50 @@
# @config-plugins/android-jsc-intl
Expo Config Plugin to auto configure [`android-jsc-intl`](https://www.npmjs.com/package/android-jsc-intl) when the native code is generated (`expo prebuild`).
## Expo installation
> Tested against Expo SDK 42
This package cannot be used in the "Expo Go" app because [it requires custom native code](https://docs.expo.io/workflow/customizing/).
- First install the package with yarn, npm, or [`expo install`](https://docs.expo.io/workflow/expo-cli/#expo-install).
```sh
expo install android-jsc-intl @config-plugins/android-jsc-intl
```
After installing this npm package, add the [config plugin](https://docs.expo.io/guides/config-plugins/) to the [`plugins`](https://docs.expo.io/versions/latest/config/app/#plugins) array of your `app.json` or `app.config.js`:
```json
{
"expo": {
"plugins": ["@config-plugins/android-jsc-intl"]
}
}
```
Next, rebuild your app as described in the ["Adding custom native code"](https://docs.expo.io/workflow/customizing/) guide.
## API
The plugin provides props for extra customization. Every time you change the props or plugins, you'll need to rebuild (and `prebuild`) the native app. If no extra properties are added, defaults will be used.
- `foobar` (_boolean_): Does XYZ. Default `false`.
#### Example
```json
{
"expo": {
"plugins": [
[
"@config-plugins/android-jsc-intl",
{
// props ...
}
]
]
}
}
```
+1
View File
@@ -0,0 +1 @@
module.exports = require("./build/withAndroidJscIntl");
@@ -0,0 +1,3 @@
import { ConfigPlugin } from "@expo/config-plugins";
declare const _default: ConfigPlugin<void | {}>;
export default _default;
@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const config_plugins_1 = require("@expo/config-plugins");
/**
* Apply android-jsc-intl configuration for Expo SDK 42 projects.
*/
const withAndroidJscIntl = (config, _props = {}) => {
// Support passing no props to the plugin.
const props = _props || {};
// Return the modified config.
return config;
};
const pkg = {
// Prevent this plugin from being run more than once.
// This pattern enables users to safely migrate off of this
// out-of-tree `@config-plugins/android-jsc-intl` to a future
// upstream plugin in `android-jsc-intl`
name: "android-jsc-intl",
// Indicates that this plugin is dangerously linked to a module,
// and might not work with the latest version of that module.
version: "UNVERSIONED",
};
exports.default = config_plugins_1.createRunOncePlugin(withAndroidJscIntl, pkg.name, pkg.version);
+34
View File
@@ -0,0 +1,34 @@
{
"name": "@config-plugins/android-jsc-intl",
"version": "0.0.0",
"description": "Config plugin for android-jsc-intl package",
"main": "build/withAndroidJscIntl.js",
"types": "build/withAndroidJscIntl.d.ts",
"sideEffects": false,
"scripts": {
"build": "expo-module build",
"clean": "expo-module clean",
"lint": "expo-module lint",
"test": "expo-module test",
"prepare": "expo-module prepare",
"prepublishOnly": "expo-module prepublishOnly",
"expo-module": "expo-module"
},
"keywords": [
"react",
"expo",
"config-plugins",
"prebuild",
"android-jsc-intl",
"expo-42"
],
"jest": {
"preset": "expo-module-scripts"
},
"dependencies": {
"@expo/config-plugins": "^3.0.2"
},
"devDependencies": {
"expo-module-scripts": "^2.0.0"
}
}
@@ -0,0 +1,34 @@
import { ConfigPlugin, createRunOncePlugin, withAppBuildGradle } from "@expo/config-plugins";
/**
* Apply android-jsc-intl configuration for Expo SDK 42 projects.
*
* This plugin lets you access the `Intl` API in Android apps (without Hermes).
*/
const withAndroidJscIntl: ConfigPlugin = (config) => {
// Return the modified config.
return withAppBuildGradle(config, config => {
if (config.modResults.language === 'groovy') {
config.modResults.contents = config.modResults.contents.replace(
'org.webkit:android-jsc:+',
'org.webkit:android-jsc-intl:+'
)
} else {
throw new Error('[@expo/config-plugins][withAndroidJscIntl] Cannot enable Intl in Android JSC app gradle because the build.gradle is not groovy.')
}
return config
});
};
const pkg = {
// Prevent this plugin from being run more than once.
// This pattern enables users to safely migrate off of this
// out-of-tree `@config-plugins/android-jsc-intl` to a future
// upstream plugin in `android-jsc-intl`
name: "android-jsc-intl",
// Indicates that this plugin is dangerously linked to a module,
// and might not work with the latest version of that module.
version: "UNVERSIONED",
};
export default createRunOncePlugin(withAndroidJscIntl, pkg.name, pkg.version);
+8
View File
@@ -0,0 +1,8 @@
{
"extends": "expo-module-scripts/tsconfig.plugin",
"compilerOptions": {
"outDir": "./build"
},
"include": ["./src"],
"exclude": ["**/__mocks__/*", "**/__tests__/*"]
}
+18
View File
@@ -1330,6 +1330,24 @@
xcode "^3.0.1"
xml2js "^0.4.23"
"@expo/config-plugins@^3.0.2":
version "3.0.3"
resolved "https://registry.yarnpkg.com/@expo/config-plugins/-/config-plugins-3.0.3.tgz#4aff484fd2adedbd12a1cd73daabf07b1a5af0e5"
integrity sha512-+DWHd/2L3O+njVercxGSzcBUXMm5CSzdvIK+7dU+FRhoiF57y2NzBhfNQcReYx/EY1coBrYOsMtENPhV1tWoWQ==
dependencies:
"@expo/config-types" "^41.0.0"
"@expo/json-file" "8.2.30"
"@expo/plist" "0.0.13"
debug "^4.3.1"
find-up "~5.0.0"
fs-extra "9.0.0"
getenv "^1.0.0"
glob "7.1.6"
resolve-from "^5.0.0"
slash "^3.0.0"
xcode "^3.0.1"
xml2js "^0.4.23"
"@expo/config-types@^40.0.0-beta.2":
version "40.0.0-beta.2"
resolved "https://registry.yarnpkg.com/@expo/config-types/-/config-types-40.0.0-beta.2.tgz#4fea4ef5654d02218b02b0b3772529a9ce5b0471"