chore(repo): dog-food @websnacksjs/conventional in this repo

This commit is contained in:
M. George Hansen 2025-08-19 18:35:47 +12:00
parent 5f519f54f2
commit 2867c2f875
Signed by: mgeorgehansen
SSH key fingerprint: SHA256:JlIGiQLPyQ2RHTH3a2oVlb20Xkh9Glr8DUF4YTXHJxM
6 changed files with 123 additions and 5121 deletions

4
.gitignore vendored
View file

@ -35,6 +35,10 @@
!/flake.nix !/flake.nix
!/flake.lock !/flake.lock
### Repository configuration ###
!/.husky/commit-msg
!/conventional.config.js
### Workspace configuration ### ### Workspace configuration ###
!/package.json !/package.json
!/package-lock.json !/package-lock.json

1
.husky/commit-msg Normal file
View file

@ -0,0 +1 @@
npx conventional commit-msg "$1"

71
conventional.config.js Normal file
View file

@ -0,0 +1,71 @@
import * as fs from "node:fs/promises";
import { defineConfig } from "@websnacksjs/conventional";
/**
* @param {import("@websnacksjs/conventional").CommitMessage} message
* @returns {void}
*/
const validateRepoScopedCommit = (message) => {
const supportedTypes = ["docs", "chore"];
if (!supportedTypes.includes(message.type)) {
throw new Error(
`${JSON.stringify(message.type)} is not a supported repo-scoped commit type ` +
`(must be one of ${JSON.stringify(supportedTypes).replaceAll(",", ", ")})`,
);
}
};
const packagePrefix = "@websnacksjs/";
const packages = await fs.readdir(new URL("./packages", import.meta.url));
/**
* @param {import("@websnacksjs/conventional").CommitMessage} message
* @returns {void}
*/
const validatePackageScopedCommit = (message) => {
const pkg = message.scope?.slice(packagePrefix.length) ?? "";
if (!packages.includes(pkg)) {
throw new Error(
`unknown package ${JSON.stringify(pkg)} referenced in commit scope`,
);
}
const supportedTypes = ["feat", "fix", "docs", "test", "chore"];
if (!supportedTypes.includes(message.type)) {
throw new Error(
`${JSON.stringify(message.type)} is not a supported package-scoped commit type ` +
`(must be one of ${JSON.stringify(supportedTypes).replaceAll(",", ", ")})`,
);
}
};
export default defineConfig({
validateCommitMessage(message) {
if (!message.scope) {
throw new Error(
`missing required scope (use "repo" for monorepo-related commits or "@websnacksjs/:package" for package-specific commits)`,
);
}
if (message.footers.length > 0) {
throw new Error(
`commit message footers are currently unsupported ` +
`(try removing them from your commit message)`,
);
}
if (message.scope === "repo") {
validateRepoScopedCommit(message);
return;
}
if (message.scope.startsWith(packagePrefix)) {
validatePackageScopedCommit(message);
return;
}
throw new Error(
`scope ${JSON.stringify(message.scope)} is unsupported (try one of ["repo", "@websnacksjs/:package"])`,
);
},
});

5151
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -3,9 +3,11 @@
"./packages/*" "./packages/*"
], ],
"private": true, "private": true,
"type": "module",
"scripts": { "scripts": {
"build": "tsc --build", "build": "tsc --build",
"clean": "git clean -dxi --exclude .direnv" "clean": "git clean -dxi --exclude .direnv",
"prepare": "husky"
}, },
"devDependencies": { "devDependencies": {
"@biomejs/biome": "=2.1.3", "@biomejs/biome": "=2.1.3",
@ -13,6 +15,8 @@
"@tsconfig/strictest": "^2.0.5", "@tsconfig/strictest": "^2.0.5",
"@types/deno": "^2.3.0", "@types/deno": "^2.3.0",
"@types/node": "^24.2.0", "@types/node": "^24.2.0",
"@websnacksjs/conventional": "^0.1.0",
"husky": "^9.1.7",
"typescript": "^5.9.2" "typescript": "^5.9.2"
} }
} }

View file

@ -1,5 +1,14 @@
{ {
"files": [], "extends": ["./tsconfig.common.json"],
"compilerOptions": {
"rootDir": ".",
"module": "nodenext",
"moduleResolution": "nodenext",
"allowJs": true,
"noEmit": true,
"checkJs": true
},
"include": ["./*.config.js"],
"references": [ "references": [
{ {
"path": "./packages/conventional" "path": "./packages/conventional"