mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
feat: support .mjs extension resolution (#2283)
Removed `extmap` and added .mjs entry in `map_file_extension`. The assert in the compiler does not need to be updated, since it is resolving from the compiled cache instead of elsewhere (notice the .map is asserted next to it)
This commit is contained in:
parent
4648277fb4
commit
401a5c0211
5 changed files with 8 additions and 15 deletions
|
@ -26,16 +26,6 @@ use std::str;
|
|||
use url;
|
||||
use url::Url;
|
||||
|
||||
/// Gets corresponding MediaType given extension
|
||||
fn extmap(ext: &str) -> msg::MediaType {
|
||||
match ext {
|
||||
"ts" => msg::MediaType::TypeScript,
|
||||
"js" => msg::MediaType::JavaScript,
|
||||
"json" => msg::MediaType::Json,
|
||||
_ => msg::MediaType::Unknown,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct DenoDir {
|
||||
// Example: /Users/rld/.deno/
|
||||
|
@ -553,6 +543,7 @@ fn map_file_extension(path: &Path) -> msg::MediaType {
|
|||
Some(os_str) => match os_str.to_str() {
|
||||
Some("ts") => msg::MediaType::TypeScript,
|
||||
Some("js") => msg::MediaType::JavaScript,
|
||||
Some("mjs") => msg::MediaType::JavaScript,
|
||||
Some("json") => msg::MediaType::Json,
|
||||
_ => msg::MediaType::Unknown,
|
||||
},
|
||||
|
@ -871,11 +862,7 @@ fn save_source_code_headers(
|
|||
let mime_type_string = mime_type.clone().unwrap();
|
||||
let resolved_mime_type =
|
||||
{ map_content_type(Path::new(""), Some(mime_type_string.as_str())) };
|
||||
let ext = p
|
||||
.extension()
|
||||
.map(|x| x.to_str().unwrap_or(""))
|
||||
.unwrap_or("");
|
||||
let ext_based_mime_type = extmap(&ext);
|
||||
let ext_based_mime_type = map_file_extension(&p);
|
||||
// Add mime to headers only when content type is different from extension.
|
||||
if ext_based_mime_type == msg::MediaType::Unknown
|
||||
|| resolved_mime_type != ext_based_mime_type
|
||||
|
|
2
tests/021_mjs_modules.test
Normal file
2
tests/021_mjs_modules.test
Normal file
|
@ -0,0 +1,2 @@
|
|||
args: --reload tests/021_mjs_modules.ts
|
||||
output: tests/021_mjs_modules.ts.out
|
2
tests/021_mjs_modules.ts
Normal file
2
tests/021_mjs_modules.ts
Normal file
|
@ -0,0 +1,2 @@
|
|||
import { isMod5 } from "./subdir/mod5.mjs";
|
||||
console.log(isMod5);
|
1
tests/021_mjs_modules.ts.out
Normal file
1
tests/021_mjs_modules.ts.out
Normal file
|
@ -0,0 +1 @@
|
|||
true
|
1
tests/subdir/mod5.mjs
Normal file
1
tests/subdir/mod5.mjs
Normal file
|
@ -0,0 +1 @@
|
|||
export const isMod5 = true;
|
Loading…
Reference in a new issue