From 03f47e6cf05cb1237bc13733a0c13496f84064b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 20 Nov 2024 18:01:56 +0000 Subject: [PATCH 01/11] fix(fmt): formatting of .svelte files (#26948) Closes https://github.com/denoland/deno/issues/26690 Closes https://github.com/denoland/deno/issues/26324 --- Cargo.lock | 4 ++-- cli/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 52bb39ee83..bc386c9571 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4562,9 +4562,9 @@ dependencies = [ [[package]] name = "markup_fmt" -version = "0.15.0" +version = "0.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ebae65c91eab3d42231232bf48107f351e5a8d511454927218c53aeb68bbdb6f" +checksum = "f303c36143671ac6c54112eb5aa95649b169dae783fdb6ead2c0e88b408c425c" dependencies = [ "aho-corasick", "css_dataset", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 16f39e9d48..ae573827b1 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -129,7 +129,7 @@ libz-sys.workspace = true log = { workspace = true, features = ["serde"] } lsp-types.workspace = true malva = "=0.11.0" -markup_fmt = "=0.15.0" +markup_fmt = "=0.16.0" memmem.workspace = true monch.workspace = true notify.workspace = true From 8f7279862249d8274dbef2cf5f48d13f0c0ab53a Mon Sep 17 00:00:00 2001 From: Keith Tan Date: Wed, 20 Nov 2024 20:59:43 +0100 Subject: [PATCH 02/11] feat(lint): Add checked files list to the JSON output(#26936) Fixes #26930 --- cli/tools/lint/reporters.rs | 18 ++++++++++++++++++ tests/specs/lint/json/expected_json.out | 5 +++++ .../stdin_json/expected_from_stdin_json.out | 5 ++++- .../with_report_config_override.out | 5 ++++- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/cli/tools/lint/reporters.rs b/cli/tools/lint/reporters.rs index bf80be9f20..18bc1216a6 100644 --- a/cli/tools/lint/reporters.rs +++ b/cli/tools/lint/reporters.rs @@ -175,6 +175,7 @@ struct JsonLintReporter { version: u8, diagnostics: Vec, errors: Vec, + checked_files: Vec, } impl JsonLintReporter { @@ -183,6 +184,7 @@ impl JsonLintReporter { version: JSON_SCHEMA_VERSION, diagnostics: Vec::new(), errors: Vec::new(), + checked_files: Vec::new(), } } } @@ -209,6 +211,17 @@ impl LintReporter for JsonLintReporter { code: d.code().to_string(), hint: d.hint().map(|h| h.to_string()), }); + + let file_path = d + .specifier + .to_file_path() + .unwrap() + .to_string_lossy() + .to_string(); + + if !self.checked_files.contains(&file_path) { + self.checked_files.push(file_path); + } } fn visit_error(&mut self, file_path: &str, err: &AnyError) { @@ -216,10 +229,15 @@ impl LintReporter for JsonLintReporter { file_path: file_path.to_string(), message: err.to_string(), }); + + if !self.checked_files.contains(&file_path.to_string()) { + self.checked_files.push(file_path.to_string()); + } } fn close(&mut self, _check_count: usize) { sort_diagnostics(&mut self.diagnostics); + self.checked_files.sort(); let json = serde_json::to_string_pretty(&self); #[allow(clippy::print_stdout)] { diff --git a/tests/specs/lint/json/expected_json.out b/tests/specs/lint/json/expected_json.out index 6712c891a5..242c47cf56 100644 --- a/tests/specs/lint/json/expected_json.out +++ b/tests/specs/lint/json/expected_json.out @@ -61,5 +61,10 @@ "file_path": "[WILDCARD]malformed.js", "message": "Expected '{', got 'B' at [WILDCARD]malformed.js:4:16\n\n export class A B C\n ~" } + ], + "checked_files": [ + "[WILDCARD]file1.js", + "[WILDCARD]file2.ts", + "[WILDCARD]malformed.js" ] } diff --git a/tests/specs/lint/stdin_json/expected_from_stdin_json.out b/tests/specs/lint/stdin_json/expected_from_stdin_json.out index 5788248aa2..8db157bccb 100644 --- a/tests/specs/lint/stdin_json/expected_from_stdin_json.out +++ b/tests/specs/lint/stdin_json/expected_from_stdin_json.out @@ -20,5 +20,8 @@ "hint": [WILDCARD] } ], - "errors": [] + "errors": [], + "checked_files": [ + "[WILDCARD]main.ts" + ] } diff --git a/tests/specs/lint/with_report_config_override/with_report_config_override.out b/tests/specs/lint/with_report_config_override/with_report_config_override.out index ad32e31236..fb873f187e 100644 --- a/tests/specs/lint/with_report_config_override/with_report_config_override.out +++ b/tests/specs/lint/with_report_config_override/with_report_config_override.out @@ -38,5 +38,8 @@ "hint": "If this is intentional, prefix it with an underscore like `_add`" } ], - "errors": [] + "errors": [], + "checked_files": [ + "[WILDCARD]a.ts" + ] } From cf49599359d480b0716b34a8f0a27f37e2f51e48 Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Wed, 20 Nov 2024 13:24:04 -0800 Subject: [PATCH 03/11] feat: permission stack traces in ops (#26938) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit improves permission prompts by adding an option to print a full trace of where the permissions is being requested. Due to big performance hint of stack trace collection, this is only enabled when `DENO_TRACE_PERMISSIONS` env var is present. Closes https://github.com/denoland/deno/issues/20756 --------- Co-authored-by: Bartek Iwańczuk --- cli/args/flags.rs | 41 ++++++------ cli/args/mod.rs | 4 ++ cli/ops/bench.rs | 2 +- cli/ops/testing.rs | 2 +- cli/worker.rs | 4 ++ ext/fetch/lib.rs | 4 +- ext/ffi/call.rs | 4 +- ext/ffi/callback.rs | 2 +- ext/ffi/dlfcn.rs | 2 +- ext/ffi/repr.rs | 42 ++++++------ ext/fs/ops.rs | 88 ++++++++++++------------- ext/kv/lib.rs | 2 +- ext/napi/lib.rs | 2 +- ext/net/ops.rs | 12 ++-- ext/net/ops_tls.rs | 6 +- ext/net/ops_unix.rs | 12 ++-- ext/node/ops/fs.rs | 18 ++--- ext/node/ops/http.rs | 2 +- ext/node/ops/inspector.rs | 4 +- ext/node/ops/os/mod.rs | 14 ++-- ext/node/ops/process.rs | 2 +- ext/node/ops/require.rs | 18 ++--- ext/node/ops/worker_threads.rs | 2 +- ext/websocket/lib.rs | 4 +- runtime/ops/fs_events.rs | 2 +- runtime/ops/os/mod.rs | 30 ++++----- runtime/ops/permissions.rs | 2 +- runtime/ops/process.rs | 8 +-- runtime/ops/worker_host.rs | 2 +- runtime/permissions/prompter.rs | 62 ++++++++++++----- runtime/web_worker.rs | 8 +++ runtime/worker.rs | 7 ++ tests/integration/run_tests.rs | 52 ++++++++++++++- tests/testdata/run/permissions_trace.ts | 9 +++ 34 files changed, 294 insertions(+), 181 deletions(-) create mode 100644 tests/testdata/run/permissions_trace.ts diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 5d85f2861c..567d4adfb9 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -1160,25 +1160,26 @@ static ENV_VARIABLES_HELP: &str = cstr!( Docs: https://docs.deno.com/go/env-vars DENO_AUTH_TOKENS A semi-colon separated list of bearer tokens and hostnames - to use when fetching remote modules from private repositories - (e.g. "abcde12345@deno.land;54321edcba@github.com") - DENO_CERT Load certificate authorities from PEM encoded file - DENO_DIR Set the cache directory - DENO_INSTALL_ROOT Set deno install's output directory - (defaults to $HOME/.deno/bin) - DENO_NO_PACKAGE_JSON Disables auto-resolution of package.json - DENO_NO_UPDATE_CHECK Set to disable checking if a newer Deno version is available - DENO_TLS_CA_STORE Comma-separated list of order dependent certificate stores. - Possible values: "system", "mozilla". - (defaults to "mozilla") - HTTP_PROXY Proxy address for HTTP requests - (module downloads, fetch) - HTTPS_PROXY Proxy address for HTTPS requests - (module downloads, fetch) - NO_COLOR Set to disable color - NO_PROXY Comma-separated list of hosts which do not use a proxy - (module downloads, fetch) - NPM_CONFIG_REGISTRY URL to use for the npm registry."# + to use when fetching remote modules from private repositories + (e.g. "abcde12345@deno.land;54321edcba@github.com") + DENO_CERT Load certificate authorities from PEM encoded file + DENO_DIR Set the cache directory + DENO_INSTALL_ROOT Set deno install's output directory + (defaults to $HOME/.deno/bin) + DENO_NO_PACKAGE_JSON Disables auto-resolution of package.json + DENO_NO_UPDATE_CHECK Set to disable checking if a newer Deno version is available + DENO_TLS_CA_STORE Comma-separated list of order dependent certificate stores. + DENO_TRACE_PERMISSIONS Environmental variable to enable stack traces in permission prompts. + Possible values: "system", "mozilla". + (defaults to "mozilla") + HTTP_PROXY Proxy address for HTTP requests + (module downloads, fetch) + HTTPS_PROXY Proxy address for HTTPS requests + (module downloads, fetch) + NO_COLOR Set to disable color + NO_PROXY Comma-separated list of hosts which do not use a proxy + (module downloads, fetch) + NPM_CONFIG_REGISTRY URL to use for the npm registry."# ); static DENO_HELP: &str = cstr!( @@ -3346,6 +3347,8 @@ fn permission_args(app: Command, requires: Option<&'static str>) -> Command { --deny-run | --deny-run="whoami,ps" --deny-ffi[=<...] (Unstable) Deny loading dynamic libraries. Optionally specify denied directories or files. --deny-ffi | --deny-ffi="./libfoo.so" + DENO_TRACE_PERMISSIONS Environmental variable to enable stack traces in permission prompts. + DENO_TRACE_PERMISSIONS=1 deno run main.ts "#)) .arg( { diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 21df6cf115..bbdfa478c1 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1912,6 +1912,10 @@ pub fn resolve_no_prompt(flags: &PermissionFlags) -> bool { flags.no_prompt || has_flag_env_var("DENO_NO_PROMPT") } +pub fn has_trace_permissions_enabled() -> bool { + has_flag_env_var("DENO_TRACE_PERMISSIONS") +} + pub fn has_flag_env_var(name: &str) -> bool { let value = env::var(name); matches!(value.as_ref().map(|s| s.as_str()), Ok("1")) diff --git a/cli/ops/bench.rs b/cli/ops/bench.rs index 1f4a4bd9b5..a7c788a189 100644 --- a/cli/ops/bench.rs +++ b/cli/ops/bench.rs @@ -51,7 +51,7 @@ fn op_bench_get_origin(state: &mut OpState) -> String { #[derive(Clone)] struct PermissionsHolder(Uuid, PermissionsContainer); -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_pledge_test_permissions( state: &mut OpState, diff --git a/cli/ops/testing.rs b/cli/ops/testing.rs index 00aafb8286..3c6936971a 100644 --- a/cli/ops/testing.rs +++ b/cli/ops/testing.rs @@ -46,7 +46,7 @@ deno_core::extension!(deno_test, #[derive(Clone)] struct PermissionsHolder(Uuid, PermissionsContainer); -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_pledge_test_permissions( state: &mut OpState, diff --git a/cli/worker.rs b/cli/worker.rs index 0b07bb4bf3..5761571c5c 100644 --- a/cli/worker.rs +++ b/cli/worker.rs @@ -617,6 +617,8 @@ impl CliMainWorkerFactory { origin_storage_dir, stdio, skip_op_registration: shared.options.skip_op_registration, + enable_stack_trace_arg_in_ops: crate::args::has_trace_permissions_enabled( + ), }; let mut worker = MainWorker::bootstrap_from_options( @@ -813,6 +815,8 @@ fn create_web_worker_callback( strace_ops: shared.options.strace_ops.clone(), close_on_idle: args.close_on_idle, maybe_worker_metadata: args.maybe_worker_metadata, + enable_stack_trace_arg_in_ops: crate::args::has_trace_permissions_enabled( + ), }; WebWorker::bootstrap_from_options(services, options) diff --git a/ext/fetch/lib.rs b/ext/fetch/lib.rs index c8e93b9fea..303c955622 100644 --- a/ext/fetch/lib.rs +++ b/ext/fetch/lib.rs @@ -397,7 +397,7 @@ impl FetchPermissions for deno_permissions::PermissionsContainer { } } -#[op2] +#[op2(stack_trace)] #[serde] #[allow(clippy::too_many_arguments)] pub fn op_fetch( @@ -866,7 +866,7 @@ fn default_true() -> bool { true } -#[op2] +#[op2(stack_trace)] #[smi] pub fn op_fetch_custom_client( state: &mut OpState, diff --git a/ext/ffi/call.rs b/ext/ffi/call.rs index bbff0ee48f..c964071a09 100644 --- a/ext/ffi/call.rs +++ b/ext/ffi/call.rs @@ -287,7 +287,7 @@ fn ffi_call( } } -#[op2(async)] +#[op2(async, stack_trace)] #[serde] pub fn op_ffi_call_ptr_nonblocking( scope: &mut v8::HandleScope, @@ -385,7 +385,7 @@ pub fn op_ffi_call_nonblocking( }) } -#[op2(reentrant)] +#[op2(reentrant, stack_trace)] #[serde] pub fn op_ffi_call_ptr( scope: &mut v8::HandleScope, diff --git a/ext/ffi/callback.rs b/ext/ffi/callback.rs index 29583c800c..eff14503d1 100644 --- a/ext/ffi/callback.rs +++ b/ext/ffi/callback.rs @@ -561,7 +561,7 @@ pub struct RegisterCallbackArgs { result: NativeType, } -#[op2] +#[op2(stack_trace)] pub fn op_ffi_unsafe_callback_create( state: &mut OpState, scope: &mut v8::HandleScope<'scope>, diff --git a/ext/ffi/dlfcn.rs b/ext/ffi/dlfcn.rs index 26d1b71e9f..e1bb121d8c 100644 --- a/ext/ffi/dlfcn.rs +++ b/ext/ffi/dlfcn.rs @@ -124,7 +124,7 @@ pub struct FfiLoadArgs { symbols: HashMap, } -#[op2] +#[op2(stack_trace)] pub fn op_ffi_load<'scope, FP>( scope: &mut v8::HandleScope<'scope>, state: Rc>, diff --git a/ext/ffi/repr.rs b/ext/ffi/repr.rs index fd8a2c8e70..eea15f3e97 100644 --- a/ext/ffi/repr.rs +++ b/ext/ffi/repr.rs @@ -49,7 +49,7 @@ pub enum ReprError { Permission(#[from] deno_permissions::PermissionCheckError), } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_ffi_ptr_create( state: &mut OpState, #[bigint] ptr_number: usize, @@ -63,7 +63,7 @@ where Ok(ptr_number as *mut c_void) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_ffi_ptr_equals( state: &mut OpState, a: *const c_void, @@ -78,7 +78,7 @@ where Ok(a == b) } -#[op2] +#[op2(stack_trace)] pub fn op_ffi_ptr_of( state: &mut OpState, #[anybuffer] buf: *const u8, @@ -92,7 +92,7 @@ where Ok(buf as *mut c_void) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_ffi_ptr_of_exact( state: &mut OpState, buf: v8::Local, @@ -112,7 +112,7 @@ where Ok(buf.as_ptr() as _) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_ffi_ptr_offset( state: &mut OpState, ptr: *mut c_void, @@ -142,7 +142,7 @@ unsafe extern "C" fn noop_deleter_callback( ) { } -#[op2(fast)] +#[op2(fast, stack_trace)] #[bigint] pub fn op_ffi_ptr_value( state: &mut OpState, @@ -157,7 +157,7 @@ where Ok(ptr as usize) } -#[op2] +#[op2(stack_trace)] pub fn op_ffi_get_buf( scope: &mut v8::HandleScope<'scope>, state: &mut OpState, @@ -189,7 +189,7 @@ where Ok(array_buffer) } -#[op2] +#[op2(stack_trace)] pub fn op_ffi_buf_copy_into( state: &mut OpState, src: *mut c_void, @@ -219,7 +219,7 @@ where } } -#[op2] +#[op2(stack_trace)] pub fn op_ffi_cstr_read( scope: &mut v8::HandleScope<'scope>, state: &mut OpState, @@ -244,7 +244,7 @@ where Ok(value) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_ffi_read_bool( state: &mut OpState, ptr: *mut c_void, @@ -264,7 +264,7 @@ where Ok(unsafe { ptr::read_unaligned::(ptr.offset(offset) as *const bool) }) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_ffi_read_u8( state: &mut OpState, ptr: *mut c_void, @@ -286,7 +286,7 @@ where }) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_ffi_read_i8( state: &mut OpState, ptr: *mut c_void, @@ -308,7 +308,7 @@ where }) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_ffi_read_u16( state: &mut OpState, ptr: *mut c_void, @@ -330,7 +330,7 @@ where }) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_ffi_read_i16( state: &mut OpState, ptr: *mut c_void, @@ -352,7 +352,7 @@ where }) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_ffi_read_u32( state: &mut OpState, ptr: *mut c_void, @@ -372,7 +372,7 @@ where Ok(unsafe { ptr::read_unaligned::(ptr.offset(offset) as *const u32) }) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_ffi_read_i32( state: &mut OpState, ptr: *mut c_void, @@ -392,7 +392,7 @@ where Ok(unsafe { ptr::read_unaligned::(ptr.offset(offset) as *const i32) }) } -#[op2(fast)] +#[op2(fast, stack_trace)] #[bigint] pub fn op_ffi_read_u64( state: &mut OpState, @@ -418,7 +418,7 @@ where Ok(value) } -#[op2(fast)] +#[op2(fast, stack_trace)] #[bigint] pub fn op_ffi_read_i64( state: &mut OpState, @@ -444,7 +444,7 @@ where Ok(value) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_ffi_read_f32( state: &mut OpState, ptr: *mut c_void, @@ -464,7 +464,7 @@ where Ok(unsafe { ptr::read_unaligned::(ptr.offset(offset) as *const f32) }) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_ffi_read_f64( state: &mut OpState, ptr: *mut c_void, @@ -484,7 +484,7 @@ where Ok(unsafe { ptr::read_unaligned::(ptr.offset(offset) as *const f64) }) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_ffi_read_ptr( state: &mut OpState, ptr: *mut c_void, diff --git a/ext/fs/ops.rs b/ext/fs/ops.rs index e3a511f8e7..7a9778c485 100644 --- a/ext/fs/ops.rs +++ b/ext/fs/ops.rs @@ -146,7 +146,7 @@ fn map_permission_error( } } -#[op2] +#[op2(stack_trace)] #[string] pub fn op_fs_cwd

(state: &mut OpState) -> Result where @@ -161,7 +161,7 @@ where Ok(path_str) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_fs_chdir

( state: &mut OpState, #[string] directory: &str, @@ -188,7 +188,7 @@ where state.borrow::().umask(mask).context("umask") } -#[op2] +#[op2(stack_trace)] #[smi] pub fn op_fs_open_sync

( state: &mut OpState, @@ -215,7 +215,7 @@ where Ok(rid) } -#[op2(async)] +#[op2(async, stack_trace)] #[smi] pub async fn op_fs_open_async

( state: Rc>, @@ -243,7 +243,7 @@ where Ok(rid) } -#[op2] +#[op2(stack_trace)] pub fn op_fs_mkdir_sync

( state: &mut OpState, #[string] path: String, @@ -266,7 +266,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] pub async fn op_fs_mkdir_async

( state: Rc>, #[string] path: String, @@ -291,7 +291,7 @@ where Ok(()) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_fs_chmod_sync

( state: &mut OpState, #[string] path: String, @@ -308,7 +308,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] pub async fn op_fs_chmod_async

( state: Rc>, #[string] path: String, @@ -328,7 +328,7 @@ where Ok(()) } -#[op2] +#[op2(stack_trace)] pub fn op_fs_chown_sync

( state: &mut OpState, #[string] path: String, @@ -347,7 +347,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] pub async fn op_fs_chown_async

( state: Rc>, #[string] path: String, @@ -368,7 +368,7 @@ where Ok(()) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_fs_remove_sync

( state: &mut OpState, #[string] path: &str, @@ -388,7 +388,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] pub async fn op_fs_remove_async

( state: Rc>, #[string] path: String, @@ -419,7 +419,7 @@ where Ok(()) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_fs_copy_file_sync

( state: &mut OpState, #[string] from: &str, @@ -439,7 +439,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] pub async fn op_fs_copy_file_async

( state: Rc>, #[string] from: String, @@ -463,7 +463,7 @@ where Ok(()) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_fs_stat_sync

( state: &mut OpState, #[string] path: String, @@ -482,7 +482,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] #[serde] pub async fn op_fs_stat_async

( state: Rc>, @@ -504,7 +504,7 @@ where Ok(SerializableStat::from(stat)) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_fs_lstat_sync

( state: &mut OpState, #[string] path: String, @@ -523,7 +523,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] #[serde] pub async fn op_fs_lstat_async

( state: Rc>, @@ -545,7 +545,7 @@ where Ok(SerializableStat::from(stat)) } -#[op2] +#[op2(stack_trace)] #[string] pub fn op_fs_realpath_sync

( state: &mut OpState, @@ -568,7 +568,7 @@ where Ok(path_string) } -#[op2(async)] +#[op2(async, stack_trace)] #[string] pub async fn op_fs_realpath_async

( state: Rc>, @@ -596,7 +596,7 @@ where Ok(path_string) } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_fs_read_dir_sync

( state: &mut OpState, @@ -615,7 +615,7 @@ where Ok(entries) } -#[op2(async)] +#[op2(async, stack_trace)] #[serde] pub async fn op_fs_read_dir_async

( state: Rc>, @@ -640,7 +640,7 @@ where Ok(entries) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_fs_rename_sync

( state: &mut OpState, #[string] oldpath: String, @@ -661,7 +661,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] pub async fn op_fs_rename_async

( state: Rc>, #[string] oldpath: String, @@ -686,7 +686,7 @@ where Ok(()) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_fs_link_sync

( state: &mut OpState, #[string] oldpath: &str, @@ -708,7 +708,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] pub async fn op_fs_link_async

( state: Rc>, #[string] oldpath: String, @@ -734,7 +734,7 @@ where Ok(()) } -#[op2] +#[op2(stack_trace)] pub fn op_fs_symlink_sync

( state: &mut OpState, #[string] oldpath: &str, @@ -758,7 +758,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] pub async fn op_fs_symlink_async

( state: Rc>, #[string] oldpath: String, @@ -786,7 +786,7 @@ where Ok(()) } -#[op2] +#[op2(stack_trace)] #[string] pub fn op_fs_read_link_sync

( state: &mut OpState, @@ -806,7 +806,7 @@ where Ok(target_string) } -#[op2(async)] +#[op2(async, stack_trace)] #[string] pub async fn op_fs_read_link_async

( state: Rc>, @@ -831,7 +831,7 @@ where Ok(target_string) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_fs_truncate_sync

( state: &mut OpState, #[string] path: &str, @@ -851,7 +851,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] pub async fn op_fs_truncate_async

( state: Rc>, #[string] path: String, @@ -875,7 +875,7 @@ where Ok(()) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_fs_utime_sync

( state: &mut OpState, #[string] path: &str, @@ -896,7 +896,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] pub async fn op_fs_utime_async

( state: Rc>, #[string] path: String, @@ -927,7 +927,7 @@ where Ok(()) } -#[op2] +#[op2(stack_trace)] #[string] pub fn op_fs_make_temp_dir_sync

( state: &mut OpState, @@ -969,7 +969,7 @@ where .context("tmpdir") } -#[op2(async)] +#[op2(async, stack_trace)] #[string] pub async fn op_fs_make_temp_dir_async

( state: Rc>, @@ -1015,7 +1015,7 @@ where .context("tmpdir") } -#[op2] +#[op2(stack_trace)] #[string] pub fn op_fs_make_temp_file_sync

( state: &mut OpState, @@ -1063,7 +1063,7 @@ where .context("tmpfile") } -#[op2(async)] +#[op2(async, stack_trace)] #[string] pub async fn op_fs_make_temp_file_async

( state: Rc>, @@ -1235,7 +1235,7 @@ fn tmp_name( Ok(path) } -#[op2] +#[op2(stack_trace)] pub fn op_fs_write_file_sync

( state: &mut OpState, #[string] path: String, @@ -1261,7 +1261,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] #[allow(clippy::too_many_arguments)] pub async fn op_fs_write_file_async

( state: Rc>, @@ -1315,7 +1315,7 @@ where Ok(()) } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_fs_read_file_sync

( state: &mut OpState, @@ -1336,7 +1336,7 @@ where Ok(buf.into()) } -#[op2(async)] +#[op2(async, stack_trace)] #[serde] pub async fn op_fs_read_file_async

( state: Rc>, @@ -1378,7 +1378,7 @@ where Ok(buf.into()) } -#[op2] +#[op2(stack_trace)] #[string] pub fn op_fs_read_file_text_sync

( state: &mut OpState, @@ -1399,7 +1399,7 @@ where Ok(str) } -#[op2(async)] +#[op2(async, stack_trace)] #[string] pub async fn op_fs_read_file_text_async

( state: Rc>, diff --git a/ext/kv/lib.rs b/ext/kv/lib.rs index 5392b97210..ce7509721a 100644 --- a/ext/kv/lib.rs +++ b/ext/kv/lib.rs @@ -178,7 +178,7 @@ pub enum KvErrorKind { InvalidRange, } -#[op2(async)] +#[op2(async, stack_trace)] #[smi] async fn op_kv_database_open( state: Rc>, diff --git a/ext/napi/lib.rs b/ext/napi/lib.rs index 88b8c238df..6db6af48a2 100644 --- a/ext/napi/lib.rs +++ b/ext/napi/lib.rs @@ -530,7 +530,7 @@ static NAPI_LOADED_MODULES: std::sync::LazyLock< RwLock>, > = std::sync::LazyLock::new(|| RwLock::new(HashMap::new())); -#[op2(reentrant)] +#[op2(reentrant, stack_trace)] fn op_napi_open( scope: &mut v8::HandleScope<'scope>, isolate: *mut v8::Isolate, diff --git a/ext/net/ops.rs b/ext/net/ops.rs index 9a8b70f0f6..8d62bdeb4d 100644 --- a/ext/net/ops.rs +++ b/ext/net/ops.rs @@ -182,7 +182,7 @@ pub async fn op_net_recv_udp( Ok((nread, IpAddr::from(remote_addr))) } -#[op2(async)] +#[op2(async, stack_trace)] #[number] pub async fn op_net_send_udp( state: Rc>, @@ -343,7 +343,7 @@ pub async fn op_net_set_multi_ttl_udp( Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] #[serde] pub async fn op_net_connect_tcp( state: Rc>, @@ -401,7 +401,7 @@ impl Resource for UdpSocketResource { } } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_net_listen_tcp( state: &mut OpState, @@ -501,7 +501,7 @@ where Ok((rid, IpAddr::from(local_addr))) } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_net_listen_udp( state: &mut OpState, @@ -516,7 +516,7 @@ where net_listen_udp::(state, addr, reuse_address, loopback) } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_node_unstable_net_listen_udp( state: &mut OpState, @@ -601,7 +601,7 @@ pub struct NameServer { port: u16, } -#[op2(async)] +#[op2(async, stack_trace)] #[serde] pub async fn op_dns_resolve( state: Rc>, diff --git a/ext/net/ops_tls.rs b/ext/net/ops_tls.rs index c7d65dd85e..4d2073fd09 100644 --- a/ext/net/ops_tls.rs +++ b/ext/net/ops_tls.rs @@ -251,7 +251,7 @@ pub fn op_tls_cert_resolver_resolve_error( lookup.resolve(sni, Err(error)) } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_tls_start( state: Rc>, @@ -340,7 +340,7 @@ where Ok((rid, IpAddr::from(local_addr), IpAddr::from(remote_addr))) } -#[op2(async)] +#[op2(async, stack_trace)] #[serde] pub async fn op_net_connect_tls( state: Rc>, @@ -445,7 +445,7 @@ pub struct ListenTlsArgs { load_balanced: bool, } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_net_listen_tls( state: &mut OpState, diff --git a/ext/net/ops_unix.rs b/ext/net/ops_unix.rs index 04ae84906f..483dc99b40 100644 --- a/ext/net/ops_unix.rs +++ b/ext/net/ops_unix.rs @@ -85,7 +85,7 @@ pub async fn op_net_accept_unix( Ok((rid, local_addr_path, remote_addr_path)) } -#[op2(async)] +#[op2(async, stack_trace)] #[serde] pub async fn op_net_connect_unix( state: Rc>, @@ -118,7 +118,7 @@ where Ok((rid, local_addr_path, remote_addr_path)) } -#[op2(async)] +#[op2(async, stack_trace)] #[serde] pub async fn op_net_recv_unixpacket( state: Rc>, @@ -140,7 +140,7 @@ pub async fn op_net_recv_unixpacket( Ok((nread, path)) } -#[op2(async)] +#[op2(async, stack_trace)] #[number] pub async fn op_net_send_unixpacket( state: Rc>, @@ -171,7 +171,7 @@ where Ok(nwritten) } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_net_listen_unix( state: &mut OpState, @@ -222,7 +222,7 @@ where Ok((rid, pathname)) } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_net_listen_unixpacket( state: &mut OpState, @@ -235,7 +235,7 @@ where net_listen_unixpacket::(state, path) } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_node_unstable_net_listen_unixpacket( state: &mut OpState, diff --git a/ext/node/ops/fs.rs b/ext/node/ops/fs.rs index 9c0e4e1ccf..58a688a1fe 100644 --- a/ext/node/ops/fs.rs +++ b/ext/node/ops/fs.rs @@ -26,7 +26,7 @@ pub enum FsError { Fs(#[from] deno_io::fs::FsError), } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_node_fs_exists_sync

( state: &mut OpState, #[string] path: String, @@ -41,7 +41,7 @@ where Ok(fs.exists_sync(&path)) } -#[op2(async)] +#[op2(async, stack_trace)] pub async fn op_node_fs_exists

( state: Rc>, #[string] path: String, @@ -60,7 +60,7 @@ where Ok(fs.exists_async(path).await?) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_node_cp_sync

( state: &mut OpState, #[string] path: &str, @@ -81,7 +81,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] pub async fn op_node_cp

( state: Rc>, #[string] path: String, @@ -117,7 +117,7 @@ pub struct StatFs { pub ffree: u64, } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_node_statfs

( state: Rc>, @@ -258,7 +258,7 @@ where } } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_node_lutimes_sync

( state: &mut OpState, #[string] path: &str, @@ -279,7 +279,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] pub async fn op_node_lutimes

( state: Rc>, #[string] path: String, @@ -305,7 +305,7 @@ where Ok(()) } -#[op2] +#[op2(stack_trace)] pub fn op_node_lchown_sync

( state: &mut OpState, #[string] path: String, @@ -323,7 +323,7 @@ where Ok(()) } -#[op2(async)] +#[op2(async, stack_trace)] pub async fn op_node_lchown

( state: Rc>, #[string] path: String, diff --git a/ext/node/ops/http.rs b/ext/node/ops/http.rs index 69571078fe..f4adb94060 100644 --- a/ext/node/ops/http.rs +++ b/ext/node/ops/http.rs @@ -49,7 +49,7 @@ use std::cmp::min; use tokio::io::AsyncReadExt; use tokio::io::AsyncWriteExt; -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_node_http_request

( state: &mut OpState, diff --git a/ext/node/ops/inspector.rs b/ext/node/ops/inspector.rs index 34a7e004c1..9986aeb197 100644 --- a/ext/node/ops/inspector.rs +++ b/ext/node/ops/inspector.rs @@ -20,7 +20,7 @@ pub fn op_inspector_enabled() -> bool { false } -#[op2] +#[op2(stack_trace)] pub fn op_inspector_open

( _state: &mut OpState, _port: Option, @@ -85,7 +85,7 @@ struct JSInspectorSession { impl GarbageCollected for JSInspectorSession {} -#[op2] +#[op2(stack_trace)] #[cppgc] pub fn op_inspector_connect<'s, P>( isolate: *mut v8::Isolate, diff --git a/ext/node/ops/os/mod.rs b/ext/node/ops/os/mod.rs index d291277ad4..ddb2a70c64 100644 --- a/ext/node/ops/os/mod.rs +++ b/ext/node/ops/os/mod.rs @@ -21,7 +21,7 @@ pub enum OsError { FailedToGetUserInfo(#[source] std::io::Error), } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_node_os_get_priority

( state: &mut OpState, pid: u32, @@ -37,7 +37,7 @@ where priority::get_priority(pid).map_err(OsError::Priority) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_node_os_set_priority

( state: &mut OpState, pid: u32, @@ -193,7 +193,7 @@ fn get_user_info(_uid: u32) -> Result { }) } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_node_os_user_info

( state: &mut OpState, @@ -212,7 +212,7 @@ where get_user_info(uid) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_geteuid

( state: &mut OpState, ) -> Result @@ -233,7 +233,7 @@ where Ok(euid) } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_getegid

( state: &mut OpState, ) -> Result @@ -254,7 +254,7 @@ where Ok(egid) } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_cpus

(state: &mut OpState) -> Result, OsError> where @@ -268,7 +268,7 @@ where cpus::cpu_info().ok_or(OsError::FailedToGetCpuInfo) } -#[op2] +#[op2(stack_trace)] #[string] pub fn op_homedir

( state: &mut OpState, diff --git a/ext/node/ops/process.rs b/ext/node/ops/process.rs index 282567226e..45c599bee2 100644 --- a/ext/node/ops/process.rs +++ b/ext/node/ops/process.rs @@ -45,7 +45,7 @@ fn kill(pid: i32, _sig: i32) -> i32 { } } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_node_process_kill( state: &mut OpState, #[smi] pid: i32, diff --git a/ext/node/ops/require.rs b/ext/node/ops/require.rs index 06c034fd50..f8de07a3be 100644 --- a/ext/node/ops/require.rs +++ b/ext/node/ops/require.rs @@ -125,7 +125,7 @@ pub fn op_require_init_paths() -> Vec { vec![] } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_require_node_module_paths

( state: &mut OpState, @@ -295,7 +295,7 @@ pub fn op_require_path_is_absolute(#[string] p: String) -> bool { PathBuf::from(p).is_absolute() } -#[op2(fast)] +#[op2(fast, stack_trace)] pub fn op_require_stat

( state: &mut OpState, #[string] path: String, @@ -317,7 +317,7 @@ where Ok(-1) } -#[op2] +#[op2(stack_trace)] #[string] pub fn op_require_real_path

( state: &mut OpState, @@ -381,7 +381,7 @@ pub fn op_require_path_basename( } } -#[op2] +#[op2(stack_trace)] #[string] pub fn op_require_try_self_parent_path

( state: &mut OpState, @@ -412,7 +412,7 @@ where Ok(None) } -#[op2] +#[op2(stack_trace)] #[string] pub fn op_require_try_self

( state: &mut OpState, @@ -476,7 +476,7 @@ where } } -#[op2] +#[op2(stack_trace)] #[string] pub fn op_require_read_file

( state: &mut OpState, @@ -507,7 +507,7 @@ pub fn op_require_as_file_path(#[string] file_or_url: String) -> String { file_or_url } -#[op2] +#[op2(stack_trace)] #[string] pub fn op_require_resolve_exports

( state: &mut OpState, @@ -583,7 +583,7 @@ pub fn op_require_is_maybe_cjs( loader.is_maybe_cjs(&url) } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_require_read_package_scope

( state: &mut OpState, @@ -604,7 +604,7 @@ where .flatten() } -#[op2] +#[op2(stack_trace)] #[string] pub fn op_require_package_imports_resolve

( state: &mut OpState, diff --git a/ext/node/ops/worker_threads.rs b/ext/node/ops/worker_threads.rs index d2e5758826..37a7b477d0 100644 --- a/ext/node/ops/worker_threads.rs +++ b/ext/node/ops/worker_threads.rs @@ -45,7 +45,7 @@ pub enum WorkerThreadsFilenameError { } // todo(dsherret): we should remove this and do all this work inside op_create_worker -#[op2] +#[op2(stack_trace)] #[string] pub fn op_worker_threads_filename

( state: &mut OpState, diff --git a/ext/websocket/lib.rs b/ext/websocket/lib.rs index a5734271cf..5aef1a7a55 100644 --- a/ext/websocket/lib.rs +++ b/ext/websocket/lib.rs @@ -148,7 +148,7 @@ impl Resource for WsCancelResource { // This op is needed because creating a WS instance in JavaScript is a sync // operation and should throw error when permissions are not fulfilled, // but actual op that connects WS is async. -#[op2] +#[op2(stack_trace)] #[smi] pub fn op_ws_check_permission_and_cancel_handle( state: &mut OpState, @@ -443,7 +443,7 @@ fn populate_common_request_headers( Ok(request) } -#[op2(async)] +#[op2(async, stack_trace)] #[serde] pub async fn op_ws_create( state: Rc>, diff --git a/runtime/ops/fs_events.rs b/runtime/ops/fs_events.rs index c8e0228bc0..a91722f91a 100644 --- a/runtime/ops/fs_events.rs +++ b/runtime/ops/fs_events.rs @@ -162,7 +162,7 @@ fn start_watcher( Ok(()) } -#[op2] +#[op2(stack_trace)] #[smi] fn op_fs_events_open( state: &mut OpState, diff --git a/runtime/ops/os/mod.rs b/runtime/ops/os/mod.rs index 74c708c532..b8ebc88bed 100644 --- a/runtime/ops/os/mod.rs +++ b/runtime/ops/os/mod.rs @@ -87,7 +87,7 @@ pub enum OsError { Io(#[from] std::io::Error), } -#[op2] +#[op2(stack_trace)] #[string] fn op_exec_path(state: &mut OpState) -> Result { let current_exe = env::current_exe().unwrap(); @@ -103,7 +103,7 @@ fn op_exec_path(state: &mut OpState) -> Result { .map_err(OsError::InvalidUtf8) } -#[op2(fast)] +#[op2(fast, stack_trace)] fn op_set_env( state: &mut OpState, #[string] key: &str, @@ -123,7 +123,7 @@ fn op_set_env( Ok(()) } -#[op2] +#[op2(stack_trace)] #[serde] fn op_env( state: &mut OpState, @@ -132,7 +132,7 @@ fn op_env( Ok(env::vars().collect()) } -#[op2] +#[op2(stack_trace)] #[string] fn op_get_env( state: &mut OpState, @@ -159,7 +159,7 @@ fn op_get_env( Ok(r) } -#[op2(fast)] +#[op2(fast, stack_trace)] fn op_delete_env( state: &mut OpState, #[string] key: String, @@ -189,7 +189,7 @@ fn op_exit(state: &mut OpState) { crate::exit(code) } -#[op2] +#[op2(stack_trace)] #[serde] fn op_loadavg( state: &mut OpState, @@ -200,7 +200,7 @@ fn op_loadavg( Ok(sys_info::loadavg()) } -#[op2] +#[op2(stack_trace, stack_trace)] #[string] fn op_hostname( state: &mut OpState, @@ -211,7 +211,7 @@ fn op_hostname( Ok(sys_info::hostname()) } -#[op2] +#[op2(stack_trace)] #[string] fn op_os_release( state: &mut OpState, @@ -222,7 +222,7 @@ fn op_os_release( Ok(sys_info::os_release()) } -#[op2] +#[op2(stack_trace)] #[serde] fn op_network_interfaces( state: &mut OpState, @@ -274,7 +274,7 @@ impl From for NetworkInterface { } } -#[op2] +#[op2(stack_trace)] #[serde] fn op_system_memory_info( state: &mut OpState, @@ -286,7 +286,7 @@ fn op_system_memory_info( } #[cfg(not(windows))] -#[op2] +#[op2(stack_trace)] #[smi] fn op_gid( state: &mut OpState, @@ -302,7 +302,7 @@ fn op_gid( } #[cfg(windows)] -#[op2] +#[op2(stack_trace)] #[smi] fn op_gid( state: &mut OpState, @@ -314,7 +314,7 @@ fn op_gid( } #[cfg(not(windows))] -#[op2] +#[op2(stack_trace)] #[smi] fn op_uid( state: &mut OpState, @@ -330,7 +330,7 @@ fn op_uid( } #[cfg(windows)] -#[op2] +#[op2(stack_trace)] #[smi] fn op_uid( state: &mut OpState, @@ -519,7 +519,7 @@ fn os_uptime(state: &mut OpState) -> Result { Ok(sys_info::os_uptime()) } -#[op2(fast)] +#[op2(fast, stack_trace)] #[number] fn op_os_uptime( state: &mut OpState, diff --git a/runtime/ops/permissions.rs b/runtime/ops/permissions.rs index 9ad963f3bc..b5f9e284df 100644 --- a/runtime/ops/permissions.rs +++ b/runtime/ops/permissions.rs @@ -99,7 +99,7 @@ pub fn op_revoke_permission( Ok(PermissionStatus::from(perm)) } -#[op2] +#[op2(stack_trace)] #[serde] pub fn op_request_permission( state: &mut OpState, diff --git a/runtime/ops/process.rs b/runtime/ops/process.rs index ee2f660dcc..83d9317d32 100644 --- a/runtime/ops/process.rs +++ b/runtime/ops/process.rs @@ -802,7 +802,7 @@ fn get_requires_allow_all_env_vars(env: &RunEnv) -> Vec<&str> { found_envs } -#[op2] +#[op2(stack_trace)] #[serde] fn op_spawn_child( state: &mut OpState, @@ -844,7 +844,7 @@ async fn op_spawn_wait( Ok(result) } -#[op2] +#[op2(stack_trace)] #[serde] fn op_spawn_sync( state: &mut OpState, @@ -928,7 +928,7 @@ mod deprecated { stderr_rid: Option, } - #[op2] + #[op2(stack_trace)] #[serde] pub fn op_run( state: &mut OpState, @@ -1129,7 +1129,7 @@ mod deprecated { } } - #[op2(fast)] + #[op2(fast, stack_trace)] pub fn op_kill( state: &mut OpState, #[smi] pid: i32, diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs index 521284a6a0..131bad1962 100644 --- a/runtime/ops/worker_host.rs +++ b/runtime/ops/worker_host.rs @@ -133,7 +133,7 @@ pub enum CreateWorkerError { } /// Create worker as the host -#[op2] +#[op2(stack_trace)] #[serde] fn op_create_worker( state: &mut OpState, diff --git a/runtime/permissions/prompter.rs b/runtime/permissions/prompter.rs index 168a845a29..0272744cc2 100644 --- a/runtime/permissions/prompter.rs +++ b/runtime/permissions/prompter.rs @@ -1,5 +1,7 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use crate::is_standalone; +use deno_core::error::JsStackFrame; use deno_core::parking_lot::Mutex; use deno_terminal::colors; use once_cell::sync::Lazy; @@ -10,8 +12,6 @@ use std::io::StderrLock; use std::io::StdinLock; use std::io::Write as IoWrite; -use crate::is_standalone; - /// Helper function to make control characters visible so users can see the underlying filename. fn escape_control_characters(s: &str) -> std::borrow::Cow { if !s.contains(|c: char| c.is_ascii_control() || c.is_control()) { @@ -53,6 +53,13 @@ static MAYBE_BEFORE_PROMPT_CALLBACK: Lazy>> = static MAYBE_AFTER_PROMPT_CALLBACK: Lazy>> = Lazy::new(|| Mutex::new(None)); +static MAYBE_CURRENT_STACKTRACE: Lazy>>> = + Lazy::new(|| Mutex::new(None)); + +pub fn set_current_stacktrace(trace: Vec) { + *MAYBE_CURRENT_STACKTRACE.lock() = Some(trace); +} + pub fn permission_prompt( message: &str, flag: &str, @@ -62,9 +69,10 @@ pub fn permission_prompt( if let Some(before_callback) = MAYBE_BEFORE_PROMPT_CALLBACK.lock().as_mut() { before_callback(); } + let stack = MAYBE_CURRENT_STACKTRACE.lock().take(); let r = PERMISSION_PROMPTER .lock() - .prompt(message, flag, api_name, is_unary); + .prompt(message, flag, api_name, is_unary, stack); if let Some(after_callback) = MAYBE_AFTER_PROMPT_CALLBACK.lock().as_mut() { after_callback(); } @@ -92,6 +100,7 @@ pub trait PermissionPrompter: Send + Sync { name: &str, api_name: Option<&str>, is_unary: bool, + stack: Option>, ) -> PromptResponse; } @@ -298,6 +307,7 @@ impl PermissionPrompter for TtyPrompter { name: &str, api_name: Option<&str>, is_unary: bool, + stack: Option>, ) -> PromptResponse { if !std::io::stdin().is_terminal() || !std::io::stderr().is_terminal() { return PromptResponse::Deny; @@ -340,7 +350,7 @@ impl PermissionPrompter for TtyPrompter { }; // output everything in one shot to make the tests more reliable - { + let stack_lines_count = { let mut output = String::new(); write!(&mut output, "┏ {PERMISSION_EMOJI} ").unwrap(); write!(&mut output, "{}", colors::bold("Deno requests ")).unwrap(); @@ -354,6 +364,27 @@ impl PermissionPrompter for TtyPrompter { ) .unwrap(); } + let stack_lines_count = if let Some(stack) = stack { + let len = stack.len(); + for (idx, frame) in stack.into_iter().enumerate() { + writeln!( + &mut output, + "┃ {} {}", + colors::gray(if idx != len - 1 { "├─" } else { "└─" }), + colors::gray(deno_core::error::format_frame::< + deno_core::error::NoAnsiColors, + >(&frame)) + ) + .unwrap(); + } + len + } else { + writeln!( + &mut output, + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.", + ).unwrap(); + 1 + }; let msg = format!( "Learn more at: {}", colors::cyan_with_underline(&format!( @@ -372,7 +403,9 @@ impl PermissionPrompter for TtyPrompter { write!(&mut output, " {opts} > ").unwrap(); stderr_lock.write_all(output.as_bytes()).unwrap(); - } + + stack_lines_count + }; let value = loop { // Clear stdin each time we loop around in case the user accidentally pasted @@ -391,30 +424,24 @@ impl PermissionPrompter for TtyPrompter { if result.is_err() || input.len() != 1 { break PromptResponse::Deny; }; + + let clear_n = if api_name.is_some() { 5 } else { 4 } + stack_lines_count; + match input.as_bytes()[0] as char { 'y' | 'Y' => { - clear_n_lines( - &mut stderr_lock, - if api_name.is_some() { 5 } else { 4 }, - ); + clear_n_lines(&mut stderr_lock, clear_n); let msg = format!("Granted {message}."); writeln!(stderr_lock, "✅ {}", colors::bold(&msg)).unwrap(); break PromptResponse::Allow; } 'n' | 'N' | '\x1b' => { - clear_n_lines( - &mut stderr_lock, - if api_name.is_some() { 5 } else { 4 }, - ); + clear_n_lines(&mut stderr_lock, clear_n); let msg = format!("Denied {message}."); writeln!(stderr_lock, "❌ {}", colors::bold(&msg)).unwrap(); break PromptResponse::Deny; } 'A' if is_unary => { - clear_n_lines( - &mut stderr_lock, - if api_name.is_some() { 5 } else { 4 }, - ); + clear_n_lines(&mut stderr_lock, clear_n); let msg = format!("Granted all {name} access."); writeln!(stderr_lock, "✅ {}", colors::bold(&msg)).unwrap(); break PromptResponse::AllowAll; @@ -475,6 +502,7 @@ pub mod tests { _name: &str, _api_name: Option<&str>, _is_unary: bool, + _stack: Option>, ) -> PromptResponse { if STUB_PROMPT_VALUE.load(Ordering::SeqCst) { PromptResponse::Allow diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index a282d11b9a..214ae59c80 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -373,6 +373,7 @@ pub struct WebWorkerOptions { pub strace_ops: Option>, pub close_on_idle: bool, pub maybe_worker_metadata: Option, + pub enable_stack_trace_arg_in_ops: bool, } /// This struct is an implementation of `Worker` Web API @@ -585,6 +586,13 @@ impl WebWorker { validate_import_attributes_callback, )), import_assertions_support: deno_core::ImportAssertionsSupport::Error, + maybe_op_stack_trace_callback: if options.enable_stack_trace_arg_in_ops { + Some(Box::new(|stack| { + deno_permissions::prompter::set_current_stacktrace(stack) + })) + } else { + None + }, ..Default::default() }); diff --git a/runtime/worker.rs b/runtime/worker.rs index 97cbb6428f..65fc99c766 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -207,6 +207,7 @@ pub struct WorkerOptions { pub cache_storage_dir: Option, pub origin_storage_dir: Option, pub stdio: Stdio, + pub enable_stack_trace_arg_in_ops: bool, } impl Default for WorkerOptions { @@ -231,6 +232,7 @@ impl Default for WorkerOptions { create_params: Default::default(), bootstrap: Default::default(), stdio: Default::default(), + enable_stack_trace_arg_in_ops: false, } } } @@ -544,6 +546,11 @@ impl MainWorker { ) as Box, ) }), + maybe_op_stack_trace_callback: if options.enable_stack_trace_arg_in_ops { + Some(Box::new(|stack| { + deno_permissions::prompter::set_current_stacktrace(stack) + })) + } else { None }, ..Default::default() }); diff --git a/tests/integration/run_tests.rs b/tests/integration/run_tests.rs index c97b700c5d..18cded90cb 100644 --- a/tests/integration/run_tests.rs +++ b/tests/integration/run_tests.rs @@ -179,6 +179,7 @@ fn _090_run_permissions_request() { console.expect(concat!( "┏ ⚠️ Deno requests run access to \"ls\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-run\r\n", "┠─ Run again with --allow-run to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all run permissions)", @@ -189,6 +190,7 @@ fn _090_run_permissions_request() { console.expect(concat!( "┏ ⚠️ Deno requests run access to \"cat\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-run\r\n", "┠─ Run again with --allow-run to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all run permissions)", @@ -210,6 +212,7 @@ fn _090_run_permissions_request_sync() { console.expect(concat!( "┏ ⚠️ Deno requests run access to \"ls\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-run\r\n", "┠─ Run again with --allow-run to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all run permissions)", @@ -220,6 +223,7 @@ fn _090_run_permissions_request_sync() { console.expect(concat!( "┏ ⚠️ Deno requests run access to \"cat\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-run\r\n", "┠─ Run again with --allow-run to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all run permissions)", @@ -242,6 +246,7 @@ fn permissions_prompt_allow_all() { console.expect(concat!( "┏ ⚠️ Deno requests run access to \"FOO\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-run\r\n", "┠─ Run again with --allow-run to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all run permissions)", @@ -253,6 +258,7 @@ fn permissions_prompt_allow_all() { console.expect(concat!( "┏ ⚠️ Deno requests read access to \"FOO\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-read\r\n", "┠─ Run again with --allow-read to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all read permissions)", @@ -264,6 +270,7 @@ fn permissions_prompt_allow_all() { console.expect(concat!( "┏ ⚠️ Deno requests write access to \"FOO\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-write\r\n", "┠─ Run again with --allow-write to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all write permissions)", @@ -275,6 +282,7 @@ fn permissions_prompt_allow_all() { console.expect(concat!( "┏ ⚠️ Deno requests net access to \"foo\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-net\r\n", "┠─ Run again with --allow-net to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all net permissions)", @@ -286,6 +294,7 @@ fn permissions_prompt_allow_all() { console.expect(concat!( "┏ ⚠️ Deno requests env access to \"FOO\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-env\r\n", "┠─ Run again with --allow-env to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all env permissions)", @@ -297,6 +306,7 @@ fn permissions_prompt_allow_all() { console.expect(concat!( "┏ ⚠️ Deno requests sys access to \"loadavg\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-sys\r\n", "┠─ Run again with --allow-sys to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all sys permissions)", @@ -308,6 +318,7 @@ fn permissions_prompt_allow_all() { console.expect(concat!( "┏ ⚠️ Deno requests ffi access to \"FOO\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-ffi\r\n", "┠─ Run again with --allow-ffi to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all ffi permissions)", @@ -328,6 +339,7 @@ fn permissions_prompt_allow_all_2() { // "env" permissions console.expect(concat!( "┏ ⚠️ Deno requests env access to \"FOO\".\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-env\r\n", "┠─ Run again with --allow-env to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all env permissions)", @@ -340,6 +352,7 @@ fn permissions_prompt_allow_all_2() { console.expect(concat!( "┏ ⚠️ Deno requests sys access to \"loadavg\".\r\n", "┠─ Requested by `Deno.loadavg()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-sys\r\n", "┠─ Run again with --allow-sys to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all sys permissions)", @@ -352,6 +365,7 @@ fn permissions_prompt_allow_all_2() { console.expect(concat!( "┏ ⚠️ Deno requests read access to .\r\n", "┠─ Requested by `Deno.cwd()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-read\r\n", "┠─ Run again with --allow-read to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all read permissions)", @@ -372,6 +386,7 @@ fn permissions_prompt_allow_all_lowercase_a() { console.expect(concat!( "┏ ⚠️ Deno requests run access to \"FOO\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-run\r\n", "┠─ Run again with --allow-run to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all run permissions)", @@ -406,6 +421,7 @@ fn permissions_cache() { "prompt\r\n", "┏ ⚠️ Deno requests read access to \"foo\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-read\r\n", "┠─ Run again with --allow-read to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all read permissions)", @@ -418,6 +434,32 @@ fn permissions_cache() { }); } +#[test] +fn permissions_trace() { + TestContext::default() + .new_command() + .env("DENO_TRACE_PERMISSIONS", "1") + .args_vec(["run", "--quiet", "run/permissions_trace.ts"]) + .with_pty(|mut console| { + let text = console.read_until("Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all sys permissions)"); + test_util::assertions::assert_wildcard_match(&text, concat!( + "┏ ⚠️ Deno requests sys access to \"hostname\".\r\n", + "┠─ Requested by `Deno.hostname()` API.\r\n", + "┃ ├─ Object.hostname (ext:runtime/30_os.js:43:10)\r\n", + "┃ ├─ foo (file://[WILDCARD]/run/permissions_trace.ts:2:8)\r\n", + "┃ ├─ bar (file://[WILDCARD]/run/permissions_trace.ts:6:3)\r\n", + "┃ └─ file://[WILDCARD]/run/permissions_trace.ts:9:1\r\n", + "┠─ Learn more at: https://docs.deno.com/go/--allow-sys\r\n", + "┠─ Run again with --allow-sys to bypass this prompt.\r\n", + "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all sys permissions)", + )); + + console.human_delay(); + console.write_line_raw("y"); + console.expect("✅ Granted sys access to \"hostname\"."); + }); +} + itest!(lock_write_fetch { args: "run --quiet --allow-import --allow-read --allow-write --allow-env --allow-run run/lock_write_fetch/main.ts", @@ -1512,6 +1554,7 @@ mod permissions { console.expect(concat!( "┏ ⚠️ Deno requests read access to \"foo\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-read\r\n", "┠─ Run again with --allow-read to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all read permissions)", @@ -1521,6 +1564,7 @@ mod permissions { console.expect(concat!( "┏ ⚠️ Deno requests read access to \"bar\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-read\r\n", "┠─ Run again with --allow-read to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all read permissions)", @@ -1542,6 +1586,7 @@ mod permissions { console.expect(concat!( "┏ ⚠️ Deno requests read access to \"foo\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-read\r\n", "┠─ Run again with --allow-read to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all read permissions)", @@ -1551,6 +1596,7 @@ mod permissions { console.expect(concat!( "┏ ⚠️ Deno requests read access to \"bar\".\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-read\r\n", "┠─ Run again with --allow-read to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all read permissions)", @@ -1572,6 +1618,7 @@ mod permissions { console.expect(concat!( "┏ ⚠️ Deno requests read access.\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-read\r\n", "┠─ Run again with --allow-read to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all read permissions)", @@ -1596,6 +1643,7 @@ mod permissions { console.expect(concat!( "┏ ⚠️ Deno requests read access.\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-read\r\n", "┠─ Run again with --allow-read to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all read permissions)", @@ -1673,6 +1721,7 @@ fn issue9750() { console.expect(concat!( "┏ ⚠️ Deno requests env access.\r\n", "┠─ Requested by `Deno.permissions.request()` API.\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-env\r\n", "┠─ Run again with --allow-env to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all env permissions)", @@ -1682,6 +1731,7 @@ fn issue9750() { console.expect("Denied env access."); console.expect(concat!( "┏ ⚠️ Deno requests env access to \"SECRET\".\r\n", + "┠─ To see a stack trace for this prompt, set the DENO_TRACE_PERMISSIONS environmental variable.\r\n", "┠─ Learn more at: https://docs.deno.com/go/--allow-env\r\n", "┠─ Run again with --allow-env to bypass this prompt.\r\n", "┗ Allow? [y/n/A] (y = yes, allow; n = no, deny; A = allow all env permissions)", @@ -2723,7 +2773,7 @@ fn stdio_streams_are_locked_in_permission_prompt() { console.human_delay(); console.write_line_raw("y"); // We ensure that nothing gets written here between the permission prompt and this text, despire the delay - console.expect_raw_next(format!("y{newline}\x1b[5A\x1b[0J✅ Granted read access to \"")); + console.expect_raw_next(format!("y{newline}\x1b[6A\x1b[0J✅ Granted read access to \"")); // Back to spamming! console.expect(malicious_output); diff --git a/tests/testdata/run/permissions_trace.ts b/tests/testdata/run/permissions_trace.ts new file mode 100644 index 0000000000..d061ac6bf8 --- /dev/null +++ b/tests/testdata/run/permissions_trace.ts @@ -0,0 +1,9 @@ +function foo() { + Deno.hostname(); +} + +function bar() { + foo(); +} + +bar(); From 0670206a2cf7751e6927912bddc06ce0b5839b52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Wed, 20 Nov 2024 23:21:41 +0000 Subject: [PATCH 04/11] chore: use forked sqlformat-rs (#26952) Some crucial fixes have not yet been released, so I forked it for the time being. --- Cargo.lock | 25 +++++++++++++------------ cli/Cargo.toml | 4 ++-- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc386c9571..8850726cec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1232,6 +1232,7 @@ dependencies = [ "deno_resolver", "deno_runtime", "deno_semver", + "deno_sqlformat", "deno_task_shell", "deno_terminal 0.2.0", "deno_tower_lsp", @@ -1291,7 +1292,6 @@ dependencies = [ "sha2", "shell-escape", "spki", - "sqlformat", "strsim", "tar", "tempfile", @@ -2147,6 +2147,18 @@ dependencies = [ "url", ] +[[package]] +name = "deno_sqlformat" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e196799ec0cc240fac1fb5c5bf813ef92a9602740a059cfcbb20593b2deee52" +dependencies = [ + "nom 7.1.3", + "once_cell", + "regex", + "unicode_categories", +] + [[package]] name = "deno_task_shell" version = "0.18.1" @@ -6797,17 +6809,6 @@ dependencies = [ "der", ] -[[package]] -name = "sqlformat" -version = "0.3.1" -source = "git+https://github.com/shssoichiro/sqlformat-rs.git?rev=827d639#827d639bef94d8e5a5a0e29b41185c8d572f24e6" -dependencies = [ - "nom 7.1.3", - "once_cell", - "regex", - "unicode_categories", -] - [[package]] name = "stable_deref_trait" version = "1.2.0" diff --git a/cli/Cargo.toml b/cli/Cargo.toml index ae573827b1..d6f509eb97 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -151,8 +151,8 @@ serde_repr.workspace = true sha2.workspace = true shell-escape = "=0.1.5" spki = { version = "0.7", features = ["pem"] } -# NOTE(bartlomieju): for now using github URL, because 0.3.2 with important fixes hasn't been released yet. -sqlformat = { git = "https://github.com/shssoichiro/sqlformat-rs.git", rev = "827d639" } +# NOTE(bartlomieju): using temporary fork for now, revert back to `sqlformat-rs` later +sqlformat = { package = "deno_sqlformat", version = "0.3.2" } strsim = "0.11.1" tar.workspace = true tempfile.workspace = true From 56f31628f7a9d4a3dc54c70c4df1067b8a214ec6 Mon Sep 17 00:00:00 2001 From: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Date: Wed, 20 Nov 2024 15:22:15 -0800 Subject: [PATCH 05/11] feat: subcommand to view and update outdated dependencies (#26942) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #20487 Currently spelled ``` deno outdated ``` and ``` deno outdated --update ``` Works across package.json and deno.json, and in workspaces. There's a bit of duplicated code, I'll refactor to reduce this in follow ups ## Currently supported: ### Printing outdated deps (current output below which basically mimics pnpm, but requesting feedback / suggestions) ``` deno outdated ``` ![Screenshot 2024-11-19 at 2 01 56 PM](https://github.com/user-attachments/assets/51fea83a-181a-4082-b388-163313ce15e7) ### Updating deps semver compatible: ``` deno outdated --update ``` latest: ``` deno outdated --latest ``` current output is basic, again would love suggestions ![Screenshot 2024-11-19 at 2 13 46 PM](https://github.com/user-attachments/assets/e4c4db87-cd67-4b74-9ea7-4bd80106d5e9) #### Filters ``` deno outdated --update "@std/*" deno outdated --update --latest "@std/* "!@std/fmt" ``` #### Update to specific versions ``` deno outdated --update @std/fmt@1.0.2 @std/cli@^1.0.3 ``` ### Include all workspace members ``` deno outdated --recursive deno outdated --update --recursive ``` ## Future work - interactive update - update deps in js/ts files - better support for transitive deps Known issues (to be fixed in follow ups): - If no top level dependencies have changed, we won't update transitive deps (even if they could be updated) - Can't filter transitive deps, or update them to specific versions ## TODO (in this PR): - ~~spec tests for filters~~ - ~~spec test for mixed workspace (have tested manually)~~ - tweak output - suggestion when you try `deno update` --------- Co-authored-by: Bartek Iwańczuk --- cli/args/flags.rs | 192 ++++ cli/args/mod.rs | 1 + cli/main.rs | 5 + cli/npm/managed/mod.rs | 2 +- cli/tools/registry/mod.rs | 1 + cli/tools/registry/pm.rs | 32 +- cli/tools/registry/pm/cache_deps.rs | 17 +- cli/tools/registry/pm/deps.rs | 964 ++++++++++++++++++ cli/tools/registry/pm/outdated.rs | 661 ++++++++++++ tests/registry/jsr/@denotest/add/0.2.1/mod.ts | 4 + .../jsr/@denotest/add/0.2.1_meta.json | 8 + tests/registry/jsr/@denotest/add/meta.json | 3 +- .../@denotest/multiple-exports/0.2.0/add.ts | 1 + .../multiple-exports/0.2.0/data.json | 3 + .../multiple-exports/0.2.0/subtract.ts | 1 + .../multiple-exports/0.2.0_meta.json | 7 + .../@denotest/multiple-exports/0.5.0/add.ts | 1 + .../multiple-exports/0.5.0/data.json | 3 + .../multiple-exports/0.5.0/subtract.ts | 1 + .../multiple-exports/0.5.0_meta.json | 7 + .../jsr/@denotest/multiple-exports/meta.json | 4 +- .../jsr/@denotest/subtract/0.2.0/mod.ts | 3 + .../jsr/@denotest/subtract/0.2.0_meta.json | 8 + .../registry/jsr/@denotest/subtract/meta.json | 4 +- .../has-patch-versions/0.1.0/package.json | 5 + .../has-patch-versions/0.1.1/package.json | 5 + .../has-patch-versions/0.2.0/package.json | 4 + tests/specs/update/deno_json/__test__.jsonc | 101 ++ tests/specs/update/deno_json/deno.json | 19 + tests/specs/update/deno_json/deno.lock | 43 + .../specs/update/deno_json/deno.lock.orig.out | 43 + .../update/deno_json/filtered/deno.json.out | 19 + .../update/deno_json/filtered/update.out | 10 + tests/specs/update/deno_json/outdated.out | 15 + .../update/deno_json/outdated_compatible.out | 7 + tests/specs/update/deno_json/print_file.ts | 2 + .../deno_json/update_compatible/deno.json.out | 19 + .../deno_json/update_compatible/deno.lock.out | 43 + .../deno_json/update_compatible/update.out | 7 + .../deno_json/update_latest/deno.json.out | 19 + .../deno_json/update_latest/deno.lock.out | 43 + .../update/deno_json/update_latest/update.out | 16 + .../update/mixed_workspace/__test__.jsonc | 153 +++ tests/specs/update/mixed_workspace/deno.json | 6 + tests/specs/update/mixed_workspace/deno.lock | 55 + .../update/mixed_workspace/deno.lock.orig.out | 55 + .../filtered/member_a_deno.json.out | 10 + .../filtered/member_b_package.json.out | 8 + .../mixed_workspace/filtered/update.out | 12 + .../update/mixed_workspace/member-a/deno.json | 10 + .../update/mixed_workspace/member-a/mod.ts | 0 .../mixed_workspace/member-b/package.json | 8 + .../update/mixed_workspace/print_file.ts | 2 + .../print_outdated/member_a.out | 9 + .../print_outdated/member_b.out | 7 + .../print_outdated/recursive.out | 15 + .../mixed_workspace/print_outdated/root.out | 5 + .../update_latest/recursive/update.out | 16 + .../update_latest/root/deno.json.out | 6 + .../update_latest/root/update.out | 3 + .../update_latest/subdir/member_a.out | 10 + .../subdir/member_a_deno.json.out | 10 + .../update_latest/subdir/member_b.out | 7 + .../subdir/member_b_package.json.out | 8 + .../specs/update/package_json/__test__.jsonc | 100 ++ tests/specs/update/package_json/deno.lock | 28 + .../update/package_json/deno.lock.orig.out | 28 + .../package_json/filtered/package.json.out | 9 + .../update/package_json/filtered/update.out | 9 + tests/specs/update/package_json/outdated.out | 9 + .../package_json/outdated_compatible.out | 5 + tests/specs/update/package_json/package.json | 9 + tests/specs/update/package_json/print_file.ts | 2 + .../update_compatible/deno.lock.out | 28 + .../update_compatible/package.json.out | 9 + .../package_json/update_compatible/update.out | 4 + .../package_json/update_latest/deno.lock.out | 28 + .../update_latest/package.json.out | 9 + .../package_json/update_latest/update.out | 14 + tests/util/server/src/npm.rs | 68 +- 80 files changed, 3109 insertions(+), 18 deletions(-) create mode 100644 cli/tools/registry/pm/deps.rs create mode 100644 cli/tools/registry/pm/outdated.rs create mode 100644 tests/registry/jsr/@denotest/add/0.2.1/mod.ts create mode 100644 tests/registry/jsr/@denotest/add/0.2.1_meta.json create mode 100644 tests/registry/jsr/@denotest/multiple-exports/0.2.0/add.ts create mode 100644 tests/registry/jsr/@denotest/multiple-exports/0.2.0/data.json create mode 100644 tests/registry/jsr/@denotest/multiple-exports/0.2.0/subtract.ts create mode 100644 tests/registry/jsr/@denotest/multiple-exports/0.2.0_meta.json create mode 100644 tests/registry/jsr/@denotest/multiple-exports/0.5.0/add.ts create mode 100644 tests/registry/jsr/@denotest/multiple-exports/0.5.0/data.json create mode 100644 tests/registry/jsr/@denotest/multiple-exports/0.5.0/subtract.ts create mode 100644 tests/registry/jsr/@denotest/multiple-exports/0.5.0_meta.json create mode 100644 tests/registry/jsr/@denotest/subtract/0.2.0/mod.ts create mode 100644 tests/registry/jsr/@denotest/subtract/0.2.0_meta.json create mode 100644 tests/registry/npm/@denotest/has-patch-versions/0.1.0/package.json create mode 100644 tests/registry/npm/@denotest/has-patch-versions/0.1.1/package.json create mode 100644 tests/registry/npm/@denotest/has-patch-versions/0.2.0/package.json create mode 100644 tests/specs/update/deno_json/__test__.jsonc create mode 100644 tests/specs/update/deno_json/deno.json create mode 100644 tests/specs/update/deno_json/deno.lock create mode 100644 tests/specs/update/deno_json/deno.lock.orig.out create mode 100644 tests/specs/update/deno_json/filtered/deno.json.out create mode 100644 tests/specs/update/deno_json/filtered/update.out create mode 100644 tests/specs/update/deno_json/outdated.out create mode 100644 tests/specs/update/deno_json/outdated_compatible.out create mode 100644 tests/specs/update/deno_json/print_file.ts create mode 100644 tests/specs/update/deno_json/update_compatible/deno.json.out create mode 100644 tests/specs/update/deno_json/update_compatible/deno.lock.out create mode 100644 tests/specs/update/deno_json/update_compatible/update.out create mode 100644 tests/specs/update/deno_json/update_latest/deno.json.out create mode 100644 tests/specs/update/deno_json/update_latest/deno.lock.out create mode 100644 tests/specs/update/deno_json/update_latest/update.out create mode 100644 tests/specs/update/mixed_workspace/__test__.jsonc create mode 100644 tests/specs/update/mixed_workspace/deno.json create mode 100644 tests/specs/update/mixed_workspace/deno.lock create mode 100644 tests/specs/update/mixed_workspace/deno.lock.orig.out create mode 100644 tests/specs/update/mixed_workspace/filtered/member_a_deno.json.out create mode 100644 tests/specs/update/mixed_workspace/filtered/member_b_package.json.out create mode 100644 tests/specs/update/mixed_workspace/filtered/update.out create mode 100644 tests/specs/update/mixed_workspace/member-a/deno.json create mode 100644 tests/specs/update/mixed_workspace/member-a/mod.ts create mode 100644 tests/specs/update/mixed_workspace/member-b/package.json create mode 100644 tests/specs/update/mixed_workspace/print_file.ts create mode 100644 tests/specs/update/mixed_workspace/print_outdated/member_a.out create mode 100644 tests/specs/update/mixed_workspace/print_outdated/member_b.out create mode 100644 tests/specs/update/mixed_workspace/print_outdated/recursive.out create mode 100644 tests/specs/update/mixed_workspace/print_outdated/root.out create mode 100644 tests/specs/update/mixed_workspace/update_latest/recursive/update.out create mode 100644 tests/specs/update/mixed_workspace/update_latest/root/deno.json.out create mode 100644 tests/specs/update/mixed_workspace/update_latest/root/update.out create mode 100644 tests/specs/update/mixed_workspace/update_latest/subdir/member_a.out create mode 100644 tests/specs/update/mixed_workspace/update_latest/subdir/member_a_deno.json.out create mode 100644 tests/specs/update/mixed_workspace/update_latest/subdir/member_b.out create mode 100644 tests/specs/update/mixed_workspace/update_latest/subdir/member_b_package.json.out create mode 100644 tests/specs/update/package_json/__test__.jsonc create mode 100644 tests/specs/update/package_json/deno.lock create mode 100644 tests/specs/update/package_json/deno.lock.orig.out create mode 100644 tests/specs/update/package_json/filtered/package.json.out create mode 100644 tests/specs/update/package_json/filtered/update.out create mode 100644 tests/specs/update/package_json/outdated.out create mode 100644 tests/specs/update/package_json/outdated_compatible.out create mode 100644 tests/specs/update/package_json/package.json create mode 100644 tests/specs/update/package_json/print_file.ts create mode 100644 tests/specs/update/package_json/update_compatible/deno.lock.out create mode 100644 tests/specs/update/package_json/update_compatible/package.json.out create mode 100644 tests/specs/update/package_json/update_compatible/update.out create mode 100644 tests/specs/update/package_json/update_latest/deno.lock.out create mode 100644 tests/specs/update/package_json/update_latest/package.json.out create mode 100644 tests/specs/update/package_json/update_latest/update.out diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 567d4adfb9..6945065574 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -465,6 +465,7 @@ pub enum DenoSubcommand { Serve(ServeFlags), Task(TaskFlags), Test(TestFlags), + Outdated(OutdatedFlags), Types, Upgrade(UpgradeFlags), Vendor, @@ -472,6 +473,19 @@ pub enum DenoSubcommand { Help(HelpFlags), } +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum OutdatedKind { + Update { latest: bool }, + PrintOutdated { compatible: bool }, +} + +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct OutdatedFlags { + pub filters: Vec, + pub recursive: bool, + pub kind: OutdatedKind, +} + impl DenoSubcommand { pub fn is_run(&self) -> bool { matches!(self, Self::Run(_)) @@ -1203,6 +1217,7 @@ static DENO_HELP: &str = cstr!( deno add jsr:@std/assert | deno add npm:express install Installs dependencies either in the local project or globally to a bin directory uninstall Uninstalls a dependency or an executable script in the installation root's bin directory + outdated Find and update outdated dependencies remove Remove dependencies from the configuration file Tooling: @@ -1385,6 +1400,7 @@ pub fn flags_from_vec(args: Vec) -> clap::error::Result { "jupyter" => jupyter_parse(&mut flags, &mut m), "lint" => lint_parse(&mut flags, &mut m)?, "lsp" => lsp_parse(&mut flags, &mut m), + "outdated" => outdated_parse(&mut flags, &mut m)?, "repl" => repl_parse(&mut flags, &mut m)?, "run" => run_parse(&mut flags, &mut m, app, false)?, "serve" => serve_parse(&mut flags, &mut m, app)?, @@ -1627,6 +1643,7 @@ pub fn clap_root() -> Command { .subcommand(json_reference_subcommand()) .subcommand(jupyter_subcommand()) .subcommand(uninstall_subcommand()) + .subcommand(outdated_subcommand()) .subcommand(lsp_subcommand()) .subcommand(lint_subcommand()) .subcommand(publish_subcommand()) @@ -2617,6 +2634,83 @@ fn jupyter_subcommand() -> Command { .conflicts_with("install")) } +fn outdated_subcommand() -> Command { + command( + "outdated", + cstr!("Find and update outdated dependencies. +By default, outdated dependencies are only displayed. + +Display outdated dependencies: + deno outdated + deno outdated --compatible + +Update dependencies: + deno outdated --update + deno outdated --update --latest + deno outdated --update + +Filters can be used to select which packages to act on. Filters can include wildcards (*) to match multiple packages. + deno outdated --update --latest \"@std/*\" + deno outdated --update --latest \"react*\" +Note that filters act on their aliases configured in deno.json / package.json, not the actual package names: + Given \"foobar\": \"npm:react@17.0.0\" in deno.json or package.json, the filter \"foobar\" would update npm:react to + the latest version. + deno outdated --update --latest foobar +Filters can be combined, and negative filters can be used to exclude results: + deno outdated --update --latest \"@std/*\" \"!@std/fmt*\" + +Specific version requirements to update to can be specified: + deno outdated --update @std/fmt@^1.0.2 +"), + UnstableArgsConfig::None, + ) + .defer(|cmd| { + cmd + .arg( + Arg::new("filters") + .num_args(0..) + .action(ArgAction::Append) + .help(concat!("Filters selecting which packages to act on. Can include wildcards (*) to match multiple packages. ", + "If a version requirement is specified, the matching packages will be updated to the given requirement."), + ) + ) + .arg(no_lock_arg()) + .arg(lock_arg()) + .arg( + Arg::new("latest") + .long("latest") + .action(ArgAction::SetTrue) + .help( + "Update to the latest version, regardless of semver constraints", + ) + .requires("update") + .conflicts_with("compatible"), + ) + .arg( + Arg::new("update") + .long("update") + .short('u') + .action(ArgAction::SetTrue) + .conflicts_with("compatible") + .help("Update dependency versions"), + ) + .arg( + Arg::new("compatible") + .long("compatible") + .action(ArgAction::SetTrue) + .help("Only output versions that satisfy semver requirements") + .conflicts_with("update"), + ) + .arg( + Arg::new("recursive") + .long("recursive") + .short('r') + .action(ArgAction::SetTrue) + .help("include all workspace members"), + ) + }) +} + fn uninstall_subcommand() -> Command { command( "uninstall", @@ -4353,6 +4447,31 @@ fn remove_parse(flags: &mut Flags, matches: &mut ArgMatches) { }); } +fn outdated_parse( + flags: &mut Flags, + matches: &mut ArgMatches, +) -> clap::error::Result<()> { + let filters = match matches.remove_many::("filters") { + Some(f) => f.collect(), + None => vec![], + }; + let recursive = matches.get_flag("recursive"); + let update = matches.get_flag("update"); + let kind = if update { + let latest = matches.get_flag("latest"); + OutdatedKind::Update { latest } + } else { + let compatible = matches.get_flag("compatible"); + OutdatedKind::PrintOutdated { compatible } + }; + flags.subcommand = DenoSubcommand::Outdated(OutdatedFlags { + filters, + recursive, + kind, + }); + Ok(()) +} + fn bench_parse( flags: &mut Flags, matches: &mut ArgMatches, @@ -11299,4 +11418,77 @@ Usage: deno repl [OPTIONS] [-- [ARGS]...]\n" assert!(r.is_err()); } } + + #[test] + fn outdated_subcommand() { + let cases = [ + ( + svec![], + OutdatedFlags { + filters: vec![], + kind: OutdatedKind::PrintOutdated { compatible: false }, + recursive: false, + }, + ), + ( + svec!["--recursive"], + OutdatedFlags { + filters: vec![], + kind: OutdatedKind::PrintOutdated { compatible: false }, + recursive: true, + }, + ), + ( + svec!["--recursive", "--compatible"], + OutdatedFlags { + filters: vec![], + kind: OutdatedKind::PrintOutdated { compatible: true }, + recursive: true, + }, + ), + ( + svec!["--update"], + OutdatedFlags { + filters: vec![], + kind: OutdatedKind::Update { latest: false }, + recursive: false, + }, + ), + ( + svec!["--update", "--latest"], + OutdatedFlags { + filters: vec![], + kind: OutdatedKind::Update { latest: true }, + recursive: false, + }, + ), + ( + svec!["--update", "--recursive"], + OutdatedFlags { + filters: vec![], + kind: OutdatedKind::Update { latest: false }, + recursive: true, + }, + ), + ( + svec!["--update", "@foo/bar"], + OutdatedFlags { + filters: svec!["@foo/bar"], + kind: OutdatedKind::Update { latest: false }, + recursive: false, + }, + ), + ]; + for (input, expected) in cases { + let mut args = svec!["deno", "outdated"]; + args.extend(input); + let r = flags_from_vec(args.clone()).unwrap(); + assert_eq!( + r.subcommand, + DenoSubcommand::Outdated(expected), + "incorrect result for args: {:?}", + args + ); + } + } } diff --git a/cli/args/mod.rs b/cli/args/mod.rs index bbdfa478c1..37e1f00ffa 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1628,6 +1628,7 @@ impl CliOptions { DenoSubcommand::Install(_) | DenoSubcommand::Add(_) | DenoSubcommand::Remove(_) + | DenoSubcommand::Outdated(_) ) { // For `deno install/add/remove` we want to force the managed resolver so it can set up `node_modules/` directory. return false; diff --git a/cli/main.rs b/cli/main.rs index 3dd2692f05..017e343178 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -188,6 +188,11 @@ async fn run_subcommand(flags: Arc) -> Result { tools::lint::lint(flags, lint_flags).await } }), + DenoSubcommand::Outdated(update_flags) => { + spawn_subcommand(async move { + tools::registry::outdated(flags, update_flags).await + }) + } DenoSubcommand::Repl(repl_flags) => { spawn_subcommand(async move { tools::repl::run(flags, repl_flags).await }) } diff --git a/cli/npm/managed/mod.rs b/cli/npm/managed/mod.rs index 2e64f5f188..88094d5141 100644 --- a/cli/npm/managed/mod.rs +++ b/cli/npm/managed/mod.rs @@ -500,7 +500,7 @@ impl ManagedCliNpmResolver { self.resolve_pkg_folder_from_pkg_id(&pkg_id) } - fn resolve_pkg_id_from_pkg_req( + pub fn resolve_pkg_id_from_pkg_req( &self, req: &PackageReq, ) -> Result { diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs index 89447f04f9..ba61d352d3 100644 --- a/cli/tools/registry/mod.rs +++ b/cli/tools/registry/mod.rs @@ -68,6 +68,7 @@ use auth::get_auth_method; use auth::AuthMethod; pub use pm::add; pub use pm::cache_top_level_deps; +pub use pm::outdated; pub use pm::remove; pub use pm::AddCommandName; pub use pm::AddRmPackageReq; diff --git a/cli/tools/registry/pm.rs b/cli/tools/registry/pm.rs index c1ea2c75ea..5718cd3ec1 100644 --- a/cli/tools/registry/pm.rs +++ b/cli/tools/registry/pm.rs @@ -16,6 +16,7 @@ use deno_semver::package::PackageNv; use deno_semver::package::PackageReq; use deno_semver::Version; use deno_semver::VersionReq; +use deps::KeyPath; use jsonc_parser::cst::CstObject; use jsonc_parser::cst::CstObjectProp; use jsonc_parser::cst::CstRootNode; @@ -32,10 +33,13 @@ use crate::jsr::JsrFetchResolver; use crate::npm::NpmFetchResolver; mod cache_deps; +pub(crate) mod deps; +mod outdated; pub use cache_deps::cache_top_level_deps; +pub use outdated::outdated; -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Hash)] enum ConfigKind { DenoJson, PackageJson, @@ -86,6 +90,28 @@ impl ConfigUpdater { self.cst.to_string() } + fn get_property_for_mutation( + &mut self, + key_path: &KeyPath, + ) -> Option { + let mut current_node = self.root_object.clone(); + + self.modified = true; + + for (i, part) in key_path.parts.iter().enumerate() { + let s = part.as_str(); + if i < key_path.parts.len().saturating_sub(1) { + let object = current_node.object_value(s)?; + current_node = object; + } else { + // last part + return current_node.get(s); + } + } + + None + } + fn add(&mut self, selected: SelectedPackage, dev: bool) { fn insert_index(object: &CstObject, searching_name: &str) -> usize { object @@ -824,7 +850,7 @@ async fn npm_install_after_modification( flags: Arc, // explicitly provided to prevent redownloading jsr_resolver: Option>, -) -> Result<(), AnyError> { +) -> Result { // clear the previously cached package.json from memory before reloading it node_resolver::PackageJsonThreadLocalCache::clear(); @@ -842,7 +868,7 @@ async fn npm_install_after_modification( lockfile.write_if_changed()?; } - Ok(()) + Ok(cli_factory) } #[cfg(test)] diff --git a/cli/tools/registry/pm/cache_deps.rs b/cli/tools/registry/pm/cache_deps.rs index d3c8da868c..f9d67e4d4f 100644 --- a/cli/tools/registry/pm/cache_deps.rs +++ b/cli/tools/registry/pm/cache_deps.rs @@ -8,7 +8,7 @@ use crate::graph_container::ModuleGraphUpdatePermit; use deno_core::error::AnyError; use deno_core::futures::stream::FuturesUnordered; use deno_core::futures::StreamExt; -use deno_semver::package::PackageReq; +use deno_semver::jsr::JsrPackageReqReference; pub async fn cache_top_level_deps( // todo(dsherret): don't pass the factory into this function. Instead use ctor deps @@ -56,15 +56,20 @@ pub async fn cache_top_level_deps( match specifier.scheme() { "jsr" => { let specifier_str = specifier.as_str(); - let specifier_str = - specifier_str.strip_prefix("jsr:").unwrap_or(specifier_str); - if let Ok(req) = PackageReq::from_str(specifier_str) { - if !seen_reqs.insert(req.clone()) { + if let Ok(req) = JsrPackageReqReference::from_str(specifier_str) { + if let Some(sub_path) = req.sub_path() { + if sub_path.ends_with('/') { + continue; + } + roots.push(specifier.clone()); + continue; + } + if !seen_reqs.insert(req.req().clone()) { continue; } let jsr_resolver = jsr_resolver.clone(); info_futures.push(async move { - if let Some(nv) = jsr_resolver.req_to_nv(&req).await { + if let Some(nv) = jsr_resolver.req_to_nv(req.req()).await { if let Some(info) = jsr_resolver.package_version_info(&nv).await { return Some((specifier.clone(), info)); diff --git a/cli/tools/registry/pm/deps.rs b/cli/tools/registry/pm/deps.rs new file mode 100644 index 0000000000..4778d6f327 --- /dev/null +++ b/cli/tools/registry/pm/deps.rs @@ -0,0 +1,964 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +use std::borrow::Cow; +use std::collections::HashMap; +use std::sync::atomic::AtomicBool; +use std::sync::Arc; + +use deno_ast::ModuleSpecifier; +use deno_config::deno_json::ConfigFile; +use deno_config::deno_json::ConfigFileRc; +use deno_config::workspace::Workspace; +use deno_config::workspace::WorkspaceDirectory; +use deno_core::anyhow::bail; +use deno_core::error::AnyError; +use deno_core::futures::future::try_join; +use deno_core::futures::stream::FuturesOrdered; +use deno_core::futures::stream::FuturesUnordered; +use deno_core::futures::FutureExt; +use deno_core::futures::StreamExt; +use deno_core::serde_json; +use deno_graph::FillFromLockfileOptions; +use deno_package_json::PackageJsonDepValue; +use deno_package_json::PackageJsonDepValueParseError; +use deno_package_json::PackageJsonRc; +use deno_runtime::deno_permissions::PermissionsContainer; +use deno_semver::jsr::JsrPackageReqReference; +use deno_semver::npm::NpmPackageReqReference; +use deno_semver::package::PackageNv; +use deno_semver::package::PackageReq; +use deno_semver::package::PackageReqReference; +use deno_semver::VersionReq; +use import_map::ImportMap; +use import_map::ImportMapWithDiagnostics; +use import_map::SpecifierMapEntry; +use indexmap::IndexMap; +use tokio::sync::Semaphore; + +use crate::args::CliLockfile; +use crate::graph_container::MainModuleGraphContainer; +use crate::graph_container::ModuleGraphContainer; +use crate::graph_container::ModuleGraphUpdatePermit; +use crate::jsr::JsrFetchResolver; +use crate::module_loader::ModuleLoadPreparer; +use crate::npm::CliNpmResolver; +use crate::npm::NpmFetchResolver; + +use super::ConfigUpdater; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum ImportMapKind { + Inline, + Outline, +} + +#[derive(Clone)] +pub enum DepLocation { + DenoJson(ConfigFileRc, KeyPath, ImportMapKind), + PackageJson(PackageJsonRc, KeyPath), +} + +impl DepLocation { + pub fn is_deno_json(&self) -> bool { + matches!(self, DepLocation::DenoJson(..)) + } + + pub fn file_path(&self) -> Cow { + match self { + DepLocation::DenoJson(arc, _, _) => { + Cow::Owned(arc.specifier.to_file_path().unwrap()) + } + DepLocation::PackageJson(arc, _) => Cow::Borrowed(arc.path.as_ref()), + } + } + fn config_kind(&self) -> super::ConfigKind { + match self { + DepLocation::DenoJson(_, _, _) => super::ConfigKind::DenoJson, + DepLocation::PackageJson(_, _) => super::ConfigKind::PackageJson, + } + } +} + +struct DebugAdapter(T); + +impl<'a> std::fmt::Debug for DebugAdapter<&'a ConfigFileRc> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("ConfigFile") + .field("specifier", &self.0.specifier) + .finish() + } +} +impl<'a> std::fmt::Debug for DebugAdapter<&'a PackageJsonRc> { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.debug_struct("PackageJson") + .field("path", &self.0.path) + .finish() + } +} + +impl std::fmt::Debug for DepLocation { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + DepLocation::DenoJson(arc, key_path, kind) => { + let mut debug = f.debug_tuple("DenoJson"); + debug + .field(&DebugAdapter(arc)) + .field(key_path) + .field(kind) + .finish() + } + DepLocation::PackageJson(arc, key_path) => { + let mut debug = f.debug_tuple("PackageJson"); + debug.field(&DebugAdapter(arc)).field(key_path).finish() + } + } + } +} + +#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)] +pub enum DepKind { + Jsr, + Npm, +} + +impl DepKind { + pub fn scheme(&self) -> &'static str { + match self { + DepKind::Npm => "npm", + DepKind::Jsr => "jsr", + } + } +} + +#[derive(Clone, Debug)] +pub enum KeyPart { + Imports, + Scopes, + Dependencies, + DevDependencies, + String(String), +} + +impl From for KeyPart { + fn from(value: String) -> Self { + KeyPart::String(value) + } +} + +impl From for KeyPart { + fn from(value: PackageJsonDepKind) -> Self { + match value { + PackageJsonDepKind::Normal => Self::Dependencies, + PackageJsonDepKind::Dev => Self::DevDependencies, + } + } +} + +impl KeyPart { + pub fn as_str(&self) -> &str { + match self { + KeyPart::Imports => "imports", + KeyPart::Scopes => "scopes", + KeyPart::Dependencies => "dependencies", + KeyPart::DevDependencies => "devDependencies", + KeyPart::String(s) => s, + } + } +} + +#[derive(Clone, Debug)] +pub struct KeyPath { + pub parts: Vec, +} + +impl KeyPath { + fn from_parts(parts: impl IntoIterator) -> Self { + Self { + parts: parts.into_iter().collect(), + } + } + fn last(&self) -> Option<&KeyPart> { + self.parts.last() + } + fn push(&mut self, part: KeyPart) { + self.parts.push(part) + } +} + +#[derive(Clone, Debug)] +pub struct Dep { + pub req: PackageReq, + pub kind: DepKind, + pub location: DepLocation, + #[allow(dead_code)] + pub id: DepId, + #[allow(dead_code)] + pub alias: Option, +} + +fn import_map_entries( + import_map: &ImportMap, +) -> impl Iterator)> { + import_map + .imports() + .entries() + .map(|entry| { + ( + KeyPath::from_parts([ + KeyPart::Imports, + KeyPart::String(entry.raw_key.into()), + ]), + entry, + ) + }) + .chain(import_map.scopes().flat_map(|scope| { + let path = KeyPath::from_parts([ + KeyPart::Scopes, + scope.raw_key.to_string().into(), + ]); + + scope.imports.entries().map(move |entry| { + let mut full_path = path.clone(); + full_path.push(KeyPart::String(entry.raw_key.to_string())); + (full_path, entry) + }) + })) +} + +fn to_import_map_value_from_imports( + deno_json: &ConfigFile, +) -> serde_json::Value { + let mut value = serde_json::Map::with_capacity(2); + if let Some(imports) = &deno_json.json.imports { + value.insert("imports".to_string(), imports.clone()); + } + if let Some(scopes) = &deno_json.json.scopes { + value.insert("scopes".to_string(), scopes.clone()); + } + serde_json::Value::Object(value) +} + +fn deno_json_import_map( + deno_json: &ConfigFile, +) -> Result, AnyError> { + let (value, kind) = + if deno_json.json.imports.is_some() || deno_json.json.scopes.is_some() { + ( + to_import_map_value_from_imports(deno_json), + ImportMapKind::Inline, + ) + } else { + match deno_json.to_import_map_path()? { + Some(path) => { + let text = std::fs::read_to_string(&path)?; + let value = serde_json::from_str(&text)?; + (value, ImportMapKind::Outline) + } + None => return Ok(None), + } + }; + + import_map::parse_from_value(deno_json.specifier.clone(), value) + .map_err(Into::into) + .map(|import_map| Some((import_map, kind))) +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum PackageJsonDepKind { + Normal, + Dev, +} + +type PackageJsonDeps = IndexMap< + String, + Result< + (PackageJsonDepKind, PackageJsonDepValue), + PackageJsonDepValueParseError, + >, +>; + +/// Resolve the package.json's dependencies. +// TODO(nathanwhit): Remove once we update deno_package_json with dev deps split out +fn resolve_local_package_json_deps( + package_json: &PackageJsonRc, +) -> PackageJsonDeps { + /// Gets the name and raw version constraint for a registry info or + /// package.json dependency entry taking into account npm package aliases. + fn parse_dep_entry_name_and_raw_version<'a>( + key: &'a str, + value: &'a str, + ) -> (&'a str, &'a str) { + if let Some(package_and_version) = value.strip_prefix("npm:") { + if let Some((name, version)) = package_and_version.rsplit_once('@') { + // if empty, then the name was scoped and there's no version + if name.is_empty() { + (package_and_version, "*") + } else { + (name, version) + } + } else { + (package_and_version, "*") + } + } else { + (key, value) + } + } + + fn parse_entry( + key: &str, + value: &str, + ) -> Result { + if let Some(workspace_key) = value.strip_prefix("workspace:") { + let version_req = VersionReq::parse_from_npm(workspace_key)?; + return Ok(PackageJsonDepValue::Workspace(version_req)); + } + if value.starts_with("file:") + || value.starts_with("git:") + || value.starts_with("http:") + || value.starts_with("https:") + { + return Err(PackageJsonDepValueParseError::Unsupported { + scheme: value.split(':').next().unwrap().to_string(), + }); + } + let (name, version_req) = parse_dep_entry_name_and_raw_version(key, value); + let result = VersionReq::parse_from_npm(version_req); + match result { + Ok(version_req) => Ok(PackageJsonDepValue::Req(PackageReq { + name: name.to_string(), + version_req, + })), + Err(err) => Err(PackageJsonDepValueParseError::VersionReq(err)), + } + } + + fn insert_deps( + deps: Option<&IndexMap>, + result: &mut PackageJsonDeps, + kind: PackageJsonDepKind, + ) { + if let Some(deps) = deps { + for (key, value) in deps { + result.entry(key.to_string()).or_insert_with(|| { + parse_entry(key, value).map(|entry| (kind, entry)) + }); + } + } + } + + let deps = package_json.dependencies.as_ref(); + let dev_deps = package_json.dev_dependencies.as_ref(); + let mut result = IndexMap::new(); + + // favors the deps over dev_deps + insert_deps(deps, &mut result, PackageJsonDepKind::Normal); + insert_deps(dev_deps, &mut result, PackageJsonDepKind::Dev); + + result +} + +fn add_deps_from_deno_json( + deno_json: &Arc, + mut filter: impl DepFilter, + deps: &mut Vec, +) { + let (import_map, import_map_kind) = match deno_json_import_map(deno_json) { + Ok(Some((import_map, import_map_kind))) => (import_map, import_map_kind), + Ok(None) => return, + Err(e) => { + log::warn!("failed to parse imports from {}: {e}", &deno_json.specifier); + return; + } + }; + for (key_path, entry) in import_map_entries(&import_map.import_map) { + let Some(value) = entry.value else { continue }; + let kind = match value.scheme() { + "npm" => DepKind::Npm, + "jsr" => DepKind::Jsr, + _ => continue, + }; + let req = match parse_req_reference(value.as_str(), kind) { + Ok(req) => req.req.clone(), + Err(err) => { + log::warn!("failed to parse package req \"{}\": {err}", value.as_str()); + continue; + } + }; + let alias: &str = key_path.last().unwrap().as_str().trim_end_matches('/'); + let alias = (alias != req.name).then(|| alias.to_string()); + if !filter.should_include(alias.as_deref(), &req, kind) { + continue; + } + let id = DepId(deps.len()); + deps.push(Dep { + location: DepLocation::DenoJson( + deno_json.clone(), + key_path, + import_map_kind, + ), + kind, + req, + id, + alias, + }); + } +} + +fn add_deps_from_package_json( + package_json: &PackageJsonRc, + mut filter: impl DepFilter, + deps: &mut Vec, +) { + let package_json_deps = resolve_local_package_json_deps(package_json); + for (k, v) in package_json_deps { + let (package_dep_kind, v) = match v { + Ok((k, v)) => (k, v), + Err(e) => { + log::warn!("bad package json dep value: {e}"); + continue; + } + }; + match v { + deno_package_json::PackageJsonDepValue::Req(req) => { + let alias = k.as_str(); + let alias = (alias != req.name).then(|| alias.to_string()); + if !filter.should_include(alias.as_deref(), &req, DepKind::Npm) { + continue; + } + let id = DepId(deps.len()); + deps.push(Dep { + id, + kind: DepKind::Npm, + location: DepLocation::PackageJson( + package_json.clone(), + KeyPath::from_parts([package_dep_kind.into(), k.into()]), + ), + req, + alias, + }) + } + deno_package_json::PackageJsonDepValue::Workspace(_) => continue, + } + } +} + +fn deps_from_workspace( + workspace: &Arc, + dep_filter: impl DepFilter, +) -> Result, AnyError> { + let mut deps = Vec::with_capacity(256); + for deno_json in workspace.deno_jsons() { + add_deps_from_deno_json(deno_json, dep_filter, &mut deps); + } + for package_json in workspace.package_jsons() { + add_deps_from_package_json(package_json, dep_filter, &mut deps); + } + + Ok(deps) +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub struct DepId(usize); + +#[derive(Debug, Clone)] +pub enum Change { + Update(DepId, VersionReq), +} + +pub trait DepFilter: Copy { + fn should_include( + &mut self, + alias: Option<&str>, + package_req: &PackageReq, + dep_kind: DepKind, + ) -> bool; +} + +impl DepFilter for T +where + T: FnMut(Option<&str>, &PackageReq, DepKind) -> bool + Copy, +{ + fn should_include<'a>( + &mut self, + alias: Option<&'a str>, + package_req: &'a PackageReq, + dep_kind: DepKind, + ) -> bool { + (*self)(alias, package_req, dep_kind) + } +} + +#[derive(Clone, Debug)] +pub struct PackageLatestVersion { + pub semver_compatible: Option, + pub latest: Option, +} + +pub struct DepManager { + deps: Vec, + resolved_versions: Vec>, + latest_versions: Vec, + + pending_changes: Vec, + + dependencies_resolved: AtomicBool, + module_load_preparer: Arc, + // TODO(nathanwhit): probably shouldn't be pub + pub(crate) jsr_fetch_resolver: Arc, + pub(crate) npm_fetch_resolver: Arc, + npm_resolver: Arc, + permissions_container: PermissionsContainer, + main_module_graph_container: Arc, + lockfile: Option>, +} + +pub struct DepManagerArgs { + pub module_load_preparer: Arc, + pub jsr_fetch_resolver: Arc, + pub npm_fetch_resolver: Arc, + pub npm_resolver: Arc, + pub permissions_container: PermissionsContainer, + pub main_module_graph_container: Arc, + pub lockfile: Option>, +} + +impl DepManager { + pub fn reloaded_after_modification(self, args: DepManagerArgs) -> Self { + let mut new = Self::with_deps_args(self.deps, args); + new.latest_versions = self.latest_versions; + new + } + fn with_deps_args(deps: Vec, args: DepManagerArgs) -> Self { + let DepManagerArgs { + module_load_preparer, + jsr_fetch_resolver, + npm_fetch_resolver, + npm_resolver, + permissions_container, + main_module_graph_container, + lockfile, + } = args; + Self { + deps, + resolved_versions: Vec::new(), + latest_versions: Vec::new(), + jsr_fetch_resolver, + dependencies_resolved: AtomicBool::new(false), + module_load_preparer, + npm_fetch_resolver, + npm_resolver, + permissions_container, + main_module_graph_container, + lockfile, + pending_changes: Vec::new(), + } + } + pub fn from_workspace_dir( + workspace_dir: &Arc, + dep_filter: impl DepFilter, + args: DepManagerArgs, + ) -> Result { + let mut deps = Vec::with_capacity(256); + if let Some(deno_json) = workspace_dir.maybe_deno_json() { + if deno_json.specifier.scheme() != "file" { + bail!("remote deno.json files are not supported"); + } + let path = deno_json.specifier.to_file_path().unwrap(); + if path.parent().unwrap() == workspace_dir.dir_path() { + add_deps_from_deno_json(deno_json, dep_filter, &mut deps); + } + } + if let Some(package_json) = workspace_dir.maybe_pkg_json() { + add_deps_from_package_json(package_json, dep_filter, &mut deps); + } + + Ok(Self::with_deps_args(deps, args)) + } + pub fn from_workspace( + workspace: &Arc, + dep_filter: impl DepFilter, + args: DepManagerArgs, + ) -> Result { + let deps = deps_from_workspace(workspace, dep_filter)?; + Ok(Self::with_deps_args(deps, args)) + } + + async fn run_dependency_resolution(&self) -> Result<(), AnyError> { + if self + .dependencies_resolved + .load(std::sync::atomic::Ordering::Relaxed) + { + return Ok(()); + } + + let mut graph_permit = self + .main_module_graph_container + .acquire_update_permit() + .await; + let graph = graph_permit.graph_mut(); + // populate the information from the lockfile + if let Some(lockfile) = &self.lockfile { + let lockfile = lockfile.lock(); + graph.fill_from_lockfile(FillFromLockfileOptions { + redirects: lockfile + .content + .redirects + .iter() + .map(|(from, to)| (from.as_str(), to.as_str())), + package_specifiers: lockfile + .content + .packages + .specifiers + .iter() + .map(|(dep, id)| (dep, id.as_str())), + }); + } + + let npm_resolver = self.npm_resolver.as_managed().unwrap(); + if self.deps.iter().all(|dep| match dep.kind { + DepKind::Npm => { + npm_resolver.resolve_pkg_id_from_pkg_req(&dep.req).is_ok() + } + DepKind::Jsr => graph.packages.mappings().contains_key(&dep.req), + }) { + self + .dependencies_resolved + .store(true, std::sync::atomic::Ordering::Relaxed); + graph_permit.commit(); + return Ok(()); + } + + npm_resolver.ensure_top_level_package_json_install().await?; + let mut roots = Vec::new(); + let mut info_futures = FuturesUnordered::new(); + for dep in &self.deps { + if dep.location.is_deno_json() { + match dep.kind { + DepKind::Npm => roots.push( + ModuleSpecifier::parse(&format!("npm:/{}/", dep.req)).unwrap(), + ), + DepKind::Jsr => info_futures.push(async { + if let Some(nv) = self.jsr_fetch_resolver.req_to_nv(&dep.req).await + { + if let Some(info) = + self.jsr_fetch_resolver.package_version_info(&nv).await + { + let specifier = + ModuleSpecifier::parse(&format!("jsr:/{}/", dep.req)) + .unwrap(); + return Some((specifier, info)); + } + } + None + }), + } + } + } + + while let Some(info_future) = info_futures.next().await { + if let Some((specifier, info)) = info_future { + let exports = info.exports(); + for (k, _) in exports { + if let Ok(spec) = specifier.join(k) { + roots.push(spec); + } + } + } + } + + self + .module_load_preparer + .prepare_module_load( + graph, + &roots, + false, + deno_config::deno_json::TsTypeLib::DenoWindow, + self.permissions_container.clone(), + None, + ) + .await?; + + graph_permit.commit(); + + Ok(()) + } + + pub fn resolved_version(&self, id: DepId) -> Option<&PackageNv> { + self.resolved_versions[id.0].as_ref() + } + + pub async fn resolve_current_versions(&mut self) -> Result<(), AnyError> { + self.run_dependency_resolution().await?; + + let graph = self.main_module_graph_container.graph(); + + let mut resolved = Vec::with_capacity(self.deps.len()); + let snapshot = self.npm_resolver.as_managed().unwrap().snapshot(); + let resolved_npm = snapshot.package_reqs(); + let resolved_jsr = graph.packages.mappings(); + for dep in &self.deps { + match dep.kind { + DepKind::Npm => { + let resolved_version = resolved_npm.get(&dep.req).cloned(); + resolved.push(resolved_version); + } + DepKind::Jsr => { + let resolved_version = resolved_jsr.get(&dep.req).cloned(); + resolved.push(resolved_version) + } + } + } + + self.resolved_versions = resolved; + + Ok(()) + } + + async fn load_latest_versions( + &self, + ) -> Result, AnyError> { + if self.latest_versions.len() == self.deps.len() { + return Ok(self.latest_versions.clone()); + } + let latest_tag_req = deno_semver::VersionReq::from_raw_text_and_inner( + "latest".into(), + deno_semver::RangeSetOrTag::Tag("latest".into()), + ); + let mut latest_versions = Vec::with_capacity(self.deps.len()); + + let npm_sema = Semaphore::new(32); + let jsr_sema = Semaphore::new(32); + let mut futs = FuturesOrdered::new(); + + for dep in &self.deps { + match dep.kind { + DepKind::Npm => futs.push_back( + async { + let semver_req = &dep.req; + let latest_req = PackageReq { + name: dep.req.name.clone(), + version_req: latest_tag_req.clone(), + }; + let _permit = npm_sema.acquire().await; + let semver_compatible = + self.npm_fetch_resolver.req_to_nv(semver_req).await; + let latest = self.npm_fetch_resolver.req_to_nv(&latest_req).await; + PackageLatestVersion { + latest, + semver_compatible, + } + } + .boxed_local(), + ), + DepKind::Jsr => futs.push_back( + async { + let semver_req = &dep.req; + let latest_req = PackageReq { + name: dep.req.name.clone(), + version_req: deno_semver::WILDCARD_VERSION_REQ.clone(), + }; + let _permit = jsr_sema.acquire().await; + let semver_compatible = + self.jsr_fetch_resolver.req_to_nv(semver_req).await; + let latest = self.jsr_fetch_resolver.req_to_nv(&latest_req).await; + PackageLatestVersion { + latest, + semver_compatible, + } + } + .boxed_local(), + ), + } + } + while let Some(nv) = futs.next().await { + latest_versions.push(nv); + } + + Ok(latest_versions) + } + + pub async fn resolve_versions(&mut self) -> Result<(), AnyError> { + let (_, latest_versions) = try_join( + self.run_dependency_resolution(), + self.load_latest_versions(), + ) + .await?; + + self.latest_versions = latest_versions; + + self.resolve_current_versions().await?; + + Ok(()) + } + + pub fn deps_with_resolved_latest_versions( + &self, + ) -> impl IntoIterator, PackageLatestVersion)> + '_ + { + self + .resolved_versions + .iter() + .zip(self.latest_versions.iter()) + .enumerate() + .map(|(i, (resolved, latest))| { + (DepId(i), resolved.clone(), latest.clone()) + }) + } + + pub fn get_dep(&self, id: DepId) -> &Dep { + &self.deps[id.0] + } + + pub fn update_dep(&mut self, dep_id: DepId, new_version_req: VersionReq) { + self + .pending_changes + .push(Change::Update(dep_id, new_version_req)); + } + + pub fn commit_changes(&mut self) -> Result<(), AnyError> { + let changes = std::mem::take(&mut self.pending_changes); + let mut config_updaters = HashMap::new(); + for change in changes { + match change { + Change::Update(dep_id, version_req) => { + // TODO: move most of this to ConfigUpdater + let dep = &mut self.deps[dep_id.0]; + dep.req.version_req = version_req.clone(); + match &dep.location { + DepLocation::DenoJson(arc, key_path, import_map_kind) => { + if matches!(import_map_kind, ImportMapKind::Outline) { + // not supported + continue; + } + let updater = + get_or_create_updater(&mut config_updaters, &dep.location)?; + + let Some(property) = updater.get_property_for_mutation(key_path) + else { + log::warn!( + "failed to find property at path {key_path:?} for file {}", + arc.specifier + ); + continue; + }; + let Some(string_value) = cst_string_literal(&property) else { + continue; + }; + let mut req_reference = match dep.kind { + DepKind::Npm => NpmPackageReqReference::from_str(&string_value) + .unwrap() + .into_inner(), + DepKind::Jsr => JsrPackageReqReference::from_str(&string_value) + .unwrap() + .into_inner(), + }; + req_reference.req.version_req = version_req; + let mut new_value = + format!("{}:{}", dep.kind.scheme(), req_reference); + if string_value.ends_with('/') && !new_value.ends_with('/') { + // the display impl for PackageReqReference maps `/` to the root + // subpath, but for the import map the trailing `/` is significant + new_value.push('/'); + } + if string_value + .trim_start_matches(format!("{}:", dep.kind.scheme()).as_str()) + .starts_with('/') + { + // this is gross + new_value = new_value.replace(':', ":/"); + } + property + .set_value(jsonc_parser::cst::CstInputValue::String(new_value)); + } + DepLocation::PackageJson(arc, key_path) => { + let updater = + get_or_create_updater(&mut config_updaters, &dep.location)?; + let Some(property) = updater.get_property_for_mutation(key_path) + else { + log::warn!( + "failed to find property at path {key_path:?} for file {}", + arc.path.display() + ); + continue; + }; + let Some(string_value) = cst_string_literal(&property) else { + continue; + }; + let new_value = if string_value.starts_with("npm:") { + // aliased + let rest = string_value.trim_start_matches("npm:"); + let mut parts = rest.split('@'); + let first = parts.next().unwrap(); + if first.is_empty() { + let scope_and_name = parts.next().unwrap(); + format!("npm:@{scope_and_name}@{version_req}") + } else { + format!("npm:{first}@{version_req}") + } + } else if string_value.contains(":") { + bail!("Unexpected package json dependency string: \"{string_value}\" in {}", arc.path.display()); + } else { + version_req.to_string() + }; + property + .set_value(jsonc_parser::cst::CstInputValue::String(new_value)); + } + } + } + } + } + + for (_, updater) in config_updaters { + updater.commit()?; + } + + Ok(()) + } +} + +fn get_or_create_updater<'a>( + config_updaters: &'a mut HashMap, + location: &DepLocation, +) -> Result<&'a mut ConfigUpdater, AnyError> { + match config_updaters.entry(location.file_path().into_owned()) { + std::collections::hash_map::Entry::Occupied(occupied_entry) => { + Ok(occupied_entry.into_mut()) + } + std::collections::hash_map::Entry::Vacant(vacant_entry) => { + let updater = ConfigUpdater::new( + location.config_kind(), + location.file_path().into_owned(), + )?; + Ok(vacant_entry.insert(updater)) + } + } +} + +fn cst_string_literal( + property: &jsonc_parser::cst::CstObjectProp, +) -> Option { + // TODO(nathanwhit): ensure this unwrap is safe + let value = property.value().unwrap(); + let Some(string) = value.as_string_lit() else { + log::warn!("malformed entry"); + return None; + }; + let Ok(string_value) = string.decoded_value() else { + log::warn!("malformed string: {string:?}"); + return None; + }; + Some(string_value) +} + +fn parse_req_reference( + input: &str, + kind: DepKind, +) -> Result< + PackageReqReference, + deno_semver::package::PackageReqReferenceParseError, +> { + Ok(match kind { + DepKind::Npm => NpmPackageReqReference::from_str(input)?.into_inner(), + DepKind::Jsr => JsrPackageReqReference::from_str(input)?.into_inner(), + }) +} diff --git a/cli/tools/registry/pm/outdated.rs b/cli/tools/registry/pm/outdated.rs new file mode 100644 index 0000000000..2a29014267 --- /dev/null +++ b/cli/tools/registry/pm/outdated.rs @@ -0,0 +1,661 @@ +// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. + +use std::collections::HashSet; +use std::sync::Arc; + +use deno_core::error::AnyError; +use deno_semver::package::PackageNv; +use deno_semver::package::PackageReq; +use deno_semver::VersionReq; +use deno_terminal::colors; + +use crate::args::CacheSetting; +use crate::args::CliOptions; +use crate::args::Flags; +use crate::args::OutdatedFlags; +use crate::factory::CliFactory; +use crate::file_fetcher::FileFetcher; +use crate::jsr::JsrFetchResolver; +use crate::npm::NpmFetchResolver; +use crate::tools::registry::pm::deps::DepKind; + +use super::deps::Dep; +use super::deps::DepManager; +use super::deps::DepManagerArgs; +use super::deps::PackageLatestVersion; + +#[derive(Debug, PartialEq, Eq, PartialOrd, Ord)] +struct OutdatedPackage { + kind: DepKind, + latest: String, + semver_compatible: String, + current: String, + name: String, +} + +#[allow(clippy::print_stdout)] +fn print_outdated_table(packages: &[OutdatedPackage]) { + const HEADINGS: &[&str] = &["Package", "Current", "Update", "Latest"]; + + let mut longest_package = 0; + let mut longest_current = 0; + let mut longest_update = 0; + let mut longest_latest = 0; + + for package in packages { + let name_len = package.kind.scheme().len() + 1 + package.name.len(); + longest_package = longest_package.max(name_len); + longest_current = longest_current.max(package.current.len()); + longest_update = longest_update.max(package.semver_compatible.len()); + longest_latest = longest_latest.max(package.latest.len()); + } + + let package_column_width = longest_package.max(HEADINGS[0].len()) + 2; + let current_column_width = longest_current.max(HEADINGS[1].len()) + 2; + let update_column_width = longest_update.max(HEADINGS[2].len()) + 2; + let latest_column_width = longest_latest.max(HEADINGS[3].len()) + 2; + + let package_fill = "─".repeat(package_column_width); + let current_fill = "─".repeat(current_column_width); + let update_fill = "─".repeat(update_column_width); + let latest_fill = "─".repeat(latest_column_width); + + println!("┌{package_fill}┬{current_fill}┬{update_fill}┬{latest_fill}┐"); + println!( + "│ {}{} │ {}{} │ {}{} │ {}{} │", + colors::intense_blue(HEADINGS[0]), + " ".repeat(package_column_width - 2 - HEADINGS[0].len()), + colors::intense_blue(HEADINGS[1]), + " ".repeat(current_column_width - 2 - HEADINGS[1].len()), + colors::intense_blue(HEADINGS[2]), + " ".repeat(update_column_width - 2 - HEADINGS[2].len()), + colors::intense_blue(HEADINGS[3]), + " ".repeat(latest_column_width - 2 - HEADINGS[3].len()) + ); + for package in packages { + println!("├{package_fill}┼{current_fill}┼{update_fill}┼{latest_fill}┤",); + + print!( + "│ {: Result<(), AnyError> { + let mut outdated = Vec::new(); + let mut seen = std::collections::BTreeSet::new(); + for (dep_id, resolved, latest_versions) in + deps.deps_with_resolved_latest_versions() + { + let dep = deps.get_dep(dep_id); + + let Some(resolved) = resolved else { continue }; + + let latest = { + let preferred = if compatible { + &latest_versions.semver_compatible + } else { + &latest_versions.latest + }; + if let Some(v) = preferred { + v + } else { + continue; + } + }; + + if latest > &resolved + && seen.insert((dep.kind, dep.req.name.clone(), resolved.version.clone())) + { + outdated.push(OutdatedPackage { + kind: dep.kind, + name: dep.req.name.clone(), + current: resolved.version.to_string(), + latest: latest_versions + .latest + .map(|l| l.version.to_string()) + .unwrap_or_default(), + semver_compatible: latest_versions + .semver_compatible + .map(|l| l.version.to_string()) + .unwrap_or_default(), + }) + } + } + + if !outdated.is_empty() { + outdated.sort(); + print_outdated_table(&outdated); + } + + Ok(()) +} + +pub async fn outdated( + flags: Arc, + update_flags: OutdatedFlags, +) -> Result<(), AnyError> { + let factory = CliFactory::from_flags(flags.clone()); + let cli_options = factory.cli_options()?; + let workspace = cli_options.workspace(); + let http_client = factory.http_client_provider(); + let deps_http_cache = factory.global_http_cache()?; + let mut file_fetcher = FileFetcher::new( + deps_http_cache.clone(), + CacheSetting::RespectHeaders, + true, + http_client.clone(), + Default::default(), + None, + ); + file_fetcher.set_download_log_level(log::Level::Trace); + let file_fetcher = Arc::new(file_fetcher); + let npm_fetch_resolver = Arc::new(NpmFetchResolver::new( + file_fetcher.clone(), + cli_options.npmrc().clone(), + )); + let jsr_fetch_resolver = + Arc::new(JsrFetchResolver::new(file_fetcher.clone())); + + let args = dep_manager_args( + &factory, + cli_options, + npm_fetch_resolver.clone(), + jsr_fetch_resolver.clone(), + ) + .await?; + + let filter_set = filter::FilterSet::from_filter_strings( + update_flags.filters.iter().map(|s| s.as_str()), + )?; + + let filter_fn = |alias: Option<&str>, req: &PackageReq, _: DepKind| { + if filter_set.is_empty() { + return true; + } + let name = alias.unwrap_or(&req.name); + filter_set.matches(name) + }; + let mut deps = if update_flags.recursive { + super::deps::DepManager::from_workspace(workspace, filter_fn, args)? + } else { + super::deps::DepManager::from_workspace_dir( + &cli_options.start_dir, + filter_fn, + args, + )? + }; + + deps.resolve_versions().await?; + + match update_flags.kind { + crate::args::OutdatedKind::Update { latest } => { + update(deps, latest, &filter_set, flags).await?; + } + crate::args::OutdatedKind::PrintOutdated { compatible } => { + print_outdated(&mut deps, compatible)?; + } + } + + Ok(()) +} + +fn choose_new_version_req( + dep: &Dep, + resolved: Option<&PackageNv>, + latest_versions: &PackageLatestVersion, + update_to_latest: bool, + filter_set: &filter::FilterSet, +) -> Option { + let explicit_version_req = filter_set + .matching_filter(dep.alias.as_deref().unwrap_or(&dep.req.name)) + .version_spec() + .cloned(); + + if let Some(version_req) = explicit_version_req { + if let Some(resolved) = resolved { + // todo(nathanwhit): handle tag + if version_req.tag().is_none() && version_req.matches(&resolved.version) { + return None; + } + } + Some(version_req) + } else { + let preferred = if update_to_latest { + latest_versions.latest.as_ref()? + } else { + latest_versions.semver_compatible.as_ref()? + }; + if preferred.version <= resolved?.version { + return None; + } + Some( + VersionReq::parse_from_specifier( + format!("^{}", preferred.version).as_str(), + ) + .unwrap(), + ) + } +} + +async fn update( + mut deps: DepManager, + update_to_latest: bool, + filter_set: &filter::FilterSet, + flags: Arc, +) -> Result<(), AnyError> { + let mut updated = Vec::new(); + + for (dep_id, resolved, latest_versions) in deps + .deps_with_resolved_latest_versions() + .into_iter() + .collect::>() + { + let dep = deps.get_dep(dep_id); + let new_version_req = choose_new_version_req( + dep, + resolved.as_ref(), + &latest_versions, + update_to_latest, + filter_set, + ); + let Some(new_version_req) = new_version_req else { + continue; + }; + + updated.push(( + dep_id, + format!("{}:{}", dep.kind.scheme(), dep.req.name), + deps.resolved_version(dep.id).cloned(), + new_version_req.clone(), + )); + + deps.update_dep(dep_id, new_version_req); + } + + deps.commit_changes()?; + + if !updated.is_empty() { + let factory = super::npm_install_after_modification( + flags.clone(), + Some(deps.jsr_fetch_resolver.clone()), + ) + .await?; + + let mut updated_to_versions = HashSet::new(); + let cli_options = factory.cli_options()?; + let args = dep_manager_args( + &factory, + cli_options, + deps.npm_fetch_resolver.clone(), + deps.jsr_fetch_resolver.clone(), + ) + .await?; + + let mut deps = deps.reloaded_after_modification(args); + deps.resolve_current_versions().await?; + for (dep_id, package_name, maybe_current_version, new_version_req) in + updated + { + if let Some(nv) = deps.resolved_version(dep_id) { + updated_to_versions.insert(( + package_name, + maybe_current_version, + nv.version.clone(), + )); + } else { + log::warn!( + "Failed to resolve version for new version requirement: {} -> {}", + package_name, + new_version_req + ); + } + } + + log::info!( + "Updated {} dependenc{}:", + updated_to_versions.len(), + if updated_to_versions.len() == 1 { + "y" + } else { + "ies" + } + ); + let mut updated_to_versions = + updated_to_versions.into_iter().collect::>(); + updated_to_versions.sort_by(|(k, _, _), (k2, _, _)| k.cmp(k2)); + let max_name = updated_to_versions + .iter() + .map(|(name, _, _)| name.len()) + .max() + .unwrap_or(0); + let max_old = updated_to_versions + .iter() + .map(|(_, maybe_current, _)| { + maybe_current + .as_ref() + .map(|v| v.version.to_string().len()) + .unwrap_or(0) + }) + .max() + .unwrap_or(0); + let max_new = updated_to_versions + .iter() + .map(|(_, _, new_version)| new_version.to_string().len()) + .max() + .unwrap_or(0); + + for (package_name, maybe_current_version, new_version) in + updated_to_versions + { + let current_version = if let Some(current_version) = maybe_current_version + { + current_version.version.to_string() + } else { + "".to_string() + }; + + log::info!( + " - {}{} {}{} -> {}{}", + format!( + "{}{}", + colors::gray(package_name[0..4].to_string()), + package_name[4..].to_string() + ), + " ".repeat(max_name - package_name.len()), + " ".repeat(max_old - current_version.len()), + colors::gray(¤t_version), + " ".repeat(max_new - new_version.to_string().len()), + colors::green(&new_version), + ); + } + } else { + log::info!( + "All {}dependencies are up to date.", + if filter_set.is_empty() { + "" + } else { + "matching " + } + ); + } + + Ok(()) +} + +async fn dep_manager_args( + factory: &CliFactory, + cli_options: &CliOptions, + npm_fetch_resolver: Arc, + jsr_fetch_resolver: Arc, +) -> Result { + Ok(DepManagerArgs { + module_load_preparer: factory.module_load_preparer().await?.clone(), + jsr_fetch_resolver, + npm_fetch_resolver, + npm_resolver: factory.npm_resolver().await?.clone(), + permissions_container: factory.root_permissions_container()?.clone(), + main_module_graph_container: factory + .main_module_graph_container() + .await? + .clone(), + lockfile: cli_options.maybe_lockfile().cloned(), + }) +} + +mod filter { + use deno_core::anyhow::anyhow; + use deno_core::anyhow::Context; + use deno_core::error::AnyError; + use deno_semver::VersionReq; + + enum FilterKind { + Exclude, + Include, + } + pub struct Filter { + kind: FilterKind, + regex: regex::Regex, + version_spec: Option, + } + + fn pattern_to_regex(pattern: &str) -> Result { + let escaped = regex::escape(pattern); + let unescaped_star = escaped.replace(r"\*", ".*"); + Ok(regex::Regex::new(&format!("^{}$", unescaped_star))?) + } + + impl Filter { + pub fn version_spec(&self) -> Option<&VersionReq> { + self.version_spec.as_ref() + } + pub fn from_str(input: &str) -> Result { + let (kind, first_idx) = if input.starts_with('!') { + (FilterKind::Exclude, 1) + } else { + (FilterKind::Include, 0) + }; + let s = &input[first_idx..]; + let (pattern, version_spec) = + if let Some(scope_name) = s.strip_prefix('@') { + if let Some(idx) = scope_name.find('@') { + let (pattern, version_spec) = s.split_at(idx + 1); + ( + pattern, + Some( + VersionReq::parse_from_specifier( + version_spec.trim_start_matches('@'), + ) + .with_context(|| format!("Invalid filter \"{input}\""))?, + ), + ) + } else { + (s, None) + } + } else { + let mut parts = s.split('@'); + let Some(pattern) = parts.next() else { + return Err(anyhow!("Invalid filter \"{input}\"")); + }; + ( + pattern, + parts + .next() + .map(VersionReq::parse_from_specifier) + .transpose() + .with_context(|| format!("Invalid filter \"{input}\""))?, + ) + }; + + Ok(Filter { + kind, + regex: pattern_to_regex(pattern) + .with_context(|| format!("Invalid filter \"{input}\""))?, + version_spec, + }) + } + + pub fn matches(&self, name: &str) -> bool { + self.regex.is_match(name) + } + } + + pub struct FilterSet { + filters: Vec, + has_exclude: bool, + has_include: bool, + } + impl FilterSet { + pub fn from_filter_strings<'a>( + filter_strings: impl IntoIterator, + ) -> Result { + let filters = filter_strings + .into_iter() + .map(Filter::from_str) + .collect::, _>>()?; + let has_exclude = filters + .iter() + .any(|f| matches!(f.kind, FilterKind::Exclude)); + let has_include = filters + .iter() + .any(|f| matches!(f.kind, FilterKind::Include)); + Ok(FilterSet { + filters, + has_exclude, + has_include, + }) + } + + pub fn is_empty(&self) -> bool { + self.filters.is_empty() + } + + pub fn matches(&self, name: &str) -> bool { + self.matching_filter(name).is_included() + } + + pub fn matching_filter(&self, name: &str) -> MatchResult<'_> { + if self.filters.is_empty() { + return MatchResult::Included; + } + let mut matched = None; + for filter in &self.filters { + match filter.kind { + FilterKind::Include => { + if matched.is_none() && filter.matches(name) { + matched = Some(filter); + } + } + FilterKind::Exclude => { + if filter.matches(name) { + return MatchResult::Excluded; + } + } + } + } + if let Some(filter) = matched { + MatchResult::Matches(filter) + } else if self.has_exclude && !self.has_include { + MatchResult::Included + } else { + MatchResult::Excluded + } + } + } + + pub enum MatchResult<'a> { + Matches(&'a Filter), + Included, + Excluded, + } + + impl MatchResult<'_> { + pub fn version_spec(&self) -> Option<&VersionReq> { + match self { + MatchResult::Matches(filter) => filter.version_spec(), + _ => None, + } + } + pub fn is_included(&self) -> bool { + matches!(self, MatchResult::Included | MatchResult::Matches(_)) + } + } + + #[cfg(test)] + mod test { + fn matches_filters<'a, 'b>( + filters: impl IntoIterator, + name: &str, + ) -> bool { + let filters = super::FilterSet::from_filter_strings(filters).unwrap(); + filters.matches(name) + } + + fn version_spec(s: &str) -> deno_semver::VersionReq { + deno_semver::VersionReq::parse_from_specifier(s).unwrap() + } + + #[test] + fn basic_glob() { + assert!(matches_filters(["foo*"], "foo")); + assert!(matches_filters(["foo*"], "foobar")); + assert!(!matches_filters(["foo*"], "barfoo")); + + assert!(matches_filters(["*foo"], "foo")); + assert!(matches_filters(["*foo"], "barfoo")); + assert!(!matches_filters(["*foo"], "foobar")); + + assert!(matches_filters(["@scope/foo*"], "@scope/foobar")); + } + + #[test] + fn basic_glob_with_version() { + assert!(matches_filters(["foo*@1"], "foo",)); + assert!(matches_filters(["foo*@1"], "foobar",)); + assert!(matches_filters(["foo*@1"], "foo-bar",)); + assert!(!matches_filters(["foo*@1"], "barfoo",)); + assert!(matches_filters(["@scope/*@1"], "@scope/foo")); + } + + #[test] + fn glob_exclude() { + assert!(!matches_filters(["!foo*"], "foo")); + assert!(!matches_filters(["!foo*"], "foobar")); + assert!(matches_filters(["!foo*"], "barfoo")); + + assert!(!matches_filters(["!*foo"], "foo")); + assert!(!matches_filters(["!*foo"], "barfoo")); + assert!(matches_filters(["!*foo"], "foobar")); + + assert!(!matches_filters(["!@scope/foo*"], "@scope/foobar")); + } + + #[test] + fn multiple_globs() { + assert!(matches_filters(["foo*", "bar*"], "foo")); + assert!(matches_filters(["foo*", "bar*"], "bar")); + assert!(!matches_filters(["foo*", "bar*"], "baz")); + + assert!(matches_filters(["foo*", "!bar*"], "foo")); + assert!(!matches_filters(["foo*", "!bar*"], "bar")); + assert!(matches_filters(["foo*", "!bar*"], "foobar")); + assert!(!matches_filters(["foo*", "!*bar"], "foobar")); + assert!(!matches_filters(["foo*", "!*bar"], "baz")); + + let filters = + super::FilterSet::from_filter_strings(["foo*@1", "bar*@2"]).unwrap(); + + assert_eq!( + filters.matching_filter("foo").version_spec().cloned(), + Some(version_spec("1")) + ); + + assert_eq!( + filters.matching_filter("bar").version_spec().cloned(), + Some(version_spec("2")) + ); + } + } +} diff --git a/tests/registry/jsr/@denotest/add/0.2.1/mod.ts b/tests/registry/jsr/@denotest/add/0.2.1/mod.ts new file mode 100644 index 0000000000..864e8dd321 --- /dev/null +++ b/tests/registry/jsr/@denotest/add/0.2.1/mod.ts @@ -0,0 +1,4 @@ +// This is renamed to `add()` in 1.0.0. +export function sum(a: number, b: number): number { + return a + b; +} diff --git a/tests/registry/jsr/@denotest/add/0.2.1_meta.json b/tests/registry/jsr/@denotest/add/0.2.1_meta.json new file mode 100644 index 0000000000..6eebe21985 --- /dev/null +++ b/tests/registry/jsr/@denotest/add/0.2.1_meta.json @@ -0,0 +1,8 @@ +{ + "exports": { + ".": "./mod.ts" + }, + "moduleGraph1": { + "/mod.ts": {} + } +} diff --git a/tests/registry/jsr/@denotest/add/meta.json b/tests/registry/jsr/@denotest/add/meta.json index 72aea80cc3..f1a50109d8 100644 --- a/tests/registry/jsr/@denotest/add/meta.json +++ b/tests/registry/jsr/@denotest/add/meta.json @@ -4,6 +4,7 @@ "yanked": true }, "1.0.0": {}, - "0.2.0": {} + "0.2.0": {}, + "0.2.1": {} } } diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.2.0/add.ts b/tests/registry/jsr/@denotest/multiple-exports/0.2.0/add.ts new file mode 100644 index 0000000000..de02f69024 --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.2.0/add.ts @@ -0,0 +1 @@ +export * from "jsr:@denotest/add@1"; diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.2.0/data.json b/tests/registry/jsr/@denotest/multiple-exports/0.2.0/data.json new file mode 100644 index 0000000000..885e71c6cc --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.2.0/data.json @@ -0,0 +1,3 @@ +{ + "a": 1 +} \ No newline at end of file diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.2.0/subtract.ts b/tests/registry/jsr/@denotest/multiple-exports/0.2.0/subtract.ts new file mode 100644 index 0000000000..215c42310d --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.2.0/subtract.ts @@ -0,0 +1 @@ +export * from "jsr:@denotest/subtract@1"; diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.2.0_meta.json b/tests/registry/jsr/@denotest/multiple-exports/0.2.0_meta.json new file mode 100644 index 0000000000..d9f58b9a61 --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.2.0_meta.json @@ -0,0 +1,7 @@ +{ + "exports": { + "./add": "./add.ts", + "./subtract": "./subtract.ts", + "./data-json": "./data.json" + } +} diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.5.0/add.ts b/tests/registry/jsr/@denotest/multiple-exports/0.5.0/add.ts new file mode 100644 index 0000000000..de02f69024 --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.5.0/add.ts @@ -0,0 +1 @@ +export * from "jsr:@denotest/add@1"; diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.5.0/data.json b/tests/registry/jsr/@denotest/multiple-exports/0.5.0/data.json new file mode 100644 index 0000000000..885e71c6cc --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.5.0/data.json @@ -0,0 +1,3 @@ +{ + "a": 1 +} \ No newline at end of file diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.5.0/subtract.ts b/tests/registry/jsr/@denotest/multiple-exports/0.5.0/subtract.ts new file mode 100644 index 0000000000..215c42310d --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.5.0/subtract.ts @@ -0,0 +1 @@ +export * from "jsr:@denotest/subtract@1"; diff --git a/tests/registry/jsr/@denotest/multiple-exports/0.5.0_meta.json b/tests/registry/jsr/@denotest/multiple-exports/0.5.0_meta.json new file mode 100644 index 0000000000..d9f58b9a61 --- /dev/null +++ b/tests/registry/jsr/@denotest/multiple-exports/0.5.0_meta.json @@ -0,0 +1,7 @@ +{ + "exports": { + "./add": "./add.ts", + "./subtract": "./subtract.ts", + "./data-json": "./data.json" + } +} diff --git a/tests/registry/jsr/@denotest/multiple-exports/meta.json b/tests/registry/jsr/@denotest/multiple-exports/meta.json index 02601e4d0d..aaaf18a184 100644 --- a/tests/registry/jsr/@denotest/multiple-exports/meta.json +++ b/tests/registry/jsr/@denotest/multiple-exports/meta.json @@ -1,5 +1,7 @@ { "versions": { - "1.0.0": {} + "1.0.0": {}, + "0.5.0": {}, + "0.2.0": {} } } diff --git a/tests/registry/jsr/@denotest/subtract/0.2.0/mod.ts b/tests/registry/jsr/@denotest/subtract/0.2.0/mod.ts new file mode 100644 index 0000000000..74e49ea6fa --- /dev/null +++ b/tests/registry/jsr/@denotest/subtract/0.2.0/mod.ts @@ -0,0 +1,3 @@ +export function sub(a: number, b: number): number { + return a - b; +} diff --git a/tests/registry/jsr/@denotest/subtract/0.2.0_meta.json b/tests/registry/jsr/@denotest/subtract/0.2.0_meta.json new file mode 100644 index 0000000000..6eebe21985 --- /dev/null +++ b/tests/registry/jsr/@denotest/subtract/0.2.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 index 02601e4d0d..2f4cee59df 100644 --- a/tests/registry/jsr/@denotest/subtract/meta.json +++ b/tests/registry/jsr/@denotest/subtract/meta.json @@ -1,5 +1,7 @@ { + "latest": "1.0.0", "versions": { - "1.0.0": {} + "1.0.0": {}, + "0.2.0": {} } } diff --git a/tests/registry/npm/@denotest/has-patch-versions/0.1.0/package.json b/tests/registry/npm/@denotest/has-patch-versions/0.1.0/package.json new file mode 100644 index 0000000000..45684d4f52 --- /dev/null +++ b/tests/registry/npm/@denotest/has-patch-versions/0.1.0/package.json @@ -0,0 +1,5 @@ +{ + "name": "@denotest/has-patch-versions", + "version": "0.1.0" + +} \ No newline at end of file diff --git a/tests/registry/npm/@denotest/has-patch-versions/0.1.1/package.json b/tests/registry/npm/@denotest/has-patch-versions/0.1.1/package.json new file mode 100644 index 0000000000..4483df34e5 --- /dev/null +++ b/tests/registry/npm/@denotest/has-patch-versions/0.1.1/package.json @@ -0,0 +1,5 @@ +{ + "name": "@denotest/has-patch-versions", + "version": "0.1.1" + +} \ No newline at end of file diff --git a/tests/registry/npm/@denotest/has-patch-versions/0.2.0/package.json b/tests/registry/npm/@denotest/has-patch-versions/0.2.0/package.json new file mode 100644 index 0000000000..55efaaa326 --- /dev/null +++ b/tests/registry/npm/@denotest/has-patch-versions/0.2.0/package.json @@ -0,0 +1,4 @@ +{ + "name": "@denotest/has-patch-versions", + "version": "0.2.0" +} \ No newline at end of file diff --git a/tests/specs/update/deno_json/__test__.jsonc b/tests/specs/update/deno_json/__test__.jsonc new file mode 100644 index 0000000000..8b4aa26b5c --- /dev/null +++ b/tests/specs/update/deno_json/__test__.jsonc @@ -0,0 +1,101 @@ +{ + "tempDir": true, + "tests": { + // just to make sure install doesn't change the lockfile + "sanity_lockfile_up_to_date": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": [ + "eval", + "const now = Deno.readTextFileSync('./deno.lock'); console.log(now.trim());" + ], + "output": "deno.lock.orig.out" + } + ] + }, + "print_outdated": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": "outdated", + "output": "outdated.out" + } + ] + }, + "print_outdated_compatible": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": "outdated --compatible", + "output": "outdated_compatible.out" + } + ] + }, + "update_compatible": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": "outdated --update", + "output": "./update_compatible/update.out" + }, + { + "args": "-A print_file.ts ./deno.json", + "output": "./update_compatible/deno.json.out" + }, + { + "args": "-A print_file.ts ./deno.lock", + "output": "./update_compatible/deno.lock.out" + } + ] + }, + "update_latest": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": "outdated --update --latest", + "output": "update_latest/update.out" + }, + { + "args": "-A print_file.ts ./deno.json", + "output": "./update_latest/deno.json.out" + }, + { + "args": "-A print_file.ts ./deno.lock", + "output": "./update_latest/deno.lock.out" + } + ] + }, + "update_filtered": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": "outdated --update --latest @denotest/add @denotest/b* !@denotest/breaking* @denotest/with-subpath@0.5.0", + "output": "filtered/update.out" + }, + { + "args": "-A print_file.ts ./deno.json", + "output": "filtered/deno.json.out" + } + ] + } + } +} diff --git a/tests/specs/update/deno_json/deno.json b/tests/specs/update/deno_json/deno.json new file mode 100644 index 0000000000..4f880e6db9 --- /dev/null +++ b/tests/specs/update/deno_json/deno.json @@ -0,0 +1,19 @@ +{ + "imports": { + "@denotest/add": "jsr:@denotest/add@^0.2.0", + "@denotest/add/": "jsr:/@denotest/add@^0.2.0/", + "@denotest/subtract": "jsr:@denotest/subtract@^0.2.0", + "@denotest/with-subpath": "jsr:@denotest/multiple-exports@0.2.0/data-json", + "@denotest/breaking-change-between-versions": "npm:@denotest/breaking-change-between-versions@1.0.0", + "@denotest/bin": "npm:@denotest/bin@0.6.0", + "@denotest/has-patch-versions": "npm:@denotest/has-patch-versions@^0.1.0" + }, + "scopes": { + "/foo/": { + "@denotest/add": "jsr:@denotest/add@^0.2.0", + "@denotest/add/": "jsr:/@denotest/add@^0.2.0/", + "@denotest/subtract": "jsr:@denotest/subtract@^0.2.0", + "@denotest/with-subpath": "jsr:@denotest/multiple-exports@0.2.0/data-json" + } + } +} diff --git a/tests/specs/update/deno_json/deno.lock b/tests/specs/update/deno_json/deno.lock new file mode 100644 index 0000000000..7c4d5e3690 --- /dev/null +++ b/tests/specs/update/deno_json/deno.lock @@ -0,0 +1,43 @@ +{ + "version": "4", + "specifiers": { + "jsr:@denotest/add@0.2": "0.2.0", + "jsr:@denotest/multiple-exports@0.2.0": "0.2.0", + "jsr:@denotest/subtract@0.2": "0.2.0", + "npm:@denotest/bin@0.6.0": "0.6.0", + "npm:@denotest/breaking-change-between-versions@1.0.0": "1.0.0", + "npm:@denotest/has-patch-versions@0.1": "0.1.0" + }, + "jsr": { + "@denotest/add@0.2.0": { + "integrity": "a9076d30ecb42b2fc6dd95e7055fbf4e6358b53f550741bd7f60089d19f68848" + }, + "@denotest/multiple-exports@0.2.0": { + "integrity": "efe9748a0c0939c7ac245fee04acc0c42bd7a61874ff71a360c4543e4f5f6b36" + }, + "@denotest/subtract@0.2.0": { + "integrity": "c9650fc559ab2430effc0c7fb1540e3aa89888fbdd926335ccfdeac57eb3a64d" + } + }, + "npm": { + "@denotest/bin@0.6.0": { + "integrity": "sha512-vCNpxFgQN4fw4ZOp63nbTX1ilcDqNpvXCvYyC8nmfxQQAezsEt095I/YXwMIoMGzWtjCvlMf9kVEYfLuT5oEGQ==" + }, + "@denotest/breaking-change-between-versions@1.0.0": { + "integrity": "sha512-bzMGYx+DxxPlI74n/VsDAN7Db1BY7Sz2XqxXruMo9dEznsBZu7Ez3i8YQ8n0leTxAiiMk1RCG4zQHPG1aj3xRw==" + }, + "@denotest/has-patch-versions@0.1.0": { + "integrity": "sha512-H/MBo0jKDdMsX4AAGEGQbZj70nfNe3oUNZXbohYHhqf9EfpLnXp/7FC29ZdfV4+p6VjEcOGdCtXc6rilE6iYpg==" + } + }, + "workspace": { + "dependencies": [ + "jsr:@denotest/add@0.2", + "jsr:@denotest/multiple-exports@0.2.0", + "jsr:@denotest/subtract@0.2", + "npm:@denotest/bin@0.6.0", + "npm:@denotest/breaking-change-between-versions@1.0.0", + "npm:@denotest/has-patch-versions@0.1" + ] + } +} diff --git a/tests/specs/update/deno_json/deno.lock.orig.out b/tests/specs/update/deno_json/deno.lock.orig.out new file mode 100644 index 0000000000..7c4d5e3690 --- /dev/null +++ b/tests/specs/update/deno_json/deno.lock.orig.out @@ -0,0 +1,43 @@ +{ + "version": "4", + "specifiers": { + "jsr:@denotest/add@0.2": "0.2.0", + "jsr:@denotest/multiple-exports@0.2.0": "0.2.0", + "jsr:@denotest/subtract@0.2": "0.2.0", + "npm:@denotest/bin@0.6.0": "0.6.0", + "npm:@denotest/breaking-change-between-versions@1.0.0": "1.0.0", + "npm:@denotest/has-patch-versions@0.1": "0.1.0" + }, + "jsr": { + "@denotest/add@0.2.0": { + "integrity": "a9076d30ecb42b2fc6dd95e7055fbf4e6358b53f550741bd7f60089d19f68848" + }, + "@denotest/multiple-exports@0.2.0": { + "integrity": "efe9748a0c0939c7ac245fee04acc0c42bd7a61874ff71a360c4543e4f5f6b36" + }, + "@denotest/subtract@0.2.0": { + "integrity": "c9650fc559ab2430effc0c7fb1540e3aa89888fbdd926335ccfdeac57eb3a64d" + } + }, + "npm": { + "@denotest/bin@0.6.0": { + "integrity": "sha512-vCNpxFgQN4fw4ZOp63nbTX1ilcDqNpvXCvYyC8nmfxQQAezsEt095I/YXwMIoMGzWtjCvlMf9kVEYfLuT5oEGQ==" + }, + "@denotest/breaking-change-between-versions@1.0.0": { + "integrity": "sha512-bzMGYx+DxxPlI74n/VsDAN7Db1BY7Sz2XqxXruMo9dEznsBZu7Ez3i8YQ8n0leTxAiiMk1RCG4zQHPG1aj3xRw==" + }, + "@denotest/has-patch-versions@0.1.0": { + "integrity": "sha512-H/MBo0jKDdMsX4AAGEGQbZj70nfNe3oUNZXbohYHhqf9EfpLnXp/7FC29ZdfV4+p6VjEcOGdCtXc6rilE6iYpg==" + } + }, + "workspace": { + "dependencies": [ + "jsr:@denotest/add@0.2", + "jsr:@denotest/multiple-exports@0.2.0", + "jsr:@denotest/subtract@0.2", + "npm:@denotest/bin@0.6.0", + "npm:@denotest/breaking-change-between-versions@1.0.0", + "npm:@denotest/has-patch-versions@0.1" + ] + } +} diff --git a/tests/specs/update/deno_json/filtered/deno.json.out b/tests/specs/update/deno_json/filtered/deno.json.out new file mode 100644 index 0000000000..4458e2d037 --- /dev/null +++ b/tests/specs/update/deno_json/filtered/deno.json.out @@ -0,0 +1,19 @@ +{ + "imports": { + "@denotest/add": "jsr:@denotest/add@^1.0.0", + "@denotest/add/": "jsr:/@denotest/add@^1.0.0/", + "@denotest/subtract": "jsr:@denotest/subtract@^0.2.0", + "@denotest/with-subpath": "jsr:@denotest/multiple-exports@0.5.0/data-json", + "@denotest/breaking-change-between-versions": "npm:@denotest/breaking-change-between-versions@1.0.0", + "@denotest/bin": "npm:@denotest/bin@^1.0.0", + "@denotest/has-patch-versions": "npm:@denotest/has-patch-versions@^0.1.0" + }, + "scopes": { + "/foo/": { + "@denotest/add": "jsr:@denotest/add@^1.0.0", + "@denotest/add/": "jsr:/@denotest/add@^1.0.0/", + "@denotest/subtract": "jsr:@denotest/subtract@^0.2.0", + "@denotest/with-subpath": "jsr:@denotest/multiple-exports@0.5.0/data-json" + } + } +} diff --git a/tests/specs/update/deno_json/filtered/update.out b/tests/specs/update/deno_json/filtered/update.out new file mode 100644 index 0000000000..ce16c6f6b7 --- /dev/null +++ b/tests/specs/update/deno_json/filtered/update.out @@ -0,0 +1,10 @@ +[UNORDERED_START] +Download http://localhost:4260/@denotest/bin/1.0.0.tgz +Download http://127.0.0.1:4250/@denotest/multiple-exports/0.5.0_meta.json +Download http://127.0.0.1:4250/@denotest/multiple-exports/0.5.0/data.json +Download http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts +[UNORDERED_END] +Updated 3 dependencies: + - jsr:@denotest/add 0.2.0 -> 1.0.0 + - jsr:@denotest/multiple-exports 0.2.0 -> 0.5.0 + - npm:@denotest/bin 0.6.0 -> 1.0.0 diff --git a/tests/specs/update/deno_json/outdated.out b/tests/specs/update/deno_json/outdated.out new file mode 100644 index 0000000000..07ff9f3416 --- /dev/null +++ b/tests/specs/update/deno_json/outdated.out @@ -0,0 +1,15 @@ +┌────────────────────────────────────────────────┬─────────┬────────┬────────┐ +│ Package │ Current │ Update │ Latest │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ jsr:@denotest/multiple-exports │ 0.2.0 │ 0.2.0 │ 1.0.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ jsr:@denotest/subtract │ 0.2.0 │ 0.2.0 │ 1.0.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ jsr:@denotest/add │ 0.2.0 │ 0.2.1 │ 1.0.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/has-patch-versions │ 0.1.0 │ 0.1.1 │ 0.2.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/bin │ 0.6.0 │ 0.6.0 │ 1.0.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/breaking-change-between-versions │ 1.0.0 │ 1.0.0 │ 2.0.0 │ +└────────────────────────────────────────────────┴─────────┴────────┴────────┘ diff --git a/tests/specs/update/deno_json/outdated_compatible.out b/tests/specs/update/deno_json/outdated_compatible.out new file mode 100644 index 0000000000..54511a537f --- /dev/null +++ b/tests/specs/update/deno_json/outdated_compatible.out @@ -0,0 +1,7 @@ +┌──────────────────────────────────┬─────────┬────────┬────────┐ +│ Package │ Current │ Update │ Latest │ +├──────────────────────────────────┼─────────┼────────┼────────┤ +│ jsr:@denotest/add │ 0.2.0 │ 0.2.1 │ 1.0.0 │ +├──────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/has-patch-versions │ 0.1.0 │ 0.1.1 │ 0.2.0 │ +└──────────────────────────────────┴─────────┴────────┴────────┘ diff --git a/tests/specs/update/deno_json/print_file.ts b/tests/specs/update/deno_json/print_file.ts new file mode 100644 index 0000000000..c57b6c3a4e --- /dev/null +++ b/tests/specs/update/deno_json/print_file.ts @@ -0,0 +1,2 @@ +const file = Deno.args[0]; +console.log(Deno.readTextFileSync(file).trim()); diff --git a/tests/specs/update/deno_json/update_compatible/deno.json.out b/tests/specs/update/deno_json/update_compatible/deno.json.out new file mode 100644 index 0000000000..e453eff3c9 --- /dev/null +++ b/tests/specs/update/deno_json/update_compatible/deno.json.out @@ -0,0 +1,19 @@ +{ + "imports": { + "@denotest/add": "jsr:@denotest/add@^0.2.1", + "@denotest/add/": "jsr:/@denotest/add@^0.2.1/", + "@denotest/subtract": "jsr:@denotest/subtract@^0.2.0", + "@denotest/with-subpath": "jsr:@denotest/multiple-exports@0.2.0/data-json", + "@denotest/breaking-change-between-versions": "npm:@denotest/breaking-change-between-versions@1.0.0", + "@denotest/bin": "npm:@denotest/bin@0.6.0", + "@denotest/has-patch-versions": "npm:@denotest/has-patch-versions@^0.1.1" + }, + "scopes": { + "/foo/": { + "@denotest/add": "jsr:@denotest/add@^0.2.1", + "@denotest/add/": "jsr:/@denotest/add@^0.2.1/", + "@denotest/subtract": "jsr:@denotest/subtract@^0.2.0", + "@denotest/with-subpath": "jsr:@denotest/multiple-exports@0.2.0/data-json" + } + } +} diff --git a/tests/specs/update/deno_json/update_compatible/deno.lock.out b/tests/specs/update/deno_json/update_compatible/deno.lock.out new file mode 100644 index 0000000000..994d6f7ac9 --- /dev/null +++ b/tests/specs/update/deno_json/update_compatible/deno.lock.out @@ -0,0 +1,43 @@ +{ + "version": "4", + "specifiers": { + "jsr:@denotest/add@~0.2.1": "0.2.1", + "jsr:@denotest/multiple-exports@0.2.0": "0.2.0", + "jsr:@denotest/subtract@0.2": "0.2.0", + "npm:@denotest/bin@0.6.0": "0.6.0", + "npm:@denotest/breaking-change-between-versions@1.0.0": "1.0.0", + "npm:@denotest/has-patch-versions@~0.1.1": "0.1.1" + }, + "jsr": { + "@denotest/add@0.2.1": { + "integrity": "a9076d30ecb42b2fc6dd95e7055fbf4e6358b53f550741bd7f60089d19f68848" + }, + "@denotest/multiple-exports@0.2.0": { + "integrity": "efe9748a0c0939c7ac245fee04acc0c42bd7a61874ff71a360c4543e4f5f6b36" + }, + "@denotest/subtract@0.2.0": { + "integrity": "c9650fc559ab2430effc0c7fb1540e3aa89888fbdd926335ccfdeac57eb3a64d" + } + }, + "npm": { + "@denotest/bin@0.6.0": { + "integrity": "sha512-vCNpxFgQN4fw4ZOp63nbTX1ilcDqNpvXCvYyC8nmfxQQAezsEt095I/YXwMIoMGzWtjCvlMf9kVEYfLuT5oEGQ==" + }, + "@denotest/breaking-change-between-versions@1.0.0": { + "integrity": "sha512-bzMGYx+DxxPlI74n/VsDAN7Db1BY7Sz2XqxXruMo9dEznsBZu7Ez3i8YQ8n0leTxAiiMk1RCG4zQHPG1aj3xRw==" + }, + "@denotest/has-patch-versions@0.1.1": { + "integrity": "sha512-slUqYhu6DrPiSdNzmW5aMdW2/osIYnDP0yY3CwgLzAiyK0/cwb0epSpTSyZEmTKXA3rezxxC7ASSsnD34uH1/w==" + } + }, + "workspace": { + "dependencies": [ + "jsr:@denotest/add@~0.2.1", + "jsr:@denotest/multiple-exports@0.2.0", + "jsr:@denotest/subtract@0.2", + "npm:@denotest/bin@0.6.0", + "npm:@denotest/breaking-change-between-versions@1.0.0", + "npm:@denotest/has-patch-versions@~0.1.1" + ] + } +} diff --git a/tests/specs/update/deno_json/update_compatible/update.out b/tests/specs/update/deno_json/update_compatible/update.out new file mode 100644 index 0000000000..17c5358fe6 --- /dev/null +++ b/tests/specs/update/deno_json/update_compatible/update.out @@ -0,0 +1,7 @@ +[UNORDERED_START] +Download http://127.0.0.1:4250/@denotest/add/0.2.1/mod.ts +Download http://localhost:4260/@denotest/has-patch-versions/0.1.1.tgz +[UNORDERED_END] +Updated 2 dependencies: + - jsr:@denotest/add 0.2.0 -> 0.2.1 + - npm:@denotest/has-patch-versions 0.1.0 -> 0.1.1 diff --git a/tests/specs/update/deno_json/update_latest/deno.json.out b/tests/specs/update/deno_json/update_latest/deno.json.out new file mode 100644 index 0000000000..5e4e99bd66 --- /dev/null +++ b/tests/specs/update/deno_json/update_latest/deno.json.out @@ -0,0 +1,19 @@ +{ + "imports": { + "@denotest/add": "jsr:@denotest/add@^1.0.0", + "@denotest/add/": "jsr:/@denotest/add@^1.0.0/", + "@denotest/subtract": "jsr:@denotest/subtract@^1.0.0", + "@denotest/with-subpath": "jsr:@denotest/multiple-exports@^1.0.0/data-json", + "@denotest/breaking-change-between-versions": "npm:@denotest/breaking-change-between-versions@^2.0.0", + "@denotest/bin": "npm:@denotest/bin@^1.0.0", + "@denotest/has-patch-versions": "npm:@denotest/has-patch-versions@^0.2.0" + }, + "scopes": { + "/foo/": { + "@denotest/add": "jsr:@denotest/add@^1.0.0", + "@denotest/add/": "jsr:/@denotest/add@^1.0.0/", + "@denotest/subtract": "jsr:@denotest/subtract@^1.0.0", + "@denotest/with-subpath": "jsr:@denotest/multiple-exports@^1.0.0/data-json" + } + } +} diff --git a/tests/specs/update/deno_json/update_latest/deno.lock.out b/tests/specs/update/deno_json/update_latest/deno.lock.out new file mode 100644 index 0000000000..ad83546ab1 --- /dev/null +++ b/tests/specs/update/deno_json/update_latest/deno.lock.out @@ -0,0 +1,43 @@ +{ + "version": "4", + "specifiers": { + "jsr:@denotest/add@1": "1.0.0", + "jsr:@denotest/multiple-exports@1": "1.0.0", + "jsr:@denotest/subtract@1": "1.0.0", + "npm:@denotest/bin@1": "1.0.0", + "npm:@denotest/breaking-change-between-versions@2": "2.0.0", + "npm:@denotest/has-patch-versions@0.2": "0.2.0" + }, + "jsr": { + "@denotest/add@1.0.0": { + "integrity": "3b2e675c1ad7fba2a45bc251992e01aff08a3c974ac09079b11e6a5b95d4bfcb" + }, + "@denotest/multiple-exports@1.0.0": { + "integrity": "efe9748a0c0939c7ac245fee04acc0c42bd7a61874ff71a360c4543e4f5f6b36" + }, + "@denotest/subtract@1.0.0": { + "integrity": "e178a7101c073e93d9efa6833d5cbf83bc1bc8d509b7c2a5ecbf74265e917597" + } + }, + "npm": { + "@denotest/bin@1.0.0": { + "integrity": "sha512-ZtrWnYYPIzw4a9H1uNeZRZRWuLCpHZZU/SllIyFLqcTLH/3zdRI8UH4Z1Kf+8N++bWGO3fg8Ev4vvS1LoLlidg==" + }, + "@denotest/breaking-change-between-versions@2.0.0": { + "integrity": "sha512-3eQpPhhJYbSHaAmpgyVT8IM3+MkxcAQl90Uw8zmuTiFs64Wt3HGzSz74cwPlvfqqesRktm8fBZMmrtxVo3ENzw==" + }, + "@denotest/has-patch-versions@0.2.0": { + "integrity": "sha512-7XIVGrBMyqnts5/wcc7dn7rVl4IWrCiGUT2GLDSLWnogOMIZBapJJLW9n8Leq1bDTJ3U6aDTEFKz9fVSOwZfLQ==" + } + }, + "workspace": { + "dependencies": [ + "jsr:@denotest/add@1", + "jsr:@denotest/multiple-exports@1", + "jsr:@denotest/subtract@1", + "npm:@denotest/bin@1", + "npm:@denotest/breaking-change-between-versions@2", + "npm:@denotest/has-patch-versions@0.2" + ] + } +} diff --git a/tests/specs/update/deno_json/update_latest/update.out b/tests/specs/update/deno_json/update_latest/update.out new file mode 100644 index 0000000000..35e1ef9fe5 --- /dev/null +++ b/tests/specs/update/deno_json/update_latest/update.out @@ -0,0 +1,16 @@ +[UNORDERED_START] +Download http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts +Download http://127.0.0.1:4250/@denotest/subtract/1.0.0/mod.ts +Download http://127.0.0.1:4250/@denotest/multiple-exports/1.0.0_meta.json +Download http://127.0.0.1:4250/@denotest/multiple-exports/1.0.0/data.json +Download http://localhost:4260/@denotest/has-patch-versions/0.2.0.tgz +Download http://localhost:4260/@denotest/bin/1.0.0.tgz +Download http://localhost:4260/@denotest/breaking-change-between-versions/2.0.0.tgz +[UNORDERED_END] +Updated 6 dependencies: + - jsr:@denotest/add 0.2.0 -> 1.0.0 + - jsr:@denotest/multiple-exports 0.2.0 -> 1.0.0 + - jsr:@denotest/subtract 0.2.0 -> 1.0.0 + - npm:@denotest/bin 0.6.0 -> 1.0.0 + - npm:@denotest/breaking-change-between-versions 1.0.0 -> 2.0.0 + - npm:@denotest/has-patch-versions 0.1.0 -> 0.2.0 diff --git a/tests/specs/update/mixed_workspace/__test__.jsonc b/tests/specs/update/mixed_workspace/__test__.jsonc new file mode 100644 index 0000000000..8c846467d4 --- /dev/null +++ b/tests/specs/update/mixed_workspace/__test__.jsonc @@ -0,0 +1,153 @@ +{ + "tempDir": true, + "tests": { + // just to make sure install doesn't change the lockfile + "sanity_lockfile_up_to_date": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": [ + "eval", + "const now = Deno.readTextFileSync('./deno.lock'); console.log(now.trim());" + ], + "output": "deno.lock.orig.out" + } + ] + }, + "print_outdated_root": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": "outdated", + "output": "print_outdated/root.out" + } + ] + }, + "print_outdated_recursive": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": "outdated --recursive", + "output": "print_outdated/recursive.out" + } + ] + }, + "print_outdated_subdir": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "cwd": "member-a", + "args": "outdated", + "output": "print_outdated/member_a.out" + }, + { + "cwd": "member-b", + "args": "outdated", + "output": "print_outdated/member_b.out" + } + ] + }, + "update_latest_root": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": "outdated --update --latest", + "output": "update_latest/root/update.out" + }, + { + "args": "-A print_file.ts ./deno.json", + "output": "./update_latest/root/deno.json.out" + } + ] + }, + "update_latest_subdir": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "cwd": "member-a", + "args": "outdated --update --latest", + "output": "update_latest/subdir/member_a.out" + }, + { + "args": "-A print_file.ts ./member-a/deno.json", + "output": "update_latest/subdir/member_a_deno.json.out" + }, + { + "cwd": "member-b", + "args": "outdated --update --latest", + "output": "update_latest/subdir/member_b.out" + }, + { + "args": "-A print_file.ts ./member-b/package.json", + "output": "update_latest/subdir/member_b_package.json.out" + } + ] + }, + "update_latest_recursive": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": "outdated --update --latest --recursive", + "output": "update_latest/recursive/update.out" + }, + { + "args": "-A print_file.ts ./deno.json", + "output": "update_latest/root/deno.json.out" + }, + { + "args": "-A print_file.ts ./member-a/deno.json", + "output": "update_latest/subdir/member_a_deno.json.out" + }, + { + "args": "-A print_file.ts ./member-b/package.json", + "output": "update_latest/subdir/member_b_package.json.out" + } + ] + }, + "update_filtered": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": "outdated --update --latest --recursive @denotest/add @denotest/sub* !@denotest/breaking* aliased @denotest/with-subpath@0.5.0", + "output": "filtered/update.out" + }, + { + "args": "-A print_file.ts ./deno.json", + "output": "./update_latest/root/deno.json.out" + }, + { + "args": "-A print_file.ts ./member-a/deno.json", + "output": "./filtered/member_a_deno.json.out" + }, + { + "args": "-A print_file.ts ./member-b/package.json", + "output": "./filtered/member_b_package.json.out" + } + ] + } + } +} diff --git a/tests/specs/update/mixed_workspace/deno.json b/tests/specs/update/mixed_workspace/deno.json new file mode 100644 index 0000000000..e4034d3a31 --- /dev/null +++ b/tests/specs/update/mixed_workspace/deno.json @@ -0,0 +1,6 @@ +{ + "workspace": ["./member-a", "./member-b"], + "imports": { + "@denotest/subtract": "jsr:@denotest/subtract@^0.2.0" + } +} diff --git a/tests/specs/update/mixed_workspace/deno.lock b/tests/specs/update/mixed_workspace/deno.lock new file mode 100644 index 0000000000..23613ce58d --- /dev/null +++ b/tests/specs/update/mixed_workspace/deno.lock @@ -0,0 +1,55 @@ +{ + "version": "4", + "specifiers": { + "jsr:@denotest/add@0.2": "0.2.1", + "jsr:@denotest/multiple-exports@0.2.0": "0.2.0", + "jsr:@denotest/subtract@0.2": "0.2.0", + "npm:@denotest/bin@0.6.0": "0.6.0", + "npm:@denotest/breaking-change-between-versions@1.0.0": "1.0.0", + "npm:@denotest/has-patch-versions@0.1.0": "0.1.0" + }, + "jsr": { + "@denotest/add@0.2.1": { + "integrity": "a9076d30ecb42b2fc6dd95e7055fbf4e6358b53f550741bd7f60089d19f68848" + }, + "@denotest/multiple-exports@0.2.0": { + "integrity": "efe9748a0c0939c7ac245fee04acc0c42bd7a61874ff71a360c4543e4f5f6b36" + }, + "@denotest/subtract@0.2.0": { + "integrity": "c9650fc559ab2430effc0c7fb1540e3aa89888fbdd926335ccfdeac57eb3a64d" + } + }, + "npm": { + "@denotest/bin@0.6.0": { + "integrity": "sha512-vCNpxFgQN4fw4ZOp63nbTX1ilcDqNpvXCvYyC8nmfxQQAezsEt095I/YXwMIoMGzWtjCvlMf9kVEYfLuT5oEGQ==" + }, + "@denotest/breaking-change-between-versions@1.0.0": { + "integrity": "sha512-bzMGYx+DxxPlI74n/VsDAN7Db1BY7Sz2XqxXruMo9dEznsBZu7Ez3i8YQ8n0leTxAiiMk1RCG4zQHPG1aj3xRw==" + }, + "@denotest/has-patch-versions@0.1.0": { + "integrity": "sha512-H/MBo0jKDdMsX4AAGEGQbZj70nfNe3oUNZXbohYHhqf9EfpLnXp/7FC29ZdfV4+p6VjEcOGdCtXc6rilE6iYpg==" + } + }, + "workspace": { + "dependencies": [ + "jsr:@denotest/subtract@0.2" + ], + "members": { + "member-a": { + "dependencies": [ + "jsr:@denotest/add@0.2", + "jsr:@denotest/multiple-exports@0.2.0", + "npm:@denotest/breaking-change-between-versions@1.0.0" + ] + }, + "member-b": { + "packageJson": { + "dependencies": [ + "npm:@denotest/bin@0.6.0", + "npm:@denotest/has-patch-versions@0.1.0" + ] + } + } + } + } +} diff --git a/tests/specs/update/mixed_workspace/deno.lock.orig.out b/tests/specs/update/mixed_workspace/deno.lock.orig.out new file mode 100644 index 0000000000..23613ce58d --- /dev/null +++ b/tests/specs/update/mixed_workspace/deno.lock.orig.out @@ -0,0 +1,55 @@ +{ + "version": "4", + "specifiers": { + "jsr:@denotest/add@0.2": "0.2.1", + "jsr:@denotest/multiple-exports@0.2.0": "0.2.0", + "jsr:@denotest/subtract@0.2": "0.2.0", + "npm:@denotest/bin@0.6.0": "0.6.0", + "npm:@denotest/breaking-change-between-versions@1.0.0": "1.0.0", + "npm:@denotest/has-patch-versions@0.1.0": "0.1.0" + }, + "jsr": { + "@denotest/add@0.2.1": { + "integrity": "a9076d30ecb42b2fc6dd95e7055fbf4e6358b53f550741bd7f60089d19f68848" + }, + "@denotest/multiple-exports@0.2.0": { + "integrity": "efe9748a0c0939c7ac245fee04acc0c42bd7a61874ff71a360c4543e4f5f6b36" + }, + "@denotest/subtract@0.2.0": { + "integrity": "c9650fc559ab2430effc0c7fb1540e3aa89888fbdd926335ccfdeac57eb3a64d" + } + }, + "npm": { + "@denotest/bin@0.6.0": { + "integrity": "sha512-vCNpxFgQN4fw4ZOp63nbTX1ilcDqNpvXCvYyC8nmfxQQAezsEt095I/YXwMIoMGzWtjCvlMf9kVEYfLuT5oEGQ==" + }, + "@denotest/breaking-change-between-versions@1.0.0": { + "integrity": "sha512-bzMGYx+DxxPlI74n/VsDAN7Db1BY7Sz2XqxXruMo9dEznsBZu7Ez3i8YQ8n0leTxAiiMk1RCG4zQHPG1aj3xRw==" + }, + "@denotest/has-patch-versions@0.1.0": { + "integrity": "sha512-H/MBo0jKDdMsX4AAGEGQbZj70nfNe3oUNZXbohYHhqf9EfpLnXp/7FC29ZdfV4+p6VjEcOGdCtXc6rilE6iYpg==" + } + }, + "workspace": { + "dependencies": [ + "jsr:@denotest/subtract@0.2" + ], + "members": { + "member-a": { + "dependencies": [ + "jsr:@denotest/add@0.2", + "jsr:@denotest/multiple-exports@0.2.0", + "npm:@denotest/breaking-change-between-versions@1.0.0" + ] + }, + "member-b": { + "packageJson": { + "dependencies": [ + "npm:@denotest/bin@0.6.0", + "npm:@denotest/has-patch-versions@0.1.0" + ] + } + } + } + } +} diff --git a/tests/specs/update/mixed_workspace/filtered/member_a_deno.json.out b/tests/specs/update/mixed_workspace/filtered/member_a_deno.json.out new file mode 100644 index 0000000000..2b622efee5 --- /dev/null +++ b/tests/specs/update/mixed_workspace/filtered/member_a_deno.json.out @@ -0,0 +1,10 @@ +{ + "name": "@denotest/member-a", + "exports": "./mod.ts", + "imports": { + "@denotest/add": "jsr:@denotest/add@^1.0.0", + "@denotest/add/": "jsr:/@denotest/add@^1.0.0/", + "@denotest/with-subpath": "jsr:@denotest/multiple-exports@0.5.0/data-json", + "@denotest/breaking-change-between-versions": "npm:@denotest/breaking-change-between-versions@1.0.0" + } +} diff --git a/tests/specs/update/mixed_workspace/filtered/member_b_package.json.out b/tests/specs/update/mixed_workspace/filtered/member_b_package.json.out new file mode 100644 index 0000000000..7e582feeab --- /dev/null +++ b/tests/specs/update/mixed_workspace/filtered/member_b_package.json.out @@ -0,0 +1,8 @@ +{ + "name": "@denotest/member-b", + "version": "0.1.0", + "dependencies": { + "@denotest/has-patch-versions": "0.1.0", + "aliased": "npm:@denotest/bin@^1.0.0" + } +} diff --git a/tests/specs/update/mixed_workspace/filtered/update.out b/tests/specs/update/mixed_workspace/filtered/update.out new file mode 100644 index 0000000000..26543e5167 --- /dev/null +++ b/tests/specs/update/mixed_workspace/filtered/update.out @@ -0,0 +1,12 @@ +[UNORDERED_START] +Download http://localhost:4260/@denotest/bin/1.0.0.tgz +Download http://127.0.0.1:4250/@denotest/multiple-exports/0.5.0_meta.json +Download http://127.0.0.1:4250/@denotest/multiple-exports/0.5.0/data.json +Download http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts +Download http://127.0.0.1:4250/@denotest/subtract/1.0.0/mod.ts +[UNORDERED_END] +Updated 4 dependencies: + - jsr:@denotest/add 0.2.1 -> 1.0.0 + - jsr:@denotest/multiple-exports 0.2.0 -> 0.5.0 + - jsr:@denotest/subtract 0.2.0 -> 1.0.0 + - npm:@denotest/bin 0.6.0 -> 1.0.0 diff --git a/tests/specs/update/mixed_workspace/member-a/deno.json b/tests/specs/update/mixed_workspace/member-a/deno.json new file mode 100644 index 0000000000..0340d3bb92 --- /dev/null +++ b/tests/specs/update/mixed_workspace/member-a/deno.json @@ -0,0 +1,10 @@ +{ + "name": "@denotest/member-a", + "exports": "./mod.ts", + "imports": { + "@denotest/add": "jsr:@denotest/add@^0.2.0", + "@denotest/add/": "jsr:/@denotest/add@^0.2.0/", + "@denotest/with-subpath": "jsr:@denotest/multiple-exports@0.2.0/data-json", + "@denotest/breaking-change-between-versions": "npm:@denotest/breaking-change-between-versions@1.0.0" + } +} diff --git a/tests/specs/update/mixed_workspace/member-a/mod.ts b/tests/specs/update/mixed_workspace/member-a/mod.ts new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/specs/update/mixed_workspace/member-b/package.json b/tests/specs/update/mixed_workspace/member-b/package.json new file mode 100644 index 0000000000..0f9929a478 --- /dev/null +++ b/tests/specs/update/mixed_workspace/member-b/package.json @@ -0,0 +1,8 @@ +{ + "name": "@denotest/member-b", + "version": "0.1.0", + "dependencies": { + "@denotest/has-patch-versions": "0.1.0", + "aliased": "npm:@denotest/bin@0.6.0" + } +} diff --git a/tests/specs/update/mixed_workspace/print_file.ts b/tests/specs/update/mixed_workspace/print_file.ts new file mode 100644 index 0000000000..c57b6c3a4e --- /dev/null +++ b/tests/specs/update/mixed_workspace/print_file.ts @@ -0,0 +1,2 @@ +const file = Deno.args[0]; +console.log(Deno.readTextFileSync(file).trim()); diff --git a/tests/specs/update/mixed_workspace/print_outdated/member_a.out b/tests/specs/update/mixed_workspace/print_outdated/member_a.out new file mode 100644 index 0000000000..8699aac2bf --- /dev/null +++ b/tests/specs/update/mixed_workspace/print_outdated/member_a.out @@ -0,0 +1,9 @@ +┌────────────────────────────────────────────────┬─────────┬────────┬────────┐ +│ Package │ Current │ Update │ Latest │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ jsr:@denotest/multiple-exports │ 0.2.0 │ 0.2.0 │ 1.0.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ jsr:@denotest/add │ 0.2.1 │ 0.2.1 │ 1.0.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/breaking-change-between-versions │ 1.0.0 │ 1.0.0 │ 2.0.0 │ +└────────────────────────────────────────────────┴─────────┴────────┴────────┘ diff --git a/tests/specs/update/mixed_workspace/print_outdated/member_b.out b/tests/specs/update/mixed_workspace/print_outdated/member_b.out new file mode 100644 index 0000000000..fc8ef320a8 --- /dev/null +++ b/tests/specs/update/mixed_workspace/print_outdated/member_b.out @@ -0,0 +1,7 @@ +┌──────────────────────────────────┬─────────┬────────┬────────┐ +│ Package │ Current │ Update │ Latest │ +├──────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/has-patch-versions │ 0.1.0 │ 0.1.0 │ 0.2.0 │ +├──────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/bin │ 0.6.0 │ 0.6.0 │ 1.0.0 │ +└──────────────────────────────────┴─────────┴────────┴────────┘ diff --git a/tests/specs/update/mixed_workspace/print_outdated/recursive.out b/tests/specs/update/mixed_workspace/print_outdated/recursive.out new file mode 100644 index 0000000000..ca03776a9c --- /dev/null +++ b/tests/specs/update/mixed_workspace/print_outdated/recursive.out @@ -0,0 +1,15 @@ +┌────────────────────────────────────────────────┬─────────┬────────┬────────┐ +│ Package │ Current │ Update │ Latest │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ jsr:@denotest/multiple-exports │ 0.2.0 │ 0.2.0 │ 1.0.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ jsr:@denotest/subtract │ 0.2.0 │ 0.2.0 │ 1.0.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ jsr:@denotest/add │ 0.2.1 │ 0.2.1 │ 1.0.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/has-patch-versions │ 0.1.0 │ 0.1.0 │ 0.2.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/bin │ 0.6.0 │ 0.6.0 │ 1.0.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/breaking-change-between-versions │ 1.0.0 │ 1.0.0 │ 2.0.0 │ +└────────────────────────────────────────────────┴─────────┴────────┴────────┘ diff --git a/tests/specs/update/mixed_workspace/print_outdated/root.out b/tests/specs/update/mixed_workspace/print_outdated/root.out new file mode 100644 index 0000000000..c7934edc79 --- /dev/null +++ b/tests/specs/update/mixed_workspace/print_outdated/root.out @@ -0,0 +1,5 @@ +┌────────────────────────┬─────────┬────────┬────────┐ +│ Package │ Current │ Update │ Latest │ +├────────────────────────┼─────────┼────────┼────────┤ +│ jsr:@denotest/subtract │ 0.2.0 │ 0.2.0 │ 1.0.0 │ +└────────────────────────┴─────────┴────────┴────────┘ diff --git a/tests/specs/update/mixed_workspace/update_latest/recursive/update.out b/tests/specs/update/mixed_workspace/update_latest/recursive/update.out new file mode 100644 index 0000000000..ef6e36ded5 --- /dev/null +++ b/tests/specs/update/mixed_workspace/update_latest/recursive/update.out @@ -0,0 +1,16 @@ +[UNORDERED_START] +Download http://localhost:4260/@denotest/breaking-change-between-versions/2.0.0.tgz +Download http://localhost:4260/@denotest/has-patch-versions/0.2.0.tgz +Download http://localhost:4260/@denotest/bin/1.0.0.tgz +Download http://127.0.0.1:4250/@denotest/multiple-exports/1.0.0_meta.json +Download http://127.0.0.1:4250/@denotest/multiple-exports/1.0.0/data.json +Download http://127.0.0.1:4250/@denotest/subtract/1.0.0/mod.ts +Download http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts +[UNORDERED_END] +Updated 6 dependencies: + - jsr:@denotest/add 0.2.1 -> 1.0.0 + - jsr:@denotest/multiple-exports 0.2.0 -> 1.0.0 + - jsr:@denotest/subtract 0.2.0 -> 1.0.0 + - npm:@denotest/bin 0.6.0 -> 1.0.0 + - npm:@denotest/breaking-change-between-versions 1.0.0 -> 2.0.0 + - npm:@denotest/has-patch-versions 0.1.0 -> 0.2.0 diff --git a/tests/specs/update/mixed_workspace/update_latest/root/deno.json.out b/tests/specs/update/mixed_workspace/update_latest/root/deno.json.out new file mode 100644 index 0000000000..0317e6c39f --- /dev/null +++ b/tests/specs/update/mixed_workspace/update_latest/root/deno.json.out @@ -0,0 +1,6 @@ +{ + "workspace": ["./member-a", "./member-b"], + "imports": { + "@denotest/subtract": "jsr:@denotest/subtract@^1.0.0" + } +} diff --git a/tests/specs/update/mixed_workspace/update_latest/root/update.out b/tests/specs/update/mixed_workspace/update_latest/root/update.out new file mode 100644 index 0000000000..15d21621e8 --- /dev/null +++ b/tests/specs/update/mixed_workspace/update_latest/root/update.out @@ -0,0 +1,3 @@ +Download http://127.0.0.1:4250/@denotest/subtract/1.0.0/mod.ts +Updated 1 dependency: + - jsr:@denotest/subtract 0.2.0 -> 1.0.0 diff --git a/tests/specs/update/mixed_workspace/update_latest/subdir/member_a.out b/tests/specs/update/mixed_workspace/update_latest/subdir/member_a.out new file mode 100644 index 0000000000..f16e0b7f2a --- /dev/null +++ b/tests/specs/update/mixed_workspace/update_latest/subdir/member_a.out @@ -0,0 +1,10 @@ +[UNORDERED_START] +Download http://localhost:4260/@denotest/breaking-change-between-versions/2.0.0.tgz +Download http://127.0.0.1:4250/@denotest/multiple-exports/1.0.0_meta.json +Download http://127.0.0.1:4250/@denotest/multiple-exports/1.0.0/data.json +Download http://127.0.0.1:4250/@denotest/add/1.0.0/mod.ts +[UNORDERED_END] +Updated 3 dependencies: + - jsr:@denotest/add 0.2.1 -> 1.0.0 + - jsr:@denotest/multiple-exports 0.2.0 -> 1.0.0 + - npm:@denotest/breaking-change-between-versions 1.0.0 -> 2.0.0 diff --git a/tests/specs/update/mixed_workspace/update_latest/subdir/member_a_deno.json.out b/tests/specs/update/mixed_workspace/update_latest/subdir/member_a_deno.json.out new file mode 100644 index 0000000000..9210123b82 --- /dev/null +++ b/tests/specs/update/mixed_workspace/update_latest/subdir/member_a_deno.json.out @@ -0,0 +1,10 @@ +{ + "name": "@denotest/member-a", + "exports": "./mod.ts", + "imports": { + "@denotest/add": "jsr:@denotest/add@^1.0.0", + "@denotest/add/": "jsr:/@denotest/add@^1.0.0/", + "@denotest/with-subpath": "jsr:@denotest/multiple-exports@^1.0.0/data-json", + "@denotest/breaking-change-between-versions": "npm:@denotest/breaking-change-between-versions@^2.0.0" + } +} diff --git a/tests/specs/update/mixed_workspace/update_latest/subdir/member_b.out b/tests/specs/update/mixed_workspace/update_latest/subdir/member_b.out new file mode 100644 index 0000000000..5ca3297e20 --- /dev/null +++ b/tests/specs/update/mixed_workspace/update_latest/subdir/member_b.out @@ -0,0 +1,7 @@ +[UNORDERED_START] +Download http://localhost:4260/@denotest/bin/1.0.0.tgz +Download http://localhost:4260/@denotest/has-patch-versions/0.2.0.tgz +[UNORDERED_END] +Updated 2 dependencies: + - npm:@denotest/bin 0.6.0 -> 1.0.0 + - npm:@denotest/has-patch-versions 0.1.0 -> 0.2.0 diff --git a/tests/specs/update/mixed_workspace/update_latest/subdir/member_b_package.json.out b/tests/specs/update/mixed_workspace/update_latest/subdir/member_b_package.json.out new file mode 100644 index 0000000000..1426fcd7f8 --- /dev/null +++ b/tests/specs/update/mixed_workspace/update_latest/subdir/member_b_package.json.out @@ -0,0 +1,8 @@ +{ + "name": "@denotest/member-b", + "version": "0.1.0", + "dependencies": { + "@denotest/has-patch-versions": "^0.2.0", + "aliased": "npm:@denotest/bin@^1.0.0" + } +} diff --git a/tests/specs/update/package_json/__test__.jsonc b/tests/specs/update/package_json/__test__.jsonc new file mode 100644 index 0000000000..19d576dfc0 --- /dev/null +++ b/tests/specs/update/package_json/__test__.jsonc @@ -0,0 +1,100 @@ +{ + "tempDir": true, + "tests": { + "sanity_lockfile_up_to_date": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": [ + "eval", + "const now = Deno.readTextFileSync('./deno.lock'); console.log(now.trim());" + ], + "output": "deno.lock.orig.out" + } + ] + }, + "print_outdated": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": "outdated", + "output": "outdated.out" + } + ] + }, + "print_outdated_compatible": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": "outdated --compatible", + "output": "outdated_compatible.out" + } + ] + }, + "update_compatible": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": "outdated --update", + "output": "./update_compatible/update.out" + }, + { + "args": "-A ./print_file.ts ./package.json", + "output": "./update_compatible/package.json.out" + }, + { + "args": "-A ./print_file.ts ./deno.lock", + "output": "./update_compatible/deno.lock.out" + } + ] + }, + "update_latest": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": "outdated --update --latest", + "output": "update_latest/update.out" + }, + { + "args": "-A ./print_file.ts ./package.json", + "output": "update_latest/package.json.out" + }, + { + "args": "-A ./print_file.ts ./deno.lock", + "output": "update_latest/deno.lock.out" + } + ] + }, + "update_filtered": { + "steps": [ + { + "args": "install", + "output": "[WILDCARD]" + }, + { + "args": "outdated --update --latest @denotest/has-patch* aliased@0.7.0", + "output": "filtered/update.out" + }, + { + "args": "-A print_file.ts ./package.json", + "output": "filtered/package.json.out" + } + ] + } + } +} diff --git a/tests/specs/update/package_json/deno.lock b/tests/specs/update/package_json/deno.lock new file mode 100644 index 0000000000..05253094db --- /dev/null +++ b/tests/specs/update/package_json/deno.lock @@ -0,0 +1,28 @@ +{ + "version": "4", + "specifiers": { + "npm:@denotest/bin@0.6": "0.6.0", + "npm:@denotest/breaking-change-between-versions@1.0.0": "1.0.0", + "npm:@denotest/has-patch-versions@0.1": "0.1.0" + }, + "npm": { + "@denotest/bin@0.6.0": { + "integrity": "sha512-vCNpxFgQN4fw4ZOp63nbTX1ilcDqNpvXCvYyC8nmfxQQAezsEt095I/YXwMIoMGzWtjCvlMf9kVEYfLuT5oEGQ==" + }, + "@denotest/breaking-change-between-versions@1.0.0": { + "integrity": "sha512-bzMGYx+DxxPlI74n/VsDAN7Db1BY7Sz2XqxXruMo9dEznsBZu7Ez3i8YQ8n0leTxAiiMk1RCG4zQHPG1aj3xRw==" + }, + "@denotest/has-patch-versions@0.1.0": { + "integrity": "sha512-H/MBo0jKDdMsX4AAGEGQbZj70nfNe3oUNZXbohYHhqf9EfpLnXp/7FC29ZdfV4+p6VjEcOGdCtXc6rilE6iYpg==" + } + }, + "workspace": { + "packageJson": { + "dependencies": [ + "npm:@denotest/bin@0.6", + "npm:@denotest/breaking-change-between-versions@1.0.0", + "npm:@denotest/has-patch-versions@0.1" + ] + } + } +} diff --git a/tests/specs/update/package_json/deno.lock.orig.out b/tests/specs/update/package_json/deno.lock.orig.out new file mode 100644 index 0000000000..05253094db --- /dev/null +++ b/tests/specs/update/package_json/deno.lock.orig.out @@ -0,0 +1,28 @@ +{ + "version": "4", + "specifiers": { + "npm:@denotest/bin@0.6": "0.6.0", + "npm:@denotest/breaking-change-between-versions@1.0.0": "1.0.0", + "npm:@denotest/has-patch-versions@0.1": "0.1.0" + }, + "npm": { + "@denotest/bin@0.6.0": { + "integrity": "sha512-vCNpxFgQN4fw4ZOp63nbTX1ilcDqNpvXCvYyC8nmfxQQAezsEt095I/YXwMIoMGzWtjCvlMf9kVEYfLuT5oEGQ==" + }, + "@denotest/breaking-change-between-versions@1.0.0": { + "integrity": "sha512-bzMGYx+DxxPlI74n/VsDAN7Db1BY7Sz2XqxXruMo9dEznsBZu7Ez3i8YQ8n0leTxAiiMk1RCG4zQHPG1aj3xRw==" + }, + "@denotest/has-patch-versions@0.1.0": { + "integrity": "sha512-H/MBo0jKDdMsX4AAGEGQbZj70nfNe3oUNZXbohYHhqf9EfpLnXp/7FC29ZdfV4+p6VjEcOGdCtXc6rilE6iYpg==" + } + }, + "workspace": { + "packageJson": { + "dependencies": [ + "npm:@denotest/bin@0.6", + "npm:@denotest/breaking-change-between-versions@1.0.0", + "npm:@denotest/has-patch-versions@0.1" + ] + } + } +} diff --git a/tests/specs/update/package_json/filtered/package.json.out b/tests/specs/update/package_json/filtered/package.json.out new file mode 100644 index 0000000000..39faff22d6 --- /dev/null +++ b/tests/specs/update/package_json/filtered/package.json.out @@ -0,0 +1,9 @@ +{ + "dependencies": { + "@denotest/has-patch-versions": "^0.2.0", + "@denotest/breaking-change-between-versions": "1.0.0" + }, + "devDependencies": { + "aliased": "npm:@denotest/bin@0.7.0" + } +} diff --git a/tests/specs/update/package_json/filtered/update.out b/tests/specs/update/package_json/filtered/update.out new file mode 100644 index 0000000000..3093281f10 --- /dev/null +++ b/tests/specs/update/package_json/filtered/update.out @@ -0,0 +1,9 @@ +[UNORDERED_START] +Download http://localhost:4260/@denotest/bin/0.7.0.tgz +Download http://localhost:4260/@denotest/has-patch-versions/0.2.0.tgz +Initialize @denotest/has-patch-versions@0.2.0 +Initialize @denotest/bin@0.7.0 +[UNORDERED_END] +Updated 2 dependencies: + - npm:@denotest/bin 0.6.0 -> 0.7.0 + - npm:@denotest/has-patch-versions 0.1.0 -> 0.2.0 diff --git a/tests/specs/update/package_json/outdated.out b/tests/specs/update/package_json/outdated.out new file mode 100644 index 0000000000..d672aace7f --- /dev/null +++ b/tests/specs/update/package_json/outdated.out @@ -0,0 +1,9 @@ +┌────────────────────────────────────────────────┬─────────┬────────┬────────┐ +│ Package │ Current │ Update │ Latest │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/has-patch-versions │ 0.1.0 │ 0.1.1 │ 0.2.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/bin │ 0.6.0 │ 0.6.0 │ 1.0.0 │ +├────────────────────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/breaking-change-between-versions │ 1.0.0 │ 1.0.0 │ 2.0.0 │ +└────────────────────────────────────────────────┴─────────┴────────┴────────┘ diff --git a/tests/specs/update/package_json/outdated_compatible.out b/tests/specs/update/package_json/outdated_compatible.out new file mode 100644 index 0000000000..8a682c461c --- /dev/null +++ b/tests/specs/update/package_json/outdated_compatible.out @@ -0,0 +1,5 @@ +┌──────────────────────────────────┬─────────┬────────┬────────┐ +│ Package │ Current │ Update │ Latest │ +├──────────────────────────────────┼─────────┼────────┼────────┤ +│ npm:@denotest/has-patch-versions │ 0.1.0 │ 0.1.1 │ 0.2.0 │ +└──────────────────────────────────┴─────────┴────────┴────────┘ diff --git a/tests/specs/update/package_json/package.json b/tests/specs/update/package_json/package.json new file mode 100644 index 0000000000..9cd8cf59dc --- /dev/null +++ b/tests/specs/update/package_json/package.json @@ -0,0 +1,9 @@ +{ + "dependencies": { + "@denotest/has-patch-versions": "^0.1.0", + "@denotest/breaking-change-between-versions": "1.0.0" + }, + "devDependencies": { + "aliased": "npm:@denotest/bin@^0.6.0" + } +} diff --git a/tests/specs/update/package_json/print_file.ts b/tests/specs/update/package_json/print_file.ts new file mode 100644 index 0000000000..c57b6c3a4e --- /dev/null +++ b/tests/specs/update/package_json/print_file.ts @@ -0,0 +1,2 @@ +const file = Deno.args[0]; +console.log(Deno.readTextFileSync(file).trim()); diff --git a/tests/specs/update/package_json/update_compatible/deno.lock.out b/tests/specs/update/package_json/update_compatible/deno.lock.out new file mode 100644 index 0000000000..f82a21ee46 --- /dev/null +++ b/tests/specs/update/package_json/update_compatible/deno.lock.out @@ -0,0 +1,28 @@ +{ + "version": "4", + "specifiers": { + "npm:@denotest/bin@0.6": "0.6.0", + "npm:@denotest/breaking-change-between-versions@1.0.0": "1.0.0", + "npm:@denotest/has-patch-versions@~0.1.1": "0.1.1" + }, + "npm": { + "@denotest/bin@0.6.0": { + "integrity": "sha512-vCNpxFgQN4fw4ZOp63nbTX1ilcDqNpvXCvYyC8nmfxQQAezsEt095I/YXwMIoMGzWtjCvlMf9kVEYfLuT5oEGQ==" + }, + "@denotest/breaking-change-between-versions@1.0.0": { + "integrity": "sha512-bzMGYx+DxxPlI74n/VsDAN7Db1BY7Sz2XqxXruMo9dEznsBZu7Ez3i8YQ8n0leTxAiiMk1RCG4zQHPG1aj3xRw==" + }, + "@denotest/has-patch-versions@0.1.1": { + "integrity": "sha512-slUqYhu6DrPiSdNzmW5aMdW2/osIYnDP0yY3CwgLzAiyK0/cwb0epSpTSyZEmTKXA3rezxxC7ASSsnD34uH1/w==" + } + }, + "workspace": { + "packageJson": { + "dependencies": [ + "npm:@denotest/bin@0.6", + "npm:@denotest/breaking-change-between-versions@1.0.0", + "npm:@denotest/has-patch-versions@~0.1.1" + ] + } + } +} diff --git a/tests/specs/update/package_json/update_compatible/package.json.out b/tests/specs/update/package_json/update_compatible/package.json.out new file mode 100644 index 0000000000..6f822ee5d6 --- /dev/null +++ b/tests/specs/update/package_json/update_compatible/package.json.out @@ -0,0 +1,9 @@ +{ + "dependencies": { + "@denotest/has-patch-versions": "^0.1.1", + "@denotest/breaking-change-between-versions": "1.0.0" + }, + "devDependencies": { + "aliased": "npm:@denotest/bin@^0.6.0" + } +} diff --git a/tests/specs/update/package_json/update_compatible/update.out b/tests/specs/update/package_json/update_compatible/update.out new file mode 100644 index 0000000000..4c3c740791 --- /dev/null +++ b/tests/specs/update/package_json/update_compatible/update.out @@ -0,0 +1,4 @@ +Download http://localhost:4260/@denotest/has-patch-versions/0.1.1.tgz +Initialize @denotest/has-patch-versions@0.1.1 +Updated 1 dependency: + - npm:@denotest/has-patch-versions 0.1.0 -> 0.1.1 diff --git a/tests/specs/update/package_json/update_latest/deno.lock.out b/tests/specs/update/package_json/update_latest/deno.lock.out new file mode 100644 index 0000000000..9a9b1bad5e --- /dev/null +++ b/tests/specs/update/package_json/update_latest/deno.lock.out @@ -0,0 +1,28 @@ +{ + "version": "4", + "specifiers": { + "npm:@denotest/bin@1": "1.0.0", + "npm:@denotest/breaking-change-between-versions@2": "2.0.0", + "npm:@denotest/has-patch-versions@0.2": "0.2.0" + }, + "npm": { + "@denotest/bin@1.0.0": { + "integrity": "sha512-ZtrWnYYPIzw4a9H1uNeZRZRWuLCpHZZU/SllIyFLqcTLH/3zdRI8UH4Z1Kf+8N++bWGO3fg8Ev4vvS1LoLlidg==" + }, + "@denotest/breaking-change-between-versions@2.0.0": { + "integrity": "sha512-3eQpPhhJYbSHaAmpgyVT8IM3+MkxcAQl90Uw8zmuTiFs64Wt3HGzSz74cwPlvfqqesRktm8fBZMmrtxVo3ENzw==" + }, + "@denotest/has-patch-versions@0.2.0": { + "integrity": "sha512-7XIVGrBMyqnts5/wcc7dn7rVl4IWrCiGUT2GLDSLWnogOMIZBapJJLW9n8Leq1bDTJ3U6aDTEFKz9fVSOwZfLQ==" + } + }, + "workspace": { + "packageJson": { + "dependencies": [ + "npm:@denotest/bin@1", + "npm:@denotest/breaking-change-between-versions@2", + "npm:@denotest/has-patch-versions@0.2" + ] + } + } +} diff --git a/tests/specs/update/package_json/update_latest/package.json.out b/tests/specs/update/package_json/update_latest/package.json.out new file mode 100644 index 0000000000..fb483d78bd --- /dev/null +++ b/tests/specs/update/package_json/update_latest/package.json.out @@ -0,0 +1,9 @@ +{ + "dependencies": { + "@denotest/has-patch-versions": "^0.2.0", + "@denotest/breaking-change-between-versions": "^2.0.0" + }, + "devDependencies": { + "aliased": "npm:@denotest/bin@^1.0.0" + } +} diff --git a/tests/specs/update/package_json/update_latest/update.out b/tests/specs/update/package_json/update_latest/update.out new file mode 100644 index 0000000000..a24ae1e32b --- /dev/null +++ b/tests/specs/update/package_json/update_latest/update.out @@ -0,0 +1,14 @@ +[UNORDERED_START] +Download http://localhost:4260/@denotest/bin/1.0.0.tgz +Download http://localhost:4260/@denotest/has-patch-versions/0.2.0.tgz +Download http://localhost:4260/@denotest/breaking-change-between-versions/2.0.0.tgz +Initialize @denotest/has-patch-versions@0.2.0 +Initialize @denotest/breaking-change-between-versions@2.0.0 +Initialize @denotest/bin@1.0.0 +[UNORDERED_END] +Updated 3 dependencies: +[UNORDERED_START] + - npm:@denotest/bin 0.6.0 -> 1.0.0 + - npm:@denotest/breaking-change-between-versions 1.0.0 -> 2.0.0 + - npm:@denotest/has-patch-versions 0.1.0 -> 0.2.0 +[UNORDERED_END] diff --git a/tests/util/server/src/npm.rs b/tests/util/server/src/npm.rs index 31686fa854..081989ddb5 100644 --- a/tests/util/server/src/npm.rs +++ b/tests/util/server/src/npm.rs @@ -2,6 +2,7 @@ use std::collections::HashMap; use std::fs; +use std::path::Path; use anyhow::Context; use anyhow::Result; @@ -189,6 +190,60 @@ impl TestNpmRegistry { } } +// NOTE: extracted out partially from the `tar` crate, all credits to the original authors +fn append_dir_all( + builder: &mut tar::Builder, + path: &Path, + src_path: &Path, +) -> Result<()> { + builder.follow_symlinks(true); + let mode = tar::HeaderMode::Deterministic; + builder.mode(mode); + let mut stack = vec![(src_path.to_path_buf(), true, false)]; + let mut entries = Vec::new(); + while let Some((src, is_dir, is_symlink)) = stack.pop() { + let dest = path.join(src.strip_prefix(src_path).unwrap()); + // In case of a symlink pointing to a directory, is_dir is false, but src.is_dir() will return true + if is_dir || (is_symlink && src.is_dir()) { + for entry in fs::read_dir(&src)? { + let entry = entry?; + let file_type = entry.file_type()?; + stack.push((entry.path(), file_type.is_dir(), file_type.is_symlink())); + } + if dest != Path::new("") { + entries.push((src, dest)); + } + } else { + entries.push((src, dest)); + } + } + entries.sort_by(|(_, a), (_, b)| a.cmp(b)); + for (src, dest) in entries { + let mut header = tar::Header::new_gnu(); + let metadata = src.metadata().with_context(|| { + format!("trying to get metadata for {}", src.display()) + })?; + header.set_metadata_in_mode(&metadata, mode); + // this is what `tar` sets the mtime to on unix in deterministic mode, on windows it uses a different + // value, which causes the tarball to have a different hash on windows. force it to be the same + // to ensure the same output on all platforms + header.set_mtime(1153704088); + + let data = if src.is_file() { + Box::new( + fs::File::open(&src) + .with_context(|| format!("trying to open file {}", src.display()))?, + ) as Box + } else { + Box::new(std::io::empty()) as Box + }; + builder + .append_data(&mut header, dest, data) + .with_context(|| "appending data")?; + } + Ok(()) +} + fn get_npm_package( registry_hostname: &str, local_path: &str, @@ -228,11 +283,14 @@ fn get_npm_package( GzEncoder::new(&mut tarball_bytes, Compression::default()); { let mut builder = Builder::new(&mut encoder); - builder - .append_dir_all("package", &version_folder) - .with_context(|| { - format!("Error adding tarball for directory: {}", version_folder) - })?; + append_dir_all( + &mut builder, + Path::new("package"), + version_folder.as_path(), + ) + .with_context(|| { + format!("Error adding tarball for directory {}", version_folder,) + })?; builder.finish()?; } encoder.finish()?; From b729bf0ad9a2711b9740b30dcf78d826fbc76349 Mon Sep 17 00:00:00 2001 From: Yazan AbdAl-Rahman Date: Thu, 21 Nov 2024 01:30:43 +0200 Subject: [PATCH 06/11] feat(permission): support suffix wildcards in `--allow-env` flag (#25255) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds support for suffix wildcard for `--allow-env` flag. Specifying flag like `--allow-env=DENO_*` will enable access to all environmental variables starting with `DENO_*`. Closes #24847 --------- Co-authored-by: Bartek Iwańczuk Co-authored-by: David Sherret --- runtime/permissions/lib.rs | 203 ++++++++++++++++-- .../process_env_permissions/__test__.jsonc | 26 +++ .../process_env_permissions/main.js | 5 + .../allow_env_wildcard_worker/__test__.jsonc | 10 + .../run/allow_env_wildcard_worker/main.js | 12 ++ .../run/allow_env_wildcard_worker/main.out | 11 + .../run/allow_env_wildcard_worker/worker.js | 3 + 7 files changed, 250 insertions(+), 20 deletions(-) create mode 100644 tests/specs/permission/process_env_permissions/__test__.jsonc create mode 100644 tests/specs/permission/process_env_permissions/main.js create mode 100644 tests/specs/run/allow_env_wildcard_worker/__test__.jsonc create mode 100644 tests/specs/run/allow_env_wildcard_worker/main.js create mode 100644 tests/specs/run/allow_env_wildcard_worker/main.out create mode 100644 tests/specs/run/allow_env_wildcard_worker/worker.js diff --git a/runtime/permissions/lib.rs b/runtime/permissions/lib.rs index 71ef7d2289..a0b901d200 100644 --- a/runtime/permissions/lib.rs +++ b/runtime/permissions/lib.rs @@ -294,7 +294,7 @@ impl UnitPermission { /// A normalized environment variable name. On Windows this will /// be uppercase and on other platforms it will stay as-is. #[derive(Clone, Eq, PartialEq, Hash, Debug)] -struct EnvVarName { +pub struct EnvVarName { inner: String, } @@ -1114,15 +1114,37 @@ impl ImportDescriptor { pub struct EnvDescriptorParseError; #[derive(Clone, Eq, PartialEq, Hash, Debug)] -pub struct EnvDescriptor(EnvVarName); +pub enum EnvDescriptor { + Name(EnvVarName), + PrefixPattern(EnvVarName), +} impl EnvDescriptor { pub fn new(env: impl AsRef) -> Self { - Self(EnvVarName::new(env)) + if let Some(prefix_pattern) = env.as_ref().strip_suffix('*') { + Self::PrefixPattern(EnvVarName::new(prefix_pattern)) + } else { + Self::Name(EnvVarName::new(env)) + } } } -impl QueryDescriptor for EnvDescriptor { +#[derive(Clone, Eq, PartialEq, Hash, Debug)] +enum EnvQueryDescriptorInner { + Name(EnvVarName), + PrefixPattern(EnvVarName), +} + +#[derive(Clone, Eq, PartialEq, Hash, Debug)] +pub struct EnvQueryDescriptor(EnvQueryDescriptorInner); + +impl EnvQueryDescriptor { + pub fn new(env: impl AsRef) -> Self { + Self(EnvQueryDescriptorInner::Name(EnvVarName::new(env))) + } +} + +impl QueryDescriptor for EnvQueryDescriptor { type AllowDesc = EnvDescriptor; type DenyDesc = EnvDescriptor; @@ -1131,19 +1153,45 @@ impl QueryDescriptor for EnvDescriptor { } fn display_name(&self) -> Cow { - Cow::from(self.0.as_ref()) + Cow::from(match &self.0 { + EnvQueryDescriptorInner::Name(env_var_name) => env_var_name.as_ref(), + EnvQueryDescriptorInner::PrefixPattern(env_var_name) => { + env_var_name.as_ref() + } + }) } fn from_allow(allow: &Self::AllowDesc) -> Self { - allow.clone() + match allow { + Self::AllowDesc::Name(s) => { + Self(EnvQueryDescriptorInner::Name(s.clone())) + } + Self::AllowDesc::PrefixPattern(s) => { + Self(EnvQueryDescriptorInner::PrefixPattern(s.clone())) + } + } } fn as_allow(&self) -> Option { - Some(self.clone()) + Some(match &self.0 { + EnvQueryDescriptorInner::Name(env_var_name) => { + Self::AllowDesc::Name(env_var_name.clone()) + } + EnvQueryDescriptorInner::PrefixPattern(env_var_name) => { + Self::AllowDesc::PrefixPattern(env_var_name.clone()) + } + }) } fn as_deny(&self) -> Self::DenyDesc { - self.clone() + match &self.0 { + EnvQueryDescriptorInner::Name(env_var_name) => { + Self::DenyDesc::Name(env_var_name.clone()) + } + EnvQueryDescriptorInner::PrefixPattern(env_var_name) => { + Self::DenyDesc::PrefixPattern(env_var_name.clone()) + } + } } fn check_in_permission( @@ -1156,19 +1204,79 @@ impl QueryDescriptor for EnvDescriptor { } fn matches_allow(&self, other: &Self::AllowDesc) -> bool { - self == other + match other { + Self::AllowDesc::Name(n) => match &self.0 { + EnvQueryDescriptorInner::Name(env_var_name) => n == env_var_name, + EnvQueryDescriptorInner::PrefixPattern(env_var_name) => { + env_var_name.as_ref().starts_with(n.as_ref()) + } + }, + Self::AllowDesc::PrefixPattern(p) => match &self.0 { + EnvQueryDescriptorInner::Name(env_var_name) => { + env_var_name.as_ref().starts_with(p.as_ref()) + } + EnvQueryDescriptorInner::PrefixPattern(env_var_name) => { + env_var_name.as_ref().starts_with(p.as_ref()) + } + }, + } } fn matches_deny(&self, other: &Self::DenyDesc) -> bool { - self == other + match other { + Self::AllowDesc::Name(n) => match &self.0 { + EnvQueryDescriptorInner::Name(env_var_name) => n == env_var_name, + EnvQueryDescriptorInner::PrefixPattern(env_var_name) => { + env_var_name.as_ref().starts_with(n.as_ref()) + } + }, + Self::AllowDesc::PrefixPattern(p) => match &self.0 { + EnvQueryDescriptorInner::Name(env_var_name) => { + env_var_name.as_ref().starts_with(p.as_ref()) + } + EnvQueryDescriptorInner::PrefixPattern(env_var_name) => { + p == env_var_name + } + }, + } } fn revokes(&self, other: &Self::AllowDesc) -> bool { - self == other + match other { + Self::AllowDesc::Name(n) => match &self.0 { + EnvQueryDescriptorInner::Name(env_var_name) => n == env_var_name, + EnvQueryDescriptorInner::PrefixPattern(env_var_name) => { + env_var_name.as_ref().starts_with(n.as_ref()) + } + }, + Self::AllowDesc::PrefixPattern(p) => match &self.0 { + EnvQueryDescriptorInner::Name(env_var_name) => { + env_var_name.as_ref().starts_with(p.as_ref()) + } + EnvQueryDescriptorInner::PrefixPattern(env_var_name) => { + p == env_var_name + } + }, + } } fn stronger_than_deny(&self, other: &Self::DenyDesc) -> bool { - self == other + match other { + Self::AllowDesc::Name(n) => match &self.0 { + EnvQueryDescriptorInner::Name(env_var_name) => n == env_var_name, + EnvQueryDescriptorInner::PrefixPattern(env_var_name) => { + env_var_name.as_ref().starts_with(n.as_ref()) + } + }, + Self::AllowDesc::PrefixPattern(p) => match &self.0 { + EnvQueryDescriptorInner::Name(env_var_name) => { + env_var_name.as_ref().starts_with(p.as_ref()) + } + EnvQueryDescriptorInner::PrefixPattern(env_var_name) => { + p == env_var_name + } + }, + } } fn overlaps_deny(&self, _other: &Self::DenyDesc) -> bool { @@ -1176,9 +1284,14 @@ impl QueryDescriptor for EnvDescriptor { } } -impl AsRef for EnvDescriptor { +impl AsRef for EnvQueryDescriptor { fn as_ref(&self) -> &str { - self.0.as_ref() + match &self.0 { + EnvQueryDescriptorInner::Name(env_var_name) => env_var_name.as_ref(), + EnvQueryDescriptorInner::PrefixPattern(env_var_name) => { + env_var_name.as_ref() + } + } } } @@ -1749,20 +1862,20 @@ impl UnaryPermission { } } -impl UnaryPermission { +impl UnaryPermission { pub fn query(&self, env: Option<&str>) -> PermissionState { self.query_desc( - env.map(EnvDescriptor::new).as_ref(), + env.map(EnvQueryDescriptor::new).as_ref(), AllowPartial::TreatAsPartialGranted, ) } pub fn request(&mut self, env: Option<&str>) -> PermissionState { - self.request_desc(env.map(EnvDescriptor::new).as_ref()) + self.request_desc(env.map(EnvQueryDescriptor::new).as_ref()) } pub fn revoke(&mut self, env: Option<&str>) -> PermissionState { - self.revoke_desc(env.map(EnvDescriptor::new).as_ref()) + self.revoke_desc(env.map(EnvQueryDescriptor::new).as_ref()) } pub fn check( @@ -1771,7 +1884,7 @@ impl UnaryPermission { api_name: Option<&str>, ) -> Result<(), PermissionDeniedError> { skip_check_if_is_permission_fully_granted!(self); - self.check_desc(Some(&EnvDescriptor::new(env)), false, api_name) + self.check_desc(Some(&EnvQueryDescriptor::new(env)), false, api_name) } pub fn check_all(&mut self) -> Result<(), PermissionDeniedError> { @@ -1905,7 +2018,7 @@ pub struct Permissions { pub read: UnaryPermission, pub write: UnaryPermission, pub net: UnaryPermission, - pub env: UnaryPermission, + pub env: UnaryPermission, pub sys: UnaryPermission, pub run: UnaryPermission, pub ffi: UnaryPermission, @@ -4564,6 +4677,56 @@ mod tests { assert_eq!(perms.env.revoke(Some("HomE")), PermissionState::Prompt); } + #[test] + fn test_env_wildcards() { + set_prompter(Box::new(TestPrompter)); + let _prompt_value = PERMISSION_PROMPT_STUB_VALUE_SETTER.lock(); + let mut perms = Permissions::allow_all(); + perms.env = UnaryPermission { + granted_global: false, + ..Permissions::new_unary( + Some(HashSet::from([EnvDescriptor::new("HOME_*")])), + None, + false, + ) + }; + assert_eq!(perms.env.query(Some("HOME")), PermissionState::Prompt); + assert_eq!(perms.env.query(Some("HOME_")), PermissionState::Granted); + assert_eq!(perms.env.query(Some("HOME_TEST")), PermissionState::Granted); + + // assert no privilege escalation + let parser = TestPermissionDescriptorParser; + assert!(perms + .env + .create_child_permissions( + ChildUnaryPermissionArg::GrantedList(vec!["HOME_SUB".to_string()]), + |value| parser.parse_env_descriptor(value).map(Some), + ) + .is_ok()); + assert!(perms + .env + .create_child_permissions( + ChildUnaryPermissionArg::GrantedList(vec!["HOME*".to_string()]), + |value| parser.parse_env_descriptor(value).map(Some), + ) + .is_err()); + assert!(perms + .env + .create_child_permissions( + ChildUnaryPermissionArg::GrantedList(vec!["OUTSIDE".to_string()]), + |value| parser.parse_env_descriptor(value).map(Some), + ) + .is_err()); + assert!(perms + .env + .create_child_permissions( + // ok because this is a subset of HOME_* + ChildUnaryPermissionArg::GrantedList(vec!["HOME_S*".to_string()]), + |value| parser.parse_env_descriptor(value).map(Some), + ) + .is_ok()); + } + #[test] fn test_check_partial_denied() { let parser = TestPermissionDescriptorParser; diff --git a/tests/specs/permission/process_env_permissions/__test__.jsonc b/tests/specs/permission/process_env_permissions/__test__.jsonc new file mode 100644 index 0000000000..d3c756e0dc --- /dev/null +++ b/tests/specs/permission/process_env_permissions/__test__.jsonc @@ -0,0 +1,26 @@ +{ + "tempDir": true, + "tests": { + "deno_env_wildcard_tests": { + "envs": { + "MYAPP_HELLO": "Hello\tworld,", + "MYAPP_GOODBYE": "farewell", + "OTHER_VAR": "ignore" + }, + "steps": [ + { + "args": "run --allow-env=MYAPP_* main.js", + "output": "Hello\tworld,\nfarewell\ndone\n" + }, + { + "args": "run --allow-env main.js", + "output": "Hello\tworld,\nfarewell\ndone\n" + }, + { + "args": "run --allow-env=MYAPP_HELLO,MYAPP_GOODBYE,MYAPP_TEST,MYAPP_DONE main.js", + "output": "Hello\tworld,\nfarewell\ndone\n" + } + ] + } + } +} diff --git a/tests/specs/permission/process_env_permissions/main.js b/tests/specs/permission/process_env_permissions/main.js new file mode 100644 index 0000000000..7a412659c9 --- /dev/null +++ b/tests/specs/permission/process_env_permissions/main.js @@ -0,0 +1,5 @@ +console.log(Deno.env.get("MYAPP_HELLO")); +console.log(Deno.env.get("MYAPP_GOODBYE")); +Deno.env.set("MYAPP_TEST", "done"); +Deno.env.set("MYAPP_DONE", "done"); +console.log(Deno.env.get("MYAPP_DONE")); diff --git a/tests/specs/run/allow_env_wildcard_worker/__test__.jsonc b/tests/specs/run/allow_env_wildcard_worker/__test__.jsonc new file mode 100644 index 0000000000..6cfde6207f --- /dev/null +++ b/tests/specs/run/allow_env_wildcard_worker/__test__.jsonc @@ -0,0 +1,10 @@ +{ + "envs": { + "DENO_HELLO": "hello", + "DENO_BYE": "bye", + "AWS_HELLO": "aws" + }, + "args": "run --allow-env --allow-read --unstable-worker-options main.js", + "output": "main.out", + "exitCode": 1 +} diff --git a/tests/specs/run/allow_env_wildcard_worker/main.js b/tests/specs/run/allow_env_wildcard_worker/main.js new file mode 100644 index 0000000000..8d1a45fa61 --- /dev/null +++ b/tests/specs/run/allow_env_wildcard_worker/main.js @@ -0,0 +1,12 @@ +console.log("main1", Deno.env.get("DENO_HELLO")); +console.log("main2", Deno.env.get("DENO_BYE")); +console.log("main3", Deno.env.get("AWS_HELLO")); + +new Worker(import.meta.resolve("./worker.js"), { + type: "module", + deno: { + permissions: { + env: ["DENO_*"], + }, + }, +}); diff --git a/tests/specs/run/allow_env_wildcard_worker/main.out b/tests/specs/run/allow_env_wildcard_worker/main.out new file mode 100644 index 0000000000..01a7c42e39 --- /dev/null +++ b/tests/specs/run/allow_env_wildcard_worker/main.out @@ -0,0 +1,11 @@ +main1 hello +main2 bye +main3 aws +worker1 hello +worker2 bye +error: Uncaught (in worker "") (in promise) NotCapable: Requires env access to "AWS_HELLO", run again with the --allow-env flag +console.log("worker3", Deno.env.get("AWS_HELLO")); + ^ +[WILDCARD] +error: Uncaught (in promise) Error: Unhandled error in child worker. +[WILDCARD] diff --git a/tests/specs/run/allow_env_wildcard_worker/worker.js b/tests/specs/run/allow_env_wildcard_worker/worker.js new file mode 100644 index 0000000000..0238cbf6dc --- /dev/null +++ b/tests/specs/run/allow_env_wildcard_worker/worker.js @@ -0,0 +1,3 @@ +console.log("worker1", Deno.env.get("DENO_HELLO")); +console.log("worker2", Deno.env.get("DENO_BYE")); +console.log("worker3", Deno.env.get("AWS_HELLO")); From f0b245c8eee563a8d52db07b25a72d7382c2620b Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Thu, 21 Nov 2024 00:35:12 +0100 Subject: [PATCH 07/11] feat(task): workspace support with --filter and --recursive (#26949) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds workspace support to "deno taks". Two new flags were added: - "--recursive" - allows to run a specified task in workspace members, eg. "deno task --recursive dev" - "--filter" - allows to run a specified task only in specific workspace members, eg. "deno task --recursive --filter 'client/*' dev" "--filter" flag implies "--recursive" flag. Closes https://github.com/denoland/deno/issues/24991 --------- Signed-off-by: Bartek Iwańczuk Signed-off-by: David Sherret Co-authored-by: Bartek Iwańczuk Co-authored-by: Nathan Whitaker <17734409+nathanwhit@users.noreply.github.com> Co-authored-by: David Sherret Co-authored-by: David Sherret --- Cargo.lock | 4 +- Cargo.toml | 2 +- cli/args/flags.rs | 97 +++++- cli/main.rs | 2 + cli/tools/task.rs | 277 +++++++++++++----- .../__test__.jsonc | 5 + .../deno_json_lifecycle_script_names/bin.out | 2 + .../deno.jsonc | 7 + .../package.json | 5 + tests/specs/task/filter/__test__.jsonc | 59 ++++ tests/specs/task/filter/deno/bar/deno.json | 7 + tests/specs/task/filter/deno/deno.json | 6 + tests/specs/task/filter/deno/foo/deno.json | 7 + tests/specs/task/filter/deno_all.out | 4 + tests/specs/task/filter/deno_exact.out | 2 + tests/specs/task/filter/deno_multi.out | 0 tests/specs/task/filter/deno_scoped/deno.json | 3 + .../task/filter/deno_scoped/foo_bar/deno.json | 7 + .../task/filter/deno_scoped/foo_baz/deno.json | 7 + tests/specs/task/filter/deno_scoped_exact.out | 2 + tests/specs/task/filter/deno_scoped_multi.out | 4 + .../task/filter/deno_workspace_order.out | 4 + .../filter/deno_workspace_order/deno.json | 6 + .../deno_workspace_order/foo_bar/deno.json | 7 + .../deno_workspace_order/foo_baz/deno.json | 10 + tests/specs/task/filter/npm/bar/package.json | 6 + tests/specs/task/filter/npm/foo/package.json | 6 + tests/specs/task/filter/npm/package.json | 3 + tests/specs/task/filter/npm_all.out | 4 + tests/specs/task/filter/npm_exact.out | 2 + tests/specs/task/filter/npm_multi.out | 4 + .../filter/npm_multi/multi-a/package.json | 6 + .../filter/npm_multi/multi-b/package.json | 6 + .../specs/task/filter/npm_multi/package.json | 3 + .../filter/npm_scoped/foo_bar/package.json | 6 + .../filter/npm_scoped/foo_baz/package.json | 6 + .../specs/task/filter/npm_scoped/package.json | 3 + tests/specs/task/filter/npm_scoped_exact.out | 2 + tests/specs/task/filter/npm_scoped_multi.out | 4 + .../specs/task/filter/npm_workspace_order.out | 4 + .../npm_workspace_order/foo_bar/package.json | 6 + .../npm_workspace_order/foo_baz/package.json | 9 + .../filter/npm_workspace_order/package.json | 3 + 43 files changed, 541 insertions(+), 78 deletions(-) create mode 100644 tests/specs/task/deno_json_lifecycle_script_names/__test__.jsonc create mode 100644 tests/specs/task/deno_json_lifecycle_script_names/bin.out create mode 100644 tests/specs/task/deno_json_lifecycle_script_names/deno.jsonc create mode 100644 tests/specs/task/deno_json_lifecycle_script_names/package.json create mode 100644 tests/specs/task/filter/__test__.jsonc create mode 100644 tests/specs/task/filter/deno/bar/deno.json create mode 100644 tests/specs/task/filter/deno/deno.json create mode 100644 tests/specs/task/filter/deno/foo/deno.json create mode 100644 tests/specs/task/filter/deno_all.out create mode 100644 tests/specs/task/filter/deno_exact.out create mode 100644 tests/specs/task/filter/deno_multi.out create mode 100644 tests/specs/task/filter/deno_scoped/deno.json create mode 100644 tests/specs/task/filter/deno_scoped/foo_bar/deno.json create mode 100644 tests/specs/task/filter/deno_scoped/foo_baz/deno.json create mode 100644 tests/specs/task/filter/deno_scoped_exact.out create mode 100644 tests/specs/task/filter/deno_scoped_multi.out create mode 100644 tests/specs/task/filter/deno_workspace_order.out create mode 100644 tests/specs/task/filter/deno_workspace_order/deno.json create mode 100644 tests/specs/task/filter/deno_workspace_order/foo_bar/deno.json create mode 100644 tests/specs/task/filter/deno_workspace_order/foo_baz/deno.json create mode 100644 tests/specs/task/filter/npm/bar/package.json create mode 100644 tests/specs/task/filter/npm/foo/package.json create mode 100644 tests/specs/task/filter/npm/package.json create mode 100644 tests/specs/task/filter/npm_all.out create mode 100644 tests/specs/task/filter/npm_exact.out create mode 100644 tests/specs/task/filter/npm_multi.out create mode 100644 tests/specs/task/filter/npm_multi/multi-a/package.json create mode 100644 tests/specs/task/filter/npm_multi/multi-b/package.json create mode 100644 tests/specs/task/filter/npm_multi/package.json create mode 100644 tests/specs/task/filter/npm_scoped/foo_bar/package.json create mode 100644 tests/specs/task/filter/npm_scoped/foo_baz/package.json create mode 100644 tests/specs/task/filter/npm_scoped/package.json create mode 100644 tests/specs/task/filter/npm_scoped_exact.out create mode 100644 tests/specs/task/filter/npm_scoped_multi.out create mode 100644 tests/specs/task/filter/npm_workspace_order.out create mode 100644 tests/specs/task/filter/npm_workspace_order/foo_bar/package.json create mode 100644 tests/specs/task/filter/npm_workspace_order/foo_baz/package.json create mode 100644 tests/specs/task/filter/npm_workspace_order/package.json diff --git a/Cargo.lock b/Cargo.lock index 8850726cec..2896c0e058 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1435,9 +1435,9 @@ dependencies = [ [[package]] name = "deno_config" -version = "0.39.1" +version = "0.39.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a91aa99751ebe305a7edad12a3ad751f3b3b9f5ecddbfe4a0459e3cdc8493b6" +checksum = "38fb809500238be2b10eee42944a47b3ac38974e1edbb47f73afcfca7df143bf" dependencies = [ "anyhow", "deno_package_json", diff --git a/Cargo.toml b/Cargo.toml index cf7e2610bb..0dfe7e8bd9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,7 @@ deno_ast = { version = "=0.43.3", features = ["transpiling"] } deno_core = { version = "0.321.0" } deno_bench_util = { version = "0.171.0", path = "./bench_util" } -deno_config = { version = "=0.39.1", features = ["workspace", "sync"] } +deno_config = { version = "=0.39.2", features = ["workspace", "sync"] } deno_lockfile = "=0.23.1" deno_media_type = { version = "0.2.0", features = ["module_specifier"] } deno_npm = "=0.25.4" diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 6945065574..3464766728 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -380,6 +380,8 @@ pub struct TaskFlags { pub cwd: Option, pub task: Option, pub is_run: bool, + pub recursive: bool, + pub filter: Option, pub eval: bool, } @@ -3046,13 +3048,27 @@ Evaluate a task from string .help("Specify the directory to run the task in") .value_hint(ValueHint::DirPath), ) + .arg( + Arg::new("recursive") + .long("recursive") + .short('r') + .help("Run the task in all projects in the workspace") + .action(ArgAction::SetTrue), + ) + .arg( + Arg::new("filter") + .long("filter") + .short('f') + .help("Filter members of the workspace by name - should be used with --recursive") + .value_parser(value_parser!(String)), + ) .arg( Arg::new("eval") .long("eval") .help( "Evaluate the passed value as if, it was a task in a configuration file", ).action(ArgAction::SetTrue) - ) + ) .arg(node_modules_dir_arg()) }) } @@ -5212,10 +5228,15 @@ fn task_parse( unstable_args_parse(flags, matches, UnstableArgsConfig::ResolutionAndRuntime); node_modules_arg_parse(flags, matches); + let filter = matches.remove_one::("filter"); + let recursive = matches.get_flag("recursive") || filter.is_some(); + let mut task_flags = TaskFlags { cwd: matches.remove_one::("cwd"), task: None, is_run: false, + recursive, + filter, eval: matches.get_flag("eval"), }; @@ -10418,6 +10439,8 @@ mod tests { cwd: None, task: Some("build".to_string()), is_run: false, + recursive: false, + filter: None, eval: false, }), argv: svec!["hello", "world"], @@ -10433,6 +10456,8 @@ mod tests { cwd: None, task: Some("build".to_string()), is_run: false, + recursive: false, + filter: None, eval: false, }), ..Flags::default() @@ -10447,6 +10472,56 @@ mod tests { cwd: Some("foo".to_string()), task: Some("build".to_string()), is_run: false, + recursive: false, + filter: None, + eval: false, + }), + ..Flags::default() + } + ); + + let r = flags_from_vec(svec!["deno", "task", "--filter", "*", "build"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Task(TaskFlags { + cwd: None, + task: Some("build".to_string()), + is_run: false, + recursive: true, + filter: Some("*".to_string()), + eval: false, + }), + ..Flags::default() + } + ); + + let r = flags_from_vec(svec!["deno", "task", "--recursive", "build"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Task(TaskFlags { + cwd: None, + task: Some("build".to_string()), + is_run: false, + recursive: true, + filter: None, + eval: false, + }), + ..Flags::default() + } + ); + + let r = flags_from_vec(svec!["deno", "task", "-r", "build"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Task(TaskFlags { + cwd: None, + task: Some("build".to_string()), + is_run: false, + recursive: true, + filter: None, eval: false, }), ..Flags::default() @@ -10461,6 +10536,8 @@ mod tests { cwd: None, task: Some("echo 1".to_string()), is_run: false, + recursive: false, + filter: None, eval: true, }), ..Flags::default() @@ -10490,6 +10567,8 @@ mod tests { cwd: None, task: Some("build".to_string()), is_run: false, + recursive: false, + filter: None, eval: false, }), argv: svec!["--", "hello", "world"], @@ -10508,6 +10587,8 @@ mod tests { cwd: Some("foo".to_string()), task: Some("build".to_string()), is_run: false, + recursive: false, + filter: None, eval: false, }), argv: svec!["--", "hello", "world"], @@ -10527,6 +10608,8 @@ mod tests { cwd: None, task: Some("build".to_string()), is_run: false, + recursive: false, + filter: None, eval: false, }), argv: svec!["--"], @@ -10545,6 +10628,8 @@ mod tests { cwd: None, task: Some("build".to_string()), is_run: false, + recursive: false, + filter: None, eval: false, }), argv: svec!["-1", "--test"], @@ -10563,6 +10648,8 @@ mod tests { cwd: None, task: Some("build".to_string()), is_run: false, + recursive: false, + filter: None, eval: false, }), argv: svec!["--test"], @@ -10582,6 +10669,8 @@ mod tests { cwd: None, task: Some("build".to_string()), is_run: false, + recursive: false, + filter: None, eval: false, }), log_level: Some(log::Level::Error), @@ -10600,6 +10689,8 @@ mod tests { cwd: None, task: None, is_run: false, + recursive: false, + filter: None, eval: false, }), ..Flags::default() @@ -10617,6 +10708,8 @@ mod tests { cwd: None, task: None, is_run: false, + recursive: false, + filter: None, eval: false, }), config_flag: ConfigFlag::Path("deno.jsonc".to_string()), @@ -10635,6 +10728,8 @@ mod tests { cwd: None, task: None, is_run: false, + recursive: false, + filter: None, eval: false, }), config_flag: ConfigFlag::Path("deno.jsonc".to_string()), diff --git a/cli/main.rs b/cli/main.rs index 017e343178..29f5914bbf 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -243,6 +243,8 @@ async fn run_subcommand(flags: Arc) -> Result { cwd: None, task: Some(run_flags.script.clone()), is_run: true, + recursive: false, + filter: None, eval: false, }; new_flags.subcommand = DenoSubcommand::Task(task_flags.clone()); diff --git a/cli/tools/task.rs b/cli/tools/task.rs index 85145c7af7..b0c290adc0 100644 --- a/cli/tools/task.rs +++ b/cli/tools/task.rs @@ -8,6 +8,7 @@ use std::path::PathBuf; use std::rc::Rc; use std::sync::Arc; +use deno_config::workspace::FolderConfigs; use deno_config::workspace::TaskDefinition; use deno_config::workspace::TaskOrScript; use deno_config::workspace::WorkspaceDirectory; @@ -25,6 +26,7 @@ use deno_path_util::normalize_path; use deno_runtime::deno_node::NodeResolver; use deno_task_shell::ShellCommand; use indexmap::IndexMap; +use regex::Regex; use crate::args::CliOptions; use crate::args::Flags; @@ -35,6 +37,12 @@ use crate::npm::CliNpmResolver; use crate::task_runner; use crate::util::fs::canonicalize_path; +#[derive(Debug)] +struct PackageTaskInfo { + matched_tasks: Vec, + tasks_config: WorkspaceTasksConfig, +} + pub async fn execute_script( flags: Arc, task_flags: TaskFlags, @@ -55,18 +63,145 @@ pub async fn execute_script( v == "1" }) .unwrap_or(false); - let mut tasks_config = start_dir.to_tasks_config()?; - if force_use_pkg_json { - tasks_config = tasks_config.with_only_pkg_json() + + fn arg_to_regex(input: &str) -> Result { + let mut regex_str = regex::escape(input); + regex_str = regex_str.replace("\\*", ".*"); + + Regex::new(®ex_str) } - let Some(task_name) = &task_flags.task else { - print_available_tasks( - &mut std::io::stdout(), - &cli_options.start_dir, - &tasks_config, - )?; - return Ok(0); + let packages_task_configs: Vec = if let Some(filter) = + &task_flags.filter + { + let task_name = task_flags.task.as_ref().unwrap(); + + // Filter based on package name + let package_regex = arg_to_regex(filter)?; + let task_regex = arg_to_regex(task_name)?; + + let mut packages_task_info: Vec = vec![]; + + fn matches_package( + config: &FolderConfigs, + force_use_pkg_json: bool, + regex: &Regex, + ) -> bool { + if !force_use_pkg_json { + if let Some(deno_json) = &config.deno_json { + if let Some(name) = &deno_json.json.name { + if regex.is_match(name) { + return true; + } + } + } + } + + if let Some(package_json) = &config.pkg_json { + if let Some(name) = &package_json.name { + if regex.is_match(name) { + return true; + } + } + } + + false + } + + let workspace = cli_options.workspace(); + for folder in workspace.config_folders() { + if !matches_package(folder.1, force_use_pkg_json, &package_regex) { + continue; + } + + let member_dir = workspace.resolve_member_dir(folder.0); + let mut tasks_config = member_dir.to_tasks_config()?; + if force_use_pkg_json { + tasks_config = tasks_config.with_only_pkg_json(); + } + + // Any of the matched tasks could be a child task of another matched + // one. Therefore we need to filter these out to ensure that every + // task is only run once. + let mut matched: HashSet = HashSet::new(); + let mut visited: HashSet = HashSet::new(); + + fn visit_task( + tasks_config: &WorkspaceTasksConfig, + visited: &mut HashSet, + name: &str, + ) { + if visited.contains(name) { + return; + } + + visited.insert(name.to_string()); + + if let Some((_, TaskOrScript::Task(_, task))) = &tasks_config.task(name) + { + for dep in &task.dependencies { + visit_task(tasks_config, visited, dep); + } + } + } + + // Match tasks in deno.json + for name in tasks_config.task_names() { + if task_regex.is_match(name) && !visited.contains(name) { + matched.insert(name.to_string()); + visit_task(&tasks_config, &mut visited, name); + } + } + + packages_task_info.push(PackageTaskInfo { + matched_tasks: matched + .iter() + .map(|s| s.to_string()) + .collect::>(), + tasks_config, + }); + } + + // Logging every task definition would be too spammy. Pnpm only + // logs a simple message too. + if packages_task_info + .iter() + .all(|config| config.matched_tasks.is_empty()) + { + log::warn!( + "{}", + colors::red(format!( + "No matching task or script '{}' found in selected packages.", + task_name + )) + ); + return Ok(0); + } + + // FIXME: Sort packages topologically + // + + packages_task_info + } else { + let mut tasks_config = start_dir.to_tasks_config()?; + + if force_use_pkg_json { + tasks_config = tasks_config.with_only_pkg_json() + } + + let Some(task_name) = &task_flags.task else { + print_available_tasks( + &mut std::io::stdout(), + &cli_options.start_dir, + &tasks_config, + )?; + return Ok(0); + }; + + vec![PackageTaskInfo { + tasks_config, + matched_tasks: vec![task_name.to_string()], + }] }; let npm_resolver = factory.npm_resolver().await?; @@ -81,7 +216,6 @@ pub async fn execute_script( .unwrap_or_else(|| NonZeroUsize::new(2).unwrap()); let task_runner = TaskRunner { - tasks_config, task_flags: &task_flags, npm_resolver: npm_resolver.as_ref(), node_resolver: node_resolver.as_ref(), @@ -94,7 +228,7 @@ pub async fn execute_script( return task_runner .run_deno_task( &Url::from_directory_path(cli_options.initial_cwd()).unwrap(), - &"".to_string(), + "", &TaskDefinition { command: task_flags.task.as_ref().unwrap().to_string(), dependencies: vec![], @@ -103,7 +237,15 @@ pub async fn execute_script( ) .await; } - task_runner.run_task(task_name).await + + for task_config in &packages_task_configs { + let exit_code = task_runner.run_tasks(task_config).await?; + if exit_code > 0 { + return Ok(exit_code); + } + } + + Ok(0) } struct RunSingleOptions<'a> { @@ -114,7 +256,6 @@ struct RunSingleOptions<'a> { } struct TaskRunner<'a> { - tasks_config: WorkspaceTasksConfig, task_flags: &'a TaskFlags, npm_resolver: &'a dyn CliNpmResolver, node_resolver: &'a NodeResolver, @@ -124,12 +265,16 @@ struct TaskRunner<'a> { } impl<'a> TaskRunner<'a> { - pub async fn run_task( + pub async fn run_tasks( &self, - task_name: &str, + pkg_tasks_config: &PackageTaskInfo, ) -> Result { - match sort_tasks_topo(task_name, &self.tasks_config) { - Ok(sorted) => self.run_tasks_in_parallel(sorted).await, + match sort_tasks_topo(pkg_tasks_config) { + Ok(sorted) => { + self + .run_tasks_in_parallel(&pkg_tasks_config.tasks_config, sorted) + .await + } Err(err) => match err { TaskError::NotFound(name) => { if self.task_flags.is_run { @@ -138,7 +283,7 @@ impl<'a> TaskRunner<'a> { log::error!("Task not found: {}", name); if log::log_enabled!(log::Level::Error) { - self.print_available_tasks()?; + self.print_available_tasks(&pkg_tasks_config.tasks_config)?; } Ok(1) } @@ -150,16 +295,20 @@ impl<'a> TaskRunner<'a> { } } - pub fn print_available_tasks(&self) -> Result<(), std::io::Error> { + pub fn print_available_tasks( + &self, + tasks_config: &WorkspaceTasksConfig, + ) -> Result<(), std::io::Error> { print_available_tasks( &mut std::io::stderr(), &self.cli_options.start_dir, - &self.tasks_config, + tasks_config, ) } async fn run_tasks_in_parallel( &self, + tasks_config: &WorkspaceTasksConfig, task_names: Vec, ) -> Result { struct PendingTasksContext { @@ -181,22 +330,23 @@ impl<'a> TaskRunner<'a> { fn get_next_task<'a>( &mut self, runner: &'a TaskRunner<'a>, + tasks_config: &'a WorkspaceTasksConfig, ) -> Option>> { for name in &self.task_names { if self.completed.contains(name) || self.running.contains(name) { continue; } - let should_run = if let Ok((_, def)) = runner.get_task(name) { - match def { - TaskOrScript::Task(_, def) => def - .dependencies - .iter() - .all(|dep| self.completed.contains(dep)), - TaskOrScript::Script(_, _) => true, - } - } else { - false + let Some((folder_url, task_or_script)) = tasks_config.task(name) + else { + continue; + }; + let should_run = match task_or_script { + TaskOrScript::Task(_, def) => def + .dependencies + .iter() + .all(|dep| self.completed.contains(dep)), + TaskOrScript::Script(_, _) => true, }; if !should_run { @@ -207,10 +357,15 @@ impl<'a> TaskRunner<'a> { let name = name.clone(); return Some( async move { - runner - .run_task_no_dependencies(&name) - .await - .map(|exit_code| (exit_code, name)) + match task_or_script { + TaskOrScript::Task(_, def) => { + runner.run_deno_task(folder_url, &name, def).await + } + TaskOrScript::Script(scripts, _) => { + runner.run_npm_script(folder_url, &name, scripts).await + } + } + .map(|exit_code| (exit_code, name)) } .boxed_local(), ); @@ -229,7 +384,7 @@ impl<'a> TaskRunner<'a> { while context.has_remaining_tasks() { while queue.len() < self.concurrency { - if let Some(task) = context.get_next_task(self) { + if let Some(task) = context.get_next_task(self, tasks_config) { queue.push(task); } else { break; @@ -253,37 +408,10 @@ impl<'a> TaskRunner<'a> { Ok(0) } - fn get_task( - &self, - task_name: &str, - ) -> Result<(&Url, TaskOrScript), TaskError> { - let Some(result) = self.tasks_config.task(task_name) else { - return Err(TaskError::NotFound(task_name.to_string())); - }; - - Ok(result) - } - - async fn run_task_no_dependencies( - &self, - task_name: &String, - ) -> Result { - let (dir_url, task_or_script) = self.get_task(task_name.as_str()).unwrap(); - - match task_or_script { - TaskOrScript::Task(_tasks, definition) => { - self.run_deno_task(dir_url, task_name, definition).await - } - TaskOrScript::Script(scripts, _script) => { - self.run_npm_script(dir_url, task_name, scripts).await - } - } - } - - async fn run_deno_task( + pub async fn run_deno_task( &self, dir_url: &Url, - task_name: &String, + task_name: &str, definition: &TaskDefinition, ) -> Result { let cwd = match &self.task_flags.cwd { @@ -306,10 +434,10 @@ impl<'a> TaskRunner<'a> { .await } - async fn run_npm_script( + pub async fn run_npm_script( &self, dir_url: &Url, - task_name: &String, + task_name: &str, scripts: &IndexMap, ) -> Result { // ensure the npm packages are installed if using a managed resolver @@ -327,7 +455,7 @@ impl<'a> TaskRunner<'a> { // dealing with package.json here and not deno.json let task_names = vec![ format!("pre{}", task_name), - task_name.clone(), + task_name.to_string(), format!("post{}", task_name), ]; let custom_commands = task_runner::resolve_custom_commands( @@ -394,8 +522,7 @@ enum TaskError { } fn sort_tasks_topo( - name: &str, - task_config: &WorkspaceTasksConfig, + pkg_task_config: &PackageTaskInfo, ) -> Result, TaskError> { fn sort_visit<'a>( name: &'a str, @@ -416,12 +543,12 @@ fn sort_tasks_topo( }); } - let Some(def) = tasks_config.task(name) else { + let Some((_, task_or_script)) = tasks_config.task(name) else { return Err(TaskError::NotFound(name.to_string())); }; - if let TaskOrScript::Task(_, actual_def) = def.1 { - for dep in &actual_def.dependencies { + if let TaskOrScript::Task(_, task) = task_or_script { + for dep in &task.dependencies { let mut path = path.clone(); path.push(name); sort_visit(dep, sorted, path, tasks_config)? @@ -435,7 +562,9 @@ fn sort_tasks_topo( let mut sorted: Vec = vec![]; - sort_visit(name, &mut sorted, Vec::new(), task_config)?; + for name in &pkg_task_config.matched_tasks { + sort_visit(name, &mut sorted, Vec::new(), &pkg_task_config.tasks_config)?; + } Ok(sorted) } diff --git a/tests/specs/task/deno_json_lifecycle_script_names/__test__.jsonc b/tests/specs/task/deno_json_lifecycle_script_names/__test__.jsonc new file mode 100644 index 0000000000..d22f77cc2b --- /dev/null +++ b/tests/specs/task/deno_json_lifecycle_script_names/__test__.jsonc @@ -0,0 +1,5 @@ +{ + "args": "task test", + "output": "bin.out", + "exitCode": 0 +} diff --git a/tests/specs/task/deno_json_lifecycle_script_names/bin.out b/tests/specs/task/deno_json_lifecycle_script_names/bin.out new file mode 100644 index 0000000000..ad66595f1e --- /dev/null +++ b/tests/specs/task/deno_json_lifecycle_script_names/bin.out @@ -0,0 +1,2 @@ +Task test echo 'test' +test diff --git a/tests/specs/task/deno_json_lifecycle_script_names/deno.jsonc b/tests/specs/task/deno_json_lifecycle_script_names/deno.jsonc new file mode 100644 index 0000000000..de2f8be880 --- /dev/null +++ b/tests/specs/task/deno_json_lifecycle_script_names/deno.jsonc @@ -0,0 +1,7 @@ +{ + "task": { + // should not execute this one because it's in a deno.json + // and not in the package.json + "pretest": "echo 'should not be in output'" + } +} diff --git a/tests/specs/task/deno_json_lifecycle_script_names/package.json b/tests/specs/task/deno_json_lifecycle_script_names/package.json new file mode 100644 index 0000000000..e66cb27e3d --- /dev/null +++ b/tests/specs/task/deno_json_lifecycle_script_names/package.json @@ -0,0 +1,5 @@ +{ + "scripts": { + "test": "echo 'test'" + } +} diff --git a/tests/specs/task/filter/__test__.jsonc b/tests/specs/task/filter/__test__.jsonc new file mode 100644 index 0000000000..8baaf04dd4 --- /dev/null +++ b/tests/specs/task/filter/__test__.jsonc @@ -0,0 +1,59 @@ +{ + "tests": { + "npm_all": { + "cwd": "./npm", + "args": "task --filter * dev", + "output": "npm_all.out" + }, + "npm_exact": { + "cwd": "./npm", + "args": "task --filter foo dev", + "output": "npm_exact.out" + }, + "npm_multi": { + "cwd": "./npm_multi", + "args": "task --filter multi-* dev", + "output": "npm_multi.out" + }, + "npm_scoped_exact": { + "cwd": "./npm_scoped", + "args": "task --filter @foo/bar dev", + "output": "npm_scoped_exact.out" + }, + "npm_scoped_multi": { + "cwd": "./npm_scoped", + "args": "task --filter @foo/* dev", + "output": "npm_scoped_multi.out" + }, + "npm_workspace_order": { + "cwd": "./npm_workspace_order", + "args": "task --filter @foo/* dev", + "output": "npm_workspace_order.out" + }, + "deno_all": { + "cwd": "./deno", + "args": "task --filter * dev", + "output": "deno_all.out" + }, + "deno_exact": { + "cwd": "./deno", + "args": "task --filter foo dev", + "output": "deno_exact.out" + }, + "deno_scoped_exact": { + "cwd": "./deno_scoped", + "args": "task --filter @foo/bar dev", + "output": "deno_scoped_exact.out" + }, + "deno_scoped_multi": { + "cwd": "./deno_scoped", + "args": "task --filter @foo/* dev", + "output": "deno_scoped_multi.out" + }, + "deno_workspace_order": { + "cwd": "./deno_workspace_order", + "args": "task --filter @foo/* dev", + "output": "deno_workspace_order.out" + } + } +} diff --git a/tests/specs/task/filter/deno/bar/deno.json b/tests/specs/task/filter/deno/bar/deno.json new file mode 100644 index 0000000000..9bc7d54233 --- /dev/null +++ b/tests/specs/task/filter/deno/bar/deno.json @@ -0,0 +1,7 @@ +{ + "name": "@deno/bar", + "tasks": { + "dev": "echo '@deno/bar'" + }, + "exports": {} +} diff --git a/tests/specs/task/filter/deno/deno.json b/tests/specs/task/filter/deno/deno.json new file mode 100644 index 0000000000..133ab666b4 --- /dev/null +++ b/tests/specs/task/filter/deno/deno.json @@ -0,0 +1,6 @@ +{ + "workspace": [ + "./foo", + "./bar" + ] +} diff --git a/tests/specs/task/filter/deno/foo/deno.json b/tests/specs/task/filter/deno/foo/deno.json new file mode 100644 index 0000000000..6efb2125b7 --- /dev/null +++ b/tests/specs/task/filter/deno/foo/deno.json @@ -0,0 +1,7 @@ +{ + "name": "@deno/foo", + "tasks": { + "dev": "echo '@deno/foo'" + }, + "exports": {} +} diff --git a/tests/specs/task/filter/deno_all.out b/tests/specs/task/filter/deno_all.out new file mode 100644 index 0000000000..c3c3441559 --- /dev/null +++ b/tests/specs/task/filter/deno_all.out @@ -0,0 +1,4 @@ +Task dev echo '@deno/bar' +@deno/bar +Task dev echo '@deno/foo' +@deno/foo diff --git a/tests/specs/task/filter/deno_exact.out b/tests/specs/task/filter/deno_exact.out new file mode 100644 index 0000000000..4bfebd6e92 --- /dev/null +++ b/tests/specs/task/filter/deno_exact.out @@ -0,0 +1,2 @@ +Task dev echo '@deno/foo' +@deno/foo diff --git a/tests/specs/task/filter/deno_multi.out b/tests/specs/task/filter/deno_multi.out new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/specs/task/filter/deno_scoped/deno.json b/tests/specs/task/filter/deno_scoped/deno.json new file mode 100644 index 0000000000..7a26f9ca68 --- /dev/null +++ b/tests/specs/task/filter/deno_scoped/deno.json @@ -0,0 +1,3 @@ +{ + "workspace": ["./foo_bar", "./foo_baz"] +} diff --git a/tests/specs/task/filter/deno_scoped/foo_bar/deno.json b/tests/specs/task/filter/deno_scoped/foo_bar/deno.json new file mode 100644 index 0000000000..1773d76c26 --- /dev/null +++ b/tests/specs/task/filter/deno_scoped/foo_bar/deno.json @@ -0,0 +1,7 @@ +{ + "name": "@foo/bar", + "exports": {}, + "tasks": { + "dev": "echo '@foo/bar'" + } +} diff --git a/tests/specs/task/filter/deno_scoped/foo_baz/deno.json b/tests/specs/task/filter/deno_scoped/foo_baz/deno.json new file mode 100644 index 0000000000..f3e59719e5 --- /dev/null +++ b/tests/specs/task/filter/deno_scoped/foo_baz/deno.json @@ -0,0 +1,7 @@ +{ + "name": "@foo/baz", + "exports": {}, + "tasks": { + "dev": "echo '@foo/baz'" + } +} diff --git a/tests/specs/task/filter/deno_scoped_exact.out b/tests/specs/task/filter/deno_scoped_exact.out new file mode 100644 index 0000000000..f7d61e8714 --- /dev/null +++ b/tests/specs/task/filter/deno_scoped_exact.out @@ -0,0 +1,2 @@ +Task dev echo '@foo/bar' +@foo/bar diff --git a/tests/specs/task/filter/deno_scoped_multi.out b/tests/specs/task/filter/deno_scoped_multi.out new file mode 100644 index 0000000000..f4609e94b6 --- /dev/null +++ b/tests/specs/task/filter/deno_scoped_multi.out @@ -0,0 +1,4 @@ +Task dev echo '@foo/bar' +@foo/bar +Task dev echo '@foo/baz' +@foo/baz diff --git a/tests/specs/task/filter/deno_workspace_order.out b/tests/specs/task/filter/deno_workspace_order.out new file mode 100644 index 0000000000..f4609e94b6 --- /dev/null +++ b/tests/specs/task/filter/deno_workspace_order.out @@ -0,0 +1,4 @@ +Task dev echo '@foo/bar' +@foo/bar +Task dev echo '@foo/baz' +@foo/baz diff --git a/tests/specs/task/filter/deno_workspace_order/deno.json b/tests/specs/task/filter/deno_workspace_order/deno.json new file mode 100644 index 0000000000..cd73d72b22 --- /dev/null +++ b/tests/specs/task/filter/deno_workspace_order/deno.json @@ -0,0 +1,6 @@ +{ + "workspace": [ + "./foo_bar", + "./foo_baz" + ] +} diff --git a/tests/specs/task/filter/deno_workspace_order/foo_bar/deno.json b/tests/specs/task/filter/deno_workspace_order/foo_bar/deno.json new file mode 100644 index 0000000000..5be2ceac7f --- /dev/null +++ b/tests/specs/task/filter/deno_workspace_order/foo_bar/deno.json @@ -0,0 +1,7 @@ +{ + "name": "@foo/bar", + "tasks": { + "dev": "echo '@foo/bar'" + }, + "exports": {} +} diff --git a/tests/specs/task/filter/deno_workspace_order/foo_baz/deno.json b/tests/specs/task/filter/deno_workspace_order/foo_baz/deno.json new file mode 100644 index 0000000000..083cea5bf0 --- /dev/null +++ b/tests/specs/task/filter/deno_workspace_order/foo_baz/deno.json @@ -0,0 +1,10 @@ +{ + "name": "@foo/baz", + "tasks": { + "dev": "echo '@foo/baz'" + }, + "imports": { + "@foo/bar": "jsr:@foo/bar" + }, + "exports": {} +} diff --git a/tests/specs/task/filter/npm/bar/package.json b/tests/specs/task/filter/npm/bar/package.json new file mode 100644 index 0000000000..3723db6f01 --- /dev/null +++ b/tests/specs/task/filter/npm/bar/package.json @@ -0,0 +1,6 @@ +{ + "name": "bar", + "scripts": { + "dev": "echo 'bar'" + } +} diff --git a/tests/specs/task/filter/npm/foo/package.json b/tests/specs/task/filter/npm/foo/package.json new file mode 100644 index 0000000000..86fa20d111 --- /dev/null +++ b/tests/specs/task/filter/npm/foo/package.json @@ -0,0 +1,6 @@ +{ + "name": "foo", + "scripts": { + "dev": "echo 'foo'" + } +} diff --git a/tests/specs/task/filter/npm/package.json b/tests/specs/task/filter/npm/package.json new file mode 100644 index 0000000000..2d70009f2c --- /dev/null +++ b/tests/specs/task/filter/npm/package.json @@ -0,0 +1,3 @@ +{ + "workspaces": ["./foo", "./bar"] +} diff --git a/tests/specs/task/filter/npm_all.out b/tests/specs/task/filter/npm_all.out new file mode 100644 index 0000000000..592d4640cd --- /dev/null +++ b/tests/specs/task/filter/npm_all.out @@ -0,0 +1,4 @@ +Task dev echo 'bar' +bar +Task dev echo 'foo' +foo diff --git a/tests/specs/task/filter/npm_exact.out b/tests/specs/task/filter/npm_exact.out new file mode 100644 index 0000000000..f879b66df8 --- /dev/null +++ b/tests/specs/task/filter/npm_exact.out @@ -0,0 +1,2 @@ +Task dev echo 'foo' +foo diff --git a/tests/specs/task/filter/npm_multi.out b/tests/specs/task/filter/npm_multi.out new file mode 100644 index 0000000000..58898a5965 --- /dev/null +++ b/tests/specs/task/filter/npm_multi.out @@ -0,0 +1,4 @@ +Task dev echo 'multi-a' +multi-a +Task dev echo 'multi-b' +multi-b diff --git a/tests/specs/task/filter/npm_multi/multi-a/package.json b/tests/specs/task/filter/npm_multi/multi-a/package.json new file mode 100644 index 0000000000..348d7273ff --- /dev/null +++ b/tests/specs/task/filter/npm_multi/multi-a/package.json @@ -0,0 +1,6 @@ +{ + "name": "multi-a", + "scripts": { + "dev": "echo 'multi-a'" + } +} diff --git a/tests/specs/task/filter/npm_multi/multi-b/package.json b/tests/specs/task/filter/npm_multi/multi-b/package.json new file mode 100644 index 0000000000..f11006aea4 --- /dev/null +++ b/tests/specs/task/filter/npm_multi/multi-b/package.json @@ -0,0 +1,6 @@ +{ + "name": "multi-b", + "scripts": { + "dev": "echo 'multi-b'" + } +} diff --git a/tests/specs/task/filter/npm_multi/package.json b/tests/specs/task/filter/npm_multi/package.json new file mode 100644 index 0000000000..b6000c0487 --- /dev/null +++ b/tests/specs/task/filter/npm_multi/package.json @@ -0,0 +1,3 @@ +{ + "workspaces": ["./multi-a", "./multi-b"] +} diff --git a/tests/specs/task/filter/npm_scoped/foo_bar/package.json b/tests/specs/task/filter/npm_scoped/foo_bar/package.json new file mode 100644 index 0000000000..0e2c92c8be --- /dev/null +++ b/tests/specs/task/filter/npm_scoped/foo_bar/package.json @@ -0,0 +1,6 @@ +{ + "name": "@foo/bar", + "scripts": { + "dev": "echo '@foo/bar'" + } +} diff --git a/tests/specs/task/filter/npm_scoped/foo_baz/package.json b/tests/specs/task/filter/npm_scoped/foo_baz/package.json new file mode 100644 index 0000000000..77ec9209b1 --- /dev/null +++ b/tests/specs/task/filter/npm_scoped/foo_baz/package.json @@ -0,0 +1,6 @@ +{ + "name": "@foo/baz", + "scripts": { + "dev": "echo '@foo/baz'" + } +} diff --git a/tests/specs/task/filter/npm_scoped/package.json b/tests/specs/task/filter/npm_scoped/package.json new file mode 100644 index 0000000000..d02abfb3f8 --- /dev/null +++ b/tests/specs/task/filter/npm_scoped/package.json @@ -0,0 +1,3 @@ +{ + "workspaces": ["./foo_bar", "./foo_baz"] +} diff --git a/tests/specs/task/filter/npm_scoped_exact.out b/tests/specs/task/filter/npm_scoped_exact.out new file mode 100644 index 0000000000..f7d61e8714 --- /dev/null +++ b/tests/specs/task/filter/npm_scoped_exact.out @@ -0,0 +1,2 @@ +Task dev echo '@foo/bar' +@foo/bar diff --git a/tests/specs/task/filter/npm_scoped_multi.out b/tests/specs/task/filter/npm_scoped_multi.out new file mode 100644 index 0000000000..f4609e94b6 --- /dev/null +++ b/tests/specs/task/filter/npm_scoped_multi.out @@ -0,0 +1,4 @@ +Task dev echo '@foo/bar' +@foo/bar +Task dev echo '@foo/baz' +@foo/baz diff --git a/tests/specs/task/filter/npm_workspace_order.out b/tests/specs/task/filter/npm_workspace_order.out new file mode 100644 index 0000000000..f4609e94b6 --- /dev/null +++ b/tests/specs/task/filter/npm_workspace_order.out @@ -0,0 +1,4 @@ +Task dev echo '@foo/bar' +@foo/bar +Task dev echo '@foo/baz' +@foo/baz diff --git a/tests/specs/task/filter/npm_workspace_order/foo_bar/package.json b/tests/specs/task/filter/npm_workspace_order/foo_bar/package.json new file mode 100644 index 0000000000..0e2c92c8be --- /dev/null +++ b/tests/specs/task/filter/npm_workspace_order/foo_bar/package.json @@ -0,0 +1,6 @@ +{ + "name": "@foo/bar", + "scripts": { + "dev": "echo '@foo/bar'" + } +} diff --git a/tests/specs/task/filter/npm_workspace_order/foo_baz/package.json b/tests/specs/task/filter/npm_workspace_order/foo_baz/package.json new file mode 100644 index 0000000000..79f4b4b793 --- /dev/null +++ b/tests/specs/task/filter/npm_workspace_order/foo_baz/package.json @@ -0,0 +1,9 @@ +{ + "name": "@foo/baz", + "scripts": { + "dev": "echo '@foo/baz'" + }, + "dependencies": { + "@foo/bar": "workspace:*" + } +} diff --git a/tests/specs/task/filter/npm_workspace_order/package.json b/tests/specs/task/filter/npm_workspace_order/package.json new file mode 100644 index 0000000000..d02abfb3f8 --- /dev/null +++ b/tests/specs/task/filter/npm_workspace_order/package.json @@ -0,0 +1,3 @@ +{ + "workspaces": ["./foo_bar", "./foo_baz"] +} From d17f4590a246675b12ced7272b93b670b37f9f3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Thu, 21 Nov 2024 00:03:11 +0000 Subject: [PATCH 08/11] feat(init): add --npm flag to initialize npm projects (#26896) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds support for `deno init --npm `. Running this will actually call to `npm:create-` package that is equivalent to running `npm create `. User will be prompted if they want to allow all permissions and lifecycle scripts to be executed. Closes https://github.com/denoland/deno/issues/26461 --------- Signed-off-by: Bartek Iwańczuk Co-authored-by: crowlkats Co-authored-by: David Sherret --- cli/args/flags.rs | 121 ++++++++++++++++++++++++++-- cli/args/mod.rs | 3 +- cli/main.rs | 4 +- cli/tools/init/mod.rs | 68 +++++++++++++++- tests/specs/init/npm/__test__.jsonc | 6 ++ tests/specs/init/npm/init.out | 1 + 6 files changed, 191 insertions(+), 12 deletions(-) create mode 100644 tests/specs/init/npm/__test__.jsonc create mode 100644 tests/specs/init/npm/init.out diff --git a/cli/args/flags.rs b/cli/args/flags.rs index 3464766728..f6d53cd15e 100644 --- a/cli/args/flags.rs +++ b/cli/args/flags.rs @@ -222,6 +222,8 @@ impl FmtFlags { #[derive(Clone, Debug, Eq, PartialEq)] pub struct InitFlags { + pub package: Option, + pub package_args: Vec, pub dir: Option, pub lib: bool, pub serve: bool, @@ -1395,7 +1397,7 @@ pub fn flags_from_vec(args: Vec) -> clap::error::Result { "doc" => doc_parse(&mut flags, &mut m)?, "eval" => eval_parse(&mut flags, &mut m)?, "fmt" => fmt_parse(&mut flags, &mut m)?, - "init" => init_parse(&mut flags, &mut m), + "init" => init_parse(&mut flags, &mut m)?, "info" => info_parse(&mut flags, &mut m)?, "install" => install_parse(&mut flags, &mut m)?, "json_reference" => json_reference_parse(&mut flags, &mut m, app), @@ -2448,7 +2450,19 @@ fn init_subcommand() -> Command { command("init", "scaffolds a basic Deno project with a script, test, and configuration file", UnstableArgsConfig::None).defer( |cmd| { cmd - .arg(Arg::new("dir").value_hint(ValueHint::DirPath)) + .arg(Arg::new("args") + .num_args(0..) + .action(ArgAction::Append) + .value_name("DIRECTORY OR PACKAGE") + .trailing_var_arg(true) + ) + .arg( + Arg::new("npm") + .long("npm") + .help("Generate a npm create-* project") + .conflicts_with_all(["lib", "serve"]) + .action(ArgAction::SetTrue), + ) .arg( Arg::new("lib") .long("lib") @@ -4820,12 +4834,44 @@ fn fmt_parse( Ok(()) } -fn init_parse(flags: &mut Flags, matches: &mut ArgMatches) { +fn init_parse( + flags: &mut Flags, + matches: &mut ArgMatches, +) -> Result<(), clap::Error> { + let mut lib = matches.get_flag("lib"); + let mut serve = matches.get_flag("serve"); + let mut dir = None; + let mut package = None; + let mut package_args = vec![]; + + if let Some(mut args) = matches.remove_many::("args") { + let name = args.next().unwrap(); + let mut args = args.collect::>(); + + if matches.get_flag("npm") { + package = Some(name); + package_args = args; + } else { + dir = Some(name); + + if !args.is_empty() { + args.insert(0, "init".to_string()); + let inner_matches = init_subcommand().try_get_matches_from_mut(args)?; + lib = inner_matches.get_flag("lib"); + serve = inner_matches.get_flag("serve"); + } + } + } + flags.subcommand = DenoSubcommand::Init(InitFlags { - dir: matches.remove_one::("dir"), - lib: matches.get_flag("lib"), - serve: matches.get_flag("serve"), + package, + package_args, + dir, + lib, + serve, }); + + Ok(()) } fn info_parse( @@ -10907,6 +10953,8 @@ mod tests { r.unwrap(), Flags { subcommand: DenoSubcommand::Init(InitFlags { + package: None, + package_args: vec![], dir: None, lib: false, serve: false, @@ -10920,6 +10968,8 @@ mod tests { r.unwrap(), Flags { subcommand: DenoSubcommand::Init(InitFlags { + package: None, + package_args: vec![], dir: Some(String::from("foo")), lib: false, serve: false, @@ -10933,6 +10983,8 @@ mod tests { r.unwrap(), Flags { subcommand: DenoSubcommand::Init(InitFlags { + package: None, + package_args: vec![], dir: None, lib: false, serve: false, @@ -10947,6 +10999,8 @@ mod tests { r.unwrap(), Flags { subcommand: DenoSubcommand::Init(InitFlags { + package: None, + package_args: vec![], dir: None, lib: true, serve: false, @@ -10960,6 +11014,8 @@ mod tests { r.unwrap(), Flags { subcommand: DenoSubcommand::Init(InitFlags { + package: None, + package_args: vec![], dir: None, lib: false, serve: true, @@ -10973,6 +11029,8 @@ mod tests { r.unwrap(), Flags { subcommand: DenoSubcommand::Init(InitFlags { + package: None, + package_args: vec![], dir: Some(String::from("foo")), lib: true, serve: false, @@ -10980,6 +11038,57 @@ mod tests { ..Flags::default() } ); + + let r = flags_from_vec(svec!["deno", "init", "--lib", "--npm", "vite"]); + assert!(r.is_err()); + + let r = flags_from_vec(svec!["deno", "init", "--serve", "--npm", "vite"]); + assert!(r.is_err()); + + let r = flags_from_vec(svec!["deno", "init", "--npm", "vite", "--lib"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Init(InitFlags { + package: Some("vite".to_string()), + package_args: svec!["--lib"], + dir: None, + lib: false, + serve: false, + }), + ..Flags::default() + } + ); + + let r = flags_from_vec(svec!["deno", "init", "--npm", "vite", "--serve"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Init(InitFlags { + package: Some("vite".to_string()), + package_args: svec!["--serve"], + dir: None, + lib: false, + serve: false, + }), + ..Flags::default() + } + ); + + let r = flags_from_vec(svec!["deno", "init", "--npm", "vite", "new_dir"]); + assert_eq!( + r.unwrap(), + Flags { + subcommand: DenoSubcommand::Init(InitFlags { + package: Some("vite".to_string()), + package_args: svec!["new_dir"], + dir: None, + lib: false, + serve: false, + }), + ..Flags::default() + } + ); } #[test] diff --git a/cli/args/mod.rs b/cli/args/mod.rs index 37e1f00ffa..a1a9c49cbe 100644 --- a/cli/args/mod.rs +++ b/cli/args/mod.rs @@ -1628,9 +1628,10 @@ impl CliOptions { DenoSubcommand::Install(_) | DenoSubcommand::Add(_) | DenoSubcommand::Remove(_) + | DenoSubcommand::Init(_) | DenoSubcommand::Outdated(_) ) { - // For `deno install/add/remove` we want to force the managed resolver so it can set up `node_modules/` directory. + // For `deno install/add/remove/init` we want to force the managed resolver so it can set up `node_modules/` directory. return false; } if self.node_modules_dir().ok().flatten().is_none() diff --git a/cli/main.rs b/cli/main.rs index 29f5914bbf..c49c8a83a6 100644 --- a/cli/main.rs +++ b/cli/main.rs @@ -144,9 +144,7 @@ async fn run_subcommand(flags: Arc) -> Result { } DenoSubcommand::Init(init_flags) => { spawn_subcommand(async { - // make compiler happy since init_project is sync - tokio::task::yield_now().await; - tools::init::init_project(init_flags) + tools::init::init_project(init_flags).await }) } DenoSubcommand::Info(info_flags) => { diff --git a/cli/tools/init/mod.rs b/cli/tools/init/mod.rs index 4e4a686c5f..8f486dad53 100644 --- a/cli/tools/init/mod.rs +++ b/cli/tools/init/mod.rs @@ -1,15 +1,28 @@ // Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. +use crate::args::DenoSubcommand; +use crate::args::Flags; use crate::args::InitFlags; +use crate::args::PackagesAllowedScripts; +use crate::args::PermissionFlags; +use crate::args::RunFlags; use crate::colors; +use color_print::cformat; +use color_print::cstr; use deno_core::anyhow::Context; use deno_core::error::AnyError; use deno_core::serde_json::json; +use deno_runtime::WorkerExecutionMode; use log::info; +use std::io::IsTerminal; use std::io::Write; use std::path::Path; -pub fn init_project(init_flags: InitFlags) -> Result<(), AnyError> { +pub async fn init_project(init_flags: InitFlags) -> Result { + if let Some(package) = &init_flags.package { + return init_npm(package, init_flags.package_args).await; + } + let cwd = std::env::current_dir().context("Can't read current working directory.")?; let dir = if let Some(dir) = &init_flags.dir { @@ -235,7 +248,58 @@ Deno.test(function addTest() { info!(" {}", colors::gray("# Run the tests")); info!(" deno test"); } - Ok(()) + Ok(0) +} + +async fn init_npm(name: &str, args: Vec) -> Result { + let script_name = format!("npm:create-{}", name); + + fn print_manual_usage(script_name: &str, args: &[String]) -> i32 { + log::info!("{}", cformat!("You can initialize project manually by running deno run {} {} and applying desired permissions.", script_name, args.join(" "))); + 1 + } + + if std::io::stdin().is_terminal() { + log::info!( + cstr!("⚠️ Do you fully trust {} package? Deno will invoke code from it with all permissions. Do you want to continue? [y/n]"), + script_name + ); + loop { + let _ = std::io::stdout().write(b"> ")?; + std::io::stdout().flush()?; + let mut answer = String::new(); + if std::io::stdin().read_line(&mut answer).is_ok() { + let answer = answer.trim().to_ascii_lowercase(); + if answer != "y" { + return Ok(print_manual_usage(&script_name, &args)); + } else { + break; + } + } + } + } else { + return Ok(print_manual_usage(&script_name, &args)); + } + + let new_flags = Flags { + permissions: PermissionFlags { + allow_all: true, + ..Default::default() + }, + allow_scripts: PackagesAllowedScripts::All, + argv: args, + subcommand: DenoSubcommand::Run(RunFlags { + script: script_name, + ..Default::default() + }), + ..Default::default() + }; + crate::tools::run::run_script( + WorkerExecutionMode::Run, + new_flags.into(), + None, + ) + .await } fn create_json_file( diff --git a/tests/specs/init/npm/__test__.jsonc b/tests/specs/init/npm/__test__.jsonc new file mode 100644 index 0000000000..ccc9d181dd --- /dev/null +++ b/tests/specs/init/npm/__test__.jsonc @@ -0,0 +1,6 @@ +{ + "tempDir": true, + "args": "init --npm vite my-project", + "output": "init.out", + "exitCode": 1 +} diff --git a/tests/specs/init/npm/init.out b/tests/specs/init/npm/init.out new file mode 100644 index 0000000000..f4ba939437 --- /dev/null +++ b/tests/specs/init/npm/init.out @@ -0,0 +1 @@ +You can initialize project manually by running deno run npm:create-vite my-project and applying desired permissions. From be10901dfcfe84bda6b02828a9253f08365d5cfb Mon Sep 17 00:00:00 2001 From: David Sherret Date: Wed, 20 Nov 2024 20:02:58 -0500 Subject: [PATCH 09/11] docs: fix casing of Wasm (#26954) --- cli/tsc/dts/lib.deno.shared_globals.d.ts | 58 +++++++++---------- .../close_in_wasm_reactions.js | 2 +- .../worker_close_in_wasm_reactions.js | 2 +- .../workers/close_in_wasm_reactions.js | 2 +- tests/unit/wasm_test.ts | 4 +- 5 files changed, 34 insertions(+), 34 deletions(-) diff --git a/cli/tsc/dts/lib.deno.shared_globals.d.ts b/cli/tsc/dts/lib.deno.shared_globals.d.ts index ba872ef46e..96790fb665 100644 --- a/cli/tsc/dts/lib.deno.shared_globals.d.ts +++ b/cli/tsc/dts/lib.deno.shared_globals.d.ts @@ -15,14 +15,14 @@ /// /// -/** @category WASM */ +/** @category Wasm */ declare namespace WebAssembly { /** * The `WebAssembly.CompileError` object indicates an error during WebAssembly decoding or validation. * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/CompileError) * - * @category WASM + * @category Wasm */ export class CompileError extends Error { /** Creates a new `WebAssembly.CompileError` object. */ @@ -36,7 +36,7 @@ declare namespace WebAssembly { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Global) * - * @category WASM + * @category Wasm */ export class Global { /** Creates a new `Global` object. */ @@ -59,7 +59,7 @@ declare namespace WebAssembly { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Instance) * - * @category WASM + * @category Wasm */ export class Instance { /** Creates a new Instance object. */ @@ -79,7 +79,7 @@ declare namespace WebAssembly { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/LinkError) * - * @category WASM + * @category Wasm */ export class LinkError extends Error { /** Creates a new WebAssembly.LinkError object. */ @@ -95,7 +95,7 @@ declare namespace WebAssembly { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Memory) * - * @category WASM + * @category Wasm */ export class Memory { /** Creates a new `Memory` object. */ @@ -117,7 +117,7 @@ declare namespace WebAssembly { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Module) * - * @category WASM + * @category Wasm */ export class Module { /** Creates a new `Module` object. */ @@ -145,7 +145,7 @@ declare namespace WebAssembly { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/RuntimeError) * - * @category WASM + * @category Wasm */ export class RuntimeError extends Error { /** Creates a new `WebAssembly.RuntimeError` object. */ @@ -160,7 +160,7 @@ declare namespace WebAssembly { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/Table) * - * @category WASM + * @category Wasm */ export class Table { /** Creates a new `Table` object. */ @@ -182,7 +182,7 @@ declare namespace WebAssembly { /** The `GlobalDescriptor` describes the options you can pass to * `new WebAssembly.Global()`. * - * @category WASM + * @category Wasm */ export interface GlobalDescriptor { mutable?: boolean; @@ -192,7 +192,7 @@ declare namespace WebAssembly { /** The `MemoryDescriptor` describes the options you can pass to * `new WebAssembly.Memory()`. * - * @category WASM + * @category Wasm */ export interface MemoryDescriptor { initial: number; @@ -203,7 +203,7 @@ declare namespace WebAssembly { /** A `ModuleExportDescriptor` is the description of a declared export in a * `WebAssembly.Module`. * - * @category WASM + * @category Wasm */ export interface ModuleExportDescriptor { kind: ImportExportKind; @@ -213,7 +213,7 @@ declare namespace WebAssembly { /** A `ModuleImportDescriptor` is the description of a declared import in a * `WebAssembly.Module`. * - * @category WASM + * @category Wasm */ export interface ModuleImportDescriptor { kind: ImportExportKind; @@ -224,7 +224,7 @@ declare namespace WebAssembly { /** The `TableDescriptor` describes the options you can pass to * `new WebAssembly.Table()`. * - * @category WASM + * @category Wasm */ export interface TableDescriptor { element: TableKind; @@ -234,7 +234,7 @@ declare namespace WebAssembly { /** The value returned from `WebAssembly.instantiate`. * - * @category WASM + * @category Wasm */ export interface WebAssemblyInstantiatedSource { /* A `WebAssembly.Instance` object that contains all the exported WebAssembly functions. */ @@ -247,21 +247,21 @@ declare namespace WebAssembly { module: Module; } - /** @category WASM */ + /** @category Wasm */ export type ImportExportKind = "function" | "global" | "memory" | "table"; - /** @category WASM */ + /** @category Wasm */ export type TableKind = "anyfunc"; - /** @category WASM */ + /** @category Wasm */ export type ValueType = "f32" | "f64" | "i32" | "i64"; - /** @category WASM */ + /** @category Wasm */ export type ExportValue = Function | Global | Memory | Table; - /** @category WASM */ + /** @category Wasm */ export type Exports = Record; - /** @category WASM */ + /** @category Wasm */ export type ImportValue = ExportValue | number; - /** @category WASM */ + /** @category Wasm */ export type ModuleImports = Record; - /** @category WASM */ + /** @category Wasm */ export type Imports = Record; /** @@ -272,7 +272,7 @@ declare namespace WebAssembly { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compile) * - * @category WASM + * @category Wasm */ export function compile(bytes: BufferSource): Promise; @@ -284,7 +284,7 @@ declare namespace WebAssembly { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/compileStreaming) * - * @category WASM + * @category Wasm */ export function compileStreaming( source: Response | Promise, @@ -301,7 +301,7 @@ declare namespace WebAssembly { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate) * - * @category WASM + * @category Wasm */ export function instantiate( bytes: BufferSource, @@ -318,7 +318,7 @@ declare namespace WebAssembly { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiate) * - * @category WASM + * @category Wasm */ export function instantiate( moduleObject: Module, @@ -332,7 +332,7 @@ declare namespace WebAssembly { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/instantiateStreaming) * - * @category WASM + * @category Wasm */ export function instantiateStreaming( response: Response | PromiseLike, @@ -346,7 +346,7 @@ declare namespace WebAssembly { * * [MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WebAssembly/validate) * - * @category WASM + * @category Wasm */ export function validate(bytes: BufferSource): boolean; } diff --git a/tests/specs/run/worker_close_in_wasm_reactions/close_in_wasm_reactions.js b/tests/specs/run/worker_close_in_wasm_reactions/close_in_wasm_reactions.js index abe5731085..2cb0e4a768 100644 --- a/tests/specs/run/worker_close_in_wasm_reactions/close_in_wasm_reactions.js +++ b/tests/specs/run/worker_close_in_wasm_reactions/close_in_wasm_reactions.js @@ -1,6 +1,6 @@ // https://github.com/denoland/deno/issues/12263 // Test for a panic that happens when a worker is closed in the reactions of a -// WASM async operation. +// Wasm async operation. // The minimum valid wasm module, plus two additional zero bytes. const buffer = new Uint8Array([ diff --git a/tests/specs/run/worker_close_in_wasm_reactions/worker_close_in_wasm_reactions.js b/tests/specs/run/worker_close_in_wasm_reactions/worker_close_in_wasm_reactions.js index 828320a240..2f62707eff 100644 --- a/tests/specs/run/worker_close_in_wasm_reactions/worker_close_in_wasm_reactions.js +++ b/tests/specs/run/worker_close_in_wasm_reactions/worker_close_in_wasm_reactions.js @@ -2,7 +2,7 @@ // https://github.com/denoland/deno/issues/12263 // Test for a panic that happens when a worker is closed in the reactions of a -// WASM async operation. +// Wasm async operation. new Worker( import.meta.resolve("./close_in_wasm_reactions.js"), diff --git a/tests/testdata/workers/close_in_wasm_reactions.js b/tests/testdata/workers/close_in_wasm_reactions.js index abe5731085..2cb0e4a768 100644 --- a/tests/testdata/workers/close_in_wasm_reactions.js +++ b/tests/testdata/workers/close_in_wasm_reactions.js @@ -1,6 +1,6 @@ // https://github.com/denoland/deno/issues/12263 // Test for a panic that happens when a worker is closed in the reactions of a -// WASM async operation. +// Wasm async operation. // The minimum valid wasm module, plus two additional zero bytes. const buffer = new Uint8Array([ diff --git a/tests/unit/wasm_test.ts b/tests/unit/wasm_test.ts index e0db41ed0e..8ee9392f93 100644 --- a/tests/unit/wasm_test.ts +++ b/tests/unit/wasm_test.ts @@ -32,7 +32,7 @@ Deno.test(async function wasmInstantiateWorksWithBuffer() { }); // V8's default implementation of `WebAssembly.instantiateStreaming()` if you -// don't set the WASM streaming callback, is to take a byte source. Here we +// don't set the Wasm streaming callback, is to take a byte source. Here we // check that our implementation of the callback disallows it. Deno.test( async function wasmInstantiateStreamingFailsWithBuffer() { @@ -95,7 +95,7 @@ Deno.test( Deno.test( { permissions: { net: true } }, async function wasmStreamingNonTrivial() { - // deno-dom's WASM file is a real-world non-trivial case that gave us + // deno-dom's Wasm file is a real-world non-trivial case that gave us // trouble when implementing this. await WebAssembly.instantiateStreaming(fetch( "http://localhost:4545/assets/deno_dom_0.1.3-alpha2.wasm", From 3da4eca7c1ed97906654671669e0bb3b095bc637 Mon Sep 17 00:00:00 2001 From: denobot <33910674+denobot@users.noreply.github.com> Date: Wed, 20 Nov 2024 21:05:02 -0500 Subject: [PATCH 10/11] 2.1.0 (#26957) Bumped versions for 2.1.0 Co-authored-by: bartlomieju --- .github/workflows/ci.generate.ts | 2 +- .github/workflows/ci.yml | 8 ++-- Cargo.lock | 58 +++++++++++++------------- Cargo.toml | 56 ++++++++++++------------- Releases.md | 70 ++++++++++++++++++++++++++++++++ bench_util/Cargo.toml | 2 +- cli/Cargo.toml | 2 +- ext/broadcast_channel/Cargo.toml | 2 +- ext/cache/Cargo.toml | 2 +- ext/canvas/Cargo.toml | 2 +- ext/console/Cargo.toml | 2 +- ext/cron/Cargo.toml | 2 +- ext/crypto/Cargo.toml | 2 +- ext/fetch/Cargo.toml | 2 +- ext/ffi/Cargo.toml | 2 +- ext/fs/Cargo.toml | 2 +- ext/http/Cargo.toml | 2 +- ext/io/Cargo.toml | 2 +- ext/kv/Cargo.toml | 2 +- ext/napi/Cargo.toml | 2 +- ext/napi/sym/Cargo.toml | 2 +- ext/net/Cargo.toml | 2 +- ext/node/Cargo.toml | 2 +- ext/tls/Cargo.toml | 2 +- ext/url/Cargo.toml | 2 +- ext/web/Cargo.toml | 2 +- ext/webgpu/Cargo.toml | 2 +- ext/webidl/Cargo.toml | 2 +- ext/websocket/Cargo.toml | 2 +- ext/webstorage/Cargo.toml | 2 +- resolvers/deno/Cargo.toml | 2 +- resolvers/node/Cargo.toml | 2 +- runtime/Cargo.toml | 2 +- runtime/permissions/Cargo.toml | 2 +- 34 files changed, 161 insertions(+), 91 deletions(-) diff --git a/.github/workflows/ci.generate.ts b/.github/workflows/ci.generate.ts index 5ed02d3cde..941ee47984 100755 --- a/.github/workflows/ci.generate.ts +++ b/.github/workflows/ci.generate.ts @@ -5,7 +5,7 @@ import { stringify } from "jsr:@std/yaml@^0.221/stringify"; // Bump this number when you want to purge the cache. // Note: the tools/release/01_bump_crate_versions.ts script will update this version // automatically via regex, so ensure that this line maintains this format. -const cacheVersion = 25; +const cacheVersion = 26; const ubuntuX86Runner = "ubuntu-24.04"; const ubuntuX86XlRunner = "ubuntu-24.04-xl"; diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 39a3afe769..20e9fef503 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -361,8 +361,8 @@ jobs: path: |- ~/.cargo/registry/index ~/.cargo/registry/cache - key: '25-cargo-home-${{ matrix.os }}-${{ matrix.arch }}-${{ hashFiles(''Cargo.lock'') }}' - restore-keys: '25-cargo-home-${{ matrix.os }}-${{ matrix.arch }}' + key: '26-cargo-home-${{ matrix.os }}-${{ matrix.arch }}-${{ hashFiles(''Cargo.lock'') }}' + restore-keys: '26-cargo-home-${{ matrix.os }}-${{ matrix.arch }}' if: '!(matrix.skip)' - name: Restore cache build output (PR) uses: actions/cache/restore@v4 @@ -375,7 +375,7 @@ jobs: !./target/*/*.zip !./target/*/*.tar.gz key: never_saved - restore-keys: '25-cargo-target-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.profile }}-${{ matrix.job }}-' + restore-keys: '26-cargo-target-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.profile }}-${{ matrix.job }}-' - name: Apply and update mtime cache if: '!(matrix.skip) && (!startsWith(github.ref, ''refs/tags/''))' uses: ./.github/mtime_cache @@ -685,7 +685,7 @@ jobs: !./target/*/*.zip !./target/*/*.sha256sum !./target/*/*.tar.gz - key: '25-cargo-target-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.profile }}-${{ matrix.job }}-${{ github.sha }}' + key: '26-cargo-target-${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.profile }}-${{ matrix.job }}-${{ github.sha }}' publish-canary: name: publish canary runs-on: ubuntu-24.04 diff --git a/Cargo.lock b/Cargo.lock index 2896c0e058..bf6d3a3714 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1201,7 +1201,7 @@ dependencies = [ [[package]] name = "deno" -version = "2.0.6" +version = "2.1.0" dependencies = [ "anstream", "async-trait", @@ -1371,7 +1371,7 @@ dependencies = [ [[package]] name = "deno_bench_util" -version = "0.171.0" +version = "0.172.0" dependencies = [ "bencher", "deno_core", @@ -1380,7 +1380,7 @@ dependencies = [ [[package]] name = "deno_broadcast_channel" -version = "0.171.0" +version = "0.172.0" dependencies = [ "async-trait", "deno_core", @@ -1391,7 +1391,7 @@ dependencies = [ [[package]] name = "deno_cache" -version = "0.109.0" +version = "0.110.0" dependencies = [ "async-trait", "deno_core", @@ -1424,7 +1424,7 @@ dependencies = [ [[package]] name = "deno_canvas" -version = "0.46.0" +version = "0.47.0" dependencies = [ "deno_core", "deno_webgpu", @@ -1459,7 +1459,7 @@ dependencies = [ [[package]] name = "deno_console" -version = "0.177.0" +version = "0.178.0" dependencies = [ "deno_core", ] @@ -1506,7 +1506,7 @@ checksum = "fe4dccb6147bb3f3ba0c7a48e993bfeb999d2c2e47a81badee80e2b370c8d695" [[package]] name = "deno_cron" -version = "0.57.0" +version = "0.58.0" dependencies = [ "anyhow", "async-trait", @@ -1519,7 +1519,7 @@ dependencies = [ [[package]] name = "deno_crypto" -version = "0.191.0" +version = "0.192.0" dependencies = [ "aes", "aes-gcm", @@ -1587,7 +1587,7 @@ dependencies = [ [[package]] name = "deno_fetch" -version = "0.201.0" +version = "0.202.0" dependencies = [ "base64 0.21.7", "bytes", @@ -1621,7 +1621,7 @@ dependencies = [ [[package]] name = "deno_ffi" -version = "0.164.0" +version = "0.165.0" dependencies = [ "deno_core", "deno_permissions", @@ -1641,7 +1641,7 @@ dependencies = [ [[package]] name = "deno_fs" -version = "0.87.0" +version = "0.88.0" dependencies = [ "async-trait", "base32", @@ -1694,7 +1694,7 @@ dependencies = [ [[package]] name = "deno_http" -version = "0.175.0" +version = "0.176.0" dependencies = [ "async-compression", "async-trait", @@ -1733,7 +1733,7 @@ dependencies = [ [[package]] name = "deno_io" -version = "0.87.0" +version = "0.88.0" dependencies = [ "async-trait", "deno_core", @@ -1754,7 +1754,7 @@ dependencies = [ [[package]] name = "deno_kv" -version = "0.85.0" +version = "0.86.0" dependencies = [ "anyhow", "async-trait", @@ -1827,7 +1827,7 @@ dependencies = [ [[package]] name = "deno_napi" -version = "0.108.0" +version = "0.109.0" dependencies = [ "deno_core", "deno_permissions", @@ -1855,7 +1855,7 @@ dependencies = [ [[package]] name = "deno_net" -version = "0.169.0" +version = "0.170.0" dependencies = [ "deno_core", "deno_permissions", @@ -1872,7 +1872,7 @@ dependencies = [ [[package]] name = "deno_node" -version = "0.114.0" +version = "0.115.0" dependencies = [ "aead-gcm-stream", "aes", @@ -2024,7 +2024,7 @@ dependencies = [ [[package]] name = "deno_permissions" -version = "0.37.0" +version = "0.38.0" dependencies = [ "deno_core", "deno_path_util", @@ -2042,7 +2042,7 @@ dependencies = [ [[package]] name = "deno_resolver" -version = "0.9.0" +version = "0.10.0" dependencies = [ "anyhow", "base32", @@ -2061,7 +2061,7 @@ dependencies = [ [[package]] name = "deno_runtime" -version = "0.186.0" +version = "0.187.0" dependencies = [ "async-trait", "color-print", @@ -2198,7 +2198,7 @@ dependencies = [ [[package]] name = "deno_tls" -version = "0.164.0" +version = "0.165.0" dependencies = [ "deno_core", "deno_native_certs", @@ -2247,7 +2247,7 @@ dependencies = [ [[package]] name = "deno_url" -version = "0.177.0" +version = "0.178.0" dependencies = [ "deno_bench_util", "deno_console", @@ -2259,7 +2259,7 @@ dependencies = [ [[package]] name = "deno_web" -version = "0.208.0" +version = "0.209.0" dependencies = [ "async-trait", "base64-simd 0.8.0", @@ -2281,7 +2281,7 @@ dependencies = [ [[package]] name = "deno_webgpu" -version = "0.144.0" +version = "0.145.0" dependencies = [ "deno_core", "raw-window-handle", @@ -2294,7 +2294,7 @@ dependencies = [ [[package]] name = "deno_webidl" -version = "0.177.0" +version = "0.178.0" dependencies = [ "deno_bench_util", "deno_core", @@ -2302,7 +2302,7 @@ dependencies = [ [[package]] name = "deno_websocket" -version = "0.182.0" +version = "0.183.0" dependencies = [ "bytes", "deno_core", @@ -2324,7 +2324,7 @@ dependencies = [ [[package]] name = "deno_webstorage" -version = "0.172.0" +version = "0.173.0" dependencies = [ "deno_core", "deno_web", @@ -4752,7 +4752,7 @@ dependencies = [ [[package]] name = "napi_sym" -version = "0.107.0" +version = "0.108.0" dependencies = [ "quote", "serde", @@ -4807,7 +4807,7 @@ dependencies = [ [[package]] name = "node_resolver" -version = "0.16.0" +version = "0.17.0" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 0dfe7e8bd9..5f66c0d44d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,17 +48,17 @@ repository = "https://github.com/denoland/deno" deno_ast = { version = "=0.43.3", features = ["transpiling"] } deno_core = { version = "0.321.0" } -deno_bench_util = { version = "0.171.0", path = "./bench_util" } +deno_bench_util = { version = "0.172.0", path = "./bench_util" } deno_config = { version = "=0.39.2", features = ["workspace", "sync"] } deno_lockfile = "=0.23.1" deno_media_type = { version = "0.2.0", features = ["module_specifier"] } deno_npm = "=0.25.4" deno_path_util = "=0.2.1" -deno_permissions = { version = "0.37.0", path = "./runtime/permissions" } -deno_runtime = { version = "0.186.0", path = "./runtime" } +deno_permissions = { version = "0.38.0", path = "./runtime/permissions" } +deno_runtime = { version = "0.187.0", path = "./runtime" } deno_semver = "=0.5.16" deno_terminal = "0.2.0" -napi_sym = { version = "0.107.0", path = "./ext/napi/sym" } +napi_sym = { version = "0.108.0", path = "./ext/napi/sym" } test_util = { package = "test_server", path = "./tests/util/server" } denokv_proto = "0.8.4" @@ -67,32 +67,32 @@ denokv_remote = "0.8.4" denokv_sqlite = { default-features = false, version = "0.8.4" } # exts -deno_broadcast_channel = { version = "0.171.0", path = "./ext/broadcast_channel" } -deno_cache = { version = "0.109.0", path = "./ext/cache" } -deno_canvas = { version = "0.46.0", path = "./ext/canvas" } -deno_console = { version = "0.177.0", path = "./ext/console" } -deno_cron = { version = "0.57.0", path = "./ext/cron" } -deno_crypto = { version = "0.191.0", path = "./ext/crypto" } -deno_fetch = { version = "0.201.0", path = "./ext/fetch" } -deno_ffi = { version = "0.164.0", path = "./ext/ffi" } -deno_fs = { version = "0.87.0", path = "./ext/fs" } -deno_http = { version = "0.175.0", path = "./ext/http" } -deno_io = { version = "0.87.0", path = "./ext/io" } -deno_kv = { version = "0.85.0", path = "./ext/kv" } -deno_napi = { version = "0.108.0", path = "./ext/napi" } -deno_net = { version = "0.169.0", path = "./ext/net" } -deno_node = { version = "0.114.0", path = "./ext/node" } -deno_tls = { version = "0.164.0", path = "./ext/tls" } -deno_url = { version = "0.177.0", path = "./ext/url" } -deno_web = { version = "0.208.0", path = "./ext/web" } -deno_webgpu = { version = "0.144.0", path = "./ext/webgpu" } -deno_webidl = { version = "0.177.0", path = "./ext/webidl" } -deno_websocket = { version = "0.182.0", path = "./ext/websocket" } -deno_webstorage = { version = "0.172.0", path = "./ext/webstorage" } +deno_broadcast_channel = { version = "0.172.0", path = "./ext/broadcast_channel" } +deno_cache = { version = "0.110.0", path = "./ext/cache" } +deno_canvas = { version = "0.47.0", path = "./ext/canvas" } +deno_console = { version = "0.178.0", path = "./ext/console" } +deno_cron = { version = "0.58.0", path = "./ext/cron" } +deno_crypto = { version = "0.192.0", path = "./ext/crypto" } +deno_fetch = { version = "0.202.0", path = "./ext/fetch" } +deno_ffi = { version = "0.165.0", path = "./ext/ffi" } +deno_fs = { version = "0.88.0", path = "./ext/fs" } +deno_http = { version = "0.176.0", path = "./ext/http" } +deno_io = { version = "0.88.0", path = "./ext/io" } +deno_kv = { version = "0.86.0", path = "./ext/kv" } +deno_napi = { version = "0.109.0", path = "./ext/napi" } +deno_net = { version = "0.170.0", path = "./ext/net" } +deno_node = { version = "0.115.0", path = "./ext/node" } +deno_tls = { version = "0.165.0", path = "./ext/tls" } +deno_url = { version = "0.178.0", path = "./ext/url" } +deno_web = { version = "0.209.0", path = "./ext/web" } +deno_webgpu = { version = "0.145.0", path = "./ext/webgpu" } +deno_webidl = { version = "0.178.0", path = "./ext/webidl" } +deno_websocket = { version = "0.183.0", path = "./ext/websocket" } +deno_webstorage = { version = "0.173.0", path = "./ext/webstorage" } # resolvers -deno_resolver = { version = "0.9.0", path = "./resolvers/deno" } -node_resolver = { version = "0.16.0", path = "./resolvers/node" } +deno_resolver = { version = "0.10.0", path = "./resolvers/deno" } +node_resolver = { version = "0.17.0", path = "./resolvers/node" } aes = "=0.8.3" anyhow = "1.0.57" diff --git a/Releases.md b/Releases.md index 5ce25815bd..2cb2dfbd80 100644 --- a/Releases.md +++ b/Releases.md @@ -6,6 +6,76 @@ https://github.com/denoland/deno/releases We also have one-line install commands at: https://github.com/denoland/deno_install +### 2.1.0 / 2024.11.21 + +- feat(cli): add `--unstable-node-globals` flag (#26617) +- feat(cli): support multiple env file argument (#26527) +- feat(compile): ability to embed directory in executable (#26939) +- feat(compile): ability to embed local data files (#26934) +- feat(ext/fetch): Make fetch client parameters configurable (#26909) +- feat(ext/fetch): allow embedders to use `hickory_dns_resolver` instead of + default `GaiResolver` (#26740) +- feat(ext/fs): add ctime to Deno.stats and use it in node compat layer (#24801) +- feat(ext/http): Make http server parameters configurable (#26785) +- feat(ext/node): perf_hooks.monitorEventLoopDelay() (#26905) +- feat(fetch): accept async iterables for body (#26882) +- feat(fmt): support SQL (#26750) +- feat(info): show location for Web Cache (#26205) +- feat(init): add --npm flag to initialize npm projects (#26896) +- feat(jupyter): Add `Deno.jupyter.image` API (#26284) +- feat(lint): Add checked files list to the JSON output(#26936) +- feat(lsp): auto-imports with @deno-types directives (#26821) +- feat(node): stabilize detecting if CJS via `"type": "commonjs"` in a + package.json (#26439) +- feat(permission): support suffix wildcards in `--allow-env` flag (#25255) +- feat(publish): add `--set-version ` flag (#26141) +- feat(runtime): remove public OTEL trace API (#26854) +- feat(task): add --eval flag (#26943) +- feat(task): dependencies (#26467) +- feat(task): support object notation, remove support for JSDocs (#26886) +- feat(task): workspace support with --filter and --recursive (#26949) +- feat(watch): log which file changed on HMR or watch change (#25801) +- feat: OpenTelemetry Tracing API and Exporting (#26710) +- feat: Wasm module support (#26668) +- feat: fmt and lint respect .gitignore file (#26897) +- feat: permission stack traces in ops (#26938) +- feat: subcommand to view and update outdated dependencies (#26942) +- feat: upgrade V8 to 13.0 (#26851) +- fix(cli): preserve comments in doc tests (#26828) +- fix(cli): show prefix hint when installing a package globally (#26629) +- fix(ext/cache): gracefully error when cache creation failed (#26895) +- fix(ext/http): prefer brotli for `accept-encoding: gzip, deflate, br, zstd` + (#26814) +- fix(ext/node): New async setInterval function to improve the nodejs + compatibility (#26703) +- fix(ext/node): add autoSelectFamily option to net.createConnection (#26661) +- fix(ext/node): handle `--allow-sys=inspector` (#26836) +- fix(ext/node): increase tolerance for interval test (#26899) +- fix(ext/node): process.getBuiltinModule (#26833) +- fix(ext/node): use ERR_NOT_IMPLEMENTED for notImplemented (#26853) +- fix(ext/node): zlib.crc32() (#26856) +- fix(ext/webgpu): Create GPUQuerySet converter before usage (#26883) +- fix(ext/websocket): initialize `error` attribute of WebSocket ErrorEvent + (#26796) +- fix(ext/webstorage): use error class for sqlite error case (#26806) +- fix(fmt): error instead of panic on unstable format (#26859) +- fix(fmt): formatting of .svelte files (#26948) +- fix(install): percent encodings in interactive progress bar (#26600) +- fix(install): re-setup bin entries after running lifecycle scripts (#26752) +- fix(lockfile): track dependencies specified in TypeScript compiler options + (#26551) +- fix(lsp): ignore editor indent settings if deno.json is present (#26912) +- fix(lsp): skip code action edits that can't be converted (#26831) +- fix(node): handle resolving ".//" in npm packages (#26920) +- fix(node/crypto): support promisify on generateKeyPair (#26913) +- fix(permissions): say to use --allow-run instead of --allow-all (#26842) +- fix(publish): improve error message when missing exports (#26945) +- fix: otel resiliency (#26857) +- fix: update message for unsupported schemes with npm and jsr (#26884) +- perf(compile): code cache (#26528) +- perf(windows): delay load webgpu and some other dlls (#26917) +- perf: use available system memory for v8 isolate memory limit (#26868) + ### 2.0.6 / 2024.11.10 - feat(ext/http): abort event when request is cancelled (#26781) diff --git a/bench_util/Cargo.toml b/bench_util/Cargo.toml index d6eefc3a5d..7bb785e6e5 100644 --- a/bench_util/Cargo.toml +++ b/bench_util/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_bench_util" -version = "0.171.0" +version = "0.172.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/cli/Cargo.toml b/cli/Cargo.toml index d6f509eb97..c681884837 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno" -version = "2.0.6" +version = "2.1.0" authors.workspace = true default-run = "deno" edition.workspace = true diff --git a/ext/broadcast_channel/Cargo.toml b/ext/broadcast_channel/Cargo.toml index 90ac038357..b92b1c7beb 100644 --- a/ext/broadcast_channel/Cargo.toml +++ b/ext/broadcast_channel/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_broadcast_channel" -version = "0.171.0" +version = "0.172.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/cache/Cargo.toml b/ext/cache/Cargo.toml index 56fa0a527f..c79024e82c 100644 --- a/ext/cache/Cargo.toml +++ b/ext/cache/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_cache" -version = "0.109.0" +version = "0.110.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/canvas/Cargo.toml b/ext/canvas/Cargo.toml index 4231d7c84d..8fcb2c4a9c 100644 --- a/ext/canvas/Cargo.toml +++ b/ext/canvas/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_canvas" -version = "0.46.0" +version = "0.47.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/console/Cargo.toml b/ext/console/Cargo.toml index 80f1cca84d..9f925ac61b 100644 --- a/ext/console/Cargo.toml +++ b/ext/console/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_console" -version = "0.177.0" +version = "0.178.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/cron/Cargo.toml b/ext/cron/Cargo.toml index 966ccdc958..23ac77d5ed 100644 --- a/ext/cron/Cargo.toml +++ b/ext/cron/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_cron" -version = "0.57.0" +version = "0.58.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/crypto/Cargo.toml b/ext/crypto/Cargo.toml index a5794dc68b..4a44314221 100644 --- a/ext/crypto/Cargo.toml +++ b/ext/crypto/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_crypto" -version = "0.191.0" +version = "0.192.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/fetch/Cargo.toml b/ext/fetch/Cargo.toml index 00c85f2aa1..9ebd9ec03f 100644 --- a/ext/fetch/Cargo.toml +++ b/ext/fetch/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_fetch" -version = "0.201.0" +version = "0.202.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/ffi/Cargo.toml b/ext/ffi/Cargo.toml index 295e8be846..e63d22e57d 100644 --- a/ext/ffi/Cargo.toml +++ b/ext/ffi/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_ffi" -version = "0.164.0" +version = "0.165.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/fs/Cargo.toml b/ext/fs/Cargo.toml index ace1b89f3a..f37d1f6997 100644 --- a/ext/fs/Cargo.toml +++ b/ext/fs/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_fs" -version = "0.87.0" +version = "0.88.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/http/Cargo.toml b/ext/http/Cargo.toml index ed98fe349c..5105b47dde 100644 --- a/ext/http/Cargo.toml +++ b/ext/http/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_http" -version = "0.175.0" +version = "0.176.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/io/Cargo.toml b/ext/io/Cargo.toml index 6ef049ff9b..8f7c0e197a 100644 --- a/ext/io/Cargo.toml +++ b/ext/io/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_io" -version = "0.87.0" +version = "0.88.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/kv/Cargo.toml b/ext/kv/Cargo.toml index aa73817667..870e4fec3b 100644 --- a/ext/kv/Cargo.toml +++ b/ext/kv/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_kv" -version = "0.85.0" +version = "0.86.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/napi/Cargo.toml b/ext/napi/Cargo.toml index df3ec0287b..19f4036a88 100644 --- a/ext/napi/Cargo.toml +++ b/ext/napi/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_napi" -version = "0.108.0" +version = "0.109.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/napi/sym/Cargo.toml b/ext/napi/sym/Cargo.toml index 7c13a9165c..83107782b8 100644 --- a/ext/napi/sym/Cargo.toml +++ b/ext/napi/sym/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "napi_sym" -version = "0.107.0" +version = "0.108.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/net/Cargo.toml b/ext/net/Cargo.toml index 1febbd5338..1cb109dd21 100644 --- a/ext/net/Cargo.toml +++ b/ext/net/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_net" -version = "0.169.0" +version = "0.170.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/node/Cargo.toml b/ext/node/Cargo.toml index 36910a8446..3502d3b5f8 100644 --- a/ext/node/Cargo.toml +++ b/ext/node/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_node" -version = "0.114.0" +version = "0.115.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/tls/Cargo.toml b/ext/tls/Cargo.toml index 943fc8413e..81d28d4421 100644 --- a/ext/tls/Cargo.toml +++ b/ext/tls/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_tls" -version = "0.164.0" +version = "0.165.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/url/Cargo.toml b/ext/url/Cargo.toml index 557a4669e6..2b390e8b07 100644 --- a/ext/url/Cargo.toml +++ b/ext/url/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_url" -version = "0.177.0" +version = "0.178.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/web/Cargo.toml b/ext/web/Cargo.toml index db28d0e578..c00298991b 100644 --- a/ext/web/Cargo.toml +++ b/ext/web/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_web" -version = "0.208.0" +version = "0.209.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/webgpu/Cargo.toml b/ext/webgpu/Cargo.toml index f23bb8371e..73541ba6a2 100644 --- a/ext/webgpu/Cargo.toml +++ b/ext/webgpu/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_webgpu" -version = "0.144.0" +version = "0.145.0" authors = ["the Deno authors"] edition.workspace = true license = "MIT" diff --git a/ext/webidl/Cargo.toml b/ext/webidl/Cargo.toml index 8c3f6f6128..9f6fdc4943 100644 --- a/ext/webidl/Cargo.toml +++ b/ext/webidl/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_webidl" -version = "0.177.0" +version = "0.178.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/websocket/Cargo.toml b/ext/websocket/Cargo.toml index 61f1f5959c..bdbc169435 100644 --- a/ext/websocket/Cargo.toml +++ b/ext/websocket/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_websocket" -version = "0.182.0" +version = "0.183.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/ext/webstorage/Cargo.toml b/ext/webstorage/Cargo.toml index 01e23ab839..928844c5aa 100644 --- a/ext/webstorage/Cargo.toml +++ b/ext/webstorage/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_webstorage" -version = "0.172.0" +version = "0.173.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/resolvers/deno/Cargo.toml b/resolvers/deno/Cargo.toml index c2d4a3bc29..6be746cecb 100644 --- a/resolvers/deno/Cargo.toml +++ b/resolvers/deno/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_resolver" -version = "0.9.0" +version = "0.10.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/resolvers/node/Cargo.toml b/resolvers/node/Cargo.toml index eeac79c256..7f914479ad 100644 --- a/resolvers/node/Cargo.toml +++ b/resolvers/node/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "node_resolver" -version = "0.16.0" +version = "0.17.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/runtime/Cargo.toml b/runtime/Cargo.toml index b59cd14fa9..d4c41b831f 100644 --- a/runtime/Cargo.toml +++ b/runtime/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_runtime" -version = "0.186.0" +version = "0.187.0" authors.workspace = true edition.workspace = true license.workspace = true diff --git a/runtime/permissions/Cargo.toml b/runtime/permissions/Cargo.toml index e088eb8ce5..1e7133de6d 100644 --- a/runtime/permissions/Cargo.toml +++ b/runtime/permissions/Cargo.toml @@ -2,7 +2,7 @@ [package] name = "deno_permissions" -version = "0.37.0" +version = "0.38.0" authors.workspace = true edition.workspace = true license.workspace = true From 0b8df9f24d0119386dff4341bc4a6a1142688f2d Mon Sep 17 00:00:00 2001 From: David Sherret Date: Thu, 21 Nov 2024 00:13:47 -0500 Subject: [PATCH 11/11] chore: fix cargo publish (#26958) --- resolvers/deno/Cargo.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/resolvers/deno/Cargo.toml b/resolvers/deno/Cargo.toml index 6be746cecb..0de8b31b38 100644 --- a/resolvers/deno/Cargo.toml +++ b/resolvers/deno/Cargo.toml @@ -25,6 +25,7 @@ deno_package_json.features = ["sync"] deno_path_util.workspace = true deno_semver.workspace = true node_resolver.workspace = true +node_resolver.features = ["sync"] thiserror.workspace = true url.workspace = true