summaryrefslogtreecommitdiff
path: root/cli/tools
diff options
context:
space:
mode:
Diffstat (limited to 'cli/tools')
-rw-r--r--cli/tools/bench/mod.rs4
-rw-r--r--cli/tools/bundle.rs4
-rw-r--r--cli/tools/check.rs60
-rw-r--r--cli/tools/compile.rs6
-rw-r--r--cli/tools/doc.rs9
-rw-r--r--cli/tools/info.rs3
-rw-r--r--cli/tools/lint/mod.rs4
-rw-r--r--cli/tools/registry/mod.rs27
-rw-r--r--cli/tools/test/mod.rs4
-rw-r--r--cli/tools/vendor/mod.rs4
10 files changed, 74 insertions, 51 deletions
diff --git a/cli/tools/bench/mod.rs b/cli/tools/bench/mod.rs
index 146c9e8bd..2f0d59f49 100644
--- a/cli/tools/bench/mod.rs
+++ b/cli/tools/bench/mod.rs
@@ -511,7 +511,7 @@ pub async fn run_benchmarks_with_watch(
}
let graph_kind = cli_options.type_check_mode().as_graph_kind();
- let module_graph_builder = factory.module_graph_builder().await?;
+ let module_graph_creator = factory.module_graph_creator().await?;
let module_load_preparer = factory.module_load_preparer().await?;
let bench_modules = collect_specifiers(
@@ -525,7 +525,7 @@ pub async fn run_benchmarks_with_watch(
let permissions =
Permissions::from_options(&cli_options.permissions_options())?;
- let graph = module_graph_builder
+ let graph = module_graph_creator
.create_graph(graph_kind, bench_modules.clone())
.await?;
graph_valid_with_cli_options(
diff --git a/cli/tools/bundle.rs b/cli/tools/bundle.rs
index 4099ad41a..c0b1ce31b 100644
--- a/cli/tools/bundle.rs
+++ b/cli/tools/bundle.rs
@@ -62,10 +62,10 @@ async fn bundle_action(
let cli_options = factory.cli_options();
let module_specifier = cli_options.resolve_main_module()?;
log::debug!(">>>>> bundle START");
- let module_graph_builder = factory.module_graph_builder().await?;
+ let module_graph_creator = factory.module_graph_creator().await?;
let cli_options = factory.cli_options();
- let graph = module_graph_builder
+ let graph = module_graph_creator
.create_graph_and_maybe_check(vec![module_specifier.clone()])
.await?;
diff --git a/cli/tools/check.rs b/cli/tools/check.rs
index 6e14d09f5..08fc6f087 100644
--- a/cli/tools/check.rs
+++ b/cli/tools/check.rs
@@ -22,6 +22,8 @@ use crate::args::TypeCheckMode;
use crate::cache::Caches;
use crate::cache::FastInsecureHasher;
use crate::cache::TypeCheckCache;
+use crate::graph_util::BuildFastCheckGraphOptions;
+use crate::graph_util::ModuleGraphBuilder;
use crate::npm::CliNpmResolver;
use crate::tsc;
use crate::tsc::Diagnostics;
@@ -30,6 +32,11 @@ use crate::version;
/// Options for performing a check of a module graph. Note that the decision to
/// emit or not is determined by the `ts_config` settings.
pub struct CheckOptions {
+ /// Whether to build the fast check type graph if necessary.
+ ///
+ /// Note: For perf reasons, the fast check type graph is only
+ /// built if type checking is necessary.
+ pub build_fast_check_graph: bool,
/// Default type library to type check with.
pub lib: TsTypeLib,
/// Whether to log about any ignored compiler options.
@@ -42,6 +49,7 @@ pub struct CheckOptions {
pub struct TypeChecker {
caches: Arc<Caches>,
cli_options: Arc<CliOptions>,
+ module_graph_builder: Arc<ModuleGraphBuilder>,
node_resolver: Arc<NodeResolver>,
npm_resolver: Arc<dyn CliNpmResolver>,
}
@@ -50,12 +58,14 @@ impl TypeChecker {
pub fn new(
caches: Arc<Caches>,
cli_options: Arc<CliOptions>,
+ module_graph_builder: Arc<ModuleGraphBuilder>,
node_resolver: Arc<NodeResolver>,
npm_resolver: Arc<dyn CliNpmResolver>,
) -> Self {
Self {
caches,
cli_options,
+ module_graph_builder,
node_resolver,
npm_resolver,
}
@@ -67,12 +77,12 @@ impl TypeChecker {
/// before the function is called.
pub async fn check(
&self,
- graph: Arc<ModuleGraph>,
+ graph: ModuleGraph,
options: CheckOptions,
- ) -> Result<(), AnyError> {
- let diagnostics = self.check_diagnostics(graph, options).await?;
+ ) -> Result<Arc<ModuleGraph>, AnyError> {
+ let (graph, diagnostics) = self.check_diagnostics(graph, options).await?;
if diagnostics.is_empty() {
- Ok(())
+ Ok(graph)
} else {
Err(diagnostics.into())
}
@@ -84,11 +94,11 @@ impl TypeChecker {
/// before the function is called.
pub async fn check_diagnostics(
&self,
- graph: Arc<ModuleGraph>,
+ mut graph: ModuleGraph,
options: CheckOptions,
- ) -> Result<Diagnostics, AnyError> {
+ ) -> Result<(Arc<ModuleGraph>, Diagnostics), AnyError> {
if graph.roots.is_empty() {
- return Ok(Default::default());
+ return Ok((graph.into(), Default::default()));
}
// node built-in specifiers use the @types/node package to determine
@@ -112,9 +122,6 @@ impl TypeChecker {
let ts_config = ts_config_result.ts_config;
let type_check_mode = self.cli_options.type_check_mode();
- let debug = self.cli_options.log_level() == Some(log::Level::Debug);
- let cache = TypeCheckCache::new(self.caches.type_checking_cache_db());
- let check_js = ts_config.get_check_js();
let maybe_check_hash = match self.npm_resolver.check_state_hash() {
Some(npm_check_hash) => {
match get_check_hash(
@@ -123,7 +130,9 @@ impl TypeChecker {
type_check_mode,
&ts_config,
) {
- CheckHashResult::NoFiles => return Ok(Default::default()),
+ CheckHashResult::NoFiles => {
+ return Ok((graph.into(), Default::default()))
+ }
CheckHashResult::Hash(hash) => Some(hash),
}
}
@@ -131,10 +140,12 @@ impl TypeChecker {
};
// do not type check if we know this is type checked
+ let cache = TypeCheckCache::new(self.caches.type_checking_cache_db());
if !options.reload {
if let Some(check_hash) = maybe_check_hash {
if cache.has_check_hash(check_hash) {
- return Ok(Default::default());
+ log::debug!("Already type checked.");
+ return Ok((graph.into(), Default::default()));
}
}
}
@@ -144,7 +155,7 @@ impl TypeChecker {
log::info!("{} {}", colors::green("Check"), root_str);
}
- let root_names = get_tsc_roots(&graph, check_js);
+ let check_js = ts_config.get_check_js();
// while there might be multiple roots, we can't "merge" the build info, so we
// try to retrieve the build info for first root, which is the most common use
// case.
@@ -161,9 +172,21 @@ impl TypeChecker {
.write_str(version::deno())
.finish();
+ // add fast check to the graph before getting the roots
+ if options.build_fast_check_graph {
+ self.module_graph_builder.build_fast_check_graph(
+ &mut graph,
+ BuildFastCheckGraphOptions {
+ workspace_fast_check: false,
+ },
+ )?;
+ }
+
+ let root_names = get_tsc_roots(&graph, check_js);
+ let graph = Arc::new(graph);
let response = tsc::exec(tsc::Request {
config: ts_config,
- debug,
+ debug: self.cli_options.log_level() == Some(log::Level::Debug),
graph: graph.clone(),
hash_data,
maybe_npm: Some(tsc::RequestNpmState {
@@ -212,7 +235,7 @@ impl TypeChecker {
log::debug!("{}", response.stats);
- Ok(diagnostics)
+ Ok((graph, diagnostics))
}
}
@@ -277,12 +300,7 @@ fn get_check_hash(
}
hasher.write_str(module.specifier.as_str());
- hasher.write_str(
- module
- .fast_check_module()
- .map(|s| s.source.as_ref())
- .unwrap_or(&module.source),
- );
+ hasher.write_str(&module.source);
}
Module::Node(_) => {
// the @types/node package will be in the resolved
diff --git a/cli/tools/compile.rs b/cli/tools/compile.rs
index 70baed669..0a5e75f9a 100644
--- a/cli/tools/compile.rs
+++ b/cli/tools/compile.rs
@@ -24,7 +24,7 @@ pub async fn compile(
) -> Result<(), AnyError> {
let factory = CliFactory::from_flags(flags).await?;
let cli_options = factory.cli_options();
- let module_graph_builder = factory.module_graph_builder().await?;
+ let module_graph_creator = factory.module_graph_creator().await?;
let parsed_source_cache = factory.parsed_source_cache();
let binary_writer = factory.create_compile_binary_writer().await?;
let module_specifier = cli_options.resolve_main_module()?;
@@ -56,7 +56,7 @@ pub async fn compile(
.await?;
let graph = Arc::try_unwrap(
- module_graph_builder
+ module_graph_creator
.create_graph_and_maybe_check(module_roots.clone())
.await?,
)
@@ -65,7 +65,7 @@ pub async fn compile(
// In this case, the previous graph creation did type checking, which will
// create a module graph with types information in it. We don't want to
// store that in the eszip so create a code only module graph from scratch.
- module_graph_builder
+ module_graph_creator
.create_graph(GraphKind::CodeOnly, module_roots)
.await?
} else {
diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs
index 5044e73d3..0b7b26e31 100644
--- a/cli/tools/doc.rs
+++ b/cli/tools/doc.rs
@@ -23,6 +23,7 @@ use deno_graph::GraphKind;
use deno_graph::ModuleAnalyzer;
use deno_graph::ModuleParser;
use deno_graph::ModuleSpecifier;
+use doc::html::ShortPath;
use doc::DocDiagnostic;
use indexmap::IndexMap;
use std::collections::BTreeMap;
@@ -89,7 +90,7 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
.await?
}
DocSourceFileFlag::Paths(ref source_files) => {
- let module_graph_builder = factory.module_graph_builder().await?;
+ let module_graph_creator = factory.module_graph_creator().await?;
let maybe_lockfile = factory.maybe_lockfile();
let module_specifiers = collect_specifiers(
@@ -103,7 +104,7 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> {
},
|_, _| true,
)?;
- let graph = module_graph_builder
+ let graph = module_graph_creator
.create_graph(GraphKind::TypesOnly, module_specifiers.clone())
.await?;
@@ -211,9 +212,9 @@ impl deno_doc::html::HrefResolver for DocResolver {
fn resolve_usage(
&self,
_current_specifier: &ModuleSpecifier,
- current_file: Option<&str>,
+ current_file: Option<&ShortPath>,
) -> Option<String> {
- current_file.map(|f| f.to_string())
+ current_file.map(|f| f.as_str().to_string())
}
fn resolve_source(&self, location: &deno_doc::Location) -> Option<String> {
diff --git a/cli/tools/info.rs b/cli/tools/info.rs
index 0ad7d8920..ca08003ad 100644
--- a/cli/tools/info.rs
+++ b/cli/tools/info.rs
@@ -40,6 +40,7 @@ pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> {
let cli_options = factory.cli_options();
if let Some(specifier) = info_flags.file {
let module_graph_builder = factory.module_graph_builder().await?;
+ let module_graph_creator = factory.module_graph_creator().await?;
let npm_resolver = factory.npm_resolver().await?;
let maybe_lockfile = factory.maybe_lockfile();
let maybe_imports_map = factory.maybe_import_map().await?;
@@ -63,7 +64,7 @@ pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> {
let mut loader = module_graph_builder.create_graph_loader();
loader.enable_loading_cache_info(); // for displaying the cache information
- let graph = module_graph_builder
+ let graph = module_graph_creator
.create_graph_with_loader(GraphKind::All, vec![specifier], &mut loader)
.await?;
diff --git a/cli/tools/lint/mod.rs b/cli/tools/lint/mod.rs
index e4a88f91c..1240b391f 100644
--- a/cli/tools/lint/mod.rs
+++ b/cli/tools/lint/mod.rs
@@ -178,13 +178,13 @@ async fn lint_files(
let members = config_file.to_workspace_members()?;
let has_error = has_error.clone();
let reporter_lock = reporter_lock.clone();
- let module_graph_builder = factory.module_graph_builder().await?.clone();
+ let module_graph_creator = factory.module_graph_creator().await?.clone();
let path_urls = paths
.iter()
.filter_map(|p| ModuleSpecifier::from_file_path(p).ok())
.collect::<HashSet<_>>();
futures.push(deno_core::unsync::spawn(async move {
- let graph = module_graph_builder.create_publish_graph(&members).await?;
+ let graph = module_graph_creator.create_publish_graph(&members).await?;
// todo(dsherret): this isn't exactly correct as linting isn't properly
// setup to handle workspaces. Iterating over the workspace members
// should be done at a higher level because it also needs to take into
diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs
index 37bd3616b..951ac4944 100644
--- a/cli/tools/registry/mod.rs
+++ b/cli/tools/registry/mod.rs
@@ -31,7 +31,7 @@ use crate::args::PublishFlags;
use crate::cache::LazyGraphSourceParser;
use crate::cache::ParsedSourceCache;
use crate::factory::CliFactory;
-use crate::graph_util::ModuleGraphBuilder;
+use crate::graph_util::ModuleGraphCreator;
use crate::http_util::HttpClient;
use crate::tools::check::CheckOptions;
use crate::tools::lint::no_slow_types;
@@ -656,7 +656,7 @@ async fn prepare_packages_for_publishing(
import_map: Arc<ImportMap>,
) -> Result<PreparePackagesData, AnyError> {
let members = deno_json.to_workspace_members()?;
- let module_graph_builder = cli_factory.module_graph_builder().await?.as_ref();
+ let module_graph_creator = cli_factory.module_graph_creator().await?.as_ref();
let source_cache = cli_factory.parsed_source_cache();
let type_checker = cli_factory.type_checker().await?;
let cli_options = cli_factory.cli_options();
@@ -667,7 +667,7 @@ async fn prepare_packages_for_publishing(
// create the module graph
let graph = build_and_check_graph_for_publish(
- module_graph_builder,
+ module_graph_creator,
type_checker,
cli_options,
allow_slow_types,
@@ -715,15 +715,14 @@ async fn prepare_packages_for_publishing(
}
async fn build_and_check_graph_for_publish(
- module_graph_builder: &ModuleGraphBuilder,
+ module_graph_creator: &ModuleGraphCreator,
type_checker: &TypeChecker,
cli_options: &CliOptions,
allow_slow_types: bool,
diagnostics_collector: &PublishDiagnosticsCollector,
packages: &[WorkspaceMemberConfig],
) -> Result<Arc<deno_graph::ModuleGraph>, deno_core::anyhow::Error> {
- let graph =
- Arc::new(module_graph_builder.create_publish_graph(packages).await?);
+ let graph = module_graph_creator.create_publish_graph(packages).await?;
graph.valid()?;
// todo(dsherret): move to lint rule
@@ -740,6 +739,7 @@ async fn build_and_check_graph_for_publish(
),
colors::yellow("Warning"),
);
+ Ok(Arc::new(graph))
} else {
log::info!("Checking for slow types in the public API...");
let mut any_pkg_had_diagnostics = false;
@@ -755,12 +755,16 @@ async fn build_and_check_graph_for_publish(
}
}
- if !any_pkg_had_diagnostics {
- // this is a temporary measure until we know that fast check is reliable and stable
- let check_diagnostics = type_checker
+ if any_pkg_had_diagnostics {
+ Ok(Arc::new(graph))
+ } else {
+ // fast check passed, type check the output as a temporary measure
+ // until we know that it's reliable and stable
+ let (graph, check_diagnostics) = type_checker
.check_diagnostics(
- graph.clone(),
+ graph,
CheckOptions {
+ build_fast_check_graph: false, // already built
lib: cli_options.ts_type_lib_window(),
log_ignored_options: false,
reload: cli_options.reload_flag(),
@@ -778,10 +782,9 @@ async fn build_and_check_graph_for_publish(
check_diagnostics
);
}
+ Ok(graph)
}
}
-
- Ok(graph)
}
pub async fn publish(
diff --git a/cli/tools/test/mod.rs b/cli/tools/test/mod.rs
index 6e22b894a..b088cf7a3 100644
--- a/cli/tools/test/mod.rs
+++ b/cli/tools/test/mod.rs
@@ -1490,7 +1490,7 @@ pub async fn run_tests_with_watch(
let graph_kind = cli_options.type_check_mode().as_graph_kind();
let log_level = cli_options.log_level();
let cli_options = cli_options.clone();
- let module_graph_builder = factory.module_graph_builder().await?;
+ let module_graph_creator = factory.module_graph_creator().await?;
let file_fetcher = factory.file_fetcher()?;
let test_modules = if test_options.doc {
collect_specifiers(test_options.files.clone(), |p, _| {
@@ -1505,7 +1505,7 @@ pub async fn run_tests_with_watch(
let permissions =
Permissions::from_options(&cli_options.permissions_options())?;
- let graph = module_graph_builder
+ let graph = module_graph_creator
.create_graph(graph_kind, test_modules.clone())
.await?;
graph_valid_with_cli_options(
diff --git a/cli/tools/vendor/mod.rs b/cli/tools/vendor/mod.rs
index e2c04305a..f168f84a2 100644
--- a/cli/tools/vendor/mod.rs
+++ b/cli/tools/vendor/mod.rs
@@ -51,12 +51,12 @@ pub async fn vendor(
let entry_points =
resolve_entry_points(&vendor_flags, cli_options.initial_cwd())?;
let jsx_import_source = cli_options.to_maybe_jsx_import_source_config()?;
- let module_graph_builder = factory.module_graph_builder().await?.clone();
+ let module_graph_creator = factory.module_graph_creator().await?.clone();
let output = build::build(build::BuildInput {
entry_points,
build_graph: move |entry_points| {
async move {
- module_graph_builder
+ module_graph_creator
.create_graph(GraphKind::All, entry_points)
.await
}