Skip to content

Commit c28e772

Browse files
committed
Add migration docs for v2 to README
1 parent 8680471 commit c28e772

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

shopify_function/README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,46 @@ A crate to help developers build [Shopify Functions].
1010

1111
See the [example_with_targets] for details on usage, or use the following guide to convert an existing Rust-based function.
1212

13+
## Updating an existing function to using shopify_function 2.0.0 and higher
14+
15+
If you are using a version less than `1.0.0`, you should update to version `1.1.1` as outlined below before following these steps.
16+
17+
1. [Update to the latest](https://shopify.dev/docs/api/shopify-cli#installation) Shopify CLI version.
18+
19+
2. Install the `wasm32-unknown-unknown` build target using [`rustup target`](https://rust-lang.github.io/rustup/cross-compilation.html):
20+
21+
```terminal
22+
rustup target add wasm32-unknown-unknown
23+
```
24+
25+
3. Update your build `command` and `path` in the `[extensions.build]` section of your [`shopify.extension.toml`](https://shopify.dev/docs/api/functions/latest#configuration) to use `wasm32-unknown-unknown` instead of `wasm32-wasip1`. Replace `RUST-PACKAGE-NAME` with the `name` from your `Cargo.toml`:
26+
27+
```toml
28+
[extensions.build]
29+
command = "cargo build --target=wasm32-unknown-unknown --release"
30+
path = "target/wasm32-unknown-unknown/release/[RUST-PACKAGE-NAME].wasm"
31+
```
32+
33+
4. Throughout all of your source files, update any references to `eprintln!` to use `log!` instead.
34+
35+
```rust
36+
#[shopify_function]
37+
fn run(input: schema::run::Input) -> Result<schema::FunctionRunResult> {
38+
log!("This will be logged");
39+
todo!();
40+
}
41+
```
42+
43+
5. Throughout all of your source files, update any references to `process::exit(1)` to use `process::abort()` instead.
44+
45+
```rust
46+
#[shopify_function]
47+
fn run(input: schema::run::Input) -> Result<schema::FunctionRunResult> {
48+
log!("Please invoke a named export.");
49+
process::abort();
50+
}
51+
```
52+
1353
## Updating an existing function using a version of `shopify_function` below `1.0.0` to use version `1.0.0` and above
1454
1555
1. In `main.rs`, add imports for `shopify_function`.

0 commit comments

Comments
 (0)