diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cae836..c4ebb70 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` (#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 }` 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..cd713c8 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 @@ -43,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) @@ -84,7 +82,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 +288,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:"