Skip to content

Commit 4d80aec

Browse files
committed
add version
1 parent 941d1f8 commit 4d80aec

5 files changed

Lines changed: 40 additions & 29 deletions

File tree

src/__tests__/changefile/getQuestionsForPackage.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ describe('getQuestionsForPackage', () => {
5353
expect(questions![0].choices).toEqual([
5454
{
5555
title:
56-
' [1mPatch[22m - bug fixes; new features; backwards-compatible API changes (ok in patches for v0.x packages)',
56+
' [1mPatch[22m - bug fixes; new features; backwards-compatible API changes (ok in patches for version < 1)',
5757
value: 'patch',
5858
},
5959
{
60-
title: ' [1mMinor[22m - breaking changes; major feature (ok in minor versions for v0.x packages)',
60+
title: ' [1mMinor[22m - breaking changes; major feature (ok in minors for version < 1)',
6161
value: 'minor',
6262
},
6363
{ title: ' None - this change does not affect the published package in any way', value: 'none' },

src/__tests__/changefile/promptForChange.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,15 @@ describe('promptForChange', () => {
8181
await waitForPrompt();
8282

8383
// verify asking for first package
84-
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo');
84+
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo (currently v1.0.0)');
8585
// choose custom options for this package
8686
stdin.emitKey({ name: 'down' });
8787
await stdin.sendByChar('\n');
8888
stdin.emitKey({ name: 'down' });
8989
await stdin.sendByChar('\n');
9090

9191
// verify asking for second package
92-
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: bar');
92+
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: bar (currently v1.0.0)');
9393
// choose defaults
9494
await stdin.sendByChar('\n\n');
9595

@@ -118,11 +118,11 @@ describe('promptForChange', () => {
118118
await waitForPrompt();
119119

120120
// use defaults for first package
121-
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo');
121+
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo (currently v1.0.0)');
122122
await stdin.sendByChar('\n\n');
123123

124124
// cancel for second package
125-
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: bar');
125+
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: bar (currently v1.0.0)');
126126
stdin.emitKey({ name: 'c', ctrl: true });
127127

128128
// nothing is returned
@@ -146,12 +146,12 @@ describe('promptForChange', () => {
146146
await waitForPrompt();
147147

148148
// enter a valid type for foo
149-
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo');
149+
expect(logs.mocks.log).toHaveBeenLastCalledWith('Please describe the changes for: foo (currently v1.0.0)');
150150
expect(stdout.getOutput()).toMatch(/enter any type/);
151151
await stdin.sendByChar('patch\n');
152152

153153
// enter an invalid type for bar
154-
expect(logs.mocks.log).toHaveBeenCalledWith('Please describe the changes for: bar');
154+
expect(logs.mocks.log).toHaveBeenCalledWith('Please describe the changes for: bar (currently v1.0.0)');
155155
await stdin.sendByChar('invalid\n');
156156

157157
expect(await changeFilesPromise).toBeUndefined();

src/__tests__/changefile/promptForChange_promptForPackageChange.test.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ describe('promptForChange _promptForPackageChange', () => {
4141
expect.objectContaining({ name: 'comment', type: 'autocomplete' }),
4242
];
4343

44+
/** Info for the default package used in tests */
45+
const pkgInfo = defaultQuestionsParams.packageInfos[pkg];
46+
4447
/** Wait for the prompt to finish rendering (simulates real user input) */
4548
const waitForPrompt = () => new Promise(resolve => process.nextTick(resolve));
4649

@@ -59,7 +62,7 @@ describe('promptForChange _promptForPackageChange', () => {
5962
});
6063

6164
it('returns an empty object and logs nothing if there are no questions', async () => {
62-
const answers = await _promptForPackageChange([], pkg);
65+
const answers = await _promptForPackageChange([], pkgInfo);
6366
expect(answers).toEqual({});
6467
expect(logs.mocks.log).not.toHaveBeenCalled();
6568
});
@@ -68,13 +71,15 @@ describe('promptForChange _promptForPackageChange', () => {
6871
const questions = getQuestionsForPackage(defaultQuestionsParams);
6972
expect(questions).toEqual(expectedQuestions);
7073

71-
const answersPromise = _promptForPackageChange(questions!, pkg);
74+
const answersPromise = _promptForPackageChange(questions!, pkgInfo);
7275

7376
// input: press enter twice to use defaults (with a pause in between to simulate real user input)
7477
await stdin.sendByChar('\n\n');
7578
const answers = await answersPromise;
7679

77-
expect(logs.getMockLines('log')).toMatchInlineSnapshot(`"Please describe the changes for: foo"`);
80+
expect(logs.getMockLines('log')).toMatchInlineSnapshot(
81+
`"Please describe the changes for: foo (currently v1.0.0)"`
82+
);
7883
expect(stdout.getOutput()).toMatchInlineSnapshot(`
7984
"? Change type » - Use arrow-keys. Return to submit.
8085
> Patch - bug fixes; no API changes
@@ -97,7 +102,7 @@ describe('promptForChange _promptForPackageChange', () => {
97102
});
98103
expect(questions).toEqual(expectedQuestions.slice(1));
99104

100-
const answerPromise = _promptForPackageChange(questions!, pkg);
105+
const answerPromise = _promptForPackageChange(questions!, pkgInfo);
101106
await waitForPrompt();
102107
expect(stdout.lastOutput()).toMatchInlineSnapshot(`
103108
"? Describe changes (type or choose one) »
@@ -110,7 +115,9 @@ describe('promptForChange _promptForPackageChange', () => {
110115
await stdin.sendByChar('abc\n');
111116
const answers = await answerPromise;
112117

113-
expect(logs.getMockLines('log')).toMatchInlineSnapshot(`"Please describe the changes for: foo"`);
118+
expect(logs.getMockLines('log')).toMatchInlineSnapshot(
119+
`"Please describe the changes for: foo (currently v1.0.0)"`
120+
);
114121
expect(stdout.getOutput()).toMatchInlineSnapshot(`
115122
"? Describe changes (type or choose one) » a
116123
? Describe changes (type or choose one) » ab
@@ -128,7 +135,7 @@ describe('promptForChange _promptForPackageChange', () => {
128135
});
129136
expect(questions).toEqual(expectedQuestions.slice(1));
130137

131-
const answerPromise = _promptForPackageChange(questions!, pkg);
138+
const answerPromise = _promptForPackageChange(questions!, pkgInfo);
132139
await waitForPrompt();
133140
expect(stdout.lastOutput()).toMatchInlineSnapshot(`
134141
"? Describe changes (type or choose one) »
@@ -142,7 +149,9 @@ describe('promptForChange _promptForPackageChange', () => {
142149
await stdin.sendByChar('\n');
143150
const answers = await answerPromise;
144151

145-
expect(logs.getMockLines('log')).toMatchInlineSnapshot(`"Please describe the changes for: foo"`);
152+
expect(logs.getMockLines('log')).toMatchInlineSnapshot(
153+
`"Please describe the changes for: foo (currently v1.0.0)"`
154+
);
146155
expect(stdout.getOutput()).toMatchInlineSnapshot(`
147156
"? Describe changes (type or choose one) » abc
148157
√ Describe changes (type or choose one) » abc"
@@ -158,7 +167,7 @@ describe('promptForChange _promptForPackageChange', () => {
158167
});
159168
expect(questions).toEqual(expectedQuestions.slice(1));
160169

161-
const answerPromise = _promptForPackageChange(questions!, pkg);
170+
const answerPromise = _promptForPackageChange(questions!, pkgInfo);
162171
await waitForPrompt();
163172
expect(stdout.lastOutput()).toMatchInlineSnapshot(`
164173
"? Describe changes (type or choose one) »
@@ -171,7 +180,9 @@ describe('promptForChange _promptForPackageChange', () => {
171180
stdin.send('abc\n');
172181
const answers = await answerPromise;
173182

174-
expect(logs.getMockLines('log')).toMatchInlineSnapshot(`"Please describe the changes for: foo"`);
183+
expect(logs.getMockLines('log')).toMatchInlineSnapshot(
184+
`"Please describe the changes for: foo (currently v1.0.0)"`
185+
);
175186
expect(stdout.getOutput()).toMatchInlineSnapshot(`""`);
176187
expect(answers).toEqual({ comment: 'abc' });
177188
});
@@ -181,7 +192,7 @@ describe('promptForChange _promptForPackageChange', () => {
181192
const questions = getQuestionsForPackage({ ...defaultQuestionsParams, recentMessages });
182193
expect(questions).toEqual(expectedQuestions);
183194

184-
const answerPromise = _promptForPackageChange(questions!, pkg);
195+
const answerPromise = _promptForPackageChange(questions!, pkgInfo);
185196

186197
// arrow down to select the third type
187198
stdin.emitKey({ name: 'down' });
@@ -231,7 +242,7 @@ describe('promptForChange _promptForPackageChange', () => {
231242
});
232243
expect(questions).toEqual(expectedQuestions.slice(1));
233244

234-
const answerPromise = _promptForPackageChange(questions!, pkg);
245+
const answerPromise = _promptForPackageChange(questions!, pkgInfo);
235246

236247
// type "ba" and press enter to select "bar"
237248
await stdin.sendByChar('ba\n');
@@ -262,7 +273,7 @@ describe('promptForChange _promptForPackageChange', () => {
262273
});
263274
expect(questions).toEqual(expectedQuestions.slice(1));
264275

265-
const answerPromise = _promptForPackageChange(questions!, pkg);
276+
const answerPromise = _promptForPackageChange(questions!, pkgInfo);
266277

267278
// type "b", press backspace to delete it, press enter to select foo
268279
await stdin.sendByChar('b');
@@ -292,7 +303,7 @@ describe('promptForChange _promptForPackageChange', () => {
292303
const questions = getQuestionsForPackage(defaultQuestionsParams);
293304
expect(questions).toEqual(expectedQuestions);
294305

295-
const answerPromise = _promptForPackageChange(questions!, pkg);
306+
const answerPromise = _promptForPackageChange(questions!, pkgInfo);
296307

297308
// answer the first question
298309
await stdin.sendByChar('\n');
@@ -303,7 +314,7 @@ describe('promptForChange _promptForPackageChange', () => {
303314
const answers = await answerPromise;
304315

305316
expect(logs.getMockLines('log')).toMatchInlineSnapshot(`
306-
"Please describe the changes for: foo
317+
"Please describe the changes for: foo (currently v1.0.0)
307318
Cancelled, no change files are written"
308319
`);
309320

src/changefile/getQuestionsForPackage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ const defaultChangeTypeDescriptions: ChangeTypeDescriptions = {
1010
prerelease: 'bump prerelease version',
1111
patch: {
1212
general: 'bug fixes; no API changes',
13-
v0: 'bug fixes; new features; backwards-compatible API changes (ok in patches for v0.x packages)',
13+
v0: 'bug fixes; new features; backwards-compatible API changes (ok in patches for version < 1)',
1414
},
1515
minor: {
1616
general: 'new feature; backwards-compatible API changes',
17-
v0: 'breaking changes; major feature (ok in minor versions for v0.x packages)',
17+
v0: 'breaking changes; major feature (ok in minors for version < 1)',
1818
},
1919
none: 'this change does not affect the published package in any way',
2020
major: {

src/changefile/promptForChange.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import prompts from 'prompts';
22
import { ChangeFileInfo, ChangeType } from '../types/ChangeInfo';
33
import { BeachballOptions } from '../types/BeachballOptions';
44
import { isValidChangeType } from '../validation/isValidChangeType';
5-
import { PackageGroups, PackageInfos } from '../types/PackageInfo';
5+
import { PackageGroups, PackageInfo, PackageInfos } from '../types/PackageInfo';
66
import { getQuestionsForPackage } from './getQuestionsForPackage';
77

88
type ChangePromptResponse = { type?: ChangeType; comment?: string };
@@ -19,7 +19,7 @@ export async function promptForChange(params: {
1919
email: string | null;
2020
options: Pick<BeachballOptions, 'message' | 'type' | 'dependentChangeType'>;
2121
}): Promise<ChangeFileInfo[] | undefined> {
22-
const { changedPackages, email, options } = params;
22+
const { changedPackages, packageInfos, email, options } = params;
2323
if (!changedPackages.length) {
2424
return;
2525
}
@@ -43,7 +43,7 @@ export async function promptForChange(params: {
4343
// Now prompt for each package
4444
const packageChangeInfo: ChangeFileInfo[] = [];
4545
for (let pkg of changedPackages) {
46-
const response = await _promptForPackageChange(packageQuestions[pkg], pkg);
46+
const response = await _promptForPackageChange(packageQuestions[pkg], packageInfos[pkg]);
4747
if (!response) {
4848
return; // user cancelled
4949
}
@@ -64,7 +64,7 @@ export async function promptForChange(params: {
6464
*/
6565
export async function _promptForPackageChange(
6666
questions: prompts.PromptObject[],
67-
pkg: string
67+
pkg: PackageInfo
6868
): Promise<ChangePromptResponse | undefined> {
6969
if (!questions.length) {
7070
// This MUST return an empty object rather than nothing, because returning nothing means the
@@ -73,7 +73,7 @@ export async function _promptForPackageChange(
7373
}
7474

7575
console.log('');
76-
console.log(`Please describe the changes for: ${pkg}`);
76+
console.log(`Please describe the changes for: ${pkg.name} (currently v${pkg.version})`);
7777

7878
let isCancelled = false;
7979
const onCancel = () => {

0 commit comments

Comments
 (0)