Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update deno_graph and deno_doc #13173

Merged
merged 2 commits into from
Dec 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand Down
3 changes: 3 additions & 0 deletions cli/cache.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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)
},
Expand Down
12 changes: 12 additions & 0 deletions cli/config_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 4 additions & 2 deletions cli/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}
Expand Down
8 changes: 4 additions & 4 deletions cli/file_fetcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
46 changes: 35 additions & 11 deletions cli/graph_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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);
Expand All @@ -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)]
Expand Down Expand Up @@ -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,
};
Expand All @@ -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,
};
Expand All @@ -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") {
Expand All @@ -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)]
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion cli/lsp/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Expand Down
14 changes: 12 additions & 2 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cli/ops/runtime_compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
15 changes: 11 additions & 4 deletions cli/proc_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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()?;
}

Expand Down
5 changes: 2 additions & 3 deletions cli/tests/integration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/integration/run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
});
Expand Down Expand Up @@ -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,
});
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/integration/watcher_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ");
Expand Down
3 changes: 1 addition & 2 deletions cli/tests/testdata/020_json_modules.ts.out
Original file line number Diff line number Diff line change
@@ -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]
4 changes: 2 additions & 2 deletions cli/tests/testdata/compiler_api_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -524,7 +524,7 @@ Deno.test({
]);
assert(
Deno.formatDiagnostics(diagnostics).includes(
'Cannot load module "file:///b.ts".',
'Module not found "file:///b.ts".',
),
);
},
Expand Down
2 changes: 1 addition & 1 deletion cli/tests/testdata/error_004_missing_module.ts.out
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion cli/tests/testdata/error_005_missing_dynamic_import.ts.out
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion cli/tests/testdata/error_006_import_ext_failure.ts.out
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion cli/tests/testdata/error_013_missing_script.out
Original file line number Diff line number Diff line change
@@ -1 +1 @@
error: Cannot load module "[WILDCARD]missing_file_name".
error: Module not found "[WILDCARD]missing_file_name".
Loading