-
Notifications
You must be signed in to change notification settings - Fork 5.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Guess extensions on extension not provided #859
Changes from 9 commits
c6a2413
bffb412
699822b
09739fb
469771e
c4f5adb
02fbf23
9da5589
b9d1ccc
eb95e04
c211eb7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
// Copyright 2018 the Deno authors. All rights reserved. MIT license. | ||
|
||
use errors::DenoResult; | ||
use errors; | ||
use errors::{DenoError, DenoResult}; | ||
use futures; | ||
use futures::future::Either; | ||
use futures::Future; | ||
use tokio_util; | ||
|
||
use futures::Future; | ||
use futures::Stream; | ||
use hyper; | ||
use hyper::client::Client; | ||
kevinkassimo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
@@ -31,11 +34,25 @@ pub fn get_client() -> Client<Connector, hyper::Body> { | |
pub fn fetch_sync_string(module_name: &str) -> DenoResult<String> { | ||
let url = module_name.parse::<Uri>().unwrap(); | ||
let client = get_client(); | ||
let future = client | ||
let fetch_future = client | ||
.get(url) | ||
.and_then(|response| response.into_body().concat2()); | ||
let body = tokio_util::block_on(future)?; | ||
Ok(String::from_utf8(body.to_vec()).unwrap()) | ||
.map_err(|err| DenoError::from(err)) | ||
.and_then(|response| { | ||
if !response.status().is_success() { | ||
return Either::A(futures::future::err(errors::new( | ||
errors::ErrorKind::NotFound, | ||
"module not found".to_string(), | ||
))); | ||
} | ||
Either::B( | ||
response | ||
.into_body() | ||
.concat2() | ||
.map(|body| String::from_utf8(body.to_vec()).unwrap()) | ||
.map_err(|err| DenoError::from(err)), | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to do this more simply myself but couldn't. I think this is correct. Rust is annoyingly painful at times. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah... I found threads complaining similar stuff this morning, and supposedly these issues could be better addressed with the currently experimental async-await syntax |
||
}); | ||
tokio_util::block_on(fetch_future) | ||
} | ||
|
||
/* TODO(ry) Re-enabled this test. Disabling to work around bug in #782. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { isTSFile, printHello, phNoExt } from "./subdir/mod3"; | ||
console.log(isTSFile); | ||
console.log(printHello); | ||
console.log(phNoExt); | ||
|
||
import { isMod4 } from "./subdir/mod4"; | ||
console.log(isMod4); | ||
|
||
import { printHello as ph } from "http://localhost:4545/tests/subdir/mod2"; | ||
console.log(ph); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Downloading http://localhost:4545/tests/subdir/mod2 | ||
Downloading http://localhost:4545/tests/subdir/mod2.ts | ||
Downloading http://localhost:4545/tests/subdir/print_hello.ts | ||
true | ||
[Function: printHello] | ||
[Function: printHello] | ||
true | ||
[Function: printHello] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "./non-existent"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
NotFound: Cannot resolve module "./non-existent" from "[WILDCARD]deno/tests/error_006_import_ext_failure.ts" | ||
at maybeError (deno/js/errors.ts:[WILDCARD]) | ||
at maybeThrowError (deno/js/errors.ts:[WILDCARD]) | ||
at sendSync (deno/js/dispatch.ts:[WILDCARD]) | ||
at Object.codeFetch (deno/js/os.ts:[WILDCARD]) | ||
at DenoCompiler.resolveModule (deno/js/compiler.ts:[WILDCARD]) | ||
at DenoCompiler._resolveModuleName (deno/js/compiler.ts:[WILDCARD]) | ||
at moduleNames.map.name (deno/js/compiler.ts:[WILDCARD]) | ||
at Array.map (<anonymous>) | ||
at DenoCompiler.resolveModuleNames (deno/js/compiler.ts:[WILDCARD]) | ||
at Object.compilerHost.resolveModuleNames (deno/third_party/node_modules/typescript/lib/typescript.js:[WILDCARD]) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const isTSFile = false; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const isTSFile = true; | ||
export { printHello } from "./print_hello.ts"; | ||
export { printHello as phNoExt } from "./print_hello"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const isMod4 = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If no need to use the value in
Ok
, would it be better to use withis_some()
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW should be
Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yes! Thanks for catching the typo :P