mirror of
https://github.com/starship/starship.git
synced 2025-08-18 12:00:02 +02:00
Revert "Parallelize nodejs file checks"
This reverts commit 99bdf27eca
.
This commit is contained in:
@@ -4,7 +4,6 @@ extern crate clap;
|
||||
extern crate ansi_term;
|
||||
extern crate dirs;
|
||||
extern crate git2;
|
||||
extern crate rayon;
|
||||
|
||||
mod modules;
|
||||
mod print;
|
||||
|
@@ -1,13 +1,12 @@
|
||||
use super::Segment;
|
||||
use ansi_term::{Color, Style};
|
||||
use clap::ArgMatches;
|
||||
use rayon::prelude::*;
|
||||
use std::env;
|
||||
use std::fs::{self, DirEntry};
|
||||
use std::process::Command;
|
||||
|
||||
/// Creates a segment with the current Node.js version
|
||||
///
|
||||
///
|
||||
/// Will display the Node.js version if any of the following criteria are met:
|
||||
/// - Current directory contains a `.js` file
|
||||
/// - Current directory contains a `node_modules` directory
|
||||
@@ -17,13 +16,10 @@ pub fn segment(_: &ArgMatches) -> Segment {
|
||||
const SECTION_COLOR: Color = Color::Green;
|
||||
|
||||
let current_path = env::current_dir().expect("Unable to identify current directory");
|
||||
let files = fs::read_dir(¤t_path)
|
||||
.unwrap()
|
||||
.filter_map(Result::ok)
|
||||
.collect::<Vec<DirEntry>>();
|
||||
let files = fs::read_dir(¤t_path).unwrap();
|
||||
|
||||
// Early return if there are no JS project files
|
||||
let is_js_project = files.par_iter().any(has_js_files);
|
||||
let is_js_project = files.filter_map(Result::ok).any(has_js_files);
|
||||
if !is_js_project {
|
||||
return Segment::default();
|
||||
}
|
||||
@@ -42,7 +38,7 @@ pub fn segment(_: &ArgMatches) -> Segment {
|
||||
}
|
||||
}
|
||||
|
||||
fn has_js_files(dir_entry: &DirEntry) -> bool {
|
||||
fn has_js_files(dir_entry: DirEntry) -> bool {
|
||||
let is_js_file = |d: &DirEntry| -> bool {
|
||||
d.path().is_file() && d.path().extension().unwrap_or_default() == "js"
|
||||
};
|
||||
@@ -53,5 +49,5 @@ fn has_js_files(dir_entry: &DirEntry) -> bool {
|
||||
d.path().is_file() && d.path().file_name().unwrap_or_default() == "package.json"
|
||||
};
|
||||
|
||||
is_js_file(dir_entry) || is_node_modules(dir_entry) || is_package_json(dir_entry)
|
||||
is_js_file(&dir_entry) || is_node_modules(&dir_entry) || is_package_json(&dir_entry)
|
||||
}
|
||||
|
Reference in New Issue
Block a user