Skip to content

Commit

Permalink
fix(config-nx-scopes): restore compatibility with nx 17.2.0 and higher
Browse files Browse the repository at this point in the history
  • Loading branch information
mattlewis92 committed Jan 16, 2024
1 parent fb0b43c commit 8f30dc3
Showing 1 changed file with 24 additions and 29 deletions.
53 changes: 24 additions & 29 deletions @commitlint/config-nx-scopes/index.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,36 @@
const {Workspaces} = require('nx/src/config/workspaces');
const {
getProjects: getNXProjects,
} = require('nx/src/generators/utils/project-configuration');
const {FsTree} = require('nx/src/generators/tree');

module.exports = {
utils: {getProjects},
rules: {
'scope-enum': (ctx) =>
getProjects(ctx).then((packages) => [2, 'always', packages]),
'scope-enum': (ctx) => Promise.resolve([2, 'always', getProjects(ctx)]),
},
};

/**
* @param {(params: Pick<Nx.ProjectConfiguration, 'name' | 'projectType' | 'tags'>) => boolean} selector
*/
function getProjects(context, selector = () => true) {
return Promise.resolve()
.then(() => {
const ctx = context || {};
const cwd = ctx.cwd || process.cwd();
const ws = new Workspaces(cwd);
const workspace = ws.readWorkspaceConfiguration();
return Object.entries(workspace.projects || {}).map(
([name, project]) => ({
name,
...project,
})
);
})
.then((projects) => {
return projects
.filter((project) =>
selector({
name: project.name,
projectType: project.projectType,
tags: project.tags,
})
)
.filter((project) => project.targets)
.map((project) => project.name)
.map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name));
});
const ctx = context || {};
const cwd = ctx.cwd || process.cwd();

const projects = getNXProjects(new FsTree(cwd, false));
return Array.from(projects.entries())
.map(([name, project]) => ({
name,
...project,
}))
.filter((project) =>
selector({
name: project.name,
projectType: project.projectType,
tags: project.tags,
})
)
.filter((project) => project.targets)
.map((project) => project.name)
.map((name) => (name.charAt(0) === '@' ? name.split('/')[1] : name));
}

0 comments on commit 8f30dc3

Please sign in to comment.