Skip to content

Commit

Permalink
fix(angular): handle projects without name in angular cli adapter (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez authored Feb 17, 2023
1 parent a1a1cda commit 2011e29
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions packages/nx/src/adapter/ngcli-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,25 +226,30 @@ export class NxScopedHost extends virtualFs.ScopedHost<any> {
concatMap((arg) => {
const graph = arg[0] as any;
const ret = (arg[1] || { projects: {} }) as any;
const projectJsonReads = [] as Observable<any>[];
const projectJsonReads: Observable<
[string, ProjectConfiguration & { version: string }]
>[] = [];
for (let projectName of Object.keys(graph.nodes)) {
if (!ret.projects[projectName]) {
projectJsonReads.push(
this.readExistingProjectJson(
join(graph.nodes[projectName].data.root, 'project.json')
zip(
of(projectName),
this.readExistingProjectJson(
join(graph.nodes[projectName].data.root, 'project.json')
)
)
);
}
}
return zip(...projectJsonReads).pipe(
map((projectJsons) => {
projectJsons
.filter((p) => p !== null)
.forEach((p) => {
delete p.version;
ret.projects[p.name] = {
...p,
root: graph.nodes[p.name].data.root,
map((reads) => {
reads
.filter(([, p]) => p !== null)
.forEach(([projectName, project]) => {
delete project.version;
ret.projects[projectName] = {
...project,
root: graph.nodes[projectName].data.root,
};
});

Expand Down Expand Up @@ -290,9 +295,11 @@ export class NxScopedHost extends virtualFs.ScopedHost<any> {
if (existingConfig.projects[projectName]) {
const updatedContent = this.mergeProjectConfiguration(
existingConfig.projects[projectName],
projects[projectName]
projects[projectName],
projectName
);
if (updatedContent) {
delete updatedContent.root;
allObservables.push(
super.write(
path as any,
Expand Down Expand Up @@ -338,7 +345,8 @@ export class NxScopedHost extends virtualFs.ScopedHost<any> {

mergeProjectConfiguration(
existing: ProjectConfiguration,
updated: ProjectConfiguration
updated: ProjectConfiguration,
projectName: string
) {
const res = { ...existing };

Expand All @@ -353,6 +361,10 @@ export class NxScopedHost extends virtualFs.ScopedHost<any> {
modified = true;
}
}
if (!res.name) {
res.name = updated.name || projectName;
modified = true;
}

return modified ? res : null;
}
Expand Down

0 comments on commit 2011e29

Please sign in to comment.