Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(unstable): package manager #20517

Merged
merged 13 commits into from
Sep 18, 2023
Merged
45 changes: 29 additions & 16 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
8 changes: 4 additions & 4 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions cli/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
72 changes: 35 additions & 37 deletions cli/graph_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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;

Expand All @@ -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
Expand Down
7 changes: 3 additions & 4 deletions cli/tests/integration/check_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is some additional cleanup I forgot to do in #20504

http_server: true,
exit_code: 1,
});
Expand Down Expand Up @@ -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"),
Expand All @@ -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,
});
Expand Down
11 changes: 2 additions & 9 deletions cli/tests/integration/compile_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions cli/tests/integration/info_tests.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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"),
Expand Down
Loading