Latest Threat Research:SANDWORM_MODE: Shai-Hulud-Style npm Worm Hijacks CI Workflows and Poisons AI Toolchains.Details
Socket
Book a DemoInstallSign in
Socket

@wroud/conventional-commits-parser

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wroud/conventional-commits-parser - npm Package Compare versions

Comparing version
0.2.0
to
0.2.1
+3
src/gitTrailersConventionalCommits.ts
export const gitTrailersConventionalCommits = [
/^(?<token>BREAKING CHANGE):[\s\t]*(?<value>.+)$/,
];
import type { IGitCommitInfo } from "@wroud/git";
export interface IConventionalCommit {
commitInfo: IGitCommitInfo;
type: string;
scope?: string;
description: string;
body?: string;
breakingChanges: string[];
}
export * from "./IConventionalCommit.js";
export * from "./parseConventionalCommit.js";
export * from "./gitTrailersConventionalCommits.js";
import { describe, expect, it } from "vitest";
import { parseConventionalCommit } from "./parseConventionalCommit.js";
import { readFile } from "fs/promises";
import path from "path";
describe("parseConventionalCommit", () => {
it("without", async () => {
const data = await readFile(
path.join(
import.meta.dirname,
"../__testfixtures__/fixture.git-commits.json",
),
"utf8",
);
const commits = JSON.parse(data);
expect(commits.map(parseConventionalCommit)).toMatchSnapshot();
});
it("breaking body", () => {
const commit = {
hash: "abcdef1",
tags: [],
authorName: "Tester",
authorEmail: "tester@example.com",
subject: "feat!: changed API",
body: "This change breaks things\n",
trailers: [],
links: {},
};
expect(parseConventionalCommit(commit)).toMatchSnapshot();
});
});
import type { IGitCommitInfo } from "@wroud/git";
import type { IConventionalCommit } from "./IConventionalCommit.js";
const headerRegex =
/^(?<type>[\w-]+)(\((?<scope>[\w-]+)\))?(?<breaking>!)?:\s(?<description>[\S\s]*)/;
export function parseConventionalCommit(
commitInfo: IGitCommitInfo,
): IConventionalCommit | null {
const match = headerRegex.exec(commitInfo.subject);
if (!match) {
return null;
}
const breakingChanges: string[] = [];
const { type, breaking, scope, description } = match.groups as {
type: string;
breaking?: string;
scope?: string;
description: string;
};
const rawBody = commitInfo.body?.trim() || "";
if (breaking) {
if (rawBody) {
breakingChanges.push(rawBody);
} else {
breakingChanges.push(description);
}
}
for (const trailer of commitInfo.trailers) {
const value = trailer.value.trim();
if (
trailer.token === "BREAKING CHANGE" ||
trailer.token === "BREAKING-CHANGE"
) {
breakingChanges.push(value);
continue;
}
}
const body = rawBody || undefined;
const uniqueBreakingChanges = Array.from(new Set(breakingChanges));
return {
commitInfo,
type: type.toLowerCase(),
scope: scope || undefined,
description,
body,
breakingChanges: uniqueBreakingChanges,
};
}
+10
-0

@@ -6,2 +6,12 @@ <!-- header -->

<!-- version:0.2.1 -->
## 0.2.1 (2025-09-22)
[Compare changes](https://github.com/Wroud/foundation/compare/cc-parser-v0.2.0...cc-parser-v0.2.1)
<!-- changelog -->
### 🩹 Fixes
- publish sources to npm for source maps ([0631b68](https://github.com/Wroud/foundation/commit/0631b68))
<!-- version:0.2.0 -->

@@ -8,0 +18,0 @@ ## 0.2.0 (2025-06-05)

+2
-1
{
"name": "@wroud/conventional-commits-parser",
"description": "A lightweight parser for conventional commits that supports extracting commit metadata, generating commit messages, and managing commit trailers in TypeScript.",
"version": "0.2.0",
"version": "0.2.1",
"type": "module",

@@ -16,2 +16,3 @@ "packageManager": "yarn@4.9.1",

"lib",
"src",
"!lib/**/*.d.ts.map",

@@ -18,0 +19,0 @@ "!lib/**/*.test.js",