diff --git a/Cargo.lock b/Cargo.lock index 1056a3510..1adab9928 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -197,7 +197,7 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -268,7 +268,7 @@ dependencies = [ "objc_id", "parking_lot", "thiserror", - "winapi", + "winapi 0.3.9", "x11rb", ] @@ -466,7 +466,7 @@ checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" dependencies = [ "hermit-abi 0.1.19", "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -711,6 +711,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +[[package]] +name = "c_linked_list" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4964518bd3b4a8190e832886cdc0da9794f12e8e6c1613a9e90ff331c4c8724b" + [[package]] name = "cached" version = "0.46.1" @@ -887,7 +893,7 @@ checksum = "7191c27c2357d9b7ef96baac1773290d4ca63b24205b82a3fd8a0637afcf0362" dependencies = [ "error-code", "str-buf", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -1328,7 +1334,7 @@ dependencies = [ "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "winapi", + "winapi 0.3.9", "winit", ] @@ -1736,6 +1742,12 @@ dependencies = [ "byteorder", ] +[[package]] +name = "gcc" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" + [[package]] name = "generic-array" version = "0.14.7" @@ -1746,6 +1758,28 @@ dependencies = [ "version_check", ] +[[package]] +name = "get_if_addrs" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abddb55a898d32925f3148bd281174a68eeb68bbfd9a5938a57b18f506ee4ef7" +dependencies = [ + "c_linked_list", + "get_if_addrs-sys", + "libc", + "winapi 0.2.8", +] + +[[package]] +name = "get_if_addrs-sys" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d04f9fb746cf36b191c00f3ede8bde9c8e64f9f4b05ae2694a9ccf5e3f5ab48" +dependencies = [ + "gcc", + "libc", +] + [[package]] name = "gethostname" version = "0.2.3" @@ -1753,7 +1787,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -2069,7 +2103,7 @@ dependencies = [ "rand", "tokio", "url", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -2473,7 +2507,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" dependencies = [ "cfg-if", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -2556,6 +2590,7 @@ dependencies = [ "dashmap 4.0.2", "delegate", "fixedbitset", + "get_if_addrs", "glob-match", "heck", "insta", @@ -3047,7 +3082,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a9da8c9922c35a1033d76f7272dfc2e7ee20392083d75aeea6ced23c6266578" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -3089,7 +3124,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" dependencies = [ "overload", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -4363,7 +4398,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -4423,7 +4458,7 @@ dependencies = [ "cfg-if", "libc", "psm", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -6182,7 +6217,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df" dependencies = [ "libc", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -6626,7 +6661,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ce65604324d3cce9b966701489fbd0cf318cb1f7bd9dd07ac9a4ee6fb791930d" dependencies = [ "tempfile", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -6971,6 +7006,12 @@ dependencies = [ "web-sys", ] +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" + [[package]] name = "winapi" version = "0.3.9" @@ -6993,7 +7034,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -7002,7 +7043,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e" dependencies = [ - "winapi", + "winapi 0.3.9", ] [[package]] @@ -7266,7 +7307,7 @@ checksum = "592b4883219f345e712b3209c62654ebda0bb50887f330cbd018d0f654bfd507" dependencies = [ "gethostname", "nix 0.24.3", - "winapi", + "winapi 0.3.9", "winapi-wsapoll", "x11rb-protocol", ] @@ -7296,7 +7337,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2769203cd13a0c6015d515be729c526d041e9cf2c0cc478d57faee85f40c6dcd" dependencies = [ "nix 0.26.4", - "winapi", + "winapi 0.3.9", ] [[package]] @@ -7354,7 +7395,7 @@ dependencies = [ "static_assertions", "tracing", "uds_windows", - "winapi", + "winapi 0.3.9", "xdg-home", "zbus_macros", "zbus_names", diff --git a/crates/mako/Cargo.toml b/crates/mako/Cargo.toml index 41352a0dc..7dddbad6e 100644 --- a/crates/mako/Cargo.toml +++ b/crates/mako/Cargo.toml @@ -16,6 +16,7 @@ cached = { workspace = true } dashmap = "4.0.1" delegate = "0.12.0" fixedbitset = "0.4.2" +get_if_addrs = "0.5.3" glob-match = "0.2.1" heck = "0.4.1" mako_core = { path = "../core" } diff --git a/crates/mako/src/dev/mod.rs b/crates/mako/src/dev/mod.rs index d6643c486..e9815a163 100644 --- a/crates/mako/src/dev/mod.rs +++ b/crates/mako/src/dev/mod.rs @@ -6,6 +6,7 @@ use std::path::PathBuf; use std::sync::{mpsc, Arc}; use std::time::{Duration, Instant, UNIX_EPOCH}; +use get_if_addrs::get_if_addrs; use mako_core::anyhow::{self, Result}; use mako_core::colored::Colorize; use mako_core::futures::{SinkExt, StreamExt}; @@ -84,6 +85,25 @@ impl DevServer { }); let server = Server::bind(&addr).serve(make_svc); // TODO: print when mako is run standalone + if std::env::var("MAKO_CLI").is_ok() { + println!(); + println!( + "Local: {}", + format!("http://localhost:{}/", port).to_string().cyan() + ); + let ips = Self::get_ips(); + let ips = ips + .iter() + .filter(|ip| !ip.starts_with("127.")) + .collect::>(); + for ip in ips { + println!( + "Network: {}", + format!("http://{}:{}/", ip, port).to_string().cyan() + ); + } + println!(); + } debug!("Listening on http://{:?}", addr); if let Err(e) = server.await { eprintln!("Error starting server: {:?}", e); @@ -167,6 +187,22 @@ impl DevServer { } } + fn get_ips() -> Vec { + let mut ips = vec![]; + match get_if_addrs() { + Ok(if_addrs) => { + for if_addr in if_addrs { + if let get_if_addrs::IfAddr::V4(addr) = if_addr.addr { + let ip = addr.ip.to_string(); + ips.push(ip); + } + } + } + Err(_e) => {} + } + ips + } + // TODO: refact socket message data structure async fn handle_websocket( websocket: hyper_tungstenite::HyperWebsocket, @@ -285,12 +321,12 @@ impl DevServer { "hot update chunks generated, next_full_hash: {:?}", next_hash ); - if !has_missing_deps { - println!( - "Hot rebuilt in {}", - format!("{}ms", t_compiler.elapsed().as_millis()).bold() - ); - } + // if !has_missing_deps { + // println!( + // "Hot rebuilt in {}", + // format!("{}ms", t_compiler.elapsed().as_millis()).bold() + // ); + // } if let Err(e) = next_hash { eprintln!("Error in watch: {:?}", e); return Err(e); diff --git a/packages/mako/binding.d.ts b/packages/mako/binding.d.ts index 396cc8a8f..5831ff6e6 100644 --- a/packages/mako/binding.d.ts +++ b/packages/mako/binding.d.ts @@ -3,6 +3,10 @@ /* auto-generated by NAPI-RS */ +export interface TransformOutput { + code: string; + map?: string; +} export interface JsHooks { name?: string; load?: ( diff --git a/packages/mako/package.json b/packages/mako/package.json index c06beaae8..9464ce1b9 100644 --- a/packages/mako/package.json +++ b/packages/mako/package.json @@ -21,6 +21,7 @@ "license": "MIT", "dependencies": { "@swc/helpers": "0.5.1", + "chalk": "^4.1.2", "less": "^4.2.0", "less-plugin-resolve": "^1.0.2", "lodash": "^4.17.21", @@ -74,4 +75,4 @@ "@umijs/mako-linux-x64-musl": "0.5.4" }, "repository": "git@github.com:umijs/mako.git" -} \ No newline at end of file +} diff --git a/packages/mako/src/cli.ts b/packages/mako/src/cli.ts index 722da9bb5..c67169b30 100644 --- a/packages/mako/src/cli.ts +++ b/packages/mako/src/cli.ts @@ -1,3 +1,4 @@ +import chalk from 'chalk'; import yParser from 'yargs-parser'; (async () => { @@ -9,6 +10,13 @@ import yParser from 'yargs-parser'; process.exit(1); } + // use MAKO_CLI to identify if it's running in mako cli standalone + // so that we can print extra information + process.env.MAKO_CLI = '1'; + console.log(); + console.log(chalk.bold(`Mako v${require('../package.json').version}`)); + console.log(); + let argv = yParser(process.argv.slice(2)); let command = argv._[0]; switch (command) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bfea3134d..9990e41ff 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -428,6 +428,9 @@ importers: '@swc/helpers': specifier: 0.5.1 version: 0.5.1 + chalk: + specifier: ^4.1.2 + version: 4.1.2 less: specifier: ^4.2.0 version: 4.2.0 @@ -3337,6 +3340,7 @@ packages: /@humanwhocodes/config-array@0.11.8: resolution: {integrity: sha512-UybHIJzJnR5Qc/MsD9Kr+RpO2h+/P1GhOwdiLPXK5TWk5sgTdu88bTD9UP+CKbPPh5Rni1u0GjAdYQLemG8g+g==} engines: {node: '>=10.10.0'} + deprecated: Use @eslint/config-array instead dependencies: '@humanwhocodes/object-schema': 1.2.1 debug: 4.3.4(supports-color@5.5.0) @@ -3352,6 +3356,7 @@ packages: /@humanwhocodes/object-schema@1.2.1: resolution: {integrity: sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==} + deprecated: Use @eslint/object-schema instead dev: true /@iconify/types@2.0.0: @@ -6552,8 +6557,8 @@ packages: ansi-styles: 4.3.0 supports-color: 7.2.0 - /chalk@5.2.0: - resolution: {integrity: sha512-ree3Gqw/nazQAPuJJEy+avdl7QfZMcUvmHIKgEZkGL+xOBzRvup5Hxo6LHuMceSxOabuJLJm5Yp/92R9eMmMvA==} + /chalk@5.3.0: + resolution: {integrity: sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==} engines: {node: ^12.17.0 || ^14.13 || >=16.0.0} dev: true @@ -15165,7 +15170,7 @@ packages: '@types/node': 18.16.19 '@types/ps-tree': 1.1.2 '@types/which': 3.0.0 - chalk: 5.2.0 + chalk: 5.3.0 fs-extra: 11.1.1 fx: 28.0.0 globby: 13.1.4