File tree Expand file tree Collapse file tree 4 files changed +143
-9
lines changed Expand file tree Collapse file tree 4 files changed +143
-9
lines changed Original file line number Diff line number Diff line change 2929 "@react-native-async-storage/async-storage" : " >=1.18.0"
3030 },
3131 "devDependencies" : {
32+ "@rollup/plugin-commonjs" : " ^25.0.0" ,
33+ "@rollup/plugin-node-resolve" : " ^15.0.0" ,
3234 "@rollup/plugin-typescript" : " ^11.1.3" ,
3335 "tslib" : " ^2.6.2" ,
3436 "@testing-library/jest-dom" : " ^6.6.3" ,
Original file line number Diff line number Diff line change 11import typescript from "@rollup/plugin-typescript" ;
2+ import resolve from "@rollup/plugin-node-resolve" ;
3+ import commonjs from "@rollup/plugin-commonjs" ;
24
35export default {
46 input : "src/index.ts" ,
@@ -7,11 +9,13 @@ export default {
79 file : "dist/index.js" ,
810 format : "cjs" ,
911 sourcemap : true ,
12+ exports : "named" ,
1013 } ,
1114 {
1215 file : "dist/index.esm.js" ,
1316 format : "es" ,
1417 sourcemap : true ,
18+ exports : "named" ,
1519 } ,
1620 ] ,
1721 external : [
@@ -20,10 +24,14 @@ export default {
2024 "@react-native-async-storage/async-storage" ,
2125 ] ,
2226 plugins : [
27+ resolve ( ) ,
28+ commonjs ( ) ,
2329 typescript ( {
2430 tsconfig : "./tsconfig.json" ,
2531 declaration : true ,
2632 declarationDir : "dist" ,
33+ jsx : "react" ,
34+ sourceMap : true ,
2735 } ) ,
2836 ] ,
2937} ;
Original file line number Diff line number Diff line change 1+ import AsyncStorage from "@react-native-async-storage/async-storage" ;
2+
13interface StorageAdapter {
24 getItem : ( key : string ) => Promise < string | null > ;
35 setItem : ( key : string , value : string ) => Promise < void > ;
46 removeItem : ( key : string ) => Promise < void > ;
57}
68
7- export async function getStorageAdapter ( ) : Promise < StorageAdapter > {
8- try {
9- const AsyncStorage = await import (
10- "@react-native-async-storage/async-storage"
11- ) . catch ( ( ) => null ) ;
12- if ( AsyncStorage ?. default ) {
13- return AsyncStorage . default ;
14- }
15- } catch ( e ) {
9+ export function getStorageAdapter ( ) : StorageAdapter {
10+ if ( ! AsyncStorage ) {
1611 throw new Error (
1712 "No storage adapter available. Please install @react-native-async-storage/async-storage"
1813 ) ;
1914 }
15+ return AsyncStorage ;
2016}
You can’t perform that action at this time.
0 commit comments