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
6 changes: 3 additions & 3 deletions azure-pipelines.release-vnext-nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,15 @@ jobs:
# --only makes it only run tests (otherwise due to the missing --production arg, lage would re-run the build)
# https://github.com/microsoft/fluentui/issues/21686
- script: |
yarn run:published test
yarn lage test --to @fluentui/react-components
displayName: yarn test

- script: |
yarn run:published lint
yarn lage lint --to @fluentui/react-components
displayName: yarn lint

- script: |
yarn run:published build --production
yarn lage build --to @fluentui/react-components
displayName: yarn build

- script: |
Expand Down
58 changes: 58 additions & 0 deletions tools/generators/version-bump/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {

import generator from './index';
import { VersionBumpGeneratorSchema } from './schema';
import { PackageJsonWithBeachball } from '../../types';

const noop = () => null;

Expand Down Expand Up @@ -128,12 +129,67 @@ describe('version-string-replace generator', () => {
projectConfiguration: { tags: ['vNext', 'platform:web'], sourceRoot: 'packages/make-styles/src' },
});

tree = setupDummyPackage(tree, {
name: '@proj/react-button',
version: '9.0.0-alpha.0',
dependencies: {
'@proj/make-styles': '^9.0.0',
},
devDependencies: {
'@proj/make-styles': '^9.0.0',
},
projectConfiguration: { tags: ['vNext', 'platform:web'], sourceRoot: 'packages/react-button/src' },
});

await generator(tree, { name: '@proj/make-styles', bumpType: 'nightly', prereleaseTag: 'nightly' });

const packageJson = readJson(tree, 'packages/react-button/package.json');
expect(packageJson.dependencies).toMatchInlineSnapshot(`
Object {
"@proj/make-styles": "0.0.0-nightly.0",
}
`);
expect(packageJson.devDependencies).toMatchInlineSnapshot(`
Object {
"@proj/make-styles": "0.0.0-nightly.0",
}
`);
});

it('should remove carets for dependents when `nightly` is selected as the bump type', async () => {
tree = setupDummyPackage(tree, {
name: '@proj/make-styles',
version: '^9.0.0',
projectConfiguration: { tags: ['vNext', 'platform:web'], sourceRoot: 'packages/make-styles/src' },
});

await generator(tree, { name: '@proj/make-styles', bumpType: 'nightly', prereleaseTag: 'nightly' });

const packageJson = readJson(tree, 'packages/make-styles/package.json');
expect(packageJson.version).toMatchInlineSnapshot(`"0.0.0-nightly.0"`);
});

it('should remove beachball disallowedChangeType config when bumping nightly', async () => {
tree = setupDummyPackage(tree, {
name: '@proj/make-styles',
version: '9.0.0-alpha.0',
projectConfiguration: { tags: ['vNext', 'platform:web'], sourceRoot: 'packages/make-styles/src' },
beachball: {
disallowedChangeTypes: ['prerelease'],
},
});

expect(
readJson<PackageJsonWithBeachball>(tree, 'packages/make-styles/package.json').beachball?.disallowedChangeTypes,
).toEqual(['prerelease']);

await generator(tree, { name: '@proj/make-styles', bumpType: 'nightly', prereleaseTag: 'nightly' });

const packageJson = readJson<PackageJsonWithBeachball>(tree, 'packages/make-styles/package.json');
expect(packageJson.version).toMatchInlineSnapshot(`"0.0.0-nightly.0"`);
expect(packageJson.beachball?.disallowedChangeTypes).toBeUndefined();
});

