mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 04:52:26 -05:00
Compare commits
3 commits
0b5cb3d009
...
95e32c3c66
Author | SHA1 | Date | |
---|---|---|---|
|
95e32c3c66 | ||
|
0d3d4f5466 | ||
|
7d6e62c073 |
9 changed files with 82 additions and 10 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2421,8 +2421,10 @@ dependencies = [
|
||||||
"async-trait",
|
"async-trait",
|
||||||
"deno_core",
|
"deno_core",
|
||||||
"deno_error",
|
"deno_error",
|
||||||
|
"deno_tls",
|
||||||
"http-body-util",
|
"http-body-util",
|
||||||
"hyper 1.4.1",
|
"hyper 1.4.1",
|
||||||
|
"hyper-rustls",
|
||||||
"hyper-util",
|
"hyper-util",
|
||||||
"log",
|
"log",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
|
|
|
@ -115,10 +115,16 @@ exec deno {} "$@"
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_installer_root() -> Result<PathBuf, io::Error> {
|
fn get_installer_root() -> Result<PathBuf, AnyError> {
|
||||||
if let Ok(env_dir) = env::var("DENO_INSTALL_ROOT") {
|
if let Some(env_dir) = env::var_os("DENO_INSTALL_ROOT") {
|
||||||
if !env_dir.is_empty() {
|
if !env_dir.is_empty() {
|
||||||
return canonicalize_path_maybe_not_exists(&PathBuf::from(env_dir));
|
let env_dir = PathBuf::from(env_dir);
|
||||||
|
return canonicalize_path_maybe_not_exists(&env_dir).with_context(|| {
|
||||||
|
format!(
|
||||||
|
"Canonicalizing DENO_INSTALL_ROOT ('{}').",
|
||||||
|
env_dir.display()
|
||||||
|
)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Note: on Windows, the $HOME environment variable may be set by users or by
|
// Note: on Windows, the $HOME environment variable may be set by users or by
|
||||||
|
@ -587,11 +593,22 @@ async fn resolve_shim_data(
|
||||||
let copy_path = get_hidden_file_with_ext(&file_path, "deno.json");
|
let copy_path = get_hidden_file_with_ext(&file_path, "deno.json");
|
||||||
executable_args.push("--config".to_string());
|
executable_args.push("--config".to_string());
|
||||||
executable_args.push(copy_path.to_str().unwrap().to_string());
|
executable_args.push(copy_path.to_str().unwrap().to_string());
|
||||||
extra_files.push((
|
let mut config_text = fs::read_to_string(config_path)
|
||||||
copy_path,
|
.with_context(|| format!("error reading {config_path}"))?;
|
||||||
fs::read_to_string(config_path)
|
// always remove the import map field because when someone specifies `--import-map` we
|
||||||
.with_context(|| format!("error reading {config_path}"))?,
|
// don't want that file to be attempted to be loaded and when they don't specify that
|
||||||
));
|
// (which is just something we haven't implemented yet)
|
||||||
|
if let Some(new_text) = remove_import_map_field_from_text(&config_text) {
|
||||||
|
if flags.import_map_path.is_none() {
|
||||||
|
log::warn!(
|
||||||
|
"{} \"importMap\" field in the specified config file we be ignored. Use the --import-map flag instead.",
|
||||||
|
crate::colors::yellow("Warning"),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
config_text = new_text;
|
||||||
|
}
|
||||||
|
|
||||||
|
extra_files.push((copy_path, config_text));
|
||||||
} else {
|
} else {
|
||||||
executable_args.push("--no-config".to_string());
|
executable_args.push("--no-config".to_string());
|
||||||
}
|
}
|
||||||
|
@ -631,6 +648,16 @@ async fn resolve_shim_data(
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn remove_import_map_field_from_text(config_text: &str) -> Option<String> {
|
||||||
|
let value =
|
||||||
|
jsonc_parser::cst::CstRootNode::parse(config_text, &Default::default())
|
||||||
|
.ok()?;
|
||||||
|
let root_value = value.object_value()?;
|
||||||
|
let import_map_value = root_value.get("importMap")?;
|
||||||
|
import_map_value.remove();
|
||||||
|
Some(value.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
fn get_hidden_file_with_ext(file_path: &Path, ext: &str) -> PathBuf {
|
fn get_hidden_file_with_ext(file_path: &Path, ext: &str) -> PathBuf {
|
||||||
// use a dot file to prevent the file from showing up in some
|
// use a dot file to prevent the file from showing up in some
|
||||||
// users shell auto-complete since this directory is on the PATH
|
// users shell auto-complete since this directory is on the PATH
|
||||||
|
@ -1585,4 +1612,17 @@ mod tests {
|
||||||
assert!(!file_path.exists());
|
assert!(!file_path.exists());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_remove_import_map_field_from_text() {
|
||||||
|
assert_eq!(
|
||||||
|
remove_import_map_field_from_text(
|
||||||
|
r#"{
|
||||||
|
"importMap": "./value.json"
|
||||||
|
}"#,
|
||||||
|
)
|
||||||
|
.unwrap(),
|
||||||
|
"{}"
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,8 +17,10 @@ path = "lib.rs"
|
||||||
async-trait.workspace = true
|
async-trait.workspace = true
|
||||||
deno_core.workspace = true
|
deno_core.workspace = true
|
||||||
deno_error.workspace = true
|
deno_error.workspace = true
|
||||||
|
deno_tls.workspace = true
|
||||||
http-body-util.workspace = true
|
http-body-util.workspace = true
|
||||||
hyper.workspace = true
|
hyper.workspace = true
|
||||||
|
hyper-rustls.workspace = true
|
||||||
hyper-util.workspace = true
|
hyper-util.workspace = true
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
once_cell.workspace = true
|
once_cell.workspace = true
|
||||||
|
|
|
@ -477,10 +477,14 @@ mod hyper_client {
|
||||||
use std::task::Poll;
|
use std::task::Poll;
|
||||||
use std::task::{self};
|
use std::task::{self};
|
||||||
|
|
||||||
|
use deno_tls::create_client_config;
|
||||||
|
use deno_tls::SocketUse;
|
||||||
|
use deno_tls::TlsKeys;
|
||||||
use http_body_util::BodyExt;
|
use http_body_util::BodyExt;
|
||||||
use http_body_util::Full;
|
use http_body_util::Full;
|
||||||
use hyper::body::Body as HttpBody;
|
use hyper::body::Body as HttpBody;
|
||||||
use hyper::body::Frame;
|
use hyper::body::Frame;
|
||||||
|
use hyper_rustls::HttpsConnector;
|
||||||
use hyper_util::client::legacy::connect::HttpConnector;
|
use hyper_util::client::legacy::connect::HttpConnector;
|
||||||
use hyper_util::client::legacy::Client;
|
use hyper_util::client::legacy::Client;
|
||||||
use opentelemetry_http::Bytes;
|
use opentelemetry_http::Bytes;
|
||||||
|
@ -494,13 +498,23 @@ mod hyper_client {
|
||||||
// same as opentelemetry_http::HyperClient except it uses OtelSharedRuntime
|
// same as opentelemetry_http::HyperClient except it uses OtelSharedRuntime
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct HyperClient {
|
pub struct HyperClient {
|
||||||
inner: Client<HttpConnector, Body>,
|
inner: Client<HttpsConnector<HttpConnector>, Body>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HyperClient {
|
impl HyperClient {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
|
let tls_config = create_client_config(
|
||||||
|
None,
|
||||||
|
vec![],
|
||||||
|
None,
|
||||||
|
TlsKeys::Null,
|
||||||
|
SocketUse::Http,
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
let http_connector = HttpConnector::new();
|
||||||
|
let connector = HttpsConnector::from((http_connector, tls_config));
|
||||||
Self {
|
Self {
|
||||||
inner: Client::builder(OtelSharedRuntime).build(HttpConnector::new()),
|
inner: Client::builder(OtelSharedRuntime).build(connector),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
{
|
||||||
|
"tempDir": true,
|
||||||
|
"args": "install -g --root ./folder --config deno.json main.ts --name my-cli",
|
||||||
|
"output": "install.out"
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"importMap": "./import_map.json"
|
||||||
|
}
|
|
@ -0,0 +1,2 @@
|
||||||
|
{
|
||||||
|
}
|
|
@ -0,0 +1,3 @@
|
||||||
|
Warning "importMap" field in the specified config file we be ignored. Use the --import-map flag instead.
|
||||||
|
✅ Successfully installed my-cli
|
||||||
|
[WILDCARD]
|
|
@ -0,0 +1 @@
|
||||||
|
console.log(1);
|
Loading…
Add table
Reference in a new issue