Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
deno
提交
f47f3f96
D
deno
项目概览
张重言
/
deno
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
deno
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
f47f3f96
编写于
2月 25, 2020
作者:
R
Ryan Dahl
提交者:
GitHub
2月 25, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove _async from method names since _sync are gone (#4128)
上级
fe181e2b
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
81 addition
and
90 deletion
+81
-90
cli/compilers/js.rs
cli/compilers/js.rs
+1
-1
cli/compilers/json.rs
cli/compilers/json.rs
+1
-1
cli/compilers/mod.rs
cli/compilers/mod.rs
+2
-2
cli/compilers/ts.rs
cli/compilers/ts.rs
+8
-8
cli/compilers/wasm.rs
cli/compilers/wasm.rs
+3
-3
cli/file_fetcher.rs
cli/file_fetcher.rs
+45
-47
cli/global_state.rs
cli/global_state.rs
+8
-14
cli/http_util.rs
cli/http_util.rs
+2
-3
cli/lib.rs
cli/lib.rs
+4
-4
cli/ops/compiler.rs
cli/ops/compiler.rs
+3
-3
cli/ops/runtime_compiler.rs
cli/ops/runtime_compiler.rs
+4
-4
未找到文件。
cli/compilers/js.rs
浏览文件 @
f47f3f96
...
...
@@ -7,7 +7,7 @@ use std::str;
pub
struct
JsCompiler
{}
impl
JsCompiler
{
pub
async
fn
compile
_async
(
pub
async
fn
compile
(
&
self
,
source_file
:
SourceFile
,
)
->
Result
<
CompiledModule
,
ErrBox
>
{
...
...
cli/compilers/json.rs
浏览文件 @
f47f3f96
...
...
@@ -10,7 +10,7 @@ static JS_RESERVED_WORDS: &str = r"^(?:do|if|in|for|let|new|try|var|case|else|en
pub
struct
JsonCompiler
{}
impl
JsonCompiler
{
pub
async
fn
compile
_async
(
pub
async
fn
compile
(
&
self
,
source_file
:
&
SourceFile
,
)
->
Result
<
CompiledModule
,
ErrBox
>
{
...
...
cli/compilers/mod.rs
浏览文件 @
f47f3f96
...
...
@@ -11,8 +11,8 @@ mod wasm;
pub
use
js
::
JsCompiler
;
pub
use
json
::
JsonCompiler
;
pub
use
ts
::
runtime_compile
_async
;
pub
use
ts
::
runtime_transpile
_async
;
pub
use
ts
::
runtime_compile
;
pub
use
ts
::
runtime_transpile
;
pub
use
ts
::
TargetLib
;
pub
use
ts
::
TsCompiler
;
pub
use
wasm
::
WasmCompiler
;
...
...
cli/compilers/ts.rs
浏览文件 @
f47f3f96
...
...
@@ -269,7 +269,7 @@ impl TsCompiler {
worker
}
pub
async
fn
bundle
_async
(
pub
async
fn
bundle
(
&
self
,
global_state
:
GlobalState
,
module_name
:
String
,
...
...
@@ -322,7 +322,7 @@ impl TsCompiler {
///
/// If compilation is required then new V8 worker is spawned with fresh TS
/// compiler.
pub
async
fn
compile
_async
(
pub
async
fn
compile
(
&
self
,
global_state
:
GlobalState
,
source_file
:
&
SourceFile
,
...
...
@@ -641,7 +641,7 @@ async fn execute_in_thread_json(
Ok
(
json!
(
json_str
))
}
pub
fn
runtime_compile
_async
<
S
:
BuildHasher
>
(
pub
fn
runtime_compile
<
S
:
BuildHasher
>
(
global_state
:
GlobalState
,
root_name
:
&
str
,
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
()
}
pub
fn
runtime_transpile
_async
<
S
:
BuildHasher
>
(
pub
fn
runtime_transpile
<
S
:
BuildHasher
>
(
global_state
:
GlobalState
,
sources
:
&
HashMap
<
String
,
String
,
S
>
,
options
:
&
Option
<
String
>
,
...
...
@@ -689,7 +689,7 @@ mod tests {
use
tempfile
::
TempDir
;
#[tokio::test]
async
fn
test_compile
_async
()
{
async
fn
test_compile
()
{
let
p
=
std
::
path
::
PathBuf
::
from
(
env!
(
"CARGO_MANIFEST_DIR"
))
.parent
()
.unwrap
()
...
...
@@ -707,7 +707,7 @@ mod tests {
GlobalState
::
mock
(
vec!
[
String
::
from
(
"deno"
),
String
::
from
(
"hello.js"
)]);
let
result
=
mock_state
.ts_compiler
.compile
_async
(
mock_state
.clone
(),
&
out
,
TargetLib
::
Main
)
.compile
(
mock_state
.clone
(),
&
out
,
TargetLib
::
Main
)
.await
;
assert
!
(
result
.is_ok
());
assert
!
(
result
...
...
@@ -718,7 +718,7 @@ mod tests {
}
#[tokio::test]
async
fn
test_bundle
_async
()
{
async
fn
test_bundle
()
{
let
p
=
std
::
path
::
PathBuf
::
from
(
env!
(
"CARGO_MANIFEST_DIR"
))
.parent
()
.unwrap
()
...
...
@@ -736,7 +736,7 @@ mod tests {
let
result
=
state
.ts_compiler
.bundle
_async
(
.bundle
(
state
.clone
(),
module_name
,
Some
(
PathBuf
::
from
(
"$deno$/bundle.js"
)),
...
...
cli/compilers/wasm.rs
浏览文件 @
f47f3f96
...
...
@@ -71,7 +71,7 @@ impl WasmCompiler {
worker
}
pub
async
fn
compile
_async
(
pub
async
fn
compile
(
&
self
,
global_state
:
GlobalState
,
source_file
:
&
SourceFile
,
...
...
@@ -84,7 +84,7 @@ impl WasmCompiler {
if
let
Some
(
m
)
=
maybe_cached
{
return
Ok
(
m
);
}
debug!
(
">>>>> wasm_compile
_async
START"
);
debug!
(
">>>>> wasm_compile START"
);
let
base64_data
=
base64
::
encode
(
&
source_file
.source_code
);
let
url
=
source_file
.url
.clone
();
let
req_msg
=
serde_json
::
to_string
(
&
base64_data
)
...
...
@@ -108,7 +108,7 @@ impl WasmCompiler {
{
cache_
.lock
()
.unwrap
()
.insert
(
url
.clone
(),
module
.clone
());
}
debug!
(
"<<<<< wasm_compile
_async
END"
);
debug!
(
"<<<<< wasm_compile END"
);
Ok
(
module
)
}
}
...
...
cli/file_fetcher.rs
浏览文件 @
f47f3f96
...
...
@@ -127,18 +127,18 @@ impl SourceFileFetcher {
// future, because it doesn't actually do any asynchronous
// action in that path.
self
.get_source_file
_async
(
specifier
.as_url
(),
true
,
false
,
true
)
.get_source_file
(
specifier
.as_url
(),
true
,
false
,
true
)
.await
.ok
()
}
pub
async
fn
fetch_source_file
_async
(
pub
async
fn
fetch_source_file
(
&
self
,
specifier
:
&
ModuleSpecifier
,
maybe_referrer
:
Option
<
ModuleSpecifier
>
,
)
->
Result
<
SourceFile
,
ErrBox
>
{
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.
let
maybe_cached_file
=
self
.source_file_cache
.get
(
specifier
.to_string
());
...
...
@@ -150,7 +150,7 @@ impl SourceFileFetcher {
let
specifier_
=
specifier
.clone
();
let
result
=
self
.get_source_file
_async
(
.get_source_file
(
&
module_url
,
self
.use_disk_cache
,
self
.no_remote
,
...
...
@@ -218,7 +218,7 @@ impl SourceFileFetcher {
///
/// If `cached_only` is true then this method will fail for remote files
/// not already cached.
async
fn
get_source_file
_async
(
async
fn
get_source_file
(
&
self
,
module_url
:
&
Url
,
use_disk_cache
:
bool
,
...
...
@@ -248,7 +248,7 @@ impl SourceFileFetcher {
// Fetch remote file and cache on-disk for subsequent access
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
}
...
...
@@ -346,7 +346,7 @@ impl SourceFileFetcher {
///
/// Note that this is a recursive method so it can't be "async", but rather return
/// Pin<Box<..>>.
fn
fetch_remote_source
_async
(
fn
fetch_remote_source
(
&
self
,
module_url
:
&
Url
,
use_disk_cache
:
bool
,
...
...
@@ -419,7 +419,7 @@ impl SourceFileFetcher {
// Recurse
dir
.fetch_remote_source
_async
(
.fetch_remote_source
(
&
new_module_url
,
use_disk_cache
,
cached_only
,
...
...
@@ -738,7 +738,7 @@ mod tests {
let
headers_file_name_2
=
headers_file_name
.clone
();
let
result
=
fetcher
.get_source_file
_async
(
&
module_url
,
true
,
false
,
false
)
.get_source_file
(
&
module_url
,
true
,
false
,
false
)
.await
;
assert
!
(
result
.is_ok
());
let
r
=
result
.unwrap
();
...
...
@@ -755,7 +755,7 @@ mod tests {
"{
\"
content-type
\"
:
\"
text/javascript
\"
}"
,
);
let
result2
=
fetcher_1
.get_source_file
_async
(
&
module_url
,
true
,
false
,
false
)
.get_source_file
(
&
module_url
,
true
,
false
,
false
)
.await
;
assert
!
(
result2
.is_ok
());
let
r2
=
result2
.unwrap
();
...
...
@@ -763,7 +763,7 @@ mod tests {
r2
.source_code
,
&
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)
assert_eq!
(
&
(
r2
.media_type
),
&
msg
::
MediaType
::
JavaScript
);
let
(
_
,
headers
)
=
fetcher_2
.http_cache
.get
(
&
module_url_1
)
.unwrap
();
...
...
@@ -776,7 +776,7 @@ mod tests {
"{
\"
content-type
\"
:
\"
application/json
\"
}"
,
);
let
result3
=
fetcher_2
.get_source_file
_async
(
&
module_url_1
,
true
,
false
,
false
)
.get_source_file
(
&
module_url_1
,
true
,
false
,
false
)
.await
;
assert
!
(
result3
.is_ok
());
let
r3
=
result3
.unwrap
();
...
...
@@ -784,7 +784,7 @@ mod tests {
r3
.source_code
,
&
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)
assert_eq!
(
&
(
r3
.media_type
),
&
msg
::
MediaType
::
Json
);
assert
!
(
fs
::
read_to_string
(
&
headers_file_name_2
)
...
...
@@ -795,7 +795,7 @@ mod tests {
// and don't use cache
let
fetcher
=
setup_file_fetcher
(
temp_dir
.path
());
let
result4
=
fetcher
.get_source_file
_async
(
&
module_url_2
,
false
,
false
,
false
)
.get_source_file
(
&
module_url_2
,
false
,
false
,
false
)
.await
;
assert
!
(
result4
.is_ok
());
let
r4
=
result4
.unwrap
();
...
...
@@ -821,7 +821,7 @@ mod tests {
.with_extension
(
"headers.json"
);
let
result
=
fetcher
.get_source_file
_async
(
&
module_url
,
true
,
false
,
false
)
.get_source_file
(
&
module_url
,
true
,
false
,
false
)
.await
;
assert
!
(
result
.is_ok
());
let
r
=
result
.unwrap
();
...
...
@@ -837,13 +837,13 @@ mod tests {
"{
\"
content-type
\"
:
\"
text/typescript
\"
}"
,
);
let
result2
=
fetcher
.get_source_file
_async
(
&
module_url
,
true
,
false
,
false
)
.get_source_file
(
&
module_url
,
true
,
false
,
false
)
.await
;
assert
!
(
result2
.is_ok
());
let
r2
=
result2
.unwrap
();
let
expected2
=
b
"export const loaded = true;
\n
"
;
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
// fetch)
assert_eq!
(
&
(
r2
.media_type
),
&
msg
::
MediaType
::
TypeScript
);
...
...
@@ -856,7 +856,7 @@ mod tests {
// process) and don't use cache
let
fetcher
=
setup_file_fetcher
(
temp_dir
.path
());
let
result3
=
fetcher
.get_source_file
_async
(
&
module_url_1
,
false
,
false
,
false
)
.get_source_file
(
&
module_url_1
,
false
,
false
,
false
)
.await
;
assert
!
(
result3
.is_ok
());
let
r3
=
result3
.unwrap
();
...
...
@@ -885,7 +885,7 @@ mod tests {
.with_extension
(
"headers.json"
);
// 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
());
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
// header file creation timestamp (should be the same as after 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
());
let
result
=
fs
::
File
::
open
(
&
headers_file_name
);
...
...
@@ -937,7 +937,7 @@ mod tests {
// Test basic follow and headers recording
let
result
=
fetcher
.get_source_file
_async
(
&
redirect_module_url
,
true
,
false
,
false
)
.get_source_file
(
&
redirect_module_url
,
true
,
false
,
false
)
.await
;
assert
!
(
result
.is_ok
());
let
mod_meta
=
result
.unwrap
();
...
...
@@ -986,7 +986,7 @@ mod tests {
// Test double redirects and headers recording
let
result
=
fetcher
.get_source_file
_async
(
&
double_redirect_url
,
true
,
false
,
false
)
.get_source_file
(
&
double_redirect_url
,
true
,
false
,
false
)
.await
;
assert
!
(
result
.is_ok
());
let
mod_meta
=
result
.unwrap
();
...
...
@@ -1033,7 +1033,7 @@ mod tests {
// Test that redirect target is not downloaded twice for different redirect source.
let
result
=
fetcher
.get_source_file
_async
(
&
double_redirect_url
,
true
,
false
,
false
)
.get_source_file
(
&
double_redirect_url
,
true
,
false
,
false
)
.await
;
assert
!
(
result
.is_ok
());
let
result
=
fs
::
File
::
open
(
&
target_path
);
...
...
@@ -1048,7 +1048,7 @@ mod tests {
// using source header file creation timestamp (should be the same as
// after first `get_source_file`)
let
result
=
fetcher
.get_source_file
_async
(
&
redirect_url
,
true
,
false
,
false
)
.get_source_file
(
&
redirect_url
,
true
,
false
,
false
)
.await
;
assert
!
(
result
.is_ok
());
let
result
=
fs
::
File
::
open
(
&
target_path_
);
...
...
@@ -1074,12 +1074,12 @@ mod tests {
// Test that redirections can be limited
let
result
=
fetcher
.fetch_remote_source
_async
(
&
double_redirect_url
,
false
,
false
,
2
)
.fetch_remote_source
(
&
double_redirect_url
,
false
,
false
,
2
)
.await
;
assert
!
(
result
.is_ok
());
let
result
=
fetcher
.fetch_remote_source
_async
(
&
double_redirect_url
,
false
,
false
,
1
)
.fetch_remote_source
(
&
double_redirect_url
,
false
,
false
,
1
)
.await
;
assert
!
(
result
.is_err
());
// FIXME(bartlomieju):
...
...
@@ -1097,7 +1097,7 @@ mod tests {
Url
::
parse
(
"http://localhost:4545/cli/tests/002_hello.ts"
)
.unwrap
();
// Remote modules are not allowed
let
result
=
fetcher
.get_source_file
_async
(
&
module_url
,
true
,
true
,
false
)
.get_source_file
(
&
module_url
,
true
,
true
,
false
)
.await
;
assert
!
(
result
.is_err
());
// FIXME(bartlomieju):
...
...
@@ -1120,7 +1120,7 @@ mod tests {
// file hasn't been cached before
let
result
=
fetcher
.get_source_file
_async
(
&
module_url
,
true
,
false
,
true
)
.get_source_file
(
&
module_url
,
true
,
false
,
true
)
.await
;
assert
!
(
result
.is_err
());
// FIXME(bartlomieju):
...
...
@@ -1129,21 +1129,19 @@ mod tests {
// download and cache file
let
result
=
fetcher_1
.get_source_file
_async
(
&
module_url_1
,
true
,
false
,
false
)
.get_source_file
(
&
module_url_1
,
true
,
false
,
false
)
.await
;
assert
!
(
result
.is_ok
());
// module is already cached, should be ok even with `cached_only`
let
result
=
fetcher_2
.get_source_file
_async
(
&
module_url_2
,
true
,
false
,
true
)
.get_source_file
(
&
module_url_2
,
true
,
false
,
true
)
.await
;
assert
!
(
result
.is_ok
());
drop
(
http_server_guard
);
}
#[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
(
_
temp_dir
,
fetcher
)
=
test_setup
();
let
module_url
=
...
...
@@ -1154,7 +1152,7 @@ mod tests {
.get_cache_filename
(
&
module_url
)
.with_extension
(
"headers.json"
);
let
result
=
fetcher
.fetch_remote_source
_async
(
&
module_url
,
false
,
false
,
10
)
.fetch_remote_source
(
&
module_url
,
false
,
false
,
10
)
.await
;
assert
!
(
result
.is_ok
());
let
r
=
result
.unwrap
();
...
...
@@ -1185,7 +1183,7 @@ mod tests {
.unwrap
();
let
result
=
fetcher
.fetch_remote_source
_async
(
&
module_url
,
false
,
false
,
10
)
.fetch_remote_source
(
&
module_url
,
false
,
false
,
10
)
.await
;
assert
!
(
result
.is_ok
());
let
r
=
result
.unwrap
();
...
...
@@ -1228,7 +1226,7 @@ mod tests {
let
module_url_3_
=
module_url_3
.clone
();
let
result
=
fetcher
.fetch_remote_source
_async
(
&
module_url
,
false
,
false
,
10
)
.fetch_remote_source
(
&
module_url
,
false
,
false
,
10
)
.await
;
assert
!
(
result
.is_ok
());
let
r
=
result
.unwrap
();
...
...
@@ -1237,7 +1235,7 @@ mod tests {
let
(
_
,
headers
)
=
fetcher
.http_cache
.get
(
&
module_url
)
.unwrap
();
assert_eq!
(
headers
.get
(
"content-type"
)
.unwrap
(),
"text/typescript"
);
let
result
=
fetcher_1
.fetch_remote_source
_async
(
&
module_url_2
,
false
,
false
,
10
)
.fetch_remote_source
(
&
module_url_2
,
false
,
false
,
10
)
.await
;
assert
!
(
result
.is_ok
());
let
r2
=
result
.unwrap
();
...
...
@@ -1248,7 +1246,7 @@ mod tests {
// test unknown extension
let
result
=
fetcher_2
.fetch_remote_source
_async
(
&
module_url_3
,
false
,
false
,
10
)
.fetch_remote_source
(
&
module_url_3
,
false
,
false
,
10
)
.await
;
assert
!
(
result
.is_ok
());
let
r3
=
result
.unwrap
();
...
...
@@ -1267,14 +1265,14 @@ mod tests {
// Test failure case.
let
specifier
=
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
());
let
p
=
std
::
path
::
PathBuf
::
from
(
env!
(
"CARGO_MANIFEST_DIR"
))
.join
(
"js/main.ts"
);
let
specifier
=
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
());
}
...
...
@@ -1286,14 +1284,14 @@ mod tests {
// Test failure case.
let
specifier
=
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
());
let
p
=
std
::
path
::
PathBuf
::
from
(
env!
(
"CARGO_MANIFEST_DIR"
))
.join
(
"js/main.ts"
);
let
specifier
=
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
());
}
...
...
@@ -1306,7 +1304,7 @@ mod tests {
.join
(
"tests/001_hello.js"
);
let
specifier
=
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
());
}
...
...
@@ -1550,7 +1548,7 @@ mod tests {
Url
::
parse
(
"http://127.0.0.1:4545/etag_script.ts"
)
.unwrap
();
let
source
=
fetcher
.fetch_remote_source
_async
(
&
module_url
,
false
,
false
,
1
)
.fetch_remote_source
(
&
module_url
,
false
,
false
,
1
)
.await
;
assert
!
(
source
.is_ok
());
let
source
=
source
.unwrap
();
...
...
@@ -1573,7 +1571,7 @@ mod tests {
let
file_name
=
fetcher
.http_cache
.get_cache_filename
(
&
module_url
);
let
_
=
fs
::
write
(
&
file_name
,
"changed content"
);
let
cached_source
=
fetcher
.fetch_remote_source
_async
(
&
module_url
,
false
,
false
,
1
)
.fetch_remote_source
(
&
module_url
,
false
,
false
,
1
)
.await
.unwrap
();
assert_eq!
(
cached_source
.source_code
,
b
"changed content"
);
...
...
@@ -1672,7 +1670,7 @@ mod tests {
let
module_url
=
Url
::
parse
(
"http://127.0.0.1:4545/xTypeScriptTypes.js"
)
.unwrap
();
let
source
=
fetcher
.fetch_remote_source
_async
(
&
module_url
,
false
,
false
,
1
)
.fetch_remote_source
(
&
module_url
,
false
,
false
,
1
)
.await
;
assert
!
(
source
.is_ok
());
let
source
=
source
.unwrap
();
...
...
@@ -1692,7 +1690,7 @@ mod tests {
let
module_url
=
Url
::
parse
(
"http://127.0.0.1:4545/referenceTypes.js"
)
.unwrap
();
let
source
=
fetcher
.fetch_remote_source
_async
(
&
module_url
,
false
,
false
,
1
)
.fetch_remote_source
(
&
module_url
,
false
,
false
,
1
)
.await
;
assert
!
(
source
.is_ok
());
let
source
=
source
.unwrap
();
...
...
cli/global_state.rs
浏览文件 @
f47f3f96
...
...
@@ -111,7 +111,7 @@ impl GlobalState {
let
out
=
self
.file_fetcher
.fetch_source_file
_async
(
&
module_specifier
,
maybe_referrer
)
.fetch_source_file
(
&
module_specifier
,
maybe_referrer
)
.await
?
;
// 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
compiled_module
=
match
out
.media_type
{
msg
::
MediaType
::
Unknown
=>
state1
.js_compiler
.compile
_async
(
out
)
.await
,
msg
::
MediaType
::
Json
=>
state1
.json_compiler
.compile
_async
(
&
out
)
.await
,
msg
::
MediaType
::
Unknown
=>
state1
.js_compiler
.compile
(
out
)
.await
,
msg
::
MediaType
::
Json
=>
state1
.json_compiler
.compile
(
&
out
)
.await
,
msg
::
MediaType
::
Wasm
=>
{
state1
.wasm_compiler
.compile_async
(
state1
.clone
(),
&
out
)
.await
state1
.wasm_compiler
.compile
(
state1
.clone
(),
&
out
)
.await
}
msg
::
MediaType
::
TypeScript
|
msg
::
MediaType
::
TSX
|
msg
::
MediaType
::
JSX
=>
{
state1
.ts_compiler
.compile
_async
(
state1
.clone
(),
&
out
,
target_lib
)
.compile
(
state1
.clone
(),
&
out
,
target_lib
)
.await
}
msg
::
MediaType
::
JavaScript
=>
{
if
state1
.ts_compiler.compile_js
{
state2
.ts_compiler
.compile
_async
(
state1
.clone
(),
&
out
,
target_lib
)
.compile
(
state1
.clone
(),
&
out
,
target_lib
)
.await
}
else
{
state1
.js_compiler
.compile
_async
(
out
)
.await
state1
.js_compiler
.compile
(
out
)
.await
}
}
}
?
;
...
...
@@ -182,10 +179,7 @@ impl GlobalState {
#[test]
fn
thread_safe
()
{
fn
f
<
S
:
Send
+
Sync
>
(
_
:
S
)
{}
f
(
GlobalState
::
mock
(
vec!
[
String
::
from
(
"./deno"
),
String
::
from
(
"hello.js"
),
]));
f
(
GlobalState
::
mock
(
vec!
[]));
}
#[test]
...
...
cli/http_util.rs
浏览文件 @
f47f3f96
...
...
@@ -238,7 +238,7 @@ mod tests {
use
super
::
*
;
#[tokio::test]
async
fn
test_fetch_s
ync_s
tring
()
{
async
fn
test_fetch_string
()
{
let
http_server_guard
=
crate
::
test_util
::
http_server
();
// Relies on external http server. See tools/http_server.py
let
url
=
...
...
@@ -388,7 +388,7 @@ mod tests {
}
#[tokio::test]
async
fn
test_fetch_with_cafile_s
ync_s
tring
()
{
async
fn
test_fetch_with_cafile_string
()
{
let
http_server_guard
=
crate
::
test_util
::
http_server
();
// Relies on external http server. See tools/http_server.py
let
url
=
...
...
@@ -402,7 +402,6 @@ mod tests {
)))
.unwrap
();
let
result
=
fetch_once
(
client
,
&
url
,
None
)
.await
;
if
let
Ok
(
FetchOnceResult
::
Code
(
body
,
headers
))
=
result
{
assert
!
(
!
body
.is_empty
());
assert_eq!
(
headers
.get
(
"content-type"
)
.unwrap
(),
"application/json"
);
...
...
cli/lib.rs
浏览文件 @
f47f3f96
...
...
@@ -152,7 +152,7 @@ async fn print_file_info(
let
out
=
global_state
.file_fetcher
.fetch_source_file
_async
(
&
module_specifier
,
None
)
.fetch_source_file
(
&
module_specifier
,
None
)
.await
?
;
println!
(
...
...
@@ -303,12 +303,12 @@ async fn bundle_command(
)
->
Result
<
(),
ErrBox
>
{
let
module_name
=
ModuleSpecifier
::
resolve_url_or_path
(
&
source_file
)
?
;
let
global_state
=
GlobalState
::
new
(
flags
)
?
;
debug!
(
">>>>> bundle
_async
START"
);
debug!
(
">>>>> bundle START"
);
let
bundle_result
=
global_state
.ts_compiler
.bundle
_async
(
global_state
.clone
(),
module_name
.to_string
(),
out_file
)
.bundle
(
global_state
.clone
(),
module_name
.to_string
(),
out_file
)
.await
;
debug!
(
">>>>> bundle
_async
END"
);
debug!
(
">>>>> bundle END"
);
bundle_result
}
...
...
cli/ops/compiler.rs
浏览文件 @
f47f3f96
...
...
@@ -112,7 +112,7 @@ fn op_fetch_source_files(
let
resolved_specifier
=
ModuleSpecifier
::
resolve_url
(
&
specifier
)
.expect
(
"Invalid specifier"
);
file_fetcher_
.fetch_source_file
_async
(
&
resolved_specifier
,
ref_specifier_
)
.fetch_source_file
(
&
resolved_specifier
,
ref_specifier_
)
.await
}
.boxed_local
()
...
...
@@ -130,7 +130,7 @@ fn op_fetch_source_files(
let
types_specifier
=
ModuleSpecifier
::
from
(
types_url
);
global_state
.file_fetcher
.fetch_source_file
_async
(
&
types_specifier
,
ref_specifier
.clone
())
.fetch_source_file
(
&
types_specifier
,
ref_specifier
.clone
())
.await
.map_err
(
OpError
::
from
)
?
}
...
...
@@ -143,7 +143,7 @@ fn op_fetch_source_files(
msg
::
MediaType
::
Wasm
=>
{
global_state
.wasm_compiler
.compile
_async
(
global_state
.clone
(),
&
file
)
.compile
(
global_state
.clone
(),
&
file
)
.await
.map_err
(|
e
|
OpError
::
other
(
e
.to_string
()))
?
.code
...
...
cli/ops/runtime_compiler.rs
浏览文件 @
f47f3f96
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
use
super
::
dispatch_json
::{
Deserialize
,
JsonOp
,
Value
};
use
crate
::
compilers
::
runtime_compile
_async
;
use
crate
::
compilers
::
runtime_transpile
_async
;
use
crate
::
compilers
::
runtime_compile
;
use
crate
::
compilers
::
runtime_transpile
;
use
crate
::
op_error
::
OpError
;
use
crate
::
state
::
State
;
use
deno_core
::
*
;
...
...
@@ -27,7 +27,7 @@ fn op_compile(
_
zero_copy
:
Option
<
ZeroCopyBuf
>
,
)
->
Result
<
JsonOp
,
OpError
>
{
let
args
:
CompileArgs
=
serde_json
::
from_value
(
args
)
?
;
Ok
(
JsonOp
::
Async
(
runtime_compile
_async
(
Ok
(
JsonOp
::
Async
(
runtime_compile
(
state
.borrow
()
.global_state
.clone
(),
&
args
.root_name
,
&
args
.sources
,
...
...
@@ -48,7 +48,7 @@ fn op_transpile(
_
zero_copy
:
Option
<
ZeroCopyBuf
>
,
)
->
Result
<
JsonOp
,
OpError
>
{
let
args
:
TranspileArgs
=
serde_json
::
from_value
(
args
)
?
;
Ok
(
JsonOp
::
Async
(
runtime_transpile
_async
(
Ok
(
JsonOp
::
Async
(
runtime_transpile
(
state
.borrow
()
.global_state
.clone
(),
&
args
.sources
,
&
args
.options
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录