1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-21 23:04:45 -05:00

fix(npm): binary entrypoint for .js or no extension (#15900)

This commit is contained in:
Bartek Iwańczuk 2022-09-14 16:41:47 +02:00 committed by GitHub
parent 6a9acc8142
commit 7b98282993
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 47 additions and 10 deletions

View file

@ -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)
})
}

View file

@ -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",

View file

@ -0,0 +1,4 @@
this
is
a
test

View file

@ -0,0 +1,4 @@
this
is
a
test

View file

@ -0,0 +1,5 @@
const process = require("process");
for (const arg of process.argv.slice(2)) {
console.log(arg);
}

View file

@ -0,0 +1,5 @@
const process = require("process");
for (const arg of process.argv.slice(2)) {
console.log(arg);
}

View file

@ -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"
}
}

View file

@ -1,5 +0,0 @@
{
"name": "@deno/esm-bin",
"version": "1.0.0",
"bin": "./cli.mjs"
}