@@ -60,15 +60,15 @@ const getPlatforms = async (pkg: Package | PackageRequirement) => {
6060 return rv
6161}
6262
63- const getRawDistributableURL = ( yml : PlainObject ) => {
64- if ( isPlainObject ( yml . distributable ) ) {
65- return validate . str ( yml . distributable . url )
66- } else if ( isString ( yml . distributable ) ) {
67- return yml . distributable
68- } else if ( yml . distributable === null || yml . distributable === undefined ) {
63+ const getRawDistributableURL = ( dist : PlainObject ) => {
64+ if ( isPlainObject ( dist ) ) {
65+ return validate . str ( dist . url )
66+ } else if ( isString ( dist ) ) {
67+ return dist
68+ } else if ( dist === null || dist === undefined ) {
6969 return
7070 } else {
71- throw new Error ( `invalid distributable node: ${ yml . distributable } ` )
71+ throw new Error ( `invalid distributable node: ${ dist } ` )
7272 }
7373}
7474
@@ -93,30 +93,62 @@ const getDistributable = async (pkg: Package) => {
9393 const moustaches = useMoustaches ( )
9494
9595 const yml = await hooks . usePantry ( ) . project ( pkg ) . yaml ( )
96-
97- if ( yml . distributable ?. git ) {
98- console . warn ( "brewkit: using distributable.git instead of distributable.url is deprecated" )
99- return getGitDistribution ( { pkg, ...yml . distributable } )
100- }
101- if ( yml . distributable ?. url ?. startsWith ( "git" ) ) {
102- return getGitDistribution ( { pkg, ...yml . distributable } )
96+ const dists = isArray ( yml . distributable ) ? yml . distributable : [ yml . distributable ]
97+
98+ for ( const dist of dists ) {
99+ if ( ! dist ) continue
100+ //FIXME: Add check for Git dists as well
101+ if ( dist . git ) {
102+ console . warn (
103+ "brewkit: using distributable.git instead of distributable.url is deprecated" ,
104+ )
105+ return getGitDistribution ( { pkg, ...dist } )
106+ }
107+
108+ if ( dist . url ?. startsWith ( "git" ) ) {
109+ return getGitDistribution ( { pkg, ...dist } )
110+ }
111+
112+ let urlstr = getRawDistributableURL ( dist )
113+ if ( ! urlstr ) continue
114+
115+ let v = pkg . version
116+ const stripComponents = flatmap ( dist [ "strip-components" ] , coerceNumber )
117+
118+ if ( isPlainObject ( dist ) ) {
119+ if ( dist . rewrite ?. match ) {
120+ const v_raw = v . raw . replace (
121+ new RegExp ( dist . rewrite [ "match" ] , "gi" ) ,
122+ dist . rewrite [ "with" ] ,
123+ )
124+ Object . assign ( v , { raw : v_raw } )
125+ }
126+
127+ if ( dist . if ) {
128+ const matched = new RegExp ( dist . if ) . test ( pkg . version . raw ) ;
129+ if ( ! matched ) continue
130+ }
131+ }
132+
133+ urlstr = moustaches . apply ( urlstr , [
134+ ...moustaches . tokenize . version ( v ) ,
135+ ...moustaches . tokenize . host ( ) ,
136+ ] )
137+
138+ try {
139+ const rsp = await fetch ( urlstr , { method : "HEAD" } )
140+
141+ if ( rsp . status == 200 ) {
142+ const url = new URL ( urlstr )
143+ return { url, ref : undefined , stripComponents, type : "url" }
144+ } else {
145+ console . warn ( `brewkit: Could not fetch ${ urlstr } [${ rsp . status } ]` )
146+ }
147+ } catch ( err ) {
148+ console . warn ( `brewkit: Could not fetch ${ urlstr } \nError: ${ err } ` )
149+ }
103150 }
104-
105- let urlstr = getRawDistributableURL ( yml )
106- if ( ! urlstr ) return
107- let stripComponents : number | undefined
108- if ( isPlainObject ( yml . distributable ) ) {
109- stripComponents = flatmap ( yml . distributable [ "strip-components" ] , coerceNumber )
110- }
111-
112- urlstr = moustaches . apply ( urlstr , [
113- ...moustaches . tokenize . version ( pkg . version ) ,
114- ...moustaches . tokenize . host ( )
115- ] )
116-
117- const url = new URL ( urlstr )
118-
119- return { url, ref : undefined , stripComponents, type : 'url' }
151+ return ;
120152}
121153
122154// deno-lint-ignore no-explicit-any
0 commit comments