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:
parent
6a9acc8142
commit
7b98282993
9 changed files with 47 additions and 10 deletions
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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",
|
||||
|
|
4
cli/tests/testdata/npm/deno_run_cjs.out
vendored
Normal file
4
cli/tests/testdata/npm/deno_run_cjs.out
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
this
|
||||
is
|
||||
a
|
||||
test
|
4
cli/tests/testdata/npm/deno_run_no_ext.out
vendored
Normal file
4
cli/tests/testdata/npm/deno_run_no_ext.out
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
this
|
||||
is
|
||||
a
|
||||
test
|
5
cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/cli-cjs.js
vendored
Normal file
5
cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/cli-cjs.js
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
const process = require("process");
|
||||
|
||||
for (const arg of process.argv.slice(2)) {
|
||||
console.log(arg);
|
||||
}
|
5
cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/cli-no-ext
vendored
Normal file
5
cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/cli-no-ext
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
const process = require("process");
|
||||
|
||||
for (const arg of process.argv.slice(2)) {
|
||||
console.log(arg);
|
||||
}
|
9
cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/package.json
vendored
Normal file
9
cli/tests/testdata/npm/registry/@denotest/bin/1.0.0/package.json
vendored
Normal 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"
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"name": "@deno/esm-bin",
|
||||
"version": "1.0.0",
|
||||
"bin": "./cli.mjs"
|
||||
}
|
Loading…
Reference in a new issue