From 0464563e527f821e53d78028d9bbf3c4e1050f5b Mon Sep 17 00:00:00 2001 From: Erika <3019731+Princesseuh@users.noreply.github.com> Date: Thu, 4 Apr 2024 03:08:41 -0400 Subject: [PATCH] fix(install-package): Automatically exit in CI instead of waiting for input (#10669) --- .changeset/neat-grapes-cry.md | 5 +++++ packages/astro/src/cli/install-package.ts | 17 +++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 .changeset/neat-grapes-cry.md diff --git a/.changeset/neat-grapes-cry.md b/.changeset/neat-grapes-cry.md new file mode 100644 index 000000000000..5cf191d73d93 --- /dev/null +++ b/.changeset/neat-grapes-cry.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fixes Astro waiting infinitely in CI when a required package was not installed diff --git a/packages/astro/src/cli/install-package.ts b/packages/astro/src/cli/install-package.ts index 197c9907892e..1f0afd4e5319 100644 --- a/packages/astro/src/cli/install-package.ts +++ b/packages/astro/src/cli/install-package.ts @@ -8,6 +8,7 @@ import prompts from 'prompts'; import resolvePackage from 'resolve'; import whichPm from 'which-pm'; import { type Logger } from '../core/logger/core.js'; +import ci from 'ci-info'; const require = createRequire(import.meta.url); type GetPackageOptions = { @@ -38,10 +39,18 @@ export async function getPackage( return packageImport as T; } catch (e) { if (options.optional) return undefined; - logger.info( - 'SKIP_FORMAT', - `To continue, Astro requires the following dependency to be installed: ${bold(packageName)}.` - ); + let message = `To continue, Astro requires the following dependency to be installed: ${bold(packageName)}.`; + + if (ci.isCI) { + message += ` Packages cannot be installed automatically in CI environments.`; + } + + logger.info('SKIP_FORMAT', message); + + if (ci.isCI) { + return undefined; + } + const result = await installPackage([packageName, ...otherDeps], options, logger); if (result) {