fn cache_compiled_file(
    &self,
    module_specifier: &ModuleSpecifier,
    source_file: SourceFile,
    contents: &str,
  ) -> std::io::Result<()> {
    // By default TSC output source map url that is relative; we need
    // to substitute it manually to correct file URL in DENO_DIR.
    let mut content_lines = contents
      .split('\n')
      .map(|s| s.to_string())
      .collect::<Vec<String>>();

    if !content_lines.is_empty() {
      let last_line = content_lines.pop().unwrap();
      if last_line.starts_with("//# sourceMappingURL=") {
        let source_map_key = self.disk_cache.get_cache_filename_with_extension(
          module_specifier.as_url(),
          "js.map",
        );
        let source_map_path = self.disk_cache.location.join(source_map_key);
        let source_map_file_url = Url::from_file_path(source_map_path)
          .expect("Bad file URL for source map");
        let new_last_line =
          format!("//# sourceMappingURL={}", source_map_file_url.to_string());
        content_lines.push(new_last_line);
      } else {
        content_lines.push(last_line);
      }
    }

    let contents = content_lines.join("\n");

    let js_key = self
      .disk_cache
      .get_cache_filename_with_extension(module_specifier.as_url(), "js");
    self.disk_cache.set(&js_key, contents.as_bytes())?;
    self.mark_compiled(module_specifier.as_url());

    let version_hash = source_code_version_hash(
      &source_file.source_code,
      version::DENO,
      &self.config.hash,
    );

    let compiled_file_metadata = CompiledFileMetadata {
      source_path: source_file.filename,
      version_hash,
    };
    let meta_key = self
      .disk_cache
      .get_cache_filename_with_extension(module_specifier.as_url(), "meta");
    self.disk_cache.set(
      &meta_key,
      compiled_file_metadata.to_json_string()?.as_bytes(),
    )
  }
/// Save compiled JS file for given TS module to on-disk cache.
///
/// Along compiled file a special metadata file is saved as well containing
/// hash that can be validated to avoid unnecessary recompilation.
Save compiled JS file for given TS module to on-disk cache.
Along compiled file a special metadata file is saved as well containing
hash that can be validated to avoid unnecessary recompilation.
Save compiled JS file for given TS module to on - disk cache . Along compiled file a special metadata file is saved as well containing hash that can be validated to avoid unnecessary recompilation .
fn cache_compiled_file(
    &self,
    module_specifier: &ModuleSpecifier,
    source_file: SourceFile,
    contents: &str,
  ) -> std::io::Result<()> {
    // By default TSC output source map url that is relative; we need
    // to substitute it manually to correct file URL in DENO_DIR.
    let mut content_lines = contents
      .split('\n')
      .map(|s| s.to_string())
      .collect::<Vec<String>>();
    if !content_lines.is_empty() {
      let last_line = content_lines.pop().unwrap();
      if last_line.starts_with("//# sourceMappingURL=") {
        let source_map_key = self.disk_cache.get_cache_filename_with_extension(
          module_specifier.as_url(),
          "js.map",
        );
        let source_map_path = self.disk_cache.location.join(source_map_key);
        let source_map_file_url = Url::from_file_path(source_map_path)
          .expect("Bad file URL for source map");
        let new_last_line =
          format!("//# sourceMappingURL={}", source_map_file_url.to_string());
        content_lines.push(new_last_line);
      } else {
        content_lines.push(last_line);
      }
    }
    let contents = content_lines.join("\n");
    let js_key = self
      .disk_cache
      .get_cache_filename_with_extension(module_specifier.as_url(), "js");
    self.disk_cache.set(&js_key, contents.as_bytes())?;
    self.mark_compiled(module_specifier.as_url());
    let version_hash = source_code_version_hash(
      &source_file.source_code,
      version::DENO,
      &self.config.hash,
    );
    let compiled_file_metadata = CompiledFileMetadata {
      source_path: source_file.filename,
      version_hash,
    };
    let meta_key = self
      .disk_cache
      .get_cache_filename_with_extension(module_specifier.as_url(), "meta");
    self.disk_cache.set(
      &meta_key,
      compiled_file_metadata.to_json_string()?.as_bytes(),
    )
  }
fn cache_compiled_file ( & self , module_specifier : & ModuleSpecifier , source_file : SourceFile , contents : & str , ) -> std :: io :: Result < ( ) > { // By default TSC output source map url that is relative; we need // to substitute it manually to correct file URL in DENO_DIR. let mut content_lines = contents . split ( '\n' ) . map ( | s | s . to_string ( ) ) . collect :: < Vec < String > > ( ) ; if ! content_lines . is_empty ( ) { let last_line = content_lines . pop ( ) . unwrap ( ) ; if last_line . starts_with ( " " ) { let source_map_key = self . disk_cache . get_cache_filename_with_extension ( module_specifier . as_url ( ) , " " , ) ; let source_map_path = self . disk_cache . location . join ( source_map_key ) ; let source_map_file_url = Url :: from_file_path ( source_map_path ) . expect ( " " ) ; let new_last_line = format ! ( " " source_map_file_url to_string ( ) ) ; content_lines . push ( new_last_line ) ; } else { content_lines . push ( last_line ) ; } } let contents = content_lines . join ( " \n " ) ; let js_key = self . disk_cache . get_cache_filename_with_extension ( module_specifier . as_url ( ) , " " ) ; self . disk_cache . set ( & js_key , contents . as_bytes ( ) ) ? ; self . mark_compiled ( module_specifier . as_url ( ) ) ; let version_hash = source_code_version_hash ( & source_file . source_code , version :: DENO , & self . config . hash , ) ; let compiled_file_metadata = CompiledFileMetadata { source_path : source_file . filename , version_hash , } ; let meta_key = self . disk_cache . get_cache_filename_with_extension ( module_specifier . as_url ( ) , " " ) ; self . disk_cache . set ( & meta_key , compiled_file_metadata . to_json_string ( ) ? . as_bytes ( ) , ) }
Save compiled JS file for given TS module to on-disk cache.
Save compiled JS file for given TS module to on - disk cache .
&self
module_specifier
&ModuleSpecifier
source_file
SourceFile
contents
&str
&self
module_specifier
&ModuleSpecifier
source_file
SourceFile
contents
&str