diff options
27 files changed, 113 insertions, 53 deletions
diff --git a/Cargo.lock b/Cargo.lock index 88cc7105b..0c2e3b62d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 4a9e31056..e0cd0e1d6 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -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" } diff --git a/cli/cache.rs b/cli/cache.rs index 2c94172b8..c5fd0a8a0 100644 --- a/cli/cache.rs +++ b/cli/cache.rs @@ -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) }, diff --git a/cli/config_file.rs b/cli/config_file.rs index 5cd76eaca..a254d074d 100644 --- a/cli/config_file.rs +++ b/cli/config_file.rs @@ -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( diff --git a/cli/errors.rs b/cli/errors.rs index bd5793430..9d0f1371a 100644 --- a/cli/errors.rs +++ b/cli/errors.rs @@ -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", } } diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index 3ac8f9bd4..29e4f41fe 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -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 diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 941243d90..fc1b742b8 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -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() } diff --git a/cli/lsp/cache.rs b/cli/lsp/cache.rs index b26c0ba4f..941b6d9cf 100644 --- a/cli/lsp/cache.rs +++ b/cli/lsp/cache.rs @@ -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"); } } diff --git a/cli/main.rs b/cli/main.rs index 6a6a742bb..97b902ee6 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -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 diff --git a/cli/ops/runtime_compiler.rs b/cli/ops/runtime_compiler.rs index fb5b07878..46aaafd09 100644 --- a/cli/ops/runtime_compiler.rs +++ b/cli/ops/runtime_compiler.rs @@ -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); } diff --git a/cli/proc_state.rs b/cli/proc_state.rs index b6797d663..7f49b6b1b 100644 --- a/cli/proc_state.rs +++ b/cli/proc_state.rs @@ -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()?; } diff --git a/cli/tests/integration/mod.rs b/cli/tests/integration/mod.rs index b04f552e8..8dd50b2f3 100644 --- a/cli/tests/integration/mod.rs +++ b/cli/tests/integration/mod.rs @@ -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()) diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index d36d0de1b..6e4f45338 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -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, }); diff --git a/cli/tests/integration/watcher_tests.rs b/cli/tests/integration/watcher_tests.rs index f0431e301..855538b16 100644 --- a/cli/tests/integration/watcher_tests.rs +++ b/cli/tests/integration/watcher_tests.rs @@ -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 "); diff --git a/cli/tests/testdata/020_json_modules.ts.out b/cli/tests/testdata/020_json_modules.ts.out index bfb7c80cf..da33c40bf 100644 --- a/cli/tests/testdata/020_json_modules.ts.out +++ b/cli/tests/testdata/020_json_modules.ts.out @@ -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]
\ No newline at end of file diff --git a/cli/tests/testdata/038_checkjs.tsconfig.json b/cli/tests/testdata/checkjs.tsconfig.json index 46d96db9e..46d96db9e 100644 --- a/cli/tests/testdata/038_checkjs.tsconfig.json +++ b/cli/tests/testdata/checkjs.tsconfig.json diff --git a/cli/tests/testdata/compiler_api_test.ts b/cli/tests/testdata/compiler_api_test.ts index f51b5647c..30fc19d5f 100644 --- a/cli/tests/testdata/compiler_api_test.ts +++ b/cli/tests/testdata/compiler_api_test.ts @@ -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".', ), ); }, diff --git a/cli/tests/testdata/error_004_missing_module.ts.out b/cli/tests/testdata/error_004_missing_module.ts.out index 798ffc007..9a2cfb8a8 100644 --- a/cli/tests/testdata/error_004_missing_module.ts.out +++ b/cli/tests/testdata/error_004_missing_module.ts.out @@ -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 diff --git a/cli/tests/testdata/error_005_missing_dynamic_import.ts.out b/cli/tests/testdata/error_005_missing_dynamic_import.ts.out index 0ca35bd3b..55e4a8524 100644 --- a/cli/tests/testdata/error_005_missing_dynamic_import.ts.out +++ b/cli/tests/testdata/error_005_missing_dynamic_import.ts.out @@ -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 diff --git a/cli/tests/testdata/error_006_import_ext_failure.ts.out b/cli/tests/testdata/error_006_import_ext_failure.ts.out index bffbafc7a..667579bd8 100644 --- a/cli/tests/testdata/error_006_import_ext_failure.ts.out +++ b/cli/tests/testdata/error_006_import_ext_failure.ts.out @@ -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 diff --git a/cli/tests/testdata/error_013_missing_script.out b/cli/tests/testdata/error_013_missing_script.out index fdd7aa27e..7ee268de4 100644 --- a/cli/tests/testdata/error_013_missing_script.out +++ b/cli/tests/testdata/error_013_missing_script.out @@ -1 +1 @@ -error: Cannot load module "[WILDCARD]missing_file_name". +error: Module not found "[WILDCARD]missing_file_name". diff --git a/cli/tests/testdata/error_missing_module_named_import.ts.out b/cli/tests/testdata/error_missing_module_named_import.ts.out index d1162ab52..3dccaffb1 100644 --- a/cli/tests/testdata/error_missing_module_named_import.ts.out +++ b/cli/tests/testdata/error_missing_module_named_import.ts.out @@ -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] diff --git a/cli/tests/testdata/import_assertions/static_error.out b/cli/tests/testdata/import_assertions/static_error.out index 8524079de..4efdf8682 100644 --- a/cli/tests/testdata/import_assertions/static_error.out +++ b/cli/tests/testdata/import_assertions/static_error.out @@ -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 diff --git a/cli/tests/testdata/jsx_import_source_error.out b/cli/tests/testdata/jsx_import_source_error.out index b9758a99e..957fa4a97 100644 --- a/cli/tests/testdata/jsx_import_source_error.out +++ b/cli/tests/testdata/jsx_import_source_error.out @@ -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 diff --git a/cli/tests/testdata/reference_types_error.js.out b/cli/tests/testdata/reference_types_error.js.out index 89b450520..ebb9b3a26 100644 --- a/cli/tests/testdata/reference_types_error.js.out +++ b/cli/tests/testdata/reference_types_error.js.out @@ -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 diff --git a/cli/tests/testdata/workers/nonexistent_worker.out b/cli/tests/testdata/workers/nonexistent_worker.out index 5280e22d1..1b5111b14 100644 --- a/cli/tests/testdata/workers/nonexistent_worker.out +++ b/cli/tests/testdata/workers/nonexistent_worker.out @@ -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]) diff --git a/cli/tools/test.rs b/cli/tools/test.rs index 959cefcc1..d78363add 100644 --- a/cli/tools/test.rs +++ b/cli/tools/test.rs @@ -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 { |