Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ description = "A javascript runtime with [pjs](https://github.com/polkadot-js) e

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
deno_ast = { version = "0.38", features = ["transpiling"] }
deno_core = "0.272.0"
deno_ast = { version = "0.43.3", features = ["transpiling"] }
deno_core = "0.321.0"
deno_permissions = "0.39.0"
deno_console = "0.179.0"
deno_webidl = "0.179.0"
deno_fetch = "0.203.0"
deno_crypto = "0.193.0"
deno_url = "0.179.0"
deno_web = "0.210.0"
deno_websocket = "0.184.0"
deno_net = "0.171.0"
log = "0.4.22"
tokio = { version = "1.37.0", features = ["full"] }
deno_console = "0.143.0"
deno_webidl = "0.144.0"
deno_fetch = "0.167.0"
deno_crypto = "0.157.0"
deno_url = "0.143.0"
deno_web = "0.174.0"
deno_websocket = "0.149.0"
log = "0.4.21"
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::sync::Arc;

use deno_ast::MediaType;
use deno_ast::ParseParams;
use deno_ast::SourceTextInfo;
use deno_core::error::AnyError;
use deno_core::serde_json;
use deno_core::serde_json::json;
Expand Down Expand Up @@ -58,6 +57,7 @@ pub fn create_runtime_with_loader(loader: Option<DynLoader>) -> JsRuntime {
user_agent: "zombienet-agent".to_string(),
..Default::default()
}),
deno_net::deno_net::init_ops_and_esm::<ZombiePermissions>(None, None),
deno_websocket::deno_websocket::init_ops_and_esm::<ZombiePermissions>(
"zombienet-agent".to_string(),
None,
Expand Down Expand Up @@ -166,14 +166,14 @@ pub async fn run_ts_code(
fn transpile(code: impl Into<String>) -> Result<String, AnyError> {
let parsed = deno_ast::parse_module(ParseParams {
specifier: url::Url::parse("file:///inner")?,
text_info: SourceTextInfo::from_string(code.into()),
text: Arc::from(code.into()),
media_type: MediaType::TypeScript,
capture_tokens: false,
scope_analysis: false,
maybe_syntax: None,
})?;

let transpiled = parsed.transpile(&Default::default(), &Default::default())?;
let transpiled = parsed.transpile(&Default::default(), &Default::default(), &Default::default())?;
Ok(transpiled.into_source().text)
}
async fn get_code(file_path: impl AsRef<Path>) -> Result<String, AnyError> {
Expand Down
30 changes: 25 additions & 5 deletions src/perms.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::path::Path;
use std::borrow::Cow;
use std::path::{Path, PathBuf};

use deno_core::error::AnyError;
use deno_core::url::Url;
use deno_fetch::FetchPermissions;
use deno_net::NetPermissions;
use deno_web::TimersPermission;
use deno_websocket::WebSocketPermissions;
use deno_permissions::PermissionCheckError;

pub struct ZombiePermissions;

Expand All @@ -26,16 +28,34 @@ impl WebSocketPermissions for ZombiePermissions {
&mut self,
_url: &deno_core::url::Url,
_api_name: &str,
) -> Result<(), AnyError> {
) -> Result<(), PermissionCheckError> {
Ok(())
}
}

impl FetchPermissions for ZombiePermissions {
fn check_net_url(&mut self, _url: &Url, _api_name: &str) -> Result<(), AnyError> {
fn check_net_url(&mut self, _url: &Url, _api_name: &str) -> Result<(), PermissionCheckError> {
Ok(())
}
fn check_read(&mut self, _p: &Path, _api_name: &str) -> Result<(), AnyError> {
fn check_read<'a>(&mut self, p: &'a Path, _api_name: &str) -> Result<Cow<'a, Path>, PermissionCheckError> {
Ok(p.into())
}
}

impl NetPermissions for ZombiePermissions {
fn check_net<T: AsRef<str>>(&mut self, _host: &(T, Option<u16>), _api_name: &str) -> Result<(), PermissionCheckError> {
Ok(())
}

fn check_read(&mut self, p: &str, _api_name: &str) -> Result<PathBuf, PermissionCheckError> {
Ok(p.into())
}

fn check_write(&mut self, p: &str, _api_name: &str) -> Result<PathBuf, PermissionCheckError> {
Ok(p.into())
}

fn check_write_path<'a>(&mut self, p: &'a Path, _api_name: &str) -> Result<Cow<'a, Path>, PermissionCheckError> {
Ok(p.into())
}
}