0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-17 22:44:24 -05:00

fix(install-package): Automatically exit in CI instead of waiting for input (#10669)

This commit is contained in:
Erika 2024-04-04 03:08:41 -04:00 committed by GitHub
parent a8ab23700f
commit 0464563e52
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Fixes Astro waiting infinitely in CI when a required package was not installed

View file

@ -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<T>(
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) {