Skip to content
This repository was archived by the owner on Aug 4, 2023. It is now read-only.

Commit 6c021a0

Browse files
committed
Fix the Node.FS.Async.exists patch
Copy the original method verbatim and wait for a new release.
1 parent df575c6 commit 6c021a0

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/Node/FS/Aff.purs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import Node.Path (FilePath())
2828
import Node.FS.Perms (Perms())
2929
import Node.FS.Stats (Stats())
3030
import Data.Date (Date())
31-
import Control.Monad.Eff (Eff())
31+
import Control.Monad.Eff (Eff(), runPure)
32+
import Control.Monad.Eff.Unsafe (unsafeInterleaveEff)
3233
import Data.Either (either)
3334
import Control.Monad.Aff (Aff(), makeAff)
3435
import Node.Buffer (Buffer())
@@ -221,14 +222,22 @@ appendTextFile = toAff3 A.appendTextFile
221222

222223
-- |
223224
-- Patch `Node.FS.Async.exists`
225+
-- The current version of `Node.FS.Async.exists` fails the occurs check
226+
-- because it's callback signature does not include the FS effect.
224227
--
225228
import Data.Function
229+
foreign import mkEff
230+
"function mkEff(action) {\
231+
\ return action;\
232+
\}" :: forall eff a. (Unit -> a) -> Eff eff a
226233
foreign import fs "var fs = require('fs');" ::
227234
{ exists :: forall a. Fn2 FilePath (Boolean -> a) Unit }
235+
_exists file cb = mkEff $ \_ -> runFn2
236+
fs.exists file $ \b -> runPure (unsafeInterleaveEff (cb b))
228237

229238
-- |
230239
-- | Check to see if a file exists.
231240
-- |
232241
exists :: forall eff. String
233242
-> Aff (fs :: F.FS | eff) Boolean
234-
exists file = makeAff \_ a -> pure $ runFn2 fs.exists file a
243+
exists file = makeAff \_ a -> _exists file a

0 commit comments

Comments
 (0)