-
Notifications
You must be signed in to change notification settings - Fork 357
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
add windows test #582
add windows test #582
Conversation
041a732
to
776ab2c
Compare
https://github.com/awslabs/llrt/actions/runs/10792507462/job/29932350859 Paths between platforms are a pain to deal with, especially when using them obfuscated, and at the moment there are some differences between llrt's behavior and node's, which will probably be fixed in a future update. |
I am a bit wary of doing manual path handling, I am wondering if we should transform all the string in |
Mixing different styles and platform differences is very troublesome. However, there is no such thing as node_resolve or node_path. Deno uses js to implement path logic and also distinguishes win and unix. We only need to ensure that common scenarios can be consistent with node. In most cases, llrt runs the bundled code.
|
@ahaoboy thanks for the PR. Doesn't windows also support forward slash paths these days? Can we consolidate the path module by supporting forward slashes only? |
There are three path separators that can be used on Windows: In most cases, using / is fine, and in import statements, only / can be used, but considering that we cannot get rid of the influence of node and npm, and the behavior of many third-party libraries may depend on this inconsistency, I think the best way is to be consistent with node. Adding win path support is just for developers(like me) using windows to test and develop. |
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 think that a lot of code from the unix and windows path module could be consolidated. From the looks of it it's mostly the strip_suffic
or rfind
closure that's different.
One option would be to define this closure as a function instead and use conditional compilation on windows/unix.
There is also some optimizations that can be applied cross the entire path module such as avoiding extra allocations. For example, in join_path we can do this instead:
pub fn join_path<'a, I>(parts: I) -> String
where
I: Iterator<Item = &'a str>,
{
let mut path_buf = parts.fold(PathBuf::new(), |mut acc, part| {
if !part.is_empty() {
for part in part.split("/") {
if !part.is_empty() {
if part == ".." {
acc.pop();
} else if part != "." {
acc.push(part);
}
}
}
}
acc
});
path_buf.to_string_lossy().into_owned()
}
and similarly in resolve_path
working with string slice iter instead of strings.
Stick to a shared function between linux and windows as much as possible even within functions to reduce maintenance burden and reduce error risks. Only if the same function has completely different implementations use a dedicated per OS.
7dae3cf
to
0e9bead
Compare
Using a platform-dependent SEP_PAT variable for path segmentation seems to work well. |
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.
Thank you! Almost there! Just added a few optimization suggestions. I know you've based your implementation on our previous code but we've find more optimization by reviewing this code again :)
Description of changes
Added Windows platform test
Checklist
tests/unit
and/or in Rust for my feature if neededmake fix
to format JS and apply Clippy auto fixesmake check
types/
directory