@ -11,6 +11,7 @@ use self::npm::{
repository ::Repository , CommonJSPackage , ESModulesPackage , NoModulesPackage , NpmPackage ,
} ;
use emoji ;
use failure ;
use error ::Error ;
use progressbar ::Step ;
use serde_json ;
@ -75,13 +76,13 @@ struct CargoLib {
crate_type : Option < Vec < String > > ,
}
fn read_cargo_toml ( path : & Path ) -> Result < CargoManifest , Error > {
fn read_cargo_toml ( path : & Path ) -> Result < CargoManifest , failure ::Error > {
let manifest_path = path . join ( "Cargo.toml" ) ;
if ! manifest_path . is_file ( ) {
return Err ( Error ::crate_config ( & format! (
"Crate directory is missing a `Cargo.toml` file; is `{}` the wrong directory?" ,
path . display ( )
) ) ) ;
) ) . into ( ) ) ;
}
let mut cargo_file = File ::open ( manifest_path ) ? ;
let mut cargo_contents = String ::new ( ) ;
@ -213,7 +214,7 @@ pub fn write_package_json(
disable_dts : bool ,
target : & str ,
step : & Step ,
) -> Result < ( ) , Error > {
) -> Result < ( ) , failure ::Error > {
let msg = format! ( "{}Writing a package.json..." , emoji ::MEMO ) ;
PBAR . step ( step , & msg ) ;
@ -234,19 +235,19 @@ pub fn write_package_json(
}
/// Get the crate name for the crate at the given path.
pub fn get_crate_name ( path : & Path ) -> Result < String , Error > {
pub fn get_crate_name ( path : & Path ) -> Result < String , failure ::Error > {
Ok ( read_cargo_toml ( path ) ? . package . name )
}
/// Check that the crate the given path is properly configured.
pub fn check_crate_config ( path : & Path , step : & Step ) -> Result < ( ) , Error > {
pub fn check_crate_config ( path : & Path , step : & Step ) -> Result < ( ) , failure ::Error > {
let msg = format! ( "{}Checking crate configuration..." , emoji ::WRENCH ) ;
PBAR . step ( & step , & msg ) ;
check_crate_type ( path ) ? ;
Ok ( ( ) )
}
fn check_crate_type ( path : & Path ) -> Result < ( ) , Error > {
fn check_crate_type ( path : & Path ) -> Result < ( ) , failure ::Error > {
if read_cargo_toml ( path ) ? . lib . map_or ( false , | lib | {
lib . crate_type
. map_or ( false , | types | types . iter ( ) . any ( | s | s = = "cdylib" ) )
@ -258,5 +259,5 @@ fn check_crate_type(path: &Path) -> Result<(), Error> {
Cargo . toml file :\ n \ n \
[ lib ] \ n \
crate - type = [ \ "cdylib\", \"rlib\"]"
) )
) . into ( ) )
}