@@ -24,6 +24,8 @@ mod wit;
2424use oci:: OciCommands ;
2525use wit:: WitCommands ;
2626
27+ use crate :: wit:: temp_wit_file;
28+
2729#[ derive( Parser , Debug ) ]
2830#[ command( version) ]
2931struct Cli {
@@ -252,15 +254,15 @@ impl PublishArgs {
252254 pub async fn run ( self ) -> anyhow:: Result < ( ) > {
253255 let client = self . common . get_client ( ) . await ?;
254256
255- let package = if let Some ( package ) = self . package {
256- Some ( (
257- package. package ,
258- package . version . ok_or_else ( || {
259- anyhow :: anyhow! ( "version is required when manually overriding the package ID" )
260- } ) ? ,
261- ) )
262- } else {
263- None
257+ let package = match self . package {
258+ Some ( PackageSpec {
259+ package,
260+ version : Some ( v ) ,
261+ } ) => Some ( ( package, v ) ) ,
262+ Some ( PackageSpec { version : None , .. } ) => {
263+ anyhow :: bail! ( "version is required when manually overriding the package ID" ) ;
264+ }
265+ None => None ,
264266 } ;
265267
266268 // If the input is a directory, build a WIT package from it into a temp
@@ -269,7 +271,7 @@ impl PublishArgs {
269271 let ( publish_path, _tmp) = if self . path . is_dir ( ) {
270272 let mut lock_file = LockFile :: load ( true ) . await ?;
271273 let prev_lock_ref = ( lock_file. version , lock_file. packages . clone ( ) ) ;
272- let ( build_ref , _, bytes) =
274+ let ( pkg_ref , _, bytes) =
273275 wit:: build_wit_dir ( & self . path , client. clone ( ) , & mut lock_file) . await ?;
274276 // There is no way to check if we are in a git repository unlike `cargo publish --allow-dirty` so
275277 // check against previous values.
@@ -285,22 +287,9 @@ impl PublishArgs {
285287 } ) ;
286288 }
287289
288- // Sanitize the package ref for use as a filename prefix: `namespace:name`
289- // contains characters (`:`, `/`) that are invalid in filenames on some
290- // platforms (notably Windows).
291- let prefix: String = build_ref. to_string ( ) . replace ( [ ':' , '/' ] , "_" ) ;
292- let tmp = tempfile:: Builder :: new ( )
293- . prefix ( & prefix)
294- . suffix ( ".wasm" )
295- . tempfile ( )
296- . context ( "Failed to create temporary file for built WIT package" ) ?;
297- tokio:: fs:: write ( tmp. path ( ) , & bytes)
298- . await
299- . context ( "Failed to write built WIT package to temp file" ) ?;
300- let tmp_pkg_path = tmp. path ( ) . to_path_buf ( ) ;
301- tracing:: debug!( tmp_pkg_path = %tmp_pkg_path. display( ) , "Wrote temporary WIT package file" ) ;
290+ let tmp = temp_wit_file ( & pkg_ref, & bytes) . await ?;
302291
303- ( tmp_pkg_path , Some ( tmp) )
292+ ( tmp . path ( ) . to_path_buf ( ) , Some ( tmp) )
304293 } else {
305294 ( self . path . clone ( ) , None )
306295 } ;
0 commit comments