-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Core: Fix staticDirs path issue on Windows #17641
Conversation
☁️ Nx Cloud ReportCI ran the following commands for commit 6f9c8a5. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
The failing e2e test doesn't appear to have anything to do with the code I've changed? |
@tooppaaa can you please kick the tires on windows? 🙏 |
Everything looks good on windows ! 🚀 |
@@ -72,6 +72,13 @@ describe('parseStaticDir', () => { | |||
targetDir: './custom-endpoint', | |||
targetEndpoint: '/custom-endpoint', | |||
}); | |||
|
|||
await expect(parseStaticDir('C:\\foo\\bar:\\custom-endpoint')).resolves.toEqual({ |
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.
await expect(parseStaticDir('C:\\foo\\bar:\\custom-endpoint')).resolves.toEqual({ | |
await expect(parseStaticDir('C:\\foo\\bar:/custom-endpoint')).resolves.toEqual({ |
shouldn't this be a forward slash since it's a URL?
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.
So, the underlying issue is that getDirectoryFromWorkingDir()
in useStatics
returns this "URL" with backslashes; see arg
in the screencap:
I'm sure that parseStaticDir
is intended to receive the path as a URL, but the reality is that it might not.
As such, I've left the original test with /custom-endpoint
and added \\custom-endpoint
to ensure this case is covered.
I did briefly consider fixing the underlying issue inside useStatics
, however that seemed like a much riskier fix with a much, much broader footprint. To me the safer course of action was to make parseStaticDir
more forgiving (not to mention significantly easier for my first contrib).
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.
Thanks for the clarification! 🙏
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.
Thanks so much for the great fix @justrhysism !!! 🙏
BTW, to run unit tests on windows, you can add the |
Issue: #17271
What I did
Noticed that the test "supports absolute file paths with custom endpoint" didn't cover the reality for Windows.
The
relativeDir
provided bygetDirectoryFromWorkingDir()
resolves all paths to OS separators (e.g.\
on Windows). The result of which would look likeC:\\foo\\bar:\\custom-endpoint
and notC:\\foo\\bar:/custom-endpoint
which the test was covering; so I added a test to cover the actual case.Digging in, the regex split in
parseStaticDir
didn't account for the actual path, as it was ignoring all cases of:\
to cover theX:\
scenario, which is what resulted in bug #17271.To work around this, I changed the code to look for the last colon
:
, and use that to split. However, in case the last colon is actually part of a Windows absolute path (e.g.C:\
), needed to check a few conditions::
delimiter for static and target dirs.Once this was determined, the final piece of the puzzle was ensuring the
target
was converted from\
to/
, for which I just split onpath.sep
and joined onpath.posix.sep
to ensure a forward-slash/
.How to test
If your answer is yes to any of these, please make sure to include it in your PR.