Skip to content

Commit

Permalink
Fix experimental-nodejs-module target with #[wasm_bindgen(start)] (
Browse files Browse the repository at this point in the history
  • Loading branch information
kawaemon authored Oct 8, 2024
1 parent e6e098d commit 8a8f65c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
* Fixed multiline doc comment alignment and remove empty ones entirely.
[#4135](https://github.com/rustwasm/wasm-bindgen/pull/4135)

* Fixed `experimental-nodejs-module` target when used with `#[wasm_bindgen(start)]`.
[#4093](https://github.com/rustwasm/wasm-bindgen/pull/4093)

--------------------------------------------------------------------------------

## [0.2.93](https://github.com/rustwasm/wasm-bindgen/compare/0.2.92...0.2.93)
Expand Down
19 changes: 19 additions & 0 deletions crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,25 @@ impl<'a> Context<'a> {
module_name
))));
}

match self.config.mode {
OutputMode::Bundler { .. } => {
start.get_or_insert_with(String::new).push_str(&format!(
"\
import {{ __wbg_set_wasm }} from \"./{module_name}_bg.js\";
__wbg_set_wasm(wasm);"
));
}

OutputMode::Node { module: true } => {
start.get_or_insert_with(String::new).push_str(&format!(
"imports[\"./{module_name}_bg.js\"].__wbg_set_wasm(wasm);"
));
}

_ => {}
}

if needs_manual_start {
start
.get_or_insert_with(String::new)
Expand Down
8 changes: 2 additions & 6 deletions crates/cli-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,21 +701,17 @@ impl Output {
write(
&js_path,
format!(
"
import {{ __wbg_set_wasm }} from \"./{js_name}\";
"\
{start}
__wbg_set_wasm(wasm);
export * from \"./{js_name}\";",
),
)?;
} else {
write(
&js_path,
format!(
"
"\
import * as wasm from \"./{wasm_name}.wasm\";
import {{ __wbg_set_wasm }} from \"./{js_name}\";
__wbg_set_wasm(wasm);
export * from \"./{js_name}\";
{start}"
),
Expand Down

0 comments on commit 8a8f65c

Please sign in to comment.