diff --git a/@commitlint/config-pnpm-scopes/index.test.js b/@commitlint/config-pnpm-scopes/index.test.ts similarity index 100% rename from @commitlint/config-pnpm-scopes/index.test.js rename to @commitlint/config-pnpm-scopes/index.test.ts diff --git a/@commitlint/config-pnpm-scopes/index.js b/@commitlint/config-pnpm-scopes/index.ts similarity index 57% rename from @commitlint/config-pnpm-scopes/index.js rename to @commitlint/config-pnpm-scopes/index.ts index eb93cce86e..57283cc30a 100644 --- a/@commitlint/config-pnpm-scopes/index.js +++ b/@commitlint/config-pnpm-scopes/index.ts @@ -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")); @@ -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) || ["**"], ); @@ -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) { diff --git a/@commitlint/config-pnpm-scopes/package.json b/@commitlint/config-pnpm-scopes/package.json index af47383145..9b405b4dc2 100644 --- a/@commitlint/config-pnpm-scopes/package.json +++ b/@commitlint/config-pnpm-scopes/package.json @@ -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" }, @@ -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" } diff --git a/@commitlint/config-pnpm-scopes/tsconfig.json b/@commitlint/config-pnpm-scopes/tsconfig.json new file mode 100644 index 0000000000..965e6a1469 --- /dev/null +++ b/@commitlint/config-pnpm-scopes/tsconfig.json @@ -0,0 +1,12 @@ +{ + "compilerOptions": { + "target": "ES2020", + "module": "CommonJS", + "declaration": true, + "outDir": "dist", + "rootDir": "/", + "strict": true, + "esModuleInterop": true + }, + "include": ["/"] +}