refactor(cli): migrate runtime compile/bundle to new infrastructure (#8192)

Fixes #8060
This commit is contained in:
Kitson Kelly 2020-11-02 13:51:56 +11:00 committed by GitHub
parent 3558769d46
commit fdcc78500c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 852 additions and 2770 deletions

View file

@ -15,9 +15,6 @@ use crate::module_graph2::TypeLib;
use crate::permissions::Permissions;
use crate::source_maps::SourceMapGetter;
use crate::specifier_handler::FetchHandler;
use crate::tsc::CompiledModule;
use crate::tsc::TargetLib;
use crate::tsc::TsCompiler;
use deno_core::error::generic_error;
use deno_core::error::AnyError;
@ -37,6 +34,12 @@ pub fn exit_unstable(api_name: &str) {
std::process::exit(70);
}
// TODO(@kitsonk) probably can refactor this better with the graph.
pub struct CompiledModule {
pub code: String,
pub name: String,
}
/// This structure represents state of single "deno" program.
///
/// It is shared by all created workers (thus V8 isolates).
@ -47,7 +50,6 @@ pub struct ProgramState {
pub permissions: Permissions,
pub dir: deno_dir::DenoDir,
pub file_fetcher: SourceFileFetcher,
pub ts_compiler: TsCompiler,
pub lockfile: Option<Arc<Mutex<Lockfile>>>,
pub maybe_import_map: Option<ImportMap>,
pub maybe_inspector_server: Option<Arc<InspectorServer>>,
@ -70,12 +72,6 @@ impl ProgramState {
ca_file.as_deref(),
)?;
let ts_compiler = TsCompiler::new(
file_fetcher.clone(),
flags.clone(),
dir.gen_cache.clone(),
)?;
let lockfile = if let Some(filename) = &flags.lock {
let lockfile = Lockfile::new(filename.clone(), flags.lock_write)?;
Some(Arc::new(Mutex::new(lockfile)))
@ -105,7 +101,6 @@ impl ProgramState {
permissions: Permissions::from_flags(&flags),
flags,
file_fetcher,
ts_compiler,
lockfile,
maybe_import_map,
maybe_inspector_server,
@ -120,7 +115,7 @@ impl ProgramState {
pub async fn prepare_module_load(
self: &Arc<Self>,
specifier: ModuleSpecifier,
target_lib: TargetLib,
lib: TypeLib,
runtime_permissions: Permissions,
is_dynamic: bool,
maybe_import_map: Option<ImportMap>,
@ -129,7 +124,7 @@ impl ProgramState {
// Workers are subject to the current runtime permissions. We do the
// permission check here early to avoid "wasting" time building a module
// graph for a module that cannot be loaded.
if target_lib == TargetLib::Worker {
if lib == TypeLib::DenoWorker || lib == TypeLib::UnstableDenoWorker {
runtime_permissions.check_specifier(&specifier)?;
}
let handler =
@ -153,37 +148,20 @@ impl ProgramState {
eprintln!("{}", ignored_options);
}
} else {
let lib = match target_lib {
TargetLib::Main => {
if self.flags.unstable {
TypeLib::UnstableDenoWindow
} else {
TypeLib::DenoWindow
}
}
TargetLib::Worker => {
if self.flags.unstable {
TypeLib::UnstableDenoWorker
} else {
TypeLib::DenoWorker
}
}
};
let (stats, diagnostics, maybe_ignored_options) =
graph.check(CheckOptions {
debug,
emit: true,
lib,
maybe_config_path,
reload: self.flags.reload,
})?;
let result_info = graph.check(CheckOptions {
debug,
emit: true,
lib,
maybe_config_path,
reload: self.flags.reload,
})?;
debug!("{}", stats);
if let Some(ignored_options) = maybe_ignored_options {
debug!("{}", result_info.stats);
if let Some(ignored_options) = result_info.maybe_ignored_options {
eprintln!("{}", ignored_options);
}
if !diagnostics.is_empty() {
return Err(generic_error(diagnostics.to_string()));
if !result_info.diagnostics.is_empty() {
return Err(generic_error(result_info.diagnostics.to_string()));
}
};