Skip to content

Commit e2f942c

Browse files
committed
Rename option and improve documentation
1 parent 39bec64 commit e2f942c

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

crates/cli-support/src/js/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,7 +3148,7 @@ impl<'a> Context<'a> {
31483148
assert!(kind == AdapterJsImportKind::Normal);
31493149
assert!(!variadic);
31503150
assert_eq!(args.len(), 0);
3151-
if self.config.allow_links {
3151+
if self.config.split_linked_modules {
31523152
let base = match self.config.mode {
31533153
OutputMode::Web
31543154
| OutputMode::Bundler { .. }
@@ -3173,8 +3173,8 @@ impl<'a> Context<'a> {
31733173
"\"data:application/javascript,\" + encodeURIComponent(`{escaped}`)"
31743174
))
31753175
} else {
3176-
Err(anyhow!("wasm-bindgen needs to be invoked with `--allow-links`, because \"{}\" cannot be embedded.\n\
3177-
See https://rustwasm.github.io/wasm-bindgen/reference/cli.html#--allow-links for details.", path))
3176+
Err(anyhow!("wasm-bindgen needs to be invoked with `--split-linked-modules`, because \"{}\" cannot be embedded.\n\
3177+
See https://rustwasm.github.io/wasm-bindgen/reference/cli.html#--split-linked-modules for details.", path))
31783178
}
31793179
}
31803180
}

crates/cli-support/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub struct Bindgen {
4646
multi_value: bool,
4747
wasm_interface_types: bool,
4848
encode_into: EncodeInto,
49-
allow_links: bool,
49+
split_linked_modules: bool,
5050
}
5151

5252
pub struct Output {
@@ -121,7 +121,7 @@ impl Bindgen {
121121
wasm_interface_types,
122122
encode_into: EncodeInto::Test,
123123
omit_default_module_path: true,
124-
allow_links: true,
124+
split_linked_modules: true,
125125
}
126126
}
127127

@@ -306,8 +306,8 @@ impl Bindgen {
306306
self
307307
}
308308

309-
pub fn allow_links(&mut self, allow_links: bool) -> &mut Bindgen {
310-
self.allow_links = allow_links;
309+
pub fn split_linked_modules(&mut self, split_linked_modules: bool) -> &mut Bindgen {
310+
self.split_linked_modules = split_linked_modules;
311311
self
312312
}
313313

crates/cli/src/bin/wasm-bindgen.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ Options:
3636
--remove-name-section Remove the debugging `name` section of the file
3737
--remove-producers-section Remove the telemetry `producers` section
3838
--omit-default-module-path Don't add WebAssembly fallback imports in generated JavaScript
39-
--allow-links Allow to use the `new URL('…', import.meta.url)` syntax
39+
--split-linked-modules Split linked modules out into their own files. Recommended if possible.
40+
If a bundler is used, it needs to be set up accordingly.
4041
--encode-into MODE Whether or not to use TextEncoder#encodeInto,
4142
valid values are [test, always, never]
4243
--nodejs Deprecated, use `--target nodejs`
@@ -45,6 +46,8 @@ Options:
4546
--weak-refs Enable usage of the JS weak references proposal
4647
--reference-types Enable usage of WebAssembly reference types
4748
-V --version Print the version number of wasm-bindgen
49+
50+
Additional documentation: https://rustwasm.github.io/wasm-bindgen/reference/cli.html
4851
";
4952

5053
#[derive(Debug, Deserialize)]
@@ -71,7 +74,7 @@ struct Args {
7174
flag_encode_into: Option<String>,
7275
flag_target: Option<String>,
7376
flag_omit_default_module_path: bool,
74-
flag_allow_links: bool,
77+
flag_split_linked_modules: bool,
7578
arg_input: Option<PathBuf>,
7679
}
7780

@@ -126,7 +129,7 @@ fn rmain(args: &Args) -> Result<(), Error> {
126129
.typescript(typescript)
127130
.omit_imports(args.flag_omit_imports)
128131
.omit_default_module_path(args.flag_omit_default_module_path)
129-
.allow_links(args.flag_allow_links);
132+
.split_linked_modules(args.flag_split_linked_modules);
130133
if let Some(true) = args.flag_weak_refs {
131134
b.weak_refs(true);
132135
}

guide/src/reference/cli.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,16 @@ about reference types](./reference-types.md).
105105

106106
Don't add WebAssembly fallback imports in generated JavaScript.
107107

108-
### `--allow-links`
108+
### `--split-linked-modules`
109109

110-
Allow to use the `new URL('…', import.meta.url)` link syntax. This is safe with
111-
webpack 5 or no bundler at all.
110+
Controls whether wasm-bindgen will split linked modules out into their own files.
111+
Enabling this is recommended, because it allows lazy loading and setting a
112+
stricter Content Security Policy.
113+
114+
wasm-bindgen uses the `new URL('…', import.meta.url)` syntax to link such split
115+
out files. This is directly supported when using webpack 5 or no bundler at all.
112116

113117
For other bundlers, ensure they support the link syntax, possibly by enabling an
114-
extra plugin. Alternatively, configure the bundler to keep the link syntax as is
115-
and to copy all files in `snippets/` to the output directory preserving their
116-
paths.
118+
extra plugin. That's why this option is disabled by default. Alternatively,
119+
configure the bundler to keep the link syntax as is and to copy all files in
120+
`snippets/` to the output directory preserving their paths.

0 commit comments

Comments
 (0)