|
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'); |
2 | 5 |
|
3 | 6 | module.exports = {
|
4 | 7 | utils: {getProjects},
|
5 | 8 | rules: {
|
6 |
| - 'scope-enum': (ctx) => |
7 |
| - getProjects(ctx).then((packages) => [2, 'always', packages]), |
| 9 | + 'scope-enum': (ctx) => Promise.resolve([2, 'always', getProjects(ctx)]), |
8 | 10 | },
|
9 | 11 | };
|
10 | 12 |
|
11 | 13 | /**
|
12 | 14 | * @param {(params: Pick<Nx.ProjectConfiguration, 'name' | 'projectType' | 'tags'>) => boolean} selector
|
13 | 15 | */
|
14 | 16 | 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)); |
41 | 36 | }
|
0 commit comments