Skip to content

Commit d6ed997

Browse files
committed
refactor: use static base url for tree sitter
1 parent 8cf0cf0 commit d6ed997

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

crates/codemod-sandbox/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name = "codemod-sandbox"
33
version.workspace = true
44
edition = "2021"
5+
build = "src/build.rs"
56

67
[dependencies]
78
rquickjs-registry = { package = "rquickjs", version = "0.9.0", default-features = false, optional = true }

crates/codemod-sandbox/src/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
fn main() {
2+
let url = std::env::var("TREE_SITTER_BASE_URL")
3+
.unwrap_or_else(|_| "https://tree-sitter-parsers.s3.us-east-1.amazonaws.com".to_string());
4+
println!("cargo:rustc-env=TREE_SITTER_BASE_URL={url}");
5+
}

crates/codemod-sandbox/src/tree_sitter/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ struct ReadyLang {
1717
lib_path: PathBuf,
1818
}
1919

20+
pub const BASE_URL: &str = env!("TREE_SITTER_BASE_URL");
21+
2022
pub async fn load_tree_sitter(languages: &[SupportedLanguage]) -> Result<Vec<DynamicLang>, String> {
2123
let mut ready_langs = HashSet::new();
2224
for language in languages {
@@ -54,10 +56,10 @@ pub async fn load_tree_sitter(languages: &[SupportedLanguage]) -> Result<Vec<Dyn
5456
std::fs::create_dir_all(parent)
5557
.map_err(|e| format!("Failed to create directory: {e}"))?;
5658
}
57-
let base_url = std::env::var("TREE_SITTER_BASE_URL").unwrap_or_else(|_| {
58-
"https://tree-sitter-parsers.s3.us-east-1.amazonaws.com".to_string()
59-
});
60-
let url = format!("{base_url}/tree-sitter/parsers/tree-sitter-{language}/latest/{os}-{arch}.{extension}");
59+
println!("base_url: {BASE_URL}");
60+
let url = format!(
61+
"{BASE_URL}/tree-sitter/parsers/tree-sitter-{language}/latest/{os}-{arch}.{extension}"
62+
);
6163

6264
let client = reqwest::Client::builder()
6365
.timeout(std::time::Duration::from_secs(30))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy