Skip to content
Open
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
2 changes: 1 addition & 1 deletion src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn wasm_bindgen_build(
reference_types: bool,
target: Target,
profile: BuildProfile,
extra_options: &Vec<String>,
extra_options: &[String],
) -> Result<()> {
let profile_name = match profile.clone() {
BuildProfile::Release | BuildProfile::Profiling => "release",
Expand Down
4 changes: 2 additions & 2 deletions src/build/wasm_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ pub fn check_for_wasm32_target() -> Result<()> {
/// Get rustc's sysroot as a PathBuf
fn get_rustc_sysroot() -> Result<PathBuf> {
let command = Command::new("rustc")
.args(&["--print", "sysroot"])
.args(["--print", "sysroot"])
.output()?;

if command.status.success() {
Expand All @@ -84,7 +84,7 @@ fn get_rustc_sysroot() -> Result<PathBuf> {
/// Get wasm32-unknown-unknown target libdir
fn get_rustc_wasm32_unknown_unknown_target_libdir() -> Result<PathBuf> {
let command = Command::new("rustc")
.args(&[
.args([
"--target",
"wasm32-unknown-unknown",
"--print",
Expand Down
34 changes: 3 additions & 31 deletions src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ pub struct Build {

/// What sort of output we're going to be generating and flags we're invoking
/// `wasm-bindgen` with.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Default)]
pub enum Target {
/// Default output mode or `--target bundler`, indicates output will be
/// used with a bundle in a later step.
#[default]
Bundler,
/// Correspond to `--target web` where the output is natively usable as an
/// ES module in a browser and the wasm is manually instantiated.
Expand All @@ -65,12 +66,6 @@ pub enum Target {
Deno,
}

impl Default for Target {
fn default() -> Target {
Target::Bundler
}
}

impl fmt::Display for Target {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = match self {
Expand Down Expand Up @@ -115,6 +110,7 @@ pub enum BuildProfile {
/// Everything required to configure and run the `wasm-pack build` command.
#[derive(Debug, Args)]
#[command(allow_hyphen_values = true, trailing_var_arg = true)]
#[derive(Default)]
pub struct BuildOptions {
/// The path to the Rust crate. If not set, searches up the path from the current directory.
#[clap()]
Expand Down Expand Up @@ -186,30 +182,6 @@ pub struct BuildOptions {
pub extra_options: Vec<String>,
}

impl Default for BuildOptions {
fn default() -> Self {
Self {
path: None,
scope: None,
mode: InstallMode::default(),
disable_dts: false,
weak_refs: false,
reference_types: false,
target: Target::default(),
debug: false,
dev: false,
no_pack: false,
no_opt: false,
release: false,
profiling: false,
profile: None,
out_dir: String::new(),
out_name: None,
extra_options: Vec::new(),
}
}
}

type BuildStep = fn(&mut Build) -> Result<()>;

impl Build {
Expand Down
4 changes: 2 additions & 2 deletions src/command/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ pub fn login(
&scope, &registry, &auth_type
);
info!("npm info located in the npm debug log");
npm::npm_login(&registry, &scope, &auth_type)?;
npm::npm_login(&registry, scope, auth_type)?;
info!("Logged you in!");

PBAR.info(&"👋 logged you in!".to_string());
PBAR.info("👋 logged you in!");
Ok(())
}
4 changes: 2 additions & 2 deletions src/command/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Test {
} = test_opts;

let first_arg_is_path = path_and_extra_options
.get(0)
.first()
.map(|first_arg| !first_arg.starts_with("-"))
.unwrap_or(false);

Expand Down Expand Up @@ -295,7 +295,7 @@ impl Test {
let status = install::download_prebuilt_or_cargo_install(
Tool::WasmBindgen,
&self.cache,
&bindgen_version,
bindgen_version,
self.mode.install_permitted(),
)?;

Expand Down
4 changes: 2 additions & 2 deletions src/command/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn find_manifest_from_cwd() -> Result<PathBuf> {
/// Construct our `pkg` directory in the crate.
pub fn create_pkg_dir(out_dir: &Path) -> Result<()> {
let _ = fs::remove_file(out_dir.join("package.json")); // Clean up package.json from previous runs
fs::create_dir_all(&out_dir)?;
fs::create_dir_all(out_dir)?;
fs::write(out_dir.join(".gitignore"), "*")?;
Ok(())
}
Expand All @@ -53,7 +53,7 @@ pub fn find_pkg_directory(path: &Path, pkg_directory: &Path) -> Option<PathBuf>
WalkDir::new(path)
.into_iter()
.filter_map(|x| x.ok().map(|e| e.into_path()))
.find(|x| is_pkg_directory(&x, pkg_directory))
.find(|x| is_pkg_directory(x, pkg_directory))
}

fn is_pkg_directory(path: &Path, pkg_directory: &Path) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ pub fn generate(template: &str, name: &str, install_status: &install::Status) ->
.binary(&Tool::CargoGenerate.to_string())?;
let mut cmd = Command::new(&bin_path);
cmd.arg("generate");
cmd.arg("--git").arg(&template);
cmd.arg("--name").arg(&name);
cmd.arg("--git").arg(template);
cmd.arg("--name").arg(name);

println!(
"{} Generating a new rustwasm project with name '{}'...",
Expand Down
2 changes: 1 addition & 1 deletion src/install/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ pub fn get_cli_version(tool: &Tool, path: &Path) -> Result<String> {
let mut cmd = Command::new(path);
cmd.arg("--version");
let stdout = child::run_capture_stdout(cmd, tool)?;
let version = stdout.trim().split_whitespace().nth(1);
let version = stdout.split_whitespace().nth(1);
match version {
Some(v) => Ok(v.to_string()),
None => bail!("Something went wrong! We couldn't determine your version of the wasm-bindgen CLI. We were supposed to set that up for you, so it's likely not your fault! You should file an issue: https://github.com/drager/wasm-pack/issues/new?template=bug_report.md.")
Expand Down
9 changes: 2 additions & 7 deletions src/install/mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use std::str::FromStr;

/// The `InstallMode` determines which mode of initialization we are running, and
/// what install steps we perform.
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, Default)]
pub enum InstallMode {
/// Perform all the install steps.
#[default]
Normal,
/// Don't install tools like `wasm-bindgen`, just use the global
/// environment's existing versions to do builds.
Expand All @@ -14,12 +15,6 @@ pub enum InstallMode {
Force,
}

impl Default for InstallMode {
fn default() -> InstallMode {
InstallMode::Normal
}
}

impl FromStr for InstallMode {
type Err = Error;
fn from_str(s: &str) -> Result<Self> {
Expand Down
1 change: 0 additions & 1 deletion src/installer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use std::path::Path;
use std::process;

use anyhow::{anyhow, bail, Context, Result};
use which;

pub fn install() -> ! {
if let Err(e) = do_install() {
Expand Down
4 changes: 2 additions & 2 deletions src/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ fn glob_license_files(path: &Path) -> Result<Vec<String>> {
/// Copy the crate's license into the `pkg` directory.
pub fn copy_from_crate(crate_data: &CrateData, path: &Path, out_dir: &Path) -> Result<()> {
assert!(
fs::metadata(path).ok().map_or(false, |m| m.is_dir()),
fs::metadata(path).ok().is_some_and(|m| m.is_dir()),
"crate directory should exist"
);

assert!(
fs::metadata(&out_dir).ok().map_or(false, |m| m.is_dir()),
fs::metadata(out_dir).ok().is_some_and(|m| m.is_dir()),
"crate's pkg directory should exist"
);

Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn run() -> Result<()> {
let wasm_pack_version = background_check_for_updates();

// Deprecate `init`
if let Some("init") = env::args().nth(1).as_ref().map(|arg| arg.as_str()) {
if let Some("init") = env::args().nth(1).as_deref() {
println!("wasm-pack init is deprecated, consider using wasm-pack build");
}

Expand Down Expand Up @@ -111,7 +111,7 @@ fn setup_panic_hooks() {
let default_hook = panic::take_hook();

if let Err(_) = env::var("RUST_BACKTRACE") {
panic::set_hook(Box::new(move |info: &panic::PanicInfo| {
panic::set_hook(Box::new(move |info: &panic::PanicHookInfo| {
// First call the default hook that prints to standard error.
default_hook(info);

Expand Down
19 changes: 9 additions & 10 deletions src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ impl Crate {

match old_metadata_file {
Some(ref file_contents) => {
let last_updated = Self::return_stamp_file_value(&file_contents, "created")
let last_updated = Self::return_stamp_file_value(file_contents, "created")
.and_then(|t| DateTime::parse_from_str(t.as_str(), "%+").ok());

last_updated
.map(|last_updated| {
if current_time.signed_duration_since(last_updated).num_hours() > 24 {
Self::return_api_call_result(current_time).map(Some)
} else {
Ok(Self::return_stamp_file_value(&file_contents, "version"))
Ok(Self::return_stamp_file_value(file_contents, "version"))
}
})
.unwrap_or_else(|| Ok(None))
Expand All @@ -177,7 +177,7 @@ impl Crate {
// "policy" as the success. This means that the 24 hours rate limiting
// will be active regardless if the check succeeded or failed.
match version {
Ok(ref version) => Self::override_stamp_file(current_time, Some(&version)).ok(),
Ok(ref version) => Self::override_stamp_file(current_time, Some(version)).ok(),
Err(_) => Self::override_stamp_file(current_time, None).ok(),
};

Expand All @@ -192,7 +192,6 @@ impl Crate {

let mut file = fs::OpenOptions::new()
.read(true)
.write(true)
.append(true)
.create(true)
.open(path.with_extension("stamp"))?;
Expand Down Expand Up @@ -240,7 +239,7 @@ impl Crate {
.try_proxy_from_env(true)
.user_agent(&format!(
"wasm-pack/{} ({})",
WASM_PACK_VERSION.unwrap_or_else(|| "unknown"),
WASM_PACK_VERSION.unwrap_or("unknown"),
WASM_PACK_REPO_URL
))
.build();
Expand All @@ -251,7 +250,7 @@ impl Crate {

let status_code = resp.status();

if 200 <= status_code && status_code < 300 {
if (200..300).contains(&status_code) {
let json = resp.into_json()?;

Ok(json)
Expand Down Expand Up @@ -473,8 +472,8 @@ impl CrateData {
}

fn is_same_path(path1: &Path, path2: &Path) -> bool {
if let Ok(path1) = fs::canonicalize(&path1) {
if let Ok(path2) = fs::canonicalize(&path2) {
if let Ok(path1) = fs::canonicalize(path1) {
if let Ok(path2) = fs::canonicalize(path2) {
return path1 == path2;
}
}
Expand All @@ -489,7 +488,7 @@ impl CrateData {
/// Will return Err if the file (manifest_path) couldn't be read or
/// if deserialize to `CargoManifest` fails.
pub fn parse_crate_data(manifest_path: &Path) -> Result<ManifestAndUnsedKeys> {
let manifest = fs::read_to_string(&manifest_path)
let manifest = fs::read_to_string(manifest_path)
.with_context(|| anyhow!("failed to read: {}", manifest_path.display()))?;
let manifest = toml::Deserializer::new(&manifest);

Expand Down Expand Up @@ -683,7 +682,7 @@ impl CrateData {
None
};

let keywords = if pkg.keywords.len() > 0 {
let keywords = if !pkg.keywords.is_empty() {
Some(pkg.keywords.clone())
} else {
None
Expand Down
2 changes: 1 addition & 1 deletion src/npm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn npm_pack(path: &str) -> Result<()> {
pub fn npm_publish(path: &str, access: Option<Access>, tag: Option<String>) -> Result<()> {
let mut cmd = child::new_command("npm");
match access {
Some(a) => cmd.current_dir(path).arg("publish").arg(&a.to_string()),
Some(a) => cmd.current_dir(path).arg("publish").arg(a.to_string()),
None => cmd.current_dir(path).arg("publish"),
};
if let Some(tag) = tag {
Expand Down
4 changes: 2 additions & 2 deletions src/readme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ use crate::PBAR;
/// Copy the crate's README into the `pkg` directory.
pub fn copy_from_crate(crate_data: &CrateData, path: &Path, out_dir: &Path) -> Result<()> {
assert!(
fs::metadata(path).ok().map_or(false, |m| m.is_dir()),
fs::metadata(path).ok().is_some_and(|m| m.is_dir()),
"crate directory should exist"
);
assert!(
fs::metadata(&out_dir).ok().map_or(false, |m| m.is_dir()),
fs::metadata(out_dir).ok().is_some_and(|m| m.is_dir()),
"crate's pkg directory should exist"
);

Expand Down
2 changes: 1 addition & 1 deletion src/test/webdriver/geckodriver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub fn install_geckodriver(cache: &Cache, installation_allowed: bool) -> Result<
///
/// It returns the latest one without checking the installed `Firefox` version
/// - it should be relatively safe because each `geckodriver` supports many `Firefox` versions:
/// https://firefox-source-docs.mozilla.org/testing/geckodriver/Support.html#supported-platforms
/// <https://firefox-source-docs.mozilla.org/testing/geckodriver/Support.html#supported-platforms>
fn get_geckodriver_url(target: &str, ext: &str) -> String {
let fetch_and_save_version =
|| fetch_latest_geckodriver_tag_json().and_then(save_geckodriver_version);
Expand Down
Loading