mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
fix: media type for .cjs and application/node (#6005)
This commit is contained in:
parent
aa514c058a
commit
02d46bae9f
5 changed files with 23 additions and 1 deletions
|
@ -544,6 +544,7 @@ pub fn map_file_extension(path: &Path) -> msg::MediaType {
|
|||
Some("js") => msg::MediaType::JavaScript,
|
||||
Some("jsx") => msg::MediaType::JSX,
|
||||
Some("mjs") => msg::MediaType::JavaScript,
|
||||
Some("cjs") => msg::MediaType::JavaScript,
|
||||
Some("json") => msg::MediaType::Json,
|
||||
Some("wasm") => msg::MediaType::Wasm,
|
||||
_ => msg::MediaType::Unknown,
|
||||
|
@ -572,7 +573,8 @@ fn map_content_type(path: &Path, content_type: Option<&str>) -> msg::MediaType {
|
|||
| "text/javascript"
|
||||
| "application/ecmascript"
|
||||
| "text/ecmascript"
|
||||
| "application/x-javascript" => {
|
||||
| "application/x-javascript"
|
||||
| "application/node" => {
|
||||
map_js_like_extension(path, msg::MediaType::JavaScript)
|
||||
}
|
||||
"application/json" | "text/json" => msg::MediaType::Json,
|
||||
|
@ -1596,6 +1598,10 @@ mod tests {
|
|||
map_file_extension(Path::new("foo/bar.wasm")),
|
||||
msg::MediaType::Wasm
|
||||
);
|
||||
assert_eq!(
|
||||
map_file_extension(Path::new("foo/bar.cjs")),
|
||||
msg::MediaType::JavaScript
|
||||
);
|
||||
assert_eq!(
|
||||
map_file_extension(Path::new("foo/bar.txt")),
|
||||
msg::MediaType::Unknown
|
||||
|
@ -1641,6 +1647,10 @@ mod tests {
|
|||
map_content_type(Path::new("foo/bar.wasm"), None),
|
||||
msg::MediaType::Wasm
|
||||
);
|
||||
assert_eq!(
|
||||
map_content_type(Path::new("foo/bar.cjs"), None),
|
||||
msg::MediaType::JavaScript
|
||||
);
|
||||
assert_eq!(
|
||||
map_content_type(Path::new("foo/bar"), None),
|
||||
msg::MediaType::Unknown
|
||||
|
@ -1694,6 +1704,10 @@ mod tests {
|
|||
map_content_type(Path::new("foo/bar"), Some("application/json")),
|
||||
msg::MediaType::Json
|
||||
);
|
||||
assert_eq!(
|
||||
map_content_type(Path::new("foo/bar"), Some("application/node")),
|
||||
msg::MediaType::JavaScript
|
||||
);
|
||||
assert_eq!(
|
||||
map_content_type(Path::new("foo/bar"), Some("text/json")),
|
||||
msg::MediaType::Json
|
||||
|
|
1
cli/tests/cjs_imports.ts
Normal file
1
cli/tests/cjs_imports.ts
Normal file
|
@ -0,0 +1 @@
|
|||
import "./commonjs.cjs";
|
1
cli/tests/cjs_imports.ts.out
Normal file
1
cli/tests/cjs_imports.ts.out
Normal file
|
@ -0,0 +1 @@
|
|||
Hello World
|
1
cli/tests/commonjs.cjs
Normal file
1
cli/tests/commonjs.cjs
Normal file
|
@ -0,0 +1 @@
|
|||
console.log("Hello World");
|
|
@ -1832,6 +1832,11 @@ itest!(es_private_fields {
|
|||
output: "es_private_fields.js.out",
|
||||
});
|
||||
|
||||
itest!(cjs_imports {
|
||||
args: "run --quiet --reload cjs_imports.ts",
|
||||
output: "cjs_imports.ts.out",
|
||||
});
|
||||
|
||||
itest!(proto_exploit {
|
||||
args: "run proto_exploit.js",
|
||||
output: "proto_exploit.js.out",
|
||||
|
|
Loading…
Add table
Reference in a new issue