Replace target flags with --target

This commit deprecates the `--web`, `--no-modules`, and `--nodejs` flags
in favor of one `--target` flag. The motivation for this commit is to be
consistent between `wasm-bindgen` and `wasm-pack` so documentation for
one is applicable for the other (so we don't have to document everywhere
what the translation is between flags). Additionally this should make it
a bit easier to add new targets (if necessary) in the future as it won't
add to the proliferation of flags.

For now the old flags (like `--web`) continue to be accepted, but
they'll be removed during the next set of breaking changes for
`wasm-bindgen`.
This commit is contained in:
Alex Crichton
2019-03-19 11:25:13 -07:00
parent 93cab3d755
commit 995be7c027
12 changed files with 125 additions and 118 deletions

View File

@ -59,7 +59,9 @@ impl Bindgen {
Bindgen {
input: Input::None,
out_name: None,
mode: OutputMode::Bundler { browser_only: false },
mode: OutputMode::Bundler {
browser_only: false,
},
debug: false,
typescript: false,
demangle: true,
@ -108,7 +110,7 @@ impl Bindgen {
OutputMode::Node {
experimental_modules: false,
},
"--nodejs",
"--target nodejs",
)?;
}
Ok(self)
@ -126,9 +128,21 @@ impl Bindgen {
Ok(self)
}
pub fn bundler(&mut self, bundler: bool) -> Result<&mut Bindgen, Error> {
if bundler {
self.switch_mode(
OutputMode::Bundler {
browser_only: false,
},
"--target bundler",
)?;
}
Ok(self)
}
pub fn web(&mut self, web: bool) -> Result<&mut Bindgen, Error> {
if web {
self.switch_mode(OutputMode::Web, "--web")?;
self.switch_mode(OutputMode::Web, "--target web")?;
}
Ok(self)
}
@ -139,7 +153,7 @@ impl Bindgen {
OutputMode::NoModules {
global: "wasm_bindgen".to_string(),
},
"--no-modules",
"--target no-modules",
)?;
}
Ok(self)
@ -158,7 +172,7 @@ impl Bindgen {
pub fn no_modules_global(&mut self, name: &str) -> Result<&mut Bindgen, Error> {
match &mut self.mode {
OutputMode::NoModules { global } => *global = name.to_string(),
_ => bail!("can only specify `--no-modules-global` with `--no-modules`"),
_ => bail!("can only specify `--no-modules-global` with `--target no-modules`"),
}
Ok(self)
}