Skip to content

Commit 442eb07

Browse files
authored
Fixes tagging when pushing, also pays attention to brand new packages to be deployed (#234)
* publishes new packages if not in registry * Change files
1 parent d2ff10c commit 442eb07

14 files changed

Lines changed: 70 additions & 11 deletions
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"type": "patch",
3+
"comment": "Fixes tagging and also publish brand new packages if not exists",
4+
"packageName": "beachball",
5+
"email": "kchau@microsoft.com",
6+
"commit": "09a7071c0c71193224e203aaa0f51fa2dfc395c4",
7+
"date": "2020-01-15T04:41:35.192Z"
8+
}

packages/beachball/src/__tests__/publishGit.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ describe('publish command', () => {
5151
registry: 'http://localhost:99999/',
5252
tag: 'latest',
5353
token: '',
54+
new: false,
5455
yes: true,
5556
access: 'public',
5657
package: 'foo',
@@ -93,7 +94,6 @@ describe('publish command', () => {
9394
gitFailFast(['checkout', '-b', publishBranch], { cwd: repo1.rootPath });
9495

9596
console.log('Bumping version for npm publish');
96-
const bumpInfo = gatherBumpInfo(repo1.rootPath);
9797

9898
const options: BeachballOptions = {
9999
branch: 'origin/master',
@@ -107,6 +107,7 @@ describe('publish command', () => {
107107
tag: 'latest',
108108
token: '',
109109
yes: true,
110+
new: false,
110111
access: 'public',
111112
package: 'foo',
112113
changehint: 'Run "beachball change" to create a change file',
@@ -116,6 +117,8 @@ describe('publish command', () => {
116117
defaultNpmTag: 'latest',
117118
};
118119

120+
const bumpInfo = gatherBumpInfo(options);
121+
119122
// 3. Meanwhile, in repo2, also create a new change file
120123
const repo2 = await repositoryFactory.cloneRepository();
121124

packages/beachball/src/__tests__/publishRegistry.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ describe('publishToRegistry', () => {
5454
tag: 'latest',
5555
token: '',
5656
yes: true,
57+
new: false,
5758
access: 'public',
5859
package: 'foo',
5960
changehint: 'Run "beachball change" to create a change file',
@@ -131,6 +132,7 @@ describe('publishToRegistry', () => {
131132
tag: 'latest',
132133
token: '',
133134
yes: true,
135+
new: false,
134136
access: 'public',
135137
package: 'foopkg',
136138
changehint: 'Run "beachball change" to create a change file',
@@ -203,6 +205,7 @@ describe('publishToRegistry', () => {
203205
tag: 'latest',
204206
token: '',
205207
yes: true,
208+
new: false,
206209
access: 'public',
207210
package: 'foopkg',
208211
changehint: 'Run "beachball change" to create a change file',

packages/beachball/src/bump/bumpInPlace.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { updateRelatedChangeType } from './updateRelatedChangeType';
55
import { bumpPackageInfoVersion } from './bumpPackageInfoVersion';
66
import { BeachballOptions } from '../types/BeachballOptions';
77
import { setGroupsInBumpInfo } from './setGroupsInBumpInfo';
8-
import { gatherBumpInfo } from './gatherBumpInfo';
8+
99
/**
1010
* Updates BumpInfo according to change types, bump deps, and version groups
1111
*

packages/beachball/src/bump/gatherBumpInfo.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ import { readChangeFiles } from '../changefile/readChangeFiles';
33
import { getPackageInfos } from '../monorepo/getPackageInfos';
44
import { ChangeSet } from '../types/ChangeInfo';
55
import { BumpInfo } from '../types/BumpInfo';
6+
import { bumpInPlace } from './bumpInPlace';
7+
import { BeachballOptions } from '../types/BeachballOptions';
68

7-
export function gatherBumpInfo(cwd: string): BumpInfo {
9+
function gatherPreBumpInfo(cwd: string): BumpInfo {
810
// Collate the changes per package
911
const changes = readChangeFiles(cwd);
1012
const packageChangeTypes = getPackageChangeTypes(changes);
@@ -31,6 +33,13 @@ export function gatherBumpInfo(cwd: string): BumpInfo {
3133
packageGroups: {},
3234
changes: filteredChanges,
3335
modifiedPackages: new Set<string>(),
36+
newPackages: new Set<string>(),
3437
dependents: {},
3538
};
3639
}
40+
41+
export function gatherBumpInfo(options: BeachballOptions): BumpInfo {
42+
const bumpInfo = gatherPreBumpInfo(options.path);
43+
bumpInPlace(bumpInfo, options);
44+
return bumpInfo;
45+
}

packages/beachball/src/bump/performBump.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import fs from 'fs';
44
import { BumpInfo } from '../types/BumpInfo';
55
import { bumpInPlace } from './bumpInPlace';
66
import { BeachballOptions } from '../types/BeachballOptions';
7+
import { getNewPackages } from '../publish/getNewPackages';
78

89
/**
910
* Performs the bump, writes to the file system
@@ -15,8 +16,6 @@ import { BeachballOptions } from '../types/BeachballOptions';
1516
* @param bumpDeps
1617
*/
1718
export function performBump(bumpInfo: BumpInfo, options: BeachballOptions) {
18-
bumpInPlace(bumpInfo, options);
19-
2019
const { modifiedPackages, packageInfos, changes } = bumpInfo;
2120

2221
for (const pkgName of modifiedPackages) {

packages/beachball/src/commands/bump.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ import { performBump } from '../bump/performBump';
33
import { BeachballOptions } from '../types/BeachballOptions';
44

55
export function bump(options: BeachballOptions) {
6-
return performBump(gatherBumpInfo(options.path), options);
6+
return performBump(gatherBumpInfo(options), options);
77
}

packages/beachball/src/commands/publish.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { getPackageChangeTypes } from '../changefile/getPackageChangeTypes';
66
import { readChangeFiles } from '../changefile/readChangeFiles';
77
import { bumpAndPush } from '../publish/bumpAndPush';
88
import { publishToRegistry } from '../publish/publishToRegistry';
9+
import { getNewPackages } from '../publish/getNewPackages';
910
export async function publish(options: BeachballOptions) {
1011
const { path: cwd, branch, registry, tag } = options;
1112
// First, validate that we have changes to publish
@@ -43,7 +44,12 @@ export async function publish(options: BeachballOptions) {
4344
const publishBranch = 'publish_' + String(new Date().getTime());
4445
gitFailFast(['checkout', '-b', publishBranch], { cwd });
4546
console.log('Bumping version for npm publish');
46-
const bumpInfo = gatherBumpInfo(cwd);
47+
const bumpInfo = gatherBumpInfo(options);
48+
49+
if (options.new) {
50+
bumpInfo.newPackages = new Set<string>(getNewPackages(bumpInfo, options.registry));
51+
}
52+
4753
// Step 1. Bump + npm publish
4854
// npm / yarn publish
4955
if (options.publish) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { BumpInfo } from '../types/BumpInfo';
2+
import { listPackageVersions } from '../packageManager/listPackageVersions';
3+
export function getNewPackages(bumpInfo: BumpInfo, registry: string) {
4+
const { modifiedPackages, packageInfos } = bumpInfo;
5+
6+
const newPackages = Object.keys(packageInfos).filter(pkg => !modifiedPackages.has(pkg));
7+
8+
return newPackages.filter(pkg => {
9+
const packageInfo = packageInfos[pkg];
10+
// Ignore private packages or change type "none" packages
11+
if (packageInfo.private) {
12+
return false;
13+
}
14+
15+
const publishedVersions = listPackageVersions(packageInfo.name, registry);
16+
17+
if (publishedVersions.length === 0) {
18+
console.log(`New package detected: ${pkg}`);
19+
return true;
20+
}
21+
});
22+
}

packages/beachball/src/publish/publishToRegistry.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,20 @@ import { BeachballOptions } from '../types/BeachballOptions';
44
import { packagePublish } from '../packageManager/packagePublish';
55
import { validatePackageVersions } from './validatePackageVersions';
66
import { displayManualRecovery } from './displayManualRecovery';
7+
import { getNewPackages } from './getNewPackages';
78
export function publishToRegistry(bumpInfo: BumpInfo, options: BeachballOptions) {
8-
const { path: cwd, registry, tag, token, access } = options;
9+
const { registry, tag, token, access } = options;
10+
const { modifiedPackages, newPackages } = bumpInfo;
11+
912
performBump(bumpInfo, options);
13+
1014
if (!validatePackageVersions(bumpInfo, registry)) {
1115
displayManualRecovery(bumpInfo);
1216
console.error('No packages have been published');
1317
process.exit(1);
1418
}
15-
bumpInfo.modifiedPackages.forEach(pkg => {
19+
20+
[...modifiedPackages, ...newPackages].forEach(pkg => {
1621
const packageInfo = bumpInfo.packageInfos[pkg];
1722
const changeType = bumpInfo.packageChangeTypes[pkg];
1823
if (changeType === 'none') {

0 commit comments

Comments
 (0)