From 12c6a734fc6248df83530715b6eb98301e204a87 Mon Sep 17 00:00:00 2001 From: Jason Jean Date: Thu, 23 May 2024 22:07:29 -0400 Subject: [PATCH] fix(core): cache getting the package manager to the module scope (#25992) ## Current Behavior This function is called many times and they all `exec` a command ## Expected Behavior This function is called once and the result is cached. ## Related Issue(s) Fixes # --- packages/nx/src/utils/package-json.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/nx/src/utils/package-json.ts b/packages/nx/src/utils/package-json.ts index 3ac14df43c..ea68784b9d 100644 --- a/packages/nx/src/utils/package-json.ts +++ b/packages/nx/src/utils/package-json.ts @@ -136,11 +136,13 @@ export function buildTargetFromScript( }; } +let packageManagerCommand: PackageManagerCommands | undefined; + export function readTargetsFromPackageJson(packageJson: PackageJson) { const { scripts, nx, private: isPrivate } = packageJson ?? {}; const res: Record = {}; const includedScripts = nx?.includedScripts || Object.keys(scripts ?? {}); - const packageManagerCommand = getPackageManagerCommand(); + packageManagerCommand ??= getPackageManagerCommand(); for (const script of includedScripts) { res[script] = buildTargetFromScript(script, scripts, packageManagerCommand); }