A high-performance inference engine for AI models
use std::path::PathBuf;
use anyhow::{Result, anyhow};
use crate::{
configs::{PlatformsConfig, WorkspaceManifest},
sync::SyncTask,
};
const NAPI_IMPORT: &str = "from './napi/index';";
const WASM_IMPORT: &str = "from './wasm/uzu.js';";
const HEADER: &str =
"// Generated by `cargo tools sync` from bindings/typescript/src/tool.ts: edit that file instead.\n\n";
/// Keeps the wasm package's `tool.ts` a copy of the napi package's, importing the wasm bindings,
/// so both packages offer the same zod tool helpers.
pub struct WasmToolSyncTask {
source: PathBuf,
}
impl WasmToolSyncTask {
pub fn new(source: PathBuf) -> Self {
Self {
source,
}
}
}
impl SyncTask for WasmToolSyncTask {
fn process(
&self,
_platforms: &PlatformsConfig,
_workspace: &WorkspaceManifest,
_input: &str,
) -> Result<String> {
let source = std::fs::read_to_string(&self.source)?;
if !source.contains(NAPI_IMPORT) {
return Err(anyhow!("Expected `{NAPI_IMPORT}` in {}", self.source.display()));
}
Ok(format!("{HEADER}{}", source.replace(NAPI_IMPORT, WASM_IMPORT)))
}
}