From 3850e95870eb5f9ca1806b55b85263dc57da962d Mon Sep 17 00:00:00 2001
From: Jacob Ley <37151850+JacobLey@users.noreply.github.com>
Date: Sat, 7 Dec 2024 01:02:58 -0800
Subject: [PATCH] fix(core): defer loading package manager until necessary
 (#29248)

(cherry picked from commit 5d6119199937b8552655745d39b075cbe4a7df6c)
---
 packages/nx/src/utils/package-json.ts | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/packages/nx/src/utils/package-json.ts b/packages/nx/src/utils/package-json.ts
index 3e46cc2dff513..ea6dda74d0a66 100644
--- a/packages/nx/src/utils/package-json.ts
+++ b/packages/nx/src/utils/package-json.ts
@@ -177,8 +177,8 @@ export function readTargetsFromPackageJson(
   const { scripts, nx, private: isPrivate } = packageJson ?? {};
   const res: Record<string, TargetConfiguration> = {};
   const includedScripts = nx?.includedScripts || Object.keys(scripts ?? {});
-  packageManagerCommand ??= getPackageManagerCommand();
   for (const script of includedScripts) {
+    packageManagerCommand ??= getPackageManagerCommand();
     res[script] = buildTargetFromScript(script, scripts, packageManagerCommand);
   }
   for (const targetName in nx?.targets) {