Skip to content

Commit

Permalink
fix(angular): respect cli config and schematics defaults in ng cli ad…
Browse files Browse the repository at this point in the history
…apter (#15510)
  • Loading branch information
leosvelperez committed Mar 7, 2023
1 parent e358849 commit bfdd2eb
Showing 1 changed file with 19 additions and 30 deletions.
49 changes: 19 additions & 30 deletions packages/nx/src/adapter/ngcli-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { dirname, extname, join, resolve } from 'path';
import { concat, from, Observable, of, zip } from 'rxjs';
import { catchError, concatMap, map, tap } from 'rxjs/operators';
import { GenerateOptions } from '../command-line/generate';
import { NxJsonConfiguration } from '../config/nx-json';
import { ProjectConfiguration } from '../config/workspace-json-project-json';
import { FsTree, Tree } from '../generators/tree';
import { readJson } from '../generators/utils/json';
Expand Down Expand Up @@ -213,31 +214,32 @@ export class NxScopedHost extends virtualFs.ScopedHost<any> {

read(path: Path): Observable<FileBuffer> {
if (path === 'angular.json' || path === '/angular.json') {
return this.readMergedProjectConfiguration().pipe(
return this.readMergedWorkspaceConfiguration().pipe(
map((r) => Buffer.from(JSON.stringify(toOldFormat(r))))
);
} else {
return super.read(path);
}
}

private readMergedProjectConfiguration() {
private readMergedWorkspaceConfiguration() {
return zip(
from(createProjectGraphAsync()),
this.readExistingAngularJson()
this.readExistingAngularJson(),
this.readJson<NxJsonConfiguration>('nx.json')
).pipe(
concatMap((arg) => {
const graph = arg[0] as any;
const ret = (arg[1] || { projects: {} }) as any;
const projectJsonReads: Observable<
[string, ProjectConfiguration & { version: string }]
>[] = [];
concatMap(([graph, angularJson, nxJson]) => {
const workspaceConfig = (angularJson || { projects: {} }) as any;
workspaceConfig.cli ??= nxJson.cli;
workspaceConfig.schematics ??= nxJson.generators;
const projectJsonReads: Observable<[string, ProjectConfiguration]>[] =
[];
for (let projectName of Object.keys(graph.nodes)) {
if (!ret.projects[projectName]) {
if (!workspaceConfig.projects[projectName]) {
projectJsonReads.push(
zip(
of(projectName),
this.readExistingProjectJson(
this.readJson<ProjectConfiguration>(
join(graph.nodes[projectName].data.root, 'project.json')
)
)
Expand All @@ -249,14 +251,13 @@ export class NxScopedHost extends virtualFs.ScopedHost<any> {
reads
.filter(([, p]) => p !== null)
.forEach(([projectName, project]) => {
delete project.version;
ret.projects[projectName] = {
workspaceConfig.projects[projectName] = {
...project,
root: graph.nodes[projectName].data.root,
};
});

return ret;
return workspaceConfig;
})
);
}),
Expand All @@ -274,7 +275,7 @@ export class NxScopedHost extends virtualFs.ScopedHost<any> {
const root = this.root;

return zip(
this.readMergedProjectConfiguration(),
this.readMergedWorkspaceConfiguration(),
this.readExistingAngularJson()
).pipe(
concatMap((arg) => {
Expand Down Expand Up @@ -386,30 +387,18 @@ export class NxScopedHost extends virtualFs.ScopedHost<any> {
}

readExistingAngularJson() {
return super
.exists('angular.json' as any)
.pipe(
concatMap((r) =>
r
? super
.read('angular.json' as any)
.pipe(map((r) => parseJson(arrayBufferToString(r))))
: of(null)
)
);
return this.readJson('angular.json');
}

readExistingProjectJson(path: string) {
private readJson<T = any>(path: string): Observable<T> {
return super
.exists(path as any)
.pipe(
concatMap((r) =>
r
? super
.read(path as any)
.pipe(
map((r) => toNewFormat(parseJson(arrayBufferToString(r))))
)
.pipe(map((r) => parseJson(arrayBufferToString(r))))
: of(null)
)
);
Expand Down

1 comment on commit bfdd2eb

@vercel
Copy link

@vercel vercel bot commented on bfdd2eb Mar 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx.dev
nx-five.vercel.app
nx-dev-git-master-nrwl.vercel.app

Please sign in to comment.