diff options
Diffstat (limited to 'cli/tsc.rs')
-rw-r--r-- | cli/tsc.rs | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/cli/tsc.rs b/cli/tsc.rs index 7c54905c5..834b0cc58 100644 --- a/cli/tsc.rs +++ b/cli/tsc.rs @@ -110,6 +110,19 @@ fn hash_data_url( format!("data:///{}{}", hash, media_type.as_ts_extension()) } +fn hash_blob_url( + specifier: &ModuleSpecifier, + media_type: &MediaType, +) -> String { + assert_eq!( + specifier.scheme(), + "blob", + "Specifier must be a blob: specifier." + ); + let hash = crate::checksum::gen(&[specifier.path().as_bytes()]); + format!("blob:///{}{}", hash, media_type.as_ts_extension()) +} + /// tsc only supports `.ts`, `.tsx`, `.d.ts`, `.js`, or `.jsx` as root modules /// and so we have to detect the apparent media type based on extensions it /// supports. @@ -378,15 +391,19 @@ fn resolve(state: &mut State, args: Value) -> Result<Value, AnyError> { resolved_specifier ) }; - let resolved_specifier_str = if resolved_specifier.scheme() == "data" - { - let specifier_str = hash_data_url(&resolved_specifier, &media_type); - state - .data_url_map - .insert(specifier_str.clone(), resolved_specifier); - specifier_str - } else { - resolved_specifier.to_string() + let resolved_specifier_str = match resolved_specifier.scheme() { + "data" | "blob" => { + let specifier_str = if resolved_specifier.scheme() == "data" { + hash_data_url(&resolved_specifier, &media_type) + } else { + hash_blob_url(&resolved_specifier, &media_type) + }; + state + .data_url_map + .insert(specifier_str.clone(), resolved_specifier); + specifier_str + } + _ => resolved_specifier.to_string(), }; resolved.push(( resolved_specifier_str, @@ -439,12 +456,17 @@ pub fn exec(request: Request) -> Result<Response, AnyError> { let root_names: Vec<String> = request .root_names .iter() - .map(|(s, mt)| { - if s.scheme() == "data" { - let specifier_str = hash_data_url(s, mt); + .map(|(s, mt)| match s.scheme() { + "data" | "blob" => { + let specifier_str = if s.scheme() == "data" { + hash_data_url(&s, &mt) + } else { + hash_blob_url(&s, &mt) + }; data_url_map.insert(specifier_str.clone(), s.clone()); specifier_str - } else { + } + _ => { let ext_media_type = get_tsc_media_type(s); if mt != &ext_media_type { let new_specifier = format!("{}{}", s, mt.as_ts_extension()); |