Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Workspaces for update-versions script #4783

Merged
merged 2 commits into from
Nov 1, 2024
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
2 changes: 1 addition & 1 deletion libraries/botbuilder-repo-utils/src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface Package {
deprecated?: boolean;
internal?: boolean;

workspaces?: string[];
workspaces?: { packages: string[] };

dependencies?: Record<string, string>;
devDependencies?: Record<string, string>;
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-repo-utils/src/updateVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export const command = (argv: string[], quiet = false) => async (): Promise<Resu
const commitSha = JSON.parse(flags.git) ? await gitSha('HEAD') : undefined;

// Collect all workspaces from the repo root. Returns workspaces with absolute paths.
const workspaces = await collectWorkspacePackages(repoRoot, packageFile.workspaces);
const workspaces = await collectWorkspacePackages(repoRoot, packageFile.workspaces?.packages);

// Build an object mapping a package name to its new, updated version
const workspaceVersions = workspaces.reduce<Record<string, string>>(
Expand Down
41 changes: 35 additions & 6 deletions libraries/botbuilder-repo-utils/tests/updateVersions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe('updateVersions', function () {
dependsOn?: string[];
}>,
args: string[] = [],
{ commitSha = '' } = {}
{ commitSha = '' } = {},
) => {
const root = 'root';

Expand Down Expand Up @@ -200,7 +200,7 @@ describe('updateVersions', function () {
.withArgs(path.join(root, 'package.json'))
.resolves({
version: packageVersion,
workspaces: workspacePaths.map((workspace) => path.posix.join(...workspace.relPath)),
workspaces: { packages: workspacePaths.map((workspace) => path.posix.join(...workspace.relPath)) },
});

sandbox
Expand All @@ -219,14 +219,14 @@ describe('updateVersions', function () {
deprecated: workspace.deprecated,
dependencies: (workspace.dependsOn ?? []).reduce(
(acc, name) => ({ ...acc, [name]: dummyVersion }),
{}
{},
),
});

let packageMatch = sinon.match.hasOwn('version', workspace.expectedVersion);
if (workspace.expectedDependencies) {
packageMatch = packageMatch.and(
sinon.match.hasOwn('dependencies', sinon.match(workspace.expectedDependencies))
sinon.match.hasOwn('dependencies', sinon.match(workspace.expectedDependencies)),
);
}

Expand Down Expand Up @@ -300,7 +300,7 @@ describe('updateVersions', function () {
},
},
],
[expectedVersion]
[expectedVersion],
);
});

Expand Down Expand Up @@ -339,8 +339,37 @@ describe('updateVersions', function () {
},
],
['--buildLabel', 'dev', '--git', 'true', '--date', dateFormat],
{ commitSha: 'COMMIT' }
{ commitSha: 'COMMIT' },
);
});

it('runs properly', async function () {
const writeFileStub = sandbox.stub(file, 'writeJsonFile').returns(Promise.resolve());
const version = '4.24.0';
await command(
[
version,
'--buildLabel',
'dev',
'--internal',
'internal',
'--preview',
'preview',
'--deprecated',
'deprecated',
'--date',
'YYYYMMDD',
'--git',
'false',
],
true,
)();

assert.ok(writeFileStub.called);
const packagesAssertion = (writeFileStub.args as [string, Package][])
.filter(([, pkg]) => !pkg.private)
.every(([, pkg]) => pkg.version.startsWith(version));
assert.ok(packagesAssertion);
});
});
});
Loading