Skip to content

Remove faulty location.href fallback and disable --split-linked-modules by default #3279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
test_wasm_bindgen:
name: "Run wasm-bindgen crate tests (unix)"
runs-on: ubuntu-latest
env:
WASM_BINDGEN_SPLIT_LINKED_MODULES: 1
steps:
- uses: actions/checkout@v2
- run: rustup update --no-self-update stable && rustup default stable
Expand Down
6 changes: 2 additions & 4 deletions crates/cli-support/src/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,7 @@ impl<'a> Context<'a> {
js.push_str("let script_src;\n");
js.push_str(
"\
if (typeof document === 'undefined') {
script_src = location.href;
} else {
if (typeof document !== 'undefined') {
script_src = new URL(document.currentScript.src, location.href).toString();
}\n",
);
Expand Down Expand Up @@ -720,7 +718,7 @@ impl<'a> Context<'a> {
stem = self.config.stem()?
),
OutputMode::NoModules { .. } => "\
if (typeof input === 'undefined') {
if (typeof input === 'undefined' && script_src !== 'undefined') {
input = script_src.replace(/\\.js$/, '_bg.wasm');
}"
.to_string(),
Expand Down
2 changes: 1 addition & 1 deletion crates/cli-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl Bindgen {
wasm_interface_types,
encode_into: EncodeInto::Test,
omit_default_module_path: true,
split_linked_modules: true,
split_linked_modules: false,
}
}

Expand Down
4 changes: 4 additions & 0 deletions crates/cli/src/bin/wasm-bindgen-test-runner/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ integration test.\
TestMode::NoModule => b.no_modules(true)?,
};

if std::env::var("WASM_BINDGEN_SPLIT_LINKED_MODULES").is_ok() {
b.split_linked_modules(true);
}

b.debug(debug)
.input_module(module, wasm)
.keep_debug(false)
Expand Down
6 changes: 2 additions & 4 deletions crates/cli/tests/wasm-bindgen/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,14 @@ fn default_module_path_target_no_modules() {
fs::read_to_string(out_dir.join("default_module_path_target_no_modules.js")).unwrap();
assert!(contents.contains(
"\
if (typeof document === 'undefined') {
script_src = location.href;
} else {
if (typeof document !== 'undefined') {
script_src = new URL(document.currentScript.src, location.href).toString();
}",
));
assert!(contents.contains(
"\
async function init(input) {
if (typeof input === 'undefined') {
if (typeof input === 'undefined' && script_src !== 'undefined') {
input = script_src.replace(/\\.js$/, '_bg.wasm');
}",
));
Expand Down
4 changes: 4 additions & 0 deletions guide/src/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,7 @@ using a plugin. Alternatively, you can leave the syntax as is and instead
manually configure the bundler to copy all files in `snippets/` to the output
directory, preserving their paths relative to whichever bundled file ends up
containing the JS shim.

On the no-modules target, `link_to!` won't work if used outside of a document,
e.g. inside a worker. This is because it's impossible to figure out what the
URL of the linked module is without a reference point like `import.meta.url`.