pub async fn compile_module_graph(
    &self,
    global_state: GlobalState,
    source_file: &SourceFile,
    target: TargetLib,
    permissions: Permissions,
    module_graph: HashMap<String, ModuleGraphFile>,
  ) -> Result<(), ErrBox> {
    let mut has_cached_version = false;

    if self.use_disk_cache {
      if let Some(metadata) = self.get_graph_metadata(&source_file.url) {
        has_cached_version = true;

        let version_hash = crate::checksum::gen(vec![
          version::DENO.as_bytes(),
          &self.config.hash,
        ]);

        has_cached_version &= metadata.version_hash == version_hash;
        has_cached_version &= self
          .has_compiled_source(&global_state.file_fetcher, &source_file.url);

        for dep in metadata.deps {
          let url = Url::parse(&dep).expect("Dep is not a valid url");
          has_cached_version &=
            self.has_compiled_source(&global_state.file_fetcher, &url);
        }
      }
    }

    if has_cached_version {
      return Ok(());
    }

    let module_url = source_file.url.clone();

    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 bundle = false;
    let unstable = global_state.flags.unstable;
    let compiler_config = self.config.clone();
    let cwd = std::env::current_dir().unwrap();
    let j = match (compiler_config.path, compiler_config.content) {
      (Some(config_path), Some(config_data)) => json!({
        "type": msg::CompilerRequestType::Compile as i32,
        "target": target,
        "rootNames": root_names,
        "bundle": bundle,
        "unstable": unstable,
        "configPath": config_path,
        "config": str::from_utf8(&config_data).unwrap(),
        "cwd": cwd,
        "sourceFileMap": module_graph_json,
      }),
      _ => json!({
        "type": msg::CompilerRequestType::Compile as i32,
        "target": target,
        "rootNames": root_names,
        "bundle": bundle,
        "unstable": unstable,
        "cwd": cwd,
        "sourceFileMap": module_graph_json,
      }),
    };

    let req_msg = j.to_string().into_boxed_str().into_boxed_bytes();

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

    let msg =
      execute_in_same_thread(global_state.clone(), permissions, req_msg)
        .await?;

    let json_str = std::str::from_utf8(&msg).unwrap();

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

    if !compile_response.diagnostics.items.is_empty() {
      return Err(ErrBox::from(compile_response.diagnostics));
    }

    self.set_graph_metadata(
      source_file.url.clone(),
      &compile_response.emit_map,
    )?;
    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_module_graph(
    &self,
    global_state: GlobalState,
    source_file: &SourceFile,
    target: TargetLib,
    permissions: Permissions,
    module_graph: HashMap<String, ModuleGraphFile>,
  ) -> Result<(), ErrBox> {
    let mut has_cached_version = false;
    if self.use_disk_cache {
      if let Some(metadata) = self.get_graph_metadata(&source_file.url) {
        has_cached_version = true;
        let version_hash = crate::checksum::gen(vec![
          version::DENO.as_bytes(),
          &self.config.hash,
        ]);
        has_cached_version &= metadata.version_hash == version_hash;
        has_cached_version &= self
          .has_compiled_source(&global_state.file_fetcher, &source_file.url);
        for dep in metadata.deps {
          let url = Url::parse(&dep).expect("Dep is not a valid url");
          has_cached_version &=
            self.has_compiled_source(&global_state.file_fetcher, &url);
        }
      }
    }
    if has_cached_version {
      return Ok(());
    }
    let module_url = source_file.url.clone();
    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 bundle = false;
    let unstable = global_state.flags.unstable;
    let compiler_config = self.config.clone();
    let cwd = std::env::current_dir().unwrap();
    let j = match (compiler_config.path, compiler_config.content) {
      (Some(config_path), Some(config_data)) => json!({
        "type": msg::CompilerRequestType::Compile as i32,
        "target": target,
        "rootNames": root_names,
        "bundle": bundle,
        "unstable": unstable,
        "configPath": config_path,
        "config": str::from_utf8(&config_data).unwrap(),
        "cwd": cwd,
        "sourceFileMap": module_graph_json,
      }),
      _ => json!({
        "type": msg::CompilerRequestType::Compile as i32,
        "target": target,
        "rootNames": root_names,
        "bundle": bundle,
        "unstable": unstable,
        "cwd": cwd,
        "sourceFileMap": module_graph_json,
      }),
    };
    let req_msg = j.to_string().into_boxed_str().into_boxed_bytes();
    // TODO(bartlomieju): lift this call up - TSC shouldn't print anything
    info!(
      "{} {}",
      colors::green("Compile".to_string()),
      module_url.to_string()
    );
    let msg =
      execute_in_same_thread(global_state.clone(), permissions, req_msg)
        .await?;
    let json_str = std::str::from_utf8(&msg).unwrap();
    let compile_response: CompileResponse = serde_json::from_str(json_str)?;
    if !compile_response.diagnostics.items.is_empty() {
      return Err(ErrBox::from(compile_response.diagnostics));
    }
    self.set_graph_metadata(
      source_file.url.clone(),
      &compile_response.emit_map,
    )?;
    self.cache_emitted_files(compile_response.emit_map)?;
    Ok(())
  }
pub async fn compile_module_graph ( & self , global_state : GlobalState , source_file : & SourceFile , target : TargetLib , permissions : Permissions , module_graph : HashMap < String , ModuleGraphFile > , ) -> Result < ( ) , ErrBox > { let mut has_cached_version = false ; if self . use_disk_cache { if let Some ( metadata ) = self . get_graph_metadata ( & source_file . url ) { has_cached_version = true ; let version_hash = crate :: checksum :: gen ( vec ! [ version DENO as_bytes ( ) self config hash ] ) ; has_cached_version &= metadata . version_hash == version_hash ; has_cached_version &= self . has_compiled_source ( & global_state . file_fetcher , & source_file . url ) ; for dep in metadata . deps { let url = Url :: parse ( & dep ) . expect ( " " ) ; has_cached_version &= self . has_compiled_source ( & global_state . file_fetcher , & url ) ; } } } if has_cached_version { return Ok ( ( ) ) ; } let module_url = source_file . url . clone ( ) ; 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 bundle = false ; let unstable = global_state . flags . unstable ; let compiler_config = self . config . clone ( ) ; let cwd = std :: env :: current_dir ( ) . unwrap ( ) ; let j = match ( compiler_config . path , compiler_config . content ) { ( Some ( config_path ) , Some ( config_data ) ) => json ! ( { " " msg CompilerRequestType Compile as i32 " " target " " root_names " " bundle " " unstable " " config_path " " str from_utf8 ( config_data ) unwrap ( ) " " cwd " " module_graph_json } ) , _ => json ! ( { " " msg CompilerRequestType Compile as i32 " " target " " root_names " " bundle " " unstable " " cwd " " module_graph_json } ) , } ; let req_msg = j . to_string ( ) . into_boxed_str ( ) . into_boxed_bytes ( ) ; // TODO(bartlomieju): lift this call up - TSC shouldn't print anything info ! ( " " colors green ( " " to_string ( ) ) module_url to_string ( ) ) ; let msg = execute_in_same_thread ( global_state . clone ( ) , permissions , req_msg ) . await ? ; let json_str = std :: str :: from_utf8 ( & msg ) . unwrap ( ) ; let compile_response : CompileResponse = serde_json :: from_str ( json_str ) ? ; if ! compile_response . diagnostics . items . is_empty ( ) { return Err ( ErrBox :: from ( compile_response . diagnostics ) ) ; } self . set_graph_metadata ( source_file . url . clone ( ) , & compile_response . emit_map , ) ? ; 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
GlobalState
source_file
&SourceFile
target
TargetLib
permissions
Permissions
module_graph
HashMap<String, ModuleGraphFile>
&self
global_state
GlobalState
source_file
&SourceFile
target
TargetLib
permissions
Permissions
module_graph
HashMap<String, ModuleGraphFile>