mirror of
https://github.com/denoland/deno.git
synced 2024-12-22 07:14:47 -05:00
refactor(cli): remove 'js' module, simplify compiler snapshot (#9020)
This commit removes "js" module from "cli". It contained stuff related to TypeScript compiler (snapshot, declaration files) and thus it was moved to "tsc" module.
This commit is contained in:
parent
4c4791b589
commit
bb88418221
6 changed files with 63 additions and 80 deletions
40
cli/js.rs
40
cli/js.rs
|
@ -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(
|
|
||||||
"<anon>",
|
|
||||||
r#"
|
|
||||||
if (!(startup)) {
|
|
||||||
throw Error("bad");
|
|
||||||
}
|
|
||||||
console.log(`ts version: ${ts.version}`);
|
|
||||||
"#,
|
|
||||||
)
|
|
||||||
.unwrap();
|
|
||||||
}
|
|
|
@ -5,7 +5,6 @@ use super::language_server::StateSnapshot;
|
||||||
use super::text;
|
use super::text;
|
||||||
use super::utils;
|
use super::utils;
|
||||||
|
|
||||||
use crate::js;
|
|
||||||
use crate::media_type::MediaType;
|
use crate::media_type::MediaType;
|
||||||
use crate::tokio_util::create_basic_runtime;
|
use crate::tokio_util::create_basic_runtime;
|
||||||
use crate::tsc;
|
use crate::tsc;
|
||||||
|
@ -1025,7 +1024,7 @@ fn set_asset(state: &mut State, args: Value) -> Result<Value, AnyError> {
|
||||||
/// server.
|
/// server.
|
||||||
pub fn start(debug: bool) -> Result<JsRuntime, AnyError> {
|
pub fn start(debug: bool) -> Result<JsRuntime, AnyError> {
|
||||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
let mut runtime = JsRuntime::new(RuntimeOptions {
|
||||||
startup_snapshot: Some(js::compiler_isolate_init()),
|
startup_snapshot: Some(tsc::compiler_snapshot()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
13
cli/main.rs
13
cli/main.rs
|
@ -25,7 +25,6 @@ mod http_cache;
|
||||||
mod http_util;
|
mod http_util;
|
||||||
mod import_map;
|
mod import_map;
|
||||||
mod info;
|
mod info;
|
||||||
mod js;
|
|
||||||
mod lockfile;
|
mod lockfile;
|
||||||
mod lsp;
|
mod lsp;
|
||||||
mod media_type;
|
mod media_type;
|
||||||
|
@ -277,15 +276,15 @@ fn print_cache_info(
|
||||||
fn get_types(unstable: bool) -> String {
|
fn get_types(unstable: bool) -> String {
|
||||||
let mut types = format!(
|
let mut types = format!(
|
||||||
"{}\n{}\n{}\n{}\n{}",
|
"{}\n{}\n{}\n{}\n{}",
|
||||||
crate::js::DENO_NS_LIB,
|
crate::tsc::DENO_NS_LIB,
|
||||||
crate::js::DENO_WEB_LIB,
|
crate::tsc::DENO_WEB_LIB,
|
||||||
crate::js::DENO_FETCH_LIB,
|
crate::tsc::DENO_FETCH_LIB,
|
||||||
crate::js::SHARED_GLOBALS_LIB,
|
crate::tsc::SHARED_GLOBALS_LIB,
|
||||||
crate::js::WINDOW_LIB,
|
crate::tsc::WINDOW_LIB,
|
||||||
);
|
);
|
||||||
|
|
||||||
if unstable {
|
if unstable {
|
||||||
types.push_str(&format!("\n{}", crate::js::UNSTABLE_NS_LIB,));
|
types.push_str(&format!("\n{}", crate::tsc::UNSTABLE_NS_LIB,));
|
||||||
}
|
}
|
||||||
|
|
||||||
types
|
types
|
||||||
|
|
|
@ -13,7 +13,6 @@ use crate::info::ModuleGraphInfo;
|
||||||
use crate::info::ModuleInfo;
|
use crate::info::ModuleInfo;
|
||||||
use crate::info::ModuleInfoMap;
|
use crate::info::ModuleInfoMap;
|
||||||
use crate::info::ModuleInfoMapItem;
|
use crate::info::ModuleInfoMapItem;
|
||||||
use crate::js;
|
|
||||||
use crate::lockfile::Lockfile;
|
use crate::lockfile::Lockfile;
|
||||||
use crate::media_type::MediaType;
|
use crate::media_type::MediaType;
|
||||||
use crate::specifier_handler::CachedModule;
|
use crate::specifier_handler::CachedModule;
|
||||||
|
@ -855,17 +854,14 @@ impl Graph {
|
||||||
vec![config.as_bytes(), version::deno().as_bytes().to_owned()];
|
vec![config.as_bytes(), version::deno().as_bytes().to_owned()];
|
||||||
let graph = Arc::new(Mutex::new(self));
|
let graph = Arc::new(Mutex::new(self));
|
||||||
|
|
||||||
let response = tsc::exec(
|
let response = tsc::exec(tsc::Request {
|
||||||
js::compiler_isolate_init(),
|
config: config.clone(),
|
||||||
tsc::Request {
|
debug: options.debug,
|
||||||
config: config.clone(),
|
graph: graph.clone(),
|
||||||
debug: options.debug,
|
hash_data,
|
||||||
graph: graph.clone(),
|
maybe_tsbuildinfo,
|
||||||
hash_data,
|
root_names,
|
||||||
maybe_tsbuildinfo,
|
})?;
|
||||||
root_names,
|
|
||||||
},
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let mut graph = graph.lock().unwrap();
|
let mut graph = graph.lock().unwrap();
|
||||||
graph.maybe_tsbuildinfo = response.maybe_tsbuildinfo;
|
graph.maybe_tsbuildinfo = response.maybe_tsbuildinfo;
|
||||||
|
@ -983,17 +979,14 @@ impl Graph {
|
||||||
let hash_data =
|
let hash_data =
|
||||||
vec![config.as_bytes(), version::deno().as_bytes().to_owned()];
|
vec![config.as_bytes(), version::deno().as_bytes().to_owned()];
|
||||||
let graph = Arc::new(Mutex::new(self));
|
let graph = Arc::new(Mutex::new(self));
|
||||||
let response = tsc::exec(
|
let response = tsc::exec(tsc::Request {
|
||||||
js::compiler_isolate_init(),
|
config: config.clone(),
|
||||||
tsc::Request {
|
debug: options.debug,
|
||||||
config: config.clone(),
|
graph: graph.clone(),
|
||||||
debug: options.debug,
|
hash_data,
|
||||||
graph: graph.clone(),
|
maybe_tsbuildinfo: None,
|
||||||
hash_data,
|
root_names,
|
||||||
maybe_tsbuildinfo: None,
|
})?;
|
||||||
root_names,
|
|
||||||
},
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let graph = graph.lock().unwrap();
|
let graph = graph.lock().unwrap();
|
||||||
match options.bundle_type {
|
match options.bundle_type {
|
||||||
|
|
46
cli/tsc.rs
46
cli/tsc.rs
|
@ -25,6 +25,23 @@ use std::path::PathBuf;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::Mutex;
|
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.
|
/// Provide static assets that are not preloaded in the compiler snapshot.
|
||||||
pub fn get_asset(asset: &str) -> Option<&'static str> {
|
pub fn get_asset(asset: &str) -> Option<&'static str> {
|
||||||
macro_rules! inc {
|
macro_rules! inc {
|
||||||
|
@ -357,12 +374,9 @@ fn respond(state: &mut State, args: Value) -> Result<Value, AnyError> {
|
||||||
/// Execute a request on the supplied snapshot, returning a response which
|
/// Execute a request on the supplied snapshot, returning a response which
|
||||||
/// contains information, like any emitted files, diagnostics, statistics and
|
/// contains information, like any emitted files, diagnostics, statistics and
|
||||||
/// optionally an updated TypeScript build info.
|
/// optionally an updated TypeScript build info.
|
||||||
pub fn exec(
|
pub fn exec(request: Request) -> Result<Response, AnyError> {
|
||||||
snapshot: Snapshot,
|
|
||||||
request: Request,
|
|
||||||
) -> Result<Response, AnyError> {
|
|
||||||
let mut runtime = JsRuntime::new(RuntimeOptions {
|
let mut runtime = JsRuntime::new(RuntimeOptions {
|
||||||
startup_snapshot: Some(snapshot),
|
startup_snapshot: Some(compiler_snapshot()),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
});
|
||||||
// tsc cannot handle root specifiers that don't have one of the "acceptable"
|
// tsc cannot handle root specifiers that don't have one of the "acceptable"
|
||||||
|
@ -442,7 +456,6 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::diagnostics::Diagnostic;
|
use crate::diagnostics::Diagnostic;
|
||||||
use crate::diagnostics::DiagnosticCategory;
|
use crate::diagnostics::DiagnosticCategory;
|
||||||
use crate::js;
|
|
||||||
use crate::module_graph::tests::MockSpecifierHandler;
|
use crate::module_graph::tests::MockSpecifierHandler;
|
||||||
use crate::module_graph::GraphBuilder;
|
use crate::module_graph::GraphBuilder;
|
||||||
use crate::tsc_config::TsConfig;
|
use crate::tsc_config::TsConfig;
|
||||||
|
@ -512,7 +525,26 @@ mod tests {
|
||||||
maybe_tsbuildinfo: None,
|
maybe_tsbuildinfo: None,
|
||||||
root_names: vec![(specifier.clone(), MediaType::TypeScript)],
|
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(
|
||||||
|
"<anon>",
|
||||||
|
r#"
|
||||||
|
if (!(startup)) {
|
||||||
|
throw Error("bad");
|
||||||
|
}
|
||||||
|
console.log(`ts version: ${ts.version}`);
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
pub const GIT_COMMIT_HASH: &str = env!("GIT_COMMIT_HASH");
|
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 {
|
pub fn deno() -> String {
|
||||||
let semver = env!("CARGO_PKG_VERSION");
|
let semver = env!("CARGO_PKG_VERSION");
|
||||||
|
|
Loading…
Reference in a new issue