pub async fn compile(
    &self,
    global_state: GlobalState,
    source_file: &SourceFile,
    target: TargetLib,
    permissions: Permissions,
    module_graph: ModuleGraph,
    allow_js: bool,
  ) -> Result<(), ErrBox> {
    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 = match self.flags.log_level {
      Some(Level::Debug) => true,
      _ => false,
    };
    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,
        "allowJs": allow_js,
        "target": target,
        "rootNames": root_names,
        "unstable": unstable,
        "performance": performance,
        "configPath": config_path,
        "config": str::from_utf8(&config_data).unwrap(),
        "cwd": cwd,
        "sourceFileMap": module_graph_json,
        "buildInfo": if self.use_disk_cache { build_info } else { None },
      }),
      _ => json!({
        "type": msg::CompilerRequestType::Compile,
        "allowJs": allow_js,
        "target": target,
        "rootNames": root_names,
        "unstable": unstable,
        "performance": performance,
        "cwd": cwd,
        "sourceFileMap": module_graph_json,
        "buildInfo": if self.use_disk_cache { build_info } else { None },
      }),
    };

    let req_msg = j.to_string();

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

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

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

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

    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: GlobalState,
    source_file: &SourceFile,
    target: TargetLib,
    permissions: Permissions,
    module_graph: ModuleGraph,
    allow_js: bool,
  ) -> Result<(), ErrBox> {
    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 = match self.flags.log_level {
      Some(Level::Debug) => true,
      _ => false,
    };
    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,
        "allowJs": allow_js,
        "target": target,
        "rootNames": root_names,
        "unstable": unstable,
        "performance": performance,
        "configPath": config_path,
        "config": str::from_utf8(&config_data).unwrap(),
        "cwd": cwd,
        "sourceFileMap": module_graph_json,
        "buildInfo": if self.use_disk_cache { build_info } else { None },
      }),
      _ => json!({
        "type": msg::CompilerRequestType::Compile,
        "allowJs": allow_js,
        "target": target,
        "rootNames": root_names,
        "unstable": unstable,
        "performance": performance,
        "cwd": cwd,
        "sourceFileMap": module_graph_json,
        "buildInfo": if self.use_disk_cache { build_info } else { None },
      }),
    };
    let req_msg = j.to_string();
    // TODO(bartlomieju): lift this call up - TSC shouldn't print anything
    info!("{} {}", colors::green("Check"), module_url.to_string());
    let json_str =
      execute_in_same_thread(global_state, permissions, req_msg).await?;
    let compile_response: CompileResponse = serde_json::from_str(&json_str)?;
    if !compile_response.diagnostics.items.is_empty() {
      return Err(ErrBox::from(compile_response.diagnostics));
    }
    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 : GlobalState , source_file : & SourceFile , target : TargetLib , permissions : Permissions , module_graph : ModuleGraph , allow_js : bool , ) -> Result < ( ) , ErrBox > { 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 = match self . flags . log_level { Some ( Level :: Debug ) => true , _ => false , } ; 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 " " allow_js " " target " " root_names " " unstable " " performance " " config_path " " str from_utf8 ( config_data ) unwrap ( ) " " cwd " " module_graph_json " " if self use_disk_cache { build_info } else { None } } ) , _ => json ! ( { " " msg CompilerRequestType Compile " " allow_js " " target " " root_names " " unstable " " performance " " cwd " " module_graph_json " " if self use_disk_cache { build_info } else { None } } ) , } ; let req_msg = j . to_string ( ) ; // TODO(bartlomieju): lift this call up - TSC shouldn't print anything info ! ( " " colors green ( " " ) module_url to_string ( ) ) ; let json_str = execute_in_same_thread ( global_state , permissions , req_msg ) . await ? ; let compile_response : CompileResponse = serde_json :: from_str ( & json_str ) ? ; if ! compile_response . diagnostics . items . is_empty ( ) { return Err ( ErrBox :: from ( compile_response . diagnostics ) ) ; } 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
GlobalState
source_file
&SourceFile
target
TargetLib
permissions
Permissions
module_graph
ModuleGraph
allow_js
bool
&self
global_state
GlobalState
source_file
&SourceFile
target
TargetLib
permissions
Permissions
module_graph
ModuleGraph
allow_js
bool