From 927e716b87c69323375edb76438e1dd1e64fbda4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Sun, 11 Jun 2023 18:02:14 +0200 Subject: [PATCH 1/2] Revert "Respect package.readme in Cargo.toml" This reverts commit 22d6d728d021691729ef8d9acf839ec315da79e7. --- src/command/build.rs | 2 +- src/manifest/mod.rs | 8 ---- src/readme.rs | 9 +---- tests/all/readme.rs | 90 ++------------------------------------------ 4 files changed, 7 insertions(+), 102 deletions(-) diff --git a/src/command/build.rs b/src/command/build.rs index ad50e08..f16d797 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -376,7 +376,7 @@ impl Build { fn step_copy_readme(&mut self) -> Result<()> { info!("Copying readme from crate..."); - readme::copy_from_crate(&self.crate_data, &self.crate_path, &self.out_dir)?; + readme::copy_from_crate(&self.crate_path, &self.out_dir)?; info!("Copied readme from crate to {:#?}.", &self.out_dir); Ok(()) } diff --git a/src/manifest/mod.rs b/src/manifest/mod.rs index 5557553..f6fcae9 100644 --- a/src/manifest/mod.rs +++ b/src/manifest/mod.rs @@ -541,14 +541,6 @@ impl CrateData { } } - /// Gets the optional path to the readme, or None if disabled. - pub fn crate_readme(&self) -> Option { - self.pkg() - .readme - .clone() - .map(|readme_file| readme_file.into_string()) - } - /// Get the license for the crate at the given path. pub fn crate_license(&self) -> &Option { &self.pkg().license diff --git a/src/readme.rs b/src/readme.rs index d82f5b3..c98cdc0 100644 --- a/src/readme.rs +++ b/src/readme.rs @@ -4,11 +4,10 @@ use anyhow::{Context, Result}; use std::fs; use std::path::Path; -use crate::manifest::CrateData; 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<()> { +pub fn copy_from_crate(path: &Path, out_dir: &Path) -> Result<()> { assert!( fs::metadata(path).ok().map_or(false, |m| m.is_dir()), "crate directory should exist" @@ -18,11 +17,7 @@ pub fn copy_from_crate(crate_data: &CrateData, path: &Path, out_dir: &Path) -> R "crate's pkg directory should exist" ); - let crate_readme_path = match crate_data.crate_readme() { - None => return Ok(()), - Some(readme_path) => path.join(readme_path), - }; - + let crate_readme_path = path.join("README.md"); let new_readme_path = out_dir.join("README.md"); if crate_readme_path.exists() { fs::copy(&crate_readme_path, &new_readme_path).context("failed to copy README")?; diff --git a/tests/all/readme.rs b/tests/all/readme.rs index 042e315..cefb01f 100644 --- a/tests/all/readme.rs +++ b/tests/all/readme.rs @@ -4,9 +4,6 @@ extern crate wasm_pack; use std::fs; use crate::utils::{self, fixture}; -use assert_cmd::prelude::*; -use predicates::boolean::PredicateBooleanExt; -use wasm_pack::manifest::CrateData; use wasm_pack::readme; #[test] @@ -14,9 +11,8 @@ fn it_copies_a_readme_default_path() { let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); - let crate_data = CrateData::new(&fixture.path, None).unwrap(); - assert!(readme::copy_from_crate(&crate_data, &fixture.path, &out_dir).is_ok()); + assert!(readme::copy_from_crate(&fixture.path, &out_dir).is_ok()); let crate_readme_path = fixture.path.join("README.md"); let pkg_readme_path = out_dir.join("README.md"); @@ -36,51 +32,12 @@ fn it_copies_a_readme_default_path() { #[test] fn it_copies_a_readme_provided_path() { - let fixture = 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 = "js-hello-world" - readme = "docs/README.md" - repository = "https://github.com/rustwasm/wasm-pack.git" - version = "0.1.0" - - [lib] - crate-type = ["cdylib"] - - [dependencies] - # Note that this uses and `=` dependency because there are - # various tests which assert that the version of wasm - # bindgen downloaded is what we expect, and if `=` is - # removed then it will download whatever the newest version - # of wasm-bindgen is which may not be what's listed here. - wasm-bindgen = "=0.2.74" - - [dev-dependencies] - wasm-bindgen-test = "0.3" - "#, - ) - .file( - "docs/README.md", - r#" - # Fixture! - > an example rust -> wasm project - "#, - ); - - let crate_docs_dir = fixture.path.join("docs"); + let fixture = fixture::js_hello_world(); let out_dir = fixture.path.join("pkg"); fs::create_dir(&out_dir).expect("should create pkg directory OK"); - let crate_data = CrateData::new(&fixture.path, None).unwrap(); - assert!(readme::copy_from_crate(&crate_data, &fixture.path, &out_dir).is_ok()); - let crate_readme_path = crate_docs_dir.join("README.md"); + assert!(readme::copy_from_crate(&fixture.path, &out_dir).is_ok()); + let crate_readme_path = fixture.path.join("README.md"); let pkg_readme_path = out_dir.join("README.md"); println!( "wasm-pack: should have copied README.md from '{}' to '{}'", @@ -94,42 +51,3 @@ fn it_copies_a_readme_provided_path() { let pkg_readme = utils::file::read_file(&pkg_readme_path).unwrap(); assert_eq!(crate_readme, pkg_readme); } - -#[test] -fn it_ignores_a_disabled_readme() { - let fixture = fixture::Fixture::new(); - fixture - .hello_world_src_lib() - .file( - "Cargo.toml", - r#" - [package] - authors = ["The wasm-pack developers"] - description = "so awesome rust+wasm package" - name = "js-hello-world" - readme = false - repository = "https://github.com/rustwasm/wasm-pack.git" - version = "0.1.0" - - [lib] - crate-type = ["cdylib"] - - [dependencies] - # Note that this uses and `=` dependency because there are - # various tests which assert that the version of wasm - # bindgen downloaded is what we expect, and if `=` is - # removed then it will download whatever the newest version - # of wasm-bindgen is which may not be what's listed here. - wasm-bindgen = "=0.2.74" - - [dev-dependencies] - wasm-bindgen-test = "0.3" - "#, - ) - .license() - .wasm_pack() - .arg("build") - .assert() - .success() - .stderr(predicates::str::contains("origin crate has no README").not()); -} From 673bc296fc6cd22dd799c3e00f1bd74b1355b028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jesper=20H=C3=A5kansson?= Date: Sun, 11 Jun 2023 18:06:30 +0200 Subject: [PATCH 2/2] chore: Run cargo fmt --- src/command/build.rs | 2 +- src/command/mod.rs | 4 ++-- src/command/test.rs | 4 ++-- src/lib.rs | 8 ++++---- src/main.rs | 4 ++-- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/command/build.rs b/src/command/build.rs index f16d797..f807323 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -14,12 +14,12 @@ use crate::wasm_opt; use crate::PBAR; use anyhow::{anyhow, bail, Error, Result}; use binary_install::Cache; +use clap::Args; use log::info; use std::fmt; use std::path::PathBuf; use std::str::FromStr; use std::time::Instant; -use clap::{Args}; /// Everything required to configure and run the `wasm-pack build` command. #[allow(missing_docs)] diff --git a/src/command/mod.rs b/src/command/mod.rs index dad39f4..c3e4edf 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -18,10 +18,10 @@ use self::publish::{access::Access, publish}; use self::test::{Test, TestOptions}; use crate::install::InstallMode; use anyhow::Result; +use clap::builder::ValueParser; +use clap::Subcommand; use log::info; use std::path::PathBuf; -use clap::Subcommand; -use clap::builder::ValueParser; /// The various kinds of commands that `wasm-pack` can execute. #[derive(Debug, Subcommand)] pub enum Command { diff --git a/src/command/test.rs b/src/command/test.rs index c093974..30b0e5f 100644 --- a/src/command/test.rs +++ b/src/command/test.rs @@ -9,13 +9,13 @@ use crate::manifest; use crate::test::{self, webdriver}; use anyhow::{bail, Result}; use binary_install::Cache; +use clap::builder::ValueParser; +use clap::Args; use console::style; use log::info; use std::path::PathBuf; use std::str::FromStr; use std::time::Instant; -use clap::Args; -use clap::builder::ValueParser; #[derive(Debug, Default, Args)] #[command(allow_hyphen_values = true, trailing_var_arg = true)] diff --git a/src/lib.rs b/src/lib.rs index af66554..e0df8b3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,12 +13,12 @@ extern crate strsim; extern crate which; #[macro_use] extern crate serde_derive; -extern crate serde_ignored; -extern crate serde_json; extern crate binary_install; extern crate chrono; extern crate dialoguer; extern crate log; +extern crate serde_ignored; +extern crate serde_json; extern crate toml; extern crate walkdir; @@ -41,9 +41,9 @@ pub mod target; pub mod test; pub mod wasm_opt; -use clap::Parser; -use clap::builder::ArgAction; use crate::progressbar::{LogLevel, ProgressOutput}; +use clap::builder::ArgAction; +use clap::Parser; /// The global progress bar and user-facing message output. pub static PBAR: ProgressOutput = ProgressOutput::new(); diff --git a/src/main.rs b/src/main.rs index 048561a..e8e0754 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,19 +2,19 @@ extern crate anyhow; extern crate atty; +extern crate clap; extern crate env_logger; extern crate human_panic; extern crate log; -extern crate clap; extern crate wasm_pack; extern crate which; use anyhow::Result; +use clap::Parser; use std::env; use std::panic; use std::sync::mpsc; use std::thread; -use clap::Parser; use wasm_pack::{ build::{self, WasmPackVersion}, command::run_wasm_pack,