mirror of
https://github.com/denoland/deno.git
synced 2025-12-23 08:48:24 +00:00
fix(x): fix shim script when use custom alias name, re-enable alias tests (#31653)
This commit is contained in:
parent
892bc94afe
commit
8a00009a83
6 changed files with 98 additions and 20 deletions
|
|
@ -427,6 +427,7 @@ pub enum DenoXShimName {
|
|||
#[default]
|
||||
Dx,
|
||||
Denox,
|
||||
Dnx,
|
||||
Other(String),
|
||||
}
|
||||
|
||||
|
|
@ -435,6 +436,7 @@ impl DenoXShimName {
|
|||
match self {
|
||||
Self::Dx => "dx",
|
||||
Self::Denox => "denox",
|
||||
Self::Dnx => "dnx",
|
||||
Self::Other(name) => name,
|
||||
}
|
||||
}
|
||||
|
|
@ -1628,7 +1630,8 @@ pub fn flags_from_vec_with_initial_cwd(
|
|||
) -> clap::error::Result<Flags> {
|
||||
let args = if !args.is_empty()
|
||||
&& (args[0].as_encoded_bytes().ends_with(b"dx")
|
||||
|| args[0].as_encoded_bytes().ends_with(b"denox"))
|
||||
|| args[0].as_encoded_bytes().ends_with(b"denox")
|
||||
|| args[0].as_encoded_bytes().ends_with(b"dnx"))
|
||||
{
|
||||
let mut new_args = Vec::with_capacity(args.len() + 1);
|
||||
new_args.push(args[0].clone());
|
||||
|
|
@ -3637,6 +3640,7 @@ fn deno_x_shim_name_parser(value: &str) -> Result<DenoXShimName, String> {
|
|||
match value {
|
||||
"dx" => Ok(DenoXShimName::Dx),
|
||||
"denox" => Ok(DenoXShimName::Denox),
|
||||
"dnx" => Ok(DenoXShimName::Dnx),
|
||||
_ => Ok(DenoXShimName::Other(value.to_string())),
|
||||
}
|
||||
}
|
||||
|
|
@ -3665,7 +3669,6 @@ fn x_subcommand() -> Command {
|
|||
.long("install-alias")
|
||||
.num_args(0..=1)
|
||||
.default_missing_value("dx")
|
||||
.require_equals(true)
|
||||
.value_parser(deno_x_shim_name_parser)
|
||||
.action(ArgAction::Set)
|
||||
.conflicts_with("script_arg"),
|
||||
|
|
|
|||
|
|
@ -242,7 +242,7 @@ fn write_shim(
|
|||
&out_path,
|
||||
r##"#!/bin/sh
|
||||
SCRIPT_DIR="$(dirname -- "$(readlink -f -- "$0")")"
|
||||
exec "$SCRIPT_DIR/deno" x --default-allow-all "$@"
|
||||
exec "$SCRIPT_DIR/deno" x "$@"
|
||||
"##
|
||||
.as_bytes(),
|
||||
)?;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
// Copyright 2018-2025 the Deno authors. MIT license.
|
||||
|
||||
use std::borrow::Cow;
|
||||
use std::cell::RefCell;
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::HashMap;
|
||||
|
|
@ -281,7 +282,12 @@ fn run_test(
|
|||
let diagnostic_logger = Rc::new(RefCell::new(Vec::<u8>::new()));
|
||||
let result = TestResult::from_maybe_panic_or_result(AssertUnwindSafe(|| {
|
||||
let metadata = deserialize_value(metadata_value);
|
||||
if metadata.ignore || !should_run(metadata.if_cond.as_deref()) {
|
||||
let substs = variant_substitutions(&BTreeMap::new(), &metadata.variants);
|
||||
let if_cond = metadata
|
||||
.if_cond
|
||||
.as_deref()
|
||||
.map(|s| apply_substs(s, &substs));
|
||||
if metadata.ignore || !should_run(if_cond.as_deref()) {
|
||||
TestResult::Ignored
|
||||
} else if let Some(repeat) = metadata.repeat {
|
||||
for _ in 0..repeat {
|
||||
|
|
@ -500,11 +506,8 @@ fn run_step(
|
|||
if substs.is_empty() {
|
||||
command.args(text)
|
||||
} else {
|
||||
let mut text = text.clone();
|
||||
for (from, to) in &substs {
|
||||
text = text.replace(from, to);
|
||||
}
|
||||
command.args(text)
|
||||
let text = apply_substs(text, &substs);
|
||||
command.args(text.as_ref())
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
@ -513,7 +516,14 @@ fn run_step(
|
|||
None => command,
|
||||
};
|
||||
let command = match &step.command_name {
|
||||
Some(command_name) => command.name(command_name),
|
||||
Some(command_name) => {
|
||||
if substs.is_empty() {
|
||||
command.name(command_name)
|
||||
} else {
|
||||
let command_name = apply_substs(command_name, &substs);
|
||||
command.name(command_name.as_ref())
|
||||
}
|
||||
}
|
||||
None => command,
|
||||
};
|
||||
let command = match *NO_CAPTURE {
|
||||
|
|
@ -693,3 +703,18 @@ fn substitute_variants_into_envs(
|
|||
envs.remove(&key);
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_substs<'a>(
|
||||
text: &'a str,
|
||||
substs: &'_ [(String, String)],
|
||||
) -> Cow<'a, str> {
|
||||
if substs.is_empty() {
|
||||
Cow::Borrowed(text)
|
||||
} else {
|
||||
let mut text = Cow::Borrowed(text);
|
||||
for (from, to) in substs {
|
||||
text = text.replace(from, to).into();
|
||||
}
|
||||
text
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,14 +1,57 @@
|
|||
{
|
||||
"tempDir": true,
|
||||
"ignore": true,
|
||||
"steps": [
|
||||
{
|
||||
"args": "x --install-alias",
|
||||
"output": ""
|
||||
"tests": {
|
||||
"dx": {
|
||||
"if": "${IF}",
|
||||
"steps": [
|
||||
{
|
||||
"args": "x --install-alias dx",
|
||||
"output": ""
|
||||
},
|
||||
{
|
||||
"commandName": "dx${COMMAND_SUFFIX}",
|
||||
"args": "",
|
||||
"output": "alias.out"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"args": "task --eval \"dx\"",
|
||||
"output": "alias.out"
|
||||
"dnx": {
|
||||
"if": "${IF}",
|
||||
"steps": [
|
||||
{
|
||||
"args": "x --install-alias dnx",
|
||||
"output": ""
|
||||
},
|
||||
{
|
||||
"commandName": "dnx${COMMAND_SUFFIX}",
|
||||
"args": "",
|
||||
"output": "alias.out"
|
||||
}
|
||||
]
|
||||
},
|
||||
"other": {
|
||||
"if": "${IF}",
|
||||
"steps": [
|
||||
{
|
||||
"args": "x --install-alias deno-x-shim",
|
||||
"output": ""
|
||||
},
|
||||
{
|
||||
"commandName": "deno-x-shim${COMMAND_SUFFIX}",
|
||||
"args": "",
|
||||
"output": "alias.out"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"variants": {
|
||||
"windows": {
|
||||
"IF": "windows",
|
||||
"COMMAND_SUFFIX": ".cmd"
|
||||
},
|
||||
"unix": {
|
||||
"IF": "unix",
|
||||
"COMMAND_SUFFIX": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,2 +1 @@
|
|||
Task "dx"
|
||||
No local commands found
|
||||
|
|
|
|||
|
|
@ -891,6 +891,14 @@ impl TestCommandBuilder {
|
|||
tsgo_prebuilt_path().to_string(),
|
||||
);
|
||||
}
|
||||
if !envs.contains_key("PATH") {
|
||||
let path = std::env::var_os("PATH").unwrap_or_default();
|
||||
let path = std::env::split_paths(&path);
|
||||
let additional = deno_exe_path().parent().to_path_buf();
|
||||
let path =
|
||||
std::env::join_paths(std::iter::once(additional).chain(path)).unwrap();
|
||||
envs.insert("PATH".to_string(), path.to_string_lossy().to_string());
|
||||
}
|
||||
for key in &self.envs_remove {
|
||||
envs.remove(key);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue