Skip to content

Commit

Permalink
refactor: bump conventional-recommended-bump and remove manual prom…
Browse files Browse the repository at this point in the history
…isify
  • Loading branch information
favna committed Sep 10, 2023
1 parent 65998f0 commit fe1dc29
Show file tree
Hide file tree
Showing 5 changed files with 4,348 additions and 4,078 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,287 @@
diff --git a/index.d.ts b/index.d.ts
index 9c397f71d8ac6f192c1ac4c55c298badc9b9aadf..ae65e4582541ba84748953e55a4062b06532492c 100644
--- a/index.d.ts
+++ b/index.d.ts
@@ -1,4 +1,4 @@
-// Type definitions for conventional-recommended-bump 6.1
+// Type definitions for conventional-recommended-bump 9.0
// Project: https://github.com/conventional-changelog/conventional-changelog/tree/master/packages/conventional-recommended-bump#readme
// Definitions by: Jason Kwok <https://github.com/JasonHK>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -17,7 +17,7 @@ import { Commit, Options as ParserOptions } from "conventional-commits-parser";
* * `whatBump`
* @param callback
*/
-declare function conventionalRecommendedBump(options: Options, callback: Callback): void;
+declare function conventionalRecommendedBump(options: Options): Promise<void>;

/**
* @param options `options` is an object with the following properties:
@@ -30,9 +30,29 @@ declare function conventionalRecommendedBump(options: Options, callback: Callbac
* documentation for available options.
* @param callback
*/
-declare function conventionalRecommendedBump(options: Options, parserOpts: ParserOptions, callback: Callback): void;
+declare function conventionalRecommendedBump(
+ options: Options,
+ parserOpts: ParserOptions
+): Promise<void>;

