import { __name } from './chunk-6AXVLTU5.js';
import { LogLevelLabel } from '@storm-software/config-tools/types';
import { install } from '@stryke/fs/install';
import { isPackageListed } from '@stryke/fs/package-fns';
import { isNumber } from '@stryke/type-checks/is-number';

async function installPackage(log, context, packageName, dev = false) {
  const isInstalled = await isPackageListed(packageName, context.projectRoot);
  if (!isInstalled) {
    if (context.skipInstalls !== true) {
      log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. It will be installed automatically.`);
      const result = await install(packageName, {
        cwd: context.projectRoot,
        dev
      });
      if (isNumber(result.exitCode) && result.exitCode > 0) {
        log(LogLevelLabel.ERROR, result.stderr);
        throw new Error(`An error occurred while installing the package "${packageName}"`);
      }
    } else {
      log(LogLevelLabel.WARN, `The package "${packageName}" is not installed. Since the "skipInstalls" option is set to true, it will not be installed automatically.`);
    }
  }
}
__name(installPackage, "installPackage");
async function installPackages(log, context, packages) {
  return Promise.all(packages.map(async (pkg) => installPackage(log, context, pkg.name, pkg.dev)));
}
__name(installPackages, "installPackages");

export { installPackage, installPackages };
//# sourceMappingURL=chunk-QLRH4TNM.js.map
//# sourceMappingURL=chunk-QLRH4TNM.js.map