Skip to content

Commit

Permalink
Prefer homepage URL over repository URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Skelton committed Dec 23, 2022
1 parent 970c93e commit ff49444
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const truthy = Boolean as unknown as <T>(

export function getHomepageURL({ raw: manifest }: Manifest): string | null {
const repo = manifest.repository
const repoURL = !repo
const repoURL = manifest.homepage
? manifest.homepage
: typeof repo === "string"
? repo
Expand Down
26 changes: 20 additions & 6 deletions test/specs/url.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,44 @@ test.describe("yarn outdated --url", () => {
const getURL = (raw: Record<string, unknown>) =>
getHomepageURL({ raw } as Manifest)

// npm
expect(getURL({ repository: "npm/npm" })).toBe("https://github.com/npm/npm")

// GitHub
expect(getURL({ repository: "https://github.com/user/repo.git" })).toBe(
"https://github.com/user/repo"
)
expect(getURL({ repository: "github:mskelton/yarn-plugin-outdated" })).toBe(
"https://github.com/mskelton/yarn-plugin-outdated"
)
expect(getURL({ repository: "bitbucket:user/repo" })).toBe(
"https://bitbucket.org/user/repo"
)
expect(getURL({ repository: "gitlab:user/repo" })).toBe(
"https://gitlab.com/user/repo"
)
expect(getURL({ repository: "git://github.com/user/repo.git" })).toBe(
"https://github.com/user/repo"
)
expect(getURL({ repository: "git@github.com:user/repo.git" })).toBe(
"https://github.com/user/repo"
)

// BitBucket
expect(getURL({ repository: "bitbucket:user/repo" })).toBe(
"https://bitbucket.org/user/repo"
)

// GitLab
expect(getURL({ repository: "gitlab:user/repo" })).toBe(
"https://gitlab.com/user/repo"
)

// Other
expect(getURL({ homepage: "https://foo.com" })).toBe("https://foo.com")
expect(getURL({ homepage: "http://foo.com" })).toBe("http://foo.com")
expect(getURL({ repository: { url: "http://foo.com" } })).toBe(
"http://foo.com"
)

// Prefer homepage over repository
expect(
getURL({ homepage: "http://foo.com", repository: "http://bar.com" })
).toBe("http://foo.com")
})

test.describe("when outdatedIncludeURL config is true", () => {
Expand Down

0 comments on commit ff49444

Please sign in to comment.