/
get-mfe-projects.ts
45 lines (41 loc) · 1.29 KB
/
get-mfe-projects.ts
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
42
43
44
45
import type { Tree } from '@nrwl/devkit';
import { tsquery } from '@phenomnomnominal/tsquery';
import { forEachExecutorOptions } from '@nrwl/workspace/src/utilities/executor-options-utils';
export function getMfeProjects(
tree: Tree,
{ legacy }: { legacy: boolean } = { legacy: false }
) {
const NRWL_WEBPACK_BROWSER_BUILDER = '@nrwl/angular:webpack-browser';
const CUSTOM_WEBPACK_OPTION = 'customWebpackConfig';
const MODULE_FEDERATION_IDENTIFIER = legacy
? 'Identifier[name=ModuleFederationPlugin]'
: 'Identifier[name=withModuleFederation]';
const projects: string[] = [];
forEachExecutorOptions(
tree,
NRWL_WEBPACK_BROWSER_BUILDER,
(opts, projectName) => {
const webpackPath = opts[CUSTOM_WEBPACK_OPTION]?.path;
if (!webpackPath || !tree.exists(webpackPath)) {
return;
}
const webpackConfig = tree.read(webpackPath, 'utf-8');
const ast = tsquery.ast(webpackConfig);
const moduleFederationWebpackConfig = tsquery(
ast,
MODULE_FEDERATION_IDENTIFIER,
{
visitAllChildren: true,
}
);
if (
!moduleFederationWebpackConfig ||
moduleFederationWebpackConfig.length === 0
) {
return;
}
projects.push(projectName);
}
);
return projects;
}