Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(angular): write config correctly when using the angular cli adapter #15133

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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