pub async fn compile(
    &self,
    global_state: &Arc<GlobalState>,
    source_file: &SourceFile,
    target: TargetLib,
    module_graph: &ModuleGraph,
    allow_js: bool,
  ) -> Result<(), AnyError> {
    let module_url = source_file.url.clone();
    let build_info_key = self
      .disk_cache
      .get_cache_filename_with_extension(&module_url, "buildinfo");
    let build_info = match self.disk_cache.get(&build_info_key) {
      Ok(bytes) => Some(String::from_utf8(bytes)?),
      Err(_) => None,
    };

    // Only use disk cache if `--reload` flag was not used or this file has
    // already been compiled during current process lifetime.
    if (self.use_disk_cache || self.has_compiled(&source_file.url))
      && self.has_valid_cache(&source_file.url, &build_info)?
    {
      return Ok(());
    }

    let module_graph_json =
      serde_json::to_value(module_graph).expect("Failed to serialize data");
    let target = match target {
      TargetLib::Main => "main",
      TargetLib::Worker => "worker",
    };
    let root_names = vec![module_url.to_string()];
    let unstable = self.flags.unstable;
    let performance = matches!(self.flags.log_level, Some(Level::Debug));
    let compiler_config = self.config.clone();

    // TODO(bartlomieju): lift this call up - TSC shouldn't print anything
    info!("{} {}", colors::green("Check"), module_url.to_string());

    let mut lib = if target == "main" {
      vec!["deno.window"]
    } else {
      vec!["deno.worker"]
    };

    if unstable {
      lib.push("deno.unstable");
    }

    let mut compiler_options = json!({
      "allowJs": allow_js,
      "allowNonTsExtensions": true,
      "checkJs": false,
      "esModuleInterop": true,
      "incremental": true,
      "inlineSourceMap": true,
      // TODO(lucacasonato): enable this by default in 1.5.0
      "isolatedModules": unstable,
      "importsNotUsedAsValues": if unstable { "error" } else { "remove" },
      "jsx": "react",
      "lib": lib,
      "module": "esnext",
      "outDir": "deno://",
      "resolveJsonModule": true,
      "sourceMap": false,
      "strict": true,
      "removeComments": true,
      "target": "esnext",
      "tsBuildInfoFile": "cache:///tsbuildinfo.json",
    });

    tsc_config::json_merge(&mut compiler_options, &compiler_config.options);

    warn_ignored_options(
      compiler_config.maybe_ignored_options,
      compiler_config.path.as_ref().unwrap(),
    );

    let j = json!({
      "type": CompilerRequestType::Compile,
      "target": target,
      "rootNames": root_names,
      "performance": performance,
      "compilerOptions": compiler_options,
      "sourceFileMap": module_graph_json,
      "buildInfo": if self.use_disk_cache { build_info } else { None },
    });

    let req_msg = j.to_string();

    let json_str = execute_in_tsc(global_state.clone(), req_msg)?;

    let compile_response: CompileResponse = serde_json::from_str(&json_str)?;

    if !compile_response.diagnostics.0.is_empty() {
      return Err(generic_error(compile_response.diagnostics.to_string()));
    }

    maybe_log_stats(compile_response.stats);

    if let Some(build_info) = compile_response.build_info {
      self.cache_build_info(&module_url, build_info)?;
    }
    self.cache_emitted_files(compile_response.emit_map)?;
    Ok(())
  }
/// Asynchronously compile module and all it's dependencies.
///
/// This method compiled every module at most once.
///
/// If `--reload` flag was provided then compiler will not on-disk cache and
/// force recompilation.
///
/// If compilation is required then new V8 worker is spawned with fresh TS
/// compiler.
Asynchronously compile module and all it's dependencies.
This method compiled every module at most once.

If `--reload` flag was provided then compiler will not on-disk cache and
force recompilation.

