Skip to content

Commit 86c67eb

Browse files
committed
feat: use FilePath instead of String where needed, AutodetectLink
1 parent 791cefe commit 86c67eb

File tree

4 files changed

+21
-17
lines changed

4 files changed

+21
-17
lines changed

src/Node/FS.purs

+9-5
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ module Node.FS
1212

1313
import Prelude
1414

15+
import Data.Nullable (Nullable)
16+
import Data.Nullable as Nullable
1517
import Node.FS.Constants (FileFlags(..), fileFlagsToNode) as Exports
1618

1719
foreign import data FileDescriptor :: Type
@@ -23,19 +25,21 @@ type BufferOffset = Int
2325
type ByteCount = Int
2426

2527
-- | Symlink varieties.
26-
data SymlinkType = FileLink | DirLink | JunctionLink
28+
data SymlinkType = FileLink | DirLink | JunctionLink | AutodetectLink
2729

2830
-- | Convert a `SymlinkType` to a `String` in the format expected by the
2931
-- | Node.js filesystem API.
30-
symlinkTypeToNode :: SymlinkType -> String
32+
symlinkTypeToNode :: SymlinkType -> Nullable String
3133
symlinkTypeToNode ty = case ty of
32-
FileLink -> "file"
33-
DirLink -> "dir"
34-
JunctionLink -> "junction"
34+
FileLink -> Nullable.notNull "file"
35+
DirLink -> Nullable.notNull "dir"
36+
JunctionLink -> Nullable.notNull "junction"
37+
AutodetectLink -> Nullable.null
3538

3639
instance showSymlinkType :: Show SymlinkType where
3740
show FileLink = "FileLink"
3841
show DirLink = "DirLink"
3942
show JunctionLink = "JunctionLink"
43+
show AutodetectLink = "AutodetectLink"
4044

4145
derive instance eqSymlinkType :: Eq SymlinkType

src/Node/FS/Aff.purs

+6-6
Original file line numberDiff line numberDiff line change
@@ -156,26 +156,26 @@ toAff5 f a b c d e = toAff (f a b c d e)
156156
-- -> Aff a
157157
-- toAff6 f a b c d e t = toAff (f a b c d e t)
158158

159-
access :: String -> Aff (Maybe Error)
159+
access :: FilePath -> Aff (Maybe Error)
160160
access path = makeAff \k -> do
161161
A.access path (k <<< Right)
162162
pure nonCanceler
163163

164-
access' :: String -> AccessMode -> Aff (Maybe Error)
164+
access' :: FilePath -> AccessMode -> Aff (Maybe Error)
165165
access' path mode = makeAff \k -> do
166166
A.access' path mode (k <<< Right)
167167
pure nonCanceler
168168

169-
copyFile :: String -> String -> Aff Unit
169+
copyFile :: FilePath -> FilePath -> Aff Unit
170170
copyFile = toAff2 A.copyFile
171171

172-
copyFile' :: String -> String -> CopyMode -> Aff Unit
172+
copyFile' :: FilePath -> FilePath -> CopyMode -> Aff Unit
173173
copyFile' = toAff3 A.copyFile'
174174

175-
mkdtemp :: String -> Aff String
175+
mkdtemp :: FilePath -> Aff FilePath
176176
mkdtemp = toAff1 A.mkdtemp
177177

178-
mkdtemp' :: String -> Encoding -> Aff String
178+
mkdtemp' :: FilePath -> Encoding -> Aff FilePath
179179
mkdtemp' = toAff2 A.mkdtemp'
180180

181181
-- |

src/Node/FS/Async.purs

+5-5
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,13 @@ copyFile' src dest mode cb = runEffectFn4 copyFileImpl src dest mode (handleCall
139139

140140
foreign import copyFileImpl :: EffectFn4 FilePath FilePath CopyMode (JSCallback Unit) Unit
141141

142-
mkdtemp :: String -> Callback String -> Effect Unit
142+
mkdtemp :: FilePath -> Callback FilePath -> Effect Unit
143143
mkdtemp prefix = mkdtemp' prefix UTF8
144144

