Skip to content

Commit

Permalink
fix(angular): write config correctly when using the angular cli adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
leosvelperez committed Feb 20, 2023
1 parent bce05ae commit 6b4001b
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions packages/nx/src/adapter/ngcli-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ async function runSchematic(
return { status: 0, loggingQueue: record.loggingQueue };
}

type AngularProjectConfiguration = ProjectConfiguration & { prefix?: string };

export class NxScopedHost extends virtualFs.ScopedHost<any> {
constructor(private root: string) {
super(new NodeJsSyncHost(), normalize(root));
Expand Down Expand Up @@ -344,27 +346,40 @@ export class NxScopedHost extends virtualFs.ScopedHost<any> {
}

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

if (!res.targets) {
res.targets = {};
}

const res: AngularProjectConfiguration = { ...existing };
let modified = false;
for (let target of Object.keys(updated.targets)) {
if (!res.targets[target]) {
res.targets[target] = updated.targets[target];

function updatePropertyIfDifferent<
T extends Exclude<keyof AngularProjectConfiguration, 'namedInputs'>
>(property: T): void {
if (typeof res[property] === 'string') {
if (res[property] !== updated[property]) {
res[property] = updated[property];
modified = true;
}
} else if (
JSON.stringify(res[property]) !== JSON.stringify(updated[property])
) {
res[property] = updated[property];
modified = true;
}
}
if (!res.name) {
res.name = updated.name || projectName;

if (!res.name || (updated.name && res.name !== updated.name)) {
res.name ??= updated.name || projectName;
modified = true;
}
updatePropertyIfDifferent('projectType');
updatePropertyIfDifferent('sourceRoot');
updatePropertyIfDifferent('prefix');
updatePropertyIfDifferent('targets');
updatePropertyIfDifferent('generators');
updatePropertyIfDifferent('implicitDependencies');
updatePropertyIfDifferent('tags');

return modified ? res : null;
}
Expand Down

0 comments on commit 6b4001b

Please sign in to comment.