describe('--all', () => {
beforeEach(() => {
tree = setupDummyPackage(tree, {
Expand Down Expand Up @@ -252,6 +308,7 @@ function setupDummyPackage(
devDependencies: Record<string, string>;
dependencies: Record<string, string>;
projectConfiguration: Partial<ReturnType<typeof readProjectConfiguration>>;
beachball: PackageJsonWithBeachball['beachball'];
}>,
) {
const workspaceConfig = readWorkspaceConfiguration(tree);
Expand Down Expand Up @@ -279,6 +336,7 @@ function setupDummyPackage(
version: normalizedOptions.version,
dependencies: normalizedOptions.dependencies,
devDependencies: normalizedOptions.devDependencies,
beachball: options.beachball,
},
};

Expand Down
72 changes: 53 additions & 19 deletions tools/generators/version-bump/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Tree, updateJson, getProjects, formatFiles, readJson } from '@nrwl/devkit';
import * as semver from 'semver';
import { VersionBumpGeneratorSchema } from './schema';
import { getProjectConfig, isPackageVersionConverged, printUserLogs, UserLog } from '../../utils';
import {
getProjectConfig,
isPackageVersionConverged,
packageJsonHasBeachballConfig,
printUserLogs,
UserLog,
} from '../../utils';
import { PackageJson } from '../../types';

export default async function (host: Tree, schema: VersionBumpGeneratorSchema) {
Expand Down Expand Up @@ -33,61 +39,89 @@ function runMigrationOnProject(host: Tree, schema: ValidatedSchema, userLog: Use

updateJson(host, packageJsonPath, (packageJson: PackageJson) => {
nextVersion = bumpVersion(packageJson, schema.bumpType, schema.prereleaseTag);

// nightly releases should bypass beachball disallowed changetypes
if (
schema.bumpType === 'nightly' &&
packageJsonHasBeachballConfig(packageJson) &&
packageJson.beachball?.disallowedChangeTypes
) {
packageJson.beachball.disallowedChangeTypes = undefined;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets get rid of it completely

Suggested change
packageJson.beachball.disallowedChangeTypes = undefined;
delete packageJson.beachball.disallowedChangeTypes

}
packageJson.version = nextVersion;

return packageJson;
});

if (nextVersion) {
updatePackageDependents(host, nextVersion, schema.name, userLog);
updatePackageDependents({ host, nextVersion, userLog, schema });
}
}

function updatePackageDependents(host: Tree, nextVersion: string, dependencyName: string, userLog: UserLog) {
function updatePackageDependents(options: {
host: Tree;
nextVersion: string;
userLog: UserLog;
schema: ValidatedSchema;
}) {
const { host, nextVersion, userLog, schema } = options;
const projects = getProjects(host);

projects.forEach((project, projectName) => {
const projectConfig = getProjectConfig(host, { packageName: projectName });
updatePackageDependent(host, nextVersion, dependencyName, projectConfig.paths.packageJson, userLog);
updatePackageDependent({
host,
nextVersion,
dependencyName: schema.name,
packageJsonPath: projectConfig.paths.packageJson,
userLog,
bumpType: schema.bumpType,
});
});
}

function updatePackageDependent(
host: Tree,
nextVersion: string,
dependencyName: string,
packageJsonPath: string,
userLog: UserLog,
) {
function updatePackageDependent(options: {
host: Tree;
nextVersion: string;
dependencyName: string;
packageJsonPath: string;
userLog: UserLog;
bumpType: ValidatedSchema['bumpType'];
}) {
const { host, nextVersion, dependencyName, packageJsonPath, userLog, bumpType } = options;

updateJson(host, packageJsonPath, (packageJson: PackageJson) => {
if (packageJson.dependencies?.[dependencyName]) {
userLog.push({
type: 'info',
message: `bumping dependency ${dependencyName} in ${packageJsonPath}`,
});

bumpDependency(packageJson.dependencies, dependencyName, nextVersion);
bumpDependency({ dependencies: packageJson.dependencies, dependencyName, version: nextVersion, bumpType });
}

if (packageJson.devDependencies?.[dependencyName]) {
userLog.push({
type: 'info',
message: `bumping devDependency ${dependencyName} in ${packageJsonPath}`,
});
bumpDependency(packageJson.devDependencies, dependencyName, nextVersion);
bumpDependency({ dependencies: packageJson.devDependencies, dependencyName, version: nextVersion, bumpType });
}

return packageJson;
});
}

const bumpDependency = (
dependencies: NonNullable<PackageJson['dependencies'] | PackageJson['devDependencies']>,
dependencyName: string,
version: string,
) => {
const bumpDependency = (options: {
dependencies: NonNullable<PackageJson['dependencies'] | PackageJson['devDependencies']>;
dependencyName: string;
version: string;
bumpType: ValidatedSchema['bumpType'];
}) => {
const { dependencies, dependencyName, version, bumpType } = options;

const hasCaret = dependencies[dependencyName].includes('^');
const versionToBump = hasCaret ? `^${version}` : version;
const versionToBump = hasCaret && bumpType !== 'nightly' ? `^${version}` : version;
dependencies[dependencyName] = versionToBump;
};

Expand Down
6 changes: 6 additions & 0 deletions tools/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export interface PackageJson {
exports?: Record<string, string | Partial<{ types: string; import: string; require: string }>>;
}

export interface PackageJsonWithBeachball extends PackageJson {
beachball?: {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: can we extract these tool specific to separate interface and extend PackageJson ? I mean "beachball" is definitely not a standard package.json property

disallowedChangeTypes?: string[];
};
}

// ===============
// Type Utilities
// ===============
Expand Down
12 changes: 9 additions & 3 deletions tools/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ProjectConfiguration,
readJson,
} from '@nrwl/devkit';
import { PackageJson } from './types';
import { PackageJson, PackageJsonWithBeachball } from './types';
import * as semver from 'semver';

/**
Expand Down Expand Up @@ -186,9 +186,11 @@ export function hasSchemaFlag<T, K extends keyof T>(schema: T, flag: K): schema
}

export function isPackageVersionConverged(versionString: string) {
const version = semver.parse(versionString);
const versionWithoutCaret = versionString.replace('^', '');

const version = semver.parse(versionWithoutCaret);
if (version === null) {
throw new Error(`${versionString} is not a valid semver version`);
throw new Error(`${versionWithoutCaret} is not a valid semver version`);
}
return version.major === 9;
}
Expand All @@ -207,3 +209,7 @@ export function isV8Package(tree: Tree, project: ProjectConfiguration) {
const packageJson = readJson<PackageJson>(tree, joinPathFragments(project.root, 'package.json'));
return packageJson.version.startsWith('8.');
}

export function packageJsonHasBeachballConfig(packageJson: PackageJson): packageJson is PackageJsonWithBeachball {
return !!(packageJson as PackageJsonWithBeachball).beachball;
}