Skip to content

Commit 3507515

Browse files
fix(scanner): prioritize repository over homepage in getLinks
1 parent f1d0f9a commit 3507515

3 files changed

Lines changed: 44 additions & 5 deletions

File tree

.changeset/wacky-lizards-attack.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@nodesecure/scanner": patch
3+
---
4+
5+
Prioritize repository over homepage in package.json to generate repository link

workspaces/scanner/src/utils/getLinks.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ export function getLinks(
4444
npm: `https://www.npmjs.com/package/${packumentVersion.name}/v/${packumentVersion.version}`,
4545
homepage,
4646
repository:
47-
getVCSRepositoryURL(homepage) ??
48-
getVCSRepositoryURL(repositoryUrl)
47+
getVCSRepositoryURL(repositoryUrl) ??
48+
getVCSRepositoryURL(homepage)
4949
};
5050
}
5151

@@ -61,7 +61,7 @@ export function getManifestLinks(
6161
npm: null,
6262
homepage,
6363
repository:
64-
getVCSRepositoryURL(homepage) ??
65-
getVCSRepositoryURL(repositoryUrl)
64+
getVCSRepositoryURL(repositoryUrl) ??
65+
getVCSRepositoryURL(homepage)
6666
};
6767
}

workspaces/scanner/test/utils/getLinks.spec.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,29 @@ describe("utils.getLinks", () => {
4444
type: "git",
4545
url: "github.com/foo/bar"
4646
}
47-
} as any), {
47+
} as PackumentVersion), {
4848
npm: "https://www.npmjs.com/package/foo/v/1.0.0",
4949
homepage: "https://github.com/foo/bar",
5050
repository: "https://github.com/foo/bar"
5151
});
5252
});
53+
54+
it("repository url should prioritize repository over homepage", () => {
55+
assert.deepStrictEqual(utils.getLinks({
56+
name: "@nodesecure/utils",
57+
version: "2.3.0",
58+
homepage: "https://github.com/NodeSecure/tree/master/workspaces/utils#readme",
59+
repository: {
60+
type: "git",
61+
url: "https://github.com/NodeSecure/scanner",
62+
directory: "workspaces/utils"
63+
}
64+
} as PackumentVersion), {
65+
npm: "https://www.npmjs.com/package/@nodesecure/utils/v/2.3.0",
66+
homepage: "https://github.com/NodeSecure/tree/master/workspaces/utils#readme",
67+
repository: "https://github.com/NodeSecure/scanner"
68+
});
69+
});
5370
});
5471

5572
describe("utils.getManifestLinks", () => {
@@ -94,4 +111,21 @@ describe("utils.getManifestLinks", () => {
94111
repository: "https://github.com/foo/bar"
95112
});
96113
});
114+
115+
it("repository url should prioritize repository over homepage", () => {
116+
assert.deepStrictEqual(utils.getManifestLinks({
117+
name: "@nodesecure/utils",
118+
version: "2.3.0",
119+
homepage: "https://github.com/NodeSecure/tree/master/workspaces/utils#readme",
120+
repository: {
121+
type: "git",
122+
url: "https://github.com/NodeSecure/scanner",
123+
directory: "workspaces/utils"
124+
}
125+
}), {
126+
npm: null,
127+
homepage: "https://github.com/NodeSecure/tree/master/workspaces/utils#readme",
128+
repository: "https://github.com/NodeSecure/scanner"
129+
});
130+
});
97131
});

0 commit comments

Comments
 (0)