@commitlint/config-lerna-scopes 19.5.0 → 19.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +74 -55
- package/package.json +8 -11
- package/readme.md +4 -1
package/index.js
CHANGED
|
@@ -1,70 +1,89 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import importFrom from 'import-from';
|
|
6
|
-
import semver from 'semver';
|
|
7
|
-
|
|
8
|
-
const require = createRequire(import.meta.url);
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import fg from "fast-glob";
|
|
4
|
+
import configWorkspaceScopes from "@commitlint/config-workspace-scopes";
|
|
9
5
|
|
|
10
6
|
export default {
|
|
11
|
-
utils: {
|
|
7
|
+
utils: { getProjects },
|
|
12
8
|
rules: {
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
"scope-enum": (ctx) =>
|
|
10
|
+
getProjects(ctx).then((packages) => [2, "always", packages]),
|
|
15
11
|
},
|
|
16
12
|
};
|
|
17
13
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Turn glob paths with potential 'package.json' ending always into paths
|
|
16
|
+
* with a package.json ending to find monorepo packages
|
|
17
|
+
* @param {string[]} patterns
|
|
18
|
+
* @returns A list of glob paths to resolve package.json files
|
|
19
|
+
*/
|
|
20
|
+
function normalizePatterns(patterns) {
|
|
21
|
+
const normalizedPatterns = [];
|
|
22
|
+
for (const pattern of patterns) {
|
|
23
|
+
normalizedPatterns.push(pattern.replace(/\/?$/, "/package.json"));
|
|
24
|
+
}
|
|
25
|
+
return normalizedPatterns;
|
|
26
|
+
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Find all package.json contents in the defined cwd
|
|
30
|
+
* @param {string} cwd
|
|
31
|
+
* @returns A list of parsed package.json files as objects
|
|
32
|
+
*/
|
|
33
|
+
async function findPackages(cwd) {
|
|
34
|
+
const json = await fs.readFile(path.join(cwd, "lerna.json"), {
|
|
35
|
+
encoding: "utf-8",
|
|
36
|
+
});
|
|
32
37
|
|
|
33
|
-
|
|
34
|
-
|
|
38
|
+
const packages = JSON.parse(json)?.packages || [];
|
|
39
|
+
if (packages.length === 0) {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
35
42
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
43
|
+
const patterns = normalizePatterns(packages);
|
|
44
|
+
const entries = await fg(patterns, {
|
|
45
|
+
cwd,
|
|
46
|
+
ignore: ["**/node_modules/**", "**/bower_components/**"],
|
|
47
|
+
});
|
|
40
48
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
49
|
+
const pkgJsons = await Promise.all(
|
|
50
|
+
Array.from(new Set(entries.map((entry) => path.join(cwd, entry)))).map(
|
|
51
|
+
(pkgPath) => fs.readFile(pkgPath, { encoding: "utf-8" }),
|
|
52
|
+
),
|
|
53
|
+
);
|
|
47
54
|
|
|
48
|
-
|
|
49
|
-
return getPackages(cwd);
|
|
50
|
-
})
|
|
51
|
-
.then((packages) => {
|
|
52
|
-
return packages
|
|
53
|
-
.map((pkg) => pkg.name)
|
|
54
|
-
.filter(Boolean)
|
|
55
|
-
.map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name));
|
|
56
|
-
});
|
|
55
|
+
return pkgJsons.map((pkgJson) => JSON.parse(pkgJson) || {});
|
|
57
56
|
}
|
|
58
57
|
|
|
59
|
-
function
|
|
60
|
-
const
|
|
61
|
-
|
|
58
|
+
async function getProjects(context) {
|
|
59
|
+
const ctx = context || {};
|
|
60
|
+
const cwd = ctx.cwd || process.cwd();
|
|
61
|
+
|
|
62
|
+
// try to read workspaces for backwards compatibility
|
|
63
|
+
const workspacePackages = await configWorkspaceScopes.utils.getPackages({
|
|
64
|
+
cwd,
|
|
62
65
|
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
// native npm/yarn workspaces detected, inform user to use new package instead
|
|
67
|
+
if (workspacePackages.length > 0) {
|
|
68
|
+
console.warn(
|
|
69
|
+
[
|
|
70
|
+
`It seems that you are using npm/yarn workspaces instead of lernas "packages" declaration.`,
|
|
71
|
+
`Support for workspaces will be removed in a future major version of this package.`,
|
|
72
|
+
`Please make sure to transition to "@commitlint/config-workspace-scopes" in the near future.`,
|
|
73
|
+
].join("\n"),
|
|
74
|
+
);
|
|
75
|
+
return workspacePackages;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const packages = await findPackages(cwd);
|
|
79
|
+
|
|
80
|
+
return packages
|
|
81
|
+
.reduce((pkgNames, pkg) => {
|
|
82
|
+
const name = pkg.name;
|
|
83
|
+
if (name) {
|
|
84
|
+
pkgNames.push(name.charAt(0) === "@" ? name.split("/")[1] : name);
|
|
85
|
+
}
|
|
86
|
+
return pkgNames;
|
|
87
|
+
}, [])
|
|
88
|
+
.sort();
|
|
70
89
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commitlint/config-lerna-scopes",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "19.
|
|
4
|
+
"version": "19.8.1",
|
|
5
5
|
"description": "Shareable commitlint config enforcing lerna package and workspace names as scopes",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"files": [
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
"commitlint-config",
|
|
23
23
|
"lerna"
|
|
24
24
|
],
|
|
25
|
-
"author": "
|
|
25
|
+
"author": "Jan Biasi (https://github.com/janbiasi)",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"bugs": {
|
|
28
28
|
"url": "https://github.com/conventional-changelog/commitlint/issues"
|
|
29
29
|
},
|
|
30
30
|
"homepage": "https://commitlint.js.org/",
|
|
31
31
|
"peerDependencies": {
|
|
32
|
-
"lerna": "
|
|
32
|
+
"lerna": "*"
|
|
33
33
|
},
|
|
34
34
|
"peerDependenciesMeta": {
|
|
35
35
|
"lerna": {
|
|
@@ -40,15 +40,12 @@
|
|
|
40
40
|
"node": ">=v18"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@
|
|
44
|
-
"glob": "^
|
|
45
|
-
"import-from": "^4.0.0",
|
|
46
|
-
"semver": "^7.6.0"
|
|
43
|
+
"@commitlint/config-workspace-scopes": "^19.8.1",
|
|
44
|
+
"fast-glob": "^3.3.3"
|
|
47
45
|
},
|
|
48
46
|
"devDependencies": {
|
|
49
|
-
"@commitlint/test": "^19.
|
|
50
|
-
"@commitlint/utils": "^19.
|
|
51
|
-
"@types/glob": "^8.1.0"
|
|
47
|
+
"@commitlint/test": "^19.8.1",
|
|
48
|
+
"@commitlint/utils": "^19.8.1"
|
|
52
49
|
},
|
|
53
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "3c302008cabeb0b08cd246b2417a51a9d745a918"
|
|
54
51
|
}
|
package/readme.md
CHANGED
|
@@ -2,9 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Lint your lerna project commits
|
|
4
4
|
|
|
5
|
-
Shareable `commitlint` config enforcing lerna package
|
|
5
|
+
Shareable `commitlint` config enforcing lerna package scopes.
|
|
6
6
|
Use with [@commitlint/cli](../cli) and [@commitlint/prompt-cli](../prompt-cli).
|
|
7
7
|
|
|
8
|
+
> [!IMPORTANT]
|
|
9
|
+
> If you are using NPM or Yarn workspaces, please use the [@commitlint/config-workspace-scopes](../config-workspace-scopes/) package instead. Support for workspaces will be removed from this package in a future major version.
|
|
10
|
+
|
|
8
11
|
## Getting started
|
|
9
12
|
|
|
10
13
|
```sh
|