-
Notifications
You must be signed in to change notification settings - Fork 27
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
Adapt paths for different development environments #336
base: main
Are you sure you want to change the base?
Conversation
@@ -31,7 +31,7 @@ environment: | |||
sdk: '^$sdkVersion' | |||
dependencies: | |||
web: | |||
path: ${Directory.current.path} | |||
path: ${p.current.replaceAll(r'\', '/')} |
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 Directory.current.uri.toFilePath()
makes more sense here than us manually modifying the path.
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.
Oh, I missed that. Thank you for the mention.
Since the issue trying to fix here is to force yaml using POSIX-like path (here is the lint), so the upcomming fix will use Directory.current.uri.toFilePath(windows: false)
.
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 this fix will encounter another problem.
For example, web path in Windows is C:\a\b
, the lint suggests the fix is to simply change \
to /
.
The correct path is C:/a/b
.
This results C:/a/b
is not Windows path nor POSIX path, so it cannot be fixed by using uri.toFilePath(windows: false)
since the output will be something like /C:/a/b/
Perhaps there's an approach to avoid manually modifying the path that I'm unaware of ?
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 see, it looks like it's not correctly interpreting the C:
as the authority. We've tried different APIs to see what the right way of emitting a POSIX path from a Windows path is, but everything else also seems janky (maybe adding a directory:///
or something similar may help, but that doesn't look like it's sufficient anyways), so I'm okay keeping the p.current.replaceAll(r'\', '/')
change you initially had. I'd just add a comment mentioning why we do it like:
// Convert the current path to a POSIX path to avoid 'path_not_posix' lint.
Thanks for investigating!
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.
As a minor detail, I think the beat looking comment position is above the writeFile()
because we have full control of the yaml file.
// set up project
// COMMENT_HERE
writeFile(tempDir, 'pubspec.yaml', '''
...
''');
There are another two options
- commenting inside the yaml.
- commenting out of multiline string.
Since none of them look concise enough comparing to the above, so I choose to the above over the others.
- inside yaml:
writeFile(tempDir, 'pubspec.yaml', '''
name: test_project
environment:
sdk: '^$sdkVersion'
dependencies:
web:
# COMMENT_HERE
path: ${p.current.replaceAll(r'\', '/')}
''');
- out of multiline string:
writeFile(tempDir, 'pubspec.yaml', '''
name: test_project
environment:
sdk: '^$sdkVersion'
dependencies:
web:
'''
// COMMENT_HERE
'path: ${p.current.replaceAll(r'\', '/')}');
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 agree that it makes sense to keep it outside of the yaml as an implementation detail and place it above writeFile
.
- remove redundant call `p.context`
@@ -31,7 +31,7 @@ environment: | |||
sdk: '^$sdkVersion' | |||
dependencies: | |||
web: | |||
path: ${Directory.current.path} | |||
path: ${p.current.replaceAll(r'\', '/')} |
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 see, it looks like it's not correctly interpreting the C:
as the authority. We've tried different APIs to see what the right way of emitting a POSIX path from a Windows path is, but everything else also seems janky (maybe adding a directory:///
or something similar may help, but that doesn't look like it's sufficient anyways), so I'm okay keeping the p.current.replaceAll(r'\', '/')
change you initially had. I'd just add a comment mentioning why we do it like:
// Convert the current path to a POSIX path to avoid 'path_not_posix' lint.
Thanks for investigating!
related: #335
Contribution guidelines:
dart format
.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.