chore(repo): dog-food @websnacksjs/conventional in this repo
This commit is contained in:
parent
5f519f54f2
commit
2867c2f875
6 changed files with 123 additions and 5121 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -35,6 +35,10 @@
|
|||
!/flake.nix
|
||||
!/flake.lock
|
||||
|
||||
### Repository configuration ###
|
||||
!/.husky/commit-msg
|
||||
!/conventional.config.js
|
||||
|
||||
### Workspace configuration ###
|
||||
!/package.json
|
||||
!/package-lock.json
|
||||
|
|
|
|||
1
.husky/commit-msg
Normal file
1
.husky/commit-msg
Normal file
|
|
@ -0,0 +1 @@
|
|||
npx conventional commit-msg "$1"
|
||||
71
conventional.config.js
Normal file
71
conventional.config.js
Normal 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
5151
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -3,9 +3,11 @@
|
|||
"./packages/*"
|
||||
],
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc --build",
|
||||
"clean": "git clean -dxi --exclude .direnv"
|
||||
"clean": "git clean -dxi --exclude .direnv",
|
||||
"prepare": "husky"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "=2.1.3",
|
||||
|
|
@ -13,6 +15,8 @@
|
|||
"@tsconfig/strictest": "^2.0.5",
|
||||
"@types/deno": "^2.3.0",
|
||||
"@types/node": "^24.2.0",
|
||||
"@websnacksjs/conventional": "^0.1.0",
|
||||
"husky": "^9.1.7",
|
||||
"typescript": "^5.9.2"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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": [
|
||||
{
|
||||
"path": "./packages/conventional"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue