Skip to content

Commit

Permalink
feat: support unstable scope (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
kt3k authored Jul 30, 2024
1 parent 27547da commit 4f7a906
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,19 @@ refactor(*): clean up

The above commit causes `patch` upgrade to the all packages.

## Unstable updates

You can mark the change only affects the unstable part of the package by using
`scope/unstable` or `unstable/scope`.

```
feat(crypto/unstable): a new unstable feature
BREAKING(crypto/unstable): breaking change to unstable feature
```
If this notation is used, the effect of the commit becomes `patch` no matter
what commit type is used.
# License
MIT
16 changes: 15 additions & 1 deletion util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export type VersionUpdateResult = {
};

const RE_DEFAULT_PATTERN = /^([^:()]+)(?:\((.+)\))?: (.*)$/;
const REGEXP_UNSTABLE_SCOPE = /^(unstable\/(.+)|(.+)\/unstable)$/;

// Defines the version bump for each tag.
const TAG_TO_VERSION: Record<string, "major" | "minor" | "patch"> = {
Expand Down Expand Up @@ -153,7 +154,20 @@ export function defaultParseCommitMessage(
reason: `Unknown commit tag: ${tag}.`,
};
}
return modules.map((module) => ({ module, tag, version, commit }));
return modules.map((module) => {
const matchUnstable = REGEXP_UNSTABLE_SCOPE.exec(module);
if (matchUnstable) {
// 'scope' is in the form of unstable/foo or foo/unstable
// In this case all changes are considered as patch
return {
module: matchUnstable[2] || matchUnstable[3],
tag,
commit,
version: "patch",
};
}
return ({ module, tag, version, commit });
});
}

export function summarizeVersionBumpsByModule(
Expand Down
29 changes: 29 additions & 0 deletions util_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,35 @@ Deno.test("defaultParseCommitMessage()", () => {
},
},
]);

assertEquals(parse("feat(foo/unstable): a new unstable feature", modules), [
{
module: "foo",
tag: "feat",
version: "patch",
commit: {
subject: "feat(foo/unstable): a new unstable feature",
body: "",
hash,
},
},
]);

assertEquals(
parse("BREAKING(unstable/foo): break some unstable feature", modules),
[
{
module: "foo",
tag: "BREAKING",
version: "patch",
commit: {
subject: "BREAKING(unstable/foo): break some unstable feature",
body: "",
hash,
},
},
],
);
});

Deno.test("checkModuleName()", () => {
Expand Down

0 comments on commit 4f7a906

Please sign in to comment.