Skip to content

Commit 563f0a4

Browse files
committed
feat(provenance): only enable provenance for the official registry
at least until there is a known why to use provenance with alternative registries
1 parent c8e5cb0 commit 563f0a4

8 files changed

Lines changed: 30 additions & 20 deletions

File tree

src/project-type/publishable/badges.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
function buildNpmBadgeImageUrl(packageName, registry) {
2-
const params = new URLSearchParams({logo: 'npm', ...registry && {registry_uri: registry}});
1+
function buildNpmBadgeImageUrl(packageName, customRegistry) {
2+
const params = new URLSearchParams({logo: 'npm', ...customRegistry && {registry_uri: customRegistry}});
33

44
return `https://img.shields.io/npm/v/${packageName}?${params}`;
55
}
66

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

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ describe('badges for publishable project types', async () => {
1616
});
1717

1818
it('should return the npm badge for packages with a public access level', () => {
19-
expect(defineBadges(packageName, 'public').consumer).toEqual({npm: npmBadgeDetails});
19+
expect(defineBadges({packageName, accessLevel: 'public'}).consumer).toEqual({npm: npmBadgeDetails});
2020
});
2121

2222
it('should include the registry_uri in the npm badge when a custom registry is provided', () => {
23-
const registry = any.url();
23+
const customRegistry = any.url();
2424

25-
const {searchParams} = new URL(defineBadges(packageName, 'public', registry).consumer.npm.img);
25+
const {searchParams} = new URL(defineBadges({packageName, accessLevel: 'public', customRegistry}).consumer.npm.img);
2626

27-
expect(searchParams.get('registry_uri')).toEqual(registry);
27+
expect(searchParams.get('registry_uri')).toEqual(customRegistry);
2828
});
2929
});

src/project-type/publishable/lifter.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,17 @@ 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 homepage = `https://npm.im/${packageName}`;
11-
const registry = resolveRegistry(packageName, configs.registries);
11+
const customRegistry = resolveRegistry(packageName, configs.registries);
1212

1313
await mergeIntoExistingPackageJson({projectRoot, config: {homepage}});
1414

1515
return deepmerge(
16-
await liftProvenance({packageDetails, projectRoot}),
16+
await liftProvenance({packageDetails, projectRoot, customRegistry}),
1717
{
1818
homepage,
1919
dependencies: {javascript: {development: ['publint']}},
2020
scripts: {'lint:publish': 'publint --strict'},
21-
badges: defineBadges(packageName, packageAccessLevel, registry)
21+
badges: defineBadges({packageName, accessLevel: packageAccessLevel, customRegistry})
2222
}
2323
);
2424
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,17 @@ describe('publishable project-type lifter', () => {
2222
const packageName = any.word();
2323
const packageAccessLevel = any.word();
2424
const registries = any.simpleObject();
25-
const registry = any.url();
25+
const customRegistry = any.url();
2626
const packageDetails = {...any.simpleObject(), name: packageName, publishConfig: {access: packageAccessLevel}};
2727
const provenanceResults = any.simpleObject();
2828
const mergedResults = any.simpleObject();
2929
const badgesResults = any.simpleObject();
3030
const homepage = `https://npm.im/${packageName}`;
31-
when(resolveRegistry).calledWith(packageName, registries).thenReturn(registry);
32-
when(liftProvenance).calledWith({packageDetails, projectRoot}).thenResolve(provenanceResults);
33-
when(defineBadges).calledWith(packageName, packageAccessLevel, registry).thenReturn(badgesResults);
31+
when(resolveRegistry).calledWith(packageName, registries).thenReturn(customRegistry);
32+
when(liftProvenance).calledWith({packageDetails, projectRoot, customRegistry}).thenResolve(provenanceResults);
33+
when(defineBadges)
34+
.calledWith({packageName, accessLevel: packageAccessLevel, customRegistry})
35+
.thenReturn(badgesResults);
3436
when(deepmerge).calledWith(
3537
provenanceResults,
3638
{

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import {mergeIntoExistingPackageJson} from '@form8ion/javascript-core';
22

33
import enhanceSlsa from './slsa.js';
44

5-
export default async function liftProvenance({projectRoot, packageDetails}) {
5+
export default async function liftProvenance({projectRoot, packageDetails, customRegistry}) {
66
const {publishConfig: {access} = {}} = packageDetails;
77

8-
if ('public' === access) {
8+
if ('public' === access && !customRegistry) {
99
await mergeIntoExistingPackageJson({projectRoot, config: {publishConfig: {provenance: true}}});
1010

1111
return enhanceSlsa({provenance: true});

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ describe('provenance lifter', () => {
2929
});
3030
});
3131

32+
it('should not configure provenance for a public package published to an alternative registry', async () => {
33+
const packageDetails = {...any.simpleObject(), publishConfig: {access: 'public'}};
34+
const customRegistry = any.url();
35+
36+
expect(await lift({packageDetails, projectRoot, customRegistry})).toEqual({});
37+
expect(enhanceSlsa).not.toHaveBeenCalled();
38+
expect(mergeIntoExistingPackageJson).not.toHaveBeenCalled();
39+
});
40+
3241
it('should not configure provenance for a restricted package', async () => {
3342
const packageDetails = {...any.simpleObject(), publishConfig: {access: 'restricted'}};
3443

test/integration/features/lift/provenance.feature

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ Feature: Package Provenance
2020
And provenance is enabled for publishing
2121
Then the SLSA badge is added to the status group
2222

23-
@wip
2423
Scenario: Public Package on registry that does not support provenance
2524
Given an "npm" lockfile exists
2625
And the project is of type "Publishable"
2726
And the package is published publicly
2827
And the package is published without provenance
29-
And the package is published to an alternative registry
28+
And an alternative registry is defined for publishing
3029
And husky v5 is installed
3130
When the scaffolder results are processed
3231
And provenance is not enabled for publishing

test/integration/features/step_definitions/publishable-steps.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Given('the package is published with provenance', async function () {
1616
});
1717

1818
Given('the package is published without provenance', async function () {
19-
this.publishConfig.provenance = null;
19+
delete this.publishConfig.provenance;
2020
});
2121

2222
Then('publint is configured', async function () {

0 commit comments

Comments
 (0)