pub async fn prepare_module_load(
    &self,
    module_specifier: ModuleSpecifier,
    maybe_referrer: Option<ModuleSpecifier>,
    target_lib: TargetLib,
    permissions: Permissions,
    is_dyn_import: bool,
    maybe_import_map: Option<ImportMap>,
  ) -> Result<(), ErrBox> {
    let module_specifier = module_specifier.clone();

    // TODO(ry) Try to lift compile_lock as high up in the call stack for
    // sanity.
    let compile_lock = self.compile_lock.lock().await;

    let mut module_graph_loader = ModuleGraphLoader::new(
      self.file_fetcher.clone(),
      maybe_import_map,
      permissions.clone(),
      is_dyn_import,
      false,
    );
    module_graph_loader
      .add_to_graph(&module_specifier, maybe_referrer)
      .await?;
    let module_graph = module_graph_loader.get_graph();

    let out = self
      .file_fetcher
      .fetch_cached_source_file(&module_specifier, permissions.clone())
      .expect("Source file not found");

    // Check if we need to compile files
    let needs_compilation = match out.media_type {
      msg::MediaType::TypeScript
      | msg::MediaType::TSX
      | msg::MediaType::JSX => true,
      msg::MediaType::JavaScript => self.ts_compiler.compile_js,
      _ => false,
    };

    if needs_compilation {
      self
        .ts_compiler
        .compile_module_graph(
          self.clone(),
          &out,
          target_lib,
          permissions,
          module_graph,
        )
        .await?;
    }

    drop(compile_lock);

    Ok(())
  }
/// This function is called when new module load is
/// initialized by the EsIsolate. Its resposibility is to collect
/// all dependencies and if it is required then also perform TS typecheck
/// and traspilation.
This function is called when new module load is
initialized by the EsIsolate. Its resposibility is to collect
all dependencies and if it is required then also perform TS typecheck
and traspilation.
This function is called when new module load is initialized by the EsIsolate . Its resposibility is to collect all dependencies and if it is required then also perform TS typecheck and traspilation .
pub async fn prepare_module_load(
    &self,
    module_specifier: ModuleSpecifier,
    maybe_referrer: Option<ModuleSpecifier>,
    target_lib: TargetLib,
    permissions: Permissions,
    is_dyn_import: bool,
    maybe_import_map: Option<ImportMap>,
  ) -> Result<(), ErrBox> {
    let module_specifier = module_specifier.clone();
    // TODO(ry) Try to lift compile_lock as high up in the call stack for
    // sanity.
    let compile_lock = self.compile_lock.lock().await;
    let mut module_graph_loader = ModuleGraphLoader::new(
      self.file_fetcher.clone(),
      maybe_import_map,
      permissions.clone(),
      is_dyn_import,
      false,
    );
    module_graph_loader
      .add_to_graph(&module_specifier, maybe_referrer)
      .await?;
    let module_graph = module_graph_loader.get_graph();
    let out = self
      .file_fetcher
      .fetch_cached_source_file(&module_specifier, permissions.clone())
      .expect("Source file not found");
    // Check if we need to compile files
    let needs_compilation = match out.media_type {
      msg::MediaType::TypeScript
      | msg::MediaType::TSX
      | msg::MediaType::JSX => true,
      msg::MediaType::JavaScript => self.ts_compiler.compile_js,
      _ => false,
    };
    if needs_compilation {
      self
        .ts_compiler
        .compile_module_graph(
          self.clone(),
          &out,
          target_lib,
          permissions,
          module_graph,
        )
        .await?;
    }
    drop(compile_lock);
    Ok(())
  }
pub async fn prepare_module_load ( & self , module_specifier : ModuleSpecifier , maybe_referrer : Option < ModuleSpecifier > , target_lib : TargetLib , permissions : Permissions , is_dyn_import : bool , maybe_import_map : Option < ImportMap > , ) -> Result < ( ) , ErrBox > { let module_specifier = module_specifier . clone ( ) ; // TODO(ry) Try to lift compile_lock as high up in the call stack for // sanity. let compile_lock = self . compile_lock . lock ( ) . await ; let mut module_graph_loader = ModuleGraphLoader :: new ( self . file_fetcher . clone ( ) , maybe_import_map , permissions . clone ( ) , is_dyn_import , false , ) ; module_graph_loader . add_to_graph ( & module_specifier , maybe_referrer ) . await ? ; let module_graph = module_graph_loader . get_graph ( ) ; let out = self . file_fetcher . fetch_cached_source_file ( & module_specifier , permissions . clone ( ) ) . expect ( " " ) ; // Check if we need to compile files let needs_compilation = match out . media_type { msg :: MediaType :: TypeScript | msg :: MediaType :: TSX | msg :: MediaType :: JSX => true , msg :: MediaType :: JavaScript => self . ts_compiler . compile_js , _ => false , } ; if needs_compilation { self . ts_compiler . compile_module_graph ( self . clone ( ) , & out , target_lib , permissions , module_graph , ) . await ? ; } drop ( compile_lock ) ; Ok ( ( ) ) }
This function is called when new module load is
initialized by the EsIsolate.
This function is called when new module load is initialized by the EsIsolate .
&self
module_specifier
ModuleSpecifier
maybe_referrer
Option<ModuleSpecifier>
target_lib
TargetLib
permissions
Permissions
is_dyn_import
bool
maybe_import_map
Option<ImportMap>
&self
module_specifier
ModuleSpecifier
maybe_referrer
Option<ModuleSpecifier>
target_lib
TargetLib
permissions
Permissions
is_dyn_import
bool
maybe_import_map
Option<ImportMap>