Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

maple135790
Copy link
Contributor

related: #335


  • I’ve reviewed the contributor guide and applied the relevant portions to this PR.
Contribution guidelines:

Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.

@@ -31,7 +31,7 @@ environment:
sdk: '^$sdkVersion'
dependencies:
web:
path: ${Directory.current.path}
path: ${p.current.replaceAll(r'\', '/')}
Copy link
Contributor

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.

Copy link
Contributor Author

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).

Copy link
Contributor Author

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 ?

Copy link
Contributor

@srujzs srujzs Jan 9, 2025

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!

Copy link
Contributor Author

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

  1. commenting inside the yaml.
  2. 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.

  1. inside yaml:
      writeFile(tempDir, 'pubspec.yaml', '''
name: test_project
environment:
  sdk: '^$sdkVersion'
dependencies:
  web:
    # COMMENT_HERE
    path: ${p.current.replaceAll(r'\', '/')}
  ''');
  1. out of multiline string:
      writeFile(tempDir, 'pubspec.yaml', '''
name: test_project
environment:
  sdk: '^$sdkVersion'
dependencies:
  web:
  '''
    // COMMENT_HERE
    'path: ${p.current.replaceAll(r'\', '/')}');

Copy link
Contributor

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.

web/CHANGELOG.md Outdated Show resolved Hide resolved
web_generator/bin/scrape_mdn.dart Outdated Show resolved Hide resolved
@@ -31,7 +31,7 @@ environment:
sdk: '^$sdkVersion'
dependencies:
web:
path: ${Directory.current.path}
path: ${p.current.replaceAll(r'\', '/')}
Copy link
Contributor

@srujzs srujzs Jan 9, 2025

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants