mirror of
https://github.com/denoland/deno.git
synced 2025-09-26 12:19:12 +00:00
refactor: use globbing from deno_config (#21925)
This commit is contained in:
parent
3ff80eb152
commit
4e72ca313a
18 changed files with 294 additions and 789 deletions
|
@ -9,6 +9,7 @@ pub mod package_json;
|
|||
pub use self::import_map::resolve_import_map_from_specifier;
|
||||
use self::package_json::PackageJsonDeps;
|
||||
use ::import_map::ImportMap;
|
||||
use deno_config::glob::PathOrPattern;
|
||||
use deno_core::resolve_url_or_path;
|
||||
use deno_npm::resolution::ValidSerializedNpmResolutionSnapshot;
|
||||
use deno_npm::NpmSystemInfo;
|
||||
|
@ -16,9 +17,9 @@ use deno_runtime::deno_tls::RootCertStoreProvider;
|
|||
use deno_semver::npm::NpmPackageReqReference;
|
||||
use indexmap::IndexMap;
|
||||
|
||||
pub use deno_config::glob::FilePatterns;
|
||||
pub use deno_config::BenchConfig;
|
||||
pub use deno_config::ConfigFile;
|
||||
pub use deno_config::FilesConfig;
|
||||
pub use deno_config::FmtOptionsConfig;
|
||||
pub use deno_config::JsxImportSourceConfig;
|
||||
pub use deno_config::LintRulesConfig;
|
||||
|
@ -69,10 +70,9 @@ use thiserror::Error;
|
|||
|
||||
use crate::file_fetcher::FileFetcher;
|
||||
use crate::util::fs::canonicalize_path_maybe_not_exists;
|
||||
use crate::util::glob::FilePatterns;
|
||||
use crate::util::glob::PathOrPatternSet;
|
||||
use crate::version;
|
||||
|
||||
use deno_config::glob::PathOrPatternSet;
|
||||
use deno_config::FmtConfig;
|
||||
use deno_config::LintConfig;
|
||||
use deno_config::TestConfig;
|
||||
|
@ -1187,16 +1187,13 @@ impl CliOptions {
|
|||
}
|
||||
|
||||
pub fn resolve_config_excludes(&self) -> Result<PathOrPatternSet, AnyError> {
|
||||
let maybe_files_config = if let Some(config_file) = &self.maybe_config_file
|
||||
let maybe_config_files = if let Some(config_file) = &self.maybe_config_file
|
||||
{
|
||||
config_file.to_files_config()?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
PathOrPatternSet::from_absolute_paths(
|
||||
maybe_files_config.map(|c| c.exclude).unwrap_or_default(),
|
||||
)
|
||||
.context("Invalid config file exclude pattern.")
|
||||
Ok(maybe_config_files.map(|f| f.exclude).unwrap_or_default())
|
||||
}
|
||||
|
||||
pub fn resolve_test_options(
|
||||
|
@ -1647,30 +1644,38 @@ impl StorageKeyResolver {
|
|||
/// over config file, i.e. if there's `files.ignore` in config file
|
||||
/// and `--ignore` CLI flag, only the flag value is taken into account.
|
||||
fn resolve_files(
|
||||
maybe_files_config: Option<FilesConfig>,
|
||||
maybe_files_config: Option<FilePatterns>,
|
||||
maybe_file_flags: Option<FileFlags>,
|
||||
initial_cwd: &Path,
|
||||
) -> Result<FilePatterns, AnyError> {
|
||||
let mut maybe_files_config = maybe_files_config.unwrap_or_default();
|
||||
if let Some(file_flags) = maybe_file_flags {
|
||||
let file_flags = file_flags.with_absolute_paths(initial_cwd);
|
||||
if !file_flags.include.is_empty() {
|
||||
maybe_files_config.include = Some(file_flags.include);
|
||||
maybe_files_config.include =
|
||||
Some(PathOrPatternSet::from_relative_path_or_patterns(
|
||||
initial_cwd,
|
||||
&file_flags.include,
|
||||
)?);
|
||||
}
|
||||
if !file_flags.ignore.is_empty() {
|
||||
maybe_files_config.exclude = file_flags.ignore
|
||||
maybe_files_config.exclude =
|
||||
PathOrPatternSet::from_relative_path_or_patterns(
|
||||
initial_cwd,
|
||||
&file_flags.ignore,
|
||||
)?;
|
||||
}
|
||||
}
|
||||
Ok(FilePatterns {
|
||||
include: {
|
||||
let files = match maybe_files_config.include {
|
||||
Some(include) => include,
|
||||
None => vec![initial_cwd.to_path_buf()],
|
||||
None => PathOrPatternSet::new(vec![PathOrPattern::Path(
|
||||
initial_cwd.to_path_buf(),
|
||||
)]),
|
||||
};
|
||||
Some(PathOrPatternSet::from_absolute_paths(files)?)
|
||||
Some(files)
|
||||
},
|
||||
exclude: PathOrPatternSet::from_absolute_paths(maybe_files_config.exclude)
|
||||
.context("Invalid exclude.")?,
|
||||
exclude: maybe_files_config.exclude,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1882,26 +1887,32 @@ mod test {
|
|||
temp_dir.write("pages/[id].ts", "");
|
||||
|
||||
let temp_dir_path = temp_dir.path().as_path();
|
||||
let error = resolve_files(
|
||||
Some(FilesConfig {
|
||||
include: Some(vec![temp_dir_path.join("data/**********.ts")]),
|
||||
exclude: vec![],
|
||||
}),
|
||||
None,
|
||||
let error = PathOrPatternSet::from_relative_path_or_patterns(
|
||||
temp_dir_path,
|
||||
&["data/**********.ts".to_string()],
|
||||
)
|
||||
.unwrap_err();
|
||||
assert!(error.to_string().starts_with("Failed to expand glob"));
|
||||
|
||||
let resolved_files = resolve_files(
|
||||
Some(FilesConfig {
|
||||
include: Some(vec![
|
||||
temp_dir_path.join("data/test1.?s"),
|
||||
temp_dir_path.join("nested/foo/*.ts"),
|
||||
temp_dir_path.join("nested/fizz/*.ts"),
|
||||
temp_dir_path.join("pages/[id].ts"),
|
||||
]),
|
||||
exclude: vec![temp_dir_path.join("nested/**/*bazz.ts")],
|
||||
Some(FilePatterns {
|
||||
include: Some(
|
||||
PathOrPatternSet::from_relative_path_or_patterns(
|
||||
temp_dir_path,
|
||||
&[
|
||||
"data/test1.?s".to_string(),
|
||||
"nested/foo/*.ts".to_string(),
|
||||
"nested/fizz/*.ts".to_string(),
|
||||
"pages/[id].ts".to_string(),
|
||||
],
|
||||
)
|
||||
.unwrap(),
|
||||
),
|
||||
exclude: PathOrPatternSet::from_relative_path_or_patterns(
|
||||
temp_dir_path,
|
||||
&["nested/**/*bazz.ts".to_string()],
|
||||
)
|
||||
.unwrap(),
|
||||
}),
|
||||
None,
|
||||
temp_dir_path,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue