Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
44 changes: 42 additions & 2 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,49 @@ fn find_affected_internal(
for changed_file in &source_files {
let file_path = &changed_file.file_path;

// Check if file exists in our analyzed files
// Check if file exists in our analyzed files. A source-typed file (.ts/.tsx/.js/.jsx)
// can live inside a project's root but outside its sourceRoot (e.g. jest.config.js,
// webpack.config.js at project root when sourceRoot = "<proj>/src"). The semantic
// analyzer only walks sourceRoot, so such files never reach it — but they still
// belong to the project and changing them must mark it affected. Fall back to the
// same root-based ownership lookup used for assets.
if !analyzer.files.contains_key(file_path) {
debug!("Skipping unanalyzed source file: {:?}", file_path);
debug!(
"Source file not in analyzer.files, using root fallback: {:?}",
file_path
);
let owning_packages = project_index.get_package_names_by_path(file_path);
for pkg in &owning_packages {
debug!(
"File {:?} belongs to package '{}' (via root fallback)",
file_path, pkg
);
affected_packages.insert(pkg.clone());

if generate_report {
Comment thread
nirsky marked this conversation as resolved.
if changed_file.changed_lines.is_empty() {
project_causes
.entry(pkg.clone())
.or_default()
.push(AffectCause::DirectChange {
file: file_path.clone(),
symbol: None,
line: 0,
});
} else {
for &line in &changed_file.changed_lines {
project_causes
.entry(pkg.clone())
Comment thread
nirsky marked this conversation as resolved.
Outdated
.or_default()
.push(AffectCause::DirectChange {
file: file_path.clone(),
symbol: None,
line,
});
}
}
}
}
continue;
}

Expand Down
23 changes: 23 additions & 0 deletions tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3293,6 +3293,29 @@ fn test_named_inputs_negation_with_root_differs_from_source_root() {
);
}

#[test]
fn test_source_file_outside_sourceroot_affects_owning_project() {
// lib-a has sourceRoot = "libs/lib-a/src" but project root = "libs/lib-a".
// A source-typed config file (jest.config.js) at project root lives OUTSIDE
// sourceRoot, so the semantic analyzer never parses it. It must still mark
// its owning project as affected via the root fallback — otherwise changes
// to project-level config files would be silently ignored.
let repo = TempNxRepo::new(r#"{}"#);

repo.change_and_commit(
"libs/lib-a/jest.config.js",
"module.exports = { workerIdleMemoryLimit: '2048MB' };\n",
);

let affected = repo.get_affected();

assert!(
affected.contains(&"lib-a".to_string()),
"lib-a should be affected (jest.config.js at project root, outside sourceRoot). Got: {:?}",
Comment thread
nirsky marked this conversation as resolved.
Outdated
affected
);
}

#[test]
fn test_head_flag_commit_to_commit_diff() {
let branch = TestBranch::new("test-head-flag");
Expand Down
Loading