diff --git a/src/command/build.rs b/src/command/build.rs index 75374ad..096c51d 100644 --- a/src/command/build.rs +++ b/src/command/build.rs @@ -31,6 +31,7 @@ pub struct Build { pub weak_refs: bool, pub reference_types: bool, pub target: Target, + pub no_pack: bool, pub profile: BuildProfile, pub mode: InstallMode, pub out_dir: PathBuf, @@ -171,6 +172,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(allow_hyphen_values = true)] /// List of extra options to pass to `cargo build` pub extra_options: Vec, @@ -188,6 +193,7 @@ impl Default for BuildOptions { target: Target::default(), debug: false, dev: false, + no_pack: false, release: false, profiling: false, out_dir: String::new(), @@ -232,6 +238,7 @@ impl Build { weak_refs: build_opts.weak_refs, reference_types: build_opts.reference_types, target: build_opts.target, + no_pack: build_opts.no_pack, profile, mode: build_opts.mode, out_dir, @@ -249,7 +256,7 @@ impl Build { /// Execute this `Build` command. pub fn run(&mut self) -> Result<()> { - 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(); @@ -274,7 +281,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),+) => { { @@ -296,16 +303,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 6c42b48..11cc287 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();