From 2538752d04ac1f6e11cd22d53b684aede5adf7db Mon Sep 17 00:00:00 2001 From: Dan Chao Date: Wed, 12 Jun 2024 17:48:52 -0700 Subject: [PATCH] Fix links to dependencies This fixes an issue where package dependencies are not rendered correctly. --- .../packages/birds@0.5.0/birds@0.5.0.json | 2 +- .../packages/fruit@1.0.5/fruit@1.0.5.json | 1 - .../packages/fruit@1.1.0/fruit@1.1.0.json | 1 - .../org/pkl/commons/test/PackageServer.kt | 6 ++-- .../input/packages/packages1.pkl | 2 +- .../input/packages/packages2.pkl | 2 +- .../projects/project4/PklProject.deps.json | 2 +- .../output/packages/packages2.pcf | 4 +-- .../kotlin/org/pkl/doc/CliDocGenerator.kt | 5 +-- .../main/kotlin/org/pkl/doc/DocPackageInfo.kt | 2 +- .../src/main/kotlin/org/pkl/doc/DocScope.kt | 2 +- .../main/kotlin/org/pkl/doc/PageGenerator.kt | 33 ++++++++++++++----- .../output/com.package1/1.2.3/index.html | 2 +- .../birds/0.5.0/Bird/index.html | 2 +- .../localhost(3a)0/birds/0.5.0/index.html | 4 +-- .../birds/0.5.0/package-data.json | 2 +- .../localhost(3a)0/fruit/1.1.0/index.html | 2 +- 17 files changed, 44 insertions(+), 30 deletions(-) diff --git a/pkl-commons-test/src/main/files/packages/birds@0.5.0/birds@0.5.0.json b/pkl-commons-test/src/main/files/packages/birds@0.5.0/birds@0.5.0.json index fe28814de..ca047007f 100644 --- a/pkl-commons-test/src/main/files/packages/birds@0.5.0/birds@0.5.0.json +++ b/pkl-commons-test/src/main/files/packages/birds@0.5.0/birds@0.5.0.json @@ -7,7 +7,7 @@ "fruities": { "uri": "package://localhost:0/fruit@1.0.5", "checksums": { - "sha256": "34a15b02346e6acb85da5bd71d8b0738a79008b38a7fc805e5869d9129ad27d2" + "sha256": "8ff80e5ac882650e817f261c8af024bf0db9b07888c9d18c20017457e04ffe06" } } }, diff --git a/pkl-commons-test/src/main/files/packages/fruit@1.0.5/fruit@1.0.5.json b/pkl-commons-test/src/main/files/packages/fruit@1.0.5/fruit@1.0.5.json index 3eaa93b7d..a7ea204d3 100644 --- a/pkl-commons-test/src/main/files/packages/fruit@1.0.5/fruit@1.0.5.json +++ b/pkl-commons-test/src/main/files/packages/fruit@1.0.5/fruit@1.0.5.json @@ -9,7 +9,6 @@ "sha256": "$computedChecksum" }, "sourceCode": "https://example.com/fruit", - "documentation": "https://example.com/fruit-docs", "license": "UNLICENSED", "authors": [ "apple-1@example.com", diff --git a/pkl-commons-test/src/main/files/packages/fruit@1.1.0/fruit@1.1.0.json b/pkl-commons-test/src/main/files/packages/fruit@1.1.0/fruit@1.1.0.json index d27fc890f..797ef9035 100644 --- a/pkl-commons-test/src/main/files/packages/fruit@1.1.0/fruit@1.1.0.json +++ b/pkl-commons-test/src/main/files/packages/fruit@1.1.0/fruit@1.1.0.json @@ -9,7 +9,6 @@ "sha256": "$computedChecksum" }, "sourceCode": "https://example.com/fruit", - "documentation": "https://example.com/fruit-docs", "license": "UNLICENSED", "authors": [ "apple-1@example.com", diff --git a/pkl-commons-test/src/main/kotlin/org/pkl/commons/test/PackageServer.kt b/pkl-commons-test/src/main/kotlin/org/pkl/commons/test/PackageServer.kt index e5c26a048..3359d2dcd 100644 --- a/pkl-commons-test/src/main/kotlin/org/pkl/commons/test/PackageServer.kt +++ b/pkl-commons-test/src/main/kotlin/org/pkl/commons/test/PackageServer.kt @@ -46,9 +46,9 @@ import org.pkl.commons.deleteRecursively */ class PackageServer : AutoCloseable { companion object { - const val BIRDS_SHA = "bfaf5281613d170a740505cc87561041f4e0cad1f0e6938bf94f7609f9a4673d" - const val FRUIT_SHA = "34a15b02346e6acb85da5bd71d8b0738a79008b38a7fc805e5869d9129ad27d2" - const val FRUIT_1_1_SHA = "8d982761d182f2185e4180c82190791d9a60c721cb3393bb2e946fab90131e8c" + const val BIRDS_SHA = "c90e62ac513c93bd5850e21d669dbc70afd267ab7b6c7aff77ab4e0111c5b723" + const val FRUIT_SHA = "8ff80e5ac882650e817f261c8af024bf0db9b07888c9d18c20017457e04ffe06" + const val FRUIT_1_1_SHA = "eaf03e7162bdc23797b92cffc8151b98ac655476e4ec843d2d2280f225bdfddc" fun populateCacheDir(cacheDir: Path) { doPopulateCacheDir(cacheDir.resolve("package-2/localhost(3a)$PORT")) diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/packages/packages1.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/packages/packages1.pkl index 5aa4ac52e..253793bc6 100644 --- a/pkl-core/src/test/files/LanguageSnippetTests/input/packages/packages1.pkl +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/packages/packages1.pkl @@ -16,7 +16,7 @@ examples { import("package://localhost:0/birds@0.5.0#/catalog/Ostritch.pkl") } ["importing while specifying checksum"] { - import("package://localhost:0/birds@0.5.0::sha256:bfaf5281613d170a740505cc87561041f4e0cad1f0e6938bf94f7609f9a4673d#/catalog/Swallow.pkl") + import("package://localhost:0/birds@0.5.0::sha256:c90e62ac513c93bd5850e21d669dbc70afd267ab7b6c7aff77ab4e0111c5b723#/catalog/Swallow.pkl") } ["reads"] { read("package://localhost:0/birds@0.5.0#/Bird.pkl") diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/packages/packages2.pkl b/pkl-core/src/test/files/LanguageSnippetTests/input/packages/packages2.pkl index 8d9f614c7..affe90bdd 100644 --- a/pkl-core/src/test/files/LanguageSnippetTests/input/packages/packages2.pkl +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/packages/packages2.pkl @@ -20,6 +20,6 @@ examples { import("package://localhost:0/birds@0.5.0#/allFruit.pkl").fruitFiles } ["glob import while specifying checksum"] { - import*("package://localhost:0/birds@0.5.0::sha256:bfaf5281613d170a740505cc87561041f4e0cad1f0e6938bf94f7609f9a4673d#/catalog/*.pkl") + import*("package://localhost:0/birds@0.5.0::sha256:c90e62ac513c93bd5850e21d669dbc70afd267ab7b6c7aff77ab4e0111c5b723#/catalog/*.pkl") } } diff --git a/pkl-core/src/test/files/LanguageSnippetTests/input/projects/project4/PklProject.deps.json b/pkl-core/src/test/files/LanguageSnippetTests/input/projects/project4/PklProject.deps.json index 681310c7c..e0ff4edef 100644 --- a/pkl-core/src/test/files/LanguageSnippetTests/input/projects/project4/PklProject.deps.json +++ b/pkl-core/src/test/files/LanguageSnippetTests/input/projects/project4/PklProject.deps.json @@ -5,7 +5,7 @@ "type": "remote", "uri": "projectpackage://localhost:0/fruit@1.0.5", "checksums": { - "sha256": "34a15b02346e6acb85da5bd71d8b0738a79008b38a7fc805e5869d9129ad27d2" + "sha256": "8ff80e5ac882650e817f261c8af024bf0db9b07888c9d18c20017457e04ffe06" } } } diff --git a/pkl-core/src/test/files/LanguageSnippetTests/output/packages/packages2.pcf b/pkl-core/src/test/files/LanguageSnippetTests/output/packages/packages2.pcf index 3c6ec7ee9..4da3642e4 100644 --- a/pkl-core/src/test/files/LanguageSnippetTests/output/packages/packages2.pcf +++ b/pkl-core/src/test/files/LanguageSnippetTests/output/packages/packages2.pcf @@ -118,13 +118,13 @@ examples { } ["glob import while specifying checksum"] { new { - ["package://localhost:0/birds@0.5.0::sha256:bfaf5281613d170a740505cc87561041f4e0cad1f0e6938bf94f7609f9a4673d#/catalog/Ostritch.pkl"] { + ["package://localhost:0/birds@0.5.0::sha256:c90e62ac513c93bd5850e21d669dbc70afd267ab7b6c7aff77ab4e0111c5b723#/catalog/Ostritch.pkl"] { name = "Ostritch" favoriteFruit { name = "Orange" } } - ["package://localhost:0/birds@0.5.0::sha256:bfaf5281613d170a740505cc87561041f4e0cad1f0e6938bf94f7609f9a4673d#/catalog/Swallow.pkl"] { + ["package://localhost:0/birds@0.5.0::sha256:c90e62ac513c93bd5850e21d669dbc70afd267ab7b6c7aff77ab4e0111c5b723#/catalog/Swallow.pkl"] { name = "Swallow" favoriteFruit { name = "Apple" diff --git a/pkl-doc/src/main/kotlin/org/pkl/doc/CliDocGenerator.kt b/pkl-doc/src/main/kotlin/org/pkl/doc/CliDocGenerator.kt index e94215210..170a5641a 100644 --- a/pkl-doc/src/main/kotlin/org/pkl/doc/CliDocGenerator.kt +++ b/pkl-doc/src/main/kotlin/org/pkl/doc/CliDocGenerator.kt @@ -58,7 +58,7 @@ class CliDocGenerator(private val options: CliDocGeneratorOptions) : CliCommand( PklInfo.current() .packageIndex .getPackagePage("pkl", Release.current().version().toString()) - ) + ), ) private fun DependencyMetadata.getPackageDependencies(): List { @@ -74,7 +74,8 @@ class CliDocGenerator(private val options: CliDocGeneratorOptions) : CliCommand( } val packageDependency = DocPackageInfo.PackageDependency( - name = metadata.name, + name = + "${dependency.packageUri.uri.authority}${dependency.packageUri.uri.path.substringBeforeLast('@')}", uri = dependency.packageUri.uri, version = metadata.version.toString(), sourceCode = metadata.sourceCode, diff --git a/pkl-doc/src/main/kotlin/org/pkl/doc/DocPackageInfo.kt b/pkl-doc/src/main/kotlin/org/pkl/doc/DocPackageInfo.kt index a4d343c02..9829ffc54 100644 --- a/pkl-doc/src/main/kotlin/org/pkl/doc/DocPackageInfo.kt +++ b/pkl-doc/src/main/kotlin/org/pkl/doc/DocPackageInfo.kt @@ -101,7 +101,7 @@ data class DocPackageInfo( version = dependency["version"] as String, sourceCode = (dependency["sourceCode"] as String?)?.toUri(), sourceCodeUrlScheme = dependency["sourceCodeUrlScheme"] as String?, - documentation = (dependency["documentation"] as String?)?.toUri() + documentation = (dependency["documentation"] as String?)?.toUri(), ) }, overview = module["overview"] as String, diff --git a/pkl-doc/src/main/kotlin/org/pkl/doc/DocScope.kt b/pkl-doc/src/main/kotlin/org/pkl/doc/DocScope.kt index 30ca4b7f9..aa69bd62d 100644 --- a/pkl-doc/src/main/kotlin/org/pkl/doc/DocScope.kt +++ b/pkl-doc/src/main/kotlin/org/pkl/doc/DocScope.kt @@ -35,7 +35,7 @@ internal sealed class DocScope { abstract val parent: DocScope? - private val siteScope: SiteScope? by lazy { + val siteScope: SiteScope? by lazy { var scope = this while (scope !is SiteScope) { scope = scope.parent ?: return@lazy null diff --git a/pkl-doc/src/main/kotlin/org/pkl/doc/PageGenerator.kt b/pkl-doc/src/main/kotlin/org/pkl/doc/PageGenerator.kt index 98f120622..e081ed4e3 100644 --- a/pkl-doc/src/main/kotlin/org/pkl/doc/PageGenerator.kt +++ b/pkl-doc/src/main/kotlin/org/pkl/doc/PageGenerator.kt @@ -525,15 +525,30 @@ internal abstract class PageGenerator( var first = true for (dep in dependencies) { if (first) first = false else +", " - a { - href = - dep.documentation?.toString() - ?: pageScope.relativeSiteUrl - .resolve("${dep.name}/${dep.version}/index.html") - .toString() - +dep.name - +":" - +dep.version + val text = "${dep.name}:${dep.version}" + if (dep.documentation != null) { + a { + href = dep.documentation.toString() + +text + } + } else { + val localSitePackage = + pageScope.siteScope?.packageScopes?.values?.find { + it.docPackageInfo.name == dep.name + } + if (localSitePackage != null) { + a { + href = + pageScope.relativeSiteUrl + .resolve( + "${localSitePackage.docPackageInfo.name.pathEncoded}/current/index.html" + ) + .toString() + +text + } + } else { + +text + } } } } diff --git a/pkl-doc/src/test/files/DocGeneratorTest/output/com.package1/1.2.3/index.html b/pkl-doc/src/test/files/DocGeneratorTest/output/com.package1/1.2.3/index.html index 0d4c7910f..f6f03595a 100644 --- a/pkl-doc/src/test/files/DocGeneratorTest/output/com.package1/1.2.3/index.html +++ b/pkl-doc/src/test/files/DocGeneratorTest/output/com.package1/1.2.3/index.html @@ -39,7 +39,7 @@

com.package11.2.3Issue tracker:
https://issues.apple.com/package1/
Dependencies:
-
com.package2:4.5.6, com.externalpackage:7.8.9
+
com.package2:4.5.6, com.externalpackage:7.8.9
diff --git a/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/birds/0.5.0/Bird/index.html b/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/birds/0.5.0/Bird/index.html index 8329ca762..b7e6beb8f 100644 --- a/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/birds/0.5.0/Bird/index.html +++ b/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/birds/0.5.0/Bird/index.html @@ -74,7 +74,7 @@

Properties
-
favoriteFruit: FruitSource
+
favoriteFruit: FruitSource
diff --git a/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/birds/0.5.0/index.html b/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/birds/0.5.0/index.html index 33ed09bd2..8707a3b4b 100644 --- a/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/birds/0.5.0/index.html +++ b/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/birds/0.5.0/index.html @@ -37,9 +37,9 @@

localhost:0/birds0.5.0
Issue tracker:
https://example.com/birds/issues
Dependencies:
-
fruit:1.0.5
+
localhost:0/fruit:1.0.5
Checksum:
-
bfaf5281613d170a740505cc87561041f4e0cad1f0e6938bf94f7609f9a4673d
+
c90e62ac513c93bd5850e21d669dbc70afd267ab7b6c7aff77ab4e0111c5b723
diff --git a/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/birds/0.5.0/package-data.json b/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/birds/0.5.0/package-data.json index a5cf6df8f..f1c8524bc 100644 --- a/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/birds/0.5.0/package-data.json +++ b/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/birds/0.5.0/package-data.json @@ -1 +1 @@ -{"ref":{"pkg":"localhost:0/birds","pkgUri":"package://localhost:0/birds@0.5.0","version":"0.5.0"},"sourceCode":"https://example.com/birds","sourceCodeUrlScheme":"https://example.com/birds/v0.5.0/blob%{path}#L%{line}-L%{endLine}","dependencies":[{"ref":{"pkg":"fruit","pkgUri":"package://localhost:0/fruit@1.0.5","version":"1.0.5"}},{"ref":{"pkg":"pkl","pkgUri":null,"version":"0.24.0"}}],"modules":[{"ref":{"pkg":"localhost:0/birds","pkgUri":"package://localhost:0/birds@0.5.0","version":"0.5.0","module":"catalog"},"moduleClass":{"ref":{"pkg":"localhost:0/birds","pkgUri":"package://localhost:0/birds@0.5.0","version":"0.5.0","module":"catalog","type":"ModuleClass"},"superclasses":[{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Module"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Typed"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Object"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Any"}]}},{"ref":{"pkg":"localhost:0/birds","pkgUri":"package://localhost:0/birds@0.5.0","version":"0.5.0","module":"allFruit"},"moduleClass":{"ref":{"pkg":"localhost:0/birds","pkgUri":"package://localhost:0/birds@0.5.0","version":"0.5.0","module":"allFruit","type":"ModuleClass"},"superclasses":[{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Module"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Typed"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Object"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Any"}]}},{"ref":{"pkg":"localhost:0/birds","pkgUri":"package://localhost:0/birds@0.5.0","version":"0.5.0","module":"Bird"},"moduleClass":{"ref":{"pkg":"localhost:0/birds","pkgUri":"package://localhost:0/birds@0.5.0","version":"0.5.0","module":"Bird","type":"ModuleClass"},"superclasses":[{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Module"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Typed"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Object"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Any"}],"usedTypes":[{"pkg":"fruit","pkgUri":"package://localhost:0/fruit@1.0.5","version":"1.0.5","module":"Fruit","type":"ModuleClass"}]}}]} \ No newline at end of file +{"ref":{"pkg":"localhost:0/birds","pkgUri":"package://localhost:0/birds@0.5.0","version":"0.5.0"},"sourceCode":"https://example.com/birds","sourceCodeUrlScheme":"https://example.com/birds/v0.5.0/blob%{path}#L%{line}-L%{endLine}","dependencies":[{"ref":{"pkg":"localhost:0/fruit","pkgUri":"package://localhost:0/fruit@1.0.5","version":"1.0.5"}},{"ref":{"pkg":"pkl","pkgUri":null,"version":"0.24.0"}}],"modules":[{"ref":{"pkg":"localhost:0/birds","pkgUri":"package://localhost:0/birds@0.5.0","version":"0.5.0","module":"catalog"},"moduleClass":{"ref":{"pkg":"localhost:0/birds","pkgUri":"package://localhost:0/birds@0.5.0","version":"0.5.0","module":"catalog","type":"ModuleClass"},"superclasses":[{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Module"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Typed"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Object"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Any"}]}},{"ref":{"pkg":"localhost:0/birds","pkgUri":"package://localhost:0/birds@0.5.0","version":"0.5.0","module":"allFruit"},"moduleClass":{"ref":{"pkg":"localhost:0/birds","pkgUri":"package://localhost:0/birds@0.5.0","version":"0.5.0","module":"allFruit","type":"ModuleClass"},"superclasses":[{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Module"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Typed"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Object"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Any"}]}},{"ref":{"pkg":"localhost:0/birds","pkgUri":"package://localhost:0/birds@0.5.0","version":"0.5.0","module":"Bird"},"moduleClass":{"ref":{"pkg":"localhost:0/birds","pkgUri":"package://localhost:0/birds@0.5.0","version":"0.5.0","module":"Bird","type":"ModuleClass"},"superclasses":[{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Module"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Typed"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Object"},{"pkg":"pkl","pkgUri":null,"version":"0.24.0","module":"base","type":"Any"}]}}]} \ No newline at end of file diff --git a/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/fruit/1.1.0/index.html b/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/fruit/1.1.0/index.html index ed46e80c4..80a49eccf 100644 --- a/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/fruit/1.1.0/index.html +++ b/pkl-doc/src/test/files/DocGeneratorTest/output/localhost(3a)0/fruit/1.1.0/index.html @@ -37,7 +37,7 @@

localhost:0/fruit1.1.0
Issue tracker:
https://example.com/fruit/issues
Checksum:
-
8d982761d182f2185e4180c82190791d9a60c721cb3393bb2e946fab90131e8c
+
eaf03e7162bdc23797b92cffc8151b98ac655476e4ec843d2d2280f225bdfddc