Skip to content

Commit c3530c2

Browse files
committed
fix(registry-page): normalize the link to the registry page between the badge and package.json
1 parent 9cf8c77 commit c3530c2

5 files changed

Lines changed: 30 additions & 16 deletions

File tree

src/project-type/publishable/badges.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ function buildNpmBadgeImageUrl(packageName, customRegistry) {
44
return `https://img.shields.io/npm/v/${packageName}?${params}`;
55
}
66

7-
export default function scaffoldPublishableBadges({packageName, accessLevel, customRegistry}) {
7+
export default function scaffoldPublishableBadges({packageName, accessLevel, customRegistry, registryPage}) {
88
return {
99
consumer: {
1010
...'public' === accessLevel && {
1111
npm: {
1212
img: buildNpmBadgeImageUrl(packageName, customRegistry),
1313
text: 'npm',
14-
link: `https://www.npmjs.com/package/${packageName}`
14+
link: registryPage
1515
}
1616
}
1717
},

src/project-type/publishable/badges.test.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,33 @@ import defineBadges from './badges.js';
55

66
describe('badges for publishable project types', async () => {
77
const packageName = any.word();
8+
const registryPage = any.url();
89
const npmBadgeDetails = {
910
img: `https://img.shields.io/npm/v/${packageName}?logo=npm`,
1011
text: 'npm',
11-
link: `https://www.npmjs.com/package/${packageName}`
12+
link: registryPage
1213
};
1314

14-
it('should define the badges when the access level is not public', () => {
15-
expect(defineBadges(packageName)).toEqual({consumer: {}, status: {}});
15+
it('should note define the badges when the access level is not public', () => {
16+
expect(defineBadges({packageName})).toEqual({consumer: {}, status: {}});
1617
});
1718

1819
it('should return the npm badge for packages with a public access level', () => {
19-
expect(defineBadges({packageName, accessLevel: 'public'}).consumer).toEqual({npm: npmBadgeDetails});
20+
expect(defineBadges({
21+
packageName,
22+
accessLevel: 'public',
23+
registryPage
24+
}).consumer).toEqual({npm: npmBadgeDetails});
2025
});
2126

2227
it('should include the registry_uri in the npm badge when a custom registry is provided', () => {
2328
const customRegistry = any.url();
2429

25-
const {searchParams} = new URL(defineBadges({packageName, accessLevel: 'public', customRegistry}).consumer.npm.img);
30+
const {searchParams} = new URL(defineBadges({
31+
packageName,
32+
accessLevel: 'public',
33+
customRegistry
34+
}, `https://www.npmjs.com/package/${packageName}`).consumer.npm.img);
2635

2736
expect(searchParams.get('registry_uri')).toEqual(customRegistry);
2837
});

src/project-type/publishable/lifter.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@ import {lift as liftProvenance} from './provenance/index.js';
88
export default async function liftPublishable({projectRoot, packageDetails, configs}) {
99
const {name: packageName, publishConfig: {access: packageAccessLevel}} = packageDetails;
1010
const customRegistry = resolveRegistry(packageName, configs.registries);
11-
const homepage = `https://npm.im/${packageName}`;
11+
const registryPage = `https://www.npmjs.com/package/${packageName}`;
1212

13-
await mergeIntoExistingPackageJson({projectRoot, config: {homepage}});
13+
await mergeIntoExistingPackageJson({projectRoot, config: {homepage: registryPage}});
1414

1515
return deepmerge(
1616
await liftProvenance({packageDetails, projectRoot, customRegistry}),
1717
{
18-
homepage,
18+
homepage: registryPage,
1919
dependencies: {javascript: {development: ['publint']}},
2020
scripts: {'lint:publish': 'publint --strict'},
21-
badges: defineBadges({packageName, accessLevel: packageAccessLevel, customRegistry})
21+
badges: defineBadges({
22+
packageName,
23+
accessLevel: packageAccessLevel,
24+
customRegistry,
25+
registryPage
26+
})
2227
}
2328
);
2429
}

src/project-type/publishable/lifter.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,23 @@ describe('publishable project-type lifter', () => {
2727
const provenanceResults = any.simpleObject();
2828
const mergedResults = any.simpleObject();
2929
const badgesResults = any.simpleObject();
30-
const homepage = `https://npm.im/${packageName}`;
30+
const registryPage = `https://www.npmjs.com/package/${packageName}`;
3131
when(resolveRegistry).calledWith(packageName, registries).thenReturn(customRegistry);
3232
when(liftProvenance).calledWith({packageDetails, projectRoot, customRegistry}).thenResolve(provenanceResults);
3333
when(defineBadges)
34-
.calledWith({packageName, accessLevel: packageAccessLevel, customRegistry})
34+
.calledWith({packageName, accessLevel: packageAccessLevel, customRegistry, registryPage})
3535
.thenReturn(badgesResults);
3636
when(deepmerge).calledWith(
3737
provenanceResults,
3838
{
3939
scripts: {'lint:publish': 'publint --strict'},
4040
dependencies: {javascript: {development: ['publint']}},
4141
badges: badgesResults,
42-
homepage
42+
homepage: registryPage
4343
}
4444
).thenReturn(mergedResults);
4545

4646
expect(await lift({projectRoot, packageDetails, configs: {registries}})).toEqual(mergedResults);
47-
expect(mergeIntoExistingPackageJson).toHaveBeenCalledWith({projectRoot, config: {homepage}});
47+
expect(mergeIntoExistingPackageJson).toHaveBeenCalledWith({projectRoot, config: {homepage: registryPage}});
4848
});
4949
});

test/integration/features/step_definitions/project-type-steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import any from '@travi/any';
99
export function assertHomepageDefinedProperly(homepage, projectType, projectName, npmAccount, vcs) {
1010
if ([projectTypes.PACKAGE, projectTypes.CLI].includes(projectType)) {
1111
const packageName = `@${npmAccount}/${projectName}`;
12-
assert.equal(homepage, `https://npm.im/${packageName}`);
12+
assert.equal(homepage, `https://www.npmjs.com/package/${packageName}`);
1313
} else if (vcs && 'github' === vcs.host) {
1414
assert.equal(homepage, `https://github.com/${vcs.owner}/${vcs.name}#readme`);
1515
} else if (!vcs) {

0 commit comments

Comments
 (0)