From 448fe67b7a2142f62332b651f9d215534dceb1f5 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 28 May 2024 14:58:43 -0400 Subject: [PATCH] feat(vendor): support modifying remote files in vendor folder without checksum errors (#23979) Includes: * https://github.com/denoland/deno_graph/pull/486 * https://github.com/denoland/deno_graph/pull/488 * https://github.com/denoland/deno_lockfile/pull/25 * https://github.com/denoland/deno_lockfile/pull/22 * https://github.com/denoland/deno_graph/pull/483 * https://github.com/denoland/deno_graph/pull/470 --- Cargo.lock | 30 +- Cargo.toml | 4 +- cli/Cargo.toml | 10 +- cli/args/lockfile.rs | 34 +- cli/args/mod.rs | 3 +- cli/cache/mod.rs | 2 +- cli/cache/module_info.rs | 6 +- cli/errors.rs | 59 ++- cli/factory.rs | 1 - cli/file_fetcher.rs | 23 +- cli/graph_util.rs | 358 ++++++++++++------ cli/lsp/config.rs | 3 +- cli/lsp/documents.rs | 26 +- cli/lsp/language_server.rs | 8 +- cli/main.rs | 5 - cli/module_loader.rs | 10 +- cli/npm/managed/mod.rs | 7 +- cli/npm/managed/resolution.rs | 11 +- cli/standalone/mod.rs | 2 +- cli/tools/doc.rs | 7 +- cli/tools/info.rs | 25 +- cli/tools/installer.rs | 3 +- cli/tools/registry/graph.rs | 4 +- cli/tools/vendor/build.rs | 14 +- cli/tools/vendor/mod.rs | 1 - cli/tools/vendor/test.rs | 1 - cli/worker.rs | 7 +- tests/integration/bundle_tests.rs | 7 - tests/integration/jsr_tests.rs | 68 ++-- tests/integration/npm_tests.rs | 20 +- tests/integration/run_tests.rs | 96 +---- .../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 + 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 +- tests/specs/jsr/version_not_found/main.out | 3 +- .../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 | 5 + .../auto_discover_lockfile/deno.json | 0 .../auto_discover_lockfile/deno.lock | 0 .../lockfile/auto_discover_lockfile/main.out | 13 + .../lockfile}/auto_discover_lockfile/main.ts | 0 .../checksum_at_redirect/__test__.jsonc | 5 + .../lockfile/checksum_at_redirect/deno.json | 2 + .../lockfile/checksum_at_redirect/deno.lock | 6 + .../lockfile/checksum_at_redirect/run.out | 12 + .../config_file_lock_boolean/__test__.jsonc | 13 + .../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 | 11 + .../019_media_types.ts.out | 1 + .../config_file_lock_path/__test__.jsonc | 13 + .../config_file_lock_path.json | 0 .../config_file_lock_path.out | 11 + .../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_check_ok2.json | 14 + .../lockfile/lock_check_err/__test__.jsonc | 5 + .../lock_check_err}/lock_check_err.json | 0 .../lock_check_err/lock_check_err.out | 11 + .../lockfile/lock_check_err2/__test__.jsonc | 5 + .../lock_check_err2/lock_check_err2.json | 10 + .../lock_check_err2/lock_check_err2.out | 11 + .../lock_dynamic_imports/__test__.jsonc | 5 + .../lock_dynamic_imports.json | 0 .../lock_dynamic_imports.out | 12 + .../lockfile/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 + .../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/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 + .../__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 | 2 +- .../testdata/bundle/lockfile/check_error.out | 4 - tests/testdata/fmt/invalid_data.out | 6 +- .../run/auto_discover_lockfile/main.out | 5 - .../config_file_lock_boolean/true.main.out | 3 - tests/testdata/run/config_file_lock_path.out | 3 - tests/testdata/run/lock_check_err.out | 3 - tests/testdata/run/lock_check_err2.json | 19 +- tests/testdata/run/lock_check_err2.out | 3 - 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 ++- tests/wpt/runner/expectation.json | 10 +- tools/lint.js | 6 +- 141 files changed, 1163 insertions(+), 493 deletions(-) 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/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/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 create mode 100644 tests/specs/lockfile/auto_discover_lockfile/__test__.jsonc rename tests/{testdata/run => specs/lockfile}/auto_discover_lockfile/deno.json (100%) rename tests/{testdata/run => specs/lockfile}/auto_discover_lockfile/deno.lock (100%) create mode 100644 tests/specs/lockfile/auto_discover_lockfile/main.out rename tests/{testdata/run => specs/lockfile}/auto_discover_lockfile/main.ts (100%) 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 create mode 100644 tests/specs/lockfile/config_file_lock_boolean/__test__.jsonc rename tests/{testdata/run => specs/lockfile}/config_file_lock_boolean/deno.lock (100%) rename tests/{testdata/run => specs/lockfile}/config_file_lock_boolean/false.json (100%) rename tests/{testdata/run => specs/lockfile}/config_file_lock_boolean/false.main.out (100%) rename tests/{testdata/run => specs/lockfile}/config_file_lock_boolean/main.ts (100%) rename tests/{testdata/run => specs/lockfile}/config_file_lock_boolean/true.json (100%) create mode 100644 tests/specs/lockfile/config_file_lock_boolean/true.main.out create mode 100644 tests/specs/lockfile/config_file_lock_path/019_media_types.ts.out create mode 100644 tests/specs/lockfile/config_file_lock_path/__test__.jsonc rename tests/{testdata/run => specs/lockfile/config_file_lock_path}/config_file_lock_path.json (100%) create mode 100644 tests/specs/lockfile/config_file_lock_path/config_file_lock_path.out create mode 100644 tests/specs/lockfile/config_file_lock_path/lock_check_err2.json create mode 100644 tests/specs/lockfile/config_file_lock_path/lock_check_err2.out create mode 100644 tests/specs/lockfile/config_file_lock_path/lock_check_ok2.json create mode 100644 tests/specs/lockfile/config_file_lock_path/run/lock_check_ok2.json create mode 100644 tests/specs/lockfile/lock_check_err/__test__.jsonc rename tests/{testdata/run => specs/lockfile/lock_check_err}/lock_check_err.json (100%) create mode 100644 tests/specs/lockfile/lock_check_err/lock_check_err.out create mode 100644 tests/specs/lockfile/lock_check_err2/__test__.jsonc create mode 100644 tests/specs/lockfile/lock_check_err2/lock_check_err2.json create mode 100644 tests/specs/lockfile/lock_check_err2/lock_check_err2.out create mode 100644 tests/specs/lockfile/lock_dynamic_imports/__test__.jsonc rename tests/{testdata/run => specs/lockfile/lock_dynamic_imports}/lock_dynamic_imports.json (100%) create mode 100644 tests/specs/lockfile/lock_dynamic_imports/lock_dynamic_imports.out create mode 100644 tests/specs/lockfile/lock_v2_check_err/__test__.jsonc rename tests/{testdata/run => specs/lockfile/lock_v2_check_err}/lock_v2_check_err.json (100%) create mode 100644 tests/specs/lockfile/lock_v2_check_err/lock_v2_check_err.out create mode 100644 tests/specs/lockfile/lock_v2_check_err2/__test__.jsonc rename tests/{testdata/run => specs/lockfile/lock_v2_check_err2}/lock_v2_check_err2.json (100%) create mode 100644 tests/specs/lockfile/lock_v2_check_err2/lock_v2_check_err2.out create mode 100644 tests/specs/lockfile/lock_v2_dynamic_imports/__test__.jsonc rename tests/{testdata/run => specs/lockfile/lock_v2_dynamic_imports}/lock_v2_dynamic_imports.json (100%) create mode 100644 tests/specs/lockfile/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out delete mode 100644 tests/specs/lockfile/no_lock/fail_initial.out 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 (83%) 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/config_file_lock_boolean/true.main.out delete mode 100644 tests/testdata/run/config_file_lock_path.out delete mode 100644 tests/testdata/run/lock_check_err.out delete mode 100644 tests/testdata/run/lock_check_err2.out 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 0adc22f5cf..41679e2390 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1250,11 +1250,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", @@ -1386,9 +1385,9 @@ dependencies = [ [[package]] name = "deno_doc" -version = "0.135.0" +version = "0.137.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2c39bbe2769f6e8bfba1a99d7656e6994474c48fd2085ed82b59556e9d398dd" +checksum = "57f13d6254b2e05b014e8464647025fa28ef2f385c9c102744a27bd788eb3ebe" dependencies = [ "ammonia", "anyhow", @@ -1411,9 +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 = "80b80fef2bf1b6e14712633975f7f39a3b29b95a5769cafcb959ffa1a84b7680" +checksum = "ebe4b6c67f21a73901e962e92d51065f3c1bb42d2195bca8c2fef9f1808c4c2d" dependencies = [ "anyhow", "base64 0.21.7", @@ -1479,9 +1478,9 @@ dependencies = [ [[package]] name = "deno_graph" -version = "0.75.2" +version = "0.77.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a68ddc87ce88c0a2568277ee6caabf37890128710910416c09cd6f6a8931dba6" +checksum = "e94a8739bb6087061f8419e4c1719459a144ef477ab649dca597a0603290ec82" dependencies = [ "anyhow", "async-trait", @@ -1606,13 +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 = "8835418ae924f25ab20f508bf6240193b22d893519d44432b670a27b8fb1efeb" +checksum = "23120f905aec2deed858820113e089551025b74e261c5c404812cd8e61421379" dependencies = [ "serde", "serde_json", - "sha2", "thiserror", ] @@ -1735,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", @@ -2540,9 +2538,9 @@ dependencies = [ [[package]] name = "eszip" -version = "0.69.0" +version = "0.70.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f606daca1ce18c69ccdabc59aa1c7e077356b8ffcd74e12c7646f545320a2fd" +checksum = "e5f9947a8dd5ba292461c84a5bf142497e2840c4165994c5c3b3ae4954d38fef" dependencies = [ "anyhow", "base64 0.21.7", diff --git a/Cargo.toml b/Cargo.toml index 16db0e15f9..4e6224fe03 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" } @@ -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"] } diff --git a/cli/Cargo.toml b/cli/Cargo.toml index ec02a801c1..bdb1bbfb18 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.135.0", features = ["html", "syntect"] } -deno_emit = "=0.40.3" -deno_graph = { version = "=0.75.2", 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.1" napi_sym.workspace = true async-trait.workspace = true diff --git a/cli/args/lockfile.rs b/cli/args/lockfile.rs index d5ab14432d..79d139487e 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; @@ -13,7 +16,6 @@ use super::InstallFlags; use super::InstallKind; pub use deno_lockfile::Lockfile; -pub use deno_lockfile::LockfileError; pub fn discover( flags: &Flags, @@ -54,6 +56,34 @@ pub fn discover( }, }; - let lockfile = Lockfile::new(filename, flags.lock_write)?; + let lockfile = if flags.lock_write { + Lockfile::new_empty(filename, true) + } else { + 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> { + 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/args/mod.rs b/cli/args/mod.rs index a1ca6d9a71..69adee970d 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -34,8 +34,9 @@ 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 lockfile::LockfileError; pub use package_json::PackageJsonDepsProvider; use deno_ast::ModuleSpecifier; diff --git a/cli/cache/mod.rs b/cli/cache/mod.rs index cee93bac55..bb18b1a132 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/cache/module_info.rs b/cli/cache/module_info.rs index 0e7a97678c..e34b8d2bbd 100644 --- a/cli/cache/module_info.rs +++ b/cli/cache/module_info.rs @@ -150,8 +150,9 @@ pub struct ModuleInfoCacheModuleAnalyzer<'a> { parser: &'a dyn ModuleParser, } +#[async_trait::async_trait(?Send)] impl<'a> deno_graph::ModuleAnalyzer for ModuleInfoCacheModuleAnalyzer<'a> { - fn analyze( + async fn analyze( &self, specifier: &ModuleSpecifier, source: Arc, @@ -176,8 +177,9 @@ impl<'a> deno_graph::ModuleAnalyzer for ModuleInfoCacheModuleAnalyzer<'a> { } // otherwise, get the module info from the parsed source cache + // todo(23858): take advantage of this being async let analyzer = ParserModuleAnalyzer::new(self.parser); - let module_info = analyzer.analyze(specifier, source, media_type)?; + 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/errors.rs b/cli/errors.rs index fce286f159..9fe433f18d 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,56 @@ 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::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", - }, ModuleGraphError::ResolutionError(err) | ModuleGraphError::TypesResolutionError(err) => { get_resolution_error_class(err) } + ModuleGraphError::ModuleError(err) => match err { + ModuleError::InvalidTypeAssertion { .. } => "SyntaxError", + ModuleError::ParseErr(_, diagnostic) => get_diagnostic_class(diagnostic), + ModuleError::UnsupportedMediaType { .. } + | ModuleError::UnsupportedImportAttributeType { .. } => "TypeError", + 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::PackageVersionManifestChecksumIntegrity(..) + | 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", + }, + }, + }, } } diff --git a/cli/factory.rs b/cli/factory.rs index 6cdbff9bba..ce9736e68a 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 eda579b2b4..a8d835d0e7 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 ed56cf9f7a..81ae21d0da 100644 --- a/cli/graph_util.rs +++ b/cli/graph_util.rs @@ -18,6 +18,9 @@ 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_graph::JsrLoadError; +use deno_graph::ModuleLoadError; use deno_runtime::fs_util::specifier_to_file_path; use deno_config::WorkspaceMemberConfig; @@ -51,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 @@ -62,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, @@ -95,8 +105,10 @@ pub fn graph_valid( enhanced_resolution_error_message(resolution_error) ) } - ModuleGraphError::ModuleError(e) => { - enhanced_module_error_message(fs.clone(), e) + ModuleGraphError::ModuleError(error) => { + enhanced_lockfile_error_message(error) + .or_else(|| enhanced_sloppy_imports_error_message(fs, error)) + .unwrap_or_else(|| format!("{}", error)) } }; @@ -152,40 +164,16 @@ 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, - }; +pub fn graph_exit_lock_errors(graph: &ModuleGraph) { + for error in graph.module_errors() { + exit_for_lockfile_error(error); + } +} - // 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); - } +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); } } @@ -201,7 +189,6 @@ pub struct ModuleGraphCreator { options: Arc, npm_resolver: Arc, module_graph_builder: Arc, - lockfile: Option>>, type_checker: Arc, } @@ -210,13 +197,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 +302,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 @@ -426,6 +408,67 @@ impl ModuleGraphBuilder { } } + struct LockfileLocker<'a>(&'a Mutex); + + impl<'a> deno_graph::source::Locker for LockfileLocker<'a> { + fn get_remote_checksum( + &self, + specifier: &deno_ast::ModuleSpecifier, + ) -> Option { + self + .0 + .lock() + .remote() + .get(specifier.as_str()) + .map(|s| LoaderChecksum::new(s.clone())) + } + + 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 + .packages + .jsr + .get(&package_nv.to_string()) + .map(|s| LoaderChecksum::new(s.integrity.clone())) + } + + fn set_pkg_manifest_checksum( + &mut self, + 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() + .insert_package(package_nv.to_string(), checksum.into_string()); + } + } + 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); @@ -442,6 +485,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)); self .build_graph_with_npm_resolution_and_build_options( graph, @@ -459,6 +506,7 @@ impl ModuleGraphBuilder { module_analyzer: &analyzer, reporter: maybe_file_watcher_reporter, resolver: Some(graph_resolver), + locker: locker.as_mut().map(|l| l as _), }, ) .await @@ -468,7 +516,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 @@ -479,8 +527,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 { @@ -492,13 +542,6 @@ 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 (key, value) in &lockfile.content.packages.specifiers { if let Some(key) = key .strip_prefix("jsr:") @@ -512,60 +555,16 @@ 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(), - })?; - } - } } } + let initial_redirects_len = graph.redirects.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; - // 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 @@ -578,6 +577,53 @@ impl ModuleGraphBuilder { npm_resolver.resolve_pending().await?; } + let has_redirects_changed = graph.redirects.len() != initial_redirects_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_package_deps_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()); + } + } + // 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_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 { + self.npm_resolver.as_managed().unwrap().lock(&mut lockfile); + } + } + } + Ok(()) } @@ -658,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, }, ) } @@ -701,28 +748,99 @@ pub fn enhanced_resolution_error_message(error: &ResolutionError) -> String { message } -pub fn enhanced_module_error_message( - fs: Arc, +fn enhanced_sloppy_imports_error_message( + fs: &Arc, error: &ModuleError, -) -> String { - let additional_message = match error { - ModuleError::LoadingErr(specifier, _, _) // ex. "Is a directory" error +) -> Option { + match error { + ModuleError::LoadingErr(specifier, _, ModuleLoadError::Loader(_)) // ex. "Is a directory" error | ModuleError::Missing(specifier, _) => { - SloppyImportsResolver::new(fs).resolve( - specifier, - ResolutionMode::Execution, - ) - .as_suggestion_message() + 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, - }; - if let Some(message) = additional_message { - format!( - "{} {} or run with --unstable-sloppy-imports", - error, message - ) - } else { - format!("{}", error) } } diff --git a/cli/lsp/config.rs b/cli/lsp/config.rs index 89ecb84d85..543200ad1f 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; @@ -1685,7 +1686,7 @@ fn resolve_node_modules_dir( } fn resolve_lockfile_from_path(lockfile_path: PathBuf) -> Option { - match Lockfile::new(lockfile_path, false) { + match read_lockfile_at_path(lockfile_path) { Ok(value) => { if let Ok(specifier) = ModuleSpecifier::from_file_path(&value.filename) { lsp_log!(" Resolved lockfile: \"{}\"", specifier); diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs index ab053336ff..b30217bcb4 100644 --- a/cli/lsp/documents.rs +++ b/cli/lsp/documents.rs @@ -310,7 +310,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, @@ -370,10 +370,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(), self.file_referrer.as_ref(), @@ -481,7 +484,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, @@ -1455,14 +1458,15 @@ 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, file_referrer: Option<&ModuleSpecifier>, 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, @@ -1474,12 +1478,12 @@ fn parse_and_analyze_module( } 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, @@ -1489,7 +1493,7 @@ fn parse_source( } fn analyze_module( - specifier: &ModuleSpecifier, + specifier: ModuleSpecifier, parsed_source_result: &ParsedSourceResult, maybe_headers: Option<&HashMap>, file_referrer: Option<&ModuleSpecifier>, @@ -1511,7 +1515,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/lsp/language_server.rs b/cli/lsp/language_server.rs index 8f37d8b9ca..621f45f96f 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; @@ -247,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, }, )?; @@ -260,8 +262,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/main.rs b/cli/main.rs index 586c2ff10d..e8bea9f546 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -280,11 +280,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/module_loader.rs b/cli/module_loader.rs index 6d8d3e92b9..9be1ceff24 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; @@ -20,7 +21,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; @@ -173,13 +173,9 @@ 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 mut lockfile = lockfile.lock(); - // validate the integrity of all the modules - graph_lock_or_exit(graph, &mut lockfile); - // update it with anything new - lockfile.write().context("Failed writing lockfile.")?; + write_lockfile_if_has_changes(&lockfile.lock())?; } drop(_pb_clear_guard); diff --git a/cli/npm/managed/mod.rs b/cli/npm/managed/mod.rs index 3a2657cfb4..938c16d9a0 100644 --- a/cli/npm/managed/mod.rs +++ b/cli/npm/managed/mod.rs @@ -370,9 +370,8 @@ impl ManagedCliNpmResolver { 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)?; + if let Some(lockfile) = &self.maybe_lockfile { + self.lock(&mut lockfile.lock()); } Ok(()) @@ -401,7 +400,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 1903d339b7..9cea5d305e 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,10 +384,8 @@ fn populate_lockfile_from_snapshot( ); } for package in snapshot.all_packages_for_every_system() { - 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( @@ -403,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/standalone/mod.rs b/cli/standalone/mod.rs index 8f8a78de0b..8c268d9288 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 0ae9a8483f..696823a915 100644 --- a/cli/tools/doc.rs +++ b/cli/tools/doc.rs @@ -8,7 +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_lock_or_exit; +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; @@ -62,6 +62,7 @@ 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, @@ -121,8 +122,8 @@ 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()); + if maybe_lockfile.is_some() { + graph_exit_lock_errors(&graph); } let doc_parser = doc::DocParser::new( diff --git a/cli/tools/info.rs b/cli/tools/info.rs index 19975571b7..b023970f8e 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,11 +25,12 @@ 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; use crate::factory::CliFactory; -use crate::graph_util::graph_lock_or_exit; +use crate::graph_util::graph_exit_lock_errors; use crate::npm::CliNpmResolver; use crate::npm::ManagedCliNpmResolver; use crate::util::checksum; @@ -68,13 +68,10 @@ 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 mut lockfile = lockfile.lock(); - // validate the integrity of all the modules - graph_lock_or_exit(&graph, &mut lockfile); - // update it with anything new - lockfile.write().context("Failed writing lockfile.")?; + graph_exit_lock_errors(&graph); + write_lockfile_if_has_changes(&lockfile.lock())?; } if info_flags.json { @@ -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/installer.rs b/cli/tools/installer.rs index e0cb5a222b..2b518f46f3 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/tools/registry/graph.rs b/cli/tools/registry/graph.rs index d1356df9e4..b363efdb45 100644 --- a/cli/tools/registry/graph.rs +++ b/cli/tools/registry/graph.rs @@ -59,8 +59,8 @@ impl GraphDiagnosticsCollector { 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 5435a0035e..fd7401f777 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,20 +113,17 @@ 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 + 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/cli/tools/vendor/mod.rs b/cli/tools/vendor/mod.rs index cf10b77c75..a8d8000d8f 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, diff --git a/cli/tools/vendor/test.rs b/cli/tools/vendor/test.rs index b4993565dd..830d5f8f0c 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/cli/worker.rs b/cli/worker.rs index bfdeb35689..833f3d5430 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) diff --git a/tests/integration/bundle_tests.rs b/tests/integration/bundle_tests.rs index 0738a0cfec..20f8832932 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 83d696093d..7da0cc5b59 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 @@ -214,7 +219,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 "); @@ -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"); @@ -259,18 +269,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 +300,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 +334,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] @@ -335,39 +351,39 @@ 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 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 + "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); } 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 63547cfce1..923d151be6 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", @@ -1518,7 +1510,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 f3fc18fee2..91370a87c1 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -821,40 +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!(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", - 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", @@ -868,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() @@ -4562,13 +4501,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", @@ -4576,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", @@ -4812,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/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 0000000000..de02f69024 --- /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 0000000000..215c42310d --- /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 0000000000..9af658497b --- /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 0000000000..02601e4d0d --- /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 0000000000..b5bd2dfcf4 --- /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 0000000000..6eebe21985 --- /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 0000000000..02601e4d0d --- /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 0000000000..9b197eb1e4 --- /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 0000000000..8a40cd7fd2 --- /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 0000000000..01d662baae --- /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 0000000000..c26a4aec5f --- /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 0000000000..0114210a45 --- /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 0000000000..5ed43efa9a --- /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/bundle/lockfile/__test__.jsonc b/tests/specs/bundle/lockfile/__test__.jsonc new file mode 100644 index 0000000000..3fe64a28b5 --- /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 0000000000..2b8bdfc96e --- /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 89578cbe26..9943c1ce9f 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/jsr/version_not_found/main.out b/tests/specs/jsr/version_not_found/main.out index 6a32b5d812..081917d715 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/adding_jsr_dep/__test__.jsonc b/tests/specs/lockfile/adding_jsr_dep/__test__.jsonc new file mode 100644 index 0000000000..905aaf49c3 --- /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 0000000000..c0fe70808d --- /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 0000000000..c37f65adc2 --- /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 0000000000..0ac0075265 --- /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 0000000000..4293c7dfed --- /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 0000000000..b07f2cdfd3 --- /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 0000000000..905aaf49c3 --- /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 0000000000..06492d2ec5 --- /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 0000000000..b26a08521d --- /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 0000000000..e78ea355a5 --- /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 0000000000..0f4a388c60 --- /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 0000000000..1576e29e25 --- /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 0000000000..905aaf49c3 --- /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 0000000000..c0fe70808d --- /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 0000000000..b3bfef8156 --- /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 0000000000..5d5567dc06 --- /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 0000000000..6042b1cb9a --- /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 0000000000..b07f2cdfd3 --- /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 0000000000..7556f22667 --- /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 0000000000..525b6bc7e9 --- /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 0000000000..d53beedbd4 --- /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 0000000000..75cddd8267 --- /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 0000000000..f00cefa6a8 --- /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 0000000000..70c38c9661 --- /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/lockfile/auto_discover_lockfile/__test__.jsonc b/tests/specs/lockfile/auto_discover_lockfile/__test__.jsonc new file mode 100644 index 0000000000..50213381ad --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/auto_discover_lockfile/deno.json similarity index 100% rename from tests/testdata/run/auto_discover_lockfile/deno.json rename to tests/specs/lockfile/auto_discover_lockfile/deno.json diff --git a/tests/testdata/run/auto_discover_lockfile/deno.lock b/tests/specs/lockfile/auto_discover_lockfile/deno.lock similarity index 100% rename from tests/testdata/run/auto_discover_lockfile/deno.lock rename to tests/specs/lockfile/auto_discover_lockfile/deno.lock diff --git a/tests/specs/lockfile/auto_discover_lockfile/main.out b/tests/specs/lockfile/auto_discover_lockfile/main.out new file mode 100644 index 0000000000..aa24320d14 --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/auto_discover_lockfile/main.ts similarity index 100% rename from tests/testdata/run/auto_discover_lockfile/main.ts rename to tests/specs/lockfile/auto_discover_lockfile/main.ts 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 0000000000..66d9850da6 --- /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 0000000000..2c63c08510 --- /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 0000000000..12e84cd019 --- /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 0000000000..75a34777f5 --- /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. diff --git a/tests/specs/lockfile/config_file_lock_boolean/__test__.jsonc b/tests/specs/lockfile/config_file_lock_boolean/__test__.jsonc new file mode 100644 index 0000000000..65679a1c81 --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/config_file_lock_boolean/deno.lock similarity index 100% rename from tests/testdata/run/config_file_lock_boolean/deno.lock rename to tests/specs/lockfile/config_file_lock_boolean/deno.lock diff --git a/tests/testdata/run/config_file_lock_boolean/false.json b/tests/specs/lockfile/config_file_lock_boolean/false.json similarity index 100% rename from tests/testdata/run/config_file_lock_boolean/false.json rename to tests/specs/lockfile/config_file_lock_boolean/false.json diff --git a/tests/testdata/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/testdata/run/config_file_lock_boolean/false.main.out rename to tests/specs/lockfile/config_file_lock_boolean/false.main.out diff --git a/tests/testdata/run/config_file_lock_boolean/main.ts b/tests/specs/lockfile/config_file_lock_boolean/main.ts similarity index 100% rename from tests/testdata/run/config_file_lock_boolean/main.ts rename to tests/specs/lockfile/config_file_lock_boolean/main.ts diff --git a/tests/testdata/run/config_file_lock_boolean/true.json b/tests/specs/lockfile/config_file_lock_boolean/true.json similarity index 100% rename from tests/testdata/run/config_file_lock_boolean/true.json rename to tests/specs/lockfile/config_file_lock_boolean/true.json diff --git a/tests/specs/lockfile/config_file_lock_boolean/true.main.out b/tests/specs/lockfile/config_file_lock_boolean/true.main.out new file mode 100644 index 0000000000..11dfc07408 --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/config_file_lock_path/019_media_types.ts.out b/tests/specs/lockfile/config_file_lock_path/019_media_types.ts.out new file mode 100644 index 0000000000..b3e94678c5 --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/config_file_lock_path/__test__.jsonc b/tests/specs/lockfile/config_file_lock_path/__test__.jsonc new file mode 100644 index 0000000000..defb113b38 --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/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/lockfile/config_file_lock_path/config_file_lock_path.json diff --git a/tests/specs/lockfile/config_file_lock_path/config_file_lock_path.out b/tests/specs/lockfile/config_file_lock_path/config_file_lock_path.out new file mode 100644 index 0000000000..1383d945d0 --- /dev/null +++ b/tests/specs/lockfile/config_file_lock_path/config_file_lock_path.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/lockfile/config_file_lock_path/lock_check_err2.json b/tests/specs/lockfile/config_file_lock_path/lock_check_err2.json new file mode 100644 index 0000000000..a59cbc9e30 --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/config_file_lock_path/lock_check_err2.out b/tests/specs/lockfile/config_file_lock_path/lock_check_err2.out new file mode 100644 index 0000000000..1383d945d0 --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/config_file_lock_path/lock_check_ok2.json b/tests/specs/lockfile/config_file_lock_path/lock_check_ok2.json new file mode 100644 index 0000000000..14d8b71171 --- /dev/null +++ b/tests/specs/lockfile/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/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 0000000000..e1bf67c8f4 --- /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/lockfile/lock_check_err/__test__.jsonc b/tests/specs/lockfile/lock_check_err/__test__.jsonc new file mode 100644 index 0000000000..7b4777fadd --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/lock_check_err/lock_check_err.json similarity index 100% rename from tests/testdata/run/lock_check_err.json rename to tests/specs/lockfile/lock_check_err/lock_check_err.json diff --git a/tests/specs/lockfile/lock_check_err/lock_check_err.out b/tests/specs/lockfile/lock_check_err/lock_check_err.out new file mode 100644 index 0000000000..25d22490da --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/lock_check_err2/__test__.jsonc b/tests/specs/lockfile/lock_check_err2/__test__.jsonc new file mode 100644 index 0000000000..adcf816c40 --- /dev/null +++ b/tests/specs/lockfile/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/specs/lockfile/lock_check_err2/lock_check_err2.json b/tests/specs/lockfile/lock_check_err2/lock_check_err2.json new file mode 100644 index 0000000000..a59cbc9e30 --- /dev/null +++ b/tests/specs/lockfile/lock_check_err2/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/lockfile/lock_check_err2/lock_check_err2.out b/tests/specs/lockfile/lock_check_err2/lock_check_err2.out new file mode 100644 index 0000000000..1383d945d0 --- /dev/null +++ b/tests/specs/lockfile/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/specs/lockfile/lock_dynamic_imports/__test__.jsonc b/tests/specs/lockfile/lock_dynamic_imports/__test__.jsonc new file mode 100644 index 0000000000..54b9932959 --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/lock_dynamic_imports/lock_dynamic_imports.json similarity index 100% rename from tests/testdata/run/lock_dynamic_imports.json rename to tests/specs/lockfile/lock_dynamic_imports/lock_dynamic_imports.json diff --git a/tests/specs/lockfile/lock_dynamic_imports/lock_dynamic_imports.out b/tests/specs/lockfile/lock_dynamic_imports/lock_dynamic_imports.out new file mode 100644 index 0000000000..2b8bdfc96e --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/lock_v2_check_err/__test__.jsonc b/tests/specs/lockfile/lock_v2_check_err/__test__.jsonc new file mode 100644 index 0000000000..b58fddeecc --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/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/lockfile/lock_v2_check_err/lock_v2_check_err.json diff --git a/tests/specs/lockfile/lock_v2_check_err/lock_v2_check_err.out b/tests/specs/lockfile/lock_v2_check_err/lock_v2_check_err.out new file mode 100644 index 0000000000..25d22490da --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/lock_v2_check_err2/__test__.jsonc b/tests/specs/lockfile/lock_v2_check_err2/__test__.jsonc new file mode 100644 index 0000000000..bb02b41e25 --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/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/lockfile/lock_v2_check_err2/lock_v2_check_err2.json diff --git a/tests/specs/lockfile/lock_v2_check_err2/lock_v2_check_err2.out b/tests/specs/lockfile/lock_v2_check_err2/lock_v2_check_err2.out new file mode 100644 index 0000000000..1383d945d0 --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/lock_v2_dynamic_imports/__test__.jsonc b/tests/specs/lockfile/lock_v2_dynamic_imports/__test__.jsonc new file mode 100644 index 0000000000..8d8913431b --- /dev/null +++ b/tests/specs/lockfile/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/lockfile/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/lockfile/lock_v2_dynamic_imports/lock_v2_dynamic_imports.json diff --git a/tests/specs/lockfile/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out b/tests/specs/lockfile/lock_v2_dynamic_imports/lock_v2_dynamic_imports.out new file mode 100644 index 0000000000..2b8bdfc96e --- /dev/null +++ b/tests/specs/lockfile/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/specs/lockfile/no_lock/__test__.jsonc b/tests/specs/lockfile/no_lock/__test__.jsonc index 60bbd17e0a..75821ac64c 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 351efc9709..83e4de242b 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 e69de29bb2..e2d66c027b 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 4c2b044238..0d67cd4788 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 6a808c0a54..0000000000 --- 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 b036611937..3133777802 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 b5039c2d6d..1332dfa8f1 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/npm/lock_file_integrity_failure/__test__.jsonc b/tests/specs/npm/lock_file_integrity_failure/__test__.jsonc new file mode 100644 index 0000000000..d2f1b06a2c --- /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 83% rename from tests/testdata/npm/lock_file/main.out rename to tests/specs/npm/lock_file_integrity_failure/main.out index dead1a623c..741edd9d22 100644 --- a/tests/testdata/npm/lock_file/main.out +++ b/tests/specs/npm/lock_file_integrity_failure/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/bundle/lockfile/check_error.out b/tests/testdata/bundle/lockfile/check_error.out deleted file mode 100644 index 9299bc27e1..0000000000 --- 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/fmt/invalid_data.out b/tests/testdata/fmt/invalid_data.out index dee00fcc5e..d0869e9ee8 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/auto_discover_lockfile/main.out b/tests/testdata/run/auto_discover_lockfile/main.out deleted file mode 100644 index 28f4724e98..0000000000 --- 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/config_file_lock_boolean/true.main.out b/tests/testdata/run/config_file_lock_boolean/true.main.out deleted file mode 100644 index 313c0eb0cc..0000000000 --- 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/config_file_lock_path.out b/tests/testdata/run/config_file_lock_path.out deleted file mode 100644 index 97d35337f7..0000000000 --- a/tests/testdata/run/config_file_lock_path.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: [WILDCARD]lock_check_err2.json diff --git a/tests/testdata/run/lock_check_err.out b/tests/testdata/run/lock_check_err.out deleted file mode 100644 index e4cc7b81a1..0000000000 --- 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.json b/tests/testdata/run/lock_check_err2.json index a59cbc9e30..14d8b71171 100644 --- a/tests/testdata/run/lock_check_err2.json +++ b/tests/testdata/run/lock_check_err2.json @@ -1,10 +1,13 @@ { - "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" + "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_check_err2.out b/tests/testdata/run/lock_check_err2.out deleted file mode 100644 index 065c7434b8..0000000000 --- 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 diff --git a/tests/testdata/run/lock_dynamic_imports.out b/tests/testdata/run/lock_dynamic_imports.out deleted file mode 100644 index acc65c8e6b..0000000000 --- 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 28ad01cf44..0000000000 --- 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 3d82cba273..0000000000 --- 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 36c2c9b5cc..0000000000 --- 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 bf5de64dc4..bd2d02f3fe 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)| { diff --git a/tests/wpt/runner/expectation.json b/tests/wpt/runner/expectation.json index 44979f08bf..cd11b1d42c 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, diff --git a/tools/lint.js b/tools/lint.js index d4fb4e9a01..ec8e147a51 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,