Skip to content

Commit

Permalink
Merge branch 'main' into watch-file-fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
nayeemrmn committed Dec 22, 2022
2 parents 08d454a + e58cdbc commit 9d0bed2
Show file tree
Hide file tree
Showing 102 changed files with 2,428 additions and 968 deletions.
122 changes: 45 additions & 77 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Expand Up @@ -56,10 +56,10 @@ deno_broadcast_channel = { version = "0.76.0", path = "./ext/broadcast_channel"
deno_cache = { version = "0.14.0", path = "./ext/cache" }
deno_console = { version = "0.82.0", path = "./ext/console" }
deno_crypto = { version = "0.96.0", path = "./ext/crypto" }
deno_fetch = { version = "0.105.0", path = "./ext/fetch" }
deno_fetch = { version = "0.106.0", path = "./ext/fetch" }
deno_ffi = { version = "0.69.0", path = "./ext/ffi" }
deno_flash = { version = "0.18.0", path = "./ext/flash" }
deno_http = { version = "0.76.0", path = "./ext/http" }
deno_http = { version = "0.77.0", path = "./ext/http" }
deno_net = { version = "0.74.0", path = "./ext/net" }
deno_node = { version = "0.19.0", path = "./ext/node" }
deno_tls = { version = "0.69.0", path = "./ext/tls" }
Expand Down
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Expand Up @@ -59,7 +59,7 @@ chrono = { version = "=0.4.22", default-features = false, features = ["clock"] }
clap = "=3.1.12"
clap_complete = "=3.1.2"
clap_complete_fig = "=3.1.5"
console_static_text = "=0.3.3"
console_static_text = "=0.3.4"
data-url.workspace = true
dissimilar = "=1.0.4"
dprint-plugin-json = "=0.17.0"
Expand Down
1 change: 0 additions & 1 deletion cli/args/config_file.rs
Expand Up @@ -130,7 +130,6 @@ pub const IGNORED_COMPILER_OPTIONS: &[&str] = &[
"noEmit",
"noEmitHelpers",
"noEmitOnError",
"noErrorTruncation",
"noLib",
"noResolve",
"out",
Expand Down
9 changes: 8 additions & 1 deletion cli/args/lockfile.rs
Expand Up @@ -19,6 +19,8 @@ use crate::tools::fmt::format_json;
use crate::util;
use crate::Flags;

use super::DenoSubcommand;

#[derive(Debug)]
pub struct LockfileError(String);

Expand Down Expand Up @@ -96,7 +98,12 @@ impl Lockfile {
flags: &Flags,
maybe_config_file: Option<&ConfigFile>,
) -> Result<Option<Lockfile>, AnyError> {
if flags.no_lock {
if flags.no_lock
|| matches!(
flags.subcommand,
DenoSubcommand::Install(_) | DenoSubcommand::Uninstall(_)
)
{
return Ok(None);
}

Expand Down
2 changes: 1 addition & 1 deletion cli/deno_std.rs
Expand Up @@ -5,7 +5,7 @@ use once_cell::sync::Lazy;

// WARNING: Ensure this is the only deno_std version reference as this
// is automatically updated by the version bump workflow.
static CURRENT_STD_URL_STR: &str = "https://deno.land/std@0.168.0/";
static CURRENT_STD_URL_STR: &str = "https://deno.land/std@0.170.0/";

pub static CURRENT_STD_URL: Lazy<Url> =
Lazy::new(|| Url::parse(CURRENT_STD_URL_STR).unwrap());
49 changes: 44 additions & 5 deletions cli/file_fetcher.rs
@@ -1,15 +1,17 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.

use crate::args::CacheSetting;
use crate::auth_tokens::AuthToken;
use crate::auth_tokens::AuthTokens;
use crate::cache::HttpCache;
use crate::colors;
use crate::http_util;
use crate::http_util::resolve_redirect_from_response;
use crate::http_util::CacheSemantics;
use crate::http_util::FetchOnceArgs;
use crate::http_util::FetchOnceResult;
use crate::http_util::HeadersMap;
use crate::http_util::HttpClient;
use crate::util::progress_bar::ProgressBar;
use crate::util::progress_bar::UpdateGuard;
use crate::util::text_encoding;

use data_url::DataUrl;
Expand All @@ -21,6 +23,7 @@ use deno_core::error::AnyError;
use deno_core::futures;
use deno_core::futures::future::FutureExt;
use deno_core::parking_lot::Mutex;
use deno_core::url::Url;
use deno_core::ModuleSpecifier;
use deno_runtime::deno_fetch::reqwest::header::HeaderValue;
use deno_runtime::deno_fetch::reqwest::header::ACCEPT;
Expand Down Expand Up @@ -470,6 +473,7 @@ impl FileFetcher {
maybe_accept: maybe_accept.clone(),
maybe_etag,
maybe_auth_token,
maybe_progress_guard: maybe_progress_guard.as_ref(),
},
)
.await?
Expand Down Expand Up @@ -637,14 +641,30 @@ impl FileFetcher {
}
}

#[derive(Debug, Eq, PartialEq)]
enum FetchOnceResult {
Code(Vec<u8>, HeadersMap),
NotModified,
Redirect(Url, HeadersMap),
}

#[derive(Debug)]
struct FetchOnceArgs<'a> {
pub url: Url,
pub maybe_accept: Option<String>,
pub maybe_etag: Option<String>,
pub maybe_auth_token: Option<AuthToken>,
pub maybe_progress_guard: Option<&'a UpdateGuard>,
}

/// Asynchronously fetches the given HTTP URL one pass only.
/// If no redirect is present and no error occurs,
/// yields Code(ResultPayload).
/// If redirect occurs, does not follow and
/// yields Redirect(url).
async fn fetch_once(
async fn fetch_once<'a>(
http_client: &HttpClient,
args: FetchOnceArgs,
args: FetchOnceArgs<'a>,
) -> Result<FetchOnceResult, AnyError> {
let mut request = http_client.get_no_redirect(args.url.clone());

Expand Down Expand Up @@ -710,7 +730,11 @@ async fn fetch_once(
return Err(err);
}

let body = response.bytes().await?.to_vec();
let body = http_util::get_response_body_with_progress(
response,
args.maybe_progress_guard,
)
.await?;

Ok(FetchOnceResult::Code(body, result_headers))
}
Expand Down Expand Up @@ -1760,6 +1784,7 @@ mod tests {
maybe_accept: None,
maybe_etag: None,
maybe_auth_token: None,
maybe_progress_guard: None,
},
)
.await;
Expand Down Expand Up @@ -1787,6 +1812,7 @@ mod tests {
maybe_accept: None,
maybe_etag: None,
maybe_auth_token: None,
maybe_progress_guard: None,
},
)
.await;
Expand Down Expand Up @@ -1815,6 +1841,7 @@ mod tests {
maybe_accept: None,
maybe_etag: None,
maybe_auth_token: None,
maybe_progress_guard: None,
},
)
.await;
Expand All @@ -1837,6 +1864,7 @@ mod tests {
maybe_accept: None,
maybe_etag: Some("33a64df551425fcc55e".to_string()),
maybe_auth_token: None,
maybe_progress_guard: None,
},
)
.await;
Expand All @@ -1857,6 +1885,7 @@ mod tests {
maybe_accept: None,
maybe_etag: None,
maybe_auth_token: None,
maybe_progress_guard: None,
},
)
.await;
Expand Down Expand Up @@ -1887,6 +1916,7 @@ mod tests {
maybe_accept: Some("application/json".to_string()),
maybe_etag: None,
maybe_auth_token: None,
maybe_progress_guard: None,
},
)
.await;
Expand All @@ -1913,6 +1943,7 @@ mod tests {
maybe_accept: None,
maybe_etag: None,
maybe_auth_token: None,
maybe_progress_guard: None,
},
)
.await;
Expand Down Expand Up @@ -1953,6 +1984,7 @@ mod tests {
maybe_accept: None,
maybe_etag: None,
maybe_auth_token: None,
maybe_progress_guard: None,
},
)
.await;
Expand Down Expand Up @@ -1990,6 +2022,7 @@ mod tests {
maybe_accept: None,
maybe_etag: None,
maybe_auth_token: None,
maybe_progress_guard: None,
},
)
.await;
Expand Down Expand Up @@ -2025,6 +2058,7 @@ mod tests {
maybe_accept: None,
maybe_etag: None,
maybe_auth_token: None,
maybe_progress_guard: None,
},
)
.await;
Expand Down Expand Up @@ -2066,6 +2100,7 @@ mod tests {
maybe_accept: None,
maybe_etag: None,
maybe_auth_token: None,
maybe_progress_guard: None,
},
)
.await;
Expand Down Expand Up @@ -2110,6 +2145,7 @@ mod tests {
maybe_accept: None,
maybe_etag: None,
maybe_auth_token: None,
maybe_progress_guard: None,
},
)
.await;
Expand All @@ -2133,6 +2169,7 @@ mod tests {
maybe_accept: None,
maybe_etag: Some("33a64df551425fcc55e".to_string()),
maybe_auth_token: None,
maybe_progress_guard: None,
},
)
.await;
Expand Down Expand Up @@ -2170,6 +2207,7 @@ mod tests {
maybe_accept: None,
maybe_etag: None,
maybe_auth_token: None,
maybe_progress_guard: None,
},
)
.await;
Expand Down Expand Up @@ -2200,6 +2238,7 @@ mod tests {
maybe_accept: None,
maybe_etag: None,
maybe_auth_token: None,
maybe_progress_guard: None,
},
)
.await;
Expand Down
60 changes: 26 additions & 34 deletions cli/http_util.rs
@@ -1,5 +1,4 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.
use crate::auth_tokens::AuthToken;
use crate::util::progress_bar::UpdateGuard;
use crate::version::get_user_agent;

