Skip to content

Commit 1e08a17

Browse files
authored
fix(config-nx-scopes): restore compatibility with nx 17.2.0 and higher (#3855)
Fixes #3820
1 parent 59b3b31 commit 1e08a17

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

@commitlint/config-nx-scopes/index.js

+24-29
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,36 @@
1-
const {Workspaces} = require('nx/src/config/workspaces');
1+
const {
2+
getProjects: getNXProjects,
3+
} = require('nx/src/generators/utils/project-configuration');
4+
const {FsTree} = require('nx/src/generators/tree');
25

36
module.exports = {
47
utils: {getProjects},
58
rules: {
6-
'scope-enum': (ctx) =>
7-
getProjects(ctx).then((packages) => [2, 'always', packages]),
9+
'scope-enum': (ctx) => Promise.resolve([2, 'always', getProjects(ctx)]),
810
},
911
};
1012

1113
/**
1214
* @param {(params: Pick<Nx.ProjectConfiguration, 'name' | 'projectType' | 'tags'>) => boolean} selector
1315
*/
1416
function getProjects(context, selector = () => true) {
15-
return Promise.resolve()
16-
.then(() => {
17-
const ctx = context || {};
18-
const cwd = ctx.cwd || process.cwd();
19-
const ws = new Workspaces(cwd);
20-
const workspace = ws.readWorkspaceConfiguration();
21-
return Object.entries(workspace.projects || {}).map(
22-
([name, project]) => ({
23-
name,
24-
...project,
25-
})
26-
);
27-
})
28-
.then((projects) => {
29-
return projects
30-
.filter((project) =>
31-
selector({
32-
name: project.name,
33-
projectType: project.projectType,
34-
tags: project.tags,
35-
})
36-
)
37-
.filter((project) => project.targets)
38-
.map((project) => project.name)
39-
.map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name));
40-
});
17+
const ctx = context || {};
18+
const cwd = ctx.cwd || process.cwd();
19+
20+
const projects = getNXProjects(new FsTree(cwd, false));
21+
return Array.from(projects.entries())
22+
.map(([name, project]) => ({
23+
name,
24+
...project,
25+
}))
26+
.filter((project) =>
27+
selector({
28+
name: project.name,
29+
projectType: project.projectType,
30+
tags: project.tags,
31+
})
32+
)
33+
.filter((project) => project.targets)
34+
.map((project) => project.name)
35+
.map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name));
4136
}

0 commit comments

Comments
 (0)