Skip to content

Commit

Permalink
feat: support .mjs extension resolution (denoland#2283)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
kevinkassimo authored and ry committed May 3, 2019
1 parent 4648277 commit 401a5c0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 15 deletions.
17 changes: 2 additions & 15 deletions cli/deno_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/021_mjs_modules.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
args: --reload tests/021_mjs_modules.ts
output: tests/021_mjs_modules.ts.out
2 changes: 2 additions & 0 deletions tests/021_mjs_modules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { isMod5 } from "./subdir/mod5.mjs";
console.log(isMod5);
1 change: 1 addition & 0 deletions tests/021_mjs_modules.ts.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
1 change: 1 addition & 0 deletions tests/subdir/mod5.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isMod5 = true;

0 comments on commit 401a5c0

Please sign in to comment.