Projects STRLCPY dum Commits 0c16bd0a
🤬
Revision indexing in progress... (symbol navigation in revisions will be accurate after indexed)
  • ■ ■ ■ ■ ■
    CHANGELOG.md
     1 +## v0.1.16
     2 + 
     3 +- Resolve `-c <dir>` to absolute path, previously it always searches package.json from current directory even if `-c` contains `../`.
     4 +- Allow flags in `install` `uninstall` `add` commands.
     5 + 
    1 6  ## v0.1.15
    2 7   
    3 8  - Forward args to `install` `uninstall` and `add` commands
    skipped 47 lines
  • ■ ■ ■ ■ ■ ■
    Cargo.lock
    skipped 2 lines
    3 3  version = 3
    4 4   
    5 5  [[package]]
     6 +name = "aho-corasick"
     7 +version = "0.7.18"
     8 +source = "registry+https://github.com/rust-lang/crates.io-index"
     9 +checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
     10 +dependencies = [
     11 + "memchr",
     12 +]
     13 + 
     14 +[[package]]
    6 15  name = "ansi_term"
    7 16  version = "0.12.1"
    8 17  source = "registry+https://github.com/rust-lang/crates.io-index"
    9 18  checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2"
    10 19  dependencies = [
     20 + "winapi",
     21 +]
     22 + 
     23 +[[package]]
     24 +name = "atty"
     25 +version = "0.2.14"
     26 +source = "registry+https://github.com/rust-lang/crates.io-index"
     27 +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
     28 +dependencies = [
     29 + "hermit-abi",
     30 + "libc",
    11 31   "winapi",
    12 32  ]
    13 33   
    skipped 60 lines
    74 94   
    75 95  [[package]]
    76 96  name = "dum"
    77  -version = "0.1.15"
     97 +version = "0.1.16"
    78 98  dependencies = [
    79 99   "ansi_term",
    80 100   "ctrlc",
    81 101   "dialoguer",
     102 + "env_logger",
     103 + "log",
     104 + "path-absolutize",
    82 105   "serde_json",
    83 106  ]
    84 107   
    skipped 4 lines
    89 112  checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
    90 113   
    91 114  [[package]]
     115 +name = "env_logger"
     116 +version = "0.9.0"
     117 +source = "registry+https://github.com/rust-lang/crates.io-index"
     118 +checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
     119 +dependencies = [
     120 + "atty",
     121 + "humantime",
     122 + "log",
     123 + "regex",
     124 + "termcolor",
     125 +]
     126 + 
     127 +[[package]]
    92 128  name = "getrandom"
    93 129  version = "0.2.3"
    94 130  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 3 lines
    98 134   "libc",
    99 135   "wasi",
    100 136  ]
     137 + 
     138 +[[package]]
     139 +name = "hermit-abi"
     140 +version = "0.1.19"
     141 +source = "registry+https://github.com/rust-lang/crates.io-index"
     142 +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33"
     143 +dependencies = [
     144 + "libc",
     145 +]
     146 + 
     147 +[[package]]
     148 +name = "humantime"
     149 +version = "2.1.0"
     150 +source = "registry+https://github.com/rust-lang/crates.io-index"
     151 +checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
    101 152   
    102 153  [[package]]
    103 154  name = "itoa"
    skipped 14 lines
    118 169  checksum = "fbe5e23404da5b4f555ef85ebed98fb4083e55a00c317800bc2a50ede9f3d219"
    119 170   
    120 171  [[package]]
     172 +name = "log"
     173 +version = "0.4.14"
     174 +source = "registry+https://github.com/rust-lang/crates.io-index"
     175 +checksum = "51b9bbe6c47d51fc3e1a9b945965946b4c44142ab8792c50835a980d362c2710"
     176 +dependencies = [
     177 + "cfg-if",
     178 +]
     179 + 
     180 +[[package]]
     181 +name = "memchr"
     182 +version = "2.4.1"
     183 +source = "registry+https://github.com/rust-lang/crates.io-index"
     184 +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a"
     185 + 
     186 +[[package]]
    121 187  name = "memoffset"
    122 188  version = "0.6.5"
    123 189  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 22 lines
    146 212  checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56"
    147 213   
    148 214  [[package]]
     215 +name = "path-absolutize"
     216 +version = "3.0.11"
     217 +source = "registry+https://github.com/rust-lang/crates.io-index"
     218 +checksum = "b288298a7a3a7b42539e3181ba590d32f2d91237b0691ed5f103875c754b3bf5"
     219 +dependencies = [
     220 + "path-dedot",
     221 +]
     222 + 
     223 +[[package]]
     224 +name = "path-dedot"
     225 +version = "3.0.14"
     226 +source = "registry+https://github.com/rust-lang/crates.io-index"
     227 +checksum = "4bfa72956f6be8524f7f7e2b07972dda393cb0008a6df4451f658b7e1bd1af80"
     228 +dependencies = [
     229 + "once_cell",
     230 +]
     231 + 
     232 +[[package]]
    149 233  name = "ppv-lite86"
    150 234  version = "0.2.15"
    151 235  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 54 lines
    206 290  source = "registry+https://github.com/rust-lang/crates.io-index"
    207 291  checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
    208 292  dependencies = [
     293 + "aho-corasick",
     294 + "memchr",
    209 295   "regex-syntax",
    210 296  ]
    211 297   
    skipped 50 lines
    262 348  ]
    263 349   
    264 350  [[package]]
     351 +name = "termcolor"
     352 +version = "1.1.2"
     353 +source = "registry+https://github.com/rust-lang/crates.io-index"
     354 +checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
     355 +dependencies = [
     356 + "winapi-util",
     357 +]
     358 + 
     359 +[[package]]
    265 360  name = "terminal_size"
    266 361  version = "0.1.17"
    267 362  source = "registry+https://github.com/rust-lang/crates.io-index"
    skipped 30 lines
    298 393  version = "0.4.0"
    299 394  source = "registry+https://github.com/rust-lang/crates.io-index"
    300 395  checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
     396 + 
     397 +[[package]]
     398 +name = "winapi-util"
     399 +version = "0.1.5"
     400 +source = "registry+https://github.com/rust-lang/crates.io-index"
     401 +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
     402 +dependencies = [
     403 + "winapi",
     404 +]
    301 405   
    302 406  [[package]]
    303 407  name = "winapi-x86_64-pc-windows-gnu"
    skipped 10 lines
  • ■ ■ ■ ■
    Cargo.toml
    1 1  [package]
    2 2  name = "dum"
    3  -version = "0.1.15"
     3 +version = "0.1.16"
    4 4  edition = "2021"
    5 5  license = "MIT"
    6 6  description = "An npm scripts runner"
    skipped 7 lines
    14 14  dialoguer = "0.9.0"
    15 15  ansi_term = "0.12.1"
    16 16  ctrlc = "3.2.1"
     17 +log = "0.4.14"
     18 +env_logger = "0.9.0"
     19 +path-absolutize = "3.0.11"
  • ■ ■ ■ ■ ■
    src/args.rs
     1 +extern crate path_absolutize;
     2 + 
    1 3  use std::env;
    2  -use std::path::PathBuf;
     4 +use std::path::{Path, PathBuf};
    3 5  use std::process::exit;
     6 + 
     7 +use path_absolutize::Absolutize;
    4 8   
    5 9  #[derive(Debug)]
    6 10  pub struct AppArgs {
    skipped 22 lines
    29 33   match arg {
    30 34   Some(v) => {
    31 35   if v.starts_with("-") {
    32  - if args.script_name.is_empty() {
     36 + if args.script_name.is_empty()
     37 + && (args.command.is_empty() || args.command == "run")
     38 + {
    33 39   match v.as_ref() {
    34 40   "-c" => {
    35 41   let dir = match args_iter.next() {
    36  - Some(v) => PathBuf::from(v),
     42 + Some(v) => PathBuf::from(Path::new(v).absolutize().unwrap()),
    37 43   None => {
    38 44   println!("No directory specified");
    39 45   exit(1);
    skipped 121 lines
  • ■ ■ ■ ■ ■
    src/main.rs
    skipped 5 lines
    6 6  use std::env;
    7 7   
    8 8  fn main() {
     9 + env_logger::init();
    9 10   prompt::handle_ctrlc();
    10 11   
    11 12   let args_vec: Vec<String> = env::args().collect();
    skipped 5 lines
  • ■ ■ ■ ■ ■
    src/run.rs
    skipped 3 lines
    4 4   Color::{Purple, Red},
    5 5   Style,
    6 6  };
     7 +use log::debug;
    7 8  use serde_json::Value;
    8 9  use std::collections::HashMap;
    9 10  use std::env;
    skipped 21 lines
    31 32  fn find_closest_files(_current_dir: &PathBuf, name: &str, stop_on_first: bool) -> Vec<PathBuf> {
    32 33   let mut closest_file: Vec<PathBuf> = Vec::new();
    33 34   let mut current_dir = _current_dir.clone();
    34  - 
    35 35   loop {
    36 36   let path = current_dir.join(name);
     37 + 
    37 38   if path.exists() {
    38 39   closest_file.push(path);
    39 40   if stop_on_first {
    skipped 46 lines
    86 87   
    87 88  pub fn run(app_args: &args::AppArgs) {
    88 89   if args::COMMANDS_TO_FORWARD.contains(&app_args.command.as_str()) {
     90 + debug!("Running command {}", app_args.command);
    89 91   let pm = install::guess_package_manager(&app_args.change_dir);
    90 92   
    91 93   if pm.is_none() {
    skipped 11 lines
    103 105   return;
    104 106   }
    105 107   
     108 + debug!("change dir to {}", app_args.change_dir.display());
    106 109   let pkg_paths = find_closest_files(&app_args.change_dir, "package.json", true);
    107 110   let pkg_path = if pkg_paths.is_empty() {
    108 111   eprintln!("No package.json found");
    skipped 2 lines
    111 114   pkg_paths[0].clone()
    112 115   };
    113 116   
     117 + debug!("Found package.json at {}", pkg_path.display());
    114 118   // The current_dir to execute npm scripts
    115 119   let execute_dir = PathBuf::from(pkg_path.parent().unwrap());
     120 + debug!("execute_dir: {:?}", execute_dir);
    116 121   
    117 122   let node_modules_dirs = find_closest_files(&app_args.change_dir, "node_modules", false);
    118 123   let bin_dirs = node_modules_dirs
    skipped 117 lines
Please wait...
Page is in error, reload to recover