Skip to content

Commit ec77e1b

Browse files
committed
perf(@angular/cli): create require instance once outside dependency loop
1 parent c2c77a4 commit ec77e1b

File tree

1 file changed

+6
-13
lines changed
  • packages/angular/cli/src/commands/update

1 file changed

+6
-13
lines changed

packages/angular/cli/src/commands/update/cli.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -716,12 +716,16 @@ export async function supplementWithLocalDependencies(
716716
...localManifest.peerDependencies,
717717
};
718718

719+
const projectRequire = createRequire(path.join(projectRoot, 'package.json'));
720+
719721
for (const depName of Object.keys(localDeps)) {
720722
if (dependencies.has(depName)) {
721723
continue;
722724
}
723-
const pkgJsonPath = findPackageJson(projectRoot, depName);
724-
if (!pkgJsonPath) {
725+
let pkgJsonPath: string;
726+
try {
727+
pkgJsonPath = projectRequire.resolve(`${depName}/package.json`);
728+
} catch {
725729
continue;
726730
}
727731
const installed = await readPackageManifest(pkgJsonPath);
@@ -744,14 +748,3 @@ async function readPackageManifest(manifestPath: string): Promise<PackageManifes
744748
return undefined;
745749
}
746750
}
747-
748-
function findPackageJson(workspaceDir: string, packageName: string): string | undefined {
749-
try {
750-
const projectRequire = createRequire(path.join(workspaceDir, 'package.json'));
751-
const packageJsonPath = projectRequire.resolve(`${packageName}/package.json`);
752-
753-
return packageJsonPath;
754-
} catch {
755-
return undefined;
756-
}
757-
}

0 commit comments

Comments
 (0)