mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-20 16:26:33 +00:00
Switch the --browser
argument to --web
This commit reverts part of the implementation of [RFC 6]. That RFC specified that the `--browser` flag was going to be repurposed for the new "natively loadable as ES module output", but unfortunately the breakage is far broader than initially expected. It turns out that `wasm-pack` passes `--browser` by default which means that a change to break `--browser` would break all historical versions of `wasm-pack` which is a bit much for now. To solve this the `--browser` flag is going back to what it represents on the current released version of `wasm-bindgen` (optimize away some node.js checks in a few places for bundler-style output) and a new `--web` flag is being introduced as the new deployment strategy. [RFC 6]: https://github.com/rustwasm/rfcs/pull/6 Closes #1318
This commit is contained in:
@ -36,8 +36,8 @@ pub struct Bindgen {
|
||||
}
|
||||
|
||||
enum OutputMode {
|
||||
Bundler,
|
||||
Browser,
|
||||
Bundler { browser_only: bool },
|
||||
Web,
|
||||
NoModules { global: String },
|
||||
Node { experimental_modules: bool },
|
||||
}
|
||||
@ -59,7 +59,7 @@ impl Bindgen {
|
||||
Bindgen {
|
||||
input: Input::None,
|
||||
out_name: None,
|
||||
mode: OutputMode::Bundler,
|
||||
mode: OutputMode::Bundler { browser_only: false },
|
||||
debug: false,
|
||||
typescript: false,
|
||||
demangle: true,
|
||||
@ -93,7 +93,7 @@ impl Bindgen {
|
||||
|
||||
fn switch_mode(&mut self, mode: OutputMode, flag: &str) -> Result<(), Error> {
|
||||
match self.mode {
|
||||
OutputMode::Bundler => self.mode = mode,
|
||||
OutputMode::Bundler { .. } => self.mode = mode,
|
||||
_ => bail!(
|
||||
"cannot specify `{}` with another output mode already specified",
|
||||
flag
|
||||
@ -126,9 +126,9 @@ impl Bindgen {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn browser(&mut self, browser: bool) -> Result<&mut Bindgen, Error> {
|
||||
if browser {
|
||||
self.switch_mode(OutputMode::Browser, "--browser")?;
|
||||
pub fn web(&mut self, web: bool) -> Result<&mut Bindgen, Error> {
|
||||
if web {
|
||||
self.switch_mode(OutputMode::Web, "--web")?;
|
||||
}
|
||||
Ok(self)
|
||||
}
|
||||
@ -145,6 +145,16 @@ impl Bindgen {
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn browser(&mut self, browser: bool) -> Result<&mut Bindgen, Error> {
|
||||
if browser {
|
||||
match &mut self.mode {
|
||||
OutputMode::Bundler { browser_only } => *browser_only = true,
|
||||
_ => bail!("cannot specify `--browser` with other output types"),
|
||||
}
|
||||
}
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn no_modules_global(&mut self, name: &str) -> Result<&mut Bindgen, Error> {
|
||||
match &mut self.mode {
|
||||
OutputMode::NoModules { global } => *global = name.to_string(),
|
||||
@ -660,15 +670,16 @@ impl OutputMode {
|
||||
|
||||
fn always_run_in_browser(&self) -> bool {
|
||||
match self {
|
||||
OutputMode::Browser => true,
|
||||
OutputMode::Web => true,
|
||||
OutputMode::NoModules { .. } => true,
|
||||
OutputMode::Bundler { browser_only } => *browser_only,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn browser(&self) -> bool {
|
||||
fn web(&self) -> bool {
|
||||
match self {
|
||||
OutputMode::Browser => true,
|
||||
OutputMode::Web => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user