summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-09-03 15:56:39 +0200
committerGitHub <noreply@github.com>2024-09-03 13:56:39 +0000
commitb8ed6f822174b2322fbe9f8b58698b76b5505b4a (patch)
tree324f208e53ac8f5ee1f04e7c69fc7d8f4946c81e
parent7c594023256ffdc8a16db017676319da448dd926 (diff)
fix(task): correct name for scoped npm package binaries (#25390)
This is for when not using a node_modules directory or when using auto install for a node_modules dir.
-rw-r--r--cli/tools/task.rs41
-rw-r--r--ext/node_resolver/resolution.rs1
-rw-r--r--tests/specs/task/bin_pkg_with_scope_auto/__test__.jsonc5
-rw-r--r--tests/specs/task/bin_pkg_with_scope_auto/bin_auto.out14
-rw-r--r--tests/specs/task/bin_pkg_with_scope_auto/bin_none.out12
-rw-r--r--tests/specs/task/bin_pkg_with_scope_auto/deno.json3
-rw-r--r--tests/specs/task/bin_pkg_with_scope_auto/package.json9
-rw-r--r--tests/specs/task/bin_pkg_with_scope_none/__test__.jsonc5
-rw-r--r--tests/specs/task/bin_pkg_with_scope_none/bin_none.out12
-rw-r--r--tests/specs/task/bin_pkg_with_scope_none/deno.json3
-rw-r--r--tests/specs/task/bin_pkg_with_scope_none/package.json9
11 files changed, 93 insertions, 21 deletions
diff --git a/cli/tools/task.rs b/cli/tools/task.rs
index 23da5b4fb..cc16bb9a3 100644
--- a/cli/tools/task.rs
+++ b/cli/tools/task.rs
@@ -1,13 +1,13 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
-use crate::args::CliOptions;
-use crate::args::Flags;
-use crate::args::TaskFlags;
-use crate::colors;
-use crate::factory::CliFactory;
-use crate::npm::CliNpmResolver;
-use crate::task_runner;
-use crate::util::fs::canonicalize_path;
+use std::borrow::Cow;
+use std::collections::HashMap;
+use std::collections::HashSet;
+use std::path::Path;
+use std::path::PathBuf;
+use std::rc::Rc;
+use std::sync::Arc;
+
use deno_config::deno_json::Task;
use deno_config::workspace::TaskOrScript;
use deno_config::workspace::WorkspaceDirectory;
@@ -18,13 +18,15 @@ use deno_core::anyhow::Context;
use deno_core::error::AnyError;
use deno_core::normalize_path;
use deno_task_shell::ShellCommand;
-use std::borrow::Cow;
-use std::collections::HashMap;
-use std::collections::HashSet;
-use std::path::Path;
-use std::path::PathBuf;
-use std::rc::Rc;
-use std::sync::Arc;
+
+use crate::args::CliOptions;
+use crate::args::Flags;
+use crate::args::TaskFlags;
+use crate::colors;
+use crate::factory::CliFactory;
+use crate::npm::CliNpmResolver;
+use crate::task_runner;
+use crate::util::fs::canonicalize_path;
pub async fn execute_script(
flags: Arc<Flags>,
@@ -106,12 +108,9 @@ See https://docs.deno.com/go/config"#
.await
}
TaskOrScript::Script(scripts, _script) => {
- // ensure the npm packages are installed if using a node_modules
- // directory and managed resolver
- if cli_options.has_node_modules_dir() {
- if let Some(npm_resolver) = npm_resolver.as_managed() {
- npm_resolver.ensure_top_level_package_json_install().await?;
- }
+ // ensure the npm packages are installed if using a managed resolver
+ if let Some(npm_resolver) = npm_resolver.as_managed() {
+ npm_resolver.ensure_top_level_package_json_install().await?;
}
let cwd = match task_flags.cwd {
diff --git a/ext/node_resolver/resolution.rs b/ext/node_resolver/resolution.rs
index ae791e312..ad9dbb710 100644
--- a/ext/node_resolver/resolution.rs
+++ b/ext/node_resolver/resolution.rs
@@ -367,6 +367,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
pkg_json_path,
});
};
+ let name = name.split("/").last().unwrap();
vec![name.to_string()]
}
Some(Value::Object(o)) => {
diff --git a/tests/specs/task/bin_pkg_with_scope_auto/__test__.jsonc b/tests/specs/task/bin_pkg_with_scope_auto/__test__.jsonc
new file mode 100644
index 000000000..2e126f6b1
--- /dev/null
+++ b/tests/specs/task/bin_pkg_with_scope_auto/__test__.jsonc
@@ -0,0 +1,5 @@
+{
+ "tempDir": true,
+ "args": "task bin extra",
+ "output": "bin_auto.out"
+}
diff --git a/tests/specs/task/bin_pkg_with_scope_auto/bin_auto.out b/tests/specs/task/bin_pkg_with_scope_auto/bin_auto.out
new file mode 100644
index 000000000..20865898e
--- /dev/null
+++ b/tests/specs/task/bin_pkg_with_scope_auto/bin_auto.out
@@ -0,0 +1,14 @@
+Download http://localhost:4260/@denotest/bin
+[UNORDERED_START]
+Download http://localhost:4260/@denotest/bin/0.5.0.tgz
+Initialize @denotest/bin@0.5.0
+Download http://localhost:4260/@denotest/bin/1.0.0.tgz
+Initialize @denotest/bin@1.0.0
+[UNORDERED_END]
+Task bin bin hi && cli-esm testing this out && npx cli-cjs test "extra"
+hi
+testing
+this
+out
+test
+extra
diff --git a/tests/specs/task/bin_pkg_with_scope_auto/bin_none.out b/tests/specs/task/bin_pkg_with_scope_auto/bin_none.out
new file mode 100644
index 000000000..066c67bd8
--- /dev/null
+++ b/tests/specs/task/bin_pkg_with_scope_auto/bin_none.out
@@ -0,0 +1,12 @@
+Download http://localhost:4260/@denotest/bin
+[UNORDERED_START]
+Download http://localhost:4260/@denotest/bin/0.5.0.tgz
+Download http://localhost:4260/@denotest/bin/1.0.0.tgz
+[UNORDERED_END]
+Task bin bin hi && cli-esm testing this out && npx cli-cjs test "extra"
+hi
+testing
+this
+out
+test
+extra
diff --git a/tests/specs/task/bin_pkg_with_scope_auto/deno.json b/tests/specs/task/bin_pkg_with_scope_auto/deno.json
new file mode 100644
index 000000000..fbd70ec48
--- /dev/null
+++ b/tests/specs/task/bin_pkg_with_scope_auto/deno.json
@@ -0,0 +1,3 @@
+{
+ "nodeModulesDir": "auto"
+}
diff --git a/tests/specs/task/bin_pkg_with_scope_auto/package.json b/tests/specs/task/bin_pkg_with_scope_auto/package.json
new file mode 100644
index 000000000..2ee4c2bbb
--- /dev/null
+++ b/tests/specs/task/bin_pkg_with_scope_auto/package.json
@@ -0,0 +1,9 @@
+{
+ "scripts": {
+ "bin": "bin hi && cli-esm testing this out && npx cli-cjs test"
+ },
+ "dependencies": {
+ "@denotest/bin": "0.5",
+ "other": "npm:@denotest/bin@1.0"
+ }
+}
diff --git a/tests/specs/task/bin_pkg_with_scope_none/__test__.jsonc b/tests/specs/task/bin_pkg_with_scope_none/__test__.jsonc
new file mode 100644
index 000000000..9f88b275f
--- /dev/null
+++ b/tests/specs/task/bin_pkg_with_scope_none/__test__.jsonc
@@ -0,0 +1,5 @@
+{
+ "tempDir": true,
+ "args": "task bin extra",
+ "output": "bin_none.out"
+}
diff --git a/tests/specs/task/bin_pkg_with_scope_none/bin_none.out b/tests/specs/task/bin_pkg_with_scope_none/bin_none.out
new file mode 100644
index 000000000..066c67bd8
--- /dev/null
+++ b/tests/specs/task/bin_pkg_with_scope_none/bin_none.out
@@ -0,0 +1,12 @@
+Download http://localhost:4260/@denotest/bin
+[UNORDERED_START]
+Download http://localhost:4260/@denotest/bin/0.5.0.tgz
+Download http://localhost:4260/@denotest/bin/1.0.0.tgz
+[UNORDERED_END]
+Task bin bin hi && cli-esm testing this out && npx cli-cjs test "extra"
+hi
+testing
+this
+out
+test
+extra
diff --git a/tests/specs/task/bin_pkg_with_scope_none/deno.json b/tests/specs/task/bin_pkg_with_scope_none/deno.json
new file mode 100644
index 000000000..38af4024b
--- /dev/null
+++ b/tests/specs/task/bin_pkg_with_scope_none/deno.json
@@ -0,0 +1,3 @@
+{
+ "nodeModulesDir": "none"
+}
diff --git a/tests/specs/task/bin_pkg_with_scope_none/package.json b/tests/specs/task/bin_pkg_with_scope_none/package.json
new file mode 100644
index 000000000..2ee4c2bbb
--- /dev/null
+++ b/tests/specs/task/bin_pkg_with_scope_none/package.json
@@ -0,0 +1,9 @@
+{
+ "scripts": {
+ "bin": "bin hi && cli-esm testing this out && npx cli-cjs test"
+ },
+ "dependencies": {
+ "@denotest/bin": "0.5",
+ "other": "npm:@denotest/bin@1.0"
+ }
+}