Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions change/beachball-2020-01-14-20-41-35-fixtag.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "patch",
"comment": "Fixes tagging and also publish brand new packages if not exists",
"packageName": "beachball",
"email": "kchau@microsoft.com",
"commit": "09a7071c0c71193224e203aaa0f51fa2dfc395c4",
"date": "2020-01-15T04:41:35.192Z"
}
5 changes: 4 additions & 1 deletion packages/beachball/src/__tests__/publishGit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ describe('publish command', () => {
registry: 'http://localhost:99999/',
tag: 'latest',
token: '',
new: false,
yes: true,
access: 'public',
package: 'foo',
Expand Down Expand Up @@ -93,7 +94,6 @@ describe('publish command', () => {
gitFailFast(['checkout', '-b', publishBranch], { cwd: repo1.rootPath });

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

const options: BeachballOptions = {
branch: 'origin/master',
Expand All @@ -107,6 +107,7 @@ describe('publish command', () => {
tag: 'latest',
token: '',
yes: true,
new: false,
access: 'public',
package: 'foo',
changehint: 'Run "beachball change" to create a change file',
Expand All @@ -116,6 +117,8 @@ describe('publish command', () => {
defaultNpmTag: 'latest',
};

const bumpInfo = gatherBumpInfo(options);

// 3. Meanwhile, in repo2, also create a new change file
const repo2 = await repositoryFactory.cloneRepository();

Expand Down
3 changes: 3 additions & 0 deletions packages/beachball/src/__tests__/publishRegistry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ describe('publishToRegistry', () => {
tag: 'latest',
token: '',
yes: true,
new: false,
access: 'public',
package: 'foo',
changehint: 'Run "beachball change" to create a change file',
Expand Down Expand Up @@ -131,6 +132,7 @@ describe('publishToRegistry', () => {
tag: 'latest',
token: '',
yes: true,
new: false,
access: 'public',
package: 'foopkg',
changehint: 'Run "beachball change" to create a change file',
Expand Down Expand Up @@ -203,6 +205,7 @@ describe('publishToRegistry', () => {
tag: 'latest',
token: '',
yes: true,
new: false,
access: 'public',
package: 'foopkg',
changehint: 'Run "beachball change" to create a change file',
Expand Down
2 changes: 1 addition & 1 deletion packages/beachball/src/bump/bumpInPlace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { updateRelatedChangeType } from './updateRelatedChangeType';
import { bumpPackageInfoVersion } from './bumpPackageInfoVersion';
import { BeachballOptions } from '../types/BeachballOptions';
import { setGroupsInBumpInfo } from './setGroupsInBumpInfo';
import { gatherBumpInfo } from './gatherBumpInfo';

/**
* Updates BumpInfo according to change types, bump deps, and version groups
*
Expand Down
11 changes: 10 additions & 1 deletion packages/beachball/src/bump/gatherBumpInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { readChangeFiles } from '../changefile/readChangeFiles';
import { getPackageInfos } from '../monorepo/getPackageInfos';
import { ChangeSet } from '../types/ChangeInfo';
import { BumpInfo } from '../types/BumpInfo';
import { bumpInPlace } from './bumpInPlace';
import { BeachballOptions } from '../types/BeachballOptions';

export function gatherBumpInfo(cwd: string): BumpInfo {
function gatherPreBumpInfo(cwd: string): BumpInfo {
// Collate the changes per package
const changes = readChangeFiles(cwd);
const packageChangeTypes = getPackageChangeTypes(changes);
Expand All @@ -31,6 +33,13 @@ export function gatherBumpInfo(cwd: string): BumpInfo {
packageGroups: {},
changes: filteredChanges,
modifiedPackages: new Set<string>(),
newPackages: new Set<string>(),
dependents: {},
};
}

export function gatherBumpInfo(options: BeachballOptions): BumpInfo {
const bumpInfo = gatherPreBumpInfo(options.path);
bumpInPlace(bumpInfo, options);
return bumpInfo;
}
3 changes: 1 addition & 2 deletions packages/beachball/src/bump/performBump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import fs from 'fs';
import { BumpInfo } from '../types/BumpInfo';
import { bumpInPlace } from './bumpInPlace';
import { BeachballOptions } from '../types/BeachballOptions';
import { getNewPackages } from '../publish/getNewPackages';

/**
* Performs the bump, writes to the file system
Expand All @@ -15,8 +16,6 @@ import { BeachballOptions } from '../types/BeachballOptions';
* @param bumpDeps
*/
export function performBump(bumpInfo: BumpInfo, options: BeachballOptions) {
bumpInPlace(bumpInfo, options);

const { modifiedPackages, packageInfos, changes } = bumpInfo;

for (const pkgName of modifiedPackages) {
Expand Down
2 changes: 1 addition & 1 deletion packages/beachball/src/commands/bump.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import { performBump } from '../bump/performBump';
import { BeachballOptions } from '../types/BeachballOptions';

export function bump(options: BeachballOptions) {
return performBump(gatherBumpInfo(options.path), options);
return performBump(gatherBumpInfo(options), options);
}
8 changes: 7 additions & 1 deletion packages/beachball/src/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getPackageChangeTypes } from '../changefile/getPackageChangeTypes';
import { readChangeFiles } from '../changefile/readChangeFiles';
import { bumpAndPush } from '../publish/bumpAndPush';
import { publishToRegistry } from '../publish/publishToRegistry';
import { getNewPackages } from '../publish/getNewPackages';
export async function publish(options: BeachballOptions) {
const { path: cwd, branch, registry, tag } = options;
// First, validate that we have changes to publish
Expand Down Expand Up @@ -43,7 +44,12 @@ export async function publish(options: BeachballOptions) {
const publishBranch = 'publish_' + String(new Date().getTime());
gitFailFast(['checkout', '-b', publishBranch], { cwd });
console.log('Bumping version for npm publish');
const bumpInfo = gatherBumpInfo(cwd);
const bumpInfo = gatherBumpInfo(options);

if (options.new) {
bumpInfo.newPackages = new Set<string>(getNewPackages(bumpInfo, options.registry));
}

// Step 1. Bump + npm publish
// npm / yarn publish
if (options.publish) {
Expand Down
22 changes: 22 additions & 0 deletions packages/beachball/src/publish/getNewPackages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { BumpInfo } from '../types/BumpInfo';
import { listPackageVersions } from '../packageManager/listPackageVersions';
export function getNewPackages(bumpInfo: BumpInfo, registry: string) {
const { modifiedPackages, packageInfos } = bumpInfo;

const newPackages = Object.keys(packageInfos).filter(pkg => !modifiedPackages.has(pkg));

return newPackages.filter(pkg => {
const packageInfo = packageInfos[pkg];
// Ignore private packages or change type "none" packages
if (packageInfo.private) {
return false;
}

const publishedVersions = listPackageVersions(packageInfo.name, registry);

if (publishedVersions.length === 0) {
console.log(`New package detected: ${pkg}`);
return true;
}
});
}
9 changes: 7 additions & 2 deletions packages/beachball/src/publish/publishToRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import { BeachballOptions } from '../types/BeachballOptions';
import { packagePublish } from '../packageManager/packagePublish';
import { validatePackageVersions } from './validatePackageVersions';
import { displayManualRecovery } from './displayManualRecovery';
import { getNewPackages } from './getNewPackages';
export function publishToRegistry(bumpInfo: BumpInfo, options: BeachballOptions) {
const { path: cwd, registry, tag, token, access } = options;
const { registry, tag, token, access } = options;
const { modifiedPackages, newPackages } = bumpInfo;

performBump(bumpInfo, options);

if (!validatePackageVersions(bumpInfo, registry)) {
displayManualRecovery(bumpInfo);
console.error('No packages have been published');
process.exit(1);
}
bumpInfo.modifiedPackages.forEach(pkg => {

[...modifiedPackages, ...newPackages].forEach(pkg => {
const packageInfo = bumpInfo.packageInfos[pkg];
const changeType = bumpInfo.packageChangeTypes[pkg];
if (changeType === 'none') {
Expand Down
4 changes: 3 additions & 1 deletion packages/beachball/src/publish/tagPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ function createTag(tag: string, cwd: string) {
}

export function tagPackages(bumpInfo: BumpInfo, tag: string, cwd: string) {
bumpInfo.modifiedPackages.forEach(pkg => {
const { modifiedPackages, newPackages } = bumpInfo;

[...modifiedPackages, ...newPackages].forEach(pkg => {
const packageInfo = bumpInfo.packageInfos[pkg];
const changeType = bumpInfo.packageChangeTypes[pkg];
// Do not tag change type of "none" or private packages
Expand Down
1 change: 1 addition & 0 deletions packages/beachball/src/publish/validatePackageVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ export function validatePackageVersions(bumpInfo: BumpInfo, registry: string) {
process.stdout.write(' OK!\n');
}
});

return !hasErrors;
}
1 change: 1 addition & 0 deletions packages/beachball/src/types/BeachballOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface CliOptions {
bumpDeps: boolean;
fetch: boolean;
yes: boolean;
new: boolean;
access: 'public' | 'restricted';
package: string;
changehint: string;
Expand Down
2 changes: 1 addition & 1 deletion packages/beachball/src/types/BumpInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ export type BumpInfo = {
packageChangeTypes: { [pkgName: string]: ChangeType };
packageGroups: { [pkgName: string]: string[] };
dependents: { [pkgName: string]: string[] };

modifiedPackages: Set<string>;
newPackages: Set<string>;
};