Skip to content

Commit 416259a

Browse files
committed
feat(publishable): consider the publish registry for the registry referenced by the version badge
1 parent d159399 commit 416259a

4 files changed

Lines changed: 37 additions & 1 deletion

File tree

src/project-type/publishable/registry-resolver.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ function isScope(firstPart) {
33
}
44

55
export default function resolveRegistry(packageName, registries = {}) {
6+
if (registries.publish) return registries.publish;
7+
68
const [firstPart] = packageName.split('/');
79
if (isScope(firstPart)) {
810
const scopedRegistry = registries[firstPart.slice(1)];

src/project-type/publishable/registry-resolver.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,25 @@ describe('registry resolver', () => {
1616
expect(resolveRegistry(any.word(), {registry})).toEqual(registry);
1717
});
1818

19+
it('should return the publish registry when defined', () => {
20+
const publishRegistry = any.url();
21+
22+
expect(resolveRegistry(any.word(), {publish: publishRegistry})).toEqual(publishRegistry);
23+
});
24+
25+
it('should prefer the publish registry over the main registry override', () => {
26+
const publishRegistry = any.url();
27+
28+
expect(resolveRegistry(any.word(), {registry, publish: publishRegistry})).toEqual(publishRegistry);
29+
});
30+
31+
it('should prefer the publish registry over the scoped registry', () => {
32+
const publishRegistry = any.url();
33+
34+
expect(resolveRegistry(`@${scope}/${any.word()}`, {[scope]: scopedRegistry, publish: publishRegistry}))
35+
.toEqual(publishRegistry);
36+
});
37+
1938
it('should return the scoped registry when the package is under a scope with a defined registry', () => {
2039
expect(resolveRegistry(`@${scope}/${any.word()}`, {[scope]: scopedRegistry})).toEqual(scopedRegistry);
2140
});

test/integration/features/lift/registries.feature

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,19 @@ Feature: Lift Registries
3232
And the lockfile-lint config allows the "npm" registry
3333
And the lockfile-lint config allows the scoped registries
3434

35+
Scenario: npmrc exists, no registry defined, alternative publish registry provided
36+
Given the npmrc does not define registry
37+
And an "npm" lockfile exists
38+
And lockfile-lint is configured
39+
And the project is of type "Package"
40+
And husky v5 is installed
41+
And an alternative registry is defined for publishing
42+
When the scaffolder results are processed
43+
Then registry is defined as the official registry
44+
And the lockfile-lint config allows the "npm" registry
45+
And the registry configuration is defined
46+
And the version badge references the custom registry
47+
3548
Scenario: npmrc exists, no registry defined, registry defined for the package's scope
3649
Given the npmrc does not define registry
3750
And an "npm" lockfile exists

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ Given('an override is defined for the official registry', async function () {
2323
});
2424

2525
Given('an alternative registry is defined for publishing', async function () {
26-
this.registries = {...this.registries, publish: any.url()};
26+
const registry = any.url();
27+
this.registries = {...this.registries, publish: registry};
28+
this.publishRegistry = registry;
2729
});
2830

2931
Given('a registry is defined for the package\'s scope', async function () {

0 commit comments

Comments
 (0)