From f53c6f5aa06cea8494b32102b294b7fd25d167bb Mon Sep 17 00:00:00 2001 From: Ashley Williams Date: Thu, 25 Jul 2019 12:50:26 -0500 Subject: [PATCH 1/3] feat(build): --no-pack flag --- src/command/build.rs | 24 +++++++++++++++++++----- tests/all/build.rs | 14 ++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/src/command/build.rs b/src/command/build.rs index 723f507..5c7a40b 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -28,6 +28,7 @@ pub struct Build { pub scope: Option, pub disable_dts: bool, pub target: Target, + pub no_pack: bool, pub profile: BuildProfile, pub mode: InstallMode, pub out_dir: PathBuf, @@ -148,6 +149,10 @@ pub struct BuildOptions { /// Sets the output file names. Defaults to package name. pub out_name: Option, + #[structopt(long = "no-pack")] + /// Option to not generate a package.json + pub no_pack: bool, + #[structopt(last = true)] /// List of extra options to pass to `cargo build` pub extra_options: Vec, @@ -163,6 +168,7 @@ impl Default for BuildOptions { target: Target::default(), debug: false, dev: false, + no_pack: false, release: false, profiling: false, out_dir: String::new(), @@ -197,6 +203,7 @@ impl Build { scope: build_opts.scope, disable_dts: build_opts.disable_dts, target: build_opts.target, + no_pack: build_opts.no_pack, profile, mode: build_opts.mode, out_dir, @@ -214,7 +221,7 @@ impl Build { /// Execute this `Build` command. pub fn run(&mut self) -> Result<(), Error> { - let process_steps = Build::get_process_steps(self.mode); + let process_steps = Build::get_process_steps(self.mode, self.no_pack); let started = Instant::now(); @@ -239,7 +246,7 @@ impl Build { Ok(()) } - fn get_process_steps(mode: InstallMode) -> Vec<(&'static str, BuildStep)> { + fn get_process_steps(mode: InstallMode, no_pack: bool) -> Vec<(&'static str, BuildStep)> { macro_rules! steps { ($($name:ident),+) => { { @@ -261,16 +268,23 @@ impl Build { ]); } } + steps.extend(steps![ step_build_wasm, step_create_dir, - step_copy_readme, - step_copy_license, step_install_wasm_bindgen, step_run_wasm_bindgen, step_run_wasm_opt, - step_create_json, ]); + + if !no_pack { + steps.extend(steps![ + step_create_json, + step_copy_readme, + step_copy_license, + ]); + } + steps } diff --git a/tests/all/build.rs b/tests/all/build.rs index 98581ae..ef7969c 100644 --- a/tests/all/build.rs +++ b/tests/all/build.rs @@ -21,6 +21,20 @@ fn it_should_build_js_hello_world_example() { fixture.wasm_pack().arg("build").assert().success(); } +#[test] +fn it_should_not_make_a_pkg_json_if_passed_no_pack() { + let fixture = utils::fixture::js_hello_world(); + fixture + .wasm_pack() + .arg("build") + .arg("--no-pack") + .assert() + .success(); + + let pkg_json_path = fixture.path.join("pkg").join("package.json"); + assert_eq!(pkg_json_path.exists(), false); +} + #[test] fn it_should_build_crates_in_a_workspace() { let fixture = utils::fixture::Fixture::new(); From 624ed91ec5ee6e98f920b7b5fd05a93adf1c4aec Mon Sep 17 00:00:00 2001 From: Muhammad Hamza Date: Tue, 30 May 2023 18:30:44 +0500 Subject: [PATCH 2/3] alias no-pack with no-package --- src/command/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/command/build.rs b/src/command/build.rs index 096c51d..77a9eae 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -172,7 +172,7 @@ pub struct BuildOptions { /// Sets the output file names. Defaults to package name. pub out_name: Option, - #[structopt(long = "no-pack")] + #[structopt(long = "no-pack", alias = "no-package")] /// Option to not generate a package.json pub no_pack: bool, From b6a30b02775c1e30a355285d98c8b45a4513534c Mon Sep 17 00:00:00 2001 From: Muhammad Hamza Date: Tue, 30 May 2023 20:20:04 +0500 Subject: [PATCH 3/3] assert non-existence of other files as well --- tests/all/build.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/all/build.rs b/tests/all/build.rs index 11cc287..4b87e4f 100644 --- a/tests/all/build.rs +++ b/tests/all/build.rs @@ -31,8 +31,10 @@ fn it_should_not_make_a_pkg_json_if_passed_no_pack() { .assert() .success(); - let pkg_json_path = fixture.path.join("pkg").join("package.json"); - assert_eq!(pkg_json_path.exists(), false); + let pkg_path = fixture.path.join("pkg"); + assert_eq!(pkg_path.join("package.json").exists(), false); + assert_eq!(pkg_path.join("README.md").exists(), false); + assert_eq!(pkg_path.join("licence").exists(), false); } #[test]