summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cli/node/mod.rs7
-rw-r--r--cli/tests/integration/npm_tests.rs18
-rw-r--r--cli/tests/testdata/npm/deno_run_cjs.out4
-rw-r--r--cli/tests/testdata/npm/deno_run_no_ext.out4
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/cli-cjs.js5
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/cli-no-ext5
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/cli.mjs (renamed from cli/tests/testdata/npm/registry/@denotest/esm-bin/1.0.0/cli.mjs)0
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/package.json9
-rw-r--r--cli/tests/testdata/npm/registry/@denotest/esm-bin/1.0.0/package.json5
9 files changed, 47 insertions, 10 deletions
diff --git a/cli/node/mod.rs b/cli/node/mod.rs
index 7e1ea95f7..2ec9295dd 100644
--- a/cli/node/mod.rs
+++ b/cli/node/mod.rs
@@ -42,6 +42,7 @@ mod analyze;
pub use analyze::esm_code_with_node_globals;
+#[derive(Debug)]
pub enum NodeResolution {
Esm(ModuleSpecifier),
CommonJs(ModuleSpecifier),
@@ -578,10 +579,10 @@ fn url_to_node_resolution(
} else {
NodeResolution::CommonJs(url)
}
- } else if url.as_str().ends_with(".cjs") {
- NodeResolution::CommonJs(url)
- } else {
+ } else if url.as_str().ends_with(".mjs") {
NodeResolution::Esm(url)
+ } else {
+ NodeResolution::CommonJs(url)
})
}
diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs
index 85c31786c..49bac64fb 100644
--- a/cli/tests/integration/npm_tests.rs
+++ b/cli/tests/integration/npm_tests.rs
@@ -387,13 +387,27 @@ itest!(deno_run_cowthink {
http_server: true,
});
-itest!(deno_run_esm_module {
- args: "run --unstable -A --quiet npm:@denotest/esm-bin this is a test",
+itest!(deno_run_bin_esm {
+ args: "run --unstable -A --quiet npm:@denotest/bin/cli-esm this is a test",
output: "npm/deno_run_esm.out",
envs: env_vars(),
http_server: true,
});
+itest!(deno_run_bin_no_ext {
+ args: "run --unstable -A --quiet npm:@denotest/bin/cli-no-ext this is a test",
+ output: "npm/deno_run_no_ext.out",
+ envs: env_vars(),
+ http_server: true,
+});
+
+itest!(deno_run_bin_cjs {
+ args: "run --unstable -A --quiet npm:@denotest/bin/cli-cjs this is a test",
+ output: "npm/deno_run_cjs.out",
+ envs: env_vars(),
+ http_server: true,
+});
+
itest!(deno_run_non_existent {
args: "run --unstable npm:mkdirp@0.5.125",
output: "npm/deno_run_non_existent.out",
diff --git a/cli/tests/testdata/npm/deno_run_cjs.out b/cli/tests/testdata/npm/deno_run_cjs.out
new file mode 100644
index 000000000..ffe7cbd89
--- /dev/null
+++ b/cli/tests/testdata/npm/deno_run_cjs.out
@@ -0,0 +1,4 @@
+this
+is
+a
+test
diff --git a/cli/tests/testdata/npm/deno_run_no_ext.out b/cli/tests/testdata/npm/deno_run_no_ext.out
new file mode 100644
index 000000000..ffe7cbd89
--- /dev/null
+++ b/cli/tests/testdata/npm/deno_run_no_ext.out
@@ -0,0 +1,4 @@
+this
+is
+a
+test
diff --git a/cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/cli-cjs.js b/cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/cli-cjs.js
new file mode 100644
index 000000000..7b6ba2724
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/cli-cjs.js
@@ -0,0 +1,5 @@
+const process = require("process");
+
+for (const arg of process.argv.slice(2)) {
+ console.log(arg);
+}
diff --git a/cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/cli-no-ext b/cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/cli-no-ext
new file mode 100644
index 000000000..7b6ba2724
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/cli-no-ext
@@ -0,0 +1,5 @@
+const process = require("process");
+
+for (const arg of process.argv.slice(2)) {
+ console.log(arg);
+}
diff --git a/cli/tests/testdata/npm/registry/@denotest/esm-bin/1.0.0/cli.mjs b/cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/cli.mjs
index 0ae8e9190..0ae8e9190 100644
--- a/cli/tests/testdata/npm/registry/@denotest/esm-bin/1.0.0/cli.mjs
+++ b/cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/cli.mjs
diff --git a/cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/package.json b/cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/package.json
new file mode 100644
index 000000000..78a1abff2
--- /dev/null
+++ b/cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/package.json
@@ -0,0 +1,9 @@
+{
+ "name": "@deno/bin",
+ "version": "1.0.0",
+ "bin": {
+ "cli-esm": "./cli.mjs",
+ "cli-no-ext": "./cli-no-ext",
+ "cli-cjs": "./cli-cjs.js"
+ }
+}
diff --git a/cli/tests/testdata/npm/registry/@denotest/esm-bin/1.0.0/package.json b/cli/tests/testdata/npm/registry/@denotest/esm-bin/1.0.0/package.json
deleted file mode 100644
index ecd0d24a7..000000000
--- a/cli/tests/testdata/npm/registry/@denotest/esm-bin/1.0.0/package.json
+++ /dev/null
@@ -1,5 +0,0 @@
-{
- "name": "@deno/esm-bin",
- "version": "1.0.0",
- "bin": "./cli.mjs"
-}