Skip to content

Commit

Permalink
Merge pull request #1224 from Liamolucko/side-effects
Browse files Browse the repository at this point in the history
Mark snippets and the bundler target's main file as having side effects
  • Loading branch information
drager committed Mar 19, 2023
2 parents b4e619c + ad17780 commit 777e8ca
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -723,10 +723,10 @@ impl CrateData {
url: repo_url,
}),
files: data.files,
module: data.main,
module: data.main.clone(),
homepage: data.homepage,
types: data.dts_file,
side_effects: false,
side_effects: vec![format!("./{}", data.main), "./snippets/*".to_owned()],
keywords: data.keywords,
dependencies,
})
Expand Down Expand Up @@ -758,7 +758,7 @@ impl CrateData {
module: data.main,
homepage: data.homepage,
types: data.dts_file,
side_effects: false,
side_effects: vec!["./snippets/*".to_owned()],
keywords: data.keywords,
dependencies,
})
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 @@ -22,7 +22,7 @@ pub struct ESModulesPackage {
#[serde(skip_serializing_if = "Option::is_none")]
pub types: Option<String>,
#[serde(rename = "sideEffects")]
pub side_effects: bool,
pub side_effects: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub keywords: Option<Vec<String>>,
#[serde(skip_serializing_if = "Option::is_none")]
Expand Down
7 changes: 5 additions & 2 deletions tests/all/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,10 @@ 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,
vec!["./js_hello_world.js", "./snippets/*"]
);

let actual_files: HashSet<String> = pkg.files.into_iter().collect();
let expected_files: HashSet<String> = [
Expand Down Expand Up @@ -255,7 +258,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, vec!["./index.js", "./snippets/*"]);

let actual_files: HashSet<String> = pkg.files.into_iter().collect();
let expected_files: HashSet<String> =
Expand Down
8 changes: 2 additions & 6 deletions tests/all/utils/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ pub struct NpmPackage {
pub browser: String,
#[serde(default = "default_none")]
pub types: String,
#[serde(default = "default_false", rename = "sideEffects")]
pub side_effects: bool,
#[serde(default = "Vec::new", rename = "sideEffects")]
pub side_effects: Vec<String>,
pub homepage: Option<String>,
pub keywords: Option<Vec<String>>,
pub dependencies: Option<HashMap<String, String>>,
Expand All @@ -32,10 +32,6 @@ fn default_none() -> String {
"".to_string()
}

fn default_false() -> bool {
false
}

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

0 comments on commit 777e8ca

Please sign in to comment.