summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/file_fetcher.rs16
-rw-r--r--cli/tests/cjs_imports.ts1
-rw-r--r--cli/tests/cjs_imports.ts.out1
-rw-r--r--cli/tests/commonjs.cjs1
-rw-r--r--cli/tests/integration_tests.rs5
5 files changed, 23 insertions, 1 deletions
diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs
index 375142e07..be3bc6efc 100644
--- a/cli/file_fetcher.rs
+++ b/cli/file_fetcher.rs
@@ -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,
@@ -1597,6 +1599,10 @@ mod tests {
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
);
@@ -1642,6 +1648,10 @@ mod tests {
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
);
@@ -1695,6 +1705,10 @@ mod tests {
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
);
diff --git a/cli/tests/cjs_imports.ts b/cli/tests/cjs_imports.ts
new file mode 100644
index 000000000..d8b77c22e
--- /dev/null
+++ b/cli/tests/cjs_imports.ts
@@ -0,0 +1 @@
+import "./commonjs.cjs";
diff --git a/cli/tests/cjs_imports.ts.out b/cli/tests/cjs_imports.ts.out
new file mode 100644
index 000000000..557db03de
--- /dev/null
+++ b/cli/tests/cjs_imports.ts.out
@@ -0,0 +1 @@
+Hello World
diff --git a/cli/tests/commonjs.cjs b/cli/tests/commonjs.cjs
new file mode 100644
index 000000000..7df7d571e
--- /dev/null
+++ b/cli/tests/commonjs.cjs
@@ -0,0 +1 @@
+console.log("Hello World"); \ No newline at end of file
diff --git a/cli/tests/integration_tests.rs b/cli/tests/integration_tests.rs
index 6ab204082..807efb1c5 100644
--- a/cli/tests/integration_tests.rs
+++ b/cli/tests/integration_tests.rs
@@ -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",