mirror of
https://github.com/denoland/deno.git
synced 2024-12-25 00:29:09 -05:00
refactor(deno_graph): remove unused Resolved::Ok#kind usage (#17504)
See https://github.com/denoland/deno_graph/pull/205 for more details.
This commit is contained in:
parent
0d1471282b
commit
654e177c91
20 changed files with 75 additions and 172 deletions
16
Cargo.lock
generated
16
Cargo.lock
generated
|
@ -972,9 +972,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_doc"
|
||||
version = "0.52.0"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a4d646da7094c8c4005c1ecfeb9649a1f3875e5e964a1ecf6d44899c5692ebb"
|
||||
checksum = "9d792edabc692d89ab24cb4fa0f24cd8d71288669962e867b4634a28d04935bd"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"deno_ast",
|
||||
|
@ -990,9 +990,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_emit"
|
||||
version = "0.13.0"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33d7152339bef69b44316be53d6b34cf40718c3084a22565d729b4131c53f462"
|
||||
checksum = "9abbf7099beedb52d5d84cef071825f1abf75234d48c820b15dbd4e47576b64c"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64",
|
||||
|
@ -1054,9 +1054,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "deno_graph"
|
||||
version = "0.41.0"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "88980ad969ef1922782f4b19159bb3c46919e883292f1c71ddc3bcd8ba1a5a46"
|
||||
checksum = "f469b4a0694cb7e7fd512f23bc10d32398d7228cd2581a262109359c8e263940"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"cfg-if",
|
||||
|
@ -1657,9 +1657,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "eszip"
|
||||
version = "0.32.0"
|
||||
version = "0.33.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "584906c722ca9751a4e1dd1fde7ca3387e2af2b4b3608e8d44bd29f22095a4a2"
|
||||
checksum = "98d6b4f119df606d3cdce5b251b326b6f5cc9a5c59054d701ca973c23f90f7b4"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"base64",
|
||||
|
|
|
@ -44,9 +44,9 @@ winres.workspace = true
|
|||
[dependencies]
|
||||
deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "dep_graph", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] }
|
||||
deno_core.workspace = true
|
||||
deno_doc = "0.52.0"
|
||||
deno_emit = "0.13.0"
|
||||
deno_graph = "0.41.0"
|
||||
deno_doc = "0.53.0"
|
||||
deno_emit = "0.14.0"
|
||||
deno_graph = "0.42.0"
|
||||
deno_lint = { version = "0.37.0", features = ["docs"] }
|
||||
deno_lockfile.workspace = true
|
||||
deno_runtime.workspace = true
|
||||
|
@ -69,7 +69,7 @@ dprint-plugin-markdown = "=0.15.2"
|
|||
dprint-plugin-typescript = "=0.80.2"
|
||||
encoding_rs.workspace = true
|
||||
env_logger = "=0.9.0"
|
||||
eszip = "=0.32.0"
|
||||
eszip = "=0.33.0"
|
||||
fancy-regex = "=0.10.0"
|
||||
flate2.workspace = true
|
||||
http.workspace = true
|
||||
|
|
|
@ -25,7 +25,6 @@ use deno_graph::GraphImport;
|
|||
use deno_graph::MediaType;
|
||||
use deno_graph::ModuleGraph;
|
||||
use deno_graph::ModuleGraphError;
|
||||
use deno_graph::ModuleKind;
|
||||
use deno_graph::Range;
|
||||
use deno_graph::Resolved;
|
||||
use deno_runtime::permissions::PermissionsContainer;
|
||||
|
@ -35,13 +34,6 @@ use std::collections::HashSet;
|
|||
use std::collections::VecDeque;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub fn contains_specifier(
|
||||
v: &[(ModuleSpecifier, ModuleKind)],
|
||||
specifier: &ModuleSpecifier,
|
||||
) -> bool {
|
||||
v.iter().any(|(s, _)| s == specifier)
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum ModuleEntry {
|
||||
|
@ -175,7 +167,7 @@ impl GraphData {
|
|||
/// Return `None` if any modules are not known.
|
||||
pub fn walk<'a>(
|
||||
&'a self,
|
||||
roots: &[(ModuleSpecifier, ModuleKind)],
|
||||
roots: &[ModuleSpecifier],
|
||||
follow_dynamic: bool,
|
||||
follow_type_only: bool,
|
||||
check_js: bool,
|
||||
|
@ -183,7 +175,7 @@ impl GraphData {
|
|||
let mut result = HashMap::<&'a ModuleSpecifier, &'a ModuleEntry>::new();
|
||||
let mut seen = HashSet::<&ModuleSpecifier>::new();
|
||||
let mut visiting = VecDeque::<&ModuleSpecifier>::new();
|
||||
for (root, _) in roots {
|
||||
for root in roots {
|
||||
seen.insert(root);
|
||||
visiting.push_back(root);
|
||||
}
|
||||
|
@ -274,10 +266,7 @@ impl GraphData {
|
|||
|
||||
/// Clone part of `self`, containing only modules which are dependencies of
|
||||
/// `roots`. Returns `None` if any roots are not known.
|
||||
pub fn graph_segment(
|
||||
&self,
|
||||
roots: &[(ModuleSpecifier, ModuleKind)],
|
||||
) -> Option<Self> {
|
||||
pub fn graph_segment(&self, roots: &[ModuleSpecifier]) -> Option<Self> {
|
||||
let mut modules = HashMap::new();
|
||||
let mut referrer_map = HashMap::new();
|
||||
let entries = match self.walk(roots, true, true, true) {
|
||||
|
@ -305,7 +294,7 @@ impl GraphData {
|
|||
/// not known.
|
||||
pub fn check(
|
||||
&self,
|
||||
roots: &[(ModuleSpecifier, ModuleKind)],
|
||||
roots: &[ModuleSpecifier],
|
||||
follow_type_only: bool,
|
||||
check_js: bool,
|
||||
) -> Option<Result<(), AnyError>> {
|
||||
|
@ -365,7 +354,7 @@ impl GraphData {
|
|||
}
|
||||
}
|
||||
ModuleEntry::Error(error) => {
|
||||
if !contains_specifier(roots, specifier) {
|
||||
if !roots.contains(specifier) {
|
||||
if let Some(range) = self.referrer_map.get(specifier) {
|
||||
if !range.specifier.as_str().contains("$deno") {
|
||||
let message = error.to_string();
|
||||
|
@ -388,7 +377,7 @@ impl GraphData {
|
|||
/// Assumes that all of those modules are known.
|
||||
pub fn set_type_checked(
|
||||
&mut self,
|
||||
roots: &[(ModuleSpecifier, ModuleKind)],
|
||||
roots: &[ModuleSpecifier],
|
||||
lib: TsTypeLib,
|
||||
) {
|
||||
let specifiers: Vec<ModuleSpecifier> =
|
||||
|
@ -408,10 +397,10 @@ impl GraphData {
|
|||
/// Check if `roots` are all marked as type checked under `lib`.
|
||||
pub fn is_type_checked(
|
||||
&self,
|
||||
roots: &[(ModuleSpecifier, ModuleKind)],
|
||||
roots: &[ModuleSpecifier],
|
||||
lib: &TsTypeLib,
|
||||
) -> bool {
|
||||
roots.iter().all(|(r, _)| {
|
||||
roots.iter().all(|r| {
|
||||
let found = self.follow_redirect(r);
|
||||
match self.modules.get(&found) {
|
||||
Some(ModuleEntry::Module { checked_libs, .. }) => {
|
||||
|
@ -527,7 +516,7 @@ pub async fn create_graph_and_maybe_check(
|
|||
let analyzer = ps.parsed_source_cache.as_analyzer();
|
||||
let graph = Arc::new(
|
||||
deno_graph::create_graph(
|
||||
vec![(root, deno_graph::ModuleKind::Esm)],
|
||||
vec![root],
|
||||
&mut cache,
|
||||
deno_graph::GraphOptions {
|
||||
is_dynamic: false,
|
||||
|
|
|
@ -876,7 +876,7 @@ impl Documents {
|
|||
) -> bool {
|
||||
let maybe_resolver = self.get_maybe_resolver();
|
||||
let maybe_specifier = if let Some(resolver) = maybe_resolver {
|
||||
resolver.resolve(specifier, referrer).to_result().ok()
|
||||
resolver.resolve(specifier, referrer).ok()
|
||||
} else {
|
||||
deno_core::resolve_import(specifier, referrer.as_str()).ok()
|
||||
};
|
||||
|
@ -1318,7 +1318,7 @@ fn lsp_deno_graph_analyze(
|
|||
specifier,
|
||||
maybe_headers,
|
||||
content,
|
||||
Some(&deno_graph::ModuleKind::Esm),
|
||||
Some(deno_graph::ModuleKind::Esm),
|
||||
maybe_resolver,
|
||||
Some(&analyzer),
|
||||
),
|
||||
|
|
|
@ -8,7 +8,6 @@ use deno_core::serde_json;
|
|||
use deno_core::serde_json::json;
|
||||
use deno_core::serde_json::Value;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use deno_graph::ModuleKind;
|
||||
use import_map::ImportMap;
|
||||
use log::error;
|
||||
use log::warn;
|
||||
|
@ -158,7 +157,7 @@ impl LanguageServer {
|
|||
) -> LspResult<Option<Value>> {
|
||||
async fn create_graph_for_caching(
|
||||
cli_options: CliOptions,
|
||||
roots: Vec<(ModuleSpecifier, ModuleKind)>,
|
||||
roots: Vec<ModuleSpecifier>,
|
||||
open_docs: Vec<Document>,
|
||||
) -> Result<(), AnyError> {
|
||||
let open_docs = open_docs
|
||||
|
@ -2917,7 +2916,7 @@ impl tower_lsp::LanguageServer for LanguageServer {
|
|||
|
||||
struct PrepareCacheResult {
|
||||
cli_options: CliOptions,
|
||||
roots: Vec<(ModuleSpecifier, ModuleKind)>,
|
||||
roots: Vec<ModuleSpecifier>,
|
||||
open_docs: Vec<Document>,
|
||||
mark: PerformanceMark,
|
||||
}
|
||||
|
@ -2938,15 +2937,10 @@ impl Inner {
|
|||
params
|
||||
.uris
|
||||
.iter()
|
||||
.map(|t| {
|
||||
(
|
||||
self.url_map.normalize_url(&t.uri),
|
||||
deno_graph::ModuleKind::Esm,
|
||||
)
|
||||
})
|
||||
.map(|t| self.url_map.normalize_url(&t.uri))
|
||||
.collect()
|
||||
} else {
|
||||
vec![(referrer, deno_graph::ModuleKind::Esm)]
|
||||
vec![referrer]
|
||||
};
|
||||
|
||||
let mut cli_options = CliOptions::new(
|
||||
|
|
|
@ -280,7 +280,7 @@ pub fn resolve_npm_package_reqs(graph: &ModuleGraph) -> Vec<NpmPackageReq> {
|
|||
let root_specifiers = graph
|
||||
.roots
|
||||
.iter()
|
||||
.map(|(url, _)| graph.resolve(url))
|
||||
.map(|url| graph.resolve(url))
|
||||
.collect::<Vec<_>>();
|
||||
let mut seen = HashSet::new();
|
||||
let mut specifier_graph = SpecifierTree::default();
|
||||
|
@ -551,7 +551,6 @@ fn cmp_package_req(a: &NpmPackageReq, b: &NpmPackageReq) -> Ordering {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use deno_graph::ModuleKind;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
use super::*;
|
||||
|
@ -965,16 +964,10 @@ mod tests {
|
|||
let analyzer = deno_graph::CapturingModuleAnalyzer::default();
|
||||
let graph = deno_graph::create_graph(
|
||||
vec![
|
||||
(
|
||||
ModuleSpecifier::parse("file:///dev/local_module_a/mod.ts").unwrap(),
|
||||
ModuleKind::Esm,
|
||||
),
|
||||
(
|
||||
// test redirect at root
|
||||
ModuleSpecifier::parse("https://deno.land/x/module_redirect/mod.ts")
|
||||
.unwrap(),
|
||||
ModuleKind::Esm,
|
||||
),
|
||||
ModuleSpecifier::parse("file:///dev/local_module_a/mod.ts").unwrap(),
|
||||
// test redirect at root
|
||||
ModuleSpecifier::parse("https://deno.land/x/module_redirect/mod.ts")
|
||||
.unwrap(),
|
||||
],
|
||||
&mut loader,
|
||||
deno_graph::GraphOptions {
|
||||
|
|
|
@ -52,7 +52,6 @@ use deno_graph::source::CacheInfo;
|
|||
use deno_graph::source::LoadFuture;
|
||||
use deno_graph::source::Loader;
|
||||
use deno_graph::source::Resolver;
|
||||
use deno_graph::ModuleKind;
|
||||
use deno_graph::Resolved;
|
||||
use deno_runtime::deno_broadcast_channel::InMemoryBroadcastChannel;
|
||||
use deno_runtime::deno_node::NodeResolutionMode;
|
||||
|
@ -330,10 +329,6 @@ impl ProcState {
|
|||
let has_root_npm_specifier = roots.iter().any(|r| {
|
||||
r.scheme() == "npm" && NpmPackageReference::from_specifier(r).is_ok()
|
||||
});
|
||||
let roots = roots
|
||||
.into_iter()
|
||||
.map(|s| (s, ModuleKind::Esm))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if !has_root_npm_specifier {
|
||||
let graph_data = self.graph_data.read();
|
||||
|
@ -451,11 +446,10 @@ impl ProcState {
|
|||
drop(_pb_clear_guard);
|
||||
|
||||
// type check if necessary
|
||||
let is_std_node = roots.len() == 1 && roots[0].0 == *node::MODULE_ALL_URL;
|
||||
let is_std_node = roots.len() == 1 && roots[0] == *node::MODULE_ALL_URL;
|
||||
if self.options.type_check_mode() != TypeCheckMode::None && !is_std_node {
|
||||
log::debug!("Type checking.");
|
||||
let maybe_config_specifier = self.options.maybe_config_file_specifier();
|
||||
let roots = roots.clone();
|
||||
let options = check::CheckOptions {
|
||||
type_check_mode: self.options.type_check_mode(),
|
||||
debug: self.options.log_level() == Some(log::Level::Debug),
|
||||
|
@ -466,7 +460,7 @@ impl ProcState {
|
|||
.ts_config,
|
||||
log_checks: true,
|
||||
reload: self.options.reload_flag()
|
||||
&& !roots.iter().all(|r| reload_exclusions.contains(&r.0)),
|
||||
&& !roots.iter().all(|r| reload_exclusions.contains(r)),
|
||||
};
|
||||
let check_cache =
|
||||
TypeCheckCache::new(&self.dir.type_checking_cache_db_file_path());
|
||||
|
@ -530,7 +524,7 @@ impl ProcState {
|
|||
}
|
||||
|
||||
let node_std_graph = self
|
||||
.create_graph(vec![(node::MODULE_ALL_URL.clone(), ModuleKind::Esm)])
|
||||
.create_graph(vec![node::MODULE_ALL_URL.clone()])
|
||||
.await?;
|
||||
self.graph_data.write().add_graph(&node_std_graph);
|
||||
self.node_std_graph_prepared.store(true, Ordering::Relaxed);
|
||||
|
@ -636,9 +630,7 @@ impl ProcState {
|
|||
let specifier = self
|
||||
.maybe_resolver
|
||||
.as_ref()
|
||||
.and_then(|resolver| {
|
||||
resolver.resolve(specifier, &referrer).to_result().ok()
|
||||
})
|
||||
.and_then(|resolver| resolver.resolve(specifier, &referrer).ok())
|
||||
.or_else(|| ModuleSpecifier::parse(specifier).ok());
|
||||
if let Some(specifier) = specifier {
|
||||
if let Ok(reference) = NpmPackageReference::from_specifier(&specifier) {
|
||||
|
@ -655,7 +647,7 @@ impl ProcState {
|
|||
}
|
||||
|
||||
if let Some(resolver) = &self.maybe_resolver {
|
||||
resolver.resolve(specifier, &referrer).to_result()
|
||||
resolver.resolve(specifier, &referrer)
|
||||
} else {
|
||||
deno_core::resolve_import(specifier, referrer.as_str())
|
||||
.map_err(|err| err.into())
|
||||
|
@ -705,7 +697,7 @@ impl ProcState {
|
|||
|
||||
pub async fn create_graph(
|
||||
&self,
|
||||
roots: Vec<(ModuleSpecifier, ModuleKind)>,
|
||||
roots: Vec<ModuleSpecifier>,
|
||||
) -> Result<deno_graph::ModuleGraph, AnyError> {
|
||||
let mut cache = self.create_graph_loader();
|
||||
self.create_graph_with_loader(roots, &mut cache).await
|
||||
|
@ -713,7 +705,7 @@ impl ProcState {
|
|||
|
||||
pub async fn create_graph_with_loader(
|
||||
&self,
|
||||
roots: Vec<(ModuleSpecifier, ModuleKind)>,
|
||||
roots: Vec<ModuleSpecifier>,
|
||||
loader: &mut dyn Loader,
|
||||
) -> Result<deno_graph::ModuleGraph, AnyError> {
|
||||
let maybe_imports = self.options.to_maybe_imports()?;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
|
||||
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::resolve_import;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use deno_graph::source::ResolveResponse;
|
||||
use deno_graph::source::Resolver;
|
||||
use deno_graph::source::DEFAULT_JSX_IMPORT_SOURCE_MODULE;
|
||||
use import_map::ImportMap;
|
||||
|
@ -63,19 +63,13 @@ impl Resolver for CliResolver {
|
|||
&self,
|
||||
specifier: &str,
|
||||
referrer: &ModuleSpecifier,
|
||||
) -> ResolveResponse {
|
||||
) -> Result<ModuleSpecifier, AnyError> {
|
||||
if let Some(import_map) = &self.maybe_import_map {
|
||||
match import_map.resolve(specifier, referrer) {
|
||||
Ok(resolved_specifier) => {
|
||||
ResolveResponse::Specifier(resolved_specifier)
|
||||
}
|
||||
Err(err) => ResolveResponse::Err(err.into()),
|
||||
}
|
||||
import_map
|
||||
.resolve(specifier, referrer)
|
||||
.map_err(|err| err.into())
|
||||
} else {
|
||||
match resolve_import(specifier, referrer.as_str()) {
|
||||
Ok(specifier) => ResolveResponse::Specifier(specifier),
|
||||
Err(err) => ResolveResponse::Err(err.into()),
|
||||
}
|
||||
resolve_import(specifier, referrer.as_str()).map_err(|err| err.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -150,7 +150,7 @@ impl ModuleLoader for EmbeddedModuleLoader {
|
|||
deno_core::resolve_import(specifier, referrer.as_str())
|
||||
.map_err(|err| err.into())
|
||||
},
|
||||
|r| r.resolve(specifier, &referrer).to_result(),
|
||||
|r| r.resolve(specifier, &referrer),
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
[WILDCARD]
|
||||
Bundle file:///[WILDCARD]/subdir/shebang_file.js
|
||||
#!/usr/bin/env -S deno run --allow-read
|
||||
// deno-fmt-ignore-file
|
||||
// deno-lint-ignore-file
|
||||
|
|
|
@ -4,7 +4,6 @@ use crate::args::BenchOptions;
|
|||
use crate::args::CliOptions;
|
||||
use crate::args::TypeCheckMode;
|
||||
use crate::colors;
|
||||
use crate::graph_util::contains_specifier;
|
||||
use crate::graph_util::graph_valid;
|
||||
use crate::ops;
|
||||
use crate::proc_state::ProcState;
|
||||
|
@ -24,7 +23,6 @@ use deno_core::futures::stream;
|
|||
use deno_core::futures::FutureExt;
|
||||
use deno_core::futures::StreamExt;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use deno_graph::ModuleKind;
|
||||
use deno_runtime::permissions::Permissions;
|
||||
use deno_runtime::permissions::PermissionsContainer;
|
||||
use deno_runtime::tokio_util::run_local;
|
||||
|
@ -548,19 +546,9 @@ pub async fn run_benchmarks_with_watch(
|
|||
let mut modules_to_reload = if files_changed {
|
||||
Vec::new()
|
||||
} else {
|
||||
bench_modules
|
||||
.iter()
|
||||
.map(|url| (url.clone(), ModuleKind::Esm))
|
||||
.collect()
|
||||
bench_modules.clone()
|
||||
};
|
||||
let graph = ps
|
||||
.create_graph(
|
||||
bench_modules
|
||||
.iter()
|
||||
.map(|s| (s.clone(), ModuleKind::Esm))
|
||||
.collect(),
|
||||
)
|
||||
.await?;
|
||||
let graph = ps.create_graph(bench_modules.clone()).await?;
|
||||
graph_valid(&graph, !no_check, ps.options.check_js())?;
|
||||
|
||||
// TODO(@kitsonk) - This should be totally derivable from the graph.
|
||||
|
@ -618,7 +606,7 @@ pub async fn run_benchmarks_with_watch(
|
|||
deno_core::resolve_url_or_path(&path.to_string_lossy()).ok()
|
||||
}) {
|
||||
if modules.contains(&path) {
|
||||
modules_to_reload.push((specifier, ModuleKind::Esm));
|
||||
modules_to_reload.push(specifier);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -649,7 +637,7 @@ pub async fn run_benchmarks_with_watch(
|
|||
})
|
||||
};
|
||||
|
||||
let operation = |modules_to_reload: Vec<(ModuleSpecifier, ModuleKind)>| {
|
||||
let operation = |modules_to_reload: Vec<ModuleSpecifier>| {
|
||||
let permissions = &permissions;
|
||||
let bench_options = &bench_options;
|
||||
ps.borrow_mut().reset_for_file_watcher();
|
||||
|
@ -659,7 +647,7 @@ pub async fn run_benchmarks_with_watch(
|
|||
let specifiers =
|
||||
collect_specifiers(&bench_options.files, is_supported_bench_path)?
|
||||
.into_iter()
|
||||
.filter(|specifier| contains_specifier(&modules_to_reload, specifier))
|
||||
.filter(|specifier| modules_to_reload.contains(specifier))
|
||||
.collect::<Vec<ModuleSpecifier>>();
|
||||
|
||||
check_specifiers(&ps, permissions.clone(), specifiers.clone()).await?;
|
||||
|
|
|
@ -134,7 +134,7 @@ fn bundle_module_graph(
|
|||
graph: &deno_graph::ModuleGraph,
|
||||
ps: &ProcState,
|
||||
) -> Result<deno_emit::BundleEmit, AnyError> {
|
||||
log::info!("{} {}", colors::green("Bundle"), graph.roots[0].0);
|
||||
log::info!("{} {}", colors::green("Bundle"), graph.roots[0]);
|
||||
|
||||
let ts_config_result = ps
|
||||
.options
|
||||
|
@ -145,29 +145,12 @@ fn bundle_module_graph(
|
|||
}
|
||||
}
|
||||
|
||||
let mut output = deno_emit::bundle_graph(
|
||||
deno_emit::bundle_graph(
|
||||
graph,
|
||||
deno_emit::BundleOptions {
|
||||
bundle_type: deno_emit::BundleType::Module,
|
||||
emit_options: ts_config_result.ts_config.into(),
|
||||
emit_ignore_directives: true,
|
||||
},
|
||||
)?;
|
||||
|
||||
// todo(https://github.com/denoland/deno_emit/issues/85): move to deno_emit
|
||||
if let Some(shebang) = shebang_file(graph) {
|
||||
output.code = format!("{}\n{}", shebang, output.code);
|
||||
}
|
||||
|
||||
Ok(output)
|
||||
}
|
||||
|
||||
fn shebang_file(graph: &deno_graph::ModuleGraph) -> Option<String> {
|
||||
let source = graph.get(&graph.roots[0].0)?.maybe_source.as_ref()?;
|
||||
let first_line = source.lines().next()?;
|
||||
if first_line.starts_with("#!") {
|
||||
Some(first_line.to_string())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ use deno_ast::MediaType;
|
|||
use deno_ast::ModuleSpecifier;
|
||||
use deno_core::error::AnyError;
|
||||
use deno_core::parking_lot::RwLock;
|
||||
use deno_graph::ModuleKind;
|
||||
use deno_runtime::colors;
|
||||
use once_cell::sync::Lazy;
|
||||
use regex::Regex;
|
||||
|
@ -55,7 +54,7 @@ pub struct CheckResult {
|
|||
/// It is expected that it is determined if a check and/or emit is validated
|
||||
/// before the function is called.
|
||||
pub fn check(
|
||||
roots: &[(ModuleSpecifier, ModuleKind)],
|
||||
roots: &[ModuleSpecifier],
|
||||
graph_data: Arc<RwLock<GraphData>>,
|
||||
cache: &TypeCheckCache,
|
||||
npm_resolver: &NpmPackageResolver,
|
||||
|
@ -78,7 +77,7 @@ pub fn check(
|
|||
|
||||
let root_names = get_tsc_roots(&segment_graph_data, check_js);
|
||||
if options.log_checks {
|
||||
for (root, _) in roots {
|
||||
for root in roots {
|
||||
let root_str = root.as_str();
|
||||
// `$deno` specifiers are internal, don't print them.
|
||||
if !root_str.contains("$deno") {
|
||||
|
@ -92,7 +91,7 @@ pub fn check(
|
|||
let maybe_tsbuildinfo = if options.reload {
|
||||
None
|
||||
} else {
|
||||
cache.get_tsbuildinfo(&roots[0].0)
|
||||
cache.get_tsbuildinfo(&roots[0])
|
||||
};
|
||||
// to make tsc build info work, we need to consistently hash modules, so that
|
||||
// tsc can better determine if an emit is still valid or not, so we provide
|
||||
|
@ -137,7 +136,7 @@ pub fn check(
|
|||
};
|
||||
|
||||
if let Some(tsbuildinfo) = response.maybe_tsbuildinfo {
|
||||
cache.set_tsbuildinfo(&roots[0].0, &tsbuildinfo);
|
||||
cache.set_tsbuildinfo(&roots[0], &tsbuildinfo);
|
||||
}
|
||||
|
||||
if diagnostics.is_empty() {
|
||||
|
|
|
@ -14,7 +14,6 @@ use deno_core::anyhow::bail;
|
|||
use deno_core::error::AnyError;
|
||||
use deno_core::resolve_url_or_path;
|
||||
use deno_doc as doc;
|
||||
use deno_graph::ModuleKind;
|
||||
use deno_graph::ModuleSpecifier;
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
@ -42,7 +41,7 @@ pub async fn print_docs(
|
|||
);
|
||||
let analyzer = deno_graph::CapturingModuleAnalyzer::default();
|
||||
let graph = deno_graph::create_graph(
|
||||
vec![(source_file_specifier.clone(), ModuleKind::Esm)],
|
||||
vec![source_file_specifier.clone()],
|
||||
&mut loader,
|
||||
deno_graph::GraphOptions {
|
||||
is_dynamic: false,
|
||||
|
@ -78,9 +77,7 @@ pub async fn print_docs(
|
|||
// Save our fake file into file fetcher cache.
|
||||
ps.file_fetcher.insert_cached(root);
|
||||
|
||||
let graph = ps
|
||||
.create_graph(vec![(root_specifier.clone(), ModuleKind::Esm)])
|
||||
.await?;
|
||||
let graph = ps.create_graph(vec![root_specifier.clone()]).await?;
|
||||
let doc_parser = doc::DocParser::new(
|
||||
graph,
|
||||
doc_flags.private,
|
||||
|
|
|
@ -14,7 +14,6 @@ use deno_graph::Dependency;
|
|||
use deno_graph::Module;
|
||||
use deno_graph::ModuleGraph;
|
||||
use deno_graph::ModuleGraphError;
|
||||
use deno_graph::ModuleKind;
|
||||
use deno_graph::Resolved;
|
||||
use deno_runtime::colors;
|
||||
|
||||
|
@ -34,7 +33,7 @@ pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> {
|
|||
let ps = ProcState::build(flags).await?;
|
||||
if let Some(specifier) = info_flags.file {
|
||||
let specifier = resolve_url_or_path(&specifier)?;
|
||||
let graph = ps.create_graph(vec![(specifier, ModuleKind::Esm)]).await?;
|
||||
let graph = ps.create_graph(vec![specifier]).await?;
|
||||
|
||||
if info_flags.json {
|
||||
let mut json_graph = json!(graph);
|
||||
|
@ -395,7 +394,7 @@ impl<'a> GraphDisplayContext<'a> {
|
|||
);
|
||||
}
|
||||
|
||||
let root_specifier = self.graph.resolve(&self.graph.roots[0].0);
|
||||
let root_specifier = self.graph.resolve(&self.graph.roots[0]);
|
||||
match self.graph.try_get(&root_specifier) {
|
||||
Ok(Some(root)) => {
|
||||
if let Some(cache_info) = root.maybe_cache_info.as_ref() {
|
||||
|
|
|
@ -446,9 +446,7 @@ impl ReplSession {
|
|||
.proc_state
|
||||
.maybe_resolver
|
||||
.as_ref()
|
||||
.and_then(|resolver| {
|
||||
resolver.resolve(i, &self.referrer).to_result().ok()
|
||||
})
|
||||
.and_then(|resolver| resolver.resolve(i, &self.referrer).ok())
|
||||
.or_else(|| ModuleSpecifier::parse(i).ok())
|
||||
.and_then(|url| NpmPackageReference::from_specifier(&url).ok())
|
||||
})
|
||||
|
|
|
@ -7,7 +7,6 @@ use crate::args::TypeCheckMode;
|
|||
use crate::colors;
|
||||
use crate::display;
|
||||
use crate::file_fetcher::File;
|
||||
use crate::graph_util::contains_specifier;
|
||||
use crate::graph_util::graph_valid;
|
||||
use crate::ops;
|
||||
use crate::proc_state::ProcState;
|
||||
|
@ -32,7 +31,6 @@ use deno_core::futures::StreamExt;
|
|||
use deno_core::parking_lot::Mutex;
|
||||
use deno_core::url::Url;
|
||||
use deno_core::ModuleSpecifier;
|
||||
use deno_graph::ModuleKind;
|
||||
use deno_runtime::fmt_errors::format_js_error;
|
||||
use deno_runtime::ops::io::Stdio;
|
||||
use deno_runtime::ops::io::StdioPipe;
|
||||
|
@ -1374,19 +1372,9 @@ pub async fn run_tests_with_watch(
|
|||
let mut modules_to_reload = if files_changed {
|
||||
Vec::new()
|
||||
} else {
|
||||
test_modules
|
||||
.iter()
|
||||
.map(|url| (url.clone(), ModuleKind::Esm))
|
||||
.collect()
|
||||
test_modules.clone()
|
||||
};
|
||||
let graph = ps
|
||||
.create_graph(
|
||||
test_modules
|
||||
.iter()
|
||||
.map(|s| (s.clone(), ModuleKind::Esm))
|
||||
.collect(),
|
||||
)
|
||||
.await?;
|
||||
let graph = ps.create_graph(test_modules.clone()).await?;
|
||||
graph_valid(&graph, !no_check, ps.options.check_js())?;
|
||||
|
||||
// TODO(@kitsonk) - This should be totally derivable from the graph.
|
||||
|
@ -1445,7 +1433,7 @@ pub async fn run_tests_with_watch(
|
|||
deno_core::resolve_url_or_path(&path.to_string_lossy()).ok()
|
||||
}) {
|
||||
if modules.contains(&path) {
|
||||
modules_to_reload.push((specifier, ModuleKind::Esm));
|
||||
modules_to_reload.push(specifier);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -1476,7 +1464,7 @@ pub async fn run_tests_with_watch(
|
|||
})
|
||||
};
|
||||
|
||||
let operation = |modules_to_reload: Vec<(ModuleSpecifier, ModuleKind)>| {
|
||||
let operation = |modules_to_reload: Vec<ModuleSpecifier>| {
|
||||
let permissions = &permissions;
|
||||
let test_options = &test_options;
|
||||
ps.borrow_mut().reset_for_file_watcher();
|
||||
|
@ -1490,9 +1478,7 @@ pub async fn run_tests_with_watch(
|
|||
)
|
||||
.await?
|
||||
.into_iter()
|
||||
.filter(|(specifier, _)| {
|
||||
contains_specifier(&modules_to_reload, specifier)
|
||||
})
|
||||
.filter(|(specifier, _)| modules_to_reload.contains(specifier))
|
||||
.collect::<Vec<(ModuleSpecifier, TestMode)>>();
|
||||
|
||||
check_specifiers(&ps, permissions.clone(), specifiers_with_mode.clone())
|
||||
|
|
7
cli/tools/vendor/mod.rs
vendored
7
cli/tools/vendor/mod.rs
vendored
|
@ -268,11 +268,8 @@ async fn create_graph(
|
|||
let entry_points = flags
|
||||
.specifiers
|
||||
.iter()
|
||||
.map(|p| {
|
||||
let url = resolve_url_or_path(p)?;
|
||||
Ok((url, deno_graph::ModuleKind::Esm))
|
||||
})
|
||||
.collect::<Result<Vec<_>, AnyError>>()?;
|
||||
.map(|p| resolve_url_or_path(p))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
|
||||
ps.create_graph(entry_points).await
|
||||
}
|
||||
|
|
9
cli/tools/vendor/test.rs
vendored
9
cli/tools/vendor/test.rs
vendored
|
@ -17,7 +17,6 @@ use deno_graph::source::LoadFuture;
|
|||
use deno_graph::source::LoadResponse;
|
||||
use deno_graph::source::Loader;
|
||||
use deno_graph::ModuleGraph;
|
||||
use deno_graph::ModuleKind;
|
||||
use import_map::ImportMap;
|
||||
|
||||
use crate::cache::ParsedSourceCache;
|
||||
|
@ -214,11 +213,7 @@ impl VendorTestBuilder {
|
|||
|
||||
pub async fn build(&mut self) -> Result<VendorOutput, AnyError> {
|
||||
let output_dir = make_path("/vendor");
|
||||
let roots = self
|
||||
.entry_points
|
||||
.iter()
|
||||
.map(|s| (s.to_owned(), deno_graph::ModuleKind::Esm))
|
||||
.collect();
|
||||
let roots = self.entry_points.clone();
|
||||
let loader = self.loader.clone();
|
||||
let parsed_source_cache = ParsedSourceCache::new(None);
|
||||
let analyzer = parsed_source_cache.as_analyzer();
|
||||
|
@ -260,7 +255,7 @@ impl VendorTestBuilder {
|
|||
}
|
||||
|
||||
async fn build_test_graph(
|
||||
roots: Vec<(ModuleSpecifier, ModuleKind)>,
|
||||
roots: Vec<ModuleSpecifier>,
|
||||
original_import_map: Option<ImportMap>,
|
||||
mut loader: TestLoader,
|
||||
analyzer: &dyn deno_graph::ModuleAnalyzer,
|
||||
|
|
|
@ -863,7 +863,6 @@ mod tests {
|
|||
use crate::args::TsConfig;
|
||||
use deno_core::futures::future;
|
||||
use deno_core::OpState;
|
||||
use deno_graph::ModuleKind;
|
||||
use std::fs;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
|
@ -907,7 +906,7 @@ mod tests {
|
|||
let fixtures = test_util::testdata_path().join("tsc2");
|
||||
let mut loader = MockLoader { fixtures };
|
||||
let graph = deno_graph::create_graph(
|
||||
vec![(specifier, ModuleKind::Esm)],
|
||||
vec![specifier],
|
||||
&mut loader,
|
||||
deno_graph::GraphOptions {
|
||||
is_dynamic: false,
|
||||
|
@ -939,7 +938,7 @@ mod tests {
|
|||
let fixtures = test_util::testdata_path().join("tsc2");
|
||||
let mut loader = MockLoader { fixtures };
|
||||
let graph = deno_graph::create_graph(
|
||||
vec![(specifier.clone(), ModuleKind::Esm)],
|
||||
vec![specifier.clone()],
|
||||
&mut loader,
|
||||
deno_graph::GraphOptions {
|
||||
is_dynamic: false,
|
||||
|
|
Loading…
Reference in a new issue