feat(unstable): package manager (#20517)

Adds an experimental unstable built-in package manager to Deno, but it is
currently not usable because the registry infrastructure hasn't been
setup and it points to a non-existent url by default. The default
registry url can be configured via the `DENO_REGISTRY_URL` environment
variable.
This commit is contained in:
David Sherret 2023-09-18 10:46:44 -04:00 committed by GitHub
parent 4fcd9a0de8
commit 0709c051f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
44 changed files with 419 additions and 119 deletions

45
Cargo.lock generated
View File

@ -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",

View File

@ -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" }

View File

@ -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

15
cli/cache/mod.rs vendored
View File

@ -274,14 +274,19 @@ impl Loader for FetchCacher {
}))
})
.unwrap_or_else(|err| {
if let Some(err) = err.downcast_ref::<std::io::Error>() {
if err.kind() == std::io::ErrorKind::NotFound {
if let Some(io_err) = err.downcast_ref::<std::io::Error>() {
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()

View File

@ -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

View File

@ -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,
});

View File

@ -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();

View File

@ -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"),

View File

@ -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");
}

View File

@ -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"]

View File

@ -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/"),

View File

@ -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,
});

13
cli/tests/testdata/jsr/deps/main.out vendored Normal file
View File

@ -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 {} }

3
cli/tests/testdata/jsr/deps/main.ts vendored Normal file
View File

@ -0,0 +1,3 @@
import value from "jsr:@denotest/deps/mod.ts";
console.log(value);

View File

@ -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])

View File

@ -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 {} }

View File

@ -0,0 +1,3 @@
import { Test } from "jsr:@denotest/module_graph/mod.ts";
console.log(new Test());

View File

@ -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])

View File

@ -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 {}

View File

@ -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());

View File

@ -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])

View File

@ -0,0 +1,2 @@
0.1.0
0.2.0

View File

@ -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);

View File

@ -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(),
};

View File

@ -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]]
}]
}
}
}

View File

@ -0,0 +1,5 @@
{
"versions": {
"1.0.0": {}
}
}

View File

@ -0,0 +1,5 @@
import { Other } from "./other.ts";
export class Test {
other = new Other();
}

View File

@ -0,0 +1,2 @@
export class Other {
}

View File

@ -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": {}
}
}

View File

@ -0,0 +1,6 @@
{
"versions": {
"1.0.0": {},
"1.4.0": {}
}
}

View File

@ -0,0 +1 @@
export default class TestClass {}

View File

@ -0,0 +1,3 @@
export default "0.1.0";
export { default as TestClass } from "./TestClass.ts";

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1 @@
export default class TestClass {}

View File

@ -0,0 +1,3 @@
export default "0.1.1";
export { default as TestClass } from "./TestClass.ts";

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1 @@
export default class TestClass {}

View File

@ -0,0 +1,3 @@
export default "0.2.0";
export { default as TestClass } from "./TestClass.ts";

View File

@ -0,0 +1 @@
{}

View File

@ -0,0 +1,7 @@
{
"versions": {
"0.1.0": {},
"0.1.1": {},
"0.2.0": {}
}
}

View File

@ -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

View File

@ -0,0 +1,2 @@
import value from "jsr:@denotest/deps@0.1.4/mod.ts";
console.log(value);

View File

@ -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<Path>) -> 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 {

View File

@ -114,21 +114,18 @@ pub const PERMISSION_DENIED_PATTERN: &str = "PermissionDenied";
static GUARD: Lazy<Mutex<HttpServerCount>> =
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 = &current_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!(
"<FOUND>{}</FOUND>",
colors::gray(annotate_whitespace(expected))
));
}
}
output_lines.push("# Found matching unordered lines".to_string());
}
}
was_last_wildcard = matches!(part, WildcardPatternPart::Wildcard);