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

Fix sideEffects value in generated package.json should be boolean #649

Closed
wants to merge 2 commits into from
Closed
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
4 changes: 2 additions & 2 deletions src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ impl CrateData {
module: data.main,
homepage: data.homepage,
types: data.dts_file,
side_effects: "false".to_string(),
side_effects: false,
})
}

Expand Down Expand Up @@ -668,7 +668,7 @@ impl CrateData {
module: data.main,
homepage: data.homepage,
types: data.dts_file,
side_effects: "false".to_string(),
side_effects: false,
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/manifest/npm/esmodules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ pub struct ESModulesPackage {
#[serde(skip_serializing_if = "Option::is_none")]
pub types: Option<String>,
#[serde(rename = "sideEffects")]
pub side_effects: String,
pub side_effects: bool,
}
12 changes: 7 additions & 5 deletions tests/all/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ fn it_should_build_crates_in_a_workspace() {
"Cargo.toml",
r#"
[workspace]
members = ["blah"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not sure i understand this change- can you explain? otherwise this looks good!

members = ["it_should_build_crates_in_a_workspace"]
"#,
)
.file(
Path::new("blah").join("Cargo.toml"),
Path::new("it_should_build_crates_in_a_workspace").join("Cargo.toml"),
r#"
[package]
authors = ["The wasm-pack developers"]
description = "so awesome rust+wasm package"
license = "WTFPL"
name = "blah"
name = "it_should_build_crates_in_a_workspace"
repository = "https://github.com/rustwasm/wasm-pack.git"
version = "0.1.0"

Expand All @@ -50,7 +50,9 @@ fn it_should_build_crates_in_a_workspace() {
"#,
)
.file(
Path::new("blah").join("src").join("lib.rs"),
Path::new("it_should_build_crates_in_a_workspace")
.join("src")
.join("lib.rs"),
r#"
extern crate wasm_bindgen;
use wasm_bindgen::prelude::*;
Expand All @@ -62,7 +64,7 @@ fn it_should_build_crates_in_a_workspace() {
.install_local_wasm_bindgen();
fixture
.wasm_pack()
.current_dir(&fixture.path.join("blah"))
.current_dir(&fixture.path.join("it_should_build_crates_in_a_workspace"))
.arg("build")
.assert()
.success();
Expand Down
4 changes: 2 additions & 2 deletions tests/all/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ fn it_creates_a_package_json_default_path() {
);
assert_eq!(pkg.module, "js_hello_world.js");
assert_eq!(pkg.types, "js_hello_world.d.ts");
assert_eq!(pkg.side_effects, "false");
assert_eq!(pkg.side_effects, false);

let actual_files: HashSet<String> = pkg.files.into_iter().collect();
let expected_files: HashSet<String> = [
Expand Down Expand Up @@ -252,7 +252,7 @@ fn it_creates_a_package_json_with_correct_files_when_out_name_is_provided() {
);
assert_eq!(pkg.module, "index.js");
assert_eq!(pkg.types, "index.d.ts");
assert_eq!(pkg.side_effects, "false");
assert_eq!(pkg.side_effects, false);

let actual_files: HashSet<String> = pkg.files.into_iter().collect();
let expected_files: HashSet<String> = ["index_bg.wasm", "index.d.ts", "index.js"]
Expand Down
8 changes: 6 additions & 2 deletions tests/all/utils/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ pub struct NpmPackage {
pub browser: String,
#[serde(default = "default_none")]
pub types: String,
#[serde(default = "default_none", rename = "sideEffects")]
pub side_effects: String,
#[serde(default = "default_false", rename = "sideEffects")]
pub side_effects: bool,
pub homepage: Option<String>,
}

fn default_none() -> String {
"".to_string()
}

fn default_false() -> bool {
false
}

#[derive(Deserialize)]
pub struct Repository {
#[serde(rename = "type")]
Expand Down