mirror of
https://github.com/denoland/deno.git
synced 2025-01-21 04:52:26 -05:00
refactor: extract out FileFetcher
to deno_cache_dir
(#27263)
This commit is contained in:
parent
358bf566c2
commit
95928c46eb
42 changed files with 1018 additions and 2152 deletions
34
Cargo.lock
generated
34
Cargo.lock
generated
|
@ -596,9 +596,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "boxed_error"
|
||||
version = "0.2.2"
|
||||
version = "0.2.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "69aae56aaf59d1994b902ed5c0c79024012bdc2426741def75a635999a030e7e"
|
||||
checksum = "17d4f95e880cfd28c4ca5a006cf7f6af52b4bcb7b5866f573b2faa126fb7affb"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"syn 2.0.87",
|
||||
|
@ -1193,9 +1193,9 @@ checksum = "7e962a19be5cfc3f3bf6dd8f61eb50107f356ad6270fbb3ed41476571db78be5"
|
|||
|
||||
[[package]]
|
||||
name = "data-url"
|
||||
version = "0.3.0"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41b319d1b62ffbd002e057f36bebd1f42b9f97927c9577461d855f3513c4289f"
|
||||
checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a"
|
||||
|
||||
[[package]]
|
||||
name = "debug-ignore"
|
||||
|
@ -1221,6 +1221,7 @@ dependencies = [
|
|||
"async-trait",
|
||||
"base64 0.21.7",
|
||||
"bincode",
|
||||
"boxed_error",
|
||||
"bytes",
|
||||
"cache_control",
|
||||
"chrono",
|
||||
|
@ -1237,6 +1238,7 @@ dependencies = [
|
|||
"deno_config",
|
||||
"deno_core",
|
||||
"deno_doc",
|
||||
"deno_error",
|
||||
"deno_graph",
|
||||
"deno_lint",
|
||||
"deno_lockfile",
|
||||
|
@ -1421,13 +1423,21 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_cache_dir"
|
||||
version = "0.14.0"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cca43605c8cbce6c6787e0daf227864487c07c2b31d438c0bf43d1b38da94b7f"
|
||||
checksum = "54df1c5177ace01d92b872584ab9af8290681bb150fd9b423c37a494ad5ddbdc"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"base32",
|
||||
"base64 0.21.7",
|
||||
"boxed_error",
|
||||
"cache_control",
|
||||
"chrono",
|
||||
"data-url",
|
||||
"deno_error",
|
||||
"deno_media_type",
|
||||
"deno_path_util",
|
||||
"http 1.1.0",
|
||||
"indexmap 2.3.0",
|
||||
"log",
|
||||
"once_cell",
|
||||
|
@ -1612,6 +1622,7 @@ dependencies = [
|
|||
"libc",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1857,9 +1868,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_media_type"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7fcf552fbdedbe81c89705349d7d2485c7051382b000dfddbdbf7fc25931cf83"
|
||||
checksum = "eaa135b8a9febc9a51c16258e294e268a1276750780d69e46edb31cced2826e4"
|
||||
dependencies = [
|
||||
"data-url",
|
||||
"serde",
|
||||
|
@ -2085,12 +2096,13 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_path_util"
|
||||
version = "0.2.1"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff25f6e08e7a0214bbacdd6f7195c7f1ebcd850c87a624e4ff06326b68b42d99"
|
||||
checksum = "b02c7d341e1b2cf089daff0f4fb2b4be8f3b5511b1d96040b3f7ed63a66c737b"
|
||||
dependencies = [
|
||||
"deno_error",
|
||||
"percent-encoding",
|
||||
"thiserror 1.0.64",
|
||||
"thiserror 2.0.3",
|
||||
"url",
|
||||
]
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ deno_config = { version = "=0.39.3", features = ["workspace", "sync"] }
|
|||
deno_lockfile = "=0.23.2"
|
||||
deno_media_type = { version = "0.2.0", features = ["module_specifier"] }
|
||||
deno_npm = "=0.26.0"
|
||||
deno_path_util = "=0.2.1"
|
||||
deno_path_util = "=0.2.2"
|
||||
deno_permissions = { version = "0.42.0", path = "./runtime/permissions" }
|
||||
deno_runtime = { version = "0.191.0", path = "./runtime" }
|
||||
deno_semver = "=0.6.1"
|
||||
|
@ -104,7 +104,7 @@ async-trait = "0.1.73"
|
|||
base32 = "=0.5.1"
|
||||
base64 = "0.21.7"
|
||||
bencher = "0.1"
|
||||
boxed_error = "0.2.2"
|
||||
boxed_error = "0.2.3"
|
||||
brotli = "6.0.0"
|
||||
bytes = "1.4.0"
|
||||
cache_control = "=0.2.0"
|
||||
|
@ -117,8 +117,9 @@ color-print = "0.3.5"
|
|||
console_static_text = "=0.8.1"
|
||||
dashmap = "5.5.3"
|
||||
data-encoding = "2.3.3"
|
||||
data-url = "=0.3.0"
|
||||
deno_cache_dir = "=0.14.0"
|
||||
data-url = "=0.3.1"
|
||||
deno_cache_dir = "=0.15.0"
|
||||
deno_error = "=0.5.2"
|
||||
deno_package_json = { version = "0.2.1", default-features = false }
|
||||
deno_unsync = "0.4.2"
|
||||
dlopen2 = "0.6.1"
|
||||
|
|
|
@ -73,6 +73,7 @@ deno_cache_dir.workspace = true
|
|||
deno_config.workspace = true
|
||||
deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] }
|
||||
deno_doc = { version = "=0.161.3", features = ["rust", "comrak"] }
|
||||
deno_error.workspace = true
|
||||
deno_graph = { version = "=0.86.3" }
|
||||
deno_lint = { version = "=0.68.2", features = ["docs"] }
|
||||
deno_lockfile.workspace = true
|
||||
|
@ -93,6 +94,7 @@ anstream = "0.6.14"
|
|||
async-trait.workspace = true
|
||||
base64.workspace = true
|
||||
bincode = "=1.3.3"
|
||||
boxed_error.workspace = true
|
||||
bytes.workspace = true
|
||||
cache_control.workspace = true
|
||||
chrono = { workspace = true, features = ["now"] }
|
||||
|
|
|
@ -4,21 +4,21 @@ use deno_core::error::AnyError;
|
|||
use deno_core::serde_json;
|
||||
use deno_core::url::Url;
|
||||
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::file_fetcher::TextDecodedFile;
|
||||
|
||||
pub async fn resolve_import_map_value_from_specifier(
|
||||
specifier: &Url,
|
||||
file_fetcher: &FileFetcher,
|
||||
file_fetcher: &CliFileFetcher,
|
||||
) -> Result<serde_json::Value, AnyError> {
|
||||
if specifier.scheme() == "data" {
|
||||
let data_url_text =
|
||||
deno_graph::source::RawDataUrl::parse(specifier)?.decode()?;
|
||||
Ok(serde_json::from_str(&data_url_text)?)
|
||||
} else {
|
||||
let file = file_fetcher
|
||||
.fetch_bypass_permissions(specifier)
|
||||
.await?
|
||||
.into_text_decoded()?;
|
||||
let file = TextDecodedFile::decode(
|
||||
file_fetcher.fetch_bypass_permissions(specifier).await?,
|
||||
)?;
|
||||
Ok(serde_json::from_str(&file.source)?)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ mod package_json;
|
|||
|
||||
use deno_ast::MediaType;
|
||||
use deno_ast::SourceMapOption;
|
||||
use deno_cache_dir::file_fetcher::CacheSetting;
|
||||
use deno_config::deno_json::NodeModulesDirMode;
|
||||
use deno_config::workspace::CreateResolverOptions;
|
||||
use deno_config::workspace::FolderConfigs;
|
||||
|
@ -27,7 +28,6 @@ use deno_npm::npm_rc::NpmRc;
|
|||
use deno_npm::npm_rc::ResolvedNpmRc;
|
||||
use deno_npm::resolution::ValidSerializedNpmResolutionSnapshot;
|
||||
use deno_npm::NpmSystemInfo;
|
||||
use deno_npm_cache::NpmCacheSetting;
|
||||
use deno_path_util::normalize_path;
|
||||
use deno_semver::npm::NpmPackageReqReference;
|
||||
use deno_telemetry::OtelConfig;
|
||||
|
@ -85,7 +85,7 @@ use thiserror::Error;
|
|||
|
||||
use crate::cache;
|
||||
use crate::cache::DenoDirProvider;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::util::fs::canonicalize_path_maybe_not_exists;
|
||||
use crate::version;
|
||||
|
||||
|
@ -217,52 +217,6 @@ pub fn ts_config_to_transpile_and_emit_options(
|
|||
))
|
||||
}
|
||||
|
||||
/// Indicates how cached source files should be handled.
|
||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||
pub enum CacheSetting {
|
||||
/// Only the cached files should be used. Any files not in the cache will
|
||||
/// error. This is the equivalent of `--cached-only` in the CLI.
|
||||
Only,
|
||||
/// No cached source files should be used, and all files should be reloaded.
|
||||
/// This is the equivalent of `--reload` in the CLI.
|
||||
ReloadAll,
|
||||
/// Only some cached resources should be used. This is the equivalent of
|
||||
/// `--reload=jsr:@std/http/file-server` or
|
||||
/// `--reload=jsr:@std/http/file-server,jsr:@std/assert/assert-equals`.
|
||||
ReloadSome(Vec<String>),
|
||||
/// The usability of a cached value is determined by analyzing the cached
|
||||
/// headers and other metadata associated with a cached response, reloading
|
||||
/// any cached "non-fresh" cached responses.
|
||||
RespectHeaders,
|
||||
/// The cached source files should be used for local modules. This is the
|
||||
/// default behavior of the CLI.
|
||||
Use,
|
||||
}
|
||||
|
||||
impl CacheSetting {
|
||||
pub fn as_npm_cache_setting(&self) -> NpmCacheSetting {
|
||||
match self {
|
||||
CacheSetting::Only => NpmCacheSetting::Only,
|
||||
CacheSetting::ReloadAll => NpmCacheSetting::ReloadAll,
|
||||
CacheSetting::ReloadSome(values) => {
|
||||
if values.iter().any(|v| v == "npm:") {
|
||||
NpmCacheSetting::ReloadAll
|
||||
} else {
|
||||
NpmCacheSetting::ReloadSome {
|
||||
npm_package_names: values
|
||||
.iter()
|
||||
.filter_map(|v| v.strip_prefix("npm:"))
|
||||
.map(|n| n.to_string())
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
CacheSetting::RespectHeaders => unreachable!(), // not supported
|
||||
CacheSetting::Use => NpmCacheSetting::Use,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WorkspaceBenchOptions {
|
||||
pub filter: Option<String>,
|
||||
pub json: bool,
|
||||
|
@ -1091,7 +1045,7 @@ impl CliOptions {
|
|||
|
||||
pub async fn create_workspace_resolver(
|
||||
&self,
|
||||
file_fetcher: &FileFetcher,
|
||||
file_fetcher: &CliFileFetcher,
|
||||
pkg_json_dep_resolution: PackageJsonDepResolution,
|
||||
) -> Result<WorkspaceResolver, AnyError> {
|
||||
let overrode_no_import_map: bool = self
|
||||
|
|
|
@ -1,369 +0,0 @@
|
|||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use base64::prelude::BASE64_STANDARD;
|
||||
use base64::Engine;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use log::debug;
|
||||
use log::error;
|
||||
use std::borrow::Cow;
|
||||
use std::fmt;
|
||||
use std::net::IpAddr;
|
||||
use std::net::Ipv4Addr;
|
||||
use std::net::Ipv6Addr;
|
||||
use std::net::SocketAddr;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum AuthTokenData {
|
||||
Bearer(String),
|
||||
Basic { username: String, password: String },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct AuthToken {
|
||||
host: AuthDomain,
|
||||
token: AuthTokenData,
|
||||
}
|
||||
|
||||
impl fmt::Display for AuthToken {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
match &self.token {
|
||||
AuthTokenData::Bearer(token) => write!(f, "Bearer {token}"),
|
||||
AuthTokenData::Basic { username, password } => {
|
||||
let credentials = format!("{username}:{password}");
|
||||
write!(f, "Basic {}", BASE64_STANDARD.encode(credentials))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A structure which contains bearer tokens that can be used when sending
|
||||
/// requests to websites, intended to authorize access to private resources
|
||||
/// such as remote modules.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct AuthTokens(Vec<AuthToken>);
|
||||
|
||||
/// An authorization domain, either an exact or suffix match.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum AuthDomain {
|
||||
Ip(IpAddr),
|
||||
IpPort(SocketAddr),
|
||||
/// Suffix match, no dot. May include a port.
|
||||
Suffix(Cow<'static, str>),
|
||||
}
|
||||
|
||||
impl<T: ToString> From<T> for AuthDomain {
|
||||
fn from(value: T) -> Self {
|
||||
let s = value.to_string().to_lowercase();
|
||||
if let Ok(ip) = SocketAddr::from_str(&s) {
|
||||
return AuthDomain::IpPort(ip);
|
||||
};
|
||||
if s.starts_with('[') && s.ends_with(']') {
|
||||
if let Ok(ip) = Ipv6Addr::from_str(&s[1..s.len() - 1]) {
|
||||
return AuthDomain::Ip(ip.into());
|
||||
}
|
||||
} else if let Ok(ip) = Ipv4Addr::from_str(&s) {
|
||||
return AuthDomain::Ip(ip.into());
|
||||
}
|
||||
if let Some(s) = s.strip_prefix('.') {
|
||||
AuthDomain::Suffix(Cow::Owned(s.to_owned()))
|
||||
} else {
|
||||
AuthDomain::Suffix(Cow::Owned(s))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AuthDomain {
|
||||
pub fn matches(&self, specifier: &ModuleSpecifier) -> bool {
|
||||
let Some(host) = specifier.host_str() else {
|
||||
return false;
|
||||
};
|
||||
match *self {
|
||||
Self::Ip(ip) => {
|
||||
let AuthDomain::Ip(parsed) = AuthDomain::from(host) else {
|
||||
return false;
|
||||
};
|
||||
ip == parsed && specifier.port().is_none()
|
||||
}
|
||||
Self::IpPort(ip) => {
|
||||
let AuthDomain::Ip(parsed) = AuthDomain::from(host) else {
|
||||
return false;
|
||||
};
|
||||
ip.ip() == parsed && specifier.port() == Some(ip.port())
|
||||
}
|
||||
Self::Suffix(ref suffix) => {
|
||||
let hostname = if let Some(port) = specifier.port() {
|
||||
Cow::Owned(format!("{}:{}", host, port))
|
||||
} else {
|
||||
Cow::Borrowed(host)
|
||||
};
|
||||
|
||||
if suffix.len() == hostname.len() {
|
||||
return suffix == &hostname;
|
||||
}
|
||||
|
||||
// If it's a suffix match, ensure a dot
|
||||
if hostname.ends_with(suffix.as_ref())
|
||||
&& hostname.ends_with(&format!(".{suffix}"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AuthTokens {
|
||||
/// Create a new set of tokens based on the provided string. It is intended
|
||||
/// that the string be the value of an environment variable and the string is
|
||||
/// parsed for token values. The string is expected to be a semi-colon
|
||||
/// separated string, where each value is `{token}@{hostname}`.
|
||||
pub fn new(maybe_tokens_str: Option<String>) -> Self {
|
||||
let mut tokens = Vec::new();
|
||||
if let Some(tokens_str) = maybe_tokens_str {
|
||||
for token_str in tokens_str.trim().split(';') {
|
||||
if token_str.contains('@') {
|
||||
let mut iter = token_str.rsplitn(2, '@');
|
||||
let host = AuthDomain::from(iter.next().unwrap());
|
||||
let token = iter.next().unwrap();
|
||||
if token.contains(':') {
|
||||
let mut iter = token.rsplitn(2, ':');
|
||||
let password = iter.next().unwrap().to_owned();
|
||||
let username = iter.next().unwrap().to_owned();
|
||||
tokens.push(AuthToken {
|
||||
host,
|
||||
token: AuthTokenData::Basic { username, password },
|
||||
});
|
||||
} else {
|
||||
tokens.push(AuthToken {
|
||||
host,
|
||||
token: AuthTokenData::Bearer(token.to_string()),
|
||||
});
|
||||
}
|
||||
} else {
|
||||
error!("Badly formed auth token discarded.");
|
||||
}
|
||||
}
|
||||
debug!("Parsed {} auth token(s).", tokens.len());
|
||||
}
|
||||
|
||||
Self(tokens)
|
||||
}
|
||||
|
||||
/// Attempt to match the provided specifier to the tokens in the set. The
|
||||
/// matching occurs from the right of the hostname plus port, irrespective of
|
||||
/// scheme. For example `https://www.deno.land:8080/` would match a token
|
||||
/// with a host value of `deno.land:8080` but not match `www.deno.land`. The
|
||||
/// matching is case insensitive.
|
||||
pub fn get(&self, specifier: &ModuleSpecifier) -> Option<AuthToken> {
|
||||
self.0.iter().find_map(|t| {
|
||||
if t.host.matches(specifier) {
|
||||
Some(t.clone())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use deno_core::resolve_url;
|
||||
|
||||
#[test]
|
||||
fn test_auth_token() {
|
||||
let auth_tokens = AuthTokens::new(Some("abc123@deno.land".to_string()));
|
||||
let fixture = resolve_url("https://deno.land/x/mod.ts").unwrap();
|
||||
assert_eq!(
|
||||
auth_tokens.get(&fixture).unwrap().to_string(),
|
||||
"Bearer abc123"
|
||||
);
|
||||
let fixture = resolve_url("https://www.deno.land/x/mod.ts").unwrap();
|
||||
assert_eq!(
|
||||
auth_tokens.get(&fixture).unwrap().to_string(),
|
||||
"Bearer abc123".to_string()
|
||||
);
|
||||
let fixture = resolve_url("http://127.0.0.1:8080/x/mod.ts").unwrap();
|
||||
assert_eq!(auth_tokens.get(&fixture), None);
|
||||
let fixture =
|
||||
resolve_url("https://deno.land.example.com/x/mod.ts").unwrap();
|
||||
assert_eq!(auth_tokens.get(&fixture), None);
|
||||
let fixture = resolve_url("https://deno.land:8080/x/mod.ts").unwrap();
|
||||
assert_eq!(auth_tokens.get(&fixture), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_auth_tokens_multiple() {
|
||||
let auth_tokens =
|
||||
AuthTokens::new(Some("abc123@deno.land;def456@example.com".to_string()));
|
||||
let fixture = resolve_url("https://deno.land/x/mod.ts").unwrap();
|
||||
assert_eq!(
|
||||
auth_tokens.get(&fixture).unwrap().to_string(),
|
||||
"Bearer abc123".to_string()
|
||||
);
|
||||
let fixture = resolve_url("http://example.com/a/file.ts").unwrap();
|
||||
assert_eq!(
|
||||
auth_tokens.get(&fixture).unwrap().to_string(),
|
||||
"Bearer def456".to_string()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_auth_tokens_space() {
|
||||
let auth_tokens = AuthTokens::new(Some(
|
||||
" abc123@deno.land;def456@example.com\t".to_string(),
|
||||
));
|
||||
let fixture = resolve_url("https://deno.land/x/mod.ts").unwrap();
|
||||
assert_eq!(
|
||||
auth_tokens.get(&fixture).unwrap().to_string(),
|
||||
"Bearer abc123".to_string()
|
||||
);
|
||||
let fixture = resolve_url("http://example.com/a/file.ts").unwrap();
|
||||
assert_eq!(
|
||||
auth_tokens.get(&fixture).unwrap().to_string(),
|
||||
"Bearer def456".to_string()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_auth_tokens_newline() {
|
||||
let auth_tokens = AuthTokens::new(Some(
|
||||
"\nabc123@deno.land;def456@example.com\n".to_string(),
|
||||
));
|
||||
let fixture = resolve_url("https://deno.land/x/mod.ts").unwrap();
|
||||
assert_eq!(
|
||||
auth_tokens.get(&fixture).unwrap().to_string(),
|
||||
"Bearer abc123".to_string()
|
||||
);
|
||||
let fixture = resolve_url("http://example.com/a/file.ts").unwrap();
|
||||
assert_eq!(
|
||||
auth_tokens.get(&fixture).unwrap().to_string(),
|
||||
"Bearer def456".to_string()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_auth_tokens_port() {
|
||||
let auth_tokens =
|
||||
AuthTokens::new(Some("abc123@deno.land:8080".to_string()));
|
||||
let fixture = resolve_url("https://deno.land/x/mod.ts").unwrap();
|
||||
assert_eq!(auth_tokens.get(&fixture), None);
|
||||
let fixture = resolve_url("http://deno.land:8080/x/mod.ts").unwrap();
|
||||
assert_eq!(
|
||||
auth_tokens.get(&fixture).unwrap().to_string(),
|
||||
"Bearer abc123".to_string()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_auth_tokens_contain_at() {
|
||||
let auth_tokens = AuthTokens::new(Some("abc@123@deno.land".to_string()));
|
||||
let fixture = resolve_url("https://deno.land/x/mod.ts").unwrap();
|
||||
assert_eq!(
|
||||
auth_tokens.get(&fixture).unwrap().to_string(),
|
||||
"Bearer abc@123".to_string()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_auth_token_basic() {
|
||||
let auth_tokens = AuthTokens::new(Some("abc:123@deno.land".to_string()));
|
||||
let fixture = resolve_url("https://deno.land/x/mod.ts").unwrap();
|
||||
assert_eq!(
|
||||
auth_tokens.get(&fixture).unwrap().to_string(),
|
||||
"Basic YWJjOjEyMw=="
|
||||
);
|
||||
let fixture = resolve_url("https://www.deno.land/x/mod.ts").unwrap();
|
||||
assert_eq!(
|
||||
auth_tokens.get(&fixture).unwrap().to_string(),
|
||||
"Basic YWJjOjEyMw==".to_string()
|
||||
);
|
||||
let fixture = resolve_url("http://127.0.0.1:8080/x/mod.ts").unwrap();
|
||||
assert_eq!(auth_tokens.get(&fixture), None);
|
||||
let fixture =
|
||||
resolve_url("https://deno.land.example.com/x/mod.ts").unwrap();
|
||||
assert_eq!(auth_tokens.get(&fixture), None);
|
||||
let fixture = resolve_url("https://deno.land:8080/x/mod.ts").unwrap();
|
||||
assert_eq!(auth_tokens.get(&fixture), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_ip() {
|
||||
let ip = AuthDomain::from("[2001:db8:a::123]");
|
||||
assert_eq!("Ip(2001:db8:a::123)", format!("{ip:?}"));
|
||||
let ip = AuthDomain::from("[2001:db8:a::123]:8080");
|
||||
assert_eq!("IpPort([2001:db8:a::123]:8080)", format!("{ip:?}"));
|
||||
let ip = AuthDomain::from("1.1.1.1");
|
||||
assert_eq!("Ip(1.1.1.1)", format!("{ip:?}"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_case_insensitive() {
|
||||
let domain = AuthDomain::from("EXAMPLE.com");
|
||||
assert!(
|
||||
domain.matches(&ModuleSpecifier::parse("http://example.com").unwrap())
|
||||
);
|
||||
assert!(
|
||||
domain.matches(&ModuleSpecifier::parse("http://example.COM").unwrap())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_matches() {
|
||||
let candidates = [
|
||||
"example.com",
|
||||
"www.example.com",
|
||||
"1.1.1.1",
|
||||
"[2001:db8:a::123]",
|
||||
// These will never match
|
||||
"example.com.evil.com",
|
||||
"1.1.1.1.evil.com",
|
||||
"notexample.com",
|
||||
"www.notexample.com",
|
||||
];
|
||||
let domains = [
|
||||
("example.com", vec!["example.com", "www.example.com"]),
|
||||
(".example.com", vec!["example.com", "www.example.com"]),
|
||||
("www.example.com", vec!["www.example.com"]),
|
||||
("1.1.1.1", vec!["1.1.1.1"]),
|
||||
("[2001:db8:a::123]", vec!["[2001:db8:a::123]"]),
|
||||
];
|
||||
let url = |c: &str| ModuleSpecifier::parse(&format!("http://{c}")).unwrap();
|
||||
let url_port =
|
||||
|c: &str| ModuleSpecifier::parse(&format!("http://{c}:8080")).unwrap();
|
||||
|
||||
// Generate each candidate with and without a port
|
||||
let candidates = candidates
|
||||
.into_iter()
|
||||
.flat_map(|c| [url(c), url_port(c)])
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for (domain, expected_domain) in domains {
|
||||
// Test without a port -- all candidates return without a port
|
||||
let auth_domain = AuthDomain::from(domain);
|
||||
let actual = candidates
|
||||
.iter()
|
||||
.filter(|c| auth_domain.matches(c))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
let expected = expected_domain.iter().map(|u| url(u)).collect::<Vec<_>>();
|
||||
assert_eq!(actual, expected);
|
||||
|
||||
// Test with a port, all candidates return with a port
|
||||
let auth_domain = AuthDomain::from(&format!("{domain}:8080"));
|
||||
let actual = candidates
|
||||
.iter()
|
||||
.filter(|c| auth_domain.matches(c))
|
||||
.cloned()
|
||||
.collect::<Vec<_>>();
|
||||
let expected = expected_domain
|
||||
.iter()
|
||||
.map(|u| url_port(u))
|
||||
.collect::<Vec<_>>();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
}
|
||||
}
|
93
cli/cache/mod.rs
vendored
93
cli/cache/mod.rs
vendored
|
@ -1,18 +1,19 @@
|
|||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use crate::args::jsr_url;
|
||||
use crate::args::CacheSetting;
|
||||
use crate::errors::get_error_class_name;
|
||||
use crate::file_fetcher::CliFetchNoFollowErrorKind;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::file_fetcher::FetchNoFollowOptions;
|
||||
use crate::file_fetcher::FetchOptions;
|
||||
use crate::file_fetcher::FetchPermissionsOptionRef;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::FileOrRedirect;
|
||||
use crate::util::fs::atomic_write_file_with_retries;
|
||||
use crate::util::fs::atomic_write_file_with_retries_and_fs;
|
||||
use crate::util::fs::AtomicWriteFileFsAdapter;
|
||||
|
||||
use deno_ast::MediaType;
|
||||
use deno_cache_dir::file_fetcher::CacheSetting;
|
||||
use deno_cache_dir::file_fetcher::FetchNoFollowErrorKind;
|
||||
use deno_cache_dir::file_fetcher::FileOrRedirect;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::futures;
|
||||
use deno_core::futures::FutureExt;
|
||||
use deno_core::ModuleSpecifier;
|
||||
|
@ -190,7 +191,7 @@ pub struct FetchCacherOptions {
|
|||
/// a concise interface to the DENO_DIR when building module graphs.
|
||||
pub struct FetchCacher {
|
||||
pub file_header_overrides: HashMap<ModuleSpecifier, HashMap<String, String>>,
|
||||
file_fetcher: Arc<FileFetcher>,
|
||||
file_fetcher: Arc<CliFileFetcher>,
|
||||
fs: Arc<dyn deno_fs::FileSystem>,
|
||||
global_http_cache: Arc<GlobalHttpCache>,
|
||||
in_npm_pkg_checker: Arc<dyn InNpmPackageChecker>,
|
||||
|
@ -202,7 +203,7 @@ pub struct FetchCacher {
|
|||
|
||||
impl FetchCacher {
|
||||
pub fn new(
|
||||
file_fetcher: Arc<FileFetcher>,
|
||||
file_fetcher: Arc<CliFileFetcher>,
|
||||
fs: Arc<dyn deno_fs::FileSystem>,
|
||||
global_http_cache: Arc<GlobalHttpCache>,
|
||||
in_npm_pkg_checker: Arc<dyn InNpmPackageChecker>,
|
||||
|
@ -320,18 +321,18 @@ impl Loader for FetchCacher {
|
|||
LoaderCacheSetting::Only => Some(CacheSetting::Only),
|
||||
};
|
||||
file_fetcher
|
||||
.fetch_no_follow_with_options(FetchNoFollowOptions {
|
||||
fetch_options: FetchOptions {
|
||||
specifier: &specifier,
|
||||
permissions: if is_statically_analyzable {
|
||||
FetchPermissionsOptionRef::StaticContainer(&permissions)
|
||||
} else {
|
||||
FetchPermissionsOptionRef::DynamicContainer(&permissions)
|
||||
},
|
||||
maybe_auth: None,
|
||||
maybe_accept: None,
|
||||
maybe_cache_setting: maybe_cache_setting.as_ref(),
|
||||
},
|
||||
.fetch_no_follow(
|
||||
&specifier,
|
||||
FetchPermissionsOptionRef::Restricted(&permissions,
|
||||
if is_statically_analyzable {
|
||||
deno_runtime::deno_permissions::CheckSpecifierKind::Static
|
||||
} else {
|
||||
deno_runtime::deno_permissions::CheckSpecifierKind::Dynamic
|
||||
}),
|
||||
FetchNoFollowOptions {
|
||||
maybe_auth: None,
|
||||
maybe_accept: None,
|
||||
maybe_cache_setting: maybe_cache_setting.as_ref(),
|
||||
maybe_checksum: options.maybe_checksum.as_ref(),
|
||||
})
|
||||
.await
|
||||
|
@ -348,7 +349,7 @@ impl Loader for FetchCacher {
|
|||
(None, None) => None,
|
||||
};
|
||||
Ok(Some(LoadResponse::Module {
|
||||
specifier: file.specifier,
|
||||
specifier: file.url,
|
||||
maybe_headers,
|
||||
content: file.source,
|
||||
}))
|
||||
|
@ -361,18 +362,46 @@ impl Loader for FetchCacher {
|
|||
}
|
||||
})
|
||||
.unwrap_or_else(|err| {
|
||||
if let Some(io_err) = err.downcast_ref::<std::io::Error>() {
|
||||
if io_err.kind() == std::io::ErrorKind::NotFound {
|
||||
return Ok(None);
|
||||
} else {
|
||||
return Err(err);
|
||||
}
|
||||
}
|
||||
let error_class_name = get_error_class_name(&err);
|
||||
match error_class_name {
|
||||
"NotFound" => Ok(None),
|
||||
"NotCached" if options.cache_setting == LoaderCacheSetting::Only => Ok(None),
|
||||
_ => Err(err),
|
||||
let err = err.into_kind();
|
||||
match err {
|
||||
CliFetchNoFollowErrorKind::FetchNoFollow(err) => {
|
||||
let err = err.into_kind();
|
||||
match err {
|
||||
FetchNoFollowErrorKind::NotFound(_) => Ok(None),
|
||||
FetchNoFollowErrorKind::UrlToFilePath { .. } |
|
||||
FetchNoFollowErrorKind::ReadingBlobUrl { .. } |
|
||||
FetchNoFollowErrorKind::ReadingFile { .. } |
|
||||
FetchNoFollowErrorKind::FetchingRemote { .. } |
|
||||
FetchNoFollowErrorKind::ClientError { .. } |
|
||||
FetchNoFollowErrorKind::NoRemote { .. } |
|
||||
FetchNoFollowErrorKind::DataUrlDecode { .. } |
|
||||
FetchNoFollowErrorKind::RedirectResolution { .. } |
|
||||
FetchNoFollowErrorKind::CacheRead { .. } |
|
||||
FetchNoFollowErrorKind::CacheSave { .. } |
|
||||
FetchNoFollowErrorKind::UnsupportedScheme { .. } |
|
||||
FetchNoFollowErrorKind::RedirectHeaderParse { .. } |
|
||||
FetchNoFollowErrorKind::InvalidHeader { .. } => Err(AnyError::from(err)),
|
||||
FetchNoFollowErrorKind::NotCached { .. } => {
|
||||
if options.cache_setting == LoaderCacheSetting::Only {
|
||||
Ok(None)
|
||||
} else {
|
||||
Err(AnyError::from(err))
|
||||
}
|
||||
},
|
||||
FetchNoFollowErrorKind::ChecksumIntegrity(err) => {
|
||||
// convert to the equivalent deno_graph error so that it
|
||||
// enhances it if this is passed to deno_graph
|
||||
Err(
|
||||
deno_graph::source::ChecksumIntegrityError {
|
||||
actual: err.actual,
|
||||
expected: err.expected,
|
||||
}
|
||||
.into(),
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
CliFetchNoFollowErrorKind::PermissionCheck(permission_check_error) => Err(AnyError::from(permission_check_error)),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@ use crate::cache::ModuleInfoCache;
|
|||
use crate::cache::NodeAnalysisCache;
|
||||
use crate::cache::ParsedSourceCache;
|
||||
use crate::emit::Emitter;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::graph_container::MainModuleGraphContainer;
|
||||
use crate::graph_util::FileWatcherReporter;
|
||||
use crate::graph_util::ModuleGraphBuilder;
|
||||
|
@ -185,7 +185,7 @@ struct CliFactoryServices {
|
|||
emit_cache: Deferred<Arc<EmitCache>>,
|
||||
emitter: Deferred<Arc<Emitter>>,
|
||||
feature_checker: Deferred<Arc<FeatureChecker>>,
|
||||
file_fetcher: Deferred<Arc<FileFetcher>>,
|
||||
file_fetcher: Deferred<Arc<CliFileFetcher>>,
|
||||
fs: Deferred<Arc<dyn deno_fs::FileSystem>>,
|
||||
global_http_cache: Deferred<Arc<GlobalHttpCache>>,
|
||||
http_cache: Deferred<Arc<dyn HttpCache>>,
|
||||
|
@ -350,16 +350,17 @@ impl CliFactory {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn file_fetcher(&self) -> Result<&Arc<FileFetcher>, AnyError> {
|
||||
pub fn file_fetcher(&self) -> Result<&Arc<CliFileFetcher>, AnyError> {
|
||||
self.services.file_fetcher.get_or_try_init(|| {
|
||||
let cli_options = self.cli_options()?;
|
||||
Ok(Arc::new(FileFetcher::new(
|
||||
Ok(Arc::new(CliFileFetcher::new(
|
||||
self.http_cache()?.clone(),
|
||||
cli_options.cache_setting(),
|
||||
!cli_options.no_remote(),
|
||||
self.http_client_provider().clone(),
|
||||
self.blob_store().clone(),
|
||||
Some(self.text_only_progress_bar().clone()),
|
||||
!cli_options.no_remote(),
|
||||
cli_options.cache_setting(),
|
||||
log::Level::Info,
|
||||
)))
|
||||
})
|
||||
}
|
||||
|
|
1387
cli/file_fetcher.rs
1387
cli/file_fetcher.rs
File diff suppressed because it is too large
Load diff
|
@ -13,7 +13,7 @@ use crate::cache::ModuleInfoCache;
|
|||
use crate::cache::ParsedSourceCache;
|
||||
use crate::colors;
|
||||
use crate::errors::get_error_class_name;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::npm::CliNpmResolver;
|
||||
use crate::resolver::CjsTracker;
|
||||
use crate::resolver::CliResolver;
|
||||
|
@ -431,7 +431,7 @@ pub struct ModuleGraphBuilder {
|
|||
caches: Arc<cache::Caches>,
|
||||
cjs_tracker: Arc<CjsTracker>,
|
||||
cli_options: Arc<CliOptions>,
|
||||
file_fetcher: Arc<FileFetcher>,
|
||||
file_fetcher: Arc<CliFileFetcher>,
|
||||
fs: Arc<dyn FileSystem>,
|
||||
global_http_cache: Arc<GlobalHttpCache>,
|
||||
in_npm_pkg_checker: Arc<dyn InNpmPackageChecker>,
|
||||
|
@ -450,7 +450,7 @@ impl ModuleGraphBuilder {
|
|||
caches: Arc<cache::Caches>,
|
||||
cjs_tracker: Arc<CjsTracker>,
|
||||
cli_options: Arc<CliOptions>,
|
||||
file_fetcher: Arc<FileFetcher>,
|
||||
file_fetcher: Arc<CliFileFetcher>,
|
||||
fs: Arc<dyn FileSystem>,
|
||||
global_http_cache: Arc<GlobalHttpCache>,
|
||||
in_npm_pkg_checker: Arc<dyn InNpmPackageChecker>,
|
||||
|
|
895
cli/http_util.rs
895
cli/http_util.rs
File diff suppressed because it is too large
Load diff
|
@ -1,7 +1,7 @@
|
|||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use crate::args::jsr_url;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use dashmap::DashMap;
|
||||
use deno_core::serde_json;
|
||||
use deno_graph::packages::JsrPackageInfo;
|
||||
|
@ -19,11 +19,11 @@ pub struct JsrFetchResolver {
|
|||
/// It can be large and we don't want to store it.
|
||||
info_by_nv: DashMap<PackageNv, Option<Arc<JsrPackageVersionInfo>>>,
|
||||
info_by_name: DashMap<String, Option<Arc<JsrPackageInfo>>>,
|
||||
file_fetcher: Arc<FileFetcher>,
|
||||
file_fetcher: Arc<CliFileFetcher>,
|
||||
}
|
||||
|
||||
impl JsrFetchResolver {
|
||||
pub fn new(file_fetcher: Arc<FileFetcher>) -> Self {
|
||||
pub fn new(file_fetcher: Arc<CliFileFetcher>) -> Self {
|
||||
Self {
|
||||
nv_by_req: Default::default(),
|
||||
info_by_nv: Default::default(),
|
||||
|
|
|
@ -63,7 +63,7 @@ use crate::args::ConfigFile;
|
|||
use crate::args::LintFlags;
|
||||
use crate::args::LintOptions;
|
||||
use crate::cache::FastInsecureHasher;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::lsp::logging::lsp_warn;
|
||||
use crate::resolver::CliSloppyImportsResolver;
|
||||
use crate::resolver::SloppyImportsCachedFs;
|
||||
|
@ -1218,7 +1218,7 @@ impl ConfigData {
|
|||
specified_config: Option<&Path>,
|
||||
scope: &ModuleSpecifier,
|
||||
settings: &Settings,
|
||||
file_fetcher: &Arc<FileFetcher>,
|
||||
file_fetcher: &Arc<CliFileFetcher>,
|
||||
// sync requirement is because the lsp requires sync
|
||||
cached_deno_config_fs: &(dyn DenoConfigFs + Sync),
|
||||
deno_json_cache: &(dyn DenoJsonCache + Sync),
|
||||
|
@ -1313,7 +1313,7 @@ impl ConfigData {
|
|||
member_dir: Arc<WorkspaceDirectory>,
|
||||
scope: Arc<ModuleSpecifier>,
|
||||
settings: &Settings,
|
||||
file_fetcher: Option<&Arc<FileFetcher>>,
|
||||
file_fetcher: Option<&Arc<CliFileFetcher>>,
|
||||
) -> Self {
|
||||
let (settings, workspace_folder) = settings.get_for_specifier(&scope);
|
||||
let mut watched_files = HashMap::with_capacity(10);
|
||||
|
@ -1834,7 +1834,7 @@ impl ConfigTree {
|
|||
&mut self,
|
||||
settings: &Settings,
|
||||
workspace_files: &IndexSet<ModuleSpecifier>,
|
||||
file_fetcher: &Arc<FileFetcher>,
|
||||
file_fetcher: &Arc<CliFileFetcher>,
|
||||
) {
|
||||
lsp_log!("Refreshing configuration tree...");
|
||||
// since we're resolving a workspace multiple times in different
|
||||
|
|
|
@ -2,7 +2,8 @@
|
|||
|
||||
use crate::args::jsr_api_url;
|
||||
use crate::args::jsr_url;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::file_fetcher::TextDecodedFile;
|
||||
use crate::jsr::partial_jsr_package_version_info_from_slice;
|
||||
use crate::jsr::JsrFetchResolver;
|
||||
use dashmap::DashMap;
|
||||
|
@ -267,7 +268,7 @@ fn read_cached_url(
|
|||
|
||||
#[derive(Debug)]
|
||||
pub struct CliJsrSearchApi {
|
||||
file_fetcher: Arc<FileFetcher>,
|
||||
file_fetcher: Arc<CliFileFetcher>,
|
||||
resolver: JsrFetchResolver,
|
||||
search_cache: DashMap<String, Arc<Vec<String>>>,
|
||||
versions_cache: DashMap<String, Arc<Vec<Version>>>,
|
||||
|
@ -275,7 +276,7 @@ pub struct CliJsrSearchApi {
|
|||
}
|
||||
|
||||
impl CliJsrSearchApi {
|
||||
pub fn new(file_fetcher: Arc<FileFetcher>) -> Self {
|
||||
pub fn new(file_fetcher: Arc<CliFileFetcher>) -> Self {
|
||||
let resolver = JsrFetchResolver::new(file_fetcher.clone());
|
||||
Self {
|
||||
file_fetcher,
|
||||
|
@ -309,10 +310,8 @@ impl PackageSearchApi for CliJsrSearchApi {
|
|||
let file_fetcher = self.file_fetcher.clone();
|
||||
// spawn due to the lsp's `Send` requirement
|
||||
let file = deno_core::unsync::spawn(async move {
|
||||
file_fetcher
|
||||
.fetch_bypass_permissions(&search_url)
|
||||
.await?
|
||||
.into_text_decoded()
|
||||
let file = file_fetcher.fetch_bypass_permissions(&search_url).await?;
|
||||
TextDecodedFile::decode(file)
|
||||
})
|
||||
.await??;
|
||||
let names = Arc::new(parse_jsr_search_response(&file.source)?);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use deno_ast::MediaType;
|
||||
use deno_cache_dir::file_fetcher::CacheSetting;
|
||||
use deno_config::workspace::WorkspaceDirectory;
|
||||
use deno_config::workspace::WorkspaceDiscoverOptions;
|
||||
use deno_core::anyhow::anyhow;
|
||||
|
@ -95,13 +96,12 @@ use crate::args::create_default_npmrc;
|
|||
use crate::args::get_root_cert_store;
|
||||
use crate::args::has_flag_env_var;
|
||||
use crate::args::CaData;
|
||||
use crate::args::CacheSetting;
|
||||
use crate::args::CliOptions;
|
||||
use crate::args::Flags;
|
||||
use crate::args::InternalFlags;
|
||||
use crate::args::UnstableFmtOptions;
|
||||
use crate::factory::CliFactory;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::graph_util;
|
||||
use crate::http_util::HttpClientProvider;
|
||||
use crate::lsp::config::ConfigWatchedFileType;
|
||||
|
@ -958,15 +958,15 @@ impl Inner {
|
|||
}
|
||||
|
||||
async fn refresh_config_tree(&mut self) {
|
||||
let mut file_fetcher = FileFetcher::new(
|
||||
let file_fetcher = CliFileFetcher::new(
|
||||
self.cache.global().clone(),
|
||||
CacheSetting::RespectHeaders,
|
||||
true,
|
||||
self.http_client_provider.clone(),
|
||||
Default::default(),
|
||||
None,
|
||||
true,
|
||||
CacheSetting::RespectHeaders,
|
||||
super::logging::lsp_log_level(),
|
||||
);
|
||||
file_fetcher.set_download_log_level(super::logging::lsp_log_level());
|
||||
let file_fetcher = Arc::new(file_fetcher);
|
||||
self
|
||||
.config
|
||||
|
|
|
@ -11,21 +11,22 @@ use serde::Deserialize;
|
|||
use std::sync::Arc;
|
||||
|
||||
use crate::args::npm_registry_url;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::file_fetcher::TextDecodedFile;
|
||||
use crate::npm::NpmFetchResolver;
|
||||
|
||||
use super::search::PackageSearchApi;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct CliNpmSearchApi {
|
||||
file_fetcher: Arc<FileFetcher>,
|
||||
file_fetcher: Arc<CliFileFetcher>,
|
||||
resolver: NpmFetchResolver,
|
||||
search_cache: DashMap<String, Arc<Vec<String>>>,
|
||||
versions_cache: DashMap<String, Arc<Vec<Version>>>,
|
||||
}
|
||||
|
||||
impl CliNpmSearchApi {
|
||||
pub fn new(file_fetcher: Arc<FileFetcher>) -> Self {
|
||||
pub fn new(file_fetcher: Arc<CliFileFetcher>) -> Self {
|
||||
let resolver = NpmFetchResolver::new(
|
||||
file_fetcher.clone(),
|
||||
Arc::new(NpmRc::default().as_resolved(npm_registry_url()).unwrap()),
|
||||
|
@ -57,10 +58,8 @@ impl PackageSearchApi for CliNpmSearchApi {
|
|||
.append_pair("text", &format!("{} boost-exact:false", query));
|
||||
let file_fetcher = self.file_fetcher.clone();
|
||||
let file = deno_core::unsync::spawn(async move {
|
||||
file_fetcher
|
||||
.fetch_bypass_permissions(&search_url)
|
||||
.await?
|
||||
.into_text_decoded()
|
||||
let file = file_fetcher.fetch_bypass_permissions(&search_url).await?;
|
||||
TextDecodedFile::decode(file)
|
||||
})
|
||||
.await??;
|
||||
let names = Arc::new(parse_npm_search_response(&file.source)?);
|
||||
|
|
|
@ -12,14 +12,15 @@ use super::path_to_regex::StringOrNumber;
|
|||
use super::path_to_regex::StringOrVec;
|
||||
use super::path_to_regex::Token;
|
||||
|
||||
use crate::args::CacheSetting;
|
||||
use crate::cache::GlobalHttpCache;
|
||||
use crate::cache::HttpCache;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::file_fetcher::FetchOptions;
|
||||
use crate::file_fetcher::FetchPermissionsOptionRef;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::TextDecodedFile;
|
||||
use crate::http_util::HttpClientProvider;
|
||||
|
||||
use deno_cache_dir::file_fetcher::CacheSetting;
|
||||
use deno_core::anyhow::anyhow;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::serde::Deserialize;
|
||||
|
@ -418,7 +419,7 @@ enum VariableItems {
|
|||
pub struct ModuleRegistry {
|
||||
origins: HashMap<String, Vec<RegistryConfiguration>>,
|
||||
pub location: PathBuf,
|
||||
pub file_fetcher: Arc<FileFetcher>,
|
||||
pub file_fetcher: Arc<CliFileFetcher>,
|
||||
http_cache: Arc<GlobalHttpCache>,
|
||||
}
|
||||
|
||||
|
@ -432,15 +433,15 @@ impl ModuleRegistry {
|
|||
location.clone(),
|
||||
crate::cache::RealDenoCacheEnv,
|
||||
));
|
||||
let mut file_fetcher = FileFetcher::new(
|
||||
let file_fetcher = CliFileFetcher::new(
|
||||
http_cache.clone(),
|
||||
CacheSetting::RespectHeaders,
|
||||
true,
|
||||
http_client_provider,
|
||||
Default::default(),
|
||||
None,
|
||||
true,
|
||||
CacheSetting::RespectHeaders,
|
||||
super::logging::lsp_log_level(),
|
||||
);
|
||||
file_fetcher.set_download_log_level(super::logging::lsp_log_level());
|
||||
|
||||
Self {
|
||||
origins: HashMap::new(),
|
||||
|
@ -479,13 +480,15 @@ impl ModuleRegistry {
|
|||
let specifier = specifier.clone();
|
||||
async move {
|
||||
file_fetcher
|
||||
.fetch_with_options(FetchOptions {
|
||||
specifier: &specifier,
|
||||
permissions: FetchPermissionsOptionRef::AllowAll,
|
||||
maybe_auth: None,
|
||||
maybe_accept: Some("application/vnd.deno.reg.v2+json, application/vnd.deno.reg.v1+json;q=0.9, application/json;q=0.8"),
|
||||
maybe_cache_setting: None,
|
||||
})
|
||||
.fetch_with_options(
|
||||
&specifier,
|
||||
FetchPermissionsOptionRef::AllowAll,
|
||||
FetchOptions {
|
||||
maybe_auth: None,
|
||||
maybe_accept: Some("application/vnd.deno.reg.v2+json, application/vnd.deno.reg.v1+json;q=0.9, application/json;q=0.8"),
|
||||
maybe_cache_setting: None,
|
||||
}
|
||||
)
|
||||
.await
|
||||
}
|
||||
}).await?;
|
||||
|
@ -500,7 +503,7 @@ impl ModuleRegistry {
|
|||
);
|
||||
self.http_cache.set(specifier, headers_map, &[])?;
|
||||
}
|
||||
let file = fetch_result?.into_text_decoded()?;
|
||||
let file = TextDecodedFile::decode(fetch_result?)?;
|
||||
let config: RegistryConfigurationJson = serde_json::from_str(&file.source)?;
|
||||
validate_config(&config)?;
|
||||
Ok(config.registries)
|
||||
|
@ -584,12 +587,11 @@ impl ModuleRegistry {
|
|||
// spawn due to the lsp's `Send` requirement
|
||||
let file = deno_core::unsync::spawn({
|
||||
async move {
|
||||
file_fetcher
|
||||
let file = file_fetcher
|
||||
.fetch_bypass_permissions(&endpoint)
|
||||
.await
|
||||
.ok()?
|
||||
.into_text_decoded()
|
||||
.ok()
|
||||
.ok()?;
|
||||
TextDecodedFile::decode(file).ok()
|
||||
}
|
||||
})
|
||||
.await
|
||||
|
@ -983,12 +985,11 @@ impl ModuleRegistry {
|
|||
let file_fetcher = self.file_fetcher.clone();
|
||||
// spawn due to the lsp's `Send` requirement
|
||||
let file = deno_core::unsync::spawn(async move {
|
||||
file_fetcher
|
||||
let file = file_fetcher
|
||||
.fetch_bypass_permissions(&specifier)
|
||||
.await
|
||||
.ok()?
|
||||
.into_text_decoded()
|
||||
.ok()
|
||||
.ok()?;
|
||||
TextDecodedFile::decode(file).ok()
|
||||
})
|
||||
.await
|
||||
.ok()??;
|
||||
|
@ -1049,7 +1050,7 @@ impl ModuleRegistry {
|
|||
let file_fetcher = self.file_fetcher.clone();
|
||||
let specifier = specifier.clone();
|
||||
async move {
|
||||
file_fetcher
|
||||
let file = file_fetcher
|
||||
.fetch_bypass_permissions(&specifier)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
|
@ -1058,9 +1059,8 @@ impl ModuleRegistry {
|
|||
specifier, err
|
||||
);
|
||||
})
|
||||
.ok()?
|
||||
.into_text_decoded()
|
||||
.ok()
|
||||
.ok()?;
|
||||
TextDecodedFile::decode(file).ok()
|
||||
}
|
||||
})
|
||||
.await
|
||||
|
@ -1095,7 +1095,7 @@ impl ModuleRegistry {
|
|||
let file_fetcher = self.file_fetcher.clone();
|
||||
let specifier = specifier.clone();
|
||||
async move {
|
||||
file_fetcher
|
||||
let file = file_fetcher
|
||||
.fetch_bypass_permissions(&specifier)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
|
@ -1104,9 +1104,8 @@ impl ModuleRegistry {
|
|||
specifier, err
|
||||
);
|
||||
})
|
||||
.ok()?
|
||||
.into_text_decoded()
|
||||
.ok()
|
||||
.ok()?;
|
||||
TextDecodedFile::decode(file).ok()
|
||||
}
|
||||
})
|
||||
.await
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use dashmap::DashMap;
|
||||
use deno_ast::MediaType;
|
||||
use deno_cache_dir::file_fetcher::CacheSetting;
|
||||
use deno_cache_dir::npm::NpmCacheDir;
|
||||
use deno_cache_dir::HttpCache;
|
||||
use deno_config::deno_json::JsxImportSourceConfig;
|
||||
|
@ -39,7 +40,6 @@ use std::sync::Arc;
|
|||
use super::cache::LspCache;
|
||||
use super::jsr::JsrCacheResolver;
|
||||
use crate::args::create_default_npmrc;
|
||||
use crate::args::CacheSetting;
|
||||
use crate::args::CliLockfile;
|
||||
use crate::args::NpmInstallDepsProvider;
|
||||
use crate::cache::DenoCacheEnvFsAdapter;
|
||||
|
|
|
@ -5516,7 +5516,6 @@ impl TscRequest {
|
|||
mod tests {
|
||||
use super::*;
|
||||
use crate::cache::HttpCache;
|
||||
use crate::http_util::HeadersMap;
|
||||
use crate::lsp::cache::LspCache;
|
||||
use crate::lsp::config::Config;
|
||||
use crate::lsp::config::WorkspaceSettings;
|
||||
|
@ -5953,7 +5952,7 @@ mod tests {
|
|||
.global()
|
||||
.set(
|
||||
&specifier_dep,
|
||||
HeadersMap::default(),
|
||||
Default::default(),
|
||||
b"export const b = \"b\";\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
@ -5992,7 +5991,7 @@ mod tests {
|
|||
.global()
|
||||
.set(
|
||||
&specifier_dep,
|
||||
HeadersMap::default(),
|
||||
Default::default(),
|
||||
b"export const b = \"b\";\n\nexport const a = \"b\";\n",
|
||||
)
|
||||
.unwrap();
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
mod args;
|
||||
mod auth_tokens;
|
||||
mod cache;
|
||||
mod cdp;
|
||||
mod emit;
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
mod standalone;
|
||||
|
||||
mod args;
|
||||
mod auth_tokens;
|
||||
mod cache;
|
||||
mod emit;
|
||||
mod errors;
|
||||
|
|
|
@ -20,6 +20,7 @@ use deno_npm::resolution::ValidSerializedNpmResolutionSnapshot;
|
|||
use deno_npm::NpmPackageId;
|
||||
use deno_npm::NpmResolutionPackage;
|
||||
use deno_npm::NpmSystemInfo;
|
||||
use deno_npm_cache::NpmCacheSetting;
|
||||
use deno_resolver::npm::CliNpmReqResolver;
|
||||
use deno_runtime::colors;
|
||||
use deno_runtime::deno_fs::FileSystem;
|
||||
|
@ -70,7 +71,7 @@ pub struct CliManagedNpmResolverCreateOptions {
|
|||
pub fs: Arc<dyn deno_runtime::deno_fs::FileSystem>,
|
||||
pub http_client_provider: Arc<crate::http_util::HttpClientProvider>,
|
||||
pub npm_cache_dir: Arc<NpmCacheDir>,
|
||||
pub cache_setting: crate::args::CacheSetting,
|
||||
pub cache_setting: deno_cache_dir::file_fetcher::CacheSetting,
|
||||
pub text_only_progress_bar: crate::util::progress_bar::ProgressBar,
|
||||
pub maybe_node_modules_path: Option<PathBuf>,
|
||||
pub npm_system_info: NpmSystemInfo,
|
||||
|
@ -203,7 +204,7 @@ fn create_cache(
|
|||
) -> Arc<CliNpmCache> {
|
||||
Arc::new(CliNpmCache::new(
|
||||
options.npm_cache_dir.clone(),
|
||||
options.cache_setting.as_npm_cache_setting(),
|
||||
NpmCacheSetting::from_cache_setting(&options.cache_setting),
|
||||
env,
|
||||
options.npmrc.clone(),
|
||||
))
|
||||
|
|
|
@ -28,7 +28,7 @@ use managed::create_managed_in_npm_pkg_checker;
|
|||
use node_resolver::InNpmPackageChecker;
|
||||
use node_resolver::NpmPackageFolderResolver;
|
||||
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::http_util::HttpClientProvider;
|
||||
use crate::util::fs::atomic_write_file_with_retries_and_fs;
|
||||
use crate::util::fs::hard_link_dir_recursive;
|
||||
|
@ -115,14 +115,14 @@ impl deno_npm_cache::NpmCacheEnv for CliNpmCacheEnv {
|
|||
.download_with_progress_and_retries(url, maybe_auth_header, &guard)
|
||||
.await
|
||||
.map_err(|err| {
|
||||
use crate::http_util::DownloadError::*;
|
||||
let status_code = match &err {
|
||||
use crate::http_util::DownloadErrorKind::*;
|
||||
let status_code = match err.as_kind() {
|
||||
Fetch { .. }
|
||||
| UrlParse { .. }
|
||||
| HttpParse { .. }
|
||||
| Json { .. }
|
||||
| ToStr { .. }
|
||||
| NoRedirectHeader { .. }
|
||||
| RedirectHeaderParse { .. }
|
||||
| TooManyRedirects => None,
|
||||
BadResponse(bad_response_error) => {
|
||||
Some(bad_response_error.status_code)
|
||||
|
@ -232,13 +232,13 @@ pub trait CliNpmResolver: NpmPackageFolderResolver + CliNpmReqResolver {
|
|||
pub struct NpmFetchResolver {
|
||||
nv_by_req: DashMap<PackageReq, Option<PackageNv>>,
|
||||
info_by_name: DashMap<String, Option<Arc<NpmPackageInfo>>>,
|
||||
file_fetcher: Arc<FileFetcher>,
|
||||
file_fetcher: Arc<CliFileFetcher>,
|
||||
npmrc: Arc<ResolvedNpmRc>,
|
||||
}
|
||||
|
||||
impl NpmFetchResolver {
|
||||
pub fn new(
|
||||
file_fetcher: Arc<FileFetcher>,
|
||||
file_fetcher: Arc<CliFileFetcher>,
|
||||
npmrc: Arc<ResolvedNpmRc>,
|
||||
) -> Self {
|
||||
Self {
|
||||
|
|
|
@ -71,7 +71,7 @@ use crate::args::UnstableConfig;
|
|||
use crate::cache::DenoDir;
|
||||
use crate::cache::FastInsecureHasher;
|
||||
use crate::emit::Emitter;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::http_util::HttpClientProvider;
|
||||
use crate::npm::CliNpmResolver;
|
||||
use crate::npm::InnerCliNpmResolverRef;
|
||||
|
@ -390,7 +390,7 @@ pub struct DenoCompileBinaryWriter<'a> {
|
|||
cli_options: &'a CliOptions,
|
||||
deno_dir: &'a DenoDir,
|
||||
emitter: &'a Emitter,
|
||||
file_fetcher: &'a FileFetcher,
|
||||
file_fetcher: &'a CliFileFetcher,
|
||||
http_client_provider: &'a HttpClientProvider,
|
||||
npm_resolver: &'a dyn CliNpmResolver,
|
||||
workspace_resolver: &'a WorkspaceResolver,
|
||||
|
@ -404,7 +404,7 @@ impl<'a> DenoCompileBinaryWriter<'a> {
|
|||
cli_options: &'a CliOptions,
|
||||
deno_dir: &'a DenoDir,
|
||||
emitter: &'a Emitter,
|
||||
file_fetcher: &'a FileFetcher,
|
||||
file_fetcher: &'a CliFileFetcher,
|
||||
http_client_provider: &'a HttpClientProvider,
|
||||
npm_resolver: &'a dyn CliNpmResolver,
|
||||
workspace_resolver: &'a WorkspaceResolver,
|
||||
|
|
|
@ -9,6 +9,7 @@ use binary::StandaloneData;
|
|||
use binary::StandaloneModules;
|
||||
use code_cache::DenoCompileCodeCache;
|
||||
use deno_ast::MediaType;
|
||||
use deno_cache_dir::file_fetcher::CacheSetting;
|
||||
use deno_cache_dir::npm::NpmCacheDir;
|
||||
use deno_config::workspace::MappedResolution;
|
||||
use deno_config::workspace::MappedResolutionError;
|
||||
|
@ -64,7 +65,6 @@ use crate::args::create_default_npmrc;
|
|||
use crate::args::get_root_cert_store;
|
||||
use crate::args::npm_pkg_req_ref_to_binary_command;
|
||||
use crate::args::CaData;
|
||||
use crate::args::CacheSetting;
|
||||
use crate::args::NpmInstallDepsProvider;
|
||||
use crate::args::StorageKeyResolver;
|
||||
use crate::cache::Caches;
|
||||
|
|
|
@ -64,7 +64,7 @@ pub async fn check(
|
|||
let file = file_fetcher.fetch(&s, root_permissions).await?;
|
||||
let snippet_files = extract::extract_snippet_files(file)?;
|
||||
for snippet_file in snippet_files {
|
||||
specifiers_for_typecheck.push(snippet_file.specifier.clone());
|
||||
specifiers_for_typecheck.push(snippet_file.url.clone());
|
||||
file_fetcher.insert_memory_files(snippet_file);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use crate::args::FileFlags;
|
|||
use crate::args::Flags;
|
||||
use crate::cdp;
|
||||
use crate::factory::CliFactory;
|
||||
use crate::file_fetcher::TextDecodedFile;
|
||||
use crate::tools::fmt::format_json;
|
||||
use crate::tools::test::is_supported_test_path;
|
||||
use crate::util::text_encoding::source_map_from_code;
|
||||
|
@ -559,6 +560,12 @@ pub fn cover_files(
|
|||
},
|
||||
None => None,
|
||||
};
|
||||
let get_message = |specifier: &ModuleSpecifier| -> String {
|
||||
format!(
|
||||
"Failed to fetch \"{}\" from cache. Before generating coverage report, run `deno test --coverage` to ensure consistent state.",
|
||||
specifier,
|
||||
)
|
||||
};
|
||||
|
||||
for script_coverage in script_coverages {
|
||||
let module_specifier = deno_core::resolve_url_or_path(
|
||||
|
@ -566,21 +573,14 @@ pub fn cover_files(
|
|||
cli_options.initial_cwd(),
|
||||
)?;
|
||||
|
||||
let maybe_file = if module_specifier.scheme() == "file" {
|
||||
file_fetcher.get_source(&module_specifier)
|
||||
} else {
|
||||
file_fetcher
|
||||
.fetch_cached(&module_specifier, 10)
|
||||
.with_context(|| {
|
||||
format!("Failed to fetch \"{module_specifier}\" from cache.")
|
||||
})?
|
||||
let maybe_file_result = file_fetcher
|
||||
.get_cached_source_or_local(&module_specifier)
|
||||
.map_err(AnyError::from);
|
||||
let file = match maybe_file_result {
|
||||
Ok(Some(file)) => TextDecodedFile::decode(file)?,
|
||||
Ok(None) => return Err(anyhow!("{}", get_message(&module_specifier))),
|
||||
Err(err) => return Err(err).context(get_message(&module_specifier)),
|
||||
};
|
||||
let file = maybe_file.ok_or_else(|| {
|
||||
anyhow!("Failed to fetch \"{}\" from cache.
|
||||
Before generating coverage report, run `deno test --coverage` to ensure consistent state.",
|
||||
module_specifier
|
||||
)
|
||||
})?.into_text_decoded()?;
|
||||
|
||||
let original_source = file.source.clone();
|
||||
// Check if file was transpiled
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
use crate::args::resolve_no_prompt;
|
||||
use crate::args::AddFlags;
|
||||
use crate::args::CaData;
|
||||
use crate::args::CacheSetting;
|
||||
use crate::args::ConfigFlag;
|
||||
use crate::args::Flags;
|
||||
use crate::args::InstallFlags;
|
||||
|
@ -13,13 +12,14 @@ use crate::args::TypeCheckMode;
|
|||
use crate::args::UninstallFlags;
|
||||
use crate::args::UninstallKind;
|
||||
use crate::factory::CliFactory;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::graph_container::ModuleGraphContainer;
|
||||
use crate::http_util::HttpClientProvider;
|
||||
use crate::jsr::JsrFetchResolver;
|
||||
use crate::npm::NpmFetchResolver;
|
||||
use crate::util::fs::canonicalize_path_maybe_not_exists;
|
||||
|
||||
use deno_cache_dir::file_fetcher::CacheSetting;
|
||||
use deno_core::anyhow::bail;
|
||||
use deno_core::anyhow::Context;
|
||||
use deno_core::error::generic_error;
|
||||
|
@ -361,18 +361,18 @@ async fn install_global(
|
|||
let cli_options = factory.cli_options()?;
|
||||
let http_client = factory.http_client_provider();
|
||||
let deps_http_cache = factory.global_http_cache()?;
|
||||
let mut deps_file_fetcher = FileFetcher::new(
|
||||
let deps_file_fetcher = CliFileFetcher::new(
|
||||
deps_http_cache.clone(),
|
||||
CacheSetting::ReloadAll,
|
||||
true,
|
||||
http_client.clone(),
|
||||
Default::default(),
|
||||
None,
|
||||
true,
|
||||
CacheSetting::ReloadAll,
|
||||
log::Level::Trace,
|
||||
);
|
||||
|
||||
let npmrc = factory.cli_options().unwrap().npmrc();
|
||||
|
||||
deps_file_fetcher.set_download_log_level(log::Level::Trace);
|
||||
let deps_file_fetcher = Arc::new(deps_file_fetcher);
|
||||
let jsr_resolver = Arc::new(JsrFetchResolver::new(deps_file_fetcher.clone()));
|
||||
let npm_resolver = Arc::new(NpmFetchResolver::new(
|
||||
|
|
|
@ -4,6 +4,7 @@ use std::path::Path;
|
|||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
|
||||
use deno_cache_dir::file_fetcher::CacheSetting;
|
||||
use deno_core::anyhow::bail;
|
||||
use deno_core::anyhow::Context;
|
||||
use deno_core::error::AnyError;
|
||||
|
@ -23,12 +24,11 @@ use jsonc_parser::cst::CstRootNode;
|
|||
use jsonc_parser::json;
|
||||
|
||||
use crate::args::AddFlags;
|
||||
use crate::args::CacheSetting;
|
||||
use crate::args::CliOptions;
|
||||
use crate::args::Flags;
|
||||
use crate::args::RemoveFlags;
|
||||
use crate::factory::CliFactory;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::jsr::JsrFetchResolver;
|
||||
use crate::npm::NpmFetchResolver;
|
||||
|
||||
|
@ -411,18 +411,18 @@ pub async fn add(
|
|||
|
||||
let http_client = cli_factory.http_client_provider();
|
||||
let deps_http_cache = cli_factory.global_http_cache()?;
|
||||
let mut deps_file_fetcher = FileFetcher::new(
|
||||
let deps_file_fetcher = CliFileFetcher::new(
|
||||
deps_http_cache.clone(),
|
||||
CacheSetting::ReloadAll,
|
||||
true,
|
||||
http_client.clone(),
|
||||
Default::default(),
|
||||
None,
|
||||
true,
|
||||
CacheSetting::ReloadAll,
|
||||
log::Level::Trace,
|
||||
);
|
||||
|
||||
let npmrc = cli_factory.cli_options().unwrap().npmrc();
|
||||
|
||||
deps_file_fetcher.set_download_log_level(log::Level::Trace);
|
||||
let deps_file_fetcher = Arc::new(deps_file_fetcher);
|
||||
let jsr_resolver = Arc::new(JsrFetchResolver::new(deps_file_fetcher.clone()));
|
||||
let npm_resolver =
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use std::collections::HashSet;
|
||||
use std::sync::Arc;
|
||||
|
||||
use deno_cache_dir::file_fetcher::CacheSetting;
|
||||
use deno_core::anyhow::bail;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_semver::package::PackageNv;
|
||||
|
@ -10,12 +11,11 @@ use deno_semver::package::PackageReq;
|
|||
use deno_semver::VersionReq;
|
||||
use deno_terminal::colors;
|
||||
|
||||
use crate::args::CacheSetting;
|
||||
use crate::args::CliOptions;
|
||||
use crate::args::Flags;
|
||||
use crate::args::OutdatedFlags;
|
||||
use crate::factory::CliFactory;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::jsr::JsrFetchResolver;
|
||||
use crate::npm::NpmFetchResolver;
|
||||
use crate::tools::registry::pm::deps::DepKind;
|
||||
|
@ -181,15 +181,15 @@ pub async fn outdated(
|
|||
let workspace = cli_options.workspace();
|
||||
let http_client = factory.http_client_provider();
|
||||
let deps_http_cache = factory.global_http_cache()?;
|
||||
let mut file_fetcher = FileFetcher::new(
|
||||
let file_fetcher = CliFileFetcher::new(
|
||||
deps_http_cache.clone(),
|
||||
CacheSetting::RespectHeaders,
|
||||
true,
|
||||
http_client.clone(),
|
||||
Default::default(),
|
||||
None,
|
||||
true,
|
||||
CacheSetting::RespectHeaders,
|
||||
log::Level::Trace,
|
||||
);
|
||||
file_fetcher.set_download_log_level(log::Level::Trace);
|
||||
let file_fetcher = Arc::new(file_fetcher);
|
||||
let npm_fetch_resolver = Arc::new(NpmFetchResolver::new(
|
||||
file_fetcher.clone(),
|
||||
|
|
|
@ -11,7 +11,8 @@ use crate::args::ReplFlags;
|
|||
use crate::cdp;
|
||||
use crate::colors;
|
||||
use crate::factory::CliFactory;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::file_fetcher::TextDecodedFile;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::futures::StreamExt;
|
||||
use deno_core::serde_json;
|
||||
|
@ -143,7 +144,7 @@ async fn read_line_and_poll(
|
|||
|
||||
async fn read_eval_file(
|
||||
cli_options: &CliOptions,
|
||||
file_fetcher: &FileFetcher,
|
||||
file_fetcher: &CliFileFetcher,
|
||||
eval_file: &str,
|
||||
) -> Result<Arc<str>, AnyError> {
|
||||
let specifier =
|
||||
|
@ -151,7 +152,7 @@ async fn read_eval_file(
|
|||
|
||||
let file = file_fetcher.fetch_bypass_permissions(&specifier).await?;
|
||||
|
||||
Ok(file.into_text_decoded()?.source)
|
||||
Ok(TextDecodedFile::decode(file)?.source)
|
||||
}
|
||||
|
||||
#[allow(clippy::print_stdout)]
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
use std::io::Read;
|
||||
use std::sync::Arc;
|
||||
|
||||
use deno_cache_dir::file_fetcher::File;
|
||||
use deno_config::deno_json::NodeModulesDirMode;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_runtime::WorkerExecutionMode;
|
||||
|
@ -11,7 +12,6 @@ use crate::args::EvalFlags;
|
|||
use crate::args::Flags;
|
||||
use crate::args::WatchFlagsWithPaths;
|
||||
use crate::factory::CliFactory;
|
||||
use crate::file_fetcher::File;
|
||||
use crate::util;
|
||||
use crate::util::file_watcher::WatcherRestartMode;
|
||||
|
||||
|
@ -97,7 +97,7 @@ pub async fn run_from_stdin(flags: Arc<Flags>) -> Result<i32, AnyError> {
|
|||
// Save a fake file into file fetcher cache
|
||||
// to allow module access by TS compiler
|
||||
file_fetcher.insert_memory_files(File {
|
||||
specifier: main_module.clone(),
|
||||
url: main_module.clone(),
|
||||
maybe_headers: None,
|
||||
source: source.into(),
|
||||
});
|
||||
|
@ -184,7 +184,7 @@ pub async fn eval_command(
|
|||
// Save a fake file into file fetcher cache
|
||||
// to allow module access by TS compiler.
|
||||
file_fetcher.insert_memory_files(File {
|
||||
specifier: main_module.clone(),
|
||||
url: main_module.clone(),
|
||||
maybe_headers: None,
|
||||
source: source_code.into_bytes().into(),
|
||||
});
|
||||
|
|
|
@ -7,8 +7,7 @@ use crate::args::TestReporterConfig;
|
|||
use crate::colors;
|
||||
use crate::display;
|
||||
use crate::factory::CliFactory;
|
||||
use crate::file_fetcher::File;
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::file_fetcher::CliFileFetcher;
|
||||
use crate::graph_util::has_graph_root_local_dependent_changed;
|
||||
use crate::ops;
|
||||
use crate::util::extract::extract_doc_tests;
|
||||
|
@ -21,6 +20,7 @@ use crate::worker::CliMainWorkerFactory;
|
|||
use crate::worker::CoverageCollector;
|
||||
|
||||
use deno_ast::MediaType;
|
||||
use deno_cache_dir::file_fetcher::File;
|
||||
use deno_config::glob::FilePatterns;
|
||||
use deno_config::glob::WalkEntry;
|
||||
use deno_core::anyhow;
|
||||
|
@ -1514,7 +1514,7 @@ fn collect_specifiers_with_test_mode(
|
|||
/// as well.
|
||||
async fn fetch_specifiers_with_test_mode(
|
||||
cli_options: &CliOptions,
|
||||
file_fetcher: &FileFetcher,
|
||||
file_fetcher: &CliFileFetcher,
|
||||
member_patterns: impl Iterator<Item = FilePatterns>,
|
||||
doc: &bool,
|
||||
) -> Result<Vec<(ModuleSpecifier, TestMode)>, AnyError> {
|
||||
|
@ -1822,7 +1822,7 @@ pub async fn run_tests_with_watch(
|
|||
/// Extracts doc tests from files specified by the given specifiers.
|
||||
async fn get_doc_tests(
|
||||
specifiers_with_mode: &[(Url, TestMode)],
|
||||
file_fetcher: &FileFetcher,
|
||||
file_fetcher: &CliFileFetcher,
|
||||
) -> Result<Vec<File>, AnyError> {
|
||||
let specifiers_needing_extraction = specifiers_with_mode
|
||||
.iter()
|
||||
|
@ -1847,7 +1847,7 @@ fn get_target_specifiers(
|
|||
specifiers_with_mode
|
||||
.into_iter()
|
||||
.filter_map(|(s, mode)| mode.needs_test_run().then_some(s))
|
||||
.chain(doc_tests.iter().map(|d| d.specifier.clone()))
|
||||
.chain(doc_tests.iter().map(|d| d.url.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ use deno_ast::swc::visit::VisitMut;
|
|||
use deno_ast::swc::visit::VisitWith as _;
|
||||
use deno_ast::MediaType;
|
||||
use deno_ast::SourceRangedForSpanned as _;
|
||||
use deno_cache_dir::file_fetcher::File;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use regex::Regex;
|
||||
|
@ -20,7 +21,7 @@ use std::collections::BTreeSet;
|
|||
use std::fmt::Write as _;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::file_fetcher::File;
|
||||
use crate::file_fetcher::TextDecodedFile;
|
||||
use crate::util::path::mapped_specifier_for_tsc;
|
||||
|
||||
/// Extracts doc tests from a given file, transforms them into pseudo test
|
||||
|
@ -52,7 +53,7 @@ fn extract_inner(
|
|||
file: File,
|
||||
wrap_kind: WrapKind,
|
||||
) -> Result<Vec<File>, AnyError> {
|
||||
let file = file.into_text_decoded()?;
|
||||
let file = TextDecodedFile::decode(file)?;
|
||||
|
||||
let exports = match deno_ast::parse_program(deno_ast::ParseParams {
|
||||
specifier: file.specifier.clone(),
|
||||
|
@ -230,7 +231,7 @@ fn extract_files_from_regex_blocks(
|
|||
.unwrap_or(file_specifier);
|
||||
|
||||
Some(File {
|
||||
specifier: file_specifier,
|
||||
url: file_specifier,
|
||||
maybe_headers: None,
|
||||
source: file_source.into_bytes().into(),
|
||||
})
|
||||
|
@ -558,7 +559,7 @@ fn generate_pseudo_file(
|
|||
exports: &ExportCollector,
|
||||
wrap_kind: WrapKind,
|
||||
) -> Result<File, AnyError> {
|
||||
let file = file.into_text_decoded()?;
|
||||
let file = TextDecodedFile::decode(file)?;
|
||||
|
||||
let parsed = deno_ast::parse_program(deno_ast::ParseParams {
|
||||
specifier: file.specifier.clone(),
|
||||
|
@ -594,7 +595,7 @@ fn generate_pseudo_file(
|
|||
log::debug!("{}:\n{}", file.specifier, source);
|
||||
|
||||
Ok(File {
|
||||
specifier: file.specifier,
|
||||
url: file.specifier,
|
||||
maybe_headers: None,
|
||||
source: source.into_bytes().into(),
|
||||
})
|
||||
|
@ -1199,14 +1200,14 @@ Deno.test("file:///main.ts$3-7.ts", async ()=>{
|
|||
|
||||
for test in tests {
|
||||
let file = File {
|
||||
specifier: ModuleSpecifier::parse(test.input.specifier).unwrap(),
|
||||
url: ModuleSpecifier::parse(test.input.specifier).unwrap(),
|
||||
maybe_headers: None,
|
||||
source: test.input.source.as_bytes().into(),
|
||||
};
|
||||
let got_decoded = extract_doc_tests(file)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|f| f.into_text_decoded().unwrap())
|
||||
.map(|f| TextDecodedFile::decode(f).unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
let expected = test
|
||||
.expected
|
||||
|
@ -1435,14 +1436,14 @@ add('1', '2');
|
|||
|
||||
for test in tests {
|
||||
let file = File {
|
||||
specifier: ModuleSpecifier::parse(test.input.specifier).unwrap(),
|
||||
url: ModuleSpecifier::parse(test.input.specifier).unwrap(),
|
||||
maybe_headers: None,
|
||||
source: test.input.source.as_bytes().into(),
|
||||
};
|
||||
let got_decoded = extract_snippet_files(file)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|f| f.into_text_decoded().unwrap())
|
||||
.map(|f| TextDecodedFile::decode(f).unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
let expected = test
|
||||
.expected
|
||||
|
|
|
@ -9,6 +9,7 @@ use std::sync::Arc;
|
|||
use anyhow::bail;
|
||||
use anyhow::Context;
|
||||
use anyhow::Error as AnyError;
|
||||
use deno_cache_dir::file_fetcher::CacheSetting;
|
||||
use deno_cache_dir::npm::NpmCacheDir;
|
||||
use deno_npm::npm_rc::ResolvedNpmRc;
|
||||
use deno_npm::registry::NpmPackageInfo;
|
||||
|
@ -90,6 +91,27 @@ pub enum NpmCacheSetting {
|
|||
}
|
||||
|
||||
impl NpmCacheSetting {
|
||||
pub fn from_cache_setting(cache_setting: &CacheSetting) -> NpmCacheSetting {
|
||||
match cache_setting {
|
||||
CacheSetting::Only => NpmCacheSetting::Only,
|
||||
CacheSetting::ReloadAll => NpmCacheSetting::ReloadAll,
|
||||
CacheSetting::ReloadSome(values) => {
|
||||
if values.iter().any(|v| v == "npm:") {
|
||||
NpmCacheSetting::ReloadAll
|
||||
} else {
|
||||
NpmCacheSetting::ReloadSome {
|
||||
npm_package_names: values
|
||||
.iter()
|
||||
.filter_map(|v| v.strip_prefix("npm:"))
|
||||
.map(|n| n.to_string())
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
CacheSetting::RespectHeaders => panic!("not supported"),
|
||||
CacheSetting::Use => NpmCacheSetting::Use,
|
||||
}
|
||||
}
|
||||
pub fn should_use_for_npm_package(&self, package_name: &str) -> bool {
|
||||
match self {
|
||||
NpmCacheSetting::ReloadAll => false,
|
||||
|
|
|
@ -43,7 +43,7 @@ fn conditionally_loads_type_graph() {
|
|||
.new_command()
|
||||
.args("bench --reload -L debug run/type_directives_js_main.js")
|
||||
.run();
|
||||
output.assert_matches_text("[WILDCARD] - FileFetcher::fetch_no_follow_with_options - specifier: file:///[WILDCARD]/subdir/type_reference.d.ts[WILDCARD]");
|
||||
output.assert_matches_text("[WILDCARD] - FileFetcher::fetch_no_follow - specifier: file:///[WILDCARD]/subdir/type_reference.d.ts[WILDCARD]");
|
||||
let output = context
|
||||
.new_command()
|
||||
.args("bench --reload -L debug --no-check run/type_directives_js_main.js")
|
||||
|
|
|
@ -107,5 +107,5 @@ fn loads_type_graph() {
|
|||
.new_command()
|
||||
.args("cache --reload -L debug run/type_directives_js_main.js")
|
||||
.run();
|
||||
output.assert_matches_text("[WILDCARD] - FileFetcher::fetch_no_follow_with_options - specifier: file:///[WILDCARD]/subdir/type_reference.d.ts[WILDCARD]");
|
||||
output.assert_matches_text("[WILDCARD] - FileFetcher::fetch_no_follow - specifier: file:///[WILDCARD]/subdir/type_reference.d.ts[WILDCARD]");
|
||||
}
|
||||
|
|
|
@ -922,7 +922,7 @@ fn type_directives_js_main() {
|
|||
.new_command()
|
||||
.args("run --reload -L debug --check run/type_directives_js_main.js")
|
||||
.run();
|
||||
output.assert_matches_text("[WILDCARD] - FileFetcher::fetch_no_follow_with_options - specifier: file:///[WILDCARD]/subdir/type_reference.d.ts[WILDCARD]");
|
||||
output.assert_matches_text("[WILDCARD] - FileFetcher::fetch_no_follow - specifier: file:///[WILDCARD]/subdir/type_reference.d.ts[WILDCARD]");
|
||||
let output = context
|
||||
.new_command()
|
||||
.args("run --reload -L debug run/type_directives_js_main.js")
|
||||
|
|
|
@ -111,7 +111,7 @@ fn conditionally_loads_type_graph() {
|
|||
.new_command()
|
||||
.args("test --reload -L debug run/type_directives_js_main.js")
|
||||
.run();
|
||||
output.assert_matches_text("[WILDCARD] - FileFetcher::fetch_no_follow_with_options - specifier: file:///[WILDCARD]/subdir/type_reference.d.ts[WILDCARD]");
|
||||
output.assert_matches_text("[WILDCARD] - FileFetcher::fetch_no_follow - specifier: file:///[WILDCARD]/subdir/type_reference.d.ts[WILDCARD]");
|
||||
let output = context
|
||||
.new_command()
|
||||
.args("test --reload -L debug --no-check run/type_directives_js_main.js")
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
DANGER: TLS certificate validation is disabled for: deno.land
|
||||
error: Import 'https://localhost:5545/subdir/mod2.ts' failed: error sending request for url (https://localhost:5545/subdir/mod2.ts): client error[WILDCARD]
|
||||
at file:///[WILDCARD]/cafile_url_imports.ts:[WILDCARD]
|
||||
error: Import 'https://localhost:5545/subdir/mod2.ts' failed.
|
||||
0: error sending request for url (https://localhost:5545/subdir/mod2.ts): client error (Connect): invalid peer certificate: UnknownIssuer
|
||||
1: client error (Connect)
|
||||
2: invalid peer certificate: UnknownIssuer
|
||||
at file:///[WILDLINE]/cafile_url_imports.ts:[WILDLINE]
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
"output": "jsx_import_source_dev.out"
|
||||
},
|
||||
"jsx_import_source_pragma_with_config_vendor_dir": {
|
||||
"tempDir": true,
|
||||
"args": "run --allow-import --reload --config jsx/deno-jsx.jsonc --no-lock --vendor jsx_import_source_pragma.tsx",
|
||||
"output": "jsx_import_source.out"
|
||||
},
|
||||
|
|
|
@ -577,11 +577,6 @@ async fn main_server(
|
|||
);
|
||||
Ok(res)
|
||||
}
|
||||
(_, "/bad_redirect") => {
|
||||
let mut res = Response::new(empty_body());
|
||||
*res.status_mut() = StatusCode::FOUND;
|
||||
Ok(res)
|
||||
}
|
||||
(_, "/server_error") => {
|
||||
let mut res = Response::new(empty_body());
|
||||
*res.status_mut() = StatusCode::INTERNAL_SERVER_ERROR;
|
||||
|
|
Loading…
Add table
Reference in a new issue