Incremental compilation for TypeScript (#6428)

This commit adds incremental compilation capabilities to internal TS compiler.

Instead of using "ts.createProgram()" API for compilation step (during deno 
startup), "ts.createIncrementalProgram()" API is used instead.

Thanks to TS' ".tsbuildinfo" file that already stores all necessary metadata
for compilation I was able to remove our own invention that is ".graph" file. 
".tsbuildinfo" file is stored alongside compiled source and is used to 
cache-bust outdated dependencies, facilitated by the "version" field. 
The value for "version" field is computed in Rust during loading of module 
graph and is basically a hash of the file contents.

Please keep in mind that incremental compilation is only used for initial 
compilation (or dynamic imports compilation) - bundling and runtime compiler 
APIs haven't been changed at all.

Due to problems with source map I changed compilation settings to inline 
source map (inlineSourceMap instead of sourceMap).
This commit is contained in:
Bartek Iwańczuk 2020-06-24 16:59:12 +02:00 committed by GitHub
parent 3314b46321
commit 3cbd1075c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 245 additions and 188 deletions

View file

@ -1,5 +1,5 @@
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use crate::checksum;
use crate::doc::Location;
use crate::file_fetcher::map_file_extension;
use crate::file_fetcher::SourceFile;
@ -13,6 +13,7 @@ use crate::tsc::ImportDesc;
use crate::tsc::TsReferenceDesc;
use crate::tsc::TsReferenceKind;
use crate::tsc::AVAILABLE_LIBS;
use crate::version;
use deno_core::ErrBox;
use deno_core::ModuleSpecifier;
use futures::stream::FuturesUnordered;
@ -228,6 +229,7 @@ pub struct ModuleGraphFile {
pub url: String,
pub redirect: Option<String>,
pub filename: String,
pub version_hash: String,
pub imports: Vec<ImportDescriptor>,
pub referenced_files: Vec<ReferenceDescriptor>,
pub lib_directives: Vec<ReferenceDescriptor>,
@ -369,6 +371,7 @@ impl ModuleGraphLoader {
specifier: specifier.to_string(),
url: specifier.to_string(),
redirect: None,
version_hash: "".to_string(),
media_type: map_file_extension(&PathBuf::from(specifier.clone())),
filename: specifier,
source_code,
@ -454,6 +457,10 @@ impl ModuleGraphLoader {
url: module_specifier.to_string(),
redirect: Some(source_file.url.to_string()),
filename: source_file.filename.to_str().unwrap().to_string(),
version_hash: checksum::gen(vec![
&source_file.source_code,
version::DENO.as_bytes(),
]),
media_type: source_file.media_type,
source_code: "".to_string(),
imports: vec![],
@ -466,6 +473,8 @@ impl ModuleGraphLoader {
}
let module_specifier = ModuleSpecifier::from(source_file.url.clone());
let version_hash =
checksum::gen(vec![&source_file.source_code, version::DENO.as_bytes()]);
let source_code = String::from_utf8(source_file.source_code)?;
if SUPPORTED_MEDIA_TYPES.contains(&source_file.media_type) {
@ -553,6 +562,7 @@ impl ModuleGraphLoader {
specifier: module_specifier.to_string(),
url: module_specifier.to_string(),
redirect: None,
version_hash,
filename: source_file.filename.to_str().unwrap().to_string(),
media_type: source_file.media_type,
source_code,