Skip to content

Commit 3dd1c6a

Browse files
authored
fix: Workspaces for update-versions script (#4783)
* Fix workspaces for update-versions script * Add unit test
1 parent 38e4678 commit 3dd1c6a

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

libraries/botbuilder-repo-utils/src/package.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export interface Package {
1111
deprecated?: boolean;
1212
internal?: boolean;
1313

14-
workspaces?: string[];
14+
workspaces?: { packages: string[] };
1515

1616
dependencies?: Record<string, string>;
1717
devDependencies?: Record<string, string>;

libraries/botbuilder-repo-utils/src/updateVersions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export const command = (argv: string[], quiet = false) => async (): Promise<Resu
9595
const commitSha = JSON.parse(flags.git) ? await gitSha('HEAD') : undefined;
9696

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

100100
// Build an object mapping a package name to its new, updated version
101101
const workspaceVersions = workspaces.reduce<Record<string, string>>(

libraries/botbuilder-repo-utils/tests/updateVersions.test.ts

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ describe('updateVersions', function () {
169169
dependsOn?: string[];
170170
}>,
171171
args: string[] = [],
172-
{ commitSha = '' } = {}
172+
{ commitSha = '' } = {},
173173
) => {
174174
const root = 'root';
175175

@@ -200,7 +200,7 @@ describe('updateVersions', function () {
200200
.withArgs(path.join(root, 'package.json'))
201201
.resolves({
202202
version: packageVersion,
203-
workspaces: workspacePaths.map((workspace) => path.posix.join(...workspace.relPath)),
203+
workspaces: { packages: workspacePaths.map((workspace) => path.posix.join(...workspace.relPath)) },
204204
});
205205

206206
sandbox
@@ -219,14 +219,14 @@ describe('updateVersions', function () {
219219
deprecated: workspace.deprecated,
220220
dependencies: (workspace.dependsOn ?? []).reduce(
221221
(acc, name) => ({ ...acc, [name]: dummyVersion }),
222-
{}
222+
{},
223223
),
224224
});
225225

226226
let packageMatch = sinon.match.hasOwn('version', workspace.expectedVersion);
227227
if (workspace.expectedDependencies) {
228228
packageMatch = packageMatch.and(
229-
sinon.match.hasOwn('dependencies', sinon.match(workspace.expectedDependencies))
229+
sinon.match.hasOwn('dependencies', sinon.match(workspace.expectedDependencies)),
230230
);
231231
}
232232

@@ -300,7 +300,7 @@ describe('updateVersions', function () {
300300
},
301301
},
302302
],
303-
[expectedVersion]
303+
[expectedVersion],
304304
);
305305
});
306306

@@ -339,8 +339,37 @@ describe('updateVersions', function () {
339339
},
340340
],
341341
['--buildLabel', 'dev', '--git', 'true', '--date', dateFormat],
342-
{ commitSha: 'COMMIT' }
342+
{ commitSha: 'COMMIT' },
343343
);
344344
});
345+
346+
it('runs properly', async function () {
347+
const writeFileStub = sandbox.stub(file, 'writeJsonFile').returns(Promise.resolve());
348+
const version = '4.24.0';
349+
await command(
350+
[
351+
version,
352+
'--buildLabel',
353+
'dev',
354+
'--internal',
355+
'internal',
356+
'--preview',
357+
'preview',
358+
'--deprecated',
359+
'deprecated',
360+
'--date',
361+
'YYYYMMDD',
362+
'--git',
363+
'false',
364+
],
365+
true,
366+
)();
367+
368+
assert.ok(writeFileStub.called);
369+
const packagesAssertion = (writeFileStub.args as [string, Package][])
370+
.filter(([, pkg]) => !pkg.private)
371+
.every(([, pkg]) => pkg.version.startsWith(version));
372+
assert.ok(packagesAssertion);
373+
});
345374
});
346375
});

0 commit comments

Comments
 (0)