From 046bbb26913f9da58b0d23ae331e9dab9dc19e59 Mon Sep 17 00:00:00 2001 From: Kitson Kelly Date: Wed, 19 Feb 2020 16:34:11 +1100 Subject: 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. --- cli/ops/compiler.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'cli/ops/compiler.rs') 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, +) -> Result { + 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 }))) +} -- cgit v1.2.3