Skip to content

Commit 496eb7d

Browse files
authored
Make relative effectful (#25)
1 parent ebff905 commit 496eb7d

4 files changed

Lines changed: 8 additions & 4 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Notable changes to this project are documented in this file. The format is based
55
## [Unreleased]
66

77
Breaking changes:
8+
- `relative` now returns `Effect FilePath`, since Node resolves both arguments against the current working directory (#25)
89

910
New features:
1011

‎src/Node/Path.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export function resolve(from) {
1010
}
1111

1212
export function relative(from) {
13-
return to => path.relative(from, to);
13+
return to => () => path.relative(from, to);
1414
}
1515

1616
export function dirname(p) {

‎src/Node/Path.purs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ foreign import concat :: Array FilePath -> FilePath
1717
-- | Resolves `to` to an absolute path ([from...], to).
1818
foreign import resolve :: Array FilePath -> FilePath -> Effect FilePath
1919

20-
-- | Solve the relative path from `from` to `to`.
21-
foreign import relative :: FilePath -> FilePath -> FilePath
20+
-- | Solve the relative path from `from` to `to`. Both paths are resolved
21+
-- | against the current working directory first, so the result depends on it
22+
-- | whenever either path is relative.
23+
foreign import relative :: FilePath -> FilePath -> Effect FilePath
2224

2325
-- | Return the directory name of a path.
2426
foreign import dirname :: FilePath -> FilePath

‎test/Test/Main.purs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ main :: Effect Unit
1010
main = do
1111
assertEqual { actual: normalize "/foo/bar//baz/asdf/quux/..", expected: normalize "/foo/bar/baz/asdf" }
1212
assertEqual { actual: concat ["/foo", "bar"], expected: normalize "/foo/bar" }
13-
assertEqual { actual: relative "/data/orandea/test/aaa" "/data/orandea/impl/bbb", expected: normalize "../../impl/bbb" }
13+
rel <- relative "/data/orandea/test/aaa" "/data/orandea/impl/bbb"
14+
assertEqual { actual: rel, expected: normalize "../../impl/bbb" }
1415
assertEqual { actual: dirname "/foo/bar/baz/asdf/quux", expected: normalize "/foo/bar/baz/asdf" }
1516
assertEqual { actual: basename "/foo/bar/baz/asdf/quux.html", expected: "quux.html" }
1617
assertEqual { actual: basenameWithoutExt "/foo/bar/baz/asdf/quux.html" ".html", expected: "quux" }

0 commit comments

Comments
 (0)