diff --git a/cli/lib.rs b/cli/lib.rs index 6bae9c46f4..c0ad84c852 100644 --- a/cli/lib.rs +++ b/cli/lib.rs @@ -146,7 +146,7 @@ fn create_worker_and_state( } fn types_command() { - let content = include_str!("./js/lib.deno_runtime.d.ts"); + let content = deno_typescript::get_asset("lib.deno_runtime.d.ts").unwrap(); println!("{}", content); } diff --git a/deno_typescript/lib.rs b/deno_typescript/lib.rs index 370079fa14..c503d35081 100644 --- a/deno_typescript/lib.rs +++ b/deno_typescript/lib.rs @@ -241,7 +241,7 @@ fn write_snapshot( } /// Same as get_asset() but returns NotFound intead of None. -pub fn get_asset2(name: &str) -> Result { +pub fn get_asset2(name: &str) -> Result<&'static str, ErrBox> { match get_asset(name) { Some(a) => Ok(a), None => Err( @@ -251,23 +251,18 @@ pub fn get_asset2(name: &str) -> Result { } } -fn read_file(name: &str) -> String { - fs::read_to_string(name).unwrap() -} - -macro_rules! inc { - ($e:expr) => { - Some(read_file(concat!("../deno_typescript/typescript/lib/", $e))) - }; -} - -pub fn get_asset(name: &str) -> Option { +pub fn get_asset(name: &str) -> Option<&'static str> { + macro_rules! inc { + ($e:expr) => { + Some(include_str!(concat!("typescript/lib/", $e))) + }; + } match name { - "bundle_loader.js" => { - Some(read_file("../deno_typescript/bundle_loader.js")) + "bundle_loader.js" => Some(include_str!("bundle_loader.js")), + "lib.deno_runtime.d.ts" => { + Some(include_str!("../cli/js/lib.deno_runtime.d.ts")) } - "lib.deno_runtime.d.ts" => Some(read_file("js/lib.deno_runtime.d.ts")), - "bootstrap.ts" => Some("console.log(\"hello deno\");".to_string()), + "bootstrap.ts" => Some("console.log(\"hello deno\");"), "typescript.d.ts" => inc!("typescript.d.ts"), "lib.esnext.d.ts" => inc!("lib.esnext.d.ts"), "lib.es2020.d.ts" => inc!("lib.es2020.d.ts"), diff --git a/deno_typescript/ops.rs b/deno_typescript/ops.rs index c64b709b6d..d557b9b8c0 100644 --- a/deno_typescript/ops.rs +++ b/deno_typescript/ops.rs @@ -45,7 +45,7 @@ pub fn read_file(_s: &mut TSState, v: Value) -> Result { let v: ReadFile = serde_json::from_value(v)?; let (module_name, source_code) = if v.file_name.starts_with("$asset$/") { let asset = v.file_name.replace("$asset$/", ""); - let source_code = crate::get_asset2(&asset)?; + let source_code = crate::get_asset2(&asset)?.to_string(); (asset, source_code) } else { assert!(!v.file_name.starts_with("$assets$"), "you meant $asset$");