1- import { warning } from "ci-log"
21import escapeRegex from "escape-string-regexp"
32import { execa } from "execa"
43import { getAptEnv } from "./apt-env.js"
@@ -37,7 +36,12 @@ export async function qualifiedNeededAptPackage(pack: AptPackage, apt: string =
3736 return ( await isAptPackInstalled ( qualified ) ) ? undefined : qualified
3837}
3938
40- async function aptPackageType ( apt : string , name : string , version : string | undefined ) : Promise < AptPackageType > {
39+ async function aptPackageType (
40+ apt : string ,
41+ name : string ,
42+ version : string | undefined ,
43+ fallBackToLatest : boolean ,
44+ ) : Promise < AptPackageType > {
4145 if ( version !== undefined && version !== "" ) {
4246 const { stdout } = await execa ( "apt-cache" , [
4347 "search" ,
@@ -72,10 +76,10 @@ async function aptPackageType(apt: string, name: string, version: string | undef
7276 // If apt-cache fails, update the repos and try again
7377 if ( ! updatedRepos ) {
7478 updateAptReposMemoized ( apt )
75- return aptPackageType ( apt , name , version )
79+ return aptPackageType ( apt , name , version , fallBackToLatest )
7680 }
7781
78- if ( version === undefined || version === "" ) {
82+ if ( version === undefined || version === "" || fallBackToLatest ) {
7983 // if the version is undefined or empty, return the name as a package name
8084 return AptPackageType . Name
8185 }
@@ -86,21 +90,14 @@ async function aptPackageType(apt: string, name: string, version: string | undef
8690async function getAptArg ( apt : string , pack : AptPackage ) {
8791 const { name, version, fallBackToLatest = false } = pack
8892
89- const package_type = await aptPackageType ( apt , name , version )
93+ const package_type = await aptPackageType ( apt , name , version , fallBackToLatest )
9094 switch ( package_type ) {
9195 case AptPackageType . NameDashVersion :
9296 return `${ name } -${ version } `
9397 case AptPackageType . NameEqualsVersion :
9498 return `${ name } =${ version } `
9599 case AptPackageType . Name : {
96- if ( version === undefined || version === "" ) {
97- return name
98- }
99- if ( fallBackToLatest ) {
100- warning ( `Could not find package '${ name } ' with version '${ version } '. Installing the latest version.` )
101- return name
102- }
103- throw new Error ( `Could not find package '${ name } ' with version '${ version } '` )
100+ return name
104101 }
105102 default :
106103 throw new Error ( `Could not find package '${ name } ' ${ version ?? "with unspecified version" } ` )
0 commit comments