Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--no-pack flag #1291

Merged
merged 5 commits into from
May 30, 2023
Merged
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
24 changes: 19 additions & 5 deletions src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -171,6 +172,10 @@ pub struct BuildOptions {
/// Sets the output file names. Defaults to package name.
pub out_name: Option<String>,

#[structopt(long = "no-pack", alias = "no-package")]
/// 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<String>,
Expand All @@ -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(),
Expand Down Expand Up @@ -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,
Expand All @@ -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();

Expand All @@ -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),+) => {
{
Expand All @@ -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
}

Expand Down
16 changes: 16 additions & 0 deletions tests/all/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,22 @@ 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_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]
fn it_should_build_crates_in_a_workspace() {
let fixture = utils::fixture::Fixture::new();
Expand Down