Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support 'homepage' field of Cargo.toml and package.json #531

Merged
merged 2 commits into from
Jan 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct CargoPackage {
description: Option<String>,
license: Option<String>,
repository: Option<String>,
homepage: Option<String>,

#[serde(default)]
metadata: CargoMetadata,
Expand Down Expand Up @@ -199,6 +200,7 @@ struct NpmData {
files: Vec<String>,
dts_file: Option<String>,
main: String,
homepage: Option<String>, // https://docs.npmjs.com/files/package.json#homepage
}

#[doc(hidden)]
Expand Down Expand Up @@ -422,6 +424,7 @@ impl CrateData {
dts_file,
files,
main: js_file,
homepage: self.manifest.package.homepage.clone(),
}
}

Expand All @@ -448,6 +451,7 @@ impl CrateData {
}),
files: data.files,
main: data.main,
homepage: data.homepage,
types: data.dts_file,
})
}
Expand Down Expand Up @@ -475,6 +479,7 @@ impl CrateData {
}),
files: data.files,
module: data.main,
homepage: data.homepage,
types: data.dts_file,
side_effects: "false".to_string(),
})
Expand Down Expand Up @@ -503,6 +508,7 @@ impl CrateData {
}),
files: data.files,
browser: data.main,
homepage: data.homepage,
types: data.dts_file,
})
}
Expand Down
2 changes: 2 additions & 0 deletions src/manifest/npm/commonjs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ pub struct CommonJSPackage {
pub files: Vec<String>,
pub main: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub homepage: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub types: Option<String>,
}
2 changes: 2 additions & 0 deletions src/manifest/npm/esmodules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ pub struct ESModulesPackage {
pub files: Vec<String>,
pub module: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub homepage: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub types: Option<String>,
#[serde(rename = "sideEffects")]
pub side_effects: String,
Expand Down
2 changes: 2 additions & 0 deletions src/manifest/npm/nomodules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ pub struct NoModulesPackage {
pub files: Vec<String>,
pub browser: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub homepage: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub types: Option<String>,
}
57 changes: 57 additions & 0 deletions tests/all/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,63 @@ fn it_errors_when_wasm_bindgen_is_not_declared() {
assert!(crate_data.check_crate_config(&step).is_err());
}

#[test]
fn it_sets_homepage_field_if_available_in_cargo_toml() {
// When 'homepage' is available
let fixture = utils::fixture::Fixture::new();
fixture.hello_world_src_lib().file(
"Cargo.toml",
r#"
[package]
authors = ["The wasm-pack developers"]
description = "so awesome rust+wasm package"
license = "WTFPL"
name = "homepage-field-test"
repository = "https://github.com/rustwasm/wasm-pack.git"
version = "0.1.0"
homepage = "https://rustwasm.github.io/wasm-pack/"

[lib]
crate-type = ["cdylib"]

[dependencies]
wasm-bindgen = "=0.2"

[dev-dependencies]
wasm-bindgen-test = "=0.2"
"#,
);

let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();

let step = wasm_pack::progressbar::Step::new(2);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
crate_data
.write_package_json(&out_dir, &None, true, "", &step)
.unwrap();

let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
assert_eq!(
pkg.homepage,
Some("https://rustwasm.github.io/wasm-pack/".to_string()),
);

// When 'homepage' is unavailable
let fixture = fixture::js_hello_world();
let out_dir = fixture.path.join("pkg");
let crate_data = manifest::CrateData::new(&fixture.path).unwrap();

let step = wasm_pack::progressbar::Step::new(2);
wasm_pack::command::utils::create_pkg_dir(&out_dir, &step).unwrap();
crate_data
.write_package_json(&out_dir, &None, true, "", &step)
.unwrap();

let pkg = utils::manifest::read_package_json(&fixture.path, &out_dir).unwrap();
assert_eq!(pkg.homepage, None);
}

#[test]
fn it_does_not_error_when_wasm_bindgen_is_declared() {
let fixture = fixture::js_hello_world();
Expand Down
1 change: 1 addition & 0 deletions tests/all/utils/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct NpmPackage {
pub types: String,
#[serde(default = "default_none", rename = "sideEffects")]
pub side_effects: String,
pub homepage: Option<String>,
}

fn default_none() -> String {
Expand Down