summaryrefslogtreecommitdiff
path: root/cli/fs_util.rs
diff options
context:
space:
mode:
authorYusuke Tanaka <yusuktan@maguro.dev>2020-11-23 05:45:44 +0900
committerGitHub <noreply@github.com>2020-11-22 21:45:44 +0100
commite3f73d3ec0aa822c9d125374ec34b7d8d5dfc0a5 (patch)
tree1f61389d70aeb116bb7075d5489c042d5d8a2d52 /cli/fs_util.rs
parent17d4cd92133bb822ff3a4f2f5bb32dfd17f99282 (diff)
feat(unstable): Support --watch flag for bundle and fmt subcommands (#8276)
This commit adds support for "--watch" flag for "bundle" and "fmt" subcommands. In addition to this, it refactors "run --watch" command so that module resolution will occur every time the file watcher detects file addition/deletion, which allows the watcher to observe a file that is newly added to the dependency as well.
Diffstat (limited to 'cli/fs_util.rs')
-rw-r--r--cli/fs_util.rs30
1 files changed, 13 insertions, 17 deletions
diff --git a/cli/fs_util.rs b/cli/fs_util.rs
index 16f9e1f64..217476c01 100644
--- a/cli/fs_util.rs
+++ b/cli/fs_util.rs
@@ -88,8 +88,8 @@ pub fn is_supported_ext(path: &Path) -> bool {
/// Collects file paths that satisfy the given predicate, by recursively walking `files`.
/// If the walker visits a path that is listed in `ignore`, it skips descending into the directory.
pub fn collect_files<P>(
- files: Vec<PathBuf>,
- ignore: Vec<PathBuf>,
+ files: &[PathBuf],
+ ignore: &[PathBuf],
predicate: P,
) -> Result<Vec<PathBuf>, AnyError>
where
@@ -99,15 +99,12 @@ where
// retain only the paths which exist and ignore the rest
let canonicalized_ignore: Vec<PathBuf> = ignore
- .into_iter()
+ .iter()
.filter_map(|i| i.canonicalize().ok())
.collect();
- let files = if files.is_empty() {
- vec![std::env::current_dir()?]
- } else {
- files
- };
+ let cur_dir = [std::env::current_dir()?];
+ let files = if files.is_empty() { &cur_dir } else { files };
for file in files {
for entry in WalkDir::new(file)
@@ -232,15 +229,14 @@ mod tests {
let ignore_dir_files = ["g.d.ts", ".gitignore"];
create_files(&ignore_dir_path, &ignore_dir_files);
- let result =
- collect_files(vec![root_dir_path], vec![ignore_dir_path], |path| {
- // exclude dotfiles
- path
- .file_name()
- .and_then(|f| f.to_str())
- .map_or(false, |f| !f.starts_with('.'))
- })
- .unwrap();
+ let result = collect_files(&[root_dir_path], &[ignore_dir_path], |path| {
+ // exclude dotfiles
+ path
+ .file_name()
+ .and_then(|f| f.to_str())
+ .map_or(false, |f| !f.starts_with('.'))
+ })
+ .unwrap();
let expected = [
"a.ts",
"b.js",