From 25ac7ff5ef431f3d28f561d08ab51565ef4d9da1 Mon Sep 17 00:00:00 2001 From: David Sherret Date: Sat, 30 Dec 2023 12:42:56 -0500 Subject: [PATCH] refactor: upgrade deno_core to 0.238 --- Cargo.lock | 169 ++++++++++++---------------------------- Cargo.toml | 4 +- base/src/build.rs | 1 + base/src/channel.rs | 2 +- base/src/runtime.rs | 14 +++- dprint.json | 2 +- plugin/Cargo.toml | 12 +-- plugin/build.rs | 3 + plugin/src/config.rs | 7 -- plugin/src/formatter.rs | 13 +++- plugin/tests/tests.rs | 11 +-- rust-toolchain.toml | 2 +- 12 files changed, 90 insertions(+), 150 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bdf5f48..2ee9955 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -145,6 +145,12 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" +[[package]] +name = "cooked-waker" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147be55d677052dabc6b22252d5dd0fd4c29c8c27aa4f2fbef0f94aa003b406f" + [[package]] name = "core-foundation-sys" version = "0.8.4" @@ -205,53 +211,29 @@ dependencies = [ "uuid", ] -[[package]] -name = "deno-proc-macro-rules" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c65c2ffdafc1564565200967edc4851c7b55422d3913466688907efd05ea26f" -dependencies = [ - "deno-proc-macro-rules-macros", - "proc-macro2", - "syn 2.0.27", -] - -[[package]] -name = "deno-proc-macro-rules-macros" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3047b312b7451e3190865713a4dd6e1f821aed614ada219766ebc3024a690435" -dependencies = [ - "once_cell", - "proc-macro2", - "quote", - "syn 2.0.27", -] - [[package]] name = "deno_console" -version = "0.121.0" +version = "0.129.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b72cbce2b28d1ede2669f4ddfbb2e68e8e360c4cfe9494686bec4ffd60aeee4b" +checksum = "dafc349dd66deb1e8d4fb8474e0416e86684c0e6d75c8cc5264486c2786326d9" dependencies = [ "deno_core", ] [[package]] name = "deno_core" -version = "0.222.0" +version = "0.238.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b13c81b9ea8462680e7b77088a44fc36390bab3dbfa5a205a285e11b64e0919c" +checksum = "0ded8b759e4435aa0929913909dd6c482ed6042dae19c53260e1caf9d55b37a9" dependencies = [ "anyhow", "bytes", + "cooked-waker", "deno_ops", "deno_unsync", "futures", - "indexmap", "libc", "log", - "once_cell", "parking_lot", "pin-project", "serde", @@ -259,6 +241,7 @@ dependencies = [ "serde_v8", "smallvec", "sourcemap", + "static_assertions", "tokio", "url", "v8", @@ -266,18 +249,13 @@ dependencies = [ [[package]] name = "deno_ops" -version = "0.98.0" +version = "0.114.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf89da1a3e50ff7c89956495b53d9bcad29e1f1b3f3d2bc54cad7155f55419c4" +checksum = "168a929496191fdd8e91f898c8454429df4d5489597777d89f47897f6a37da6b" dependencies = [ - "deno-proc-macro-rules", - "lazy-regex", - "once_cell", - "pmutil", - "proc-macro-crate", + "proc-macro-rules", "proc-macro2", "quote", - "regex", "strum", "strum_macros", "syn 2.0.27", @@ -295,9 +273,9 @@ dependencies = [ [[package]] name = "deno_url" -version = "0.121.0" +version = "0.129.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1511f888bd2a7c458c31536f5a13403202b5443ed01eeab8b6eb5b5eaff29e2" +checksum = "bf2973ee5189b027a0cafd856ce67e42aa65e975b0f41cb98f9f81328fe33ece" dependencies = [ "deno_core", "serde", @@ -306,9 +284,9 @@ dependencies = [ [[package]] name = "deno_webidl" -version = "0.121.0" +version = "0.129.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1358d0bd1ebe7286e7beb0f81848ff1478a08ead6191d6b2ad16bf9b6d712b3" +checksum = "03a3840ca8a597af0fafbaff106353766610b43ff3bcfe624662c83dfd9c4927" dependencies = [ "deno_core", ] @@ -344,9 +322,9 @@ dependencies = [ [[package]] name = "dprint-core" -version = "0.63.3" +version = "0.65.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7227b28d24aafee21ff72512336c797fa00bb3ea803186b1b105a68abc97660b" +checksum = "b569f4e3085ae957ecc37588e6b2227791b72745434eae966db29e122ba27f0d" dependencies = [ "anyhow", "async-trait", @@ -626,29 +604,6 @@ dependencies = [ "libc", ] -[[package]] -name = "lazy-regex" -version = "3.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e723bd417b2df60a0f6a2b6825f297ea04b245d4ba52b5a22cb679bdf58b05fa" -dependencies = [ - "lazy-regex-proc_macros", - "once_cell", - "regex", -] - -[[package]] -name = "lazy-regex-proc_macros" -version = "3.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f0a1d9139f0ee2e862e08a9c5d0ba0470f2aa21cd1e1aa1b1562f83116c725f" -dependencies = [ - "proc-macro2", - "quote", - "regex", - "syn 2.0.27", -] - [[package]] name = "lazy_static" version = "1.4.0" @@ -835,17 +790,6 @@ version = "0.3.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" -[[package]] -name = "pmutil" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52a40bc70c2c58040d2d8b167ba9a5ff59fc9dab7ad44771cfde3dcfde7a09c6" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.27", -] - [[package]] name = "pretty_assertions" version = "1.4.0" @@ -857,13 +801,26 @@ dependencies = [ ] [[package]] -name = "proc-macro-crate" -version = "1.3.1" +name = "proc-macro-rules" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "07c277e4e643ef00c1233393c673f655e3672cf7eb3ba08a00bdd0ea59139b5f" +dependencies = [ + "proc-macro-rules-macros", + "proc-macro2", + "syn 2.0.27", +] + +[[package]] +name = "proc-macro-rules-macros" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +checksum = "207fffb0fe655d1d47f6af98cc2793405e85929bdbc420d685554ff07be27ac7" dependencies = [ "once_cell", - "toml_edit", + "proc-macro2", + "quote", + "syn 2.0.27", ] [[package]] @@ -1015,15 +972,6 @@ dependencies = [ "serde_derive", ] -[[package]] -name = "serde_bytes" -version = "0.11.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab33ec92f677585af6d88c65593ae2375adde54efdbf16d597f2cbc7a6d368ff" -dependencies = [ - "serde", -] - [[package]] name = "serde_derive" version = "1.0.178" @@ -1049,15 +997,14 @@ dependencies = [ [[package]] name = "serde_v8" -version = "0.131.0" +version = "0.147.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38cafa16d0a4288d75925351bb54d06d2e830118ad3fad393947bb11f91b18f3" +checksum = "2af950d83e1c70b762d48fa7a869d6db9a4f191548dfd666fa4e62f2229e1dce" dependencies = [ "bytes", "derive_more", "num-bigint", "serde", - "serde_bytes", "smallvec", "thiserror", "v8", @@ -1143,6 +1090,12 @@ dependencies = [ "url", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "strum" version = "0.25.0" @@ -1280,23 +1233,6 @@ dependencies = [ "tokio", ] -[[package]] -name = "toml_datetime" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" - -[[package]] -name = "toml_edit" -version = "0.19.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8123f27e969974a3dfba720fdb560be359f57b44302d280ba72e76a74480e8a" -dependencies = [ - "indexmap", - "toml_datetime", - "winnow", -] - [[package]] name = "typenum" version = "1.16.0" @@ -1410,9 +1346,9 @@ checksum = "79daa5ed5740825c40b389c5e50312b9c86df53fccd33f281df655642b43869d" [[package]] name = "v8" -version = "0.79.2" +version = "0.82.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b15561535230812a1db89a696f1f16a12ae6c2c370c6b2241c68d4cb33963faf" +checksum = "f53dfb242f4c0c39ed3fc7064378a342e57b5c9bd774636ad34ffe405b808121" dependencies = [ "bitflags", "fslock", @@ -1597,15 +1533,6 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" -[[package]] -name = "winnow" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8bd122eb777186e60c3fdf765a58ac76e41c582f1f535fbf3314434c6b58f3f7" -dependencies = [ - "memchr", -] - [[package]] name = "yansi" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 3635b39..7f59da6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ members = [ ] [workspace.dependencies] -deno_core = "0.222.0" -dprint-core = "0.63.3" +deno_core = "0.238.0" +dprint-core = "0.65.0" serde = { version = "1.0.149", features = ["derive"] } serde_json = { version = "1.0", features = ["preserve_order"] } diff --git a/base/src/build.rs b/base/src/build.rs index c538f07..e85f3f4 100644 --- a/base/src/build.rs +++ b/base/src/build.rs @@ -19,6 +19,7 @@ pub fn create_snapshot(options: CreateSnapshotOptions) -> CreateSnapshotOutput { snapshot_path: options.snapshot_path, startup_snapshot: None, extensions: options.extensions, + skip_op_registration: false, #[cfg(debug_assertions)] compression_cb: None, #[cfg(not(debug_assertions))] diff --git a/base/src/channel.rs b/base/src/channel.rs index 309d9d4..b873920 100644 --- a/base/src/channel.rs +++ b/base/src/channel.rs @@ -16,7 +16,7 @@ pub trait Formatter { async fn format_text( &mut self, request: FormatRequest, - ) -> Result, Error>; + ) -> Result>, Error>; } pub type CreateFormatterCb = diff --git a/base/src/runtime.rs b/base/src/runtime.rs index e17d84b..9766be6 100644 --- a/base/src/runtime.rs +++ b/base/src/runtime.rs @@ -4,6 +4,7 @@ use deno_core::anyhow::Result; use deno_core::serde_v8; use deno_core::v8; use deno_core::Extension; +use deno_core::PollEventLoopOptions; use deno_core::RuntimeOptions; use serde::Deserialize; @@ -42,7 +43,11 @@ impl JsRuntime { pub async fn execute_format_script(&mut self, code: String) -> Result, Error> { let global = self.inner.execute_script("format.js", code.into())?; - let global = self.inner.resolve_value(global).await?; + let resolve = self.inner.resolve(global); + let global = self + .inner + .with_event_loop_promise(resolve, PollEventLoopOptions::default()) + .await?; let scope = &mut self.inner.handle_scope(); let local = v8::Local::new(scope, global); if local.is_undefined() { @@ -66,12 +71,15 @@ impl JsRuntime { { let inner = &mut self.inner; let fn_value = inner.execute_script(script_name, fn_name.into())?; - let fn_value = inner.resolve_value(fn_value).await?; + let fn_value = inner.resolve(fn_value).await?; let mut scope = inner.handle_scope(); let fn_func: v8::Local = v8::Local::new(&mut scope, fn_value).try_into()?; let fn_func = v8::Global::new(&mut scope, fn_func); drop(scope); - let result = inner.call_and_await(&fn_func).await?; + let call = inner.call(&fn_func); + let result = inner + .with_event_loop_promise(call, PollEventLoopOptions::default()) + .await?; let mut scope = inner.handle_scope(); let local = v8::Local::new(&mut scope, result); Ok(serde_v8::from_v8::(&mut scope, local)?) diff --git a/dprint.json b/dprint.json index a216ab4..e29ba48 100644 --- a/dprint.json +++ b/dprint.json @@ -18,7 +18,7 @@ "https://plugins.dprint.dev/json-0.19.1.wasm", "https://plugins.dprint.dev/markdown-0.16.3.wasm", "https://plugins.dprint.dev/exec-0.4.4.json@c207bf9b9a4ee1f0ecb75c594f774924baf62e8e53a2ce9d873816a408cecbf7", - "https://plugins.dprint.dev/prettier-0.28.1.json@a4808eb7b1edaa23e7df7f1facc9483b494b639c2de9f25034339f76c71d9636", + "https://plugins.dprint.dev/prettier-0.32.0.json@fa93f05ab38f00c6de138f7747372585c661f79dfb11d7f1209c069b56680820", "https://plugins.dprint.dev/toml-0.5.4.wasm" ] } diff --git a/plugin/Cargo.toml b/plugin/Cargo.toml index 8d7bf78..a6f1042 100644 --- a/plugin/Cargo.toml +++ b/plugin/Cargo.toml @@ -4,10 +4,10 @@ version = "0.32.0" edition = "2021" [dependencies] -deno_console = "0.121.0" +deno_console = "0.129.0" deno_core = { workspace = true } -deno_url = "0.121.0" -deno_webidl = "0.121.0" +deno_url = "0.129.0" +deno_webidl = "0.129.0" dprint-core = { workspace = true, features = ["process"] } dprint-plugin-deno-base = { version = "0.1.0", path = "../base" } once_cell = "1.18" @@ -15,11 +15,11 @@ serde = { workspace = true } serde_json = { workspace = true } [build-dependencies] -deno_console = "0.121.0" +deno_console = "0.129.0" deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] } dprint-plugin-deno-base = { version = "0.1.0", features = ["build"], path = "../base" } -deno_url = "0.121.0" -deno_webidl = "0.121.0" +deno_url = "0.129.0" +deno_webidl = "0.129.0" sha256 = "1.4.0" zstd = "0.13.0" diff --git a/plugin/build.rs b/plugin/build.rs index ecfceb0..3ce9b45 100644 --- a/plugin/build.rs +++ b/plugin/build.rs @@ -58,6 +58,8 @@ fn main() { extensions: Vec::new(), startup_snapshot: Some(StartupSnapshot::Boxed(snapshot)), }); + + eprintln!("Getting extensions..."); let file_extensions = tokio_runtime .block_on(runtime.execute_async_fn::>( "deno:get_extensions.js", @@ -69,6 +71,7 @@ fn main() { deno_core::serde_json::to_string(&file_extensions).unwrap(), ) .unwrap(); + eprintln!("Done"); } fn create_snapshot(snapshot_path: PathBuf, js_dir: &Path) { diff --git a/plugin/src/config.rs b/plugin/src/config.rs index 5d0e43b..da52e7c 100644 --- a/plugin/src/config.rs +++ b/plugin/src/config.rs @@ -84,13 +84,6 @@ pub fn resolve_config( NewLineKind::Auto => "auto", NewLineKind::CarriageReturnLineFeed => "crlf", NewLineKind::LineFeed => "lf", - NewLineKind::System => { - if cfg!(windows) { - "crlf" - } else { - "lf" - } - } } .into(), ); diff --git a/plugin/src/formatter.rs b/plugin/src/formatter.rs index 6844acd..827766d 100644 --- a/plugin/src/formatter.rs +++ b/plugin/src/formatter.rs @@ -51,7 +51,7 @@ impl Formatter for PrettierFormatter { async fn format_text( &mut self, request: FormatRequest, - ) -> Result, Error> { + ) -> Result>, Error> { // todo: implement cancellation and range formatting let request_value = serde_json::Value::Object({ let mut obj = serde_json::Map::new(); @@ -59,7 +59,10 @@ impl Formatter for PrettierFormatter { "filePath".to_string(), request.file_path.to_string_lossy().into(), ); - obj.insert("fileText".to_string(), request.file_text.into()); + obj.insert( + "fileText".to_string(), + String::from_utf8(request.file_bytes)?.into(), + ); obj }); let file_path = request.file_path.to_string_lossy(); @@ -70,7 +73,11 @@ impl Formatter for PrettierFormatter { serde_json::to_string(&resolve_config(&file_path, config)).unwrap(), serde_json::to_string(&config.plugins).unwrap(), ); - self.runtime.execute_format_script(code).await + self + .runtime + .execute_format_script(code) + .await + .map(|s| s.map(|s| s.into_bytes())) } } diff --git a/plugin/tests/tests.rs b/plugin/tests/tests.rs index 02f985e..a522d32 100644 --- a/plugin/tests/tests.rs +++ b/plugin/tests/tests.rs @@ -37,13 +37,13 @@ fn test_specs() { let config_result = resolve_config(spec_config, Default::default()); ensure_no_diagnostics(&config_result.diagnostics); - handle.block_on(async { + let result = handle.block_on(async { handler .format( FormatRequest { config_id: FormatConfigId::from_raw(0), file_path: file_name.to_path_buf(), - file_text: file_text.to_string(), + file_bytes: file_text.to_string().into_bytes(), config: Arc::new(config_result.config), range: None, token: Arc::new(NullCancellationToken), @@ -51,7 +51,8 @@ fn test_specs() { |_| std::future::ready(Ok(None)).boxed_local(), ) .await - }) + }); + result.map(|r| r.map(|r| String::from_utf8(r).unwrap())) } }, move |_file_name, _file_text, _spec_config| panic!("Not supported."), @@ -69,7 +70,7 @@ fn handle_syntax_error() { FormatRequest { config_id: FormatConfigId::from_raw(0), file_path: PathBuf::from("file.js"), - file_text: "const v =".to_string(), + file_bytes: "const v =".to_string().into_bytes(), config: Arc::new(Default::default()), range: None, token: Arc::new(NullCancellationToken), @@ -95,7 +96,7 @@ fn handle_invalid_file() { FormatRequest { config_id: FormatConfigId::from_raw(0), file_path: PathBuf::from("file.txt"), - file_text: "const v =".to_string(), + file_bytes: "const v =".to_string().into_bytes(), config: Arc::new(Default::default()), range: None, token: Arc::new(NullCancellationToken), diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 3c4b81e..f743517 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.73.0" +channel = "1.75.0" components = ["clippy", "rustfmt"]