1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-01-21 13:00:36 -05:00

refactor: deno_graph 0.43 upgrade (#17692)

This commit is contained in:
David Sherret 2023-02-09 22:00:23 -05:00 committed by GitHub
parent 8da235adce
commit b3e88e0681
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 1321 additions and 1570 deletions

1237
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -42,7 +42,7 @@ repository = "https://github.com/denoland/deno"
[workspace.dependencies] [workspace.dependencies]
v8 = { version = "0.62.2", default-features = false } v8 = { version = "0.62.2", default-features = false }
deno_ast = { version = "0.23.2", features = ["transpiling"] } deno_ast = { version = "0.24.0", features = ["transpiling"] }
deno_core = { version = "0.171.0", path = "./core" } deno_core = { version = "0.171.0", path = "./core" }
deno_ops = { version = "0.49.0", path = "./ops" } deno_ops = { version = "0.49.0", path = "./ops" }
@ -146,6 +146,11 @@ incremental = true
lto = true lto = true
opt-level = 'z' # Optimize for size opt-level = 'z' # Optimize for size
# Build release with debug symbols: cargo build --profile=release-with-debug
[profile.release-with-debug]
inherits = "release"
debug = true
# NB: the `bench` and `release` profiles must remain EXACTLY the same. # NB: the `bench` and `release` profiles must remain EXACTLY the same.
[profile.bench] [profile.bench]
codegen-units = 1 codegen-units = 1

View file

@ -44,10 +44,10 @@ winres.workspace = true
[dependencies] [dependencies]
deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "dep_graph", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] } deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "dep_graph", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] }
deno_core.workspace = true deno_core.workspace = true
deno_doc = "0.53.0" deno_doc = "0.55.0"
deno_emit = "0.14.0" deno_emit = "0.15.0"
deno_graph = "0.42.0" deno_graph = "0.43.0"
deno_lint = { version = "0.37.0", features = ["docs"] } deno_lint = { version = "0.38.0", features = ["docs"] }
deno_lockfile.workspace = true deno_lockfile.workspace = true
deno_runtime.workspace = true deno_runtime.workspace = true
deno_task_shell = "0.8.1" deno_task_shell = "0.8.1"
@ -66,10 +66,10 @@ data-url.workspace = true
dissimilar = "=1.0.4" dissimilar = "=1.0.4"
dprint-plugin-json = "=0.17.0" dprint-plugin-json = "=0.17.0"
dprint-plugin-markdown = "=0.15.2" dprint-plugin-markdown = "=0.15.2"
dprint-plugin-typescript = "=0.81.1" dprint-plugin-typescript = "=0.83.0"
encoding_rs.workspace = true encoding_rs.workspace = true
env_logger = "=0.9.0" env_logger = "=0.9.0"
eszip = "=0.33.0" eszip = "=0.35.0"
fancy-regex = "=0.10.0" fancy-regex = "=0.10.0"
flate2.workspace = true flate2.workspace = true
http.workspace = true http.workspace = true

View file

@ -26,7 +26,7 @@ use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
pub type MaybeImportsResult = pub type MaybeImportsResult =
Result<Option<Vec<(ModuleSpecifier, Vec<String>)>>, AnyError>; Result<Vec<deno_graph::ReferrerImports>, AnyError>;
#[derive(Hash)] #[derive(Hash)]
pub struct JsxImportSourceConfig { pub struct JsxImportSourceConfig {
@ -765,7 +765,7 @@ impl ConfigFile {
if let Some(value) = self.json.compiler_options.as_ref() { if let Some(value) = self.json.compiler_options.as_ref() {
value value
} else { } else {
return Ok(None); return Ok(Vec::new());
}; };
let compiler_options: CompilerOptions = let compiler_options: CompilerOptions =
serde_json::from_value(compiler_options_value.clone())?; serde_json::from_value(compiler_options_value.clone())?;
@ -774,9 +774,9 @@ impl ConfigFile {
} }
if !imports.is_empty() { if !imports.is_empty() {
let referrer = self.specifier.clone(); let referrer = self.specifier.clone();
Ok(Some(vec![(referrer, imports)])) Ok(vec![deno_graph::ReferrerImports { referrer, imports }])
} else { } else {
Ok(None) Ok(Vec::new())
} }
} }

View file

