diff --git a/Cargo.lock b/Cargo.lock index 2ee9955..897929b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,6 +75,21 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "bit-set" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0700ddab506f33b20a03b13996eccd309a48e5ff77d0d95926aa0210fb4e95f1" +dependencies = [ + "bit-vec", +] + +[[package]] +name = "bit-vec" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" + [[package]] name = "bitflags" version = "1.3.2" @@ -213,20 +228,22 @@ dependencies = [ [[package]] name = "deno_console" -version = "0.129.0" +version = "0.130.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dafc349dd66deb1e8d4fb8474e0416e86684c0e6d75c8cc5264486c2786326d9" +checksum = "b9d5dc3f086ff92fe030733290a1a9036b5ef00c1857d2f580a50b4d2c402d29" dependencies = [ "deno_core", ] [[package]] name = "deno_core" -version = "0.238.0" +version = "0.243.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ded8b759e4435aa0929913909dd6c482ed6042dae19c53260e1caf9d55b37a9" +checksum = "cadc994e8ecacc8b44a60bd26e510a9913d69ff9aa2fca39f9c0378084ba722d" dependencies = [ "anyhow", + "bit-set", + "bit-vec", "bytes", "cooked-waker", "deno_ops", @@ -234,6 +251,7 @@ dependencies = [ "futures", "libc", "log", + "memoffset", "parking_lot", "pin-project", "serde", @@ -249,9 +267,9 @@ dependencies = [ [[package]] name = "deno_ops" -version = "0.114.0" +version = "0.119.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168a929496191fdd8e91f898c8454429df4d5489597777d89f47897f6a37da6b" +checksum = "3ac6a58c4aef86af8a55751cb157c703cd9f21f209026515412e0912ca9c2e4c" dependencies = [ "proc-macro-rules", "proc-macro2", @@ -264,18 +282,18 @@ dependencies = [ [[package]] name = "deno_unsync" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8a8f3722afd50e566ecfc783cc8a3a046bc4dd5eb45007431dfb2776aeb8993" +checksum = "30dff7e03584dbae188dae96a0f1876740054809b2ad0cf7c9fc5d361f20e739" dependencies = [ "tokio", ] [[package]] name = "deno_url" -version = "0.129.0" +version = "0.130.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf2973ee5189b027a0cafd856ce67e42aa65e975b0f41cb98f9f81328fe33ece" +checksum = "aabb028f2d765632f84368446a2a80b8a8a5da4f70c67cc84a655bdf40598d60" dependencies = [ "deno_core", "serde", @@ -284,9 +302,9 @@ dependencies = [ [[package]] name = "deno_webidl" -version = "0.129.0" +version = "0.130.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03a3840ca8a597af0fafbaff106353766610b43ff3bcfe624662c83dfd9c4927" +checksum = "a84a33be5ba736aae662d142ffbaf3c359eea3b276cd849eecb76d1c1911aa4d" dependencies = [ "deno_core", ] @@ -638,6 +656,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "memoffset" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +dependencies = [ + "autocfg", +] + [[package]] name = "miniz_oxide" version = "0.7.1" @@ -997,9 +1024,9 @@ dependencies = [ [[package]] name = "serde_v8" -version = "0.147.0" +version = "0.152.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2af950d83e1c70b762d48fa7a869d6db9a4f191548dfd666fa4e62f2229e1dce" +checksum = "016d49be02ecb10655486c7e0a3fe2fe9345bc4c7f3cf5c66671ff327115eabe" dependencies = [ "bytes", "derive_more", diff --git a/Cargo.toml b/Cargo.toml index 7f59da6..b2cd6e8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ members = [ ] [workspace.dependencies] -deno_core = "0.238.0" +deno_core = "0.243.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/runtime.rs b/base/src/runtime.rs index 9766be6..e3b798d 100644 --- a/base/src/runtime.rs +++ b/base/src/runtime.rs @@ -41,6 +41,11 @@ impl JsRuntime { } } + /// Call this once on the main thread. + pub fn initialize_main_thread() { + deno_core::JsRuntime::init_platform(None) + } + pub async fn execute_format_script(&mut self, code: String) -> Result, Error> { let global = self.inner.execute_script("format.js", code.into())?; let resolve = self.inner.resolve(global); diff --git a/js/node/package.json b/js/node/package.json index 113db9f..7bc4929 100644 --- a/js/node/package.json +++ b/js/node/package.json @@ -40,7 +40,6 @@ "dependencies": { "buffer": "^6.0.3", "prettier": "^3.1.1", - "prettier-plugin-astro": "^0.12.3", "prettier-plugin-jsdoc": "^1.3.0", "prettier-plugin-svelte": "^3.1.2", "process": "^0.11.10", diff --git a/plugin/Cargo.toml b/plugin/Cargo.toml index a6f1042..57d7fea 100644 --- a/plugin/Cargo.toml +++ b/plugin/Cargo.toml @@ -4,10 +4,10 @@ version = "0.32.0" edition = "2021" [dependencies] -deno_console = "0.129.0" +deno_console = "0.130.0" deno_core = { workspace = true } -deno_url = "0.129.0" -deno_webidl = "0.129.0" +deno_url = "0.130.0" +deno_webidl = "0.130.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.129.0" +deno_console = "0.130.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.129.0" -deno_webidl = "0.129.0" +deno_url = "0.130.0" +deno_webidl = "0.130.0" sha256 = "1.4.0" zstd = "0.13.0" diff --git a/plugin/src/main.rs b/plugin/src/main.rs index 36c2649..5b260ca 100644 --- a/plugin/src/main.rs +++ b/plugin/src/main.rs @@ -1,6 +1,7 @@ use dprint_core::plugins::process::get_parent_process_id_from_cli_args; use dprint_core::plugins::process::handle_process_stdio_messages; use dprint_core::plugins::process::start_parent_process_checker_task; +use dprint_plugin_deno_base::runtime::JsRuntime; use dprint_plugin_deno_base::util::create_tokio_runtime; use handler::PrettierPluginHandler; @@ -9,6 +10,7 @@ mod formatter; mod handler; fn main() { + JsRuntime::initialize_main_thread(); let runtime = create_tokio_runtime(); let result = runtime.block_on(async { if let Some(parent_process_id) = get_parent_process_id_from_cli_args() { diff --git a/scripts/createForTesting.ps1 b/scripts/createForTesting.ps1 deleted file mode 100644 index 932e03d..0000000 --- a/scripts/createForTesting.ps1 +++ /dev/null @@ -1,15 +0,0 @@ -# Script for quickly creating the plugin for testing purposes on Windows -# To run: -# 1. Change the one line to `reference": `./${zipFileName}`,` in scripts/createPluginFile.js -# 2. Run `./scripts/createForTesting.ps1` -# 3. Update dprint.json to point at ./plugin.json then update checksum -# as shown when initially run. - -$ErrorActionPreference = "Stop" - -deno task build - -# todo: support more operating systems -cargo build --release -Compress-Archive -Force -Path target/release/dprint-plugin-prettier.exe -DestinationPath target/release/dprint-plugin-prettier-x86_64-pc-windows-msvc.zip -pwsh -Command { cd target/release && deno run -A ../../scripts/create_plugin_file.ts --test } diff --git a/scripts/create_for_testing.ts b/scripts/create_for_testing.ts new file mode 100644 index 0000000..89b0ca6 --- /dev/null +++ b/scripts/create_for_testing.ts @@ -0,0 +1,21 @@ +#!/usr/bin/env -S deno run -A + +// Script for quickly creating the plugin for testing purposes on Windows +// To run: +// 1. Run `./scripts/create_plugin_file.ts` +// 2. Update dprint.json to point at ./target/release/plugin.json then update checksum +// as shown when initially run. + +import $ from "dax"; + +await $`deno task build`; +await $`cargo build --release`; +if (Deno.build.os === "windows") { + await $`powershell -Command ${"Compress-Archive -Force -Path target/release/dprint-plugin-prettier.exe -DestinationPath target/release/dprint-plugin-prettier-x86_64-pc-windows-msvc.zip"}`; +} else if (Deno.build.os === "linux") { + await $`zip -j target/release/dprint-plugin-prettier-x86_64-unknown-linux-gnu.zip target/release/dprint-plugin-prettier`; +} else { + throw "TODO"; +} + +await $`cd target/release && deno run -A ../../scripts/create_plugin_file.ts --test`; diff --git a/scripts/local_test.ts b/scripts/local_test.ts new file mode 100644 index 0000000..c13c831 --- /dev/null +++ b/scripts/local_test.ts @@ -0,0 +1,11 @@ +import $ from "dax"; +import { getChecksum } from "https://raw.githubusercontent.com/dprint/automation/0.8.1/hash.ts"; + +await $`./scripts/create_for_testing.ts`; +const checksum = await getChecksum($.path("./target/release/plugin.json").readBytesSync()); +const dprintConfig = $.path("dprint.json"); +const data = dprintConfig.readJsonSync(); +const index = data.plugins.findIndex(d => d.startsWith("./target") || d.includes("prettier")); +data.plugins[index] = `./target/release/plugin.json@${checksum}`; +dprintConfig.writeJsonPrettySync(data); +await $`dprint fmt`; diff --git a/scripts/update.ts b/scripts/update.ts index 99d2dc3..e3e6024 100644 --- a/scripts/update.ts +++ b/scripts/update.ts @@ -11,7 +11,7 @@ $.logStep("Upgrading prettier..."); const jsNodePath = rootDirPath.join("./js/node"); await $`npm install`.cwd(jsNodePath); await $`npm install --save prettier`.cwd(jsNodePath); -await $`npm install --save prettier-plugin-astro`.cwd(jsNodePath); +// await $`npm install --save prettier-plugin-astro`.cwd(jsNodePath); await $`npm install --save prettier-plugin-jsdoc`.cwd(jsNodePath); await $`npm install --save prettier-plugin-svelte`.cwd(jsNodePath);