summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock12
-rw-r--r--Cargo.toml4
-rw-r--r--cli/Cargo.toml2
-rw-r--r--cli/graph_util.rs32
-rw-r--r--cli/tests/integration/run_tests.rs95
5 files changed, 136 insertions, 9 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d1a6d176e..d565cbb23 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1324,9 +1324,9 @@ dependencies = [
[[package]]
name = "deno_lockfile"
-version = "0.15.0"
+version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3e1fcc91fa4e18c3e0574965d7133709e76eda665cb589de703219f0819dfaec"
+checksum = "1038f33740cd29127efa0f7858a869cef5df6baed7fd97c1c0db19213b11f5ef"
dependencies = [
"ring",
"serde",
@@ -1429,9 +1429,9 @@ dependencies = [
[[package]]
name = "deno_npm"
-version = "0.12.0"
+version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c90198ae433bf22ac9b39fe5e18748d9d5b36db042ef1c24637f43d3b5e101e0"
+checksum = "3f4f1ce6bc2738c0068f205cef30b33d46103f65a26031affcd8c3994db0ca51"
dependencies = [
"anyhow",
"async-trait",
@@ -2061,9 +2061,9 @@ dependencies = [
[[package]]
name = "eszip"
-version = "0.50.0"
+version = "0.50.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e254fcba0a6481f44fa41f41cb9027d811072e7e7fa94780ade4a7fa43b34c4b"
+checksum = "96c51f197ceba98354cd4bf2db99db68c082e531685c634cea3453fbbcb071ba"
dependencies = [
"anyhow",
"base64 0.21.2",
diff --git a/Cargo.toml b/Cargo.toml
index 2fe72de97..49a6d256d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -46,9 +46,9 @@ deno_runtime = { version = "0.125.0", path = "./runtime" }
napi_sym = { version = "0.47.0", path = "./cli/napi/sym" }
deno_bench_util = { version = "0.111.0", path = "./bench_util" }
test_util = { path = "./test_util" }
-deno_lockfile = "0.15.0"
+deno_lockfile = "0.16.2"
deno_media_type = { version = "0.1.1", features = ["module_specifier"] }
-deno_npm = "0.12.0"
+deno_npm = "0.13.0"
deno_semver = "0.4.0"
# exts
diff --git a/cli/Cargo.toml b/cli/Cargo.toml
index 69635141b..dab935b63 100644
--- a/cli/Cargo.toml
+++ b/cli/Cargo.toml
@@ -58,7 +58,7 @@ 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.50.0"
+eszip = "=0.50.1"
napi_sym.workspace = true
async-trait.workspace = true
diff --git a/cli/graph_util.rs b/cli/graph_util.rs
index 3623f49d0..fc530032a 100644
--- a/cli/graph_util.rs
+++ b/cli/graph_util.rs
@@ -320,8 +320,40 @@ impl ModuleGraphBuilder {
self.resolver.force_top_level_package_json_install().await?;
}
+ // add the lockfile redirects to the graph if it's the first time executing
+ if graph.redirects.is_empty() {
+ if let Some(lockfile) = &self.lockfile {
+ let lockfile = lockfile.lock();
+ 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")
+ {
+ graph.redirects.insert(from, to);
+ }
+ }
+ }
+ }
+ }
+ }
+
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"));
+ let mut lockfile = lockfile.lock();
+ for (from, to) in graph_redirects {
+ lockfile.insert_redirect(from.to_string(), to.to_string());
+ }
+ }
+ }
+
// ensure that the top level package.json is installed if a
// specifier was matched in the package.json
self
diff --git a/cli/tests/integration/run_tests.rs b/cli/tests/integration/run_tests.rs
index 3a385f7cd..22096cb60 100644
--- a/cli/tests/integration/run_tests.rs
+++ b/cli/tests/integration/run_tests.rs
@@ -3,6 +3,7 @@
use deno_core::serde_json::json;
use deno_core::url;
use deno_runtime::deno_fetch::reqwest;
+use pretty_assertions::assert_eq;
use std::io::Read;
use std::io::Write;
use std::process::Command;
@@ -973,6 +974,100 @@ fn lock_no_declaration_files() {
);
}
+#[test]
+fn lock_redirects() {
+ let context = TestContextBuilder::new()
+ .use_temp_cwd()
+ .use_http_server()
+ .add_npm_env_vars()
+ .build();
+ let temp_dir = context.temp_dir();
+ temp_dir.write("deno.json", "{}"); // cause a lockfile to be created
+ temp_dir.write(
+ "main.ts",
+ "import 'http://localhost:4546/run/001_hello.js';",
+ );
+ context
+ .new_command()
+ .args("run main.ts")
+ .run()
+ .skip_output_check();
+ let initial_lockfile_text = r#"{
+ "version": "2",
+ "redirects": {
+ "http://localhost:4546/run/001_hello.js": "http://localhost:4545/run/001_hello.js"
+ },
+ "remote": {
+ "http://localhost:4545/run/001_hello.js": "c479db5ea26965387423ca438bb977d0b4788d5901efcef52f69871e4c1048c5"
+ }
+}
+"#;
+ assert_eq!(temp_dir.read_to_string("deno.lock"), initial_lockfile_text);
+ context
+ .new_command()
+ .args("run main.ts")
+ .run()
+ .assert_matches_text("Hello World\n");
+ assert_eq!(temp_dir.read_to_string("deno.lock"), initial_lockfile_text);
+
+ // now try changing where the redirect occurs in the lockfile
+ temp_dir.write("deno.lock", r#"{
+ "version": "2",
+ "redirects": {
+ "http://localhost:4546/run/001_hello.js": "http://localhost:4545/echo.ts"
+ },
+ "remote": {
+ "http://localhost:4545/run/001_hello.js": "c479db5ea26965387423ca438bb977d0b4788d5901efcef52f69871e4c1048c5"
+ }
+}
+"#);
+
+ // also, add some npm dependency to ensure it doesn't end up in
+ // the redirects as they're currently stored separately
+ temp_dir.write(
+ "main.ts",
+ "import 'http://localhost:4546/run/001_hello.js';\n import 'npm:@denotest/esm-basic';\n",
+ );
+
+ // it should use the echo script instead
+ context
+ .new_command()
+ .args("run main.ts Hi there")
+ .run()
+ .assert_matches_text(
+ concat!(
+ "Download http://localhost:4545/echo.ts\n",
+ "Download http://localhost:4545/npm/registry/@denotest/esm-basic\n",
+ "Download http://localhost:4545/npm/registry/@denotest/esm-basic/1.0.0.tgz\n",
+ "Hi, there",
+ ));
+ util::assertions::assert_wildcard_match(
+ &temp_dir.read_to_string("deno.lock"),
+ r#"{
+ "version": "2",
+ "redirects": {
+ "http://localhost:4546/run/001_hello.js": "http://localhost:4545/echo.ts"
+ },
+ "remote": {
+ "http://localhost:4545/echo.ts": "829eb4d67015a695d70b2a33c78b631b29eea1dbac491a6bfcf394af2a2671c2",
+ "http://localhost:4545/run/001_hello.js": "c479db5ea26965387423ca438bb977d0b4788d5901efcef52f69871e4c1048c5"
+ },
+ "npm": {
+ "specifiers": {
+ "@denotest/esm-basic": "@denotest/esm-basic@1.0.0"
+ },
+ "packages": {
+ "@denotest/esm-basic@1.0.0": {
+ "integrity": "sha512-[WILDCARD]",
+ "dependencies": {}
+ }
+ }
+ }
+}
+"#,
+ );
+}
+
itest!(mts_dmts_mjs {
args: "run subdir/import.mts",
output: "run/mts_dmts_mjs.out",