mirror of
https://github.com/denoland/deno.git
synced 2024-11-28 16:20:57 -05:00
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.
This commit is contained in:
parent
7c59402325
commit
b8ed6f8221
11 changed files with 93 additions and 21 deletions
|
@ -1,13 +1,13 @@
|
||||||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||||
|
|
||||||
use crate::args::CliOptions;
|
use std::borrow::Cow;
|
||||||
use crate::args::Flags;
|
use std::collections::HashMap;
|
||||||
use crate::args::TaskFlags;
|
use std::collections::HashSet;
|
||||||
use crate::colors;
|
use std::path::Path;
|
||||||
use crate::factory::CliFactory;
|
use std::path::PathBuf;
|
||||||
use crate::npm::CliNpmResolver;
|
use std::rc::Rc;
|
||||||
use crate::task_runner;
|
use std::sync::Arc;
|
||||||
use crate::util::fs::canonicalize_path;
|
|
||||||
use deno_config::deno_json::Task;
|
use deno_config::deno_json::Task;
|
||||||
use deno_config::workspace::TaskOrScript;
|
use deno_config::workspace::TaskOrScript;
|
||||||
use deno_config::workspace::WorkspaceDirectory;
|
use deno_config::workspace::WorkspaceDirectory;
|
||||||
|
@ -18,13 +18,15 @@ use deno_core::anyhow::Context;
|
||||||
use deno_core::error::AnyError;
|
use deno_core::error::AnyError;
|
||||||
use deno_core::normalize_path;
|
use deno_core::normalize_path;
|
||||||
use deno_task_shell::ShellCommand;
|
use deno_task_shell::ShellCommand;
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::collections::HashMap;
|
use crate::args::CliOptions;
|
||||||
use std::collections::HashSet;
|
use crate::args::Flags;
|
||||||
use std::path::Path;
|
use crate::args::TaskFlags;
|
||||||
use std::path::PathBuf;
|
use crate::colors;
|
||||||
use std::rc::Rc;
|
use crate::factory::CliFactory;
|
||||||
use std::sync::Arc;
|
use crate::npm::CliNpmResolver;
|
||||||
|
use crate::task_runner;
|
||||||
|
use crate::util::fs::canonicalize_path;
|
||||||
|
|
||||||
pub async fn execute_script(
|
pub async fn execute_script(
|
||||||
flags: Arc<Flags>,
|
flags: Arc<Flags>,
|
||||||
|
@ -106,13 +108,10 @@ See https://docs.deno.com/go/config"#
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
TaskOrScript::Script(scripts, _script) => {
|
TaskOrScript::Script(scripts, _script) => {
|
||||||
// ensure the npm packages are installed if using a node_modules
|
// ensure the npm packages are installed if using a managed resolver
|
||||||
// directory and managed resolver
|
|
||||||
if cli_options.has_node_modules_dir() {
|
|
||||||
if let Some(npm_resolver) = npm_resolver.as_managed() {
|
if let Some(npm_resolver) = npm_resolver.as_managed() {
|
||||||
npm_resolver.ensure_top_level_package_json_install().await?;
|
npm_resolver.ensure_top_level_package_json_install().await?;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let cwd = match task_flags.cwd {
|
let cwd = match task_flags.cwd {
|
||||||
Some(path) => canonicalize_path(&PathBuf::from(path))?,
|
Some(path) => canonicalize_path(&PathBuf::from(path))?,
|
||||||
|
|
|
@ -367,6 +367,7 @@ impl<TEnv: NodeResolverEnv> NodeResolver<TEnv> {
|
||||||
pkg_json_path,
|
pkg_json_path,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
let name = name.split("/").last().unwrap();
|
||||||
vec![name.to_string()]
|
vec![name.to_string()]
|
||||||
}
|
}
|
||||||
Some(Value::Object(o)) => {
|
Some(Value::Object(o)) => {
|
||||||
|
|
5
tests/specs/task/bin_pkg_with_scope_auto/__test__.jsonc
Normal file
5
tests/specs/task/bin_pkg_with_scope_auto/__test__.jsonc
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"tempDir": true,
|
||||||
|
"args": "task bin extra",
|
||||||
|
"output": "bin_auto.out"
|
||||||
|
}
|
14
tests/specs/task/bin_pkg_with_scope_auto/bin_auto.out
Normal file
14
tests/specs/task/bin_pkg_with_scope_auto/bin_auto.out
Normal file
|
@ -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
|
12
tests/specs/task/bin_pkg_with_scope_auto/bin_none.out
Normal file
12
tests/specs/task/bin_pkg_with_scope_auto/bin_none.out
Normal file
|
@ -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
|
3
tests/specs/task/bin_pkg_with_scope_auto/deno.json
Normal file
3
tests/specs/task/bin_pkg_with_scope_auto/deno.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"nodeModulesDir": "auto"
|
||||||
|
}
|
9
tests/specs/task/bin_pkg_with_scope_auto/package.json
Normal file
9
tests/specs/task/bin_pkg_with_scope_auto/package.json
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
5
tests/specs/task/bin_pkg_with_scope_none/__test__.jsonc
Normal file
5
tests/specs/task/bin_pkg_with_scope_none/__test__.jsonc
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"tempDir": true,
|
||||||
|
"args": "task bin extra",
|
||||||
|
"output": "bin_none.out"
|
||||||
|
}
|
12
tests/specs/task/bin_pkg_with_scope_none/bin_none.out
Normal file
12
tests/specs/task/bin_pkg_with_scope_none/bin_none.out
Normal file
|
@ -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
|
3
tests/specs/task/bin_pkg_with_scope_none/deno.json
Normal file
3
tests/specs/task/bin_pkg_with_scope_none/deno.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"nodeModulesDir": "none"
|
||||||
|
}
|
9
tests/specs/task/bin_pkg_with_scope_none/package.json
Normal file
9
tests/specs/task/bin_pkg_with_scope_none/package.json
Normal file
|
@ -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"
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue