Skip to content

Commit

Permalink
feat(node): Handle textual repository nodes in package.json
Browse files Browse the repository at this point in the history
The repository nodes can be textual, see [1]

[1]: https://docs.npmjs.com/cli/v10/configuring-npm/package-json#repository

Signed-off-by: Frank Viernau <[email protected]>
  • Loading branch information
fviernau committed Apr 12, 2024
1 parent a9bcec8 commit cb39f8c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 11 deletions.
29 changes: 19 additions & 10 deletions plugins/package-managers/node/src/main/kotlin/utils/NpmSupport.kt
Original file line number Diff line number Diff line change
Expand Up @@ -153,16 +153,25 @@ internal fun parseNpmVcsInfo(node: JsonNode): VcsInfo {
revision = head
)

val type = repository["type"].textValueOrEmpty()
val url = repository.textValue() ?: repository["url"].textValueOrEmpty()
val path = repository["directory"].textValueOrEmpty()

return VcsInfo(
type = VcsType.forName(type),
url = expandNpmShortcutUrl(url),
revision = head,
path = path
)
return if (repository.isTextual) {
VcsInfo(
type = VcsType.UNKNOWN,
url = expandNpmShortcutUrl(repository.textValue()),
path = "",
revision = head
)
} else {
val type = repository["type"].textValueOrEmpty()
val url = repository.textValue() ?: repository["url"].textValueOrEmpty()
val path = repository["directory"].textValueOrEmpty()

VcsInfo(
type = VcsType.forName(type),
url = expandNpmShortcutUrl(url),
revision = head,
path = path
)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class NpmSupportTest : WordSpec({
}

"parseNpmVcsInfo()" should {
"get VCS information from an object node" {
"get VCS information from an object node containing a repository node which is an object" {
val node = """
{
"gitHead": "bar",
Expand All @@ -211,6 +211,21 @@ class NpmSupportTest : WordSpec({
"foo"
)
}

"get VCS information from an object node containing a repository node which is textual" {
val node = """
{
"gitHead": "bar",
"repository": "git+ssh://example.com/a/b.git"
}
""".readJsonTree()

parseNpmVcsInfo(node) shouldBe VcsInfo(
VcsType.UNKNOWN,
"git+ssh://example.com/a/b.git",
"bar"
)
}
}

"splitNpmNamespaceAndName()" should {
Expand Down

0 comments on commit cb39f8c

Please sign in to comment.