145-
mkdtemp' :: String -> Encoding -> Callback String -> Effect Unit
145+
mkdtemp' :: FilePath -> Encoding -> Callback FilePath -> Effect Unit
146146
mkdtemp' prefix encoding cb = runEffectFn3 mkdtempImpl prefix (encodingToNode encoding) (handleCallback cb)
147147

148-
foreign import mkdtempImpl :: EffectFn3 FilePath String (JSCallback String) Unit
148+
foreign import mkdtempImpl :: EffectFn3 FilePath FilePath (JSCallback FilePath) Unit
149149

150150
foreign import renameImpl :: EffectFn3 FilePath FilePath (JSCallback Unit) Unit
151151
foreign import truncateImpl :: EffectFn3 FilePath Int (JSCallback Unit) Unit
@@ -154,7 +154,7 @@ foreign import chmodImpl :: EffectFn3 FilePath String (JSCallback Unit) Unit
154154
foreign import statImpl :: EffectFn2 FilePath (JSCallback Stats) Unit
155155
foreign import lstatImpl :: EffectFn2 FilePath (JSCallback Stats) Unit
156156
foreign import linkImpl :: EffectFn3 FilePath FilePath (JSCallback Unit) Unit
157-
foreign import symlinkImpl :: EffectFn4 FilePath FilePath String (JSCallback Unit) Unit
157+
foreign import symlinkImpl :: EffectFn4 FilePath FilePath (Nullable String) (JSCallback Unit) Unit
158158
foreign import readlinkImpl :: EffectFn2 FilePath (JSCallback FilePath) Unit
159159
foreign import realpathImpl :: forall cache. EffectFn3 FilePath { | cache } (JSCallback FilePath) Unit
160160
foreign import unlinkImpl :: EffectFn2 FilePath (JSCallback Unit) Unit
@@ -180,7 +180,7 @@ foreign import fstatImpl :: EffectFn2 FileDescriptor (JSCallback Stats) Unit
180180
foreign import fsyncImpl :: EffectFn2 FileDescriptor (JSCallback Unit) Unit
181181
foreign import ftruncateImpl :: EffectFn3 FileDescriptor Int (JSCallback Unit) Unit
182182
foreign import futimesImpl :: EffectFn4 FileDescriptor Int Int (JSCallback Unit) Unit
183-
foreign import globImpl :: forall filepathOrDirent. EffectFn3 (Array String) { cwd :: Nullable FilePath, exclude :: Nullable (filepathOrDirent -> Boolean), withFileTypes :: Boolean } (JSCallback (Array filepathOrDirent)) Unit
183+
foreign import globImpl :: forall filepathOrDirent. EffectFn3 (Array FilePath) { cwd :: Nullable FilePath, exclude :: Nullable (filepathOrDirent -> Boolean), withFileTypes :: Boolean } (JSCallback (Array filepathOrDirent)) Unit
184184
foreign import lchmodImpl :: EffectFn3 FilePath String (JSCallback Unit) Unit
185185
foreign import lchownImpl :: EffectFn4 FilePath Int Int (JSCallback Unit) Unit
186186
foreign import lutimesImpl :: EffectFn4 FilePath Int Int (JSCallback Unit) Unit

src/Node/FS/Sync.purs

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ foreign import chmodSyncImpl :: EffectFn2 FilePath String Unit
9393
foreign import statSyncImpl :: EffectFn1 FilePath Stats
9494
foreign import lstatSyncImpl :: EffectFn1 FilePath Stats
9595
foreign import linkSyncImpl :: EffectFn2 FilePath FilePath Unit
96-
foreign import symlinkSyncImpl :: EffectFn3 FilePath FilePath String Unit
96+
foreign import symlinkSyncImpl :: EffectFn3 FilePath FilePath (Nullable String) Unit
9797
foreign import readlinkSyncImpl :: EffectFn1 FilePath FilePath
9898
foreign import realpathSyncImpl :: forall cache. EffectFn2 FilePath { | cache } FilePath
9999
foreign import unlinkSyncImpl :: EffectFn1 FilePath Unit

0 commit comments

Comments
 (0)