mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
feat(npm): support packages with multiple command names (#15565)
This commit is contained in:
parent
4ef08a58df
commit
452df99222
84 changed files with 130 additions and 64240 deletions
|
@ -35,6 +35,7 @@
|
||||||
"cli/tests/testdata/import_assertions/json_with_shebang.json",
|
"cli/tests/testdata/import_assertions/json_with_shebang.json",
|
||||||
"cli/tests/testdata/inline_js_source_map*",
|
"cli/tests/testdata/inline_js_source_map*",
|
||||||
"cli/tests/testdata/malformed_config/*",
|
"cli/tests/testdata/malformed_config/*",
|
||||||
|
"cli/tests/testdata/npm/registry/",
|
||||||
"cli/tests/testdata/test/markdown_windows.md",
|
"cli/tests/testdata/test/markdown_windows.md",
|
||||||
"cli/tsc/*typescript.js",
|
"cli/tsc/*typescript.js",
|
||||||
"gh-pages",
|
"gh-pages",
|
||||||
|
|
|
@ -106,6 +106,27 @@ pub async fn initialize_runtime(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn initialize_binary_command(
|
||||||
|
js_runtime: &mut JsRuntime,
|
||||||
|
binary_name: &str,
|
||||||
|
) -> Result<(), AnyError> {
|
||||||
|
// overwrite what's done in deno_std in order to set the binary arg name
|
||||||
|
let source_code = &format!(
|
||||||
|
r#"(async function initializeBinaryCommand(binaryName) {{
|
||||||
|
const process = Deno[Deno.internal].node.globalThis.process;
|
||||||
|
Object.defineProperty(process.argv, "0", {{
|
||||||
|
get: () => binaryName,
|
||||||
|
}});
|
||||||
|
}})('{}');"#,
|
||||||
|
binary_name,
|
||||||
|
);
|
||||||
|
|
||||||
|
let value =
|
||||||
|
js_runtime.execute_script(&located_script_name!(), source_code)?;
|
||||||
|
js_runtime.resolve_value(value).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
/// This function is an implementation of `defaultResolve` in
|
/// This function is an implementation of `defaultResolve` in
|
||||||
/// `lib/internal/modules/esm/resolve.js` from Node.
|
/// `lib/internal/modules/esm/resolve.js` from Node.
|
||||||
pub fn node_resolve(
|
pub fn node_resolve(
|
||||||
|
|
|
@ -184,6 +184,27 @@ fn deno_run_cjs_module() {
|
||||||
assert!(deno_dir.path().join("test_dir").exists());
|
assert!(deno_dir.path().join("test_dir").exists());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
itest!(deno_run_cowsay {
|
||||||
|
args: "run --unstable -A --quiet npm:cowsay@1.5.0 Hello",
|
||||||
|
output: "npm/deno_run_cowsay.out",
|
||||||
|
envs: env_vars_no_sync_download(),
|
||||||
|
http_server: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
itest!(deno_run_cowsay_explicit {
|
||||||
|
args: "run --unstable -A --quiet npm:cowsay@1.5.0/cowsay Hello",
|
||||||
|
output: "npm/deno_run_cowsay.out",
|
||||||
|
envs: env_vars_no_sync_download(),
|
||||||
|
http_server: true,
|
||||||
|
});
|
||||||
|
|
||||||
|
itest!(deno_run_cowthink {
|
||||||
|
args: "run --unstable -A --quiet npm:cowsay@1.5.0/cowthink Hello",
|
||||||
|
output: "npm/deno_run_cowthink.out",
|
||||||
|
envs: env_vars_no_sync_download(),
|
||||||
|
http_server: true,
|
||||||
|
});
|
||||||
|
|
||||||
itest!(deno_run_non_existent {
|
itest!(deno_run_non_existent {
|
||||||
args: "run --unstable npm:mkdirp@0.5.125",
|
args: "run --unstable npm:mkdirp@0.5.125",
|
||||||
output: "npm/deno_run_non_existent.out",
|
output: "npm/deno_run_non_existent.out",
|
||||||
|
|
8
cli/tests/testdata/npm/deno_run_cowsay.out
vendored
Normal file
8
cli/tests/testdata/npm/deno_run_cowsay.out
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
_______
|
||||||
|
< Hello >
|
||||||
|
-------
|
||||||
|
\ ^__^
|
||||||
|
\ (oo)\_______
|
||||||
|
(__)\ )\/\
|
||||||
|
||----w |
|
||||||
|
|| ||
|
8
cli/tests/testdata/npm/deno_run_cowthink.out
vendored
Normal file
8
cli/tests/testdata/npm/deno_run_cowthink.out
vendored
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
_______
|
||||||
|
( Hello )
|
||||||
|
-------
|
||||||
|
o ^__^
|
||||||
|
o (oo)\_______
|
||||||
|
(__)\ )\/\
|
||||||
|
||----w |
|
||||||
|
|| ||
|
File diff suppressed because one or more lines are too long
31202
cli/tests/testdata/npm/registry/ajv/registry.json
vendored
31202
cli/tests/testdata/npm/registry/ajv/registry.json
vendored
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/ansi-regex/ansi-regex-3.0.1.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/ansi-regex/ansi-regex-3.0.1.tgz
vendored
Normal file
Binary file not shown.
BIN
cli/tests/testdata/npm/registry/ansi-regex/ansi-regex-5.0.1.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/ansi-regex/ansi-regex-5.0.1.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/ansi-regex/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/ansi-regex/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/camelcase/camelcase-5.3.1.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/camelcase/camelcase-5.3.1.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/camelcase/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/camelcase/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
4685
cli/tests/testdata/npm/registry/chai/registry.json
vendored
4685
cli/tests/testdata/npm/registry/chai/registry.json
vendored
File diff suppressed because one or more lines are too long
3745
cli/tests/testdata/npm/registry/chalk/registry.json
vendored
3745
cli/tests/testdata/npm/registry/chalk/registry.json
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/cliui/cliui-6.0.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/cliui/cliui-6.0.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/cliui/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/cliui/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/cowsay/cowsay-1.5.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/cowsay/cowsay-1.5.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/cowsay/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/cowsay/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/decamelize/decamelize-1.2.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/decamelize/decamelize-1.2.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/decamelize/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/decamelize/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
1429
cli/tests/testdata/npm/registry/deep-eql/registry.json
vendored
1429
cli/tests/testdata/npm/registry/deep-eql/registry.json
vendored
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/emoji-regex/emoji-regex-8.0.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/emoji-regex/emoji-regex-8.0.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/emoji-regex/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/emoji-regex/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/find-up/find-up-4.1.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/find-up/find-up-4.1.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/find-up/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/find-up/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/get-caller-file/get-caller-file-2.0.5.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/get-caller-file/get-caller-file-2.0.5.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/get-caller-file/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/get-caller-file/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/get-stdin/get-stdin-8.0.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/get-stdin/get-stdin-8.0.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/get-stdin/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/get-stdin/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/is-fullwidth-code-point/is-fullwidth-code-point-2.0.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/is-fullwidth-code-point/is-fullwidth-code-point-2.0.0.tgz
vendored
Normal file
Binary file not shown.
BIN
cli/tests/testdata/npm/registry/is-fullwidth-code-point/is-fullwidth-code-point-3.0.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/is-fullwidth-code-point/is-fullwidth-code-point-3.0.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/is-fullwidth-code-point/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/is-fullwidth-code-point/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/locate-path/locate-path-5.0.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/locate-path/locate-path-5.0.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/locate-path/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/locate-path/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
3036
cli/tests/testdata/npm/registry/loupe/registry.json
vendored
3036
cli/tests/testdata/npm/registry/loupe/registry.json
vendored
File diff suppressed because one or more lines are too long
1866
cli/tests/testdata/npm/registry/mkdirp/registry.json
vendored
1866
cli/tests/testdata/npm/registry/mkdirp/registry.json
vendored
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/p-limit/p-limit-2.3.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/p-limit/p-limit-2.3.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/p-limit/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/p-limit/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/p-locate/p-locate-4.1.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/p-locate/p-locate-4.1.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/p-locate/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/p-locate/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/p-try/p-try-2.2.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/p-try/p-try-2.2.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/p-try/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/p-try/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/path-exists/path-exists-4.0.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/path-exists/path-exists-4.0.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/path-exists/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/path-exists/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1518
cli/tests/testdata/npm/registry/punycode/registry.json
vendored
1518
cli/tests/testdata/npm/registry/punycode/registry.json
vendored
File diff suppressed because one or more lines are too long
1
cli/tests/testdata/npm/registry/require-directory/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/require-directory/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/require-directory/require-directory-2.1.1.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/require-directory/require-directory-2.1.1.tgz
vendored
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
1
cli/tests/testdata/npm/registry/require-main-filename/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/require-main-filename/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/require-main-filename/require-main-filename-2.0.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/require-main-filename/require-main-filename-2.0.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/set-blocking/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/set-blocking/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/set-blocking/set-blocking-2.0.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/set-blocking/set-blocking-2.0.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/string-width/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/string-width/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/string-width/string-width-2.1.1.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/string-width/string-width-2.1.1.tgz
vendored
Normal file
Binary file not shown.
BIN
cli/tests/testdata/npm/registry/string-width/string-width-4.2.3.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/string-width/string-width-4.2.3.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/strip-ansi/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/strip-ansi/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/strip-ansi/strip-ansi-4.0.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/strip-ansi/strip-ansi-4.0.0.tgz
vendored
Normal file
Binary file not shown.
BIN
cli/tests/testdata/npm/registry/strip-ansi/strip-ansi-6.0.1.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/strip-ansi/strip-ansi-6.0.1.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/strip-final-newline/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/strip-final-newline/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/strip-final-newline/strip-final-newline-2.0.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/strip-final-newline/strip-final-newline-2.0.0.tgz
vendored
Normal file
Binary file not shown.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1075
cli/tests/testdata/npm/registry/uri-js/registry.json
vendored
1075
cli/tests/testdata/npm/registry/uri-js/registry.json
vendored
File diff suppressed because one or more lines are too long
1
cli/tests/testdata/npm/registry/which-module/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/which-module/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/which-module/which-module-2.0.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/which-module/which-module-2.0.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/wrap-ansi/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/wrap-ansi/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/wrap-ansi/wrap-ansi-6.2.0.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/wrap-ansi/wrap-ansi-6.2.0.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/y18n/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/y18n/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/y18n/y18n-4.0.3.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/y18n/y18n-4.0.3.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/yargs-parser/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/yargs-parser/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/yargs-parser/yargs-parser-18.1.3.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/yargs-parser/yargs-parser-18.1.3.tgz
vendored
Normal file
Binary file not shown.
1
cli/tests/testdata/npm/registry/yargs/registry.json
vendored
Normal file
1
cli/tests/testdata/npm/registry/yargs/registry.json
vendored
Normal file
File diff suppressed because one or more lines are too long
BIN
cli/tests/testdata/npm/registry/yargs/yargs-15.4.1.tgz
vendored
Normal file
BIN
cli/tests/testdata/npm/registry/yargs/yargs-15.4.1.tgz
vendored
Normal file
Binary file not shown.
|
@ -21,6 +21,7 @@ use deno_runtime::worker::MainWorker;
|
||||||
use deno_runtime::worker::WorkerOptions;
|
use deno_runtime::worker::WorkerOptions;
|
||||||
use deno_runtime::BootstrapOptions;
|
use deno_runtime::BootstrapOptions;
|
||||||
|
|
||||||
|
use crate::args::DenoSubcommand;
|
||||||
use crate::checksum;
|
use crate::checksum;
|
||||||
use crate::compat;
|
use crate::compat;
|
||||||
use crate::errors;
|
use crate::errors;
|
||||||
|
@ -103,7 +104,7 @@ impl CliMainWorker {
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
} else if self.is_main_cjs {
|
} else if self.is_main_cjs {
|
||||||
node::initialize_runtime(&mut self.worker.js_runtime).await?;
|
self.initialize_main_module_for_node().await?;
|
||||||
node::load_cjs_module_from_ext_node(
|
node::load_cjs_module_from_ext_node(
|
||||||
&mut self.worker.js_runtime,
|
&mut self.worker.js_runtime,
|
||||||
&self.main_module.to_file_path().unwrap().to_string_lossy(),
|
&self.main_module.to_file_path().unwrap().to_string_lossy(),
|
||||||
|
@ -422,11 +423,31 @@ impl CliMainWorker {
|
||||||
id: ModuleId,
|
id: ModuleId,
|
||||||
) -> Result<(), AnyError> {
|
) -> Result<(), AnyError> {
|
||||||
if self.ps.npm_resolver.has_packages() {
|
if self.ps.npm_resolver.has_packages() {
|
||||||
node::initialize_runtime(&mut self.worker.js_runtime).await?;
|
self.initialize_main_module_for_node().await?;
|
||||||
}
|
}
|
||||||
self.worker.evaluate_module(id).await
|
self.worker.evaluate_module(id).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async fn initialize_main_module_for_node(&mut self) -> Result<(), AnyError> {
|
||||||
|
node::initialize_runtime(&mut self.worker.js_runtime).await?;
|
||||||
|
if let DenoSubcommand::Run(flags) = self.ps.options.sub_command() {
|
||||||
|
if let Ok(pkg_ref) = NpmPackageReference::from_str(&flags.script) {
|
||||||
|
// if the user ran a binary command, we'll need to set process.argv[0]
|
||||||
|
// to be the name of the binary command instead of deno
|
||||||
|
let binary_name = pkg_ref
|
||||||
|
.sub_path
|
||||||
|
.as_deref()
|
||||||
|
.unwrap_or(pkg_ref.req.name.as_str());
|
||||||
|
node::initialize_binary_command(
|
||||||
|
&mut self.worker.js_runtime,
|
||||||
|
binary_name,
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
async fn maybe_setup_coverage_collector(
|
async fn maybe_setup_coverage_collector(
|
||||||
&mut self,
|
&mut self,
|
||||||
) -> Result<Option<CoverageCollector>, AnyError> {
|
) -> Result<Option<CoverageCollector>, AnyError> {
|
||||||
|
|
Loading…
Reference in a new issue