@@ -108,40 +108,36 @@ async function getLatestMagoVersions(): Promise<MagoVersions> {
108108 return { formatter, phpVersion } ;
109109}
110110
111- async function getLatestCrateVersion ( crateName : string ) : Promise < string > {
112- const data = await $ . request ( `https://crates.io/api/v1/crates/${ crateName } ` ) . json ( ) ;
113- const latestVersion = data . crate ?. newest_version ;
114- if ( latestVersion == null ) {
115- throw new Error ( `Could not find latest version of ${ crateName } on crates.io.` ) ;
116- }
117- $ . logLight ( `Latest ${ crateName } version on crates.io:` , latestVersion ) ;
118- return latestVersion ;
119- }
120-
121- async function updateRustToolchain ( formatterVersion : string ) {
122- const data = await $ . request ( `https://crates.io/api/v1/crates/mago-formatter/${ formatterVersion } ` ) . json ( ) ;
123- const requiredRustVersion = data . version ?. rust_version ;
124- if ( requiredRustVersion == null ) {
125- $ . log ( `mago-formatter ${ formatterVersion } does not declare a rust_version; leaving rust-toolchain.toml alone.` ) ;
126- return ;
111+ async function updateRustToolchain ( magoVersion : string ) {
112+ const content = await $ . request (
113+ `https://raw.githubusercontent.com/carthage-software/mago/${ magoVersion } /Cargo.toml` ,
114+ ) . text ( ) ;
115+ const match = content . match ( / r u s t - v e r s i o n \s * = \s * " ( [ ^ " ] + ) " / ) ;
116+ if ( match == null ) {
117+ throw new Error ( "Could not find rust-version in mago's Cargo.toml." ) ;
127118 }
128-
119+ const magoRustVersion = match [ 1 ] ;
129120 const toolchainPath = rootDirPath . join ( "rust-toolchain.toml" ) ;
130121 const localContent = toolchainPath . readTextSync ( ) ;
131122 const localMatch = localContent . match ( / c h a n n e l \s * = \s * " ( [ ^ " ] + ) " / ) ;
132123 if ( localMatch == null ) {
133124 throw new Error ( "Could not find channel in local rust-toolchain.toml." ) ;
134125 }
135- // crates.io rust_version may be "1.84" (no patch); pad to MAJOR.MINOR.PATCH
136- // so @std /semver can parse it.
137- const normalize = ( v : string ) => / ^ \d + \. \d + $ / . test ( v ) ? `${ v } .0` : v ;
138- // only bump up; never downgrade. compare as semver so 1.95.0 > 1.92.0.
139- const local = semver . parse ( normalize ( localMatch [ 1 ] ) ) ;
140- const required = semver . parse ( normalize ( requiredRustVersion ) ) ;
141- if ( semver . greaterThan ( required , local ) ) {
142- $ . log ( `Updating Rust toolchain: ${ localMatch [ 1 ] } -> ${ requiredRustVersion } ` ) ;
143- toolchainPath . writeTextSync ( localContent . replace ( localMatch [ 0 ] , `channel = "${ requiredRustVersion } "` ) ) ;
126+ if ( localMatch [ 1 ] !== magoRustVersion ) {
127+ $ . log ( `Updating Rust toolchain: ${ localMatch [ 1 ] } -> ${ magoRustVersion } ` ) ;
128+ toolchainPath . writeTextSync ( localContent . replace ( localMatch [ 0 ] , `channel = "${ magoRustVersion } "` ) ) ;
144129 } else {
145- $ . log ( `Rust toolchain at ${ localMatch [ 1 ] } already satisfies mago-formatter ${ formatterVersion } (needs >= ${ requiredRustVersion } ) .` ) ;
130+ $ . log ( `Rust toolchain already at ${ magoRustVersion } .` ) ;
146131 }
147132}
133+
134+ async function getLatestCrateVersion ( crateName : string ) : Promise < string > {
135+ const data = await $ . request ( `https://crates.io/api/v1/crates/${ crateName } ` )
136+ . json < { crate ?: { newest_version ?: string } } > ( ) ;
137+ const latestVersion = data . crate ?. newest_version ;
138+ if ( latestVersion == null ) {
139+ throw new Error ( `Could not find latest version of ${ crateName } on crates.io.` ) ;
140+ }
141+ $ . logLight ( `Latest ${ crateName } version on crates.io:` , latestVersion ) ;
142+ return latestVersion ;
143+ }
0 commit comments