这是indexloc提供的服务,不要输入任何密码
Skip to content

feat(boundaries): add a nice message after finishing boundaries checks #9861

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 40 additions & 15 deletions crates/turborepo-lib/src/boundaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use miette::{Diagnostic, NamedSource, Report, SourceSpan};
use oxc_resolver::{ResolveError, Resolver};
use regex::Regex;
use swc_common::{
comments::SingleThreadedComments,
errors::{ColorConfig, Handler},
input::StringInput,
FileName, SourceMap,
comments::SingleThreadedComments, errors::Handler, input::StringInput, FileName, SourceMap,
};
use swc_ecma_ast::EsVersion;
use swc_ecma_parser::{lexer::Lexer, Capturing, EsSyntax, Parser, Syntax, TsSyntax};
Expand All @@ -24,6 +21,7 @@ use turborepo_repository::{
package_graph::{PackageName, PackageNode},
package_json::PackageJson,
};
use turborepo_ui::{color, ColorConfig, BOLD_GREEN, BOLD_RED};

use crate::run::Run;

Expand Down Expand Up @@ -80,6 +78,8 @@ static PACKAGE_NAME_REGEX: LazyLock<Regex> = LazyLock::new(|| {
});

pub struct BoundariesResult {
files_checked: usize,
packages_checked: usize,
pub source_map: Arc<SourceMap>,
pub diagnostics: Vec<BoundariesDiagnostic>,
}
Expand All @@ -89,13 +89,15 @@ impl BoundariesResult {
self.diagnostics.is_empty()
}

pub fn emit(&self) {
let handler = Handler::with_tty_emitter(
ColorConfig::Auto,
true,
false,
Some(self.source_map.clone()),
);
pub fn emit(&self, color_config: ColorConfig) {
let swc_color_config = if color_config.should_strip_ansi {
swc_common::errors::ColorConfig::Never
} else {
swc_common::errors::ColorConfig::Always
};

let handler =
Handler::with_tty_emitter(swc_color_config, true, false, Some(self.source_map.clone()));

for diagnostic in self.diagnostics.clone() {
match diagnostic {
Expand All @@ -107,6 +109,21 @@ impl BoundariesResult {
}
}
}
let result_message = if self.diagnostics.is_empty() {
color!(color_config, BOLD_GREEN, "no issues found")
} else {
color!(
color_config,
BOLD_RED,
"{} issues found",
self.diagnostics.len()
)
};

println!(
"Checked {} files in {} packages, {}",
self.files_checked, self.packages_checked, result_message
);
}
}

Expand All @@ -116,6 +133,7 @@ impl Run {
let repo = Repository::discover(self.repo_root()).ok().map(Mutex::new);
let mut diagnostics = vec![];
let source_map = SourceMap::default();
let mut total_files_checked = 0;
for (package_name, package_info) in packages {
if !self.filtered_pkgs().contains(package_name)
|| matches!(package_name, PackageName::Root)
Expand All @@ -132,7 +150,7 @@ impl Run {
let unresolved_external_dependencies =
package_info.unresolved_external_dependencies.as_ref();

let package_diagnostics = self
let (files_checked, package_diagnostics) = self
.check_package(
&repo,
&package_root,
Expand All @@ -143,10 +161,14 @@ impl Run {
)
.await?;

total_files_checked += files_checked;
diagnostics.extend(package_diagnostics);
}

Ok(BoundariesResult {
files_checked: total_files_checked,
// Subtract 1 for the root package
packages_checked: self.pkg_dep_graph().len() - 1,
source_map: Arc::new(source_map),
diagnostics,
})
Expand All @@ -156,7 +178,8 @@ impl Run {
PACKAGE_NAME_REGEX.is_match(import)
}

/// Either returns a list of errors or a single, fatal error
/// Either returns a list of errors and number of files checked or a single,
/// fatal error
async fn check_package(
&self,
repo: &Option<Mutex<Repository>>,
Expand All @@ -165,7 +188,7 @@ impl Run {
internal_dependencies: HashSet<&PackageNode>,
unresolved_external_dependencies: Option<&BTreeMap<String, String>>,
source_map: &SourceMap,
) -> Result<Vec<BoundariesDiagnostic>, Error> {
) -> Result<(usize, Vec<BoundariesDiagnostic>), Error> {
let files = globwalk::globwalk(
package_root,
&[
Expand All @@ -180,6 +203,8 @@ impl Run {
globwalk::WalkType::Files,
)?;

let files_checked = files.len();

let mut diagnostics: Vec<BoundariesDiagnostic> = Vec::new();
// We assume the tsconfig.json is at the root of the package
let tsconfig_path = package_root.join_component("tsconfig.json");
Expand Down Expand Up @@ -271,7 +296,7 @@ impl Run {
}
}

Ok(diagnostics)
Ok((files_checked, diagnostics))
}

fn check_file_import(
Expand Down
2 changes: 1 addition & 1 deletion crates/turborepo-lib/src/commands/boundaries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub async fn run(base: CommandBase, telemetry: CommandEventBuilder) -> Result<i3

let result = run.check_boundaries().await?;

result.emit();
result.emit(run.color_config());

if result.is_ok() {
Ok(0)
Expand Down
6 changes: 1 addition & 5 deletions crates/turborepo-lib/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,11 +566,7 @@ impl RepositoryQuery {
/// Check boundaries for all packages.
async fn boundaries(&self) -> Result<Array<Diagnostic>, Error> {
match self.run.check_boundaries().await {
Ok(result) => {
result.emit();

Ok(result.diagnostics.into_iter().map(|b| b.into()).collect())
}
Ok(result) => Ok(result.diagnostics.into_iter().map(|b| b.into()).collect()),
Err(err) => Err(Error::Boundaries(err)),
}
}
Expand Down
Loading