-
Notifications
You must be signed in to change notification settings - Fork 1
feat: add a few utils #1
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
Conversation
Yeah I think we should.
What do you mean? |
|
Could you try yalcing this into graphite, json-ref-resolver, and studio if you have time today? And updating various usages in those projects to make sure these utils feel good? Thank you! |
What I'm saying is whether the fn should generate the following path |
No. Windows is perfectly happy with forward slash separators. The only part of Windows that doesn't like forward slash separators are old DOS shell commands that use forward slash to indicate CLI arguments (instead of dash like POSIX CLIs). The only reason to use back slashes would be if users complain. There is no technical reason why we should convert to back slashes on certain platforms. |
Andddd a primary purpose of this path package is to normalize windows and posix where we can (in this case, to always use forward slashes). So that graphite lookup by uri works across os, etc. |
|
I'm still not sure why we don't just use path where possible (normalize, join, dirname, basename)? Maybe the codebase inside of path is not perfect, but it works... the only thing we need to do when using path is make sure that the result is using posix style slashes. Besides that, I think we still need to cover a few things:
In general, I'd suggest that for almost every method (perhaps not toFSPath) we simply:
Basically, we need to:
I think that will cover all of our use cases? |
Unfortunately @marbemac, that's simply not true. At a minimum we should stop using path and change our dependency to use In an ideal we'd use our own parser so we have full control and can understand what the library is doing, as I suggest in #2. Edit: The reason that the minimum is OK is because at least then we have predictable behavior. I.e. the same code paths will be running whether the environment is Webpack, Jest, Node on Windows, or Node on Mac. Developers will be able to do things like, |
|
In fact I feel so strongly about the "minimum" I'm going to change that right now and push it to this PR hold on. |
|
@wmhilton hold on with pushing to this branch. I'm about to push a commit. |
|
ok. It shouldn't have any merge conflicts though, just swapping out |
|
I'm gonna re-run tests on Windows, make sure nothing is amiss |
billiegoose
left a comment
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.
Left a couple suggestions
src/__tests__/join.spec.ts
Outdated
| }); | ||
|
|
||
| it('treats URLs as file URIs', () => { | ||
| expect(join('https://foo.test', 'com', 'baz')).toEqual('/com/baz'); |
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.
| expect(join('https://foo.test', 'com', 'baz')).toEqual('/com/baz'); | |
| expect(join('https://foo.test', 'com', 'baz')).toEqual('https://foo.test/com/baz'); |
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.
treats URLs as file URIs
Yeah in general I think the premise of the test is wrong. URLs should be treated as URLs. File paths as file paths.
Should be able to pass the following in (prob not comprehensive, but ya get the idea):
join('https://foo.test', 'com', 'baz')join('https://foo.com/pets', '..', 'users', 123)join('/foo/bar', '..', 'baz')join('c:/foo/bar', '..', 'baz')join('c:/foo\bar', '..', 'baz')
marbemac
left a comment
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.
Closer!
| import { relative } from '../'; | ||
|
|
||
| describe('relative', () => { | ||
| it('handles URLs', () => { |
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.
Should also add some tests to make sure it handles the various file path cases (posix, windows, forward slash, mixed slash, etc).
src/__tests__/join.spec.ts
Outdated
| }); | ||
|
|
||
| it('treats URLs as file URIs', () => { | ||
| expect(join('https://foo.test', 'com', 'baz')).toEqual('/com/baz'); |
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.
treats URLs as file URIs
Yeah in general I think the premise of the test is wrong. URLs should be treated as URLs. File paths as file paths.
Should be able to pass the following in (prob not comprehensive, but ya get the idea):
join('https://foo.test', 'com', 'baz')join('https://foo.com/pets', '..', 'users', 123)join('/foo/bar', '..', 'baz')join('c:/foo/bar', '..', 'baz')join('c:/foo\bar', '..', 'baz')
| }); | ||
|
|
||
| it('handles Windows URIs', () => { | ||
| expect(relative('c:\\test\\baz', 'C:\\test\\foo')).toEqual('../../../C:/test/foo'); |
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.
@marbemac weird things happening here.
looking much better - will's going to finish up the review!
|
Closing favor of #2 |

Question:
Should we add tests for actual URIs?
https://github.com/stoplightio/json-ref-resolver/pull/60/files#r295356728
should
toFSPathreturn a Windows-compatible path when executed under Windows?TODO: