From aa8b28f4dffce48af8cecf47337df81c443558e5 Mon Sep 17 00:00:00 2001 From: David Worms Date: Mon, 26 Aug 2024 10:39:13 +0200 Subject: [PATCH] build: custom implementation of commitlint scopes --- commitlint.config.js | 18 +++++++++++++++--- package.json | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/commitlint.config.js b/commitlint.config.js index db40040d..4456273b 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,16 +1,28 @@ -import scopes from "@commitlint/config-lerna-scopes"; +import fs from "node:fs/promises"; +import path from "node:path"; +import { glob } from "glob"; +const pkg = await fs.readFile("./package.json", { encoding: 'utf8'}).then((data) => JSON.parse(data)); + +const packages = await glob( + pkg.workspaces.packages.map((pattern) => `${pattern}/package.json`) +).then((files) => + Promise.all( + files.map((file) => + fs.readFile(file, { encoding: "utf8" }).then((data) => JSON.parse(data)).then( pkg => pkg.name) + ) + ) +); export default { extends: [ "@commitlint/config-conventional", - "@commitlint/config-lerna-scopes", ], rules: { "scope-enum": async (ctx) => [ 2, "always", [ - ...(await scopes.utils.getPackages(ctx)), + ...packages, // Custom scopes "release", ], diff --git a/package.json b/package.json index 89c4aac3..b5010867 100644 --- a/package.json +++ b/package.json @@ -3,8 +3,8 @@ "devDependencies": { "@commitlint/cli": "^19.4.0", "@commitlint/config-conventional": "^19.2.2", - "@commitlint/config-lerna-scopes": "^19.0.0", "cz-conventional-changelog": "^3.3.0", + "glob": "^11.0.0", "husky": "^9.1.5", "lerna": "^8.1.8" },