diff --git a/.travis.yml b/.travis.yml index beb4b48..5b14646 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,14 @@ language: node_js dist: trusty sudo: required -node_js: 6 +node_js: stable +env: + - PATH=$HOME/purescript:$PATH install: + - TAG=$(wget -q -O - https://github.com/purescript/purescript/releases/latest --server-response --max-redirect 0 2>&1 | sed -n -e 's/.*Location:.*tag\///p') + - wget -O $HOME/purescript.tar.gz https://github.com/purescript/purescript/releases/download/$TAG/linux64.tar.gz + - tar -xvf $HOME/purescript.tar.gz -C $HOME/ + - chmod a+x $HOME/purescript - npm install -g bower - npm install - bower install --production diff --git a/bower.json b/bower.json index 7aa5cd3..6161c5d 100644 --- a/bower.json +++ b/bower.json @@ -27,9 +27,12 @@ "example" ], "dependencies": { - "purescript-aff": "^4.0.0", - "purescript-either": "^3.0.0", - "purescript-node-fs": "^4.0.0", - "purescript-node-path": "^2.0.0" + "purescript-aff": "^5.0.0", + "purescript-either": "^4.0.0", + "purescript-node-fs": "^5.0.0", + "purescript-node-path": "^3.0.0" + }, + "devDependencies": { + "purescript-console": "^4.1.0" } } diff --git a/package.json b/package.json index da76be2..5a4bff0 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,8 @@ "test": "pulp test" }, "devDependencies": { - "pulp": "^11.0.0", - "purescript-psa": "^0.5.0", - "purescript": "^0.11.1", - "rimraf": "^2.5.4" + "pulp": "^12.2.0", + "purescript-psa": "^0.6.0", + "rimraf": "^2.6.2" } } diff --git a/src/Node/FS/Aff.purs b/src/Node/FS/Aff.purs index a907277..3d4a570 100644 --- a/src/Node/FS/Aff.purs +++ b/src/Node/FS/Aff.purs @@ -28,16 +28,15 @@ module Node.FS.Aff , fdWrite , fdAppend , fdClose - , module Exports ) where import Prelude -import Control.Monad.Aff (Aff, makeAff, nonCanceler) -import Control.Monad.Eff (Eff) +import Effect.Aff (Aff, makeAff, nonCanceler) +import Effect (Effect) import Data.DateTime (DateTime) import Data.Maybe (Maybe) -import Node.Buffer (Buffer, BUFFER) +import Node.Buffer (Buffer) import Node.Encoding (Encoding) import Node.FS as F import Node.FS.Async as A @@ -45,275 +44,223 @@ import Node.FS.Perms (Perms) import Node.FS.Stats (Stats) import Node.Path (FilePath) -import Node.FS (FS) as Exports - -toAff :: forall eff a. - (A.Callback eff a -> Eff (fs :: F.FS | eff) Unit) -> - Aff (fs :: F.FS | eff) a +toAff :: forall a. + (A.Callback a -> Effect Unit) -> + Aff a toAff p = makeAff \k -> p k $> nonCanceler -toAff1 :: forall eff a x. - (x -> A.Callback eff a -> Eff (fs :: F.FS | eff) Unit) -> +toAff1 :: forall a x. + (x -> A.Callback a -> Effect Unit) -> x -> - Aff (fs :: F.FS | eff) a + Aff a toAff1 f a = toAff (f a) -toAff2 :: forall eff a x y. - (x -> y -> A.Callback eff a -> Eff (fs :: F.FS | eff) Unit) -> +toAff2 :: forall a x y. + (x -> y -> A.Callback a -> Effect Unit) -> x -> y -> - Aff (fs :: F.FS | eff) a + Aff a toAff2 f a b = toAff (f a b) -toAff3 :: forall eff a x y z. - (x -> y -> z -> A.Callback eff a -> Eff (fs :: F.FS | eff) Unit) -> +toAff3 :: forall a x y z. + (x -> y -> z -> A.Callback a -> Effect Unit) -> x -> y -> z -> - Aff (fs :: F.FS | eff) a + Aff a toAff3 f a b c = toAff (f a b c) -toAff5 :: forall eff a w v x y z. - (w -> v -> x -> y -> z -> A.Callback eff a -> Eff (fs :: F.FS | eff) Unit) -> +toAff5 :: forall a w v x y z. + (w -> v -> x -> y -> z -> A.Callback a -> Effect Unit) -> w -> v -> x -> y -> z -> - Aff (fs :: F.FS | eff) a + Aff a toAff5 f a b c d e = toAff (f a b c d e) -- | -- | Rename a file. -- | -rename :: forall eff. FilePath - -> FilePath - -> Aff (fs :: F.FS | eff) Unit +rename :: FilePath -> FilePath -> Aff Unit rename = toAff2 A.rename -- | -- | Truncates a file to the specified length. -- | -truncate :: forall eff. FilePath - -> Int - -> Aff (fs :: F.FS | eff) Unit +truncate :: FilePath -> Int -> Aff Unit truncate = toAff2 A.truncate -- | -- | Changes the ownership of a file. -- | -chown :: forall eff. FilePath - -> Int - -> Int - -> Aff (fs :: F.FS | eff) Unit +chown :: FilePath -> Int -> Int -> Aff Unit chown = toAff3 A.chown -- | -- | Changes the permissions of a file. -- | -chmod :: forall eff. FilePath - -> Perms - -> Aff (fs :: F.FS | eff) Unit +chmod :: FilePath -> Perms -> Aff Unit chmod = toAff2 A.chmod -- | -- | Gets file statistics. -- | -stat :: forall eff. FilePath - -> Aff (fs :: F.FS | eff) Stats +stat :: FilePath -> Aff Stats stat = toAff1 A.stat -- | -- | Creates a link to an existing file. -- | -link :: forall eff. FilePath - -> FilePath - -> Aff (fs :: F.FS | eff) Unit +link :: FilePath -> FilePath -> Aff Unit link = toAff2 A.link -- | -- | Creates a symlink. -- | -symlink :: forall eff. FilePath - -> FilePath - -> F.SymlinkType - -> Aff (fs :: F.FS | eff) Unit +symlink :: FilePath + -> FilePath + -> F.SymlinkType + -> Aff Unit symlink = toAff3 A.symlink -- | -- | Reads the value of a symlink. -- | -readlink :: forall eff. FilePath - -> Aff (fs :: F.FS | eff) FilePath +readlink :: FilePath -> Aff FilePath readlink = toAff1 A.readlink -- | -- | Find the canonicalized absolute location for a path. -- | -realpath :: forall eff. FilePath - -> Aff (fs :: F.FS | eff) FilePath +realpath :: FilePath -> Aff FilePath realpath = toAff1 A.realpath -- | -- | Find the canonicalized absolute location for a path using a cache object -- | for already resolved paths. -- | -realpath' :: forall eff cache. FilePath - -> { | cache } - -> Aff (fs :: F.FS | eff) FilePath +realpath' :: forall cache. FilePath -> { | cache } -> Aff FilePath realpath' = toAff2 A.realpath' -- | -- | Deletes a file. -- | -unlink :: forall eff. FilePath - -> Aff (fs :: F.FS | eff) Unit +unlink :: FilePath -> Aff Unit unlink = toAff1 A.unlink -- | -- | Deletes a directory. -- | -rmdir :: forall eff. FilePath - -> Aff (fs :: F.FS | eff) Unit +rmdir :: FilePath -> Aff Unit rmdir = toAff1 A.rmdir -- | -- | Makes a new directory. -- | -mkdir :: forall eff. FilePath - -> Aff (fs :: F.FS | eff) Unit +mkdir :: FilePath -> Aff Unit mkdir = toAff1 A.mkdir -- | -- | Makes a new directory with the specified permissions. -- | -mkdir' :: forall eff. FilePath - -> Perms - -> Aff (fs :: F.FS | eff) Unit +mkdir' :: FilePath -> Perms -> Aff Unit mkdir' = toAff2 A.mkdir' -- | -- | Reads the contents of a directory. -- | -readdir :: forall eff. FilePath - -> Aff (fs :: F.FS | eff) (Array FilePath) +readdir :: FilePath -> Aff (Array FilePath) readdir = toAff1 A.readdir -- | -- | Sets the accessed and modified times for the specified file. -- | -utimes :: forall eff. FilePath - -> DateTime - -> DateTime - -> Aff (fs :: F.FS | eff) Unit +utimes :: FilePath -> DateTime -> DateTime -> Aff Unit utimes = toAff3 A.utimes -- | -- | Reads the entire contents of a file returning the result as a raw buffer. -- | -readFile :: forall eff. FilePath - -> Aff (fs :: F.FS, buffer :: BUFFER | eff) Buffer +readFile :: FilePath -> Aff Buffer readFile = toAff1 A.readFile -- | -- | Reads the entire contents of a text file with the specified encoding. -- | -readTextFile :: forall eff. Encoding - -> FilePath - -> Aff (fs :: F.FS | eff) String +readTextFile :: Encoding -> FilePath -> Aff String readTextFile = toAff2 A.readTextFile -- | -- | Writes a buffer to a file. -- | -writeFile :: forall eff. FilePath - -> Buffer - -> Aff (fs :: F.FS, buffer :: BUFFER | eff) Unit +writeFile :: FilePath -> Buffer -> Aff Unit writeFile = toAff2 A.writeFile -- | -- | Writes text to a file using the specified encoding. -- | -writeTextFile :: forall eff. Encoding - -> FilePath - -> String - -> Aff (fs :: F.FS | eff) Unit +writeTextFile :: Encoding -> FilePath -> String -> Aff Unit writeTextFile = toAff3 A.writeTextFile -- | -- | Appends the contents of a buffer to a file. -- | -appendFile :: forall eff. FilePath - -> Buffer - -> Aff (fs :: F.FS, buffer :: BUFFER | eff) Unit +appendFile :: FilePath -> Buffer -> Aff Unit appendFile = toAff2 A.appendFile -- | -- | Appends text to a file using the specified encoding. -- | -appendTextFile :: forall eff. Encoding - -> FilePath - -> String - -> Aff (fs :: F.FS | eff) Unit +appendTextFile :: Encoding -> FilePath -> String -> Aff Unit appendTextFile = toAff3 A.appendTextFile -- | -- | Check to see if a file exists. -- | -exists :: forall eff. String - -> Aff (fs :: F.FS | eff) Boolean +exists :: String -> Aff Boolean exists file = makeAff \k -> A.exists file (pure >>> k) $> nonCanceler -- | Open a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_open_path_flags_mode_callback) -- | for details. -fdOpen :: forall eff. - FilePath +fdOpen :: FilePath -> F.FileFlags -> Maybe F.FileMode - -> Aff (fs :: F.FS | eff) F.FileDescriptor + -> Aff F.FileDescriptor fdOpen = toAff3 A.fdOpen -- | Read from a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_read_fd_buffer_offset_length_position_callback) -- | for details. -fdRead :: forall eff. - F.FileDescriptor +fdRead :: F.FileDescriptor -> Buffer -> F.BufferOffset -> F.BufferLength -> Maybe F.FilePosition - -> Aff (buffer :: BUFFER, fs :: F.FS | eff) F.ByteCount + -> Aff F.ByteCount fdRead = toAff5 A.fdRead -- | Convenience function to fill the whole buffer from the current -- | file position. -fdNext :: forall eff. - F.FileDescriptor - -> Buffer - -> Aff (buffer :: BUFFER, fs :: F.FS | eff) F.ByteCount +fdNext :: F.FileDescriptor -> Buffer -> Aff F.ByteCount fdNext = toAff2 A.fdNext -- | Write to a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_write_fd_buffer_offset_length_position_callback) -- | for details. -fdWrite :: forall eff. - F.FileDescriptor +fdWrite :: F.FileDescriptor -> Buffer -> F.BufferOffset -> F.BufferLength -> Maybe F.FilePosition - -> Aff (buffer :: BUFFER, fs :: F.FS | eff) F.ByteCount + -> Aff F.ByteCount fdWrite = toAff5 A.fdWrite -- | Convenience function to append the whole buffer to the current -- | file position. -fdAppend :: forall eff. - F.FileDescriptor - -> Buffer - -> Aff (buffer :: BUFFER, fs :: F.FS | eff) F.ByteCount +fdAppend :: F.FileDescriptor -> Buffer -> Aff F.ByteCount fdAppend = toAff2 A.fdAppend -- | Close a file asynchronously. See the [Node Documentation](https://nodejs.org/api/fs.html#fs_fs_close_fd_callback) -- | for details. -fdClose :: forall eff. - F.FileDescriptor - -> Aff (fs :: F.FS | eff) Unit +fdClose :: F.FileDescriptor -> Aff Unit fdClose = toAff1 A.fdClose diff --git a/test/Main.purs b/test/Main.purs index 36389e3..7445d25 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -2,27 +2,21 @@ module Test.Main where import Prelude -import Control.Monad.Aff (launchAff) -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Class (liftEff) -import Control.Monad.Eff.Console (CONSOLE, log) -import Control.Monad.Eff.Exception (EXCEPTION) import Data.Array (filterA) import Data.Maybe (maybe) -import Data.String (charAt, singleton) -import Node.FS (FS) +import Data.String.CodeUnits (charAt, singleton) +import Effect (Effect) +import Effect.Aff (launchAff_) +import Effect.Class (liftEffect) +import Effect.Console (log) import Node.FS.Aff (stat, readdir) import Node.FS.Stats (isDirectory) -main :: forall eff. Eff ( exception :: EXCEPTION - , fs :: FS - , console :: CONSOLE - | eff - ) Unit -main = void $ launchAff do +main :: Effect Unit +main = launchAff_ do files <- readdir "." files' <- flip filterA files \file -> do stat <- stat file pure $ isDirectory stat && (maybe false (singleton >>> (_ /= ".")) $ charAt 0 file) - liftEff $ log $ show files' + liftEffect $ log $ show files'