declare namespace conventionalRecommendedBump {
+ /**
+ * `recommendation` is an `object` with a single property, `releaseType`.
+ *
+ * `releaseType` is a `string`: Possible values: `major`, `minor` and `patch`,
+ * or `undefined` if `whatBump` does not return a valid `level` property, or
+ * the `level` property is not set by `whatBump`.
+ */
+ interface Callback {
+ /**
+ * @param error
+ * @param recommendation `recommendation` is an `object` with a single property,
+ * `releaseType`.
+ */
+ (error: any, recommendation: Callback.Recommendation): void;
+ }
+
+ namespace Callback {
/**
* `recommendation` is an `object` with a single property, `releaseType`.
*
@@ -40,134 +60,117 @@ declare namespace conventionalRecommendedBump {
* or `undefined` if `whatBump` does not return a valid `level` property, or
* the `level` property is not set by `whatBump`.
*/
- interface Callback {
- /**
- * @param error
- * @param recommendation `recommendation` is an `object` with a single property,
- * `releaseType`.
- */
- (error: any, recommendation: Callback.Recommendation): void;
+ interface Recommendation extends Options.WhatBump.Result {
+ /**
+ * `releaseType` is a `string`: Possible values: `major`, `minor` and `patch`,
+ * or `undefined` if `whatBump` does not return a valid `level` property, or
+ * the `level` property is not set by `whatBump`.
+ */
+ releaseType?: Recommendation.ReleaseType | undefined;
}

- namespace Callback {
- /**
- * `recommendation` is an `object` with a single property, `releaseType`.
- *
- * `releaseType` is a `string`: Possible values: `major`, `minor` and `patch`,
- * or `undefined` if `whatBump` does not return a valid `level` property, or
- * the `level` property is not set by `whatBump`.
- */
- interface Recommendation extends Options.WhatBump.Result {
- /**
- * `releaseType` is a `string`: Possible values: `major`, `minor` and `patch`,
- * or `undefined` if `whatBump` does not return a valid `level` property, or
- * the `level` property is not set by `whatBump`.
- */
- releaseType?: Recommendation.ReleaseType | undefined;
- }
-
- namespace Recommendation {
- type ReleaseType = "major" | "minor" | "patch";
- }
+ namespace Recommendation {
+ type ReleaseType = "major" | "minor" | "patch";
}
+ }
+
+ /**
+ * `options` is an object with the following properties:
+ * * `ignoreReverted`
+ * * `preset`
+ * * `config`
+ * * `whatBump`
+ */
+ interface Options {
+ /**
+ * If `true`, reverted commits will be ignored.
+ *
+ * @default
+ * true
+ */
+ ignoreReverted?: boolean | undefined;

/**
- * `options` is an object with the following properties:
- * * `ignoreReverted`
- * * `preset`
- * * `config`
- * * `whatBump`
+ * It's recommended to use a preset so you don't have to define everything
+ * yourself.
+ *
+ * The value is passed to [`conventional-changelog-preset-loader`](https://www.npmjs.com/package/conventional-changelog-preset-loader).
*/
- interface Options {
- /**
- * If `true`, reverted commits will be ignored.
- *
- * @default
- * true
- */
- ignoreReverted?: boolean | undefined;
-
- /**
- * It's recommended to use a preset so you don't have to define everything
- * yourself.
- *
- * The value is passed to [`conventional-changelog-preset-loader`](https://www.npmjs.com/package/conventional-changelog-preset-loader).
- */
- preset?: string | undefined;
-
- /**
- * This should serve as default values for other arguments of
- * `conventional-recommended-bump` so you don't need to rewrite the same or
- * similar config across your projects.
- *
- * @remarks
- * `config` option will be overwritten by the value loaded by
- * `conventional-changelog-preset-loader` if the `preset` options is set.
- */
- config?: CoreOptions.Config<Commit, WriterContext> | undefined;
-
- /**
- * A function that takes parsed commits as an argument.
- *
- * ```
- * whatBump(commits) {};
- * ```
- *
- * `commits` is an array of all commits from last semver tag to `HEAD` as parsed
- * by `conventional-commits-parser`.
- *
- * This should return an object including but not limited to `level` and `reason`.
- * `level` is a `number` indicating what bump it should be and `reason` is the
- * reason of such release.
- */
- whatBump?: Options.WhatBump | undefined;
-
- /**
- * Specify a prefix for the git tag that will be taken into account during the
- * comparison.
- *
- * For instance if your version tag is prefixed by `version/` instead of `v` you
- * would specifying `--tagPrefix=version/` using the CLI, or `version/` as the
- * value of the `tagPrefix` option.
- */
- tagPrefix?: string | undefined;
-
- /**
- * If given, unstable tags (e.g. `x.x.x-alpha.1`, `x.x.x-rc.2`) will be skipped.
- */
- skipUnstable?: boolean | undefined;
-
- /**
- * Specify the name of a package in a [Lerna](https://lernajs.io/)-managed
- * repository. The package name will be used when fetching all changes to a
- * package since the last time that package was released.
- *
- * For instance if your project contained a package named
- * `conventional-changelog`, you could have only commits that have happened
- * since the last release of `conventional-changelog` was tagged by
- * specifying `--lernaPackage=conventional-changelog` using the CLI, or
- * `conventional-changelog` as the value of the `lernaPackage` option.
- */
- lernaPackage?: string | undefined;
-
- /**
- * Specify the path to only calculate with git commits related to the path.
- * If you want to calculate recommended bumps of packages in a Lerna-managed
- * repository, path should be use along with lernaPackage for each of the package.
- */
- path?: string | undefined;
- }
+ preset?: string | undefined;
+
+ /**
+ * This should serve as default values for other arguments of
+ * `conventional-recommended-bump` so you don't need to rewrite the same or
+ * similar config across your projects.
+ *
+ * @remarks
+ * `config` option will be overwritten by the value loaded by
+ * `conventional-changelog-preset-loader` if the `preset` options is set.
+ */
+ config?: CoreOptions.Config<Commit, WriterContext> | undefined;
+
+ /**
+ * A function that takes parsed commits as an argument.
+ *
+ * ```
+ * whatBump(commits) {};
+ * ```
+ *
+ * `commits` is an array of all commits from last semver tag to `HEAD` as parsed
+ * by `conventional-commits-parser`.
+ *
+ * This should return an object including but not limited to `level` and `reason`.
+ * `level` is a `number` indicating what bump it should be and `reason` is the
+ * reason of such release.
+ */
+ whatBump?: Options.WhatBump | undefined;
+
+ /**
+ * Specify a prefix for the git tag that will be taken into account during the
+ * comparison.
+ *
+ * For instance if your version tag is prefixed by `version/` instead of `v` you
+ * would specifying `--tagPrefix=version/` using the CLI, or `version/` as the
+ * value of the `tagPrefix` option.
+ */
+ tagPrefix?: string | undefined;
+
+ /**
+ * If given, unstable tags (e.g. `x.x.x-alpha.1`, `x.x.x-rc.2`) will be skipped.
+ */
+ skipUnstable?: boolean | undefined;
+
+ /**
+ * Specify the name of a package in a [Lerna](https://lernajs.io/)-managed
+ * repository. The package name will be used when fetching all changes to a
+ * package since the last time that package was released.
+ *
+ * For instance if your project contained a package named
+ * `conventional-changelog`, you could have only commits that have happened
+ * since the last release of `conventional-changelog` was tagged by
+ * specifying `--lernaPackage=conventional-changelog` using the CLI, or
+ * `conventional-changelog` as the value of the `lernaPackage` option.
+ */
+ lernaPackage?: string | undefined;
+
+ /**
+ * Specify the path to only calculate with git commits related to the path.
+ * If you want to calculate recommended bumps of packages in a Lerna-managed
+ * repository, path should be use along with lernaPackage for each of the package.
+ */
+ path?: string | undefined;
+ }

- namespace Options {
- type WhatBump = (commits: Commit[]) => WhatBump.Result;
+ namespace Options {
+ type WhatBump = (commits: Commit[]) => WhatBump.Result;

- namespace WhatBump {
- interface Result {
- level?: number | undefined;
- reason?: string | undefined;
- }
- }
+ namespace WhatBump {
+ interface Result {
+ level?: number | undefined;
+ reason?: string | undefined;
+ }
}
+ }
}

type Callback = conventionalRecommendedBump.Callback;
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"colorette": "^2.0.20",
"commander": "^11.0.0",
"compare-func": "^2.0.0",
"conventional-recommended-bump": "^8.0.0",
"conventional-recommended-bump": "^9.0.0",
"git-cliff": "~1.3.0",
"js-yaml": "^4.1.0",
"semver": "^7.5.4"
Expand Down Expand Up @@ -75,7 +75,9 @@
"resolutions": {
"acorn": "^8.10.0",
"ansi-regex": "^5.0.1",
"minimist": "^1.2.8"
"minimist": "^1.2.8",
"@types/conventional-recommended-bump@^6.1.1": "patch:@types/conventional-recommended-bump@npm%3A6.1.1#./.yarn/patches/@types-conventional-recommended-bump-npm-6.1.1-1c00ca9397.patch",
"@types/conventional-recommended-bump@*": "patch:@types/conventional-recommended-bump@npm%3A6.1.1#./.yarn/patches/@types-conventional-recommended-bump-npm-6.1.1-1c00ca9397.patch"
},
"engines": {
"node": ">=v16"
Expand Down
4 changes: 2 additions & 2 deletions src/commands/get-conventional-bump.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { asyncConventionalRecommendBump } from '#lib/constants';
import { getFullPackageName } from '#lib/utils';
import type { Options } from 'commander';
import compareFunc from 'compare-func';
import type { Context } from 'conventional-changelog-writer';
import type { Commit } from 'conventional-commits-parser';
import conventionalRecommendedBump from 'conventional-recommended-bump';
import { readFile } from 'node:fs/promises';

export async function getConventionalBump(options: Options) {
Expand All @@ -14,7 +14,7 @@ export async function getConventionalBump(options: Options) {
readFile(new URL('../../conventional-templates/footer.hbs', import.meta.url), 'utf-8')
]);

return asyncConventionalRecommendBump({
return conventionalRecommendedBump({
config: {
parserOpts: {
headerPattern: /^(\w*)(?:\((.*)\))?: (.*)$/,
Expand Down
8 changes: 0 additions & 8 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
import conventionalRecommendedBump, {
type Callback as ConventionalChangelogCallback,
type Options as ConventionalChangelogOptions
} from 'conventional-recommended-bump';
import { join } from 'node:path';
import { URL } from 'node:url';
import { promisify } from 'node:util';

/** Whether the CLI is being ran in a CI environment */
export const isCi = process.env.CI === 'true';
Expand All @@ -29,6 +24,3 @@ export const cliffJumperRcYamlPath = `${cliffJumperRcPath}.yaml`;

/** 4 spaces indent for logging */
export const indent = ' '.repeat(4);

export const asyncConventionalRecommendBump: (options: ConventionalChangelogOptions) => Promise<ConventionalChangelogCallback.Recommendation> =
promisify(conventionalRecommendedBump);
Loading

0 comments on commit fe1dc29

Please sign in to comment.