Expand Down Expand Up @@ -218,21 +217,6 @@ impl CacheSemantics {
}
}

#[derive(Debug, Eq, PartialEq)]
pub enum FetchOnceResult {
Code(Vec<u8>, HeadersMap),
NotModified,
Redirect(Url, HeadersMap),
}

#[derive(Debug)]
pub struct FetchOnceArgs {
pub url: Url,
pub maybe_accept: Option<String>,
pub maybe_etag: Option<String>,
pub maybe_auth_token: Option<AuthToken>,
}

#[derive(Debug, Clone)]
pub struct HttpClient(reqwest::Client);

Expand Down Expand Up @@ -312,24 +296,9 @@ impl HttpClient {
);
}

if let Some(progress_guard) = progress_guard {
if let Some(total_size) = response.content_length() {
progress_guard.set_total_size(total_size);
let mut current_size = 0;
let mut data = Vec::with_capacity(total_size as usize);
let mut stream = response.bytes_stream();
while let Some(item) = stream.next().await {
let bytes = item?;
current_size += bytes.len() as u64;
progress_guard.set_position(current_size);
data.extend(bytes.into_iter());
}
return Ok(Some(data));
}
}

let bytes = response.bytes().await?;
Ok(Some(bytes.into()))
get_response_body_with_progress(response, progress_guard)
.await
.map(Some)
}

