diff --git a/Cargo.lock b/Cargo.lock index 329df26b55..9cb7c2bd75 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1007,7 +1007,7 @@ dependencies = [ "deno_lockfile", "deno_npm", "deno_runtime", - "deno_semver", + "deno_semver 0.5.0", "deno_task_shell", "dissimilar", "dprint-plugin-json", @@ -1196,7 +1196,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed5999e360fec39bbfee5d85bac82c5f557ed93a58660bc255026a90796138c6" dependencies = [ "anyhow", - "deno_semver", + "deno_semver 0.4.0", "indexmap 2.0.0", "jsonc-parser", "log", @@ -1277,9 +1277,9 @@ dependencies = [ [[package]] name = "deno_doc" -version = "0.66.0" +version = "0.67.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4cc42f49e0aa338e438f59b8367c0ca73c789e9321bd6e1ee086d57733826190" +checksum = "2480971d683babc07eea6cdb37d1214675c25d084b0c819e2e52898634b044ce" dependencies = [ "cfg-if 1.0.0", "deno_ast", @@ -1295,9 +1295,9 @@ dependencies = [ [[package]] name = "deno_emit" -version = "0.27.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae90c86c7cd7b828bc8503703dc06fa750a2f49ce7ae78968c04f91b244a6f31" +checksum = "ebc68365e2e5ce6dd11506a1a17aac6a10ea7787e084c45690f70c46a6662fd8" dependencies = [ "anyhow", "base64 0.13.1", @@ -1362,15 +1362,15 @@ dependencies = [ [[package]] name = "deno_graph" -version = "0.54.0" +version = "0.55.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb7464fab13748a26407d0250ab3fb412a88d8b95c30b8a96aa5d49c79d4ee6" +checksum = "f09c93dac12402a37be3ee24e0b6a691ddc5fdef13831b375b6c0950efc89e40" dependencies = [ "anyhow", "async-trait", "data-url", "deno_ast", - "deno_semver", + "deno_semver 0.5.0", "futures", "indexmap 2.0.0", "monch", @@ -1538,7 +1538,7 @@ dependencies = [ "deno_media_type", "deno_net", "deno_npm", - "deno_semver", + "deno_semver 0.5.0", "digest 0.10.7", "dsa", "ecb", @@ -1588,14 +1588,14 @@ dependencies = [ [[package]] name = "deno_npm" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48ec636e8e1a92cb70b2451d9450698f1738f973b0436fe195cb934a51dcdb01" +checksum = "b266a37deae9bc36785d44e9cc1c52d504940b89e5fea63b65119bef44b128a3" dependencies = [ "anyhow", "async-trait", "deno_lockfile", - "deno_semver", + "deno_semver 0.5.0", "futures", "log", "monch", @@ -1691,6 +1691,19 @@ dependencies = [ "url", ] +[[package]] +name = "deno_semver" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "594fd570fecc994ef602b96214f9d6c8ae11e60e29e37e89ab90af7f6b7f9d00" +dependencies = [ + "monch", + "once_cell", + "serde", + "thiserror", + "url", +] + [[package]] name = "deno_task_shell" version = "0.13.2" @@ -2240,16 +2253,16 @@ dependencies = [ [[package]] name = "eszip" -version = "0.52.0" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4baf8c2353535c8ba042249c73b80d289c2ea82cd1eee4838560fa96b77dc392" +checksum = "cf1763e61b99be49c961817d2211fbcef23b04159a60895b208e4608beb20ee0" dependencies = [ "anyhow", "base64 0.21.4", "deno_ast", "deno_graph", "deno_npm", - "deno_semver", + "deno_semver 0.5.0", "futures", "hashlink", "serde", diff --git a/Cargo.toml b/Cargo.toml index e896d4c985..22b6aa4e85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,8 +48,8 @@ deno_bench_util = { version = "0.112.0", path = "./bench_util" } test_util = { path = "./test_util" } deno_lockfile = "0.17.1" deno_media_type = { version = "0.1.1", features = ["module_specifier"] } -deno_npm = "0.14.0" -deno_semver = "0.4.0" +deno_npm = "0.15.0" +deno_semver = "0.5.0" # exts deno_broadcast_channel = { version = "0.112.0", path = "./ext/broadcast_channel" } diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 58a45538a6..8c67d7b292 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -49,16 +49,16 @@ deno_ast = { workspace = true, features = ["bundler", "cjs", "codegen", "dep_gra deno_cache_dir = "=0.6.0" deno_config = "=0.3.1" deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] } -deno_doc = "=0.66.0" -deno_emit = "=0.27.0" -deno_graph = "=0.54.0" +deno_doc = "=0.67.0" +deno_emit = "=0.28.0" +deno_graph = "=0.55.0" deno_lint = { version = "=0.51.0", features = ["docs"] } deno_lockfile.workspace = true deno_npm.workspace = true deno_runtime = { workspace = true, features = ["dont_create_runtime_snapshot", "exclude_runtime_main_js", "include_js_files_for_snapshotting"] } deno_semver.workspace = true deno_task_shell = "=0.13.2" -eszip = "=0.52.0" +eszip = "=0.53.0" napi_sym.workspace = true async-trait.workspace = true diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index 58d4679d1c..1d6a799634 100644 --- a/cli/cache/mod.rs +++ b/cli/cache/mod.rs @@ -274,14 +274,19 @@ impl Loader for FetchCacher { })) }) .unwrap_or_else(|err| { - if let Some(err) = err.downcast_ref::() { - if err.kind() == std::io::ErrorKind::NotFound { + if let Some(io_err) = err.downcast_ref::() { + if io_err.kind() == std::io::ErrorKind::NotFound { return Ok(None); + } else { + return Err(err); } - } else if get_error_class_name(&err) == "NotFound" { - return Ok(None); } - Err(err) + let error_class_name = get_error_class_name(&err); + match error_class_name { + "NotFound" => Ok(None), + "NotCached" if cache_setting == LoaderCacheSetting::Only => Ok(None), + _ => Err(err), + } }) } .boxed() diff --git a/cli/graph_util.rs b/cli/graph_util.rs index 1a5a293a71..e567bebb58 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -32,6 +32,8 @@ use deno_graph::ResolutionError; use deno_graph::SpecifierError; use deno_runtime::deno_node; use deno_runtime::permissions::PermissionsContainer; +use deno_semver::package::PackageNv; +use deno_semver::package::PackageReq; use import_map::ImportMapError; use std::collections::HashMap; use std::collections::HashSet; @@ -331,9 +333,7 @@ impl ModuleGraphBuilder { for (from, to) in &lockfile.content.redirects { if let Ok(from) = ModuleSpecifier::parse(from) { if let Ok(to) = ModuleSpecifier::parse(to) { - if !matches!(from.scheme(), "file" | "npm") - && !matches!(to.scheme(), "file" | "npm") - { + if !matches!(from.scheme(), "file" | "npm" | "jsr") { graph.redirects.insert(from, to); } } @@ -342,26 +342,25 @@ impl ModuleGraphBuilder { } } - // todo(dsherret): uncomment when adding deno: specifier support - // add the deno specifiers to the graph if it's the first time executing - // if graph.deno_specifiers.is_empty() { - // if let Some(lockfile) = &self.lockfile { - // let lockfile = lockfile.lock(); - // for (key, value) in &lockfile.content.packages.specifiers { - // if let Some(key) = key - // .strip_prefix("deno:") - // .and_then(|key| PackageReq::from_str(key)) - // { - // if let Ok(value) = value - // .strip_prefix("deno:") - // .and_then(|value| PackageNv::from_str(value)) - // { - // graph.deno_specifiers.add(key, value); - // } - // } - // } - // } - // } + // 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 (key, value) in &lockfile.content.packages.specifiers { + if let Some(key) = key + .strip_prefix("jsr:") + .and_then(|key| PackageReq::from_str(key).ok()) + { + if let Some(value) = value + .strip_prefix("jsr:") + .and_then(|value| PackageNv::from_str(value).ok()) + { + graph.packages.add(key, value); + } + } + } + } + } graph.build(roots, loader, options).await; @@ -378,20 +377,19 @@ impl ModuleGraphBuilder { } } - // todo(dsherret): uncomment when adding support for deno specifiers - // add the deno specifiers in the graph to the lockfile - // if !graph.deno_specifiers.is_empty() { - // if let Some(lockfile) = &self.lockfile { - // let mappings = graph.deno_specifiers.mappings(); - // let mut lockfile = lockfile.lock(); - // for (from, to) in mappings { - // lockfile.insert_package_specifier( - // format!("deno:{}", from), - // format!("deno:{}", to), - // ); - // } - // } - // } + // 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), + ); + } + } + } // ensure that the top level package.json is installed if a // specifier was matched in the package.json diff --git a/cli/tests/integration/check_tests.rs b/cli/tests/integration/check_tests.rs index 402f683c81..ca80ffa943 100644 --- a/cli/tests/integration/check_tests.rs +++ b/cli/tests/integration/check_tests.rs @@ -2,7 +2,6 @@ use test_util as util; use util::env_vars_for_npm_tests; -use util::env_vars_for_npm_tests_no_sync_download; use util::TestContext; use util::TestContextBuilder; @@ -61,7 +60,7 @@ itest!(bundle_jsximportsource_importmap_config { itest!(jsx_not_checked { args: "check check/jsx_not_checked/main.jsx", output: "check/jsx_not_checked/main.out", - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), http_server: true, exit_code: 1, }); @@ -272,7 +271,7 @@ itest!(package_json_basic { itest!(package_json_fail_check { args: "check --quiet fail_check.ts", output: "package_json/basic/fail_check.check.out", - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), http_server: true, cwd: Some("package_json/basic"), copy_temp_dir: Some("package_json/basic"), @@ -284,7 +283,7 @@ itest!(package_json_with_deno_json { output: "package_json/deno_json/main.check.out", cwd: Some("package_json/deno_json/"), copy_temp_dir: Some("package_json/deno_json/"), - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), http_server: true, exit_code: 1, }); diff --git a/cli/tests/integration/compile_tests.rs b/cli/tests/integration/compile_tests.rs index f43b1cff98..657d17d7d0 100644 --- a/cli/tests/integration/compile_tests.rs +++ b/cli/tests/integration/compile_tests.rs @@ -792,10 +792,7 @@ fn dynamic_import_unanalyzable() { #[test] fn compile_npm_specifiers() { - let context = TestContextBuilder::for_npm() - .use_sync_npm_download() - .use_temp_cwd() - .build(); + let context = TestContextBuilder::for_npm().use_temp_cwd().build(); let temp_dir = context.temp_dir(); temp_dir.write( @@ -1012,10 +1009,7 @@ struct RunNpmBinCompileOptions<'a> { } fn run_npm_bin_compile_test(opts: RunNpmBinCompileOptions) { - let context = TestContextBuilder::for_npm() - .use_sync_npm_download() - .use_temp_cwd() - .build(); + let context = TestContextBuilder::for_npm().use_temp_cwd().build(); let temp_dir = context.temp_dir(); let testdata_path = context.testdata_path(); @@ -1066,7 +1060,6 @@ fn run_npm_bin_compile_test(opts: RunNpmBinCompileOptions) { #[test] fn compile_node_modules_symlink_outside() { let context = TestContextBuilder::for_npm() - .use_sync_npm_download() .use_copy_temp_dir("compile/node_modules_symlink_outside") .cwd("compile/node_modules_symlink_outside") .build(); diff --git a/cli/tests/integration/info_tests.rs b/cli/tests/integration/info_tests.rs index aeabf82080..bfba400804 100644 --- a/cli/tests/integration/info_tests.rs +++ b/cli/tests/integration/info_tests.rs @@ -1,7 +1,7 @@ // Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. use test_util as util; -use util::env_vars_for_npm_tests_no_sync_download; +use util::env_vars_for_npm_tests; use util::TestContextBuilder; #[test] @@ -141,7 +141,7 @@ itest!(with_config_override { itest!(package_json_basic { args: "info --quiet main.ts", output: "package_json/basic/main.info.out", - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), http_server: true, cwd: Some("package_json/basic"), copy_temp_dir: Some("package_json/basic"), diff --git a/cli/tests/integration/jsr_tests.rs b/cli/tests/integration/jsr_tests.rs new file mode 100644 index 0000000000..d1706d84b1 --- /dev/null +++ b/cli/tests/integration/jsr_tests.rs @@ -0,0 +1,99 @@ +// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license. + +use deno_lockfile::Lockfile; +use test_util as util; +use util::env_vars_for_jsr_tests; +use util::TestContextBuilder; + +itest!(no_module_graph_run { + args: "run jsr/no_module_graph/main.ts", + output: "jsr/no_module_graph/main.out", + envs: env_vars_for_jsr_tests(), + http_server: true, +}); + +itest!(no_module_graph_info { + args: "info jsr/no_module_graph/main.ts", + output: "jsr/no_module_graph/main_info.out", + envs: env_vars_for_jsr_tests(), + http_server: true, +}); + +itest!(same_package_multiple_versions { + args: "run --quiet jsr/no_module_graph/multiple.ts", + output: "jsr/no_module_graph/multiple.out", + envs: env_vars_for_jsr_tests(), + http_server: true, +}); + +itest!(module_graph_run { + args: "run jsr/module_graph/main.ts", + output: "jsr/module_graph/main.out", + envs: env_vars_for_jsr_tests(), + http_server: true, +}); + +itest!(module_graph_info { + args: "info jsr/module_graph/main.ts", + output: "jsr/module_graph/main_info.out", + envs: env_vars_for_jsr_tests(), + http_server: true, +}); + +itest!(deps_run { + args: "run jsr/deps/main.ts", + output: "jsr/deps/main.out", + envs: env_vars_for_jsr_tests(), + http_server: true, +}); + +itest!(deps_info { + args: "info jsr/deps/main.ts", + output: "jsr/deps/main_info.out", + envs: env_vars_for_jsr_tests(), + http_server: true, +}); + +itest!(version_not_found { + args: "run jsr/version_not_found/main.ts", + output: "jsr/version_not_found/main.out", + envs: env_vars_for_jsr_tests(), + http_server: true, + exit_code: 1, +}); + +#[test] +fn specifiers_in_lockfile() { + let test_context = TestContextBuilder::for_jsr().use_temp_cwd().build(); + let temp_dir = test_context.temp_dir(); + + temp_dir.write( + "main.ts", + r#"import version from "jsr:@denotest/no_module_graph@0.1/mod.ts"; + +console.log(version);"#, + ); + temp_dir.write("deno.json", "{}"); // to automatically create a lockfile + + test_context + .new_command() + .args("run --quiet main.ts") + .run() + .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(); + *lockfile + .content + .packages + .specifiers + .get_mut("jsr:@denotest/no_module_graph@0.1") + .unwrap() = "jsr:@denotest/no_module_graph@0.1.0".to_string(); + lockfile_path.write(lockfile.as_json_string()); + + test_context + .new_command() + .args("run --quiet main.ts") + .run() + .assert_matches_text("0.1.0\n"); +} diff --git a/cli/tests/integration/mod.rs b/cli/tests/integration/mod.rs index 39a694c269..80b3164327 100644 --- a/cli/tests/integration/mod.rs +++ b/cli/tests/integration/mod.rs @@ -121,6 +121,7 @@ mod inspector; mod install; #[path = "js_unit_tests.rs"] mod js_unit_tests; +mod jsr_tests; #[path = "lint_tests.rs"] mod lint; #[path = "lsp_tests.rs"] diff --git a/cli/tests/integration/npm_tests.rs b/cli/tests/integration/npm_tests.rs index ff600637c3..edd100d7db 100644 --- a/cli/tests/integration/npm_tests.rs +++ b/cli/tests/integration/npm_tests.rs @@ -8,7 +8,6 @@ use std::process::Stdio; use test_util as util; use util::assert_contains; use util::env_vars_for_npm_tests; -use util::env_vars_for_npm_tests_no_sync_download; use util::http_server; use util::TestContextBuilder; @@ -461,7 +460,7 @@ fn parallel_downloading() { ], None, // don't use the sync env var - Some(env_vars_for_npm_tests_no_sync_download()), + Some(env_vars_for_npm_tests()), true, ); assert!(out.contains("chalk cjs loads")); @@ -742,7 +741,7 @@ fn deno_run_cjs_module() { itest!(deno_run_cowsay { args: "run -A --quiet npm:cowsay@1.5.0 Hello", output: "npm/deno_run_cowsay.out", - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), http_server: true, }); @@ -750,21 +749,21 @@ itest!(deno_run_cowsay_with_node_modules_dir { args: "run -A --quiet --node-modules-dir npm:cowsay@1.5.0 Hello", temp_cwd: true, output: "npm/deno_run_cowsay.out", - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), http_server: true, }); itest!(deno_run_cowsay_explicit { args: "run -A --quiet npm:cowsay@1.5.0/cowsay Hello", output: "npm/deno_run_cowsay.out", - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), http_server: true, }); itest!(deno_run_cowthink { args: "run -A --quiet npm:cowsay@1.5.0/cowthink Hello", output: "npm/deno_run_cowthink.out", - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), http_server: true, }); @@ -1553,7 +1552,6 @@ fn auto_discover_lock_file() { #[test] fn peer_deps_with_copied_folders_and_lockfile() { let context = TestContextBuilder::for_npm() - .use_sync_npm_download() .use_copy_temp_dir("npm/peer_deps_with_copied_folders") .cwd("npm/peer_deps_with_copied_folders") .build(); @@ -1749,10 +1747,7 @@ fn reload_info_not_found_cache_but_exists_remote() { // This tests that when a local machine doesn't have a version // specified in a dependency that exists in the npm registry - let test_context = TestContextBuilder::for_npm() - .use_sync_npm_download() - .use_temp_cwd() - .build(); + let test_context = TestContextBuilder::for_npm().use_temp_cwd().build(); let deno_dir = test_context.deno_dir(); let temp_dir = test_context.temp_dir(); temp_dir.write( @@ -1955,7 +1950,6 @@ fn reload_info_not_found_cache_but_exists_remote() { #[test] fn binary_package_with_optional_dependencies() { let context = TestContextBuilder::for_npm() - .use_sync_npm_download() .use_copy_temp_dir("npm/binary_package") .cwd("npm/binary_package") .build(); @@ -2171,7 +2165,7 @@ itest!(dynamic_import_json { itest!(check_package_file_dts_dmts_dcts { args: "check npm/file_dts_dmts_dcts/main.ts", output: "npm/file_dts_dmts_dcts/main.out", - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), http_server: true, exit_code: 1, }); @@ -2179,7 +2173,7 @@ itest!(check_package_file_dts_dmts_dcts { itest!(require_resolve_url_paths { args: "run -A --quiet --node-modules-dir url_paths.ts", output: "npm/require_resolve_url/url_paths.out", - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), http_server: true, exit_code: 0, cwd: Some("npm/require_resolve_url/"), diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs index 0a5e86b1f8..1dff1f6d6a 100644 --- a/cli/tests/integration/run_tests.rs +++ b/cli/tests/integration/run_tests.rs @@ -15,7 +15,7 @@ use trust_dns_client::serialize::txt::Lexer; use trust_dns_client::serialize::txt::Parser; use util::assert_contains; use util::assert_not_contains; -use util::env_vars_for_npm_tests_no_sync_download; +use util::env_vars_for_npm_tests; use util::PathRef; use util::TestContext; use util::TestContextBuilder; @@ -3122,7 +3122,7 @@ itest!(package_json_auto_discovered_for_local_script_arg { cwd: Some("run/with_package_json/"), // prevent creating a node_modules dir in the code directory copy_temp_dir: Some("run/with_package_json/"), - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), http_server: true, }); @@ -3134,7 +3134,7 @@ itest!( output: "run/with_package_json/with_stop/main.out", cwd: Some("run/with_package_json/"), copy_temp_dir: Some("run/with_package_json/"), - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), http_server: true, exit_code: 1, } @@ -3165,7 +3165,7 @@ itest!( output: "run/with_package_json/no_deno_json/sub_dir/main.out", cwd: Some("run/with_package_json/no_deno_json/sub_dir"), copy_temp_dir: Some("run/with_package_json/no_deno_json/"), - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), http_server: true, } ); @@ -3175,7 +3175,7 @@ itest!(package_json_auto_discovered_for_npm_binary { output: "run/with_package_json/npm_binary/main.out", cwd: Some("run/with_package_json/npm_binary/"), copy_temp_dir: Some("run/with_package_json/"), - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), http_server: true, }); @@ -4565,21 +4565,21 @@ fn permission_prompt_strips_ansi_codes_and_control_chars() { itest!(node_builtin_modules_ts { args: "run --quiet --allow-read run/node_builtin_modules/mod.ts hello there", output: "run/node_builtin_modules/mod.ts.out", - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), exit_code: 0, }); itest!(node_builtin_modules_js { args: "run --quiet --allow-read run/node_builtin_modules/mod.js hello there", output: "run/node_builtin_modules/mod.js.out", - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), exit_code: 0, }); itest!(node_prefix_missing { args: "run --quiet run/node_prefix_missing/main.ts", output: "run/node_prefix_missing/main.ts.out", - envs: env_vars_for_npm_tests_no_sync_download(), + envs: env_vars_for_npm_tests(), exit_code: 1, }); diff --git a/cli/tests/testdata/jsr/deps/main.out b/cli/tests/testdata/jsr/deps/main.out new file mode 100644 index 0000000000..388e1a6d56 --- /dev/null +++ b/cli/tests/testdata/jsr/deps/main.out @@ -0,0 +1,13 @@ +Download http://localhost:4545/jsr/registry/@denotest/deps/meta.json +Download http://localhost:4545/jsr/registry/@denotest/deps/1.0.0_meta.json +Download http://localhost:4545/jsr/registry/@denotest/module_graph/meta.json +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/meta.json +Download http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0_meta.json +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.1_meta.json +[UNORDERED_START] +Download http://localhost:4545/jsr/registry/@denotest/deps/1.0.0/mod.ts +Download http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0/other.ts +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.1/mod.ts +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.1/TestClass.ts +[UNORDERED_END] +{ version: "0.1.1", other: Other {} } diff --git a/cli/tests/testdata/jsr/deps/main.ts b/cli/tests/testdata/jsr/deps/main.ts new file mode 100644 index 0000000000..25b13a6815 --- /dev/null +++ b/cli/tests/testdata/jsr/deps/main.ts @@ -0,0 +1,3 @@ +import value from "jsr:@denotest/deps/mod.ts"; + +console.log(value); diff --git a/cli/tests/testdata/jsr/deps/main_info.out b/cli/tests/testdata/jsr/deps/main_info.out new file mode 100644 index 0000000000..c100e1363f --- /dev/null +++ b/cli/tests/testdata/jsr/deps/main_info.out @@ -0,0 +1,22 @@ +Download http://localhost:4545/jsr/registry/@denotest/deps/meta.json +Download http://localhost:4545/jsr/registry/@denotest/deps/1.0.0_meta.json +Download http://localhost:4545/jsr/registry/@denotest/module_graph/meta.json +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/meta.json +Download http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0_meta.json +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.1_meta.json +[UNORDERED_START] +Download http://localhost:4545/jsr/registry/@denotest/deps/1.0.0/mod.ts +Download http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0/other.ts +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.1/mod.ts +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.1/TestClass.ts +[UNORDERED_END] +local: [WILDCARD]main.ts +type: TypeScript +dependencies: 4 unique +size: [WILDCARD] + +file:///[WILDCARD]main.ts ([WILDCARD]) +└─┬ http://localhost:4545/jsr/registry/@denotest/deps/1.0.0/mod.ts ([WILDCARD]) + ├── http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0/other.ts ([WILDCARD]) + └─┬ http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.1/mod.ts ([WILDCARD]) + └── http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.1/TestClass.ts ([WILDCARD]) diff --git a/cli/tests/testdata/jsr/module_graph/main.out b/cli/tests/testdata/jsr/module_graph/main.out new file mode 100644 index 0000000000..c1c8d039d3 --- /dev/null +++ b/cli/tests/testdata/jsr/module_graph/main.out @@ -0,0 +1,7 @@ +Download http://localhost:4545/jsr/registry/@denotest/module_graph/meta.json +Download http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0_meta.json +[UNORDERED_START] +Download http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0/other.ts +Download http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0/mod.ts +[UNORDERED_END] +Test { other: Other {} } diff --git a/cli/tests/testdata/jsr/module_graph/main.ts b/cli/tests/testdata/jsr/module_graph/main.ts new file mode 100644 index 0000000000..02052595c2 --- /dev/null +++ b/cli/tests/testdata/jsr/module_graph/main.ts @@ -0,0 +1,3 @@ +import { Test } from "jsr:@denotest/module_graph/mod.ts"; + +console.log(new Test()); diff --git a/cli/tests/testdata/jsr/module_graph/main_info.out b/cli/tests/testdata/jsr/module_graph/main_info.out new file mode 100644 index 0000000000..4bb8388ed5 --- /dev/null +++ b/cli/tests/testdata/jsr/module_graph/main_info.out @@ -0,0 +1,14 @@ +Download http://localhost:4545/jsr/registry/@denotest/module_graph/meta.json +Download http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0_meta.json +[UNORDERED_START] +Download http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0/mod.ts +Download http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0/other.ts +[UNORDERED_END] +local: [WILDCARD]main.ts +type: TypeScript +dependencies: 2 unique +size: [WILDCARD] + +file:///[WILDCARD]/module_graph/main.ts ([WILDCARD]) +└─┬ http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0/mod.ts ([WILDCARD]) + └── http://localhost:4545/jsr/registry/@denotest/module_graph/1.4.0/other.ts ([WILDCARD]) diff --git a/cli/tests/testdata/jsr/no_module_graph/main.out b/cli/tests/testdata/jsr/no_module_graph/main.out new file mode 100644 index 0000000000..70cae572d7 --- /dev/null +++ b/cli/tests/testdata/jsr/no_module_graph/main.out @@ -0,0 +1,6 @@ +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/meta.json +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.0_meta.json +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.0/mod.ts +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.0/TestClass.ts +0.1.0 +TestClass {} diff --git a/cli/tests/testdata/jsr/no_module_graph/main.ts b/cli/tests/testdata/jsr/no_module_graph/main.ts new file mode 100644 index 0000000000..ab1e781dc3 --- /dev/null +++ b/cli/tests/testdata/jsr/no_module_graph/main.ts @@ -0,0 +1,4 @@ +import version, { TestClass } from "jsr:@denotest/no_module_graph@0.1.0/mod.ts"; + +console.log(version); +console.log(new TestClass()); diff --git a/cli/tests/testdata/jsr/no_module_graph/main_info.out b/cli/tests/testdata/jsr/no_module_graph/main_info.out new file mode 100644 index 0000000000..282e0580ce --- /dev/null +++ b/cli/tests/testdata/jsr/no_module_graph/main_info.out @@ -0,0 +1,12 @@ +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/meta.json +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.0_meta.json +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.0/mod.ts +Download http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.0/TestClass.ts +local: [WILDCARD]main.ts +type: TypeScript +dependencies: 2 unique +size: [WILDCARD] + +file:///[WILDCARD]/jsr/no_module_graph/main.ts ([WILDCARD]) +└─┬ http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.0/mod.ts ([WILDCARD]) + └── http://localhost:4545/jsr/registry/@denotest/no_module_graph/0.1.0/TestClass.ts ([WILDCARD]) diff --git a/cli/tests/testdata/jsr/no_module_graph/multiple.out b/cli/tests/testdata/jsr/no_module_graph/multiple.out new file mode 100644 index 0000000000..8146276d08 --- /dev/null +++ b/cli/tests/testdata/jsr/no_module_graph/multiple.out @@ -0,0 +1,2 @@ +0.1.0 +0.2.0 diff --git a/cli/tests/testdata/jsr/no_module_graph/multiple.ts b/cli/tests/testdata/jsr/no_module_graph/multiple.ts new file mode 100644 index 0000000000..0df32b7800 --- /dev/null +++ b/cli/tests/testdata/jsr/no_module_graph/multiple.ts @@ -0,0 +1,5 @@ +import version1 from "jsr:@denotest/no_module_graph@0.1.0/mod.ts"; +import version2 from "jsr:@denotest/no_module_graph@^0.2/mod.ts"; + +console.log(version1); +console.log(version2); diff --git a/cli/tests/testdata/jsr/registry/@denotest/deps/1.0.0/mod.ts b/cli/tests/testdata/jsr/registry/@denotest/deps/1.0.0/mod.ts new file mode 100644 index 0000000000..5b860b6030 --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/deps/1.0.0/mod.ts @@ -0,0 +1,7 @@ +import { Other } from "jsr:@denotest/module_graph@1/other.ts"; +import version from "jsr:@denotest/no_module_graph@^0.1/mod.ts"; + +export default { + version, + other: new Other(), +}; diff --git a/cli/tests/testdata/jsr/registry/@denotest/deps/1.0.0_meta.json b/cli/tests/testdata/jsr/registry/@denotest/deps/1.0.0_meta.json new file mode 100644 index 0000000000..c6236b7df1 --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/deps/1.0.0_meta.json @@ -0,0 +1,17 @@ +{ + "moduleGraph1": { + "/mod.ts": { + "dependencies": [{ + "kind": "import", + "range": [[0, 0], [0, 62]], + "specifier": "jsr:@denotest/module_graph@1/other.ts", + "specifierRange": [[0, 22], [0, 61]] + }, { + "kind": "import", + "range": [[1, 0], [1, 64]], + "specifier": "jsr:@denotest/no_module_graph@^0.1/mod.ts", + "specifierRange": [[1, 20], [1, 63]] + }] + } + } +} diff --git a/cli/tests/testdata/jsr/registry/@denotest/deps/meta.json b/cli/tests/testdata/jsr/registry/@denotest/deps/meta.json new file mode 100644 index 0000000000..02601e4d0d --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/deps/meta.json @@ -0,0 +1,5 @@ +{ + "versions": { + "1.0.0": {} + } +} diff --git a/cli/tests/testdata/jsr/registry/@denotest/module_graph/1.4.0/mod.ts b/cli/tests/testdata/jsr/registry/@denotest/module_graph/1.4.0/mod.ts new file mode 100644 index 0000000000..cb3c4a5e02 --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/module_graph/1.4.0/mod.ts @@ -0,0 +1,5 @@ +import { Other } from "./other.ts"; + +export class Test { + other = new Other(); +} diff --git a/cli/tests/testdata/jsr/registry/@denotest/module_graph/1.4.0/other.ts b/cli/tests/testdata/jsr/registry/@denotest/module_graph/1.4.0/other.ts new file mode 100644 index 0000000000..57e436cf88 --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/module_graph/1.4.0/other.ts @@ -0,0 +1,2 @@ +export class Other { +} diff --git a/cli/tests/testdata/jsr/registry/@denotest/module_graph/1.4.0_meta.json b/cli/tests/testdata/jsr/registry/@denotest/module_graph/1.4.0_meta.json new file mode 100644 index 0000000000..d1e9a96b92 --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/module_graph/1.4.0_meta.json @@ -0,0 +1,13 @@ +{ + "moduleGraph1": { + "/mod.ts": { + "dependencies": [{ + "kind": "import", + "range": [[0, 0], [0, 35]], + "specifier": "./other.ts", + "specifierRange": [[0, 22], [0, 34]] + }] + }, + "/other.ts": {} + } +} diff --git a/cli/tests/testdata/jsr/registry/@denotest/module_graph/meta.json b/cli/tests/testdata/jsr/registry/@denotest/module_graph/meta.json new file mode 100644 index 0000000000..9a450c08b4 --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/module_graph/meta.json @@ -0,0 +1,6 @@ +{ + "versions": { + "1.0.0": {}, + "1.4.0": {} + } +} diff --git a/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.0/TestClass.ts b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.0/TestClass.ts new file mode 100644 index 0000000000..88ac04c122 --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.0/TestClass.ts @@ -0,0 +1 @@ +export default class TestClass {} diff --git a/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.0/mod.ts b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.0/mod.ts new file mode 100644 index 0000000000..57600eb4b7 --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.0/mod.ts @@ -0,0 +1,3 @@ +export default "0.1.0"; + +export { default as TestClass } from "./TestClass.ts"; diff --git a/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.0_meta.json b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.0_meta.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.0_meta.json @@ -0,0 +1 @@ +{} diff --git a/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.1/TestClass.ts b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.1/TestClass.ts new file mode 100644 index 0000000000..88ac04c122 --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.1/TestClass.ts @@ -0,0 +1 @@ +export default class TestClass {} diff --git a/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.1/mod.ts b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.1/mod.ts new file mode 100644 index 0000000000..5e1fd94359 --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.1/mod.ts @@ -0,0 +1,3 @@ +export default "0.1.1"; + +export { default as TestClass } from "./TestClass.ts"; diff --git a/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.1_meta.json b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.1_meta.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.1.1_meta.json @@ -0,0 +1 @@ +{} diff --git a/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.2.0/TestClass.ts b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.2.0/TestClass.ts new file mode 100644 index 0000000000..88ac04c122 --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.2.0/TestClass.ts @@ -0,0 +1 @@ +export default class TestClass {} diff --git a/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.2.0/mod.ts b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.2.0/mod.ts new file mode 100644 index 0000000000..edf9622fb2 --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.2.0/mod.ts @@ -0,0 +1,3 @@ +export default "0.2.0"; + +export { default as TestClass } from "./TestClass.ts"; diff --git a/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.2.0_meta.json b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.2.0_meta.json new file mode 100644 index 0000000000..0967ef424b --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/0.2.0_meta.json @@ -0,0 +1 @@ +{} diff --git a/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/meta.json b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/meta.json new file mode 100644 index 0000000000..0268b6c8aa --- /dev/null +++ b/cli/tests/testdata/jsr/registry/@denotest/no_module_graph/meta.json @@ -0,0 +1,7 @@ +{ + "versions": { + "0.1.0": {}, + "0.1.1": {}, + "0.2.0": {} + } +} diff --git a/cli/tests/testdata/jsr/version_not_found/main.out b/cli/tests/testdata/jsr/version_not_found/main.out new file mode 100644 index 0000000000..ec9a2ee967 --- /dev/null +++ b/cli/tests/testdata/jsr/version_not_found/main.out @@ -0,0 +1,4 @@ +Download http://localhost:4545/jsr/registry/@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 + at file:///[WILDCARD]/version_not_found/main.ts:1:19 diff --git a/cli/tests/testdata/jsr/version_not_found/main.ts b/cli/tests/testdata/jsr/version_not_found/main.ts new file mode 100644 index 0000000000..a7673b7449 --- /dev/null +++ b/cli/tests/testdata/jsr/version_not_found/main.ts @@ -0,0 +1,2 @@ +import value from "jsr:@denotest/deps@0.1.4/mod.ts"; +console.log(value); diff --git a/test_util/src/builders.rs b/test_util/src/builders.rs index 769c054bf1..17871baa1d 100644 --- a/test_util/src/builders.rs +++ b/test_util/src/builders.rs @@ -15,7 +15,8 @@ use os_pipe::pipe; use crate::assertions::assert_wildcard_match; use crate::deno_exe_path; -use crate::env_vars_for_npm_tests_no_sync_download; +use crate::env_vars_for_jsr_tests; +use crate::env_vars_for_npm_tests; use crate::fs::PathRef; use crate::http_server; use crate::lsp::LspClientBuilder; @@ -50,6 +51,10 @@ impl TestContextBuilder { Self::new().use_http_server().add_npm_env_vars() } + pub fn for_jsr() -> Self { + Self::new().use_http_server().add_jsr_env_vars() + } + pub fn temp_dir_path(mut self, path: impl AsRef) -> Self { self.temp_dir_path = Some(path.as_ref().to_path_buf()); self @@ -98,18 +103,17 @@ impl TestContextBuilder { } pub fn add_npm_env_vars(mut self) -> Self { - for (key, value) in env_vars_for_npm_tests_no_sync_download() { + for (key, value) in env_vars_for_npm_tests() { self = self.env(key, value); } self } - pub fn use_sync_npm_download(self) -> Self { - self.env( - // make downloads deterministic - "DENO_UNSTABLE_NPM_SYNC_DOWNLOAD", - "1", - ) + pub fn add_jsr_env_vars(mut self) -> Self { + for (key, value) in env_vars_for_jsr_tests() { + self = self.env(key, value); + } + self } pub fn build(&self) -> TestContext { diff --git a/test_util/src/lib.rs b/test_util/src/lib.rs index 635520b44d..07ed558227 100644 --- a/test_util/src/lib.rs +++ b/test_util/src/lib.rs @@ -114,21 +114,18 @@ pub const PERMISSION_DENIED_PATTERN: &str = "PermissionDenied"; static GUARD: Lazy> = Lazy::new(|| Mutex::new(HttpServerCount::default())); -pub fn env_vars_for_npm_tests_no_sync_download() -> Vec<(String, String)> { +pub fn env_vars_for_npm_tests() -> Vec<(String, String)> { vec![ ("NPM_CONFIG_REGISTRY".to_string(), npm_registry_url()), ("NO_COLOR".to_string(), "1".to_string()), ] } -pub fn env_vars_for_npm_tests() -> Vec<(String, String)> { - let mut env_vars = env_vars_for_npm_tests_no_sync_download(); - env_vars.push(( - // make downloads deterministic - "DENO_UNSTABLE_NPM_SYNC_DOWNLOAD".to_string(), - "1".to_string(), - )); - env_vars +pub fn env_vars_for_jsr_tests() -> Vec<(String, String)> { + vec![ + ("DENO_REGISTRY_URL".to_string(), jsr_registry_url()), + ("NO_COLOR".to_string(), "1".to_string()), + ] } pub fn root_path() -> PathRef { @@ -168,6 +165,10 @@ pub fn npm_registry_unset_url() -> String { "http://NPM_CONFIG_REGISTRY.is.unset".to_string() } +pub fn jsr_registry_url() -> String { + "http://localhost:4545/jsr/registry/".to_string() +} + pub fn std_path() -> PathRef { root_path().join("test_util").join("std") } @@ -2620,6 +2621,21 @@ pub fn wildcard_match_detailed( )) )); } + let actual_next_text = ¤t_text[max_found_index..]; + let max_next_text_len = 40; + let next_text_len = + std::cmp::min(max_next_text_len, actual_next_text.len()); + output_lines.push(format!( + "==== NEXT ACTUAL TEXT ====\n{}{}", + colors::red(annotate_whitespace( + &actual_next_text[..next_text_len] + )), + if actual_next_text.len() > max_next_text_len { + "[TRUNCATED]" + } else { + "" + }, + )); return WildcardMatchResult::Fail(output_lines.join("\n")); } } @@ -2673,9 +2689,13 @@ pub fn wildcard_match_detailed( colors::green(annotate_whitespace(expected)) )); return WildcardMatchResult::Fail(output_lines.join("\n")); + } else { + output_lines.push(format!( + "{}", + colors::gray(annotate_whitespace(expected)) + )); } } - output_lines.push("# Found matching unordered lines".to_string()); } } was_last_wildcard = matches!(part, WildcardPatternPart::Wildcard);