Skip to content

Commit bfdd2eb

Browse files
authored
fix(angular): respect cli config and schematics defaults in ng cli adapter (#15510)
1 parent e358849 commit bfdd2eb

File tree

1 file changed

+19
-30
lines changed

1 file changed

+19
-30
lines changed

packages/nx/src/adapter/ngcli-adapter.ts

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { dirname, extname, join, resolve } from 'path';
1919
import { concat, from, Observable, of, zip } from 'rxjs';
2020
import { catchError, concatMap, map, tap } from 'rxjs/operators';
2121
import { GenerateOptions } from '../command-line/generate';
22+
import { NxJsonConfiguration } from '../config/nx-json';
2223
import { ProjectConfiguration } from '../config/workspace-json-project-json';
2324
import { FsTree, Tree } from '../generators/tree';
2425
import { readJson } from '../generators/utils/json';
@@ -213,31 +214,32 @@ export class NxScopedHost extends virtualFs.ScopedHost<any> {
213214

214215
read(path: Path): Observable<FileBuffer> {
215216
if (path === 'angular.json' || path === '/angular.json') {
216-
return this.readMergedProjectConfiguration().pipe(
217+
return this.readMergedWorkspaceConfiguration().pipe(
217218
map((r) => Buffer.from(JSON.stringify(toOldFormat(r))))
218219
);
219220
} else {
220221
return super.read(path);
221222
}
222223
}
223224

224-
private readMergedProjectConfiguration() {
225+
private readMergedWorkspaceConfiguration() {
225226
return zip(
226227
from(createProjectGraphAsync()),
227-
this.readExistingAngularJson()
228+
this.readExistingAngularJson(),
229+
this.readJson<NxJsonConfiguration>('nx.json')
228230
).pipe(
229-
concatMap((arg) => {
230-
const graph = arg[0] as any;
231-
const ret = (arg[1] || { projects: {} }) as any;
232-
const projectJsonReads: Observable<
233-
[string, ProjectConfiguration & { version: string }]
234-
>[] = [];
231+
concatMap(([graph, angularJson, nxJson]) => {
232+
const workspaceConfig = (angularJson || { projects: {} }) as any;
233+
workspaceConfig.cli ??= nxJson.cli;
234+
workspaceConfig.schematics ??= nxJson.generators;
235+
const projectJsonReads: Observable<[string, ProjectConfiguration]>[] =
236+
[];
235237
for (let projectName of Object.keys(graph.nodes)) {
236-
if (!ret.projects[projectName]) {
238+
if (!workspaceConfig.projects[projectName]) {
237239
projectJsonReads.push(
238240
zip(
239241
of(projectName),
240-
this.readExistingProjectJson(
242+
this.readJson<ProjectConfiguration>(
241243
join(graph.nodes[projectName].data.root, 'project.json')
242244
)
243245
)
@@ -249,14 +251,13 @@ export class NxScopedHost extends virtualFs.ScopedHost<any> {
249251
reads
250252
.filter(([, p]) => p !== null)
251253
.forEach(([projectName, project]) => {
252-
delete project.version;
253-
ret.projects[projectName] = {
254+
workspaceConfig.projects[projectName] = {
254255
...project,
255256
root: graph.nodes[projectName].data.root,
256257
};
257258
});
258259

259-
return ret;
260+
return workspaceConfig;
260261
})
261262
);
262263
}),
@@ -274,7 +275,7 @@ export class NxScopedHost extends virtualFs.ScopedHost<any> {
274275
const root = this.root;
275276

276277
return zip(
277-
this.readMergedProjectConfiguration(),
278+
this.readMergedWorkspaceConfiguration(),
278279
this.readExistingAngularJson()
279280
).pipe(
280281
concatMap((arg) => {
@@ -386,30 +387,18 @@ export class NxScopedHost extends virtualFs.ScopedHost<any> {
386387
}
387388

388389
readExistingAngularJson() {
389-
return super
390-
.exists('angular.json' as any)
391-
.pipe(
392-
concatMap((r) =>
393-
r
394-
? super
395-
.read('angular.json' as any)
396-
.pipe(map((r) => parseJson(arrayBufferToString(r))))
397-
: of(null)
398-
)
399-
);
390+
return this.readJson('angular.json');
400391
}
401392

402-
readExistingProjectJson(path: string) {
393+
private readJson<T = any>(path: string): Observable<T> {
403394
return super
404395
.exists(path as any)
405396
.pipe(
406397
concatMap((r) =>
407398
r
408399
? super
409400
.read(path as any)
410-
.pipe(
411-
map((r) => toNewFormat(parseJson(arrayBufferToString(r))))
412-
)
401+
.pipe(map((r) => parseJson(arrayBufferToString(r))))
413402
: of(null)
414403
)
415404
);

0 commit comments

Comments
 (0)