1- // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
1+ // Copyright 2018-2025 the Deno authors. All rights reserved. MIT license.
22
3- import { $ , dax , PathRef , semver } from "./deps.ts" ;
3+ import * as dax from "@david/dax" ;
4+ import { $ , type Path } from "@david/dax" ;
5+ import * as semver from "@std/semver" ;
46import type { Repo } from "./repo.ts" ;
5- import { CargoDependencyMetadata , CargoPackageMetadata } from "./cargo.ts" ;
7+ import type { CargoDependencyMetadata , CargoPackageMetadata } from "./cargo.ts" ;
68import { getCratesIoMetadata } from "./crates_io.ts" ;
79
810export interface CrateDep {
@@ -24,28 +26,28 @@ export class Crate {
2426 this . #pkg = crateMetadata ;
2527 }
2628
27- get manifestPath ( ) {
29+ get manifestPath ( ) : Path {
2830 return $ . path ( this . #pkg. manifest_path ) ;
2931 }
3032
31- get folderPath ( ) {
33+ get folderPath ( ) : Path {
3234 return this . manifestPath . parentOrThrow ( ) ;
3335 }
3436
35- get name ( ) {
37+ get name ( ) : string {
3638 return this . #pkg. name ;
3739 }
3840
39- get version ( ) {
41+ get version ( ) : string {
4042 return this . #pkg. version ;
4143 }
4244
43- get dependencies ( ) {
45+ get dependencies ( ) : readonly CargoDependencyMetadata [ ] {
4446 return this . #pkg. dependencies as readonly CargoDependencyMetadata [ ] ;
4547 }
4648
4749 /** Prompts the user how they would like to patch and increments the version accordingly. */
48- async promptAndIncrement ( ) {
50+ async promptAndIncrement ( ) : Promise < "patch" | "minor" | "major" > {
4951 const result = await this . promptAndTryIncrement ( ) ;
5052 if ( result == null ) {
5153 throw new Error ( "No decision." ) ;
@@ -54,7 +56,9 @@ export class Crate {
5456 }
5557
5658 /** Prompts the user how they would like to patch and increments the version accordingly. */
57- async promptAndTryIncrement ( ) {
59+ async promptAndTryIncrement ( ) : Promise <
60+ "patch" | "minor" | "major" | undefined
61+ > {
5862 $ . log ( `${ this . name } is on ${ this . version } ` ) ;
5963 const versionIncrement = getVersionIncrement ( ) ;
6064 if ( versionIncrement != null ) {
@@ -110,12 +114,14 @@ export class Crate {
110114 this . #updateManifestVersion( version ) ;
111115 }
112116
113- static async getLatestVersion ( crateName : string ) {
117+ static async getLatestVersion (
118+ crateName : string ,
119+ ) : Promise < string | undefined > {
114120 return ( await getCratesIoMetadata ( crateName ) ) ?. crate . max_stable_version ;
115121 }
116122
117123 /** Gets the latest version from crates.io or returns undefined if not exists. */
118- getLatestVersion ( ) {
124+ getLatestVersion ( ) : Promise < string | undefined > {
119125 return Crate . getLatestVersion ( this . name ) ;
120126 }
121127
@@ -169,7 +175,7 @@ export class Crate {
169175 }
170176
171177 /** Gets all the descendant dependencies in the repository. */
172- descendantDependenciesInRepo ( ) {
178+ descendantDependenciesInRepo ( ) : Crate [ ] {
173179 // try to maintain publish order.
174180 const crates = new Map < string , Crate > ( ) ;
175181 const stack = [ ...this . immediateDependenciesInRepo ( ) ] ;
@@ -184,7 +190,7 @@ export class Crate {
184190 }
185191
186192 /** Gets the immediate child dependencies found in the repo. */
187- immediateDependenciesInRepo ( ) {
193+ immediateDependenciesInRepo ( ) : CrateDep [ ] {
188194 const dependencies : CrateDep [ ] = [ ] ;
189195 for ( const dependency of this . #pkg. dependencies ) {
190196 const crate = this . repo . crates . find ( ( c ) => c . name === dependency . name ) ;
@@ -199,17 +205,17 @@ export class Crate {
199205 }
200206
201207 /** Gets if published or not, returning undefined if it was never published. */
202- async isPublished ( ) {
208+ async isPublished ( ) : Promise < boolean | undefined > {
203209 const cratesIoMetadata = await getCratesIoMetadata ( this . name ) ;
204210 if ( cratesIoMetadata == null ) {
205211 return undefined ;
206212 }
207- return cratesIoMetadata . versions . some ( ( v ) =>
213+ return cratesIoMetadata . versions . some ( ( v : any ) =>
208214 v . num === this . version . toString ( )
209215 ) ;
210216 }
211217
212- async publish ( ...additionalArgs : string [ ] ) {
218+ async publish ( ...additionalArgs : string [ ] ) : Promise < boolean > {
213219 const isPublished = await this . isPublished ( ) ;
214220 if ( isPublished == null ) {
215221 $ . log ( `Never published, so skipping ${ this . name } ${ this . version } ` ) ;
@@ -269,20 +275,20 @@ export class Crate {
269275 await this . command ( cliArgs ) ;
270276 }
271277
272- command ( command : string | string [ ] ) {
278+ command ( command : string | string [ ] ) : dax . CommandBuilder {
273279 return new dax . CommandBuilder ( )
274280 . command ( command )
275281 . cwd ( this . folderPath ) ;
276282 }
277283
278284 #updateManifestFile(
279- action : ( filePath : PathRef , fileText : string ) => string ,
285+ action : ( filePath : Path , fileText : string ) => string ,
280286 ) {
281287 updateFileEnsureChange ( this . manifestPath , action ) ;
282288 }
283289
284290 #updateRootManifestFile(
285- action : ( filePath : PathRef , fileText : string ) => string ,
291+ action : ( filePath : Path , fileText : string ) => string ,
286292 ) {
287293 const rootManifestFilePath = this . repo . folderPath . join ( "Cargo.toml" ) ;
288294 if (
@@ -296,8 +302,8 @@ export class Crate {
296302}
297303
298304function updateFileEnsureChange (
299- filePath : PathRef ,
300- action : ( filePath : PathRef , fileText : string ) => string ,
305+ filePath : Path ,
306+ action : ( filePath : Path , fileText : string ) => string ,
301307) {
302308 const originalText = filePath . readTextSync ( ) ;
303309 const newText = action ( filePath , originalText ) ;
0 commit comments