async fn get_redirected_response<U: reqwest::IntoUrl>(
Expand Down Expand Up @@ -358,6 +327,29 @@ impl HttpClient {
}
}

pub async fn get_response_body_with_progress(
response: reqwest::Response,
progress_guard: Option<&UpdateGuard>,
) -> Result<Vec<u8>, AnyError> {
if let Some(progress_guard) = progress_guard {
if let Some(total_size) = response.content_length() {
progress_guard.set_total_size(total_size);
let mut current_size = 0;
let mut data = Vec::with_capacity(total_size as usize);
let mut stream = response.bytes_stream();
while let Some(item) = stream.next().await {
let bytes = item?;
current_size += bytes.len() as u64;
progress_guard.set_position(current_size);
data.extend(bytes.into_iter());
}
return Ok(data);
}
}
let bytes = response.bytes().await?;
Ok(bytes.into())
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion cli/lsp/completions.rs
Expand Up @@ -526,7 +526,7 @@ mod tests {
documents.open(
specifier.clone(),
*version,
language_id.clone(),
*language_id,
(*source).into(),
);
}
Expand Down
2 changes: 1 addition & 1 deletion cli/lsp/diagnostics.rs
Expand Up @@ -1010,7 +1010,7 @@ mod tests {
documents.open(
specifier.clone(),
*version,
language_id.clone(),
*language_id,
(*source).into(),
);
}
Expand Down

0 comments on commit 9d0bed2

Please sign in to comment.