Skip to content

Commit 5d83bef

Browse files
committed
Compile TypeScript incrementally
1 parent 9136984 commit 5d83bef

File tree

3 files changed

+158
-46
lines changed

3 files changed

+158
-46
lines changed

cli/compilers/ts.rs

+20-24
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ struct BundleResponse {
254254
struct CompileResponse {
255255
diagnostics: Diagnostic,
256256
emit_map: HashMap<String, EmittedSource>,
257+
sources: Vec<String>,
257258
}
258259

259260
// TODO(bartlomieju): possible deduplicate once TS refactor is stabilized
@@ -392,29 +393,6 @@ impl TsCompiler {
392393
return self.get_compiled_module(&source_file.url);
393394
}
394395

395-
if self.use_disk_cache {
396-
// Try to load cached version:
397-
// 1. check if there's 'meta' file
398-
if let Some(metadata) = self.get_metadata(&source_file.url) {
399-
// 2. compare version hashes
400-
// TODO: it would probably be good idea to make it method implemented on SourceFile
401-
let version_hash_to_validate = source_code_version_hash(
402-
&source_file.source_code,
403-
version::DENO,
404-
&self.config.hash,
405-
);
406-
407-
if metadata.version_hash == version_hash_to_validate {
408-
debug!("load_cache metadata version hash match");
409-
if let Ok(compiled_module) =
410-
self.get_compiled_module(&source_file.url)
411-
{
412-
self.mark_compiled(&source_file.url);
413-
return Ok(compiled_module);
414-
}
415-
}
416-
}
417-
}
418396
let source_file_ = source_file.clone();
419397
let module_url = source_file.url.clone();
420398
let target = match target {
@@ -444,6 +422,11 @@ impl TsCompiler {
444422

445423
let compile_response: CompileResponse = serde_json::from_str(json_str)?;
446424

425+
for source in compile_response.sources.iter() {
426+
let ref url = Url::parse(source)?;
427+
self.mark_compiled(url);
428+
}
429+
447430
if !compile_response.diagnostics.items.is_empty() {
448431
return Err(ErrBox::from(compile_response.diagnostics));
449432
}
@@ -484,6 +467,8 @@ impl TsCompiler {
484467
self.cache_source_map(&specifier, &source.contents)?;
485468
} else if emitted_name.ends_with(".js") {
486469
self.cache_compiled_file(&specifier, &source.contents)?;
470+
} else if emitted_name.ends_with("tsbuildinfo.json") {
471+
self.cache_build_info(&specifier, &source.contents)?;
487472
} else {
488473
panic!("Trying to cache unknown file type {}", emitted_name);
489474
}
@@ -558,7 +543,6 @@ impl TsCompiler {
558543
.disk_cache
559544
.get_cache_filename_with_extension(module_specifier.as_url(), "js");
560545
self.disk_cache.set(&js_key, contents.as_bytes())?;
561-
self.mark_compiled(module_specifier.as_url());
562546

563547
let version_hash = source_code_version_hash(
564548
&source_file.source_code,
@@ -627,6 +611,18 @@ impl TsCompiler {
627611
.get_cache_filename_with_extension(module_specifier.as_url(), "js.map");
628612
self.disk_cache.set(&source_map_key, contents.as_bytes())
629613
}
614+
615+
/// Save TS build info file to on-disk cache.
616+
fn cache_build_info(
617+
&self,
618+
module_specifier: &ModuleSpecifier,
619+
contents: &str,
620+
) -> std::io::Result<()> {
621+
let build_info_key = self
622+
.disk_cache
623+
.get_cache_filename(module_specifier.as_url());
624+
self.disk_cache.set(&build_info_key, contents.as_bytes())
625+
}
630626
}
631627

632628
impl SourceMapGetter for TsCompiler {

0 commit comments

Comments
 (0)