-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add wasm fallback plugin (#1957)
resolves #1919
- Loading branch information
Showing
14 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
[package] | ||
edition.workspace = true | ||
homepage.workspace = true | ||
license.workspace = true | ||
name = "rolldown_plugin_wasm_fallback" | ||
repository.workspace = true | ||
version = "0.1.0" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[lib] | ||
doctest = false | ||
|
||
[lints] | ||
workspace = true | ||
|
||
[dependencies] | ||
anyhow = { workspace = true } | ||
rolldown_plugin = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use std::borrow::Cow; | ||
|
||
use rolldown_plugin::{HookLoadArgs, HookLoadReturn, Plugin, SharedPluginContext}; | ||
|
||
#[derive(Debug)] | ||
pub struct WasmFallbackPlugin {} | ||
|
||
impl Plugin for WasmFallbackPlugin { | ||
fn name(&self) -> Cow<'static, str> { | ||
Cow::Borrowed("builtin:wasm-fallback-plugin") | ||
} | ||
|
||
#[allow(clippy::case_sensitive_file_extension_comparisons)] | ||
async fn load(&self, _ctx: &SharedPluginContext, args: &HookLoadArgs<'_>) -> HookLoadReturn { | ||
if args.id.ends_with(".wasm") { | ||
// TODO: Replace the link here after rolldown's document is ready | ||
Err(anyhow::anyhow!( | ||
"\"ESM integration proposal for Wasm\" is not supported currently. | ||
Use plugin-wasm or other community plugins to handle this. | ||
Alternatively, you can use `.wasm?init` or `.wasm?url`. | ||
See https://vitejs.dev/guide/features.html#webassembly for more details." | ||
)) | ||
} else { | ||
Ok(None) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
packages/rolldown/tests/fixtures/builtin-plugin/wasm-fallback/_config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { wasmFallbackPlugin } from 'rolldown/experimental' | ||
import { defineTest } from '@tests' | ||
|
||
export default defineTest({ | ||
config: { | ||
plugins: [wasmFallbackPlugin()], | ||
}, | ||
catchError: () => { | ||
// Errors are swallowed here | ||
}, | ||
}) |
5 changes: 5 additions & 0 deletions
5
packages/rolldown/tests/fixtures/builtin-plugin/wasm-fallback/main.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import init from './add.wasm' | ||
|
||
init().then(({ exports }) => { | ||
exports.add(1, 2) === 3 | ||
}) |
4 changes: 2 additions & 2 deletions
4
packages/rolldown/tests/fixtures/builtin-plugin/wasm/_config.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { wasmPlugin } from 'rolldown/experimental' | ||
import { wasmFallbackPlugin, wasmPlugin } from 'rolldown/experimental' | ||
import { defineTest } from '@tests' | ||
|
||
export default defineTest({ | ||
config: { | ||
plugins: [wasmPlugin()], | ||
plugins: [wasmPlugin(), wasmFallbackPlugin()], | ||
}, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters