diff options
author | Kitson Kelly <me@kitsonkelly.com> | 2020-02-19 16:34:11 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-19 00:34:11 -0500 |
commit | 046bbb26913f9da58b0d23ae331e9dab9dc19e59 (patch) | |
tree | 74dd5945ed1ff10ce84fea05c73d9c13b31ad376 /cli/ops/compiler.rs | |
parent | 3d5bed35e032ee20e4fe34cad925202c6f0c0d3e (diff) |
Support loading additional TS lib files (#3863)
Fixes #3726
This PR provides support for referencing other lib files (like lib.dom.d.ts that are not
used by default in Deno.
Diffstat (limited to 'cli/ops/compiler.rs')
-rw-r--r-- | cli/ops/compiler.rs | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/cli/ops/compiler.rs b/cli/ops/compiler.rs index cce2f4980..f61bf6820 100644 --- a/cli/ops/compiler.rs +++ b/cli/ops/compiler.rs @@ -1,5 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. -use super::dispatch_json::{Deserialize, JsonOp, Value}; +use super::dispatch_json::Deserialize; +use super::dispatch_json::JsonOp; +use super::dispatch_json::Value; use crate::futures::future::try_join_all; use crate::msg; use crate::ops::json_op; @@ -17,6 +19,10 @@ pub fn init(i: &mut Isolate, s: &State) { "fetch_source_files", s.core_op(json_op(s.stateful_op(op_fetch_source_files))), ); + i.register_op( + "fetch_asset", + s.core_op(json_op(s.stateful_op(op_fetch_asset))), + ); } #[derive(Deserialize)] @@ -154,3 +160,26 @@ fn op_fetch_source_files( Ok(JsonOp::Async(future)) } + +#[derive(Deserialize, Debug)] +struct FetchRemoteAssetArgs { + name: String, +} + +fn op_fetch_asset( + _state: &State, + args: Value, + _data: Option<ZeroCopyBuf>, +) -> Result<JsonOp, ErrBox> { + let args: FetchRemoteAssetArgs = serde_json::from_value(args)?; + debug!("args.name: {}", args.name); + + let source_code = + if let Some(source_code) = deno_typescript::get_asset(&args.name) { + source_code.to_string() + } else { + panic!("Asset not found: \"{}\"", args.name) + }; + + Ok(JsonOp::Sync(json!({ "sourceCode": source_code }))) +} |