Skip to content

Commit 177a920

Browse files
feat(expo): add an Expo config plugin to simplify enabling Next Storage
Fixes #750 Co-Authored-By: Bill Spooner <[email protected]>
1 parent 471a1b8 commit 177a920

File tree

8 files changed

+3180
-48
lines changed

8 files changed

+3180
-48
lines changed

.changeset/shaggy-eggs-grin.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-native-async-storage/async-storage": minor
3+
---
4+
5+
Add an Expo config plugin to simplify enabling Next Storage
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./plugin/build');

packages/default-storage/package.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@
5252
"bundle:android": "scripts/android_e2e.sh 'bundle'",
5353
"bundle:ios": "scripts/ios_e2e.sh 'bundle'",
5454
"bundle:macos": "react-native bundle --entry-file index.ts --platform macos --dev false --bundle-output example/index.macos.jsbundle",
55-
"test": "concurrently -n lint,ts yarn:test:lint yarn:test:ts",
55+
"plugin:build": "expo-module build plugin",
56+
"plugin:clean": "expo-module clean plugin",
57+
"plugin:lint": "expo-module lint plugin",
58+
"plugin:test": "expo-module test plugin",
59+
"test": "concurrently -n lint,ts,plugin-lint yarn:test:lint yarn:test:ts yarn:plugin:lint",
5660
"test:lint": "eslint $(git ls-files '*.js' '*.ts' '*.tsx')",
5761
"test:ts": "tsc",
5862
"test:e2e:android": "scripts/android_e2e.sh 'test'",
@@ -71,6 +75,7 @@
7175
"devDependencies": {
7276
"@babel/core": "^7.20.0",
7377
"@babel/preset-env": "^7.20.0",
78+
"@expo/config-plugins": "^8.0.8",
7479
"@react-native/babel-preset": "^0.73.19",
7580
"@react-native/metro-config": "^0.73.3",
7681
"@rnx-kit/metro-config": "^1.3.15",
@@ -88,6 +93,7 @@
8893
"concurrently": "^8.2.2",
8994
"eslint": "^8.54.0",
9095
"expo": "^48.0.0",
96+
"expo-module-scripts": "^3.5.2",
9197
"lodash": "^4.17.21",
9298
"prettier": "2.8.8",
9399
"react": "18.2.0",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @generated by expo-module-scripts
2+
module.exports = require('expo-module-scripts/eslintrc.base.js');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('expo-module-scripts/jest-preset-plugin');
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { ConfigPlugin} from '@expo/config-plugins';
2+
import { withGradleProperties } from '@expo/config-plugins';
3+
4+
export type AsyncStorageOptions = {
5+
useNextStorage?: boolean;
6+
}
7+
8+
const withUseNextStorage: ConfigPlugin<AsyncStorageOptions> = (config, { useNextStorage = false }) => {
9+
if (!useNextStorage) {
10+
return config;
11+
}
12+
13+
return withGradleProperties(config, (config) => {
14+
config.modResults.push({
15+
key: 'AsyncStorage_useNextStorage',
16+
value: 'true',
17+
type: 'property',
18+
});
19+
20+
return config;
21+
});
22+
};
23+
24+
const DEFAULT_OPTS: AsyncStorageOptions = {
25+
useNextStorage: false,
26+
}
27+
28+
const withAsyncStorage: ConfigPlugin<AsyncStorageOptions> = (config, props) => {
29+
const normalizedProps = { ...DEFAULT_OPTS, ...props };
30+
config = withUseNextStorage(config, normalizedProps);
31+
return config;
32+
};
33+
34+
export default withAsyncStorage;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "expo-module-scripts/tsconfig.plugin",
3+
"compilerOptions": {
4+
"outDir": "build",
5+
"rootDir": "src"
6+
},
7+
"include": ["./src"],
8+
"exclude": ["**/__mocks__/*", "**/__tests__/*"]
9+
}

0 commit comments

Comments
 (0)