Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { util } from "@app/util";

util();
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const thing = () => "thing";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"compilerOptions": {
"composite": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const util = () => "util";
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": { "@app/*": ["./src/*"] }
},
"references": [{ "path": "./pkg" }]
}
15 changes: 15 additions & 0 deletions src/tests/tsconfig_project_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,18 @@ fn walk_up_when_ref_excludes_file() {
resolver.resolve_file(f.join("pkg-a/src/excluded/bar.ts"), "@/foo").map(|f| f.full_path());
assert_eq!(resolved_path, Err(ResolveError::NotFound("@/foo".into())));
}

#[test]
fn root_paths_apply_to_default_include_files() {
let f = super::fixture_root().join("tsconfig/cases/project-references-default-include");

let resolver = Resolver::new(ResolveOptions {
extensions: vec![".ts".into()],
tsconfig: Some(TsconfigDiscovery::Auto),
..ResolveOptions::default()
});

let resolved_path =
resolver.resolve_file(f.join("index.ts"), "@app/util").map(|f| f.full_path());
assert_eq!(resolved_path, Ok(f.join("src/util.ts")));
}
20 changes: 9 additions & 11 deletions src/tsconfig.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ use crate::{TsconfigReferences, path::PathUtil, replace_bom_with_whitespace};
/// Allow list: <https://github.com/microsoft/TypeScript/issues/57485#issuecomment-2027787456>
const TEMPLATE_VARIABLE: &str = "${configDir}";

const GLOB_ALL_PATTERN: &str = "**/*";

pub type CompilerOptionsPathsMap = IndexMap<String, Vec<PathBuf>, BuildHasherDefault<FxHasher>>;

/// Project Reference
Expand Down Expand Up @@ -578,11 +576,14 @@ impl TsConfig {
if self.references_resolved.iter().any(|r| r.is_file_included_in_tsconfig(path)) {
return true;
}
// Solution-style configs (have `references` and no own `files` /
// `include`) never claim files themselves.
// Solution-style configs (have `references` and explicit empty
// `files` / `include`) never claim files themselves. Per the
// TypeScript spec, an *omitted* `include` defaults to `**/*`, so it
// must fall through to `is_file_included_in_tsconfig`; only an
// explicit empty array means "own no files".
let is_solution_style = !self.references_resolved.is_empty()
&& self.files.as_ref().is_none_or(Vec::is_empty)
&& self.include.as_ref().is_none_or(Vec::is_empty);
&& matches!(self.files.as_deref(), Some([]))
&& matches!(self.include.as_deref(), Some([]));
if is_solution_style {
return false;
}
Expand Down Expand Up @@ -618,7 +619,8 @@ impl TsConfig {
fn is_glob_matches(&self, path: &Path, pattern: GlobPattern) -> bool {
let path_str = path.to_string_lossy().replace('\\', "/");
match pattern {
GlobPattern::All => self.is_glob_match(GLOB_ALL_PATTERN, path, &path_str),
// The default include `**/*` is scoped to the tsconfig directory.
GlobPattern::All => path.starts_with(self.directory()),
GlobPattern::Pattern(patterns) => patterns.iter().any(|pattern| {
let pattern = pattern.to_string_lossy().replace('\\', "/");
self.is_glob_match(pattern.as_ref(), path, &path_str)
Expand All @@ -630,10 +632,6 @@ impl TsConfig {
if pattern == path_str {
return true;
}
// Special case: **/* matches everything
if pattern == GLOB_ALL_PATTERN {
return true;
}
// Normalize pattern: add implicit /**/* for directory patterns
// Find the part after the last '/' to check if it looks like a directory
let after_last_slash = pattern.rsplit('/').next().unwrap_or(pattern);
Expand Down
Loading