mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
fix(check): filter resolution errors for bare ambient modules (#30690)
Some checks failed
ci / build libs (push) Has been cancelled
ci / pre-build (push) Has been cancelled
ci / publish canary (push) Has been cancelled
ci / test debug linux-aarch64 (push) Has been cancelled
ci / test debug macos-aarch64 (push) Has been cancelled
ci / bench release linux-x86_64 (push) Has been cancelled
ci / test release linux-aarch64 (push) Has been cancelled
ci / test release macos-aarch64 (push) Has been cancelled
ci / lint debug linux-x86_64 (push) Has been cancelled
ci / lint debug macos-x86_64 (push) Has been cancelled
ci / lint debug windows-x86_64 (push) Has been cancelled
ci / test debug linux-x86_64 (push) Has been cancelled
ci / test release linux-x86_64 (push) Has been cancelled
ci / test debug macos-x86_64 (push) Has been cancelled
ci / test release macos-x86_64 (push) Has been cancelled
ci / test debug windows-x86_64 (push) Has been cancelled
ci / test release windows-x86_64 (push) Has been cancelled
Some checks failed
ci / build libs (push) Has been cancelled
ci / pre-build (push) Has been cancelled
ci / publish canary (push) Has been cancelled
ci / test debug linux-aarch64 (push) Has been cancelled
ci / test debug macos-aarch64 (push) Has been cancelled
ci / bench release linux-x86_64 (push) Has been cancelled
ci / test release linux-aarch64 (push) Has been cancelled
ci / test release macos-aarch64 (push) Has been cancelled
ci / lint debug linux-x86_64 (push) Has been cancelled
ci / lint debug macos-x86_64 (push) Has been cancelled
ci / lint debug windows-x86_64 (push) Has been cancelled
ci / test debug linux-x86_64 (push) Has been cancelled
ci / test release linux-x86_64 (push) Has been cancelled
ci / test debug macos-x86_64 (push) Has been cancelled
ci / test release macos-x86_64 (push) Has been cancelled
ci / test debug windows-x86_64 (push) Has been cancelled
ci / test release windows-x86_64 (push) Has been cancelled
This commit is contained in:
parent
bf8288baa5
commit
9e2472afc0
19 changed files with 125 additions and 47 deletions
|
@ -23,6 +23,7 @@ use deno_graph::ModuleGraph;
|
|||
use deno_graph::ModuleGraphError;
|
||||
use deno_graph::ModuleLoadError;
|
||||
use deno_graph::ResolutionError;
|
||||
use deno_graph::SpecifierError;
|
||||
use deno_graph::WorkspaceFastCheckOption;
|
||||
use deno_graph::source::Loader;
|
||||
use deno_graph::source::ResolveError;
|
||||
|
@ -43,6 +44,7 @@ use deno_resolver::npm::DenoInNpmPackageChecker;
|
|||
use deno_runtime::deno_permissions::PermissionsContainer;
|
||||
use deno_semver::SmallStackString;
|
||||
use deno_semver::jsr::JsrDepPackageReq;
|
||||
use import_map::ImportMapErrorKind;
|
||||
use indexmap::IndexMap;
|
||||
use node_resolver::errors::NodeJsErrorCode;
|
||||
use sys_traits::FsMetadata;
|
||||
|
@ -74,6 +76,7 @@ use crate::util::progress_bar::ProgressBar;
|
|||
pub struct GraphValidOptions<'a> {
|
||||
pub check_js: CheckJsOption<'a>,
|
||||
pub kind: GraphKind,
|
||||
pub will_type_check: bool,
|
||||
/// Whether to exit the process for integrity check errors such as
|
||||
/// lockfile checksum mismatches and JSR integrity failures.
|
||||
/// Otherwise, surfaces integrity errors as errors.
|
||||
|
@ -106,6 +109,7 @@ pub fn graph_valid(
|
|||
GraphWalkErrorsOptions {
|
||||
check_js: options.check_js,
|
||||
kind: options.kind,
|
||||
will_type_check: options.will_type_check,
|
||||
allow_unknown_media_types: options.allow_unknown_media_types,
|
||||
allow_unknown_jsr_exports: options.allow_unknown_jsr_exports,
|
||||
},
|
||||
|
@ -129,6 +133,7 @@ pub fn graph_valid(
|
|||
pub struct GraphWalkErrorsOptions<'a> {
|
||||
pub check_js: CheckJsOption<'a>,
|
||||
pub kind: GraphKind,
|
||||
pub will_type_check: bool,
|
||||
pub allow_unknown_media_types: bool,
|
||||
pub allow_unknown_jsr_exports: bool,
|
||||
}
|
||||
|
@ -145,6 +150,7 @@ pub fn graph_walk_errors<'a>(
|
|||
sys: &CliSys,
|
||||
graph_kind: GraphKind,
|
||||
allow_unknown_media_types: bool,
|
||||
will_type_check: bool,
|
||||
error: &ModuleGraphError,
|
||||
) -> bool {
|
||||
if (graph_kind == GraphKind::TypesOnly || allow_unknown_media_types)
|
||||
|
@ -157,8 +163,7 @@ pub fn graph_walk_errors<'a>(
|
|||
}
|
||||
|
||||
// surface these as typescript diagnostics instead
|
||||
graph_kind.include_types()
|
||||
&& has_module_graph_error_for_tsc_diagnostic(sys, error)
|
||||
will_type_check && has_module_graph_error_for_tsc_diagnostic(sys, error)
|
||||
}
|
||||
|
||||
graph
|
||||
|
@ -177,6 +182,7 @@ pub fn graph_walk_errors<'a>(
|
|||
sys,
|
||||
graph.graph_kind(),
|
||||
options.allow_unknown_media_types,
|
||||
options.will_type_check,
|
||||
&error,
|
||||
) {
|
||||
log::debug!("Ignoring: {}", error);
|
||||
|
@ -269,14 +275,16 @@ pub fn module_error_for_tsc_diagnostic<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
pub struct ModuleNotFoundNodeResolutionErrorRef<'a> {
|
||||
#[derive(Debug)]
|
||||
pub struct ResolutionErrorRef<'a> {
|
||||
pub specifier: &'a str,
|
||||
pub maybe_range: Option<&'a deno_graph::Range>,
|
||||
pub range: &'a deno_graph::Range,
|
||||
pub is_module_not_found: bool,
|
||||
}
|
||||
|
||||
pub fn resolution_error_for_tsc_diagnostic(
|
||||
error: &ResolutionError,
|
||||
) -> Option<ModuleNotFoundNodeResolutionErrorRef<'_>> {
|
||||
) -> Option<ResolutionErrorRef<'_>> {
|
||||
fn is_module_not_found_code(code: NodeJsErrorCode) -> bool {
|
||||
match code {
|
||||
NodeJsErrorCode::ERR_INVALID_MODULE_SPECIFIER
|
||||
|
@ -295,28 +303,63 @@ pub fn resolution_error_for_tsc_diagnostic(
|
|||
}
|
||||
|
||||
match error {
|
||||
ResolutionError::InvalidDowngrade { .. }
|
||||
| ResolutionError::InvalidJsrHttpsTypesImport { .. }
|
||||
| ResolutionError::InvalidLocalImport { .. } => None,
|
||||
ResolutionError::InvalidSpecifier { error, range } => match error {
|
||||
SpecifierError::InvalidUrl(..) => None,
|
||||
SpecifierError::ImportPrefixMissing { specifier, .. } => {
|
||||
Some(ResolutionErrorRef {
|
||||
specifier,
|
||||
range,
|
||||
is_module_not_found: false,
|
||||
})
|
||||
}
|
||||
},
|
||||
ResolutionError::ResolverError {
|
||||
error,
|
||||
specifier,
|
||||
range,
|
||||
} => match error.as_ref() {
|
||||
ResolveError::Specifier(error) => match error {
|
||||
SpecifierError::InvalidUrl(..) => None,
|
||||
SpecifierError::ImportPrefixMissing { specifier, .. } => {
|
||||
Some(ResolutionErrorRef {
|
||||
specifier,
|
||||
range,
|
||||
is_module_not_found: false,
|
||||
})
|
||||
}
|
||||
},
|
||||
ResolveError::ImportMap(error) => match error.as_kind() {
|
||||
ImportMapErrorKind::JsonParse(_)
|
||||
| ImportMapErrorKind::ImportMapNotObject
|
||||
| ImportMapErrorKind::ImportsFieldNotObject
|
||||
| ImportMapErrorKind::ScopesFieldNotObject
|
||||
| ImportMapErrorKind::ScopePrefixNotObject(_)
|
||||
| ImportMapErrorKind::BlockedByNullEntry(_)
|
||||
| ImportMapErrorKind::SpecifierResolutionFailure { .. }
|
||||
| ImportMapErrorKind::SpecifierBacktracksAbovePrefix { .. } => None,
|
||||
ImportMapErrorKind::UnmappedBareSpecifier(specifier, _) => {
|
||||
Some(ResolutionErrorRef {
|
||||
specifier,
|
||||
range,
|
||||
is_module_not_found: false,
|
||||
})
|
||||
}
|
||||
},
|
||||
ResolveError::Other(error) => {
|
||||
let is_module_not_found_error = downcast_ref_deno_resolve_error(error)
|
||||
.and_then(|err| err.maybe_node_code())
|
||||
.map(is_module_not_found_code)
|
||||
.unwrap_or(false);
|
||||
if is_module_not_found_error {
|
||||
Some(ModuleNotFoundNodeResolutionErrorRef {
|
||||
specifier,
|
||||
maybe_range: Some(range),
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
is_module_not_found_error.then(|| ResolutionErrorRef {
|
||||
specifier,
|
||||
range,
|
||||
is_module_not_found: true,
|
||||
})
|
||||
}
|
||||
ResolveError::Specifier(_) | ResolveError::ImportMap(_) => None,
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -951,16 +994,18 @@ impl ModuleGraphBuilder {
|
|||
allow_unknown_media_types: bool,
|
||||
allow_unknown_jsr_exports: bool,
|
||||
) -> Result<(), JsErrorBox> {
|
||||
let will_type_check = self.cli_options.type_check_mode().is_true();
|
||||
graph_valid(
|
||||
graph,
|
||||
&self.sys,
|
||||
roots,
|
||||
GraphValidOptions {
|
||||
kind: if self.cli_options.type_check_mode().is_true() {
|
||||
kind: if will_type_check {
|
||||
GraphKind::All
|
||||
} else {
|
||||
GraphKind::CodeOnly
|
||||
},
|
||||
will_type_check,
|
||||
check_js: CheckJsOption::Custom(
|
||||
self.compiler_options_resolver.as_ref(),
|
||||
),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue