Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
2 changes: 1 addition & 1 deletion src/Node/Path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions src/Node/Path.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion test/Test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
Loading