Skip to content

Commit

Permalink
feat(expo): add an Expo config plugin to simplify enabling Next Storage
Browse files Browse the repository at this point in the history
Fixes #750

Co-Authored-By: Bill Spooner <[email protected]>
  • Loading branch information
hassankhan and sandyklark committed Oct 9, 2024
1 parent db99ba9 commit e570c09
Show file tree
Hide file tree
Showing 8 changed files with 3,121 additions and 70 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-eggs-grin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@react-native-async-storage/async-storage": minor
---

Add an Expo config plugin to simplify enabling Next Storage
1 change: 1 addition & 0 deletions packages/default-storage/app.plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./plugin/build');
8 changes: 7 additions & 1 deletion packages/default-storage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@
"bundle:android": "scripts/android_e2e.sh 'bundle'",
"bundle:ios": "scripts/ios_e2e.sh 'bundle'",
"bundle:macos": "react-native bundle --entry-file index.ts --platform macos --dev false --bundle-output example/index.macos.jsbundle",
"test": "concurrently -n lint,ts yarn:test:lint yarn:test:ts",
"plugin:build": "expo-module build plugin",
"plugin:clean": "expo-module clean plugin",
"plugin:lint": "expo-module lint plugin",
"plugin:test": "expo-module test plugin",
"test": "concurrently -n lint,ts,plugin-lint yarn:test:lint yarn:test:ts yarn:plugin:lint",
"test:lint": "eslint $(git ls-files '*.js' '*.ts' '*.tsx')",
"test:ts": "tsc",
"test:e2e:android": "scripts/android_e2e.sh 'test'",
Expand All @@ -71,6 +75,7 @@
"devDependencies": {
"@babel/core": "^7.20.0",
"@babel/preset-env": "^7.20.0",
"@expo/config-plugins": "^8.0.8",
"@react-native/babel-preset": "^0.75.0",
"@react-native/metro-config": "^0.75.0",
"@rnx-kit/metro-config": "^2.0.0",
Expand All @@ -88,6 +93,7 @@
"concurrently": "^8.2.2",
"eslint": "^8.54.0",
"expo": "^48.0.0",
"expo-module-scripts": "^3.5.2",
"lodash": "^4.17.21",
"prettier": "2.8.8",
"react": "^18.2.0",
Expand Down
2 changes: 2 additions & 0 deletions packages/default-storage/plugin/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// @generated by expo-module-scripts
module.exports = require('expo-module-scripts/eslintrc.base.js');
1 change: 1 addition & 0 deletions packages/default-storage/plugin/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('expo-module-scripts/jest-preset-plugin');
34 changes: 34 additions & 0 deletions packages/default-storage/plugin/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { ConfigPlugin} from '@expo/config-plugins';
import { withGradleProperties } from '@expo/config-plugins';

export type AsyncStorageOptions = {
useNextStorage?: boolean;
}

const withUseNextStorage: ConfigPlugin<AsyncStorageOptions> = (config, { useNextStorage = false }) => {
if (!useNextStorage) {
return config;
}

return withGradleProperties(config, (config) => {
config.modResults.push({
key: 'AsyncStorage_useNextStorage',
value: 'true',
type: 'property',
});

return config;
});
};

const DEFAULT_OPTS: AsyncStorageOptions = {
useNextStorage: false,
}

const withAsyncStorage: ConfigPlugin<AsyncStorageOptions> = (config, props) => {
const normalizedProps = { ...DEFAULT_OPTS, ...props };
config = withUseNextStorage(config, normalizedProps);
return config;
};

export default withAsyncStorage;
9 changes: 9 additions & 0 deletions packages/default-storage/plugin/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "expo-module-scripts/tsconfig.plugin",
"compilerOptions": {
"outDir": "build",
"rootDir": "src"
},
"include": ["./src"],
"exclude": ["**/__mocks__/*", "**/__tests__/*"]
}
Loading

0 comments on commit e570c09

Please sign in to comment.