Skip to content

Commit

Permalink
fix(pub): Improve support for custom package repositories
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Salmi <[email protected]>
  • Loading branch information
Syyllinen committed Jul 16, 2024
1 parent 2651da9 commit 02892eb
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"
} else if (type == "git" && resolvedRef.isNotEmpty()) {
// Packages with source set to "git" and a "resolved-ref" key in description set to a gitHash.
// These packages do not define a packageName in the packageInfo, but by definition the path resolves to
// the project name as given from the VcsHost and to the resolvedRef.
val projectName = VcsHost.getProject(url) ?: return null
if (resolvedPath.isNotEmpty()) {
if (resolvedPath.isNotEmpty() && resolvedPath != ".") {
"git/$projectName-$resolvedRef/$resolvedPath"
} else {
"git/$projectName-$resolvedRef"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class PubCacheReaderTest : WordSpec({
val gitPackageCacheDir = tmpPubCacheDir.resolve("git/$PACKAGE_NAME-$RESOLVED_REF")
val gitPackageWithPathCacheDir = tmpPubCacheDir.resolve("git/$PACKAGE_NAME-$RESOLVED_REF/$PACKAGE_NAME")
val hostedPackageCacheDir = tmpPubCacheDir.resolve("hosted/oss-review-toolkit.org/$PACKAGE_NAME-$PACKAGE_VERSION")
val customPackageCacheDir = tmpPubCacheDir.resolve(
"hosted/oss-review-toolkit.org%47api%47pub%47repository%47/$PACKAGE_NAME-$PACKAGE_VERSION"
)
val localPackagePathAbsolute = ABSOLUTE_PATH
val localPackagePathRelative = ABSOLUTE_PATH.resolve(RELATIVE_PATH)

Expand All @@ -49,6 +52,7 @@ class PubCacheReaderTest : WordSpec({
gitPackageCacheDir.safeMkdirs()
gitPackageWithPathCacheDir.safeMkdirs()
hostedPackageCacheDir.safeMkdirs()
customPackageCacheDir.safeMkdirs()
}

"findProjectRoot" should {
Expand All @@ -72,6 +76,27 @@ class PubCacheReaderTest : WordSpec({
) shouldBe gitPackageCacheDir
}

"resolve the path of a Git dependency with special path" {
reader.findProjectRoot(
jsonMapper.readTree(
"""
{
"dependency": "direct main",
"description": {
"path": ".",
"ref": "master",
"resolved-ref": "$RESOLVED_REF",
"url": "https://github.com/oss-review-toolkit/$PACKAGE_NAME.git"
},
"source": "git",
"version": "9.9.9"
}
""".trimIndent()
),
ABSOLUTE_PATH // not used
) shouldBe gitPackageCacheDir
}

"resolve the path of a Git dependency with path" {
reader.findProjectRoot(
jsonMapper.readTree(
Expand Down Expand Up @@ -112,6 +137,25 @@ class PubCacheReaderTest : WordSpec({
) shouldBe hostedPackageCacheDir
}

"resolve the path of a custom package repository dependency" {
PubCacheReader().findProjectRoot(
jsonMapper.readTree(
"""
{
"dependency": "transitive",
"description": {
"name": "$PACKAGE_NAME",
"url": "https://oss-review-toolkit.org/api/pub/repository/"
},
"source": "hosted",
"version": "$PACKAGE_VERSION"
}
""".trimIndent()
),
ABSOLUTE_PATH // not used
) shouldBe customPackageCacheDir
}

"resolve the relative path of a local dependency" {
PubCacheReader().findProjectRoot(
jsonMapper.readTree(
Expand Down

0 comments on commit 02892eb

Please sign in to comment.