mirror of
https://github.com/denoland/deno.git
synced 2025-10-03 07:34:36 +00:00
Remove _async from method names since _sync are gone (#4128)
This commit is contained in:
parent
fe181e2b48
commit
f47f3f9672
11 changed files with 81 additions and 90 deletions
|
@ -7,7 +7,7 @@ use std::str;
|
||||||
pub struct JsCompiler {}
|
pub struct JsCompiler {}
|
||||||
|
|
||||||
impl JsCompiler {
|
impl JsCompiler {
|
||||||
pub async fn compile_async(
|
pub async fn compile(
|
||||||
&self,
|
&self,
|
||||||
source_file: SourceFile,
|
source_file: SourceFile,
|
||||||
) -> Result<CompiledModule, ErrBox> {
|
) -> Result<CompiledModule, ErrBox> {
|
||||||
|
|
|
@ -10,7 +10,7 @@ static JS_RESERVED_WORDS: &str = r"^(?:do|if|in|for|let|new|try|var|case|else|en
|
||||||
pub struct JsonCompiler {}
|
pub struct JsonCompiler {}
|
||||||
|
|
||||||
impl JsonCompiler {
|
impl JsonCompiler {
|
||||||
pub async fn compile_async(
|
pub async fn compile(
|
||||||
&self,
|
&self,
|
||||||
source_file: &SourceFile,
|
source_file: &SourceFile,
|
||||||
) -> Result<CompiledModule, ErrBox> {
|
) -> Result<CompiledModule, ErrBox> {
|
||||||
|
|
|
@ -11,8 +11,8 @@ mod wasm;
|
||||||
|
|
||||||
pub use js::JsCompiler;
|
pub use js::JsCompiler;
|
||||||
pub use json::JsonCompiler;
|
pub use json::JsonCompiler;
|
||||||
pub use ts::runtime_compile_async;
|
pub use ts::runtime_compile;
|
||||||
pub use ts::runtime_transpile_async;
|
pub use ts::runtime_transpile;
|
||||||
pub use ts::TargetLib;
|
pub use ts::TargetLib;
|
||||||
pub use ts::TsCompiler;
|
pub use ts::TsCompiler;
|
||||||
pub use wasm::WasmCompiler;
|
pub use wasm::WasmCompiler;
|
||||||
|
|
|
@ -269,7 +269,7 @@ impl TsCompiler {
|
||||||
worker
|
worker
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn bundle_async(
|
pub async fn bundle(
|
||||||
&self,
|
&self,
|
||||||
global_state: GlobalState,
|
global_state: GlobalState,
|
||||||
module_name: String,
|
module_name: String,
|
||||||
|
@ -322,7 +322,7 @@ impl TsCompiler {
|
||||||
///
|
///
|
||||||
/// If compilation is required then new V8 worker is spawned with fresh TS
|
/// If compilation is required then new V8 worker is spawned with fresh TS
|
||||||
/// compiler.
|
/// compiler.
|
||||||
pub async fn compile_async(
|
pub async fn compile(
|
||||||
&self,
|
&self,
|
||||||
global_state: GlobalState,
|
global_state: GlobalState,
|
||||||
source_file: &SourceFile,
|
source_file: &SourceFile,
|
||||||
|
@ -641,7 +641,7 @@ async fn execute_in_thread_json(
|
||||||
Ok(json!(json_str))
|
Ok(json!(json_str))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn runtime_compile_async<S: BuildHasher>(
|
pub fn runtime_compile<S: BuildHasher>(
|
||||||
global_state: GlobalState,
|
global_state: GlobalState,
|
||||||
root_name: &str,
|
root_name: &str,
|
||||||
sources: &Option<HashMap<String, String, S>>,
|
sources: &Option<HashMap<String, String, S>>,
|
||||||
|
@ -663,7 +663,7 @@ pub fn runtime_compile_async<S: BuildHasher>(
|
||||||
execute_in_thread_json(req_msg, global_state).boxed_local()
|
execute_in_thread_json(req_msg, global_state).boxed_local()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn runtime_transpile_async<S: BuildHasher>(
|
pub fn runtime_transpile<S: BuildHasher>(
|
||||||
global_state: GlobalState,
|
global_state: GlobalState,
|
||||||
sources: &HashMap<String, String, S>,
|
sources: &HashMap<String, String, S>,
|
||||||
options: &Option<String>,
|
options: &Option<String>,
|
||||||
|
@ -689,7 +689,7 @@ mod tests {
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_compile_async() {
|
async fn test_compile() {
|
||||||
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||||
.parent()
|
.parent()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -707,7 +707,7 @@ mod tests {
|
||||||
GlobalState::mock(vec![String::from("deno"), String::from("hello.js")]);
|
GlobalState::mock(vec![String::from("deno"), String::from("hello.js")]);
|
||||||
let result = mock_state
|
let result = mock_state
|
||||||
.ts_compiler
|
.ts_compiler
|
||||||
.compile_async(mock_state.clone(), &out, TargetLib::Main)
|
.compile(mock_state.clone(), &out, TargetLib::Main)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
assert!(result
|
assert!(result
|
||||||
|
@ -718,7 +718,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_bundle_async() {
|
async fn test_bundle() {
|
||||||
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
let p = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
|
||||||
.parent()
|
.parent()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -736,7 +736,7 @@ mod tests {
|
||||||
|
|
||||||
let result = state
|
let result = state
|
||||||
.ts_compiler
|
.ts_compiler
|
||||||
.bundle_async(
|
.bundle(
|
||||||
state.clone(),
|
state.clone(),
|
||||||
module_name,
|
module_name,
|
||||||
Some(PathBuf::from("$deno$/bundle.js")),
|
Some(PathBuf::from("$deno$/bundle.js")),
|
||||||
|
|
|
@ -71,7 +71,7 @@ impl WasmCompiler {
|
||||||
worker
|
worker
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn compile_async(
|
pub async fn compile(
|
||||||
&self,
|
&self,
|
||||||
global_state: GlobalState,
|
global_state: GlobalState,
|
||||||
source_file: &SourceFile,
|
source_file: &SourceFile,
|
||||||
|
@ -84,7 +84,7 @@ impl WasmCompiler {
|
||||||
if let Some(m) = maybe_cached {
|
if let Some(m) = maybe_cached {
|
||||||
return Ok(m);
|
return Ok(m);
|
||||||
}
|
}
|
||||||
debug!(">>>>> wasm_compile_async START");
|
debug!(">>>>> wasm_compile START");
|
||||||
let base64_data = base64::encode(&source_file.source_code);
|
let base64_data = base64::encode(&source_file.source_code);
|
||||||
let url = source_file.url.clone();
|
let url = source_file.url.clone();
|
||||||
let req_msg = serde_json::to_string(&base64_data)
|
let req_msg = serde_json::to_string(&base64_data)
|
||||||
|
@ -108,7 +108,7 @@ impl WasmCompiler {
|
||||||
{
|
{
|
||||||
cache_.lock().unwrap().insert(url.clone(), module.clone());
|
cache_.lock().unwrap().insert(url.clone(), module.clone());
|
||||||
}
|
}
|
||||||
debug!("<<<<< wasm_compile_async END");
|
debug!("<<<<< wasm_compile END");
|
||||||
Ok(module)
|
Ok(module)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,18 +127,18 @@ impl SourceFileFetcher {
|
||||||
// future, because it doesn't actually do any asynchronous
|
// future, because it doesn't actually do any asynchronous
|
||||||
// action in that path.
|
// action in that path.
|
||||||
self
|
self
|
||||||
.get_source_file_async(specifier.as_url(), true, false, true)
|
.get_source_file(specifier.as_url(), true, false, true)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn fetch_source_file_async(
|
pub async fn fetch_source_file(
|
||||||
&self,
|
&self,
|
||||||
specifier: &ModuleSpecifier,
|
specifier: &ModuleSpecifier,
|
||||||
maybe_referrer: Option<ModuleSpecifier>,
|
maybe_referrer: Option<ModuleSpecifier>,
|
||||||
) -> Result<SourceFile, ErrBox> {
|
) -> Result<SourceFile, ErrBox> {
|
||||||
let module_url = specifier.as_url().to_owned();
|
let module_url = specifier.as_url().to_owned();
|
||||||
debug!("fetch_source_file_async specifier: {} ", &module_url);
|
debug!("fetch_source_file specifier: {} ", &module_url);
|
||||||
|
|
||||||
// Check if this file was already fetched and can be retrieved from in-process cache.
|
// Check if this file was already fetched and can be retrieved from in-process cache.
|
||||||
let maybe_cached_file = self.source_file_cache.get(specifier.to_string());
|
let maybe_cached_file = self.source_file_cache.get(specifier.to_string());
|
||||||
|
@ -150,7 +150,7 @@ impl SourceFileFetcher {
|
||||||
let specifier_ = specifier.clone();
|
let specifier_ = specifier.clone();
|
||||||
|
|
||||||
let result = self
|
let result = self
|
||||||
.get_source_file_async(
|
.get_source_file(
|
||||||
&module_url,
|
&module_url,
|
||||||
self.use_disk_cache,
|
self.use_disk_cache,
|
||||||
self.no_remote,
|
self.no_remote,
|
||||||
|
@ -218,7 +218,7 @@ impl SourceFileFetcher {
|
||||||
///
|
///
|
||||||
/// If `cached_only` is true then this method will fail for remote files
|
/// If `cached_only` is true then this method will fail for remote files
|
||||||
/// not already cached.
|
/// not already cached.
|
||||||
async fn get_source_file_async(
|
async fn get_source_file(
|
||||||
&self,
|
&self,
|
||||||
module_url: &Url,
|
module_url: &Url,
|
||||||
use_disk_cache: bool,
|
use_disk_cache: bool,
|
||||||
|
@ -248,7 +248,7 @@ impl SourceFileFetcher {
|
||||||
|
|
||||||
// Fetch remote file and cache on-disk for subsequent access
|
// Fetch remote file and cache on-disk for subsequent access
|
||||||
self
|
self
|
||||||
.fetch_remote_source_async(&module_url, use_disk_cache, cached_only, 10)
|
.fetch_remote_source(&module_url, use_disk_cache, cached_only, 10)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -346,7 +346,7 @@ impl SourceFileFetcher {
|
||||||
///
|
///
|
||||||
/// Note that this is a recursive method so it can't be "async", but rather return
|
/// Note that this is a recursive method so it can't be "async", but rather return
|
||||||
/// Pin<Box<..>>.
|
/// Pin<Box<..>>.
|
||||||
fn fetch_remote_source_async(
|
fn fetch_remote_source(
|
||||||
&self,
|
&self,
|
||||||
module_url: &Url,
|
module_url: &Url,
|
||||||
use_disk_cache: bool,
|
use_disk_cache: bool,
|
||||||
|
@ -419,7 +419,7 @@ impl SourceFileFetcher {
|
||||||
|
|
||||||
// Recurse
|
// Recurse
|
||||||
dir
|
dir
|
||||||
.fetch_remote_source_async(
|
.fetch_remote_source(
|
||||||
&new_module_url,
|
&new_module_url,
|
||||||
use_disk_cache,
|
use_disk_cache,
|
||||||
cached_only,
|
cached_only,
|
||||||
|
@ -738,7 +738,7 @@ mod tests {
|
||||||
let headers_file_name_2 = headers_file_name.clone();
|
let headers_file_name_2 = headers_file_name.clone();
|
||||||
|
|
||||||
let result = fetcher
|
let result = fetcher
|
||||||
.get_source_file_async(&module_url, true, false, false)
|
.get_source_file(&module_url, true, false, false)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let r = result.unwrap();
|
let r = result.unwrap();
|
||||||
|
@ -755,7 +755,7 @@ mod tests {
|
||||||
"{ \"content-type\": \"text/javascript\" }",
|
"{ \"content-type\": \"text/javascript\" }",
|
||||||
);
|
);
|
||||||
let result2 = fetcher_1
|
let result2 = fetcher_1
|
||||||
.get_source_file_async(&module_url, true, false, false)
|
.get_source_file(&module_url, true, false, false)
|
||||||
.await;
|
.await;
|
||||||
assert!(result2.is_ok());
|
assert!(result2.is_ok());
|
||||||
let r2 = result2.unwrap();
|
let r2 = result2.unwrap();
|
||||||
|
@ -763,7 +763,7 @@ mod tests {
|
||||||
r2.source_code,
|
r2.source_code,
|
||||||
&b"export { printHello } from \"./print_hello.ts\";\n"[..]
|
&b"export { printHello } from \"./print_hello.ts\";\n"[..]
|
||||||
);
|
);
|
||||||
// If get_source_file_async does not call remote, this should be JavaScript
|
// If get_source_file does not call remote, this should be JavaScript
|
||||||
// as we modified before! (we do not overwrite .headers.json due to no http fetch)
|
// as we modified before! (we do not overwrite .headers.json due to no http fetch)
|
||||||
assert_eq!(&(r2.media_type), &msg::MediaType::JavaScript);
|
assert_eq!(&(r2.media_type), &msg::MediaType::JavaScript);
|
||||||
let (_, headers) = fetcher_2.http_cache.get(&module_url_1).unwrap();
|
let (_, headers) = fetcher_2.http_cache.get(&module_url_1).unwrap();
|
||||||
|
@ -776,7 +776,7 @@ mod tests {
|
||||||
"{ \"content-type\": \"application/json\" }",
|
"{ \"content-type\": \"application/json\" }",
|
||||||
);
|
);
|
||||||
let result3 = fetcher_2
|
let result3 = fetcher_2
|
||||||
.get_source_file_async(&module_url_1, true, false, false)
|
.get_source_file(&module_url_1, true, false, false)
|
||||||
.await;
|
.await;
|
||||||
assert!(result3.is_ok());
|
assert!(result3.is_ok());
|
||||||
let r3 = result3.unwrap();
|
let r3 = result3.unwrap();
|
||||||
|
@ -784,7 +784,7 @@ mod tests {
|
||||||
r3.source_code,
|
r3.source_code,
|
||||||
&b"export { printHello } from \"./print_hello.ts\";\n"[..]
|
&b"export { printHello } from \"./print_hello.ts\";\n"[..]
|
||||||
);
|
);
|
||||||
// If get_source_file_async does not call remote, this should be JavaScript
|
// If get_source_file does not call remote, this should be JavaScript
|
||||||
// as we modified before! (we do not overwrite .headers.json due to no http fetch)
|
// as we modified before! (we do not overwrite .headers.json due to no http fetch)
|
||||||
assert_eq!(&(r3.media_type), &msg::MediaType::Json);
|
assert_eq!(&(r3.media_type), &msg::MediaType::Json);
|
||||||
assert!(fs::read_to_string(&headers_file_name_2)
|
assert!(fs::read_to_string(&headers_file_name_2)
|
||||||
|
@ -795,7 +795,7 @@ mod tests {
|
||||||
// and don't use cache
|
// and don't use cache
|
||||||
let fetcher = setup_file_fetcher(temp_dir.path());
|
let fetcher = setup_file_fetcher(temp_dir.path());
|
||||||
let result4 = fetcher
|
let result4 = fetcher
|
||||||
.get_source_file_async(&module_url_2, false, false, false)
|
.get_source_file(&module_url_2, false, false, false)
|
||||||
.await;
|
.await;
|
||||||
assert!(result4.is_ok());
|
assert!(result4.is_ok());
|
||||||
let r4 = result4.unwrap();
|
let r4 = result4.unwrap();
|
||||||
|
@ -821,7 +821,7 @@ mod tests {
|
||||||
.with_extension("headers.json");
|
.with_extension("headers.json");
|
||||||
|
|
||||||
let result = fetcher
|
let result = fetcher
|
||||||
.get_source_file_async(&module_url, true, false, false)
|
.get_source_file(&module_url, true, false, false)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let r = result.unwrap();
|
let r = result.unwrap();
|
||||||
|
@ -837,13 +837,13 @@ mod tests {
|
||||||
"{ \"content-type\": \"text/typescript\" }",
|
"{ \"content-type\": \"text/typescript\" }",
|
||||||
);
|
);
|
||||||
let result2 = fetcher
|
let result2 = fetcher
|
||||||
.get_source_file_async(&module_url, true, false, false)
|
.get_source_file(&module_url, true, false, false)
|
||||||
.await;
|
.await;
|
||||||
assert!(result2.is_ok());
|
assert!(result2.is_ok());
|
||||||
let r2 = result2.unwrap();
|
let r2 = result2.unwrap();
|
||||||
let expected2 = b"export const loaded = true;\n";
|
let expected2 = b"export const loaded = true;\n";
|
||||||
assert_eq!(r2.source_code, expected2);
|
assert_eq!(r2.source_code, expected2);
|
||||||
// If get_source_file_async does not call remote, this should be TypeScript
|
// If get_source_file does not call remote, this should be TypeScript
|
||||||
// as we modified before! (we do not overwrite .headers.json due to no http
|
// as we modified before! (we do not overwrite .headers.json due to no http
|
||||||
// fetch)
|
// fetch)
|
||||||
assert_eq!(&(r2.media_type), &msg::MediaType::TypeScript);
|
assert_eq!(&(r2.media_type), &msg::MediaType::TypeScript);
|
||||||
|
@ -856,7 +856,7 @@ mod tests {
|
||||||
// process) and don't use cache
|
// process) and don't use cache
|
||||||
let fetcher = setup_file_fetcher(temp_dir.path());
|
let fetcher = setup_file_fetcher(temp_dir.path());
|
||||||
let result3 = fetcher
|
let result3 = fetcher
|
||||||
.get_source_file_async(&module_url_1, false, false, false)
|
.get_source_file(&module_url_1, false, false, false)
|
||||||
.await;
|
.await;
|
||||||
assert!(result3.is_ok());
|
assert!(result3.is_ok());
|
||||||
let r3 = result3.unwrap();
|
let r3 = result3.unwrap();
|
||||||
|
@ -885,7 +885,7 @@ mod tests {
|
||||||
.with_extension("headers.json");
|
.with_extension("headers.json");
|
||||||
|
|
||||||
// first download
|
// first download
|
||||||
let r = fetcher.fetch_source_file_async(&specifier, None).await;
|
let r = fetcher.fetch_source_file(&specifier, None).await;
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
|
|
||||||
let result = fs::File::open(&headers_file_name);
|
let result = fs::File::open(&headers_file_name);
|
||||||
|
@ -899,7 +899,7 @@ mod tests {
|
||||||
// `use_disk_cache` is set to false, this can be verified using source
|
// `use_disk_cache` is set to false, this can be verified using source
|
||||||
// header file creation timestamp (should be the same as after first
|
// header file creation timestamp (should be the same as after first
|
||||||
// download)
|
// download)
|
||||||
let r = fetcher.fetch_source_file_async(&specifier, None).await;
|
let r = fetcher.fetch_source_file(&specifier, None).await;
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
|
|
||||||
let result = fs::File::open(&headers_file_name);
|
let result = fs::File::open(&headers_file_name);
|
||||||
|
@ -937,7 +937,7 @@ mod tests {
|
||||||
|
|
||||||
// Test basic follow and headers recording
|
// Test basic follow and headers recording
|
||||||
let result = fetcher
|
let result = fetcher
|
||||||
.get_source_file_async(&redirect_module_url, true, false, false)
|
.get_source_file(&redirect_module_url, true, false, false)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let mod_meta = result.unwrap();
|
let mod_meta = result.unwrap();
|
||||||
|
@ -986,7 +986,7 @@ mod tests {
|
||||||
|
|
||||||
// Test double redirects and headers recording
|
// Test double redirects and headers recording
|
||||||
let result = fetcher
|
let result = fetcher
|
||||||
.get_source_file_async(&double_redirect_url, true, false, false)
|
.get_source_file(&double_redirect_url, true, false, false)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let mod_meta = result.unwrap();
|
let mod_meta = result.unwrap();
|
||||||
|
@ -1033,7 +1033,7 @@ mod tests {
|
||||||
|
|
||||||
// Test that redirect target is not downloaded twice for different redirect source.
|
// Test that redirect target is not downloaded twice for different redirect source.
|
||||||
let result = fetcher
|
let result = fetcher
|
||||||
.get_source_file_async(&double_redirect_url, true, false, false)
|
.get_source_file(&double_redirect_url, true, false, false)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let result = fs::File::open(&target_path);
|
let result = fs::File::open(&target_path);
|
||||||
|
@ -1048,7 +1048,7 @@ mod tests {
|
||||||
// using source header file creation timestamp (should be the same as
|
// using source header file creation timestamp (should be the same as
|
||||||
// after first `get_source_file`)
|
// after first `get_source_file`)
|
||||||
let result = fetcher
|
let result = fetcher
|
||||||
.get_source_file_async(&redirect_url, true, false, false)
|
.get_source_file(&redirect_url, true, false, false)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let result = fs::File::open(&target_path_);
|
let result = fs::File::open(&target_path_);
|
||||||
|
@ -1074,12 +1074,12 @@ mod tests {
|
||||||
|
|
||||||
// Test that redirections can be limited
|
// Test that redirections can be limited
|
||||||
let result = fetcher
|
let result = fetcher
|
||||||
.fetch_remote_source_async(&double_redirect_url, false, false, 2)
|
.fetch_remote_source(&double_redirect_url, false, false, 2)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
|
||||||
let result = fetcher
|
let result = fetcher
|
||||||
.fetch_remote_source_async(&double_redirect_url, false, false, 1)
|
.fetch_remote_source(&double_redirect_url, false, false, 1)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
// FIXME(bartlomieju):
|
// FIXME(bartlomieju):
|
||||||
|
@ -1097,7 +1097,7 @@ mod tests {
|
||||||
Url::parse("http://localhost:4545/cli/tests/002_hello.ts").unwrap();
|
Url::parse("http://localhost:4545/cli/tests/002_hello.ts").unwrap();
|
||||||
// Remote modules are not allowed
|
// Remote modules are not allowed
|
||||||
let result = fetcher
|
let result = fetcher
|
||||||
.get_source_file_async(&module_url, true, true, false)
|
.get_source_file(&module_url, true, true, false)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
// FIXME(bartlomieju):
|
// FIXME(bartlomieju):
|
||||||
|
@ -1120,7 +1120,7 @@ mod tests {
|
||||||
|
|
||||||
// file hasn't been cached before
|
// file hasn't been cached before
|
||||||
let result = fetcher
|
let result = fetcher
|
||||||
.get_source_file_async(&module_url, true, false, true)
|
.get_source_file(&module_url, true, false, true)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_err());
|
assert!(result.is_err());
|
||||||
// FIXME(bartlomieju):
|
// FIXME(bartlomieju):
|
||||||
|
@ -1129,21 +1129,19 @@ mod tests {
|
||||||
|
|
||||||
// download and cache file
|
// download and cache file
|
||||||
let result = fetcher_1
|
let result = fetcher_1
|
||||||
.get_source_file_async(&module_url_1, true, false, false)
|
.get_source_file(&module_url_1, true, false, false)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
|
||||||
// module is already cached, should be ok even with `cached_only`
|
// module is already cached, should be ok even with `cached_only`
|
||||||
let result = fetcher_2
|
let result = fetcher_2
|
||||||
.get_source_file_async(&module_url_2, true, false, true)
|
.get_source_file(&module_url_2, true, false, true)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
|
|
||||||
drop(http_server_guard);
|
drop(http_server_guard);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_fetch_source_async_1() {
|
async fn test_fetch_source_0() {
|
||||||
let http_server_guard = crate::test_util::http_server();
|
let http_server_guard = crate::test_util::http_server();
|
||||||
let (_temp_dir, fetcher) = test_setup();
|
let (_temp_dir, fetcher) = test_setup();
|
||||||
let module_url =
|
let module_url =
|
||||||
|
@ -1154,7 +1152,7 @@ mod tests {
|
||||||
.get_cache_filename(&module_url)
|
.get_cache_filename(&module_url)
|
||||||
.with_extension("headers.json");
|
.with_extension("headers.json");
|
||||||
let result = fetcher
|
let result = fetcher
|
||||||
.fetch_remote_source_async(&module_url, false, false, 10)
|
.fetch_remote_source(&module_url, false, false, 10)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let r = result.unwrap();
|
let r = result.unwrap();
|
||||||
|
@ -1185,7 +1183,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let result = fetcher
|
let result = fetcher
|
||||||
.fetch_remote_source_async(&module_url, false, false, 10)
|
.fetch_remote_source(&module_url, false, false, 10)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let r = result.unwrap();
|
let r = result.unwrap();
|
||||||
|
@ -1228,7 +1226,7 @@ mod tests {
|
||||||
let module_url_3_ = module_url_3.clone();
|
let module_url_3_ = module_url_3.clone();
|
||||||
|
|
||||||
let result = fetcher
|
let result = fetcher
|
||||||
.fetch_remote_source_async(&module_url, false, false, 10)
|
.fetch_remote_source(&module_url, false, false, 10)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let r = result.unwrap();
|
let r = result.unwrap();
|
||||||
|
@ -1237,7 +1235,7 @@ mod tests {
|
||||||
let (_, headers) = fetcher.http_cache.get(&module_url).unwrap();
|
let (_, headers) = fetcher.http_cache.get(&module_url).unwrap();
|
||||||
assert_eq!(headers.get("content-type").unwrap(), "text/typescript");
|
assert_eq!(headers.get("content-type").unwrap(), "text/typescript");
|
||||||
let result = fetcher_1
|
let result = fetcher_1
|
||||||
.fetch_remote_source_async(&module_url_2, false, false, 10)
|
.fetch_remote_source(&module_url_2, false, false, 10)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let r2 = result.unwrap();
|
let r2 = result.unwrap();
|
||||||
|
@ -1248,7 +1246,7 @@ mod tests {
|
||||||
|
|
||||||
// test unknown extension
|
// test unknown extension
|
||||||
let result = fetcher_2
|
let result = fetcher_2
|
||||||
.fetch_remote_source_async(&module_url_3, false, false, 10)
|
.fetch_remote_source(&module_url_3, false, false, 10)
|
||||||
.await;
|
.await;
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
let r3 = result.unwrap();
|
let r3 = result.unwrap();
|
||||||
|
@ -1267,14 +1265,14 @@ mod tests {
|
||||||
// Test failure case.
|
// Test failure case.
|
||||||
let specifier =
|
let specifier =
|
||||||
ModuleSpecifier::resolve_url(file_url!("/baddir/hello.ts")).unwrap();
|
ModuleSpecifier::resolve_url(file_url!("/baddir/hello.ts")).unwrap();
|
||||||
let r = fetcher.fetch_source_file_async(&specifier, None).await;
|
let r = fetcher.fetch_source_file(&specifier, None).await;
|
||||||
assert!(r.is_err());
|
assert!(r.is_err());
|
||||||
|
|
||||||
let p =
|
let p =
|
||||||
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("js/main.ts");
|
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("js/main.ts");
|
||||||
let specifier =
|
let specifier =
|
||||||
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
|
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
|
||||||
let r = fetcher.fetch_source_file_async(&specifier, None).await;
|
let r = fetcher.fetch_source_file(&specifier, None).await;
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1286,14 +1284,14 @@ mod tests {
|
||||||
// Test failure case.
|
// Test failure case.
|
||||||
let specifier =
|
let specifier =
|
||||||
ModuleSpecifier::resolve_url(file_url!("/baddir/hello.ts")).unwrap();
|
ModuleSpecifier::resolve_url(file_url!("/baddir/hello.ts")).unwrap();
|
||||||
let r = fetcher.fetch_source_file_async(&specifier, None).await;
|
let r = fetcher.fetch_source_file(&specifier, None).await;
|
||||||
assert!(r.is_err());
|
assert!(r.is_err());
|
||||||
|
|
||||||
let p =
|
let p =
|
||||||
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("js/main.ts");
|
std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("js/main.ts");
|
||||||
let specifier =
|
let specifier =
|
||||||
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
|
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
|
||||||
let r = fetcher.fetch_source_file_async(&specifier, None).await;
|
let r = fetcher.fetch_source_file(&specifier, None).await;
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1306,7 +1304,7 @@ mod tests {
|
||||||
.join("tests/001_hello.js");
|
.join("tests/001_hello.js");
|
||||||
let specifier =
|
let specifier =
|
||||||
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
|
ModuleSpecifier::resolve_url_or_path(p.to_str().unwrap()).unwrap();
|
||||||
let r = fetcher.fetch_source_file_async(&specifier, None).await;
|
let r = fetcher.fetch_source_file(&specifier, None).await;
|
||||||
assert!(r.is_ok());
|
assert!(r.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1550,7 +1548,7 @@ mod tests {
|
||||||
Url::parse("http://127.0.0.1:4545/etag_script.ts").unwrap();
|
Url::parse("http://127.0.0.1:4545/etag_script.ts").unwrap();
|
||||||
|
|
||||||
let source = fetcher
|
let source = fetcher
|
||||||
.fetch_remote_source_async(&module_url, false, false, 1)
|
.fetch_remote_source(&module_url, false, false, 1)
|
||||||
.await;
|
.await;
|
||||||
assert!(source.is_ok());
|
assert!(source.is_ok());
|
||||||
let source = source.unwrap();
|
let source = source.unwrap();
|
||||||
|
@ -1573,7 +1571,7 @@ mod tests {
|
||||||
let file_name = fetcher.http_cache.get_cache_filename(&module_url);
|
let file_name = fetcher.http_cache.get_cache_filename(&module_url);
|
||||||
let _ = fs::write(&file_name, "changed content");
|
let _ = fs::write(&file_name, "changed content");
|
||||||
let cached_source = fetcher
|
let cached_source = fetcher
|
||||||
.fetch_remote_source_async(&module_url, false, false, 1)
|
.fetch_remote_source(&module_url, false, false, 1)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
assert_eq!(cached_source.source_code, b"changed content");
|
assert_eq!(cached_source.source_code, b"changed content");
|
||||||
|
@ -1672,7 +1670,7 @@ mod tests {
|
||||||
let module_url =
|
let module_url =
|
||||||
Url::parse("http://127.0.0.1:4545/xTypeScriptTypes.js").unwrap();
|
Url::parse("http://127.0.0.1:4545/xTypeScriptTypes.js").unwrap();
|
||||||
let source = fetcher
|
let source = fetcher
|
||||||
.fetch_remote_source_async(&module_url, false, false, 1)
|
.fetch_remote_source(&module_url, false, false, 1)
|
||||||
.await;
|
.await;
|
||||||
assert!(source.is_ok());
|
assert!(source.is_ok());
|
||||||
let source = source.unwrap();
|
let source = source.unwrap();
|
||||||
|
@ -1692,7 +1690,7 @@ mod tests {
|
||||||
let module_url =
|
let module_url =
|
||||||
Url::parse("http://127.0.0.1:4545/referenceTypes.js").unwrap();
|
Url::parse("http://127.0.0.1:4545/referenceTypes.js").unwrap();
|
||||||
let source = fetcher
|
let source = fetcher
|
||||||
.fetch_remote_source_async(&module_url, false, false, 1)
|
.fetch_remote_source(&module_url, false, false, 1)
|
||||||
.await;
|
.await;
|
||||||
assert!(source.is_ok());
|
assert!(source.is_ok());
|
||||||
let source = source.unwrap();
|
let source = source.unwrap();
|
||||||
|
|
|
@ -111,7 +111,7 @@ impl GlobalState {
|
||||||
|
|
||||||
let out = self
|
let out = self
|
||||||
.file_fetcher
|
.file_fetcher
|
||||||
.fetch_source_file_async(&module_specifier, maybe_referrer)
|
.fetch_source_file(&module_specifier, maybe_referrer)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
// TODO(ry) Try to lift compile_lock as high up in the call stack for
|
// TODO(ry) Try to lift compile_lock as high up in the call stack for
|
||||||
|
@ -119,30 +119,27 @@ impl GlobalState {
|
||||||
let compile_lock = self.compile_lock.lock().await;
|
let compile_lock = self.compile_lock.lock().await;
|
||||||
|
|
||||||
let compiled_module = match out.media_type {
|
let compiled_module = match out.media_type {
|
||||||
msg::MediaType::Unknown => state1.js_compiler.compile_async(out).await,
|
msg::MediaType::Unknown => state1.js_compiler.compile(out).await,
|
||||||
msg::MediaType::Json => state1.json_compiler.compile_async(&out).await,
|
msg::MediaType::Json => state1.json_compiler.compile(&out).await,
|
||||||
msg::MediaType::Wasm => {
|
msg::MediaType::Wasm => {
|
||||||
state1
|
state1.wasm_compiler.compile(state1.clone(), &out).await
|
||||||
.wasm_compiler
|
|
||||||
.compile_async(state1.clone(), &out)
|
|
||||||
.await
|
|
||||||
}
|
}
|
||||||
msg::MediaType::TypeScript
|
msg::MediaType::TypeScript
|
||||||
| msg::MediaType::TSX
|
| msg::MediaType::TSX
|
||||||
| msg::MediaType::JSX => {
|
| msg::MediaType::JSX => {
|
||||||
state1
|
state1
|
||||||
.ts_compiler
|
.ts_compiler
|
||||||
.compile_async(state1.clone(), &out, target_lib)
|
.compile(state1.clone(), &out, target_lib)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
msg::MediaType::JavaScript => {
|
msg::MediaType::JavaScript => {
|
||||||
if state1.ts_compiler.compile_js {
|
if state1.ts_compiler.compile_js {
|
||||||
state2
|
state2
|
||||||
.ts_compiler
|
.ts_compiler
|
||||||
.compile_async(state1.clone(), &out, target_lib)
|
.compile(state1.clone(), &out, target_lib)
|
||||||
.await
|
.await
|
||||||
} else {
|
} else {
|
||||||
state1.js_compiler.compile_async(out).await
|
state1.js_compiler.compile(out).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}?;
|
}?;
|
||||||
|
@ -182,10 +179,7 @@ impl GlobalState {
|
||||||
#[test]
|
#[test]
|
||||||
fn thread_safe() {
|
fn thread_safe() {
|
||||||
fn f<S: Send + Sync>(_: S) {}
|
fn f<S: Send + Sync>(_: S) {}
|
||||||
f(GlobalState::mock(vec![
|
f(GlobalState::mock(vec![]));
|
||||||
String::from("./deno"),
|
|
||||||
String::from("hello.js"),
|
|
||||||
]));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -238,7 +238,7 @@ mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_fetch_sync_string() {
|
async fn test_fetch_string() {
|
||||||
let http_server_guard = crate::test_util::http_server();
|
let http_server_guard = crate::test_util::http_server();
|
||||||
// Relies on external http server. See tools/http_server.py
|
// Relies on external http server. See tools/http_server.py
|
||||||
let url =
|
let url =
|
||||||
|
@ -388,7 +388,7 @@ mod tests {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_fetch_with_cafile_sync_string() {
|
async fn test_fetch_with_cafile_string() {
|
||||||
let http_server_guard = crate::test_util::http_server();
|
let http_server_guard = crate::test_util::http_server();
|
||||||
// Relies on external http server. See tools/http_server.py
|
// Relies on external http server. See tools/http_server.py
|
||||||
let url =
|
let url =
|
||||||
|
@ -402,7 +402,6 @@ mod tests {
|
||||||
)))
|
)))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let result = fetch_once(client, &url, None).await;
|
let result = fetch_once(client, &url, None).await;
|
||||||
|
|
||||||
if let Ok(FetchOnceResult::Code(body, headers)) = result {
|
if let Ok(FetchOnceResult::Code(body, headers)) = result {
|
||||||
assert!(!body.is_empty());
|
assert!(!body.is_empty());
|
||||||
assert_eq!(headers.get("content-type").unwrap(), "application/json");
|
assert_eq!(headers.get("content-type").unwrap(), "application/json");
|
||||||
|
|
|
@ -152,7 +152,7 @@ async fn print_file_info(
|
||||||
|
|
||||||
let out = global_state
|
let out = global_state
|
||||||
.file_fetcher
|
.file_fetcher
|
||||||
.fetch_source_file_async(&module_specifier, None)
|
.fetch_source_file(&module_specifier, None)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
println!(
|
println!(
|
||||||
|
@ -303,12 +303,12 @@ async fn bundle_command(
|
||||||
) -> Result<(), ErrBox> {
|
) -> Result<(), ErrBox> {
|
||||||
let module_name = ModuleSpecifier::resolve_url_or_path(&source_file)?;
|
let module_name = ModuleSpecifier::resolve_url_or_path(&source_file)?;
|
||||||
let global_state = GlobalState::new(flags)?;
|
let global_state = GlobalState::new(flags)?;
|
||||||
debug!(">>>>> bundle_async START");
|
debug!(">>>>> bundle START");
|
||||||
let bundle_result = global_state
|
let bundle_result = global_state
|
||||||
.ts_compiler
|
.ts_compiler
|
||||||
.bundle_async(global_state.clone(), module_name.to_string(), out_file)
|
.bundle(global_state.clone(), module_name.to_string(), out_file)
|
||||||
.await;
|
.await;
|
||||||
debug!(">>>>> bundle_async END");
|
debug!(">>>>> bundle END");
|
||||||
bundle_result
|
bundle_result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ fn op_fetch_source_files(
|
||||||
let resolved_specifier = ModuleSpecifier::resolve_url(&specifier)
|
let resolved_specifier = ModuleSpecifier::resolve_url(&specifier)
|
||||||
.expect("Invalid specifier");
|
.expect("Invalid specifier");
|
||||||
file_fetcher_
|
file_fetcher_
|
||||||
.fetch_source_file_async(&resolved_specifier, ref_specifier_)
|
.fetch_source_file(&resolved_specifier, ref_specifier_)
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
.boxed_local()
|
.boxed_local()
|
||||||
|
@ -130,7 +130,7 @@ fn op_fetch_source_files(
|
||||||
let types_specifier = ModuleSpecifier::from(types_url);
|
let types_specifier = ModuleSpecifier::from(types_url);
|
||||||
global_state
|
global_state
|
||||||
.file_fetcher
|
.file_fetcher
|
||||||
.fetch_source_file_async(&types_specifier, ref_specifier.clone())
|
.fetch_source_file(&types_specifier, ref_specifier.clone())
|
||||||
.await
|
.await
|
||||||
.map_err(OpError::from)?
|
.map_err(OpError::from)?
|
||||||
}
|
}
|
||||||
|
@ -143,7 +143,7 @@ fn op_fetch_source_files(
|
||||||
msg::MediaType::Wasm => {
|
msg::MediaType::Wasm => {
|
||||||
global_state
|
global_state
|
||||||
.wasm_compiler
|
.wasm_compiler
|
||||||
.compile_async(global_state.clone(), &file)
|
.compile(global_state.clone(), &file)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| OpError::other(e.to_string()))?
|
.map_err(|e| OpError::other(e.to_string()))?
|
||||||
.code
|
.code
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
||||||
use super::dispatch_json::{Deserialize, JsonOp, Value};
|
use super::dispatch_json::{Deserialize, JsonOp, Value};
|
||||||
use crate::compilers::runtime_compile_async;
|
use crate::compilers::runtime_compile;
|
||||||
use crate::compilers::runtime_transpile_async;
|
use crate::compilers::runtime_transpile;
|
||||||
use crate::op_error::OpError;
|
use crate::op_error::OpError;
|
||||||
use crate::state::State;
|
use crate::state::State;
|
||||||
use deno_core::*;
|
use deno_core::*;
|
||||||
|
@ -27,7 +27,7 @@ fn op_compile(
|
||||||
_zero_copy: Option<ZeroCopyBuf>,
|
_zero_copy: Option<ZeroCopyBuf>,
|
||||||
) -> Result<JsonOp, OpError> {
|
) -> Result<JsonOp, OpError> {
|
||||||
let args: CompileArgs = serde_json::from_value(args)?;
|
let args: CompileArgs = serde_json::from_value(args)?;
|
||||||
Ok(JsonOp::Async(runtime_compile_async(
|
Ok(JsonOp::Async(runtime_compile(
|
||||||
state.borrow().global_state.clone(),
|
state.borrow().global_state.clone(),
|
||||||
&args.root_name,
|
&args.root_name,
|
||||||
&args.sources,
|
&args.sources,
|
||||||
|
@ -48,7 +48,7 @@ fn op_transpile(
|
||||||
_zero_copy: Option<ZeroCopyBuf>,
|
_zero_copy: Option<ZeroCopyBuf>,
|
||||||
) -> Result<JsonOp, OpError> {
|
) -> Result<JsonOp, OpError> {
|
||||||
let args: TranspileArgs = serde_json::from_value(args)?;
|
let args: TranspileArgs = serde_json::from_value(args)?;
|
||||||
Ok(JsonOp::Async(runtime_transpile_async(
|
Ok(JsonOp::Async(runtime_transpile(
|
||||||
state.borrow().global_state.clone(),
|
state.borrow().global_state.clone(),
|
||||||
&args.sources,
|
&args.sources,
|
||||||
&args.options,
|
&args.options,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue