diff --git a/.gitignore b/.gitignore index 8e1be936e8df5e74c72c8f9d31bc0da49e287a45..af9fa3a2f3f6755cbef41655cb5647e4f4b067c2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ testing *.db tests/new/packages/* tests/new/ver_db/* -todo \ No newline at end of file +todo.md +test.js \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index c24d1395de01f57763c9c7720c2fb27845527898..7e8827e4eaddb4e915e9356e6cadad3d044acbd6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,7 +9,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" dependencies = [ "lazy_static", - "regex 1.7.1", + "regex 1.9.4", ] [[package]] @@ -49,9 +49,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" dependencies = [ "memchr 2.5.0", ] @@ -113,7 +113,7 @@ dependencies = [ "slab", "socket2", "waker-fn", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -141,7 +141,7 @@ dependencies = [ "futures-lite", "libc", "signal-hook", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -409,6 +409,18 @@ dependencies = [ "winapi", ] +[[package]] +name = "colored_json" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5373cd259cdfce1f5fc3d1d577c1fad8c597828f25b9ae70032b095f03825ae9" +dependencies = [ + "is-terminal", + "serde", + "serde_json", + "yansi", +] + [[package]] name = "concolor" version = "0.0.11" @@ -445,7 +457,7 @@ dependencies = [ "lazy_static", "libc", "unicode-width", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -724,7 +736,7 @@ dependencies = [ "proc-macro-crate", "proc-macro2", "quote", - "regex 1.7.1", + "regex 1.9.4", "syn", ] @@ -878,7 +890,7 @@ dependencies = [ "humantime", "is-terminal", "log 0.4.17", - "regex 1.7.1", + "regex 1.9.4", "termcolor", ] @@ -893,6 +905,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "errno" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4bcfec3a70f97c962c307b2d2c56e358cf1d00b558d74262b5f929ee8cc7e73a" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "errno-dragonfly" version = "0.1.2" @@ -962,8 +985,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb21c69b9fea5e15dbc1049e4b77145dd0ba1c84019c488102de0dc4ea4b0a27" dependencies = [ "cfg-if", - "rustix", - "windows-sys", + "rustix 0.36.7", + "windows-sys 0.42.0", ] [[package]] @@ -975,7 +998,7 @@ dependencies = [ "cfg-if", "libc", "redox_syscall", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1242,9 +1265,9 @@ dependencies = [ [[package]] name = "heck" -version = "0.4.0" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" [[package]] name = "hermit-abi" @@ -1264,6 +1287,12 @@ dependencies = [ "libc", ] +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + [[package]] name = "hex" version = "0.4.3" @@ -1281,9 +1310,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.8" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75f43d41e26995c17e71ee126451dd3941010b0514a81a9d11f3b341debc2399" +checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" dependencies = [ "bytes", "fnv", @@ -1456,7 +1485,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e7d6c6f8c91b4b9ed43484ad1a938e393caf35960fce7f82a040497207bd8e9e" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1480,14 +1509,14 @@ dependencies = [ [[package]] name = "is-terminal" -version = "0.4.2" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" +checksum = "adcf93614601c8129ddf72e2d5633df827ba6551541c6d8c59520a371475be1f" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi 0.3.1", "io-lifetimes", - "rustix", - "windows-sys", + "rustix 0.37.3", + "windows-sys 0.48.0", ] [[package]] @@ -1505,18 +1534,14 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "just_macros" -version = "0.2.0" - [[package]] name = "just_state" version = "0.2.0" dependencies = [ "clap", "colored", - "just_macros", "lazy_static", + "macros-rs", "serde", ] @@ -1532,6 +1557,7 @@ dependencies = [ "clap", "clap-verbosity-flag", "colored", + "colored_json", "data-encoding", "data-url", "deno_ast", @@ -1545,12 +1571,13 @@ dependencies = [ "futures-util", "hex", "home", + "http", "indicatif", "inquire", - "just_macros", "just_state", "libc", "log 0.4.17", + "macros-rs", "nanoid", "open", "question", @@ -1673,6 +1700,12 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" +[[package]] +name = "linux-raw-sys" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "36eb31c1778188ae1e64398743890d0877fef36d11521ac60406b42016e8c2cf" + [[package]] name = "lock_api" version = "0.4.9" @@ -1701,6 +1734,10 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "macros-rs" +version = "0.4.0" + [[package]] name = "memchr" version = "1.0.2" @@ -1778,7 +1815,7 @@ dependencies = [ "libc", "log 0.4.17", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1930,9 +1967,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.17.0" +version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" +checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" [[package]] name = "open" @@ -1941,7 +1978,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2078c0039e6a54a0c42c28faa984e115fb4c2d5bf2208f77d1961002df8576f8" dependencies = [ "pathdiff", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -2057,7 +2094,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -2176,7 +2213,7 @@ dependencies = [ "libc", "log 0.4.17", "wepoll-ffi", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -2240,9 +2277,9 @@ checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" [[package]] name = "proc-macro2" -version = "1.0.50" +version = "1.0.68" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ef7d57beacfaf2d8aee5937dab7b7f28de3cb8b1828479bb5de2a7106f2bae2" +checksum = "5b1106fec09662ec6dd98ccac0f81cef56984d0b49f75c92d8cbad76e20c005c" dependencies = [ "unicode-ident", ] @@ -2267,9 +2304,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.23" +version = "1.0.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +checksum = "5267fca4496028628a95160fc423a33e8b2e6af8a5302579e322e4b520293cae" dependencies = [ "proc-macro2", ] @@ -2349,13 +2386,25 @@ dependencies = [ [[package]] name = "regex" -version = "1.7.1" +version = "1.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48aaa5748ba571fb95cd2c85c09f629215d3a6ece942baa100950af03a34f733" +checksum = "12de2eff854e5fa4b1295edd650e227e9d8fb0c9e90b12e7f36d6a6811791a29" dependencies = [ - "aho-corasick 0.7.20", + "aho-corasick 1.1.1", "memchr 2.5.0", - "regex-syntax 0.6.28", + "regex-automata", + "regex-syntax 0.7.5", +] + +[[package]] +name = "regex-automata" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49530408a136e16e5b486e883fbb6ba058e8e4e8ae6621a77b048b314336e629" +dependencies = [ + "aho-corasick 1.1.1", + "memchr 2.5.0", + "regex-syntax 0.7.5", ] [[package]] @@ -2369,9 +2418,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.6.28" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" [[package]] name = "remove_dir_all" @@ -2429,7 +2478,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe96238927a56c408907a0c56cc7574cb198a462b4dd8c79169b98d9d5831460" dependencies = [ "env_logger 0.4.3", - "errno", + "errno 0.2.8", "lazy_static", "libc", "log 0.3.9", @@ -2474,11 +2523,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4fdebc4b395b7fbb9ab11e462e20ed9051e7b16e42d24042c776eca0ac81b03" dependencies = [ "bitflags", - "errno", + "errno 0.2.8", + "io-lifetimes", + "libc", + "linux-raw-sys 0.1.4", + "windows-sys 0.42.0", +] + +[[package]] +name = "rustix" +version = "0.37.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62b24138615de35e32031d041a09032ef3487a616d901ca4db224e7d557efae2" +dependencies = [ + "bitflags", + "errno 0.3.1", "io-lifetimes", "libc", - "linux-raw-sys", - "windows-sys", + "linux-raw-sys 0.3.4", + "windows-sys 0.45.0", ] [[package]] @@ -2532,7 +2595,7 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" dependencies = [ - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -3123,7 +3186,7 @@ dependencies = [ "dashmap", "indexmap", "once_cell", - "regex 1.7.1", + "regex 1.9.4", "serde", "sha-1", "string_enum", @@ -3359,7 +3422,7 @@ dependencies = [ "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -3874,13 +3937,61 @@ version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.1", + "windows_aarch64_msvc 0.42.1", + "windows_i686_gnu 0.42.1", + "windows_i686_msvc 0.42.1", + "windows_x86_64_gnu 0.42.1", + "windows_x86_64_gnullvm 0.42.1", + "windows_x86_64_msvc 0.42.1", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets 0.42.1", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.0", +] + +[[package]] +name = "windows-targets" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +dependencies = [ + "windows_aarch64_gnullvm 0.42.1", + "windows_aarch64_msvc 0.42.1", + "windows_i686_gnu 0.42.1", + "windows_i686_msvc 0.42.1", + "windows_x86_64_gnu 0.42.1", + "windows_x86_64_gnullvm 0.42.1", + "windows_x86_64_msvc 0.42.1", +] + +[[package]] +name = "windows-targets" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -3889,42 +4000,84 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + [[package]] name = "winreg" version = "0.10.1" @@ -3943,6 +4096,12 @@ dependencies = [ "libc", ] +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + [[package]] name = "zip" version = "0.5.13" diff --git a/Cargo.toml b/Cargo.toml index 21ec1e2b3ad04f9421adb6250fe7b1df757fa800..9ce7204bb2531c92b0358ea03f2fa660c325e6e9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,6 +6,7 @@ license = "MIT" homepage = "https://justjs.dev" repository = "https://github.com/exact-rs/just" description = "A modern runtime for javascript." +rust-version = "1.71.0" [[bin]] name = "just" @@ -14,7 +15,7 @@ path = "src/main.rs" [dependencies] # local state = { package = "just_state", path = "./crates/state", version = "0.2.0" } -macros = { package = "just_macros", path = "./crates/macros", version = "0.2.0" } +macros = { package = "macros-rs", path = "./crates/macros", version = "0.4.0" } # remote colored = "2" @@ -26,6 +27,7 @@ home = "0.5.4" open = "3.2.0" warp = "0.3.3" log = "0.4.17" +http = "0.2.9" sha2 = "0.10.6" brown = "0.2.0" sled = "0.34.7" @@ -48,6 +50,7 @@ zip-extract = "0.1.1" exact-panic = "0.0.7" env_logger = "0.10.0" esbuild-rs = "0.13.8" +colored_json = "3.1.0" futures-util = "0.3.25" v_htmlescape = "0.15.8" data-encoding = "2.3.2" diff --git a/crates/macros/Cargo.toml b/crates/macros/Cargo.toml index 496847457bcdbb1b5a176101522927206ab7bf6a..417aae038cf80266552e5e73ca996c8ac5346403 100644 --- a/crates/macros/Cargo.toml +++ b/crates/macros/Cargo.toml @@ -1,8 +1,8 @@ [package] -name = "just_macros" -version = "0.2.0" +name = "macros-rs" +version = "0.4.0" edition = "2021" license = "MIT" -description = "macros for justjs" +description = "Useful macros" [dependencies] diff --git a/crates/macros/src/expression.rs b/crates/macros/src/expression.rs index 99ee44f83ef09b312bca2c5e26d3ad1d59957ed5..1fe9eee7a91b8a1f6f05b5b8c6e884d711abe479 100644 --- a/crates/macros/src/expression.rs +++ b/crates/macros/src/expression.rs @@ -1,3 +1,21 @@ +#[macro_export] +macro_rules! inc { + ($id:expr) => {{ + let _rv = $id; + $id += 1; + _rv + }}; +} + +#[macro_export] +macro_rules! dec { + ($id:expr) => {{ + let _rv = $id; + $id -= 1; + _rv + }}; +} + #[macro_export] macro_rules! ternary { ($c:expr, $v:expr, $v1:expr) => { @@ -9,6 +27,17 @@ macro_rules! ternary { }; } +#[macro_export] +macro_rules! then { + ($c:expr, $v:expr) => { + if $c { + $v + } else { + false + } + }; +} + #[macro_export] macro_rules! attempt { (@recurse ($a:expr) { } catch ($e:ident) $b:block) => { diff --git a/crates/macros/src/format.rs b/crates/macros/src/format.rs index e288e7a2ece3b58a0e35aa3b78e24f729fda94b0..9f22f5e7505746840a04515ba08536848e882b78 100644 --- a/crates/macros/src/format.rs +++ b/crates/macros/src/format.rs @@ -26,31 +26,31 @@ macro_rules! fmtstr { #[macro_export] macro_rules! error { - ($($arg:tt)*) => { + ($($arg:tt)*) => {{ use std::io::Write; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; let mut stderr = StandardStream::stderr(ColorChoice::Always); stderr.set_color(ColorSpec::new().set_fg(Some(Color::Red))).expect("Unable to write to stderr (file handle closed?)"); write!(&mut stderr, $($arg)*).expect("Unable to write to stderr (file handle closed?)"); - } + }}; } #[macro_export] macro_rules! errorln { - ($($arg:tt)*) => { + ($($arg:tt)*) => {{ use std::io::Write; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; let mut stderr = StandardStream::stderr(ColorChoice::Always); stderr.set_color(ColorSpec::new().set_fg(Some(Color::Red))).expect("Unable to write to stderr (file handle closed?)"); writeln!(&mut stderr, $($arg)*).expect("Unable to write to stderr (file handle closed?)"); - } + }}; } #[macro_export] macro_rules! crash { - ($($arg:tt)*) => { + ($($arg:tt)*) => {{ use std::io::Write; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; @@ -58,12 +58,12 @@ macro_rules! crash { stderr.set_color(ColorSpec::new().set_fg(Some(Color::Red))).expect("Unable to write to stderr (file handle closed?)"); write!(&mut stderr, $($arg)*).expect("Unable to write to stderr (file handle closed?)"); std::process::exit(1); - } + }}; } #[macro_export] macro_rules! crashln { - ($($arg:tt)*) => { + ($($arg:tt)*) => {{ use std::io::Write; use termcolor::{Color, ColorChoice, ColorSpec, StandardStream, WriteColor}; @@ -71,5 +71,5 @@ macro_rules! crashln { stderr.set_color(ColorSpec::new().set_fg(Some(Color::Red))).expect("Unable to write to stderr (file handle closed?)"); writeln!(&mut stderr, $($arg)*).expect("Unable to write to stderr (file handle closed?)"); std::process::exit(1); - } + }}; } diff --git a/crates/macros/src/interface.rs b/crates/macros/src/interface.rs index c9cfee2f1b0958a809aeb68e9faa85a8138e42d5..a236d4d1e3875f0096e5e41b6cba6d41b41d47e7 100644 --- a/crates/macros/src/interface.rs +++ b/crates/macros/src/interface.rs @@ -24,3 +24,13 @@ macro_rules! scaffold { } }; } + +#[macro_export] +macro_rules! derive { + (pub struct $name:ident { $($field:ident: $type:ty),* $(,)? }) => { + #[derive(Clone, Debug, serde_derive::Deserialize, serde_derive::Serialize)] + struct $name { + $($field: $type),* + } + }; +} diff --git a/crates/state/Cargo.toml b/crates/state/Cargo.toml index 492ad5a41933bf3fe0c2adc33d4d04440ba88cfd..e5d04c007b270ac7aa0b38e2ba42b8d9ec4d475e 100644 --- a/crates/state/Cargo.toml +++ b/crates/state/Cargo.toml @@ -7,7 +7,7 @@ description = "justjs state manager" [dependencies] # local -macros = { package = "just_macros", path = "../macros", version = "0.2.0" } +macros = { package = "macros-rs", path = "../macros", version = "0.4.0" } # ext colored = "2.0.0" diff --git a/maidfile b/maidfile.toml similarity index 90% rename from maidfile rename to maidfile.toml index 3791e35d2d9b7f9bc0a92fc2aef4357c834efed5..bac278f5fe13d007e3a99f2d90372d29435e6c91 100644 --- a/maidfile +++ b/maidfile.toml @@ -1,14 +1,15 @@ +[env] JUST_PATH = "%{dir.home}/Developer/rust/js_runtime" [tasks._publish_macros] info = "helper for publish" path = "crates/macros" -script = "cargo publish --no-verify" +script = "cargo publish --no-verify --allow-dirty" [tasks._publish_state] info = "helper for publish" path = "crates/state" -script = "cargo publish --no-verify" +script = "cargo publish --no-verify --allow-dirty" [tasks._test_no-verify] info = "helper for test-all" diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000000000000000000000000000000000000..c0dd6ebb3c1d6641125b12508e4333df106877f2 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,2 @@ +[toolchain] +channel = "1.71.0" \ No newline at end of file diff --git a/src/ops/core.rs b/src/ops/core.rs index 6e89d72b4fb8c26fc808088381984cc121cd28a9..180c1f92b3da5634da3225f53d537428ef8edd4d 100644 --- a/src/ops/core.rs +++ b/src/ops/core.rs @@ -3,6 +3,7 @@ use crate::project; use anyhow::Error; use colored::Colorize; +use colored_json::prelude::*; use duration_string::DurationString; use engine::{op, v8, OpDecl}; use macros::{crashln, function_name, ternary}; @@ -27,6 +28,7 @@ pub fn init() -> Vec<OpDecl> { hex_decode::decl(), random_uuid::decl(), get_package::decl(), + object_print::decl(), base64_encode::decl(), base64_decode::decl(), escape_string::decl(), @@ -106,6 +108,13 @@ fn get_package(package: String, version: String) -> String { return format!("{}/packages/{package}/{}/{package_index}", dir.display(), &package_version); } +#[op] +fn object_print(msg: String) -> Result<(), Error> { + stdout().write_all(msg.to_colored_json_auto()?.as_bytes())?; + stdout().flush().unwrap(); + Ok(()) +} + #[op] fn print(msg: String) -> Result<(), Error> { stdout().write_all(msg.as_bytes())?; diff --git a/src/runtime/src/log.js b/src/runtime/src/log.js index 24c174abfbfae00a2400ec9acd4a64714dcfd7e2..04532e6eb6cadb10e2fa7f031e464a97be3f990d 100644 --- a/src/runtime/src/log.js +++ b/src/runtime/src/log.js @@ -7,7 +7,7 @@ ops.log_stdout(logWithoutObject(...args)); }, json: (string, format) => { - ops.log_stdout(formatChain(string, format)); + ops.object_print(formatChain(string, format)); }, info: (...args) => { ops.log_info(logWithoutObject(...args));