diff --git a/cli/node/mod.rs b/cli/node/mod.rs index 7e1ea95f7b..2ec9295dd8 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 85c31786ce..49bac64fb3 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 0000000000..ffe7cbd891 --- /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 0000000000..ffe7cbd891 --- /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 0000000000..7b6ba27241 --- /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 0000000000..7b6ba27241 --- /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 similarity index 100% rename from cli/tests/testdata/npm/registry/@denotest/esm-bin/1.0.0/cli.mjs rename to 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 0000000000..78a1abff2f --- /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 ecd0d24a7b..0000000000 --- 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" -}