mirror of
https://github.com/denoland/deno.git
synced 2025-01-03 04:48:52 -05:00
fix(cli): ignore x-typescript-types header when media type is not js/jsx (#10574)
This commit is contained in:
parent
ea83f18f90
commit
e8a7f237de
2 changed files with 52 additions and 2 deletions
|
@ -327,7 +327,12 @@ impl FileFetcher {
|
|||
let (media_type, maybe_charset) =
|
||||
map_content_type(specifier, maybe_content_type);
|
||||
let source = strip_shebang(get_source_from_bytes(bytes, maybe_charset)?);
|
||||
let maybe_types = headers.get("x-typescript-types").cloned();
|
||||
let maybe_types = match media_type {
|
||||
MediaType::JavaScript | MediaType::Jsx => {
|
||||
headers.get("x-typescript-types").cloned()
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
|
||||
Ok(File {
|
||||
local,
|
||||
|
@ -1593,7 +1598,7 @@ mod tests {
|
|||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_fetch_remote_with_types() {
|
||||
async fn test_fetch_remote_javascript_with_types() {
|
||||
let specifier =
|
||||
resolve_url_or_path("http://127.0.0.1:4545/xTypeScriptTypes.js").unwrap();
|
||||
let (file, _) = test_fetch_remote(&specifier).await;
|
||||
|
@ -1603,6 +1608,27 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_fetch_remote_jsx_with_types() {
|
||||
let specifier =
|
||||
resolve_url_or_path("http://127.0.0.1:4545/xTypeScriptTypes.jsx")
|
||||
.unwrap();
|
||||
let (file, _) = test_fetch_remote(&specifier).await;
|
||||
assert_eq!(file.media_type, MediaType::Jsx,);
|
||||
assert_eq!(
|
||||
file.maybe_types,
|
||||
Some("./xTypeScriptTypes.d.ts".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_fetch_remote_typescript_with_types() {
|
||||
let specifier =
|
||||
resolve_url_or_path("http://127.0.0.1:4545/xTypeScriptTypes.ts").unwrap();
|
||||
let (file, _) = test_fetch_remote(&specifier).await;
|
||||
assert_eq!(file.maybe_types, None);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_fetch_remote_utf16_le() {
|
||||
let expected =
|
||||
|
|
|
@ -497,6 +497,30 @@ async fn main_server(req: Request<Body>) -> hyper::Result<Response<Body>> {
|
|||
);
|
||||
Ok(res)
|
||||
}
|
||||
(_, "/xTypeScriptTypes.jsx") => {
|
||||
let mut res = Response::new(Body::from("export const foo = 'foo';"));
|
||||
res
|
||||
.headers_mut()
|
||||
.insert("Content-type", HeaderValue::from_static("text/jsx"));
|
||||
res.headers_mut().insert(
|
||||
"X-TypeScript-Types",
|
||||
HeaderValue::from_static("./xTypeScriptTypes.d.ts"),
|
||||
);
|
||||
Ok(res)
|
||||
}
|
||||
(_, "/xTypeScriptTypes.ts") => {
|
||||
let mut res =
|
||||
Response::new(Body::from("export const foo: string = 'foo';"));
|
||||
res.headers_mut().insert(
|
||||
"Content-type",
|
||||
HeaderValue::from_static("application/typescript"),
|
||||
);
|
||||
res.headers_mut().insert(
|
||||
"X-TypeScript-Types",
|
||||
HeaderValue::from_static("./xTypeScriptTypes.d.ts"),
|
||||
);
|
||||
Ok(res)
|
||||
}
|
||||
(_, "/xTypeScriptTypes.d.ts") => {
|
||||
let mut res = Response::new(Body::from("export const foo: 'foo';"));
|
||||
res.headers_mut().insert(
|
||||
|
|
Loading…
Reference in a new issue