chore: update deno_graph and deno_doc (#13173)

This commit is contained in:
Kitson Kelly 2021-12-23 00:25:06 +11:00 committed by GitHub
parent ac06797fa8
commit 8547a37132
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 113 additions and 53 deletions

8
Cargo.lock generated
View file

@ -795,9 +795,9 @@ dependencies = [
[[package]]
name = "deno_doc"
version = "0.23.0"
version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6cda01f52763197e4cc3cb9f5ab6fea5a5cee2fd76843bc2e7c2193d812f02ad"
checksum = "6563f9d5f40a4e8c29a43a512536734f22eca1e7f86de1eb6d6d7d5a622c2afb"
dependencies = [
"cfg-if 1.0.0",
"deno_ast",
@ -841,9 +841,9 @@ dependencies = [
[[package]]
name = "deno_graph"
version = "0.14.2"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f3280596f5b5825b0363142b72fe2786163905c61dfeb18bd5db1c390a94093"
checksum = "db82fb9c644a51d9d4303ff21d04c4c3e32175576efbddc1c7498eda665ea4fd"
dependencies = [
"anyhow",
"cfg-if 1.0.0",

View file

@ -41,8 +41,8 @@ winres = "=0.1.11"
[dependencies]
deno_ast = { version = "0.7.0", features = ["bundler", "codegen", "dep_graph", "module_specifier", "proposal", "react", "sourcemap", "transforms", "typescript", "view", "visit"] }
deno_core = { version = "0.111.0", path = "../core" }
deno_doc = "0.23.0"
deno_graph = "0.14.2"
deno_doc = "0.24.0"
deno_graph = "0.16.0"
deno_lint = { version = "0.20.0", features = ["docs"] }
deno_runtime = { version = "0.37.0", path = "../runtime" }

View file

@ -1,6 +1,7 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.
use crate::disk_cache::DiskCache;
use crate::errors::get_error_class_name;
use crate::file_fetcher::FileFetcher;
use deno_core::error::AnyError;
@ -157,6 +158,8 @@ impl Loader for FetchCacher {
if err.kind() == std::io::ErrorKind::NotFound {
return Ok(None);
}
} else if get_error_class_name(&err) == "NotFound" {
return Ok(None);
}
Err(err)
},

View file

@ -499,6 +499,18 @@ impl ConfigFile {
})
}
/// Returns true if the configuration indicates that JavaScript should be
/// type checked, otherwise false.
pub fn get_check_js(&self) -> bool {
self
.json
.compiler_options
.as_ref()
.map(|co| co.get("checkJs").map(|v| v.as_bool()).flatten())
.flatten()
.unwrap_or(false)
}
/// Parse `compilerOptions` and return a serde `Value`.
/// The result also contains any options that were ignored.
pub fn to_compiler_options(

View file

@ -34,12 +34,14 @@ pub(crate) fn get_module_graph_error_class(
) -> &'static str {
match err {
ModuleGraphError::LoadingErr(_, err) => get_error_class_name(err.as_ref()),
ModuleGraphError::InvalidSource(_, _) => "SyntaxError",
ModuleGraphError::InvalidSource(_, _)
| ModuleGraphError::InvalidTypeAssertion { .. } => "SyntaxError",
ModuleGraphError::ParseErr(_, diagnostic) => {
get_diagnostic_class(diagnostic)
}
ModuleGraphError::ResolutionError(err) => get_resolution_error_class(err),
ModuleGraphError::UnsupportedMediaType(_, _) => "TypeError",
ModuleGraphError::UnsupportedMediaType(_, _)
| ModuleGraphError::UnsupportedImportAssertionType(_, _) => "TypeError",
ModuleGraphError::Missing(_) => "NotFound",
}
}

View file

@ -376,7 +376,7 @@ impl FileFetcher {
if self.cache_setting == CacheSetting::Only {
return Err(custom_error(
"NotFound",
"NotCached",
format!(
"Specifier not found in cache: \"{}\", --cached-only is specified.",
specifier
@ -425,7 +425,7 @@ impl FileFetcher {
if self.cache_setting == CacheSetting::Only {
return Err(custom_error(
"NotFound",
"NotCached",
format!(
"Specifier not found in cache: \"{}\", --cached-only is specified.",
specifier
@ -511,7 +511,7 @@ impl FileFetcher {
if self.cache_setting == CacheSetting::Only {
return futures::future::err(custom_error(
"NotFound",
"NotCached",
format!(
"Specifier not found in cache: \"{}\", --cached-only is specified.",
specifier
@ -1517,7 +1517,7 @@ mod tests {
.await;
assert!(result.is_err());
let err = result.unwrap_err();
assert_eq!(get_custom_error_class(&err), Some("NotFound"));
assert_eq!(get_custom_error_class(&err), Some("NotCached"));
assert_eq!(err.to_string(), "Specifier not found in cache: \"http://localhost:4545/002_hello.ts\", --cached-only is specified.");
let result = file_fetcher_02

View file

@ -145,6 +145,7 @@ impl GraphData {
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();
@ -167,9 +168,19 @@ impl GraphData {
ModuleEntry::Module {
dependencies,
maybe_types,
media_type,
..
} => {
if follow_type_only {
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(Ok((types, _))) = maybe_types {
if !seen.contains(types) {
seen.insert(types);
@ -180,7 +191,7 @@ impl GraphData {
for (_, dep) in dependencies.iter().rev() {
if !dep.is_dynamic || follow_dynamic {
let mut resolutions = vec![&dep.maybe_code];
if follow_type_only {
if check_types {
resolutions.push(&dep.maybe_type);
}
#[allow(clippy::manual_flatten)]
@ -223,7 +234,7 @@ impl GraphData {
) -> Option<Self> {
let mut modules = HashMap::new();
let mut referrer_map = HashMap::new();
let entries = match self.walk(roots, true, true) {
let entries = match self.walk(roots, true, true, true) {
Some(entries) => entries,
None => return None,
};
@ -248,8 +259,9 @@ impl GraphData {
&self,
roots: &[ModuleSpecifier],
follow_type_only: bool,
check_js: bool,
) -> Option<Result<(), AnyError>> {
let entries = match self.walk(roots, false, follow_type_only) {
let entries = match self.walk(roots, false, follow_type_only, check_js) {
Some(entries) => entries,
None => return None,
};
@ -258,9 +270,19 @@ impl GraphData {
ModuleEntry::Module {
dependencies,
maybe_types,
media_type,
..
} => {
if follow_type_only {
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(Err(error)) = maybe_types {
let range = error.range();
if !range.specifier.as_str().contains("$deno") {
@ -275,7 +297,7 @@ impl GraphData {
for (_, dep) in dependencies.iter() {
if !dep.is_dynamic {
let mut resolutions = vec![&dep.maybe_code];
if follow_type_only {
if check_types {
resolutions.push(&dep.maybe_type);
}
#[allow(clippy::manual_flatten)]
@ -335,10 +357,11 @@ impl GraphData {
roots: &[ModuleSpecifier],
lib: &TypeLib,
) {
let specifiers: Vec<ModuleSpecifier> = match self.walk(roots, true, true) {
Some(entries) => entries.into_keys().cloned().collect(),
None => unreachable!("contains module not in graph data"),
};
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()
@ -397,9 +420,10 @@ impl From<&ModuleGraph> for GraphData {
pub(crate) fn graph_valid(
graph: &ModuleGraph,
follow_type_only: bool,
check_js: bool,
) -> Result<(), AnyError> {
GraphData::from(graph)
.check(&graph.roots, follow_type_only)
.check(&graph.roots, follow_type_only, check_js)
.unwrap()
}

View file

@ -83,7 +83,7 @@ impl CacheServer {
)
.await;
if tx.send(graph_valid(&graph, true)).is_err() {
if tx.send(graph_valid(&graph, true, false)).is_err() {
log::warn!("cannot send to client");
}
}

View file

@ -695,7 +695,12 @@ async fn create_graph_and_maybe_check(
.await,
);
graph_valid(&graph, ps.flags.check != CheckFlag::None)?;
let check_js = ps
.maybe_config_file
.as_ref()
.map(|cf| cf.get_check_js())
.unwrap_or(false);
graph_valid(&graph, ps.flags.check != CheckFlag::None, check_js)?;
graph_lock_or_exit(&graph);
if ps.flags.check != CheckFlag::None {
@ -1030,7 +1035,12 @@ async fn run_with_watch(flags: Flags, script: String) -> Result<i32, AnyError> {
None,
)
.await;
graph_valid(&graph, ps.flags.check != flags::CheckFlag::None)?;
let check_js = ps
.maybe_config_file
.as_ref()
.map(|cf| cf.get_check_js())
.unwrap_or(false);
graph_valid(&graph, ps.flags.check != flags::CheckFlag::None, check_js)?;
// Find all local files in graph
let mut paths_to_watch: Vec<PathBuf> = graph

View file

@ -221,7 +221,7 @@ async fn op_emit(
// There are certain graph errors that we want to return as an error of an op,
// versus something that gets returned as a diagnostic of the op, this is
// handled here.
if let Err(err) = graph_valid(&graph, check) {
if let Err(err) = graph_valid(&graph, check, true) {
if get_error_class_name(&err) == "PermissionDenied" {
return Err(err);
}

View file

@ -338,9 +338,11 @@ impl ProcState {
if self.flags.check == flags::CheckFlag::None
|| graph_data.is_type_checked(&roots, &lib)
{
if let Some(result) =
graph_data.check(&roots, self.flags.check != flags::CheckFlag::None)
{
if let Some(result) = graph_data.check(
&roots,
self.flags.check != flags::CheckFlag::None,
false,
) {
return result;
}
}
@ -417,8 +419,13 @@ impl ProcState {
{
let mut graph_data = self.graph_data.write();
graph_data.add_graph(&graph, reload_on_watch);
let check_js = self
.maybe_config_file
.as_ref()
.map(|cf| cf.get_check_js())
.unwrap_or(false);
graph_data
.check(&roots, self.flags.check != flags::CheckFlag::None)
.check(&roots, self.flags.check != flags::CheckFlag::None, check_js)
.unwrap()?;
}

View file

@ -1100,9 +1100,8 @@ fn basic_auth_tokens() {
let stderr_str = std::str::from_utf8(&output.stderr).unwrap().trim();
eprintln!("{}", stderr_str);
assert!(stderr_str.contains(
"Import 'http://127.0.0.1:4554/001_hello.js' failed, not found."
));
assert!(stderr_str
.contains("Module not found \"http://127.0.0.1:4554/001_hello.js\"."));
let output = util::deno_cmd()
.current_dir(util::root_path())

View file

@ -163,7 +163,7 @@ itest!(_035_cached_only_flag {
itest!(_038_checkjs {
// checking if JS file is run through TS compiler
args: "run --reload --config 038_checkjs.tsconfig.json 038_checkjs.js",
args: "run --reload --config checkjs.tsconfig.json 038_checkjs.js",
exit_code: 1,
output: "038_checkjs.js.out",
});
@ -1584,7 +1584,7 @@ itest!(worker_close_in_wasm_reactions {
});
itest!(reference_types_error {
args: "run reference_types_error.js",
args: "run --config checkjs.tsconfig.json reference_types_error.js",
output: "reference_types_error.js.out",
exit_code: 1,
});

View file

@ -989,7 +989,7 @@ fn test_watch_module_graph_error_referrer() {
assert_contains!(&line1, CLEAR_SCREEN);
assert_contains!(&line1, "Process started");
let line2 = stderr_lines.next().unwrap();
assert_contains!(&line2, "error: Cannot load module");
assert_contains!(&line2, "error: Module not found");
assert_contains!(&line2, "nonexistent.js");
let line3 = stderr_lines.next().unwrap();
assert_contains!(&line3, " at ");

View file

@ -1,5 +1,4 @@
[WILDCARD]
error: An unsupported media type was attempted to be imported as a module.
error: Expected a JavaScript or TypeScript module, but identified a Json module. Consider importing Json modules with an import assertion with the type of "json".
Specifier: [WILDCARD]/subdir/config.json
MediaType: Json
[WILDCARD]

View file

@ -514,7 +514,7 @@ Deno.test({
code: 900001,
start: null,
end: null,
messageText: 'Cannot load module "file:///b.ts".',
messageText: 'Module not found "file:///b.ts".',
messageChain: null,
source: null,
sourceLine: null,
@ -524,7 +524,7 @@ Deno.test({
]);
assert(
Deno.formatDiagnostics(diagnostics).includes(
'Cannot load module "file:///b.ts".',
'Module not found "file:///b.ts".',
),
);
},

View file

@ -1,2 +1,2 @@
[WILDCARD]error: Cannot load module "file:///[WILDCARD]/bad-module.ts".
[WILDCARD]error: Module not found "file:///[WILDCARD]/bad-module.ts".
at file:///[WILDCARD]/error_004_missing_module.ts:1:28

View file

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

View file

@ -1,2 +1,2 @@
[WILDCARD]error: Cannot load module "[WILDCARD]/non-existent".
[WILDCARD]error: Module not found "[WILDCARD]/non-existent".
at file:///[WILDCARD]/error_006_import_ext_failure.ts:1:8

View file

@ -1 +1 @@
error: Cannot load module "[WILDCARD]missing_file_name".
error: Module not found "[WILDCARD]missing_file_name".

View file

@ -1,3 +1,3 @@
[WILDCARD]
error: Cannot load module "file://[WILDCARD]/does_not_exist.js".
error: Module not found "file://[WILDCARD]/does_not_exist.js".
at file:///[WILDCARD]/error_missing_module_named_import.ts:[WILDCARD]

View file

@ -1,5 +1,4 @@
[WILDCARD]
error: An unsupported media type was attempted to be imported as a module.
Specifier: [WILDCARD]data.json
MediaType: Json
error: Expected a JavaScript or TypeScript module, but identified a Json module. Consider importing Json modules with an import assertion with the type of "json".
Specifier: [WILDCARD]/data.json
at [WILDCARD]static_error.ts:1:18

View file

@ -1,2 +1,2 @@
error: Cannot load module "file:///[WILDCARD]/nonexistent/jsx-runtime".
error: Module not found "file:///[WILDCARD]/nonexistent/jsx-runtime".
at file:///[WILDCARD]/deno-jsx-error.jsonc:1:1

View file

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

View file

@ -1,3 +1,3 @@
[WILDCARD]error: Uncaught (in worker "") Cannot load module "file:///[WILDCARD]/workers/doesnt_exist.js".
[WILDCARD]error: Uncaught (in worker "") Module not found "file:///[WILDCARD]/workers/doesnt_exist.js".
error: Uncaught (in promise) Error: Unhandled error event in child worker.
at Worker.#pollControl ([WILDCARD])

View file

@ -1092,6 +1092,11 @@ pub async fn run_tests_with_watch(
let files_changed = changed.is_some();
let include = include.clone();
let ignore = ignore.clone();
let check_js = ps
.maybe_config_file
.as_ref()
.map(|cf| cf.get_check_js())
.unwrap_or(false);
async move {
let test_modules = if test_flags.doc {
@ -1131,7 +1136,7 @@ pub async fn run_tests_with_watch(
None,
)
.await;
graph_valid(&graph, !no_check)?;
graph_valid(&graph, !no_check, check_js)?;
// TODO(@kitsonk) - This should be totally derivable from the graph.
for specifier in test_modules {