-
Notifications
You must be signed in to change notification settings - Fork 906
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(config-nx-scopes): restore compatibility with nx 17.2.0 and higher (
- Loading branch information
1 parent
59b3b31
commit 1e08a17
Showing
1 changed file
with
24 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} |