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

fix(pub): Improve support for custom package repositories #8876

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Syyllinen
Copy link
Contributor

I came across with some corner cases when teams are using custom package repositories in their pubspec.yaml

dependency_overrides:
  flutter_compass:
    url: https://github.com/marcotta/flutter_compass.git
    path: "."

dependencies:
  flutter_compass: ^0.7.0
  private_package:
    hosted:
      name: private_package
      url: https://internal.tool.company/api/pub/repository
    version ^1.0.0

These packages will end up in .pub-cache directory

.pub-cache % find . -type d -name "*flutter_compass*"
./git/flutter_compass-d10156058a1536dc66410619e82c7c4846d3f942

.pub-cache % find . -type d -name "*private_package*"
./hosted/internal.tool.company%47api%47pub/repository%47/private_package-1.0.0

@Syyllinen Syyllinen requested a review from a team as a code owner July 12, 2024 20:32
Copy link

codecov bot commented Jul 12, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 67.54%. Comparing base (2651da9) to head (02892eb).
Report is 29 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #8876   +/-   ##
=========================================
  Coverage     67.54%   67.54%           
- Complexity     1166     1167    +1     
=========================================
  Files           244      244           
  Lines          7775     7775           
  Branches        865      865           
=========================================
  Hits           5252     5252           
  Misses         2167     2167           
  Partials        356      356           
Flag Coverage Δ
funTest-non-docker 33.92% <ø> (ø)
test 37.90% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -85,13 +85,13 @@ internal class PubCacheReader(flutterHome: File? = null) {
val path = if (type == "hosted" && url.isNotEmpty()) {
// Packages with source set to "hosted" and "url" key in description set to "https://pub.dartlang.org".
// The path should be resolved to "hosted/pub.dartlang.org/packageName-packageVersion".
"hosted/${url.replace("https://", "")}/$packageName-$packageVersion"
"hosted/${url.replace("https://", "").replace("/", "%47")}/$packageName-$packageVersion"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is "/" really the only character that needs to be escaped here? If there's a chance that other characters might need to be escaped as well, should we use our String.fileSystemEncode() function instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's see... https://github.com/dart-lang/pub/blob/ea4a1c854690d3abceb92c8cc2c6454470f9d5a7/doc/cache_layout.md?plain=1#L72 says

The url of the repository is encoded to a directory name with a weird URI-like
encoding. This is a mistake that seems costly to fix, but is worth being aware
of.

And the code in https://github.com/dart-lang/pub/blob/ea4a1c854690d3abceb92c8cc2c6454470f9d5a7/lib/src/source/hosted.dart#L1911

  return replace(
    url,
    RegExp(r'[<>:"\\/|?*%]'),
    (match) => '%${match[0]!.codeUnitAt(0)}',
  );

String.fileSystemEncode() does not work because Pub uses decimal value instead of hex value.

But now that I found the original code, I will add replace function for the missing 9 chars.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pub uses decimal value instead of hex value.

Wow, that's indeed weird!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But now that I found the original code, I will add replace function for the missing 9 chars.

Any update here, @Syyllinen?

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