diff --git a/cli/js.rs b/cli/js.rs deleted file mode 100644 index 7cfa961a16..0000000000 --- a/cli/js.rs +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. - -use deno_core::Snapshot; - -pub const TS_VERSION: &str = env!("TS_VERSION"); - -pub static COMPILER_SNAPSHOT: &[u8] = - include_bytes!(concat!(env!("OUT_DIR"), "/COMPILER_SNAPSHOT.bin")); -pub static DENO_NS_LIB: &str = include_str!("dts/lib.deno.ns.d.ts"); -pub static DENO_WEB_LIB: &str = include_str!(env!("DENO_WEB_LIB_PATH")); -pub static DENO_FETCH_LIB: &str = include_str!(env!("DENO_FETCH_LIB_PATH")); -pub static SHARED_GLOBALS_LIB: &str = - include_str!("dts/lib.deno.shared_globals.d.ts"); -pub static WINDOW_LIB: &str = include_str!("dts/lib.deno.window.d.ts"); -pub static UNSTABLE_NS_LIB: &str = include_str!("dts/lib.deno.unstable.d.ts"); - -pub fn compiler_isolate_init() -> Snapshot { - debug!("Deno compiler isolate init with snapshots."); - let data = COMPILER_SNAPSHOT; - Snapshot::Static(data) -} - -#[test] -fn compiler_snapshot() { - let mut js_runtime = deno_core::JsRuntime::new(deno_core::RuntimeOptions { - startup_snapshot: Some(compiler_isolate_init()), - ..Default::default() - }); - js_runtime - .execute( - "", - r#" - if (!(startup)) { - throw Error("bad"); - } - console.log(`ts version: ${ts.version}`); - "#, - ) - .unwrap(); -} diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs index d40e18bbda..1182fae6bd 100644 --- a/cli/lsp/tsc.rs +++ b/cli/lsp/tsc.rs @@ -5,7 +5,6 @@ use super::language_server::StateSnapshot; use super::text; use super::utils; -use crate::js; use crate::media_type::MediaType; use crate::tokio_util::create_basic_runtime; use crate::tsc; @@ -1025,7 +1024,7 @@ fn set_asset(state: &mut State, args: Value) -> Result { /// server. pub fn start(debug: bool) -> Result { let mut runtime = JsRuntime::new(RuntimeOptions { - startup_snapshot: Some(js::compiler_isolate_init()), + startup_snapshot: Some(tsc::compiler_snapshot()), ..Default::default() }); diff --git a/cli/main.rs b/cli/main.rs index 932e465c02..7f6a80f30e 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -25,7 +25,6 @@ mod http_cache; mod http_util; mod import_map; mod info; -mod js; mod lockfile; mod lsp; mod media_type; @@ -277,15 +276,15 @@ fn print_cache_info( fn get_types(unstable: bool) -> String { let mut types = format!( "{}\n{}\n{}\n{}\n{}", - crate::js::DENO_NS_LIB, - crate::js::DENO_WEB_LIB, - crate::js::DENO_FETCH_LIB, - crate::js::SHARED_GLOBALS_LIB, - crate::js::WINDOW_LIB, + crate::tsc::DENO_NS_LIB, + crate::tsc::DENO_WEB_LIB, + crate::tsc::DENO_FETCH_LIB, + crate::tsc::SHARED_GLOBALS_LIB, + crate::tsc::WINDOW_LIB, ); if unstable { - types.push_str(&format!("\n{}", crate::js::UNSTABLE_NS_LIB,)); + types.push_str(&format!("\n{}", crate::tsc::UNSTABLE_NS_LIB,)); } types diff --git a/cli/module_graph.rs b/cli/module_graph.rs index e86732b24c..686c1bd0e4 100644 --- a/cli/module_graph.rs +++ b/cli/module_graph.rs @@ -13,7 +13,6 @@ use crate::info::ModuleGraphInfo; use crate::info::ModuleInfo; use crate::info::ModuleInfoMap; use crate::info::ModuleInfoMapItem; -use crate::js; use crate::lockfile::Lockfile; use crate::media_type::MediaType; use crate::specifier_handler::CachedModule; @@ -855,17 +854,14 @@ impl Graph { vec![config.as_bytes(), version::deno().as_bytes().to_owned()]; let graph = Arc::new(Mutex::new(self)); - let response = tsc::exec( - js::compiler_isolate_init(), - tsc::Request { - config: config.clone(), - debug: options.debug, - graph: graph.clone(), - hash_data, - maybe_tsbuildinfo, - root_names, - }, - )?; + let response = tsc::exec(tsc::Request { + config: config.clone(), + debug: options.debug, + graph: graph.clone(), + hash_data, + maybe_tsbuildinfo, + root_names, + })?; let mut graph = graph.lock().unwrap(); graph.maybe_tsbuildinfo = response.maybe_tsbuildinfo; @@ -983,17 +979,14 @@ impl Graph { let hash_data = vec![config.as_bytes(), version::deno().as_bytes().to_owned()]; let graph = Arc::new(Mutex::new(self)); - let response = tsc::exec( - js::compiler_isolate_init(), - tsc::Request { - config: config.clone(), - debug: options.debug, - graph: graph.clone(), - hash_data, - maybe_tsbuildinfo: None, - root_names, - }, - )?; + let response = tsc::exec(tsc::Request { + config: config.clone(), + debug: options.debug, + graph: graph.clone(), + hash_data, + maybe_tsbuildinfo: None, + root_names, + })?; let graph = graph.lock().unwrap(); match options.bundle_type { diff --git a/cli/tsc.rs b/cli/tsc.rs index c21c52a563..d636678765 100644 --- a/cli/tsc.rs +++ b/cli/tsc.rs @@ -25,6 +25,23 @@ use std::path::PathBuf; use std::sync::Arc; use std::sync::Mutex; +// Declaration files + +pub static DENO_NS_LIB: &str = include_str!("dts/lib.deno.ns.d.ts"); +pub static DENO_WEB_LIB: &str = include_str!(env!("DENO_WEB_LIB_PATH")); +pub static DENO_FETCH_LIB: &str = include_str!(env!("DENO_FETCH_LIB_PATH")); +pub static SHARED_GLOBALS_LIB: &str = + include_str!("dts/lib.deno.shared_globals.d.ts"); +pub static WINDOW_LIB: &str = include_str!("dts/lib.deno.window.d.ts"); +pub static UNSTABLE_NS_LIB: &str = include_str!("dts/lib.deno.unstable.d.ts"); + +pub static COMPILER_SNAPSHOT: &[u8] = + include_bytes!(concat!(env!("OUT_DIR"), "/COMPILER_SNAPSHOT.bin")); + +pub fn compiler_snapshot() -> Snapshot { + Snapshot::Static(COMPILER_SNAPSHOT) +} + /// Provide static assets that are not preloaded in the compiler snapshot. pub fn get_asset(asset: &str) -> Option<&'static str> { macro_rules! inc { @@ -357,12 +374,9 @@ fn respond(state: &mut State, args: Value) -> Result { /// Execute a request on the supplied snapshot, returning a response which /// contains information, like any emitted files, diagnostics, statistics and /// optionally an updated TypeScript build info. -pub fn exec( - snapshot: Snapshot, - request: Request, -) -> Result { +pub fn exec(request: Request) -> Result { let mut runtime = JsRuntime::new(RuntimeOptions { - startup_snapshot: Some(snapshot), + startup_snapshot: Some(compiler_snapshot()), ..Default::default() }); // tsc cannot handle root specifiers that don't have one of the "acceptable" @@ -442,7 +456,6 @@ mod tests { use super::*; use crate::diagnostics::Diagnostic; use crate::diagnostics::DiagnosticCategory; - use crate::js; use crate::module_graph::tests::MockSpecifierHandler; use crate::module_graph::GraphBuilder; use crate::tsc_config::TsConfig; @@ -512,7 +525,26 @@ mod tests { maybe_tsbuildinfo: None, root_names: vec![(specifier.clone(), MediaType::TypeScript)], }; - exec(js::compiler_isolate_init(), request) + exec(request) + } + + #[test] + fn test_compiler_snapshot() { + let mut js_runtime = deno_core::JsRuntime::new(deno_core::RuntimeOptions { + startup_snapshot: Some(compiler_snapshot()), + ..Default::default() + }); + js_runtime + .execute( + "", + r#" + if (!(startup)) { + throw Error("bad"); + } + console.log(`ts version: ${ts.version}`); + "#, + ) + .unwrap(); } #[tokio::test] diff --git a/cli/version.rs b/cli/version.rs index 63253cec82..49cb34f1d9 100644 --- a/cli/version.rs +++ b/cli/version.rs @@ -1,7 +1,7 @@ // Copyright 2018-2020 the Deno authors. All rights reserved. MIT license. pub const GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_HASH"); -pub const TYPESCRIPT: &str = crate::js::TS_VERSION; +pub const TYPESCRIPT: &str = env!("TS_VERSION"); pub fn deno() -> String { let semver = env!("CARGO_PKG_VERSION");