Skip to content
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

cli-support: Make default_module_path optional #2519

Merged
merged 1 commit into from Apr 19, 2021
Merged

cli-support: Make default_module_path optional #2519

merged 1 commit into from Apr 19, 2021

Conversation

realtimetodie
Copy link
Contributor

@realtimetodie realtimetodie commented Apr 7, 2021

Adds a new CLI flag --omit-default-module-path, to control the default_module_path generated JavaScript code.

The default_module_path generated JavaScript code is enabled by default, users need to explicitly disable it by setting the --omit-default-module-path CLI flag

$ wasm-bindgen --omit-default-module-path

Documentation

$ wasm-bindgen --help

Options:

...

--omit-default-module-path       Don't add WebAssembly fallback imports in generated JavaScript

Affected JavaScript code

$ wasm-bindgen --target web

async function init(input) {
    if (typeof input === 'undefined') {
        input = import.meta.url.replace(/\.js$/, '_bg.wasm');
    }
    ...

$ wasm-bindgen --target no-modules

async function init(input) {
    if (typeof input === 'undefined') {
        let src;
        if (typeof document === 'undefined') {
            src = location.href;
        } else {
            src = document.currentScript.src;
        }
        input = src.replace(/\\.js$/, '_bg.wasm');
    }
    ...

@realtimetodie
Copy link
Contributor Author

@alexcrichton

@alexcrichton
Copy link
Contributor

Thanks for this! I think though due to docopt the default is still false? Can a test be added for this as well?

Adds a new CLI flag `--omit-default-module-path`, to control the
`default_module_path` generated code.

The `default_module_path` generated code is enabled by default, users
need to explicitly disable it by setting the `--omit-default-module-path` CLI
flag.
@realtimetodie
Copy link
Contributor Author

I changed the CLI option to the flag --omit-default-module-path and added tests to the CLI test suite.

@realtimetodie
Copy link
Contributor Author

The Windows tests are flaky, I had to force-push it multiple times.

@alexcrichton
Copy link
Contributor

Ok thanks again for the PR!

@alexcrichton alexcrichton merged commit d4679a0 into rustwasm:master Apr 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants