pub async fn bundle(
    &self,
    global_state: GlobalState,
    module_specifier: ModuleSpecifier,
  ) -> Result<String, ErrBox> {
    debug!(
      "Invoking the compiler to bundle. module_name: {}",
      module_specifier.to_string()
    );

    let permissions = Permissions::allow_all();
    let mut module_graph_loader = ModuleGraphLoader::new(
      self.file_fetcher.clone(),
      global_state.maybe_import_map.clone(),
      permissions.clone(),
      false,
      true,
    );
    module_graph_loader
      .add_to_graph(&module_specifier, None)
      .await?;
    let module_graph = module_graph_loader.get_graph();
    let module_graph_files = module_graph.values().collect::<Vec<_>>();
    // Check integrity of every file in module graph
    if let Some(ref lockfile) = global_state.lockfile {
      let mut g = lockfile.lock().unwrap();

      for graph_file in &module_graph_files {
        let check_passed =
          g.check_or_insert(&graph_file.url, &graph_file.source_code);

        if !check_passed {
          eprintln!(
            "Subresource integrity check failed --lock={}\n{}",
            g.filename, graph_file.url
          );
          std::process::exit(10);
        }
      }
    }
    if let Some(ref lockfile) = global_state.lockfile {
      let g = lockfile.lock().unwrap();
      g.write()?;
    }
    let module_graph_json =
      serde_json::to_value(module_graph).expect("Failed to serialize data");

    let root_names = vec![module_specifier.to_string()];
    let target = "main";
    let cwd = std::env::current_dir().unwrap();
    let performance = match global_state.flags.log_level {
      Some(Level::Debug) => true,
      _ => false,
    };

    let compiler_config = self.config.clone();

    // TODO(bartlomieju): this is non-sense; CompilerConfig's `path` and `content` should
    // be optional
    let j = match (compiler_config.path, compiler_config.content) {
      (Some(config_path), Some(config_data)) => json!({
        "type": msg::CompilerRequestType::Bundle,
        "target": target,
        "rootNames": root_names,
        "unstable": self.flags.unstable,
        "performance": performance,
        "configPath": config_path,
        "config": str::from_utf8(&config_data).unwrap(),
        "cwd": cwd,
        "sourceFileMap": module_graph_json,
      }),
      _ => json!({
        "type": msg::CompilerRequestType::Bundle,
        "target": target,
        "rootNames": root_names,
        "unstable": self.flags.unstable,
        "performance": performance,
        "cwd": cwd,
        "sourceFileMap": module_graph_json,
      }),
    };

    let req_msg = j.to_string();

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

    let bundle_response: BundleResponse = serde_json::from_str(&json_str)?;

    maybe_log_stats(bundle_response.stats);

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

    assert!(bundle_response.bundle_output.is_some());
    let output = bundle_response.bundle_output.unwrap();
    Ok(output)
  }
/// For a given module, generate a single file JavaScript output that includes
/// all the dependencies for that module.
For a given module, generate a single file JavaScript output that includes
all the dependencies for that module.
For a given module generate a single file JavaScript output that includes all the dependencies for that module .
pub async fn bundle(
    &self,
    global_state: GlobalState,
    module_specifier: ModuleSpecifier,
  ) -> Result<String, ErrBox> {
    debug!(
      "Invoking the compiler to bundle. module_name: {}",
      module_specifier.to_string()
    );
    let permissions = Permissions::allow_all();
    let mut module_graph_loader = ModuleGraphLoader::new(
      self.file_fetcher.clone(),
      global_state.maybe_import_map.clone(),
      permissions.clone(),
      false,
      true,
    );
    module_graph_loader
      .add_to_graph(&module_specifier, None)
      .await?;
    let module_graph = module_graph_loader.get_graph();
    let module_graph_files = module_graph.values().collect::<Vec<_>>();
    // Check integrity of every file in module graph
    if let Some(ref lockfile) = global_state.lockfile {
      let mut g = lockfile.lock().unwrap();
      for graph_file in &module_graph_files {
        let check_passed =
          g.check_or_insert(&graph_file.url, &graph_file.source_code);
        if !check_passed {
          eprintln!(
            "Subresource integrity check failed --lock={}\n{}",
            g.filename, graph_file.url
          );
          std::process::exit(10);
        }
      }
    }
    if let Some(ref lockfile) = global_state.lockfile {
      let g = lockfile.lock().unwrap();
      g.write()?;
    }
    let module_graph_json =
      serde_json::to_value(module_graph).expect("Failed to serialize data");
    let root_names = vec![module_specifier.to_string()];
    let target = "main";
    let cwd = std::env::current_dir().unwrap();
    let performance = match global_state.flags.log_level {
      Some(Level::Debug) => true,
      _ => false,
    };
    let compiler_config = self.config.clone();
    // TODO(bartlomieju): this is non-sense; CompilerConfig's `path` and `content` should
    // be optional
    let j = match (compiler_config.path, compiler_config.content) {
      (Some(config_path), Some(config_data)) => json!({
        "type": msg::CompilerRequestType::Bundle,
        "target": target,
        "rootNames": root_names,
        "unstable": self.flags.unstable,
        "performance": performance,
        "configPath": config_path,
        "config": str::from_utf8(&config_data).unwrap(),
        "cwd": cwd,
        "sourceFileMap": module_graph_json,
      }),
      _ => json!({
        "type": msg::CompilerRequestType::Bundle,
        "target": target,
        "rootNames": root_names,
        "unstable": self.flags.unstable,
        "performance": performance,
        "cwd": cwd,
        "sourceFileMap": module_graph_json,
      }),
    };
    let req_msg = j.to_string();
    let json_str =
      execute_in_same_thread(global_state, permissions, req_msg).await?;
    let bundle_response: BundleResponse = serde_json::from_str(&json_str)?;
    maybe_log_stats(bundle_response.stats);
    if !bundle_response.diagnostics.items.is_empty() {
      return Err(ErrBox::from(bundle_response.diagnostics));
    }
    assert!(bundle_response.bundle_output.is_some());
    let output = bundle_response.bundle_output.unwrap();
    Ok(output)
  }
