Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit 0396f34

Browse files
committed
fix: do not require monorepo_root to be specified as an absolute path
Previously, the `exact` enumeration method required the `monorepo_root` to be specified as an absolute path. This commit canonicalizes the `monorepo_root` before invoking `tsc`, so this constraint is no longer required.
1 parent 9b0ec3c commit 0396f34

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

src/exact.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ impl Display for EnumerateError {
4444
EnumerateErrorKind::PackageInMonorepoRoot(path) => {
4545
write!(f, "unexpected package in monorepo root: {:?}", path)
4646
}
47+
EnumerateErrorKind::Canonicalize { path, inner: _ } => {
48+
write!(f, "unable to canonicalize path {:?}", path)
49+
}
4750
}
4851
}
4952
}
@@ -59,6 +62,7 @@ impl std::error::Error for EnumerateError {
5962
EnumerateErrorKind::InvalidUtf8(err) => Some(err),
6063
EnumerateErrorKind::StripPrefix(err) => Some(err),
6164
EnumerateErrorKind::PackageInMonorepoRoot(_) => None,
65+
EnumerateErrorKind::Canonicalize { path: _, inner } => Some(inner),
6266
}
6367
}
6468
}
@@ -75,6 +79,11 @@ pub enum EnumerateErrorKind {
7579
StripPrefix(path::StripPrefixError),
7680
#[non_exhaustive]
7781
PackageInMonorepoRoot(PathBuf),
82+
#[non_exhaustive]
83+
Canonicalize {
84+
path: PathBuf,
85+
inner: std::io::Error,
86+
},
7887
}
7988

8089
impl From<string::FromUtf8Error> for EnumerateErrorKind {
@@ -96,12 +105,19 @@ fn tsconfig_includes_exact(
96105
tsconfig: &TypescriptConfigFile,
97106
) -> Result<Vec<PathBuf>, EnumerateError> {
98107
(|| {
108+
let monorepo_root = std::fs::canonicalize(monorepo_root).map_err(|inner| {
109+
EnumerateErrorKind::Canonicalize {
110+
path: monorepo_root.to_path_buf(),
111+
inner,
112+
}
113+
})?;
114+
99115
let child = Command::new("tsc")
100116
.arg("--listFilesOnly")
101117
.arg("--project")
102118
.arg(
103119
tsconfig
104-
.package_directory(monorepo_root)
120+
.package_directory(&monorepo_root)
105121
.map_err(|err| EnumerateErrorKind::PackageInMonorepoRoot(err.0))?,
106122
)
107123
.output()
@@ -119,9 +135,9 @@ fn tsconfig_includes_exact(
119135
// Drop the empty newline at the end of stdout
120136
.filter(|s| !s.is_empty())
121137
.map(PathBuf::from)
122-
.filter(|path| is_monorepo_file(monorepo_root, path))
138+
.filter(|path| is_monorepo_file(&monorepo_root, path))
123139
.map(|source_file| {
124-
remove_relative_path_prefix_from_absolute_path(monorepo_root, &source_file)
140+
remove_relative_path_prefix_from_absolute_path(&monorepo_root, &source_file)
125141
})
126142
.collect::<Result<_, _>>()?;
127143

0 commit comments

Comments
 (0)