Skip to content

Commit

Permalink
Update wit-parser (#565)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffcharles authored Dec 4, 2023
1 parent 61616e1 commit 8e4e821
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 8 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
24 changes: 22 additions & 2 deletions crates/cli/src/exports.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand All @@ -11,7 +11,7 @@ pub struct Export {

pub fn process_exports(js: &JS, wit: &Path, wit_world: &str) -> Result<Vec<Export>> {
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);
Expand All @@ -26,3 +26,23 @@ pub fn process_exports(js: &JS, wit: &Path, wit_world: &str) -> Result<Vec<Expor
})
.collect::<Result<Vec<Export>>>()
}

fn parse_wit_exports(wit: &Path, wit_world: &str) -> Result<Vec<String>> {
// 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
}
4 changes: 2 additions & 2 deletions supply-chain/imports.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 8e4e821

Please sign in to comment.