diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d3778f..6b23415 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: +- `relative` now returns `Effect FilePath`, since Node resolves both arguments against the current working directory (#25) New features: diff --git a/src/Node/Path.js b/src/Node/Path.js index eaad2de..a38feb5 100644 --- a/src/Node/Path.js +++ b/src/Node/Path.js @@ -10,7 +10,7 @@ export function resolve(from) { } export function relative(from) { - return to => path.relative(from, to); + return to => () => path.relative(from, to); } export function dirname(p) { diff --git a/src/Node/Path.purs b/src/Node/Path.purs index 3a2394f..d1d0c2f 100644 --- a/src/Node/Path.purs +++ b/src/Node/Path.purs @@ -17,8 +17,10 @@ foreign import concat :: Array FilePath -> FilePath -- | Resolves `to` to an absolute path ([from...], to). foreign import resolve :: Array FilePath -> FilePath -> Effect FilePath --- | Solve the relative path from `from` to `to`. -foreign import relative :: FilePath -> FilePath -> FilePath +-- | Solve the relative path from `from` to `to`. Both paths are resolved +-- | against the current working directory first, so the result depends on it +-- | whenever either path is relative. +foreign import relative :: FilePath -> FilePath -> Effect FilePath -- | Return the directory name of a path. foreign import dirname :: FilePath -> FilePath diff --git a/test/Test/Main.purs b/test/Test/Main.purs index 1a4025a..90cb914 100644 --- a/test/Test/Main.purs +++ b/test/Test/Main.purs @@ -10,7 +10,8 @@ main :: Effect Unit main = do assertEqual { actual: normalize "/foo/bar//baz/asdf/quux/..", expected: normalize "/foo/bar/baz/asdf" } assertEqual { actual: concat ["/foo", "bar"], expected: normalize "/foo/bar" } - assertEqual { actual: relative "/data/orandea/test/aaa" "/data/orandea/impl/bbb", expected: normalize "../../impl/bbb" } + rel <- relative "/data/orandea/test/aaa" "/data/orandea/impl/bbb" + assertEqual { actual: rel, expected: normalize "../../impl/bbb" } assertEqual { actual: dirname "/foo/bar/baz/asdf/quux", expected: normalize "/foo/bar/baz/asdf" } assertEqual { actual: basename "/foo/bar/baz/asdf/quux.html", expected: "quux.html" } assertEqual { actual: basenameWithoutExt "/foo/bar/baz/asdf/quux.html" ".html", expected: "quux" }