From 1b79479fc01553cc688d8456b832650f84462bb8 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Mon, 15 Apr 2024 02:12:07 -0700 Subject: [PATCH] astro/cli/install-package.ts: whichPm may return null if ran in an empty directory (#10782) --- .changeset/many-hairs-jump.md | 5 +++++ packages/astro/src/cli/install-package.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/many-hairs-jump.md diff --git a/.changeset/many-hairs-jump.md b/.changeset/many-hairs-jump.md new file mode 100644 index 000000000000..2e855708fb89 --- /dev/null +++ b/.changeset/many-hairs-jump.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Handles possible null value when calling `which-pm` during dynamic package installation diff --git a/packages/astro/src/cli/install-package.ts b/packages/astro/src/cli/install-package.ts index 02e856846484..7c8601e48a8c 100644 --- a/packages/astro/src/cli/install-package.ts +++ b/packages/astro/src/cli/install-package.ts @@ -101,7 +101,7 @@ async function installPackage( logger: Logger ): Promise { const cwd = options.cwd ?? process.cwd(); - const packageManager = (await whichPm(cwd)).name ?? 'npm'; + const packageManager = (await whichPm(cwd))?.name ?? 'npm'; const installCommand = getInstallCommand(packageNames, packageManager); if (!installCommand) {