yarn-version 1.0.0-pre → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,6 +42,7 @@ import {
42
42
  import type { Workspace } from "../utils/packageUtils";
43
43
  import {
44
44
  createProjectWorkspace,
45
+ createWorkspace,
45
46
  findRootWorkspace,
46
47
  writePkg,
47
48
  } from "../utils/packageUtils";
@@ -53,7 +54,7 @@ import {
53
54
  getWorkspaceName,
54
55
  } from "../utils/workspaceUtils";
55
56
 
56
- interface Options {
57
+ export interface VersionCommandOptions {
57
58
  cwd: string;
58
59
  includesRoot: boolean;
59
60
  dryRun: boolean;
@@ -70,6 +71,7 @@ interface Options {
70
71
  gitRemote: string;
71
72
  ignoreChanges?: string;
72
73
  verbose?: boolean;
74
+ cwdIsRoot?: boolean;
73
75
  }
74
76
 
75
77
  interface BumpableWorkspace {
@@ -98,753 +100,787 @@ interface BumpedWorkspace extends ChangedWorkspace, NoVersionToUpdateWorkspace {
98
100
  newTag: string | null;
99
101
  }
100
102
 
101
- export default program
102
- .command("version")
103
- .usage("Bump package version using conventional commit")
104
- .addOption(
105
- new Option("--includes-root", "Release root workspace [untested]").default(
106
- false,
107
- ),
108
- )
109
- .addOption(new Option("--cwd", "working directory").default(process.cwd()))
110
- .addOption(
111
- new Option(
112
- "--dry-run",
113
- "Print the versions without actually generating the package archive",
114
- ).default(false),
115
- )
116
- .addOption(new Option("-v,--verbose").default(false))
117
- .addOption(
118
- new Option("--force <type>", "Specify the release type").choices([
119
- "major",
120
- "minor",
121
- "patch",
122
- ]),
123
- )
124
- .addOption(
125
- new Option(
126
- "--prerelease [releaseType]",
127
- "Add a prerelease identifier to new versions",
128
- ),
129
- )
130
- .addOption(
131
- new Option(
132
- "--preset <presetName>",
133
- "Conventional Changelog preset to require. Defaults to conventional-changelog-conventionalcommits.",
134
- ).default("conventional-changelog-conventionalcommits"),
135
- )
136
- .addOption(
137
- new Option("--tag-version-prefix <prefix>", "Tag version prefix").default(
138
- "v",
139
- ),
140
- )
141
- .addOption(
142
- new Option(
143
- "--changelog <path>",
144
- "Changelog path. Default to CHANGELOG.md.",
145
- ).default("CHANGELOG.md"),
146
- )
147
- .addOption(
148
- new Option(
149
- "-m,--commit-message <message>",
150
- 'Commit message. Default to "chore: release %a". You can use %v for the version, %s for the version with prefix, %t to list tags, %a for auto best display.',
151
- ).default("chore: release %a"),
152
- )
153
- .addOption(
154
- new Option("--create-release <type>", "Create a release").choices([
155
- "github",
156
- ]),
157
- )
158
- .addOption(
159
- new Option(
160
- "--bump-dependents-highest-as <type>",
161
- "Bump dependents highest version as major, minor or patch",
162
- )
163
- .choices(["major", "minor", "patch"])
164
- .default("major"),
165
- )
166
- .addOption(
167
- new Option(
168
- "--always-bump-peer-dependencies",
169
- "Always bump peer dependencies. Default to bumping only if the version doesn't satisfies the peer dependency range.",
170
- ).default(false),
171
- )
172
- .addOption(
173
- new Option(
174
- "--git-remote <remote-name>",
175
- "Git remote to push commits and tags to",
176
- ).default("origin"),
177
- )
178
- .addOption(
179
- new Option(
180
- "--ignore-changes <glob>",
181
- 'Ignore changes in files matching the glob. Example: "**/*.test.js"',
182
- ),
183
- )
184
- .action(async (options: Options) => {
185
- // todo nightingale-cli
186
- if (options.json) {
187
- process.env.NIGHTINGALE_CONSOLE_FORMATTER = "json";
188
- }
103
+ export const versionCommandAction = async (
104
+ options: VersionCommandOptions,
105
+ { nightingaleHandler = new ConsoleHandler(Level.INFO) } = {},
106
+ ): Promise<void> => {
107
+ // todo nightingale-cli
108
+ if (options.json) {
109
+ process.env.NIGHTINGALE_CONSOLE_FORMATTER = "json";
110
+ }
111
+
112
+ addConfig({
113
+ pattern: /^yarn-version/,
114
+ handler: nightingaleHandler,
115
+ });
189
116
 
190
- addConfig({
191
- pattern: /^yarn-version/,
192
- handler: new ConsoleHandler(Level.INFO),
193
- });
117
+ const logger = new Logger("yarn-version");
194
118
 
195
- const logger = new Logger("yarn-version");
119
+ const rootWorkspace = await (options.cwdIsRoot
120
+ ? createWorkspace(options.cwd)
121
+ : findRootWorkspace(options.cwd));
196
122
 
197
- const rootWorkspace = await findRootWorkspace(options.cwd);
198
- if (!rootWorkspace) {
199
- throw new UsageError("Could not find root workspace from this path.");
200
- }
123
+ if (!rootWorkspace) {
124
+ throw new UsageError("Could not find root workspace from this path.");
125
+ }
201
126
 
202
- const project = await createProjectWorkspace(rootWorkspace);
127
+ const project = await createProjectWorkspace(rootWorkspace);
203
128
 
204
- if (!options.dryRun) {
205
- const dirtyFiles = await getDirtyFiles(project.root);
206
- if (dirtyFiles) {
207
- throw new Error(
208
- `Dirty Files:\n${dirtyFiles}\n\nThere are uncommitted changes in the git repository. Please commit or stash them first.`,
129
+ if (!options.dryRun) {
130
+ const dirtyFiles = await getDirtyFiles(project.root);
131
+ if (dirtyFiles) {
132
+ throw new Error(
133
+ `Dirty Files:\n${dirtyFiles}\n\nThere are uncommitted changes in the git repository. Please commit or stash them first.`,
134
+ );
135
+ }
136
+ }
137
+
138
+ const rootWorkspaceChildren = [...project.children.values()];
139
+ let rootNewVersion = "";
140
+ let rootNewTag = "";
141
+ const isMonorepo = rootWorkspaceChildren.length > 0;
142
+ const isMonorepoVersionIndependent = isMonorepo && !rootWorkspace.pkg.version;
143
+ const workspaces =
144
+ !isMonorepo || options.includesRoot
145
+ ? [rootWorkspace, ...rootWorkspaceChildren]
146
+ : rootWorkspaceChildren;
147
+
148
+ if (options.prerelease) {
149
+ throw new UsageError("--prerelease is not supported yet.");
150
+ }
151
+ if (options.ignoreChanges) {
152
+ throw new UsageError("--ignore-changes is not supported yet.");
153
+ }
154
+
155
+ const conventionalGitClient = new ConventionalGitClient(rootWorkspace.cwd);
156
+
157
+ const rootPreviousVersionTagPromise = options.force
158
+ ? null
159
+ : conventionalGitClient.getLastSemverTag({
160
+ prefix: options.tagVersionPrefix,
161
+ skipUnstable: true,
162
+ });
163
+
164
+ const [
165
+ conventionalCommitConfig,
166
+ githubClient,
167
+ parsedRepoUrl,
168
+ gitCurrentBranch,
169
+ ] = await Promise.all([
170
+ loadConventionalCommitConfig(rootWorkspace, options.preset),
171
+ // create client early to fail fast if necessary
172
+ options.createRelease ? createGitHubClient() : undefined,
173
+ options.createRelease ? parseGithubRepoUrl(rootWorkspace) : undefined,
174
+ getGitCurrentBranch(rootWorkspace),
175
+ ]);
176
+
177
+ const buildTagName = (workspace: Workspace, version: string): string =>
178
+ `${
179
+ isMonorepo && workspace !== rootWorkspace
180
+ ? `${getWorkspaceName(workspace)}@`
181
+ : options.tagVersionPrefix
182
+ }${version}`;
183
+
184
+ const changedWorkspaces = new Map<Workspace, ChangedWorkspace>();
185
+ const dependenciesMap = isMonorepo ? buildDependenciesMaps(project) : null;
186
+
187
+ // todo logger.group
188
+ logger.info(
189
+ options.force
190
+ ? "Check all workspaces (force option)"
191
+ : "Finding changed workspaces",
192
+ );
193
+
194
+ // check workspaces and create bumpableWorkspaces
195
+
196
+ const bumpableWorkspaces: BumpableWorkspace[] = [];
197
+ for (const workspace of workspaces) {
198
+ const workspaceName = getWorkspaceName(workspace);
199
+ const isRoot = workspace === rootWorkspace;
200
+ if (isRoot && isMonorepo) continue;
201
+
202
+ const version = workspace.pkg.version;
203
+
204
+ if (!version || version === "0.0.0") {
205
+ if (
206
+ (isRoot || isMonorepoVersionIndependent) &&
207
+ (!isMonorepo || !isMonorepoVersionIndependent)
208
+ ) {
209
+ throw new UsageError(
210
+ 'package.json has no version in its manifest. For the first release, set to "1.0.0-pre" or "0.1.0-pre".',
209
211
  );
210
212
  }
211
- }
212
213
 
213
- const rootWorkspaceChildren = [...project.children.values()];
214
- let rootNewVersion = "";
215
- let rootNewTag = "";
216
- const isMonorepo = rootWorkspaceChildren.length > 0;
217
- const isMonorepoVersionIndependent =
218
- isMonorepo && !rootWorkspace.pkg.version;
219
- const workspaces =
220
- !isMonorepo || options.includesRoot
221
- ? [rootWorkspace, ...rootWorkspaceChildren]
222
- : rootWorkspaceChildren;
223
-
224
- if (options.prerelease) {
225
- throw new UsageError("--prerelease is not supported yet.");
226
- }
227
- if (options.ignoreChanges) {
228
- throw new UsageError("--ignore-changes is not supported yet.");
214
+ logger.info(`${workspaceName}: skipped (no version)`);
215
+ continue;
229
216
  }
230
217
 
231
- const conventionalGitClient = new ConventionalGitClient(rootWorkspace.cwd);
232
-
233
- const rootPreviousVersionTagPromise = options.force
234
- ? null
235
- : conventionalGitClient.getLastSemverTag({
236
- prefix: options.tagVersionPrefix,
237
- skipUnstable: true,
238
- });
218
+ bumpableWorkspaces.push({
219
+ workspace,
220
+ workspaceName,
221
+ isRoot,
222
+ version,
223
+ });
224
+ }
239
225
 
240
- const [
241
- conventionalCommitConfig,
242
- githubClient,
243
- parsedRepoUrl,
244
- gitCurrentBranch,
245
- ] = await Promise.all([
246
- loadConventionalCommitConfig(rootWorkspace, options.preset),
247
- // create client early to fail fast if necessary
248
- options.createRelease ? createGitHubClient() : undefined,
249
- options.createRelease ? parseGithubRepoUrl(rootWorkspace) : undefined,
250
- getGitCurrentBranch(rootWorkspace),
251
- ]);
252
-
253
- const buildTagName = (workspace: Workspace, version: string): string =>
254
- `${
255
- isMonorepo && workspace !== rootWorkspace
256
- ? `${getWorkspaceName(workspace)}@`
257
- : options.tagVersionPrefix
258
- }${version}`;
259
-
260
- const changedWorkspaces = new Map<Workspace, ChangedWorkspace>();
261
- const dependenciesMap = isMonorepo ? buildDependenciesMaps(project) : null;
262
-
263
- // todo logger.group
264
- logger.info("Finding changed workspaces");
265
-
266
- // check workspaces and create bumpableWorkspaces
267
-
268
- const bumpableWorkspaces: BumpableWorkspace[] = [];
269
- for (const workspace of workspaces) {
270
- const workspaceName = getWorkspaceName(workspace);
271
- const isRoot = workspace === rootWorkspace;
272
- if (isRoot && isMonorepo) continue;
226
+ if (bumpableWorkspaces.length > 0) {
227
+ logger.info("Found bumpable workspaces", {
228
+ count: bumpableWorkspaces.length,
229
+ });
230
+ }
273
231
 
274
- const version = workspace.pkg.version;
232
+ const previousTagByWorkspace = new Map<Workspace, string | undefined>(
233
+ await Promise.all(
234
+ bumpableWorkspaces.map(async ({ workspace, workspaceName, isRoot }) => {
235
+ const packageOption =
236
+ isMonorepo && isMonorepoVersionIndependent
237
+ ? workspaceName
238
+ : undefined;
239
+
240
+ const previousVersionTagPrefix = packageOption
241
+ ? `${packageOption}@`
242
+ : options.tagVersionPrefix;
243
+
244
+ const previousTag = await (isRoot || !isMonorepoVersionIndependent
245
+ ? rootPreviousVersionTagPromise
246
+ : conventionalGitClient.getLastSemverTag({
247
+ prefix: previousVersionTagPrefix,
248
+ skipUnstable: true,
249
+ }));
250
+
251
+ return [workspace, previousTag || undefined] as const;
252
+ }),
253
+ ),
254
+ );
275
255
 
276
- if (!version || version === "0.0.0") {
277
- if (
278
- (isRoot || isMonorepoVersionIndependent) &&
279
- (!isMonorepo || !isMonorepoVersionIndependent)
280
- ) {
281
- throw new UsageError(
282
- 'package.json has no version in its manifest. For the first release, set to "1.0.0-pre" or "0.1.0-pre".',
283
- );
284
- }
256
+ const commitsByWorkspace = options.force
257
+ ? undefined
258
+ : new Map(
259
+ await Promise.all(
260
+ bumpableWorkspaces.map(async ({ workspace }) => {
261
+ const previousTag = previousTagByWorkspace.get(workspace);
285
262
 
286
- logger.info(`${workspaceName}: skipped (no version)`);
287
- continue;
288
- }
263
+ const workspaceRelativePath = path.relative(
264
+ rootWorkspace.cwd,
265
+ workspace.cwd,
266
+ );
267
+ return [
268
+ workspace,
269
+ await asyncIterableToArray(
270
+ conventionalGitClient.getCommits(
271
+ { path: workspaceRelativePath, from: previousTag },
272
+ conventionalCommitConfig.parser,
273
+ ),
274
+ ),
275
+ ] as const;
276
+ }),
277
+ ),
278
+ );
289
279
 
290
- bumpableWorkspaces.push({
291
- workspace,
292
- workspaceName,
293
- isRoot,
294
- version,
295
- });
296
- }
280
+ // find changed workspaces
297
281
 
298
- const previousTagByWorkspace = new Map<Workspace, string | undefined>(
299
- await Promise.all(
300
- bumpableWorkspaces.map(async ({ workspace, workspaceName, isRoot }) => {
301
- const packageOption =
302
- isMonorepo && isMonorepoVersionIndependent
303
- ? workspaceName
304
- : undefined;
305
-
306
- const previousVersionTagPrefix = packageOption
307
- ? `${packageOption}@`
308
- : options.tagVersionPrefix;
309
-
310
- const previousTag = await (isRoot || !isMonorepoVersionIndependent
311
- ? rootPreviousVersionTagPromise
312
- : conventionalGitClient.getLastSemverTag({
313
- prefix: previousVersionTagPrefix,
314
- skipUnstable: true,
315
- }));
316
-
317
- return [workspace, previousTag || undefined] as const;
318
- }),
319
- ),
320
- );
282
+ for (const { workspace, workspaceName } of bumpableWorkspaces) {
283
+ let bumpType: BumpType | null = null;
284
+ let bumpReason: string | undefined;
321
285
 
322
- const commitsByWorkspace = options.force
323
- ? undefined
324
- : new Map(
325
- await Promise.all(
326
- bumpableWorkspaces.map(async ({ workspace }) => {
327
- const previousTag = previousTagByWorkspace.get(workspace);
328
-
329
- const workspaceRelativePath = path.relative(
330
- rootWorkspace.cwd,
331
- workspace.cwd,
332
- );
333
- return [
334
- workspace,
335
- await asyncIterableToArray(
336
- conventionalGitClient.getCommits(
337
- { path: workspaceRelativePath, from: previousTag },
338
- conventionalCommitConfig.parser,
339
- ),
340
- ),
341
- ] as const;
342
- }),
343
- ),
344
- );
286
+ if (options.force) {
287
+ bumpType = options.force;
288
+ bumpReason = "forced by --force flag";
289
+ } else {
290
+ const commits = commitsByWorkspace?.get(workspace);
345
291
 
346
- // find changed workspaces
292
+ // No changes found for this package
293
+ if (!commits || commits.length === 0) {
294
+ logger.info(`${workspaceName}: skipped (no changes)`);
295
+ continue;
296
+ }
347
297
 
348
- for (const { workspace, workspaceName } of bumpableWorkspaces) {
349
- if (workspaceName !== "pob") continue; // TODO to remove
298
+ const { releaseType, reason } = await recommendBump(
299
+ commits,
300
+ conventionalCommitConfig,
301
+ );
302
+ bumpReason = reason;
350
303
 
351
- let bumpType: BumpType | null = null;
352
- let bumpReason: string | undefined;
304
+ if (releaseType) {
305
+ bumpType = releaseType as BumpType;
306
+ }
307
+ }
353
308
 
354
- if (options.force) {
355
- bumpType = options.force;
356
- bumpReason = "forced by --force flag";
357
- } else {
358
- const commits = commitsByWorkspace?.get(workspace);
309
+ if (bumpType) {
310
+ if (isMonorepo && !workspace.pkg.name) {
311
+ throw new Error("Workspace name is required");
312
+ }
359
313
 
360
- // No changes found for this package
361
- if (!commits || commits.length === 0) {
362
- logger.info(`${workspaceName}: skipped (no changes)`);
363
- continue;
364
- }
314
+ const currentVersion = workspace.pkg.version;
365
315
 
366
- const { releaseType, reason } = await recommendBump(
367
- commits,
368
- conventionalCommitConfig,
316
+ if (!currentVersion) {
317
+ throw new UsageError(
318
+ `Invalid "${getWorkspaceName(workspace)}" version`,
369
319
  );
370
- bumpReason = reason;
371
-
372
- if (releaseType) {
373
- bumpType = releaseType as BumpType;
374
- }
375
320
  }
376
321
 
377
- if (bumpType) {
378
- if (isMonorepo && !workspace.pkg.name) {
379
- throw new Error("Workspace name is required");
380
- }
381
-
382
- const currentVersion = workspace.pkg.version;
322
+ changedWorkspaces.set(workspace, {
323
+ bumpType,
324
+ bumpReason,
325
+ });
326
+ }
327
+ }
328
+
329
+ if (changedWorkspaces.size === 0) {
330
+ logger.info("No changed workspaces");
331
+ return;
332
+ }
333
+
334
+ logger.info("Preparing bumping");
335
+
336
+ const bumpedWorkspaces = new Map<Workspace, BumpedWorkspace>();
337
+ const noVersionToUpdateWorkspaces = new Map<
338
+ Workspace,
339
+ NoVersionToUpdateWorkspace
340
+ >();
341
+ const batches = dependenciesMap
342
+ ? buildTopologicalOrderBatches(project, dependenciesMap)
343
+ : [[rootWorkspace]];
344
+
345
+ for (const batch of batches) {
346
+ for (const workspace of batch) {
347
+ const currentVersion = workspace.pkg.version;
348
+
349
+ if (!currentVersion && !workspace.pkg.private) {
350
+ throw new UsageError(
351
+ `Invalid "${getWorkspaceName(workspace)}" version`,
352
+ );
353
+ }
383
354
 
384
- if (!currentVersion) {
385
- throw new UsageError(
386
- `Invalid "${getWorkspaceName(workspace)}" version`,
387
- );
388
- }
355
+ const changedWorkspace = changedWorkspaces.get(workspace);
356
+ let bumpType: BumpType | null = null;
357
+ const bumpReasons: string[] = [];
358
+ const dependenciesToBump: BumpedWorkspace["dependenciesToBump"] = [];
389
359
 
390
- changedWorkspaces.set(workspace, {
391
- bumpType,
392
- bumpReason,
393
- });
360
+ if (changedWorkspace) {
361
+ bumpType = changedWorkspace.bumpType;
362
+ bumpReasons.push(changedWorkspace.bumpReason || "by commits");
394
363
  }
395
- }
396
364
 
397
- if (changedWorkspaces.size === 0) {
398
- logger.info("No changed workspaces");
399
- return;
400
- }
365
+ const dependencies = dependenciesMap?.get(workspace);
401
366
 
402
- logger.info("Preparing bumping");
367
+ if (dependencies) {
368
+ for (const [
369
+ dependencyWorkspace,
370
+ dependencyType,
371
+ dependencyDescriptor,
372
+ ] of dependencies) {
373
+ const dependencyBumpedWorkspace =
374
+ bumpedWorkspaces.get(dependencyWorkspace);
403
375
 
404
- const bumpedWorkspaces = new Map<Workspace, BumpedWorkspace>();
405
- const noVersionToUpdateWorkspaces = new Map<
406
- Workspace,
407
- NoVersionToUpdateWorkspace
408
- >();
409
- const batches = dependenciesMap
410
- ? buildTopologicalOrderBatches(project, dependenciesMap)
411
- : [[rootWorkspace]];
376
+ if (!dependencyBumpedWorkspace) {
377
+ continue;
378
+ }
412
379
 
413
- for (const batch of batches) {
414
- for (const workspace of batch) {
415
- const currentVersion = workspace.pkg.version;
380
+ if (
381
+ dependencyType === "peerDependencies" &&
382
+ !options.alwaysBumpPeerDependencies &&
383
+ // skip when peerdependency with a new version satisfied by the existing range.
384
+ satisfies(
385
+ dependencyBumpedWorkspace.newVersion,
386
+ dependencyDescriptor.selector,
387
+ { includePrerelease: true },
388
+ )
389
+ ) {
390
+ continue;
391
+ }
416
392
 
417
- if (!currentVersion && !workspace.pkg.private) {
418
- throw new UsageError(
419
- `Invalid "${getWorkspaceName(workspace)}" version`,
393
+ const newRange = calcBumpRange(
394
+ workspace,
395
+ dependencyDescriptor.selector,
396
+ dependencyBumpedWorkspace.newVersion,
420
397
  );
421
- }
422
-
423
- const changedWorkspace = changedWorkspaces.get(workspace);
424
- let bumpType: BumpType | null = null;
425
- const bumpReasons: string[] = [];
426
- const dependenciesToBump: BumpedWorkspace["dependenciesToBump"] = [];
427
398
 
428
- if (changedWorkspace) {
429
- bumpType = changedWorkspace.bumpType;
430
- bumpReasons.push(changedWorkspace.bumpReason || "by commits");
431
- }
432
-
433
- const dependencies = dependenciesMap?.get(workspace);
399
+ if (dependencyDescriptor.selector === newRange) {
400
+ continue;
401
+ }
434
402
 
435
- if (dependencies) {
436
- for (const [
437
- dependencyWorkspace,
403
+ dependenciesToBump.push([
438
404
  dependencyType,
439
405
  dependencyDescriptor,
440
- ] of dependencies) {
441
- const dependencyBumpedWorkspace =
442
- bumpedWorkspaces.get(dependencyWorkspace);
443
-
444
- if (!dependencyBumpedWorkspace) {
445
- continue;
446
- }
447
-
448
- if (
449
- dependencyType === "peerDependencies" &&
450
- !options.alwaysBumpPeerDependencies &&
451
- // skip when peerdependency with a new version satisfied by the existing range.
452
- satisfies(
453
- dependencyBumpedWorkspace.newVersion,
454
- dependencyDescriptor.selector,
455
- { includePrerelease: true },
456
- )
457
- ) {
458
- continue;
459
- }
460
-
461
- const newRange = calcBumpRange(
462
- workspace,
463
- dependencyDescriptor.selector,
464
- dependencyBumpedWorkspace.newVersion,
465
- );
406
+ newRange,
407
+ ]);
408
+
409
+ bumpType = getHighestBumpType([
410
+ bumpType ?? "patch",
411
+ calcBumpType(
412
+ dependencyBumpedWorkspace.bumpType,
413
+ options.bumpDependentsHighestAs,
414
+ ),
415
+ ]);
416
+
417
+ bumpReasons.push(
418
+ `Version bump for dependency: ${PackageDescriptorNameUtils.stringify(dependencyDescriptor.name)}`,
419
+ );
420
+ }
421
+ }
466
422
 
467
- if (dependencyDescriptor.selector === newRange) {
468
- continue;
469
- }
423
+ const workspaceName = getWorkspaceName(workspace);
424
+ if (!currentVersion) {
425
+ logger.info(`${workspaceName}: skipped (no version)`);
426
+ if (workspace !== rootWorkspace) {
427
+ noVersionToUpdateWorkspaces.set(workspace, {
428
+ dependenciesToBump,
429
+ });
430
+ }
431
+ } else if (!bumpType) {
432
+ logger.info(
433
+ `${workspaceName}: skipped (${
434
+ changedWorkspace
435
+ ? `no bump recommended by ${options.preset}`
436
+ : "no changes"
437
+ })`,
438
+ );
439
+ } else {
440
+ const newVersion = incrementVersion(
441
+ workspace,
442
+ currentVersion,
443
+ bumpType,
444
+ );
470
445
 
471
- dependenciesToBump.push([
472
- dependencyType,
473
- dependencyDescriptor,
474
- newRange,
475
- ]);
476
-
477
- bumpType = getHighestBumpType([
478
- bumpType ?? "patch",
479
- calcBumpType(
480
- dependencyBumpedWorkspace.bumpType,
481
- options.bumpDependentsHighestAs,
482
- ),
483
- ]);
446
+ const tagName = buildTagName(workspace, newVersion);
484
447
 
485
- bumpReasons.push(
486
- `Version bump for dependency: ${PackageDescriptorNameUtils.stringify(dependencyDescriptor.name)}`,
487
- );
488
- }
448
+ if (workspace === rootWorkspace) {
449
+ rootNewVersion = newVersion;
450
+ rootNewTag = tagName;
489
451
  }
490
452
 
491
- const workspaceName = getWorkspaceName(workspace);
492
- if (!currentVersion) {
493
- logger.info(`${workspaceName}: skipped (no version)`);
494
- if (workspace !== rootWorkspace) {
495
- noVersionToUpdateWorkspaces.set(workspace, {
496
- dependenciesToBump,
497
- });
498
- }
499
- } else if (!bumpType) {
500
- logger.info(
501
- `${workspaceName}: skipped (${
502
- changedWorkspace
503
- ? `no bump recommended by ${options.preset}`
504
- : "no changes"
505
- })`,
506
- );
507
- } else {
508
- const newVersion = incrementVersion(
509
- workspace,
453
+ if (workspace !== rootWorkspace || !isMonorepo) {
454
+ const bumpReason = bumpReasons.join("\n");
455
+ bumpedWorkspaces.set(workspace, {
510
456
  currentVersion,
511
457
  bumpType,
512
- );
513
-
514
- const tagName = buildTagName(workspace, newVersion);
515
-
516
- if (workspace === rootWorkspace) {
517
- rootNewVersion = newVersion;
518
- rootNewTag = tagName;
519
- }
520
-
521
- if (workspace !== rootWorkspace || !isMonorepo) {
522
- const bumpReason = bumpReasons.join("\n");
523
- bumpedWorkspaces.set(workspace, {
524
- currentVersion,
525
- bumpType,
526
- bumpReason,
527
- bumpForDependenciesReasons: bumpReasons.slice(1),
528
- newVersion,
529
- newTag: tagName,
530
- hasChanged: changedWorkspace !== undefined,
531
- dependenciesToBump,
532
- });
458
+ bumpReason,
459
+ bumpForDependenciesReasons: changedWorkspace
460
+ ? bumpReasons.slice(1)
461
+ : bumpReasons,
462
+ newVersion,
463
+ newTag: tagName,
464
+ hasChanged: changedWorkspace !== undefined,
465
+ dependenciesToBump,
466
+ });
533
467
 
534
- logger.info(
535
- `${workspaceName}: ${currentVersion} -> ${
536
- !isMonorepo || isMonorepoVersionIndependent
537
- ? newVersion
538
- : "bump"
539
- } (${bumpReason.replace("\n", " ; ")})`,
540
- );
541
- // TODO Json only:
542
- // logger.info({
543
- // cwd: npath.fromPortablePath(workspace.cwd),
544
- // ident: workspaceName,
545
- // oldVersion: currentVersion,
546
- // ...(isMonorepoVersionIndependent ? { newVersion } : {}),
547
- // bumpType,
548
- // bumpReasons,
549
- // });
550
- }
468
+ logger.info(
469
+ `${workspaceName}: ${currentVersion} -> ${
470
+ !isMonorepo || isMonorepoVersionIndependent ? newVersion : "bump"
471
+ } (${bumpReason.replace("\n", " ; ")})`,
472
+ );
473
+ // TODO Json only:
474
+ // logger.info({
475
+ // cwd: npath.fromPortablePath(workspace.cwd),
476
+ // ident: workspaceName,
477
+ // oldVersion: currentVersion,
478
+ // ...(isMonorepoVersionIndependent ? { newVersion } : {}),
479
+ // bumpType,
480
+ // bumpReasons,
481
+ // });
551
482
  }
552
483
  }
553
484
  }
485
+ }
554
486
 
555
- // TODO ask for confirmation
556
- // if (!this.yes) {
557
- // }
487
+ // TODO ask for confirmation
488
+ // if (!this.yes) {
489
+ // }
558
490
 
559
- // TODO do this entire phase here, not override for not independent only
560
- if (isMonorepo && !isMonorepoVersionIndependent) {
561
- const currentVersion = rootWorkspace.pkg.version!;
562
- const highestBumpType = getHighestBumpType(
563
- [...bumpedWorkspaces.values()].map(({ bumpType }) => bumpType),
564
- );
565
- const newVersion = incrementVersion(
566
- rootWorkspace,
567
- currentVersion,
568
- highestBumpType,
569
- );
570
- rootNewVersion = newVersion;
571
- rootNewTag = buildTagName(rootWorkspace, newVersion);
572
-
573
- [...bumpedWorkspaces.entries()].forEach(
574
- ([workspace, bumpedWorkspace]) => {
575
- const isRoot = workspace === rootWorkspace;
576
- if (isRoot) {
577
- throw new Error("Unexpected root found in bumped workspaces");
578
- }
579
- bumpedWorkspace.bumpType = highestBumpType;
580
- bumpedWorkspace.newVersion = newVersion;
581
- bumpedWorkspace.newTag = null;
582
- },
583
- );
491
+ // TODO do this entire phase here, not override for not independent only
492
+ if (isMonorepo && !isMonorepoVersionIndependent) {
493
+ const currentVersion = rootWorkspace.pkg.version!;
494
+ const highestBumpType = getHighestBumpType(
495
+ [...bumpedWorkspaces.values()].map(({ bumpType }) => bumpType),
496
+ );
497
+ const newVersion = incrementVersion(
498
+ rootWorkspace,
499
+ currentVersion,
500
+ highestBumpType,
501
+ );
502
+ rootNewVersion = newVersion;
503
+ rootNewTag = buildTagName(rootWorkspace, newVersion);
584
504
 
585
- [
586
- ...bumpedWorkspaces.entries(),
587
- ...noVersionToUpdateWorkspaces.entries(),
588
- ].forEach(([workspace, { dependenciesToBump }]) => {
589
- dependenciesToBump.forEach((dependencyToBump) => {
590
- dependencyToBump[2] = calcBumpRange(
591
- workspace,
592
- dependencyToBump[1].selector,
593
- newVersion,
594
- );
595
- });
596
- });
505
+ [...bumpedWorkspaces.entries()].forEach(([workspace, bumpedWorkspace]) => {
506
+ const isRoot = workspace === rootWorkspace;
507
+ if (isRoot) {
508
+ throw new Error("Unexpected root found in bumped workspaces");
509
+ }
510
+ bumpedWorkspace.bumpType = highestBumpType;
511
+ bumpedWorkspace.newVersion = newVersion;
512
+ bumpedWorkspace.newTag = null;
513
+ });
597
514
 
598
- bumpedWorkspaces.set(rootWorkspace, {
599
- currentVersion,
600
- bumpType: highestBumpType,
601
- hasChanged: true,
602
- newVersion: rootNewVersion,
603
- newTag: rootNewTag,
604
- dependenciesToBump: [],
515
+ [
516
+ ...bumpedWorkspaces.entries(),
517
+ ...noVersionToUpdateWorkspaces.entries(),
518
+ ].forEach(([workspace, { dependenciesToBump }]) => {
519
+ dependenciesToBump.forEach((dependencyToBump) => {
520
+ dependencyToBump[2] = calcBumpRange(
521
+ workspace,
522
+ dependencyToBump[1].selector,
523
+ newVersion,
524
+ );
605
525
  });
526
+ });
606
527
 
607
- logger.info(
608
- `${currentVersion} -> ${newVersion}`,
609
- // TODO Json only:
610
- // {
611
- // oldVersion: currentVersion,
612
- // newVersion, },
613
- );
614
- }
528
+ bumpedWorkspaces.set(rootWorkspace, {
529
+ currentVersion,
530
+ bumpType: highestBumpType,
531
+ hasChanged: true,
532
+ newVersion: rootNewVersion,
533
+ newTag: rootNewTag,
534
+ dependenciesToBump: [],
535
+ });
615
536
 
616
- // do modifications
537
+ logger.info(
538
+ `${currentVersion} -> ${newVersion}`,
539
+ // TODO Json only:
540
+ // {
541
+ // oldVersion: currentVersion,
542
+ // newVersion, },
543
+ );
544
+ }
617
545
 
618
- // Update yarn.lock ; must be done to make sure preversion script can be ran
619
- logger.info(`${getWorkspaceName(rootWorkspace)}: Running install`);
620
- spawnSync("yarn install", { cwd: options.cwd, stdio: "inherit" });
546
+ // do modifications
621
547
 
622
- logger.info("Lifecycle script: preversion");
548
+ // Update yarn.lock ; must be done to make sure preversion script can be ran
549
+ logger.info(`${getWorkspaceName(rootWorkspace)}: Running install`);
550
+ spawnSync("yarn install", { cwd: options.cwd, stdio: "inherit" });
623
551
 
624
- if (isMonorepoVersionIndependent && rootWorkspace.pkg.scripts?.preversion) {
625
- spawnSync("yarn run preversion", {
626
- cwd: rootWorkspace.cwd,
627
- stdio: "inherit",
628
- });
629
- }
552
+ logger.info("Lifecycle script: preversion");
630
553
 
631
- if (!options.dryRun) {
632
- // lifecycle: preversion
633
- for (const workspace of bumpedWorkspaces.keys()) {
634
- if (workspace.pkg.scripts?.preversion) {
635
- spawnSync("yarn run preversion", {
636
- cwd: workspace.cwd,
637
- stdio: "inherit",
638
- });
639
- }
554
+ if (isMonorepoVersionIndependent && rootWorkspace.pkg.scripts?.preversion) {
555
+ spawnSync("yarn run preversion", {
556
+ cwd: rootWorkspace.cwd,
557
+ stdio: "inherit",
558
+ });
559
+ }
560
+
561
+ if (!options.dryRun) {
562
+ // lifecycle: preversion
563
+ for (const workspace of bumpedWorkspaces.keys()) {
564
+ if (workspace.pkg.scripts?.preversion) {
565
+ spawnSync("yarn run preversion", {
566
+ cwd: workspace.cwd,
567
+ stdio: "inherit",
568
+ });
640
569
  }
570
+ }
641
571
 
642
- logger.info("Modifying versions in package.json");
643
- // update versions
572
+ logger.info("Modifying versions in package.json");
573
+ // update versions
644
574
 
645
- await Promise.all(
646
- [...bumpedWorkspaces.entries()].map(
647
- ([workspace, { newVersion, dependenciesToBump }]) => {
648
- workspace.pkg.version = newVersion;
575
+ await Promise.all(
576
+ [...bumpedWorkspaces.entries()].map(
577
+ ([workspace, { newVersion, dependenciesToBump }]) => {
578
+ workspace.pkg.version = newVersion;
649
579
 
650
- for (const [
651
- dependencyType,
580
+ for (const [
581
+ dependencyType,
582
+ dependencyDescriptor,
583
+ dependencyNewRange,
584
+ ] of dependenciesToBump) {
585
+ const newDescriptor = PackageDependencyDescriptorUtils.make(
652
586
  dependencyDescriptor,
653
587
  dependencyNewRange,
654
- ] of dependenciesToBump) {
655
- const newDescriptor = PackageDependencyDescriptorUtils.make(
656
- dependencyDescriptor,
657
- dependencyNewRange,
658
- );
659
- const [key, newValue] =
660
- PackageDependencyDescriptorUtils.stringify(newDescriptor);
661
- workspace.pkg[dependencyType]![key] = newValue;
662
- }
663
-
664
- return writePkg(workspace);
665
- },
666
- ),
667
- );
588
+ );
589
+ const [key, newValue] =
590
+ PackageDependencyDescriptorUtils.stringify(newDescriptor);
591
+ workspace.pkg[dependencyType]![key] = newValue;
592
+ }
668
593
 
669
- // Update yarn.lock ; must be done before running again lifecycle scripts
670
- logger.info(`${getWorkspaceName(rootWorkspace)}: Running install`);
671
- spawnSync("yarn install", {
672
- cwd: options.cwd,
673
- stdio: "inherit",
674
- });
594
+ return writePkg(workspace);
595
+ },
596
+ ),
597
+ );
675
598
 
676
- // lifecycle: version
677
- logger.info("Lifecycle script: version");
678
- for (const workspace of bumpedWorkspaces.keys()) {
679
- if (workspace.pkg.scripts?.version) {
680
- spawnSync("yarn run version", {
681
- cwd: workspace.cwd,
682
- stdio: "inherit",
683
- });
684
- }
599
+ // Update yarn.lock ; must be done before running again lifecycle scripts
600
+ logger.info(`${getWorkspaceName(rootWorkspace)}: Running install`);
601
+ spawnSync("yarn install", {
602
+ cwd: options.cwd,
603
+ stdio: "inherit",
604
+ });
605
+
606
+ // lifecycle: version
607
+ logger.info("Lifecycle script: version");
608
+ for (const workspace of bumpedWorkspaces.keys()) {
609
+ if (workspace.pkg.scripts?.version) {
610
+ spawnSync("yarn run version", {
611
+ cwd: workspace.cwd,
612
+ stdio: "inherit",
613
+ });
685
614
  }
686
615
  }
616
+ }
687
617
 
688
- if (isMonorepoVersionIndependent && rootWorkspace.pkg.scripts?.version) {
689
- spawnSync("yarn run version", {
690
- cwd: rootWorkspace.cwd,
691
- stdio: "inherit",
692
- });
693
- }
618
+ if (isMonorepoVersionIndependent && rootWorkspace.pkg.scripts?.version) {
619
+ spawnSync("yarn run version", {
620
+ cwd: rootWorkspace.cwd,
621
+ stdio: "inherit",
622
+ });
623
+ }
694
624
 
695
- const changelogs = new Map<Workspace, string>();
625
+ const changelogs = new Map<Workspace, string>();
696
626
 
697
- await Promise.all(
698
- [...bumpedWorkspaces.entries()].map(
699
- async ([
700
- workspace,
701
- { newTag, hasChanged, bumpReason, bumpForDependenciesReasons },
702
- ]) => {
703
- const workspaceRelativePath =
704
- rootWorkspace === workspace
705
- ? undefined
706
- : path.relative(rootWorkspace.cwd, workspace.cwd);
707
-
708
- let changelog = await generateChangelog(
709
- rootWorkspace,
710
- workspace.pkg,
711
- conventionalCommitConfig,
712
- newTag,
713
- {
714
- path: workspaceRelativePath,
715
- previousTag: previousTagByWorkspace.get(workspace),
716
- verbose: options.verbose,
717
- tagPrefix: options.tagVersionPrefix,
718
- lernaPackage:
719
- rootWorkspace === workspace || !isMonorepoVersionIndependent
720
- ? undefined
721
- : getWorkspaceName(workspace),
722
- },
723
- );
627
+ await Promise.all(
628
+ [...bumpedWorkspaces.entries()].map(
629
+ async ([
630
+ workspace,
631
+ { newTag, hasChanged, bumpReason, bumpForDependenciesReasons },
632
+ ]) => {
633
+ const workspaceRelativePath =
634
+ rootWorkspace === workspace
635
+ ? undefined
636
+ : path.relative(rootWorkspace.cwd, workspace.cwd);
637
+
638
+ let changelog = await generateChangelog(
639
+ rootWorkspace,
640
+ workspace.pkg,
641
+ conventionalCommitConfig,
642
+ newTag,
643
+ {
644
+ path: workspaceRelativePath,
645
+ previousTag: previousTagByWorkspace.get(workspace),
646
+ verbose: options.verbose,
647
+ tagPrefix: options.tagVersionPrefix,
648
+ lernaPackage:
649
+ rootWorkspace === workspace || !isMonorepoVersionIndependent
650
+ ? undefined
651
+ : getWorkspaceName(workspace),
652
+ },
653
+ );
724
654
 
725
- if (changelog.slice(changelog.indexOf("\n")).trim().length === 0) {
726
- changelog += "Note: no notable changes\n\n";
655
+ if (bumpForDependenciesReasons && workspace !== rootWorkspace) {
656
+ if (bumpForDependenciesReasons.length > 0) {
657
+ changelog += `${!changelog.endsWith("\n\n") ? "\n" : ""}${bumpForDependenciesReasons.join("\n")}\n\n`;
727
658
  }
659
+ }
728
660
 
729
- if (bumpForDependenciesReasons && workspace !== rootWorkspace) {
730
- changelog += `${bumpForDependenciesReasons.join("\n")}\n\n`;
731
- }
661
+ if (changelog.slice(changelog.indexOf("\n")).trim().length === 0) {
662
+ changelog += `${!changelog.endsWith("\n\n") ? "\n" : ""}Note: no notable changes\n\n`;
663
+ }
664
+
665
+ changelogs.set(workspace, changelog);
732
666
 
733
- changelogs.set(workspace, changelog);
734
-
735
- if (options.changelog) {
736
- if (options.dryRun) {
737
- logger.info(
738
- `${getWorkspaceName(workspace)}: ${
739
- options.changelog
740
- }\n${changelog}`,
741
- );
742
- } else {
743
- await updateChangelogFile(
744
- changelog,
745
- options.tagVersionPrefix,
746
- `${workspace.cwd}/${options.changelog}`,
747
- );
748
- }
667
+ if (options.changelog) {
668
+ if (options.dryRun) {
669
+ logger.info(
670
+ `${getWorkspaceName(workspace)}: ${
671
+ options.changelog
672
+ }\n${changelog}`,
673
+ );
674
+ } else {
675
+ await updateChangelogFile(
676
+ changelog,
677
+ options.tagVersionPrefix,
678
+ `${workspace.cwd}/${options.changelog}`,
679
+ );
749
680
  }
750
- },
751
- ),
752
- );
681
+ }
682
+ },
683
+ ),
684
+ );
753
685
 
754
- if (!options.dryRun) {
755
- // TODO nightingale separator
756
- console.log();
686
+ if (!options.dryRun) {
687
+ // TODO nightingale separator
688
+ console.log();
757
689
 
758
- // install to update versions in lock file
759
- logger.info(`${getWorkspaceName(rootWorkspace)}: Running install`);
760
- spawnSync("yarn install", {
761
- cwd: options.cwd,
762
- stdio: "inherit",
763
- });
690
+ // install to update versions in lock file
691
+ logger.info(`${getWorkspaceName(rootWorkspace)}: Running install`);
692
+ spawnSync("yarn install", {
693
+ cwd: options.cwd,
694
+ stdio: "inherit",
695
+ });
764
696
 
765
- // TODO nightingale separator
766
- console.log();
697
+ // TODO nightingale separator
698
+ console.log();
767
699
 
768
- logger.info("Commit, tag and push");
700
+ logger.info("Commit, tag and push");
769
701
 
770
- const tagsSet = new Set<string>(
771
- [...bumpedWorkspaces.values()]
772
- .map(({ newTag }) => newTag)
773
- .filter((newTag) => newTag !== null) as string[],
774
- );
702
+ const tagsSet = new Set<string>(
703
+ [...bumpedWorkspaces.values()]
704
+ .map(({ newTag }) => newTag)
705
+ .filter((newTag) => newTag !== null) as string[],
706
+ );
775
707
 
776
- const tagsInCommitMessage = [...tagsSet]
777
- .map((tag) => `- ${tag}`)
778
- .join("\n");
779
- const message = options.commitMessage
780
- .replace(/\\n/g, "\n")
781
- .replace(
782
- /%a/g,
783
- isMonorepoVersionIndependent
784
- ? `\n\n${tagsInCommitMessage}`
785
- : rootNewVersion,
786
- )
787
- .replace(/%s/g, rootNewTag)
788
- .replace(/%v/g, rootNewVersion)
789
- .replace(/%t/g, tagsInCommitMessage);
790
- await createGitCommit(rootWorkspace, message);
791
-
792
- for (const [workspace, { newTag }] of bumpedWorkspaces.entries()) {
793
- if (newTag === null) continue;
794
- await createGitTag(workspace, newTag);
795
- }
708
+ const tagsInCommitMessage = [...tagsSet]
709
+ .map((tag) => `- ${tag}`)
710
+ .join("\n");
711
+ const message = options.commitMessage
712
+ .replace(/\\n/g, "\n")
713
+ .replace(
714
+ /%a/g,
715
+ isMonorepoVersionIndependent
716
+ ? `\n\n${tagsInCommitMessage}`
717
+ : rootNewVersion,
718
+ )
719
+ .replace(/%s/g, rootNewTag)
720
+ .replace(/%v/g, rootNewVersion)
721
+ .replace(/%t/g, tagsInCommitMessage);
722
+ await createGitCommit(rootWorkspace, message);
723
+
724
+ for (const [workspace, { newTag }] of bumpedWorkspaces.entries()) {
725
+ if (newTag === null) continue;
726
+ await createGitTag(workspace, newTag);
727
+ }
796
728
 
797
- if (
798
- await isBehindRemote(rootWorkspace, options.gitRemote, gitCurrentBranch)
799
- ) {
800
- logger.error("Remote is ahead, aborting");
801
- // eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
802
- process.exit(1);
803
- }
729
+ if (
730
+ await isBehindRemote(rootWorkspace, options.gitRemote, gitCurrentBranch)
731
+ ) {
732
+ logger.error("Remote is ahead, aborting");
733
+ // eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
734
+ process.exit(1);
735
+ }
804
736
 
805
- // run postversion
806
- if (rootWorkspace.pkg.scripts?.postversion) {
807
- spawnSync("yarn run postversion", {
808
- cwd: rootWorkspace.cwd,
809
- stdio: "inherit",
810
- });
811
- }
737
+ // run postversion
738
+ if (rootWorkspace.pkg.scripts?.postversion) {
739
+ spawnSync("yarn run postversion", {
740
+ cwd: rootWorkspace.cwd,
741
+ stdio: "inherit",
742
+ });
743
+ }
812
744
 
813
- await pushCommitsAndTags(
814
- rootWorkspace,
815
- options.gitRemote,
816
- gitCurrentBranch,
817
- );
745
+ await pushCommitsAndTags(
746
+ rootWorkspace,
747
+ options.gitRemote,
748
+ gitCurrentBranch,
749
+ );
818
750
 
819
- // TODO open github PR
751
+ // TODO open github PR
820
752
 
821
- if (options.createRelease && githubClient && parsedRepoUrl) {
822
- logger.info("Create git release");
753
+ if (options.createRelease && githubClient && parsedRepoUrl) {
754
+ logger.info("Create git release");
823
755
 
824
- await Promise.all(
825
- [...bumpedWorkspaces.entries()].map(([workspace, { newTag }]) => {
826
- if (newTag === null) return undefined;
827
- const changelog = changelogs.get(workspace);
828
- if (!changelog) {
829
- logger.warn(
830
- `No changelog found for workspace: ${getWorkspaceName(
831
- workspace,
832
- )}`,
833
- );
834
- return undefined;
835
- }
836
- return createGitRelease(
837
- githubClient,
838
- parsedRepoUrl,
839
- newTag,
840
- changelog,
841
- !!options.prerelease,
756
+ await Promise.all(
757
+ [...bumpedWorkspaces.entries()].map(([workspace, { newTag }]) => {
758
+ if (newTag === null) return undefined;
759
+ const changelog = changelogs.get(workspace);
760
+ if (!changelog) {
761
+ logger.warn(
762
+ `No changelog found for workspace: ${getWorkspaceName(
763
+ workspace,
764
+ )}`,
842
765
  );
843
- }),
844
- );
845
- }
766
+ return undefined;
767
+ }
768
+ return createGitRelease(
769
+ githubClient,
770
+ parsedRepoUrl,
771
+ newTag,
772
+ changelog,
773
+ !!options.prerelease,
774
+ );
775
+ }),
776
+ );
846
777
  }
778
+ }
847
779
 
780
+ if (process.env.NODE_ENV !== "test") {
781
+ // issue in @conventional-changelog/git-client
848
782
  // eslint-disable-next-line n/no-process-exit, unicorn/no-process-exit
849
783
  process.exit(0);
850
- });
784
+ }
785
+ };
786
+
787
+ export const Defaults: VersionCommandOptions = {
788
+ cwd: process.cwd(),
789
+ includesRoot: false,
790
+ dryRun: false,
791
+ json: false,
792
+ preset: "conventional-changelog-conventionalcommits",
793
+ tagVersionPrefix: "v",
794
+ changelog: "CHANGELOG.md",
795
+ commitMessage: "chore: release %a",
796
+ createRelease: false,
797
+ bumpDependentsHighestAs: "major",
798
+ alwaysBumpPeerDependencies: false,
799
+ gitRemote: "origin",
800
+ verbose: false,
801
+ };
802
+
803
+ export default program
804
+ .command("version")
805
+ .usage("Bump package version using conventional commit")
806
+ .addOption(
807
+ new Option("--includes-root", "Release root workspace [untested]").default(
808
+ Defaults.includesRoot,
809
+ ),
810
+ )
811
+ .addOption(new Option("--cwd", "working directory").default(process.cwd()))
812
+ .addOption(
813
+ new Option(
814
+ "--dry-run",
815
+ "Print the versions without actually generating the package archive",
816
+ ).default(Defaults.dryRun),
817
+ )
818
+ .addOption(new Option("-v,--verbose").default(Defaults.verbose))
819
+ .addOption(
820
+ new Option("--force <type>", "Specify the release type").choices([
821
+ "major",
822
+ "minor",
823
+ "patch",
824
+ ]),
825
+ )
826
+ .addOption(
827
+ new Option(
828
+ "--prerelease [releaseType]",
829
+ "Add a prerelease identifier to new versions",
830
+ ),
831
+ )
832
+ .addOption(
833
+ new Option(
834
+ "--preset <presetName>",
835
+ "Conventional Changelog preset to require. Defaults to conventional-changelog-conventionalcommits.",
836
+ ).default("conventional-changelog-conventionalcommits"),
837
+ )
838
+ .addOption(
839
+ new Option("--tag-version-prefix <prefix>", "Tag version prefix").default(
840
+ Defaults.tagVersionPrefix,
841
+ ),
842
+ )
843
+ .addOption(
844
+ new Option(
845
+ "--changelog <path>",
846
+ "Changelog path. Default to CHANGELOG.md.",
847
+ ).default(Defaults.changelog),
848
+ )
849
+ .addOption(
850
+ new Option(
851
+ "-m,--commit-message <message>",
852
+ 'Commit message. Default to "chore: release %a". You can use %v for the version, %s for the version with prefix, %t to list tags, %a for auto best display.',
853
+ ).default(Defaults.commitMessage),
854
+ )
855
+ .addOption(
856
+ new Option("--create-release <type>", "Create a release").choices([
857
+ "github",
858
+ ]),
859
+ )
860
+ .addOption(
861
+ new Option(
862
+ "--bump-dependents-highest-as <type>",
863
+ "Bump dependents highest version as major, minor or patch",
864
+ )
865
+ .choices(["major", "minor", "patch"])
866
+ .default(Defaults.bumpDependentsHighestAs),
867
+ )
868
+ .addOption(
869
+ new Option(
870
+ "--always-bump-peer-dependencies",
871
+ "Always bump peer dependencies. Default to bumping only if the version doesn't satisfies the peer dependency range.",
872
+ ).default(Defaults.alwaysBumpPeerDependencies),
873
+ )
874
+ .addOption(
875
+ new Option(
876
+ "--git-remote <remote-name>",
877
+ "Git remote to push commits and tags to",
878
+ ).default(Defaults.gitRemote),
879
+ )
880
+ .addOption(
881
+ new Option(
882
+ "--ignore-changes <glob>",
883
+ 'Ignore changes in files matching the glob. Example: "**/*.test.js"',
884
+ ),
885
+ )
886
+ .action((options) => versionCommandAction(options));