Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5e53409

Browse files
committed
perf(@angular/cli): parallelize peer dependency checks in ng add
This commit optimizes the peer dependency validation process within the `ng add` command by parallelizing the checks for each package version. The `getPeerDependencyConflicts` method was refactored to use `Promise.all`. This allows all peer dependency lookups for a single candidate package to run concurrently, significantly speeding up the version resolution logic, especially when the dependency cache is not yet populated.
1 parent aeb49dd commit 5e53409

File tree

1 file changed

+36
-29
lines changed
  • packages/angular/cli/src/commands/add

1 file changed

+36
-29
lines changed

‎packages/angular/cli/src/commands/add/cli.ts

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -610,43 +610,50 @@ export default class AddCommandModule
610610
}
611611

612612
private async getPeerDependencyConflicts(manifest: PackageManifest): Promise<string[] | false> {
613-
const conflicts: string[] = [];
614-
for (const peer in manifest.peerDependencies) {
613+
if (!manifest.peerDependencies) {
614+
return false;
615+
}
616+
617+
const checks = Object.entries(manifest.peerDependencies).map(async ([peer, range]) => {
615618
let peerIdentifier;
616619
try {
617-
peerIdentifier = npa.resolve(peer, manifest.peerDependencies[peer]);
620+
peerIdentifier = npa.resolve(peer, range);
618621
} catch {
619622
this.context.logger.warn(`Invalid peer dependency ${peer} found in package.`);
620-
continue;
623+
624+
return null;
621625
}
622626

623-
if (peerIdentifier.type === 'version' || peerIdentifier.type === 'range') {
624-
try {
625-
const version = await this.findProjectVersion(peer);
626-
if (!version) {
627-
continue;
628-
}
629-
630-
const options = { includePrerelease: true };
631-
632-
if (
633-
!intersects(version, peerIdentifier.rawSpec, options) &&
634-
!satisfies(version, peerIdentifier.rawSpec, options)
635-
) {
636-
conflicts.push(
637-
`Package "${manifest.name}@${manifest.version}" has an incompatible peer dependency to "` +
638-
`${peer}@${peerIdentifier.rawSpec}" (requires "${version}" in project).`,
639-
);
640-
}
641-
} catch {
642-
// Not found or invalid so ignore
643-
continue;
644-
}
645-
} else {
627+
if (peerIdentifier.type !== 'version' && peerIdentifier.type !== 'range') {
646628
// type === 'tag' | 'file' | 'directory' | 'remote' | 'git'
647-
// Cannot accurately compare these as the tag/location may have changed since install
629+
// Cannot accurately compare these as the tag/location may have changed since install.
630+
return null;
648631
}
649-
}
632+
633+
try {
634+
const version = await this.findProjectVersion(peer);
635+
if (!version) {
636+
return null;
637+
}
638+
639+
const options = { includePrerelease: true };
640+
if (
641+
!intersects(version, peerIdentifier.rawSpec, options) &&
642+
!satisfies(version, peerIdentifier.rawSpec, options)
643+
) {
644+
return (
645+
`Package "${manifest.name}@${manifest.version}" has an incompatible peer dependency to "` +
646+
`${peer}@${peerIdentifier.rawSpec}" (requires "${version}" in project).`
647+
);
648+
}
649+
} catch {
650+
// Not found or invalid so ignore
651+
}
652+
653+
return null;
654+
});
655+
656+
const conflicts = (await Promise.all(checks)).filter((result): result is string => !!result);
650657

651658
return conflicts.length > 0 && conflicts;
652659
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /