-
Notifications
You must be signed in to change notification settings - Fork 932
/
Copy pathindex.js
41 lines (34 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import { createRequire } from "node:module";
import Path from "node:path";
import { globSync } from "glob";
const require = createRequire(import.meta.url);
export default {
utils: { getPackages },
rules: {
"scope-enum": (ctx) =>
getPackages(ctx).then((packages) => [2, "always", packages]),
},
};
function getPackages(context) {
return Promise.resolve()
.then(() => {
const ctx = context || {};
const cwd = ctx.cwd || process.cwd();
const { workspaces } = require(Path.join(cwd, "package.json"));
if (!Array.isArray(workspaces)) {
// no workspaces configured, skipping
return [];
}
const wsGlobs = workspaces.flatMap((ws) => {
const path = Path.posix.join(ws, "package.json");
return globSync(path, { cwd, ignore: ["**/node_modules/**"] });
});
return wsGlobs.sort().map((pJson) => require(Path.join(cwd, pJson)));
})
.then((packages) => {
return packages
.map((pkg) => pkg.name)
.filter(Boolean)
.map((name) => (name.charAt(0) === "@" ? name.split("/")[1] : name));
});
}