summaryrefslogtreecommitdiff
path: root/cli/ops
diff options
context:
space:
mode:
Diffstat (limited to 'cli/ops')
-rw-r--r--cli/ops/compiler.rs19
-rw-r--r--cli/ops/mod.rs7
2 files changed, 26 insertions, 0 deletions
diff --git a/cli/ops/compiler.rs b/cli/ops/compiler.rs
index 39d3a6d7f..40d25aa74 100644
--- a/cli/ops/compiler.rs
+++ b/cli/ops/compiler.rs
@@ -1,5 +1,6 @@
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
use super::dispatch_json::{Deserialize, JsonOp, Value};
+use crate::assets;
use crate::state::ThreadSafeState;
use crate::tokio_util;
use deno::*;
@@ -66,3 +67,21 @@ pub fn op_fetch_source_file(
"sourceCode": String::from_utf8(out.source_code).unwrap(),
})))
}
+
+#[derive(Deserialize)]
+struct FetchAssetArgs {
+ name: String,
+}
+
+pub fn op_fetch_asset(
+ _state: &ThreadSafeState,
+ args: Value,
+ _zero_copy: Option<PinnedBuf>,
+) -> Result<JsonOp, ErrBox> {
+ let args: FetchAssetArgs = serde_json::from_value(args)?;
+ if let Some(source_code) = assets::get_source_code(&args.name) {
+ Ok(JsonOp::Sync(json!(source_code)))
+ } else {
+ panic!("op_fetch_asset bad asset {}", args.name)
+ }
+}
diff --git a/cli/ops/mod.rs b/cli/ops/mod.rs
index 106948492..1f07acc65 100644
--- a/cli/ops/mod.rs
+++ b/cli/ops/mod.rs
@@ -80,6 +80,7 @@ pub const OP_READ_LINK: OpId = 53;
pub const OP_TRUNCATE: OpId = 54;
pub const OP_MAKE_TEMP_DIR: OpId = 55;
pub const OP_CWD: OpId = 56;
+pub const OP_FETCH_ASSET: OpId = 57;
pub fn dispatch(
state: &ThreadSafeState,
@@ -293,6 +294,12 @@ pub fn dispatch(
dispatch_json::dispatch(fs::op_make_temp_dir, state, control, zero_copy)
}
OP_CWD => dispatch_json::dispatch(fs::op_cwd, state, control, zero_copy),
+ OP_FETCH_ASSET => dispatch_json::dispatch(
+ compiler::op_fetch_asset,
+ state,
+ control,
+ zero_copy,
+ ),
_ => panic!("bad op_id"),
};