Skip to content

Commit

Permalink
ref(inject): Walk dir recursively instead of globbing (#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
loewenheim authored and kamilogorek committed Mar 13, 2023
1 parent d02742a commit d257f1d
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/commands/sourcemaps/inject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ use std::path::{Path, PathBuf};

use anyhow::{bail, Context, Result};
use clap::{Arg, ArgMatches, Command};
use glob::glob;
use log::{debug, warn};
use serde_json::Value;
use symbolic::debuginfo::js;
use uuid::Uuid;
use walkdir::WalkDir;

const CODE_SNIPPET_TEMPLATE: &str = r#"!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},n=(new Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="__SENTRY_DEBUG_ID__")}catch(e){}}()"#;
const DEBUGID_PLACEHOLDER: &str = "__SENTRY_DEBUG_ID__";
Expand All @@ -28,22 +28,31 @@ pub fn make_command(command: Command) -> Command {
Arg::new("path")
.value_name("PATH")
.required(true)
.help("The path or glob to the javascript files."),
.help("The path to the javascript files."),
)
.hide(true)
}

pub fn execute(matches: &ArgMatches) -> Result<()> {
let path = matches.get_one::<String>("path").unwrap();

let collected_paths: Vec<PathBuf> = glob(path)
.unwrap()
.flatten()
.filter(|path| path.extension().map_or(false, |ext| ext == "js"))
.collect();
let mut collected_paths = Vec::new();
for entry in WalkDir::new(path) {
let entry = match entry {
Ok(entry) => entry,
Err(ref e) => {
debug!("Skipping file: {e}");
continue;
}
};

if entry.path().extension().map_or(false, |ext| ext == "js") {
collected_paths.push(entry.path().to_owned());
}
}

if collected_paths.is_empty() {
warn!("Did not match any JavaScript files for pattern: {}", path);
warn!("Did not find any JavaScript files in path: {path}",);
return Ok(());
}

Expand Down

0 comments on commit d257f1d

Please sign in to comment.