Skip to content

Commit 4954411

Browse files
authored
Merge pull request #2 from AutoLocalise/react-native
update build issue
2 parents 112a0c2 + 9f404a6 commit 4954411

File tree

4 files changed

+143
-9
lines changed

4 files changed

+143
-9
lines changed

package-lock.json

Lines changed: 128 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
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",

rollup.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import typescript from "@rollup/plugin-typescript";
2+
import resolve from "@rollup/plugin-node-resolve";
3+
import commonjs from "@rollup/plugin-commonjs";
24

35
export 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
};

src/storage/index.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1+
import AsyncStorage from "@react-native-async-storage/async-storage";
2+
13
interface 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
}

0 commit comments

Comments
 (0)