fix(style): remove printlns and appease cargo fmt

master
Ashley Williams 7 years ago
parent e607eda95c
commit 354f038a1a
  1. 23
      src/manifest/mod.rs
  2. 12
      tests/all/manifest.rs
  3. 5
      tests/all/utils/manifest.rs

@ -129,7 +129,11 @@ impl CargoManifest {
None => {}
}
check_optional_fields(&self.package.description, &self.package.repository, &self.package.license);
check_optional_fields(
&self.package.description,
&self.package.repository,
&self.package.license,
);
NpmPackage::CommonJSPackage(CommonJSPackage {
name: self.package.name,
@ -170,7 +174,11 @@ impl CargoManifest {
None => {}
}
check_optional_fields(&self.package.description, &self.package.repository, &self.package.license);
check_optional_fields(
&self.package.description,
&self.package.repository,
&self.package.license,
);
NpmPackage::ESModulesPackage(ESModulesPackage {
name: self.package.name,
@ -201,7 +209,6 @@ pub fn write_package_json(
) -> Result<(), Error> {
let msg = format!("{}Writing a package.json...", emoji::MEMO);
PBAR.step(step, &msg);
let pkg_file_path = out_dir.join("package.json");
let mut pkg_file = File::create(pkg_file_path)?;
@ -212,14 +219,17 @@ pub fn write_package_json(
crate_data.into_esmodules(scope, disable_dts)
};
let npm_json = serde_json::to_string_pretty(&npm_data)?;
pkg_file.write_all(npm_json.as_bytes())?;
Ok(())
}
/// Check the data for missing fields and warn
pub fn check_optional_fields(description: &Option<String>, repository: &Option<String>, license: &Option<String>) {
/// Check the data for missing fields and warn
pub fn check_optional_fields(
description: &Option<String>,
repository: &Option<String>,
license: &Option<String>,
) {
let warn_fmt = |field| {
format!(
"Field '{}' is missing from Cargo.toml. It is not necessary, but recommended",
@ -236,7 +246,6 @@ pub fn check_optional_fields(description: &Option<String>, repository: &Option<S
if license.is_none() {
PBAR.warn(&warn_fmt("license"));
}
}
/// Get the crate name for the crate at the given path.

@ -94,7 +94,11 @@ fn it_creates_a_package_json_provided_path() {
assert_eq!(pkg.module, "js_hello_world.js");
let actual_files: HashSet<String> = pkg.files.into_iter().collect();
let expected_files: HashSet<String> = ["js_hello_world_bg.wasm", "js_hello_world.d.ts", "js_hello_world.js"]
let expected_files: HashSet<String> = [
"js_hello_world_bg.wasm",
"js_hello_world.d.ts",
"js_hello_world.js",
]
.iter()
.map(|&s| String::from(s))
.collect();
@ -125,7 +129,11 @@ fn it_creates_a_package_json_provided_path_with_scope() {
assert_eq!(pkg.module, "scopes_hello_world.js");
let actual_files: HashSet<String> = pkg.files.into_iter().collect();
let expected_files: HashSet<String> = ["scopes_hello_world_bg.wasm", "scopes_hello_world.d.ts", "scopes_hello_world.js"]
let expected_files: HashSet<String> = [
"scopes_hello_world_bg.wasm",
"scopes_hello_world.d.ts",
"scopes_hello_world.js",
]
.iter()
.map(|&s| String::from(s))
.collect();

@ -22,7 +22,7 @@ pub struct NpmPackage {
}
fn default_none() -> String {
"".to_string()
"".to_string()
}
#[derive(Deserialize)]
@ -37,7 +37,6 @@ pub fn read_package_json(path: &Path, out_dir: &Path) -> Result<NpmPackage, Erro
let mut pkg_file = File::open(manifest_path)?;
let mut pkg_contents = String::new();
pkg_file.read_to_string(&mut pkg_contents)?;
println!("pkg_file: {}", pkg_contents);
Ok(serde_json::from_str(&pkg_contents)?)
}

Loading…
Cancel
Save