@ -690,16 +690,10 @@ impl CliOptions {
/// Return any imports that should be brought into the scope of the module /// Return any imports that should be brought into the scope of the module
/// graph. /// graph.
pub fn to_maybe_imports(&self) -> MaybeImportsResult { pub fn to_maybe_imports(&self) -> MaybeImportsResult {
let mut imports = Vec::new();
if let Some(config_file) = &self.maybe_config_file { if let Some(config_file) = &self.maybe_config_file {
if let Some(config_imports) = config_file.to_maybe_imports()? { config_file.to_maybe_imports()
imports.extend(config_imports);
}
}
if imports.is_empty() {
Ok(None)
} else { } else {
Ok(Some(imports)) Ok(Vec::new())
} }
} }

View file

@ -10,6 +10,7 @@ const path = new URL("./deno_http_flash_ops.js", import.meta.url).pathname;
const cpus = navigator.hardwareConcurrency / 2; const cpus = navigator.hardwareConcurrency / 2;
const processes = new Array(cpus); const processes = new Array(cpus);
for (let i = 0; i < cpus; i++) { for (let i = 0; i < cpus; i++) {
// deno-lint-ignore no-deprecated-deno-api
const proc = Deno.run({ const proc = Deno.run({
cmd: [executable, "run", "-A", "--unstable", path, Deno.args[0]], cmd: [executable, "run", "-A", "--unstable", path, Deno.args[0]],
}); });

View file

@ -10,6 +10,7 @@ const path = new URL("./deno_http_flash.js", import.meta.url).pathname;
const cpus = navigator.hardwareConcurrency / 2; const cpus = navigator.hardwareConcurrency / 2;
const processes = new Array(cpus); const processes = new Array(cpus);
for (let i = 0; i < cpus; i++) { for (let i = 0; i < cpus; i++) {
// deno-lint-ignore no-deprecated-deno-api
const proc = Deno.run({ const proc = Deno.run({
cmd: [executable, "run", "-A", "--unstable", path, Deno.args[0]], cmd: [executable, "run", "-A", "--unstable", path, Deno.args[0]],
}); });

View file

@ -25,15 +25,17 @@ fn get_diagnostic_class(_: &Diagnostic) -> &'static str {
fn get_module_graph_error_class(err: &ModuleGraphError) -> &'static str { fn get_module_graph_error_class(err: &ModuleGraphError) -> &'static str {
match err { match err {
ModuleGraphError::LoadingErr(_, err) => get_error_class_name(err.as_ref()), ModuleGraphError::LoadingErr(_, _, err) => {
get_error_class_name(err.as_ref())
}
ModuleGraphError::InvalidTypeAssertion { .. } => "SyntaxError", ModuleGraphError::InvalidTypeAssertion { .. } => "SyntaxError",
ModuleGraphError::ParseErr(_, diagnostic) => { ModuleGraphError::ParseErr(_, diagnostic) => {
get_diagnostic_class(diagnostic) get_diagnostic_class(diagnostic)
} }
ModuleGraphError::ResolutionError(err) => get_resolution_error_class(err), ModuleGraphError::ResolutionError(err) => get_resolution_error_class(err),
ModuleGraphError::UnsupportedMediaType(_, _) ModuleGraphError::UnsupportedMediaType { .. }
| ModuleGraphError::UnsupportedImportAssertionType(_, _) => "TypeError", | ModuleGraphError::UnsupportedImportAssertionType { .. } => "TypeError",
ModuleGraphError::Missing(_) => "NotFound", ModuleGraphError::Missing(_, _) => "NotFound",
} }
} }

View file

@ -1,16 +1,14 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use crate::args::CliOptions;
use crate::args::Lockfile; use crate::args::Lockfile;
use crate::args::TsConfigType; use crate::args::TsConfigType;
use crate::args::TsTypeLib;
use crate::args::TypeCheckMode; use crate::args::TypeCheckMode;
use crate::cache; use crate::cache;
use crate::cache::TypeCheckCache; use crate::cache::TypeCheckCache;
use crate::colors; use crate::colors;
use crate::errors::get_error_class_name; use crate::errors::get_error_class_name;
use crate::npm::resolve_graph_npm_info; use crate::npm::resolve_graph_npm_info;
use crate::npm::NpmPackageReference;
use crate::npm::NpmPackageReq;
use crate::proc_state::ProcState; use crate::proc_state::ProcState;
use crate::resolver::CliResolver; use crate::resolver::CliResolver;
use crate::tools::check; use crate::tools::check;
@ -18,470 +16,61 @@ use crate::tools::check;
use deno_core::anyhow::bail; use deno_core::anyhow::bail;
use deno_core::error::custom_error; use deno_core::error::custom_error;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::parking_lot::RwLock;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use deno_graph::Dependency;
use deno_graph::GraphImport;
use deno_graph::MediaType;
use deno_graph::ModuleGraph; use deno_graph::ModuleGraph;
use deno_graph::ModuleGraphError; use deno_graph::ModuleGraphError;
use deno_graph::ModuleKind;
use deno_graph::Range;
use deno_graph::ResolutionError; use deno_graph::ResolutionError;
use deno_graph::Resolved;
use deno_graph::SpecifierError; use deno_graph::SpecifierError;
use deno_runtime::permissions::PermissionsContainer; use deno_runtime::permissions::PermissionsContainer;
use import_map::ImportMapError; use import_map::ImportMapError;
use std::collections::BTreeMap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::sync::Arc; use std::sync::Arc;
#[derive(Debug, Clone)] /// Check if `roots` and their deps are available. Returns `Ok(())` if
#[allow(clippy::large_enum_variant)] /// so. Returns `Err(_)` if there is a known module graph or resolution
pub enum ModuleEntry { /// error statically reachable from `roots` and not a dynamic import.
Module { pub fn graph_valid_with_cli_options(
code: Arc<str>, graph: &ModuleGraph,
dependencies: BTreeMap<String, Dependency>, roots: &[ModuleSpecifier],
media_type: MediaType, options: &CliOptions,
/// A set of type libs that the module has passed a type check with this ) -> Result<(), AnyError> {
/// session. This would consist of window, worker or both. graph_valid(
checked_libs: HashSet<TsTypeLib>, graph,
maybe_types: Option<Resolved>, roots,
}, deno_graph::WalkOptions {
Error(ModuleGraphError), follow_dynamic: false,
Redirect(ModuleSpecifier), follow_type_only: options.type_check_mode() != TypeCheckMode::None,
check_js: options.check_js(),
},
)
} }
/// Composes data from potentially many `ModuleGraph`s. /// Check if `roots` and their deps are available. Returns `Ok(())` if
#[derive(Debug, Default)] /// so. Returns `Err(_)` if there is a known module graph or resolution
pub struct GraphData { /// error statically reachable from `roots`.
modules: HashMap<ModuleSpecifier, ModuleEntry>, ///
/// Specifiers that are built-in or external. /// It is preferable to use this over using deno_graph's API directly
external_specifiers: HashSet<ModuleSpecifier>, /// because it will have enhanced error message information specifically
npm_packages: Vec<NpmPackageReq>, /// for the CLI.
has_node_builtin_specifier: bool,
/// Map of first known referrer locations for each module. Used to enhance
/// error messages.
referrer_map: HashMap<ModuleSpecifier, Box<Range>>,
graph_imports: Vec<GraphImport>,
}
impl GraphData {
/// Store data from `graph` into `self`.
pub fn add_graph(&mut self, graph: &ModuleGraph) {
for graph_import in &graph.imports {
for dep in graph_import.dependencies.values() {
for resolved in [&dep.maybe_code, &dep.maybe_type] {
if let Resolved::Ok {
specifier, range, ..
} = resolved
{
let entry = self.referrer_map.entry(specifier.clone());
entry.or_insert_with(|| range.clone());
}
}
}
self.graph_imports.push(graph_import.clone())
}
let mut has_npm_specifier_in_graph = false;
for (specifier, result) in graph.specifiers() {
if self.modules.contains_key(specifier) {
continue;
}
if !self.has_node_builtin_specifier && specifier.scheme() == "node" {
self.has_node_builtin_specifier = true;
}
if let Some(found) = graph.redirects.get(specifier) {
let module_entry = ModuleEntry::Redirect(found.clone());
self.modules.insert(specifier.clone(), module_entry);
continue;
}
match result {
Ok((_, module_kind, media_type)) => {
if module_kind == ModuleKind::External {
if !has_npm_specifier_in_graph
&& NpmPackageReference::from_specifier(specifier).is_ok()
{
has_npm_specifier_in_graph = true;
}
self.external_specifiers.insert(specifier.clone());
continue; // ignore npm and node specifiers
}
let module = graph.get(specifier).unwrap();
let code = match &module.maybe_source {
Some(source) => source.clone(),
None => continue,
};
let maybe_types = module
.maybe_types_dependency
.as_ref()
.map(|(_, r)| r.clone());
if let Some(Resolved::Ok {
specifier, range, ..
}) = &maybe_types
{
let specifier = graph.redirects.get(specifier).unwrap_or(specifier);
let entry = self.referrer_map.entry(specifier.clone());
entry.or_insert_with(|| range.clone());
}
for dep in module.dependencies.values() {
#[allow(clippy::manual_flatten)]
for resolved in [&dep.maybe_code, &dep.maybe_type] {
if let Resolved::Ok {
specifier, range, ..
} = resolved
{
let specifier =
graph.redirects.get(specifier).unwrap_or(specifier);
let entry = self.referrer_map.entry(specifier.clone());
entry.or_insert_with(|| range.clone());
}
}
}
let module_entry = ModuleEntry::Module {
code,
dependencies: module.dependencies.clone(),
media_type,
checked_libs: Default::default(),
maybe_types,
};
self.modules.insert(specifier.clone(), module_entry);
}
Err(error) => {
let module_entry = ModuleEntry::Error(error.clone());
self.modules.insert(specifier.clone(), module_entry);
}
}
}
if has_npm_specifier_in_graph {
self
.npm_packages
.extend(resolve_graph_npm_info(graph).package_reqs);
}
}
pub fn entries(
&self,
) -> impl Iterator<Item = (&ModuleSpecifier, &ModuleEntry)> {
self.modules.iter()
}
/// Gets if the graph had a "node:" specifier.
pub fn has_node_builtin_specifier(&self) -> bool {
self.has_node_builtin_specifier
}
/// Gets the npm package requirements from all the encountered graphs
/// in the order that they should be resolved.
pub fn npm_package_reqs(&self) -> &Vec<NpmPackageReq> {
&self.npm_packages
}
/// Walk dependencies from `roots` and return every encountered specifier.
/// Return `None` if any modules are not known.
pub fn walk<'a>(
&'a self,
roots: &[ModuleSpecifier],
follow_dynamic: bool,
follow_type_only: bool,
check_js: bool,
) -> Option<HashMap<&'a ModuleSpecifier, &'a ModuleEntry>> {
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 {
seen.insert(root);
visiting.push_back(root);
}
for (_, dep) in self.graph_imports.iter().flat_map(|i| &i.dependencies) {
let mut resolutions = vec![&dep.maybe_code];
if follow_type_only {
resolutions.push(&dep.maybe_type);
}
#[allow(clippy::manual_flatten)]
for resolved in resolutions {
if let Resolved::Ok { specifier, .. } = resolved {
if !seen.contains(specifier) {
seen.insert(specifier);
visiting.push_front(specifier);
}
}
}
}
while let Some(specifier) = visiting.pop_front() {
let (specifier, entry) = match self.modules.get_key_value(specifier) {
Some(pair) => pair,
None => {
if self.external_specifiers.contains(specifier) {
continue;
}
return None;
}
};
result.insert(specifier, entry);
match entry {
ModuleEntry::Module {
dependencies,
maybe_types,
media_type,
..
} => {
let check_types = (check_js
|| !matches!(
media_type,
MediaType::JavaScript
| MediaType::Mjs
| MediaType::Cjs
| MediaType::Jsx
))
&& follow_type_only;
if check_types {
if let Some(Resolved::Ok { specifier, .. }) = maybe_types {
if !seen.contains(specifier) {
seen.insert(specifier);
visiting.push_front(specifier);
}
}
}
for (dep_specifier, dep) in dependencies.iter().rev() {
// todo(dsherret): ideally there would be a way to skip external dependencies
// in the graph here rather than specifically npm package references
if NpmPackageReference::from_str(dep_specifier).is_ok() {
continue;
}
if !dep.is_dynamic || follow_dynamic {
let mut resolutions = vec![&dep.maybe_code];
if check_types {
resolutions.push(&dep.maybe_type);
}
#[allow(clippy::manual_flatten)]
for resolved in resolutions {
if let Resolved::Ok { specifier, .. } = resolved {
if !seen.contains(specifier) {
seen.insert(specifier);
visiting.push_front(specifier);
}
}
}
}
}
}
ModuleEntry::Error(_) => {}
ModuleEntry::Redirect(specifier) => {
if !seen.contains(specifier) {
seen.insert(specifier);
visiting.push_front(specifier);
}
}
}
}
Some(result)
}
/// 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]) -> Option<Self> {
let mut modules = HashMap::new();
let mut referrer_map = HashMap::new();
let entries = match self.walk(roots, true, true, true) {
Some(entries) => entries,
None => return None,
};
for (specifier, module_entry) in entries {
modules.insert(specifier.clone(), module_entry.clone());
if let Some(referrer) = self.referrer_map.get(specifier) {
referrer_map.insert(specifier.clone(), referrer.clone());
}
}
Some(Self {
modules,
external_specifiers: self.external_specifiers.clone(),
has_node_builtin_specifier: self.has_node_builtin_specifier,
npm_packages: self.npm_packages.clone(),
referrer_map,
graph_imports: self.graph_imports.to_vec(),
})
}
/// Check if `roots` and their deps are available. Returns `Some(Ok(()))` if
/// so. Returns `Some(Err(_))` if there is a known module graph or resolution
/// error statically reachable from `roots`. Returns `None` if any modules are
/// not known.
pub fn check(
&self,
roots: &[ModuleSpecifier],
follow_type_only: bool,
check_js: bool,
) -> Option<Result<(), AnyError>> {
let entries = match self.walk(roots, false, follow_type_only, check_js) {
Some(entries) => entries,
None => return None,
};
for (specifier, module_entry) in entries {
match module_entry {
ModuleEntry::Module {
dependencies,
maybe_types,
media_type,
..
} => {
let check_types = (check_js
|| !matches!(
media_type,
MediaType::JavaScript
| MediaType::Mjs
| MediaType::Cjs
| MediaType::Jsx
))
&& follow_type_only;
if check_types {
if let Some(Resolved::Err(error)) = maybe_types {
let range = error.range();
return Some(handle_check_error(
error.clone().into(),
Some(range),
));
}
}
for (_, dep) in dependencies.iter() {
if !dep.is_dynamic {
let mut resolutions = vec![&dep.maybe_code];
if check_types {
resolutions.push(&dep.maybe_type);
}
#[allow(clippy::manual_flatten)]
for resolved in resolutions {
if let Resolved::Err(error) = resolved {
let range = error.range();
return Some(handle_check_error(
error.clone().into(),
Some(range),
));
}
}
}
}
}
ModuleEntry::Error(error) => {
let maybe_range = if roots.contains(specifier) {
None
} else {
self.referrer_map.get(specifier)
};
return Some(handle_check_error(
error.clone().into(),
maybe_range.map(|r| &**r),
));
}
_ => {}
}
}
Some(Ok(()))
}
/// Mark `roots` and all of their dependencies as type checked under `lib`.
/// Assumes that all of those modules are known.
pub fn set_type_checked(
&mut self,
roots: &[ModuleSpecifier],
lib: TsTypeLib,
) {
let specifiers: Vec<ModuleSpecifier> =
match self.walk(roots, true, true, true) {
Some(entries) => entries.into_keys().cloned().collect(),
None => unreachable!("contains module not in graph data"),
};
for specifier in specifiers {
if let ModuleEntry::Module { checked_libs, .. } =
self.modules.get_mut(&specifier).unwrap()
{
checked_libs.insert(lib);
}
}
}
/// Check if `roots` are all marked as type checked under `lib`.
pub fn is_type_checked(
&self,
roots: &[ModuleSpecifier],
lib: &TsTypeLib,
) -> bool {
roots.iter().all(|r| {
let found = self.follow_redirect(r);
match self.modules.get(&found) {
Some(ModuleEntry::Module { checked_libs, .. }) => {
checked_libs.contains(lib)
}
_ => false,
}
})
}
/// If `specifier` is known and a redirect, return the found specifier.
/// Otherwise return `specifier`.
pub fn follow_redirect(
&self,
specifier: &ModuleSpecifier,
) -> ModuleSpecifier {
match self.modules.get(specifier) {
Some(ModuleEntry::Redirect(s)) => s.clone(),
_ => specifier.clone(),
}
}
pub fn get<'a>(
&'a self,
specifier: &ModuleSpecifier,
) -> Option<&'a ModuleEntry> {
self.modules.get(specifier)
}
/// Get the dependencies of a module or graph import.
pub fn get_dependencies<'a>(
&'a self,
specifier: &ModuleSpecifier,
) -> Option<&'a BTreeMap<String, Dependency>> {
let specifier = self.follow_redirect(specifier);
if let Some(ModuleEntry::Module { dependencies, .. }) = self.get(&specifier)
{
return Some(dependencies);
}
if let Some(graph_import) =
self.graph_imports.iter().find(|i| i.referrer == specifier)
{
return Some(&graph_import.dependencies);
}
None
}
}
impl From<&ModuleGraph> for GraphData {
fn from(graph: &ModuleGraph) -> Self {
let mut graph_data = GraphData::default();
graph_data.add_graph(graph);
graph_data
}
}
/// Like `graph.valid()`, but enhanced with referrer info.
pub fn graph_valid( pub fn graph_valid(
graph: &ModuleGraph, graph: &ModuleGraph,
follow_type_only: bool, roots: &[ModuleSpecifier],
check_js: bool, walk_options: deno_graph::WalkOptions,
) -> Result<(), AnyError> { ) -> Result<(), AnyError> {
GraphData::from(graph) graph.walk(roots, walk_options).validate().map_err(|error| {
.check(&graph.roots, follow_type_only, check_js) let mut message = if let ModuleGraphError::ResolutionError(err) = &error {
.unwrap() enhanced_resolution_error_message(err)
} else {
format!("{error}")
};
if let Some(range) = error.maybe_range() {
if !range.specifier.as_str().contains("/$deno$eval") {
message.push_str(&format!("\n at {range}"));
}
}
custom_error(get_error_class_name(&error.into()), message)
})
} }
/// Checks the lockfile against the graph and and exits on errors. /// Checks the lockfile against the graph and and exits on errors.
@ -523,11 +112,12 @@ pub async fn create_graph_and_maybe_check(
let maybe_graph_resolver = let maybe_graph_resolver =
maybe_cli_resolver.as_ref().map(|r| r.as_graph_resolver()); maybe_cli_resolver.as_ref().map(|r| r.as_graph_resolver());
let analyzer = ps.parsed_source_cache.as_analyzer(); let analyzer = ps.parsed_source_cache.as_analyzer();
let graph = Arc::new( let mut graph = ModuleGraph::default();
deno_graph::create_graph( graph
.build(
vec![root], vec![root],
&mut cache, &mut cache,
deno_graph::GraphOptions { deno_graph::BuildOptions {
is_dynamic: false, is_dynamic: false,
imports: maybe_imports, imports: maybe_imports,
resolver: maybe_graph_resolver, resolver: maybe_graph_resolver,
@ -535,21 +125,12 @@ pub async fn create_graph_and_maybe_check(
reporter: None, reporter: None,
}, },
) )
.await, .await;
); graph_valid_with_cli_options(&graph, &graph.roots, &ps.options)?;
let graph = Arc::new(graph);
let check_js = ps.options.check_js(); let npm_graph_info = resolve_graph_npm_info(&graph);
let mut graph_data = GraphData::default();
graph_data.add_graph(&graph);
graph_data
.check(
&graph.roots,
ps.options.type_check_mode() != TypeCheckMode::None,
check_js,
)
.unwrap()?;
ps.npm_resolver ps.npm_resolver
.add_package_reqs(graph_data.npm_package_reqs().clone()) .add_package_reqs(npm_graph_info.package_reqs)
.await?; .await?;
if let Some(lockfile) = &ps.lockfile { if let Some(lockfile) = &ps.lockfile {
graph_lock_or_exit(&graph, &mut lockfile.lock()); graph_lock_or_exit(&graph, &mut lockfile.lock());
@ -558,7 +139,7 @@ pub async fn create_graph_and_maybe_check(
if ps.options.type_check_mode() != TypeCheckMode::None { if ps.options.type_check_mode() != TypeCheckMode::None {
// node built-in specifiers use the @types/node package to determine // node built-in specifiers use the @types/node package to determine
// types, so inject that now after the lockfile has been written // types, so inject that now after the lockfile has been written
if graph_data.has_node_builtin_specifier() { if npm_graph_info.has_node_builtin_specifier {
ps.npm_resolver ps.npm_resolver
.inject_synthetic_types_node_package() .inject_synthetic_types_node_package()
.await?; .await?;
@ -574,8 +155,7 @@ pub async fn create_graph_and_maybe_check(
let maybe_config_specifier = ps.options.maybe_config_file_specifier(); let maybe_config_specifier = ps.options.maybe_config_file_specifier();
let cache = TypeCheckCache::new(&ps.dir.type_checking_cache_db_file_path()); let cache = TypeCheckCache::new(&ps.dir.type_checking_cache_db_file_path());
let check_result = check::check( let check_result = check::check(
&graph.roots, graph.clone(),
Arc::new(RwLock::new(graph_data)),
&cache, &cache,
&ps.npm_resolver, &ps.npm_resolver,
check::CheckOptions { check::CheckOptions {
@ -585,6 +165,7 @@ pub async fn create_graph_and_maybe_check(
ts_config: ts_config_result.ts_config, ts_config: ts_config_result.ts_config,
log_checks: true, log_checks: true,
reload: ps.options.reload_flag(), reload: ps.options.reload_flag(),
has_node_builtin_specifier: npm_graph_info.has_node_builtin_specifier,
}, },
)?; )?;
log::debug!("{}", check_result.stats); log::debug!("{}", check_result.stats);
@ -602,8 +183,8 @@ pub fn error_for_any_npm_specifier(
let first_npm_specifier = graph let first_npm_specifier = graph
.specifiers() .specifiers()
.filter_map(|(_, r)| match r { .filter_map(|(_, r)| match r {
Ok((specifier, kind, _)) if kind == deno_graph::ModuleKind::External => { Ok(module) if module.kind == deno_graph::ModuleKind::External => {
Some(specifier) Some(&module.specifier)
} }
_ => None, _ => None,
}) })
@ -615,25 +196,6 @@ pub fn error_for_any_npm_specifier(
} }
} }
fn handle_check_error(
error: AnyError,
maybe_range: Option<&deno_graph::Range>,
) -> Result<(), AnyError> {
let mut message = if let Some(err) = error.downcast_ref::<ResolutionError>() {
enhanced_resolution_error_message(err)
} else {
format!("{error}")
};
if let Some(range) = maybe_range {
if !range.specifier.as_str().contains("$deno") {
message.push_str(&format!("\n at {range}"));
}
}
Err(custom_error(get_error_class_name(&error), message))
}
/// Adds more explanatory information to a resolution error. /// Adds more explanatory information to a resolution error.
pub fn enhanced_resolution_error_message(error: &ResolutionError) -> String { pub fn enhanced_resolution_error_message(error: &ResolutionError) -> String {
let mut message = format!("{error}"); let mut message = format!("{error}");

View file

@ -27,8 +27,8 @@ use deno_core::serde::Deserialize;
use deno_core::serde_json; use deno_core::serde_json;
use deno_core::serde_json::json; use deno_core::serde_json::json;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use deno_graph::Resolution;
use deno_graph::ResolutionError; use deno_graph::ResolutionError;
use deno_graph::Resolved;
use deno_graph::SpecifierError; use deno_graph::SpecifierError;
use deno_lint::rules::LintRule; use deno_lint::rules::LintRule;
use deno_runtime::tokio_util::create_basic_runtime; use deno_runtime::tokio_util::create_basic_runtime;
@ -852,18 +852,17 @@ impl DenoDiagnostic {
} }
} }
fn diagnose_resolved( fn diagnose_resolution(
diagnostics: &mut Vec<lsp::Diagnostic>, diagnostics: &mut Vec<lsp::Diagnostic>,
snapshot: &language_server::StateSnapshot, snapshot: &language_server::StateSnapshot,
resolved: &deno_graph::Resolved, resolution: &Resolution,
is_dynamic: bool, is_dynamic: bool,
maybe_assert_type: Option<&str>, maybe_assert_type: Option<&str>,
) { ) {
match resolved { match resolution {
Resolved::Ok { Resolution::Ok(resolved) => {
specifier, range, .. let specifier = &resolved.specifier;
} => { let range = documents::to_lsp_range(&resolved.range);
let range = documents::to_lsp_range(range);
// If the module is a remote module and has a `X-Deno-Warning` header, we // If the module is a remote module and has a `X-Deno-Warning` header, we
// want a warning diagnostic with that message. // want a warning diagnostic with that message.
if let Some(metadata) = snapshot.cache_metadata.get(specifier) { if let Some(metadata) = snapshot.cache_metadata.get(specifier) {
@ -959,8 +958,8 @@ fn diagnose_resolved(
} }
// The specifier resolution resulted in an error, so we want to issue a // The specifier resolution resulted in an error, so we want to issue a
// diagnostic for that. // diagnostic for that.
Resolved::Err(err) => diagnostics.push( Resolution::Err(err) => diagnostics.push(
DenoDiagnostic::ResolutionError(err.clone()) DenoDiagnostic::ResolutionError(*err.clone())
.to_lsp_diagnostic(&documents::to_lsp_range(err.range())), .to_lsp_diagnostic(&documents::to_lsp_range(err.range())),
), ),
_ => (), _ => (),
@ -984,31 +983,28 @@ fn diagnose_dependency(
} }
if let Some(import_map) = &snapshot.maybe_import_map { if let Some(import_map) = &snapshot.maybe_import_map {
if let Resolved::Ok { if let Resolution::Ok(resolved) = &dependency.maybe_code {
specifier, range, .. if let Some(to) = import_map.lookup(&resolved.specifier, referrer) {
} = &dependency.maybe_code
{
if let Some(to) = import_map.lookup(specifier, referrer) {
if dependency_key != to { if dependency_key != to {
diagnostics.push( diagnostics.push(
DenoDiagnostic::ImportMapRemap { DenoDiagnostic::ImportMapRemap {
from: dependency_key.to_string(), from: dependency_key.to_string(),
to, to,
} }
.to_lsp_diagnostic(&documents::to_lsp_range(range)), .to_lsp_diagnostic(&documents::to_lsp_range(&resolved.range)),
); );
} }
} }
} }
} }
diagnose_resolved( diagnose_resolution(
diagnostics, diagnostics,
snapshot, snapshot,
&dependency.maybe_code, &dependency.maybe_code,
dependency.is_dynamic, dependency.is_dynamic,
dependency.maybe_assert_type.as_deref(), dependency.maybe_assert_type.as_deref(),
); );
diagnose_resolved( diagnose_resolution(
diagnostics, diagnostics,
snapshot, snapshot,
&dependency.maybe_type, &dependency.maybe_type,
@ -1064,6 +1060,7 @@ mod tests {
use crate::lsp::documents::Documents; use crate::lsp::documents::Documents;
use crate::lsp::documents::LanguageId; use crate::lsp::documents::LanguageId;
use crate::lsp::language_server::StateSnapshot; use crate::lsp::language_server::StateSnapshot;
use pretty_assertions::assert_eq;
use std::path::Path; use std::path::Path;
use std::path::PathBuf; use std::path::PathBuf;
use std::sync::Arc; use std::sync::Arc;

View file

@ -33,7 +33,7 @@ use deno_core::parking_lot::Mutex;
use deno_core::url; use deno_core::url;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use deno_graph::GraphImport; use deno_graph::GraphImport;
use deno_graph::Resolved; use deno_graph::Resolution;
use deno_runtime::deno_node::NodeResolutionMode; use deno_runtime::deno_node::NodeResolutionMode;
use deno_runtime::permissions::PermissionsContainer; use deno_runtime::permissions::PermissionsContainer;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
@ -243,7 +243,7 @@ impl AssetOrDocument {
#[derive(Debug, Default)] #[derive(Debug, Default)]
struct DocumentDependencies { struct DocumentDependencies {
deps: BTreeMap<String, deno_graph::Dependency>, deps: BTreeMap<String, deno_graph::Dependency>,
maybe_types_dependency: Option<(String, Resolved)>, maybe_types_dependency: Option<deno_graph::TypesDependency>,
} }
impl DocumentDependencies { impl DocumentDependencies {
@ -508,13 +508,12 @@ impl Document {
self.0.maybe_lsp_version.is_some() self.0.maybe_lsp_version.is_some()
} }
pub fn maybe_types_dependency(&self) -> deno_graph::Resolved { pub fn maybe_types_dependency(&self) -> Resolution {
if let Some((_, maybe_dep)) = if let Some(types_dep) = self.0.dependencies.maybe_types_dependency.as_ref()
self.0.dependencies.maybe_types_dependency.as_ref()
{ {
maybe_dep.clone() types_dep.dependency.clone()
} else { } else {
deno_graph::Resolved::None Resolution::None
} }
} }
@ -597,20 +596,23 @@ impl Document {
} }
} }
pub fn to_hover_text(result: &Resolved) -> String { pub fn to_hover_text(result: &Resolution) -> String {
match result { match result {
Resolved::Ok { specifier, .. } => match specifier.scheme() { Resolution::Ok(resolved) => {
"data" => "_(a data url)_".to_string(), let specifier = &resolved.specifier;
"blob" => "_(a blob url)_".to_string(), match specifier.scheme() {
_ => format!( "data" => "_(a data url)_".to_string(),
"{}&#8203;{}", "blob" => "_(a blob url)_".to_string(),
&specifier[..url::Position::AfterScheme], _ => format!(
&specifier[url::Position::AfterScheme..], "{}&#8203;{}",
) &specifier[..url::Position::AfterScheme],
.replace('@', "&#8203;@"), &specifier[url::Position::AfterScheme..],
}, )
Resolved::Err(_) => "_[errored]_".to_string(), .replace('@', "&#8203;@"),
Resolved::None => "_[missing]_".to_string(), }
}
Resolution::Err(_) => "_[errored]_".to_string(),
Resolution::None => "_[missing]_".to_string(),
} }
} }
@ -1094,15 +1096,16 @@ impl Documents {
} else if let Some(dep) = } else if let Some(dep) =
dependencies.as_ref().and_then(|d| d.deps.get(&specifier)) dependencies.as_ref().and_then(|d| d.deps.get(&specifier))
{ {
if let Resolved::Ok { specifier, .. } = &dep.maybe_type { if let Some(specifier) = dep.maybe_type.maybe_specifier() {
results.push(self.resolve_dependency(specifier, maybe_npm_resolver)); results.push(self.resolve_dependency(specifier, maybe_npm_resolver));
} else if let Resolved::Ok { specifier, .. } = &dep.maybe_code { } else if let Some(specifier) = dep.maybe_code.maybe_specifier() {
results.push(self.resolve_dependency(specifier, maybe_npm_resolver)); results.push(self.resolve_dependency(specifier, maybe_npm_resolver));
} else { } else {
results.push(None); results.push(None);
} }
} else if let Some(Resolved::Ok { specifier, .. }) = } else if let Some(specifier) = self
self.resolve_imports_dependency(&specifier) .resolve_imports_dependency(&specifier)
.and_then(|r| r.maybe_specifier())
{ {
results.push(self.resolve_dependency(specifier, maybe_npm_resolver)); results.push(self.resolve_dependency(specifier, maybe_npm_resolver));
} else if let Ok(npm_ref) = NpmPackageReference::from_str(&specifier) { } else if let Ok(npm_ref) = NpmPackageReference::from_str(&specifier) {
@ -1186,18 +1189,18 @@ impl Documents {
self.maybe_resolver = self.maybe_resolver =
CliResolver::maybe_new(maybe_jsx_config, maybe_import_map); CliResolver::maybe_new(maybe_jsx_config, maybe_import_map);
self.imports = Arc::new( self.imports = Arc::new(
if let Some(Ok(Some(imports))) = if let Some(Ok(imports)) =
maybe_config_file.map(|cf| cf.to_maybe_imports()) maybe_config_file.map(|cf| cf.to_maybe_imports())
{ {
imports imports
.into_iter() .into_iter()
.map(|(referrer, dependencies)| { .map(|import| {
let graph_import = GraphImport::new( let graph_import = GraphImport::new(
referrer.clone(), &import.referrer,
dependencies, import.imports,
self.get_maybe_resolver(), self.get_maybe_resolver(),
); );
(referrer, graph_import) (import.referrer, graph_import)
}) })
.collect() .collect()
} else { } else {
@ -1274,10 +1277,8 @@ impl Documents {
self.add(dep, specifier); self.add(dep, specifier);
} }
} }
if let Resolved::Ok { specifier: dep, .. } = if let Some(dep) = doc.maybe_types_dependency().maybe_specifier() {
doc.maybe_types_dependency() self.add(dep, specifier);
{
self.add(&dep, specifier);
} }
} }
} }
@ -1345,13 +1346,12 @@ impl Documents {
} }
let doc = self.get(specifier)?; let doc = self.get(specifier)?;
let maybe_module = doc.maybe_module().and_then(|r| r.as_ref().ok()); let maybe_module = doc.maybe_module().and_then(|r| r.as_ref().ok());
let maybe_types_dependency = maybe_module.and_then(|m| { let maybe_types_dependency = maybe_module
m.maybe_types_dependency .and_then(|m| m.maybe_types_dependency.as_ref().map(|d| &d.dependency));
.as_ref() if let Some(specifier) =
.map(|(_, resolved)| resolved.clone()) maybe_types_dependency.and_then(|d| d.maybe_specifier())
}); {
if let Some(Resolved::Ok { specifier, .. }) = maybe_types_dependency { self.resolve_dependency(specifier, maybe_npm_resolver)
self.resolve_dependency(&specifier, maybe_npm_resolver)
} else { } else {
let media_type = doc.media_type(); let media_type = doc.media_type();
Some((specifier.clone(), media_type)) Some((specifier.clone(), media_type))
@ -1361,10 +1361,7 @@ impl Documents {
/// Iterate through any "imported" modules, checking to see if a dependency /// Iterate through any "imported" modules, checking to see if a dependency
/// is available. This is used to provide "global" imports like the JSX import /// is available. This is used to provide "global" imports like the JSX import
/// source. /// source.
fn resolve_imports_dependency( fn resolve_imports_dependency(&self, specifier: &str) -> Option<&Resolution> {
&self,
specifier: &str,
) -> Option<&deno_graph::Resolved> {
for graph_imports in self.imports.values() { for graph_imports in self.imports.values() {
let maybe_dep = graph_imports.dependencies.get(specifier); let maybe_dep = graph_imports.dependencies.get(specifier);
if maybe_dep.is_some() { if maybe_dep.is_some() {

View file

@ -173,8 +173,18 @@ impl LanguageServer {
inner_loader: &mut inner_loader, inner_loader: &mut inner_loader,
open_docs: &open_docs, open_docs: &open_docs,
}; };
let graph = ps.create_graph_with_loader(roots, &mut loader).await?; let graph = ps
graph_valid(&graph, true, false)?; .create_graph_with_loader(roots.clone(), &mut loader)
.await?;
graph_valid(
&graph,
&roots,
deno_graph::WalkOptions {
follow_dynamic: false,
follow_type_only: true,
check_js: false,
},
)?;
Ok(()) Ok(())
} }

View file

@ -2,7 +2,6 @@
use crate::args::TsTypeLib; use crate::args::TsTypeLib;
use crate::emit::emit_parsed_source; use crate::emit::emit_parsed_source;
use crate::graph_util::ModuleEntry;
use crate::node; use crate::node;
use crate::proc_state::ProcState; use crate::proc_state::ProcState;
use crate::util::text_encoding::code_without_source_map; use crate::util::text_encoding::code_without_source_map;
@ -85,11 +84,13 @@ impl CliModuleLoader {
media_type: MediaType::JavaScript, media_type: MediaType::JavaScript,
}); });
} }
let graph_data = self.ps.graph_data.read(); let graph = self.ps.graph();
let found_url = graph_data.follow_redirect(specifier); match graph.get(specifier) {
match graph_data.get(&found_url) { Some(deno_graph::Module {
Some(ModuleEntry::Module { maybe_source: Some(code),
code, media_type, .. media_type,
specifier,
..
}) => { }) => {
let code = match media_type { let code = match media_type {
MediaType::JavaScript MediaType::JavaScript
@ -107,7 +108,7 @@ impl CliModuleLoader {
emit_parsed_source( emit_parsed_source(
&self.ps.emit_cache, &self.ps.emit_cache,
&self.ps.parsed_source_cache, &self.ps.parsed_source_cache,
&found_url, specifier,
*media_type, *media_type,
code, code,
&self.ps.emit_options, &self.ps.emit_options,
@ -115,7 +116,7 @@ impl CliModuleLoader {
)? )?
} }
MediaType::TsBuildInfo | MediaType::Wasm | MediaType::SourceMap => { MediaType::TsBuildInfo | MediaType::Wasm | MediaType::SourceMap => {
panic!("Unexpected media type {media_type} for {found_url}") panic!("Unexpected media type {media_type} for {specifier}")
} }
}; };
@ -124,7 +125,7 @@ impl CliModuleLoader {
Ok(ModuleCodeSource { Ok(ModuleCodeSource {
code, code,
found_url, found_url: specifier.clone(),
media_type: *media_type, media_type: *media_type,
}) })
} }
@ -295,10 +296,12 @@ impl SourceMapGetter for CliModuleLoader {
file_name: &str, file_name: &str,
line_number: usize, line_number: usize,
) -> Option<String> { ) -> Option<String> {
let graph_data = self.ps.graph_data.read(); let graph = self.ps.graph();
let specifier = graph_data.follow_redirect(&resolve_url(file_name).ok()?); let code = match graph.get(&resolve_url(file_name).ok()?) {
let code = match graph_data.get(&specifier) { Some(deno_graph::Module {
Some(ModuleEntry::Module { code, .. }) => code, maybe_source: Some(code),
..
}) => code,
_ => return None, _ => return None,
}; };
// Do NOT use .lines(): it skips the terminating empty line. // Do NOT use .lines(): it skips the terminating empty line.

View file

@ -7,7 +7,6 @@ use std::collections::VecDeque;
use deno_ast::ModuleSpecifier; use deno_ast::ModuleSpecifier;
use deno_graph::ModuleGraph; use deno_graph::ModuleGraph;
use deno_graph::Resolved;
use crate::semver::VersionReq; use crate::semver::VersionReq;
@ -70,14 +69,17 @@ pub fn resolve_graph_npm_info(graph: &ModuleGraph) -> GraphNpmInfo {
module: &'a deno_graph::Module, module: &'a deno_graph::Module,
) -> Vec<&'a ModuleSpecifier> { ) -> Vec<&'a ModuleSpecifier> {
let mut specifiers = Vec::with_capacity(module.dependencies.len() * 2 + 1); let mut specifiers = Vec::with_capacity(module.dependencies.len() * 2 + 1);
let maybe_types = module.maybe_types_dependency.as_ref().map(|(_, r)| r); let maybe_types = module
if let Some(Resolved::Ok { specifier, .. }) = &maybe_types { .maybe_types_dependency
.as_ref()
.map(|d| &d.dependency);
if let Some(specifier) = maybe_types.and_then(|d| d.maybe_specifier()) {
specifiers.push(specifier); specifiers.push(specifier);
} }
for dep in module.dependencies.values() { for dep in module.dependencies.values() {
#[allow(clippy::manual_flatten)] #[allow(clippy::manual_flatten)]
for resolved in [&dep.maybe_code, &dep.maybe_type] { for resolved in [&dep.maybe_code, &dep.maybe_type] {
if let Resolved::Ok { specifier, .. } = resolved { if let Some(specifier) = resolved.maybe_specifier() {
specifiers.push(specifier); specifiers.push(specifier);
} }
} }
@ -686,23 +688,22 @@ mod tests {
Vec::new(), Vec::new(),
); );
let analyzer = deno_graph::CapturingModuleAnalyzer::default(); let analyzer = deno_graph::CapturingModuleAnalyzer::default();
let graph = deno_graph::create_graph( let mut graph = deno_graph::ModuleGraph::default();
vec![ graph
ModuleSpecifier::parse("file:///dev/local_module_a/mod.ts").unwrap(), .build(
// test redirect at root vec![
ModuleSpecifier::parse("https://deno.land/x/module_redirect/mod.ts") ModuleSpecifier::parse("file:///dev/local_module_a/mod.ts").unwrap(),
.unwrap(), // test redirect at root
], ModuleSpecifier::parse("https://deno.land/x/module_redirect/mod.ts")
&mut loader, .unwrap(),
deno_graph::GraphOptions { ],
is_dynamic: false, &mut loader,
imports: None, deno_graph::BuildOptions {
resolver: None, module_analyzer: Some(&analyzer),
module_analyzer: Some(&analyzer), ..Default::default()
reporter: None, },
}, )
) .await;
.await;
let reqs = resolve_graph_npm_info(&graph) let reqs = resolve_graph_npm_info(&graph)
.package_reqs .package_reqs
.into_iter() .into_iter()

View file

@ -18,14 +18,14 @@ use crate::cache::TypeCheckCache;
use crate::emit::emit_parsed_source; use crate::emit::emit_parsed_source;
use crate::file_fetcher::FileFetcher; use crate::file_fetcher::FileFetcher;
use crate::graph_util::graph_lock_or_exit; use crate::graph_util::graph_lock_or_exit;
use crate::graph_util::GraphData; use crate::graph_util::graph_valid_with_cli_options;
use crate::graph_util::ModuleEntry;
use crate::http_util::HttpClient; use crate::http_util::HttpClient;
use crate::node; use crate::node;
use crate::node::NodeResolution; use crate::node::NodeResolution;
use crate::npm::resolve_graph_npm_info; use crate::npm::resolve_graph_npm_info;
use crate::npm::NpmCache; use crate::npm::NpmCache;
use crate::npm::NpmPackageReference; use crate::npm::NpmPackageReference;
use crate::npm::NpmPackageReq;
use crate::npm::NpmPackageResolver; use crate::npm::NpmPackageResolver;
use crate::npm::RealNpmRegistryApi; use crate::npm::RealNpmRegistryApi;
use crate::resolver::CliResolver; use crate::resolver::CliResolver;
@ -39,19 +39,17 @@ use deno_core::anyhow::Context;
use deno_core::error::custom_error; use deno_core::error::custom_error;
use deno_core::error::generic_error; use deno_core::error::generic_error;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::futures;
use deno_core::parking_lot::Mutex; use deno_core::parking_lot::Mutex;
use deno_core::parking_lot::RwLock; use deno_core::parking_lot::RwLock;
use deno_core::resolve_url_or_path; use deno_core::resolve_url_or_path;
use deno_core::CompiledWasmModuleStore; use deno_core::CompiledWasmModuleStore;
use deno_core::ModuleSpecifier; use deno_core::ModuleSpecifier;
use deno_core::SharedArrayBufferStore; use deno_core::SharedArrayBufferStore;
use deno_graph::create_graph;
use deno_graph::source::CacheInfo;
use deno_graph::source::LoadFuture;
use deno_graph::source::Loader; use deno_graph::source::Loader;
use deno_graph::source::Resolver; use deno_graph::source::Resolver;
use deno_graph::Resolved; use deno_graph::ModuleGraph;
use deno_graph::ModuleKind;
use deno_graph::Resolution;
use deno_runtime::deno_broadcast_channel::InMemoryBroadcastChannel; use deno_runtime::deno_broadcast_channel::InMemoryBroadcastChannel;
use deno_runtime::deno_node::NodeResolutionMode; use deno_runtime::deno_node::NodeResolutionMode;
use deno_runtime::deno_tls::rustls::RootCertStore; use deno_runtime::deno_tls::rustls::RootCertStore;
@ -60,6 +58,7 @@ use deno_runtime::inspector_server::InspectorServer;
use deno_runtime::permissions::PermissionsContainer; use deno_runtime::permissions::PermissionsContainer;
use import_map::ImportMap; use import_map::ImportMap;
use log::warn; use log::warn;
use std::collections::HashMap;
use std::collections::HashSet; use std::collections::HashSet;
use std::ops::Deref; use std::ops::Deref;
use std::path::PathBuf; use std::path::PathBuf;
@ -81,7 +80,7 @@ pub struct Inner {
pub emit_cache: EmitCache, pub emit_cache: EmitCache,
pub emit_options: deno_ast::EmitOptions, pub emit_options: deno_ast::EmitOptions,
pub emit_options_hash: u64, pub emit_options_hash: u64,
pub graph_data: Arc<RwLock<GraphData>>, graph_data: Arc<RwLock<GraphData>>,
pub lockfile: Option<Arc<Mutex<Lockfile>>>, pub lockfile: Option<Arc<Mutex<Lockfile>>>,
pub maybe_import_map: Option<Arc<ImportMap>>, pub maybe_import_map: Option<Arc<ImportMap>>,
pub maybe_inspector_server: Option<Arc<InspectorServer>>, pub maybe_inspector_server: Option<Arc<InspectorServer>>,
@ -314,31 +313,6 @@ impl ProcState {
log::debug!("Preparing module load."); log::debug!("Preparing module load.");
let _pb_clear_guard = self.progress_bar.clear_guard(); let _pb_clear_guard = self.progress_bar.clear_guard();
let has_root_npm_specifier = roots.iter().any(|r| {
r.scheme() == "npm" && NpmPackageReference::from_specifier(r).is_ok()
});
if !has_root_npm_specifier {
let graph_data = self.graph_data.read();
if self.options.type_check_mode() == TypeCheckMode::None
|| graph_data.is_type_checked(&roots, &lib)
{
if let Some(result) = graph_data.check(
&roots,
self.options.type_check_mode() != TypeCheckMode::None,
false,
) {
// TODO(bartlomieju): this is strange... ideally there should be only
// one codepath in `prepare_module_load` so we don't forget things
// like writing a lockfile. Figure a way to refactor this function.
if let Some(ref lockfile) = self.lockfile {
let g = lockfile.lock();
g.write()?;
}
return result;
}
}
}
let mut cache = cache::FetchCacher::new( let mut cache = cache::FetchCacher::new(
self.emit_cache.clone(), self.emit_cache.clone(),
self.file_fetcher.clone(), self.file_fetcher.clone(),
@ -348,36 +322,6 @@ impl ProcState {
let maybe_imports = self.options.to_maybe_imports()?; let maybe_imports = self.options.to_maybe_imports()?;
let maybe_resolver = let maybe_resolver =
self.maybe_resolver.as_ref().map(|r| r.as_graph_resolver()); self.maybe_resolver.as_ref().map(|r| r.as_graph_resolver());
struct ProcStateLoader<'a> {
inner: &'a mut cache::FetchCacher,
graph_data: Arc<RwLock<GraphData>>,
}
impl Loader for ProcStateLoader<'_> {
fn get_cache_info(
&self,
specifier: &ModuleSpecifier,
) -> Option<CacheInfo> {
self.inner.get_cache_info(specifier)
}
fn load(
&mut self,
specifier: &ModuleSpecifier,
is_dynamic: bool,
) -> LoadFuture {
let graph_data = self.graph_data.read();
let found_specifier = graph_data.follow_redirect(specifier);
match graph_data.get(&found_specifier) {
Some(_) => Box::pin(futures::future::ready(Err(anyhow!("")))),
_ => self.inner.load(specifier, is_dynamic),
}
}
}
let mut loader = ProcStateLoader {
inner: &mut cache,
graph_data: self.graph_data.clone(),
};
let maybe_file_watcher_reporter: Option<&dyn deno_graph::source::Reporter> = let maybe_file_watcher_reporter: Option<&dyn deno_graph::source::Reporter> =
if let Some(reporter) = &self.maybe_file_watcher_reporter { if let Some(reporter) = &self.maybe_file_watcher_reporter {
Some(reporter) Some(reporter)
@ -386,46 +330,41 @@ impl ProcState {
}; };
let analyzer = self.parsed_source_cache.as_analyzer(); let analyzer = self.parsed_source_cache.as_analyzer();
log::debug!("Creating module graph."); log::debug!("Creating module graph.");
let graph = create_graph( let mut graph = self.graph_data.read().graph_inner_clone();
roots.clone(),
&mut loader, // Determine any modules that have already been emitted this session and
deno_graph::GraphOptions { // should be skipped.
is_dynamic, let reload_exclusions: HashSet<ModuleSpecifier> =
imports: maybe_imports, graph.specifiers().map(|(s, _)| s.clone()).collect();
resolver: maybe_resolver,
module_analyzer: Some(&*analyzer), graph
reporter: maybe_file_watcher_reporter, .build(
}, roots.clone(),
) &mut cache,
.await; deno_graph::BuildOptions {
is_dynamic,
imports: maybe_imports,
resolver: maybe_resolver,
module_analyzer: Some(&*analyzer),
reporter: maybe_file_watcher_reporter,
},
)
.await;
// If there is a lockfile, validate the integrity of all the modules. // If there is a lockfile, validate the integrity of all the modules.
if let Some(lockfile) = &self.lockfile { if let Some(lockfile) = &self.lockfile {
graph_lock_or_exit(&graph, &mut lockfile.lock()); graph_lock_or_exit(&graph, &mut lockfile.lock());
} }
// Determine any modules that have already been emitted this session and
// should be skipped.
let reload_exclusions: HashSet<ModuleSpecifier> = {
let graph_data = self.graph_data.read();
graph_data.entries().map(|(s, _)| s).cloned().collect()
};
let (npm_package_reqs, has_node_builtin_specifier) = { let (npm_package_reqs, has_node_builtin_specifier) = {
graph_valid_with_cli_options(&graph, &roots, &self.options)?;
let mut graph_data = self.graph_data.write(); let mut graph_data = self.graph_data.write();
graph_data.add_graph(&graph); graph_data.update_graph(Arc::new(graph));
let check_js = self.options.check_js();
graph_data
.check(
&roots,
self.options.type_check_mode() != TypeCheckMode::None,
check_js,
)
.unwrap()?;
( (
graph_data.npm_package_reqs().clone(), graph_data.npm_packages.clone(),
graph_data.has_node_builtin_specifier(), graph_data.has_node_builtin_specifier,
) )
}; };
@ -447,9 +386,19 @@ impl ProcState {
// type check if necessary // type check if necessary
let is_std_node = roots.len() == 1 && roots[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 { if self.options.type_check_mode() != TypeCheckMode::None
&& !is_std_node
&& !self.graph_data.read().is_type_checked(&roots, lib)
{
log::debug!("Type checking."); log::debug!("Type checking.");
let maybe_config_specifier = self.options.maybe_config_file_specifier(); let maybe_config_specifier = self.options.maybe_config_file_specifier();
let (graph, has_node_builtin_specifier) = {
let graph_data = self.graph_data.read();
(
Arc::new(graph_data.graph.segment(&roots)),
graph_data.has_node_builtin_specifier,
)
};
let options = check::CheckOptions { let options = check::CheckOptions {
type_check_mode: self.options.type_check_mode(), type_check_mode: self.options.type_check_mode(),
debug: self.options.log_level() == Some(log::Level::Debug), debug: self.options.log_level() == Some(log::Level::Debug),
@ -461,28 +410,19 @@ impl ProcState {
log_checks: true, log_checks: true,
reload: self.options.reload_flag() reload: self.options.reload_flag()
&& !roots.iter().all(|r| reload_exclusions.contains(r)), && !roots.iter().all(|r| reload_exclusions.contains(r)),
has_node_builtin_specifier,
}; };
let check_cache = let check_cache =
TypeCheckCache::new(&self.dir.type_checking_cache_db_file_path()); TypeCheckCache::new(&self.dir.type_checking_cache_db_file_path());
let graph_data = self.graph_data.clone(); let check_result =
let check_result = check::check( check::check(graph, &check_cache, &self.npm_resolver, options)?;
&roots, self.graph_data.write().set_type_checked(&roots, lib);
graph_data,
&check_cache,
&self.npm_resolver,
options,
)?;
if !check_result.diagnostics.is_empty() { if !check_result.diagnostics.is_empty() {
return Err(anyhow!(check_result.diagnostics)); return Err(anyhow!(check_result.diagnostics));
} }
log::debug!("{}", check_result.stats); log::debug!("{}", check_result.stats);
} }
if self.options.type_check_mode() != TypeCheckMode::None {
let mut graph_data = self.graph_data.write();
graph_data.set_type_checked(&roots, lib);
}
// any updates to the lockfile should be updated now // any updates to the lockfile should be updated now
if let Some(ref lockfile) = self.lockfile { if let Some(ref lockfile) = self.lockfile {
let g = lockfile.lock(); let g = lockfile.lock();
@ -523,10 +463,21 @@ impl ProcState {
return Ok(()); return Ok(());
} }
let node_std_graph = self let mut graph = self.graph_data.read().graph_inner_clone();
.create_graph(vec![node::MODULE_ALL_URL.clone()]) let mut loader = self.create_graph_loader();
.await?; let analyzer = self.parsed_source_cache.as_analyzer();
self.graph_data.write().add_graph(&node_std_graph); graph
.build(
vec![node::MODULE_ALL_URL.clone()],
&mut loader,
deno_graph::BuildOptions {
module_analyzer: Some(&*analyzer),
..Default::default()
},
)
.await;
self.graph_data.write().update_graph(Arc::new(graph));
self.node_std_graph_prepared.store(true, Ordering::Relaxed); self.node_std_graph_prepared.store(true, Ordering::Relaxed);
Ok(()) Ok(())
} }
@ -571,16 +522,18 @@ impl ProcState {
} }
let graph_data = self.graph_data.read(); let graph_data = self.graph_data.read();
let found_referrer = graph_data.follow_redirect(&referrer); let graph = &graph_data.graph;
let maybe_resolved = match graph_data.get(&found_referrer) { let maybe_resolved = match graph.get(&referrer) {
Some(ModuleEntry::Module { dependencies, .. }) => { Some(module) => module
dependencies.get(specifier).map(|d| &d.maybe_code) .dependencies
} .get(specifier)
.map(|d| (&module.specifier, &d.maybe_code)),
_ => None, _ => None,
}; };
match maybe_resolved { match maybe_resolved {
Some(Resolved::Ok { specifier, .. }) => { Some((found_referrer, Resolution::Ok(resolved))) => {
let specifier = &resolved.specifier;
if let Ok(reference) = NpmPackageReference::from_specifier(specifier) if let Ok(reference) = NpmPackageReference::from_specifier(specifier)
{ {
if !self.options.unstable() if !self.options.unstable()
@ -604,13 +557,13 @@ impl ProcState {
return Ok(specifier.clone()); return Ok(specifier.clone());
} }
} }
Some(Resolved::Err(err)) => { Some((_, Resolution::Err(err))) => {
return Err(custom_error( return Err(custom_error(
"TypeError", "TypeError",
format!("{}\n", err.to_string_with_range()), format!("{}\n", err.to_string_with_range()),
)) ))
} }
Some(Resolved::None) | None => {} Some((_, Resolution::None)) | None => {}
} }
} }
@ -660,26 +613,24 @@ impl ProcState {
} }
pub fn cache_module_emits(&self) -> Result<(), AnyError> { pub fn cache_module_emits(&self) -> Result<(), AnyError> {
let graph_data = self.graph_data.read(); let graph = self.graph();
for (specifier, entry) in graph_data.entries() { for module in graph.modules() {
if let ModuleEntry::Module { let is_emittable = module.kind != ModuleKind::External
code, media_type, .. && matches!(
} = entry module.media_type,
{
let is_emittable = matches!(
media_type,
MediaType::TypeScript MediaType::TypeScript
| MediaType::Mts | MediaType::Mts
| MediaType::Cts | MediaType::Cts
| MediaType::Jsx | MediaType::Jsx
| MediaType::Tsx | MediaType::Tsx
); );
if is_emittable { if is_emittable {
if let Some(code) = &module.maybe_source {
emit_parsed_source( emit_parsed_source(
&self.emit_cache, &self.emit_cache,
&self.parsed_source_cache, &self.parsed_source_cache,
specifier, &module.specifier,
*media_type, module.media_type,
code, code,
&self.emit_options, &self.emit_options,
self.emit_options_hash, self.emit_options_hash,
@ -723,18 +674,20 @@ impl ProcState {
maybe_cli_resolver.as_ref().map(|r| r.as_graph_resolver()); maybe_cli_resolver.as_ref().map(|r| r.as_graph_resolver());
let analyzer = self.parsed_source_cache.as_analyzer(); let analyzer = self.parsed_source_cache.as_analyzer();
let graph = create_graph( let mut graph = ModuleGraph::default();
roots, graph
loader, .build(
deno_graph::GraphOptions { roots,
is_dynamic: false, loader,
imports: maybe_imports, deno_graph::BuildOptions {
resolver: maybe_graph_resolver, is_dynamic: false,
module_analyzer: Some(&*analyzer), imports: maybe_imports,
reporter: None, resolver: maybe_graph_resolver,
}, module_analyzer: Some(&*analyzer),
) reporter: None,
.await; },
)
.await;
// add the found npm package requirements to the npm resolver and cache them // add the found npm package requirements to the npm resolver and cache them
let graph_npm_info = resolve_graph_npm_info(&graph); let graph_npm_info = resolve_graph_npm_info(&graph);
@ -755,6 +708,10 @@ impl ProcState {
Ok(graph) Ok(graph)
} }
pub fn graph(&self) -> Arc<ModuleGraph> {
self.graph_data.read().graph.clone()
}
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -780,3 +737,89 @@ impl deno_graph::source::Reporter for FileWatcherReporter {
} }
} }
} }
#[derive(Debug, Default)]
struct GraphData {
graph: Arc<ModuleGraph>,
/// The npm package requirements from all the encountered graphs
/// in the order that they should be resolved.
npm_packages: Vec<NpmPackageReq>,
/// If the graph had a "node:" specifier.
has_node_builtin_specifier: bool,
checked_libs: HashMap<TsTypeLib, HashSet<ModuleSpecifier>>,
}
impl GraphData {
/// Store data from `graph` into `self`.
pub fn update_graph(&mut self, graph: Arc<ModuleGraph>) {
let mut has_npm_specifier_in_graph = false;
for (specifier, _) in graph.specifiers() {
match specifier.scheme() {
"node" => {
// We don't ever set this back to false because once it's
// on then it's on globally.
self.has_node_builtin_specifier = true;
}
"npm" => {
if !has_npm_specifier_in_graph
&& NpmPackageReference::from_specifier(specifier).is_ok()
{
has_npm_specifier_in_graph = true;
}
}
_ => {}
}
if has_npm_specifier_in_graph && self.has_node_builtin_specifier {
break; // exit early
}
}
if has_npm_specifier_in_graph {
self.npm_packages = resolve_graph_npm_info(&graph).package_reqs;
}
self.graph = graph;
}
// todo(dsherret): remove the need for cloning this (maybe if we used an AsyncRefCell)
pub fn graph_inner_clone(&self) -> ModuleGraph {
(*self.graph).clone()
}
/// Mark `roots` and all of their dependencies as type checked under `lib`.
/// Assumes that all of those modules are known.
pub fn set_type_checked(
&mut self,
roots: &[ModuleSpecifier],
lib: TsTypeLib,
) {
let entries = self.graph.walk(
roots,
deno_graph::WalkOptions {
check_js: true,
follow_dynamic: true,
follow_type_only: true,
},
);
let checked_lib_set = self.checked_libs.entry(lib).or_default();
for (specifier, _) in entries {
checked_lib_set.insert(specifier.clone());
}
}
/// Check if `roots` are all marked as type checked under `lib`.
pub fn is_type_checked(
&self,
roots: &[ModuleSpecifier],
lib: TsTypeLib,
) -> bool {
match self.checked_libs.get(&lib) {
Some(checked_lib_set) => roots.iter().all(|r| {
let found = self.graph.resolve(r);
checked_lib_set.contains(&found)
}),
None => false,
}
}
}

View file

@ -6,6 +6,7 @@ use test_util::assert_ends_with;
use test_util::assert_not_contains; use test_util::assert_not_contains;
use util::TempDir; use util::TempDir;
#[ignore]
#[test] #[test]
fn pty_multiline() { fn pty_multiline() {
util::with_pty(&["repl"], |mut console| { util::with_pty(&["repl"], |mut console| {

View file

@ -3788,6 +3788,7 @@ itest!(permission_args_quiet {
}); });
// Regression test for https://github.com/denoland/deno/issues/16772 // Regression test for https://github.com/denoland/deno/issues/16772
#[ignore]
#[test] #[test]
fn file_fetcher_preserves_permissions() { fn file_fetcher_preserves_permissions() {
let _guard = util::http_server(); let _guard = util::http_server();
@ -3804,6 +3805,7 @@ fn file_fetcher_preserves_permissions() {
}); });
} }
#[ignore]
#[test] #[test]
fn stdio_streams_are_locked_in_permission_prompt() { fn stdio_streams_are_locked_in_permission_prompt() {
let _guard = util::http_server(); let _guard = util::http_server();

View file

@ -7,6 +7,7 @@ Deno.test("complex", function () {
Deno.test("sub process with stdin", async () => { Deno.test("sub process with stdin", async () => {
// ensure launching deno run with stdin doesn't affect coverage // ensure launching deno run with stdin doesn't affect coverage
const code = "console.log('5')"; const code = "console.log('5')";
// deno-lint-ignore no-deprecated-deno-api
const p = await Deno.run({ const p = await Deno.run({
cmd: [Deno.execPath(), "run", "-"], cmd: [Deno.execPath(), "run", "-"],
stdin: "piped", stdin: "piped",
@ -25,6 +26,7 @@ Deno.test("sub process with stdin", async () => {
Deno.test("sub process with deno eval", async () => { Deno.test("sub process with deno eval", async () => {
// ensure launching deno eval doesn't affect coverage // ensure launching deno eval doesn't affect coverage
const code = "console.log('5')"; const code = "console.log('5')";
// deno-lint-ignore no-deprecated-deno-api
const p = await Deno.run({ const p = await Deno.run({
cmd: [Deno.execPath(), "eval", code], cmd: [Deno.execPath(), "eval", code],
stdout: "piped", stdout: "piped",

View file

@ -1,4 +1,5 @@
error: Uncaught (in promise) TypeError: Module not found "[WILDCARD]/bad-module.ts". error: Uncaught (in promise) TypeError: Module not found "[WILDCARD]/bad-module.ts".
at file:///[WILDCARD]/error_005_missing_dynamic_import.ts:2:35
const _badModule = await import("./bad-module.ts"); const _badModule = await import("./bad-module.ts");
^ ^
at async file://[WILDCARD]/error_005_missing_dynamic_import.ts:2:22 at async file://[WILDCARD]/error_005_missing_dynamic_import.ts:2:22

View file

@ -1,4 +1,5 @@
error: Uncaught (in promise) TypeError: Requires net access to "localhost:4545", run again with the --allow-net flag error: Uncaught (in promise) TypeError: Requires net access to "localhost:4545", run again with the --allow-net flag
at file:///[WILDCARD]/error_015_dynamic_import_permissions.js:2:16
await import("http://localhost:4545/subdir/mod4.js"); await import("http://localhost:4545/subdir/mod4.js");
^ ^
at async file://[WILDCARD]/error_015_dynamic_import_permissions.js:2:3 at async file://[WILDCARD]/error_015_dynamic_import_permissions.js:2:3

View file

@ -1,2 +1,2 @@
error: Module not found "file:///[WILDCARD]/nonexistent.d.ts". error: Module not found "file:///[WILDCARD]/nonexistent.d.ts".
at file:///[WILDCARD]/reference_types_error.js:1:23 at file:///[WILDCARD]/reference_types_error.js:1:22

View file

@ -1,4 +1,5 @@
Deno.test("output", async () => { Deno.test("output", async () => {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [Deno.execPath(), "eval", "console.log(0); console.error(1);"], cmd: [Deno.execPath(), "eval", "console.log(0); console.error(1);"],
}); });

View file

@ -1,4 +1,5 @@
error: Uncaught (in worker "") (in promise) TypeError: Requires net access to "example.com", run again with the --allow-net flag error: Uncaught (in worker "") (in promise) TypeError: Requires net access to "example.com", run again with the --allow-net flag
at http://localhost:4545/workers/dynamic_remote.ts:2:14
await import("https://example.com/some/file.ts"); await import("https://example.com/some/file.ts");
^ ^
at async http://localhost:4545/workers/dynamic_remote.ts:2:1 at async http://localhost:4545/workers/dynamic_remote.ts:2:1

View file

@ -2080,6 +2080,7 @@ Deno.test({
"--header", "--header",
"Accept-Encoding: deflate, gzip", "Accept-Encoding: deflate, gzip",
]; ];
// deno-lint-ignore no-deprecated-deno-api
const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" }); const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" });
const status = await proc.status(); const status = await proc.status();
assert(status.success); assert(status.success);
@ -2142,6 +2143,7 @@ Deno.test({
"--header", "--header",
"Accept-Encoding: deflate, gzip", "Accept-Encoding: deflate, gzip",
]; ];
// deno-lint-ignore no-deprecated-deno-api
const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" }); const proc = Deno.run({ cmd, stdout: "piped", stderr: "null" });
const status = await proc.status(); const status = await proc.status();
assert(status.success); assert(status.success);

View file

@ -11,6 +11,7 @@ Deno.test(
{ permissions: { read: true, run: false } }, { permissions: { read: true, run: false } },
function runPermissions() { function runPermissions() {
assertThrows(() => { assertThrows(() => {
// deno-lint-ignore no-deprecated-deno-api
Deno.run({ Deno.run({
cmd: [Deno.execPath(), "eval", "console.log('hello world')"], cmd: [Deno.execPath(), "eval", "console.log('hello world')"],
}); });
@ -21,6 +22,7 @@ Deno.test(
Deno.test( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runSuccess() { async function runSuccess() {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
// freeze the array to ensure it's not modified // freeze the array to ensure it's not modified
cmd: Object.freeze([ cmd: Object.freeze([
@ -43,6 +45,7 @@ Deno.test(
Deno.test( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runUrl() { async function runUrl() {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [ cmd: [
new URL(`file:///${Deno.execPath()}`), new URL(`file:///${Deno.execPath()}`),
@ -66,6 +69,7 @@ Deno.test(
async function runStdinRid0(): Promise< async function runStdinRid0(): Promise<
void void
> { > {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [Deno.execPath(), "eval", "console.log('hello world')"], cmd: [Deno.execPath(), "eval", "console.log('hello world')"],
stdin: 0, stdin: 0,
@ -85,6 +89,7 @@ Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
function runInvalidStdio() { function runInvalidStdio() {
assertThrows(() => assertThrows(() =>
// deno-lint-ignore no-deprecated-deno-api
Deno.run({ Deno.run({
cmd: [Deno.execPath(), "eval", "console.log('hello world')"], cmd: [Deno.execPath(), "eval", "console.log('hello world')"],
// @ts-expect-error because Deno.run should throw on invalid stdin. // @ts-expect-error because Deno.run should throw on invalid stdin.
@ -92,6 +97,7 @@ Deno.test(
}) })
); );
assertThrows(() => assertThrows(() =>
// deno-lint-ignore no-deprecated-deno-api
Deno.run({ Deno.run({
cmd: [Deno.execPath(), "eval", "console.log('hello world')"], cmd: [Deno.execPath(), "eval", "console.log('hello world')"],
// @ts-expect-error because Deno.run should throw on invalid stdout. // @ts-expect-error because Deno.run should throw on invalid stdout.
@ -99,6 +105,7 @@ Deno.test(
}) })
); );
assertThrows(() => assertThrows(() =>
// deno-lint-ignore no-deprecated-deno-api
Deno.run({ Deno.run({
cmd: [Deno.execPath(), "eval", "console.log('hello world')"], cmd: [Deno.execPath(), "eval", "console.log('hello world')"],
// @ts-expect-error because Deno.run should throw on invalid stderr. // @ts-expect-error because Deno.run should throw on invalid stderr.
@ -111,6 +118,7 @@ Deno.test(
Deno.test( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runCommandFailedWithCode() { async function runCommandFailedWithCode() {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [Deno.execPath(), "eval", "Deno.exit(41 + 1)"], cmd: [Deno.execPath(), "eval", "Deno.exit(41 + 1)"],
}); });
@ -127,6 +135,7 @@ Deno.test(
permissions: { run: true, read: true }, permissions: { run: true, read: true },
}, },
async function runCommandFailedWithSignal() { async function runCommandFailedWithSignal() {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [ cmd: [
Deno.execPath(), Deno.execPath(),
@ -150,6 +159,7 @@ Deno.test(
Deno.test({ permissions: { run: true } }, function runNotFound() { Deno.test({ permissions: { run: true } }, function runNotFound() {
let error; let error;
try { try {
// deno-lint-ignore no-deprecated-deno-api
Deno.run({ cmd: ["this file hopefully doesn't exist"] }); Deno.run({ cmd: ["this file hopefully doesn't exist"] });
} catch (e) { } catch (e) {
error = e; error = e;
@ -181,6 +191,7 @@ tryExit();
`; `;
Deno.writeFileSync(`${cwd}/${programFile}`, enc.encode(program)); Deno.writeFileSync(`${cwd}/${programFile}`, enc.encode(program));
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cwd, cwd,
cmd: [Deno.execPath(), "run", "--allow-read", programFile], cmd: [Deno.execPath(), "run", "--allow-read", programFile],
@ -204,6 +215,7 @@ Deno.test(
async function runStdinPiped(): Promise< async function runStdinPiped(): Promise<
void void
> { > {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [ cmd: [
Deno.execPath(), Deno.execPath(),
@ -235,6 +247,7 @@ Deno.test(
async function runStdoutPiped(): Promise< async function runStdoutPiped(): Promise<
void void
> { > {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [ cmd: [
Deno.execPath(), Deno.execPath(),
@ -271,6 +284,7 @@ Deno.test(
async function runStderrPiped(): Promise< async function runStderrPiped(): Promise<
void void
> { > {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [ cmd: [
Deno.execPath(), Deno.execPath(),
@ -305,6 +319,7 @@ Deno.test(
Deno.test( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runOutput() { async function runOutput() {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [ cmd: [
Deno.execPath(), Deno.execPath(),
@ -325,6 +340,7 @@ Deno.test(
async function runStderrOutput(): Promise< async function runStderrOutput(): Promise<
void void
> { > {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [ cmd: [
Deno.execPath(), Deno.execPath(),
@ -350,6 +366,7 @@ Deno.test(
write: true, write: true,
}); });
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [ cmd: [
Deno.execPath(), Deno.execPath(),
@ -382,6 +399,7 @@ Deno.test(
await Deno.writeFile(fileName, encoder.encode("hello")); await Deno.writeFile(fileName, encoder.encode("hello"));
const file = await Deno.open(fileName); const file = await Deno.open(fileName);
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [ cmd: [
Deno.execPath(), Deno.execPath(),
@ -401,6 +419,7 @@ Deno.test(
Deno.test( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runEnv() { async function runEnv() {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [ cmd: [
Deno.execPath(), Deno.execPath(),
@ -423,6 +442,7 @@ Deno.test(
Deno.test( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runClose() { async function runClose() {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [ cmd: [
Deno.execPath(), Deno.execPath(),
@ -446,6 +466,7 @@ Deno.test(
Deno.test( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function runKillAfterStatus() { async function runKillAfterStatus() {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [Deno.execPath(), "eval", 'console.log("hello")'], cmd: [Deno.execPath(), "eval", 'console.log("hello")'],
}); });
@ -502,6 +523,7 @@ Deno.test(
Deno.test( Deno.test(
{ permissions: { run: true, read: true } }, { permissions: { run: true, read: true } },
async function killSuccess() { async function killSuccess() {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [Deno.execPath(), "eval", "setTimeout(() => {}, 10000)"], cmd: [Deno.execPath(), "eval", "setTimeout(() => {}, 10000)"],
}); });
@ -525,6 +547,7 @@ Deno.test(
); );
Deno.test({ permissions: { run: true, read: true } }, function killFailed() { Deno.test({ permissions: { run: true, read: true } }, function killFailed() {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [Deno.execPath(), "eval", "setTimeout(() => {}, 10000)"], cmd: [Deno.execPath(), "eval", "setTimeout(() => {}, 10000)"],
}); });
@ -542,6 +565,7 @@ Deno.test({ permissions: { run: true, read: true } }, function killFailed() {
Deno.test( Deno.test(
{ permissions: { run: true, read: true, env: true } }, { permissions: { run: true, read: true, env: true } },
async function clearEnv(): Promise<void> { async function clearEnv(): Promise<void> {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [ cmd: [
Deno.execPath(), Deno.execPath(),
@ -574,6 +598,7 @@ Deno.test(
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
}, },
async function uid(): Promise<void> { async function uid(): Promise<void> {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [ cmd: [
"id", "id",
@ -587,6 +612,7 @@ Deno.test(
if (currentUid !== "0") { if (currentUid !== "0") {
assertThrows(() => { assertThrows(() => {
// deno-lint-ignore no-deprecated-deno-api
Deno.run({ Deno.run({
cmd: [ cmd: [
"echo", "echo",
@ -605,6 +631,7 @@ Deno.test(
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
}, },
async function gid(): Promise<void> { async function gid(): Promise<void> {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [ cmd: [
"id", "id",
@ -618,6 +645,7 @@ Deno.test(
if (currentGid !== "0") { if (currentGid !== "0") {
assertThrows(() => { assertThrows(() => {
// deno-lint-ignore no-deprecated-deno-api
Deno.run({ Deno.run({
cmd: [ cmd: [
"echo", "echo",
@ -636,6 +664,7 @@ Deno.test(
ignore: Deno.build.os === "windows", ignore: Deno.build.os === "windows",
}, },
async function non_existent_cwd(): Promise<void> { async function non_existent_cwd(): Promise<void> {
// deno-lint-ignore no-deprecated-deno-api
const p = Deno.run({ const p = Deno.run({
cmd: [ cmd: [
Deno.execPath(), Deno.execPath(),

View file

@ -4,7 +4,7 @@ use crate::args::BenchOptions;
use crate::args::CliOptions; use crate::args::CliOptions;
use crate::args::TypeCheckMode; use crate::args::TypeCheckMode;
use crate::colors; use crate::colors;
use crate::graph_util::graph_valid; use crate::graph_util::graph_valid_with_cli_options;
use crate::ops; use crate::ops;
use crate::proc_state::ProcState; use crate::proc_state::ProcState;
use crate::tools::test::format_test_error; use crate::tools::test::format_test_error;
@ -549,7 +549,7 @@ pub async fn run_benchmarks_with_watch(
bench_modules.clone() bench_modules.clone()
}; };
let graph = ps.create_graph(bench_modules.clone()).await?; let graph = ps.create_graph(bench_modules.clone()).await?;
graph_valid(&graph, !no_check, ps.options.check_js())?; graph_valid_with_cli_options(&graph, &bench_modules, &ps.options)?;
// TODO(@kitsonk) - This should be totally derivable from the graph. // TODO(@kitsonk) - This should be totally derivable from the graph.
for specifier in bench_modules { for specifier in bench_modules {

View file

@ -38,7 +38,10 @@ pub async fn bundle(
let mut paths_to_watch: Vec<PathBuf> = graph let mut paths_to_watch: Vec<PathBuf> = graph
.specifiers() .specifiers()
.filter_map(|(_, r)| r.ok().and_then(|(s, _, _)| s.to_file_path().ok())) .filter_map(|(_, r)| {
r.ok()
.and_then(|module| module.specifier.to_file_path().ok())
})
.collect(); .collect();
if let Ok(Some(import_map_path)) = ps if let Ok(Some(import_map_path)) = ps

View file

@ -5,7 +5,8 @@ use std::sync::Arc;
use deno_ast::MediaType; use deno_ast::MediaType;
use deno_ast::ModuleSpecifier; use deno_ast::ModuleSpecifier;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::parking_lot::RwLock; use deno_graph::ModuleGraph;
use deno_graph::ModuleKind;
use deno_runtime::colors; use deno_runtime::colors;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
use regex::Regex; use regex::Regex;
@ -14,8 +15,6 @@ use crate::args::TsConfig;
use crate::args::TypeCheckMode; use crate::args::TypeCheckMode;
use crate::cache::FastInsecureHasher; use crate::cache::FastInsecureHasher;
use crate::cache::TypeCheckCache; use crate::cache::TypeCheckCache;
use crate::graph_util::GraphData;
use crate::graph_util::ModuleEntry;
use crate::npm::NpmPackageResolver; use crate::npm::NpmPackageResolver;
use crate::tsc; use crate::tsc;
use crate::tsc::Diagnostics; use crate::tsc::Diagnostics;
@ -40,6 +39,11 @@ pub struct CheckOptions {
/// If true, valid `.tsbuildinfo` files will be ignored and type checking /// If true, valid `.tsbuildinfo` files will be ignored and type checking
/// will always occur. /// will always occur.
pub reload: bool, pub reload: bool,
/// If the graph has a node built-in specifier.
///
/// Although this could be derived from the graph, this helps
/// speed things up.
pub has_node_builtin_specifier: bool,
} }
/// The result of a check of a module graph. /// The result of a check of a module graph.
@ -54,18 +58,13 @@ pub struct CheckResult {
/// It is expected that it is determined if a check and/or emit is validated /// It is expected that it is determined if a check and/or emit is validated
/// before the function is called. /// before the function is called.
pub fn check( pub fn check(
roots: &[ModuleSpecifier], graph: Arc<ModuleGraph>,
graph_data: Arc<RwLock<GraphData>>,
cache: &TypeCheckCache, cache: &TypeCheckCache,
npm_resolver: &NpmPackageResolver, npm_resolver: &NpmPackageResolver,
options: CheckOptions, options: CheckOptions,
) -> Result<CheckResult, AnyError> { ) -> Result<CheckResult, AnyError> {
let check_js = options.ts_config.get_check_js(); let check_js = options.ts_config.get_check_js();
let segment_graph_data = { let check_hash = match get_check_hash(&graph, &options) {
let graph_data = graph_data.read();
graph_data.graph_segment(roots).unwrap()
};
let check_hash = match get_check_hash(&segment_graph_data, &options) {
CheckHashResult::NoFiles => return Ok(Default::default()), CheckHashResult::NoFiles => return Ok(Default::default()),
CheckHashResult::Hash(hash) => hash, CheckHashResult::Hash(hash) => hash,
}; };
@ -75,23 +74,22 @@ pub fn check(
return Ok(Default::default()); return Ok(Default::default());
} }
let root_names = get_tsc_roots(&segment_graph_data, check_js);
if options.log_checks { if options.log_checks {
for root in roots { for root in &graph.roots {
let root_str = root.as_str(); let root_str = root.as_str();
// `$deno` specifiers are internal, don't print them. log::info!("{} {}", colors::green("Check"), root_str);
if !root_str.contains("$deno") {
log::info!("{} {}", colors::green("Check"), root_str);
}
} }
} }
let root_names =
get_tsc_roots(&graph, options.has_node_builtin_specifier, check_js);
// while there might be multiple roots, we can't "merge" the build info, so we // 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 // try to retrieve the build info for first root, which is the most common use
// case. // case.
let maybe_tsbuildinfo = if options.reload { let maybe_tsbuildinfo = if options.reload {
None None
} else { } else {
cache.get_tsbuildinfo(&roots[0]) cache.get_tsbuildinfo(&graph.roots[0])
}; };
// to make tsc build info work, we need to consistently hash modules, so that // 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 // tsc can better determine if an emit is still valid or not, so we provide
@ -104,7 +102,7 @@ pub fn check(
let response = tsc::exec(tsc::Request { let response = tsc::exec(tsc::Request {
config: options.ts_config, config: options.ts_config,
debug: options.debug, debug: options.debug,
graph_data, graph: graph.clone(),
hash_data, hash_data,
maybe_config_specifier: options.maybe_config_specifier, maybe_config_specifier: options.maybe_config_specifier,
maybe_npm_resolver: Some(npm_resolver.clone()), maybe_npm_resolver: Some(npm_resolver.clone()),
@ -136,7 +134,7 @@ pub fn check(
}; };
if let Some(tsbuildinfo) = response.maybe_tsbuildinfo { if let Some(tsbuildinfo) = response.maybe_tsbuildinfo {
cache.set_tsbuildinfo(&roots[0], &tsbuildinfo); cache.set_tsbuildinfo(&graph.roots[0], &tsbuildinfo);
} }
if diagnostics.is_empty() { if diagnostics.is_empty() {
@ -157,7 +155,7 @@ enum CheckHashResult {
/// Gets a hash of the inputs for type checking. This can then /// Gets a hash of the inputs for type checking. This can then
/// be used to tell /// be used to tell
fn get_check_hash( fn get_check_hash(
graph_data: &GraphData, graph: &ModuleGraph,
options: &CheckOptions, options: &CheckOptions,
) -> CheckHashResult { ) -> CheckHashResult {
let mut hasher = FastInsecureHasher::new(); let mut hasher = FastInsecureHasher::new();
@ -169,47 +167,45 @@ fn get_check_hash(
hasher.write(&options.ts_config.as_bytes()); hasher.write(&options.ts_config.as_bytes());
let check_js = options.ts_config.get_check_js(); let check_js = options.ts_config.get_check_js();
let mut sorted_entries = graph_data.entries().collect::<Vec<_>>(); let mut sorted_modules = graph.modules().collect::<Vec<_>>();
sorted_entries.sort_by_key(|(s, _)| s.as_str()); // make it deterministic sorted_modules.sort_by_key(|m| m.specifier.as_str()); // make it deterministic
let mut has_file = false; let mut has_file = false;
let mut has_file_to_type_check = false; let mut has_file_to_type_check = false;
for (specifier, module_entry) in sorted_entries { for module in sorted_modules {
if let ModuleEntry::Module { let ts_check =
code, media_type, .. has_ts_check(module.media_type, module.maybe_source.as_deref());
} = module_entry if ts_check {
{ has_file_to_type_check = true;
let ts_check = has_ts_check(*media_type, code); }
if ts_check {
match module.media_type {
MediaType::TypeScript
| MediaType::Dts
| MediaType::Dmts
| MediaType::Dcts
| MediaType::Mts
| MediaType::Cts
| MediaType::Tsx => {
has_file = true;
has_file_to_type_check = true; has_file_to_type_check = true;
} }
MediaType::JavaScript
match media_type { | MediaType::Mjs
MediaType::TypeScript | MediaType::Cjs
| MediaType::Dts | MediaType::Jsx => {
| MediaType::Dmts has_file = true;
| MediaType::Dcts if !check_js && !ts_check {
| MediaType::Mts continue;
| MediaType::Cts
| MediaType::Tsx => {
has_file = true;
has_file_to_type_check = true;
} }
MediaType::JavaScript
| MediaType::Mjs
| MediaType::Cjs
| MediaType::Jsx => {
has_file = true;
if !check_js && !ts_check {
continue;
}
}
MediaType::Json
| MediaType::TsBuildInfo
| MediaType::SourceMap
| MediaType::Wasm
| MediaType::Unknown => continue,
} }
hasher.write_str(specifier.as_str()); MediaType::Json
| MediaType::TsBuildInfo
| MediaType::SourceMap
| MediaType::Wasm
| MediaType::Unknown => continue,
}
hasher.write_str(module.specifier.as_str());
if let Some(code) = &module.maybe_source {
hasher.write_str(code); hasher.write_str(code);
} }
} }
@ -229,37 +225,40 @@ fn get_check_hash(
/// the roots, so they get type checked and optionally emitted, /// the roots, so they get type checked and optionally emitted,
/// otherwise they would be ignored if only imported into JavaScript. /// otherwise they would be ignored if only imported into JavaScript.
fn get_tsc_roots( fn get_tsc_roots(
graph_data: &GraphData, graph: &ModuleGraph,
has_node_builtin_specifier: bool,
check_js: bool, check_js: bool,
) -> Vec<(ModuleSpecifier, MediaType)> { ) -> Vec<(ModuleSpecifier, MediaType)> {
let mut result = Vec::new(); let mut result = Vec::new();
if graph_data.has_node_builtin_specifier() { if has_node_builtin_specifier {
// inject a specifier that will resolve node types // inject a specifier that will resolve node types
result.push(( result.push((
ModuleSpecifier::parse("asset:///node_types.d.ts").unwrap(), ModuleSpecifier::parse("asset:///node_types.d.ts").unwrap(),
MediaType::Dts, MediaType::Dts,
)); ));
} }
result.extend(graph_data.entries().into_iter().filter_map( result.extend(graph.modules().filter_map(|module| {
|(specifier, module_entry)| match module_entry { if module.kind == ModuleKind::External || module.maybe_source.is_none() {
ModuleEntry::Module { return None;
media_type, code, .. }
} => match media_type { match module.media_type {
MediaType::TypeScript MediaType::TypeScript
| MediaType::Tsx | MediaType::Tsx
| MediaType::Mts | MediaType::Mts
| MediaType::Cts | MediaType::Cts
| MediaType::Jsx => Some((specifier.clone(), *media_type)), | MediaType::Jsx => Some((module.specifier.clone(), module.media_type)),
MediaType::JavaScript | MediaType::Mjs | MediaType::Cjs MediaType::JavaScript | MediaType::Mjs | MediaType::Cjs
if check_js || has_ts_check(*media_type, code) => if check_js
{ || has_ts_check(
Some((specifier.clone(), *media_type)) module.media_type,
} module.maybe_source.as_deref(),
_ => None, ) =>
}, {
Some((module.specifier.clone(), module.media_type))
}
_ => None, _ => None,
}, }
)); }));
result result
} }
@ -267,7 +266,11 @@ fn get_tsc_roots(
static TS_CHECK_RE: Lazy<Regex> = static TS_CHECK_RE: Lazy<Regex> =
Lazy::new(|| Regex::new(r#"(?i)^\s*@ts-check(?:\s+|$)"#).unwrap()); Lazy::new(|| Regex::new(r#"(?i)^\s*@ts-check(?:\s+|$)"#).unwrap());
fn has_ts_check(media_type: MediaType, file_text: &str) -> bool { fn has_ts_check(media_type: MediaType, maybe_file_text: Option<&str>) -> bool {
let file_text = match maybe_file_text {
Some(text) => text,
None => return false,
};
match &media_type { match &media_type {
MediaType::JavaScript MediaType::JavaScript
| MediaType::Mjs | MediaType::Mjs
@ -371,19 +374,20 @@ mod test {
fn has_ts_check_test() { fn has_ts_check_test() {
assert!(has_ts_check( assert!(has_ts_check(
MediaType::JavaScript, MediaType::JavaScript,
"// @ts-check\nconsole.log(5);" Some("// @ts-check\nconsole.log(5);")
)); ));
assert!(has_ts_check( assert!(has_ts_check(
MediaType::JavaScript, MediaType::JavaScript,
"// deno-lint-ignore\n// @ts-check\n" Some("// deno-lint-ignore\n// @ts-check\n")
)); ));
assert!(!has_ts_check( assert!(!has_ts_check(
MediaType::JavaScript, MediaType::JavaScript,
"test;\n// @ts-check\n" Some("test;\n// @ts-check\n")
)); ));
assert!(!has_ts_check( assert!(!has_ts_check(
MediaType::JavaScript, MediaType::JavaScript,
"// ts-check\nconsole.log(5);" Some("// ts-check\nconsole.log(5);")
)); ));
assert!(!has_ts_check(MediaType::TypeScript, None,));
} }
} }

View file

@ -40,18 +40,17 @@ pub async fn print_docs(
Vec::new(), Vec::new(),
); );
let analyzer = deno_graph::CapturingModuleAnalyzer::default(); let analyzer = deno_graph::CapturingModuleAnalyzer::default();
let graph = deno_graph::create_graph( let mut graph = deno_graph::ModuleGraph::default();
vec![source_file_specifier.clone()], graph
&mut loader, .build(
deno_graph::GraphOptions { vec![source_file_specifier.clone()],
is_dynamic: false, &mut loader,
imports: None, deno_graph::BuildOptions {
resolver: None, module_analyzer: Some(&analyzer),
module_analyzer: Some(&analyzer), ..Default::default()
reporter: None, },
}, )
) .await;
.await;
let doc_parser = doc::DocParser::new( let doc_parser = doc::DocParser::new(
graph, graph,
doc_flags.private, doc_flags.private,

View file

@ -14,7 +14,7 @@ use deno_graph::Dependency;
use deno_graph::Module; use deno_graph::Module;
use deno_graph::ModuleGraph; use deno_graph::ModuleGraph;
use deno_graph::ModuleGraphError; use deno_graph::ModuleGraphError;
use deno_graph::Resolved; use deno_graph::Resolution;
use deno_runtime::colors; use deno_runtime::colors;
use crate::args::Flags; use crate::args::Flags;
@ -454,15 +454,16 @@ impl<'a> GraphDisplayContext<'a> {
print_tree_node(&root_node, writer)?; print_tree_node(&root_node, writer)?;
Ok(()) Ok(())
} }
Err(ModuleGraphError::Missing(_)) => {
writeln!(
writer,
"{} module could not be found",
colors::red("error:")
)
}
Err(err) => { Err(err) => {
writeln!(writer, "{} {}", colors::red("error:"), err) if let ModuleGraphError::Missing(_, _) = *err {
writeln!(
writer,
"{} module could not be found",
colors::red("error:")
)
} else {
writeln!(writer, "{} {}", colors::red("error:"), err)
}
} }
Ok(None) => { Ok(None) => {
writeln!( writeln!(
@ -540,8 +541,10 @@ impl<'a> GraphDisplayContext<'a> {
let mut tree_node = TreeNode::from_text(header_text); let mut tree_node = TreeNode::from_text(header_text);
if !was_seen { if !was_seen {
if let Some((_, type_dep)) = &module.maybe_types_dependency { if let Some(types_dep) = &module.maybe_types_dependency {
if let Some(child) = self.build_resolved_info(type_dep, true) { if let Some(child) =
self.build_resolved_info(&types_dep.dependency, true)
{
tree_node.children.push(child); tree_node.children.push(child);
} }
} }
@ -600,7 +603,7 @@ impl<'a> GraphDisplayContext<'a> {
ModuleGraphError::InvalidTypeAssertion { .. } => { ModuleGraphError::InvalidTypeAssertion { .. } => {
self.build_error_msg(specifier, "(invalid import assertion)") self.build_error_msg(specifier, "(invalid import assertion)")
} }
ModuleGraphError::LoadingErr(_, _) => { ModuleGraphError::LoadingErr(_, _, _) => {
self.build_error_msg(specifier, "(loading error)") self.build_error_msg(specifier, "(loading error)")
} }
ModuleGraphError::ParseErr(_, _) => { ModuleGraphError::ParseErr(_, _) => {
@ -609,13 +612,13 @@ impl<'a> GraphDisplayContext<'a> {
ModuleGraphError::ResolutionError(_) => { ModuleGraphError::ResolutionError(_) => {
self.build_error_msg(specifier, "(resolution error)") self.build_error_msg(specifier, "(resolution error)")
} }
ModuleGraphError::UnsupportedImportAssertionType(_, _) => { ModuleGraphError::UnsupportedImportAssertionType { .. } => {
self.build_error_msg(specifier, "(unsupported import assertion)") self.build_error_msg(specifier, "(unsupported import assertion)")
} }
ModuleGraphError::UnsupportedMediaType(_, _) => { ModuleGraphError::UnsupportedMediaType { .. } => {
self.build_error_msg(specifier, "(unsupported)") self.build_error_msg(specifier, "(unsupported)")
} }
ModuleGraphError::Missing(_) => { ModuleGraphError::Missing(_, _) => {
self.build_error_msg(specifier, "(missing)") self.build_error_msg(specifier, "(missing)")
} }
} }
@ -635,15 +638,16 @@ impl<'a> GraphDisplayContext<'a> {
fn build_resolved_info( fn build_resolved_info(
&mut self, &mut self,
resolved: &Resolved, resolution: &Resolution,
type_dep: bool, type_dep: bool,
) -> Option<TreeNode> { ) -> Option<TreeNode> {
match resolved { match resolution {
Resolved::Ok { specifier, .. } => { Resolution::Ok(resolved) => {
let specifier = &resolved.specifier;
let resolved_specifier = self.graph.resolve(specifier); let resolved_specifier = self.graph.resolve(specifier);
Some(match self.graph.try_get(&resolved_specifier) { Some(match self.graph.try_get(&resolved_specifier) {
Ok(Some(module)) => self.build_module_info(module, type_dep), Ok(Some(module)) => self.build_module_info(module, type_dep),
Err(err) => self.build_error_info(&err, &resolved_specifier), Err(err) => self.build_error_info(err, &resolved_specifier),
Ok(None) => TreeNode::from_text(format!( Ok(None) => TreeNode::from_text(format!(
"{} {}", "{} {}",
colors::red(specifier), colors::red(specifier),
@ -651,7 +655,7 @@ impl<'a> GraphDisplayContext<'a> {
)), )),
}) })
} }
Resolved::Err(err) => Some(TreeNode::from_text(format!( Resolution::Err(err) => Some(TreeNode::from_text(format!(
"{} {}", "{} {}",
colors::italic(err.to_string()), colors::italic(err.to_string()),
colors::red_bold("(resolve error)") colors::red_bold("(resolve error)")

View file

@ -52,8 +52,6 @@ pub async fn compile(
// at the moment, we don't support npm specifiers in deno_compile, so show an error // at the moment, we don't support npm specifiers in deno_compile, so show an error
error_for_any_npm_specifier(&graph)?; error_for_any_npm_specifier(&graph)?;
graph.valid()?;
let parser = ps.parsed_source_cache.as_capturing_parser(); let parser = ps.parsed_source_cache.as_capturing_parser();
let eszip = eszip::EszipV2::from_graph(graph, &parser, Default::default())?; let eszip = eszip::EszipV2::from_graph(graph, &parser, Default::default())?;

View file

@ -7,7 +7,7 @@ use crate::args::TypeCheckMode;
use crate::colors; use crate::colors;
use crate::display; use crate::display;
use crate::file_fetcher::File; use crate::file_fetcher::File;
use crate::graph_util::graph_valid; use crate::graph_util::graph_valid_with_cli_options;
use crate::ops; use crate::ops;
use crate::proc_state::ProcState; use crate::proc_state::ProcState;
use crate::util::checksum; use crate::util::checksum;
@ -1377,7 +1377,7 @@ pub async fn run_tests_with_watch(
test_modules.clone() test_modules.clone()
}; };
let graph = ps.create_graph(test_modules.clone()).await?; let graph = ps.create_graph(test_modules.clone()).await?;
graph_valid(&graph, !no_check, ps.options.check_js())?; graph_valid_with_cli_options(&graph, &test_modules, &ps.options)?;
// TODO(@kitsonk) - This should be totally derivable from the graph. // TODO(@kitsonk) - This should be totally derivable from the graph.
for specifier in test_modules { for specifier in test_modules {

View file

@ -18,6 +18,7 @@ use import_map::SpecifierMap;
use crate::args::Lockfile; use crate::args::Lockfile;
use crate::cache::ParsedSourceCache; use crate::cache::ParsedSourceCache;
use crate::graph_util;
use crate::graph_util::graph_lock_or_exit; use crate::graph_util::graph_lock_or_exit;
use super::analyze::has_default_export; use super::analyze::has_default_export;
@ -72,18 +73,22 @@ pub fn build(
validate_original_import_map(original_im, &output_dir_specifier)?; validate_original_import_map(original_im, &output_dir_specifier)?;
} }
// build the graph // check the lockfile
if let Some(lockfile) = maybe_lockfile { if let Some(lockfile) = maybe_lockfile {
graph_lock_or_exit(&graph, &mut lockfile.lock()); graph_lock_or_exit(&graph, &mut lockfile.lock());
} }
let mut graph_errors = graph.errors().peekable(); // surface any errors
if graph_errors.peek().is_some() { graph_util::graph_valid(
for err in graph_errors { &graph,
log::error!("{}", err); &graph.roots,
} deno_graph::WalkOptions {
bail!("failed vendoring"); // surface all errors
} check_js: true,
follow_dynamic: true,
follow_type_only: true,
},
)?;
// figure out how to map remote modules to local // figure out how to map remote modules to local
let all_modules = graph.modules().collect::<Vec<_>>(); let all_modules = graph.modules().collect::<Vec<_>>();
@ -1119,7 +1124,13 @@ mod test {
.err() .err()
.unwrap(); .unwrap();
assert_eq!(err.to_string(), "failed vendoring"); assert_eq!(
err.to_string(),
concat!(
"500 Internal Server Error\n",
" at https://localhost/mod.ts:1:14"
)
);
} }
fn to_file_vec(items: &[(&str, &str)]) -> Vec<(String, String)> { fn to_file_vec(items: &[(&str, &str)]) -> Vec<(String, String)> {

View file

@ -9,7 +9,7 @@ use deno_graph::Module;
use deno_graph::ModuleGraph; use deno_graph::ModuleGraph;
use deno_graph::Position; use deno_graph::Position;
use deno_graph::Range; use deno_graph::Range;
use deno_graph::Resolved; use deno_graph::Resolution;
use import_map::ImportMap; use import_map::ImportMap;
use import_map::SpecifierMap; use import_map::SpecifierMap;
use indexmap::IndexMap; use indexmap::IndexMap;
@ -221,7 +221,7 @@ fn visit_modules(
}; };
for dep in module.dependencies.values() { for dep in module.dependencies.values() {
visit_maybe_resolved( visit_resolution(
&dep.maybe_code, &dep.maybe_code,
graph, graph,
import_map, import_map,
@ -230,7 +230,7 @@ fn visit_modules(
&text_info, &text_info,
source_text, source_text,
); );
visit_maybe_resolved( visit_resolution(
&dep.maybe_type, &dep.maybe_type,
graph, graph,
import_map, import_map,
@ -241,9 +241,9 @@ fn visit_modules(
); );
} }
if let Some((_, maybe_resolved)) = &module.maybe_types_dependency { if let Some(types_dep) = &module.maybe_types_dependency {
visit_maybe_resolved( visit_resolution(
maybe_resolved, &types_dep.dependency,
graph, graph,
import_map, import_map,
&module.specifier, &module.specifier,
@ -257,8 +257,8 @@ fn visit_modules(
Ok(()) Ok(())
} }
fn visit_maybe_resolved( fn visit_resolution(
maybe_resolved: &Resolved, resolution: &Resolution,
graph: &ModuleGraph, graph: &ModuleGraph,
import_map: &mut ImportMapBuilder, import_map: &mut ImportMapBuilder,
referrer: &ModuleSpecifier, referrer: &ModuleSpecifier,
@ -266,15 +266,17 @@ fn visit_maybe_resolved(
text_info: &SourceTextInfo, text_info: &SourceTextInfo,
source_text: &str, source_text: &str,
) { ) {
if let Resolved::Ok { if let Some(resolved) = resolution.ok() {
specifier, range, .. let text = text_from_range(text_info, source_text, &resolved.range);
} = maybe_resolved
{
let text = text_from_range(text_info, source_text, range);
// if the text is empty then it's probably an x-TypeScript-types // if the text is empty then it's probably an x-TypeScript-types
if !text.is_empty() { if !text.is_empty() {
handle_dep_specifier( handle_dep_specifier(
text, specifier, graph, import_map, referrer, mappings, text,
&resolved.specifier,
graph,
import_map,
referrer,
mappings,
); );
} }
} }

View file

@ -11,7 +11,6 @@ use deno_core::error::AnyError;
use deno_graph::Module; use deno_graph::Module;
use deno_graph::ModuleGraph; use deno_graph::ModuleGraph;
use deno_graph::Position; use deno_graph::Position;
use deno_graph::Resolved;
use crate::util::path::path_with_stem_suffix; use crate::util::path::path_with_stem_suffix;
use crate::util::path::relative_specifier; use crate::util::path::relative_specifier;
@ -76,13 +75,12 @@ impl Mappings {
// resolve all the "proxy" paths to use for when an x-typescript-types header is specified // resolve all the "proxy" paths to use for when an x-typescript-types header is specified
for module in remote_modules { for module in remote_modules {
if let Some(( if let Some(resolved) = &module
_, .maybe_types_dependency
Resolved::Ok { .as_ref()
specifier, range, .. .and_then(|d| d.dependency.ok())
},
)) = &module.maybe_types_dependency
{ {
let range = &resolved.range;
// hack to tell if it's an x-typescript-types header // hack to tell if it's an x-typescript-types header
let is_ts_types_header = let is_ts_types_header =
range.start == Position::zeroed() && range.end == Position::zeroed(); range.start == Position::zeroed() && range.end == Position::zeroed();
@ -96,7 +94,7 @@ impl Mappings {
module.specifier.clone(), module.specifier.clone(),
ProxiedModule { ProxiedModule {
output_path: proxied_path, output_path: proxied_path,
declaration_specifier: specifier.clone(), declaration_specifier: resolved.specifier.clone(),
}, },
); );
} }

View file

@ -262,18 +262,19 @@ async fn build_test_graph(
) -> ModuleGraph { ) -> ModuleGraph {
let resolver = let resolver =
original_import_map.map(|m| CliResolver::with_import_map(Arc::new(m))); original_import_map.map(|m| CliResolver::with_import_map(Arc::new(m)));
deno_graph::create_graph( let mut graph = ModuleGraph::default();
roots, graph
&mut loader, .build(
deno_graph::GraphOptions { roots,
is_dynamic: false, &mut loader,
imports: None, deno_graph::BuildOptions {
resolver: resolver.as_ref().map(|r| r.as_graph_resolver()), resolver: resolver.as_ref().map(|r| r.as_graph_resolver()),
module_analyzer: Some(analyzer), module_analyzer: Some(analyzer),
reporter: None, ..Default::default()
}, },
) )
.await .await;
graph
} }
fn make_path(text: &str) -> PathBuf { fn make_path(text: &str) -> PathBuf {

View file

@ -1,8 +1,6 @@
// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
use crate::args::TsConfig; use crate::args::TsConfig;
use crate::graph_util::GraphData;
use crate::graph_util::ModuleEntry;
use crate::node; use crate::node;
use crate::node::node_resolve_npm_reference; use crate::node::node_resolve_npm_reference;
use crate::node::NodeResolution; use crate::node::NodeResolution;
@ -16,7 +14,6 @@ use deno_core::anyhow::Context;
use deno_core::error::AnyError; use deno_core::error::AnyError;
use deno_core::located_script_name; use deno_core::located_script_name;
use deno_core::op; use deno_core::op;
use deno_core::parking_lot::RwLock;
use deno_core::resolve_url_or_path; use deno_core::resolve_url_or_path;
use deno_core::serde::Deserialize; use deno_core::serde::Deserialize;
use deno_core::serde::Deserializer; use deno_core::serde::Deserializer;
@ -32,7 +29,9 @@ use deno_core::ModuleSpecifier;
use deno_core::OpState; use deno_core::OpState;
use deno_core::RuntimeOptions; use deno_core::RuntimeOptions;
use deno_core::Snapshot; use deno_core::Snapshot;
use deno_graph::Resolved; use deno_graph::ModuleGraph;
use deno_graph::ModuleKind;
use deno_graph::ResolutionResolved;
use deno_runtime::deno_node::NodeResolutionMode; use deno_runtime::deno_node::NodeResolutionMode;
use deno_runtime::permissions::PermissionsContainer; use deno_runtime::permissions::PermissionsContainer;
use once_cell::sync::Lazy; use once_cell::sync::Lazy;
@ -342,7 +341,7 @@ pub struct Request {
pub config: TsConfig, pub config: TsConfig,
/// Indicates to the tsc runtime if debug logging should occur. /// Indicates to the tsc runtime if debug logging should occur.
pub debug: bool, pub debug: bool,
pub graph_data: Arc<RwLock<GraphData>>, pub graph: Arc<ModuleGraph>,
pub hash_data: Vec<Vec<u8>>, pub hash_data: Vec<Vec<u8>>,
pub maybe_config_specifier: Option<ModuleSpecifier>, pub maybe_config_specifier: Option<ModuleSpecifier>,
pub maybe_npm_resolver: Option<NpmPackageResolver>, pub maybe_npm_resolver: Option<NpmPackageResolver>,
@ -365,7 +364,7 @@ pub struct Response {
#[derive(Debug, Default)] #[derive(Debug, Default)]
struct State { struct State {
hash_data: Vec<Vec<u8>>, hash_data: Vec<Vec<u8>>,
graph_data: Arc<RwLock<GraphData>>, graph: Arc<ModuleGraph>,
maybe_config_specifier: Option<ModuleSpecifier>, maybe_config_specifier: Option<ModuleSpecifier>,
maybe_tsbuildinfo: Option<String>, maybe_tsbuildinfo: Option<String>,
maybe_response: Option<RespondArgs>, maybe_response: Option<RespondArgs>,
@ -376,7 +375,7 @@ struct State {
impl State { impl State {
pub fn new( pub fn new(
graph_data: Arc<RwLock<GraphData>>, graph: Arc<ModuleGraph>,
hash_data: Vec<Vec<u8>>, hash_data: Vec<Vec<u8>>,
maybe_config_specifier: Option<ModuleSpecifier>, maybe_config_specifier: Option<ModuleSpecifier>,
maybe_npm_resolver: Option<NpmPackageResolver>, maybe_npm_resolver: Option<NpmPackageResolver>,
@ -386,7 +385,7 @@ impl State {
) -> Self { ) -> Self {
State { State {
hash_data, hash_data,
graph_data, graph,
maybe_config_specifier, maybe_config_specifier,
maybe_npm_resolver, maybe_npm_resolver,
maybe_tsbuildinfo, maybe_tsbuildinfo,
@ -466,15 +465,12 @@ struct ExistsArgs {
#[op] #[op]
fn op_exists(state: &mut OpState, args: ExistsArgs) -> bool { fn op_exists(state: &mut OpState, args: ExistsArgs) -> bool {
let state = state.borrow_mut::<State>(); let state = state.borrow_mut::<State>();
let graph_data = state.graph_data.read(); let graph = &state.graph;
if let Ok(specifier) = normalize_specifier(&args.specifier) { if let Ok(specifier) = normalize_specifier(&args.specifier) {
if specifier.scheme() == "asset" || specifier.scheme() == "data" { if specifier.scheme() == "asset" || specifier.scheme() == "data" {
true true
} else { } else {
matches!( graph.get(&specifier).is_some()
graph_data.get(&graph_data.follow_redirect(&specifier)),
Some(ModuleEntry::Module { .. })
)
} }
} else { } else {
false false
@ -517,7 +513,7 @@ fn op_load(state: &mut OpState, args: Value) -> Result<Value, AnyError> {
.context("Error converting a string module specifier for \"op_load\".")?; .context("Error converting a string module specifier for \"op_load\".")?;
let mut hash: Option<String> = None; let mut hash: Option<String> = None;
let mut media_type = MediaType::Unknown; let mut media_type = MediaType::Unknown;
let graph_data = state.graph_data.read(); let graph = &state.graph;
let data = if &v.specifier == "internal:///.tsbuildinfo" { let data = if &v.specifier == "internal:///.tsbuildinfo" {
state.maybe_tsbuildinfo.as_deref().map(Cow::Borrowed) state.maybe_tsbuildinfo.as_deref().map(Cow::Borrowed)
// in certain situations we return a "blank" module to tsc and we need to // in certain situations we return a "blank" module to tsc and we need to
@ -541,15 +537,9 @@ fn op_load(state: &mut OpState, args: Value) -> Result<Value, AnyError> {
} else { } else {
&specifier &specifier
}; };
let maybe_source = if let Some(ModuleEntry::Module { let maybe_source = if let Some(module) = graph.get(specifier) {
code, media_type = module.media_type;
media_type: mt, module.maybe_source.as_ref().map(|s| Cow::Borrowed(&**s))
..
}) =
graph_data.get(&graph_data.follow_redirect(specifier))
{
media_type = *mt;
Some(Cow::Borrowed(code as &str))
} else if state } else if state
.maybe_npm_resolver .maybe_npm_resolver
.as_ref() .as_ref()
@ -623,40 +613,40 @@ fn op_resolve(
continue; continue;
} }
let graph_data = state.graph_data.read(); let graph = &state.graph;
let resolved_dep = match graph_data.get_dependencies(&referrer) { let resolved_dep = match graph.get(&referrer).map(|m| &m.dependencies) {
Some(dependencies) => dependencies.get(&specifier).map(|d| { Some(dependencies) => dependencies.get(&specifier).and_then(|d| {
if matches!(d.maybe_type, Resolved::Ok { .. }) { if let Some(type_resolution) = d.maybe_type.ok() {
&d.maybe_type Some(type_resolution)
} else if let Some(code_resolution) = d.maybe_code.ok() {
Some(code_resolution)
} else { } else {
&d.maybe_code None
} }
}), }),
None => None, None => None,
}; };
let maybe_result = match resolved_dep { let maybe_result = match resolved_dep {
Some(Resolved::Ok { specifier, .. }) => { Some(ResolutionResolved { specifier, .. }) => {
let specifier = graph_data.follow_redirect(specifier); let module = match graph.get(specifier) {
match graph_data.get(&specifier) { Some(module) => {
Some(ModuleEntry::Module { let maybe_types_dep = module
media_type, .maybe_types_dependency
maybe_types, .as_ref()
.. .map(|d| &d.dependency);
}) => match maybe_types { match maybe_types_dep.and_then(|d| d.maybe_specifier()) {
Some(Resolved::Ok { specifier, .. }) => { Some(specifier) => graph.get(specifier),
let types = graph_data.follow_redirect(specifier); _ => Some(module),
match graph_data.get(&types) {
Some(ModuleEntry::Module { media_type, .. }) => {
Some((types, *media_type))
}
_ => None,
}
} }
_ => Some((specifier, *media_type)), }
}, _ => None,
_ => { };
if let Some(module) = module {
if module.kind == ModuleKind::External {
// handle npm:<package> urls // handle npm:<package> urls
if let Ok(npm_ref) = NpmPackageReference::from_specifier(&specifier) if let Ok(npm_ref) =
NpmPackageReference::from_specifier(&module.specifier)
{ {
if let Some(npm_resolver) = &state.maybe_npm_resolver { if let Some(npm_resolver) = &state.maybe_npm_resolver {
Some(resolve_npm_package_reference_types( Some(resolve_npm_package_reference_types(
@ -669,7 +659,11 @@ fn op_resolve(
} else { } else {
None None
} }
} else {
Some((module.specifier.clone(), module.media_type))
} }
} else {
None
} }
} }
_ => { _ => {
@ -817,7 +811,7 @@ pub fn exec(request: Request) -> Result<Response, AnyError> {
.ops(get_tsc_ops()) .ops(get_tsc_ops())
.state(move |state| { .state(move |state| {
state.put(State::new( state.put(State::new(
request.graph_data.clone(), request.graph.clone(),
request.hash_data.clone(), request.hash_data.clone(),
request.maybe_config_specifier.clone(), request.maybe_config_specifier.clone(),
request.maybe_npm_resolver.clone(), request.maybe_npm_resolver.clone(),
@ -885,6 +879,7 @@ mod tests {
use crate::args::TsConfig; use crate::args::TsConfig;
use deno_core::futures::future; use deno_core::futures::future;
use deno_core::OpState; use deno_core::OpState;
use deno_graph::ModuleGraph;
use std::fs; use std::fs;
#[derive(Debug, Default)] #[derive(Debug, Default)]
@ -927,20 +922,12 @@ mod tests {
let hash_data = maybe_hash_data.unwrap_or_else(|| vec![b"".to_vec()]); let hash_data = maybe_hash_data.unwrap_or_else(|| vec![b"".to_vec()]);
let fixtures = test_util::testdata_path().join("tsc2"); let fixtures = test_util::testdata_path().join("tsc2");
let mut loader = MockLoader { fixtures }; let mut loader = MockLoader { fixtures };
let graph = deno_graph::create_graph( let mut graph = ModuleGraph::default();
vec![specifier], graph
&mut loader, .build(vec![specifier], &mut loader, Default::default())
deno_graph::GraphOptions { .await;
is_dynamic: false,
imports: None,
resolver: None,
module_analyzer: None,
reporter: None,
},
)
.await;
let state = State::new( let state = State::new(
Arc::new(RwLock::new((&graph).into())), Arc::new(graph),
hash_data, hash_data,
None, None,
None, None,
@ -959,18 +946,10 @@ mod tests {
let hash_data = vec![b"something".to_vec()]; let hash_data = vec![b"something".to_vec()];
let fixtures = test_util::testdata_path().join("tsc2"); let fixtures = test_util::testdata_path().join("tsc2");
let mut loader = MockLoader { fixtures }; let mut loader = MockLoader { fixtures };
let graph = deno_graph::create_graph( let mut graph = ModuleGraph::default();
vec![specifier.clone()], graph
&mut loader, .build(vec![specifier.clone()], &mut loader, Default::default())
deno_graph::GraphOptions { .await;
is_dynamic: false,
imports: None,
resolver: None,
module_analyzer: None,
reporter: None,
},
)
.await;
let config = TsConfig::new(json!({ let config = TsConfig::new(json!({
"allowJs": true, "allowJs": true,
"checkJs": false, "checkJs": false,
@ -991,7 +970,7 @@ mod tests {
let request = Request { let request = Request {
config, config,
debug: false, debug: false,
graph_data: Arc::new(RwLock::new((&graph).into())), graph: Arc::new(graph),
hash_data, hash_data,
maybe_config_specifier: None, maybe_config_specifier: None,
maybe_npm_resolver: None, maybe_npm_resolver: None,

@ -1 +1 @@
Subproject commit 17e31cec93aef7d014dcc46bc58ef1a86c0a9995 Subproject commit b057caf2338df8ef887de464bba0ca085fa8a2b1

View file

@ -24,7 +24,8 @@ if (Deno.args.includes("--rs")) {
if (!didLint) { if (!didLint) {
await dlint(); await dlint();
await dlintPreferPrimordials(); // todo(dsherret): re-enable
// await dlintPreferPrimordials();
console.log("copyright checker"); console.log("copyright checker");
await checkCopyright(); await checkCopyright();
await clippy(); await clippy();