wasp-lang/strong-path

Add more utilities to strong-path

craigmc08 opened this issue · 2 comments

The path library offers a bunch more utility functions (https://hackage.haskell.org/package/path-0.9.2/docs/Path-Posix.html#g:4) that strong-path would benefit from having. Currently, to do things like work with extensions you have to convert to a path Path, use functions from that library, and then back to a strong-path Path.

@craigmc08 you implemented some of these, could you paste implementations here or in other relevant issues (there are some open already)?

Implementing these functions just needs a bit of wrapping/unwrapping code to use the functions from path. Here are the ones I've implemented:

stripProperPrefix :: MonadThrow m => Path' b (Dir d) -> Path' b (File f) -> m (Path' (Rel d) (File f))
stripProperPrefix base file =
  fromPathRelFile
    <$> Path.stripProperPrefix (toPathAbsDir base) (toPathAbsFile file)

replaceExtension :: MonadThrow m => String -> Path' b (File f) -> m (Path' b (File f))
replaceExtension ext path =
  fromPathAbsFile <$> Path.replaceExtension ext (toPathAbsFile path)

And I see #40 is related.