Skip to content

Commit 6ae36ea

Browse files
alsmadi99Mohammad Alsmadi
andauthored
feat(config-pnpm-scopes): migrate package to TypeScript (#4541)
Co-authored-by: Mohammad Alsmadi <[email protected]>
1 parent 776908f commit 6ae36ea

File tree

4 files changed

+46
-24
lines changed

4 files changed

+46
-24
lines changed

@commitlint/config-pnpm-scopes/index.js renamed to @commitlint/config-pnpm-scopes/index.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
import path from "node:path";
22

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

78
export default {
89
utils: { getProjects },
910
rules: {
10-
"scope-enum": (ctx) =>
11-
getProjects(ctx).then((packages) => [2, "always", packages]),
11+
"scope-enum": (ctx = {}) =>
12+
getProjects(ctx).then((packages: any) => [2, "always", packages]),
1213
},
1314
};
1415

15-
function requirePackagesManifest(dir) {
16-
return readYamlFile(path.join(dir, "pnpm-workspace.yaml")).catch((err) => {
17-
if (err.code === "ENOENT") {
18-
return null;
19-
}
16+
function requirePackagesManifest(dir: any) {
17+
return readYamlFile(path.join(dir, "pnpm-workspace.yaml")).catch(
18+
(err: any) => {
19+
if (err.code === "ENOENT") {
20+
return null;
21+
}
2022

21-
throw err;
22-
});
23+
throw err;
24+
},
25+
);
2326
}
2427

25-
function normalizePatterns(patterns) {
28+
function normalizePatterns(patterns: any) {
2629
const normalizedPatterns = [];
2730
for (const pattern of patterns) {
2831
normalizedPatterns.push(pattern.replace(/\/?$/, "/package.json"));
@@ -32,9 +35,9 @@ function normalizePatterns(patterns) {
3235
return normalizedPatterns;
3336
}
3437

35-
function findWorkspacePackages(cwd) {
38+
function findWorkspacePackages(cwd: any) {
3639
return requirePackagesManifest(cwd)
37-
.then((manifest) => {
40+
.then((manifest: any) => {
3841
const patterns = normalizePatterns(
3942
(manifest && manifest.packages) || ["**"],
4043
);
@@ -45,27 +48,29 @@ function findWorkspacePackages(cwd) {
4548

4649
return fg(patterns, opts);
4750
})
48-
.then((entries) => {
51+
.then((entries: any) => {
4952
const paths = Array.from(
50-
new Set(entries.map((entry) => path.join(cwd, entry))),
53+
new Set(entries.map((entry: any) => path.join(cwd, entry))),
5154
);
5255

5356
return Promise.all(
54-
paths.map((manifestPath) => readExactProjectManifest(manifestPath)),
57+
paths.map((manifestPath: any) =>
58+
readExactProjectManifest(manifestPath),
59+
),
5560
);
5661
})
57-
.then((manifests) => {
58-
return manifests.map((manifest) => manifest.manifest);
62+
.then((manifests: any) => {
63+
return manifests.map((manifest: any) => manifest.manifest);
5964
});
6065
}
6166

62-
function getProjects(context) {
67+
function getProjects(context: any) {
6368
const ctx = context || {};
6469
const cwd = ctx.cwd || process.cwd();
6570

66-
return findWorkspacePackages(cwd).then((projects) => {
71+
return findWorkspacePackages(cwd).then((projects: any) => {
6772
return projects
68-
.reduce((projects, project) => {
73+
.reduce((projects: any, project: any) => {
6974
const name = project.name;
7075

7176
if (name) {

@commitlint/config-pnpm-scopes/package.json

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
"type": "module",
44
"version": "19.8.1",
55
"description": "Shareable commitlint config enforcing pnpm workspaces names as scopes",
6-
"main": "index.js",
6+
"main": "dist/index.js",
7+
"types": "dist/index.d.ts",
78
"files": [
8-
"index.js"
9+
"dist"
910
],
1011
"scripts": {
12+
"build": "tsc",
13+
"test": "jest",
1114
"deps": "dep-check",
1215
"pkg": "pkg-check"
1316
},
@@ -38,7 +41,9 @@
3841
},
3942
"devDependencies": {
4043
"@commitlint/test": "^19.8.1",
41-
"@commitlint/utils": "^19.8.1"
44+
"@commitlint/utils": "^19.8.1",
45+
"typescript": "^5.2.2",
46+
"@types/node": "^18.19.17"
4247
},
4348
"gitHead": "e82f05a737626bb69979d14564f5ff601997f679"
4449
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"module": "CommonJS",
5+
"declaration": true,
6+
"outDir": "dist",
7+
"rootDir": "/",
8+
"strict": true,
9+
"esModuleInterop": true
10+
},
11+
"include": ["/"]
12+
}

0 commit comments

Comments
 (0)