pub async fn bundle(
    &self,
    global_state: &Arc<GlobalState>,
    module_specifier: ModuleSpecifier,
  ) -> Result<String, AnyError> {
    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 performance =
      matches!(global_state.flags.log_level, Some(Level::Debug));
    let unstable = self.flags.unstable;

    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": true,
      "allowNonTsExtensions": true,
      "checkJs": false,
      "esModuleInterop": true,
      "inlineSourceMap": false,
      "jsx": "react",
      "lib": lib,
      "module": "system",
      "outFile": "deno:///bundle.js",
      // disabled until we have effective way to modify source maps
      "sourceMap": false,
      "strict": true,
      "removeComments": true,
      "target": "esnext",
    });

    let compiler_config = self.config.clone();

    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::Bundle,
      "target": target,
      "rootNames": root_names,
      "performance": performance,
      "compilerOptions": compiler_options,
      "sourceFileMap": module_graph_json,
    });

    let req_msg = j.to_string();

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

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

    maybe_log_stats(bundle_response.stats);

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

    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: &Arc<GlobalState>,
    module_specifier: ModuleSpecifier,
  ) -> Result<String, AnyError> {
    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 performance =
      matches!(global_state.flags.log_level, Some(Level::Debug));
    let unstable = self.flags.unstable;
    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": true,
      "allowNonTsExtensions": true,
      "checkJs": false,
      "esModuleInterop": true,
      "inlineSourceMap": false,
      "jsx": "react",
      "lib": lib,
      "module": "system",
      "outFile": "deno:///bundle.js",
      // disabled until we have effective way to modify source maps
      "sourceMap": false,
      "strict": true,
      "removeComments": true,
      "target": "esnext",
    });
    let compiler_config = self.config.clone();
    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::Bundle,
      "target": target,
      "rootNames": root_names,
      "performance": performance,
      "compilerOptions": compiler_options,
      "sourceFileMap": module_graph_json,
    });
    let req_msg = j.to_string();
    let json_str = execute_in_tsc(global_state.clone(), req_msg)?;
    let bundle_response: BundleResponse = serde_json::from_str(&json_str)?;
    maybe_log_stats(bundle_response.stats);
    if !bundle_response.diagnostics.0.is_empty() {
      return Err(generic_error(bundle_response.diagnostics.to_string()));
    }
    assert!(bundle_response.bundle_output.is_some());
    let output = bundle_response.bundle_output.unwrap();
    Ok(output)
  }
pub async fn bundle ( & self , global_state : & Arc < GlobalState > , module_specifier : ModuleSpecifier , ) -> Result < String , AnyError > { 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 performance = matches ! ( global_state flags log_level Some ( Level Debug ) ) ; let unstable = self . flags . unstable ; let mut lib = if target == " " { vec ! [ " " ] } else { vec ! [ " " ] } ; if unstable { lib . push ( " " ) ; } let mut compiler_options = json ! ( { " " true " " true " " false " " true " " false " " " " " " lib " " " " " " " " // disabled until we have effective way to modify source maps " " false " " true " " true " " " " } ) ; let compiler_config = self . config . clone ( ) ; 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 Bundle " " target " " root_names " " performance " " compiler_options " " module_graph_json } ) ; let req_msg = j . to_string ( ) ; let json_str = execute_in_tsc ( global_state . clone ( ) , req_msg ) ? ; let bundle_response : BundleResponse = serde_json :: from_str ( & json_str ) ? ; maybe_log_stats ( bundle_response . stats ) ; if ! bundle_response . diagnostics . 0 . is_empty ( ) { return Err ( generic_error ( bundle_response . diagnostics . to_string ( ) ) ) ; } 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
&Arc<GlobalState>
module_specifier
ModuleSpecifier
&self
global_state
&Arc<GlobalState>
module_specifier
ModuleSpecifier