You can follow instructions at 'Install Rust' page from the official rust website
rustup target add wasm32-wasip1Tests use insta snapshot testing. Test macros are defined in tests/common/mod.rs:
to!(test_name, "input code")— transform with default optionsto!(test_name, options, "input code")— transform with custom optionsto_panic!(test_name, options, "input code")— expect compilation error (error message captured in snapshot)
# run all test suite
cargo test
# run individual test
cargo test js_choices_may_contain_expressions
# you may specify only prefix of test name to target more cases
cargo test jsx_
# run the whole file from the /tests folder (omit .rs extension)
cargo test --test js_icu
# Update snapshots interactively (requires: cargo install cargo-insta)
cargo insta test --review
# Bulk-accept all snapshot changes
INSTA_UPDATE=always cargo testBefore submitting a pull request, please ensure your code passes all quality checks. The CI system will run these same checks, so running them locally will save you time.
# this project uses rustfmt to enforce a consistent code style
cargo fmt# we use clippy to catch common mistakes and improve code quality
# all clippy warnings are treated as errors in the CI
cargo clippy --all-targets --all-features -- -D warnings# (alias for `cargo build --target wasm32-wasip1`)
cargo build-wasi --releaseThen wasm binary would be on the path: ./target/wasm32-wasip1/release/lingui_macro_plugin.wasm
You can check it in your own project or in the examples/nextjs-13 example in this repo by specifying full path to the WASM binary:
/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
swcPlugins: [
['/Users/tim/projects/lingui-macro-plugin/target/wasm32-wasip1/release/lingui_macro_plugin.wasm', {}],
],
},
};
module.exports = nextConfig;It's important to build a plugin with the same Rust version used to build SWC itself.
This project uses rust-toolchain file in the root of project to define rust version.
To update Rust, put new version into rust-toolchain and call rustup update command.
This project uses cargo-llvm-cov to generate code coverage reports.
cargo install cargo-llvm-cov# Generate HTML coverage report for local viewing
cargo llvm-cov --all-features --workspace --html --open