From 5805f9f268e1bc7ab4abd52f09faa15b1b1b77c6 Mon Sep 17 00:00:00 2001 From: "WWIMMO\\TST" Date: Wed, 2 Dec 2020 16:39:39 +0100 Subject: [PATCH 1/8] Update RN-FS to point to our repo for RN-Windows support --- package.json | 4 ++-- yarn.lock | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 3eb854c..5b8263f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@connected-home/redux-persist-fs-storage", - "version": "2.1.0", + "version": "2.1.1", "author": "Peter Bevan", "description": "Redux-Persist storage engine for React Native file system", "repository": "https://github.com/ConnectedHomes/redux-persist-fs-storage.git", @@ -15,7 +15,7 @@ "AsyncStorage" ], "dependencies": { - "react-native-fs": "2.16" + "react-native-fs": "https://github.com/wwimmo/react-native-fs.git" }, "peerDependencies": { "react-native": ">=0.61.0" diff --git a/yarn.lock b/yarn.lock index 3dc496c..a92b090 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6,13 +6,14 @@ base-64@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/base-64/-/base-64-0.1.0.tgz#780a99c84e7d600260361511c4877613bf24f6bb" -react-native-fs@2.12: - version "2.12.0" - resolved "https://registry.yarnpkg.com/react-native-fs/-/react-native-fs-2.12.0.tgz#77b7893d9f9a9318f577031a3447d1aace022020" +"react-native-fs@https://github.com/wwimmo/react-native-fs.git": + version "2.16.8" + resolved "https://github.com/wwimmo/react-native-fs.git#a0a3aee28c667ba8864d1e058a9fda49b43b22a2" dependencies: base-64 "^0.1.0" - utf8 "^2.1.1" + utf8 "^3.0.0" -utf8@^2.1.1: - version "2.1.2" - resolved "https://registry.yarnpkg.com/utf8/-/utf8-2.1.2.tgz#1fa0d9270e9be850d9b05027f63519bf46457d96" +utf8@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/utf8/-/utf8-3.0.0.tgz#f052eed1364d696e769ef058b183df88c87f69d1" + integrity sha512-E8VjFIQ/TyQgp+TZfS6l8yp/xWppSAHzidGiRrqe4bK4XP9pTRyKFgGJpO3SN7zdX4DeomTrwaseCHovfpFcqQ== From 0fc6aff30fbc096ff7f31bb8e4f6f23c64d8128c Mon Sep 17 00:00:00 2001 From: "WWIMMO\\TST" Date: Wed, 2 Dec 2020 17:01:04 +0100 Subject: [PATCH 2/8] Add OSPathSeparator and bump version --- index.js | 42 ++++++++++++++++++++++++------------------ package.json | 2 +- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/index.js b/index.js index 155b82e..a365982 100644 --- a/index.js +++ b/index.js @@ -1,21 +1,27 @@ /* @flow */ -import fs from 'react-native-fs'; +import fs from "react-native-fs"; +import { Platform } from "react-native"; export const DocumentDir = fs.DocumentDirectoryPath; export const CacheDir = fs.CachesDirectoryPath; +const OSPathSeparator = Platform.select({ + ios: "/", + android: "/", + windows: "\\", +}); const resolvePath = (...paths: Array) => - '/' + + OSPathSeparator + paths - .join('/') - .split('/') - .filter(part => part && part !== '.') - .join('/'); + .join(OSPathSeparator) + .split(OSPathSeparator) + .filter((part) => part && part !== ".") + .join(OSPathSeparator); // Wrap function to support both Promise and callback async function withCallback( callback?: ?(error: ?Error, result: R | void) => void, - func: () => Promise, + func: () => Promise ): Promise { try { const result = await func(); @@ -34,40 +40,40 @@ async function withCallback( const FSStorage = ( location?: string = DocumentDir, - folder?: string = 'reduxPersist', - excludeFromBackup?: boolean = true, + folder?: string = "reduxPersist", + excludeFromBackup?: boolean = true ) => { const baseFolder = resolvePath(location, folder); const pathForKey = (key: string) => - resolvePath(baseFolder, key.replace(/[;\\/:*?\"<>|&']/gi,'_')); + resolvePath(baseFolder, key.replace(/[;\\/:*?\"<>|&']/gi, "_")); const setItem = ( key: string, value: string, - callback?: ?(error: ?Error) => void, + callback?: ?(error: ?Error) => void ): Promise => withCallback(callback, async () => { await fs.mkdir(baseFolder, { NSURLIsExcludedFromBackupKey: excludeFromBackup, }); - await fs.writeFile(pathForKey(key), value, 'utf8'); + await fs.writeFile(pathForKey(key), value, "utf8"); }); const getItem = ( key: string, - callback?: ?(error: ?Error, result: ?string) => void, + callback?: ?(error: ?Error, result: ?string) => void ): Promise => withCallback(callback, async () => { if (await fs.exists(pathForKey(key))) { - const data = await fs.readFile(pathForKey(key), 'utf8'); + const data = await fs.readFile(pathForKey(key), "utf8"); return data; } }); const removeItem = ( key: string, - callback?: ?(error: ?Error) => void, + callback?: ?(error: ?Error) => void ): Promise => withCallback(callback, async () => { if (await fs.exists(pathForKey(key))) { @@ -76,7 +82,7 @@ const FSStorage = ( }); const getAllKeys = ( - callback?: ?(error: ?Error, keys: ?Array) => void, + callback?: ?(error: ?Error, keys: ?Array) => void ) => withCallback(callback, async () => { await fs.mkdir(baseFolder, { @@ -84,8 +90,8 @@ const FSStorage = ( }); const files = await fs.readDir(baseFolder); const fileNames = files - .filter(file => file.isFile()) - .map(file => decodeURIComponent(file.name)); + .filter((file) => file.isFile()) + .map((file) => decodeURIComponent(file.name)); return fileNames; }); diff --git a/package.json b/package.json index 5b8263f..50a7b07 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@connected-home/redux-persist-fs-storage", - "version": "2.1.1", + "version": "2.1.2", "author": "Peter Bevan", "description": "Redux-Persist storage engine for React Native file system", "repository": "https://github.com/ConnectedHomes/redux-persist-fs-storage.git", From 3a42383d47ef0d3753b9e0952382fa682147fa6b Mon Sep 17 00:00:00 2001 From: "WWIMMO\\TST" Date: Wed, 2 Dec 2020 17:24:20 +0100 Subject: [PATCH 3/8] Add logs to debug windows temporarily, bump version --- index.js | 9 +++++++++ package.json | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a365982..7468e09 100644 --- a/index.js +++ b/index.js @@ -44,6 +44,7 @@ const FSStorage = ( excludeFromBackup?: boolean = true ) => { const baseFolder = resolvePath(location, folder); + console.log(`baseFolder is: ${baseFolder}`); const pathForKey = (key: string) => resolvePath(baseFolder, key.replace(/[;\\/:*?\"<>|&']/gi, "_")); @@ -54,6 +55,8 @@ const FSStorage = ( callback?: ?(error: ?Error) => void ): Promise => withCallback(callback, async () => { + const path = pathForKey(key); + console.log(`setItem path is: ${path}`); await fs.mkdir(baseFolder, { NSURLIsExcludedFromBackupKey: excludeFromBackup, }); @@ -65,6 +68,8 @@ const FSStorage = ( callback?: ?(error: ?Error, result: ?string) => void ): Promise => withCallback(callback, async () => { + const path = pathForKey(key); + console.log(`getItem path is: ${path}`); if (await fs.exists(pathForKey(key))) { const data = await fs.readFile(pathForKey(key), "utf8"); return data; @@ -76,6 +81,8 @@ const FSStorage = ( callback?: ?(error: ?Error) => void ): Promise => withCallback(callback, async () => { + const path = pathForKey(key); + console.log(`removeItem path is: ${path}`); if (await fs.exists(pathForKey(key))) { await fs.unlink(pathForKey(key)); } @@ -85,6 +92,8 @@ const FSStorage = ( callback?: ?(error: ?Error, keys: ?Array) => void ) => withCallback(callback, async () => { + const path = pathForKey(key); + console.log(`getAllKeys path is: ${path}`); await fs.mkdir(baseFolder, { NSURLIsExcludedFromBackupKey: excludeFromBackup, }); diff --git a/package.json b/package.json index 50a7b07..8da26c5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@connected-home/redux-persist-fs-storage", - "version": "2.1.2", + "version": "2.1.3", "author": "Peter Bevan", "description": "Redux-Persist storage engine for React Native file system", "repository": "https://github.com/ConnectedHomes/redux-persist-fs-storage.git", From c706ddfcd276cfbe0205db9f3136b5f0603366c7 Mon Sep 17 00:00:00 2001 From: "WWIMMO\\TST" Date: Wed, 2 Dec 2020 18:04:32 +0100 Subject: [PATCH 4/8] Make redux-persist-fs-storage RN-Windows compatible --- index.js | 50 +++++++++++++++++++++++++++++--------------------- package.json | 2 +- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/index.js b/index.js index 7468e09..5ae58ea 100644 --- a/index.js +++ b/index.js @@ -10,13 +10,23 @@ const OSPathSeparator = Platform.select({ windows: "\\", }); -const resolvePath = (...paths: Array) => - OSPathSeparator + - paths - .join(OSPathSeparator) - .split(OSPathSeparator) - .filter((part) => part && part !== ".") - .join(OSPathSeparator); +const resolvePath = (...paths: Array) => { + if (Platform.OS === "windows") { + return paths + .join(OSPathSeparator) + .split(OSPathSeparator) + .filter((part) => part && part !== ".") + .join(OSPathSeparator); + } + return ( + OSPathSeparator + + paths + .join(OSPathSeparator) + .split(OSPathSeparator) + .filter((part) => part && part !== ".") + .join(OSPathSeparator) + ); +}; // Wrap function to support both Promise and callback async function withCallback( @@ -44,8 +54,6 @@ const FSStorage = ( excludeFromBackup?: boolean = true ) => { const baseFolder = resolvePath(location, folder); - console.log(`baseFolder is: ${baseFolder}`); - const pathForKey = (key: string) => resolvePath(baseFolder, key.replace(/[;\\/:*?\"<>|&']/gi, "_")); @@ -55,11 +63,12 @@ const FSStorage = ( callback?: ?(error: ?Error) => void ): Promise => withCallback(callback, async () => { - const path = pathForKey(key); - console.log(`setItem path is: ${path}`); - await fs.mkdir(baseFolder, { - NSURLIsExcludedFromBackupKey: excludeFromBackup, - }); + const baseFolderExists = await fs.exists(baseFolder); + if (!baseFolderExists) { + await fs.mkdir(baseFolder, { + NSURLIsExcludedFromBackupKey: excludeFromBackup, + }); + } await fs.writeFile(pathForKey(key), value, "utf8"); }); @@ -68,8 +77,6 @@ const FSStorage = ( callback?: ?(error: ?Error, result: ?string) => void ): Promise => withCallback(callback, async () => { - const path = pathForKey(key); - console.log(`getItem path is: ${path}`); if (await fs.exists(pathForKey(key))) { const data = await fs.readFile(pathForKey(key), "utf8"); return data; @@ -81,8 +88,6 @@ const FSStorage = ( callback?: ?(error: ?Error) => void ): Promise => withCallback(callback, async () => { - const path = pathForKey(key); - console.log(`removeItem path is: ${path}`); if (await fs.exists(pathForKey(key))) { await fs.unlink(pathForKey(key)); } @@ -94,9 +99,12 @@ const FSStorage = ( withCallback(callback, async () => { const path = pathForKey(key); console.log(`getAllKeys path is: ${path}`); - await fs.mkdir(baseFolder, { - NSURLIsExcludedFromBackupKey: excludeFromBackup, - }); + const baseFolderExists = await fs.exists(baseFolder); + if (!baseFolderExists) { + await fs.mkdir(baseFolder, { + NSURLIsExcludedFromBackupKey: excludeFromBackup, + }); + } const files = await fs.readDir(baseFolder); const fileNames = files .filter((file) => file.isFile()) diff --git a/package.json b/package.json index 8da26c5..6072423 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@connected-home/redux-persist-fs-storage", - "version": "2.1.3", + "version": "2.1.4", "author": "Peter Bevan", "description": "Redux-Persist storage engine for React Native file system", "repository": "https://github.com/ConnectedHomes/redux-persist-fs-storage.git", From 1a8a0f5f63ee0cc6190f9da19d6c3df468dcec43 Mon Sep 17 00:00:00 2001 From: "WWIMMO\\TST" Date: Thu, 3 Dec 2020 10:12:08 +0100 Subject: [PATCH 5/8] Update RN-FS Dependency --- index.js | 2 -- package.json | 2 +- yarn.lock | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 5ae58ea..90e19da 100644 --- a/index.js +++ b/index.js @@ -97,8 +97,6 @@ const FSStorage = ( callback?: ?(error: ?Error, keys: ?Array) => void ) => withCallback(callback, async () => { - const path = pathForKey(key); - console.log(`getAllKeys path is: ${path}`); const baseFolderExists = await fs.exists(baseFolder); if (!baseFolderExists) { await fs.mkdir(baseFolder, { diff --git a/package.json b/package.json index 6072423..0d5246f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@connected-home/redux-persist-fs-storage", - "version": "2.1.4", + "version": "2.1.5", "author": "Peter Bevan", "description": "Redux-Persist storage engine for React Native file system", "repository": "https://github.com/ConnectedHomes/redux-persist-fs-storage.git", diff --git a/yarn.lock b/yarn.lock index a92b090..c045a06 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8,7 +8,7 @@ base-64@^0.1.0: "react-native-fs@https://github.com/wwimmo/react-native-fs.git": version "2.16.8" - resolved "https://github.com/wwimmo/react-native-fs.git#a0a3aee28c667ba8864d1e058a9fda49b43b22a2" + resolved "https://github.com/wwimmo/react-native-fs.git#9ca95b352756a7255ffc5ec705a6fe75f6470cfc" dependencies: base-64 "^0.1.0" utf8 "^3.0.0" From ebb34209df62667185ef753e4576dd169bc6e719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Steinbr=C3=BCchel?= Date: Thu, 3 Dec 2020 18:54:24 +0100 Subject: [PATCH 6/8] Update README.md --- README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c2853b..ed3e630 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # Redux Persist FS Storage +## Forked for RN-Windows support, read the instructions how to install it + > [Redux Persist](https://github.com/rt2zz/redux-persist/) storage engine for React Native file system Inspired by [redux-persist-filesystem-storage](https://github.com/robwalkerco/redux-persist-filesystem-storage), this module works as adapter between [react-native-fs](https://github.com/itinance/react-native-fs) and [redux-persist](https://github.com/rt2zz/redux-persist/). @@ -10,12 +12,14 @@ Inspired by [redux-persist-filesystem-storage](https://github.com/robwalkerco/re yarn add react-native-fs redux-persist-fs-storage ``` -This will install `react-native-fs` as dependency. So make sure to link it natively: +This will install `react-native-fs` as dependency. So make sure to link it natively (if you're below RN 0.60): ``` react-native link react-native-fs ``` +After that, replace the react-native-fs and redux-persist-fs-storage versions with the `wwimmo/react-native-fs` and `wwimmo/redux-persist-fs-storage` .git links and npm install/yarn again. + See `react-native-fs`'s [documentation](https://github.com/itinance/react-native-fs) for details. ### Usage From dc87aebfa6a38af945d44d68d2f7fc81d5117dbb Mon Sep 17 00:00:00 2001 From: "WWIMMO\\TST" Date: Tue, 2 Mar 2021 14:56:02 +0100 Subject: [PATCH 7/8] Update rn-fs dep --- yarn.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yarn.lock b/yarn.lock index c045a06..6e5ed2b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8,7 +8,7 @@ base-64@^0.1.0: "react-native-fs@https://github.com/wwimmo/react-native-fs.git": version "2.16.8" - resolved "https://github.com/wwimmo/react-native-fs.git#9ca95b352756a7255ffc5ec705a6fe75f6470cfc" + resolved "https://github.com/wwimmo/react-native-fs.git#f7b05dea94eb24bb5ad03805d7e897b8e2b2a2ad" dependencies: base-64 "^0.1.0" utf8 "^3.0.0" From 38f72a529a8da9ad57bcae8c92f272078e4c72b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Steinbr=C3=BCchel?= Date: Mon, 20 Jun 2022 12:02:34 +0200 Subject: [PATCH 8/8] Update RNFS commit reference --- yarn.lock | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/yarn.lock b/yarn.lock index 6e5ed2b..3919ce8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5,10 +5,11 @@ base-64@^0.1.0: version "0.1.0" resolved "https://registry.yarnpkg.com/base-64/-/base-64-0.1.0.tgz#780a99c84e7d600260361511c4877613bf24f6bb" + integrity sha512-Y5gU45svrR5tI2Vt/X9GPd3L0HNIKzGu202EjxrXMpuc2V2CiKgemAbUUsqYmZJvPtCXoUKjNZwBJzsNScUbXA== "react-native-fs@https://github.com/wwimmo/react-native-fs.git": - version "2.16.8" - resolved "https://github.com/wwimmo/react-native-fs.git#f7b05dea94eb24bb5ad03805d7e897b8e2b2a2ad" + version "2.18.0" + resolved "https://github.com/wwimmo/react-native-fs.git#3d196ea45f53a1e4b74d34b74a1bb4f8cbae966a" dependencies: base-64 "^0.1.0" utf8 "^3.0.0"