If compilation is required then new V8 worker is spawned with fresh TS
compiler.
Asynchronously compile module and all it ' s dependencies . This method compiled every module at most once . If ` -- reload ` flag was provided then compiler will not on - disk cache and force recompilation . If compilation is required then new V8 worker is spawned with fresh TS compiler .
pub async fn compile(
    &self,
    global_state: &Arc<GlobalState>,
    source_file: &SourceFile,
    target: TargetLib,
    module_graph: &ModuleGraph,
    allow_js: bool,
  ) -> Result<(), AnyError> {
    let module_url = source_file.url.clone();
    let build_info_key = self
      .disk_cache
      .get_cache_filename_with_extension(&module_url, "buildinfo");
    let build_info = match self.disk_cache.get(&build_info_key) {
      Ok(bytes) => Some(String::from_utf8(bytes)?),
      Err(_) => None,
    };
    // Only use disk cache if `--reload` flag was not used or this file has
    // already been compiled during current process lifetime.
    if (self.use_disk_cache || self.has_compiled(&source_file.url))
      && self.has_valid_cache(&source_file.url, &build_info)?
    {
      return Ok(());
    }
    let module_graph_json =
      serde_json::to_value(module_graph).expect("Failed to serialize data");
    let target = match target {
      TargetLib::Main => "main",
      TargetLib::Worker => "worker",
    };
    let root_names = vec![module_url.to_string()];
    let unstable = self.flags.unstable;
    let performance = matches!(self.flags.log_level, Some(Level::Debug));
    let compiler_config = self.config.clone();
    // TODO(bartlomieju): lift this call up - TSC shouldn't print anything
    info!("{} {}", colors::green("Check"), module_url.to_string());
    let mut lib = if target == "main" {
      vec!["deno.window"]
    } else {
      vec!["deno.worker"]
    };
    if unstable {
      lib.push("deno.unstable");
    }
    let mut compiler_options = json!({
      "allowJs": allow_js,
      "allowNonTsExtensions": true,
      "checkJs": false,
      "esModuleInterop": true,
      "incremental": true,
      "inlineSourceMap": true,
      // TODO(lucacasonato): enable this by default in 1.5.0
      "isolatedModules": unstable,
      "importsNotUsedAsValues": if unstable { "error" } else { "remove" },
      "jsx": "react",
      "lib": lib,
      "module": "esnext",
      "outDir": "deno://",
      "resolveJsonModule": true,
      "sourceMap": false,
      "strict": true,
      "removeComments": true,
      "target": "esnext",
      "tsBuildInfoFile": "cache:///tsbuildinfo.json",
    });
    tsc_config::json_merge(&mut compiler_options, &compiler_config.options);
    warn_ignored_options(
      compiler_config.maybe_ignored_options,
      compiler_config.path.as_ref().unwrap(),
    );
    let j = json!({
      "type": CompilerRequestType::Compile,
      "target": target,
      "rootNames": root_names,
      "performance": performance,
      "compilerOptions": compiler_options,
      "sourceFileMap": module_graph_json,
      "buildInfo": if self.use_disk_cache { build_info } else { None },
    });
    let req_msg = j.to_string();
    let json_str = execute_in_tsc(global_state.clone(), req_msg)?;
    let compile_response: CompileResponse = serde_json::from_str(&json_str)?;
    if !compile_response.diagnostics.0.is_empty() {
      return Err(generic_error(compile_response.diagnostics.to_string()));
    }
    maybe_log_stats(compile_response.stats);
    if let Some(build_info) = compile_response.build_info {
      self.cache_build_info(&module_url, build_info)?;
    }
    self.cache_emitted_files(compile_response.emit_map)?;
    Ok(())
  }
pub async fn compile ( & self , global_state : & Arc < GlobalState > , source_file : & SourceFile , target : TargetLib , module_graph : & ModuleGraph , allow_js : bool , ) -> Result < ( ) , AnyError > { let module_url = source_file . url . clone ( ) ; let build_info_key = self . disk_cache . get_cache_filename_with_extension ( & module_url , " " ) ; let build_info = match self . disk_cache . get ( & build_info_key ) { Ok ( bytes ) => Some ( String :: from_utf8 ( bytes ) ? ) , Err ( _ ) => None , } ; // Only use disk cache if `--reload` flag was not used or this file has // already been compiled during current process lifetime. if ( self . use_disk_cache || self . has_compiled ( & source_file . url ) ) && self . has_valid_cache ( & source_file . url , & build_info ) ? { return Ok ( ( ) ) ; } let module_graph_json = serde_json :: to_value ( module_graph ) . expect ( " " ) ; let target = match target { TargetLib :: Main => " " , TargetLib :: Worker => " " , } ; let root_names = vec ! [ module_url to_string ( ) ] ; let unstable = self . flags . unstable ; let performance = matches ! ( self flags log_level Some ( Level Debug ) ) ; let compiler_config = self . config . clone ( ) ; // TODO(bartlomieju): lift this call up - TSC shouldn't print anything info ! ( " " colors green ( " " ) module_url to_string ( ) ) ; let mut lib = if target == " " { vec ! [ " " ] } else { vec ! [ " " ] } ; if unstable { lib . push ( " " ) ; } let mut compiler_options = json ! ( { " " allow_js " " true " " false " " true " " true " " true // TODO(lucacasonato): enable this by default in 1.5.0 " " unstable " " if unstable { " " } else { " " } " " " " " " lib " " " " " " " " " " true " " false " " true " " true " " " " " " " " } ) ; tsc_config :: json_merge ( & mut compiler_options , & compiler_config . options ) ; warn_ignored_options ( compiler_config . maybe_ignored_options , compiler_config . path . as_ref ( ) . unwrap ( ) , ) ; let j = json ! ( { " " CompilerRequestType Compile " " target " " root_names " " performance " " compiler_options " " module_graph_json " " if self use_disk_cache { build_info } else { None } } ) ; let req_msg = j . to_string ( ) ; let json_str = execute_in_tsc ( global_state . clone ( ) , req_msg ) ? ; let compile_response : CompileResponse = serde_json :: from_str ( & json_str ) ? ; if ! compile_response . diagnostics . 0 . is_empty ( ) { return Err ( generic_error ( compile_response . diagnostics . to_string ( ) ) ) ; } maybe_log_stats ( compile_response . stats ) ; if let Some ( build_info ) = compile_response . build_info { self . cache_build_info ( & module_url , build_info ) ? ; } self . cache_emitted_files ( compile_response . emit_map ) ? ; Ok ( ( ) ) }
Asynchronously compile module and all it's dependencies.
Asynchronously compile module and all it ' s dependencies .
&self
global_state
&Arc<GlobalState>
source_file
&SourceFile
target
TargetLib
module_graph
&ModuleGraph
allow_js
bool
&self
global_state
&Arc<GlobalState>
source_file
&SourceFile
target
TargetLib
module_graph
&ModuleGraph
allow_js
bool