Skip to content

Commit 1723186

Browse files
Add a --debug option to suppress --release.
1 parent 8102538 commit 1723186

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

src/bindgen.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,24 @@ pub fn cargo_install_wasm_bindgen() -> Result<(), Error> {
2828
}
2929
}
3030

31-
pub fn wasm_bindgen_build(path: &str, name: &str, disable_dts: bool) -> Result<(), Error> {
31+
pub fn wasm_bindgen_build(
32+
path: &str,
33+
name: &str,
34+
disable_dts: bool,
35+
debug: bool,
36+
) -> Result<(), Error> {
3237
let step = format!(
3338
"{} {}Running WASM-bindgen...",
3439
style("[7/7]").bold().dim(),
3540
emoji::RUNNER
3641
);
3742
let pb = PBAR.message(&step);
3843
let binary_name = name.replace("-", "_");
39-
let wasm_path = format!("target/wasm32-unknown-unknown/release/{}.wasm", binary_name);
44+
let release_or_debug = if debug { "debug" } else { "release" };
45+
let wasm_path = format!(
46+
"target/wasm32-unknown-unknown/{}/{}.wasm",
47+
release_or_debug, binary_name
48+
);
4049
let dts_arg = if disable_dts == false {
4150
"--typescript"
4251
} else {

src/build.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,22 @@ pub fn rustup_add_wasm_target() -> Result<(), Error> {
2525
}
2626
}
2727

28-
pub fn cargo_build_wasm(path: &str) -> Result<(), Error> {
28+
pub fn cargo_build_wasm(path: &str, debug: bool) -> Result<(), Error> {
2929
let step = format!(
3030
"{} {}Compiling to WASM...",
3131
style("[2/7]").bold().dim(),
3232
emoji::CYCLONE
3333
);
3434
let pb = PBAR.message(&step);
35-
let output = Command::new("cargo")
36-
.current_dir(path)
37-
.arg("build")
38-
.arg("--release")
39-
.arg("--target")
40-
.arg("wasm32-unknown-unknown")
41-
.output()?;
35+
let output = {
36+
let mut cmd = Command::new("cargo");
37+
cmd.current_dir(path).arg("build");
38+
if !debug {
39+
cmd.arg("--release");
40+
}
41+
cmd.arg("--target").arg("wasm32-unknown-unknown");
42+
cmd.output()?
43+
};
4244
pb.finish();
4345
if !output.status.success() {
4446
let s = String::from_utf8_lossy(&output.stderr);

src/command.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ pub enum Command {
2424
scope: Option<String>,
2525
#[structopt(long = "no-typescript")]
2626
disable_dts: bool,
27+
#[structopt(long = "debug")]
28+
/// Build without --release.
29+
debug: bool,
2730
},
2831

2932
#[structopt(name = "pack")]
@@ -67,7 +70,8 @@ pub fn run_wasm_pack(command: Command) -> result::Result<(), Error> {
6770
path,
6871
scope,
6972
disable_dts,
70-
} => init(path, scope, disable_dts),
73+
debug,
74+
} => init(path, scope, disable_dts, debug),
7175
Command::Pack { path } => pack(path),
7276
Command::Publish { path } => publish(path),
7377
Command::Login {
@@ -114,19 +118,20 @@ fn init(
114118
path: Option<String>,
115119
scope: Option<String>,
116120
disable_dts: bool,
121+
debug: bool,
117122
) -> result::Result<(), Error> {
118123
let started = Instant::now();
119124

120125
let crate_path = set_crate_path(path);
121126

122127
build::rustup_add_wasm_target()?;
123-
build::cargo_build_wasm(&crate_path)?;
128+
build::cargo_build_wasm(&crate_path, debug)?;
124129
create_pkg_dir(&crate_path)?;
125130
manifest::write_package_json(&crate_path, scope, disable_dts)?;
126131
readme::copy_from_crate(&crate_path)?;
127132
bindgen::cargo_install_wasm_bindgen()?;
128133
let name = manifest::get_crate_name(&crate_path)?;
129-
bindgen::wasm_bindgen_build(&crate_path, &name, disable_dts)?;
134+
bindgen::wasm_bindgen_build(&crate_path, &name, disable_dts, debug)?;
130135
PBAR.message(&format!(
131136
"{} Done in {}",
132137
emoji::SPARKLE,

0 commit comments

Comments
 (0)