From f736c43f46cf6fd4886f5acdd8f520b71c1a0724 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 16 May 2024 15:15:20 -0400 Subject: [PATCH 01/17] initial test --- Cargo.lock | 6 ++---- Cargo.toml | 3 +++ cli/cache/module_info.rs | 24 +++++++++++++++++------- cli/graph_util.rs | 5 +++-- cli/lsp/documents.rs | 26 +++++++++++++++----------- cli/tools/doc.rs | 3 ++- 6 files changed, 42 insertions(+), 25 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2dd72b35342182..bf420f4026736c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1471,8 +1471,6 @@ dependencies = [ [[package]] name = "deno_graph" version = "0.75.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a68ddc87ce88c0a2568277ee6caabf37890128710910416c09cd6f6a8931dba6" dependencies = [ "anyhow", "async-trait", @@ -7401,7 +7399,7 @@ dependencies = [ "log", "naga", "once_cell", - "parking_lot 0.12.1", + "parking_lot 0.11.2", "profiling", "raw-window-handle", "ron", @@ -7443,7 +7441,7 @@ dependencies = [ "ndk-sys", "objc", "once_cell", - "parking_lot 0.12.1", + "parking_lot 0.11.2", "profiling", "range-alloc", "raw-window-handle", diff --git a/Cargo.toml b/Cargo.toml index 321fc61bbcd30d..7757bca8d756fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -368,3 +368,6 @@ opt-level = 3 opt-level = 3 [profile.release.package.base64-simd] opt-level = 3 + +[patch.crates-io] +deno_graph = { path = "../deno_graph" } diff --git a/cli/cache/module_info.rs b/cli/cache/module_info.rs index 2e9274160cc642..6949716ee9ac8d 100644 --- a/cli/cache/module_info.rs +++ b/cli/cache/module_info.rs @@ -7,7 +7,6 @@ use deno_ast::ModuleSpecifier; use deno_core::error::AnyError; use deno_core::serde_json; use deno_graph::ModuleInfo; -use deno_graph::ModuleParser; use deno_graph::ParserModuleAnalyzer; use deno_runtime::deno_webstorage::rusqlite::params; @@ -15,6 +14,7 @@ use super::cache_db::CacheDB; use super::cache_db::CacheDBConfiguration; use super::cache_db::CacheFailure; use super::FastInsecureHasher; +use super::ParsedSourceCache; const SELECT_MODULE_INFO: &str = " SELECT @@ -153,22 +153,23 @@ impl ModuleInfoCache { pub fn as_module_analyzer<'a>( &'a self, - parser: &'a dyn ModuleParser, + parsed_source_cache: Arc, ) -> ModuleInfoCacheModuleAnalyzer<'a> { ModuleInfoCacheModuleAnalyzer { module_info_cache: self, - parser, + parsed_source_cache, } } } pub struct ModuleInfoCacheModuleAnalyzer<'a> { module_info_cache: &'a ModuleInfoCache, - parser: &'a dyn ModuleParser, + parsed_source_cache: Arc, } +#[async_trait::async_trait(?Send)] impl<'a> deno_graph::ModuleAnalyzer for ModuleInfoCacheModuleAnalyzer<'a> { - fn analyze( + async fn analyze( &self, specifier: &ModuleSpecifier, source: Arc, @@ -193,8 +194,17 @@ impl<'a> deno_graph::ModuleAnalyzer for ModuleInfoCacheModuleAnalyzer<'a> { } // otherwise, get the module info from the parsed source cache - let analyzer = ParserModuleAnalyzer::new(self.parser); - let module_info = analyzer.analyze(specifier, source, media_type)?; + let module_info = deno_core::unsync::spawn_blocking({ + let cache = self.parsed_source_cache.clone(); + let specifier = specifier.clone(); + move || { + let parser = cache.as_capturing_parser(); + let analyzer = ParserModuleAnalyzer::new(&parser); + analyzer.analyze_sync(&specifier, source, media_type) + } + }) + .await + .unwrap()?; // then attempt to cache it if let Err(err) = self.module_info_cache.set_module_info( diff --git a/cli/graph_util.rs b/cli/graph_util.rs index ed56cf9f7a120b..bf2c9021fc4bcd 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -427,8 +427,9 @@ impl ModuleGraphBuilder { } let maybe_imports = self.options.to_maybe_imports()?; - let parser = self.parsed_source_cache.as_capturing_parser(); - let analyzer = self.module_info_cache.as_module_analyzer(&parser); + let analyzer = self + .module_info_cache + .as_module_analyzer(self.parsed_source_cache.clone()); let mut loader = match options.loader { Some(loader) => MutLoaderRef::Borrowed(loader), None => MutLoaderRef::Owned(self.create_graph_loader()), diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index 8c553b03d28707..3d8b927ebccca7 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -307,7 +307,7 @@ impl Document { let (maybe_parsed_source, maybe_module) = if media_type_is_diagnosable(media_type) { parse_and_analyze_module( - &specifier, + specifier.clone(), text_info.clone(), maybe_headers.as_ref(), media_type, @@ -365,10 +365,13 @@ impl Document { let maybe_parsed_source; let maybe_test_module_fut; if media_type != self.media_type { - let parsed_source_result = - parse_source(&self.specifier, self.text_info.clone(), media_type); + let parsed_source_result = parse_source( + self.specifier.clone(), + self.text_info.clone(), + media_type, + ); let maybe_module = analyze_module( - &self.specifier, + self.specifier.clone(), &parsed_source_result, self.maybe_headers.as_ref(), &resolver, @@ -472,7 +475,7 @@ impl Document { .unwrap_or(false) { parse_and_analyze_module( - &self.specifier, + self.specifier.clone(), text_info.clone(), self.maybe_headers.as_ref(), media_type, @@ -1365,25 +1368,26 @@ impl<'a> deno_graph::source::Loader for OpenDocumentsGraphLoader<'a> { } fn parse_and_analyze_module( - specifier: &ModuleSpecifier, + specifier: ModuleSpecifier, text_info: SourceTextInfo, maybe_headers: Option<&HashMap>, media_type: MediaType, resolver: &LspResolver, ) -> (Option, Option) { - let parsed_source_result = parse_source(specifier, text_info, media_type); + let parsed_source_result = + parse_source(specifier.clone(), text_info, media_type); let module_result = analyze_module(specifier, &parsed_source_result, maybe_headers, resolver); (Some(parsed_source_result), Some(module_result)) } fn parse_source( - specifier: &ModuleSpecifier, + specifier: ModuleSpecifier, text_info: SourceTextInfo, media_type: MediaType, ) -> ParsedSourceResult { deno_ast::parse_module(deno_ast::ParseParams { - specifier: specifier.clone(), + specifier, text_info, media_type, capture_tokens: true, @@ -1393,7 +1397,7 @@ fn parse_source( } fn analyze_module( - specifier: &ModuleSpecifier, + specifier: ModuleSpecifier, parsed_source_result: &ParsedSourceResult, maybe_headers: Option<&HashMap>, resolver: &LspResolver, @@ -1414,7 +1418,7 @@ fn analyze_module( }, )), Err(err) => Err(deno_graph::ModuleGraphError::ModuleError( - deno_graph::ModuleError::ParseErr(specifier.clone(), err.clone()), + deno_graph::ModuleError::ParseErr(specifier, err.clone()), )), } } diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index 0ae9a8483ff66a..55d13838b95cd4 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -88,7 +88,8 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> { let module_info_cache = factory.module_info_cache()?; let parsed_source_cache = factory.parsed_source_cache(); let capturing_parser = parsed_source_cache.as_capturing_parser(); - let analyzer = module_info_cache.as_module_analyzer(&capturing_parser); + let analyzer = + module_info_cache.as_module_analyzer(parsed_source_cache.clone()); let doc_nodes_by_url = match doc_flags.source_files { DocSourceFileFlag::Builtin => { From 88b8483a223b3e48877f719153394344806e03b5 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 22 May 2024 16:06:06 -0400 Subject: [PATCH 02/17] Update locals --- Cargo.lock | 10 +++------- Cargo.toml | 2 ++ cli/Cargo.toml | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 42af5d525cefa0..9bd7e181dde366 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1385,9 +1385,7 @@ dependencies = [ [[package]] name = "deno_doc" -version = "0.135.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2c39bbe2769f6e8bfba1a99d7656e6994474c48fd2085ed82b59556e9d398dd" +version = "0.136.0" dependencies = [ "ammonia", "anyhow", @@ -1898,8 +1896,6 @@ dependencies = [ [[package]] name = "deno_unsync" version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7557a5e9278b9a5cc8056dc37062ea4344770bda4eeb5973c7cbb7ebf636b9a4" dependencies = [ "tokio", ] @@ -7496,7 +7492,7 @@ dependencies = [ "log", "naga", "once_cell", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "profiling", "raw-window-handle", "ron", @@ -7538,7 +7534,7 @@ dependencies = [ "ndk-sys", "objc", "once_cell", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "profiling", "range-alloc", "raw-window-handle", diff --git a/Cargo.toml b/Cargo.toml index f5df2af5f9827f..df5ac9ba2fe8c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -370,4 +370,6 @@ opt-level = 3 opt-level = 3 [patch.crates-io] +deno_doc = { path = "../deno_doc" } deno_graph = { path = "../deno_graph" } +deno_unsync = { path = "../deno_unsync" } diff --git a/cli/Cargo.toml b/cli/Cargo.toml index a7856b8d742170..f37f8086e18d21 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -67,7 +67,7 @@ deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "proposa deno_cache_dir = { workspace = true } deno_config = "=0.16.3" deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] } -deno_doc = { version = "=0.135.0", features = ["html", "syntect"] } +deno_doc = { version = "=0.136.0", features = ["html", "syntect"] } deno_emit = "=0.40.3" deno_graph = { version = "=0.75.2", features = ["tokio_executor"] } deno_lint = { version = "=0.58.4", features = ["docs"] } From c61b6835f9f991a0ca2b6dc98dd5d8fef5ff5441 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 24 May 2024 12:04:57 -0400 Subject: [PATCH 03/17] Update. --- Cargo.lock | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 759a8329cb5300..7cedf9233a2bdb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1468,8 +1468,6 @@ dependencies = [ [[package]] name = "deno_doc" version = "0.136.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50fc1cfe918e6cd5630c053ed1b5ee025be1cc98b0b6d6303443b7f6fa15fc1b" dependencies = [ "ammonia", "anyhow", @@ -7650,7 +7648,7 @@ dependencies = [ "log", "naga", "once_cell", - "parking_lot 0.12.1", + "parking_lot 0.11.2", "profiling", "raw-window-handle", "ron", @@ -7692,7 +7690,7 @@ dependencies = [ "ndk-sys", "objc", "once_cell", - "parking_lot 0.12.1", + "parking_lot 0.11.2", "profiling", "range-alloc", "raw-window-handle", @@ -8132,7 +8130,3 @@ dependencies = [ "cc", "pkg-config", ] - -[[patch.unused]] -name = "deno_doc" -version = "0.134.0" From 536d1e0fa28682521e4fb10493ce3f0a5b3d389b Mon Sep 17 00:00:00 2001 From: David Sherret Date: Fri, 24 May 2024 21:12:09 -0400 Subject: [PATCH 04/17] Updates for latest deno_graph changes --- Cargo.lock | 11 +-- Cargo.toml | 3 +- cli/errors.rs | 54 ++++++++--- cli/factory.rs | 1 - cli/file_fetcher.rs | 23 ++++- cli/graph_util.rs | 177 +++++++++++++++++----------------- cli/main.rs | 10 ++ cli/module_loader.rs | 8 +- cli/npm/managed/mod.rs | 6 -- cli/npm/managed/resolution.rs | 3 + cli/tools/doc.rs | 7 +- cli/tools/info.rs | 17 +--- cli/tools/registry/graph.rs | 4 +- cli/tools/vendor/build.rs | 10 -- cli/tools/vendor/mod.rs | 1 - 15 files changed, 179 insertions(+), 156 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7cedf9233a2bdb..3499bd468410b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1331,11 +1331,10 @@ dependencies = [ [[package]] name = "deno_cache_dir" -version = "0.7.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6cf517bddfd22d79d0f284500318e3f9aea193536c2b61cbf6ce7b50a85f1b6a" +checksum = "4036ac8ce97244e2a66df7b97412592acaf14671900460d28415703ad790cd70" dependencies = [ - "anyhow", "deno_media_type", "indexmap", "log", @@ -1684,8 +1683,6 @@ dependencies = [ [[package]] name = "deno_lockfile" version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8835418ae924f25ab20f508bf6240193b22d893519d44432b670a27b8fb1efeb" dependencies = [ "serde", "serde_json", @@ -7648,7 +7645,7 @@ dependencies = [ "log", "naga", "once_cell", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "profiling", "raw-window-handle", "ron", @@ -7690,7 +7687,7 @@ dependencies = [ "ndk-sys", "objc", "once_cell", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "profiling", "range-alloc", "raw-window-handle", diff --git a/Cargo.toml b/Cargo.toml index b6f3d20c45bcd3..98860f62447d8e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -100,7 +100,7 @@ chrono = { version = "0.4", default-features = false, features = ["std", "serde" console_static_text = "=0.8.1" data-encoding = "2.3.3" data-url = "=0.3.0" -deno_cache_dir = "=0.7.1" +deno_cache_dir = "=0.10.0" dlopen2 = "0.6.1" ecb = "=0.1.2" elliptic-curve = { version = "0.13.4", features = ["alloc", "arithmetic", "ecdh", "std", "pem"] } @@ -374,3 +374,4 @@ opt-level = 3 deno_doc = { path = "../deno_doc" } deno_graph = { path = "../deno_graph" } deno_unsync = { path = "../deno_unsync" } +deno_lockfile = { path = "../deno_lockfile" } diff --git a/cli/errors.rs b/cli/errors.rs index fce286f1595c9b..196ed57b088f83 100644 --- a/cli/errors.rs +++ b/cli/errors.rs @@ -14,6 +14,7 @@ use deno_core::error::AnyError; use deno_graph::source::ResolveError; use deno_graph::ModuleError; use deno_graph::ModuleGraphError; +use deno_graph::ModuleLoadError; use deno_graph::ResolutionError; use import_map::ImportMapError; use std::fmt::Write; @@ -27,24 +28,55 @@ fn get_diagnostic_class(_: &ParseDiagnostic) -> &'static str { } fn get_module_graph_error_class(err: &ModuleGraphError) -> &'static str { + use deno_graph::JsrLoadError; + use deno_graph::NpmLoadError; + use deno_graph::WorkspaceLoadError; + match err { + ModuleGraphError::ResolutionError(err) + | ModuleGraphError::TypesResolutionError(err) => { + get_resolution_error_class(err) + } ModuleGraphError::ModuleError(err) => match err { - ModuleError::LoadingErr(_, _, err) => get_error_class_name(err.as_ref()), ModuleError::InvalidTypeAssertion { .. } => "SyntaxError", ModuleError::ParseErr(_, diagnostic) => get_diagnostic_class(diagnostic), ModuleError::UnsupportedMediaType { .. } | ModuleError::UnsupportedImportAttributeType { .. } => "TypeError", - ModuleError::Missing(_, _) - | ModuleError::MissingDynamic(_, _) - | ModuleError::MissingWorkspaceMemberExports { .. } - | ModuleError::UnknownExport { .. } - | ModuleError::UnknownPackage { .. } - | ModuleError::UnknownPackageReq { .. } => "NotFound", + ModuleError::Missing(_, _) | ModuleError::MissingDynamic(_, _) => { + "NotFound" + } + ModuleError::LoadingErr(_, _, err) => match err { + ModuleLoadError::Loader(err) => get_error_class_name(err.as_ref()), + ModuleLoadError::HttpsChecksumIntegrity(_) + | ModuleLoadError::TooManyRedirects => "Error", + ModuleLoadError::NodeUnknownBuiltinModule(_) => "NotFound", + ModuleLoadError::Decode(_) => "TypeError", + ModuleLoadError::Npm(err) => match err { + NpmLoadError::NotSupportedEnvironment + | NpmLoadError::PackageReqResolution(_) + | NpmLoadError::RegistryInfo(_) => "Error", + NpmLoadError::PackageReqReferenceParse(_) => "TypeError", + }, + ModuleLoadError::Jsr(err) => match err { + JsrLoadError::UnsupportedManifestChecksum + | JsrLoadError::PackageFormat(_) => "TypeError", + JsrLoadError::ContentLoadExternalSpecifier + | JsrLoadError::ContentLoad(_) + | JsrLoadError::ContentChecksumIntegrity(_) + | JsrLoadError::PackageManifestLoad(_, _) + | JsrLoadError::PackageVersionManifestLoad(_, _) + | JsrLoadError::RedirectInPackage(_) => "Error", + JsrLoadError::PackageNotFound(_) + | JsrLoadError::PackageReqNotFound(_) + | JsrLoadError::PackageVersionNotFound(_) + | JsrLoadError::UnknownExport { .. } => "NotFound", + }, + ModuleLoadError::Workspace(err) => match err { + WorkspaceLoadError::MemberInvalidExportPath { .. } => "TypeError", + WorkspaceLoadError::MissingMemberExports { .. } => "NotFound", + }, + }, }, - ModuleGraphError::ResolutionError(err) - | ModuleGraphError::TypesResolutionError(err) => { - get_resolution_error_class(err) - } } } diff --git a/cli/factory.rs b/cli/factory.rs index 6cdbff9bba4507..ce9736e68a7d2d 100644 --- a/cli/factory.rs +++ b/cli/factory.rs @@ -665,7 +665,6 @@ impl CliFactory { self.options.clone(), self.npm_resolver().await?.clone(), self.module_graph_builder().await?.clone(), - self.maybe_lockfile().clone(), self.type_checker().await?.clone(), ))) }) diff --git a/cli/file_fetcher.rs b/cli/file_fetcher.rs index eda579b2b4c568..a8d835d0e78d37 100644 --- a/cli/file_fetcher.rs +++ b/cli/file_fetcher.rs @@ -253,15 +253,30 @@ impl FileFetcher { deno_core::resolve_import(redirect_to, specifier.as_str())?; return Ok(Some(FileOrRedirect::Redirect(redirect))); } - let Some(bytes) = self.http_cache.read_file_bytes( + let result = self.http_cache.read_file_bytes( &cache_key, maybe_checksum .as_ref() .map(|c| deno_cache_dir::Checksum::new(c.as_str())), deno_cache_dir::GlobalToLocalCopy::Allow, - )? - else { - return Ok(None); + ); + let bytes = match result { + Ok(Some(bytes)) => bytes, + Ok(None) => return Ok(None), + Err(err) => match err { + deno_cache_dir::CacheReadFileError::Io(err) => return Err(err.into()), + deno_cache_dir::CacheReadFileError::ChecksumIntegrity(err) => { + // convert to the equivalent deno_graph error so that it + // enhances it if this is passed to deno_graph + return Err( + deno_graph::source::ChecksumIntegrityError { + actual: err.actual, + expected: err.expected, + } + .into(), + ); + } + }, }; Ok(Some(FileOrRedirect::File(File { diff --git a/cli/graph_util.rs b/cli/graph_util.rs index bf2c9021fc4bcd..12b3d589efe3ce 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -18,6 +18,7 @@ use crate::tools::check; use crate::tools::check::TypeChecker; use crate::util::file_watcher::WatcherCommunicator; use crate::util::fs::canonicalize_path; +use deno_emit::LoaderChecksum; use deno_runtime::fs_util::specifier_to_file_path; use deno_config::WorkspaceMemberConfig; @@ -152,43 +153,6 @@ pub fn graph_valid( } } -/// Checks the lockfile against the graph and exits on errors. -pub fn graph_lock_or_exit(graph: &ModuleGraph, lockfile: &mut Lockfile) { - for module in graph.modules() { - let source = match module { - Module::Js(module) if module.media_type.is_declaration() => continue, // skip declaration files - Module::Js(module) => &module.source, - Module::Json(module) => &module.source, - Module::Node(_) | Module::Npm(_) | Module::External(_) => continue, - }; - - // skip over any specifiers in JSR packages because those - // are enforced via the integrity - if deno_graph::source::recommended_registry_package_url_to_nv( - jsr_url(), - module.specifier(), - ) - .is_some() - { - continue; - } - - if !lockfile.check_or_insert_remote(module.specifier().as_str(), source) { - let err = format!( - concat!( - "The source code is invalid, as it does not match the expected hash in the lock file.\n", - " Specifier: {}\n", - " Lock file: {}", - ), - module.specifier(), - lockfile.filename.display(), - ); - log::error!("{} {}", colors::red("error:"), err); - std::process::exit(10); - } - } -} - pub struct CreateGraphOptions<'a> { pub graph_kind: GraphKind, pub roots: Vec, @@ -201,7 +165,6 @@ pub struct ModuleGraphCreator { options: Arc, npm_resolver: Arc, module_graph_builder: Arc, - lockfile: Option>>, type_checker: Arc, } @@ -210,13 +173,11 @@ impl ModuleGraphCreator { options: Arc, npm_resolver: Arc, module_graph_builder: Arc, - lockfile: Option>>, type_checker: Arc, ) -> Self { Self { options, npm_resolver, - lockfile, module_graph_builder, type_checker, } @@ -317,9 +278,6 @@ impl ModuleGraphCreator { .await?; self.graph_valid(&graph)?; - if let Some(lockfile) = &self.lockfile { - graph_lock_or_exit(&graph, &mut lockfile.lock()); - } if self.options.type_check_mode().is_true() { // provide the graph to the type checker, then get it back after it's done @@ -460,6 +418,7 @@ impl ModuleGraphBuilder { module_analyzer: &analyzer, reporter: maybe_file_watcher_reporter, resolver: Some(graph_resolver), + verify_and_fill_checksums: self.lockfile.is_some(), }, ) .await @@ -480,8 +439,10 @@ impl ModuleGraphBuilder { } } - // add the lockfile redirects to the graph if it's the first time executing - if graph.redirects.is_empty() { + // fill the graph with the information from the lockfile + let is_first_execution = graph.roots.is_empty(); + if is_first_execution { + // populate the information from the lockfile if let Some(lockfile) = &self.lockfile { let lockfile = lockfile.lock(); for (from, to) in &lockfile.content.redirects { @@ -493,13 +454,13 @@ impl ModuleGraphBuilder { } } } - } - } - - // add the jsr specifiers to the graph if it's the first time executing - if graph.packages.is_empty() { - if let Some(lockfile) = &self.lockfile { - let lockfile = lockfile.lock(); + for (module, checksum) in &lockfile.content.remote { + if let Ok(module) = ModuleSpecifier::parse(module) { + graph + .checksums + .insert(module, LoaderChecksum::new(checksum.clone())); + } + } for (key, value) in &lockfile.content.packages.specifiers { if let Some(key) = key .strip_prefix("jsr:") @@ -529,44 +490,14 @@ impl ModuleGraphBuilder { } } + // todo: handle jsr package manifest checksums + let initial_redirects_len = graph.redirects.len(); + let initial_checksums_len = graph.checksums.len(); + let initial_packages_len = graph.packages.packages_len(); + let initial_package_mappings_len = graph.packages.mappings().len(); + let initial_npm_packages = graph.npm_packages.len(); graph.build(roots, loader, options).await; - // add the redirects in the graph to the lockfile - if !graph.redirects.is_empty() { - if let Some(lockfile) = &self.lockfile { - let graph_redirects = graph.redirects.iter().filter(|(from, _)| { - !matches!(from.scheme(), "npm" | "file" | "deno") - }); - let mut lockfile = lockfile.lock(); - for (from, to) in graph_redirects { - lockfile.insert_redirect(from.to_string(), to.to_string()); - } - } - } - - // add the jsr specifiers in the graph to the lockfile - if !graph.packages.is_empty() { - if let Some(lockfile) = &self.lockfile { - let mappings = graph.packages.mappings(); - let mut lockfile = lockfile.lock(); - for (from, to) in mappings { - lockfile.insert_package_specifier( - format!("jsr:{}", from), - format!("jsr:{}", to), - ); - } - for (name, checksum, deps) in - graph.packages.packages_with_checksum_and_deps() - { - lockfile.insert_package( - name.to_string(), - checksum.clone(), - deps.map(|s| s.to_string()), - ); - } - } - } - if let Some(npm_resolver) = self.npm_resolver.as_managed() { // ensure that the top level package.json is installed if a // specifier was matched in the package.json @@ -579,6 +510,76 @@ impl ModuleGraphBuilder { npm_resolver.resolve_pending().await?; } + let has_redirects_changed = graph.redirects.len() != initial_redirects_len; + let has_checksums_changed = graph.checksums.len() != initial_checksums_len; + let has_jsr_packages_changed = + graph.packages.packages_len() != initial_packages_len; + let has_jsr_package_mappings_changed = + graph.packages.mappings().len() != initial_package_mappings_len; + let has_npm_packages_changed = + graph.npm_packages.len() != initial_npm_packages; + + if has_redirects_changed + || has_checksums_changed + || has_jsr_packages_changed + || has_jsr_package_mappings_changed + || has_npm_packages_changed + { + if let Some(lockfile) = &self.lockfile { + let mut lockfile = lockfile.lock(); + // https redirects + if has_redirects_changed { + let graph_redirects = graph.redirects.iter().filter(|(from, _)| { + !matches!(from.scheme(), "npm" | "file" | "deno") + }); + for (from, to) in graph_redirects { + lockfile.insert_redirect(from.to_string(), to.to_string()); + } + } + // https module checksums + if has_checksums_changed { + for (module, checksum) in graph.checksums.iter() { + lockfile + .content + .remote + .insert(module.to_string(), checksum.as_str().to_string()); + } + } + // jsr package mappings + if has_jsr_package_mappings_changed { + for (from, to) in graph.packages.mappings() { + lockfile.insert_package_specifier( + format!("jsr:{}", from), + format!("jsr:{}", to), + ); + } + } + // jsr packages + if has_jsr_packages_changed { + for (name, checksum, deps) in + graph.packages.packages_with_checksum_and_deps() + { + lockfile.insert_package( + name.to_string(), + checksum.clone(), + deps.map(|s| s.to_string()), + ); + } + } + // npm packages + if has_npm_packages_changed { + // this verifies integrity so may possibly error, but that + // will never happen because integrity verification happens + // when loading the npm resolution snapshot + self + .npm_resolver + .as_managed() + .unwrap() + .lock(&mut lockfile)?; + } + } + } + Ok(()) } diff --git a/cli/main.rs b/cli/main.rs index a2d270d4018efd..2fef5ebebef503 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -292,6 +292,16 @@ fn exit_for_error(error: AnyError) -> ! { { error_string = e.to_string(); error_code = 10; + } else if let Some(deno_graph::ModuleGraphError::ModuleError( + deno_graph::ModuleError::LoadingErr(_, _, e), + )) = error.downcast_ref::() + { + match e { + deno_graph::ModuleLoadError::HttpsChecksumIntegrity(_) => { + error_code = 10; + } + _ => {} + } } exit_with_message(&error_string, error_code); diff --git a/cli/module_loader.rs b/cli/module_loader.rs index 6d8d3e92b96c11..e05ffbe2134e54 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -20,7 +20,6 @@ use crate::factory::CliFactory; use crate::graph_container::MainModuleGraphContainer; use crate::graph_container::ModuleGraphContainer; use crate::graph_container::ModuleGraphUpdatePermit; -use crate::graph_util::graph_lock_or_exit; use crate::graph_util::CreateGraphOptions; use crate::graph_util::ModuleGraphBuilder; use crate::node; @@ -175,9 +174,7 @@ impl ModuleLoadPreparer { // If there is a lockfile... if let Some(lockfile) = &self.lockfile { - let mut lockfile = lockfile.lock(); - // validate the integrity of all the modules - graph_lock_or_exit(graph, &mut lockfile); + let lockfile = lockfile.lock(); // update it with anything new lockfile.write().context("Failed writing lockfile.")?; } @@ -819,6 +816,9 @@ impl ModuleLoader let lib = inner.lib; let mut update_permit = graph_container.acquire_update_permit().await; let graph = update_permit.graph_mut(); + // if is_dynamic && graph.contains(&specifier) { + // return Ok(()); + // } module_load_preparer .prepare_module_load( graph, diff --git a/cli/npm/managed/mod.rs b/cli/npm/managed/mod.rs index 3a2657cfb4638d..dbbc1c18c2e91e 100644 --- a/cli/npm/managed/mod.rs +++ b/cli/npm/managed/mod.rs @@ -369,12 +369,6 @@ impl ManagedCliNpmResolver { self.resolution.add_package_reqs(packages).await?; self.fs_resolver.cache_packages().await?; - // If there's a lock file, update it with all discovered npm packages - if let Some(lockfile_mutex) = &self.maybe_lockfile { - let mut lockfile = lockfile_mutex.lock(); - self.lock(&mut lockfile)?; - } - Ok(()) } diff --git a/cli/npm/managed/resolution.rs b/cli/npm/managed/resolution.rs index 1903d339b78740..6c90528fc3447d 100644 --- a/cli/npm/managed/resolution.rs +++ b/cli/npm/managed/resolution.rs @@ -384,6 +384,9 @@ fn populate_lockfile_from_snapshot( ); } for package in snapshot.all_packages_for_every_system() { + // todo(dsherret): there is no reason to verify the integrity here + // because we already did that when populating the snapshot from + // the lockfile lockfile .check_or_insert_npm_package(npm_package_to_lockfile_info(package))?; } diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index 55d13838b95cd4..b35b80e1a9dce1 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -8,7 +8,6 @@ use crate::colors; use crate::display::write_json_to_stdout; use crate::display::write_to_stdout_ignore_sigpipe; use crate::factory::CliFactory; -use crate::graph_util::graph_lock_or_exit; use crate::tsc::get_types_declaration_file_text; use crate::util::fs::collect_specifiers; use deno_ast::diagnostics::Diagnostic; @@ -66,6 +65,7 @@ async fn generate_doc_nodes_for_builtin_types( npm_resolver: None, reporter: None, resolver: None, + verify_and_fill_checksums: false, }, ) .await; @@ -102,7 +102,6 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> { } DocSourceFileFlag::Paths(ref source_files) => { let module_graph_creator = factory.module_graph_creator().await?; - let maybe_lockfile = factory.maybe_lockfile(); let module_specifiers = collect_specifiers( FilePatterns { @@ -122,9 +121,7 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> { .create_graph(GraphKind::TypesOnly, module_specifiers.clone()) .await?; - if let Some(lockfile) = maybe_lockfile { - graph_lock_or_exit(&graph, &mut lockfile.lock()); - } + // todo(THIS PR): validate the graph in order to surface lockfile errors? let doc_parser = doc::DocParser::new( &graph, diff --git a/cli/tools/info.rs b/cli/tools/info.rs index 19975571b7ea73..4f8e228d95c074 100644 --- a/cli/tools/info.rs +++ b/cli/tools/info.rs @@ -30,7 +30,6 @@ use crate::args::Flags; use crate::args::InfoFlags; use crate::display; use crate::factory::CliFactory; -use crate::graph_util::graph_lock_or_exit; use crate::npm::CliNpmResolver; use crate::npm::ManagedCliNpmResolver; use crate::util::checksum; @@ -70,9 +69,7 @@ pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> { // If there is a lockfile... if let Some(lockfile) = &maybe_lockfile { - let mut lockfile = lockfile.lock(); - // validate the integrity of all the modules - graph_lock_or_exit(&graph, &mut lockfile); + let lockfile = lockfile.lock(); // update it with anything new lockfile.write().context("Failed writing lockfile.")?; } @@ -669,18 +666,6 @@ impl<'a> GraphDisplayContext<'a> { ModuleError::Missing(_, _) | ModuleError::MissingDynamic(_, _) => { self.build_error_msg(specifier, "(missing)") } - ModuleError::MissingWorkspaceMemberExports { .. } => { - self.build_error_msg(specifier, "(missing exports)") - } - ModuleError::UnknownExport { .. } => { - self.build_error_msg(specifier, "(unknown export)") - } - ModuleError::UnknownPackage { .. } => { - self.build_error_msg(specifier, "(unknown package)") - } - ModuleError::UnknownPackageReq { .. } => { - self.build_error_msg(specifier, "(unknown package constraint)") - } } } diff --git a/cli/tools/registry/graph.rs b/cli/tools/registry/graph.rs index 7e3239cedd070c..0b102e21fb1ea7 100644 --- a/cli/tools/registry/graph.rs +++ b/cli/tools/registry/graph.rs @@ -41,8 +41,8 @@ pub fn collect_invalid_external_imports( let maybe_version = graph .packages .mappings() - .find(|(req, _)| *req == jsr_req_ref.req()) - .map(|(_, nv)| nv.version.clone()); + .get(jsr_req_ref.req()) + .map(|nv| nv.version.clone()); diagnostics_collector.push( PublishDiagnostic::MissingConstraint { specifier: resolution.specifier.clone(), diff --git a/cli/tools/vendor/build.rs b/cli/tools/vendor/build.rs index 5435a0035ef638..ab552ca6540dcb 100644 --- a/cli/tools/vendor/build.rs +++ b/cli/tools/vendor/build.rs @@ -9,7 +9,6 @@ use deno_core::anyhow::bail; use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::futures::future::LocalBoxFuture; -use deno_core::parking_lot::Mutex; use deno_graph::source::ResolutionMode; use deno_graph::JsModule; use deno_graph::Module; @@ -19,10 +18,8 @@ use import_map::ImportMap; use import_map::SpecifierMap; use crate::args::JsxImportSourceConfig; -use crate::args::Lockfile; use crate::cache::ParsedSourceCache; use crate::graph_util; -use crate::graph_util::graph_lock_or_exit; use crate::tools::vendor::import_map::BuildImportMapInput; use super::analyze::has_default_export; @@ -62,7 +59,6 @@ pub struct BuildInput< pub parsed_source_cache: &'a ParsedSourceCache, pub output_dir: &'a Path, pub maybe_original_import_map: Option<&'a ImportMap>, - pub maybe_lockfile: Option>>, pub maybe_jsx_import_source: Option<&'a JsxImportSourceConfig>, pub resolver: &'a dyn deno_graph::source::Resolver, pub environment: &'a TEnvironment, @@ -86,7 +82,6 @@ pub async fn build< parsed_source_cache, output_dir, maybe_original_import_map: original_import_map, - maybe_lockfile, maybe_jsx_import_source: jsx_import_source, resolver, environment, @@ -118,11 +113,6 @@ pub async fn build< let graph = build_graph(entry_points).await?; - // check the lockfile - if let Some(lockfile) = maybe_lockfile { - graph_lock_or_exit(&graph, &mut lockfile.lock()); - } - // surface any errors graph_util::graph_valid( &graph, diff --git a/cli/tools/vendor/mod.rs b/cli/tools/vendor/mod.rs index cf10b77c75a8c0..a8d8000d8f52cd 100644 --- a/cli/tools/vendor/mod.rs +++ b/cli/tools/vendor/mod.rs @@ -65,7 +65,6 @@ pub async fn vendor( parsed_source_cache: factory.parsed_source_cache(), output_dir: &output_dir, maybe_original_import_map: factory.maybe_import_map().await?.as_deref(), - maybe_lockfile: factory.maybe_lockfile().clone(), maybe_jsx_import_source: jsx_import_source.as_ref(), resolver: factory.resolver().await?.as_graph_resolver(), environment: &build::RealVendorEnvironment, From 2b0192f8c6bfecb3706aae26cb0a2f4b7c4c3700 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 27 May 2024 13:20:01 -0400 Subject: [PATCH 05/17] More improvements --- .dprint.json | 8 +- Cargo.lock | 6 +- Cargo.toml | 2 + cli/Cargo.toml | 2 +- cli/errors.rs | 1 + cli/graph_util.rs | 153 ++++++++++++++---- cli/main.rs | 10 -- cli/tools/doc.rs | 2 +- cli/tools/vendor/test.rs | 1 - tests/integration/bundle_tests.rs | 7 - tests/integration/jsr_tests.rs | 20 ++- tests/integration/npm_tests.rs | 2 +- tests/integration/run_tests.rs | 21 --- tests/specs/bundle/lockfile/__test__.jsonc | 5 + .../bundle/lockfile/check_error.json | 0 tests/specs/bundle/lockfile/check_error.out | 12 ++ .../future_install_node_modules/corrupted.out | 2 +- .../run/auto_discover_lockfile/__test__.jsonc | 5 + .../run/auto_discover_lockfile/deno.json | 0 .../run/auto_discover_lockfile/deno.lock | 0 .../specs/run/auto_discover_lockfile/main.out | 13 ++ .../run/auto_discover_lockfile/main.ts | 0 tests/specs/run/lock_check_err/__test__.jsonc | 5 + .../run/lock_check_err}/lock_check_err.json | 0 .../run/lock_check_err/lock_check_err.out | 11 ++ .../specs/run/lock_check_err2/__test__.jsonc | 5 + .../run/lock_check_err2}/lock_check_err2.json | 0 .../run/lock_check_err2/lock_check_err2.out | 11 ++ .../testdata/bundle/lockfile/check_error.out | 4 - tests/testdata/npm/lock_file/main.out | 2 +- .../run/auto_discover_lockfile/main.out | 5 - tests/testdata/run/lock_check_err.out | 3 - tests/testdata/run/lock_check_err2.out | 3 - 33 files changed, 211 insertions(+), 110 deletions(-) create mode 100644 tests/specs/bundle/lockfile/__test__.jsonc rename tests/{testdata => specs}/bundle/lockfile/check_error.json (100%) create mode 100644 tests/specs/bundle/lockfile/check_error.out create mode 100644 tests/specs/run/auto_discover_lockfile/__test__.jsonc rename tests/{testdata => specs}/run/auto_discover_lockfile/deno.json (100%) rename tests/{testdata => specs}/run/auto_discover_lockfile/deno.lock (100%) create mode 100644 tests/specs/run/auto_discover_lockfile/main.out rename tests/{testdata => specs}/run/auto_discover_lockfile/main.ts (100%) create mode 100644 tests/specs/run/lock_check_err/__test__.jsonc rename tests/{testdata/run => specs/run/lock_check_err}/lock_check_err.json (100%) create mode 100644 tests/specs/run/lock_check_err/lock_check_err.out create mode 100644 tests/specs/run/lock_check_err2/__test__.jsonc rename tests/{testdata/run => specs/run/lock_check_err2}/lock_check_err2.json (100%) create mode 100644 tests/specs/run/lock_check_err2/lock_check_err2.out delete mode 100644 tests/testdata/bundle/lockfile/check_error.out delete mode 100644 tests/testdata/run/auto_discover_lockfile/main.out delete mode 100644 tests/testdata/run/lock_check_err.out delete mode 100644 tests/testdata/run/lock_check_err2.out diff --git a/.dprint.json b/.dprint.json index d34155a01453f9..e0569ca35e6cc3 100644 --- a/.dprint.json +++ b/.dprint.json @@ -57,10 +57,10 @@ "ext/websocket/autobahn/reports" ], "plugins": [ - "https://plugins.dprint.dev/typescript-0.90.5.wasm", - "https://plugins.dprint.dev/json-0.19.2.wasm", - "https://plugins.dprint.dev/markdown-0.17.0.wasm", - "https://plugins.dprint.dev/toml-0.6.1.wasm", + "https://plugins.dprint.dev/typescript-0.91.0.wasm", + "https://plugins.dprint.dev/json-0.19.3.wasm", + "https://plugins.dprint.dev/markdown-0.17.1.wasm", + "https://plugins.dprint.dev/toml-0.6.2.wasm", "https://plugins.dprint.dev/exec-0.4.4.json@c207bf9b9a4ee1f0ecb75c594f774924baf62e8e53a2ce9d873816a408cecbf7" ] } diff --git a/Cargo.lock b/Cargo.lock index 3499bd468410b5..18dee6460d3151 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1490,8 +1490,6 @@ dependencies = [ [[package]] name = "deno_emit" version = "0.40.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80b80fef2bf1b6e14712633975f7f39a3b29b95a5769cafcb959ffa1a84b7680" dependencies = [ "anyhow", "base64 0.21.7", @@ -1557,7 +1555,7 @@ dependencies = [ [[package]] name = "deno_graph" -version = "0.75.2" +version = "0.76.0" dependencies = [ "anyhow", "async-trait", @@ -2615,8 +2613,6 @@ dependencies = [ [[package]] name = "eszip" version = "0.69.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f606daca1ce18c69ccdabc59aa1c7e077356b8ffcd74e12c7646f545320a2fd" dependencies = [ "anyhow", "base64 0.21.7", diff --git a/Cargo.toml b/Cargo.toml index 98860f62447d8e..de8a9a7d275c39 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -373,5 +373,7 @@ opt-level = 3 [patch.crates-io] deno_doc = { path = "../deno_doc" } deno_graph = { path = "../deno_graph" } +eszip = { path = "../eszip" } +deno_emit = { path = "../deno_emit/rs-lib" } deno_unsync = { path = "../deno_unsync" } deno_lockfile = { path = "../deno_lockfile" } diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 2ec9f1333c85bf..2a1b9da50f3405 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -69,7 +69,7 @@ deno_config = "=0.16.3" deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] } deno_doc = { version = "=0.136.0", features = ["html", "syntect"] } deno_emit = "=0.40.3" -deno_graph = { version = "=0.75.2", features = ["tokio_executor"] } +deno_graph = { version = "=0.76.0", features = ["tokio_executor"] } deno_lint = { version = "=0.58.4", features = ["docs"] } deno_lockfile.workspace = true deno_npm = "=0.20.2" diff --git a/cli/errors.rs b/cli/errors.rs index 196ed57b088f83..9fe433f18d03ae 100644 --- a/cli/errors.rs +++ b/cli/errors.rs @@ -64,6 +64,7 @@ fn get_module_graph_error_class(err: &ModuleGraphError) -> &'static str { | JsrLoadError::ContentLoad(_) | JsrLoadError::ContentChecksumIntegrity(_) | JsrLoadError::PackageManifestLoad(_, _) + | JsrLoadError::PackageVersionManifestChecksumIntegrity(..) | JsrLoadError::PackageVersionManifestLoad(_, _) | JsrLoadError::RedirectInPackage(_) => "Error", JsrLoadError::PackageNotFound(_) diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 12b3d589efe3ce..e2c23aa01b04d9 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -19,6 +19,8 @@ use crate::tools::check::TypeChecker; use crate::util::file_watcher::WatcherCommunicator; use crate::util::fs::canonicalize_path; use deno_emit::LoaderChecksum; +use deno_graph::JsrLoadError; +use deno_graph::ModuleLoadError; use deno_runtime::fs_util::specifier_to_file_path; use deno_config::WorkspaceMemberConfig; @@ -96,8 +98,71 @@ pub fn graph_valid( enhanced_resolution_error_message(resolution_error) ) } - ModuleGraphError::ModuleError(e) => { - enhanced_module_error_message(fs.clone(), e) + ModuleGraphError::ModuleError(error) => { + match error { + ModuleError::LoadingErr(specifier, _, ModuleLoadError::Loader(_)) // ex. "Is a directory" error + | ModuleError::Missing(specifier, _) => { + sloppy_imports_error_message(fs.clone(), specifier, error) + } + ModuleError::LoadingErr(specifier, _, ModuleLoadError::Jsr(JsrLoadError::ContentChecksumIntegrity(checksum_err))) => { + let err = format!( + concat!( + "Integrity check failed in package. The package may have been tampered with.\n\n", + "Specifier: {}\n", + "Actual: {}\n", + "Expected: {}\n\n", + "If you modified your global cache, run again with the --reload ", + "flag to restore its state. If you want to modify dependencies ", + "locally run again with the --vendor flag or specify \"vendor\": true` ", + "in a deno.json then modify the contents of the `vendor` folder." + ), + specifier, + checksum_err.actual, + checksum_err.expected, + ); + log::error!("{} {}", colors::red("error:"), err); + std::process::exit(10); + } + ModuleError::LoadingErr(_specifier, _, ModuleLoadError::Jsr(JsrLoadError::PackageVersionManifestChecksumIntegrity(package_nv, checksum_err))) => { + let err = format!( + concat!( + "Integrity check failed for package. The source code is invalid, as it does not match the expected hash in the lock file.\n\n", + " Package: {}\n", + " Actual: {}\n", + " Expected: {}\n\n", + "This could be caused by:\n", + " * the lock file may be corrupt\n", + " * the source itself may be corrupt\n\n", + "Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server." + ), + package_nv, + checksum_err.actual, + checksum_err.expected, + ); + log::error!("{} {}", colors::red("error:"), err); + std::process::exit(10); + } + ModuleError::LoadingErr(specifier, _, ModuleLoadError::HttpsChecksumIntegrity(checksum_err)) => { + let err = format!( + concat!( + "Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file.\n\n", + " Specifier: {}\n", + " Actual: {}\n", + " Expected: {}\n\n", + "This could be caused by:\n", + " * the lock file may be corrupt\n", + " * the source itself may be corrupt\n\n", + "Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server." + ), + specifier, + checksum_err.actual, + checksum_err.expected, + ); + log::error!("{} {}", colors::red("error:"), err); + std::process::exit(10); + } + _ => format!("{}", error), + } } }; @@ -384,6 +449,46 @@ impl ModuleGraphBuilder { } } + // todo(THIS PR): maybe clone from the lockfile then repopulate + struct LockfileLocker(Arc>); + + impl deno_graph::source::Locker for LockfileLocker { + fn get_checksum( + &self, + specifier: &deno_ast::ModuleSpecifier, + ) -> Option { + self + .0 + .lock() + .content + .remote + .get(specifier.as_str()) + .map(|s| LoaderChecksum::new(s.clone())) + } + + fn has_checksum(&self, specifier: &deno_ast::ModuleSpecifier) -> bool { + self + .0 + .lock() + .content + .remote + .contains_key(specifier.as_str()) + } + + fn set_checksum( + &mut self, + specifier: &deno_ast::ModuleSpecifier, + checksum: LoaderChecksum, + ) { + self + .0 + .lock() + .content + .remote + .insert(specifier.as_str().to_string(), checksum.into_string()); + } + } + let maybe_imports = self.options.to_maybe_imports()?; let analyzer = self .module_info_cache @@ -401,6 +506,10 @@ impl ModuleGraphBuilder { .map(|r| r.as_reporter()); let workspace_members = self.options.resolve_deno_graph_workspace_members()?; + let mut locker = self + .lockfile + .as_ref() + .map(|lockfile| LockfileLocker(lockfile.clone())); self .build_graph_with_npm_resolution_and_build_options( graph, @@ -418,7 +527,7 @@ impl ModuleGraphBuilder { module_analyzer: &analyzer, reporter: maybe_file_watcher_reporter, resolver: Some(graph_resolver), - verify_and_fill_checksums: self.lockfile.is_some(), + locker: locker.as_mut().map(|l| l as _), }, ) .await @@ -428,7 +537,7 @@ impl ModuleGraphBuilder { &self, graph: &mut ModuleGraph, roots: Vec, - loader: &mut dyn deno_graph::source::Loader, + loader: &'a mut dyn deno_graph::source::Loader, options: deno_graph::BuildOptions<'a>, ) -> Result<(), AnyError> { // ensure an "npm install" is done if the user has explicitly @@ -454,13 +563,6 @@ impl ModuleGraphBuilder { } } } - for (module, checksum) in &lockfile.content.remote { - if let Ok(module) = ModuleSpecifier::parse(module) { - graph - .checksums - .insert(module, LoaderChecksum::new(checksum.clone())); - } - } for (key, value) in &lockfile.content.packages.specifiers { if let Some(key) = key .strip_prefix("jsr:") @@ -492,7 +594,6 @@ impl ModuleGraphBuilder { // todo: handle jsr package manifest checksums let initial_redirects_len = graph.redirects.len(); - let initial_checksums_len = graph.checksums.len(); let initial_packages_len = graph.packages.packages_len(); let initial_package_mappings_len = graph.packages.mappings().len(); let initial_npm_packages = graph.npm_packages.len(); @@ -511,7 +612,6 @@ impl ModuleGraphBuilder { } let has_redirects_changed = graph.redirects.len() != initial_redirects_len; - let has_checksums_changed = graph.checksums.len() != initial_checksums_len; let has_jsr_packages_changed = graph.packages.packages_len() != initial_packages_len; let has_jsr_package_mappings_changed = @@ -520,7 +620,6 @@ impl ModuleGraphBuilder { graph.npm_packages.len() != initial_npm_packages; if has_redirects_changed - || has_checksums_changed || has_jsr_packages_changed || has_jsr_package_mappings_changed || has_npm_packages_changed @@ -536,15 +635,6 @@ impl ModuleGraphBuilder { lockfile.insert_redirect(from.to_string(), to.to_string()); } } - // https module checksums - if has_checksums_changed { - for (module, checksum) in graph.checksums.iter() { - lockfile - .content - .remote - .insert(module.to_string(), checksum.as_str().to_string()); - } - } // jsr package mappings if has_jsr_package_mappings_changed { for (from, to) in graph.packages.mappings() { @@ -703,21 +793,14 @@ pub fn enhanced_resolution_error_message(error: &ResolutionError) -> String { message } -pub fn enhanced_module_error_message( +fn sloppy_imports_error_message( fs: Arc, + specifier: &ModuleSpecifier, error: &ModuleError, ) -> String { - let additional_message = match error { - ModuleError::LoadingErr(specifier, _, _) // ex. "Is a directory" error - | ModuleError::Missing(specifier, _) => { - SloppyImportsResolver::new(fs).resolve( - specifier, - ResolutionMode::Execution, - ) - .as_suggestion_message() - } - _ => None, - }; + let additional_message = SloppyImportsResolver::new(fs) + .resolve(specifier, ResolutionMode::Execution) + .as_suggestion_message(); if let Some(message) = additional_message { format!( "{} {} or run with --unstable-sloppy-imports", diff --git a/cli/main.rs b/cli/main.rs index 2fef5ebebef503..a2d270d4018efd 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -292,16 +292,6 @@ fn exit_for_error(error: AnyError) -> ! { { error_string = e.to_string(); error_code = 10; - } else if let Some(deno_graph::ModuleGraphError::ModuleError( - deno_graph::ModuleError::LoadingErr(_, _, e), - )) = error.downcast_ref::() - { - match e { - deno_graph::ModuleLoadError::HttpsChecksumIntegrity(_) => { - error_code = 10; - } - _ => {} - } } exit_with_message(&error_string, error_code); diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index b35b80e1a9dce1..9a1503dff3e540 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -61,11 +61,11 @@ async fn generate_doc_nodes_for_builtin_types( executor: Default::default(), file_system: &NullFileSystem, jsr_url_provider: Default::default(), + locker: None, module_analyzer: analyzer, npm_resolver: None, reporter: None, resolver: None, - verify_and_fill_checksums: false, }, ) .await; diff --git a/cli/tools/vendor/test.rs b/cli/tools/vendor/test.rs index b4993565ddd19e..830d5f8f0c9dc0 100644 --- a/cli/tools/vendor/test.rs +++ b/cli/tools/vendor/test.rs @@ -258,7 +258,6 @@ impl VendorTestBuilder { parsed_source_cache: &parsed_source_cache, output_dir: &output_dir, maybe_original_import_map: self.original_import_map.as_ref(), - maybe_lockfile: None, maybe_jsx_import_source: self.jsx_import_source_config.as_ref(), resolver: resolver.as_graph_resolver(), environment: &self.environment, diff --git a/tests/integration/bundle_tests.rs b/tests/integration/bundle_tests.rs index 0738a0cfececff..20f88329323c28 100644 --- a/tests/integration/bundle_tests.rs +++ b/tests/integration/bundle_tests.rs @@ -416,13 +416,6 @@ fn bundle_json_module_escape_sub() { ); } -itest!(lockfile_check_error { - args: "bundle --lock=bundle/lockfile/check_error.json http://127.0.0.1:4545/subdir/mod1.ts", - output: "bundle/lockfile/check_error.out", - exit_code: 10, - http_server: true, -}); - itest!(bundle { args: "bundle subdir/mod1.ts", output: "bundle/bundle.test.out", diff --git a/tests/integration/jsr_tests.rs b/tests/integration/jsr_tests.rs index 83d696093d5f88..ddff613584867b 100644 --- a/tests/integration/jsr_tests.rs +++ b/tests/integration/jsr_tests.rs @@ -259,18 +259,24 @@ console.log(version);"#, let actual_integrity = test_context.get_jsr_package_integrity("@denotest/no-module-graph/0.1.1"); - let integrity_check_failed_msg = format!("error: Integrity check failed for http://127.0.0.1:4250/@denotest/no-module-graph/0.1.1_meta.json + let integrity_check_failed_msg = format!("[WILDCARD]Integrity check failed for package. The source code is invalid, as it does not match the expected hash in the lock file. -Actual: {} -Expected: bad_integrity - at file:///[WILDCARD]/main.ts:1:21 + Package: @denotest/no-module-graph@0.1.1 + Actual: {} + Expected: bad_integrity + +This could be caused by: + * the lock file may be corrupt + * the source itself may be corrupt + +Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. ", actual_integrity); test_context .new_command() .args("run --quiet main.ts") .run() .assert_matches_text(&integrity_check_failed_msg) - .assert_exit_code(1); + .assert_exit_code(10); // now try with a vendor folder temp_dir @@ -284,7 +290,7 @@ Expected: bad_integrity .args("run --quiet main.ts") .run() .assert_matches_text(&integrity_check_failed_msg) - .assert_exit_code(1); + .assert_exit_code(10); // now update to the correct integrity set_lockfile_pkg_integrity(&mut lockfile, pkg_name, &original_integrity); @@ -318,7 +324,7 @@ Expected: bad_integrity .args("run --quiet main.ts") .run() .assert_matches_text(&integrity_check_failed_msg) - .assert_exit_code(1); + .assert_exit_code(10); } #[test] diff --git a/tests/integration/npm_tests.rs b/tests/integration/npm_tests.rs index 63547cfce1cef9..9b9d2ea57de8fd 100644 --- a/tests/integration/npm_tests.rs +++ b/tests/integration/npm_tests.rs @@ -1518,7 +1518,7 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use "--lock-write" flag to regenerate the lockfile at "[WILDCARD]deno.lock". +Use the --lock-write flag to regenerate the lockfile at "[WILDCARD]deno.lock". "#) .assert_exit_code(10); } diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs index f3fc18fee25d9d..5234799915d673 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -828,20 +828,6 @@ itest!(lock_dynamic_imports { http_server: true, }); -itest!(lock_check_err { - args: "run --lock=run/lock_check_err.json http://127.0.0.1:4545/run/003_relative_import.ts", - output: "run/lock_check_err.out", - exit_code: 10, - http_server: true, -}); - -itest!(lock_check_err2 { - args: "run --lock=run/lock_check_err2.json run/019_media_types.ts", - output: "run/lock_check_err2.out", - exit_code: 10, - http_server: true, -}); - itest!(config_file_lock_path { args: "run --config=run/config_file_lock_path.json run/019_media_types.ts", output: "run/config_file_lock_path.out", @@ -4562,13 +4548,6 @@ async fn websocket_server_idletimeout() { assert_eq!(child.wait().unwrap().code(), Some(123)); } -itest!(auto_discover_lockfile { - args: "run run/auto_discover_lockfile/main.ts", - output: "run/auto_discover_lockfile/main.out", - http_server: true, - exit_code: 10, -}); - itest!(no_lock_flag { args: "run --no-lock run/no_lock_flag/main.ts", output: "run/no_lock_flag/main.out", diff --git a/tests/specs/bundle/lockfile/__test__.jsonc b/tests/specs/bundle/lockfile/__test__.jsonc new file mode 100644 index 00000000000000..3fe64a28b54bde --- /dev/null +++ b/tests/specs/bundle/lockfile/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "bundle --lock=check_error.json http://127.0.0.1:4545/subdir/mod1.ts", + "output": "check_error.out", + "exitCode": 10 +} diff --git a/tests/testdata/bundle/lockfile/check_error.json b/tests/specs/bundle/lockfile/check_error.json similarity index 100% rename from tests/testdata/bundle/lockfile/check_error.json rename to tests/specs/bundle/lockfile/check_error.json diff --git a/tests/specs/bundle/lockfile/check_error.out b/tests/specs/bundle/lockfile/check_error.out new file mode 100644 index 00000000000000..2b8bdfc96eaf4f --- /dev/null +++ b/tests/specs/bundle/lockfile/check_error.out @@ -0,0 +1,12 @@ +[WILDCARD] +error: Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file. + + Specifier: http://127.0.0.1:4545/subdir/subdir2/mod2.ts + Actual: 8b3b670d25d238dfa72df119140406b96766a00fee635f3606429fe065b18fd1 + Expected: bad + +This could be caused by: + * the lock file may be corrupt + * the source itself may be corrupt + +Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/install/future_install_node_modules/corrupted.out b/tests/specs/install/future_install_node_modules/corrupted.out index 89578cbe260b8a..9943c1ce9f386e 100644 --- a/tests/specs/install/future_install_node_modules/corrupted.out +++ b/tests/specs/install/future_install_node_modules/corrupted.out @@ -1,3 +1,3 @@ [WILDCARD] error: Integrity check failed for package: "npm:@denotest/esm-basic@1.0.0".[WILDCARD] -Use "--lock-write" flag to regenerate the lockfile at [WILDCARD] \ No newline at end of file +Use the --lock-write flag to regenerate the lockfile at [WILDCARD] \ No newline at end of file diff --git a/tests/specs/run/auto_discover_lockfile/__test__.jsonc b/tests/specs/run/auto_discover_lockfile/__test__.jsonc new file mode 100644 index 00000000000000..50213381ad5f12 --- /dev/null +++ b/tests/specs/run/auto_discover_lockfile/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "run main.ts", + "output": "main.out", + "exitCode": 10 +} diff --git a/tests/testdata/run/auto_discover_lockfile/deno.json b/tests/specs/run/auto_discover_lockfile/deno.json similarity index 100% rename from tests/testdata/run/auto_discover_lockfile/deno.json rename to tests/specs/run/auto_discover_lockfile/deno.json diff --git a/tests/testdata/run/auto_discover_lockfile/deno.lock b/tests/specs/run/auto_discover_lockfile/deno.lock similarity index 100% rename from tests/testdata/run/auto_discover_lockfile/deno.lock rename to tests/specs/run/auto_discover_lockfile/deno.lock diff --git a/tests/specs/run/auto_discover_lockfile/main.out b/tests/specs/run/auto_discover_lockfile/main.out new file mode 100644 index 00000000000000..aa24320d14bdff --- /dev/null +++ b/tests/specs/run/auto_discover_lockfile/main.out @@ -0,0 +1,13 @@ +Download http://localhost:4545/subdir/mod2.ts +Download http://localhost:4545/subdir/print_hello.ts +error: Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file. + + Specifier: http://localhost:4545/subdir/print_hello.ts + Actual: fa6692c8f9ff3fb107e773c3ece5274e9d08be282867a1e3ded1d9c00fcaa63c + Expected: foobar + +This could be caused by: + * the lock file may be corrupt + * the source itself may be corrupt + +Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/testdata/run/auto_discover_lockfile/main.ts b/tests/specs/run/auto_discover_lockfile/main.ts similarity index 100% rename from tests/testdata/run/auto_discover_lockfile/main.ts rename to tests/specs/run/auto_discover_lockfile/main.ts diff --git a/tests/specs/run/lock_check_err/__test__.jsonc b/tests/specs/run/lock_check_err/__test__.jsonc new file mode 100644 index 00000000000000..7b4777faddf545 --- /dev/null +++ b/tests/specs/run/lock_check_err/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "run --lock=lock_check_err.json http://127.0.0.1:4545/run/003_relative_import.ts", + "output": "lock_check_err.out", + "exitCode": 10 +} diff --git a/tests/testdata/run/lock_check_err.json b/tests/specs/run/lock_check_err/lock_check_err.json similarity index 100% rename from tests/testdata/run/lock_check_err.json rename to tests/specs/run/lock_check_err/lock_check_err.json diff --git a/tests/specs/run/lock_check_err/lock_check_err.out b/tests/specs/run/lock_check_err/lock_check_err.out new file mode 100644 index 00000000000000..25d22490da3710 --- /dev/null +++ b/tests/specs/run/lock_check_err/lock_check_err.out @@ -0,0 +1,11 @@ +[WILDCARD]Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file. + + Specifier: http://127.0.0.1:4545/run/003_relative_import.ts + Actual: a1572e8fd2c2712b33f04aed2561505b5feb2c8696f1f2cded3de7127931b97e + Expected: bad + +This could be caused by: + * the lock file may be corrupt + * the source itself may be corrupt + +Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/run/lock_check_err2/__test__.jsonc b/tests/specs/run/lock_check_err2/__test__.jsonc new file mode 100644 index 00000000000000..adcf816c408f71 --- /dev/null +++ b/tests/specs/run/lock_check_err2/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "run --lock=lock_check_err2.json http://localhost:4545/run/019_media_types.ts", + "output": "lock_check_err2.out", + "exitCode": 10 +} diff --git a/tests/testdata/run/lock_check_err2.json b/tests/specs/run/lock_check_err2/lock_check_err2.json similarity index 100% rename from tests/testdata/run/lock_check_err2.json rename to tests/specs/run/lock_check_err2/lock_check_err2.json diff --git a/tests/specs/run/lock_check_err2/lock_check_err2.out b/tests/specs/run/lock_check_err2/lock_check_err2.out new file mode 100644 index 00000000000000..1383d945d05c6a --- /dev/null +++ b/tests/specs/run/lock_check_err2/lock_check_err2.out @@ -0,0 +1,11 @@ +[WILDCARD]Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file. + + Specifier: http://localhost:4545/subdir/mt_text_ecmascript.j3.js + Actual: 3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18 + Expected: bad + +This could be caused by: + * the lock file may be corrupt + * the source itself may be corrupt + +Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/testdata/bundle/lockfile/check_error.out b/tests/testdata/bundle/lockfile/check_error.out deleted file mode 100644 index 9299bc27e14990..00000000000000 --- a/tests/testdata/bundle/lockfile/check_error.out +++ /dev/null @@ -1,4 +0,0 @@ -[WILDCARD] -error: The source code is invalid, as it does not match the expected hash in the lock file. - Specifier: http://127.0.0.1:4545/subdir/subdir2/mod2.ts - Lock file: bundle/lockfile/check_error.json diff --git a/tests/testdata/npm/lock_file/main.out b/tests/testdata/npm/lock_file/main.out index dead1a623cfab2..741edd9d226165 100644 --- a/tests/testdata/npm/lock_file/main.out +++ b/tests/testdata/npm/lock_file/main.out @@ -9,4 +9,4 @@ This could be caused by: * the lock file may be corrupt * the source itself may be corrupt -Use "--lock-write" flag to regenerate the lockfile at "[WILDCARD]lock.json". +Use the --lock-write flag to regenerate the lockfile at "[WILDCARD]lock.json". diff --git a/tests/testdata/run/auto_discover_lockfile/main.out b/tests/testdata/run/auto_discover_lockfile/main.out deleted file mode 100644 index 28f4724e98798d..00000000000000 --- a/tests/testdata/run/auto_discover_lockfile/main.out +++ /dev/null @@ -1,5 +0,0 @@ -Download http://localhost:4545/subdir/mod2.ts -Download http://localhost:4545/subdir/print_hello.ts -error: The source code is invalid, as it does not match the expected hash in the lock file. - Specifier: http://localhost:4545/subdir/print_hello.ts - Lock file: [WILDCARD]auto_discover_lockfile[WILDCARD]deno.lock diff --git a/tests/testdata/run/lock_check_err.out b/tests/testdata/run/lock_check_err.out deleted file mode 100644 index e4cc7b81a18d81..00000000000000 --- a/tests/testdata/run/lock_check_err.out +++ /dev/null @@ -1,3 +0,0 @@ -[WILDCARD]The source code is invalid, as it does not match the expected hash in the lock file. - Specifier: http://127.0.0.1:4545/run/003_relative_import.ts - Lock file: run/lock_check_err.json diff --git a/tests/testdata/run/lock_check_err2.out b/tests/testdata/run/lock_check_err2.out deleted file mode 100644 index 065c7434b887a9..00000000000000 --- a/tests/testdata/run/lock_check_err2.out +++ /dev/null @@ -1,3 +0,0 @@ -[WILDCARD]The source code is invalid, as it does not match the expected hash in the lock file. - Specifier: http://localhost:4545/subdir/mt_text_ecmascript.j3.js - Lock file: run/lock_check_err2.json From b1793a3d128a55bf909b563c8354edc65a3fbcfe Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 27 May 2024 19:24:29 -0400 Subject: [PATCH 06/17] Fix a bunch of failing tests. --- Cargo.lock | 166 ++---------------- Cargo.toml | 7 +- cli/Cargo.toml | 10 +- cli/args/lockfile.rs | 1 - cli/args/mod.rs | 1 - cli/cache/mod.rs | 2 +- cli/graph_util.rs | 103 ++++++----- cli/main.rs | 5 - cli/npm/managed/mod.rs | 2 +- cli/npm/managed/resolution.rs | 13 +- tests/integration/jsr_tests.rs | 34 ++-- tests/integration/npm_tests.rs | 18 +- tests/integration/run_tests.rs | 75 +------- .../__test__.jsonc | 5 + .../lock_file_integrity_failure}/lock.json | 0 .../npm/lock_file_integrity_failure}/main.js | 0 .../npm/lock_file_integrity_failure}/main.out | 0 .../config_file_lock_boolean/__test__.jsonc | 13 ++ .../run/config_file_lock_boolean/deno.lock | 0 .../run/config_file_lock_boolean/false.json | 0 .../config_file_lock_boolean/false.main.out | 0 .../run/config_file_lock_boolean/main.ts | 0 .../run/config_file_lock_boolean/true.json | 0 .../config_file_lock_boolean/true.main.out | 11 ++ .../019_media_types.ts.out | 1 + .../run/config_file_lock_path/__test__.jsonc | 13 ++ .../config_file_lock_path.json | 0 .../config_file_lock_path.out | 0 .../lock_check_err2.json | 10 ++ .../config_file_lock_path/lock_check_err2.out | 11 ++ .../config_file_lock_path/lock_check_ok2.json | 13 ++ .../run/lock_dynamic_imports/__test__.jsonc | 5 + .../lock_dynamic_imports.json | 0 .../lock_dynamic_imports.out | 12 ++ .../run/lock_v2_check_err/__test__.jsonc | 5 + .../lock_v2_check_err}/lock_v2_check_err.json | 0 .../lock_v2_check_err/lock_v2_check_err.out | 11 ++ .../run/lock_v2_check_err2/__test__.jsonc | 5 + .../lock_v2_check_err2.json | 0 .../lock_v2_check_err2/lock_v2_check_err2.out | 11 ++ .../lock_v2_dynamic_imports/__test__.jsonc | 5 + .../lock_v2_dynamic_imports.json | 0 .../lock_v2_dynamic_imports.out | 12 ++ tests/testdata/fmt/invalid_data.out | 6 +- .../config_file_lock_boolean/true.main.out | 3 - tests/testdata/run/lock_check_err2.json | 13 ++ tests/testdata/run/lock_dynamic_imports.out | 4 - tests/testdata/run/lock_v2_check_err.out | 3 - tests/testdata/run/lock_v2_check_err2.out | 3 - .../testdata/run/lock_v2_dynamic_imports.out | 4 - tests/util/server/src/builders.rs | 51 +++++- 51 files changed, 310 insertions(+), 357 deletions(-) create mode 100644 tests/specs/npm/lock_file_integrity_failure/__test__.jsonc rename tests/{testdata/npm/lock_file => specs/npm/lock_file_integrity_failure}/lock.json (100%) rename tests/{testdata/npm/lock_file => specs/npm/lock_file_integrity_failure}/main.js (100%) rename tests/{testdata/npm/lock_file => specs/npm/lock_file_integrity_failure}/main.out (100%) create mode 100644 tests/specs/run/config_file_lock_boolean/__test__.jsonc rename tests/{testdata => specs}/run/config_file_lock_boolean/deno.lock (100%) rename tests/{testdata => specs}/run/config_file_lock_boolean/false.json (100%) rename tests/{testdata => specs}/run/config_file_lock_boolean/false.main.out (100%) rename tests/{testdata => specs}/run/config_file_lock_boolean/main.ts (100%) rename tests/{testdata => specs}/run/config_file_lock_boolean/true.json (100%) create mode 100644 tests/specs/run/config_file_lock_boolean/true.main.out create mode 100644 tests/specs/run/config_file_lock_path/019_media_types.ts.out create mode 100644 tests/specs/run/config_file_lock_path/__test__.jsonc rename tests/{testdata/run => specs/run/config_file_lock_path}/config_file_lock_path.json (100%) rename tests/{testdata/run => specs/run/config_file_lock_path}/config_file_lock_path.out (100%) create mode 100644 tests/specs/run/config_file_lock_path/lock_check_err2.json create mode 100644 tests/specs/run/config_file_lock_path/lock_check_err2.out create mode 100644 tests/specs/run/config_file_lock_path/lock_check_ok2.json create mode 100644 tests/specs/run/lock_dynamic_imports/__test__.jsonc rename tests/{testdata/run => specs/run/lock_dynamic_imports}/lock_dynamic_imports.json (100%) create mode 100644 tests/specs/run/lock_dynamic_imports/lock_dynamic_imports.out create mode 100644 tests/specs/run/lock_v2_check_err/__test__.jsonc rename tests/{testdata/run => specs/run/lock_v2_check_err}/lock_v2_check_err.json (100%) create mode 100644 tests/specs/run/lock_v2_check_err/lock_v2_check_err.out create mode 100644 tests/specs/run/lock_v2_check_err2/__test__.jsonc rename tests/{testdata/run => specs/run/lock_v2_check_err2}/lock_v2_check_err2.json (100%) create mode 100644 tests/specs/run/lock_v2_check_err2/lock_v2_check_err2.out create mode 100644 tests/specs/run/lock_v2_dynamic_imports/__test__.jsonc rename tests/{testdata/run => specs/run/lock_v2_dynamic_imports}/lock_v2_dynamic_imports.json (100%) create mode 100644 tests/specs/run/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out delete mode 100644 tests/testdata/run/config_file_lock_boolean/true.main.out create mode 100644 tests/testdata/run/lock_check_err2.json delete mode 100644 tests/testdata/run/lock_dynamic_imports.out delete mode 100644 tests/testdata/run/lock_v2_check_err.out delete mode 100644 tests/testdata/run/lock_v2_check_err2.out delete mode 100644 tests/testdata/run/lock_v2_dynamic_imports.out diff --git a/Cargo.lock b/Cargo.lock index 18dee6460d3151..ab4b8652e004c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -150,12 +150,6 @@ dependencies = [ "libc", ] -[[package]] -name = "anes" -version = "0.1.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b46cbb362ab8752921c97e041f5e366ee6297bd428a31275b9fcf1e380f7299" - [[package]] name = "anstream" version = "0.6.13" @@ -595,12 +589,6 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1bf2a5fb3207c12b5d208ebc145f967fea5cac41a021c37417ccc31ba40f39ee" -[[package]] -name = "cast" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" - [[package]] name = "cbc" version = "0.1.2" @@ -642,33 +630,6 @@ dependencies = [ "serde", ] -[[package]] -name = "ciborium" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42e69ffd6f0917f5c029256a24d0161db17cea3997d185db0d35926308770f0e" -dependencies = [ - "ciborium-io", - "ciborium-ll", - "serde", -] - -[[package]] -name = "ciborium-io" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05afea1e0a06c9be33d539b876f1ce3692f4afea2cb41f740e7743225ed1c757" - -[[package]] -name = "ciborium-ll" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57663b653d948a338bfb3eeba9bb2fd5fcfaecb9e199e87e1eda4d9e8b240fd9" -dependencies = [ - "ciborium-io", - "half", -] - [[package]] name = "cipher" version = "0.4.4" @@ -927,42 +888,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "criterion" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2b12d017a929603d80db1831cd3a24082f8137ce19c69e6447f54f5fc8d692f" -dependencies = [ - "anes", - "cast", - "ciborium", - "clap", - "criterion-plot", - "is-terminal", - "itertools", - "num-traits", - "once_cell", - "oorandom", - "plotters", - "rayon", - "regex", - "serde", - "serde_derive", - "serde_json", - "tinytemplate", - "walkdir", -] - -[[package]] -name = "criterion-plot" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b50826342786a51a89e2da3a28f1c32b06e387201bc2d19791f622c673706b1" -dependencies = [ - "cast", - "itertools", -] - [[package]] name = "crossbeam-channel" version = "0.5.12" @@ -1006,12 +931,6 @@ version = "0.8.19" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - [[package]] name = "crypto-bigint" version = "0.5.5" @@ -1466,7 +1385,9 @@ dependencies = [ [[package]] name = "deno_doc" -version = "0.136.0" +version = "0.137.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57f13d6254b2e05b014e8464647025fa28ef2f385c9c102744a27bd788eb3ebe" dependencies = [ "ammonia", "anyhow", @@ -1489,7 +1410,9 @@ dependencies = [ [[package]] name = "deno_emit" -version = "0.40.3" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe4b6c67f21a73901e962e92d51065f3c1bb42d2195bca8c2fef9f1808c4c2d" dependencies = [ "anyhow", "base64 0.21.7", @@ -1555,7 +1478,9 @@ dependencies = [ [[package]] name = "deno_graph" -version = "0.76.0" +version = "0.77.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e94a8739bb6087061f8419e4c1719459a144ef477ab649dca597a0603290ec82" dependencies = [ "anyhow", "async-trait", @@ -1680,11 +1605,12 @@ dependencies = [ [[package]] name = "deno_lockfile" -version = "0.19.0" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23120f905aec2deed858820113e089551025b74e261c5c404812cd8e61421379" dependencies = [ "serde", "serde_json", - "sha2", "thiserror", ] @@ -1807,9 +1733,9 @@ dependencies = [ [[package]] name = "deno_npm" -version = "0.20.2" +version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab92fbe02da596534ae84e2efca2f7dc5e26ca5fc972bf17701f0899784c2a8f" +checksum = "b99fac4a31098e2466f97576b53a9860d8e7ad1df2792a22d5b3209ca3bd2924" dependencies = [ "anyhow", "async-trait", @@ -1974,9 +1900,9 @@ dependencies = [ [[package]] name = "deno_unsync" version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7557a5e9278b9a5cc8056dc37062ea4344770bda4eeb5973c7cbb7ebf636b9a4" dependencies = [ - "criterion", - "futures-core", "tokio", ] @@ -2612,7 +2538,7 @@ dependencies = [ [[package]] name = "eszip" -version = "0.69.0" +version = "0.70.0" dependencies = [ "anyhow", "base64 0.21.7", @@ -3175,16 +3101,6 @@ dependencies = [ "tracing", ] -[[package]] -name = "half" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" -dependencies = [ - "cfg-if", - "crunchy", -] - [[package]] name = "halfbrown" version = "0.2.5" @@ -4481,12 +4397,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "oorandom" -version = "11.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" - [[package]] name = "opaque-debug" version = "0.3.1" @@ -4908,34 +4818,6 @@ version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" -[[package]] -name = "plotters" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a15b6eccb8484002195a3e44fe65a4ce8e93a625797a063735536fd59cb01cf3" -dependencies = [ - "num-traits", - "plotters-backend", - "plotters-svg", - "wasm-bindgen", - "web-sys", -] - -[[package]] -name = "plotters-backend" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "414cec62c6634ae900ea1c56128dfe87cf63e7caece0852ec76aba307cebadb7" - -[[package]] -name = "plotters-svg" -version = "0.3.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81b30686a7d9c3e010b84284bdd26a29f2138574f52f5eb6f794fc0ad924e705" -dependencies = [ - "plotters-backend", -] - [[package]] name = "png" version = "0.17.13" @@ -6891,16 +6773,6 @@ dependencies = [ "time-core", ] -[[package]] -name = "tinytemplate" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" -dependencies = [ - "serde", - "serde_json", -] - [[package]] name = "tinyvec" version = "1.6.0" @@ -7641,7 +7513,7 @@ dependencies = [ "log", "naga", "once_cell", - "parking_lot 0.12.1", + "parking_lot 0.11.2", "profiling", "raw-window-handle", "ron", @@ -7683,7 +7555,7 @@ dependencies = [ "ndk-sys", "objc", "once_cell", - "parking_lot 0.12.1", + "parking_lot 0.11.2", "profiling", "range-alloc", "raw-window-handle", diff --git a/Cargo.toml b/Cargo.toml index de8a9a7d275c39..7dd495cddfa0f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,7 +47,7 @@ deno_ast = { version = "=0.38.2", features = ["transpiling"] } deno_core = { version = "0.283.0" } deno_bench_util = { version = "0.147.0", path = "./bench_util" } -deno_lockfile = "0.19.0" +deno_lockfile = "0.20.0" deno_media_type = { version = "0.1.4", features = ["module_specifier"] } deno_permissions = { version = "0.13.0", path = "./runtime/permissions" } deno_runtime = { version = "0.161.0", path = "./runtime" } @@ -371,9 +371,4 @@ opt-level = 3 opt-level = 3 [patch.crates-io] -deno_doc = { path = "../deno_doc" } -deno_graph = { path = "../deno_graph" } eszip = { path = "../eszip" } -deno_emit = { path = "../deno_emit/rs-lib" } -deno_unsync = { path = "../deno_unsync" } -deno_lockfile = { path = "../deno_lockfile" } diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 2a1b9da50f3405..788bb0b9ca4a1a 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -67,17 +67,17 @@ deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "proposa deno_cache_dir = { workspace = true } deno_config = "=0.16.3" deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] } -deno_doc = { version = "=0.136.0", features = ["html", "syntect"] } -deno_emit = "=0.40.3" -deno_graph = { version = "=0.76.0", features = ["tokio_executor"] } +deno_doc = { version = "=0.137.0", features = ["html", "syntect"] } +deno_emit = "=0.41.0" +deno_graph = { version = "=0.77.0", features = ["tokio_executor"] } deno_lint = { version = "=0.58.4", features = ["docs"] } deno_lockfile.workspace = true -deno_npm = "=0.20.2" +deno_npm = "=0.21.0" deno_runtime = { workspace = true, features = ["include_js_files_for_snapshotting"] } deno_semver = "=0.5.4" deno_task_shell = "=0.16.1" deno_terminal.workspace = true -eszip = "=0.69.0" +eszip = "=0.70.0" napi_sym.workspace = true async-trait.workspace = true diff --git a/cli/args/lockfile.rs b/cli/args/lockfile.rs index d5ab14432d7492..c92a553d846c15 100644 --- a/cli/args/lockfile.rs +++ b/cli/args/lockfile.rs @@ -13,7 +13,6 @@ use super::InstallFlags; use super::InstallKind; pub use deno_lockfile::Lockfile; -pub use deno_lockfile::LockfileError; pub fn discover( flags: &Flags, diff --git a/cli/args/mod.rs b/cli/args/mod.rs index bc384a132bb459..ee82f58cb9c636 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -35,7 +35,6 @@ pub use deno_config::TsTypeLib; pub use deno_config::WorkspaceConfig; pub use flags::*; pub use lockfile::Lockfile; -pub use lockfile::LockfileError; pub use package_json::PackageJsonDepsProvider; use deno_ast::ModuleSpecifier; diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index cee93bac554c45..bb18b1a1325fc0 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -228,7 +228,7 @@ impl Loader for FetchCacher { LoaderCacheSetting::Reload => { if matches!(file_fetcher.cache_setting(), CacheSetting::Only) { return Err(deno_core::anyhow::anyhow!( - "Failed to resolve version constraint. Try running again without --cached-only" + "Could not resolve version constraint using only cached data. Try running again without --cached-only" )); } Some(CacheSetting::ReloadAll) diff --git a/cli/graph_util.rs b/cli/graph_util.rs index e2c23aa01b04d9..8af9f6eb673e3e 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -108,13 +108,13 @@ pub fn graph_valid( let err = format!( concat!( "Integrity check failed in package. The package may have been tampered with.\n\n", - "Specifier: {}\n", - "Actual: {}\n", - "Expected: {}\n\n", - "If you modified your global cache, run again with the --reload ", - "flag to restore its state. If you want to modify dependencies ", - "locally run again with the --vendor flag or specify \"vendor\": true` ", - "in a deno.json then modify the contents of the `vendor` folder." + " Specifier: {}\n", + " Actual: {}\n", + " Expected: {}\n\n", + "If you modified your global cache, run again with the --reload flag to restore ", + "its state. If you want to modify dependencies locally run again with the ", + "--vendor flag or specify `\"vendor\": true` in a deno.json then modify the contents ", + "of the vendor/ folder." ), specifier, checksum_err.actual, @@ -453,39 +453,61 @@ impl ModuleGraphBuilder { struct LockfileLocker(Arc>); impl deno_graph::source::Locker for LockfileLocker { - fn get_checksum( + fn get_remote_checksum( &self, specifier: &deno_ast::ModuleSpecifier, ) -> Option { self .0 .lock() - .content - .remote + .remote() .get(specifier.as_str()) .map(|s| LoaderChecksum::new(s.clone())) } - fn has_checksum(&self, specifier: &deno_ast::ModuleSpecifier) -> bool { + fn has_remote_checksum( + &self, + specifier: &deno_ast::ModuleSpecifier, + ) -> bool { + self.0.lock().remote().contains_key(specifier.as_str()) + } + + fn set_remote_checksum( + &mut self, + specifier: &deno_ast::ModuleSpecifier, + checksum: LoaderChecksum, + ) { + self + .0 + .lock() + .insert_remote(specifier.to_string(), checksum.into_string()) + } + + fn get_pkg_manifest_checksum( + &self, + package_nv: &PackageNv, + ) -> Option { self .0 .lock() .content - .remote - .contains_key(specifier.as_str()) + .packages + .jsr + .get(&package_nv.to_string()) + .map(|s| LoaderChecksum::new(s.integrity.clone())) } - fn set_checksum( + fn set_pkg_manifest_checksum( &mut self, - specifier: &deno_ast::ModuleSpecifier, + package_nv: &PackageNv, checksum: LoaderChecksum, ) { + // a value would only exist in here if two workers raced + // to insert the same package manifest checksum self .0 .lock() - .content - .remote - .insert(specifier.as_str().to_string(), checksum.into_string()); + .insert_package(package_nv.to_string(), checksum.into_string()); } } @@ -576,27 +598,14 @@ impl ModuleGraphBuilder { } } } - for (nv, value) in &lockfile.content.packages.jsr { - if let Ok(nv) = PackageNv::from_str(nv) { - graph - .packages - .add_manifest_checksum(nv, value.integrity.clone()) - .map_err(|err| deno_lockfile::IntegrityCheckFailedError { - package_display_id: format!("jsr:{}", err.nv), - actual: err.actual, - expected: err.expected, - filename: lockfile.filename.display().to_string(), - })?; - } - } } } - // todo: handle jsr package manifest checksums let initial_redirects_len = graph.redirects.len(); - let initial_packages_len = graph.packages.packages_len(); + let initial_package_deps_len = graph.packages.package_deps_sum(); let initial_package_mappings_len = graph.packages.mappings().len(); let initial_npm_packages = graph.npm_packages.len(); + graph.build(roots, loader, options).await; if let Some(npm_resolver) = self.npm_resolver.as_managed() { @@ -612,15 +621,15 @@ impl ModuleGraphBuilder { } let has_redirects_changed = graph.redirects.len() != initial_redirects_len; - let has_jsr_packages_changed = - graph.packages.packages_len() != initial_packages_len; + let has_jsr_package_deps_changed = + graph.packages.package_deps_sum() != initial_package_deps_len; let has_jsr_package_mappings_changed = graph.packages.mappings().len() != initial_package_mappings_len; let has_npm_packages_changed = graph.npm_packages.len() != initial_npm_packages; if has_redirects_changed - || has_jsr_packages_changed + || has_jsr_package_deps_changed || has_jsr_package_mappings_changed || has_npm_packages_changed { @@ -645,27 +654,15 @@ impl ModuleGraphBuilder { } } // jsr packages - if has_jsr_packages_changed { - for (name, checksum, deps) in - graph.packages.packages_with_checksum_and_deps() - { - lockfile.insert_package( - name.to_string(), - checksum.clone(), - deps.map(|s| s.to_string()), - ); + if has_jsr_package_deps_changed { + for (name, deps) in graph.packages.packages_with_deps() { + lockfile + .add_package_deps(&name.to_string(), deps.map(|s| s.to_string())); } } // npm packages if has_npm_packages_changed { - // this verifies integrity so may possibly error, but that - // will never happen because integrity verification happens - // when loading the npm resolution snapshot - self - .npm_resolver - .as_managed() - .unwrap() - .lock(&mut lockfile)?; + self.npm_resolver.as_managed().unwrap().lock(&mut lockfile); } } } diff --git a/cli/main.rs b/cli/main.rs index a2d270d4018efd..da8f278f146d7c 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -282,11 +282,6 @@ fn exit_for_error(error: AnyError) -> ! { if let Some(e) = error.downcast_ref::() { error_string = format_js_error(e); - } else if let Some(args::LockfileError::IntegrityCheckFailed(e)) = - error.downcast_ref::() - { - error_string = e.to_string(); - error_code = 10; } else if let Some(SnapshotFromLockfileError::IntegrityCheckFailed(e)) = error.downcast_ref::() { diff --git a/cli/npm/managed/mod.rs b/cli/npm/managed/mod.rs index dbbc1c18c2e91e..582ee8893643fd 100644 --- a/cli/npm/managed/mod.rs +++ b/cli/npm/managed/mod.rs @@ -395,7 +395,7 @@ impl ManagedCliNpmResolver { .serialized_valid_snapshot_for_system(system_info) } - pub fn lock(&self, lockfile: &mut Lockfile) -> Result<(), AnyError> { + pub fn lock(&self, lockfile: &mut Lockfile) { self.resolution.lock(lockfile) } diff --git a/cli/npm/managed/resolution.rs b/cli/npm/managed/resolution.rs index 6c90528fc3447d..0ed1e1c84e9052 100644 --- a/cli/npm/managed/resolution.rs +++ b/cli/npm/managed/resolution.rs @@ -292,7 +292,7 @@ impl NpmResolution { .as_valid_serialized_for_system(system_info) } - pub fn lock(&self, lockfile: &mut Lockfile) -> Result<(), AnyError> { + pub fn lock(&self, lockfile: &mut Lockfile) { let snapshot = self.snapshot.read(); populate_lockfile_from_snapshot(lockfile, &snapshot) } @@ -345,7 +345,7 @@ async fn add_package_reqs_to_snapshot( if let Some(lockfile_mutex) = maybe_lockfile { let mut lockfile = lockfile_mutex.lock(); - populate_lockfile_from_snapshot(&mut lockfile, &snapshot)?; + populate_lockfile_from_snapshot(&mut lockfile, &snapshot); } Ok(snapshot) @@ -369,7 +369,7 @@ fn get_npm_pending_resolver( fn populate_lockfile_from_snapshot( lockfile: &mut Lockfile, snapshot: &NpmResolutionSnapshot, -) -> Result<(), AnyError> { +) { for (package_req, nv) in snapshot.package_reqs() { lockfile.insert_package_specifier( format!("npm:{}", package_req), @@ -384,13 +384,8 @@ fn populate_lockfile_from_snapshot( ); } for package in snapshot.all_packages_for_every_system() { - // todo(dsherret): there is no reason to verify the integrity here - // because we already did that when populating the snapshot from - // the lockfile - lockfile - .check_or_insert_npm_package(npm_package_to_lockfile_info(package))?; + lockfile.insert_npm_package(npm_package_to_lockfile_info(package)); } - Ok(()) } fn npm_package_to_lockfile_info( diff --git a/tests/integration/jsr_tests.rs b/tests/integration/jsr_tests.rs index ddff613584867b..9e33a62f261798 100644 --- a/tests/integration/jsr_tests.rs +++ b/tests/integration/jsr_tests.rs @@ -214,7 +214,7 @@ fn reload_info_not_found_cache_but_exists_remote() { .args("run --cached-only main.ts") .run(); output.assert_exit_code(1); - output.assert_matches_text("error: Failed to resolve version constraint. Try running again without --cached-only + output.assert_matches_text("error: JSR package manifest for '@denotest/add' failed to load. Could not resolve version constraint using only cached data. Try running again without --cached-only at file:///[WILDCARD]main.ts:1:21 "); @@ -347,33 +347,33 @@ console.log(add);"#, "Download http://127.0.0.1:4250/@denotest/bad-manifest-checksum/meta.json Download http://127.0.0.1:4250/@denotest/bad-manifest-checksum/1.0.0_meta.json Download http://127.0.0.1:4250/@denotest/bad-manifest-checksum/1.0.0/mod.ts -error: Integrity check failed. +error: Integrity check failed in package. The package may have been tampered with. -Actual: 9a30ac96b5d5c1b67eca69e1e2cf0798817d9578c8d7d904a81a67b983b35cba -Expected: bad-checksum - at file:///[WILDCARD]main.ts:1:21 + Specifier: http://127.0.0.1:4250/@denotest/bad-manifest-checksum/1.0.0/mod.ts + Actual: 9a30ac96b5d5c1b67eca69e1e2cf0798817d9578c8d7d904a81a67b983b35cba + Expected: bad-checksum + +If you modified your global cache, run again with the --reload flag to restore its state. If you want to modify dependencies locally run again with the --vendor flag or specify `\"vendor\": true` in a deno.json then modify the contents of the vendor/ folder. ", ) - .assert_exit_code(1); + .assert_exit_code(10); // test it properly checks the checksum when loading from the cache test_context .new_command() - .args("run main.ts") + .args("run main.ts") .run() .assert_matches_text( - // ideally the two error messages would be the same... this one comes from - // deno_cache and the one above comes from deno_graph. The thing is, in deno_cache - // (source of this error) it makes sense to include the url in the error message - // because it's not always used in the context of deno_graph - "error: Integrity check failed for http://127.0.0.1:4250/@denotest/bad-manifest-checksum/1.0.0/mod.ts - -Actual: 9a30ac96b5d5c1b67eca69e1e2cf0798817d9578c8d7d904a81a67b983b35cba -Expected: bad-checksum - at file:///[WILDCARD]main.ts:1:21 + "error: Integrity check failed in package. The package may have been tampered with. + + Specifier: http://127.0.0.1:4250/@denotest/bad-manifest-checksum/1.0.0/mod.ts + Actual: 9a30ac96b5d5c1b67eca69e1e2cf0798817d9578c8d7d904a81a67b983b35cba + Expected: bad-checksum + +If you modified your global cache, run again with the --reload flag to restore its state. If you want to modify dependencies locally run again with the --vendor flag or specify `\"vendor\": true` in a deno.json then modify the contents of the vendor/ folder. ", ) - .assert_exit_code(1); + .assert_exit_code(10); } fn get_lockfile_pkg_integrity(lockfile: &Lockfile, pkg_name: &str) -> String { diff --git a/tests/integration/npm_tests.rs b/tests/integration/npm_tests.rs index 9b9d2ea57de8fd..923d151be68ef4 100644 --- a/tests/integration/npm_tests.rs +++ b/tests/integration/npm_tests.rs @@ -214,19 +214,11 @@ itest!(cached_only { }); itest!(import_map { - args: "run --allow-read --allow-env --import-map npm/import_map/import_map.json npm/import_map/main.js", - output: "npm/import_map/main.out", - envs: env_vars_for_npm_tests(), - http_server: true, - }); - -itest!(lock_file_integrity_failure { - args: "run --allow-read --allow-env --lock npm/lock_file/lock.json npm/lock_file/main.js", - output: "npm/lock_file/main.out", - envs: env_vars_for_npm_tests(), - http_server: true, - exit_code: 10, - }); + args: "run --allow-read --allow-env --import-map npm/import_map/import_map.json npm/import_map/main.js", + output: "npm/import_map/main.out", + envs: env_vars_for_npm_tests(), + http_server: true, +}); itest!(sub_paths { args: "run -A --quiet npm/sub_paths/main.jsx", diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs index 5234799915d673..91370a87c1a103 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -821,26 +821,6 @@ itest!(lock_check_ok2 { http_server: true, }); -itest!(lock_dynamic_imports { - args: "run --lock=run/lock_dynamic_imports.json --allow-read --allow-net http://127.0.0.1:4545/run/013_dynamic_import.ts", - output: "run/lock_dynamic_imports.out", - exit_code: 10, - http_server: true, -}); - -itest!(config_file_lock_path { - args: "run --config=run/config_file_lock_path.json run/019_media_types.ts", - output: "run/config_file_lock_path.out", - exit_code: 10, - http_server: true, -}); - -itest!(lock_flag_overrides_config_file_lock_path { - args: "run --lock=run/lock_check_ok2.json --config=run/config_file_lock_path.json run/019_media_types.ts", - output: "run/019_media_types.ts.out", - http_server: true, -}); - itest!(lock_v2_check_ok { args: "run --quiet --lock=run/lock_v2_check_ok.json http://127.0.0.1:4545/run/003_relative_import.ts", @@ -854,33 +834,6 @@ itest!(lock_v2_check_ok2 { http_server: true, }); -itest!(lock_v2_dynamic_imports { - args: "run --lock=run/lock_v2_dynamic_imports.json --allow-read --allow-net http://127.0.0.1:4545/run/013_dynamic_import.ts", - output: "run/lock_v2_dynamic_imports.out", - exit_code: 10, - http_server: true, -}); - -itest!(lock_v2_check_err { - args: "run --lock=run/lock_v2_check_err.json http://127.0.0.1:4545/run/003_relative_import.ts", - output: "run/lock_v2_check_err.out", - exit_code: 10, - http_server: true, -}); - -itest!(lock_v2_check_err2 { - args: "run --lock=run/lock_v2_check_err2.json run/019_media_types.ts", - output: "run/lock_v2_check_err2.out", - exit_code: 10, - http_server: true, -}); - -itest!(lock_only_http_and_https { - args: "run --lock=run/lock_only_http_and_https/deno.lock run/lock_only_http_and_https/main.ts", - output: "run/lock_only_http_and_https/main.out", - http_server: true, -}); - #[test] fn lock_no_declaration_files() { let context = TestContextBuilder::new() @@ -4555,20 +4508,6 @@ itest!(no_lock_flag { exit_code: 0, }); -itest!(config_file_lock_false { - args: "run --config=run/config_file_lock_boolean/false.json run/config_file_lock_boolean/main.ts", - output: "run/config_file_lock_boolean/false.main.out", - http_server: true, - exit_code: 0, -}); - -itest!(config_file_lock_true { - args: "run --config=run/config_file_lock_boolean/true.json run/config_file_lock_boolean/main.ts", - output: "run/config_file_lock_boolean/true.main.out", - http_server: true, - exit_code: 10, -}); - itest!(permission_args { args: "run run/001_hello.js --allow-net", output: "run/permission_args.out", @@ -4791,21 +4730,17 @@ console.log(returnsHi());"#, .join("mod1.ts"); mod1_file.write("export function returnsHi() { return 'bye bye bye'; }"); - // won't match the lockfile now - deno_run_cmd - .run() - .assert_matches_text(r#"error: The source code is invalid, as it does not match the expected hash in the lock file. - Specifier: http://localhost:4545/subdir/mod1.ts - Lock file: [WILDCARD]deno.lock -"#) - .assert_exit_code(10); + // this is fine with a lockfile because users are supposed to be able + // to modify the vendor folder + deno_run_cmd.run().assert_matches_text("bye bye bye\n"); // try updating by deleting the lockfile let lockfile = temp_dir.path().join("deno.lock"); lockfile.remove_file(); cache_command.run(); - // now it should run + // should still run and the lockfile should be recreated + // (though with the checksum from the vendor folder) deno_run_cmd.run().assert_matches_text("bye bye bye\n"); assert!(lockfile.exists()); diff --git a/tests/specs/npm/lock_file_integrity_failure/__test__.jsonc b/tests/specs/npm/lock_file_integrity_failure/__test__.jsonc new file mode 100644 index 00000000000000..d2f1b06a2cd65c --- /dev/null +++ b/tests/specs/npm/lock_file_integrity_failure/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "run --allow-read --allow-env --lock lock.json main.js", + "output": "main.out", + "exitCode": 10 +} diff --git a/tests/testdata/npm/lock_file/lock.json b/tests/specs/npm/lock_file_integrity_failure/lock.json similarity index 100% rename from tests/testdata/npm/lock_file/lock.json rename to tests/specs/npm/lock_file_integrity_failure/lock.json diff --git a/tests/testdata/npm/lock_file/main.js b/tests/specs/npm/lock_file_integrity_failure/main.js similarity index 100% rename from tests/testdata/npm/lock_file/main.js rename to tests/specs/npm/lock_file_integrity_failure/main.js diff --git a/tests/testdata/npm/lock_file/main.out b/tests/specs/npm/lock_file_integrity_failure/main.out similarity index 100% rename from tests/testdata/npm/lock_file/main.out rename to tests/specs/npm/lock_file_integrity_failure/main.out diff --git a/tests/specs/run/config_file_lock_boolean/__test__.jsonc b/tests/specs/run/config_file_lock_boolean/__test__.jsonc new file mode 100644 index 00000000000000..65679a1c813205 --- /dev/null +++ b/tests/specs/run/config_file_lock_boolean/__test__.jsonc @@ -0,0 +1,13 @@ +{ + "tests": { + "true": { + "args": "run --config=true.json main.ts", + "output": "true.main.out", + "exitCode": 10 + }, + "false": { + "args": "run --config=false.json main.ts", + "output": "false.main.out" + } + } +} diff --git a/tests/testdata/run/config_file_lock_boolean/deno.lock b/tests/specs/run/config_file_lock_boolean/deno.lock similarity index 100% rename from tests/testdata/run/config_file_lock_boolean/deno.lock rename to tests/specs/run/config_file_lock_boolean/deno.lock diff --git a/tests/testdata/run/config_file_lock_boolean/false.json b/tests/specs/run/config_file_lock_boolean/false.json similarity index 100% rename from tests/testdata/run/config_file_lock_boolean/false.json rename to tests/specs/run/config_file_lock_boolean/false.json diff --git a/tests/testdata/run/config_file_lock_boolean/false.main.out b/tests/specs/run/config_file_lock_boolean/false.main.out similarity index 100% rename from tests/testdata/run/config_file_lock_boolean/false.main.out rename to tests/specs/run/config_file_lock_boolean/false.main.out diff --git a/tests/testdata/run/config_file_lock_boolean/main.ts b/tests/specs/run/config_file_lock_boolean/main.ts similarity index 100% rename from tests/testdata/run/config_file_lock_boolean/main.ts rename to tests/specs/run/config_file_lock_boolean/main.ts diff --git a/tests/testdata/run/config_file_lock_boolean/true.json b/tests/specs/run/config_file_lock_boolean/true.json similarity index 100% rename from tests/testdata/run/config_file_lock_boolean/true.json rename to tests/specs/run/config_file_lock_boolean/true.json diff --git a/tests/specs/run/config_file_lock_boolean/true.main.out b/tests/specs/run/config_file_lock_boolean/true.main.out new file mode 100644 index 00000000000000..11dfc0740882c0 --- /dev/null +++ b/tests/specs/run/config_file_lock_boolean/true.main.out @@ -0,0 +1,11 @@ +[WILDCARD]Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file. + + Specifier: http://localhost:4545/subdir/print_hello.ts + Actual: fa6692c8f9ff3fb107e773c3ece5274e9d08be282867a1e3ded1d9c00fcaa63c + Expected: foobar + +This could be caused by: + * the lock file may be corrupt + * the source itself may be corrupt + +Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/run/config_file_lock_path/019_media_types.ts.out b/tests/specs/run/config_file_lock_path/019_media_types.ts.out new file mode 100644 index 00000000000000..b3e94678c5197b --- /dev/null +++ b/tests/specs/run/config_file_lock_path/019_media_types.ts.out @@ -0,0 +1 @@ +[WILDCARD]success true true true true true true true true diff --git a/tests/specs/run/config_file_lock_path/__test__.jsonc b/tests/specs/run/config_file_lock_path/__test__.jsonc new file mode 100644 index 00000000000000..defb113b383a34 --- /dev/null +++ b/tests/specs/run/config_file_lock_path/__test__.jsonc @@ -0,0 +1,13 @@ +{ + "tests": { + "error_bad_checksum": { + "args": "run --config=config_file_lock_path.json http://localhost:4545/run/019_media_types.ts", + "output": "config_file_lock_path.out", + "exitCode": 10 + }, + "lock_flag_override": { + "args": "run --lock=run/lock_check_ok2.json --config=config_file_lock_path.json http://localhost:4545/run/019_media_types.ts", + "output": "019_media_types.ts.out" + } + } +} diff --git a/tests/testdata/run/config_file_lock_path.json b/tests/specs/run/config_file_lock_path/config_file_lock_path.json similarity index 100% rename from tests/testdata/run/config_file_lock_path.json rename to tests/specs/run/config_file_lock_path/config_file_lock_path.json diff --git a/tests/testdata/run/config_file_lock_path.out b/tests/specs/run/config_file_lock_path/config_file_lock_path.out similarity index 100% rename from tests/testdata/run/config_file_lock_path.out rename to tests/specs/run/config_file_lock_path/config_file_lock_path.out diff --git a/tests/specs/run/config_file_lock_path/lock_check_err2.json b/tests/specs/run/config_file_lock_path/lock_check_err2.json new file mode 100644 index 00000000000000..a59cbc9e3073dc --- /dev/null +++ b/tests/specs/run/config_file_lock_path/lock_check_err2.json @@ -0,0 +1,10 @@ +{ + "http://localhost:4545/subdir/mt_application_ecmascript.j2.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_application_x_javascript.j4.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_application_x_typescript.t4.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_ecmascript.j3.js": "bad", + "http://localhost:4545/subdir/mt_text_javascript.j1.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_typescript.t1.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_video_mp2t.t3.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_video_vdn.t2.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18" +} diff --git a/tests/specs/run/config_file_lock_path/lock_check_err2.out b/tests/specs/run/config_file_lock_path/lock_check_err2.out new file mode 100644 index 00000000000000..1383d945d05c6a --- /dev/null +++ b/tests/specs/run/config_file_lock_path/lock_check_err2.out @@ -0,0 +1,11 @@ +[WILDCARD]Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file. + + Specifier: http://localhost:4545/subdir/mt_text_ecmascript.j3.js + Actual: 3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18 + Expected: bad + +This could be caused by: + * the lock file may be corrupt + * the source itself may be corrupt + +Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/run/config_file_lock_path/lock_check_ok2.json b/tests/specs/run/config_file_lock_path/lock_check_ok2.json new file mode 100644 index 00000000000000..14d8b711711aef --- /dev/null +++ b/tests/specs/run/config_file_lock_path/lock_check_ok2.json @@ -0,0 +1,13 @@ +{ + "version": "3", + "remote": { + "http://localhost:4545/subdir/mt_application_ecmascript.j2.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_application_x_javascript.j4.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_application_x_typescript.t4.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_ecmascript.j3.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_javascript.j1.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_typescript.t1.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_video_mp2t.t3.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_video_vdn.t2.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18" + } +} diff --git a/tests/specs/run/lock_dynamic_imports/__test__.jsonc b/tests/specs/run/lock_dynamic_imports/__test__.jsonc new file mode 100644 index 00000000000000..54b993295901bb --- /dev/null +++ b/tests/specs/run/lock_dynamic_imports/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "run --lock=lock_dynamic_imports.json --allow-read --allow-net http://127.0.0.1:4545/run/013_dynamic_import.ts", + "output": "lock_dynamic_imports.out", + "exitCode": 10 +} diff --git a/tests/testdata/run/lock_dynamic_imports.json b/tests/specs/run/lock_dynamic_imports/lock_dynamic_imports.json similarity index 100% rename from tests/testdata/run/lock_dynamic_imports.json rename to tests/specs/run/lock_dynamic_imports/lock_dynamic_imports.json diff --git a/tests/specs/run/lock_dynamic_imports/lock_dynamic_imports.out b/tests/specs/run/lock_dynamic_imports/lock_dynamic_imports.out new file mode 100644 index 00000000000000..2b8bdfc96eaf4f --- /dev/null +++ b/tests/specs/run/lock_dynamic_imports/lock_dynamic_imports.out @@ -0,0 +1,12 @@ +[WILDCARD] +error: Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file. + + Specifier: http://127.0.0.1:4545/subdir/subdir2/mod2.ts + Actual: 8b3b670d25d238dfa72df119140406b96766a00fee635f3606429fe065b18fd1 + Expected: bad + +This could be caused by: + * the lock file may be corrupt + * the source itself may be corrupt + +Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/run/lock_v2_check_err/__test__.jsonc b/tests/specs/run/lock_v2_check_err/__test__.jsonc new file mode 100644 index 00000000000000..b58fddeecc4501 --- /dev/null +++ b/tests/specs/run/lock_v2_check_err/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "run --lock=lock_v2_check_err.json http://127.0.0.1:4545/run/003_relative_import.ts", + "output": "lock_v2_check_err.out", + "exitCode": 10 +} diff --git a/tests/testdata/run/lock_v2_check_err.json b/tests/specs/run/lock_v2_check_err/lock_v2_check_err.json similarity index 100% rename from tests/testdata/run/lock_v2_check_err.json rename to tests/specs/run/lock_v2_check_err/lock_v2_check_err.json diff --git a/tests/specs/run/lock_v2_check_err/lock_v2_check_err.out b/tests/specs/run/lock_v2_check_err/lock_v2_check_err.out new file mode 100644 index 00000000000000..25d22490da3710 --- /dev/null +++ b/tests/specs/run/lock_v2_check_err/lock_v2_check_err.out @@ -0,0 +1,11 @@ +[WILDCARD]Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file. + + Specifier: http://127.0.0.1:4545/run/003_relative_import.ts + Actual: a1572e8fd2c2712b33f04aed2561505b5feb2c8696f1f2cded3de7127931b97e + Expected: bad + +This could be caused by: + * the lock file may be corrupt + * the source itself may be corrupt + +Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/run/lock_v2_check_err2/__test__.jsonc b/tests/specs/run/lock_v2_check_err2/__test__.jsonc new file mode 100644 index 00000000000000..bb02b41e2553ca --- /dev/null +++ b/tests/specs/run/lock_v2_check_err2/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "run --lock=lock_v2_check_err2.json http://localhost:4545/run/019_media_types.ts", + "output": "lock_v2_check_err2.out", + "exitCode": 10 +} diff --git a/tests/testdata/run/lock_v2_check_err2.json b/tests/specs/run/lock_v2_check_err2/lock_v2_check_err2.json similarity index 100% rename from tests/testdata/run/lock_v2_check_err2.json rename to tests/specs/run/lock_v2_check_err2/lock_v2_check_err2.json diff --git a/tests/specs/run/lock_v2_check_err2/lock_v2_check_err2.out b/tests/specs/run/lock_v2_check_err2/lock_v2_check_err2.out new file mode 100644 index 00000000000000..1383d945d05c6a --- /dev/null +++ b/tests/specs/run/lock_v2_check_err2/lock_v2_check_err2.out @@ -0,0 +1,11 @@ +[WILDCARD]Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file. + + Specifier: http://localhost:4545/subdir/mt_text_ecmascript.j3.js + Actual: 3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18 + Expected: bad + +This could be caused by: + * the lock file may be corrupt + * the source itself may be corrupt + +Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/run/lock_v2_dynamic_imports/__test__.jsonc b/tests/specs/run/lock_v2_dynamic_imports/__test__.jsonc new file mode 100644 index 00000000000000..8d8913431bd8bd --- /dev/null +++ b/tests/specs/run/lock_v2_dynamic_imports/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "run --lock=lock_v2_dynamic_imports.json --allow-read --allow-net http://127.0.0.1:4545/run/013_dynamic_import.ts", + "output": "lock_v2_dynamic_imports.out", + "exitCode": 10 +} diff --git a/tests/testdata/run/lock_v2_dynamic_imports.json b/tests/specs/run/lock_v2_dynamic_imports/lock_v2_dynamic_imports.json similarity index 100% rename from tests/testdata/run/lock_v2_dynamic_imports.json rename to tests/specs/run/lock_v2_dynamic_imports/lock_v2_dynamic_imports.json diff --git a/tests/specs/run/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out b/tests/specs/run/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out new file mode 100644 index 00000000000000..2b8bdfc96eaf4f --- /dev/null +++ b/tests/specs/run/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out @@ -0,0 +1,12 @@ +[WILDCARD] +error: Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file. + + Specifier: http://127.0.0.1:4545/subdir/subdir2/mod2.ts + Actual: 8b3b670d25d238dfa72df119140406b96766a00fee635f3606429fe065b18fd1 + Expected: bad + +This could be caused by: + * the lock file may be corrupt + * the source itself may be corrupt + +Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/testdata/fmt/invalid_data.out b/tests/testdata/fmt/invalid_data.out index dee00fcc5e696c..d0869e9ee82ce0 100644 --- a/tests/testdata/fmt/invalid_data.out +++ b/tests/testdata/fmt/invalid_data.out @@ -1,4 +1,4 @@ -error: [WILDCARD] is not a valid UTF-8 file +Error checking: [WILDCARD] Line 1, column 1: Unexpected token -Caused by: - invalid data +[WILDCARD] +error: Found 1 not formatted file in 1 file diff --git a/tests/testdata/run/config_file_lock_boolean/true.main.out b/tests/testdata/run/config_file_lock_boolean/true.main.out deleted file mode 100644 index 313c0eb0cc38f3..00000000000000 --- a/tests/testdata/run/config_file_lock_boolean/true.main.out +++ /dev/null @@ -1,3 +0,0 @@ -[WILDCARD]The source code is invalid, as it does not match the expected hash in the lock file. - Specifier: http://localhost:4545/subdir/print_hello.ts - Lock file: [WILDCARD]deno.lock diff --git a/tests/testdata/run/lock_check_err2.json b/tests/testdata/run/lock_check_err2.json new file mode 100644 index 00000000000000..14d8b711711aef --- /dev/null +++ b/tests/testdata/run/lock_check_err2.json @@ -0,0 +1,13 @@ +{ + "version": "3", + "remote": { + "http://localhost:4545/subdir/mt_application_ecmascript.j2.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_application_x_javascript.j4.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_application_x_typescript.t4.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_ecmascript.j3.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_javascript.j1.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_typescript.t1.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_video_mp2t.t3.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_video_vdn.t2.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18" + } +} diff --git a/tests/testdata/run/lock_dynamic_imports.out b/tests/testdata/run/lock_dynamic_imports.out deleted file mode 100644 index acc65c8e6b5d12..00000000000000 --- a/tests/testdata/run/lock_dynamic_imports.out +++ /dev/null @@ -1,4 +0,0 @@ -[WILDCARD] -error: The source code is invalid, as it does not match the expected hash in the lock file. - Specifier: http://127.0.0.1:4545/subdir/subdir2/mod2.ts - Lock file: run/lock_dynamic_imports.json diff --git a/tests/testdata/run/lock_v2_check_err.out b/tests/testdata/run/lock_v2_check_err.out deleted file mode 100644 index 28ad01cf445575..00000000000000 --- a/tests/testdata/run/lock_v2_check_err.out +++ /dev/null @@ -1,3 +0,0 @@ -[WILDCARD]The source code is invalid, as it does not match the expected hash in the lock file. - Specifier: http://127.0.0.1:4545/run/003_relative_import.ts - Lock file: run/lock_v2_check_err.json diff --git a/tests/testdata/run/lock_v2_check_err2.out b/tests/testdata/run/lock_v2_check_err2.out deleted file mode 100644 index 3d82cba273f096..00000000000000 --- a/tests/testdata/run/lock_v2_check_err2.out +++ /dev/null @@ -1,3 +0,0 @@ -[WILDCARD]The source code is invalid, as it does not match the expected hash in the lock file. - Specifier: http://localhost:4545/subdir/mt_text_ecmascript.j3.js - Lock file: run/lock_v2_check_err2.json diff --git a/tests/testdata/run/lock_v2_dynamic_imports.out b/tests/testdata/run/lock_v2_dynamic_imports.out deleted file mode 100644 index 36c2c9b5ccce09..00000000000000 --- a/tests/testdata/run/lock_v2_dynamic_imports.out +++ /dev/null @@ -1,4 +0,0 @@ -[WILDCARD] -error: The source code is invalid, as it does not match the expected hash in the lock file. - Specifier: http://127.0.0.1:4545/subdir/subdir2/mod2.ts - Lock file: run/lock_v2_dynamic_imports.json diff --git a/tests/util/server/src/builders.rs b/tests/util/server/src/builders.rs index bf5de64dc46a5d..bd2d02f3fe06ea 100644 --- a/tests/util/server/src/builders.rs +++ b/tests/util/server/src/builders.rs @@ -387,6 +387,7 @@ pub struct TestCommandBuilder { args_text: String, args_vec: Vec, split_output: bool, + debug_output: bool, } impl TestCommandBuilder { @@ -406,6 +407,7 @@ impl TestCommandBuilder { command_name: "deno".to_string(), args_text: "".to_string(), args_vec: Default::default(), + debug_output: false, } } @@ -482,6 +484,16 @@ impl TestCommandBuilder { self } + /// Set this to enable streaming the output of the command to stderr. + /// + /// Not deprecated, this is just here so you don't accidentally + /// commit code with this enabled. + #[deprecated] + pub fn debug_output(mut self) -> Self { + self.debug_output = true; + self + } + pub fn stdin>(mut self, cfg: T) -> Self { self.stdin = Some(StdioContainer::new(cfg.into())); self @@ -606,10 +618,27 @@ impl TestCommandBuilder { } pub fn run(&self) -> TestCommandOutput { - fn read_pipe_to_string(mut pipe: os_pipe::PipeReader) -> String { - let mut output = String::new(); - pipe.read_to_string(&mut output).unwrap(); - output + fn read_pipe_to_string( + mut pipe: os_pipe::PipeReader, + output_to_stderr: bool, + ) -> String { + if output_to_stderr { + let mut buffer = vec![0; 512]; + let mut final_data = Vec::new(); + loop { + let size = pipe.read(&mut buffer).unwrap(); + if size == 0 { + break; + } + final_data.extend(&buffer[..size]); + std::io::stderr().write_all(&buffer[..size]).unwrap(); + } + String::from_utf8_lossy(&final_data).to_string() + } else { + let mut output = String::new(); + pipe.read_to_string(&mut output).unwrap(); + output + } } fn sanitize_output(text: String, args: &[OsString]) -> String { @@ -633,11 +662,16 @@ impl TestCommandBuilder { let (stderr_reader, stderr_writer) = pipe().unwrap(); command.stdout(stdout_writer); command.stderr(stderr_writer); + let debug_output = self.debug_output; ( None, Some(( - std::thread::spawn(move || read_pipe_to_string(stdout_reader)), - std::thread::spawn(move || read_pipe_to_string(stderr_reader)), + std::thread::spawn(move || { + read_pipe_to_string(stdout_reader, debug_output) + }), + std::thread::spawn(move || { + read_pipe_to_string(stderr_reader, debug_output) + }), )), ) } else { @@ -660,8 +694,9 @@ impl TestCommandBuilder { // and dropping it closes them. drop(command); - let combined = combined_reader - .map(|pipe| sanitize_output(read_pipe_to_string(pipe), &args)); + let combined = combined_reader.map(|pipe| { + sanitize_output(read_pipe_to_string(pipe, self.debug_output), &args) + }); let status = process.wait().unwrap(); let std_out_err = std_out_err_handle.map(|(stdout, stderr)| { From 82f03c5eaaeb991992efbf3634b9c1f800d8c099 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 27 May 2024 19:42:51 -0400 Subject: [PATCH 07/17] Update deno_lockfile --- Cargo.lock | 8 +++++--- Cargo.toml | 3 --- cli/Cargo.toml | 2 +- cli/args/lockfile.rs | 22 +++++++++++++++++++++- cli/args/mod.rs | 1 + cli/lsp/config.rs | 9 ++++++++- cli/lsp/language_server.rs | 5 +++-- cli/module_loader.rs | 6 +++--- cli/npm/managed/resolution.rs | 1 - cli/tools/info.rs | 5 ++--- cli/tools/installer.rs | 3 ++- cli/worker.rs | 7 ++----- 12 files changed, 48 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ab4b8652e004c4..41679e23908217 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2538,7 +2538,9 @@ dependencies = [ [[package]] name = "eszip" -version = "0.70.0" +version = "0.70.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5f9947a8dd5ba292461c84a5bf142497e2840c4165994c5c3b3ae4954d38fef" dependencies = [ "anyhow", "base64 0.21.7", @@ -7513,7 +7515,7 @@ dependencies = [ "log", "naga", "once_cell", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "profiling", "raw-window-handle", "ron", @@ -7555,7 +7557,7 @@ dependencies = [ "ndk-sys", "objc", "once_cell", - "parking_lot 0.11.2", + "parking_lot 0.12.1", "profiling", "range-alloc", "raw-window-handle", diff --git a/Cargo.toml b/Cargo.toml index 7dd495cddfa0f4..4e6224fe03a094 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -369,6 +369,3 @@ opt-level = 3 opt-level = 3 [profile.release.package.base64-simd] opt-level = 3 - -[patch.crates-io] -eszip = { path = "../eszip" } diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 788bb0b9ca4a1a..bdb1bbfb18307f 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -77,7 +77,7 @@ deno_runtime = { workspace = true, features = ["include_js_files_for_snapshottin deno_semver = "=0.5.4" deno_task_shell = "=0.16.1" deno_terminal.workspace = true -eszip = "=0.70.0" +eszip = "=0.70.1" napi_sym.workspace = true async-trait.workspace = true diff --git a/cli/args/lockfile.rs b/cli/args/lockfile.rs index c92a553d846c15..45113dd967e660 100644 --- a/cli/args/lockfile.rs +++ b/cli/args/lockfile.rs @@ -2,10 +2,13 @@ use std::path::PathBuf; +use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_runtime::deno_node::PackageJson; use crate::args::ConfigFile; +use crate::cache; +use crate::util::fs::atomic_write_file; use crate::Flags; use super::DenoSubcommand; @@ -53,6 +56,23 @@ pub fn discover( }, }; - let lockfile = Lockfile::new(filename, flags.lock_write)?; + let lockfile = if flags.lock_write { + Lockfile::new_empty(filename, true) + } else { + let file_text = std::fs::read_to_string(&filename).with_context(|| { + format!("Failed reading lockfile '{}'", filename.display()) + })?; + Lockfile::with_lockfile_content(filename, &file_text, false)? + }; Ok(Some(lockfile)) } + +pub fn write_lockfile_if_has_changes( + lockfile: &Lockfile, +) -> Result<(), AnyError> { + let Some(bytes) = lockfile.resolve_write_bytes() else { + return Ok(()); // nothing to do + }; + atomic_write_file(&lockfile.filename, bytes, cache::CACHE_PERM) + .context("Failed writing lockfile.") +} diff --git a/cli/args/mod.rs b/cli/args/mod.rs index ee82f58cb9c636..29d8d60ad30856 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -34,6 +34,7 @@ pub use deno_config::TsConfigType; pub use deno_config::TsTypeLib; pub use deno_config::WorkspaceConfig; pub use flags::*; +pub use lockfile::write_lockfile_if_has_changes; pub use lockfile::Lockfile; pub use package_json::PackageJsonDepsProvider; diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index 89ecb84d8593d6..558987dce5dee2 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -15,6 +15,7 @@ use deno_ast::MediaType; use deno_config::FmtOptionsConfig; use deno_config::TsConfig; use deno_core::anyhow::anyhow; +use deno_core::error::AnyError; use deno_core::parking_lot::Mutex; use deno_core::serde::de::DeserializeOwned; use deno_core::serde::Deserialize; @@ -1685,7 +1686,13 @@ fn resolve_node_modules_dir( } fn resolve_lockfile_from_path(lockfile_path: PathBuf) -> Option { - match Lockfile::new(lockfile_path, false) { + let result = std::fs::read_to_string(&lockfile_path) + .map_err(AnyError::from) + .and_then(|text| { + Lockfile::with_lockfile_content(lockfile_path, &text, false) + .map_err(AnyError::from) + }); + match result { Ok(value) => { if let Ok(specifier) = ModuleSpecifier::from_file_path(&value.filename) { lsp_log!(" Resolved lockfile: \"{}\"", specifier); diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 8f37d8b9ca5434..5bf049f0173905 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -85,6 +85,7 @@ use super::tsc::TsServer; use super::urls; use crate::args::create_default_npmrc; use crate::args::get_root_cert_store; +use crate::args::write_lockfile_if_has_changes; use crate::args::CaData; use crate::args::CacheSetting; use crate::args::CliOptions; @@ -260,8 +261,8 @@ impl LanguageServer { // found after caching if let Some(lockfile) = cli_options.maybe_lockfile() { let lockfile = lockfile.lock(); - if let Err(err) = lockfile.write() { - lsp_warn!("Error writing lockfile: {:#}", err); + if let Err(err) = write_lockfile_if_has_changes(&lockfile) { + lsp_warn!("{:#}", err); } } diff --git a/cli/module_loader.rs b/cli/module_loader.rs index e05ffbe2134e54..a5c8ec13f21582 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -9,6 +9,7 @@ use std::str; use std::sync::Arc; use crate::args::jsr_url; +use crate::args::write_lockfile_if_has_changes; use crate::args::CliOptions; use crate::args::DenoSubcommand; use crate::args::TsTypeLib; @@ -172,11 +173,10 @@ impl ModuleLoadPreparer { self.module_graph_builder.graph_roots_valid(graph, roots)?; - // If there is a lockfile... + // write the lockfile if there is one if let Some(lockfile) = &self.lockfile { let lockfile = lockfile.lock(); - // update it with anything new - lockfile.write().context("Failed writing lockfile.")?; + write_lockfile_if_has_changes(&lockfile)?; } drop(_pb_clear_guard); diff --git a/cli/npm/managed/resolution.rs b/cli/npm/managed/resolution.rs index 0ed1e1c84e9052..9cea5d305e1757 100644 --- a/cli/npm/managed/resolution.rs +++ b/cli/npm/managed/resolution.rs @@ -401,7 +401,6 @@ fn npm_package_to_lockfile_info( .collect(); NpmPackageLockfileInfo { - display_id: pkg.id.nv.to_string(), serialized_id: pkg.id.as_serialized(), integrity: pkg.dist.integrity().for_lockfile(), dependencies, diff --git a/cli/tools/info.rs b/cli/tools/info.rs index 4f8e228d95c074..07ad40c67f9892 100644 --- a/cli/tools/info.rs +++ b/cli/tools/info.rs @@ -7,7 +7,6 @@ use std::fmt::Write; use deno_ast::ModuleSpecifier; use deno_core::anyhow::bail; -use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::resolve_url_or_path; use deno_core::serde_json; @@ -26,6 +25,7 @@ use deno_semver::npm::NpmPackageReqReference; use deno_semver::package::PackageNv; use deno_terminal::colors; +use crate::args::write_lockfile_if_has_changes; use crate::args::Flags; use crate::args::InfoFlags; use crate::display; @@ -70,8 +70,7 @@ pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> { // If there is a lockfile... if let Some(lockfile) = &maybe_lockfile { let lockfile = lockfile.lock(); - // update it with anything new - lockfile.write().context("Failed writing lockfile.")?; + write_lockfile_if_has_changes(&lockfile)?; } if info_flags.json { diff --git a/cli/tools/installer.rs b/cli/tools/installer.rs index e0cb5a222bc681..2b518f46f34750 100644 --- a/cli/tools/installer.rs +++ b/cli/tools/installer.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use crate::args::resolve_no_prompt; +use crate::args::write_lockfile_if_has_changes; use crate::args::AddFlags; use crate::args::CaData; use crate::args::Flags; @@ -266,7 +267,7 @@ async fn install_local( crate::module_loader::load_top_level_deps(&factory).await?; if let Some(lockfile) = factory.cli_options().maybe_lockfile() { - lockfile.lock().write()?; + write_lockfile_if_has_changes(&lockfile.lock())?; } Ok(()) diff --git a/cli/worker.rs b/cli/worker.rs index bfdeb35689e6d1..833f3d5430f381 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -7,7 +7,6 @@ use std::sync::Arc; use deno_ast::ModuleSpecifier; use deno_core::anyhow::bail; -use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::futures::FutureExt; use deno_core::parking_lot::Mutex; @@ -48,6 +47,7 @@ use deno_terminal::colors; use tokio::select; use crate::args::package_json::PackageJsonDeps; +use crate::args::write_lockfile_if_has_changes; use crate::args::DenoSubcommand; use crate::args::StorageKeyResolver; use crate::errors; @@ -533,10 +533,7 @@ impl CliMainWorkerFactory { // For npm binary commands, ensure that the lockfile gets updated // so that we can re-use the npm resolution the next time it runs // for better performance - lockfile - .lock() - .write() - .context("Failed writing lockfile.")?; + write_lockfile_if_has_changes(&lockfile.lock())?; } (node_resolution.into_url(), is_main_cjs) From 0c357cc530bf32088493271370f578077ef942ce Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 27 May 2024 20:02:47 -0400 Subject: [PATCH 08/17] clippy --- .dprint.json | 8 ++++---- cli/args/lockfile.rs | 2 ++ cli/cache/module_info.rs | 22 +++++++--------------- cli/graph_util.rs | 11 +++++------ cli/module_loader.rs | 6 +----- cli/standalone/mod.rs | 2 +- cli/tools/doc.rs | 5 +---- cli/tools/info.rs | 5 ++--- tests/integration/jsr_tests.rs | 14 ++++++++++++-- tools/lint.js | 6 +++--- 10 files changed, 38 insertions(+), 43 deletions(-) diff --git a/.dprint.json b/.dprint.json index e0569ca35e6cc3..d34155a01453f9 100644 --- a/.dprint.json +++ b/.dprint.json @@ -57,10 +57,10 @@ "ext/websocket/autobahn/reports" ], "plugins": [ - "https://plugins.dprint.dev/typescript-0.91.0.wasm", - "https://plugins.dprint.dev/json-0.19.3.wasm", - "https://plugins.dprint.dev/markdown-0.17.1.wasm", - "https://plugins.dprint.dev/toml-0.6.2.wasm", + "https://plugins.dprint.dev/typescript-0.90.5.wasm", + "https://plugins.dprint.dev/json-0.19.2.wasm", + "https://plugins.dprint.dev/markdown-0.17.0.wasm", + "https://plugins.dprint.dev/toml-0.6.1.wasm", "https://plugins.dprint.dev/exec-0.4.4.json@c207bf9b9a4ee1f0ecb75c594f774924baf62e8e53a2ce9d873816a408cecbf7" ] } diff --git a/cli/args/lockfile.rs b/cli/args/lockfile.rs index 45113dd967e660..51e7324b9ac54f 100644 --- a/cli/args/lockfile.rs +++ b/cli/args/lockfile.rs @@ -73,6 +73,8 @@ pub fn write_lockfile_if_has_changes( let Some(bytes) = lockfile.resolve_write_bytes() else { return Ok(()); // nothing to do }; + // do an atomic write to reduce the chance of multiple deno + // processes corrupting the file atomic_write_file(&lockfile.filename, bytes, cache::CACHE_PERM) .context("Failed writing lockfile.") } diff --git a/cli/cache/module_info.rs b/cli/cache/module_info.rs index daf01874a426b6..e34b8d2bbdd444 100644 --- a/cli/cache/module_info.rs +++ b/cli/cache/module_info.rs @@ -7,6 +7,7 @@ use deno_ast::ModuleSpecifier; use deno_core::error::AnyError; use deno_core::serde_json; use deno_graph::ModuleInfo; +use deno_graph::ModuleParser; use deno_graph::ParserModuleAnalyzer; use deno_runtime::deno_webstorage::rusqlite::params; @@ -14,7 +15,6 @@ use super::cache_db::CacheDB; use super::cache_db::CacheDBConfiguration; use super::cache_db::CacheFailure; use super::FastInsecureHasher; -use super::ParsedSourceCache; const SELECT_MODULE_INFO: &str = " SELECT @@ -136,18 +136,18 @@ impl ModuleInfoCache { pub fn as_module_analyzer<'a>( &'a self, - parsed_source_cache: Arc, + parser: &'a dyn ModuleParser, ) -> ModuleInfoCacheModuleAnalyzer<'a> { ModuleInfoCacheModuleAnalyzer { module_info_cache: self, - parsed_source_cache, + parser, } } } pub struct ModuleInfoCacheModuleAnalyzer<'a> { module_info_cache: &'a ModuleInfoCache, - parsed_source_cache: Arc, + parser: &'a dyn ModuleParser, } #[async_trait::async_trait(?Send)] @@ -177,17 +177,9 @@ impl<'a> deno_graph::ModuleAnalyzer for ModuleInfoCacheModuleAnalyzer<'a> { } // otherwise, get the module info from the parsed source cache - let module_info = deno_core::unsync::spawn_blocking({ - let cache = self.parsed_source_cache.clone(); - let specifier = specifier.clone(); - move || { - let parser = cache.as_capturing_parser(); - let analyzer = ParserModuleAnalyzer::new(&parser); - analyzer.analyze_sync(&specifier, source, media_type) - } - }) - .await - .unwrap()?; + // todo(23858): take advantage of this being async + let analyzer = ParserModuleAnalyzer::new(self.parser); + let module_info = analyzer.analyze(specifier, source, media_type).await?; // then attempt to cache it if let Err(err) = self.module_info_cache.set_module_info( diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 8af9f6eb673e3e..37326fcfbd8d35 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -450,9 +450,9 @@ impl ModuleGraphBuilder { } // todo(THIS PR): maybe clone from the lockfile then repopulate - struct LockfileLocker(Arc>); + struct LockfileLocker<'a>(&'a Mutex); - impl deno_graph::source::Locker for LockfileLocker { + impl<'a> deno_graph::source::Locker for LockfileLocker<'a> { fn get_remote_checksum( &self, specifier: &deno_ast::ModuleSpecifier, @@ -512,9 +512,8 @@ impl ModuleGraphBuilder { } let maybe_imports = self.options.to_maybe_imports()?; - let analyzer = self - .module_info_cache - .as_module_analyzer(self.parsed_source_cache.clone()); + let parser = self.parsed_source_cache.as_capturing_parser(); + let analyzer = self.module_info_cache.as_module_analyzer(&parser); let mut loader = match options.loader { Some(loader) => MutLoaderRef::Borrowed(loader), None => MutLoaderRef::Owned(self.create_graph_loader()), @@ -531,7 +530,7 @@ impl ModuleGraphBuilder { let mut locker = self .lockfile .as_ref() - .map(|lockfile| LockfileLocker(lockfile.clone())); + .map(|lockfile| LockfileLocker(lockfile)); self .build_graph_with_npm_resolution_and_build_options( graph, diff --git a/cli/module_loader.rs b/cli/module_loader.rs index a5c8ec13f21582..9be1ceff248077 100644 --- a/cli/module_loader.rs +++ b/cli/module_loader.rs @@ -175,8 +175,7 @@ impl ModuleLoadPreparer { // write the lockfile if there is one if let Some(lockfile) = &self.lockfile { - let lockfile = lockfile.lock(); - write_lockfile_if_has_changes(&lockfile)?; + write_lockfile_if_has_changes(&lockfile.lock())?; } drop(_pb_clear_guard); @@ -816,9 +815,6 @@ impl ModuleLoader let lib = inner.lib; let mut update_permit = graph_container.acquire_update_permit().await; let graph = update_permit.graph_mut(); - // if is_dynamic && graph.contains(&specifier) { - // return Ok(()); - // } module_load_preparer .prepare_module_load( graph, diff --git a/cli/standalone/mod.rs b/cli/standalone/mod.rs index 8f8a78de0b46dc..8c268d9288fe56 100644 --- a/cli/standalone/mod.rs +++ b/cli/standalone/mod.rs @@ -180,7 +180,7 @@ impl ModuleLoader for EmbeddedModuleLoader { if original_specifier.scheme() == "data" { let data_url_text = match deno_graph::source::RawDataUrl::parse(original_specifier) - .and_then(|url| url.decode().map_err(|err| err.into())) + .and_then(|url| url.decode()) { Ok(response) => response, Err(err) => { diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index 9a1503dff3e540..d434d5c5095f57 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -88,8 +88,7 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> { let module_info_cache = factory.module_info_cache()?; let parsed_source_cache = factory.parsed_source_cache(); let capturing_parser = parsed_source_cache.as_capturing_parser(); - let analyzer = - module_info_cache.as_module_analyzer(parsed_source_cache.clone()); + let analyzer = module_info_cache.as_module_analyzer(&capturing_parser); let doc_nodes_by_url = match doc_flags.source_files { DocSourceFileFlag::Builtin => { @@ -121,8 +120,6 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> { .create_graph(GraphKind::TypesOnly, module_specifiers.clone()) .await?; - // todo(THIS PR): validate the graph in order to surface lockfile errors? - let doc_parser = doc::DocParser::new( &graph, &capturing_parser, diff --git a/cli/tools/info.rs b/cli/tools/info.rs index 07ad40c67f9892..0f6babe1a0d15c 100644 --- a/cli/tools/info.rs +++ b/cli/tools/info.rs @@ -67,10 +67,9 @@ pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> { .create_graph_with_loader(GraphKind::All, vec![specifier], &mut loader) .await?; - // If there is a lockfile... + // write out the lockfile if there is one if let Some(lockfile) = &maybe_lockfile { - let lockfile = lockfile.lock(); - write_lockfile_if_has_changes(&lockfile)?; + write_lockfile_if_has_changes(&lockfile.lock())?; } if info_flags.json { diff --git a/tests/integration/jsr_tests.rs b/tests/integration/jsr_tests.rs index 9e33a62f261798..c59d5887f62623 100644 --- a/tests/integration/jsr_tests.rs +++ b/tests/integration/jsr_tests.rs @@ -141,7 +141,12 @@ console.log(version);"#, .assert_matches_text("0.1.1\n"); let lockfile_path = temp_dir.path().join("deno.lock"); - let mut lockfile = Lockfile::new(lockfile_path.to_path_buf(), false).unwrap(); + let mut lockfile = Lockfile::with_lockfile_content( + lockfile_path.to_path_buf(), + &lockfile_path.read_to_string(), + false, + ) + .unwrap(); *lockfile .content .packages @@ -251,7 +256,12 @@ console.log(version);"#, .assert_matches_text("0.1.1\n"); let lockfile_path = temp_dir.path().join("deno.lock"); - let mut lockfile = Lockfile::new(lockfile_path.to_path_buf(), false).unwrap(); + let mut lockfile = Lockfile::with_lockfile_content( + lockfile_path.to_path_buf(), + &lockfile_path.read_to_string(), + false, + ) + .unwrap(); let pkg_name = "@denotest/no-module-graph@0.1.1"; let original_integrity = get_lockfile_pkg_integrity(&lockfile, pkg_name); set_lockfile_pkg_integrity(&mut lockfile, pkg_name, "bad_integrity"); diff --git a/tools/lint.js b/tools/lint.js index d4fb4e9a018259..ec8e147a51e238 100755 --- a/tools/lint.js +++ b/tools/lint.js @@ -195,7 +195,7 @@ async function ensureNoNewITests() { // replace them with spec tests. const iTestCounts = { "bench_tests.rs": 0, - "bundle_tests.rs": 12, + "bundle_tests.rs": 11, "cache_tests.rs": 0, "cert_tests.rs": 0, "check_tests.rs": 23, @@ -217,11 +217,11 @@ async function ensureNoNewITests() { "lsp_tests.rs": 0, "node_compat_tests.rs": 4, "node_unit_tests.rs": 2, - "npm_tests.rs": 98, + "npm_tests.rs": 97, "pm_tests.rs": 0, "publish_tests.rs": 0, "repl_tests.rs": 0, - "run_tests.rs": 372, + "run_tests.rs": 360, "shared_library_tests.rs": 0, "task_tests.rs": 30, "test_tests.rs": 77, From b8740f978c74e0bde20db9e2f0490cd4f9ba6ec8 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 27 May 2024 20:17:44 -0400 Subject: [PATCH 09/17] add this back --- cli/npm/managed/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cli/npm/managed/mod.rs b/cli/npm/managed/mod.rs index 582ee8893643fd..938c16d9a0f619 100644 --- a/cli/npm/managed/mod.rs +++ b/cli/npm/managed/mod.rs @@ -369,6 +369,11 @@ impl ManagedCliNpmResolver { self.resolution.add_package_reqs(packages).await?; self.fs_resolver.cache_packages().await?; + // If there's a lock file, update it with all discovered npm packages + if let Some(lockfile) = &self.maybe_lockfile { + self.lock(&mut lockfile.lock()); + } + Ok(()) } From 14b38cd88a6f161187d6a488dd693ccb27cdd134 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 27 May 2024 21:10:56 -0400 Subject: [PATCH 10/17] fix --- cli/args/lockfile.rs | 17 +++++++++++++---- cli/args/mod.rs | 1 + cli/lsp/config.rs | 10 ++-------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/cli/args/lockfile.rs b/cli/args/lockfile.rs index 51e7324b9ac54f..79d139487e2d6c 100644 --- a/cli/args/lockfile.rs +++ b/cli/args/lockfile.rs @@ -59,14 +59,23 @@ pub fn discover( let lockfile = if flags.lock_write { Lockfile::new_empty(filename, true) } else { - let file_text = std::fs::read_to_string(&filename).with_context(|| { - format!("Failed reading lockfile '{}'", filename.display()) - })?; - Lockfile::with_lockfile_content(filename, &file_text, false)? + read_lockfile_at_path(filename)? }; Ok(Some(lockfile)) } +pub fn read_lockfile_at_path(filename: PathBuf) -> Result { + match std::fs::read_to_string(&filename) { + Ok(text) => Ok(Lockfile::with_lockfile_content(filename, &text, false)?), + Err(err) if err.kind() == std::io::ErrorKind::NotFound => { + Ok(Lockfile::new_empty(filename, false)) + } + Err(err) => Err(err).with_context(|| { + format!("Failed reading lockfile '{}'", filename.display()) + }), + } +} + pub fn write_lockfile_if_has_changes( lockfile: &Lockfile, ) -> Result<(), AnyError> { diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 5652e38b9de53b..1a0012fdadfd10 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -34,6 +34,7 @@ pub use deno_config::TsConfigType; pub use deno_config::TsTypeLib; pub use deno_config::WorkspaceConfig; pub use flags::*; +pub use lockfile::read_lockfile_at_path; pub use lockfile::write_lockfile_if_has_changes; pub use lockfile::Lockfile; pub use package_json::PackageJsonDepsProvider; diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index 558987dce5dee2..543200ad1ffef1 100644 --- a/cli/lsp/config.rs +++ b/cli/lsp/config.rs @@ -1,6 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. use super::logging::lsp_log; +use crate::args::read_lockfile_at_path; use crate::args::ConfigFile; use crate::args::FmtOptions; use crate::args::LintOptions; @@ -15,7 +16,6 @@ use deno_ast::MediaType; use deno_config::FmtOptionsConfig; use deno_config::TsConfig; use deno_core::anyhow::anyhow; -use deno_core::error::AnyError; use deno_core::parking_lot::Mutex; use deno_core::serde::de::DeserializeOwned; use deno_core::serde::Deserialize; @@ -1686,13 +1686,7 @@ fn resolve_node_modules_dir( } fn resolve_lockfile_from_path(lockfile_path: PathBuf) -> Option { - let result = std::fs::read_to_string(&lockfile_path) - .map_err(AnyError::from) - .and_then(|text| { - Lockfile::with_lockfile_content(lockfile_path, &text, false) - .map_err(AnyError::from) - }); - match result { + match read_lockfile_at_path(lockfile_path) { Ok(value) => { if let Ok(specifier) = ModuleSpecifier::from_file_path(&value.filename) { lsp_log!(" Resolved lockfile: \"{}\"", specifier); From 64f48cc95ada5e7e209f5fbb29671afc36eca5cd Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 27 May 2024 22:55:45 -0400 Subject: [PATCH 11/17] fixes --- cli/graph_util.rs | 199 +++++++++++------- cli/lsp/language_server.rs | 3 +- cli/tools/doc.rs | 6 + cli/tools/info.rs | 2 + cli/tools/vendor/build.rs | 4 +- tests/integration/jsr_tests.rs | 2 +- tests/specs/jsr/version_not_found/main.out | 3 +- tests/specs/lockfile/no_lock/__test__.jsonc | 67 +++--- tests/specs/lockfile/no_lock/bench.nolock.out | 1 + tests/specs/lockfile/no_lock/doc.nolock.out | 1 + tests/specs/lockfile/no_lock/fail.out | 15 +- tests/specs/lockfile/no_lock/fail_initial.out | 4 - tests/specs/lockfile/no_lock/info.nolock.out | 1 + tests/specs/lockfile/no_lock/test.nolock.out | 1 + .../config_file_lock_path.out | 12 +- 15 files changed, 197 insertions(+), 124 deletions(-) delete mode 100644 tests/specs/lockfile/no_lock/fail_initial.out diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 37326fcfbd8d35..81ae21d0dae842 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -54,6 +54,9 @@ pub struct GraphValidOptions { pub check_js: bool, pub follow_type_only: bool, pub is_vendoring: bool, + /// Whether to exit the process for lockfile errors. + /// Otherwise, surfaces lockfile errors as errors. + pub exit_lockfile_errors: bool, } /// Check if `roots` and their deps are available. Returns `Ok(())` if @@ -65,10 +68,14 @@ pub struct GraphValidOptions { /// for the CLI. pub fn graph_valid( graph: &ModuleGraph, - fs: Arc, + fs: &Arc, roots: &[ModuleSpecifier], options: GraphValidOptions, ) -> Result<(), AnyError> { + if options.exit_lockfile_errors { + graph_exit_lock_errors(graph); + } + let mut errors = graph .walk( roots, @@ -99,70 +106,9 @@ pub fn graph_valid( ) } ModuleGraphError::ModuleError(error) => { - match error { - ModuleError::LoadingErr(specifier, _, ModuleLoadError::Loader(_)) // ex. "Is a directory" error - | ModuleError::Missing(specifier, _) => { - sloppy_imports_error_message(fs.clone(), specifier, error) - } - ModuleError::LoadingErr(specifier, _, ModuleLoadError::Jsr(JsrLoadError::ContentChecksumIntegrity(checksum_err))) => { - let err = format!( - concat!( - "Integrity check failed in package. The package may have been tampered with.\n\n", - " Specifier: {}\n", - " Actual: {}\n", - " Expected: {}\n\n", - "If you modified your global cache, run again with the --reload flag to restore ", - "its state. If you want to modify dependencies locally run again with the ", - "--vendor flag or specify `\"vendor\": true` in a deno.json then modify the contents ", - "of the vendor/ folder." - ), - specifier, - checksum_err.actual, - checksum_err.expected, - ); - log::error!("{} {}", colors::red("error:"), err); - std::process::exit(10); - } - ModuleError::LoadingErr(_specifier, _, ModuleLoadError::Jsr(JsrLoadError::PackageVersionManifestChecksumIntegrity(package_nv, checksum_err))) => { - let err = format!( - concat!( - "Integrity check failed for package. The source code is invalid, as it does not match the expected hash in the lock file.\n\n", - " Package: {}\n", - " Actual: {}\n", - " Expected: {}\n\n", - "This could be caused by:\n", - " * the lock file may be corrupt\n", - " * the source itself may be corrupt\n\n", - "Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server." - ), - package_nv, - checksum_err.actual, - checksum_err.expected, - ); - log::error!("{} {}", colors::red("error:"), err); - std::process::exit(10); - } - ModuleError::LoadingErr(specifier, _, ModuleLoadError::HttpsChecksumIntegrity(checksum_err)) => { - let err = format!( - concat!( - "Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file.\n\n", - " Specifier: {}\n", - " Actual: {}\n", - " Expected: {}\n\n", - "This could be caused by:\n", - " * the lock file may be corrupt\n", - " * the source itself may be corrupt\n\n", - "Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server." - ), - specifier, - checksum_err.actual, - checksum_err.expected, - ); - log::error!("{} {}", colors::red("error:"), err); - std::process::exit(10); - } - _ => format!("{}", error), - } + enhanced_lockfile_error_message(error) + .or_else(|| enhanced_sloppy_imports_error_message(fs, error)) + .unwrap_or_else(|| format!("{}", error)) } }; @@ -218,6 +164,19 @@ pub fn graph_valid( } } +pub fn graph_exit_lock_errors(graph: &ModuleGraph) { + for error in graph.module_errors() { + exit_for_lockfile_error(error); + } +} + +fn exit_for_lockfile_error(err: &ModuleError) { + if let Some(err_message) = enhanced_lockfile_error_message(err) { + log::error!("{} {}", colors::red("error:"), err_message); + std::process::exit(10); + } +} + pub struct CreateGraphOptions<'a> { pub graph_kind: GraphKind, pub roots: Vec, @@ -449,7 +408,6 @@ impl ModuleGraphBuilder { } } - // todo(THIS PR): maybe clone from the lockfile then repopulate struct LockfileLocker<'a>(&'a Mutex); impl<'a> deno_graph::source::Locker for LockfileLocker<'a> { @@ -746,12 +704,13 @@ impl ModuleGraphBuilder { ) -> Result<(), AnyError> { graph_valid( graph, - self.fs.clone(), + &self.fs, roots, GraphValidOptions { is_vendoring: false, follow_type_only: self.options.type_check_mode().is_true(), check_js: self.options.check_js(), + exit_lockfile_errors: true, }, ) } @@ -789,21 +748,99 @@ pub fn enhanced_resolution_error_message(error: &ResolutionError) -> String { message } -fn sloppy_imports_error_message( - fs: Arc, - specifier: &ModuleSpecifier, +fn enhanced_sloppy_imports_error_message( + fs: &Arc, error: &ModuleError, -) -> String { - let additional_message = SloppyImportsResolver::new(fs) - .resolve(specifier, ResolutionMode::Execution) - .as_suggestion_message(); - if let Some(message) = additional_message { - format!( - "{} {} or run with --unstable-sloppy-imports", - error, message - ) - } else { - format!("{}", error) +) -> Option { + match error { + ModuleError::LoadingErr(specifier, _, ModuleLoadError::Loader(_)) // ex. "Is a directory" error + | ModuleError::Missing(specifier, _) => { + let additional_message = SloppyImportsResolver::new(fs.clone()) + .resolve(specifier, ResolutionMode::Execution) + .as_suggestion_message()?; + Some(format!( + "{} {} or run with --unstable-sloppy-imports", + error, + additional_message, + )) + } + _ => None, + } +} + +fn enhanced_lockfile_error_message(err: &ModuleError) -> Option { + match err { + ModuleError::LoadingErr( + specifier, + _, + ModuleLoadError::Jsr(JsrLoadError::ContentChecksumIntegrity( + checksum_err, + )), + ) => { + Some(format!( + concat!( + "Integrity check failed in package. The package may have been tampered with.\n\n", + " Specifier: {}\n", + " Actual: {}\n", + " Expected: {}\n\n", + "If you modified your global cache, run again with the --reload flag to restore ", + "its state. If you want to modify dependencies locally run again with the ", + "--vendor flag or specify `\"vendor\": true` in a deno.json then modify the contents ", + "of the vendor/ folder." + ), + specifier, + checksum_err.actual, + checksum_err.expected, + )) + } + ModuleError::LoadingErr( + _specifier, + _, + ModuleLoadError::Jsr( + JsrLoadError::PackageVersionManifestChecksumIntegrity( + package_nv, + checksum_err, + ), + ), + ) => { + Some(format!( + concat!( + "Integrity check failed for package. The source code is invalid, as it does not match the expected hash in the lock file.\n\n", + " Package: {}\n", + " Actual: {}\n", + " Expected: {}\n\n", + "This could be caused by:\n", + " * the lock file may be corrupt\n", + " * the source itself may be corrupt\n\n", + "Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server." + ), + package_nv, + checksum_err.actual, + checksum_err.expected, + )) + } + ModuleError::LoadingErr( + specifier, + _, + ModuleLoadError::HttpsChecksumIntegrity(checksum_err), + ) => { + Some(format!( + concat!( + "Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file.\n\n", + " Specifier: {}\n", + " Actual: {}\n", + " Expected: {}\n\n", + "This could be caused by:\n", + " * the lock file may be corrupt\n", + " * the source itself may be corrupt\n\n", + "Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server." + ), + specifier, + checksum_err.actual, + checksum_err.expected, + )) + } + _ => None, } } diff --git a/cli/lsp/language_server.rs b/cli/lsp/language_server.rs index 5bf049f0173905..621f45f96f124a 100644 --- a/cli/lsp/language_server.rs +++ b/cli/lsp/language_server.rs @@ -248,12 +248,13 @@ impl LanguageServer { .await?; graph_util::graph_valid( &graph, - factory.fs().clone(), + factory.fs(), &roots, graph_util::GraphValidOptions { is_vendoring: false, follow_type_only: true, check_js: false, + exit_lockfile_errors: false, }, )?; diff --git a/cli/tools/doc.rs b/cli/tools/doc.rs index d434d5c5095f57..696823a9151f16 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -8,6 +8,7 @@ use crate::colors; use crate::display::write_json_to_stdout; use crate::display::write_to_stdout_ignore_sigpipe; use crate::factory::CliFactory; +use crate::graph_util::graph_exit_lock_errors; use crate::tsc::get_types_declaration_file_text; use crate::util::fs::collect_specifiers; use deno_ast::diagnostics::Diagnostic; @@ -101,6 +102,7 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> { } DocSourceFileFlag::Paths(ref source_files) => { let module_graph_creator = factory.module_graph_creator().await?; + let maybe_lockfile = factory.maybe_lockfile(); let module_specifiers = collect_specifiers( FilePatterns { @@ -120,6 +122,10 @@ pub async fn doc(flags: Flags, doc_flags: DocFlags) -> Result<(), AnyError> { .create_graph(GraphKind::TypesOnly, module_specifiers.clone()) .await?; + if maybe_lockfile.is_some() { + graph_exit_lock_errors(&graph); + } + let doc_parser = doc::DocParser::new( &graph, &capturing_parser, diff --git a/cli/tools/info.rs b/cli/tools/info.rs index 0f6babe1a0d15c..b023970f8e3685 100644 --- a/cli/tools/info.rs +++ b/cli/tools/info.rs @@ -30,6 +30,7 @@ use crate::args::Flags; use crate::args::InfoFlags; use crate::display; use crate::factory::CliFactory; +use crate::graph_util::graph_exit_lock_errors; use crate::npm::CliNpmResolver; use crate::npm::ManagedCliNpmResolver; use crate::util::checksum; @@ -69,6 +70,7 @@ pub async fn info(flags: Flags, info_flags: InfoFlags) -> Result<(), AnyError> { // write out the lockfile if there is one if let Some(lockfile) = &maybe_lockfile { + graph_exit_lock_errors(&graph); write_lockfile_if_has_changes(&lockfile.lock())?; } diff --git a/cli/tools/vendor/build.rs b/cli/tools/vendor/build.rs index ab552ca6540dcb..fd7401f777a910 100644 --- a/cli/tools/vendor/build.rs +++ b/cli/tools/vendor/build.rs @@ -114,14 +114,16 @@ pub async fn build< let graph = build_graph(entry_points).await?; // surface any errors + let real_fs = Arc::new(deno_fs::RealFs) as Arc; graph_util::graph_valid( &graph, - Arc::new(deno_fs::RealFs), + &real_fs, &graph.roots, graph_util::GraphValidOptions { is_vendoring: true, check_js: true, follow_type_only: true, + exit_lockfile_errors: true, }, )?; diff --git a/tests/integration/jsr_tests.rs b/tests/integration/jsr_tests.rs index c59d5887f62623..7da0cc5b59cd0c 100644 --- a/tests/integration/jsr_tests.rs +++ b/tests/integration/jsr_tests.rs @@ -351,7 +351,7 @@ console.log(add);"#, // test it properly checks the checksum on download test_context .new_command() - .args("run main.ts") + .args("run main.ts") .run() .assert_matches_text( "Download http://127.0.0.1:4250/@denotest/bad-manifest-checksum/meta.json diff --git a/tests/specs/jsr/version_not_found/main.out b/tests/specs/jsr/version_not_found/main.out index 6a32b5d81201c7..081917d7155a79 100644 --- a/tests/specs/jsr/version_not_found/main.out +++ b/tests/specs/jsr/version_not_found/main.out @@ -1,5 +1,4 @@ Download http://127.0.0.1:4250/@denotest/deps/meta.json Download http://127.0.0.1:4250/@denotest/deps/meta.json -error: Could not find constraint in the list of versions: @denotest/deps@0.1.4 - Specifier: jsr:@denotest/deps@0.1.4/mod.ts +error: Could not find version of '@denotest/deps' that matches specified version constraint '0.1.4' at file:///[WILDCARD]/version_not_found/main.ts:1:19 diff --git a/tests/specs/lockfile/no_lock/__test__.jsonc b/tests/specs/lockfile/no_lock/__test__.jsonc index 60bbd17e0aa891..75821ac64c108a 100644 --- a/tests/specs/lockfile/no_lock/__test__.jsonc +++ b/tests/specs/lockfile/no_lock/__test__.jsonc @@ -1,31 +1,40 @@ { - "steps": [{ - "args": "info main.ts", - "output": "fail_initial.out", - "exitCode": 10 - }, { - "args": "info --no-lock main.ts", - "output": "info.nolock.out" - }, { - "args": "bench", - "output": "fail.out", - "exitCode": 10 - }, { - "args": "bench --no-lock", - "output": "bench.nolock.out" - }, { - "args": "doc main.ts", - "exitCode": 10, - "output": "fail.out" - }, { - "args": "doc --no-lock main.ts", - "output": "doc.nolock.out" - }, { - "args": "test", - "exitCode": 10, - "output": "fail.out" - }, { - "args": "test --no-lock", - "output": "test.nolock.out" - }] + "tests": { + "info": { + "args": "info main.ts", + "output": "fail.out", + "exitCode": 10 + }, + "info_no_lock": { + "args": "info --no-lock main.ts", + "output": "info.nolock.out" + }, + "bench": { + "args": "bench", + "output": "fail.out", + "exitCode": 10 + }, + "bench_no_lock": { + "args": "bench --no-lock", + "output": "bench.nolock.out" + }, + "doc": { + "args": "doc main.ts", + "exitCode": 10, + "output": "fail.out" + }, + "doc_no_lock": { + "args": "doc --no-lock main.ts", + "output": "doc.nolock.out" + }, + "test": { + "args": "test", + "exitCode": 10, + "output": "fail.out" + }, + "test_no_lock": { + "args": "test --no-lock", + "output": "test.nolock.out" + } + } } diff --git a/tests/specs/lockfile/no_lock/bench.nolock.out b/tests/specs/lockfile/no_lock/bench.nolock.out index 351efc97098d0a..83e4de242b2da2 100644 --- a/tests/specs/lockfile/no_lock/bench.nolock.out +++ b/tests/specs/lockfile/no_lock/bench.nolock.out @@ -1,3 +1,4 @@ +Download http://localhost:4545/lockfile/basic/mod.ts Check file:///[WILDCARD]/main.bench.ts cpu: [WILDCARD] runtime: [WILDCARD] diff --git a/tests/specs/lockfile/no_lock/doc.nolock.out b/tests/specs/lockfile/no_lock/doc.nolock.out index e69de29bb2d1d6..e2d66c027b7eb4 100644 --- a/tests/specs/lockfile/no_lock/doc.nolock.out +++ b/tests/specs/lockfile/no_lock/doc.nolock.out @@ -0,0 +1 @@ +Download http://localhost:4545/lockfile/basic/mod.ts diff --git a/tests/specs/lockfile/no_lock/fail.out b/tests/specs/lockfile/no_lock/fail.out index 4c2b0442383780..0d67cd47883774 100644 --- a/tests/specs/lockfile/no_lock/fail.out +++ b/tests/specs/lockfile/no_lock/fail.out @@ -1,3 +1,12 @@ -error: The source code is invalid, as it does not match the expected hash in the lock file. - Specifier: [WILDCARD]mod.ts - Lock file: [WILDCARD]deno.lock +Download http://localhost:4545/lockfile/basic/mod.ts +error: Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file. + + Specifier: http://localhost:4545/lockfile/basic/mod.ts + Actual: [WILDLINE] + Expected: invalid + +This could be caused by: + * the lock file may be corrupt + * the source itself may be corrupt + +Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. diff --git a/tests/specs/lockfile/no_lock/fail_initial.out b/tests/specs/lockfile/no_lock/fail_initial.out deleted file mode 100644 index 6a808c0a5421e8..00000000000000 --- a/tests/specs/lockfile/no_lock/fail_initial.out +++ /dev/null @@ -1,4 +0,0 @@ -Download http://localhost:4545/lockfile/basic/mod.ts -error: The source code is invalid, as it does not match the expected hash in the lock file. - Specifier: [WILDCARD]mod.ts - Lock file: [WILDCARD]deno.lock diff --git a/tests/specs/lockfile/no_lock/info.nolock.out b/tests/specs/lockfile/no_lock/info.nolock.out index b036611937063e..3133777802a891 100644 --- a/tests/specs/lockfile/no_lock/info.nolock.out +++ b/tests/specs/lockfile/no_lock/info.nolock.out @@ -1,3 +1,4 @@ +Download http://localhost:4545/lockfile/basic/mod.ts local: [WILDLINE]main.ts type: TypeScript dependencies: 1 unique diff --git a/tests/specs/lockfile/no_lock/test.nolock.out b/tests/specs/lockfile/no_lock/test.nolock.out index b5039c2d6d2a2c..1332dfa8f10cb8 100644 --- a/tests/specs/lockfile/no_lock/test.nolock.out +++ b/tests/specs/lockfile/no_lock/test.nolock.out @@ -1,3 +1,4 @@ +Download http://localhost:4545/lockfile/basic/mod.ts Check file:///[WILDCARD]/main.test.ts running 1 test from [WILDCARD]/main.test.ts [WILDCARD] diff --git a/tests/specs/run/config_file_lock_path/config_file_lock_path.out b/tests/specs/run/config_file_lock_path/config_file_lock_path.out index 97d35337f78d8e..1383d945d05c6a 100644 --- a/tests/specs/run/config_file_lock_path/config_file_lock_path.out +++ b/tests/specs/run/config_file_lock_path/config_file_lock_path.out @@ -1,3 +1,11 @@ -[WILDCARD]The source code is invalid, as it does not match the expected hash in the lock file. +[WILDCARD]Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file. + Specifier: http://localhost:4545/subdir/mt_text_ecmascript.j3.js - Lock file: [WILDCARD]lock_check_err2.json + Actual: 3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18 + Expected: bad + +This could be caused by: + * the lock file may be corrupt + * the source itself may be corrupt + +Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. From 692a6aba81e90c839669b69fe81994e78c729305 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Mon, 27 May 2024 23:03:09 -0400 Subject: [PATCH 12/17] another test --- .../lockfile/checksum_at_redirect/__test__.jsonc | 5 +++++ tests/specs/lockfile/checksum_at_redirect/deno.json | 2 ++ tests/specs/lockfile/checksum_at_redirect/deno.lock | 6 ++++++ tests/specs/lockfile/checksum_at_redirect/run.out | 12 ++++++++++++ 4 files changed, 25 insertions(+) create mode 100644 tests/specs/lockfile/checksum_at_redirect/__test__.jsonc create mode 100644 tests/specs/lockfile/checksum_at_redirect/deno.json create mode 100644 tests/specs/lockfile/checksum_at_redirect/deno.lock create mode 100644 tests/specs/lockfile/checksum_at_redirect/run.out diff --git a/tests/specs/lockfile/checksum_at_redirect/__test__.jsonc b/tests/specs/lockfile/checksum_at_redirect/__test__.jsonc new file mode 100644 index 00000000000000..66d9850da6e370 --- /dev/null +++ b/tests/specs/lockfile/checksum_at_redirect/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "run --config=deno.json http://localhost:4546/run/001_hello.js", + "output": "run.out", + "exitCode": 10 +} diff --git a/tests/specs/lockfile/checksum_at_redirect/deno.json b/tests/specs/lockfile/checksum_at_redirect/deno.json new file mode 100644 index 00000000000000..2c63c0851048d8 --- /dev/null +++ b/tests/specs/lockfile/checksum_at_redirect/deno.json @@ -0,0 +1,2 @@ +{ +} diff --git a/tests/specs/lockfile/checksum_at_redirect/deno.lock b/tests/specs/lockfile/checksum_at_redirect/deno.lock new file mode 100644 index 00000000000000..12e84cd0199783 --- /dev/null +++ b/tests/specs/lockfile/checksum_at_redirect/deno.lock @@ -0,0 +1,6 @@ +{ + "version": "3", + "remote": { + "http://localhost:4546/run/001_hello.js": "c479db5ea26965387423ca438bb977d0b4788d5901efcef52f69871e4c1048c5" + } +} diff --git a/tests/specs/lockfile/checksum_at_redirect/run.out b/tests/specs/lockfile/checksum_at_redirect/run.out new file mode 100644 index 00000000000000..75a34777f510f2 --- /dev/null +++ b/tests/specs/lockfile/checksum_at_redirect/run.out @@ -0,0 +1,12 @@ +Download http://localhost:4546/run/001_hello.js +error: Integrity check failed for remote specifier. The source code is invalid, as it does not match the expected hash in the lock file. + + Specifier: http://localhost:4546/run/001_hello.js + Actual: Redirect to http://localhost:4545/run/001_hello.js + Expected: c479db5ea26965387423ca438bb977d0b4788d5901efcef52f69871e4c1048c5 + +This could be caused by: + * the lock file may be corrupt + * the source itself may be corrupt + +Use the --lock-write flag to regenerate the lockfile or --reload to reload the source code from the server. From cbafaad2f0d1681a984f52d6960fa5a1f1dbbbd4 Mon Sep 17 00:00:00 2001 From: Luca Casonato Date: Tue, 28 May 2024 10:23:42 +0200 Subject: [PATCH 13/17] update wpt expectation --- tests/wpt/runner/expectation.json | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/wpt/runner/expectation.json b/tests/wpt/runner/expectation.json index 44979f08bf9237..cd11b1d42c9c94 100644 --- a/tests/wpt/runner/expectation.json +++ b/tests/wpt/runner/expectation.json @@ -8707,14 +8707,8 @@ "dynamic-import-with-assertion-argument.any.worker.html": true }, "json-module": { - "charset-bom.any.html": [ - "UTF-16BE BOM should result in parse error in JSON module script", - "UTF-16LE BOM should result in parse error in JSON module script" - ], - "charset-bom.any.worker.html": [ - "UTF-16BE BOM should result in parse error in JSON module script", - "UTF-16LE BOM should result in parse error in JSON module script" - ], + "charset-bom.any.html": true, + "charset-bom.any.worker.html": true, "invalid-content-type.any.html": true, "invalid-content-type.any.worker.html": true, "non-object.any.html": true, From 1952f91f700d7445bda47503f4f2eeccd3ef6718 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 28 May 2024 12:30:59 -0400 Subject: [PATCH 14/17] more tests --- .../different-deps-per-export/1.0.0/add.ts | 1 + .../1.0.0/subtract.ts | 1 + .../different-deps-per-export/1.0.0_meta.json | 6 ++++ .../different-deps-per-export/meta.json | 5 +++ .../jsr/@denotest/subtract/1.0.0/mod.ts | 3 ++ .../jsr/@denotest/subtract/1.0.0_meta.json | 8 +++++ .../registry/jsr/@denotest/subtract/meta.json | 5 +++ .../npm/@denotest/add/1.0.0/index.d.ts | 1 + .../registry/npm/@denotest/add/1.0.0/index.js | 1 + .../npm/@denotest/add/1.0.0/package.json | 4 +++ .../npm/@denotest/subtract/1.0.0/index.d.ts | 1 + .../npm/@denotest/subtract/1.0.0/index.js | 1 + .../npm/@denotest/subtract/1.0.0/package.json | 4 +++ .../lockfile/adding_jsr_dep/__test__.jsonc | 16 ++++++++++ tests/specs/lockfile/adding_jsr_dep/add.ts | 1 + tests/specs/lockfile/adding_jsr_dep/deno.json | 9 ++++++ .../specs/lockfile/adding_jsr_dep/lock01.out | 20 ++++++++++++ .../specs/lockfile/adding_jsr_dep/lock02.out | 24 ++++++++++++++ .../specs/lockfile/adding_jsr_dep/subtract.ts | 1 + .../adding_jsr_export_new_dep/__test__.jsonc | 16 ++++++++++ .../lockfile/adding_jsr_export_new_dep/add.ts | 1 + .../adding_jsr_export_new_dep/deno.json | 8 +++++ .../adding_jsr_export_new_dep/lock01.out | 26 ++++++++++++++++ .../adding_jsr_export_new_dep/lock02.out | 31 +++++++++++++++++++ .../adding_jsr_export_new_dep/subtract.ts | 1 + .../lockfile/adding_npm_dep/__test__.jsonc | 16 ++++++++++ tests/specs/lockfile/adding_npm_dep/add.ts | 1 + tests/specs/lockfile/adding_npm_dep/deno.json | 9 ++++++ .../specs/lockfile/adding_npm_dep/lock01.out | 21 +++++++++++++ .../specs/lockfile/adding_npm_dep/lock02.out | 26 ++++++++++++++++ .../specs/lockfile/adding_npm_dep/subtract.ts | 1 + tests/specs/lockfile/adding_redirect/1.ts | 1 + tests/specs/lockfile/adding_redirect/2.ts | 1 + .../lockfile/adding_redirect/__test__.jsonc | 16 ++++++++++ .../specs/lockfile/adding_redirect/deno.json | 5 +++ .../specs/lockfile/adding_redirect/lock01.out | 6 ++++ .../specs/lockfile/adding_redirect/lock02.out | 9 ++++++ .../auto_discover_lockfile/__test__.jsonc | 0 .../auto_discover_lockfile/deno.json | 0 .../auto_discover_lockfile/deno.lock | 0 .../auto_discover_lockfile/main.out | 0 .../auto_discover_lockfile/main.ts | 0 .../config_file_lock_boolean/__test__.jsonc | 0 .../config_file_lock_boolean/deno.lock | 0 .../config_file_lock_boolean/false.json | 0 .../config_file_lock_boolean/false.main.out | 0 .../config_file_lock_boolean/main.ts | 0 .../config_file_lock_boolean/true.json | 0 .../config_file_lock_boolean/true.main.out | 0 .../019_media_types.ts.out | 0 .../config_file_lock_path/__test__.jsonc | 0 .../config_file_lock_path.json | 0 .../config_file_lock_path.out | 0 .../lock_check_err2.json | 0 .../config_file_lock_path/lock_check_err2.out | 0 .../config_file_lock_path/lock_check_ok2.json | 0 .../run/lock_check_ok2.json | 14 +++++++++ .../lock_check_err/__test__.jsonc | 0 .../lock_check_err/lock_check_err.json | 0 .../lock_check_err/lock_check_err.out | 0 .../lock_check_err2/__test__.jsonc | 0 .../lock_check_err2/lock_check_err2.json | 0 .../lock_check_err2/lock_check_err2.out | 0 .../lock_dynamic_imports/__test__.jsonc | 0 .../lock_dynamic_imports.json | 0 .../lock_dynamic_imports.out | 0 .../lock_v2_check_err/__test__.jsonc | 0 .../lock_v2_check_err/lock_v2_check_err.json | 0 .../lock_v2_check_err/lock_v2_check_err.out | 0 .../lock_v2_check_err2/__test__.jsonc | 0 .../lock_v2_check_err2.json | 0 .../lock_v2_check_err2/lock_v2_check_err2.out | 0 .../lock_v2_dynamic_imports/__test__.jsonc | 0 .../lock_v2_dynamic_imports.json | 0 .../lock_v2_dynamic_imports.out | 0 75 files changed, 321 insertions(+) create mode 100644 tests/registry/jsr/@denotest/different-deps-per-export/1.0.0/add.ts create mode 100644 tests/registry/jsr/@denotest/different-deps-per-export/1.0.0/subtract.ts create mode 100644 tests/registry/jsr/@denotest/different-deps-per-export/1.0.0_meta.json create mode 100644 tests/registry/jsr/@denotest/different-deps-per-export/meta.json create mode 100644 tests/registry/jsr/@denotest/subtract/1.0.0/mod.ts create mode 100644 tests/registry/jsr/@denotest/subtract/1.0.0_meta.json create mode 100644 tests/registry/jsr/@denotest/subtract/meta.json create mode 100644 tests/registry/npm/@denotest/add/1.0.0/index.d.ts create mode 100644 tests/registry/npm/@denotest/add/1.0.0/index.js create mode 100644 tests/registry/npm/@denotest/add/1.0.0/package.json create mode 100644 tests/registry/npm/@denotest/subtract/1.0.0/index.d.ts create mode 100644 tests/registry/npm/@denotest/subtract/1.0.0/index.js create mode 100644 tests/registry/npm/@denotest/subtract/1.0.0/package.json create mode 100644 tests/specs/lockfile/adding_jsr_dep/__test__.jsonc create mode 100644 tests/specs/lockfile/adding_jsr_dep/add.ts create mode 100644 tests/specs/lockfile/adding_jsr_dep/deno.json create mode 100644 tests/specs/lockfile/adding_jsr_dep/lock01.out create mode 100644 tests/specs/lockfile/adding_jsr_dep/lock02.out create mode 100644 tests/specs/lockfile/adding_jsr_dep/subtract.ts create mode 100644 tests/specs/lockfile/adding_jsr_export_new_dep/__test__.jsonc create mode 100644 tests/specs/lockfile/adding_jsr_export_new_dep/add.ts create mode 100644 tests/specs/lockfile/adding_jsr_export_new_dep/deno.json create mode 100644 tests/specs/lockfile/adding_jsr_export_new_dep/lock01.out create mode 100644 tests/specs/lockfile/adding_jsr_export_new_dep/lock02.out create mode 100644 tests/specs/lockfile/adding_jsr_export_new_dep/subtract.ts create mode 100644 tests/specs/lockfile/adding_npm_dep/__test__.jsonc create mode 100644 tests/specs/lockfile/adding_npm_dep/add.ts create mode 100644 tests/specs/lockfile/adding_npm_dep/deno.json create mode 100644 tests/specs/lockfile/adding_npm_dep/lock01.out create mode 100644 tests/specs/lockfile/adding_npm_dep/lock02.out create mode 100644 tests/specs/lockfile/adding_npm_dep/subtract.ts create mode 100644 tests/specs/lockfile/adding_redirect/1.ts create mode 100644 tests/specs/lockfile/adding_redirect/2.ts create mode 100644 tests/specs/lockfile/adding_redirect/__test__.jsonc create mode 100644 tests/specs/lockfile/adding_redirect/deno.json create mode 100644 tests/specs/lockfile/adding_redirect/lock01.out create mode 100644 tests/specs/lockfile/adding_redirect/lock02.out rename tests/specs/{run => lockfile}/auto_discover_lockfile/__test__.jsonc (100%) rename tests/specs/{run => lockfile}/auto_discover_lockfile/deno.json (100%) rename tests/specs/{run => lockfile}/auto_discover_lockfile/deno.lock (100%) rename tests/specs/{run => lockfile}/auto_discover_lockfile/main.out (100%) rename tests/specs/{run => lockfile}/auto_discover_lockfile/main.ts (100%) rename tests/specs/{run => lockfile}/config_file_lock_boolean/__test__.jsonc (100%) rename tests/specs/{run => lockfile}/config_file_lock_boolean/deno.lock (100%) rename tests/specs/{run => lockfile}/config_file_lock_boolean/false.json (100%) rename tests/specs/{run => lockfile}/config_file_lock_boolean/false.main.out (100%) rename tests/specs/{run => lockfile}/config_file_lock_boolean/main.ts (100%) rename tests/specs/{run => lockfile}/config_file_lock_boolean/true.json (100%) rename tests/specs/{run => lockfile}/config_file_lock_boolean/true.main.out (100%) rename tests/specs/{run => lockfile}/config_file_lock_path/019_media_types.ts.out (100%) rename tests/specs/{run => lockfile}/config_file_lock_path/__test__.jsonc (100%) rename tests/specs/{run => lockfile}/config_file_lock_path/config_file_lock_path.json (100%) rename tests/specs/{run => lockfile}/config_file_lock_path/config_file_lock_path.out (100%) rename tests/specs/{run => lockfile}/config_file_lock_path/lock_check_err2.json (100%) rename tests/specs/{run => lockfile}/config_file_lock_path/lock_check_err2.out (100%) rename tests/specs/{run => lockfile}/config_file_lock_path/lock_check_ok2.json (100%) create mode 100644 tests/specs/lockfile/config_file_lock_path/run/lock_check_ok2.json rename tests/specs/{run => lockfile}/lock_check_err/__test__.jsonc (100%) rename tests/specs/{run => lockfile}/lock_check_err/lock_check_err.json (100%) rename tests/specs/{run => lockfile}/lock_check_err/lock_check_err.out (100%) rename tests/specs/{run => lockfile}/lock_check_err2/__test__.jsonc (100%) rename tests/specs/{run => lockfile}/lock_check_err2/lock_check_err2.json (100%) rename tests/specs/{run => lockfile}/lock_check_err2/lock_check_err2.out (100%) rename tests/specs/{run => lockfile}/lock_dynamic_imports/__test__.jsonc (100%) rename tests/specs/{run => lockfile}/lock_dynamic_imports/lock_dynamic_imports.json (100%) rename tests/specs/{run => lockfile}/lock_dynamic_imports/lock_dynamic_imports.out (100%) rename tests/specs/{run => lockfile}/lock_v2_check_err/__test__.jsonc (100%) rename tests/specs/{run => lockfile}/lock_v2_check_err/lock_v2_check_err.json (100%) rename tests/specs/{run => lockfile}/lock_v2_check_err/lock_v2_check_err.out (100%) rename tests/specs/{run => lockfile}/lock_v2_check_err2/__test__.jsonc (100%) rename tests/specs/{run => lockfile}/lock_v2_check_err2/lock_v2_check_err2.json (100%) rename tests/specs/{run => lockfile}/lock_v2_check_err2/lock_v2_check_err2.out (100%) rename tests/specs/{run => lockfile}/lock_v2_dynamic_imports/__test__.jsonc (100%) rename tests/specs/{run => lockfile}/lock_v2_dynamic_imports/lock_v2_dynamic_imports.json (100%) rename tests/specs/{run => lockfile}/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out (100%) diff --git a/tests/registry/jsr/@denotest/different-deps-per-export/1.0.0/add.ts b/tests/registry/jsr/@denotest/different-deps-per-export/1.0.0/add.ts new file mode 100644 index 00000000000000..de02f69024bf76 --- /dev/null +++ b/tests/registry/jsr/@denotest/different-deps-per-export/1.0.0/add.ts @@ -0,0 +1 @@ +export * from "jsr:@denotest/add@1"; diff --git a/tests/registry/jsr/@denotest/different-deps-per-export/1.0.0/subtract.ts b/tests/registry/jsr/@denotest/different-deps-per-export/1.0.0/subtract.ts new file mode 100644 index 00000000000000..215c42310d69bb --- /dev/null +++ b/tests/registry/jsr/@denotest/different-deps-per-export/1.0.0/subtract.ts @@ -0,0 +1 @@ +export * from "jsr:@denotest/subtract@1"; diff --git a/tests/registry/jsr/@denotest/different-deps-per-export/1.0.0_meta.json b/tests/registry/jsr/@denotest/different-deps-per-export/1.0.0_meta.json new file mode 100644 index 00000000000000..9af658497bc269 --- /dev/null +++ b/tests/registry/jsr/@denotest/different-deps-per-export/1.0.0_meta.json @@ -0,0 +1,6 @@ +{ + "exports": { + "./add": "./add.ts", + "./subtract": "./subtract.ts" + } +} diff --git a/tests/registry/jsr/@denotest/different-deps-per-export/meta.json b/tests/registry/jsr/@denotest/different-deps-per-export/meta.json new file mode 100644 index 00000000000000..02601e4d0d5188 --- /dev/null +++ b/tests/registry/jsr/@denotest/different-deps-per-export/meta.json @@ -0,0 +1,5 @@ +{ + "versions": { + "1.0.0": {} + } +} diff --git a/tests/registry/jsr/@denotest/subtract/1.0.0/mod.ts b/tests/registry/jsr/@denotest/subtract/1.0.0/mod.ts new file mode 100644 index 00000000000000..b5bd2dfcf4c281 --- /dev/null +++ b/tests/registry/jsr/@denotest/subtract/1.0.0/mod.ts @@ -0,0 +1,3 @@ +export function subtract(a: number, b: number): number { + return a - b; +} diff --git a/tests/registry/jsr/@denotest/subtract/1.0.0_meta.json b/tests/registry/jsr/@denotest/subtract/1.0.0_meta.json new file mode 100644 index 00000000000000..6eebe219854055 --- /dev/null +++ b/tests/registry/jsr/@denotest/subtract/1.0.0_meta.json @@ -0,0 +1,8 @@ +{ + "exports": { + ".": "./mod.ts" + }, + "moduleGraph1": { + "/mod.ts": {} + } +} diff --git a/tests/registry/jsr/@denotest/subtract/meta.json b/tests/registry/jsr/@denotest/subtract/meta.json new file mode 100644 index 00000000000000..02601e4d0d5188 --- /dev/null +++ b/tests/registry/jsr/@denotest/subtract/meta.json @@ -0,0 +1,5 @@ +{ + "versions": { + "1.0.0": {} + } +} diff --git a/tests/registry/npm/@denotest/add/1.0.0/index.d.ts b/tests/registry/npm/@denotest/add/1.0.0/index.d.ts new file mode 100644 index 00000000000000..9b197eb1e4df1f --- /dev/null +++ b/tests/registry/npm/@denotest/add/1.0.0/index.d.ts @@ -0,0 +1 @@ +export function add(a: number, b: number): number; diff --git a/tests/registry/npm/@denotest/add/1.0.0/index.js b/tests/registry/npm/@denotest/add/1.0.0/index.js new file mode 100644 index 00000000000000..8a40cd7fd231ec --- /dev/null +++ b/tests/registry/npm/@denotest/add/1.0.0/index.js @@ -0,0 +1 @@ +module.exports.add = (a, b) => a + b; \ No newline at end of file diff --git a/tests/registry/npm/@denotest/add/1.0.0/package.json b/tests/registry/npm/@denotest/add/1.0.0/package.json new file mode 100644 index 00000000000000..01d662baae7482 --- /dev/null +++ b/tests/registry/npm/@denotest/add/1.0.0/package.json @@ -0,0 +1,4 @@ +{ + "name": "@denotest/add", + "version": "1.0.0" +} diff --git a/tests/registry/npm/@denotest/subtract/1.0.0/index.d.ts b/tests/registry/npm/@denotest/subtract/1.0.0/index.d.ts new file mode 100644 index 00000000000000..c26a4aec5fc80e --- /dev/null +++ b/tests/registry/npm/@denotest/subtract/1.0.0/index.d.ts @@ -0,0 +1 @@ +export function subtract(a: number, b: number): number; diff --git a/tests/registry/npm/@denotest/subtract/1.0.0/index.js b/tests/registry/npm/@denotest/subtract/1.0.0/index.js new file mode 100644 index 00000000000000..0114210a452123 --- /dev/null +++ b/tests/registry/npm/@denotest/subtract/1.0.0/index.js @@ -0,0 +1 @@ +module.exports.subtract = (a, b) => a - b; \ No newline at end of file diff --git a/tests/registry/npm/@denotest/subtract/1.0.0/package.json b/tests/registry/npm/@denotest/subtract/1.0.0/package.json new file mode 100644 index 00000000000000..5ed43efa9aeac8 --- /dev/null +++ b/tests/registry/npm/@denotest/subtract/1.0.0/package.json @@ -0,0 +1,4 @@ +{ + "name": "@denotest/subtract", + "version": "1.0.0" +} diff --git a/tests/specs/lockfile/adding_jsr_dep/__test__.jsonc b/tests/specs/lockfile/adding_jsr_dep/__test__.jsonc new file mode 100644 index 00000000000000..905aaf49c37565 --- /dev/null +++ b/tests/specs/lockfile/adding_jsr_dep/__test__.jsonc @@ -0,0 +1,16 @@ +{ + "tempDir": true, + "steps": [{ + "args": "run add.ts", + "output": "[WILDCARD]" + }, { + "args": "task --quiet cat deno.lock", + "output": "lock01.out" + }, { + "args": "run subtract.ts", + "output": "[WILDCARD]" + }, { + "args": "task --quiet cat deno.lock", + "output": "lock02.out" + }] +} diff --git a/tests/specs/lockfile/adding_jsr_dep/add.ts b/tests/specs/lockfile/adding_jsr_dep/add.ts new file mode 100644 index 00000000000000..c0fe70808da823 --- /dev/null +++ b/tests/specs/lockfile/adding_jsr_dep/add.ts @@ -0,0 +1 @@ +import "add"; diff --git a/tests/specs/lockfile/adding_jsr_dep/deno.json b/tests/specs/lockfile/adding_jsr_dep/deno.json new file mode 100644 index 00000000000000..c37f65adc25061 --- /dev/null +++ b/tests/specs/lockfile/adding_jsr_dep/deno.json @@ -0,0 +1,9 @@ +{ + "tasks": { + "cat": "cat" + }, + "imports": { + "add": "jsr:@denotest/add@1", + "subtract": "jsr:@denotest/subtract@1" + } +} diff --git a/tests/specs/lockfile/adding_jsr_dep/lock01.out b/tests/specs/lockfile/adding_jsr_dep/lock01.out new file mode 100644 index 00000000000000..0ac0075265dc79 --- /dev/null +++ b/tests/specs/lockfile/adding_jsr_dep/lock01.out @@ -0,0 +1,20 @@ +{ + "version": "3", + "packages": { + "specifiers": { + "jsr:@denotest/add@1": "jsr:@denotest/add@1.0.0" + }, + "jsr": { + "@denotest/add@1.0.0": { + "integrity": "[WILDLINE]" + } + } + }, + "remote": {}, + "workspace": { + "dependencies": [ + "jsr:@denotest/add@1", + "jsr:@denotest/subtract@1" + ] + } +} diff --git a/tests/specs/lockfile/adding_jsr_dep/lock02.out b/tests/specs/lockfile/adding_jsr_dep/lock02.out new file mode 100644 index 00000000000000..4293c7dfed3ab9 --- /dev/null +++ b/tests/specs/lockfile/adding_jsr_dep/lock02.out @@ -0,0 +1,24 @@ +{ + "version": "3", + "packages": { + "specifiers": { + "jsr:@denotest/add@1": "jsr:@denotest/add@1.0.0", + "jsr:@denotest/subtract@1": "jsr:@denotest/subtract@1.0.0" + }, + "jsr": { + "@denotest/add@1.0.0": { + "integrity": "[WILDLINE]" + }, + "@denotest/subtract@1.0.0": { + "integrity": "[WILDLINE]" + } + } + }, + "remote": {}, + "workspace": { + "dependencies": [ + "jsr:@denotest/add@1", + "jsr:@denotest/subtract@1" + ] + } +} diff --git a/tests/specs/lockfile/adding_jsr_dep/subtract.ts b/tests/specs/lockfile/adding_jsr_dep/subtract.ts new file mode 100644 index 00000000000000..b07f2cdfd3da4d --- /dev/null +++ b/tests/specs/lockfile/adding_jsr_dep/subtract.ts @@ -0,0 +1 @@ +import "subtract"; diff --git a/tests/specs/lockfile/adding_jsr_export_new_dep/__test__.jsonc b/tests/specs/lockfile/adding_jsr_export_new_dep/__test__.jsonc new file mode 100644 index 00000000000000..905aaf49c37565 --- /dev/null +++ b/tests/specs/lockfile/adding_jsr_export_new_dep/__test__.jsonc @@ -0,0 +1,16 @@ +{ + "tempDir": true, + "steps": [{ + "args": "run add.ts", + "output": "[WILDCARD]" + }, { + "args": "task --quiet cat deno.lock", + "output": "lock01.out" + }, { + "args": "run subtract.ts", + "output": "[WILDCARD]" + }, { + "args": "task --quiet cat deno.lock", + "output": "lock02.out" + }] +} diff --git a/tests/specs/lockfile/adding_jsr_export_new_dep/add.ts b/tests/specs/lockfile/adding_jsr_export_new_dep/add.ts new file mode 100644 index 00000000000000..06492d2ec50eef --- /dev/null +++ b/tests/specs/lockfile/adding_jsr_export_new_dep/add.ts @@ -0,0 +1 @@ +import "different-deps-per-export/add"; diff --git a/tests/specs/lockfile/adding_jsr_export_new_dep/deno.json b/tests/specs/lockfile/adding_jsr_export_new_dep/deno.json new file mode 100644 index 00000000000000..b26a08521df815 --- /dev/null +++ b/tests/specs/lockfile/adding_jsr_export_new_dep/deno.json @@ -0,0 +1,8 @@ +{ + "tasks": { + "cat": "cat" + }, + "imports": { + "different-deps-per-export": "jsr:@denotest/different-deps-per-export@1" + } +} diff --git a/tests/specs/lockfile/adding_jsr_export_new_dep/lock01.out b/tests/specs/lockfile/adding_jsr_export_new_dep/lock01.out new file mode 100644 index 00000000000000..e78ea355a58a65 --- /dev/null +++ b/tests/specs/lockfile/adding_jsr_export_new_dep/lock01.out @@ -0,0 +1,26 @@ +{ + "version": "3", + "packages": { + "specifiers": { + "jsr:@denotest/add@1": "jsr:@denotest/add@1.0.0", + "jsr:@denotest/different-deps-per-export@1": "jsr:@denotest/different-deps-per-export@1.0.0" + }, + "jsr": { + "@denotest/add@1.0.0": { + "integrity": "[WILDLINE]" + }, + "@denotest/different-deps-per-export@1.0.0": { + "integrity": "[WILDLINE]", + "dependencies": [ + "jsr:@denotest/add@1" + ] + } + } + }, + "remote": {}, + "workspace": { + "dependencies": [ + "jsr:@denotest/different-deps-per-export@1" + ] + } +} diff --git a/tests/specs/lockfile/adding_jsr_export_new_dep/lock02.out b/tests/specs/lockfile/adding_jsr_export_new_dep/lock02.out new file mode 100644 index 00000000000000..0f4a388c606269 --- /dev/null +++ b/tests/specs/lockfile/adding_jsr_export_new_dep/lock02.out @@ -0,0 +1,31 @@ +{ + "version": "3", + "packages": { + "specifiers": { + "jsr:@denotest/add@1": "jsr:@denotest/add@1.0.0", + "jsr:@denotest/different-deps-per-export@1": "jsr:@denotest/different-deps-per-export@1.0.0", + "jsr:@denotest/subtract@1": "jsr:@denotest/subtract@1.0.0" + }, + "jsr": { + "@denotest/add@1.0.0": { + "integrity": "[WILDLINE]" + }, + "@denotest/different-deps-per-export@1.0.0": { + "integrity": "[WILDLINE]", + "dependencies": [ + "jsr:@denotest/add@1", + "jsr:@denotest/subtract@1" + ] + }, + "@denotest/subtract@1.0.0": { + "integrity": "[WILDLINE]" + } + } + }, + "remote": {}, + "workspace": { + "dependencies": [ + "jsr:@denotest/different-deps-per-export@1" + ] + } +} diff --git a/tests/specs/lockfile/adding_jsr_export_new_dep/subtract.ts b/tests/specs/lockfile/adding_jsr_export_new_dep/subtract.ts new file mode 100644 index 00000000000000..1576e29e2567ee --- /dev/null +++ b/tests/specs/lockfile/adding_jsr_export_new_dep/subtract.ts @@ -0,0 +1 @@ +import "different-deps-per-export/subtract"; diff --git a/tests/specs/lockfile/adding_npm_dep/__test__.jsonc b/tests/specs/lockfile/adding_npm_dep/__test__.jsonc new file mode 100644 index 00000000000000..905aaf49c37565 --- /dev/null +++ b/tests/specs/lockfile/adding_npm_dep/__test__.jsonc @@ -0,0 +1,16 @@ +{ + "tempDir": true, + "steps": [{ + "args": "run add.ts", + "output": "[WILDCARD]" + }, { + "args": "task --quiet cat deno.lock", + "output": "lock01.out" + }, { + "args": "run subtract.ts", + "output": "[WILDCARD]" + }, { + "args": "task --quiet cat deno.lock", + "output": "lock02.out" + }] +} diff --git a/tests/specs/lockfile/adding_npm_dep/add.ts b/tests/specs/lockfile/adding_npm_dep/add.ts new file mode 100644 index 00000000000000..c0fe70808da823 --- /dev/null +++ b/tests/specs/lockfile/adding_npm_dep/add.ts @@ -0,0 +1 @@ +import "add"; diff --git a/tests/specs/lockfile/adding_npm_dep/deno.json b/tests/specs/lockfile/adding_npm_dep/deno.json new file mode 100644 index 00000000000000..b3bfef81560dbd --- /dev/null +++ b/tests/specs/lockfile/adding_npm_dep/deno.json @@ -0,0 +1,9 @@ +{ + "tasks": { + "cat": "cat" + }, + "imports": { + "add": "npm:@denotest/add@1", + "subtract": "npm:@denotest/subtract@1" + } +} diff --git a/tests/specs/lockfile/adding_npm_dep/lock01.out b/tests/specs/lockfile/adding_npm_dep/lock01.out new file mode 100644 index 00000000000000..5d5567dc068dc4 --- /dev/null +++ b/tests/specs/lockfile/adding_npm_dep/lock01.out @@ -0,0 +1,21 @@ +{ + "version": "3", + "packages": { + "specifiers": { + "npm:@denotest/add@1": "npm:@denotest/add@1.0.0" + }, + "npm": { + "@denotest/add@1.0.0": { + "integrity": "[WILDLINE]", + "dependencies": {} + } + } + }, + "remote": {}, + "workspace": { + "dependencies": [ + "npm:@denotest/add@1", + "npm:@denotest/subtract@1" + ] + } +} diff --git a/tests/specs/lockfile/adding_npm_dep/lock02.out b/tests/specs/lockfile/adding_npm_dep/lock02.out new file mode 100644 index 00000000000000..6042b1cb9a1052 --- /dev/null +++ b/tests/specs/lockfile/adding_npm_dep/lock02.out @@ -0,0 +1,26 @@ +{ + "version": "3", + "packages": { + "specifiers": { + "npm:@denotest/add@1": "npm:@denotest/add@1.0.0", + "npm:@denotest/subtract@1": "npm:@denotest/subtract@1.0.0" + }, + "npm": { + "@denotest/add@1.0.0": { + "integrity": "[WILDLINE]", + "dependencies": {} + }, + "@denotest/subtract@1.0.0": { + "integrity": "[WILDLINE]", + "dependencies": {} + } + } + }, + "remote": {}, + "workspace": { + "dependencies": [ + "npm:@denotest/add@1", + "npm:@denotest/subtract@1" + ] + } +} diff --git a/tests/specs/lockfile/adding_npm_dep/subtract.ts b/tests/specs/lockfile/adding_npm_dep/subtract.ts new file mode 100644 index 00000000000000..b07f2cdfd3da4d --- /dev/null +++ b/tests/specs/lockfile/adding_npm_dep/subtract.ts @@ -0,0 +1 @@ +import "subtract"; diff --git a/tests/specs/lockfile/adding_redirect/1.ts b/tests/specs/lockfile/adding_redirect/1.ts new file mode 100644 index 00000000000000..7556f226676137 --- /dev/null +++ b/tests/specs/lockfile/adding_redirect/1.ts @@ -0,0 +1 @@ +import "http://localhost:4545/welcome.ts"; diff --git a/tests/specs/lockfile/adding_redirect/2.ts b/tests/specs/lockfile/adding_redirect/2.ts new file mode 100644 index 00000000000000..525b6bc7e9196f --- /dev/null +++ b/tests/specs/lockfile/adding_redirect/2.ts @@ -0,0 +1 @@ +import "http://localhost:4546/welcome.ts"; diff --git a/tests/specs/lockfile/adding_redirect/__test__.jsonc b/tests/specs/lockfile/adding_redirect/__test__.jsonc new file mode 100644 index 00000000000000..d53beedbd415e1 --- /dev/null +++ b/tests/specs/lockfile/adding_redirect/__test__.jsonc @@ -0,0 +1,16 @@ +{ + "tempDir": true, + "steps": [{ + "args": "run 1.ts", + "output": "[WILDCARD]" + }, { + "args": "task --quiet cat deno.lock", + "output": "lock01.out" + }, { + "args": "run 2.ts", + "output": "[WILDCARD]" + }, { + "args": "task --quiet cat deno.lock", + "output": "lock02.out" + }] +} diff --git a/tests/specs/lockfile/adding_redirect/deno.json b/tests/specs/lockfile/adding_redirect/deno.json new file mode 100644 index 00000000000000..75cddd8267e900 --- /dev/null +++ b/tests/specs/lockfile/adding_redirect/deno.json @@ -0,0 +1,5 @@ +{ + "tasks": { + "cat": "cat" + } +} diff --git a/tests/specs/lockfile/adding_redirect/lock01.out b/tests/specs/lockfile/adding_redirect/lock01.out new file mode 100644 index 00000000000000..f00cefa6a8703d --- /dev/null +++ b/tests/specs/lockfile/adding_redirect/lock01.out @@ -0,0 +1,6 @@ +{ + "version": "3", + "remote": { + "http://localhost:4545/welcome.ts": "7353d5fcbc36c45d26bcbca478cf973092523b07c45999f41319820092b4de31" + } +} diff --git a/tests/specs/lockfile/adding_redirect/lock02.out b/tests/specs/lockfile/adding_redirect/lock02.out new file mode 100644 index 00000000000000..70c38c96618663 --- /dev/null +++ b/tests/specs/lockfile/adding_redirect/lock02.out @@ -0,0 +1,9 @@ +{ + "version": "3", + "redirects": { + "http://localhost:4546/welcome.ts": "http://localhost:4545/welcome.ts" + }, + "remote": { + "http://localhost:4545/welcome.ts": "7353d5fcbc36c45d26bcbca478cf973092523b07c45999f41319820092b4de31" + } +} diff --git a/tests/specs/run/auto_discover_lockfile/__test__.jsonc b/tests/specs/lockfile/auto_discover_lockfile/__test__.jsonc similarity index 100% rename from tests/specs/run/auto_discover_lockfile/__test__.jsonc rename to tests/specs/lockfile/auto_discover_lockfile/__test__.jsonc diff --git a/tests/specs/run/auto_discover_lockfile/deno.json b/tests/specs/lockfile/auto_discover_lockfile/deno.json similarity index 100% rename from tests/specs/run/auto_discover_lockfile/deno.json rename to tests/specs/lockfile/auto_discover_lockfile/deno.json diff --git a/tests/specs/run/auto_discover_lockfile/deno.lock b/tests/specs/lockfile/auto_discover_lockfile/deno.lock similarity index 100% rename from tests/specs/run/auto_discover_lockfile/deno.lock rename to tests/specs/lockfile/auto_discover_lockfile/deno.lock diff --git a/tests/specs/run/auto_discover_lockfile/main.out b/tests/specs/lockfile/auto_discover_lockfile/main.out similarity index 100% rename from tests/specs/run/auto_discover_lockfile/main.out rename to tests/specs/lockfile/auto_discover_lockfile/main.out diff --git a/tests/specs/run/auto_discover_lockfile/main.ts b/tests/specs/lockfile/auto_discover_lockfile/main.ts similarity index 100% rename from tests/specs/run/auto_discover_lockfile/main.ts rename to tests/specs/lockfile/auto_discover_lockfile/main.ts diff --git a/tests/specs/run/config_file_lock_boolean/__test__.jsonc b/tests/specs/lockfile/config_file_lock_boolean/__test__.jsonc similarity index 100% rename from tests/specs/run/config_file_lock_boolean/__test__.jsonc rename to tests/specs/lockfile/config_file_lock_boolean/__test__.jsonc diff --git a/tests/specs/run/config_file_lock_boolean/deno.lock b/tests/specs/lockfile/config_file_lock_boolean/deno.lock similarity index 100% rename from tests/specs/run/config_file_lock_boolean/deno.lock rename to tests/specs/lockfile/config_file_lock_boolean/deno.lock diff --git a/tests/specs/run/config_file_lock_boolean/false.json b/tests/specs/lockfile/config_file_lock_boolean/false.json similarity index 100% rename from tests/specs/run/config_file_lock_boolean/false.json rename to tests/specs/lockfile/config_file_lock_boolean/false.json diff --git a/tests/specs/run/config_file_lock_boolean/false.main.out b/tests/specs/lockfile/config_file_lock_boolean/false.main.out similarity index 100% rename from tests/specs/run/config_file_lock_boolean/false.main.out rename to tests/specs/lockfile/config_file_lock_boolean/false.main.out diff --git a/tests/specs/run/config_file_lock_boolean/main.ts b/tests/specs/lockfile/config_file_lock_boolean/main.ts similarity index 100% rename from tests/specs/run/config_file_lock_boolean/main.ts rename to tests/specs/lockfile/config_file_lock_boolean/main.ts diff --git a/tests/specs/run/config_file_lock_boolean/true.json b/tests/specs/lockfile/config_file_lock_boolean/true.json similarity index 100% rename from tests/specs/run/config_file_lock_boolean/true.json rename to tests/specs/lockfile/config_file_lock_boolean/true.json diff --git a/tests/specs/run/config_file_lock_boolean/true.main.out b/tests/specs/lockfile/config_file_lock_boolean/true.main.out similarity index 100% rename from tests/specs/run/config_file_lock_boolean/true.main.out rename to tests/specs/lockfile/config_file_lock_boolean/true.main.out diff --git a/tests/specs/run/config_file_lock_path/019_media_types.ts.out b/tests/specs/lockfile/config_file_lock_path/019_media_types.ts.out similarity index 100% rename from tests/specs/run/config_file_lock_path/019_media_types.ts.out rename to tests/specs/lockfile/config_file_lock_path/019_media_types.ts.out diff --git a/tests/specs/run/config_file_lock_path/__test__.jsonc b/tests/specs/lockfile/config_file_lock_path/__test__.jsonc similarity index 100% rename from tests/specs/run/config_file_lock_path/__test__.jsonc rename to tests/specs/lockfile/config_file_lock_path/__test__.jsonc diff --git a/tests/specs/run/config_file_lock_path/config_file_lock_path.json b/tests/specs/lockfile/config_file_lock_path/config_file_lock_path.json similarity index 100% rename from tests/specs/run/config_file_lock_path/config_file_lock_path.json rename to tests/specs/lockfile/config_file_lock_path/config_file_lock_path.json diff --git a/tests/specs/run/config_file_lock_path/config_file_lock_path.out b/tests/specs/lockfile/config_file_lock_path/config_file_lock_path.out similarity index 100% rename from tests/specs/run/config_file_lock_path/config_file_lock_path.out rename to tests/specs/lockfile/config_file_lock_path/config_file_lock_path.out diff --git a/tests/specs/run/config_file_lock_path/lock_check_err2.json b/tests/specs/lockfile/config_file_lock_path/lock_check_err2.json similarity index 100% rename from tests/specs/run/config_file_lock_path/lock_check_err2.json rename to tests/specs/lockfile/config_file_lock_path/lock_check_err2.json diff --git a/tests/specs/run/config_file_lock_path/lock_check_err2.out b/tests/specs/lockfile/config_file_lock_path/lock_check_err2.out similarity index 100% rename from tests/specs/run/config_file_lock_path/lock_check_err2.out rename to tests/specs/lockfile/config_file_lock_path/lock_check_err2.out diff --git a/tests/specs/run/config_file_lock_path/lock_check_ok2.json b/tests/specs/lockfile/config_file_lock_path/lock_check_ok2.json similarity index 100% rename from tests/specs/run/config_file_lock_path/lock_check_ok2.json rename to tests/specs/lockfile/config_file_lock_path/lock_check_ok2.json diff --git a/tests/specs/lockfile/config_file_lock_path/run/lock_check_ok2.json b/tests/specs/lockfile/config_file_lock_path/run/lock_check_ok2.json new file mode 100644 index 00000000000000..e1bf67c8f42f00 --- /dev/null +++ b/tests/specs/lockfile/config_file_lock_path/run/lock_check_ok2.json @@ -0,0 +1,14 @@ +{ + "version": "3", + "remote": { + "http://localhost:4545/run/019_media_types.ts": "6b099d422b8a83e19d6672ad28c1c42dd3523eaadd8029f185bf4d10c1dc6e92", + "http://localhost:4545/subdir/mt_application_ecmascript.j2.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_application_x_javascript.j4.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_application_x_typescript.t4.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_ecmascript.j3.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_javascript.j1.js": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_text_typescript.t1.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_video_mp2t.t3.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18", + "http://localhost:4545/subdir/mt_video_vdn.t2.ts": "3a3e002e2f92dc8f045bd4a7c66b4791453ad0417b038dd2b2d9d0f277c44f18" + } +} diff --git a/tests/specs/run/lock_check_err/__test__.jsonc b/tests/specs/lockfile/lock_check_err/__test__.jsonc similarity index 100% rename from tests/specs/run/lock_check_err/__test__.jsonc rename to tests/specs/lockfile/lock_check_err/__test__.jsonc diff --git a/tests/specs/run/lock_check_err/lock_check_err.json b/tests/specs/lockfile/lock_check_err/lock_check_err.json similarity index 100% rename from tests/specs/run/lock_check_err/lock_check_err.json rename to tests/specs/lockfile/lock_check_err/lock_check_err.json diff --git a/tests/specs/run/lock_check_err/lock_check_err.out b/tests/specs/lockfile/lock_check_err/lock_check_err.out similarity index 100% rename from tests/specs/run/lock_check_err/lock_check_err.out rename to tests/specs/lockfile/lock_check_err/lock_check_err.out diff --git a/tests/specs/run/lock_check_err2/__test__.jsonc b/tests/specs/lockfile/lock_check_err2/__test__.jsonc similarity index 100% rename from tests/specs/run/lock_check_err2/__test__.jsonc rename to tests/specs/lockfile/lock_check_err2/__test__.jsonc diff --git a/tests/specs/run/lock_check_err2/lock_check_err2.json b/tests/specs/lockfile/lock_check_err2/lock_check_err2.json similarity index 100% rename from tests/specs/run/lock_check_err2/lock_check_err2.json rename to tests/specs/lockfile/lock_check_err2/lock_check_err2.json diff --git a/tests/specs/run/lock_check_err2/lock_check_err2.out b/tests/specs/lockfile/lock_check_err2/lock_check_err2.out similarity index 100% rename from tests/specs/run/lock_check_err2/lock_check_err2.out rename to tests/specs/lockfile/lock_check_err2/lock_check_err2.out diff --git a/tests/specs/run/lock_dynamic_imports/__test__.jsonc b/tests/specs/lockfile/lock_dynamic_imports/__test__.jsonc similarity index 100% rename from tests/specs/run/lock_dynamic_imports/__test__.jsonc rename to tests/specs/lockfile/lock_dynamic_imports/__test__.jsonc diff --git a/tests/specs/run/lock_dynamic_imports/lock_dynamic_imports.json b/tests/specs/lockfile/lock_dynamic_imports/lock_dynamic_imports.json similarity index 100% rename from tests/specs/run/lock_dynamic_imports/lock_dynamic_imports.json rename to tests/specs/lockfile/lock_dynamic_imports/lock_dynamic_imports.json diff --git a/tests/specs/run/lock_dynamic_imports/lock_dynamic_imports.out b/tests/specs/lockfile/lock_dynamic_imports/lock_dynamic_imports.out similarity index 100% rename from tests/specs/run/lock_dynamic_imports/lock_dynamic_imports.out rename to tests/specs/lockfile/lock_dynamic_imports/lock_dynamic_imports.out diff --git a/tests/specs/run/lock_v2_check_err/__test__.jsonc b/tests/specs/lockfile/lock_v2_check_err/__test__.jsonc similarity index 100% rename from tests/specs/run/lock_v2_check_err/__test__.jsonc rename to tests/specs/lockfile/lock_v2_check_err/__test__.jsonc diff --git a/tests/specs/run/lock_v2_check_err/lock_v2_check_err.json b/tests/specs/lockfile/lock_v2_check_err/lock_v2_check_err.json similarity index 100% rename from tests/specs/run/lock_v2_check_err/lock_v2_check_err.json rename to tests/specs/lockfile/lock_v2_check_err/lock_v2_check_err.json diff --git a/tests/specs/run/lock_v2_check_err/lock_v2_check_err.out b/tests/specs/lockfile/lock_v2_check_err/lock_v2_check_err.out similarity index 100% rename from tests/specs/run/lock_v2_check_err/lock_v2_check_err.out rename to tests/specs/lockfile/lock_v2_check_err/lock_v2_check_err.out diff --git a/tests/specs/run/lock_v2_check_err2/__test__.jsonc b/tests/specs/lockfile/lock_v2_check_err2/__test__.jsonc similarity index 100% rename from tests/specs/run/lock_v2_check_err2/__test__.jsonc rename to tests/specs/lockfile/lock_v2_check_err2/__test__.jsonc diff --git a/tests/specs/run/lock_v2_check_err2/lock_v2_check_err2.json b/tests/specs/lockfile/lock_v2_check_err2/lock_v2_check_err2.json similarity index 100% rename from tests/specs/run/lock_v2_check_err2/lock_v2_check_err2.json rename to tests/specs/lockfile/lock_v2_check_err2/lock_v2_check_err2.json diff --git a/tests/specs/run/lock_v2_check_err2/lock_v2_check_err2.out b/tests/specs/lockfile/lock_v2_check_err2/lock_v2_check_err2.out similarity index 100% rename from tests/specs/run/lock_v2_check_err2/lock_v2_check_err2.out rename to tests/specs/lockfile/lock_v2_check_err2/lock_v2_check_err2.out diff --git a/tests/specs/run/lock_v2_dynamic_imports/__test__.jsonc b/tests/specs/lockfile/lock_v2_dynamic_imports/__test__.jsonc similarity index 100% rename from tests/specs/run/lock_v2_dynamic_imports/__test__.jsonc rename to tests/specs/lockfile/lock_v2_dynamic_imports/__test__.jsonc diff --git a/tests/specs/run/lock_v2_dynamic_imports/lock_v2_dynamic_imports.json b/tests/specs/lockfile/lock_v2_dynamic_imports/lock_v2_dynamic_imports.json similarity index 100% rename from tests/specs/run/lock_v2_dynamic_imports/lock_v2_dynamic_imports.json rename to tests/specs/lockfile/lock_v2_dynamic_imports/lock_v2_dynamic_imports.json diff --git a/tests/specs/run/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out b/tests/specs/lockfile/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out similarity index 100% rename from tests/specs/run/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out rename to tests/specs/lockfile/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out From 16c881eb60f5ceb82ad3d7d5be68036f93e6838b Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 28 May 2024 13:15:39 -0400 Subject: [PATCH 15/17] perf: skip npm install if graph has no new packages --- cli/graph_util.rs | 27 +++++++++++-------- .../__test__.jsonc | 19 +++++++++++++ .../deno.json | 7 +++++ .../adding_npm_dep_in_dynamic_import/lock.out | 20 ++++++++++++++ .../adding_npm_dep_in_dynamic_import/main.out | 8 ++++++ .../adding_npm_dep_in_dynamic_import/main.ts | 8 ++++++ .../main2.out | 6 +++++ .../adding_npm_dep_in_dynamic_import/other.ts | 1 + 8 files changed, 85 insertions(+), 11 deletions(-) create mode 100644 tests/specs/npm/adding_npm_dep_in_dynamic_import/__test__.jsonc create mode 100644 tests/specs/npm/adding_npm_dep_in_dynamic_import/deno.json create mode 100644 tests/specs/npm/adding_npm_dep_in_dynamic_import/lock.out create mode 100644 tests/specs/npm/adding_npm_dep_in_dynamic_import/main.out create mode 100644 tests/specs/npm/adding_npm_dep_in_dynamic_import/main.ts create mode 100644 tests/specs/npm/adding_npm_dep_in_dynamic_import/main2.out create mode 100644 tests/specs/npm/adding_npm_dep_in_dynamic_import/other.ts diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 81ae21d0dae842..de434c7b677f76 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -565,16 +565,23 @@ impl ModuleGraphBuilder { graph.build(roots, loader, options).await; - if let Some(npm_resolver) = self.npm_resolver.as_managed() { - // ensure that the top level package.json is installed if a - // specifier was matched in the package.json - if self.resolver.found_package_json_dep() { - npm_resolver.ensure_top_level_package_json_install().await?; - } + let has_npm_packages_changed = + graph.npm_packages.len() != initial_npm_packages; + if is_first_execution + && self.npm_resolver.root_node_modules_path().is_some() + || has_npm_packages_changed + { + if let Some(npm_resolver) = self.npm_resolver.as_managed() { + // ensure that the top level package.json is installed if a + // specifier was matched in the package.json + if self.resolver.found_package_json_dep() { + npm_resolver.ensure_top_level_package_json_install().await?; + } - // resolve the dependencies of any pending dependencies - // that were inserted by building the graph - npm_resolver.resolve_pending().await?; + // resolve the dependencies of any pending dependencies + // that were inserted by building the graph + npm_resolver.resolve_pending().await?; + } } let has_redirects_changed = graph.redirects.len() != initial_redirects_len; @@ -582,8 +589,6 @@ impl ModuleGraphBuilder { graph.packages.package_deps_sum() != initial_package_deps_len; let has_jsr_package_mappings_changed = graph.packages.mappings().len() != initial_package_mappings_len; - let has_npm_packages_changed = - graph.npm_packages.len() != initial_npm_packages; if has_redirects_changed || has_jsr_package_deps_changed diff --git a/tests/specs/npm/adding_npm_dep_in_dynamic_import/__test__.jsonc b/tests/specs/npm/adding_npm_dep_in_dynamic_import/__test__.jsonc new file mode 100644 index 00000000000000..4dcedd92f09ef8 --- /dev/null +++ b/tests/specs/npm/adding_npm_dep_in_dynamic_import/__test__.jsonc @@ -0,0 +1,19 @@ +{ + "tempDir": true, + "steps": [{ + "args": "run --allow-read=. main.ts", + "output": "main.out" + }, { + "args": "task --quiet cat deno.lock", + "output": "lock.out" + }, { + "args": "task rm_node_modules", + "output": "[WILDCARD]" + }, { + "args": "run --allow-read=. main.ts", + "output": "main2.out" + }, { + "args": "task --quiet cat deno.lock", + "output": "lock.out" + }] +} diff --git a/tests/specs/npm/adding_npm_dep_in_dynamic_import/deno.json b/tests/specs/npm/adding_npm_dep_in_dynamic_import/deno.json new file mode 100644 index 00000000000000..38bbf89a0c650b --- /dev/null +++ b/tests/specs/npm/adding_npm_dep_in_dynamic_import/deno.json @@ -0,0 +1,7 @@ +{ + "nodeModulesDir": true, + "tasks": { + "cat": "cat", + "rm_node_modules": "rm -rf node_modules" + } +} diff --git a/tests/specs/npm/adding_npm_dep_in_dynamic_import/lock.out b/tests/specs/npm/adding_npm_dep_in_dynamic_import/lock.out new file mode 100644 index 00000000000000..668430162aff6c --- /dev/null +++ b/tests/specs/npm/adding_npm_dep_in_dynamic_import/lock.out @@ -0,0 +1,20 @@ +{ + "version": "3", + "packages": { + "specifiers": { + "npm:@denotest/add": "npm:@denotest/add@1.0.0", + "npm:@denotest/subtract": "npm:@denotest/subtract@1.0.0" + }, + "npm": { + "@denotest/add@1.0.0": { + "integrity": "sha512-KgwwXAkEQYoTmHAWGukagTXTISHua3DPnKtUwd2ju4/+IFtgkztqku1ZZg9y6mfKOCrkja+yZyky/ktQB7/9ZQ==", + "dependencies": {} + }, + "@denotest/subtract@1.0.0": { + "integrity": "sha512-JCkFYOt0KisCeT7+TtQaGPEqAPSs2tNlv5GZDCbSxPw1YVzWBbjj1YbUORAgtaXBZK0d7aUMvaIcuNKFDb9GIQ==", + "dependencies": {} + } + } + }, + "remote": {} +} diff --git a/tests/specs/npm/adding_npm_dep_in_dynamic_import/main.out b/tests/specs/npm/adding_npm_dep_in_dynamic_import/main.out new file mode 100644 index 00000000000000..fe612aa3c164e9 --- /dev/null +++ b/tests/specs/npm/adding_npm_dep_in_dynamic_import/main.out @@ -0,0 +1,8 @@ +Download http://localhost:4260/@denotest/add +Download http://localhost:4260/@denotest/add/1.0.0.tgz +Initialize @denotest/add@1.0.0 +3 +Download http://localhost:4260/@denotest/subtract +Download http://localhost:4260/@denotest/subtract/1.0.0.tgz +Initialize @denotest/subtract@1.0.0 +1 diff --git a/tests/specs/npm/adding_npm_dep_in_dynamic_import/main.ts b/tests/specs/npm/adding_npm_dep_in_dynamic_import/main.ts new file mode 100644 index 00000000000000..75e9b919994429 --- /dev/null +++ b/tests/specs/npm/adding_npm_dep_in_dynamic_import/main.ts @@ -0,0 +1,8 @@ +import { add } from "npm:@denotest/add"; + +console.log(add(1, 2)); + +const fileName = "other.ts"; +const specifier = "./" + fileName; // non-analyzable +const { subtract } = await import(specifier); +console.log(subtract(3, 2)); diff --git a/tests/specs/npm/adding_npm_dep_in_dynamic_import/main2.out b/tests/specs/npm/adding_npm_dep_in_dynamic_import/main2.out new file mode 100644 index 00000000000000..7f1598ed0c1e96 --- /dev/null +++ b/tests/specs/npm/adding_npm_dep_in_dynamic_import/main2.out @@ -0,0 +1,6 @@ +[UNORDERED_START] +Initialize @denotest/add@1.0.0 +Initialize @denotest/subtract@1.0.0 +[UNORDERED_END] +3 +1 diff --git a/tests/specs/npm/adding_npm_dep_in_dynamic_import/other.ts b/tests/specs/npm/adding_npm_dep_in_dynamic_import/other.ts new file mode 100644 index 00000000000000..b8487fa51bade5 --- /dev/null +++ b/tests/specs/npm/adding_npm_dep_in_dynamic_import/other.ts @@ -0,0 +1 @@ +export * from "npm:@denotest/subtract"; From 21b53bb5c4c1ea056367b7fe7ed12d3106cfc404 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 28 May 2024 13:31:12 -0400 Subject: [PATCH 16/17] add comment --- cli/graph_util.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/cli/graph_util.rs b/cli/graph_util.rs index de434c7b677f76..f1685e9781c61c 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -567,6 +567,7 @@ impl ModuleGraphBuilder { let has_npm_packages_changed = graph.npm_packages.len() != initial_npm_packages; + // skip installing npm packages if we don't have to if is_first_execution && self.npm_resolver.root_node_modules_path().is_some() || has_npm_packages_changed From ae64dda2e0cef7b180abfbbe2926783e766ebb86 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 28 May 2024 15:12:20 -0400 Subject: [PATCH 17/17] fix test --- tests/specs/npm/adding_npm_dep_in_dynamic_import/lock.out | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/specs/npm/adding_npm_dep_in_dynamic_import/lock.out b/tests/specs/npm/adding_npm_dep_in_dynamic_import/lock.out index 668430162aff6c..c67be75c936a55 100644 --- a/tests/specs/npm/adding_npm_dep_in_dynamic_import/lock.out +++ b/tests/specs/npm/adding_npm_dep_in_dynamic_import/lock.out @@ -7,11 +7,11 @@ }, "npm": { "@denotest/add@1.0.0": { - "integrity": "sha512-KgwwXAkEQYoTmHAWGukagTXTISHua3DPnKtUwd2ju4/+IFtgkztqku1ZZg9y6mfKOCrkja+yZyky/ktQB7/9ZQ==", + "integrity": "[WILDLINE]", "dependencies": {} }, "@denotest/subtract@1.0.0": { - "integrity": "sha512-JCkFYOt0KisCeT7+TtQaGPEqAPSs2tNlv5GZDCbSxPw1YVzWBbjj1YbUORAgtaXBZK0d7aUMvaIcuNKFDb9GIQ==", + "integrity": "[WILDLINE]", "dependencies": {} } }