From 266ba580121503dfb6e6535b9cdc9d0a8d26ffdd Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Sat, 9 Apr 2022 15:39:11 +0100 Subject: [PATCH 1/3] Remove deprecated exists --- CHANGELOG.md | 1 + src/Node/FS/Async.js | 1 - src/Node/FS/Async.purs | 8 -------- test/Test.purs | 21 +++++++++------------ 4 files changed, 10 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cae836..a889f34 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Notable changes to this project are documented in this file. The format is based ## [Unreleased] Breaking changes: +- Remove `Async.exists` - Update `mkdir` to take an options record arg, exposing `recursive` option (#53, #55, #58 by @JordanMartinez) To get back the old behavior of `mkdir'`, you would call `mkdir' { recursive: false, mode: mkPerms all all all }` diff --git a/src/Node/FS/Async.js b/src/Node/FS/Async.js index b14ec6f..1ed7423 100644 --- a/src/Node/FS/Async.js +++ b/src/Node/FS/Async.js @@ -16,7 +16,6 @@ export { readFile as readFileImpl, writeFile as writeFileImpl, appendFile as appendFileImpl, - exists as existsImpl, open as openImpl, read as readImpl, write as writeImpl, diff --git a/src/Node/FS/Async.purs b/src/Node/FS/Async.purs index 025ec3f..3e7bfe8 100644 --- a/src/Node/FS/Async.purs +++ b/src/Node/FS/Async.purs @@ -22,7 +22,6 @@ module Node.FS.Async , writeTextFile , appendFile , appendTextFile - , exists , fdOpen , fdRead , fdNext @@ -84,7 +83,6 @@ foreign import utimesImpl :: Fn4 FilePath Int Int (JSCallback Unit) Unit foreign import readFileImpl :: forall a opts. Fn3 FilePath { | opts } (JSCallback a) Unit foreign import writeFileImpl :: forall a opts. Fn4 FilePath a { | opts } (JSCallback Unit) Unit foreign import appendFileImpl :: forall a opts. Fn4 FilePath a { | opts } (JSCallback Unit) Unit -foreign import existsImpl :: forall a. Fn2 FilePath (Boolean -> a) Unit foreign import openImpl :: Fn4 FilePath String (Nullable FileMode) (JSCallback FileDescriptor) Unit foreign import readImpl :: Fn6 FileDescriptor Buffer BufferOffset BufferLength (Nullable FilePosition) (JSCallback ByteCount) Unit foreign import writeImpl :: Fn6 FileDescriptor Buffer BufferOffset BufferLength (Nullable FilePosition) (JSCallback ByteCount) Unit @@ -291,12 +289,6 @@ appendTextFile :: Encoding appendTextFile encoding file buff cb = mkEffect $ \_ -> runFn4 appendFileImpl file buff { encoding: show encoding } (handleCallback cb) --- | Check if the path exists. -exists :: FilePath - -> (Boolean -> Effect Unit) - -> Effect Unit -exists file cb = mkEffect $ \_ -> runFn2 - existsImpl file $ \b -> unsafePerformEffect (cb b) -- | Open a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback) -- | for details. diff --git a/test/Test.purs b/test/Test.purs index a075a48..c7eeb36 100644 --- a/test/Test.purs +++ b/test/Test.purs @@ -1,24 +1,21 @@ module Test where import Prelude -import Data.Maybe (Maybe(..)) + import Data.Either (Either(..), either) +import Data.Maybe (Maybe(..)) import Data.Traversable (traverse) import Effect (Effect) -import Effect.Exception (Error, error, throwException, catchException) import Effect.Console (log) - -import Node.Encoding (Encoding(..)) +import Effect.Exception (Error, error, throwException, catchException) import Node.Buffer as Buffer -import Node.Path as Path -import Unsafe.Coerce (unsafeCoerce) - +import Node.Encoding (Encoding(..)) import Node.FS (FileFlags(..)) -import Node.FS.Stats (statusChangedTime, accessedTime, modifiedTime, - isSymbolicLink, isSocket, isFIFO, isCharacterDevice, - isBlockDevice, isDirectory, isFile) import Node.FS.Async as A +import Node.FS.Stats (statusChangedTime, accessedTime, modifiedTime, isSymbolicLink, isSocket, isFIFO, isCharacterDevice, isBlockDevice, isDirectory, isFile) import Node.FS.Sync as S +import Node.Path as Path +import Unsafe.Coerce (unsafeCoerce) -- Cheat to allow `main` to type check. See also issue #5 in -- purescript-exceptions. @@ -34,8 +31,8 @@ main :: Effect Unit main = do let fp = Path.concat - A.exists (fp ["test", "Test.purs"]) $ \e -> - log $ "Test.purs exists? " <> show e + e <- S.exists (fp ["test", "Test.purs"]) + log $ "Test.purs exists? " <> show e file <- S.readTextFile UTF8 (fp ["test", "Test.purs"]) log "\n\nreadTextFile sync result:" From 6c93405d962b53a38bc2291e94dc6cfe22855eb7 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Sat, 9 Apr 2022 15:41:37 +0100 Subject: [PATCH 2/3] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a889f34..c4ebb70 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ Notable changes to this project are documented in this file. The format is based ## [Unreleased] Breaking changes: -- Remove `Async.exists` +- Remove `Async.exists` (#61 by @sigma-andex) - Update `mkdir` to take an options record arg, exposing `recursive` option (#53, #55, #58 by @JordanMartinez) To get back the old behavior of `mkdir'`, you would call `mkdir' { recursive: false, mode: mkPerms all all all }` From 7606e69dd0dab4a7cfd7cfbf096c8618561b1174 Mon Sep 17 00:00:00 2001 From: sigma-andex <77549848+sigma-andex@users.noreply.github.com> Date: Sat, 9 Apr 2022 15:45:09 +0100 Subject: [PATCH 3/3] Remove redundant import --- src/Node/FS/Async.purs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Node/FS/Async.purs b/src/Node/FS/Async.purs index 3e7bfe8..cd713c8 100644 --- a/src/Node/FS/Async.purs +++ b/src/Node/FS/Async.purs @@ -42,7 +42,6 @@ import Data.Nullable (Nullable, toNullable) import Data.Time.Duration (Milliseconds(..)) import Effect (Effect) import Effect.Exception (Error) -import Effect.Unsafe (unsafePerformEffect) import Node.Buffer (Buffer, size) import Node.Encoding (Encoding) import Node.FS (FileDescriptor, ByteCount, FilePosition, BufferLength, BufferOffset, FileMode, FileFlags, SymlinkType, fileFlagsToNode, symlinkTypeToNode)