From 8e4e82122a3f16b803ceb4de70869a7c541e750b Mon Sep 17 00:00:00 2001 From: Jeffrey Charles Date: Mon, 4 Dec 2023 13:05:21 -0800 Subject: [PATCH] Update wit-parser (#565) --- Cargo.lock | 6 +++--- crates/cli/Cargo.toml | 2 +- crates/cli/src/exports.rs | 24 ++++++++++++++++++++++-- supply-chain/imports.lock | 4 ++-- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fdb3c23f..2d8767ae 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1476,7 +1476,7 @@ dependencies = [ "wasmprinter", "wasmtime", "wasmtime-wasi", - "wit-parser 0.12.2", + "wit-parser 0.13.0", "wizer", ] @@ -3989,9 +3989,9 @@ dependencies = [ [[package]] name = "wit-parser" -version = "0.12.2" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43771ee863a16ec4ecf9da0fc65c3bbd4a1235c8e3da5f094b562894843dfa76" +checksum = "15df6b7b28ce94b8be39d8df5cb21a08a4f3b9f33b631aedb4aa5776f785ead3" dependencies = [ "anyhow", "id-arena", diff --git a/crates/cli/Cargo.toml b/crates/cli/Cargo.toml index 85db6070..1857076f 100644 --- a/crates/cli/Cargo.toml +++ b/crates/cli/Cargo.toml @@ -26,7 +26,7 @@ wasmtime-wasi = { workspace = true } wasi-common = { workspace = true } walrus = "0.20.1" swc_core = { version = "0.86.29", features = ["common_sourcemap", "ecma_ast", "ecma_parser"] } -wit-parser = "0.12.2" +wit-parser = "0.13.0" convert_case = "0.6.0" [dev-dependencies] diff --git a/crates/cli/src/exports.rs b/crates/cli/src/exports.rs index d33ed006..19e5eb52 100644 --- a/crates/cli/src/exports.rs +++ b/crates/cli/src/exports.rs @@ -1,6 +1,6 @@ use anyhow::{anyhow, Result}; use convert_case::{Case, Casing}; -use std::path::Path; +use std::{env, path::Path}; use crate::{js::JS, wit}; @@ -11,7 +11,7 @@ pub struct Export { pub fn process_exports(js: &JS, wit: &Path, wit_world: &str) -> Result> { let js_exports = js.exports()?; - wit::parse_exports(wit, wit_world)? + parse_wit_exports(wit, wit_world)? .into_iter() .map(|wit_export| { let export = wit_export.from_case(Case::Kebab).to_case(Case::Camel); @@ -26,3 +26,23 @@ pub fn process_exports(js: &JS, wit: &Path, wit_world: &str) -> Result>>() } + +fn parse_wit_exports(wit: &Path, wit_world: &str) -> Result> { + // Configure wit-parser to not require semicolons but only if the relevant + // environment variable is not already set. + const SEMICOLONS_OPTIONAL_ENV_VAR: &str = "WIT_REQUIRE_SEMICOLONS"; + let semicolons_env_var_already_set = env::var(SEMICOLONS_OPTIONAL_ENV_VAR).is_ok(); + if !semicolons_env_var_already_set { + env::set_var(SEMICOLONS_OPTIONAL_ENV_VAR, "0"); + } + + let exports = wit::parse_exports(wit, wit_world); + + // If we set the environment variable to not require semicolons, remove + // that environment variable now that we no longer need it set. + if !semicolons_env_var_already_set { + env::remove_var(SEMICOLONS_OPTIONAL_ENV_VAR); + } + + exports +} diff --git a/supply-chain/imports.lock b/supply-chain/imports.lock index bb6dbd98..73d07f55 100644 --- a/supply-chain/imports.lock +++ b/supply-chain/imports.lock @@ -734,8 +734,8 @@ user-login = "alexcrichton" user-name = "Alex Crichton" [[publisher.wit-parser]] -version = "0.12.2" -when = "2023-10-30" +version = "0.13.0" +when = "2023-11-06" user-id = 1 user-login = "alexcrichton" user-name = "Alex Crichton"