-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding relative method in path interface #5
Conversation
Hey @jpuri ! that sounds just about right. My strategy so far in implementing I would add test cases with:
|
I had some troubles in running tests with jbuilder with latest version of ocaml |
Interesting, do you think you can describe the issues @jpuri ? |
Seems to be trouble in some opam packages, its not able to install all required packages for running the test cases:
But I think its not specific to project |
@jpuri you shouldn't have to use opam, although you could but I don't recommend it. This is probably my fault for not documenting the commands I use to build, test, etc. So this is usually how the flow of things would go:
When using esy, you have to prefix commands with esy in order for it to pick up the local environment/sandbox. |
Yep I did not prefixed easy before |
It works now? |
yep works well now |
Still WIP. Going slow as I do not have a lot of time. |
@jpuri no worries :) Thank you so much for putting time into it! |
Hey @kennetpostigo , can you plz check the changes and share ur feedbacks. |
@jpuri yes, definitely! I'll review it today |
Hi! I suspect that macOS build fails because esy doesn't produce any output during build process when tty isn't available (like when run on CI). Sometimes build process can take longer than 10m (I saw this with earlier versions of esy too), this can be because travis is out of capacity for macOS machines, for example. See https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received for a workaround. Next release (soon) I'll fix esy output to provide some progress indication even if no tty is available. |
@andreypopp thank you! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @jpuri
-
I went through the code and ran the tests, compared against node.js ouput for same input and I noticed a difference in the output for your
relativeWithDifferentPath
test. I think this is because the output after diffing both paths should be relative to the current working directory. Both absolute and relative paths seem to be affected. -
The implementation doesn't protect against unnormalized paths, first thing you should do before testing diffing the paths is normalize them, luckily theres already a
normalize
function in path so this should be a quick fix 😀. -
In
getRelativePath
since sometimes code might be ran from a windows machine, you should change~path2=("../" ++ path2)
into~path2=(".." ++ sep ++ path2)
. -
If possible it would be good to add test cases for the new helpers.
Hey @jpuri , The project has been renamed to |
Hey @kennetpostigo , sure I will sync up the PR and work n feedbacks you shared. Thx. |
Hey @kennetpostigo , point-1 above is not clear to me: I have implemented 2, 3 and I am working on improving test coverage. More tests are required - PR is not complete. I requested a review so that I would know that my approach is correct. |
@jpuri after messing around in the node repl, the original thought was wrong, the reason why the output is different is because in node.js it expects the input to be directories and not files, so if you change: path.relative("bar/index.html", "index.html") to path.relative("bar", "index.html") you will get Personally I prefer the manner in which it is implemented now, it feels more precise to me. However, if porting code directly from node.js to lwt-node this might be one of those "gotchas". I leave the decision up to you of whether you want to leave it as is, or change it to match node.js. |
That was my thought also that nodejs is expecting directory and not file. |
@jpuri thats a good idea! 😃 |
|
@jpuri good catch, it's definitely not intended behavior and oversight on my part, the bug fix is probably: let resolve = paths => {
let keepJoining = ref(true);
let rePath = ref("");
let onPath = (path, index, e) =>
e ?
{
keepJoining := false;
rePath := path ++ sep ++ rePath^;
} :
(
switch path {
| ""
| "./"
| ".\\" => Sys.getcwd() /* <----- fix*/
... Would you want to add this into your current PR? |
PR looks complete to me now, also I added change and test coverage for resolve method. |
@jpuri thank you! I'll take a look at this ASAP :) |
6c94f37
to
922ce24
Compare
@@ -6,6 +6,47 @@ let charSep = | |||
| _ => '/' | |||
}; | |||
|
|||
let rec removeCommonPath = (~path1, ~path2) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These switches can be replaced by ternary operators may be, but they are best at handling exceptions. Plz share if you have better suggestions about code here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I personally prefer switches, they make refactoring easier and more explicit the exceptions that are being handled. These look great!
The changes look great! Thank you for your work! CI is only failing on macOS b/c travis cancels the build if theres no ouput after a period of time, but linux builds and passes. Feel free to squash and merge @jpuri |
Hi @kennetpostigo, I have squashed the changes, can you plz merge as I do not have that option enabled. |
Hey @kennetpostigo , great project.
I was checking it out. I want to contribute to the project and thus I created this PR for a method.
I want to implement
path.relative
method. What I understand about the method is:Please suggest if I am missing out on anything.