pub async fn bundle ( & self , global_state : GlobalState , module_specifier : ModuleSpecifier , ) -> Result < String , ErrBox > { debug ! ( " " module_specifier to_string ( ) ) ; let permissions = Permissions :: allow_all ( ) ; let mut module_graph_loader = ModuleGraphLoader :: new ( self . file_fetcher . clone ( ) , global_state . maybe_import_map . clone ( ) , permissions . clone ( ) , false , true , ) ; module_graph_loader . add_to_graph ( & module_specifier , None ) . await ? ; let module_graph = module_graph_loader . get_graph ( ) ; let module_graph_files = module_graph . values ( ) . collect :: < Vec < _ > > ( ) ; // Check integrity of every file in module graph if let Some ( ref lockfile ) = global_state . lockfile { let mut g = lockfile . lock ( ) . unwrap ( ) ; for graph_file in & module_graph_files { let check_passed = g . check_or_insert ( & graph_file . url , & graph_file . source_code ) ; if ! check_passed { eprintln ! ( " \n " g filename graph_file url ) ; std :: process :: exit ( 10 ) ; } } } if let Some ( ref lockfile ) = global_state . lockfile { let g = lockfile . lock ( ) . unwrap ( ) ; g . write ( ) ? ; } let module_graph_json = serde_json :: to_value ( module_graph ) . expect ( " " ) ; let root_names = vec ! [ module_specifier to_string ( ) ] ; let target = " " ; let cwd = std :: env :: current_dir ( ) . unwrap ( ) ; let performance = match global_state . flags . log_level { Some ( Level :: Debug ) => true , _ => false , } ; let compiler_config = self . config . clone ( ) ; // TODO(bartlomieju): this is non-sense; CompilerConfig's `path` and `content` should // be optional let j = match ( compiler_config . path , compiler_config . content ) { ( Some ( config_path ) , Some ( config_data ) ) => json ! ( { " " msg CompilerRequestType Bundle " " target " " root_names " " self flags unstable " " performance " " config_path " " str from_utf8 ( config_data ) unwrap ( ) " " cwd " " module_graph_json } ) , _ => json ! ( { " " msg CompilerRequestType Bundle " " target " " root_names " " self flags unstable " " performance " " cwd " " module_graph_json } ) , } ; let req_msg = j . to_string ( ) ; let json_str = execute_in_same_thread ( global_state , permissions , req_msg ) . await ? ; let bundle_response : BundleResponse = serde_json :: from_str ( & json_str ) ? ; maybe_log_stats ( bundle_response . stats ) ; if ! bundle_response . diagnostics . items . is_empty ( ) { return Err ( ErrBox :: from ( bundle_response . diagnostics ) ) ; } assert ! ( bundle_response bundle_output is_some ( ) ) ; let output = bundle_response . bundle_output . unwrap ( ) ; Ok ( output ) }
For a given module, generate a single file JavaScript output that includes
all the dependencies for that module.
For a given module generate a single file JavaScript output that includes all the dependencies for that module .
&self
global_state
GlobalState
module_specifier
ModuleSpecifier
&self
global_state
GlobalState
module_specifier
ModuleSpecifier