Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
import path from "node:path";

import fg from "fast-glob";
import readYamlFile from "read-yaml-file";
import readYamlFileModule from "read-yaml-file";
import { readExactProjectManifest } from "@pnpm/read-project-manifest";
const readYamlFile = readYamlFileModule.default;

export default {
utils: { getProjects },
rules: {
"scope-enum": (ctx) =>
getProjects(ctx).then((packages) => [2, "always", packages]),
"scope-enum": (ctx = {}) =>
getProjects(ctx).then((packages: any) => [2, "always", packages]),
},
};

function requirePackagesManifest(dir) {
return readYamlFile(path.join(dir, "pnpm-workspace.yaml")).catch((err) => {
if (err.code === "ENOENT") {
return null;
}
function requirePackagesManifest(dir: any) {
return readYamlFile(path.join(dir, "pnpm-workspace.yaml")).catch(
(err: any) => {
if (err.code === "ENOENT") {
return null;
}

throw err;
});
throw err;
},
);
}

function normalizePatterns(patterns) {
function normalizePatterns(patterns: any) {
const normalizedPatterns = [];
for (const pattern of patterns) {
normalizedPatterns.push(pattern.replace(/\/?$/, "/package.json"));
Expand All @@ -32,9 +35,9 @@ function normalizePatterns(patterns) {
return normalizedPatterns;
}

function findWorkspacePackages(cwd) {
function findWorkspacePackages(cwd: any) {
return requirePackagesManifest(cwd)
.then((manifest) => {
.then((manifest: any) => {
const patterns = normalizePatterns(
(manifest && manifest.packages) || ["**"],
);
Expand All @@ -45,27 +48,29 @@ function findWorkspacePackages(cwd) {

return fg(patterns, opts);
})
.then((entries) => {
.then((entries: any) => {
const paths = Array.from(
new Set(entries.map((entry) => path.join(cwd, entry))),
new Set(entries.map((entry: any) => path.join(cwd, entry))),
);

return Promise.all(
paths.map((manifestPath) => readExactProjectManifest(manifestPath)),
paths.map((manifestPath: any) =>
readExactProjectManifest(manifestPath),
),
);
})
.then((manifests) => {
return manifests.map((manifest) => manifest.manifest);
.then((manifests: any) => {
return manifests.map((manifest: any) => manifest.manifest);
});
}

function getProjects(context) {
function getProjects(context: any) {
const ctx = context || {};
const cwd = ctx.cwd || process.cwd();

return findWorkspacePackages(cwd).then((projects) => {
return findWorkspacePackages(cwd).then((projects: any) => {
return projects
.reduce((projects, project) => {
.reduce((projects: any, project: any) => {
const name = project.name;

if (name) {
Expand Down
11 changes: 8 additions & 3 deletions @commitlint/config-pnpm-scopes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
"type": "module",
"version": "19.8.1",
"description": "Shareable commitlint config enforcing pnpm workspaces names as scopes",
"main": "index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"index.js"
"dist"
],
"scripts": {
"build": "tsc",
"test": "jest",
"deps": "dep-check",
"pkg": "pkg-check"
},
Expand Down Expand Up @@ -38,7 +41,9 @@
},
"devDependencies": {
"@commitlint/test": "^19.8.1",
"@commitlint/utils": "^19.8.1"
"@commitlint/utils": "^19.8.1",
"typescript": "^5.2.2",
"@types/node": "^18.19.17"
},
"gitHead": "e82f05a737626bb69979d14564f5ff601997f679"
}
12 changes: 12 additions & 0 deletions @commitlint/config-pnpm-scopes/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
"declaration": true,
"outDir": "dist",
"rootDir": "/",
"strict": true,
"esModuleInterop": true
},
"include": ["/"]
}